use of android.app.TaskStackBuilder in project android_frameworks_base by ResurrectionRemix.
the class MainActivity method sendNotification.
private void sendNotification(int count) {
Notification.Builder builder = new Notification.Builder(this).setContentTitle(String.format("%s OSU available", count)).setContentText("Choose one to connect").setSmallIcon(android.R.drawable.ic_dialog_info).setAutoCancel(false);
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());
}
use of android.app.TaskStackBuilder in project android_frameworks_base by DirtyUnicorns.
the class MainActivity method sendNotification.
private void sendNotification(int count) {
Notification.Builder builder = new Notification.Builder(this).setContentTitle(String.format("%s OSU available", count)).setContentText("Choose one to connect").setSmallIcon(android.R.drawable.ic_dialog_info).setAutoCancel(false);
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());
}
use of android.app.TaskStackBuilder in project platform_frameworks_base by android.
the class MainActivity method sendNotification.
private void sendNotification(int count) {
Notification.Builder builder = new Notification.Builder(this).setContentTitle(String.format("%s OSU available", count)).setContentText("Choose one to connect").setSmallIcon(android.R.drawable.ic_dialog_info).setAutoCancel(false);
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());
}
use of android.app.TaskStackBuilder in project android-aosp-mms by slvn.
the class MmsWidgetProvider method updateWidget.
/**
* Update the widget appWidgetId
*/
private static void updateWidget(Context context, int appWidgetId) {
if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
}
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
PendingIntent clickIntent;
// Launch an intent to avoid ANRs
final Intent intent = new Intent(context, MmsWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);
remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.app_label));
// Open Mms's app conversation list when click on header
final Intent convIntent = new Intent(context, ConversationList.class);
clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);
// On click intent for Compose
final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
composeIntent.setAction(Intent.ACTION_SENDTO);
clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);
// On click intent for Conversation
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
taskStackBuilder.addParentStack(ComposeMessageActivity.class);
Intent msgIntent = new Intent(Intent.ACTION_VIEW);
msgIntent.setType("vnd.android-dir/mms-sms");
taskStackBuilder.addNextIntent(msgIntent);
remoteViews.setPendingIntentTemplate(R.id.conversation_list, taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}
use of android.app.TaskStackBuilder in project android-aosp-mms by slvn.
the class MessagingNotification method updateNotification.
/**
* updateNotification is *the* main function for building the actual notification handed to
* the NotificationManager
* @param context
* @param isNew if we've got a new message, show the ticker
* @param uniqueThreadCount
* @param notificationSet the set of notifications to display
*/
private static void updateNotification(Context context, boolean isNew, int uniqueThreadCount, SortedSet<NotificationInfo> notificationSet) {
// If the user has turned off notifications in settings, don't do any notifying.
if (!MessagingPreferenceActivity.getNotificationEnabled(context)) {
if (DEBUG) {
Log.d(TAG, "updateNotification: notifications turned off in prefs, bailing");
}
return;
}
// Figure out what we've got -- whether all sms's, mms's, or a mixture of both.
final int messageCount = notificationSet.size();
NotificationInfo mostRecentNotification = notificationSet.first();
final Notification.Builder noti = new Notification.Builder(context).setWhen(mostRecentNotification.mTimeMillis);
if (isNew) {
noti.setTicker(mostRecentNotification.mTicker);
}
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
// If we have more than one unique thread, change the title (which would
// normally be the contact who sent the message) to a generic one that
// makes sense for multiple senders, and change the Intent to take the
// user to the conversation list instead of the specific thread.
// Cases:
// 1) single message from single thread - intent goes to ComposeMessageActivity
// 2) multiple messages from single thread - intent goes to ComposeMessageActivity
// 3) messages from multiple threads - intent goes to ConversationList
final Resources res = context.getResources();
String title = null;
Bitmap avatar = null;
if (uniqueThreadCount > 1) {
// messages from multiple threads
Intent mainActivityIntent = new Intent(Intent.ACTION_MAIN);
mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
mainActivityIntent.setType("vnd.android-dir/mms-sms");
taskStackBuilder.addNextIntent(mainActivityIntent);
title = context.getString(R.string.message_count_notification, messageCount);
} else {
// same thread, single or multiple messages
title = mostRecentNotification.mTitle;
BitmapDrawable contactDrawable = (BitmapDrawable) mostRecentNotification.mSender.getAvatar(context, null);
if (contactDrawable != null) {
// Show the sender's avatar as the big icon. Contact bitmaps are 96x96 so we
// have to scale 'em up to 128x128 to fill the whole notification large icon.
avatar = contactDrawable.getBitmap();
if (avatar != null) {
final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
if (avatar.getHeight() < idealIconHeight) {
// Scale this image to fit the intended size
avatar = Bitmap.createScaledBitmap(avatar, idealIconWidth, idealIconHeight, true);
}
if (avatar != null) {
noti.setLargeIcon(avatar);
}
}
}
taskStackBuilder.addParentStack(ComposeMessageActivity.class);
taskStackBuilder.addNextIntent(mostRecentNotification.mClickIntent);
}
// Always have to set the small icon or the notification is ignored
noti.setSmallIcon(R.drawable.stat_notify_sms);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Update the notification.
noti.setContentTitle(title).setContentIntent(taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)).addKind(Notification.KIND_MESSAGE).setPriority(// TODO: set based on contact coming
Notification.PRIORITY_DEFAULT);
// from a favorite.
int defaults = 0;
if (isNew) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
boolean vibrate = false;
if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE)) {
// The most recent change to the vibrate preference is to store a boolean
// value in NOTIFICATION_VIBRATE. If prefs contain that preference, use that
// first.
vibrate = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE, false);
} else if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN)) {
// This is to support the pre-JellyBean MR1.1 version of vibrate preferences
// when vibrate was a tri-state setting. As soon as the user opens the Messaging
// app's settings, it will migrate this setting from NOTIFICATION_VIBRATE_WHEN
// to the boolean value stored in NOTIFICATION_VIBRATE.
String vibrateWhen = sp.getString(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN, null);
vibrate = "always".equals(vibrateWhen);
}
if (vibrate) {
defaults |= Notification.DEFAULT_VIBRATE;
}
String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null);
noti.setSound(TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr));
Log.d(TAG, "updateNotification: new message, adding sound to the notification");
}
defaults |= Notification.DEFAULT_LIGHTS;
noti.setDefaults(defaults);
// set up delete intent
noti.setDeleteIntent(PendingIntent.getBroadcast(context, 0, sNotificationOnDeleteIntent, 0));
final Notification notification;
if (messageCount == 1) {
// We've got a single message
// This sets the text for the collapsed form:
noti.setContentText(mostRecentNotification.formatBigMessage(context));
if (mostRecentNotification.mAttachmentBitmap != null) {
// The message has a picture, show that
notification = new Notification.BigPictureStyle(noti).bigPicture(mostRecentNotification.mAttachmentBitmap).setSummaryText(mostRecentNotification.formatPictureMessage(context)).build();
} else {
// Show a single notification -- big style with the text of the whole message
notification = new Notification.BigTextStyle(noti).bigText(mostRecentNotification.formatBigMessage(context)).build();
}
if (DEBUG) {
Log.d(TAG, "updateNotification: single message notification");
}
} else {
// We've got multiple messages
if (uniqueThreadCount == 1) {
// We've got multiple messages for the same thread.
// Starting with the oldest new message, display the full text of each message.
// Begin a line for each subsequent message.
SpannableStringBuilder buf = new SpannableStringBuilder();
NotificationInfo[] infos = notificationSet.toArray(new NotificationInfo[messageCount]);
int len = infos.length;
for (int i = len - 1; i >= 0; i--) {
NotificationInfo info = infos[i];
buf.append(info.formatBigMessage(context));
if (i != 0) {
buf.append('\n');
}
}
noti.setContentText(context.getString(R.string.message_count_notification, messageCount));
// Show a single notification -- big style with the text of all the messages
notification = new Notification.BigTextStyle(noti).bigText(buf).setSummaryText((avatar == null) ? null : " ").build();
if (DEBUG) {
Log.d(TAG, "updateNotification: multi messages for single thread");
}
} else {
// Build a set of the most recent notification per threadId.
HashSet<Long> uniqueThreads = new HashSet<Long>(messageCount);
ArrayList<NotificationInfo> mostRecentNotifPerThread = new ArrayList<NotificationInfo>();
Iterator<NotificationInfo> notifications = notificationSet.iterator();
while (notifications.hasNext()) {
NotificationInfo notificationInfo = notifications.next();
if (!uniqueThreads.contains(notificationInfo.mThreadId)) {
uniqueThreads.add(notificationInfo.mThreadId);
mostRecentNotifPerThread.add(notificationInfo);
}
}
// When collapsed, show all the senders like this:
// Fred Flinstone, Barry Manilow, Pete...
noti.setContentText(formatSenders(context, mostRecentNotifPerThread));
Notification.InboxStyle inboxStyle = new Notification.InboxStyle(noti);
// We have to set the summary text to non-empty so the content text doesn't show
// up when expanded.
inboxStyle.setSummaryText(" ");
// At this point we've got multiple messages in multiple threads. We only
// want to show the most recent message per thread, which are in
// mostRecentNotifPerThread.
int uniqueThreadMessageCount = mostRecentNotifPerThread.size();
int maxMessages = Math.min(MAX_MESSAGES_TO_SHOW, uniqueThreadMessageCount);
for (int i = 0; i < maxMessages; i++) {
NotificationInfo info = mostRecentNotifPerThread.get(i);
inboxStyle.addLine(info.formatInboxMessage(context));
}
notification = inboxStyle.build();
uniqueThreads.clear();
mostRecentNotifPerThread.clear();
if (DEBUG) {
Log.d(TAG, "updateNotification: multi messages," + " showing inboxStyle notification");
}
}
}
nm.notify(NOTIFICATION_ID, notification);
}
Aggregations