Skip to content

Commit a76f7db

Browse files
author
Romain Guy
committed
Respond to ticks when a timezone is set and it doesn't display seconds
Bug #7489774 This change also fixes a crash if you programmatically set the time formats from code before the widget is attached to the window. Change-Id: I73ead93f5866d9059a4b3823c4304aeca8e419b6
1 parent 1b3b254 commit a76f7db

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

core/java/android/widget/TextClock.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,11 @@ public void onChange(boolean selfChange, Uri uri) {
135135
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
136136
@Override
137137
public void onReceive(Context context, Intent intent) {
138-
if (mTimeZone == null) {
139-
if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) {
140-
final String timeZone = intent.getStringExtra("time-zone");
141-
createTime(timeZone);
142-
}
143-
onTimeChanged();
138+
if (mTimeZone == null && Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
139+
final String timeZone = intent.getStringExtra("time-zone");
140+
createTime(timeZone);
144141
}
142+
onTimeChanged();
145143
}
146144
};
147145

@@ -406,11 +404,9 @@ private void chooseFormat(boolean handleTicker) {
406404
boolean hadSeconds = mHasSeconds;
407405
mHasSeconds = DateFormat.hasSeconds(mFormat);
408406

409-
if (handleTicker) {
410-
if (hadSeconds != mHasSeconds) {
411-
if (hadSeconds) getHandler().removeCallbacks(mTicker);
412-
else mTicker.run();
413-
}
407+
if (handleTicker && mAttached && hadSeconds != mHasSeconds) {
408+
if (hadSeconds) getHandler().removeCallbacks(mTicker);
409+
else mTicker.run();
414410
}
415411
}
416412

0 commit comments

Comments
 (0)