1263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato/*
2263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato * Copyright (C) 2006 The Android Open Source Project
3263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato *
4263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato * Licensed under the Apache License, Version 2.0 (the "License");
5263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato * you may not use this file except in compliance with the License.
6263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato * You may obtain a copy of the License at
7263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato *
8263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato *      http://www.apache.org/licenses/LICENSE-2.0
9263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato *
10263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato * Unless required by applicable law or agreed to in writing, software
11263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato * distributed under the License is distributed on an "AS IS" BASIS,
12263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato * See the License for the specific language governing permissions and
14263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato * limitations under the License.
15263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato */
16263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
17fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onoratopackage com.android.systemui.statusbar.policy;
18263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
199c4a707912da2c954b2d3d1311b8a691ded8aa16Selim Cinekimport android.app.ActivityManager;
2087937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandlerimport android.content.BroadcastReceiver;
21263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport android.content.Context;
22263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport android.content.Intent;
23263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport android.content.IntentFilter;
24740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggiimport android.content.res.TypedArray;
253c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlockimport android.os.Bundle;
269c4a707912da2c954b2d3d1311b8a691ded8aa16Selim Cinekimport android.os.UserHandle;
27263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport android.text.Spannable;
28263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport android.text.SpannableStringBuilder;
2987937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandlerimport android.text.format.DateFormat;
3087937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandlerimport android.text.style.CharacterStyle;
3187937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandlerimport android.text.style.RelativeSizeSpan;
32263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport android.util.AttributeSet;
33263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport android.widget.TextView;
34263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
353c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlockimport com.android.systemui.DemoMode;
36740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggiimport com.android.systemui.R;
373c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock
38263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport java.text.SimpleDateFormat;
39263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport java.util.Calendar;
4043b23c6c6920287bfdb94be9a2a2fa7028a63e28Daniel Sandlerimport java.util.Locale;
41263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onoratoimport java.util.TimeZone;
42263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
434caba61ea0433099fc94e61221d02542c34e9e3aElliott Hughesimport libcore.icu.LocaleData;
444caba61ea0433099fc94e61221d02542c34e9e3aElliott Hughes
45263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato/**
46ce4f5e5c7094781434a67fe887efb8d798663c65Daniel Sandler * Digital clock for the status bar.
47263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato */
483c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlockpublic class Clock extends TextView implements DemoMode {
49263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    private boolean mAttached;
50263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    private Calendar mCalendar;
51263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    private String mClockFormatString;
52263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    private SimpleDateFormat mClockFormat;
5343b23c6c6920287bfdb94be9a2a2fa7028a63e28Daniel Sandler    private Locale mLocale;
54263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
5587937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler    private static final int AM_PM_STYLE_NORMAL  = 0;
5687937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler    private static final int AM_PM_STYLE_SMALL   = 1;
5787937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler    private static final int AM_PM_STYLE_GONE    = 2;
5887937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler
59740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi    private final int mAmPmStyle;
6087937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler
61263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    public Clock(Context context) {
62263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        this(context, null);
63263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    }
64263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
65263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    public Clock(Context context, AttributeSet attrs) {
66263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        this(context, attrs, 0);
67263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    }
68263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
69263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    public Clock(Context context, AttributeSet attrs, int defStyle) {
70263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        super(context, attrs, defStyle);
71740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi        TypedArray a = context.getTheme().obtainStyledAttributes(
72740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi                attrs,
73740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi                R.styleable.Clock,
74740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi                0, 0);
75740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi        try {
76740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi            mAmPmStyle = a.getInt(R.styleable.Clock_amPmStyle, AM_PM_STYLE_GONE);
77740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi        } finally {
78740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi            a.recycle();
79740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi        }
80263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    }
81263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
82263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    @Override
83263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    protected void onAttachedToWindow() {
84263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        super.onAttachedToWindow();
85263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
86263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        if (!mAttached) {
87263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            mAttached = true;
88263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            IntentFilter filter = new IntentFilter();
89263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
90263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            filter.addAction(Intent.ACTION_TIME_TICK);
91263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            filter.addAction(Intent.ACTION_TIME_CHANGED);
92263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
93263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
94ce4f5e5c7094781434a67fe887efb8d798663c65Daniel Sandler            filter.addAction(Intent.ACTION_USER_SWITCHED);
95263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
969c4a707912da2c954b2d3d1311b8a691ded8aa16Selim Cinek            getContext().registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter,
979c4a707912da2c954b2d3d1311b8a691ded8aa16Selim Cinek                    null, getHandler());
98263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        }
99263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
100263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        // NOTE: It's safe to do these after registering the receiver since the receiver always runs
101263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        // in the main thread, therefore the receiver can't run before this method returns.
102263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
103263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        // The time zone may have changed while the receiver wasn't registered, so update the Time
104263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        mCalendar = Calendar.getInstance(TimeZone.getDefault());
105263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
106263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        // Make sure we update to the current time
107263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        updateClock();
108263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    }
109263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
110263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    @Override
111263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    protected void onDetachedFromWindow() {
112263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        super.onDetachedFromWindow();
113263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        if (mAttached) {
114263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            getContext().unregisterReceiver(mIntentReceiver);
115263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            mAttached = false;
116263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        }
117263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    }
118263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
119263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
120263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        @Override
121263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        public void onReceive(Context context, Intent intent) {
122263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            String action = intent.getAction();
123263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)) {
124263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato                String tz = intent.getStringExtra("time-zone");
125263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato                mCalendar = Calendar.getInstance(TimeZone.getTimeZone(tz));
126263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato                if (mClockFormat != null) {
127263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato                    mClockFormat.setTimeZone(mCalendar.getTimeZone());
128263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato                }
12943b23c6c6920287bfdb94be9a2a2fa7028a63e28Daniel Sandler            } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
13043b23c6c6920287bfdb94be9a2a2fa7028a63e28Daniel Sandler                final Locale newLocale = getResources().getConfiguration().locale;
13143b23c6c6920287bfdb94be9a2a2fa7028a63e28Daniel Sandler                if (! newLocale.equals(mLocale)) {
13243b23c6c6920287bfdb94be9a2a2fa7028a63e28Daniel Sandler                    mLocale = newLocale;
13343b23c6c6920287bfdb94be9a2a2fa7028a63e28Daniel Sandler                    mClockFormatString = ""; // force refresh
13443b23c6c6920287bfdb94be9a2a2fa7028a63e28Daniel Sandler                }
135263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            }
136263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            updateClock();
137263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        }
138263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    };
139263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
140263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    final void updateClock() {
1413c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock        if (mDemoMode) return;
142263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        mCalendar.setTimeInMillis(System.currentTimeMillis());
143263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        setText(getSmallTime());
144263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    }
145263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
146263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    private final CharSequence getSmallTime() {
147263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        Context context = getContext();
1489c4a707912da2c954b2d3d1311b8a691ded8aa16Selim Cinek        boolean is24 = DateFormat.is24HourFormat(context, ActivityManager.getCurrentUser());
1494caba61ea0433099fc94e61221d02542c34e9e3aElliott Hughes        LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);
150263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
151263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        final char MAGIC1 = '\uEF00';
152263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        final char MAGIC2 = '\uEF01';
153263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
154263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        SimpleDateFormat sdf;
1554caba61ea0433099fc94e61221d02542c34e9e3aElliott Hughes        String format = is24 ? d.timeFormat24 : d.timeFormat12;
156263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        if (!format.equals(mClockFormatString)) {
157263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            /*
158263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato             * Search for an unquoted "a" in the format string, so we can
159263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato             * add dummy characters around it to let us find it again after
160263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato             * formatting and change its size.
161263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato             */
162740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi            if (mAmPmStyle != AM_PM_STYLE_NORMAL) {
16387937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                int a = -1;
16487937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                boolean quoted = false;
16587937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                for (int i = 0; i < format.length(); i++) {
16687937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    char c = format.charAt(i);
16787937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler
16887937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    if (c == '\'') {
16987937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                        quoted = !quoted;
17087937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    }
17187937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    if (!quoted && c == 'a') {
17287937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                        a = i;
17387937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                        break;
17487937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    }
175263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato                }
176263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
17787937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                if (a >= 0) {
17887937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    // Move a back so any whitespace before AM/PM is also in the alternate size.
17987937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    final int b = a;
18087937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    while (a > 0 && Character.isWhitespace(format.charAt(a-1))) {
18187937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                        a--;
18287937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    }
18387937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    format = format.substring(0, a) + MAGIC1 + format.substring(a, b)
184263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato                        + "a" + MAGIC2 + format.substring(b + 1);
18587937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                }
186263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            }
187263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            mClockFormat = sdf = new SimpleDateFormat(format);
188263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            mClockFormatString = format;
189263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        } else {
190263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato            sdf = mClockFormat;
191263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        }
192263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        String result = sdf.format(mCalendar.getTime());
193263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
194740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi        if (mAmPmStyle != AM_PM_STYLE_NORMAL) {
19587937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler            int magic1 = result.indexOf(MAGIC1);
19687937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler            int magic2 = result.indexOf(MAGIC2);
19787937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler            if (magic1 >= 0 && magic2 > magic1) {
19887937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                SpannableStringBuilder formatted = new SpannableStringBuilder(result);
199740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi                if (mAmPmStyle == AM_PM_STYLE_GONE) {
20087937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    formatted.delete(magic1, magic2+1);
20187937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                } else {
202740beb50aa28a9f1b4de76e910bc7230e1fb2cf8Jorim Jaggi                    if (mAmPmStyle == AM_PM_STYLE_SMALL) {
20387937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                        CharacterStyle style = new RelativeSizeSpan(0.7f);
20487937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                        formatted.setSpan(style, magic1, magic2,
20587937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                                          Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
20687937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    }
20787937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    formatted.delete(magic2, magic2 + 1);
20887937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                    formatted.delete(magic1, magic1 + 1);
20987937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                }
21087937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler                return formatted;
21187937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler            }
212263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato        }
213209bede6b9edb9171e5bee4077b48e35004a37b4John Spurlock
21487937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler        return result;
21587937dbcd1cee800aa6cc9824bfc32b587d893bdDaniel Sandler
216263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato    }
2173c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock
2183c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock    private boolean mDemoMode;
2193c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock
2203c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock    @Override
2213c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock    public void dispatchDemoCommand(String command, Bundle args) {
2223c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock        if (!mDemoMode && command.equals(COMMAND_ENTER)) {
2233c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock            mDemoMode = true;
2243c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock        } else if (mDemoMode && command.equals(COMMAND_EXIT)) {
2253c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock            mDemoMode = false;
2263c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock            updateClock();
2273c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock        } else if (mDemoMode && command.equals(COMMAND_CLOCK)) {
2283c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock            String millis = args.getString("millis");
2293c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock            String hhmm = args.getString("hhmm");
2303c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock            if (millis != null) {
2313c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock                mCalendar.setTimeInMillis(Long.parseLong(millis));
2323c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock            } else if (hhmm != null && hhmm.length() == 4) {
2333c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock                int hh = Integer.parseInt(hhmm.substring(0, 2));
2343c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock                int mm = Integer.parseInt(hhmm.substring(2));
2353c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock                mCalendar.set(Calendar.HOUR, hh);
2363c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock                mCalendar.set(Calendar.MINUTE, mm);
2373c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock            }
2383c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock            setText(getSmallTime());
2393c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock        }
2403c87566c115e1fce3fdc09a6fe40488bcdc04cdeJohn Spurlock    }
241263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato}
242263700df7ba34e70396d014d09a274d9ebbbf6caJoe Onorato
243