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]
}
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);
}
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);
}
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;
}
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();
}
}
}));
}
Aggregations