Search in sources :

Example 31 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project Android-ReactiveLocation by mcharmas.

the class BaseObservableOnSubscribe method subscribe.

@Override
public void subscribe(ObservableEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(emitter);
    try {
        apiClient.connect();
    } catch (Throwable ex) {
        if (!emitter.isDisposed()) {
            emitter.onError(ex);
        }
    }
    emitter.setDisposable(Disposables.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            onDisposed(apiClient);
            apiClient.disconnect();
        }
    }));
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Action(io.reactivex.functions.Action)

Example 32 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project androidApp by InspectorIncognito.

the class GoogleAccountLoader method load.

@Override
public void load(final CredentialsListener listener) {
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(TranSappApplication.getAppContext().getString(R.string.server_client_id)).build();
    final GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(TranSappApplication.getAppContext()).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
    mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

        @Override
        public void onConnected(@Nullable Bundle bundle) {
            OptionalPendingResult<GoogleSignInResult> pendingResult = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
            if (pendingResult.isDone()) {
                loadDataFromSignInResult(pendingResult.get(), listener, mGoogleApiClient);
            } else {
                pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {

                    @Override
                    public void onResult(@NonNull GoogleSignInResult result) {
                        if (result.isSuccess()) {
                            loadDataFromSignInResult(result, listener, mGoogleApiClient);
                        } else {
                            listener.onError(new ServerStatusCode(LOGIN_API_ERROR));
                        }
                    }
                }, 5000, TimeUnit.MILLISECONDS);
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            listener.onError(new ServerStatusCode(LOGIN_API_ERROR));
        }
    });
    mGoogleApiClient.connect();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) ResultCallback(com.google.android.gms.common.api.ResultCallback) Bundle(android.os.Bundle) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) OptionalPendingResult(com.google.android.gms.common.api.OptionalPendingResult) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult) NonNull(android.support.annotation.NonNull) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions)

Aggregations

GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)32 ConnectionResult (com.google.android.gms.common.ConnectionResult)10 Bundle (android.os.Bundle)6 Intent (android.content.Intent)5 Handler (android.os.Handler)4 PendingIntent (android.app.PendingIntent)3 SharedPreferences (android.content.SharedPreferences)3 Bitmap (android.graphics.Bitmap)3 NonNull (android.support.annotation.NonNull)3 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)3 NotificationManager (android.app.NotificationManager)2 NotificationCompat (android.support.v4.app.NotificationCompat)2 GoogleSignInResult (com.google.android.gms.auth.api.signin.GoogleSignInResult)2 Scope (com.google.android.gms.common.api.Scope)2 Status (com.google.android.gms.common.api.Status)2 DataItem (com.google.android.gms.wearable.DataItem)2 Node (com.google.android.gms.wearable.Node)2 PutDataMapRequest (com.google.android.gms.wearable.PutDataMapRequest)2 RemoteIntent (com.google.android.wearable.intent.RemoteIntent)2 SuppressLint (android.annotation.SuppressLint)1