From 5c8450191a91820468c36d1e3f4e93d970b4eb55 Mon Sep 17 00:00:00 2001 From: Alinson Xavier Date: Mon, 19 Sep 2016 18:32:03 -0400 Subject: [PATCH] Make notifications actionable on the Pebble Closes #126 --- .../notifications/NotificationTray.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/isoron/uhabits/notifications/NotificationTray.java b/app/src/main/java/org/isoron/uhabits/notifications/NotificationTray.java index 03fed27e5..d6a0253a2 100644 --- a/app/src/main/java/org/isoron/uhabits/notifications/NotificationTray.java +++ b/app/src/main/java/org/isoron/uhabits/notifications/NotificationTray.java @@ -21,6 +21,7 @@ package org.isoron.uhabits.notifications; import android.app.*; import android.content.*; +import android.graphics.*; import android.support.annotation.*; import android.support.v4.app.*; import android.support.v4.app.NotificationCompat.*; @@ -102,7 +103,7 @@ public class NotificationTray { DeleteHabitsCommand deleteCommand = (DeleteHabitsCommand) command; List deleted = deleteCommand.getHabits(); - for(Habit habit : deleted) + for (Habit habit : deleted) cancel(habit); } } @@ -191,9 +192,24 @@ public class NotificationTray if (!shouldShowReminderToday()) return; if (!habit.hasReminder()) return; - WearableExtender wearableExtender = - new WearableExtender().setBackground( - decodeResource(context.getResources(), R.drawable.stripe)); + Action checkAction = new Action(R.drawable.ic_action_check, + context.getString(R.string.check), + pendingIntents.addCheckmark(habit, timestamp)); + + Action snoozeAction = new Action(R.drawable.ic_action_snooze, + context.getString(R.string.snooze), + pendingIntents.snoozeNotification(habit)); + + Bitmap wearableBg = + decodeResource(context.getResources(), R.drawable.stripe); + + // Even though the set of actions is the same on the phone and + // on the watch, Pebble requires us to add them to the + // WearableExtender. + WearableExtender wearableExtender = new WearableExtender() + .setBackground(wearableBg) + .addAction(checkAction) + .addAction(snoozeAction); Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notification) @@ -201,12 +217,8 @@ public class NotificationTray .setContentText(habit.getDescription()) .setContentIntent(pendingIntents.showHabit(habit)) .setDeleteIntent(pendingIntents.dismissNotification(habit)) - .addAction(R.drawable.ic_action_check, - context.getString(R.string.check), - pendingIntents.addCheckmark(habit, timestamp)) - .addAction(R.drawable.ic_action_snooze, - context.getString(R.string.snooze), - pendingIntents.snoozeNotification(habit)) + .addAction(checkAction) + .addAction(snoozeAction) .setSound(getRingtoneUri(context)) .extend(wearableExtender) .setWhen(reminderTime)