OSDN Git Service

New UI for the list of alarms.
[android-x86/packages-apps-DeskClock.git] / src / com / android / deskclock / AlarmClock.java
index c32c046..f2533c3 100644 (file)
@@ -25,6 +25,7 @@ import android.content.SharedPreferences;
 import android.content.res.Configuration;
 import android.database.Cursor;
 import android.database.DataSetObserver;
+import android.graphics.Typeface;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
@@ -44,11 +45,11 @@ import android.widget.AdapterView.OnItemClickListener;
 import android.widget.Button;
 import android.widget.CheckBox;
 import android.widget.CursorAdapter;
+import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
 
 import java.util.Calendar;
-import java.text.DateFormatSymbols;
 
 /**
  * AlarmClock application.
@@ -69,7 +70,16 @@ public class AlarmClock extends Activity implements OnItemClickListener {
     private ListView mAlarmsList;
     private Cursor mCursor;
 
-    private String mAm, mPm;
+    private void updateIndicatorAndAlarm(boolean enabled, ImageView bar,
+            Alarm alarm) {
+        bar.setImageResource(enabled ? R.drawable.ic_indicator_on
+                : R.drawable.ic_indicator_off);
+        Alarms.enableAlarm(this, alarm.id, enabled);
+        if (enabled) {
+            SetAlarm.popAlarmSetToast(this, alarm.hour, alarm.minutes,
+                    alarm.daysOfWeek);
+        }
+    }
 
     private class AlarmTimeAdapter extends CursorAdapter {
         public AlarmTimeAdapter(Context context, Cursor cursor) {
@@ -79,9 +89,6 @@ 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);
 
-            ((TextView) ret.findViewById(R.id.am)).setText(mAm);
-            ((TextView) ret.findViewById(R.id.pm)).setText(mPm);
-
             DigitalClock digitalClock = (DigitalClock)ret.findViewById(R.id.digitalClock);
             digitalClock.setLive(false);
             if (Log.LOGV) Log.v("newView " + cursor.getPosition());
@@ -91,17 +98,33 @@ public class AlarmClock extends Activity implements OnItemClickListener {
         public void bindView(View view, Context context, Cursor cursor) {
             final Alarm alarm = new Alarm(cursor);
 
-            CheckBox onButton = (CheckBox)view.findViewById(R.id.alarmButton);
-            onButton.setChecked(alarm.enabled);
-            onButton.setOnClickListener(new OnClickListener() {
+            View indicator = view.findViewById(R.id.indicator);
+
+            // Set the initial resource for the bar image.
+            final ImageView barOnOff =
+                    (ImageView) indicator.findViewById(R.id.bar_onoff);
+            barOnOff.setImageResource(alarm.enabled ?
+                    R.drawable.ic_indicator_on : R.drawable.ic_indicator_off);
+
+            // Set the initial state of the clock "checkbox"
+            final CheckBox clockOnOff =
+                    (CheckBox) indicator.findViewById(R.id.clock_onoff);
+            clockOnOff.setChecked(alarm.enabled);
+
+            // Handle the "checkbox" click and toggle the alarm.
+            clockOnOff.setOnClickListener(new OnClickListener() {
                     public void onClick(View v) {
                         boolean isChecked = ((CheckBox) v).isChecked();
-                        Alarms.enableAlarm(AlarmClock.this, alarm.id,
-                            isChecked);
-                        if (isChecked) {
-                            SetAlarm.popAlarmSetToast(AlarmClock.this,
-                                alarm.hour, alarm.minutes, alarm.daysOfWeek);
-                        }
+                        updateIndicatorAndAlarm(isChecked, barOnOff, alarm);
+                    }
+            });
+
+            // Clicking outside the "checkbox" should also change the state.
+            indicator.setOnClickListener(new OnClickListener() {
+                    public void onClick(View v) {
+                        clockOnOff.toggle();
+                        updateIndicatorAndAlarm(clockOnOff.isChecked(),
+                                barOnOff, alarm);
                     }
             });
 
@@ -113,6 +136,7 @@ public class AlarmClock extends Activity implements OnItemClickListener {
             c.set(Calendar.HOUR_OF_DAY, alarm.hour);
             c.set(Calendar.MINUTE, alarm.minutes);
             digitalClock.updateTime(c);
+            digitalClock.setTypeface(Typeface.DEFAULT);
 
             // Set the repeat text or leave it blank if it does not repeat.
             TextView daysOfWeekView =
@@ -128,7 +152,7 @@ public class AlarmClock extends Activity implements OnItemClickListener {
 
             // Display the label
             TextView labelView =
-                    (TextView) digitalClock.findViewById(R.id.label);
+                    (TextView) view.findViewById(R.id.label);
             if (alarm.label != null && alarm.label.length() != 0) {
                 labelView.setText(alarm.label);
                 labelView.setVisibility(View.VISIBLE);
@@ -181,10 +205,6 @@ public class AlarmClock extends Activity implements OnItemClickListener {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
-        String[] ampm = new DateFormatSymbols().getAmPmStrings();
-        mAm = ampm[0];
-        mPm = ampm[1];
-
         mFactory = LayoutInflater.from(this);
         mPrefs = getSharedPreferences(PREFERENCES, 0);
         mCursor = Alarms.getAlarmsCursor(getContentResolver());