summaryrefslogtreecommitdiffstats
path: root/src-ambient/com/android/phone/common/ambient/AmbientConnection.java
blob: 04fe63a0ab59c664e96b8bdd0c43a7aafa819561 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.android.phone.common.ambient;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.cyanogen.ambient.analytics.AnalyticsServices;
import com.cyanogen.ambient.callerinfo.CallerInfoServices;
import com.cyanogen.ambient.common.ConnectionResult;
import com.cyanogen.ambient.common.api.AmbientApiClient;
import com.cyanogen.ambient.discovery.DiscoveryManagerServices;
import com.cyanogen.ambient.discovery.NudgeServices;
import com.cyanogen.ambient.incall.InCallServices;

/**
 * Holds Ambient Client for all PIM apps
 */
public class AmbientConnection {

    public static final SingletonHolder<AmbientApiClient, Context> CLIENT =
            new SingletonHolder<AmbientApiClient, Context>() {
                private static final String TAG = "PhoneCommon.AmbientSingletonHolder";

                @Override
                protected AmbientApiClient create(Context context) {
                    AmbientApiClient client = new AmbientApiClient.Builder(context)
                            .addApi(AnalyticsServices.API)
                            .addApi(InCallServices.API)
                            .addApi(CallerInfoServices.API)
                            .addApi(NudgeServices.API)
                            .addApi(DiscoveryManagerServices.API)
                            .build();

                    client.registerConnectionFailedListener(
                            new AmbientApiClient.OnConnectionFailedListener() {
                                @Override
                                public void onConnectionFailed(ConnectionResult result) {
                                    Log.w(TAG, "Connection failed: " + result);
                                }
                            });
                    client.registerDisconnectionListener(
                            new AmbientApiClient.OnDisconnectionListener() {
                                @Override
                                public void onDisconnection() {
                                    Log.d(TAG, "Connection disconnected");
                                }
                            });
                    client.registerConnectionCallbacks(
                            new AmbientApiClient.ConnectionCallbacks() {
                                @Override
                                public void onConnected(Bundle connectionHint) {
                                    Log.d(TAG, "Connection established");
                                }

                                @Override
                                public void onConnectionSuspended(int cause) {
                                    Log.d(TAG, "Connection suspended");
                                }
                            });
                    client.connect();
                    return client;
                }
            };

}