use of com.google.android.gms.common.api.GoogleApiClient in project SeriesGuide by UweTrottmann.
the class HexagonTools method checkSignInState.
private void checkSignInState() {
if (credential.getSelectedAccount() != null && !isTimeForSignInStateCheck()) {
Timber.d("%s: just checked state, skip", ACTION_SILENT_SIGN_IN);
}
lastSignInCheck = SystemClock.elapsedRealtime();
if (googleApiClient == null) {
googleApiClient = new GoogleApiClient.Builder(app).addApi(Auth.GOOGLE_SIGN_IN_API, getGoogleSignInOptions()).build();
}
android.accounts.Account account = null;
ConnectionResult connectionResult = googleApiClient.blockingConnect();
if (connectionResult.isSuccess()) {
OptionalPendingResult<GoogleSignInResult> pendingResult = Auth.GoogleSignInApi.silentSignIn(googleApiClient);
GoogleSignInResult result = pendingResult.await();
if (result.isSuccess()) {
GoogleSignInAccount signInAccount = result.getSignInAccount();
if (signInAccount != null) {
Timber.i("%s: successful", ACTION_SILENT_SIGN_IN);
account = signInAccount.getAccount();
credential.setSelectedAccount(account);
} else {
trackSignInFailure(ACTION_SILENT_SIGN_IN, "GoogleSignInAccount is null");
}
} else {
trackSignInFailure(ACTION_SILENT_SIGN_IN, result.getStatus());
}
googleApiClient.disconnect();
} else {
trackSignInFailure(ACTION_SILENT_SIGN_IN, connectionResult);
}
boolean shouldFixAccount = account == null;
PreferenceManager.getDefaultSharedPreferences(app).edit().putBoolean(HexagonSettings.KEY_SHOULD_VALIDATE_ACCOUNT, shouldFixAccount).apply();
}
use of com.google.android.gms.common.api.GoogleApiClient in project muzei by romannurik.
the class ArtworkCacheIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient: " + connectionResult.getErrorCode());
return;
}
// Read all DataItems
DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await();
if (!dataItemBuffer.getStatus().isSuccess()) {
Log.e(TAG, "Error getting all data items: " + dataItemBuffer.getStatus().getStatusMessage());
}
Iterator<DataItem> dataItemIterator = dataItemBuffer.singleRefIterator();
boolean foundArtwork = false;
while (dataItemIterator.hasNext()) {
DataItem dataItem = dataItemIterator.next();
foundArtwork = foundArtwork || processDataItem(googleApiClient, dataItem);
}
dataItemBuffer.release();
if (foundArtwork) {
// Enable the Full Screen Activity and Artwork Complication Provider Service only if we've found artwork
enableComponents(FullScreenActivity.class, ArtworkComplicationProviderService.class);
}
if (!foundArtwork && intent != null && intent.getBooleanExtra(SHOW_ACTIVATE_NOTIFICATION_EXTRA, false)) {
ActivateMuzeiIntentService.maybeShowActivateMuzeiNotification(this);
} else {
ActivateMuzeiIntentService.clearNotifications(this);
}
googleApiClient.disconnect();
}
use of com.google.android.gms.common.api.GoogleApiClient in project muzei by romannurik.
the class WearableController method updateArtwork.
public static synchronized void updateArtwork(Context context) {
if (ConnectionResult.SUCCESS != GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)) {
return;
}
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(5, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
if (connectionResult.getErrorCode() != ConnectionResult.API_UNAVAILABLE) {
Log.w(TAG, "onConnectionFailed: " + connectionResult);
}
return;
}
ContentResolver contentResolver = context.getContentResolver();
Bitmap image = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(contentResolver.openInputStream(MuzeiContract.Artwork.CONTENT_URI), null, options);
options.inJustDecodeBounds = false;
if (options.outWidth > options.outHeight) {
options.inSampleSize = ImageUtil.calculateSampleSize(options.outHeight, 320);
} else {
options.inSampleSize = ImageUtil.calculateSampleSize(options.outWidth, 320);
}
image = BitmapFactory.decodeStream(contentResolver.openInputStream(MuzeiContract.Artwork.CONTENT_URI), null, options);
} catch (FileNotFoundException e) {
Log.e(TAG, "Unable to read artwork to update Android Wear", e);
}
if (image != null) {
int rotation = getRotation(context);
if (rotation != 0) {
// Rotate the image so that Wear always gets a right side up image
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
image = Bitmap.createBitmap(image, 0, 0, image.getWidth(), image.getHeight(), matrix, true);
}
final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, byteStream);
Asset asset = Asset.createFromBytes(byteStream.toByteArray());
PutDataMapRequest dataMapRequest = PutDataMapRequest.create("/artwork");
Artwork artwork = MuzeiContract.Artwork.getCurrentArtwork(context);
dataMapRequest.getDataMap().putDataMap("artwork", DataMap.fromBundle(artwork.toBundle()));
dataMapRequest.getDataMap().putAsset("image", asset);
Wearable.DataApi.putDataItem(googleApiClient, dataMapRequest.asPutDataRequest().setUrgent()).await();
}
googleApiClient.disconnect();
}
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 GoogleApiClientTaskHelper method getConnectedGoogleApiClient.
public Task<GoogleApiClient> getConnectedGoogleApiClient() {
final TaskCompletionSource<GoogleApiClient> source = new TaskCompletionSource<>();
if (!mConnectTaskRef.compareAndSet(null, source)) {
// mConnectTaskRef Task was not null, return Task
return mConnectTaskRef.get().getTask();
}
final GoogleApiClient client = mBuilder.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
source.setResult(mClientRef.get());
if (mClientRef.get() != null) {
mClientRef.get().unregisterConnectionCallbacks(this);
}
}
@Override
public void onConnectionSuspended(int i) {
}
}).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
source.setException(new IOException("Failed to connect GoogleApiClient: " + connectionResult.getErrorMessage()));
if (mClientRef.get() != null) {
mClientRef.get().unregisterConnectionFailedListener(this);
}
}
}).build();
mClientRef.set(client);
client.connect();
return source.getTask();
}
Aggregations