Search in sources :

Example 11 with ConnectionResult

use of com.google.android.gms.common.ConnectionResult 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 12 with ConnectionResult

use of com.google.android.gms.common.ConnectionResult in project muzei by romannurik.

the class ActivateMuzeiIntentService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String action = intent.getAction();
    if (TextUtils.equals(action, ACTION_MARK_NOTIFICATION_READ)) {
        preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
        return;
    } else if (TextUtils.equals(action, ACTION_REMOTE_INSTALL_MUZEI)) {
        Intent remoteIntent = new Intent(Intent.ACTION_VIEW).addCategory(Intent.CATEGORY_BROWSABLE).setData(Uri.parse("market://details?id=" + getPackageName()));
        RemoteIntent.startRemoteActivity(this, remoteIntent, new ResultReceiver(new Handler()) {

            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (resultCode == RemoteIntent.RESULT_OK) {
                    FirebaseAnalytics.getInstance(ActivateMuzeiIntentService.this).logEvent("activate_notif_install_sent", null);
                    preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
                } else {
                    Toast.makeText(ActivateMuzeiIntentService.this, R.string.activate_install_failed, Toast.LENGTH_SHORT).show();
                }
            }
        });
        return;
    }
    // else -> Open on Phone action
    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.");
        Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
        return;
    }
    Set<Node> nodes = Wearable.CapabilityApi.getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_REACHABLE).await().getCapability().getNodes();
    if (nodes.isEmpty()) {
        Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
    } else {
        FirebaseAnalytics.getInstance(this).logEvent("activate_notif_message_sent", null);
        // Show the open on phone animation
        Intent openOnPhoneIntent = new Intent(this, ConfirmationActivity.class);
        openOnPhoneIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        openOnPhoneIntent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION);
        startActivity(openOnPhoneIntent);
        // Clear the notification
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(INSTALL_NOTIFICATION_ID);
        preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
        // Send the message to the phone to open Muzei
        for (Node node : nodes) {
            Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "notification/open", null).await();
        }
    }
    googleApiClient.disconnect();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) ConnectionResult(com.google.android.gms.common.ConnectionResult) Node(com.google.android.gms.wearable.Node) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RemoteIntent(com.google.android.wearable.intent.RemoteIntent) ResultReceiver(android.os.ResultReceiver)

Example 13 with ConnectionResult

use of com.google.android.gms.common.ConnectionResult in project muzei by romannurik.

the class ActivateMuzeiIntentService method maybeShowActivateMuzeiNotification.

public static void maybeShowActivateMuzeiNotification(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    if (preferences.getBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, false)) {
        return;
    }
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    StatusBarNotification[] notifications = notificationManager.getActiveNotifications();
    boolean hasInstallNotification = false;
    boolean hasActivateNotification = false;
    for (StatusBarNotification notification : notifications) {
        if (notification.getId() == INSTALL_NOTIFICATION_ID) {
            hasInstallNotification = true;
        } else if (notification.getId() == ACTIVATE_NOTIFICATION_ID) {
            hasActivateNotification = true;
        }
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(R.drawable.ic_stat_muzei).setColor(ContextCompat.getColor(context, R.color.notification)).setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(NotificationCompat.DEFAULT_VIBRATE).setAutoCancel(true).setContentTitle(context.getString(R.string.activate_title));
    Intent deleteIntent = new Intent(context, ActivateMuzeiIntentService.class);
    deleteIntent.setAction(ACTION_MARK_NOTIFICATION_READ);
    builder.setDeleteIntent(PendingIntent.getService(context, 0, deleteIntent, 0));
    // Check if the Muzei main app is installed
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context).addApi(Wearable.API).build();
    ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
    Set<Node> nodes = new TreeSet<>();
    if (connectionResult.isSuccess()) {
        nodes = Wearable.CapabilityApi.getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_ALL).await().getCapability().getNodes();
        googleApiClient.disconnect();
    }
    if (nodes.isEmpty()) {
        if (hasInstallNotification) {
            // No need to repost the notification
            return;
        }
        // Send an install Muzei notification
        if (PlayStoreAvailability.getPlayStoreAvailabilityOnPhone(context) != PlayStoreAvailability.PLAY_STORE_ON_PHONE_AVAILABLE) {
            builder.setContentText(context.getString(R.string.activate_no_play_store));
            FirebaseAnalytics.getInstance(context).logEvent("activate_notif_no_play_store", null);
        } else {
            builder.setContentText(context.getString(R.string.activate_install_muzei));
            Intent installMuzeiIntent = new Intent(context, ActivateMuzeiIntentService.class);
            installMuzeiIntent.setAction(ACTION_REMOTE_INSTALL_MUZEI);
            PendingIntent pendingIntent = PendingIntent.getService(context, 0, installMuzeiIntent, 0);
            builder.addAction(new NotificationCompat.Action.Builder(R.drawable.open_on_phone, context.getString(R.string.activate_install_action), pendingIntent).extend(new NotificationCompat.Action.WearableExtender().setHintDisplayActionInline(true).setAvailableOffline(false)).build());
            builder.extend(new NotificationCompat.WearableExtender().setContentAction(0));
            FirebaseAnalytics.getInstance(context).logEvent("activate_notif_play_store", null);
        }
        notificationManager.notify(INSTALL_NOTIFICATION_ID, builder.build());
        return;
    }
    // else, Muzei is installed on the phone/tablet, but not activated
    if (hasInstallNotification) {
        // Clear any install Muzei notification
        notificationManager.cancel(INSTALL_NOTIFICATION_ID);
    }
    if (hasActivateNotification) {
        // No need to repost the notification
        return;
    }
    String nodeName = nodes.iterator().next().getDisplayName();
    builder.setContentText(context.getString(R.string.activate_enable_muzei, nodeName));
    Intent launchMuzeiIntent = new Intent(context, ActivateMuzeiIntentService.class);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, launchMuzeiIntent, 0);
    builder.addAction(new NotificationCompat.Action.Builder(R.drawable.open_on_phone, context.getString(R.string.activate_action, nodeName), pendingIntent).extend(new NotificationCompat.Action.WearableExtender().setHintDisplayActionInline(true).setAvailableOffline(false)).build());
    Bitmap background = null;
    try {
        background = BitmapFactory.decodeStream(context.getAssets().open("starrynight.jpg"));
    } catch (IOException e) {
        Log.e(TAG, "Error reading default background asset", e);
    }
    builder.extend(new NotificationCompat.WearableExtender().setContentAction(0).setBackground(background));
    FirebaseAnalytics.getInstance(context).logEvent("activate_notif_installed", null);
    notificationManager.notify(ACTIVATE_NOTIFICATION_ID, builder.build());
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) Node(com.google.android.gms.wearable.Node) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RemoteIntent(com.google.android.wearable.intent.RemoteIntent) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) StatusBarNotification(android.service.notification.StatusBarNotification) TreeSet(java.util.TreeSet) ConnectionResult(com.google.android.gms.common.ConnectionResult) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 14 with ConnectionResult

use of com.google.android.gms.common.ConnectionResult in project ARD by MobileApplicationsClub.

the class AuthHelperGoogleTest method testOnConnectionFailure.

@Test
public void testOnConnectionFailure() throws Exception {
    doCallRealMethod().when(authActivity).onConnectionFailed(new ConnectionResult(ConnectionResult.CANCELED));
    authActivity.onConnectionFailed(new ConnectionResult(ConnectionResult.CANCELED));
    verify(authActivity, times(1)).handleGoogleSignInFailure();
}
Also used : ConnectionResult(com.google.android.gms.common.ConnectionResult) Test(org.junit.Test)

Example 15 with ConnectionResult

use of com.google.android.gms.common.ConnectionResult in project android-wearcamera by dheera.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (D)
        Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    mImageView = (ImageView) findViewById(R.id.imageView);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

        @Override
        public void onConnected(Bundle connectionHint) {
            if (D)
                Log.d(TAG, "onConnected: " + connectionHint);
            findWearableNode();
            Wearable.MessageApi.addListener(mGoogleApiClient, mMessageListener);
        }

        @Override
        public void onConnectionSuspended(int cause) {
            if (D)
                Log.d(TAG, "onConnectionSuspended: " + cause);
        }
    }).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {

        @Override
        public void onConnectionFailed(ConnectionResult result) {
            if (D)
                Log.d(TAG, "onConnectionFailed: " + result);
        }
    }).addApi(Wearable.API).build();
    mGoogleApiClient.connect();
    // slowly subtract from the lag; in case the lag
    // is occurring due to transmission errors
    // this will un-stick the application
    // from a stuck state in which displayFrameLag>6
    // and nothing gets transmitted (therefore nothing
    // else pulls down displayFrameLag to allow transmission
    // again)
    lastMessageTime = System.currentTimeMillis();
    Timer mTimer = new Timer();
    mTimer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            if (displayFrameLag > 1) {
                displayFrameLag--;
            }
            if (displayTimeLag > 1000) {
                displayTimeLag -= 1000;
            }
        }
    }, 0, 1000);
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Bundle(android.os.Bundle) ConnectionResult(com.google.android.gms.common.ConnectionResult)

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