OSDN Git Service

UI changes based on feedback from Jeff and Amar.
authorPatrick Scott <phanna@android.com>
Mon, 23 Nov 2009 19:46:44 +0000 (14:46 -0500)
committerPatrick Scott <phanna@android.com>
Mon, 30 Nov 2009 20:56:10 +0000 (15:56 -0500)
Bug: 2278206

13 files changed:
res/drawable-hdpi/ic_clock_strip_desk_clock.png [new file with mode: 0644]
res/drawable-mdpi/ic_clock_strip_desk_clock.png [new file with mode: 0644]
res/drawable/clock_selector.xml [new file with mode: 0644]
res/drawable/indicator_clock_onoff.xml
res/layout/alarm_clock.xml
res/layout/alarm_time.xml
res/layout/save_cancel_alarm.xml
res/values/strings.xml
res/values/styles.xml
res/xml/alarm_prefs.xml
src/com/android/deskclock/AlarmClock.java
src/com/android/deskclock/DontPressWithParentLayout.java [new file with mode: 0644]
src/com/android/deskclock/SetAlarm.java

diff --git a/res/drawable-hdpi/ic_clock_strip_desk_clock.png b/res/drawable-hdpi/ic_clock_strip_desk_clock.png
new file mode 100644 (file)
index 0000000..ddc2d31
Binary files /dev/null and b/res/drawable-hdpi/ic_clock_strip_desk_clock.png differ
diff --git a/res/drawable-mdpi/ic_clock_strip_desk_clock.png b/res/drawable-mdpi/ic_clock_strip_desk_clock.png
new file mode 100644 (file)
index 0000000..76ebbd2
Binary files /dev/null and b/res/drawable-mdpi/ic_clock_strip_desk_clock.png differ
diff --git a/res/drawable/clock_selector.xml b/res/drawable/clock_selector.xml
new file mode 100644 (file)
index 0000000..efc9e5b
--- /dev/null
@@ -0,0 +1,22 @@
+<?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_pressed="false"
+      android:drawable="@android:color/background_dark" />
+  <item android:state_pressed="true"
+      android:drawable="@*android:drawable/list_selector_background_pressed" />
+</selector>
index 3fea6c0..e3a2d8d 100644 (file)
@@ -15,7 +15,7 @@
 -->
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_selected="true" android:state_window_focused="true"
+    <item android:state_pressed="true" android:state_window_focused="true"
         android:drawable="@drawable/ic_clock_alarm_selected" />
     <item android:drawable="@drawable/ic_clock_alarm_on" />
 </selector>
index 6e70259..a66fd59 100644 (file)
@@ -26,8 +26,6 @@
         android:background="@android:drawable/list_selector_background"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
-        android:paddingTop="4dip"
-        android:paddingBottom="4dip"
         android:orientation="horizontal">
 
         <ImageView
@@ -41,7 +39,7 @@
             android:layout_height="wrap_content"
             android:layout_width="wrap_content"
             android:layout_gravity="center_vertical"
-            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textAppearance="?android:attr/textAppearanceLarge"
             android:textColor="?android:attr/textColorPrimary"
             android:text="@string/add_alarm" />
 
@@ -69,7 +67,7 @@
             style="@style/ButtonStripLeft"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:src="@drawable/ic_menu_desk_clock"
+            android:src="@drawable/ic_clock_strip_desk_clock"
             android:contentDescription="@string/desk_clock_button_description"/>
 
         <com.android.deskclock.DigitalClock
index 9f8c12a..5c3b19b 100644 (file)
@@ -16,8 +16,6 @@
 
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:paddingTop="4dip"
-    android:paddingBottom="4dip"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal">
             minimum height. If the bar is a checkbox, it is too tall and is
             clipped on the right.
     -->
-    <LinearLayout android:id="@+id/indicator"
+    <com.android.deskclock.DontPressWithParentLayout android:id="@+id/indicator"
         style="@style/alarm_list_left_column"
+        android:background="@drawable/clock_selector"
         android:gravity="center"
         android:orientation="vertical">
         <CheckBox android:id="@+id/clock_onoff"
             android:focusable="false"
+            android:clickable="false"
             android:background="@drawable/indicator_clock_onoff"
+            android:duplicateParentState="true"
             android:layout_height="wrap_content"
             android:layout_width="wrap_content"
             android:layout_gravity="center"
             android:layout_gravity="center"
             android:paddingTop="4dip"
             android:src="@drawable/ic_indicator_off" />
-    </LinearLayout>
+    </com.android.deskclock.DontPressWithParentLayout>
 
     <ImageView
         android:src="@*android:drawable/divider_vertical_dark"
+        android:background="?android:attr/windowBackground"
         android:layout_width="wrap_content"
         android:layout_height="fill_parent"
+        android:paddingTop="4dip"
+        android:paddingBottom="4dip"
         android:scaleType="fitXY"
         android:gravity="fill_vertical" />
 
index 73e9f84..837d951 100644 (file)
         android:layout_weight="1"
         android:text="@string/revert"/>
 
+    <Button android:id="@+id/alarm_delete"
+        android:focusable="true"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:layout_weight="1"
+        android:text="@string/delete"/>
+
 </LinearLayout>
index 574b45c..1cf4057 100644 (file)
     <string name="delete_alarm">Delete alarm</string>
 
     <!-- Context Menu Item on Alarm Settings screen: Enable alarm -->
-    <string name="enable_alarm">Turn alarm on/off</string>
+    <string name="enable_alarm">Turn alarm on</string>
+
+    <!-- Context Menu Item on Alarm Settings screen: Disable alarm -->
+    <string name="disable_alarm">Turn alarm off</string>
 
     <!-- Delete alarm confirmation dialog message. -->
     <string name="delete_alarm_confirm">This alarm will be deleted.</string>
     <!-- Revert button when editing an alarm. -->
     <string name="revert">Revert</string>
 
+    <!-- Delete button when editing an alarm. -->
+    <string name="delete">Delete</string>
+
     <!-- Setting title for changing the alarm volume. -->
     <string name="alarm_volume_title">Alarm volume</string>
 
index 3cfb5c9..edacfea 100644 (file)
@@ -55,6 +55,6 @@
 
     <style name="alarm_list_left_column">
         <item name="android:layout_width">68dip</item>
-        <item name="android:layout_height">60dip</item>
+        <item name="android:layout_height">68dip</item>
     </style>
 </resources>
index 3619836..b70a0b8 100644 (file)
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
         android:title="@string/set_alarm">
-    <Preference android:key="time" 
+    <CheckBoxPreference android:key="enabled"
+        android:persistent="false"
+        android:title="@string/enable_alarm" />
+    <Preference android:key="time"
         android:persistent="false"
         android:title="@string/time"/>
+    <com.android.deskclock.RepeatPreference
+        android:persistent="false"
+        android:key="setRepeat"
+        android:title="@string/alarm_repeat" />
     <com.android.deskclock.AlarmPreference
-        android:key="alarm" 
+        android:key="alarm"
         android:title="@string/alert"
         android:ringtoneType="alarm|ringtone"
         android:persistent="false"
         android:showDefault="false"
         android:showSilent="true" />
-    <CheckBoxPreference android:key="vibrate" 
+    <CheckBoxPreference android:key="vibrate"
         android:persistent="false"
         android:title="@string/alarm_vibrate"/>
-    <com.android.deskclock.RepeatPreference
-        android:persistent="false"
-        android:key="setRepeat" 
-        android:title="@string/alarm_repeat" />
     <EditTextPreference android:key="label"
         android:persistent="false"
         android:title="@string/label"
index 4e4db18..adfe740 100644 (file)
@@ -86,7 +86,7 @@ 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;
@@ -108,14 +108,6 @@ public class AlarmClock extends Activity implements OnItemClickListener {
                     (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();
-                        updateIndicatorAndAlarm(isChecked, barOnOff, alarm);
-                    }
-            });
-
             // Clicking outside the "checkbox" should also change the state.
             indicator.setOnClickListener(new OnClickListener() {
                     public void onClick(View v) {
@@ -230,6 +222,12 @@ public class AlarmClock extends Activity implements OnItemClickListener {
                     addNewAlarm();
                 }
             });
+        // Make the entire view selected when focused.
+        addAlarm.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+                public void onFocusChange(View v, boolean hasFocus) {
+                    v.setSelected(hasFocus);
+                }
+        });
 
         ImageButton deskClock =
                 (ImageButton) findViewById(R.id.desk_clock_button);
@@ -291,6 +289,10 @@ public class AlarmClock extends Activity implements OnItemClickListener {
 
         // Set the custom view on the menu.
         menu.setHeaderView(v);
+        // Change the text based on the state of the alarm.
+        if (alarm.enabled) {
+            menu.findItem(R.id.enable_alarm).setTitle(R.string.disable_alarm);
+        }
     }
 
     @Override
diff --git a/src/com/android/deskclock/DontPressWithParentLayout.java b/src/com/android/deskclock/DontPressWithParentLayout.java
new file mode 100644 (file)
index 0000000..6c13998
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+package com.android.deskclock;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.LinearLayout;
+
+/**
+ * Special class to to allow the parent to be pressed without being pressed
+ * itself. This way the time in the alarm list can be pressed without changing
+ * the background of the indicator.
+ */
+public class DontPressWithParentLayout extends LinearLayout {
+
+    public DontPressWithParentLayout(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    @Override
+    public void setPressed(boolean pressed) {
+        // If the parent is pressed, do not set to pressed.
+        if (pressed && ((View) getParent()).isPressed()) {
+            return;
+        }
+        super.setPressed(pressed);
+    }
+}
index 7d84bb4..ce07cc1 100644 (file)
 
 package com.android.deskclock;
 
+import android.app.AlertDialog;
 import android.app.TimePickerDialog;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.media.RingtoneManager;
 import android.net.Uri;
@@ -47,15 +49,14 @@ public class SetAlarm extends PreferenceActivity
         implements TimePickerDialog.OnTimeSetListener {
 
     private EditTextPreference mLabel;
+    private CheckBoxPreference mEnabledPref;
     private Preference mTimePref;
     private AlarmPreference mAlarmPref;
     private CheckBoxPreference mVibratePref;
     private RepeatPreference mRepeatPref;
-    private MenuItem mDeleteAlarmItem;
     private MenuItem mTestAlarmItem;
 
     private int     mId;
-    private boolean mEnabled;
     private int     mHour;
     private int     mMinutes;
 
@@ -80,6 +81,7 @@ public class SetAlarm extends PreferenceActivity
                         return true;
                     }
                 });
+        mEnabledPref = (CheckBoxPreference) findPreference("enabled");
         mTimePref = findPreference("time");
         mAlarmPref = (AlarmPreference) findPreference("alarm");
         mVibratePref = (CheckBoxPreference) findPreference("vibrate");
@@ -93,7 +95,7 @@ public class SetAlarm extends PreferenceActivity
 
         /* load alarm details from database */
         Alarm alarm = Alarms.getAlarm(getContentResolver(), mId);
-        mEnabled = alarm.enabled;
+        mEnabledPref.setChecked(alarm.enabled);
         mLabel.setText(alarm.label);
         mLabel.setSummary(alarm.label);
         mHour = alarm.hour;
@@ -147,6 +149,12 @@ public class SetAlarm extends PreferenceActivity
                     finish();
                 }
         });
+        b = (Button) v.findViewById(R.id.alarm_delete);
+        b.setOnClickListener(new View.OnClickListener() {
+                public void onClick(View v) {
+                    deleteAlarm();
+                }
+        });
 
         // Replace the old content view with our new one.
         setContentView(ll);
@@ -174,7 +182,7 @@ public class SetAlarm extends PreferenceActivity
         mMinutes = minute;
         updateTime();
         // If the time has been changed, enable the alarm.
-        mEnabled = true;
+        mEnabledPref.setChecked(true);
     }
 
     private void updateTime() {
@@ -187,15 +195,30 @@ public class SetAlarm extends PreferenceActivity
 
     private void saveAlarm() {
         final String alert = mAlarmPref.getAlertString();
-        long time = Alarms.setAlarm(this, mId, mEnabled, mHour, mMinutes,
-                mRepeatPref.getDaysOfWeek(), mVibratePref.isChecked(),
+        long time = Alarms.setAlarm(this, mId, mEnabledPref.isChecked(), mHour,
+                mMinutes, mRepeatPref.getDaysOfWeek(), mVibratePref.isChecked(),
                 mLabel.getText(), alert);
 
-        if (mEnabled) {
+        if (mEnabledPref.isChecked()) {
             popAlarmSetToast(this, time);
         }
     }
 
+    private void deleteAlarm() {
+        new AlertDialog.Builder(this)
+                .setTitle(getString(R.string.delete_alarm))
+                .setMessage(getString(R.string.delete_alarm_confirm))
+                .setPositiveButton(android.R.string.ok,
+                        new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface d, int w) {
+                                Alarms.deleteAlarm(SetAlarm.this, mId);
+                                finish();
+                            }
+                        })
+                .setNegativeButton(android.R.string.cancel, null)
+                .show();
+    }
+
     /**
      * Write alarm out to persistent store and pops toast if alarm
      * enabled.
@@ -273,9 +296,6 @@ public class SetAlarm extends PreferenceActivity
     public boolean onCreateOptionsMenu(Menu menu) {
         super.onCreateOptionsMenu(menu);
 
-        mDeleteAlarmItem = menu.add(0, 0, 0, R.string.delete_alarm);
-        mDeleteAlarmItem.setIcon(android.R.drawable.ic_menu_delete);
-
         if (AlarmClock.DEBUG) {
             mTestAlarmItem = menu.add(0, 0, 0, "test alarm");
         }
@@ -284,11 +304,6 @@ public class SetAlarm extends PreferenceActivity
     }
 
     public boolean onOptionsItemSelected(MenuItem item) {
-        if (item == mDeleteAlarmItem) {
-            Alarms.deleteAlarm(this, mId);
-            finish();
-            return true;
-        }
         if (AlarmClock.DEBUG) {
             if (item == mTestAlarmItem) {
                 setTestAlarm();