Search in sources :

Example 21 with TaskStackBuilder

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();
}
Also used : TaskStackBuilder(android.app.TaskStackBuilder)

Example 22 with TaskStackBuilder

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());
        }
    }
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification)

Example 23 with TaskStackBuilder

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);
    }
}
Also used : ComposeMessageActivity(com.android.mms.ui.ComposeMessageActivity) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SpannableString(android.text.SpannableString) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification) ConversationList(com.android.mms.ui.ConversationList)

Example 24 with TaskStackBuilder

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());
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RemoteViews(android.widget.RemoteViews) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder)

Aggregations

TaskStackBuilder (android.app.TaskStackBuilder)24 PendingIntent (android.app.PendingIntent)23 Intent (android.content.Intent)23 Notification (android.app.Notification)18 NotificationManager (android.app.NotificationManager)18 NotificationCompat (android.support.v4.app.NotificationCompat)9 NotificationChannel (android.app.NotificationChannel)6 SharedPreferences (android.content.SharedPreferences)6 SpannableStringBuilder (android.text.SpannableStringBuilder)5 SuppressLint (android.annotation.SuppressLint)4 TargetApi (android.annotation.TargetApi)4 Bitmap (android.graphics.Bitmap)4 Typeface (android.graphics.Typeface)4 FloatingActionButton (android.support.design.widget.FloatingActionButton)4 SpannableString (android.text.SpannableString)4 View (android.view.View)4 InterstitialAd (com.google.android.gms.ads.InterstitialAd)4 Context (android.content.Context)2 Resources (android.content.res.Resources)2 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)2