From e3c78861c6fc2490fceb113ef78809b8380edd59 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Thu, 8 Sep 2016 23:07:24 -0700 Subject: [PATCH] Fix multiple timer notifications from all clearing when first timer to launch cancels all of them. Prevent setting negative durations for ProgressBar animator. --- .../clock2/timers/TimerNotificationService.java | 11 +++++------ .../com/philliphsu/clock2/timers/TimesUpActivity.java | 3 --- .../com/philliphsu/clock2/util/ProgressBarUtils.java | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/philliphsu/clock2/timers/TimerNotificationService.java b/app/src/main/java/com/philliphsu/clock2/timers/TimerNotificationService.java index 9eaab50..62a532c 100644 --- a/app/src/main/java/com/philliphsu/clock2/timers/TimerNotificationService.java +++ b/app/src/main/java/com/philliphsu/clock2/timers/TimerNotificationService.java @@ -36,12 +36,12 @@ public class TimerNotificationService extends Service { public static final String EXTRA_TIMER = "com.philliphsu.clock2.timers.extra.TIMER"; - private Timer mTimer; + private Timer mTimer; // TODO: I think we may need a list of timers. private TimerController mController; private NotificationCompat.Builder mNoteBuilder; private NotificationManager mNotificationManager; private final CountdownDelegate mCountdownDelegate = new CountdownDelegate(); - private MyHandlerThread mThread; + private MyHandlerThread mThread; // TODO: I think we may need a list of threads. /** * Helper method to start this Service for its default action: to show @@ -62,9 +62,9 @@ public class TimerNotificationService extends Service { * you want to cancel */ public static void cancelNotification(Context context, long timerId) { // TODO: remove long param -// NotificationManager nm = (NotificationManager) -// context.getSystemService(Context.NOTIFICATION_SERVICE); -// nm.cancel(TAG, (int) timerId); + NotificationManager nm = (NotificationManager) + context.getSystemService(Context.NOTIFICATION_SERVICE); + nm.cancel(TAG, (int) timerId); context.stopService(new Intent(context, TimerNotificationService.class)); } @@ -99,7 +99,6 @@ public class TimerNotificationService extends Service { @Override public void onDestroy() { super.onDestroy(); - mNotificationManager.cancelAll(); quitThread(); } diff --git a/app/src/main/java/com/philliphsu/clock2/timers/TimesUpActivity.java b/app/src/main/java/com/philliphsu/clock2/timers/TimesUpActivity.java index 9f1ec1b..f4d200c 100644 --- a/app/src/main/java/com/philliphsu/clock2/timers/TimesUpActivity.java +++ b/app/src/main/java/com/philliphsu/clock2/timers/TimesUpActivity.java @@ -2,7 +2,6 @@ package com.philliphsu.clock2.timers; import android.app.Notification; import android.app.NotificationManager; -import android.content.Intent; import android.os.Bundle; import android.os.SystemClock; import android.support.v4.app.NotificationCompat; @@ -23,8 +22,6 @@ public class TimesUpActivity extends RingtoneActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - stopService(new Intent(this, TimerNotificationService.class)); - // TODO: Consider calling this in the service's onDestroy() TimerNotificationService.cancelNotification(this, getRingingObject().getId()); mController = new TimerController(getRingingObject(), new AsyncTimersTableUpdateHandler(this, null)); diff --git a/app/src/main/java/com/philliphsu/clock2/util/ProgressBarUtils.java b/app/src/main/java/com/philliphsu/clock2/util/ProgressBarUtils.java index 94aa590..b8ec867 100644 --- a/app/src/main/java/com/philliphsu/clock2/util/ProgressBarUtils.java +++ b/app/src/main/java/com/philliphsu/clock2/util/ProgressBarUtils.java @@ -37,7 +37,7 @@ public class ProgressBarUtils { // have hardcoded this animator to be a "countdown" progress bar. This is // sufficient for our current needs. progress, 0); - animator.setDuration(duration); + animator.setDuration(duration < 0 ? 0 : duration); // The algorithm that calculates intermediate values between keyframes. We use linear // interpolation so that the animation runs at constant speed. animator.setInterpolator(null/*results in linear interpolation*/);