DateViewpublic class DateView extends android.widget.TextView
Fields Summary |
---|
private static final String | TAG | private final Date | mCurrentTime | private SimpleDateFormat | mDateFormat | private String | mLastText | private String | mDatePattern | private android.content.BroadcastReceiver | mIntentReceiver |
Constructors Summary |
---|
public DateView(android.content.Context context, android.util.AttributeSet attrs)
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.DateView,
0, 0);
try {
mDatePattern = a.getString(R.styleable.DateView_datePattern);
} finally {
a.recycle();
}
if (mDatePattern == null) {
mDatePattern = getContext().getString(R.string.system_ui_date_pattern);
}
|
Methods Summary |
---|
protected void | onAttachedToWindow()
super.onAttachedToWindow();
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);
getContext().registerReceiver(mIntentReceiver, filter, null, null);
updateClock();
| protected void | onDetachedFromWindow()
super.onDetachedFromWindow();
mDateFormat = null; // reload the locale next time
getContext().unregisterReceiver(mIntentReceiver);
| protected void | updateClock()
if (mDateFormat == null) {
final Locale l = Locale.getDefault();
final String fmt = DateFormat.getBestDateTimePattern(l, mDatePattern);
mDateFormat = new SimpleDateFormat(fmt, l);
}
mCurrentTime.setTime(System.currentTimeMillis());
final String text = mDateFormat.format(mCurrentTime);
if (!text.equals(mLastText)) {
setText(text);
mLastText = text;
}
|
|