Loading AndroidManifest.xml +4 −0 Original line number Diff line number Diff line Loading @@ -235,6 +235,10 @@ <action android:name="timer_update" /> <action android:name="notif_in_use_show" /> <action android:name="notif_in_use_cancel" /> <action android:name="notif_times_up_stop" /> <action android:name="notif_times_up_plus_one" /> <action android:name="notif_times_up_show" /> <action android:name="notif_times_up_cancel" /> </intent-filter> </receiver> Loading res/values/strings.xml +2 −0 Original line number Diff line number Diff line Loading @@ -450,6 +450,8 @@ <string name="timer_delete">Delete</string> <!-- Describes the purpose of the button increase the remaining time on a timer by one minute. --> <string name="timer_plus_one">Add 1 Minute</string> <!-- Like "timer_plus_one", but with 'minute' abbreviated for the notification. --> <string name="timer_plus_1_min">Add 1 min</string> <!-- Describes the purpose of the button to stop the timer. --> <string name="timer_stop">Stop</string> <!-- Describes the purpose of the button to stop and delete the timer. --> Loading src/com/android/deskclock/Utils.java +18 −0 Original line number Diff line number Diff line Loading @@ -217,6 +217,24 @@ public class Utils { context.sendBroadcast(timerIntent); } /** * Broadcast a message to show the in-use timers in the notifications */ public static void showTimesUpNotifications(Context context) { Intent timerIntent = new Intent(); timerIntent.setAction(Timers.NOTIF_TIMES_UP_SHOW); context.sendBroadcast(timerIntent); } /** * Broadcast a message to cancel the in-use timers in the notifications */ public static void cancelTimesUpNotifications(Context context) { Intent timerIntent = new Intent(); timerIntent.setAction(Timers.NOTIF_TIMES_UP_CANCEL); context.sendBroadcast(timerIntent); } /** Runnable for use with screensaver and dream, to move the clock every minute. * registerViews() must be called prior to posting. */ Loading src/com/android/deskclock/timer/TimerAlertFullScreen.java +21 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import android.app.Activity; import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; Loading @@ -31,10 +32,11 @@ import com.android.deskclock.timer.TimerFragment.OnEmptyListListener; /** * Timer alarm alert: pops visible indicator. This activity is the version which * shows over the lock screen. * This activity re-uses TimerFragment GUI */ public class TimerAlertFullScreen extends Activity implements OnEmptyListListener { // private static final String TAG = "TimerAlertFullScreen"; private static final String TAG = "TimerAlertFullScreen"; private static final String FRAGMENT = "timer"; @Override Loading Loading @@ -71,6 +73,21 @@ public class TimerAlertFullScreen extends Activity implements OnEmptyListListene } } @Override protected void onResume() { super.onResume(); // Only show notifications for times-up when this activity closed. Utils.cancelTimesUpNotifications(this); } @Override public void onPause() { Utils.showTimesUpNotifications(this); super.onPause(); } @Override public boolean dispatchKeyEvent(KeyEvent event) { // Handle key down and key up on a few of the system keys. Loading Loading @@ -127,6 +144,9 @@ public class TimerAlertFullScreen extends Activity implements OnEmptyListListene @Override public void onEmptyList() { if (Timers.LOGGING) { Log.v(TAG, "onEmptyList"); } onListChanged(); finish(); } Loading src/com/android/deskclock/timer/TimerFragment.java +12 −45 Original line number Diff line number Diff line Loading @@ -566,23 +566,15 @@ public class TimerFragment extends DeskClockFragment } if (mPrefs.getBoolean(Timers.FROM_NOTIFICATION, false)) { // We need to know if this onresume is being called by the user clicking a // buzzing timer notification. If so, we need to set that timer to have "stopped" // at the moment the notification was hit. long now = mPrefs.getLong(Timers.NOTIF_TIME, Utils.getTimeNow()); int timerId = mPrefs.getInt(Timers.NOTIF_ID, -1); if (timerId != -1) { TimerObj t = Timers.findTimer(mAdapter.mTimers, timerId); t.mTimeLeft = t.mOriginalLength - (now - t.mStartTime); cancelTimerNotification(timerId); } // Clear the flag set in the notification because the adapter was just // created and is thus in sync with the database SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean(Timers.FROM_NOTIFICATION, false); editor.apply(); } if (mPrefs.getBoolean(Timers.FROM_ALERT, false)) { // Clear the flag set in the alert because the adapter was just // created and thusly in sync with the database // created and is thus in sync with the database SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean(Timers.FROM_ALERT, false); editor.apply(); Loading Loading @@ -622,7 +614,7 @@ public class TimerFragment extends DeskClockFragment // a fraction of a second. View v = getView(); if (v != null) { getView().setVisibility(View.INVISIBLE); v.setVisibility(View.INVISIBLE); } } Loading Loading @@ -904,11 +896,7 @@ public class TimerFragment extends DeskClockFragment public void setLabel(TimerObj timer, String label) { mAdapter.getItem(mAdapter.findTimerPositionById(timer.mTimerId)).mLabel = label; if (timer.mState == TimerObj.STATE_TIMESUP) { // Timer is in times-up mode. TimerReceiver.showExpiredAlarmNotification( getActivity().getApplicationContext(), timer); } updateTimersState(timer, Timers.TIMER_UPDATE); // Make sure the new label is visible. mAdapter.notifyDataSetChanged(); } Loading Loading @@ -1052,34 +1040,13 @@ public class TimerFragment extends DeskClockFragment @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (prefs.equals(mPrefs)) { if ( (key.equals(Timers.FROM_NOTIFICATION) || key.equals(Timers.NOTIF_ID) || key.equals(Timers.NOTIF_TIME)) && prefs.getBoolean(Timers.FROM_NOTIFICATION, false) ) { // We need to know if the user has clicked the buzzing timer notification // while the fragment is still open. If so, this listener will catch that event, // and allow the timers to be re-instated based on the updated stop time. // Because this method gets called with every change to the sharedprefs, we ensure // that we only recalculate the timers if the change was specifically set by the // user interacting with the notification. long now = prefs.getLong(Timers.NOTIF_TIME, Utils.getTimeNow()); int timerId = prefs.getInt(Timers.NOTIF_ID, -1); mAdapter = createAdapter(getActivity(), mPrefs); mAdapter.onRestoreInstanceState(null); if (timerId != -1) { TimerObj t = Timers.findTimer(mAdapter.mTimers, timerId); t.mTimeLeft = t.mOriginalLength - (now - t.mStartTime); cancelTimerNotification(timerId); } mTimersList.setAdapter(mAdapter); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(Timers.FROM_NOTIFICATION, false); editor.apply(); } if (key.equals(Timers.FROM_ALERT) && prefs.getBoolean(Timers.FROM_ALERT, false)) { // The flag was set in the alert so the adapter needs to re-sync // with the database SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(Timers.FROM_ALERT, false); if ((key.equals(Timers.FROM_ALERT) && prefs.getBoolean(Timers.FROM_ALERT, false)) || (key.equals(Timers.FROM_NOTIFICATION) && prefs.getBoolean(Timers.FROM_NOTIFICATION, false))) { // The data-changed flag was set in the alert or notification so the adapter needs // to re-sync with the database SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean(key, false); editor.apply(); mAdapter = createAdapter(getActivity(), mPrefs); mAdapter.onRestoreInstanceState(null); Loading Loading
AndroidManifest.xml +4 −0 Original line number Diff line number Diff line Loading @@ -235,6 +235,10 @@ <action android:name="timer_update" /> <action android:name="notif_in_use_show" /> <action android:name="notif_in_use_cancel" /> <action android:name="notif_times_up_stop" /> <action android:name="notif_times_up_plus_one" /> <action android:name="notif_times_up_show" /> <action android:name="notif_times_up_cancel" /> </intent-filter> </receiver> Loading
res/values/strings.xml +2 −0 Original line number Diff line number Diff line Loading @@ -450,6 +450,8 @@ <string name="timer_delete">Delete</string> <!-- Describes the purpose of the button increase the remaining time on a timer by one minute. --> <string name="timer_plus_one">Add 1 Minute</string> <!-- Like "timer_plus_one", but with 'minute' abbreviated for the notification. --> <string name="timer_plus_1_min">Add 1 min</string> <!-- Describes the purpose of the button to stop the timer. --> <string name="timer_stop">Stop</string> <!-- Describes the purpose of the button to stop and delete the timer. --> Loading
src/com/android/deskclock/Utils.java +18 −0 Original line number Diff line number Diff line Loading @@ -217,6 +217,24 @@ public class Utils { context.sendBroadcast(timerIntent); } /** * Broadcast a message to show the in-use timers in the notifications */ public static void showTimesUpNotifications(Context context) { Intent timerIntent = new Intent(); timerIntent.setAction(Timers.NOTIF_TIMES_UP_SHOW); context.sendBroadcast(timerIntent); } /** * Broadcast a message to cancel the in-use timers in the notifications */ public static void cancelTimesUpNotifications(Context context) { Intent timerIntent = new Intent(); timerIntent.setAction(Timers.NOTIF_TIMES_UP_CANCEL); context.sendBroadcast(timerIntent); } /** Runnable for use with screensaver and dream, to move the clock every minute. * registerViews() must be called prior to posting. */ Loading
src/com/android/deskclock/timer/TimerAlertFullScreen.java +21 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import android.app.Activity; import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; Loading @@ -31,10 +32,11 @@ import com.android.deskclock.timer.TimerFragment.OnEmptyListListener; /** * Timer alarm alert: pops visible indicator. This activity is the version which * shows over the lock screen. * This activity re-uses TimerFragment GUI */ public class TimerAlertFullScreen extends Activity implements OnEmptyListListener { // private static final String TAG = "TimerAlertFullScreen"; private static final String TAG = "TimerAlertFullScreen"; private static final String FRAGMENT = "timer"; @Override Loading Loading @@ -71,6 +73,21 @@ public class TimerAlertFullScreen extends Activity implements OnEmptyListListene } } @Override protected void onResume() { super.onResume(); // Only show notifications for times-up when this activity closed. Utils.cancelTimesUpNotifications(this); } @Override public void onPause() { Utils.showTimesUpNotifications(this); super.onPause(); } @Override public boolean dispatchKeyEvent(KeyEvent event) { // Handle key down and key up on a few of the system keys. Loading Loading @@ -127,6 +144,9 @@ public class TimerAlertFullScreen extends Activity implements OnEmptyListListene @Override public void onEmptyList() { if (Timers.LOGGING) { Log.v(TAG, "onEmptyList"); } onListChanged(); finish(); } Loading
src/com/android/deskclock/timer/TimerFragment.java +12 −45 Original line number Diff line number Diff line Loading @@ -566,23 +566,15 @@ public class TimerFragment extends DeskClockFragment } if (mPrefs.getBoolean(Timers.FROM_NOTIFICATION, false)) { // We need to know if this onresume is being called by the user clicking a // buzzing timer notification. If so, we need to set that timer to have "stopped" // at the moment the notification was hit. long now = mPrefs.getLong(Timers.NOTIF_TIME, Utils.getTimeNow()); int timerId = mPrefs.getInt(Timers.NOTIF_ID, -1); if (timerId != -1) { TimerObj t = Timers.findTimer(mAdapter.mTimers, timerId); t.mTimeLeft = t.mOriginalLength - (now - t.mStartTime); cancelTimerNotification(timerId); } // Clear the flag set in the notification because the adapter was just // created and is thus in sync with the database SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean(Timers.FROM_NOTIFICATION, false); editor.apply(); } if (mPrefs.getBoolean(Timers.FROM_ALERT, false)) { // Clear the flag set in the alert because the adapter was just // created and thusly in sync with the database // created and is thus in sync with the database SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean(Timers.FROM_ALERT, false); editor.apply(); Loading Loading @@ -622,7 +614,7 @@ public class TimerFragment extends DeskClockFragment // a fraction of a second. View v = getView(); if (v != null) { getView().setVisibility(View.INVISIBLE); v.setVisibility(View.INVISIBLE); } } Loading Loading @@ -904,11 +896,7 @@ public class TimerFragment extends DeskClockFragment public void setLabel(TimerObj timer, String label) { mAdapter.getItem(mAdapter.findTimerPositionById(timer.mTimerId)).mLabel = label; if (timer.mState == TimerObj.STATE_TIMESUP) { // Timer is in times-up mode. TimerReceiver.showExpiredAlarmNotification( getActivity().getApplicationContext(), timer); } updateTimersState(timer, Timers.TIMER_UPDATE); // Make sure the new label is visible. mAdapter.notifyDataSetChanged(); } Loading Loading @@ -1052,34 +1040,13 @@ public class TimerFragment extends DeskClockFragment @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (prefs.equals(mPrefs)) { if ( (key.equals(Timers.FROM_NOTIFICATION) || key.equals(Timers.NOTIF_ID) || key.equals(Timers.NOTIF_TIME)) && prefs.getBoolean(Timers.FROM_NOTIFICATION, false) ) { // We need to know if the user has clicked the buzzing timer notification // while the fragment is still open. If so, this listener will catch that event, // and allow the timers to be re-instated based on the updated stop time. // Because this method gets called with every change to the sharedprefs, we ensure // that we only recalculate the timers if the change was specifically set by the // user interacting with the notification. long now = prefs.getLong(Timers.NOTIF_TIME, Utils.getTimeNow()); int timerId = prefs.getInt(Timers.NOTIF_ID, -1); mAdapter = createAdapter(getActivity(), mPrefs); mAdapter.onRestoreInstanceState(null); if (timerId != -1) { TimerObj t = Timers.findTimer(mAdapter.mTimers, timerId); t.mTimeLeft = t.mOriginalLength - (now - t.mStartTime); cancelTimerNotification(timerId); } mTimersList.setAdapter(mAdapter); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(Timers.FROM_NOTIFICATION, false); editor.apply(); } if (key.equals(Timers.FROM_ALERT) && prefs.getBoolean(Timers.FROM_ALERT, false)) { // The flag was set in the alert so the adapter needs to re-sync // with the database SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(Timers.FROM_ALERT, false); if ((key.equals(Timers.FROM_ALERT) && prefs.getBoolean(Timers.FROM_ALERT, false)) || (key.equals(Timers.FROM_NOTIFICATION) && prefs.getBoolean(Timers.FROM_NOTIFICATION, false))) { // The data-changed flag was set in the alert or notification so the adapter needs // to re-sync with the database SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean(key, false); editor.apply(); mAdapter = createAdapter(getActivity(), mPrefs); mAdapter.onRestoreInstanceState(null); Loading