Search in sources :

Example 1 with ConnectionResult

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();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ConnectionResult(com.google.android.gms.common.ConnectionResult) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult)

Example 2 with ConnectionResult

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;
}
Also used : LocationManager(com.omkarmoghe.pokemap.controllers.map.LocationManager) ConnectionResult(com.google.android.gms.common.ConnectionResult) FloatingActionButton(android.support.design.widget.FloatingActionButton) LatLng(com.google.android.gms.maps.model.LatLng) View(android.view.View) Location(android.location.Location)

Example 3 with ConnectionResult

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();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) DataItem(com.google.android.gms.wearable.DataItem) ConnectionResult(com.google.android.gms.common.ConnectionResult) DataItemBuffer(com.google.android.gms.wearable.DataItemBuffer)

Example 4 with ConnectionResult

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();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Artwork(com.google.android.apps.muzei.api.Artwork) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ContentResolver(android.content.ContentResolver) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ConnectionResult(com.google.android.gms.common.ConnectionResult) Asset(com.google.android.gms.wearable.Asset) BitmapFactory(android.graphics.BitmapFactory) PutDataMapRequest(com.google.android.gms.wearable.PutDataMapRequest)

Example 5 with ConnectionResult

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();
}
Also used : TaskCompletionSource(com.google.android.gms.tasks.TaskCompletionSource) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Bundle(android.os.Bundle) NonNull(android.support.annotation.NonNull) ConnectionResult(com.google.android.gms.common.ConnectionResult) IOException(java.io.IOException)

Aggregations

ConnectionResult (com.google.android.gms.common.ConnectionResult)16 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)12 Bundle (android.os.Bundle)6 Intent (android.content.Intent)4 SharedPreferences (android.content.SharedPreferences)4 NonNull (android.support.annotation.NonNull)4 Bitmap (android.graphics.Bitmap)3 NotificationManager (android.app.NotificationManager)2 PendingIntent (android.app.PendingIntent)2 Handler (android.os.Handler)2 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)2 ConnectionCallbacks (com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks)2 OnConnectionFailedListener (com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener)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 SuppressLint (android.annotation.SuppressLint)1 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 BitmapFactory (android.graphics.BitmapFactory)1