Search in sources :

Example 16 with TaskStackBuilder

use of android.app.TaskStackBuilder in project android_frameworks_base by AOSPA.

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

Example 17 with TaskStackBuilder

use of android.app.TaskStackBuilder in project android_frameworks_base by crdroidandroid.

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

Example 18 with TaskStackBuilder

use of android.app.TaskStackBuilder in project xDrip by NightscoutFoundation.

the class Notifications method createOngoingNotification.

/* private Notification createExtensionPage(long hours) {
        return new NotificationCompat.Builder(mContext)
                .extend(new NotificationCompat.WearableExtender()
                                .setBackground(createWearBitmap(hours))
                                .setHintShowBackgroundOnly(true)
                                .setHintAvoidBackgroundClipping(true)
                )
                .build();
    }*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public synchronized Notification createOngoingNotification(BgGraphBuilder bgGraphBuilder, Context context) {
    mContext = context;
    ReadPerfs(mContext);
    Intent intent = new Intent(mContext, Home.class);
    List<BgReading> lastReadings = BgReading.latest(2);
    BgReading lastReading = null;
    if (lastReadings != null && lastReadings.size() >= 2) {
        lastReading = lastReadings.get(0);
    }
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(Home.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    // final NotificationCompat.Builder b = new NotificationCompat.Builder(mContext, NotificationChannels.ONGOING_CHANNEL);
    // final NotificationCompat.Builder b = new NotificationCompat.Builder(mContext); // temporary fix until ONGOING CHANNEL is silent by default on android 8+
    // temporary fix until ONGOING CHANNEL is silent by default on android 8+
    final Notification.Builder b = new Notification.Builder(mContext);
    // b.setOngoing(true); // TODO CHECK THIS!!
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        b.setVisibility(Pref.getBooleanDefaultFalse("public_notifications") ? Notification.VISIBILITY_PUBLIC : Notification.VISIBILITY_PRIVATE);
        b.setCategory(NotificationCompat.CATEGORY_STATUS);
    }
    if (Pref.getBooleanDefaultFalse("high_priority_notifications")) {
        b.setPriority(Notification.PRIORITY_HIGH);
    }
    final BestGlucose.DisplayGlucose dg = (use_best_glucose) ? BestGlucose.getDisplayGlucose() : null;
    // could be preference option
    final boolean use_color_in_notification = false;
    final SpannableString titleString = new SpannableString(lastReading == null ? "BG Reading Unavailable" : (dg != null) ? (dg.spannableString(dg.unitized + " " + dg.delta_arrow, use_color_in_notification)) : (lastReading.displayValue(mContext) + " " + lastReading.slopeArrow()));
    b.setContentTitle(titleString).setContentText("xDrip Data collection service is running.").setSmallIcon(R.drawable.ic_action_communication_invert_colors_on).setUsesChronometer(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // user has a chance to disable the feature
        if (SystemClock.uptimeMillis() > Constants.MINUTE_IN_MS * 15) {
            if (NumberGraphic.numberIconEnabled()) {
                if ((dg != null) && (!dg.isStale())) {
                    final Bitmap icon_bitmap = NumberGraphic.getBitmap(dg.unitized);
                    if (icon_bitmap != null)
                        b.setSmallIcon(Icon.createWithBitmap(icon_bitmap));
                }
            }
        }
    }
    if (lastReading != null) {
        b.setWhen(lastReading.timestamp);
        final SpannableString deltaString = new SpannableString("Delta: " + ((dg != null) ? (dg.spannableString(dg.unitized_delta + (dg.from_plugin ? " " + context.getString(R.string.p_in_circle) : ""))) : bgGraphBuilder.unitizedDeltaString(true, true)));
        b.setContentText(deltaString);
        iconBitmap = new BgSparklineBuilder(mContext).setHeight(64).setWidth(64).setStart(System.currentTimeMillis() - 60000 * 60 * 3).setBgGraphBuilder(bgGraphBuilder).setBackgroundColor(getCol(X.color_notification_chart_background)).build();
        b.setLargeIcon(iconBitmap);
        Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle();
        notifiationBitmap = new BgSparklineBuilder(mContext).setBgGraphBuilder(bgGraphBuilder).showHighLine().showLowLine().setStart(System.currentTimeMillis() - 60000 * 60 * 3).showAxes(true).setBackgroundColor(getCol(X.color_notification_chart_background)).setShowFiltered(DexCollectionType.hasFiltered() && Pref.getBooleanDefaultFalse("show_filtered_curve")).build();
        bigPictureStyle.bigPicture(notifiationBitmap).setSummaryText(deltaString).setBigContentTitle(titleString);
        b.setStyle(bigPictureStyle);
    }
    b.setContentIntent(resultPendingIntent);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        b.setLocalOnly(true);
    }
    return b.build();
}
Also used : TaskStackBuilder(android.app.TaskStackBuilder) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Notification(android.app.Notification) UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification) SpannableString(android.text.SpannableString) BestGlucose(com.eveningoutpost.dexdrip.BestGlucose) Bitmap(android.graphics.Bitmap) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) TargetApi(android.annotation.TargetApi)

Example 19 with TaskStackBuilder

use of android.app.TaskStackBuilder in project butter-android by butterproject.

the class RecommendationService method buildPendingIntent.

private PendingIntent buildPendingIntent(final MediaWrapper media) {
    // TODO: 6/17/17 Pending intent can not rely on provider position
    Intent detailIntent = TVMediaDetailActivity.getIntent(this, media);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(TVMediaDetailActivity.class);
    stackBuilder.addNextIntent(detailIntent);
    // Ensure a unique PendingIntents, otherwise all recommendations end up with the same
    // PendingIntent
    detailIntent.setAction(media.getMedia().getId());
    PendingIntent intent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    return intent;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder)

Example 20 with TaskStackBuilder

use of android.app.TaskStackBuilder in project xDrip-plus by jamorham.

the class Notifications method createOngoingNotification.

/* private Notification createExtensionPage(long hours) {
        return new NotificationCompat.Builder(mContext)
                .extend(new NotificationCompat.WearableExtender()
                                .setBackground(createWearBitmap(hours))
                                .setHintShowBackgroundOnly(true)
                                .setHintAvoidBackgroundClipping(true)
                )
                .build();
    }*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public synchronized Notification createOngoingNotification(BgGraphBuilder bgGraphBuilder, Context context) {
    mContext = context;
    ReadPerfs(mContext);
    Intent intent = new Intent(mContext, Home.class);
    List<BgReading> lastReadings = BgReading.latest(2);
    BgReading lastReading = null;
    if (lastReadings != null && lastReadings.size() >= 2) {
        lastReading = lastReadings.get(0);
    }
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(Home.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    // final NotificationCompat.Builder b = new NotificationCompat.Builder(mContext, NotificationChannels.ONGOING_CHANNEL);
    // final NotificationCompat.Builder b = new NotificationCompat.Builder(mContext); // temporary fix until ONGOING CHANNEL is silent by default on android 8+
    // temporary fix until ONGOING CHANNEL is silent by default on android 8+
    final Notification.Builder b = new Notification.Builder(mContext);
    // b.setOngoing(true); // TODO CHECK THIS!!
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        b.setVisibility(Pref.getBooleanDefaultFalse("public_notifications") ? Notification.VISIBILITY_PUBLIC : Notification.VISIBILITY_PRIVATE);
        b.setCategory(NotificationCompat.CATEGORY_STATUS);
    }
    if (Pref.getBooleanDefaultFalse("high_priority_notifications")) {
        b.setPriority(Notification.PRIORITY_HIGH);
    }
    final BestGlucose.DisplayGlucose dg = (use_best_glucose) ? BestGlucose.getDisplayGlucose() : null;
    // could be preference option
    final boolean use_color_in_notification = false;
    final SpannableString titleString = new SpannableString(lastReading == null ? "BG Reading Unavailable" : (dg != null) ? (dg.spannableString(dg.unitized + " " + dg.delta_arrow, use_color_in_notification)) : (lastReading.displayValue(mContext) + " " + lastReading.slopeArrow()));
    b.setContentTitle(titleString).setContentText("xDrip Data collection service is running.").setSmallIcon(R.drawable.ic_action_communication_invert_colors_on).setUsesChronometer(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // user has a chance to disable the feature
        if (SystemClock.uptimeMillis() > Constants.MINUTE_IN_MS * 15) {
            if (NumberGraphic.numberIconEnabled()) {
                if ((dg != null) && (!dg.isStale())) {
                    final Bitmap icon_bitmap = NumberGraphic.getBitmap(dg.unitized);
                    if (icon_bitmap != null)
                        b.setSmallIcon(Icon.createWithBitmap(icon_bitmap));
                }
            }
        }
    }
    if (lastReading != null) {
        b.setWhen(lastReading.timestamp);
        final SpannableString deltaString = new SpannableString("Delta: " + ((dg != null) ? (dg.spannableString(dg.unitized_delta + (dg.from_plugin ? " " + context.getString(R.string.p_in_circle) : ""))) : bgGraphBuilder.unitizedDeltaString(true, true)));
        b.setContentText(deltaString);
        iconBitmap = new BgSparklineBuilder(mContext).setHeight(64).setWidth(64).setStart(System.currentTimeMillis() - 60000 * 60 * 3).setBgGraphBuilder(bgGraphBuilder).setBackgroundColor(getCol(X.color_notification_chart_background)).build();
        b.setLargeIcon(iconBitmap);
        Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle();
        notifiationBitmap = new BgSparklineBuilder(mContext).setBgGraphBuilder(bgGraphBuilder).showHighLine().showLowLine().setStart(System.currentTimeMillis() - 60000 * 60 * 3).showAxes(true).setBackgroundColor(getCol(X.color_notification_chart_background)).setShowFiltered(DexCollectionType.hasFiltered() && Pref.getBooleanDefaultFalse("show_filtered_curve")).build();
        bigPictureStyle.bigPicture(notifiationBitmap).setSummaryText(deltaString).setBigContentTitle(titleString);
        b.setStyle(bigPictureStyle);
    }
    b.setContentIntent(resultPendingIntent);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        b.setLocalOnly(true);
    }
    return b.build();
}
Also used : TaskStackBuilder(android.app.TaskStackBuilder) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Notification(android.app.Notification) UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification) SpannableString(android.text.SpannableString) BestGlucose(com.eveningoutpost.dexdrip.BestGlucose) Bitmap(android.graphics.Bitmap) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) TargetApi(android.annotation.TargetApi)

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