Search in sources :

Example 6 with RemoteInput

use of android.support.v4.app.RemoteInput 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)

Example 7 with RemoteInput

use of android.support.v4.app.RemoteInput in project cw-omnibus by commonsguy.

the class RemoteInputReceiver method buildNotification.

static NotificationCompat.Builder buildNotification(Context ctxt) {
    Intent i = new Intent(ctxt, RemoteInputReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    RemoteInput remoteInput = new RemoteInput.Builder(RemoteInputReceiver.EXTRA_INPUT).setLabel(ctxt.getString(R.string.talk)).build();
    NotificationCompat.Action remoteAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_btn_speak_now, ctxt.getString(R.string.talk), pi).addRemoteInput(remoteInput).build();
    NotificationCompat.MessagingStyle style = new NotificationCompat.MessagingStyle("Me").setConversationTitle("A Fake Chat");
    style.addMessage("Want to chat?", INITIAL_TIMESTAMP, "Somebody");
    for (Message msg : MESSAGES) {
        style.addMessage(msg.text, msg.timestamp, style.getUserDisplayName());
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctxt).setSmallIcon(android.R.drawable.stat_sys_download_done).setContentTitle(ctxt.getString(R.string.title)).setStyle(style).addAction(remoteAction);
    return (builder);
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 8 with RemoteInput

use of android.support.v4.app.RemoteInput in project Talon-for-Twitter by klinker24.

the class NotificationUtils method refreshNotification.

public static void refreshNotification(Context context, boolean noTimeline) {
    AppSettings settings = AppSettings.getInstance(context);
    SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    int currentAccount = sharedPrefs.getInt("current_account", 1);
    //int[] unreadCounts = new int[] {4, 1, 2}; // for testing
    int[] unreadCounts = getUnreads(context);
    int timeline = unreadCounts[0];
    int realTimelineCount = timeline;
    // if they don't want that type of notification, simply set it to zero
    if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) {
        unreadCounts[0] = 0;
    }
    if (!settings.mentionsNot) {
        unreadCounts[1] = 0;
    }
    if (!settings.dmsNot) {
        unreadCounts[2] = 0;
    }
    if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) {
    } else {
        Intent markRead = new Intent(context, MarkReadService.class);
        PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);
        String shortText = getShortText(unreadCounts, context, currentAccount);
        String longText = getLongText(unreadCounts, context, currentAccount);
        // [0] is the full title and [1] is the screenname
        String[] title = getTitle(unreadCounts, context, currentAccount);
        boolean useExpanded = useExp(context);
        boolean addButton = addBtn(unreadCounts);
        if (title == null) {
            return;
        }
        Intent resultIntent;
        if (unreadCounts[1] != 0 && unreadCounts[0] == 0) {
            // it is a mention notification (could also have a direct message)
            resultIntent = new Intent(context, RedirectToMentions.class);
        } else if (unreadCounts[2] != 0 && unreadCounts[0] == 0 && unreadCounts[1] == 0) {
            // it is a direct message
            resultIntent = new Intent(context, RedirectToDMs.class);
        } else {
            resultIntent = new Intent(context, MainActivity.class);
        }
        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
        NotificationCompat.Builder mBuilder;
        Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);
        mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0]).setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)).setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1])).setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(TweetLinkUtils.removeColorHtml(shortText, settings)).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setPriority(NotificationCompat.PRIORITY_HIGH);
        if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) {
            // inbox style notification for mentions
            mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) {
            // inbox style notification for direct messages
            mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else {
            // big text style for an unread count on timeline, mentions, and direct messages
            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)));
        }
        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title[0], shortText);
        }
        // Light Flow notification
        sendToLightFlow(context, title[0], shortText);
        int homeTweets = unreadCounts[0];
        int mentionsTweets = unreadCounts[1];
        int dmTweets = unreadCounts[2];
        int newC = 0;
        if (homeTweets > 0) {
            newC++;
        }
        if (mentionsTweets > 0) {
            newC++;
        }
        if (dmTweets > 0) {
            newC++;
        }
        if (settings.notifications && newC > 0) {
            if (settings.vibrate) {
                mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
            }
            if (settings.sound) {
                try {
                    mBuilder.setSound(Uri.parse(settings.ringtone));
                } catch (Exception e) {
                    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                }
            }
            if (settings.led)
                mBuilder.setLights(0xFFFFFF, 1000, 1000);
            // Get an instance of the NotificationManager service
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
            if (addButton) {
                // the reply and read button should be shown
                Intent reply;
                if (unreadCounts[1] == 1) {
                    reply = new Intent(context, NotificationCompose.class);
                } else {
                    reply = new Intent(context, NotificationDMCompose.class);
                }
                Log.v("username_for_noti", title[1]);
                sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit();
                MentionsDataSource data = MentionsDataSource.getInstance(context);
                long id = data.getLastIds(currentAccount)[0];
                PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);
                sharedPrefs.edit().putLong("from_notification_long", id).commit();
                sharedPrefs.edit().putString("from_notification_text", "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings)).commit();
                // Create the remote input
                RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + title[1] + " ").build();
                // Create the notification action
                NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build();
                NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending);
                mBuilder.addAction(replyAction);
                mBuilder.addAction(action.build());
            } else {
                // otherwise, if they can use the expanded notifications, the popup button will be shown
                Intent popup = new Intent(context, RedirectToPopup.class);
                popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                popup.putExtra("from_notification", true);
                PendingIntent popupPending = PendingIntent.getActivity(context, 0, popup, 0);
                NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(R.drawable.ic_popup, context.getResources().getString(R.string.popup), popupPending);
                mBuilder.addAction(action.build());
            }
            // Build the notification and issues it with notification manager.
            notificationManager.notify(1, mBuilder.build());
            // if we want to wake the screen on a new message
            if (settings.wakeScreen) {
                PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
                wakeLock.acquire(5000);
            }
        }
        // if there are unread tweets on the timeline, check them for favorite users
        if (settings.favoriteUserNotifications && realTimelineCount > 0) {
            favUsersNotification(currentAccount, context);
        }
    }
    try {
        ContentValues cv = new ContentValues();
        cv.put("tag", "com.klinker.android.twitter/com.klinker.android.twitter.ui.MainActivity");
        // add the direct messages and mentions
        cv.put("count", unreadCounts[1] + unreadCounts[2]);
        context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);
    } catch (IllegalArgumentException ex) {
    /* Fine, TeslaUnread is not installed. */
    } catch (Exception ex) {
        /* Some other error, possibly because the format
               of the ContentValues are incorrect.

                Log but do not crash over this. */
        ex.printStackTrace();
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) PowerManager(android.os.PowerManager) NotificationCompat(android.support.v4.app.NotificationCompat) RedirectToMentions(com.klinker.android.twitter.utils.redirects.RedirectToMentions) ContentValues(android.content.ContentValues) RemoteInput(android.support.v4.app.RemoteInput) NotificationCompose(com.klinker.android.twitter.activities.compose.NotificationCompose) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) NotificationDMCompose(com.klinker.android.twitter.activities.compose.NotificationDMCompose) PendingIntent(android.app.PendingIntent)

Example 9 with RemoteInput

use of android.support.v4.app.RemoteInput in project Talon-for-Twitter by klinker24.

the class NotificationUtils method notifySecondMentions.

public static void notifySecondMentions(Context context, int secondAccount) {
    MentionsDataSource data = MentionsDataSource.getInstance(context);
    int numberNew = data.getUnreadCount(secondAccount);
    int smallIcon = R.drawable.ic_stat_icon;
    Bitmap largeIcon;
    Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
    NotificationCompat.Builder mBuilder;
    String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc);
    ;
    String name = null;
    String message;
    String messageLong;
    String tweetText = null;
    NotificationCompat.Action replyAction = null;
    if (numberNew == 1) {
        name = data.getNewestName(secondAccount);
        SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
        // then just quit
        if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) {
            return;
        }
        message = context.getResources().getString(R.string.mentioned_by) + " @" + name;
        tweetText = data.getNewestMessage(secondAccount);
        messageLong = "<b>@" + name + "</b>: " + tweetText;
        largeIcon = getImage(context, name);
        Intent reply = new Intent(context, NotificationComposeSecondAcc.class);
        sharedPrefs.edit().putString("from_notification_second", "@" + name).commit();
        long id = data.getLastIds(secondAccount)[0];
        PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);
        sharedPrefs.edit().putLong("from_notification_long_second", id).commit();
        sharedPrefs.edit().putString("from_notification_text_second", "@" + name + ": " + TweetLinkUtils.removeColorHtml(tweetText, AppSettings.getInstance(context))).commit();
        // Create the remote input
        RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + name + " ").build();
        // Create the notification action
        replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build();
    } else {
        // more than one mention
        message = numberNew + " " + context.getResources().getString(R.string.new_mentions);
        messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions);
        largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
    }
    Intent markRead = new Intent(context, MarkReadSecondAccService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);
    AppSettings settings = AppSettings.getInstance(context);
    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class);
    mBuilder = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon).setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setPriority(NotificationCompat.PRIORITY_HIGH);
    if (numberNew == 1) {
        mBuilder.addAction(replyAction);
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong)));
    } else {
        NotificationCompat.InboxStyle inbox = getMentionsInboxStyle(numberNew, secondAccount, context, TweetLinkUtils.removeColorHtml(message, settings));
        mBuilder.setStyle(inbox);
    }
    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }
    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);
    if (settings.notifications) {
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        notificationManager.notify(9, mBuilder.build());
        // if we want to wake the screen on a new message
        if (settings.wakeScreen) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
            wakeLock.acquire(5000);
        }
        // Pebble notification
        if (context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0).getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title, messageLong);
        }
        // Light Flow notification
        sendToLightFlow(context, title, messageLong);
    }
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) AppSettings(com.klinker.android.twitter.settings.AppSettings) SharedPreferences(android.content.SharedPreferences) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PowerManager(android.os.PowerManager) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 10 with RemoteInput

use of android.support.v4.app.RemoteInput in project muzei by romannurik.

the class NewWallpaperNotificationReceiver method maybeShowNewArtworkNotification.

public static void maybeShowNewArtworkNotification(Context context) {
    ArtDetailOpenedClosedEvent adoce = EventBus.getDefault().getStickyEvent(ArtDetailOpenedClosedEvent.class);
    if (adoce != null && adoce.isArtDetailOpened()) {
        return;
    }
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    if (!sp.getBoolean(PREF_ENABLED, true)) {
        return;
    }
    ContentResolver contentResolver = context.getContentResolver();
    Cursor artwork = contentResolver.query(MuzeiContract.Artwork.CONTENT_URI, new String[] { BaseColumns._ID, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, MuzeiContract.Artwork.COLUMN_NAME_TOKEN, MuzeiContract.Artwork.COLUMN_NAME_TITLE, MuzeiContract.Artwork.COLUMN_NAME_BYLINE, MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT, MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND, MuzeiContract.Sources.COLUMN_NAME_COMMANDS }, null, null, null);
    if (artwork == null || !artwork.moveToFirst()) {
        if (artwork != null) {
            artwork.close();
        }
        return;
    }
    long currentArtworkId = artwork.getLong(artwork.getColumnIndex(BaseColumns._ID));
    long lastReadArtworkId = sp.getLong(PREF_LAST_READ_NOTIFICATION_ARTWORK_ID, -1);
    String currentImageUri = artwork.getString(artwork.getColumnIndex(MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI));
    String lastReadImageUri = sp.getString(PREF_LAST_READ_NOTIFICATION_ARTWORK_IMAGE_URI, null);
    String currentToken = artwork.getString(artwork.getColumnIndex(MuzeiContract.Artwork.COLUMN_NAME_TOKEN));
    String lastReadToken = sp.getString(PREF_LAST_READ_NOTIFICATION_ARTWORK_TOKEN, null);
    // We've already dismissed the notification if the IDs match
    boolean previouslyDismissedNotification = lastReadArtworkId == currentArtworkId;
    // We've already dismissed the notification if the image URIs match and both are not empty
    previouslyDismissedNotification = previouslyDismissedNotification || (!TextUtils.isEmpty(lastReadImageUri) && !TextUtils.isEmpty(currentImageUri) && TextUtils.equals(lastReadImageUri, currentImageUri));
    // We've already dismissed the notification if the tokens match and both are not empty
    previouslyDismissedNotification = previouslyDismissedNotification || (!TextUtils.isEmpty(lastReadToken) && !TextUtils.isEmpty(currentToken) && TextUtils.equals(lastReadToken, currentToken));
    if (previouslyDismissedNotification) {
        artwork.close();
        return;
    }
    Bitmap largeIcon;
    Bitmap background;
    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(contentResolver.openInputStream(MuzeiContract.Artwork.CONTENT_URI), null, options);
        int width = options.outWidth;
        int height = options.outHeight;
        int shortestLength = Math.min(width, height);
        options.inJustDecodeBounds = false;
        int largeIconHeight = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
        options.inSampleSize = ImageUtil.calculateSampleSize(shortestLength, largeIconHeight);
        largeIcon = BitmapFactory.decodeStream(contentResolver.openInputStream(MuzeiContract.Artwork.CONTENT_URI), null, options);
        // Use the suggested 400x400 for Android Wear background images per
        // http://developer.android.com/training/wearables/notifications/creating.html#AddWearableFeatures
        options.inSampleSize = ImageUtil.calculateSampleSize(height, 400);
        background = BitmapFactory.decodeStream(contentResolver.openInputStream(MuzeiContract.Artwork.CONTENT_URI), null, options);
    } catch (FileNotFoundException e) {
        Log.e(TAG, "Unable to read artwork to show notification", e);
        return;
    }
    String artworkTitle = artwork.getString(artwork.getColumnIndex(MuzeiContract.Artwork.COLUMN_NAME_TITLE));
    String title = TextUtils.isEmpty(artworkTitle) ? context.getString(R.string.app_name) : artworkTitle;
    NotificationCompat.Builder nb = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_stat_muzei).setColor(ContextCompat.getColor(context, R.color.notification)).setPriority(Notification.PRIORITY_MIN).setAutoCancel(true).setContentTitle(title).setContentText(context.getString(R.string.notification_new_wallpaper)).setLargeIcon(largeIcon).setContentIntent(PendingIntent.getActivity(context, 0, Intent.makeMainActivity(new ComponentName(context, MuzeiActivity.class)), PendingIntent.FLAG_UPDATE_CURRENT)).setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(context, NewWallpaperNotificationReceiver.class).setAction(ACTION_MARK_NOTIFICATION_READ), PendingIntent.FLAG_UPDATE_CURRENT));
    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle().bigLargeIcon(null).setBigContentTitle(title).setSummaryText(artwork.getString(artwork.getColumnIndex(MuzeiContract.Artwork.COLUMN_NAME_BYLINE))).bigPicture(background);
    nb.setStyle(style);
    NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
    // Support Next Artwork
    if (artwork.getInt(artwork.getColumnIndex(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND)) != 0) {
        PendingIntent nextPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(context, NewWallpaperNotificationReceiver.class).setAction(ACTION_NEXT_ARTWORK), PendingIntent.FLAG_UPDATE_CURRENT);
        nb.addAction(R.drawable.ic_notif_next_artwork, context.getString(R.string.action_next_artwork_condensed), nextPendingIntent);
        // Android Wear uses larger action icons so we build a
        // separate action
        extender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_notif_full_next_artwork, context.getString(R.string.action_next_artwork_condensed), nextPendingIntent).extend(new NotificationCompat.Action.WearableExtender().setAvailableOffline(false)).build());
    }
    List<UserCommand> commands = MuzeiContract.Sources.parseCommands(artwork.getString(artwork.getColumnIndex(MuzeiContract.Sources.COLUMN_NAME_COMMANDS)));
    // Show custom actions as a selectable list on Android Wear devices
    if (!commands.isEmpty()) {
        String[] actions = new String[commands.size()];
        for (int h = 0; h < commands.size(); h++) {
            actions[h] = commands.get(h).getTitle();
        }
        PendingIntent userCommandPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(context, NewWallpaperNotificationReceiver.class).setAction(ACTION_USER_COMMAND), PendingIntent.FLAG_UPDATE_CURRENT);
        RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_USER_COMMAND).setAllowFreeFormInput(false).setLabel(context.getString(R.string.action_user_command_prompt)).setChoices(actions).build();
        extender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_notif_full_user_command, context.getString(R.string.action_user_command), userCommandPendingIntent).addRemoteInput(remoteInput).extend(new NotificationCompat.Action.WearableExtender().setAvailableOffline(false)).build());
    }
    Intent viewIntent = null;
    try {
        String viewIntentString = artwork.getString(artwork.getColumnIndex(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT));
        if (!TextUtils.isEmpty(viewIntentString)) {
            viewIntent = Intent.parseUri(viewIntentString, Intent.URI_INTENT_SCHEME);
        }
    } catch (URISyntaxException ignored) {
    }
    if (viewIntent != null) {
        viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            PendingIntent nextPendingIntent = PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            nb.addAction(R.drawable.ic_notif_info, context.getString(R.string.action_artwork_info), nextPendingIntent);
            // Android Wear uses larger action icons so we build a
            // separate action
            extender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_notif_full_info, context.getString(R.string.action_artwork_info), nextPendingIntent).extend(new NotificationCompat.Action.WearableExtender().setAvailableOffline(false)).build());
        } catch (RuntimeException ignored) {
        // This is actually meant to catch a FileUriExposedException, but you can't
        // have catch statements for exceptions that don't exist at your minSdkVersion
        }
    }
    nb.extend(extender);
    // Hide the image and artwork title for the public version
    NotificationCompat.Builder publicBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_stat_muzei).setColor(ContextCompat.getColor(context, R.color.notification)).setPriority(Notification.PRIORITY_MIN).setAutoCancel(true).setContentTitle(context.getString(R.string.app_name)).setContentText(context.getString(R.string.notification_new_wallpaper)).setContentIntent(PendingIntent.getActivity(context, 0, Intent.makeMainActivity(new ComponentName(context, MuzeiActivity.class)), PendingIntent.FLAG_UPDATE_CURRENT)).setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(context, NewWallpaperNotificationReceiver.class).setAction(ACTION_MARK_NOTIFICATION_READ), PendingIntent.FLAG_UPDATE_CURRENT));
    nb.setPublicVersion(publicBuilder.build());
    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.notify(NOTIFICATION_ID, nb.build());
    artwork.close();
}
Also used : FileNotFoundException(java.io.FileNotFoundException) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) URISyntaxException(java.net.URISyntaxException) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) ComponentName(android.content.ComponentName) BitmapFactory(android.graphics.BitmapFactory) RemoteInput(android.support.v4.app.RemoteInput) SharedPreferences(android.content.SharedPreferences) ArtDetailOpenedClosedEvent(com.google.android.apps.muzei.event.ArtDetailOpenedClosedEvent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) UserCommand(com.google.android.apps.muzei.api.UserCommand) PendingIntent(android.app.PendingIntent)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)13 RemoteInput (android.support.v4.app.RemoteInput)13 PendingIntent (android.app.PendingIntent)11 Intent (android.content.Intent)11 SharedPreferences (android.content.SharedPreferences)5 NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)4 PowerManager (android.os.PowerManager)3 AppSettings (com.klinker.android.twitter.settings.AppSettings)3 ArrayList (java.util.ArrayList)3 Bitmap (android.graphics.Bitmap)2 Random (java.util.Random)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 NotificationManager (android.app.NotificationManager)1 ComponentName (android.content.ComponentName)1 ContentResolver (android.content.ContentResolver)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1