OSDN Git Service

am d1373322: Landscape layout for DeskClock.
authorDaniel Sandler <dsandler@google.com>
Wed, 28 Oct 2009 18:41:17 +0000 (11:41 -0700)
committerAndroid Git Automerger <android-git-automerger@android.com>
Wed, 28 Oct 2009 18:41:17 +0000 (11:41 -0700)
Merge commit 'd13733225cb1a3e16413b35336e94e400bf5d399' into eclair-mr2

* commit 'd13733225cb1a3e16413b35336e94e400bf5d399':
  Landscape layout for DeskClock.

res/layout/analog_appwidget.xml
res/values-ko/strings.xml
res/values-pt/strings.xml
res/values-zh-rCN/strings.xml
src/com/android/deskclock/AlarmAlert.java
src/com/android/deskclock/AlarmAlertFullScreen.java
src/com/android/deskclock/AlarmClock.java
src/com/android/deskclock/AnalogAppWidgetProvider.java
src/com/android/deskclock/SetAlarm.java

index 7a32477..6a10611 100644 (file)
@@ -15,6 +15,7 @@
 -->
 
 <AnalogClock xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/analog_appwidget"
     android:dial="@drawable/appwidget_clock_dial"
     android:hand_hour="@drawable/appwidget_clock_hour"
     android:hand_minute="@drawable/appwidget_clock_minute"
index 43373f9..067b051 100644 (file)
@@ -15,7 +15,7 @@
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="6642875149600019623">"알람 시계"</string>
+    <string name="app_label" msgid="6642875149600019623">"알람"</string>
     <string name="add_alarm" msgid="5976616107390962899">"알람 추가"</string>
     <string name="delete_alarm" msgid="3457780990646206817">"알람 삭제"</string>
     <string name="enable_alarm" msgid="7442658245797418741">"알람 사용"</string>
index c38c141..a21cf86 100644 (file)
@@ -56,7 +56,7 @@
     <string name="clock_instructions" msgid="3118560284915857690">"Selecione um relógio para exibir."</string>
     <string name="analog_gadget" msgid="1670505720837152766">"Relógio analógico"</string>
     <string name="settings" msgid="5849739030579520686">"Configurações"</string>
-    <string name="alarm_in_silent_mode_title" msgid="3892612644543516705">"Alarme no modo silencioso"</string>
+    <string name="alarm_in_silent_mode_title" msgid="3892612644543516705">"Modo silencioso"</string>
     <string name="alarm_in_silent_mode_summary" msgid="6042500263899922832">"Tocar o alarme mesmo quando o telefone estiver no modo silencioso"</string>
     <string name="snooze_duration_title" msgid="1471249885139952670">"Duração do modo de espera"</string>
   <string-array name="snooze_duration_entries">
index 78255d3..477ff40 100644 (file)
     <string name="alert" msgid="6539852766423700221">"铃声"</string>
     <string name="time" msgid="8067216534232296518">"时间"</string>
     <string name="alarm_alert_dismiss_text" msgid="4942914605480888820">"关闭"</string>
-    <string name="alarm_alert_alert_silenced" msgid="7918075929961104202">"闹钟响铃时间为 <xliff:g id="MINUTES">%d</xliff:g> 分钟"</string>
+    <string name="alarm_alert_alert_silenced" msgid="7918075929961104202">"闹钟提示已过 <xliff:g id="MINUTES">%d</xliff:g> 分钟"</string>
     <string name="alarm_alert_snooze_text" msgid="1774416052207651584">"暂停"</string>
     <string name="alarm_alert_snooze_set" msgid="656470966696912087">"暂停 <xliff:g id="MINUTES">%d</xliff:g> 分钟。"</string>
   <string-array name="alarm_set">
-    <item msgid="5163476010406761625">"已将此闹钟设置为从现在起不到 1 分钟后提醒。"</item>
-    <item msgid="7110525731259629055">"已将此闹钟设置为从现在起 <xliff:g id="DAYS">%1$s</xliff:g>后提醒。"</item>
-    <item msgid="7003982794086186185">"已将此闹钟设置为从现在起 <xliff:g id="HOURS">%2$s</xliff:g>后提醒。"</item>
-    <item msgid="7311021123230077742">"已将此闹钟设置为从现在起 <xliff:g id="DAYS">%1$s</xliff:g> <xliff:g id="HOURS">%2$s</xliff:g>后提醒。"</item>
-    <item msgid="8431715191823114872">"已将此闹钟设置为从现在起 <xliff:g id="MINUTES">%3$s</xliff:g>后提醒。"</item>
-    <item msgid="3244151088673185428">"已将此闹钟设置为从现在起 <xliff:g id="DAYS">%1$s</xliff:g> <xliff:g id="MINUTES">%3$s</xliff:g>后提醒。"</item>
-    <item msgid="3663661342600168814">"已将此闹钟设置为从现在起 <xliff:g id="HOURS">%2$s</xliff:g> <xliff:g id="MINUTES">%3$s</xliff:g>后提醒。"</item>
-    <item msgid="7779544127785487304">"已将该闹钟设置为从现在起 <xliff:g id="DAYS">%1$s</xliff:g> <xliff:g id="HOURS">%2$s</xliff:g> <xliff:g id="MINUTES">%3$s</xliff:g>后提醒。"</item>
+    <item msgid="5163476010406761625">"已将此闹钟设置为从现在起不到 1 分钟后提醒。"</item>
+    <item msgid="7110525731259629055">"已将此闹钟设置为从现在起 <xliff:g id="DAYS">%1$s</xliff:g>后提醒。"</item>
+    <item msgid="7003982794086186185">"已将此闹钟设置为从现在起 <xliff:g id="HOURS">%2$s</xliff:g>后提醒。"</item>
+    <item msgid="7311021123230077742">"已将此闹钟设置为从现在起 <xliff:g id="DAYS">%1$s</xliff:g> <xliff:g id="HOURS">%2$s</xliff:g>后提醒。"</item>
+    <item msgid="8431715191823114872">"已将此闹钟设置为从现在起 <xliff:g id="MINUTES">%3$s</xliff:g>后提醒。"</item>
+    <item msgid="3244151088673185428">"已将此闹钟设置为从现在起 <xliff:g id="DAYS">%1$s</xliff:g> <xliff:g id="MINUTES">%3$s</xliff:g>后提醒。"</item>
+    <item msgid="3663661342600168814">"已将此闹钟设置为从现在起 <xliff:g id="HOURS">%2$s</xliff:g> <xliff:g id="MINUTES">%3$s</xliff:g>后提醒。"</item>
+    <item msgid="7779544127785487304">"已将该闹钟设置为从现在起 <xliff:g id="DAYS">%1$s</xliff:g> <xliff:g id="HOURS">%2$s</xliff:g> <xliff:g id="MINUTES">%3$s</xliff:g>后提醒。"</item>
   </string-array>
     <string name="day" msgid="7984755014526510295">"1 天"</string>
     <string name="days" msgid="2070509222727852210">"<xliff:g id="DAYS">%s</xliff:g> 天"</string>
index 8abbd71..72b8a3b 100644 (file)
 
 package com.android.deskclock;
 
-import android.app.Activity;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.Context;
+import android.app.KeyguardManager;
 import android.content.BroadcastReceiver;
+import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.SharedPreferences;
-import android.content.res.Configuration;
 import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.view.KeyEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.LayoutInflater;
-import android.view.Window;
+import android.os.Handler;
+import android.os.Message;
 import android.view.WindowManager;
-import android.widget.Button;
-import android.widget.Toast;
-import android.widget.TextView;
-
-import java.util.Calendar;
 
 /**
- * Alarm Clock alarm alert: pops visible indicator and plays alarm
- * tone
+ * Full screen alarm alert: pops visible indicator and plays alarm tone. This
+ * activity shows the alert as a dialog.
  */
-public class AlarmAlert extends Activity {
-
-    // These defaults must match the values in res/xml/settings.xml
-    private static final String DEFAULT_SNOOZE = "10";
-    private static final String DEFAULT_VOLUME_BEHAVIOR = "2";
+public class AlarmAlert extends AlarmAlertFullScreen {
 
-    private Alarm mAlarm;
-    private int mVolumeBehavior;
+    // If we try to check the keyguard more than 5 times, just launch the full
+    // screen activity.
+    private int mKeyguardRetryCount;
+    private final int MAX_KEYGUARD_CHECKS = 5;
 
-    // Receives the ALARM_KILLED action from the AlarmKlaxon.
-    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+    private final Handler mHandler = new Handler() {
         @Override
-        public void onReceive(Context context, Intent intent) {
-            Alarm alarm = intent.getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);
-            if (mAlarm.id == alarm.id) {
-                dismiss(true);
-            }
+        public void handleMessage(Message msg) {
+            handleScreenOff((KeyguardManager) msg.obj);
         }
     };
 
+    private final BroadcastReceiver mScreenOffReceiver =
+            new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    KeyguardManager km =
+                            (KeyguardManager) context.getSystemService(
+                            Context.KEYGUARD_SERVICE);
+                    handleScreenOff(km);
+                }
+            };
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
-        mAlarm = getIntent().getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);
-
-        // Get the volume/camera button behavior setting
-        final String vol =
-                PreferenceManager.getDefaultSharedPreferences(this)
-                .getString(SettingsActivity.KEY_VOLUME_BEHAVIOR,
-                        DEFAULT_VOLUME_BEHAVIOR);
-        mVolumeBehavior = Integer.parseInt(vol);
-
-        requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
-        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
-                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
-                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
-                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
-        updateLayout();
-
-        // Register to get the alarm killed intent.
-        registerReceiver(mReceiver, new IntentFilter(Alarms.ALARM_KILLED));
-    }
-
-    private void setTitle() {
-        String label = mAlarm.getLabelOrDefault(this);
-        TextView title = (TextView) findViewById(R.id.alertTitle);
-        title.setText(label);
-    }
-
-    // This method is overwritten in AlarmAlertFullScreen in order to show a
-    // full activity with the wallpaper as the background.
-    protected View inflateView(LayoutInflater inflater) {
-        return inflater.inflate(R.layout.alarm_alert, null);
+        // Listen for the screen turning off so that when the screen comes back
+        // on, the user does not need to unlock the phone to dismiss the alarm.
+        registerReceiver(mScreenOffReceiver,
+                new IntentFilter(Intent.ACTION_SCREEN_OFF));
     }
 
-    private void updateLayout() {
-        LayoutInflater inflater = LayoutInflater.from(this);
-
-        setContentView(inflateView(inflater));
-
-        /* snooze behavior: pop a snooze confirmation view, kick alarm
-           manager. */
-        Button snooze = (Button) findViewById(R.id.snooze);
-        snooze.requestFocus();
-        snooze.setOnClickListener(new Button.OnClickListener() {
-            public void onClick(View v) {
-                snooze();
-            }
-        });
-
-        /* dismiss button: close notification */
-        findViewById(R.id.dismiss).setOnClickListener(
-                new Button.OnClickListener() {
-                    public void onClick(View v) {
-                        dismiss(false);
-                    }
-                });
-
-        /* Set the title from the passed in alarm */
-        setTitle();
-    }
-
-    // Attempt to snooze this alert.
-    private void snooze() {
-        final String snooze =
-                PreferenceManager.getDefaultSharedPreferences(this)
-                .getString(SettingsActivity.KEY_ALARM_SNOOZE, DEFAULT_SNOOZE);
-        int snoozeMinutes = Integer.parseInt(snooze);
-
-        final long snoozeTime = System.currentTimeMillis()
-                + (1000 * 60 * snoozeMinutes);
-        Alarms.saveSnoozeAlert(AlarmAlert.this, mAlarm.id, snoozeTime);
-
-        // Get the display time for the snooze and update the notification.
-        final Calendar c = Calendar.getInstance();
-        c.setTimeInMillis(snoozeTime);
-
-        // Append (snoozed) to the label.
-        String label = mAlarm.getLabelOrDefault(this);
-        label = getString(R.string.alarm_notify_snooze_label, label);
-
-        // Notify the user that the alarm has been snoozed.
-        Intent cancelSnooze = new Intent(this, AlarmReceiver.class);
-        cancelSnooze.setAction(Alarms.CANCEL_SNOOZE);
-        cancelSnooze.putExtra(Alarms.ALARM_ID, mAlarm.id);
-        PendingIntent broadcast =
-                PendingIntent.getBroadcast(this, mAlarm.id, cancelSnooze, 0);
-        NotificationManager nm = getNotificationManager();
-        Notification n = new Notification(R.drawable.stat_notify_alarm,
-                label, 0);
-        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;
-        nm.notify(mAlarm.id, n);
-
-        String displayTime = getString(R.string.alarm_alert_snooze_set,
-                snoozeMinutes);
-        // Intentionally log the snooze time for debugging.
-        Log.v(displayTime);
-
-        // Display the snooze minutes in a toast.
-        Toast.makeText(AlarmAlert.this, displayTime, Toast.LENGTH_LONG).show();
-        stopService(new Intent(Alarms.ALARM_ALERT_ACTION));
-        finish();
-    }
-
-    private NotificationManager getNotificationManager() {
-        return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-    }
-
-    // Dismiss the alarm.
-    private void dismiss(boolean killed) {
-        // The service told us that the alarm has been killed, do not modify
-        // the notification or stop the service.
-        if (!killed) {
-            // Cancel the notification and stop playing the alarm
-            NotificationManager nm = getNotificationManager();
-            nm.cancel(mAlarm.id);
-            stopService(new Intent(Alarms.ALARM_ALERT_ACTION));
-        }
-        finish();
-    }
-
-    /**
-     * this is called when a second alarm is triggered while a
-     * previous alert window is still active.
-     */
-    @Override
-    protected void onNewIntent(Intent intent) {
-        super.onNewIntent(intent);
-
-        if (Log.LOGV) Log.v("AlarmAlert.OnNewIntent()");
-
-        mAlarm = intent.getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);
-
-        setTitle();
-    }
-
-    @Override
-    protected void onStop() {
-        super.onStop();
-        // Don't hang around.
-        finish();
-    }
-    
     @Override
     public void onDestroy() {
         super.onDestroy();
-        if (Log.LOGV) Log.v("AlarmAlert.onDestroy()");
-        // No longer care about the alarm being killed.
-        unregisterReceiver(mReceiver);
+        unregisterReceiver(mScreenOffReceiver);
+        // Remove any of the keyguard messages just in case
+        mHandler.removeMessages(0);
     }
 
     @Override
-    public boolean dispatchKeyEvent(KeyEvent event) {
-        // Do this on key down to handle a few of the system keys.
-        boolean up = event.getAction() == KeyEvent.ACTION_UP;
-        switch (event.getKeyCode()) {
-            // Volume keys and camera keys dismiss the alarm
-            case KeyEvent.KEYCODE_VOLUME_UP:
-            case KeyEvent.KEYCODE_VOLUME_DOWN:
-            case KeyEvent.KEYCODE_CAMERA:
-            case KeyEvent.KEYCODE_FOCUS:
-                if (up) {
-                    switch (mVolumeBehavior) {
-                        case 1:
-                            snooze();
-                            break;
+    public void onBackPressed() {
+        finish();
+    }
 
-                        case 2:
-                            dismiss(false);
-                            break;
+    private boolean checkRetryCount() {
+        if (mKeyguardRetryCount++ >= MAX_KEYGUARD_CHECKS) {
+            Log.e("Tried to read keyguard status too many times, bailing...");
+            return false;
+        }
+        return true;
+    }
 
-                        default:
-                            break;
-                    }
-                }
-                return true;
-            default:
-                break;
+    private void handleScreenOff(final KeyguardManager km) {
+        if (!km.inKeyguardRestrictedInputMode() && checkRetryCount()) {
+            if (checkRetryCount()) {
+                mHandler.sendMessageDelayed(mHandler.obtainMessage(0, km), 500);
+            }
+        } else {
+            // Launch the full screen activity but do not turn the screen on.
+            Intent i = new Intent(this, AlarmAlertFullScreen.class);
+            i.putExtra(Alarms.ALARM_INTENT_EXTRA, mAlarm);
+            i.putExtra(SCREEN_OFF, true);
+            startActivity(i);
+            finish();
         }
-        return super.dispatchKeyEvent(event);
     }
 }
index fe7d61d..e463dfd 100644 (file)
 
 package com.android.deskclock;
 
+import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.content.res.Configuration;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.LayoutInflater;
+import android.view.Window;
 import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.Toast;
+import android.widget.TextView;
+
+import java.util.Calendar;
 
 /**
- * Full screen alarm alert: pops visible indicator and plays alarm tone. This
- * activity displays the alert in full screen in order to be secure. The
- * background is the current wallpaper.
+ * Alarm Clock alarm alert: pops visible indicator and plays alarm
+ * tone. This activity is the full screen version which shows over the lock
+ * screen with the wallpaper as the background.
  */
-public class AlarmAlertFullScreen extends AlarmAlert {
+public class AlarmAlertFullScreen extends Activity {
+
+    // These defaults must match the values in res/xml/settings.xml
+    private static final String DEFAULT_SNOOZE = "10";
+    private static final String DEFAULT_VOLUME_BEHAVIOR = "2";
+    protected static final String SCREEN_OFF = "screen_off";
+
+    protected Alarm mAlarm;
+    private int mVolumeBehavior;
+
+    // Receives the ALARM_KILLED action from the AlarmKlaxon.
+    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);
+            }
+        }
+    };
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
+
+        mAlarm = getIntent().getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);
+
+        // Get the volume/camera button behavior setting
+        final String vol =
+                PreferenceManager.getDefaultSharedPreferences(this)
+                .getString(SettingsActivity.KEY_VOLUME_BEHAVIOR,
+                        DEFAULT_VOLUME_BEHAVIOR);
+        mVolumeBehavior = Integer.parseInt(vol);
+
+        requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
+
+        final Window win = getWindow();
+        win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
+        // Turn on the screen unless we are being launched from the AlarmAlert
+        // subclass.
+        if (!getIntent().getBooleanExtra(SCREEN_OFF, false)) {
+            win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+        }
+
+        updateLayout();
+
+        // Register to get the alarm killed intent.
+        registerReceiver(mReceiver, new IntentFilter(Alarms.ALARM_KILLED));
+    }
+
+    private void setTitle() {
+        String label = mAlarm.getLabelOrDefault(this);
+        TextView title = (TextView) findViewById(R.id.alertTitle);
+        title.setText(label);
+    }
+
+    private void updateLayout() {
+        LayoutInflater inflater = LayoutInflater.from(this);
+
+        setContentView(inflater.inflate(R.layout.alarm_alert, null));
+
+        /* snooze behavior: pop a snooze confirmation view, kick alarm
+           manager. */
+        Button snooze = (Button) findViewById(R.id.snooze);
+        snooze.requestFocus();
+        snooze.setOnClickListener(new Button.OnClickListener() {
+            public void onClick(View v) {
+                snooze();
+            }
+        });
+
+        /* dismiss button: close notification */
+        findViewById(R.id.dismiss).setOnClickListener(
+                new Button.OnClickListener() {
+                    public void onClick(View v) {
+                        dismiss(false);
+                    }
+                });
+
+        /* Set the title from the passed in alarm */
+        setTitle();
+    }
+
+    // Attempt to snooze this alert.
+    private void snooze() {
+        final String snooze =
+                PreferenceManager.getDefaultSharedPreferences(this)
+                .getString(SettingsActivity.KEY_ALARM_SNOOZE, DEFAULT_SNOOZE);
+        int snoozeMinutes = Integer.parseInt(snooze);
+
+        final long snoozeTime = System.currentTimeMillis()
+                + (1000 * 60 * snoozeMinutes);
+        Alarms.saveSnoozeAlert(AlarmAlertFullScreen.this, mAlarm.id,
+                snoozeTime);
+
+        // Get the display time for the snooze and update the notification.
+        final Calendar c = Calendar.getInstance();
+        c.setTimeInMillis(snoozeTime);
+
+        // Append (snoozed) to the label.
+        String label = mAlarm.getLabelOrDefault(this);
+        label = getString(R.string.alarm_notify_snooze_label, label);
+
+        // Notify the user that the alarm has been snoozed.
+        Intent cancelSnooze = new Intent(this, AlarmReceiver.class);
+        cancelSnooze.setAction(Alarms.CANCEL_SNOOZE);
+        cancelSnooze.putExtra(Alarms.ALARM_ID, mAlarm.id);
+        PendingIntent broadcast =
+                PendingIntent.getBroadcast(this, mAlarm.id, cancelSnooze, 0);
+        NotificationManager nm = getNotificationManager();
+        Notification n = new Notification(R.drawable.stat_notify_alarm,
+                label, 0);
+        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;
+        nm.notify(mAlarm.id, n);
+
+        String displayTime = getString(R.string.alarm_alert_snooze_set,
+                snoozeMinutes);
+        // Intentionally log the snooze time for debugging.
+        Log.v(displayTime);
+
+        // Display the snooze minutes in a toast.
+        Toast.makeText(AlarmAlertFullScreen.this, displayTime,
+                Toast.LENGTH_LONG).show();
+        stopService(new Intent(Alarms.ALARM_ALERT_ACTION));
+        finish();
+    }
+
+    private NotificationManager getNotificationManager() {
+        return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+    }
+
+    // Dismiss the alarm.
+    private void dismiss(boolean killed) {
+        // The service told us that the alarm has been killed, do not modify
+        // the notification or stop the service.
+        if (!killed) {
+            // Cancel the notification and stop playing the alarm
+            NotificationManager nm = getNotificationManager();
+            nm.cancel(mAlarm.id);
+            stopService(new Intent(Alarms.ALARM_ALERT_ACTION));
+        }
+        finish();
+    }
+
+    /**
+     * this is called when a second alarm is triggered while a
+     * previous alert window is still active.
+     */
+    @Override
+    protected void onNewIntent(Intent intent) {
+        super.onNewIntent(intent);
+
+        if (Log.LOGV) Log.v("AlarmAlert.OnNewIntent()");
+
+        mAlarm = intent.getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);
+
+        setTitle();
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+        if (!isFinishing()) {
+            // Don't hang around.
+            finish();
+        }
     }
     
     @Override
+    public void onDestroy() {
+        super.onDestroy();
+        if (Log.LOGV) Log.v("AlarmAlert.onDestroy()");
+        // No longer care about the alarm being killed.
+        unregisterReceiver(mReceiver);
+    }
+
+    @Override
+    public boolean dispatchKeyEvent(KeyEvent event) {
+        // Do this on key down to handle a few of the system keys.
+        boolean up = event.getAction() == KeyEvent.ACTION_UP;
+        switch (event.getKeyCode()) {
+            // Volume keys and camera keys dismiss the alarm
+            case KeyEvent.KEYCODE_VOLUME_UP:
+            case KeyEvent.KEYCODE_VOLUME_DOWN:
+            case KeyEvent.KEYCODE_CAMERA:
+            case KeyEvent.KEYCODE_FOCUS:
+                if (up) {
+                    switch (mVolumeBehavior) {
+                        case 1:
+                            snooze();
+                            break;
+
+                        case 2:
+                            dismiss(false);
+                            break;
+
+                        default:
+                            break;
+                    }
+                }
+                return true;
+            default:
+                break;
+        }
+        return super.dispatchKeyEvent(event);
+    }
+
+    @Override
     public void onBackPressed() {
-        // Don't allow back to dismiss.
+        // Don't allow back to dismiss. This method is overriden by AlarmAlert
+        // so that the dialog is dismissed.
         return;
     }
 }
index e9d5e78..5919300 100644 (file)
@@ -28,7 +28,6 @@ import android.database.DataSetObserver;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
-import android.provider.Settings;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.LayoutInflater;
@@ -36,7 +35,6 @@ import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
-import android.view.View.OnCreateContextMenuListener;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.AdapterView.AdapterContextMenuInfo;
@@ -54,14 +52,14 @@ import java.util.Calendar;
  */
 public class AlarmClock extends Activity implements OnItemClickListener {
 
-    final static String PREFERENCES = "AlarmClock";
+    static final String PREFERENCES = "AlarmClock";
 
     /** Cap alarm count at this number */
-    final static int MAX_ALARM_COUNT = 12;
+    static final int MAX_ALARM_COUNT = 12;
 
     /** This must be false for production.  If true, turns on logging,
         test code, etc. */
-    final static boolean DEBUG = false;
+    static final boolean DEBUG = false;
 
     private SharedPreferences mPrefs;
     private LayoutInflater mFactory;
@@ -76,16 +74,16 @@ public class AlarmClock extends Activity implements OnItemClickListener {
         public View newView(Context context, Cursor cursor, ViewGroup parent) {
             View ret = mFactory.inflate(R.layout.alarm_time, parent, false);
 
-            DigitalClock digitalClock = (DigitalClock)ret.findViewById(R.id.digitalClock);
+            DigitalClock digitalClock =
+                    (DigitalClock) ret.findViewById(R.id.digitalClock);
             digitalClock.setLive(false);
-            if (Log.LOGV) Log.v("newView " + cursor.getPosition());
             return ret;
         }
 
         public void bindView(View view, Context context, Cursor cursor) {
             final Alarm alarm = new Alarm(cursor);
 
-            CheckBox onButton = (CheckBox)view.findViewById(R.id.alarmButton);
+            CheckBox onButton = (CheckBox) view.findViewById(R.id.alarmButton);
             onButton.setChecked(alarm.enabled);
             onButton.setOnClickListener(new OnClickListener() {
                     public void onClick(View v) {
index d78f82f..a493d90 100644 (file)
 
 package com.android.deskclock;
 
-import android.app.AlarmManager;
 import android.app.PendingIntent;
 import android.appwidget.AppWidgetManager;
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
-import android.content.res.Resources;
-import android.database.Cursor;
-import android.graphics.PorterDuff;
-import android.net.Uri;
-import android.provider.Calendar;
-import android.provider.Calendar.Attendees;
-import android.provider.Calendar.Calendars;
-import android.provider.Calendar.EventsColumns;
-import android.provider.Calendar.Instances;
-import android.provider.Calendar.Reminders;
-import android.text.format.DateFormat;
-import android.text.format.DateUtils;
-import android.util.Config;
-import android.util.Log;
-import android.view.View;
 import android.widget.RemoteViews;
 
-import java.util.Arrays;
-
 /**
  * Simple widget to show analog clock.
  */
@@ -51,13 +31,19 @@ public class AnalogAppWidgetProvider extends BroadcastReceiver {
 
     public void onReceive(Context context, Intent intent) {
         String action = intent.getAction();
-        
+
         if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
             RemoteViews views = new RemoteViews(context.getPackageName(),
                     R.layout.analog_appwidget);
-            
-            int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
-            
+
+            views.setOnClickPendingIntent(R.id.analog_appwidget,
+                    PendingIntent.getActivity(context, 0,
+                        new Intent(context, AlarmClock.class),
+                        PendingIntent.FLAG_CANCEL_CURRENT));
+
+            int[] appWidgetIds = intent.getIntArrayExtra(
+                    AppWidgetManager.EXTRA_APPWIDGET_IDS);
+
             AppWidgetManager gm = AppWidgetManager.getInstance(context);
             gm.updateAppWidget(appWidgetIds, views);
         }
index 1acc1d7..17e0ceb 100644 (file)
@@ -93,6 +93,11 @@ public class SetAlarm extends PreferenceActivity
 
         /* load alarm details from database */
         Alarm alarm = Alarms.getAlarm(getContentResolver(), mId);
+        // Bad alarm, bail to avoid a NPE.
+        if (alarm == null) {
+            finish();
+            return;
+        }
         mEnabled = alarm.enabled;
         mLabel.setText(alarm.label);
         mLabel.setSummary(alarm.label);
@@ -137,6 +142,8 @@ public class SetAlarm extends PreferenceActivity
         Button b = (Button) v.findViewById(R.id.alarm_save);
         b.setOnClickListener(new View.OnClickListener() {
                 public void onClick(View v) {
+                    // Enable the alarm when clicking "Done"
+                    mEnabled = true;
                     saveAlarm();
                     finish();
                 }