use of android.support.v4.app.NotificationManagerCompat in project Talon-for-Twitter by klinker24.
the class NotificationUtils method sendTestNotification.
public static void sendTestNotification(Context context) {
if (!TEST_NOTIFICATION) {
return;
}
AppSettings settings = AppSettings.getInstance(context);
SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
Intent markRead = new Intent(context, MarkReadService.class);
PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);
String shortText = "Test Talon";
String longText = "Here is a test for Talon's notifications";
Intent resultIntent = new Intent(context, RedirectToMentions.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(shortText).setContentText(longText).setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)).setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(shortText).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setPriority(NotificationCompat.PRIORITY_HIGH);
// Pebble notification
if (sharedPrefs.getBoolean("pebble_notification", false)) {
sendAlertToPebble(context, shortText, shortText);
}
// Light Flow notification
sendToLightFlow(context, shortText, shortText);
if (settings.vibrate) {
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
}
if (settings.sound) {
try {
mBuilder.setSound(Uri.parse(settings.ringtone));
} catch (Exception e) {
e.printStackTrace();
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);
Intent reply = new Intent(context, NotificationCompose.class);
MentionsDataSource data = MentionsDataSource.getInstance(context);
PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + "lukeklinker" + " ").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());
// 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);
}
}
use of android.support.v4.app.NotificationManagerCompat in project Talon-for-Twitter by klinker24.
the class ActivityUtils method postNotification.
public void postNotification(int id) {
if (notificationItems.size() == 0) {
return;
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setContentTitle(notificationTitle);
mBuilder.setSmallIcon(R.drawable.ic_stat_icon);
mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_notification_dark));
if (notificationItems.size() > 1) {
// inbox style
NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle();
try {
inbox.setBigContentTitle(notificationTitle);
} catch (Exception e) {
}
if (notificationItems.size() <= 5) {
for (String s : notificationItems) {
inbox.addLine(Html.fromHtml(s));
}
} else {
for (int i = 0; i < 5; i++) {
inbox.addLine(Html.fromHtml(notificationItems.get(i)));
}
int extra = notificationItems.size() - 5;
if (extra > 1) {
inbox.setSummaryText("+" + extra + " " + context.getString(R.string.items));
} else {
inbox.setSummaryText("+" + extra + " " + context.getString(R.string.item));
}
}
mBuilder.setStyle(inbox);
mBuilder.setContentText(notificationItems.size() + " " + context.getString(R.string.items));
} else {
// big text style
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText(Html.fromHtml(notificationItems.get(0)));
bigText.setBigContentTitle(notificationTitle);
mBuilder.setStyle(bigText);
mBuilder.setContentText(Html.fromHtml(notificationItems.get(0)));
}
if (useSecondAccount) {
mBuilder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, SwitchAccountsToActivity.class), 0));
} else {
mBuilder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, RedirectToActivity.class), 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);
}
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 (sharedPrefs.getBoolean("pebble_notification", false)) {
NotificationUtils.sendAlertToPebble(context, notificationTitle, notificationItems.get(0));
}
// Light Flow notification
NotificationUtils.sendToLightFlow(context, notificationTitle, notificationItems.get(0));
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(id, mBuilder.build());
}
use of android.support.v4.app.NotificationManagerCompat in project k-9 by k9mail.
the class NotificationController method newInstance.
public static NotificationController newInstance(Context context) {
Context appContext = context.getApplicationContext();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(appContext);
return new NotificationController(appContext, notificationManager);
}
use of android.support.v4.app.NotificationManagerCompat in project muzei by romannurik.
the class NewWallpaperNotificationReceiver method markNotificationRead.
public static void markNotificationRead(Context context) {
Cursor lastArtwork = context.getContentResolver().query(MuzeiContract.Artwork.CONTENT_URI, new String[] { BaseColumns._ID, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, MuzeiContract.Artwork.COLUMN_NAME_TOKEN }, null, null, null);
if (lastArtwork != null && lastArtwork.moveToFirst()) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
sp.edit().putLong(PREF_LAST_READ_NOTIFICATION_ARTWORK_ID, lastArtwork.getLong(0)).putString(PREF_LAST_READ_NOTIFICATION_ARTWORK_IMAGE_URI, lastArtwork.getString(1)).putString(PREF_LAST_READ_NOTIFICATION_ARTWORK_TOKEN, lastArtwork.getString(2)).apply();
}
if (lastArtwork != null) {
lastArtwork.close();
}
NotificationManagerCompat nm = NotificationManagerCompat.from(context);
nm.cancel(NOTIFICATION_ID);
}
use of android.support.v4.app.NotificationManagerCompat in project Conversations by siacs.
the class NotificationService method updateErrorNotification.
public void updateErrorNotification() {
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
final List<Account> errors = new ArrayList<>();
for (final Account account : mXmppConnectionService.getAccounts()) {
if (account.hasErrorStatus() && account.showErrorNotification()) {
errors.add(account);
}
}
if (mXmppConnectionService.getPreferences().getBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE, false)) {
notificationManager.notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification());
}
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
if (errors.size() == 0) {
notificationManager.cancel(ERROR_NOTIFICATION_ID);
return;
} else if (errors.size() == 1) {
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
mBuilder.setContentText(errors.get(0).getJid().toBareJid().toString());
} else {
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts));
mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix));
}
mBuilder.addAction(R.drawable.ic_autorenew_white_24dp, mXmppConnectionService.getString(R.string.try_again), createTryAgainIntent());
mBuilder.setDeleteIntent(createDismissErrorIntent());
mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setSmallIcon(R.drawable.ic_warning_white_24dp);
} else {
mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
}
mBuilder.setContentIntent(PendingIntent.getActivity(mXmppConnectionService, 145, new Intent(mXmppConnectionService, ManageAccountActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
notificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
}
Aggregations