OSDN Git Service

New UI for the list of alarms.
authorPatrick Scott <phanna@android.com>
Mon, 16 Nov 2009 12:50:20 +0000 (07:50 -0500)
committerPatrick Scott <phanna@android.com>
Mon, 16 Nov 2009 16:45:26 +0000 (11:45 -0500)
Still need to put the "Add alarm" item at the top and the clock at the bottom.

15 files changed:
res/drawable-hdpi/ic_clock_alarm_off.png [new file with mode: 0644]
res/drawable-hdpi/ic_clock_alarm_on.png [new file with mode: 0644]
res/drawable-hdpi/ic_clock_alarm_selected.png [new file with mode: 0644]
res/drawable-hdpi/ic_indicator_off.png [new file with mode: 0644]
res/drawable-hdpi/ic_indicator_on.png [new file with mode: 0644]
res/drawable-mdpi/ic_clock_alarm_off.png [new file with mode: 0644]
res/drawable-mdpi/ic_clock_alarm_on.png [new file with mode: 0644]
res/drawable-mdpi/ic_clock_alarm_selected.png [new file with mode: 0644]
res/drawable-mdpi/ic_indicator_off.png [new file with mode: 0644]
res/drawable-mdpi/ic_indicator_on.png [new file with mode: 0755]
res/drawable/indicator_clock_onoff.xml [new file with mode: 0644]
res/layout/alarm_time.xml
res/values/colors.xml
src/com/android/deskclock/AlarmClock.java
src/com/android/deskclock/DigitalClock.java

diff --git a/res/drawable-hdpi/ic_clock_alarm_off.png b/res/drawable-hdpi/ic_clock_alarm_off.png
new file mode 100644 (file)
index 0000000..76c19e5
Binary files /dev/null and b/res/drawable-hdpi/ic_clock_alarm_off.png differ
diff --git a/res/drawable-hdpi/ic_clock_alarm_on.png b/res/drawable-hdpi/ic_clock_alarm_on.png
new file mode 100644 (file)
index 0000000..8304d61
Binary files /dev/null and b/res/drawable-hdpi/ic_clock_alarm_on.png differ
diff --git a/res/drawable-hdpi/ic_clock_alarm_selected.png b/res/drawable-hdpi/ic_clock_alarm_selected.png
new file mode 100644 (file)
index 0000000..ddcaea1
Binary files /dev/null and b/res/drawable-hdpi/ic_clock_alarm_selected.png differ
diff --git a/res/drawable-hdpi/ic_indicator_off.png b/res/drawable-hdpi/ic_indicator_off.png
new file mode 100644 (file)
index 0000000..1ca71d9
Binary files /dev/null and b/res/drawable-hdpi/ic_indicator_off.png differ
diff --git a/res/drawable-hdpi/ic_indicator_on.png b/res/drawable-hdpi/ic_indicator_on.png
new file mode 100644 (file)
index 0000000..5a99970
Binary files /dev/null and b/res/drawable-hdpi/ic_indicator_on.png differ
diff --git a/res/drawable-mdpi/ic_clock_alarm_off.png b/res/drawable-mdpi/ic_clock_alarm_off.png
new file mode 100644 (file)
index 0000000..742c074
Binary files /dev/null and b/res/drawable-mdpi/ic_clock_alarm_off.png differ
diff --git a/res/drawable-mdpi/ic_clock_alarm_on.png b/res/drawable-mdpi/ic_clock_alarm_on.png
new file mode 100644 (file)
index 0000000..f81d9f6
Binary files /dev/null and b/res/drawable-mdpi/ic_clock_alarm_on.png differ
diff --git a/res/drawable-mdpi/ic_clock_alarm_selected.png b/res/drawable-mdpi/ic_clock_alarm_selected.png
new file mode 100644 (file)
index 0000000..197325b
Binary files /dev/null and b/res/drawable-mdpi/ic_clock_alarm_selected.png differ
diff --git a/res/drawable-mdpi/ic_indicator_off.png b/res/drawable-mdpi/ic_indicator_off.png
new file mode 100644 (file)
index 0000000..c1aa867
Binary files /dev/null and b/res/drawable-mdpi/ic_indicator_off.png differ
diff --git a/res/drawable-mdpi/ic_indicator_on.png b/res/drawable-mdpi/ic_indicator_on.png
new file mode 100755 (executable)
index 0000000..361364b
Binary files /dev/null and b/res/drawable-mdpi/ic_indicator_on.png differ
diff --git a/res/drawable/indicator_clock_onoff.xml b/res/drawable/indicator_clock_onoff.xml
new file mode 100644 (file)
index 0000000..f44563c
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_selected="true" android:state_window_focused="true"
+        android:drawable="@drawable/ic_clock_alarm_selected" />
+    <item android:state_checked="false"
+        android:drawable="@drawable/ic_clock_alarm_off" />
+    <item android:state_checked="true"
+        android:drawable="@drawable/ic_clock_alarm_on" />
+</selector>
index 6db55d0..24a485b 100644 (file)
 
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:paddingLeft="5dip"
+    android:paddingTop="4dip"
+    android:paddingBottom="4dip"
     android:layout_width="fill_parent"
-    android:layout_height="wrap_content">
+    android:layout_height="wrap_content"
+    android:orientation="horizontal">
+
+    <LinearLayout android:id="@+id/indicator"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:paddingLeft="14dip"
+        android:paddingRight="14dip"
+        android:paddingTop="8dip"
+        android:paddingBottom="8dip"
+        android:orientation="vertical">
+        <CheckBox android:id="@+id/clock_onoff"
+            android:focusable="false"
+            android:background="@drawable/indicator_clock_onoff"
+            android:layout_height="wrap_content"
+            android:layout_width="wrap_content"
+            android:layout_gravity="center"
+            android:button="@null"/>
+        <ImageView android:id="@+id/bar_onoff"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:paddingTop="4dip"
+            android:src="@drawable/ic_indicator_off" />
+    </LinearLayout>
+
+    <ImageView
+        android:src="@*android:drawable/divider_vertical_dark"
+        android:layout_width="wrap_content"
+        android:layout_height="fill_parent"
+        android:scaleType="fitXY"
+        android:gravity="fill_vertical" />
 
     <!-- A layout that displays the time.  Shows time, am/pm (if 12-hour),
          and an optional line below, used for day/days of week -->
-
     <com.android.deskclock.DigitalClock android:id="@+id/digitalClock"
         android:layout_width="wrap_content"
         android:layout_height="fill_parent"
-        android:layout_weight="1"
         android:gravity="center_vertical"
+        android:layout_weight="1"
         android:orientation="vertical"
         android:paddingLeft="8dip"
         android:paddingRight="8dip">
 
         <LinearLayout
             android:layout_width="fill_parent"
-            android:layout_height="wrap_content">
+            android:layout_height="wrap_content"
+            android:baselineAligned="true">
 
             <TextView android:id="@+id/timeDisplay"
+                android:includeFontPadding="false"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:textSize="30sp"
+                android:paddingRight="6dip"
+                android:textSize="36sp"
                 android:textColor="@color/white"/>
 
             <TextView android:id="@+id/am_pm"
                 android:layout_width="wrap_content"
-                android:layout_height="fill_parent"
-                android:gravity="bottom"
-                android:textSize="12sp"
+                android:layout_height="wrap_content"
+                android:textSize="16sp"
+                android:textStyle="bold"
                 android:textColor="@color/white"/>
 
+            <TextView android:id="@+id/label"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:textSize="16sp"
+                android:textColor="@color/grey"
+                android:textStyle="bold"
+                android:gravity="right"
+                android:paddingRight="8dip"
+                android:singleLine="true"/>
+
         </LinearLayout>
 
         <TextView android:id="@+id/daysOfWeek"
+            android:includeFontPadding="false"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:textSize="10sp"
-            android:textColor="@color/ltgrey"/>
-
-        <TextView android:id="@+id/label"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:textSize="12sp"
-            android:textColor="@color/ltgrey"
-            android:textStyle="bold|italic"
-            android:singleLine="true"/>
+            android:textColor="@color/grey"/>
 
     </com.android.deskclock.DigitalClock>
 
-    <CheckBox android:id="@+id/alarmButton"
-        android:focusable="false"
-        android:layout_width="60dip"
-        android:layout_height="76dip"
-        android:layout_gravity="center_vertical"/>
-
 </LinearLayout>
index e61b6c3..df2c9cf 100644 (file)
@@ -20,5 +20,5 @@
 
     <color name="white">#ffffffff</color>
     <color name="red">#ffee0000</color>
-    <color name="ltgrey">#ffe0e0e0</color>
+    <color name="grey">#ffaaaaaa</color>
 </resources>
index e9d5e78..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,6 +45,7 @@ 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;
 
@@ -68,6 +70,17 @@ public class AlarmClock extends Activity implements OnItemClickListener {
     private ListView mAlarmsList;
     private Cursor mCursor;
 
+    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) {
             super(context, cursor);
@@ -85,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);
                     }
             });
 
@@ -107,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 =
@@ -122,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);
index 383ca7b..38ed91b 100644 (file)
@@ -66,11 +66,8 @@ public class DigitalClock extends LinearLayout {
         private TextView mAmPm;
         private String mAmString, mPmString;
 
-        AmPm(View parent, Typeface tf) {
+        AmPm(View parent) {
             mAmPm = (TextView) parent.findViewById(R.id.am_pm);
-            if (tf != null) {
-                mAmPm.setTypeface(tf);
-            }
 
             String[] ampm = new DateFormatSymbols().getAmPmStrings();
             mAmString = ampm[0];
@@ -113,7 +110,7 @@ public class DigitalClock extends LinearLayout {
                 "fonts/Clockopia.ttf");
         mTimeDisplay = (TextView) findViewById(R.id.timeDisplay);
         mTimeDisplay.setTypeface(tf);
-        mAmPm = new AmPm(this, null);
+        mAmPm = new AmPm(this);
         mCalendar = Calendar.getInstance();
 
         setDateFormat();
@@ -183,4 +180,8 @@ public class DigitalClock extends LinearLayout {
     void setLive(boolean live) {
         mLive = live;
     }
+
+    void setTypeface(Typeface tf) {
+        mTimeDisplay.setTypeface(tf);
+    }
 }