Java Code Examples for com.google.android.gms.common.api.GoogleApiClient#registerConnectionCallbacks()

The following examples show how to use com.google.android.gms.common.api.GoogleApiClient#registerConnectionCallbacks() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogoutHelper.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
private static void logoutGoogle(GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    if (mGoogleApiClient == null) {
        mGoogleApiClient = GoogleApiHelper.createGoogleApiClient(fragmentActivity);
    }

    if (!mGoogleApiClient.isConnected()) {
        mGoogleApiClient.connect();
    }

    final GoogleApiClient finalMGoogleApiClient = mGoogleApiClient;
    mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            if (finalMGoogleApiClient.isConnected()) {
                Auth.GoogleSignInApi.signOut(finalMGoogleApiClient).setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(@NonNull Status status) {
                        if (status.isSuccess()) {
                            LogUtil.logDebug(TAG, "User Logged out from Google");
                        } else {
                            LogUtil.logDebug(TAG, "Error Logged out from Google");
                        }
                    }
                });
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            LogUtil.logDebug(TAG, "Google API Client Connection Suspended");
        }
    });
}
 
Example 2
Source File: LogoutHelper.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
private static void logoutGoogle(GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    if (mGoogleApiClient == null) {
        mGoogleApiClient = GoogleApiHelper.createGoogleApiClient(fragmentActivity);
    }

    if (!mGoogleApiClient.isConnected()) {
        mGoogleApiClient.connect();
    }

    final GoogleApiClient finalMGoogleApiClient = mGoogleApiClient;
    mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            if (finalMGoogleApiClient.isConnected()) {
                Auth.GoogleSignInApi.signOut(finalMGoogleApiClient).setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(@NonNull Status status) {
                        if (status.isSuccess()) {
                            LogUtil.logDebug(TAG, "User Logged out from Google");
                        } else {
                            LogUtil.logDebug(TAG, "Error Logged out from Google");
                        }
                    }
                });
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            LogUtil.logDebug(TAG, "Google API Client Connection Suspended");
        }
    });
}
 
Example 3
Source File: RobocarAdvertiser.java    From robocar with Apache License 2.0 5 votes vote down vote up
public RobocarAdvertiser(GoogleApiClient client) {
    super(client);
    client.registerConnectionCallbacks(this);

    mAdvertisingLiveData = new MutableLiveData<>();
    mAdvertisingLiveData.setValue(false);
    mCompanionConnectionLiveData = new MutableLiveData<>();
}
 
Example 4
Source File: RobocarDiscoverer.java    From robocar with Apache License 2.0 5 votes vote down vote up
public RobocarDiscoverer(GoogleApiClient client) {
    super(client);
    client.registerConnectionCallbacks(this);

    mDiscoveryLiveData = new MutableLiveData<>();
    mDiscoveryLiveData.setValue(false);
    mRobocarEndpointsLiveData = new MutableLiveData<>();
    mRobocarConnectionLiveData = new MutableLiveData<>();
}