blob: 9aa80448471605ba883eb7b1f711f6b995c1d156 [file] [log] [blame]
Joe Onorato263700d2010-05-14 11:54:53 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Joe Onoratofd52b182010-11-10 18:00:52 -080017package com.android.systemui.statusbar.policy;
Joe Onorato263700d2010-05-14 11:54:53 -070018
Jason Monkaa573e92017-01-27 17:00:29 -050019import android.app.StatusBarManager;
Daniel Sandler87937db2010-05-27 13:44:11 -040020import android.content.BroadcastReceiver;
Joe Onorato263700d2010-05-14 11:54:53 -070021import android.content.Context;
22import android.content.Intent;
23import android.content.IntentFilter;
Jorim Jaggi740beb52014-05-11 18:53:19 +020024import android.content.res.TypedArray;
Jason Monkaa573e92017-01-27 17:00:29 -050025import android.graphics.Rect;
John Spurlock3c875662013-08-31 15:07:25 -040026import android.os.Bundle;
Jason Monkfe7c91b2015-08-13 15:42:28 -040027import android.os.Handler;
28import android.os.SystemClock;
Selim Cinek9c4a7072014-11-21 17:44:34 +010029import android.os.UserHandle;
Joe Onorato263700d2010-05-14 11:54:53 -070030import android.text.Spannable;
31import android.text.SpannableStringBuilder;
Daniel Sandler87937db2010-05-27 13:44:11 -040032import android.text.format.DateFormat;
33import android.text.style.CharacterStyle;
Daniel Sandler87937db2010-05-27 13:44:11 -040034import android.text.style.RelativeSizeSpan;
Joe Onorato263700d2010-05-14 11:54:53 -070035import android.util.AttributeSet;
Jason Monkfe7c91b2015-08-13 15:42:28 -040036import android.view.Display;
Jason Monkaa573e92017-01-27 17:00:29 -050037import android.view.View;
Joe Onorato263700d2010-05-14 11:54:53 -070038import android.widget.TextView;
Winsonc0d70582016-01-29 10:24:39 -080039
Rohan Shahcc3d1d82018-03-30 21:24:17 +000040import com.android.settingslib.Utils;
John Spurlock3c875662013-08-31 15:07:25 -040041import com.android.systemui.DemoMode;
Jason Monk9c7844c2017-01-18 15:21:53 -050042import com.android.systemui.Dependency;
Jason Monkaa573e92017-01-27 17:00:29 -050043import com.android.systemui.FontSizeUtils;
Jorim Jaggi740beb52014-05-11 18:53:19 +020044import com.android.systemui.R;
Jason Monkaa573e92017-01-27 17:00:29 -050045import com.android.systemui.SysUiServiceProvider;
Lucas Dupin4eae8812018-04-09 22:44:17 -070046import com.android.systemui.settings.CurrentUserTracker;
Jason Monkaa573e92017-01-27 17:00:29 -050047import com.android.systemui.statusbar.CommandQueue;
Jason Monk3e189872016-01-12 09:10:34 -050048import com.android.systemui.statusbar.phone.StatusBarIconController;
Jason Monkaa573e92017-01-27 17:00:29 -050049import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
50import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
Jason Monkfe7c91b2015-08-13 15:42:28 -040051import com.android.systemui.tuner.TunerService;
52import com.android.systemui.tuner.TunerService.Tunable;
John Spurlock3c875662013-08-31 15:07:25 -040053
Lucas Dupin4eae8812018-04-09 22:44:17 -070054import libcore.icu.LocaleData;
55
Joe Onorato263700d2010-05-14 11:54:53 -070056import java.text.SimpleDateFormat;
57import java.util.Calendar;
Daniel Sandler43b23c62012-11-29 11:35:02 -050058import java.util.Locale;
Joe Onorato263700d2010-05-14 11:54:53 -070059import java.util.TimeZone;
60
Joe Onorato263700d2010-05-14 11:54:53 -070061/**
Daniel Sandlerce4f5e52012-11-19 14:47:18 -050062 * Digital clock for the status bar.
Joe Onorato263700d2010-05-14 11:54:53 -070063 */
Jason Monkaa573e92017-01-27 17:00:29 -050064public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.Callbacks,
65 DarkReceiver, ConfigurationListener {
Jason Monkfe7c91b2015-08-13 15:42:28 -040066
67 public static final String CLOCK_SECONDS = "clock_seconds";
68
Lucas Dupin4eae8812018-04-09 22:44:17 -070069 private final CurrentUserTracker mCurrentUserTracker;
70 private int mCurrentUserId;
71
Jason Monkaa573e92017-01-27 17:00:29 -050072 private boolean mClockVisibleByPolicy = true;
73 private boolean mClockVisibleByUser = true;
74
Joe Onorato263700d2010-05-14 11:54:53 -070075 private boolean mAttached;
76 private Calendar mCalendar;
77 private String mClockFormatString;
78 private SimpleDateFormat mClockFormat;
Adrian Roos70dcf832016-04-20 15:51:42 -070079 private SimpleDateFormat mContentDescriptionFormat;
Daniel Sandler43b23c62012-11-29 11:35:02 -050080 private Locale mLocale;
Joe Onorato263700d2010-05-14 11:54:53 -070081
Daniel Sandler87937db2010-05-27 13:44:11 -040082 private static final int AM_PM_STYLE_NORMAL = 0;
83 private static final int AM_PM_STYLE_SMALL = 1;
84 private static final int AM_PM_STYLE_GONE = 2;
85
Jorim Jaggi740beb52014-05-11 18:53:19 +020086 private final int mAmPmStyle;
Jason Monke5b770e2017-03-03 21:49:29 -050087 private final boolean mShowDark;
Jason Monkfe7c91b2015-08-13 15:42:28 -040088 private boolean mShowSeconds;
89 private Handler mSecondsHandler;
Daniel Sandler87937db2010-05-27 13:44:11 -040090
Rohan Shahcc3d1d82018-03-30 21:24:17 +000091 /**
92 * Whether we should use colors that adapt based on wallpaper/the scrim behind quick settings
93 * for text.
94 */
95 private boolean mUseWallpaperTextColor;
96
97 /**
98 * Color to be set on this {@link TextView}, when wallpaperTextColor is <b>not</b> utilized.
99 */
100 private int mNonAdaptedColor;
101
Joe Onorato263700d2010-05-14 11:54:53 -0700102 public Clock(Context context) {
103 this(context, null);
104 }
105
106 public Clock(Context context, AttributeSet attrs) {
107 this(context, attrs, 0);
108 }
109
110 public Clock(Context context, AttributeSet attrs, int defStyle) {
111 super(context, attrs, defStyle);
Jorim Jaggi740beb52014-05-11 18:53:19 +0200112 TypedArray a = context.getTheme().obtainStyledAttributes(
113 attrs,
114 R.styleable.Clock,
115 0, 0);
116 try {
117 mAmPmStyle = a.getInt(R.styleable.Clock_amPmStyle, AM_PM_STYLE_GONE);
Jason Monke5b770e2017-03-03 21:49:29 -0500118 mShowDark = a.getBoolean(R.styleable.Clock_showDark, true);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000119 mNonAdaptedColor = getCurrentTextColor();
Jorim Jaggi740beb52014-05-11 18:53:19 +0200120 } finally {
121 a.recycle();
122 }
Lucas Dupin4eae8812018-04-09 22:44:17 -0700123 mCurrentUserTracker = new CurrentUserTracker(context) {
124 @Override
125 public void onUserSwitched(int newUserId) {
126 mCurrentUserId = newUserId;
127 }
128 };
Joe Onorato263700d2010-05-14 11:54:53 -0700129 }
130
131 @Override
132 protected void onAttachedToWindow() {
133 super.onAttachedToWindow();
134
135 if (!mAttached) {
136 mAttached = true;
137 IntentFilter filter = new IntentFilter();
138
139 filter.addAction(Intent.ACTION_TIME_TICK);
140 filter.addAction(Intent.ACTION_TIME_CHANGED);
141 filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
142 filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
Daniel Sandlerce4f5e52012-11-19 14:47:18 -0500143 filter.addAction(Intent.ACTION_USER_SWITCHED);
Joe Onorato263700d2010-05-14 11:54:53 -0700144
Selim Cinek9c4a7072014-11-21 17:44:34 +0100145 getContext().registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter,
Jason Monk9c7844c2017-01-18 15:21:53 -0500146 null, Dependency.get(Dependency.TIME_TICK_HANDLER));
Jason Monkde850bb2017-02-01 19:26:30 -0500147 Dependency.get(TunerService.class).addTunable(this, CLOCK_SECONDS,
Jason Monk3e189872016-01-12 09:10:34 -0500148 StatusBarIconController.ICON_BLACKLIST);
Jason Monkaa573e92017-01-27 17:00:29 -0500149 SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this);
Jason Monke5b770e2017-03-03 21:49:29 -0500150 if (mShowDark) {
151 Dependency.get(DarkIconDispatcher.class).addDarkReceiver(this);
152 }
Lucas Dupin4eae8812018-04-09 22:44:17 -0700153 mCurrentUserTracker.startTracking();
154 mCurrentUserId = mCurrentUserTracker.getCurrentUserId();
Joe Onorato263700d2010-05-14 11:54:53 -0700155 }
156
157 // NOTE: It's safe to do these after registering the receiver since the receiver always runs
158 // in the main thread, therefore the receiver can't run before this method returns.
159
160 // The time zone may have changed while the receiver wasn't registered, so update the Time
161 mCalendar = Calendar.getInstance(TimeZone.getDefault());
162
163 // Make sure we update to the current time
164 updateClock();
Jason Monkfe7c91b2015-08-13 15:42:28 -0400165 updateShowSeconds();
Joe Onorato263700d2010-05-14 11:54:53 -0700166 }
167
168 @Override
169 protected void onDetachedFromWindow() {
170 super.onDetachedFromWindow();
171 if (mAttached) {
172 getContext().unregisterReceiver(mIntentReceiver);
173 mAttached = false;
Jason Monkde850bb2017-02-01 19:26:30 -0500174 Dependency.get(TunerService.class).removeTunable(this);
Jason Monkaa573e92017-01-27 17:00:29 -0500175 SysUiServiceProvider.getComponent(getContext(), CommandQueue.class)
176 .removeCallbacks(this);
Jason Monke5b770e2017-03-03 21:49:29 -0500177 if (mShowDark) {
178 Dependency.get(DarkIconDispatcher.class).removeDarkReceiver(this);
179 }
Lucas Dupin4eae8812018-04-09 22:44:17 -0700180 mCurrentUserTracker.stopTracking();
Joe Onorato263700d2010-05-14 11:54:53 -0700181 }
182 }
183
184 private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
185 @Override
186 public void onReceive(Context context, Intent intent) {
187 String action = intent.getAction();
188 if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)) {
189 String tz = intent.getStringExtra("time-zone");
Jason Monkcd26af72017-01-11 14:32:58 -0500190 getHandler().post(() -> {
191 mCalendar = Calendar.getInstance(TimeZone.getTimeZone(tz));
192 if (mClockFormat != null) {
193 mClockFormat.setTimeZone(mCalendar.getTimeZone());
194 }
195 });
Daniel Sandler43b23c62012-11-29 11:35:02 -0500196 } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
197 final Locale newLocale = getResources().getConfiguration().locale;
Jason Monkcd26af72017-01-11 14:32:58 -0500198 getHandler().post(() -> {
199 if (!newLocale.equals(mLocale)) {
200 mLocale = newLocale;
201 mClockFormatString = ""; // force refresh
202 }
203 });
Joe Onorato263700d2010-05-14 11:54:53 -0700204 }
Jason Monkcd26af72017-01-11 14:32:58 -0500205 getHandler().post(() -> updateClock());
Joe Onorato263700d2010-05-14 11:54:53 -0700206 }
207 };
208
Jason Monkaa573e92017-01-27 17:00:29 -0500209 public void setClockVisibleByUser(boolean visible) {
210 mClockVisibleByUser = visible;
211 updateClockVisibility();
212 }
213
214 public void setClockVisibilityByPolicy(boolean visible) {
215 mClockVisibleByPolicy = visible;
216 updateClockVisibility();
217 }
218
219 private void updateClockVisibility() {
Jason Monkf8c2f7b2017-09-06 09:22:29 -0400220 boolean visible = mClockVisibleByPolicy && mClockVisibleByUser;
221 Dependency.get(IconLogger.class).onIconVisibility("clock", visible);
222 int visibility = visible ? View.VISIBLE : View.GONE;
Jason Monkaa573e92017-01-27 17:00:29 -0500223 setVisibility(visibility);
224 }
225
Joe Onorato263700d2010-05-14 11:54:53 -0700226 final void updateClock() {
John Spurlock3c875662013-08-31 15:07:25 -0400227 if (mDemoMode) return;
Joe Onorato263700d2010-05-14 11:54:53 -0700228 mCalendar.setTimeInMillis(System.currentTimeMillis());
229 setText(getSmallTime());
Adrian Roos70dcf832016-04-20 15:51:42 -0700230 setContentDescription(mContentDescriptionFormat.format(mCalendar.getTime()));
Joe Onorato263700d2010-05-14 11:54:53 -0700231 }
232
Jason Monkfe7c91b2015-08-13 15:42:28 -0400233 @Override
234 public void onTuningChanged(String key, String newValue) {
Jason Monk3e189872016-01-12 09:10:34 -0500235 if (CLOCK_SECONDS.equals(key)) {
236 mShowSeconds = newValue != null && Integer.parseInt(newValue) != 0;
237 updateShowSeconds();
Jason Monkaa573e92017-01-27 17:00:29 -0500238 } else {
239 setClockVisibleByUser(!StatusBarIconController.getIconBlacklist(newValue)
240 .contains("clock"));
241 updateClockVisibility();
Jason Monk3e189872016-01-12 09:10:34 -0500242 }
Jason Monkfe7c91b2015-08-13 15:42:28 -0400243 }
244
Jason Monkaa573e92017-01-27 17:00:29 -0500245 @Override
246 public void disable(int state1, int state2, boolean animate) {
247 boolean clockVisibleByPolicy = (state1 & StatusBarManager.DISABLE_CLOCK) == 0;
248 if (clockVisibleByPolicy != mClockVisibleByPolicy) {
249 setClockVisibilityByPolicy(clockVisibleByPolicy);
250 }
251 }
252
253 @Override
254 public void onDarkChanged(Rect area, float darkIntensity, int tint) {
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000255 mNonAdaptedColor = DarkIconDispatcher.getTint(area, this, tint);
256 if (!mUseWallpaperTextColor) {
257 setTextColor(mNonAdaptedColor);
258 }
Jason Monkaa573e92017-01-27 17:00:29 -0500259 }
260
261 @Override
262 public void onDensityOrFontScaleChanged() {
263 FontSizeUtils.updateFontSize(this, R.dimen.status_bar_clock_size);
264 setPaddingRelative(
265 mContext.getResources().getDimensionPixelSize(
266 R.dimen.status_bar_clock_starting_padding),
267 0,
268 mContext.getResources().getDimensionPixelSize(
269 R.dimen.status_bar_clock_end_padding),
270 0);
271 }
272
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000273 /**
274 * Sets whether the clock uses the wallpaperTextColor. If we're not using it, we'll revert back
275 * to dark-mode-based/tinted colors.
276 *
277 * @param shouldUseWallpaperTextColor whether we should use wallpaperTextColor for text color
278 */
279 public void useWallpaperTextColor(boolean shouldUseWallpaperTextColor) {
280 if (shouldUseWallpaperTextColor == mUseWallpaperTextColor) {
281 return;
282 }
283 mUseWallpaperTextColor = shouldUseWallpaperTextColor;
284
285 if (mUseWallpaperTextColor) {
286 setTextColor(Utils.getColorAttr(mContext, R.attr.wallpaperTextColor));
287 } else {
288 setTextColor(mNonAdaptedColor);
289 }
290 }
291
Jason Monkfe7c91b2015-08-13 15:42:28 -0400292 private void updateShowSeconds() {
293 if (mShowSeconds) {
294 // Wait until we have a display to start trying to show seconds.
295 if (mSecondsHandler == null && getDisplay() != null) {
296 mSecondsHandler = new Handler();
297 if (getDisplay().getState() == Display.STATE_ON) {
298 mSecondsHandler.postAtTime(mSecondTick,
299 SystemClock.uptimeMillis() / 1000 * 1000 + 1000);
300 }
301 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
302 filter.addAction(Intent.ACTION_SCREEN_ON);
303 mContext.registerReceiver(mScreenReceiver, filter);
304 }
305 } else {
306 if (mSecondsHandler != null) {
307 mContext.unregisterReceiver(mScreenReceiver);
308 mSecondsHandler.removeCallbacks(mSecondTick);
309 mSecondsHandler = null;
310 updateClock();
311 }
312 }
313 }
314
Joe Onorato263700d2010-05-14 11:54:53 -0700315 private final CharSequence getSmallTime() {
316 Context context = getContext();
Lucas Dupin4eae8812018-04-09 22:44:17 -0700317 boolean is24 = DateFormat.is24HourFormat(context, mCurrentUserId);
Elliott Hughes4caba612013-01-14 15:48:27 -0800318 LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);
Joe Onorato263700d2010-05-14 11:54:53 -0700319
320 final char MAGIC1 = '\uEF00';
321 final char MAGIC2 = '\uEF01';
322
323 SimpleDateFormat sdf;
Jason Monkfe7c91b2015-08-13 15:42:28 -0400324 String format = mShowSeconds
325 ? is24 ? d.timeFormat_Hms : d.timeFormat_hms
326 : is24 ? d.timeFormat_Hm : d.timeFormat_hm;
Joe Onorato263700d2010-05-14 11:54:53 -0700327 if (!format.equals(mClockFormatString)) {
Adrian Roos70dcf832016-04-20 15:51:42 -0700328 mContentDescriptionFormat = new SimpleDateFormat(format);
Joe Onorato263700d2010-05-14 11:54:53 -0700329 /*
330 * Search for an unquoted "a" in the format string, so we can
331 * add dummy characters around it to let us find it again after
332 * formatting and change its size.
333 */
Jorim Jaggi740beb52014-05-11 18:53:19 +0200334 if (mAmPmStyle != AM_PM_STYLE_NORMAL) {
Daniel Sandler87937db2010-05-27 13:44:11 -0400335 int a = -1;
336 boolean quoted = false;
337 for (int i = 0; i < format.length(); i++) {
338 char c = format.charAt(i);
Joe Onorato263700d2010-05-14 11:54:53 -0700339
Daniel Sandler87937db2010-05-27 13:44:11 -0400340 if (c == '\'') {
341 quoted = !quoted;
342 }
343 if (!quoted && c == 'a') {
344 a = i;
345 break;
346 }
Joe Onorato263700d2010-05-14 11:54:53 -0700347 }
348
Daniel Sandler87937db2010-05-27 13:44:11 -0400349 if (a >= 0) {
350 // Move a back so any whitespace before AM/PM is also in the alternate size.
351 final int b = a;
352 while (a > 0 && Character.isWhitespace(format.charAt(a-1))) {
353 a--;
354 }
355 format = format.substring(0, a) + MAGIC1 + format.substring(a, b)
Joe Onorato263700d2010-05-14 11:54:53 -0700356 + "a" + MAGIC2 + format.substring(b + 1);
Daniel Sandler87937db2010-05-27 13:44:11 -0400357 }
Joe Onorato263700d2010-05-14 11:54:53 -0700358 }
Joe Onorato263700d2010-05-14 11:54:53 -0700359 mClockFormat = sdf = new SimpleDateFormat(format);
360 mClockFormatString = format;
361 } else {
362 sdf = mClockFormat;
363 }
364 String result = sdf.format(mCalendar.getTime());
365
Jorim Jaggi740beb52014-05-11 18:53:19 +0200366 if (mAmPmStyle != AM_PM_STYLE_NORMAL) {
Daniel Sandler87937db2010-05-27 13:44:11 -0400367 int magic1 = result.indexOf(MAGIC1);
368 int magic2 = result.indexOf(MAGIC2);
369 if (magic1 >= 0 && magic2 > magic1) {
370 SpannableStringBuilder formatted = new SpannableStringBuilder(result);
Jorim Jaggi740beb52014-05-11 18:53:19 +0200371 if (mAmPmStyle == AM_PM_STYLE_GONE) {
Daniel Sandler87937db2010-05-27 13:44:11 -0400372 formatted.delete(magic1, magic2+1);
373 } else {
Jorim Jaggi740beb52014-05-11 18:53:19 +0200374 if (mAmPmStyle == AM_PM_STYLE_SMALL) {
Daniel Sandler87937db2010-05-27 13:44:11 -0400375 CharacterStyle style = new RelativeSizeSpan(0.7f);
376 formatted.setSpan(style, magic1, magic2,
377 Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
378 }
379 formatted.delete(magic2, magic2 + 1);
380 formatted.delete(magic1, magic1 + 1);
381 }
382 return formatted;
383 }
Joe Onorato263700d2010-05-14 11:54:53 -0700384 }
John Spurlock209bede2013-07-17 12:23:27 -0400385
Daniel Sandler87937db2010-05-27 13:44:11 -0400386 return result;
387
Joe Onorato263700d2010-05-14 11:54:53 -0700388 }
John Spurlock3c875662013-08-31 15:07:25 -0400389
390 private boolean mDemoMode;
391
392 @Override
393 public void dispatchDemoCommand(String command, Bundle args) {
394 if (!mDemoMode && command.equals(COMMAND_ENTER)) {
395 mDemoMode = true;
396 } else if (mDemoMode && command.equals(COMMAND_EXIT)) {
397 mDemoMode = false;
398 updateClock();
399 } else if (mDemoMode && command.equals(COMMAND_CLOCK)) {
400 String millis = args.getString("millis");
401 String hhmm = args.getString("hhmm");
402 if (millis != null) {
403 mCalendar.setTimeInMillis(Long.parseLong(millis));
404 } else if (hhmm != null && hhmm.length() == 4) {
405 int hh = Integer.parseInt(hhmm.substring(0, 2));
406 int mm = Integer.parseInt(hhmm.substring(2));
Lucas Dupin4eae8812018-04-09 22:44:17 -0700407 boolean is24 = DateFormat.is24HourFormat(getContext(), mCurrentUserId);
Julia Reynoldsc11d8382015-07-16 14:40:37 -0400408 if (is24) {
409 mCalendar.set(Calendar.HOUR_OF_DAY, hh);
410 } else {
411 mCalendar.set(Calendar.HOUR, hh);
412 }
John Spurlock3c875662013-08-31 15:07:25 -0400413 mCalendar.set(Calendar.MINUTE, mm);
414 }
415 setText(getSmallTime());
Adrian Roos70dcf832016-04-20 15:51:42 -0700416 setContentDescription(mContentDescriptionFormat.format(mCalendar.getTime()));
John Spurlock3c875662013-08-31 15:07:25 -0400417 }
418 }
Jason Monkfe7c91b2015-08-13 15:42:28 -0400419
420 private final BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
421 @Override
422 public void onReceive(Context context, Intent intent) {
423 String action = intent.getAction();
424 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
425 if (mSecondsHandler != null) {
426 mSecondsHandler.removeCallbacks(mSecondTick);
427 }
428 } else if (Intent.ACTION_SCREEN_ON.equals(action)) {
429 if (mSecondsHandler != null) {
430 mSecondsHandler.postAtTime(mSecondTick,
431 SystemClock.uptimeMillis() / 1000 * 1000 + 1000);
432 }
433 }
434 }
435 };
436
437 private final Runnable mSecondTick = new Runnable() {
438 @Override
439 public void run() {
440 if (mCalendar != null) {
441 updateClock();
442 }
443 mSecondsHandler.postAtTime(this, SystemClock.uptimeMillis() / 1000 * 1000 + 1000);
444 }
445 };
Joe Onorato263700d2010-05-14 11:54:53 -0700446}
447