OSDN Git Service

UI improvements to DeskClock.
authorDaniel Sandler <dsandler@google.com>
Fri, 23 Oct 2009 17:41:19 +0000 (13:41 -0400)
committerDaniel Sandler <dsandler@google.com>
Fri, 23 Oct 2009 17:41:19 +0000 (13:41 -0400)
Fixes:
- "Dim" button moved to TR corner per spec.
- Next Alarm moved to TL corner per spec.
- Launcher button added (not yet wired).
- Battery indicator added to BR corner per spec.
- Drop shadow added to all text per spec.
- Layout now fills the portrait display vertically.

Known problems:
- No landscape layout
- Layout jumps when status bar disappears for dim mode
- No artwork yet
- Weather is a big orange box instead of, you know, weather

res/layout/desk_clock.xml
res/values/strings.xml
src/com/android/deskclock/DeskClock.java

index bb86e12..6031e45 100644 (file)
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="vertical"
-        android:gravity="bottom"
-        android:background="#30000000"
         >
 
+        <!-- Entire display region (everything but bottom buttons) -->
         <LinearLayout
             android:orientation="vertical"
             android:layout_gravity="left"
+            android:layout_weight="1"
             android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginBottom="15dip"
-            android:layout_marginLeft="15dip"
-            android:layout_marginRight="15dip"
-            android:paddingTop="20dip"
-            android:paddingBottom="20dip"
+            android:layout_height="fill_parent"
+            android:layout_marginLeft="20dip"
+            android:layout_marginTop="20dip"
+            android:layout_marginRight="14dip"
+            android:layout_marginBottom="14dip"
             >
 
-            <TextView android:id="@+id/carrier"
+            <!-- across the top: next alarm, nightmode button -->
+            <LinearLayout
+                android:orientation="horizontal"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:gravity="right"
-                android:textSize="34sp"
-                />
+                android:layout_weight="0"
+                android:layout_marginBottom="6dip"
+                >
+                <TextView android:id="@+id/nextAlarm"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:gravity="left"
+                    android:textSize="18sp"
+                    android:textColor="#FFFFFFFF"
+                    android:drawablePadding="6dip"
+                    android:drawableLeft="@android:drawable/ic_lock_idle_alarm"
+                    android:shadowColor="#C0000000"
+                    android:shadowDx="0"
+                    android:shadowDy="0"
+                    android:shadowRadius="3.0"                        
+                    />
+                <Button android:id="@+id/nightmode_button"
+                    android:layout_weight="0"
+                    android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/nightmode_button_title_placeholder"
+                    />
+            </LinearLayout>
 
-            <!-- digital clock -->
-            <com.android.deskclock.DigitalClock android:id="@+id/time"
-                android:layout_width="wrap_content"
+
+            <!-- digital clock & date, together -->
+            <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:layout_marginTop="30dip"
+                android:layout_weight="1"
+                android:gravity="left|center_vertical"
                 android:layout_marginBottom="12dip"
-                android:layout_marginLeft="-8dip"
                 >
-                <!-- negative left margin above accounts for Clockopia's
-                     generous glyph padding -->
 
-                <TextView android:id="@+id/timeDisplay"
+                <com.android.deskclock.DigitalClock android:id="@+id/time"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:gravity="center"
-                    android:textSize="100sp"
-                    android:textColor="@color/white"
-                    />
-
-
-                <TextView android:id="@+id/am_pm"
+                    android:layout_marginBottom="12dip"
+                    android:layout_marginLeft="-8dip"
+                    >
+                    <!-- negative left margin above accounts for Clockopia's
+                         generous glyph padding -->
+
+                    <TextView android:id="@+id/timeDisplay"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:gravity="center"
+                        android:textSize="100sp"
+                        android:textColor="#FFFFFFFF"
+                        android:shadowColor="#C0000000"
+                        android:shadowDx="0"
+                        android:shadowDy="0"
+                        android:shadowRadius="3.0"                        
+                        />
+
+
+                    <TextView android:id="@+id/am_pm"
+                        android:layout_width="wrap_content"
+                        android:layout_height="fill_parent"
+                        android:gravity="bottom"
+                        android:textSize="28sp"
+                        android:singleLine="true"
+                        android:layout_marginLeft="3dip"
+                        android:textColor="#FFFFFFFF"
+                        android:shadowColor="#C0000000"
+                        android:shadowDx="0"
+                        android:shadowDy="0"
+                        android:shadowRadius="3.0"                        
+                        />
+
+                </com.android.deskclock.DigitalClock>
+
+                <TextView android:id="@+id/date"
                     android:layout_width="wrap_content"
-                    android:layout_height="fill_parent"
-                    android:gravity="bottom"
-                    android:textSize="28sp"
-                    android:layout_marginLeft="3dip"
-                    android:textColor="@color/white"
+                    android:layout_height="wrap_content"
+                    android:gravity="left"
+                    android:textSize="18sp"
+                    android:textColor="#FFFFFFFF"
+                    android:shadowColor="#C0000000"
+                    android:shadowDx="0"
+                    android:shadowDy="0"
+                    android:shadowRadius="3.0"                        
                     />
-
-            </com.android.deskclock.DigitalClock>
-
-            <TextView android:id="@+id/date"
-                      android:layout_width="wrap_content"
-                      android:layout_height="wrap_content"
-                      android:gravity="left"
-                      android:textSize="18sp"
-                      android:textColor="@color/white"
-                      />
+            
+            </LinearLayout>
 
             <!-- TODO: weather -->
             <View android:id="@+id/weather"
-                      android:layout_width="wrap_content"
-                      android:layout_height="100dip"
-                      />
-
-            <TextView android:id="@+id/nextAlarm"
-                      android:layout_width="wrap_content"
-                      android:layout_height="wrap_content"
-                      android:gravity="left"
-                      android:textSize="18sp"
-                      android:textColor="@color/white"
-                      android:drawablePadding="6dip"
-                      android:drawableLeft="@android:drawable/ic_lock_idle_alarm"
-                      />
+                android:layout_width="wrap_content"
+                android:layout_height="100dip"
+                android:layout_weight="0"
+                android:background="#C0FF8000"
+                android:layout_marginBottom="12dip"
+                />
+
+            <!-- battery/charge status -->
+            <TextView android:id="@+id/battery"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_weight="0"
+                android:gravity="right"
+                android:textSize="18sp"
+                android:textColor="#FFFFFFFF"
+                android:drawablePadding="6dip"
+                android:shadowColor="#C0000000"
+                android:shadowDx="0"
+                android:shadowDy="0"
+                android:shadowRadius="3.0"                        
+                />
 
         </LinearLayout>
 
-        <!-- TODO: buttons -->
+        <!-- buttons -->
         <LinearLayout
             android:orientation="horizontal"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
+            android:layout_weight="0"
             >
             <!--
                 android:background="@null"
                 android:layout_weight=".25"
                 android:text="@string/music_button_title_placeholder"
                 />
-            <Button android:id="@+id/nightmode_button"
+            <Button android:id="@+id/home_button"
                 android:layout_height="wrap_content"
                 android:layout_width="fill_parent"
                 android:layout_weight=".25"
-                android:text="@string/nightmode_button_title_placeholder"
+                android:text="@string/home_button_title_placeholder"
                 />
 
         </LinearLayout>
index 8131911..13ad2b7 100644 (file)
     <string name="gallery_button_title_placeholder">Gallery</string>
     <string name="music_button_title_placeholder">Music</string>
     <string name="nightmode_button_title_placeholder">Dim</string>
+    <string name="home_button_title_placeholder">Launcher</string>
+
+    <!-- A short representation of charging information, e.g "34%" -->
+    <string name="battery_charging_level"><xliff:g id="number">%d</xliff:g><xliff:g id="percent">%%</xliff:g></string>
 </resources>
 
 
index e756db1..8ff6914 100644 (file)
@@ -52,6 +52,10 @@ import android.widget.Button;
 import android.widget.TextView;
 import android.widget.CheckBox;
 
+import static android.os.BatteryManager.BATTERY_STATUS_CHARGING;
+import static android.os.BatteryManager.BATTERY_STATUS_FULL;
+import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
+
 import java.text.DateFormat;
 import java.util.Date;
 
@@ -62,6 +66,7 @@ public class DeskClock extends Activity {
 
     private TextView mNextAlarm = null;
     private TextView mDate;
+    private TextView mBatteryDisplay;
     private DigitalClock mTime;
 
     private boolean mDimmed = false;
@@ -69,12 +74,44 @@ public class DeskClock extends Activity {
     private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            refreshDate();
+            final String action = intent.getAction();
+            if (Intent.ACTION_DATE_CHANGED.equals(action)) {
+                refreshDate();
+            } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
+                handleBatteryUpdate(
+                    intent.getIntExtra("status", BATTERY_STATUS_UNKNOWN),
+                    intent.getIntExtra("level", 0));
+            }
         }
     };
 
 
     private DateFormat mDateFormat;
+    
+    private int mBatteryLevel;
+    private boolean mPluggedIn;
+
+    // Adapted from KeyguardUpdateMonitor.java
+    private void handleBatteryUpdate(int plugStatus, int batteryLevel) {
+        final boolean pluggedIn = (plugStatus == BATTERY_STATUS_CHARGING || plugStatus == BATTERY_STATUS_FULL);
+        if (pluggedIn != mPluggedIn || batteryLevel != mBatteryLevel) {
+            mBatteryLevel = batteryLevel;
+            mPluggedIn = pluggedIn;
+            refreshBattery();
+        }
+    }
+
+    private void refreshBattery() {
+        if (mPluggedIn /* || mBatteryLevel < LOW_BATTERY_THRESHOLD */) {
+            mBatteryDisplay.setCompoundDrawablesWithIntrinsicBounds(
+                0, 0, android.R.drawable.ic_lock_idle_charging, 0);
+            mBatteryDisplay.setText(
+                getString(R.string.battery_charging_level, mBatteryLevel));
+            mBatteryDisplay.setVisibility(View.VISIBLE);
+        } else {
+            mBatteryDisplay.setVisibility(View.INVISIBLE);
+        }
+    }
 
     private void refreshDate() {
         mDate.setText(mDateFormat.format(new Date()));
@@ -98,14 +135,26 @@ public class DeskClock extends Activity {
 
         Window win = getWindow();
         WindowManager.LayoutParams winParams = win.getAttributes();
+
+        // dim the wallpaper somewhat (how much is determined below)
+        winParams.flags |= (WindowManager.LayoutParams.FLAG_DIM_BEHIND);
+
         if (mDimmed) {
             winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
+//            winParams.flags &= (~WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
+            winParams.dimAmount = 0.5f; // pump up contrast in dim mode
+
+            // show the window tint
             tintView.startAnimation(AnimationUtils.loadAnimation(this, R.anim.dim));
         } else {
             winParams.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
+//            winParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
+            winParams.dimAmount = 0.2f; // lower contrast in normal mode
+    
+            // hide the window tint
             tintView.startAnimation(AnimationUtils.loadAnimation(this, R.anim.undim));
         }
-
+        
         win.setAttributes(winParams);
     }
 
@@ -119,11 +168,13 @@ public class DeskClock extends Activity {
 
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_DATE_CHANGED);
+        filter.addAction(Intent.ACTION_BATTERY_CHANGED);
         registerReceiver(mIntentReceiver, filter);
 
         doDim();
         refreshDate();
         refreshAlarm();
+        refreshBattery();
     }
 
     @Override
@@ -140,6 +191,7 @@ public class DeskClock extends Activity {
 
         mTime = (DigitalClock) findViewById(R.id.time);
         mDate = (TextView) findViewById(R.id.date);
+        mBatteryDisplay = (TextView) findViewById(R.id.battery);
 
         mNextAlarm = (TextView) findViewById(R.id.nextAlarm);