Search in sources :

Example 21 with NotificationManagerCompat

use of android.preview.support.v4.app.NotificationManagerCompat in project WordPress-Android by wordpress-mobile.

the class GCMMessageService method remove2FANotification.

public static synchronized void remove2FANotification(Context context) {
    if (context == null || !hasNotifications()) {
        return;
    }
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.cancel(AUTH_PUSH_NOTIFICATION_ID);
    sActiveNotificationsMap.remove(AUTH_PUSH_NOTIFICATION_ID);
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat)

Example 22 with NotificationManagerCompat

use of android.preview.support.v4.app.NotificationManagerCompat in project WordPress-Android by wordpress-mobile.

the class NativeNotificationsUtils method dismissNotification.

public static void dismissNotification(int pushId, Context context) {
    if (context != null) {
        final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        notificationManager.cancel(pushId);
    }
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat)

Example 23 with NotificationManagerCompat

use of android.preview.support.v4.app.NotificationManagerCompat in project materialistic by hidroh.

the class FavoriteManager method notifyExportDone.

private void notifyExportDone(Context context, Uri uri) {
    NotificationManagerCompat manager = NotificationManagerCompat.from(context);
    manager.cancel(mNotificationId);
    if (uri == null) {
        return;
    }
    context.grantUriPermission(context.getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
    manager.notify(mNotificationId, createNotificationBuilder(context).setContentText(context.getString(R.string.export_notification)).setContentIntent(PendingIntent.getActivity(context, 0, AppUtils.makeSendIntentChooser(context, uri).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_UPDATE_CURRENT)).setPriority(NotificationCompat.PRIORITY_HIGH).setVibrate(new long[0]).build());
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat)

Example 24 with NotificationManagerCompat

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

the class TrimDataService method notifyNewVersion.

public void notifyNewVersion(String version) {
    Intent goToStore = new Intent(this, RedirectToPlayStore.class);
    PendingIntent storePending = PendingIntent.getActivity(this, 0, goToStore, 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle("Talon Version " + version);
    builder.setContentText("Click to update.");
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
    builder.setSmallIcon(R.drawable.ic_stat_icon);
    builder.setContentIntent(storePending);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(552, builder.build());
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 25 with NotificationManagerCompat

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

Aggregations

NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)38 NotificationCompat (android.support.v4.app.NotificationCompat)17 PendingIntent (android.app.PendingIntent)15 Intent (android.content.Intent)15 SharedPreferences (android.content.SharedPreferences)7 PowerManager (android.os.PowerManager)7 Bitmap (android.graphics.Bitmap)6 AppSettings (com.klinker.android.twitter.settings.AppSettings)6 Notification (android.app.Notification)5 Context (android.content.Context)4 Cursor (android.database.Cursor)4 RemoteInput (android.support.v4.app.RemoteInput)4 Bundle (android.os.Bundle)3 ComponentName (android.content.ComponentName)2 ContentResolver (android.content.ContentResolver)2 ContentValues (android.content.ContentValues)2 Uri (android.net.Uri)2 Builder (android.support.v4.app.NotificationCompat.Builder)2 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)2 ArrayList (java.util.ArrayList)2