DigitalClockpublic class DigitalClock extends TextView Like AnalogClock, but digital. Shows seconds.
FIXME: implement separate views for hours/minutes/seconds, so
proportional fonts don't shake rendering |
Fields Summary |
---|
Calendar | mCalendar | private static final String | m12 | private static final String | m24 | private FormatChangeObserver | mFormatChangeObserver | private Runnable | mTicker | private android.os.Handler | mHandler | private boolean | mTickerStopped | String | mFormat |
Methods Summary |
---|
private boolean | get24HourMode()Pulls 12/24 mode from system settings
return android.text.format.DateFormat.is24HourFormat(getContext());
| private void | initClock(android.content.Context context)
Resources r = mContext.getResources();
if (mCalendar == null) {
mCalendar = Calendar.getInstance();
}
mFormatChangeObserver = new FormatChangeObserver();
getContext().getContentResolver().registerContentObserver(
Settings.System.CONTENT_URI, true, mFormatChangeObserver);
setFormat();
| protected void | onAttachedToWindow()
mTickerStopped = false;
super.onAttachedToWindow();
mHandler = new Handler();
/**
* requests a tick on the next hard-second boundary
*/
mTicker = new Runnable() {
public void run() {
if (mTickerStopped) return;
mCalendar.setTimeInMillis(System.currentTimeMillis());
setText(DateFormat.format(mFormat, mCalendar));
invalidate();
long now = SystemClock.uptimeMillis();
long next = now + (1000 - now % 1000);
mHandler.postAtTime(mTicker, next);
}
};
mTicker.run();
| protected void | onDetachedFromWindow()
super.onDetachedFromWindow();
mTickerStopped = true;
| private void | setFormat()
if (get24HourMode()) {
mFormat = m24;
} else {
mFormat = m12;
}
|
|