use of com.google.android.gms.common.ConnectionResult 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.ConnectionResult in project Pokemap by omkarmoghe.
the class MapWrapperFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
locationManager = LocationManager.getInstance(getContext());
nianticManager = NianticManager.getInstance();
locationManager.register(new LocationManager.Listener() {
@Override
public void onLocationChanged(Location location) {
if (mLocation == null) {
mLocation = location;
initMap(true, true);
} else {
mLocation = location;
}
}
@Override
public void onLocationFetchFailed(@Nullable ConnectionResult connectionResult) {
showLocationFetchFailed();
}
});
// Inflate the layout for this fragment if the view is not null
if (mView == null)
mView = inflater.inflate(R.layout.fragment_map_wrapper, container, false);
else {
}
// build the map
if (mSupportMapFragment == null) {
mSupportMapFragment = SupportMapFragment.newInstance();
getChildFragmentManager().beginTransaction().replace(R.id.map, mSupportMapFragment).commit();
mSupportMapFragment.setRetainInstance(true);
}
if (mGoogleMap == null) {
mSupportMapFragment.getMapAsync(this);
}
FloatingActionButton locationFab = (FloatingActionButton) mView.findViewById(R.id.location_fab);
locationFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mLocation != null && mGoogleMap != null) {
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLocation.getLatitude(), mLocation.getLongitude()), 15));
} else {
showLocationFetchFailed();
}
}
});
mView.findViewById(R.id.closeSuggestions).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
hideMapSuggestion();
}
});
if (!mPref.getShowMapSuggestion()) {
hideMapSuggestion();
}
return mView;
}
use of com.google.android.gms.common.ConnectionResult 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.ConnectionResult 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.ConnectionResult 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