Methods Summary |
---|
protected void | onAttachedToWindow()
super.onAttachedToWindow();
if (Log.LOGV) Log.v("onAttachedToWindow " + this);
if (mAttached) return;
mAttached = true;
if (mAnimate) {
AnimationDrawable frameAnimation =
(AnimationDrawable) mContext.getResources().getDrawable(
R.drawable.animate_circle);
View digitalClock = findViewById(R.id.digitalClock);
digitalClock.setBackgroundDrawable(frameAnimation);
/* Start the animation (looped playback by default). */
((AnimationDrawable) digitalClock.getBackground()).start();
/* No luck wrapping animation or individual bitmaps in a
ScaleDrawable */
digitalClock.requestLayout();
}
if (mLive) {
/* monitor time ticks, time changed, timezone */
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
}
/* monitor 12/24-hour display preference */
mFormatChangeObserver = new FormatChangeObserver();
mContext.getContentResolver().registerContentObserver(
Settings.System.CONTENT_URI, true, mFormatChangeObserver);
updateTime();
|
protected void | onDetachedFromWindow()
super.onDetachedFromWindow();
if (!mAttached) return;
mAttached = false;
Drawable background = getBackground();
if (background instanceof AnimationDrawable) {
((AnimationDrawable) background).stop();
}
if (mLive) {
mContext.unregisterReceiver(mIntentReceiver);
}
mContext.getContentResolver().unregisterContentObserver(
mFormatChangeObserver);
|
protected void | onFinishInflate()
super.onFinishInflate();
mTimeDisplay = (TextView) findViewById(R.id.timeDisplay);
mAmPm = new AmPm(this);
mCalendar = Calendar.getInstance();
setDateFormat();
|
void | setAnimate()
mAnimate = true;
|
private void | setDateFormat()
mFormat = Alarms.get24HourMode(mContext) ? M24 : M12;
mAmPm.setShowAmPm(mFormat == M12);
|
void | setLive(boolean live)
mLive = live;
|
void | updateTime(java.util.Calendar c)
mCalendar = c;
updateTime();
|
private void | updateTime()
if (mLive) {
mCalendar.setTimeInMillis(System.currentTimeMillis());
}
CharSequence newTime = DateFormat.format(mFormat, mCalendar);
mTimeDisplay.setText(newTime);
mAmPm.setIsMorning(mCalendar.get(Calendar.AM_PM) == 0);
|