Java Code Examples for android.support.v4.app.NotificationCompat#WearableExtender

The following examples show how to use android.support.v4.app.NotificationCompat#WearableExtender . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WearListenerService.java    From rnd-android-wear-tesla with MIT License 6 votes vote down vote up
private void showCarUnlockedNotification() {
    int notificationId = 002;

    Intent viewIntent = new Intent(this, ConfirmationNotificationActivity.class);
    viewIntent.setAction(ConfirmationNotificationActivity.ACTION_LOCK_DOOR);
    PendingIntent viewPendingIntent =
            PendingIntent.getActivity(this, 0, viewIntent, 0);

    NotificationCompat.WearableExtender wearableExtender =
            new NotificationCompat.WearableExtender()
                    .setHintHideIcon(true)
                    .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.notification_car_unlocked));

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .extend(wearableExtender)
                    .setSmallIcon(R.drawable.notification_small_car_unlock)
                    .setContentTitle(getString(R.string.notification_car_unlocked_title))
                    .addAction(R.drawable.notif_unlock, getString(R.string.notification_car_unlocked_text), viewPendingIntent);

    sendNotification(notificationId, notificationBuilder);
}
 
Example 2
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);

    NotificationCompat.Builder secondPageBuilder = new NotificationCompat.Builder(context);
    secondPageBuilder.setContentTitle(
            context.getString(R.string.second_page_content_title));
    secondPageBuilder.setContentText(context.getString(R.string.big_text_example_big_text));
    secondPageBuilder.extend(new NotificationCompat.WearableExtender()
                    .setStartScrollBottom(true));

    wearableOptions.addPage(secondPageBuilder.build());
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 3
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
    style.bigPicture(BitmapFactory.decodeResource(context.getResources(),
            R.drawable.example_big_picture));
    style.setBigContentTitle(context.getString(R.string.big_picture_style_example_title));
    style.setSummaryText(context.getString(
            R.string.big_picture_style_example_summary_text));

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setStyle(style);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 4
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
private static NotificationCompat.Builder applyBasicOptions(Context context,
        NotificationCompat.Builder builder, NotificationCompat.WearableExtender wearableOptions,
        NotificationPreset.BuildOptions options) {
    builder.setContentTitle(options.titlePreset)
            .setContentText(options.textPreset)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setDeleteIntent(NotificationUtil.getExamplePendingIntent(
                    context, R.string.example_notification_deleted));
    options.actionsPreset.apply(context, builder, wearableOptions);
    options.priorityPreset.apply(builder, wearableOptions);
    if (options.includeLargeIcon) {
        builder.setLargeIcon(BitmapFactory.decodeResource(
                context.getResources(), R.drawable.example_large_icon));
    }
    if (options.isLocalOnly) {
        builder.setLocalOnly(true);
    }
    if (options.hasContentIntent) {
        builder.setContentIntent(NotificationUtil.getExamplePendingIntent(context,
                R.string.content_intent_clicked));
    }
    if (options.vibrate) {
        builder.setVibrate(new long[] {0, 100, 50, 100} );
    }
    return builder;
}
 
Example 5
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);

    NotificationCompat.Builder secondPageBuilder = new NotificationCompat.Builder(context)
            .setContentTitle(options.titlePreset)
            .setContentText(options.textPreset)
            .extend(new NotificationCompat.WearableExtender()
                    .setGravity(Gravity.CENTER_VERTICAL));
    wearableOptions.addPage(secondPageBuilder.build());

    NotificationCompat.Builder thirdPageBuilder = new NotificationCompat.Builder(context)
            .setContentTitle(options.titlePreset)
            .setContentText(options.textPreset)
            .extend(new NotificationCompat.WearableExtender()
                    .setGravity(Gravity.TOP));
    wearableOptions.addPage(thirdPageBuilder.build());

    wearableOptions.setGravity(Gravity.BOTTOM);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 6
Source File: WearListenerService.java    From rnd-android-wear-tesla with MIT License 6 votes vote down vote up
private void showBabWeatherNotification() {
    int notificationId = 001;

    Intent viewIntent = new Intent(this, ConfirmationNotificationActivity.class);
    viewIntent.setAction(ConfirmationNotificationActivity.ACTION_CLOSE_SUNROOF);
    PendingIntent viewPendingIntent =
            PendingIntent.getActivity(this, 0, viewIntent, 0);

    NotificationCompat.WearableExtender wearableExtender =
            new NotificationCompat.WearableExtender()
                    .setHintHideIcon(true)
                    .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.notification_bad_weather));

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .extend(wearableExtender)
                    .setSmallIcon(R.drawable.notification_small_car_unlock)
                    .setContentTitle(getString(R.string.notification_bad_weather_title))
                    .addAction(R.drawable.notif_unlock, getString(R.string.notification_bad_weather_text), viewPendingIntent);

    sendNotification(notificationId, notificationBuilder);
}
 
Example 7
Source File: WearListenerService.java    From rnd-android-wear-tesla with MIT License 6 votes vote down vote up
private void showUnexpectedStopChargingNotification() {
    int notificationId = 003;

    Intent viewIntent = new Intent(this, ConfirmationNotificationActivity.class);
    viewIntent.setAction(ConfirmationNotificationActivity.ACTION_START_CHARGING);
    PendingIntent viewPendingIntent =
            PendingIntent.getActivity(this, 0, viewIntent, 0);

    NotificationCompat.WearableExtender wearableExtender =
            new NotificationCompat.WearableExtender()
                    .setHintHideIcon(true)
                    .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.notification_charge_interraped));

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .extend(wearableExtender)
                    .setSmallIcon(R.drawable.notification_small_charge_stopped)
                    .setContentTitle(getString(R.string.notification_unexpected_charge_stop_title))
                    .addAction(R.drawable.notif_charge, getString(R.string.notification_unexpected_charge_stop_text), viewPendingIntent);

    sendNotification(notificationId, notificationBuilder);
}
 
Example 8
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    Notification secondPage = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.second_page_content_title))
            .setContentText(context.getString(R.string.second_page_content_text))
            .extend(new NotificationCompat.WearableExtender()
                    .setContentAction(1))
            .build();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_result_open, null, NotificationUtil.getExamplePendingIntent(
                    context, R.string.example_content_action_clicked)).build();
    NotificationCompat.Action action2 = new NotificationCompat.Action.Builder(
            R.drawable.ic_result_open, null, NotificationUtil.getExamplePendingIntent(
                    context, R.string.example_content_action2_clicked)).build();
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender()
                    .addAction(action)
                    .addAction(action2)
                    .addPage(secondPage)
                    .setContentAction(0)
                    .setHintHideIcon(true);
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 9
Source File: ActionsPresets.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_label))
            .build();
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.example_reply_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.example_reply_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    builder.addAction(action);
}
 
Example 10
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.Builder childBuilder1 = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.first_child_content_title))
            .setContentText(context.getString(R.string.first_child_content_text))
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLocalOnly(options.isLocalOnly)
            .setGroup(EXAMPLE_GROUP_KEY)
            .setSortKey("0");

    NotificationCompat.Builder childBuilder2 = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.second_child_content_title))
            .setContentText(context.getString(R.string.second_child_content_text))
            .setSmallIcon(R.mipmap.ic_launcher)
            .addAction(R.mipmap.ic_launcher,
                    context.getString(R.string.second_child_action),
                    NotificationUtil.getExamplePendingIntent(
                            context, R.string.second_child_action_clicked))
            .setLocalOnly(options.isLocalOnly)
            .setGroup(EXAMPLE_GROUP_KEY)
            .setSortKey("1");

    NotificationCompat.Builder summaryBuilder = new NotificationCompat.Builder(context)
            .setGroup(EXAMPLE_GROUP_KEY)
            .setGroupSummary(true);

    NotificationCompat.WearableExtender summaryWearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, summaryBuilder, summaryWearableOptions, options);
    summaryBuilder.extend(summaryWearableOptions);

    return new Notification[] { summaryBuilder.build(), childBuilder1.build(),
            childBuilder2.build() };
}
 
Example 11
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 12
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
    style.bigText(context.getString(R.string.big_text_example_big_text));
    style.setBigContentTitle(context.getString(R.string.big_text_example_title));
    style.setSummaryText(context.getString(R.string.big_text_example_summary_text));

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setStyle(style);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 13
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    Notification secondPage = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.second_page_content_title))
            .setContentText(context.getString(R.string.second_page_content_text))
            .extend(new NotificationCompat.WearableExtender()
                    .setContentIcon(R.drawable.content_icon_small)
                    .setContentIconGravity(Gravity.START))
            .build();

    Notification thirdPage = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.third_page_content_title))
            .setContentText(context.getString(R.string.third_page_content_text))
            .extend(new NotificationCompat.WearableExtender()
                    .setContentIcon(R.drawable.content_icon_large))
            .build();

    Notification fourthPage = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.fourth_page_content_title))
            .setContentText(context.getString(R.string.fourth_page_content_text))
            .extend(new NotificationCompat.WearableExtender()
                    .setContentIcon(R.drawable.content_icon_large)
                    .setContentIconGravity(Gravity.START))
            .build();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender()
                    .setHintHideIcon(true)
                    .setContentIcon(R.drawable.content_icon_small)
                    .addPage(secondPage)
                    .addPage(thirdPage)
                    .addPage(fourthPage);
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 14
Source File: ActionsPresets.java    From AndroidWearable-Samples with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
}
 
Example 15
Source File: AndFChatNotification.java    From AndFChat with GNU General Public License v3.0 4 votes vote down vote up
private void startNotification(String msg, int icon, boolean messages, int amount) {
    android.support.v4.app.TaskStackBuilder stackBuilder = android.support.v4.app.TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ChatScreen.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(new Intent(context, ChatScreen.class));
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender()
                    .setHintHideIcon(true)
                    .setBackground(BitmapFactory.decodeResource(context.getResources(), (R.drawable.wearable_background)));

    NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(context)
            .setOngoing(false)
            .setSmallIcon(icon)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(msg)
            .setContentIntent(resultPendingIntent)
            .setCategory(NotificationCompat.CATEGORY_MESSAGE)
            .setAutoCancel(false)
            .extend(wearableExtender)
            .setColor(context.getResources().getColor(R.color.primary_color));

    if (amount > 0) {
        nBuilder.setNumber(amount);
    }

    Notification notif;
    if(messages) {
        nBuilder.setPriority(2)
        .setVibrate(new long[]{1, 1, 1});
        // If audio is allowed, do it on new messages!
        if (sessionData.getSessionSettings().audioFeedback()) {
            nBuilder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.tone));
        }

        notif = nBuilder.build();

        notif.ledARGB = 0xFFffffff;
        notif.flags = Notification.FLAG_SHOW_LIGHTS;
        //notif.ledOnMS = 300;
        //notif.ledOffMS = 300;

    } else {
        nBuilder.setPriority(0);
        notif = nBuilder.build();
    }

    notificationManager.notify(AndFChatApplication.NOTIFICATION_ID, notif);
}
 
Example 16
Source File: Wear.java    From Pugnotification with Apache License 2.0 4 votes vote down vote up
public Wear(NotificationCompat.Builder builder, int identifier, String tag) {
    super(builder, identifier, tag);
    this.wearableExtender = new NotificationCompat.WearableExtender();
}
 
Example 17
Source File: PriorityPreset.java    From AndroidWearable-Samples with Apache License 2.0 4 votes vote down vote up
/** Apply the priority to a notification builder */
public abstract void apply(NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions);
 
Example 18
Source File: PriorityPresets.java    From AndroidWearable-Samples with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    builder.setPriority(mPriority);
}
 
Example 19
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 4 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();

    SpannableStringBuilder title = new SpannableStringBuilder();
    appendStyled(title, "Stylized", new StyleSpan(Typeface.BOLD_ITALIC));
    title.append(" title");
    SpannableStringBuilder text = new SpannableStringBuilder("Stylized text: ");
    appendStyled(text, "C", new ForegroundColorSpan(Color.RED));
    appendStyled(text, "O", new ForegroundColorSpan(Color.GREEN));
    appendStyled(text, "L", new ForegroundColorSpan(Color.BLUE));
    appendStyled(text, "O", new ForegroundColorSpan(Color.YELLOW));
    appendStyled(text, "R", new ForegroundColorSpan(Color.MAGENTA));
    appendStyled(text, "S", new ForegroundColorSpan(Color.CYAN));
    text.append("; ");
    appendStyled(text, "1.25x size", new RelativeSizeSpan(1.25f));
    text.append("; ");
    appendStyled(text, "0.75x size", new RelativeSizeSpan(0.75f));
    text.append("; ");
    appendStyled(text, "underline", new UnderlineSpan());
    text.append("; ");
    appendStyled(text, "strikethrough", new StrikethroughSpan());
    text.append("; ");
    appendStyled(text, "bold", new StyleSpan(Typeface.BOLD));
    text.append("; ");
    appendStyled(text, "italic", new StyleSpan(Typeface.ITALIC));
    text.append("; ");
    appendStyled(text, "sans-serif-thin", new TypefaceSpan("sans-serif-thin"));
    text.append("; ");
    appendStyled(text, "monospace", new TypefaceSpan("monospace"));
    text.append("; ");
    appendStyled(text, "sub", new SubscriptSpan());
    text.append("script");
    appendStyled(text, "super", new SuperscriptSpan());

    style.setBigContentTitle(title);
    style.bigText(text);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setStyle(style);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 20
Source File: NotificationListenerService.java    From wear-notify-for-reddit with Apache License 2.0 4 votes vote down vote up
private void setBlueBackground(Bitmap themeBlueBitmap, NotificationCompat.Builder builder) {
    NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
    extender.setBackground(themeBlueBitmap);
    builder.extend(extender);
}