FileDocCategorySizeDatePackage
DigitalClock.javaAPI DocAndroid 5.1 API3917Thu Mar 12 22:22:10 GMT 2015android.widget

DigitalClock

public class DigitalClock extends TextView
Like AnalogClock, but digital. Shows seconds.
deprecated
It is recommended you use {@link TextClock} instead.

Fields Summary
Calendar
mCalendar
private FormatChangeObserver
mFormatChangeObserver
private Runnable
mTicker
private android.os.Handler
mHandler
private boolean
mTickerStopped
String
mFormat
Constructors Summary
public DigitalClock(android.content.Context context)


       
        super(context);
        initClock();
    
public DigitalClock(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
        initClock();
    
Methods Summary
private voidinitClock()

        if (mCalendar == null) {
            mCalendar = Calendar.getInstance();
        }

        mFormatChangeObserver = new FormatChangeObserver();
        getContext().getContentResolver().registerContentObserver(
                Settings.System.CONTENT_URI, true, mFormatChangeObserver);

        setFormat();
    
protected voidonAttachedToWindow()

        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 voidonDetachedFromWindow()

        super.onDetachedFromWindow();
        mTickerStopped = true;
    
public voidonInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)

        super.onInitializeAccessibilityEvent(event);
        //noinspection deprecation
        event.setClassName(DigitalClock.class.getName());
    
public voidonInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)

        super.onInitializeAccessibilityNodeInfo(info);
        //noinspection deprecation
        info.setClassName(DigitalClock.class.getName());
    
private voidsetFormat()

        mFormat = DateFormat.getTimeFormatString(getContext());