OSDN Git Service

resolved conflicts for merge of aafb2fd2 to eclair-mr2
authorPatrick Scott <phanna@android.com>
Mon, 19 Oct 2009 20:37:42 +0000 (16:37 -0400)
committerPatrick Scott <phanna@android.com>
Mon, 19 Oct 2009 20:37:42 +0000 (16:37 -0400)
1  2 
src/com/android/deskclock/AlarmAlertFullScreen.java
src/com/android/deskclock/AlarmClock.java

@@@ -69,168 -28,6 +69,154 @@@ public class AlarmAlertFullScreen exten
      @Override
      protected void onCreate(Bundle icicle) {
          super.onCreate(icicle);
-         /* 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();
-         }
 +
 +        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
@@@ -51,12 -53,10 +51,10 @@@ import java.util.Calendar
   */
  public class AlarmClock extends Activity implements OnItemClickListener {
  
 -    final static String PREFERENCES = "AlarmClock";
 +    static final String PREFERENCES = "AlarmClock";
-     static final String PREF_CLOCK_FACE = "face";
-     static final String PREF_SHOW_CLOCK = "show_clock";
  
      /** 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. */