diff options
author | Daniel Sandler <dsandler@android.com> | 2013-10-01 02:57:45 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-10-01 02:57:45 +0000 |
commit | 7eb5ce03d9697caa2e9caf0437036a937d081e90 (patch) | |
tree | eec023a2ac6f7520a6d8aea1430248456c8f6a70 | |
parent | 48cc1dc4709216256d2d7faf5a50ffcb01252efe (diff) | |
parent | b478a71625235f554263324dbf0501f6b6c87520 (diff) | |
download | frameworks_base-7eb5ce03d9697caa2e9caf0437036a937d081e90.zip frameworks_base-7eb5ce03d9697caa2e9caf0437036a937d081e90.tar.gz frameworks_base-7eb5ce03d9697caa2e9caf0437036a937d081e90.tar.bz2 |
Merge "Update date format in panel on locale change." into klp-dev
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java | 82 |
1 files changed, 20 insertions, 62 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java index 277501d..16e2e07 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java @@ -21,6 +21,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.util.AttributeSet; +import android.util.Log; import android.view.View; import android.view.ViewParent; import android.widget.TextView; @@ -39,10 +40,7 @@ public class DateView extends TextView { private final Date mCurrentTime = new Date(); private SimpleDateFormat mDateFormat; - private boolean mChangedLocale; - private boolean mAttachedToWindow; - private boolean mWindowVisible; - private boolean mUpdating; + private String mLastText; private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override @@ -53,7 +51,8 @@ public class DateView extends TextView { || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_LOCALE_CHANGED.equals(action)) { if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { - mChangedLocale = true; + // need to get a fresh date format + mDateFormat = null; } updateClock(); } @@ -67,80 +66,39 @@ public class DateView extends TextView { @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - mAttachedToWindow = true; - setUpdates(); - } - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - mAttachedToWindow = false; - setUpdates(); - } + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_TIME_TICK); + filter.addAction(Intent.ACTION_TIME_CHANGED); + filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); + filter.addAction(Intent.ACTION_LOCALE_CHANGED); + mContext.registerReceiver(mIntentReceiver, filter, null, null); - @Override - protected void onWindowVisibilityChanged(int visibility) { - super.onWindowVisibilityChanged(visibility); - mWindowVisible = visibility == VISIBLE; - setUpdates(); + updateClock(); } @Override - protected void onVisibilityChanged(View changedView, int visibility) { - super.onVisibilityChanged(changedView, visibility); - setUpdates(); - } + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); - @Override - protected int getSuggestedMinimumWidth() { - // makes the large background bitmap not force us to full width - return 0; + mDateFormat = null; // reload the locale next time + mContext.unregisterReceiver(mIntentReceiver); } protected void updateClock() { - if (mDateFormat == null || mChangedLocale) { + if (mDateFormat == null) { final String dateFormat = getContext().getString(R.string.system_ui_date_pattern); final Locale l = Locale.getDefault(); final String fmt = ICU.getBestDateTimePattern(dateFormat, l.toString()); mDateFormat = new SimpleDateFormat(fmt, l); - mChangedLocale = false; } mCurrentTime.setTime(System.currentTimeMillis()); - setText(mDateFormat.format(mCurrentTime)); - } - private boolean isVisible() { - View v = this; - while (true) { - if (v.getVisibility() != VISIBLE) { - return false; - } - final ViewParent parent = v.getParent(); - if (parent instanceof View) { - v = (View)parent; - } else { - return true; - } - } - } - - private void setUpdates() { - boolean update = mAttachedToWindow && mWindowVisible && isVisible(); - if (update != mUpdating) { - mUpdating = update; - if (update) { - // Register for Intent broadcasts for the clock and battery - IntentFilter filter = new IntentFilter(); - filter.addAction(Intent.ACTION_TIME_TICK); - filter.addAction(Intent.ACTION_TIME_CHANGED); - filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); - filter.addAction(Intent.ACTION_LOCALE_CHANGED); - mContext.registerReceiver(mIntentReceiver, filter, null, null); - updateClock(); - } else { - mContext.unregisterReceiver(mIntentReceiver); - } + final String text = mDateFormat.format(mCurrentTime); + if (!text.equals(mLastText)) { + setText(text); + mLastText = text; } } } |