android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
- android:layout_marginBottom="-4dip"
+ android:layout_marginBottom="-6dip"
>
<TextView android:id="@+id/weather_high_temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:textSize="42sp"
+ android:textSize="50sp"
android:textColor="#FFFFFFFF"
android:shadowColor="#C0000000"
android:shadowDx="0"
<TextView android:id="@+id/weather_low_temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:textSize="42sp"
- android:textColor="#FFCCCCCC"
+ android:textSize="50sp"
+ android:textColor="#FFDDDDDD"
android:shadowColor="#C0000000"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="3.0"
android:layout_marginRight="8dip"
- android:layout_centerVertical="true"
android:layout_toRightOf="@id/weather_high_temperature"
+ android:layout_alignBottom="@id/weather_high_temperature"
/>
<ImageView android:id="@+id/weather_icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_height="60sp"
+ android:layout_width="60sp"
+ android:gravity="left"
android:layout_toRightOf="@id/weather_low_temperature"
- android:layout_centerVertical="true"
- android:paddingTop="2dip"
+ android:layout_alignBottom="@id/weather_low_temperature"
+ android:scaleType="centerInside"
/>
</RelativeLayout>
<TextView android:id="@+id/weather_location"
* DeskClock clock view for desk docks.
*/
public class DeskClock extends Activity {
- private static final boolean DEBUG = true;
+ private static final boolean DEBUG = false;
private static final String LOG_TAG = "DeskClock";
private DateFormat mDateFormat;
- private int mBatteryLevel;
- private boolean mPluggedIn;
+ private int mBatteryLevel = -1;
+ private boolean mPluggedIn = false;
- private PowerManager.WakeLock mWakeLock;
private int mIdleTimeoutEpoch = 0;
private boolean mWeatherFetchScheduled = false;
private Random mRNG;
-
-
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mHandy.sendEmptyMessageDelayed(SCREEN_SAVER_MOVE_MSG, SCREEN_SAVER_MOVE_DELAY);
}
+ private void setWakeLock(boolean hold) {
+ if (DEBUG) Log.d(LOG_TAG, (hold ? "hold" : " releas") + "ing wake lock");
+ Window win = getWindow();
+ WindowManager.LayoutParams winParams = win.getAttributes();
+ winParams.flags |= WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
+ if (hold)
+ winParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
+ else
+ winParams.flags &= (~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ win.setAttributes(winParams);
+ }
+
private void restoreScreen() {
if (!mScreenSaverMode) return;
mScreenSaverMode = false;
winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
win.setAttributes(winParams);
+ // give up any internal focus before we switch layouts
+ final View focused = getCurrentFocus();
+ if (focused != null) focused.clearFocus();
+
setContentView(R.layout.desk_clock_saver);
mTime = (DigitalClock) findViewById(R.id.time);
// 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) {
+ setWakeLock(pluggedIn);
+ }
if (pluggedIn != mPluggedIn || batteryLevel != mBatteryLevel) {
mBatteryLevel = batteryLevel;
mPluggedIn = pluggedIn;
refreshBattery();
-
- if (mPluggedIn) {
- if (!mWakeLock.isHeld()) mWakeLock.acquire();
- } else {
- if (mWakeLock.isHeld()) mWakeLock.release();
- }
}
}
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
+ // secret!
+ winParams.flags |= (WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
+ winParams.flags |= (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+
// dim the wallpaper somewhat (how much is determined below)
winParams.flags |= (WindowManager.LayoutParams.FLAG_DIM_BEHIND);
@Override
public void onResume() {
super.onResume();
+ // NB: To avoid situations where the user launches Alarm Clock and is
+ // surprised to find it in dim mode (because it was last used in dim
+ // mode, but that last use is long in the past), we always un-dim upon
+ // bringing the activity to the foregreound.
+ mDimmed = false;
// reload the date format in case the user has changed settings
// recently
registerReceiver(mIntentReceiver, filter);
doDim(false);
+ restoreScreen();
refreshAll();
- if (mPluggedIn && !mWakeLock.isHeld()) mWakeLock.acquire();
+ setWakeLock(mPluggedIn);
mIdleTimeoutEpoch++;
mHandy.sendMessageDelayed(
super.onPause();
unregisterReceiver(mIntentReceiver);
unscheduleWeatherFetch();
- if (mWakeLock.isHeld()) mWakeLock.release();
}
private void initViews() {
+ // give up any internal focus before we switch layouts
+ final View focused = getCurrentFocus();
+ if (focused != null) focused.clearFocus();
+
setContentView(R.layout.desk_clock);
mTime = (DigitalClock) findViewById(R.id.time);
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
- PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
- mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
- "DeskClock");
- mWakeLock.acquire();
-
mRNG = new Random();
try {