use of android.app.TaskStackBuilder in project Parse-SDK-Android by ParsePlatform.
the class TaskStackBuilderHelper method startActivities.
public static void startActivities(Context context, Class<? extends Activity> cls, Intent activityIntent) {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(cls);
stackBuilder.addNextIntent(activityIntent);
stackBuilder.startActivities();
}
use of android.app.TaskStackBuilder in project Fairphone by Kwamecorp.
the class PeaceOfMindBroadCastReceiver method setPeaceOfMindIconInNotificationBar.
/**
* Sets the Peace of mind icon on the notification bar
* @param putIcon if true the icon is put otherwise it is removed
* @param wasInterrupted when true, an extra notification is sent to inform the user that Peace of mind was ended
*/
private void setPeaceOfMindIconInNotificationBar(boolean putIcon, boolean wasInterrupted) {
NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (putIcon) {
// just in case the user didn't clear it
manager.cancel(PEACE_OF_MIND_INTERRUPTED_NOTIFICATION);
NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.peace_system_bar_icon).setContentTitle(mContext.getResources().getString(R.string.app_name)).setContentText(mContext.getResources().getString(R.string.peace_on_notification));
Intent resultIntent = new Intent(mContext, PeaceOfMindActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(PeaceOfMindActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
Notification notificationWhileRunnig = builder.build();
notificationWhileRunnig.flags |= Notification.FLAG_NO_CLEAR;
// Add notification
manager.notify(PEACE_OF_MIND_ON_NOTIFICATION, notificationWhileRunnig);
} else {
manager.cancel(PEACE_OF_MIND_ON_NOTIFICATION);
// send a notification saying that the peace was ended
if (wasInterrupted) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.peace_system_bar_icon).setAutoCancel(true).setContentTitle(mContext.getResources().getString(R.string.app_name)).setContentText(mContext.getResources().getString(R.string.peace_off_notification)).setTicker(mContext.getResources().getString(R.string.peace_off_notification));
manager.notify(PEACE_OF_MIND_INTERRUPTED_NOTIFICATION, builder.build());
}
}
}
use of android.app.TaskStackBuilder in project android-aosp-mms by slvn.
the class MessagingNotification method notifyFailed.
private static void notifyFailed(Context context, boolean isDownload, long threadId, boolean noisy) {
// TODO factor out common code for creating notifications
boolean enabled = MessagingPreferenceActivity.getNotificationEnabled(context);
if (!enabled) {
return;
}
// Strategy:
// a. If there is a single failure notification, tapping on the notification goes
// to the compose view.
// b. If there are two failure it stays in the thread view. Selecting one undelivered
// thread will dismiss one undelivered notification but will still display the
// notification.If you select the 2nd undelivered one it will dismiss the notification.
// Dummy initial values, just to initialize the memory
long[] msgThreadId = { 0, 1 };
int totalFailedCount = getUndeliveredMessageCount(context, msgThreadId);
if (totalFailedCount == 0 && !isDownload) {
return;
}
// The getUndeliveredMessageCount method puts a non-zero value in msgThreadId[1] if all
// failures are from the same thread.
// If isDownload is true, we're dealing with 1 specific failure; therefore "all failed" are
// indeed in the same thread since there's only 1.
boolean allFailedInSameThread = (msgThreadId[1] != 0) || isDownload;
Intent failedIntent;
Notification notification = new Notification();
String title;
String description;
if (totalFailedCount > 1) {
description = context.getString(R.string.notification_failed_multiple, Integer.toString(totalFailedCount));
title = context.getString(R.string.notification_failed_multiple_title);
} else {
title = isDownload ? context.getString(R.string.message_download_failed_title) : context.getString(R.string.message_send_failed_title);
description = context.getString(R.string.message_failed_body);
}
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
if (allFailedInSameThread) {
failedIntent = new Intent(context, ComposeMessageActivity.class);
if (isDownload) {
// When isDownload is true, the valid threadId is passed into this function.
failedIntent.putExtra("failed_download_flag", true);
} else {
threadId = msgThreadId[0];
failedIntent.putExtra("undelivered_flag", true);
}
failedIntent.putExtra("thread_id", threadId);
taskStackBuilder.addParentStack(ComposeMessageActivity.class);
} else {
failedIntent = new Intent(context, ConversationList.class);
}
taskStackBuilder.addNextIntent(failedIntent);
notification.icon = R.drawable.stat_notify_sms_failed;
notification.tickerText = title;
notification.setLatestEventInfo(context, title, description, taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
if (noisy) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
boolean vibrate = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE, false);
if (vibrate) {
notification.defaults |= Notification.DEFAULT_VIBRATE;
}
String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null);
notification.sound = TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr);
}
NotificationManager notificationMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (isDownload) {
notificationMgr.notify(DOWNLOAD_FAILED_NOTIFICATION_ID, notification);
} else {
notificationMgr.notify(MESSAGE_FAILED_NOTIFICATION_ID, notification);
}
}
use of android.app.TaskStackBuilder in project Termo by Pasha7308.
the class NotificationCreator method addNotification.
void addNotification(WeatherDto dto, boolean isDarkNotification, boolean isDigitsInNotification, boolean isNotificationGraphBold) {
Resources res = context.getResources();
int temp = dto.getServerTermo().getTemp();
String tempTermo = TempRounder.round(temp, false, false);
String tempIao = TempRounder.round(dto.getServerIao().getTemp(), false, false);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), isDarkNotification ? R.layout.notification_dark : R.layout.notification_light);
remoteViews.setTextViewText(R.id.lblNotTextTermo, tempTermo);
remoteViews.setTextColor(R.id.lblNotTextTermo, Colorer.getColorOutOfTemp(tempTermo, isDarkNotification));
remoteViews.setTextViewText(R.id.lblNotTextIao, tempIao);
remoteViews.setTextColor(R.id.lblNotTextIao, Colorer.getColorOutOfTemp(tempIao, isDarkNotification));
remoteViews.setViewVisibility(R.id.lblNotTime, (dto.getUpdated().GetDateTime() != null) ? 1 : 0);
if (dto.getUpdated().GetDateTime() != null) {
remoteViews.setTextViewText(R.id.lblNotTime, DateUtils.timeToString(dto.getUpdated().GetDateTime(), true));
remoteViews.setTextColor(R.id.lblNotTime, isDarkNotification ? Color.WHITE : Color.BLACK);
}
remoteViews.setTextColor(R.id.lblNotTermo, isDarkNotification ? Color.WHITE : Color.BLACK);
remoteViews.setTextColor(R.id.lblNotIao, isDarkNotification ? Color.WHITE : Color.BLACK);
Bitmap bm = Bitmap.createBitmap(512, 256, Bitmap.Config.ARGB_8888);
DrawManager.drawOnBitmap(bm, dto, isNotificationGraphBold, isDarkNotification);
remoteViews.setBitmap(R.id.imgvNot, "setImageBitmap", bm);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(isDigitsInNotification ? getIcon(temp) : R.drawable.ic_stat_notification).setContent(remoteViews).setAutoCancel(false);
Intent resultIntent = new Intent(context, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
android.app.NotificationManager mNotificationManager = (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = res.getInteger(R.integer.notificationId);
mNotificationManager.notify(notificationId, mBuilder.build());
}
Aggregations