Search in sources :

Example 6 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project google-services by googlesamples.

the class MainActivity method onCreate.

// [END resolution_variables]
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // [START restore_saved_instance_state]
    if (savedInstanceState != null) {
        mIsResolving = savedInstanceState.getBoolean(KEY_IS_RESOLVING);
        mShouldResolve = savedInstanceState.getBoolean(KEY_SHOULD_RESOLVE);
    }
    // [END restore_saved_instance_state]
    // Set up button click listeners
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);
    findViewById(R.id.disconnect_button).setOnClickListener(this);
    // Large sign-in
    ((SignInButton) findViewById(R.id.sign_in_button)).setSize(SignInButton.SIZE_WIDE);
    // Start with sign-in button disabled until sign-in either succeeds or fails
    findViewById(R.id.sign_in_button).setEnabled(false);
    // Set up view instances
    mStatus = (TextView) findViewById(R.id.status);
    // [START create_google_api_client]
    // Build GoogleApiClient with access to basic profile
    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API).addScope(new Scope(Scopes.PROFILE)).addScope(new Scope(Scopes.EMAIL)).build();
// [END create_google_api_client]
}
Also used : SignInButton(com.google.android.gms.common.SignInButton) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Scope(com.google.android.gms.common.api.Scope)

Example 7 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project FirebaseUI-Android by firebase.

the class CheckEmailFragment method getEmailHintIntent.

private PendingIntent getEmailHintIntent() {
    GoogleApiClient client = new GoogleApiClient.Builder(getContext()).addApi(Auth.CREDENTIALS_API).enableAutoManage(getActivity(), GoogleApiHelper.getSafeAutoManageId(), new GoogleApiClient.OnConnectionFailedListener() {

        @Override
        public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
            Log.e(TAG, "Client connection failed: " + connectionResult.getErrorMessage());
        }
    }).build();
    HintRequest hintRequest = new HintRequest.Builder().setHintPickerConfig(new CredentialPickerConfig.Builder().setShowCancelButton(true).build()).setEmailAddressIdentifierSupported(true).build();
    return Auth.CredentialsApi.getHintPickerIntent(client, hintRequest);
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) HintRequest(com.google.android.gms.auth.api.credentials.HintRequest) NonNull(android.support.annotation.NonNull) ConnectionResult(com.google.android.gms.common.ConnectionResult) CredentialPickerConfig(com.google.android.gms.auth.api.credentials.CredentialPickerConfig)

Example 8 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project FirebaseUI-Android by firebase.

the class AuthUI method signOut.

/**
     * Signs the current user out, if one is signed in.
     *
     * @param activity The activity requesting the user be signed out.
     * @return a task which, upon completion, signals that the user has been signed out ({@code
     * result.isSuccess()}, or that the sign-out attempt failed unexpectedly ({@code
     * !result.isSuccess()}).
     * @deprecated use {@link #signOut(FragmentActivity)} instead
     */
@Deprecated
public Task<Void> signOut(@NonNull Activity activity) {
    // Get helper for Google Sign In and Credentials API
    GoogleApiClientTaskHelper taskHelper = GoogleApiClientTaskHelper.getInstance(activity);
    taskHelper.getBuilder().addApi(Auth.CREDENTIALS_API).addApi(Auth.GOOGLE_SIGN_IN_API, GoogleSignInOptions.DEFAULT_SIGN_IN);
    // Get Credentials Helper
    CredentialTaskApi credentialsHelper = CredentialsApiHelper.getInstance(taskHelper);
    // Firebase Sign out
    mAuth.signOut();
    // Disable credentials auto sign-in
    Task<Status> disableCredentialsTask = credentialsHelper.disableAutoSignIn();
    // Google sign out
    Task<Void> googleSignOutTask = taskHelper.getConnectedGoogleApiClient().continueWith(new Continuation<GoogleApiClient, Void>() {

        @Override
        public Void then(@NonNull Task<GoogleApiClient> task) throws Exception {
            if (task.isSuccessful()) {
                Auth.GoogleSignInApi.signOut(task.getResult());
            }
            return null;
        }
    });
    // Facebook sign out
    LoginManager.getInstance().logOut();
    // Wait for all tasks to complete
    return Tasks.whenAll(disableCredentialsTask, googleSignOutTask);
}
Also used : Status(com.google.android.gms.common.api.Status) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) GoogleApiClientTaskHelper(com.firebase.ui.auth.util.GoogleApiClientTaskHelper) CredentialTaskApi(com.firebase.ui.auth.util.CredentialTaskApi)

Example 9 with GoogleApiClient

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

the class BaseObservable method createApiClient.

protected GoogleApiClient createApiClient(Subscriber<? super T> subscriber) {
    ApiClientConnectionCallbacks apiClientConnectionCallbacks = new ApiClientConnectionCallbacks(subscriber);
    GoogleApiClient.Builder apiClientBuilder = new GoogleApiClient.Builder(ctx);
    for (Api<? extends Api.ApiOptions.NotRequiredOptions> service : services) {
        apiClientBuilder.addApi(service);
    }
    apiClientBuilder.addConnectionCallbacks(apiClientConnectionCallbacks);
    apiClientBuilder.addOnConnectionFailedListener(apiClientConnectionCallbacks);
    GoogleApiClient apiClient = apiClientBuilder.build();
    apiClientConnectionCallbacks.setClient(apiClient);
    return apiClient;
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient)

Example 10 with GoogleApiClient

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

the class BaseObservable method call.

@Override
public void call(Subscriber<? super T> subscriber) {
    final GoogleApiClient apiClient = createApiClient(subscriber);
    try {
        apiClient.connect();
    } catch (Throwable ex) {
        subscriber.onError(ex);
    }
    subscriber.add(Subscriptions.create(new Action0() {

        @Override
        public void call() {
            if (apiClient.isConnected() || apiClient.isConnecting()) {
                onUnsubscribed(apiClient);
                apiClient.disconnect();
            }
        }
    }));
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Action0(rx.functions.Action0)

Aggregations

GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)15 ConnectionResult (com.google.android.gms.common.ConnectionResult)8 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 Bitmap (android.graphics.Bitmap)3 Handler (android.os.Handler)3 NotificationManager (android.app.NotificationManager)2 PendingIntent (android.app.PendingIntent)2 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)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 IOException (java.io.IOException)2 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 BitmapFactory (android.graphics.BitmapFactory)1 Matrix (android.graphics.Matrix)1 Geocoder (android.location.Geocoder)1 HandlerThread (android.os.HandlerThread)1