OSDN Git Service

Adds hooks to DeskClock so that other programs may kill or
authorDavid Ingram <davidi@google.com>
Mon, 1 Mar 2010 15:34:38 +0000 (15:34 +0000)
committerDavid Ingram <davidi@google.com>
Mon, 1 Mar 2010 17:03:39 +0000 (17:03 +0000)
snooze a ringing alarm, and also a broadcast intent to
inform interested parties when the alarm has been dismissed.

Change-Id: I491c3a24a6bac33025665c799c76a743010e9761

src/com/android/deskclock/AlarmAlertFullScreen.java
src/com/android/deskclock/AlarmKlaxon.java
src/com/android/deskclock/Alarms.java
src/com/android/deskclock/Log.java

index 89b82ca..643b3ad 100644 (file)
@@ -55,13 +55,21 @@ public class AlarmAlertFullScreen extends Activity {
     protected Alarm mAlarm;
     private int mVolumeBehavior;
 
     protected Alarm mAlarm;
     private int mVolumeBehavior;
 
-    // Receives the ALARM_KILLED action from the AlarmKlaxon.
+    // Receives the ALARM_KILLED action from the AlarmKlaxon,
+    // and also ALARM_SNOOZE_ACTION / ALARM_DISMISS_ACTION from other applications
     private BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
     private BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            Alarm alarm = intent.getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);
-            if (alarm != null && mAlarm.id == alarm.id) {
-                dismiss(true);
+            String action = intent.getAction();
+            if (action.equals(Alarms.ALARM_SNOOZE_ACTION)) {
+                snooze();
+            } else if (action.equals(Alarms.ALARM_DISMISS_ACTION)) {
+                dismiss(false);
+            } else {
+                Alarm alarm = intent.getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);
+                if (alarm != null && mAlarm.id == alarm.id) {
+                    dismiss(true);
+                }
             }
         }
     };
             }
         }
     };
@@ -94,8 +102,11 @@ public class AlarmAlertFullScreen extends Activity {
 
         updateLayout();
 
 
         updateLayout();
 
-        // Register to get the alarm killed intent.
-        registerReceiver(mReceiver, new IntentFilter(Alarms.ALARM_KILLED));
+        // Register to get the alarm killed/snooze/dismiss intent.
+        IntentFilter filter = new IntentFilter(Alarms.ALARM_KILLED);
+        filter.addAction(Alarms.ALARM_SNOOZE_ACTION);
+        filter.addAction(Alarms.ALARM_DISMISS_ACTION);
+        registerReceiver(mReceiver, filter);
     }
 
     private void setTitle() {
     }
 
     private void setTitle() {
@@ -190,6 +201,7 @@ public class AlarmAlertFullScreen extends Activity {
 
     // Dismiss the alarm.
     private void dismiss(boolean killed) {
 
     // Dismiss the alarm.
     private void dismiss(boolean killed) {
+        Log.i(killed ? "Alarm killed" : "Alarm dismissed by user");
         // The service told us that the alarm has been killed, do not modify
         // the notification or stop the service.
         if (!killed) {
         // The service told us that the alarm has been killed, do not modify
         // the notification or stop the service.
         if (!killed) {
index 3c3543c..38098c8 100644 (file)
@@ -259,6 +259,9 @@ public class AlarmKlaxon extends Service {
         if (mPlaying) {
             mPlaying = false;
 
         if (mPlaying) {
             mPlaying = false;
 
+            Intent alarmDone = new Intent(Alarms.ALARM_DONE_ACTION);
+            sendBroadcast(alarmDone);
+
             // Stop audio playing
             if (mMediaPlayer != null) {
                 mMediaPlayer.stop();
             // Stop audio playing
             if (mMediaPlayer != null) {
                 mMediaPlayer.stop();
index 69047a0..1e331a2 100644 (file)
@@ -44,6 +44,19 @@ public class Alarms {
     // from the alarm manager.
     public static final String ALARM_ALERT_ACTION = "com.android.deskclock.ALARM_ALERT";
 
     // from the alarm manager.
     public static final String ALARM_ALERT_ACTION = "com.android.deskclock.ALARM_ALERT";
 
+    // A public action sent by AlarmKlaxon when the alarm has stopped sounding
+    // for any reason (e.g. because it has been dismissed from AlarmAlertFullScreen,
+    // or killed due to an incoming phone call, etc).
+    public static final String ALARM_DONE_ACTION = "com.android.deskclock.ALARM_DONE";
+
+    // AlarmAlertFullScreen listens for this broadcast intent, so that other applications
+    // can snooze the alarm (after ALARM_ALERT_ACTION and before ALARM_DONE_ACTION).
+    public static final String ALARM_SNOOZE_ACTION = "com.android.deskclock.ALARM_SNOOZE";
+
+    // AlarmAlertFullScreen listens for this broadcast intent, so that other applications
+    // can dismiss the alarm (after ALARM_ALERT_ACTION and before ALARM_DONE_ACTION).
+    public static final String ALARM_DISMISS_ACTION = "com.android.deskclock.ALARM_DISMISS";
+
     // This is a private action used by the AlarmKlaxon to update the UI to
     // show the alarm has been killed.
     public static final String ALARM_KILLED = "alarm_killed";
     // This is a private action used by the AlarmKlaxon to update the UI to
     // show the alarm has been killed.
     public static final String ALARM_KILLED = "alarm_killed";
index 7e128b9..6749caa 100644 (file)
@@ -32,6 +32,10 @@ class Log {
         android.util.Log.v(LOGTAG, /* SystemClock.uptimeMillis() + " " + */ logMe);
     }
 
         android.util.Log.v(LOGTAG, /* SystemClock.uptimeMillis() + " " + */ logMe);
     }
 
+    static void i(String logMe) {
+        android.util.Log.i(LOGTAG, logMe);
+    }
+
     static void e(String logMe) {
         android.util.Log.e(LOGTAG, logMe);
     }
     static void e(String logMe) {
         android.util.Log.e(LOGTAG, logMe);
     }