summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/DigitalClock.java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 18:28:45 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 18:28:45 -0800
commitd83a98f4ce9cfa908f5c54bbd70f03eec07e7553 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /core/java/android/widget/DigitalClock.java
parent076357b8567458d4b6dfdcf839ef751634cd2bfb (diff)
downloadframeworks_base-d83a98f4ce9cfa908f5c54bbd70f03eec07e7553.zip
frameworks_base-d83a98f4ce9cfa908f5c54bbd70f03eec07e7553.tar.gz
frameworks_base-d83a98f4ce9cfa908f5c54bbd70f03eec07e7553.tar.bz2
auto import from //depot/cupcake/@135843
Diffstat (limited to 'core/java/android/widget/DigitalClock.java')
-rw-r--r--core/java/android/widget/DigitalClock.java129
1 files changed, 0 insertions, 129 deletions
diff --git a/core/java/android/widget/DigitalClock.java b/core/java/android/widget/DigitalClock.java
deleted file mode 100644
index 379883a..0000000
--- a/core/java/android/widget/DigitalClock.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.widget;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.database.ContentObserver;
-import android.os.Handler;
-import android.os.SystemClock;
-import android.provider.Settings;
-import android.text.format.DateFormat;
-import android.util.AttributeSet;
-
-import java.util.Calendar;
-
-/**
- * Like AnalogClock, but digital. Shows seconds.
- *
- * FIXME: implement separate views for hours/minutes/seconds, so
- * proportional fonts don't shake rendering
- */
-
-public class DigitalClock extends TextView {
-
- Calendar mCalendar;
- private final static String m12 = "h:mm:ss aa";
- private final static String m24 = "k:mm:ss";
- private FormatChangeObserver mFormatChangeObserver;
-
- private Runnable mTicker;
- private Handler mHandler;
-
- private boolean mTickerStopped = false;
-
- String mFormat;
-
- public DigitalClock(Context context) {
- super(context);
- initClock(context);
- }
-
- public DigitalClock(Context context, AttributeSet attrs) {
- super(context, attrs);
- initClock(context);
- }
-
- private void initClock(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();
- }
-
- @Override
- 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();
- }
-
- @Override
- protected void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- mTickerStopped = true;
- }
-
- /**
- * Pulls 12/24 mode from system settings
- */
- private boolean get24HourMode() {
- return android.text.format.DateFormat.is24HourFormat(getContext());
- }
-
- private void setFormat() {
- if (get24HourMode()) {
- mFormat = m24;
- } else {
- mFormat = m12;
- }
- }
-
- private class FormatChangeObserver extends ContentObserver {
- public FormatChangeObserver() {
- super(new Handler());
- }
-
- @Override
- public void onChange(boolean selfChange) {
- setFormat();
- }
- }
-}