Search in sources :

Example 6 with WearableExtender

use of android.support.v4.app.NotificationCompat.WearableExtender in project SeriesGuide by UweTrottmann.

the class NotificationService method maybeSetPoster.

private void maybeSetPoster(NotificationCompat.Builder nb, String posterPath) {
    try {
        Bitmap poster = ServiceUtils.loadWithPicasso(this, TvdbImageTools.smallSizeUrl(posterPath)).centerCrop().resizeDimen(R.dimen.show_poster_width, R.dimen.show_poster_height).get();
        nb.setLargeIcon(poster);
        // add special large resolution background for wearables
        // https://developer.android.com/training/wearables/notifications/creating.html#AddWearableFeatures
        Bitmap posterSquare = ServiceUtils.loadWithPicasso(this, TvdbImageTools.fullSizeUrl(posterPath)).centerCrop().resize(400, 400).get();
        NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().setBackground(posterSquare);
        nb.extend(wearableExtender);
    } catch (IOException e) {
        Timber.e(e, "maybeSetPoster: failed.");
    }
}
Also used : Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) IOException(java.io.IOException)

Example 7 with WearableExtender

use of android.support.v4.app.NotificationCompat.WearableExtender in project k-9 by k9mail.

the class WearNotifications method addMarkAsSpamAction.

private void addMarkAsSpamAction(WearableExtender wearableExtender, NotificationHolder holder) {
    int icon = R.drawable.ic_action_spam_dark;
    String title = context.getString(R.string.notification_action_spam);
    MessageReference messageReference = holder.content.messageReference;
    int notificationId = holder.notificationId;
    PendingIntent action = actionCreator.createMarkMessageAsSpamPendingIntent(messageReference, notificationId);
    NotificationCompat.Action spamAction = new NotificationCompat.Action.Builder(icon, title, action).build();
    wearableExtender.addAction(spamAction);
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) MessageReference(com.fsck.k9.activity.MessageReference)

Example 8 with WearableExtender

use of android.support.v4.app.NotificationCompat.WearableExtender in project phonegap-plugin-push by phonegap.

the class GCMIntentService method createActions.

private void createActions(Bundle extras, NotificationCompat.Builder mBuilder, Resources resources, String packageName, int notId) {
    Log.d(LOG_TAG, "create actions: with in-line");
    String actions = extras.getString(ACTIONS);
    if (actions != null) {
        try {
            JSONArray actionsArray = new JSONArray(actions);
            ArrayList<NotificationCompat.Action> wActions = new ArrayList<NotificationCompat.Action>();
            for (int i = 0; i < actionsArray.length(); i++) {
                int min = 1;
                int max = 2000000000;
                Random random = new Random();
                int uniquePendingIntentRequestCode = random.nextInt((max - min) + 1) + min;
                Log.d(LOG_TAG, "adding action");
                JSONObject action = actionsArray.getJSONObject(i);
                Log.d(LOG_TAG, "adding callback = " + action.getString(CALLBACK));
                boolean foreground = action.optBoolean(FOREGROUND, true);
                boolean inline = action.optBoolean("inline", false);
                Intent intent = null;
                PendingIntent pIntent = null;
                if (inline) {
                    Log.d(LOG_TAG, "Version: " + android.os.Build.VERSION.SDK_INT + " = " + android.os.Build.VERSION_CODES.M);
                    if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) {
                        Log.d(LOG_TAG, "push activity");
                        intent = new Intent(this, PushHandlerActivity.class);
                    } else {
                        Log.d(LOG_TAG, "push receiver");
                        intent = new Intent(this, BackgroundActionButtonHandler.class);
                    }
                    updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
                    if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) {
                        Log.d(LOG_TAG, "push activity for notId " + notId);
                        pIntent = PendingIntent.getActivity(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT);
                    } else {
                        Log.d(LOG_TAG, "push receiver for notId " + notId);
                        pIntent = PendingIntent.getBroadcast(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT);
                    }
                } else if (foreground) {
                    intent = new Intent(this, PushHandlerActivity.class);
                    updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
                    pIntent = PendingIntent.getActivity(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                } else {
                    intent = new Intent(this, BackgroundActionButtonHandler.class);
                    updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
                    pIntent = PendingIntent.getBroadcast(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                }
                NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), action.getString(TITLE), pIntent);
                RemoteInput remoteInput = null;
                if (inline) {
                    Log.d(LOG_TAG, "create remote input");
                    String replyLabel = "Enter your reply here";
                    remoteInput = new RemoteInput.Builder(INLINE_REPLY).setLabel(replyLabel).build();
                    actionBuilder.addRemoteInput(remoteInput);
                }
                NotificationCompat.Action wAction = actionBuilder.build();
                wActions.add(actionBuilder.build());
                if (inline) {
                    mBuilder.addAction(wAction);
                } else {
                    mBuilder.addAction(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), action.getString(TITLE), pIntent);
                }
                wAction = null;
                pIntent = null;
            }
            mBuilder.extend(new WearableExtender().addActions(wActions));
            wActions.clear();
        } catch (JSONException e) {
        // nope
        }
    }
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) WearableExtender(android.support.v4.app.NotificationCompat.WearableExtender) Random(java.util.Random) JSONObject(org.json.JSONObject) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 9 with WearableExtender

use of android.support.v4.app.NotificationCompat.WearableExtender in project RSAndroidApp by RailwayStations.

the class NearbyBahnhofWithPhotoNotificationManager method onBitmapAvailable.

/**
     * This gets called if the requested bitmap is available. Finish and issue the notification.
     *
     * @param bitmap the fetched Bitmap for the notification. May be null
     */
@Override
public void onBitmapAvailable(@Nullable Bitmap bitmap) {
    if (context == null) {
        // we're already destroyed
        return;
    }
    if (bitmap == null) {
        bitmap = getBitmapFromResource(R.drawable.ic_stations_with_photo);
    }
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    if (fetchTask != null) {
        bigPictureStyle.bigPicture(bitmap).setBigContentTitle(null).setSummaryText(fetchTask.getLicense());
    }
    Notification fullImagePage = new NotificationCompat.Builder(context).setStyle(bigPictureStyle).extend(new NotificationCompat.WearableExtender().setHintShowBackgroundOnly(true).setHintScreenTimeout(NotificationCompat.WearableExtender.SCREEN_TIMEOUT_LONG)).build();
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().setHintHideIcon(true).setBackground(bitmap).addPage(fullImagePage);
    NotificationCompat.Builder notificationBuilder = getBasicNotificationBuilder();
    // apply our specifics
    notificationBuilder.extend(wearableExtender).setVibrate(VIBRATION_PATTERN).setColor(LED_COLOR);
    // ...and we're done!
    onNotificationReady(notificationBuilder.build());
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification)

Example 10 with WearableExtender

use of android.support.v4.app.NotificationCompat.WearableExtender in project Gadgetbridge by Freeyourgadget.

the class DebugActivity method testNotification.

private void testNotification() {
    Intent notificationIntent = new Intent(getApplicationContext(), DebugActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
    NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_REPLY).build();
    Intent replyIntent = new Intent(ACTION_REPLY);
    PendingIntent replyPendingIntent = PendingIntent.getBroadcast(this, 0, replyIntent, 0);
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(android.R.drawable.ic_input_add, "Reply", replyPendingIntent).addRemoteInput(remoteInput).build();
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().addAction(action);
    NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.test_notification)).setContentText(getString(R.string.this_is_a_test_notification_from_gadgetbridge)).setTicker(getString(R.string.this_is_a_test_notification_from_gadgetbridge)).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(pendingIntent).extend(wearableExtender);
    nManager.notify((int) System.currentTimeMillis(), ncomp.build());
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)17 PendingIntent (android.app.PendingIntent)12 MessageReference (com.fsck.k9.activity.MessageReference)8 Intent (android.content.Intent)4 WearableExtender (android.support.v4.app.NotificationCompat.WearableExtender)4 Account (com.fsck.k9.Account)4 Notification (android.app.Notification)3 Bitmap (android.graphics.Bitmap)2 RemoteInput (android.support.v4.app.RemoteInput)2 SuppressLint (android.annotation.SuppressLint)1 NotificationManager (android.app.NotificationManager)1 SharedPreferences (android.content.SharedPreferences)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 Paint (android.graphics.Paint)1 PowerManager (android.os.PowerManager)1 NotificationManagerCompat (android.preview.support.v4.app.NotificationManagerCompat)1 StatusBarNotification (android.service.notification.StatusBarNotification)1 BigTextStyle (android.support.v4.app.NotificationCompat.BigTextStyle)1 IOException (java.io.IOException)1