OSDN Git Service

More UI tweaks:
authorDaniel Sandler <dsandler@google.com>
Fri, 6 Nov 2009 19:45:45 +0000 (14:45 -0500)
committerDaniel Sandler <dsandler@google.com>
Fri, 6 Nov 2009 21:13:33 +0000 (16:13 -0500)
- Add an options menu to the main Clock activity.
  (The only item is "Alarms" to switch to the Alarm
  activity; no icon yet.)
- Now showing current temperature as well as high/low temps.
- Remove year from the displayed date.
- Tidy layouts.

res/layout-land/desk_clock.xml
res/layout/desk_clock_time_date.xml
res/layout/desk_clock_weather.xml
res/menu/desk_clock_menu.xml [new file with mode: 0644]
src/com/android/deskclock/DeskClock.java

index dd8ec70..afaaa6b 100644 (file)
                 <include layout="@layout/desk_clock_weather"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
-                    android:layout_weight="0"
                     android:layout_marginLeft="12dip"
                     />
 
index 1eb1d53..d6791f3 100644 (file)
@@ -54,7 +54,7 @@
             android:shadowColor="#C0000000"
             android:shadowDx="0"
             android:shadowDy="0"
-            android:shadowRadius="3.0"                        
+            android:shadowRadius="3.0"
             />
 
     </com.android.deskclock.DigitalClock>
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:gravity="left"
-        android:textSize="20sp"
+        android:textSize="22sp"
         android:textColor="#FFFFFFFF"
         android:shadowColor="#C0000000"
         android:shadowDx="0"
         android:shadowDy="0"
-        android:shadowRadius="3.0"                        
+        android:shadowRadius="3.0"
         />
 
 </LinearLayout>
index 762a32b..6847d14 100644 (file)
         android:layout_alignParentLeft="true"
         android:layout_marginBottom="-6dip"
         >
-        <TextView android:id="@+id/weather_high_temperature"
+        <ImageView android:id="@+id/weather_icon"
+            android:layout_height="60sp"
+            android:layout_width="60sp"
+            android:gravity="left"
+            android:scaleType="centerInside"
+            android:layout_marginRight="8dip"
+            />
+        <TextView android:id="@+id/weather_temperature"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:singleLine="true"
             android:textSize="50sp"
             android:textColor="#FFFFFFFF"
             android:shadowColor="#C0000000"
             android:shadowDx="0"
             android:shadowDy="0"
-            android:shadowRadius="3.0"                        
+            android:shadowRadius="3.0"
             android:layout_marginRight="8dip"
             android:layout_centerVertical="true"
+            android:layout_toRightOf="@id/weather_icon"
+            android:layout_alignBottom="@id/weather_icon"
             />
         <TextView android:id="@+id/weather_low_temperature"
-            android:layout_width="wrap_content"
+            android:layout_width="40sp"
             android:layout_height="wrap_content"
-            android:textSize="50sp"
-            android:textColor="#FFDDDDDD"
+            android:singleLine="true"
+            android:textSize="16sp"
+            android:textColor="#FFBEBEBE"
             android:shadowColor="#C0000000"
             android:shadowDx="0"
             android:shadowDy="0"
-            android:shadowRadius="3.0"                        
-            android:layout_marginRight="8dip"
-            android:layout_toRightOf="@id/weather_high_temperature"
-            android:layout_alignBottom="@id/weather_high_temperature"
+            android:shadowRadius="3.0"
+            android:layout_toRightOf="@id/weather_temperature"
+            android:layout_alignBaseline="@id/weather_temperature"
             />
-        <ImageView android:id="@+id/weather_icon"
-            android:layout_height="60sp"
-            android:layout_width="60sp"
-            android:gravity="left"
-            android:layout_toRightOf="@id/weather_low_temperature"
-            android:layout_alignBottom="@id/weather_low_temperature"
-            android:scaleType="centerInside"
+        <TextView android:id="@+id/weather_high_temperature"
+            android:layout_width="40sp"
+            android:layout_height="wrap_content"
+            android:singleLine="true"
+            android:textSize="18sp"
+            android:textColor="#FFFFFFFF"
+            android:shadowColor="#C0000000"
+            android:shadowDx="0"
+            android:shadowDy="0"
+            android:shadowRadius="3.0"
+            android:layout_alignTop="@id/weather_temperature"
+            android:layout_marginTop="4sp"
+            android:layout_alignLeft="@id/weather_low_temperature"
             />
     </RelativeLayout>
     <TextView android:id="@+id/weather_location"
         android:layout_height="wrap_content"
         android:layout_below="@id/weather_temp_icon_cluster"
         android:gravity="left"
+        android:singleLine="true"
         android:textSize="18sp"
         android:textColor="#ffffffff"
         android:shadowColor="#c0000000"
         android:shadowDx="0"
         android:shadowDy="0"
-        android:shadowRadius="3.0"                        
+        android:shadowRadius="3.0"
         />
 </RelativeLayout>
diff --git a/res/menu/desk_clock_menu.xml b/res/menu/desk_clock_menu.xml
new file mode 100644 (file)
index 0000000..8d0c4ae
--- /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.
+-->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:id="@+id/menu_item_alarms"
+        android:title="@string/alarm_list_title"/>
+</menu>
+
+
index 8b72ee7..56eadd0 100644 (file)
@@ -45,6 +45,7 @@ import android.view.ContextMenu.ContextMenuInfo;
 import android.view.ContextMenu;
 import android.view.LayoutInflater;
 import android.view.Menu;
+import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View.OnClickListener;
 import android.view.View.OnCreateContextMenuListener;
@@ -72,6 +73,7 @@ import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
 import java.io.IOException;
 import java.io.InputStream;
 import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Locale;
 import java.util.Random;
@@ -115,6 +117,7 @@ public class DeskClock extends Activity {
     private static final String[] WEATHER_CONTENT_COLUMNS = new String[] {
             "location",
             "timestamp",
+            "temperature",
             "highTemperature",
             "lowTemperature",
             "iconUrl",
@@ -129,11 +132,13 @@ public class DeskClock extends Activity {
     private TextView mNextAlarm = null;
     private TextView mBatteryDisplay;
 
+    private TextView mWeatherCurrentTemperature;
     private TextView mWeatherHighTemperature;
     private TextView mWeatherLowTemperature;
     private TextView mWeatherLocation;
     private ImageView mWeatherIcon;
 
+    private String mWeatherCurrentTemperatureString;
     private String mWeatherHighTemperatureString;
     private String mWeatherLowTemperatureString;
     private String mWeatherLocationString;
@@ -149,6 +154,8 @@ public class DeskClock extends Activity {
     private int mBatteryLevel = -1;
     private boolean mPluggedIn = false;
 
+    private boolean mInDock = false;
+
     private int mIdleTimeoutEpoch = 0;
 
     private boolean mWeatherFetchScheduled = false;
@@ -279,6 +286,7 @@ public class DeskClock extends Activity {
 
         mBatteryDisplay =
         mNextAlarm =
+        mWeatherCurrentTemperature =
         mWeatherHighTemperature =
         mWeatherLowTemperature =
         mWeatherLocation = null;
@@ -366,6 +374,8 @@ public class DeskClock extends Activity {
 
             mWeatherIconDrawable = mGenieResources.getDrawable(cur.getInt(
                 cur.getColumnIndexOrThrow("iconResId")));
+            mWeatherCurrentTemperatureString = String.format("%d\u00b0",
+                celsiusToLocal(cur.getInt(cur.getColumnIndexOrThrow("temperature"))));
             mWeatherHighTemperatureString = String.format("%d\u00b0",
                 celsiusToLocal(cur.getInt(cur.getColumnIndexOrThrow("highTemperature"))));
             mWeatherLowTemperatureString = String.format("%d\u00b0",
@@ -391,8 +401,9 @@ public class DeskClock extends Activity {
     }
 
     private void updateWeatherDisplay() {
-        if (mWeatherHighTemperature == null) return;
+        if (mWeatherCurrentTemperature == null) return;
 
+        mWeatherCurrentTemperature.setText(mWeatherCurrentTemperatureString);
         mWeatherHighTemperature.setText(mWeatherHighTemperatureString);
         mWeatherLowTemperature.setText(mWeatherLowTemperatureString);
         mWeatherLocation.setText(mWeatherLocationString);
@@ -494,7 +505,15 @@ public class DeskClock extends Activity {
 
         // reload the date format in case the user has changed settings
         // recently
-        mDateFormat = java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL);
+        final SimpleDateFormat dateFormat = (SimpleDateFormat)
+                java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL);
+        // This is a little clumsy; we want to honor the locale's date format
+        // (rather than simply hardcoding "Weekday, Month Date") but
+        // DateFormat.FULL includes the year (at least, in enUS). So we lop
+        // that bit off if it's there; should have no effect on
+        // locale-specific date strings that look different.
+        mDateFormat = new SimpleDateFormat(dateFormat.toPattern()
+                    .replace(", yyyy", "")); // no year
 
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_DATE_CHANGED);
@@ -511,6 +530,18 @@ public class DeskClock extends Activity {
         mHandy.sendMessageDelayed(
             Message.obtain(mHandy, SCREEN_SAVER_TIMEOUT_MSG, mIdleTimeoutEpoch, 0),
             SCREEN_SAVER_TIMEOUT);
+
+        final boolean launchedFromDock 
+            = getIntent().hasCategory(Intent.CATEGORY_DESK_DOCK);
+
+        if (supportsWeather() && launchedFromDock && !mInDock) {
+            if (DEBUG) Log.d(LOG_TAG, "Device now docked; forcing weather to refresh right now");
+            sendBroadcast(
+                new Intent("com.google.android.apps.genie.REFRESH")
+                    .putExtra("requestWeather", true));
+        }
+
+        mInDock = launchedFromDock;
     }
 
     @Override
@@ -546,6 +577,7 @@ public class DeskClock extends Activity {
 
         mTime.getRootView().requestFocus();
 
+        mWeatherCurrentTemperature = (TextView) findViewById(R.id.weather_temperature);
         mWeatherHighTemperature = (TextView) findViewById(R.id.weather_high_temperature);
         mWeatherLowTemperature = (TextView) findViewById(R.id.weather_low_temperature);
         mWeatherLocation = (TextView) findViewById(R.id.weather_location);
@@ -633,6 +665,22 @@ public class DeskClock extends Activity {
     }
 
     @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        if (item.getItemId() == R.id.menu_item_alarms) {
+            startActivity(new Intent(DeskClock.this, AlarmClock.class));
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        MenuInflater inflater = getMenuInflater();
+        inflater.inflate(R.menu.desk_clock_menu, menu);
+        return true;
+    }
+
+    @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);