2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.systemui.statusbar;
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.IntentFilter;
23 import android.util.AttributeSet;
24 import android.util.Slog;
25 import android.widget.TextView;
26 import android.view.MotionEvent;
28 import java.text.DateFormat;
29 import java.util.Date;
31 public final class DateView extends TextView {
32 private static final String TAG = "DateView";
34 private boolean mUpdating = false;
36 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
38 public void onReceive(Context context, Intent intent) {
39 String action = intent.getAction();
40 if (action.equals(Intent.ACTION_TIME_TICK)
41 || action.equals(Intent.ACTION_TIMEZONE_CHANGED)) {
47 public DateView(Context context, AttributeSet attrs) {
48 super(context, attrs);
52 protected void onAttachedToWindow() {
53 super.onAttachedToWindow();
57 protected void onDetachedFromWindow() {
58 super.onDetachedFromWindow();
63 protected int getSuggestedMinimumWidth() {
64 // makes the large background bitmap not force us to full width
68 private final void updateClock() {
69 Date now = new Date();
70 setText(DateFormat.getDateInstance(DateFormat.LONG).format(now));
73 void setUpdates(boolean update) {
74 if (update != mUpdating) {
77 // Register for Intent broadcasts for the clock and battery
78 IntentFilter filter = new IntentFilter();
79 filter.addAction(Intent.ACTION_TIME_TICK);
80 filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
81 mContext.registerReceiver(mIntentReceiver, filter, null, null);
84 mContext.unregisterReceiver(mIntentReceiver);