- 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.
<include layout="@layout/desk_clock_weather"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
- android:layout_weight="0"
android:layout_marginLeft="12dip"
/>
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>
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>
--- /dev/null
+<?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>
+
+
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;
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;
private static final String[] WEATHER_CONTENT_COLUMNS = new String[] {
"location",
"timestamp",
+ "temperature",
"highTemperature",
"lowTemperature",
"iconUrl",
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;
private int mBatteryLevel = -1;
private boolean mPluggedIn = false;
+ private boolean mInDock = false;
+
private int mIdleTimeoutEpoch = 0;
private boolean mWeatherFetchScheduled = false;
mBatteryDisplay =
mNextAlarm =
+ mWeatherCurrentTemperature =
mWeatherHighTemperature =
mWeatherLowTemperature =
mWeatherLocation = null;
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",
}
private void updateWeatherDisplay() {
- if (mWeatherHighTemperature == null) return;
+ if (mWeatherCurrentTemperature == null) return;
+ mWeatherCurrentTemperature.setText(mWeatherCurrentTemperatureString);
mWeatherHighTemperature.setText(mWeatherHighTemperatureString);
mWeatherLowTemperature.setText(mWeatherLowTemperatureString);
mWeatherLocation.setText(mWeatherLocationString);
// 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);
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
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);
}
@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);