OSDN Git Service

Adds hooks to DeskClock so that other programs may kill or
[android-x86/packages-apps-DeskClock.git] / src / com / android / deskclock / AlarmAlertFullScreen.java
index 1a43d25..643b3ad 100644 (file)
@@ -55,13 +55,21 @@ public class AlarmAlertFullScreen extends Activity {
     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) {
-            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);
+                }
             }
         }
     };
@@ -88,13 +96,17 @@ public class AlarmAlertFullScreen extends Activity {
         // subclass.
         if (!getIntent().getBooleanExtra(SCREEN_OFF, false)) {
             win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
-                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
+                    | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
         }
 
         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() {
@@ -108,20 +120,6 @@ public class AlarmAlertFullScreen extends Activity {
 
         setContentView(inflater.inflate(R.layout.alarm_alert, null));
 
-        /* set clock face */
-        SharedPreferences settings =
-                getSharedPreferences(AlarmClock.PREFERENCES, 0);
-        int face = settings.getInt(AlarmClock.PREF_CLOCK_FACE, 0);
-        if (face < 0 || face >= AlarmClock.CLOCKS.length) {
-            face = 0;
-        }
-        ViewGroup clockView = (ViewGroup) findViewById(R.id.clockView);
-        inflater.inflate(AlarmClock.CLOCKS[face], clockView);
-        View clockLayout = findViewById(R.id.clock);
-        if (clockLayout instanceof DigitalClock) {
-            ((DigitalClock) clockLayout).setAnimate();
-        }
-
         /* snooze behavior: pop a snooze confirmation view, kick alarm
            manager. */
         Button snooze = (Button) findViewById(R.id.snooze);
@@ -146,6 +144,11 @@ public class AlarmAlertFullScreen extends Activity {
 
     // Attempt to snooze this alert.
     private void snooze() {
+        // Do not snooze if the snooze button is disabled.
+        if (!findViewById(R.id.snooze).isEnabled()) {
+            dismiss(false);
+            return;
+        }
         final String snooze =
                 PreferenceManager.getDefaultSharedPreferences(this)
                 .getString(SettingsActivity.KEY_ALARM_SNOOZE, DEFAULT_SNOOZE);
@@ -176,8 +179,8 @@ public class AlarmAlertFullScreen extends Activity {
         n.setLatestEventInfo(this, label,
                 getString(R.string.alarm_notify_snooze_text,
                     Alarms.formatTime(this, c)), broadcast);
-        n.deleteIntent = broadcast;
-        n.flags |= Notification.FLAG_AUTO_CANCEL;
+        n.flags |= Notification.FLAG_AUTO_CANCEL
+                | Notification.FLAG_ONGOING_EVENT;
         nm.notify(mAlarm.id, n);
 
         String displayTime = getString(R.string.alarm_alert_snooze_set,
@@ -198,6 +201,7 @@ public class AlarmAlertFullScreen extends Activity {
 
     // 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) {
@@ -225,6 +229,16 @@ public class AlarmAlertFullScreen extends Activity {
     }
 
     @Override
+    protected void onResume() {
+        super.onResume();
+        // If the alarm was deleted at some point, disable snooze.
+        if (Alarms.getAlarm(getContentResolver(), mAlarm.id) == null) {
+            Button snooze = (Button) findViewById(R.id.snooze);
+            snooze.setEnabled(false);
+        }
+    }
+
+    @Override
     protected void onStop() {
         super.onStop();
         if (!isFinishing()) {