Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java +20 −62 Original line number Original line Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.IntentFilter; import android.content.IntentFilter; import android.util.AttributeSet; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.View; import android.view.ViewParent; import android.view.ViewParent; import android.widget.TextView; import android.widget.TextView; Loading @@ -39,10 +40,7 @@ public class DateView extends TextView { private final Date mCurrentTime = new Date(); private final Date mCurrentTime = new Date(); private SimpleDateFormat mDateFormat; private SimpleDateFormat mDateFormat; private boolean mChangedLocale; private String mLastText; private boolean mAttachedToWindow; private boolean mWindowVisible; private boolean mUpdating; private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override @Override Loading @@ -53,7 +51,8 @@ public class DateView extends TextView { || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_LOCALE_CHANGED.equals(action)) { || Intent.ACTION_LOCALE_CHANGED.equals(action)) { if (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(); updateClock(); } } Loading @@ -67,80 +66,39 @@ public class DateView extends TextView { @Override @Override protected void onAttachedToWindow() { protected void onAttachedToWindow() { super.onAttachedToWindow(); super.onAttachedToWindow(); mAttachedToWindow = true; setUpdates(); } @Override IntentFilter filter = new IntentFilter(); protected void onDetachedFromWindow() { filter.addAction(Intent.ACTION_TIME_TICK); super.onDetachedFromWindow(); filter.addAction(Intent.ACTION_TIME_CHANGED); mAttachedToWindow = false; filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); setUpdates(); filter.addAction(Intent.ACTION_LOCALE_CHANGED); } mContext.registerReceiver(mIntentReceiver, filter, null, null); @Override updateClock(); protected void onWindowVisibilityChanged(int visibility) { super.onWindowVisibilityChanged(visibility); mWindowVisible = visibility == VISIBLE; setUpdates(); } } @Override @Override protected void onVisibilityChanged(View changedView, int visibility) { protected void onDetachedFromWindow() { super.onVisibilityChanged(changedView, visibility); super.onDetachedFromWindow(); setUpdates(); } @Override mDateFormat = null; // reload the locale next time protected int getSuggestedMinimumWidth() { mContext.unregisterReceiver(mIntentReceiver); // makes the large background bitmap not force us to full width return 0; } } protected void updateClock() { protected void updateClock() { if (mDateFormat == null || mChangedLocale) { if (mDateFormat == null) { final String dateFormat = getContext().getString(R.string.system_ui_date_pattern); final String dateFormat = getContext().getString(R.string.system_ui_date_pattern); final Locale l = Locale.getDefault(); final Locale l = Locale.getDefault(); final String fmt = ICU.getBestDateTimePattern(dateFormat, l.toString()); final String fmt = ICU.getBestDateTimePattern(dateFormat, l.toString()); mDateFormat = new SimpleDateFormat(fmt, l); mDateFormat = new SimpleDateFormat(fmt, l); mChangedLocale = false; } } mCurrentTime.setTime(System.currentTimeMillis()); 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() { final String text = mDateFormat.format(mCurrentTime); boolean update = mAttachedToWindow && mWindowVisible && isVisible(); if (!text.equals(mLastText)) { if (update != mUpdating) { setText(text); mUpdating = update; mLastText = text; 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); } } } } } } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java +20 −62 Original line number Original line Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.IntentFilter; import android.content.IntentFilter; import android.util.AttributeSet; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.View; import android.view.ViewParent; import android.view.ViewParent; import android.widget.TextView; import android.widget.TextView; Loading @@ -39,10 +40,7 @@ public class DateView extends TextView { private final Date mCurrentTime = new Date(); private final Date mCurrentTime = new Date(); private SimpleDateFormat mDateFormat; private SimpleDateFormat mDateFormat; private boolean mChangedLocale; private String mLastText; private boolean mAttachedToWindow; private boolean mWindowVisible; private boolean mUpdating; private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override @Override Loading @@ -53,7 +51,8 @@ public class DateView extends TextView { || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_LOCALE_CHANGED.equals(action)) { || Intent.ACTION_LOCALE_CHANGED.equals(action)) { if (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(); updateClock(); } } Loading @@ -67,80 +66,39 @@ public class DateView extends TextView { @Override @Override protected void onAttachedToWindow() { protected void onAttachedToWindow() { super.onAttachedToWindow(); super.onAttachedToWindow(); mAttachedToWindow = true; setUpdates(); } @Override IntentFilter filter = new IntentFilter(); protected void onDetachedFromWindow() { filter.addAction(Intent.ACTION_TIME_TICK); super.onDetachedFromWindow(); filter.addAction(Intent.ACTION_TIME_CHANGED); mAttachedToWindow = false; filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); setUpdates(); filter.addAction(Intent.ACTION_LOCALE_CHANGED); } mContext.registerReceiver(mIntentReceiver, filter, null, null); @Override updateClock(); protected void onWindowVisibilityChanged(int visibility) { super.onWindowVisibilityChanged(visibility); mWindowVisible = visibility == VISIBLE; setUpdates(); } } @Override @Override protected void onVisibilityChanged(View changedView, int visibility) { protected void onDetachedFromWindow() { super.onVisibilityChanged(changedView, visibility); super.onDetachedFromWindow(); setUpdates(); } @Override mDateFormat = null; // reload the locale next time protected int getSuggestedMinimumWidth() { mContext.unregisterReceiver(mIntentReceiver); // makes the large background bitmap not force us to full width return 0; } } protected void updateClock() { protected void updateClock() { if (mDateFormat == null || mChangedLocale) { if (mDateFormat == null) { final String dateFormat = getContext().getString(R.string.system_ui_date_pattern); final String dateFormat = getContext().getString(R.string.system_ui_date_pattern); final Locale l = Locale.getDefault(); final Locale l = Locale.getDefault(); final String fmt = ICU.getBestDateTimePattern(dateFormat, l.toString()); final String fmt = ICU.getBestDateTimePattern(dateFormat, l.toString()); mDateFormat = new SimpleDateFormat(fmt, l); mDateFormat = new SimpleDateFormat(fmt, l); mChangedLocale = false; } } mCurrentTime.setTime(System.currentTimeMillis()); 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() { final String text = mDateFormat.format(mCurrentTime); boolean update = mAttachedToWindow && mWindowVisible && isVisible(); if (!text.equals(mLastText)) { if (update != mUpdating) { setText(text); mUpdating = update; mLastText = text; 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); } } } } } } }