TimePickerClockDelegate.java revision 3fc00e3139706c2c90f8e7261eef48086887dc11
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package android.widget;
18
19import android.content.Context;
20import android.content.res.ColorStateList;
21import android.content.res.Configuration;
22import android.content.res.Resources;
23import android.content.res.TypedArray;
24import android.os.Parcel;
25import android.os.Parcelable;
26import android.text.format.DateFormat;
27import android.text.format.DateUtils;
28import android.util.AttributeSet;
29import android.util.Log;
30import android.util.TypedValue;
31import android.view.HapticFeedbackConstants;
32import android.view.KeyCharacterMap;
33import android.view.KeyEvent;
34import android.view.LayoutInflater;
35import android.view.View;
36import android.view.View.AccessibilityDelegate;
37import android.view.ViewGroup;
38import android.view.accessibility.AccessibilityEvent;
39import android.view.accessibility.AccessibilityNodeInfo;
40import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
41
42import com.android.internal.R;
43
44import java.util.ArrayList;
45import java.util.Calendar;
46import java.util.Locale;
47
48/**
49 * A delegate implementing the radial clock-based TimePicker.
50 */
51class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate implements
52        RadialTimePickerView.OnValueSelectedListener {
53
54    private static final String TAG = "TimePickerClockDelegate";
55
56    // Index used by RadialPickerLayout
57    private static final int HOUR_INDEX = 0;
58    private static final int MINUTE_INDEX = 1;
59
60    // NOT a real index for the purpose of what's showing.
61    private static final int AMPM_INDEX = 2;
62
63    // Also NOT a real index, just used for keyboard mode.
64    private static final int ENABLE_PICKER_INDEX = 3;
65
66    static final int AM = 0;
67    static final int PM = 1;
68
69    private static final boolean DEFAULT_ENABLED_STATE = true;
70    private boolean mIsEnabled = DEFAULT_ENABLED_STATE;
71
72    private static final int HOURS_IN_HALF_DAY = 12;
73
74    private final View mHeaderView;
75    private final TextView mHourView;
76    private final TextView mMinuteView;
77    private final View mAmPmLayout;
78    private final CheckedTextView mAmLabel;
79    private final CheckedTextView mPmLabel;
80    private final RadialTimePickerView mRadialTimePickerView;
81    private final TextView mSeparatorView;
82
83    private final String mAmText;
84    private final String mPmText;
85
86    private final float mDisabledAlpha;
87
88    private boolean mAllowAutoAdvance;
89    private int mInitialHourOfDay;
90    private int mInitialMinute;
91    private boolean mIs24HourView;
92
93    // For hardware IME input.
94    private char mPlaceholderText;
95    private String mDoublePlaceholderText;
96    private String mDeletedKeyFormat;
97    private boolean mInKbMode;
98    private ArrayList<Integer> mTypedTimes = new ArrayList<Integer>();
99    private Node mLegalTimesTree;
100    private int mAmKeyCode;
101    private int mPmKeyCode;
102
103    // Accessibility strings.
104    private String mSelectHours;
105    private String mSelectMinutes;
106
107    // Most recent time announcement values for accessibility.
108    private CharSequence mLastAnnouncedText;
109    private boolean mLastAnnouncedIsHour;
110
111    private Calendar mTempCalendar;
112
113    public TimePickerClockDelegate(TimePicker delegator, Context context, AttributeSet attrs,
114            int defStyleAttr, int defStyleRes) {
115        super(delegator, context);
116
117        // process style attributes
118        final TypedArray a = mContext.obtainStyledAttributes(attrs,
119                R.styleable.TimePicker, defStyleAttr, defStyleRes);
120        final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
121                Context.LAYOUT_INFLATER_SERVICE);
122        final Resources res = mContext.getResources();
123
124        mSelectHours = res.getString(R.string.select_hours);
125        mSelectMinutes = res.getString(R.string.select_minutes);
126
127        String[] amPmStrings = TimePickerSpinnerDelegate.getAmPmStrings(context);
128        mAmText = amPmStrings[0];
129        mPmText = amPmStrings[1];
130
131        final int layoutResourceId = a.getResourceId(R.styleable.TimePicker_internalLayout,
132                R.layout.time_picker_holo);
133        final View mainView = inflater.inflate(layoutResourceId, delegator);
134
135        mHeaderView = mainView.findViewById(R.id.time_header);
136        mHeaderView.setBackground(a.getDrawable(R.styleable.TimePicker_headerBackground));
137
138        // Set up hour/minute labels.
139        mHourView = (TextView) mHeaderView.findViewById(R.id.hours);
140        mHourView.setOnClickListener(mClickListener);
141        mHourView.setAccessibilityDelegate(
142                new ClickActionDelegate(context, R.string.select_hours));
143        mSeparatorView = (TextView) mHeaderView.findViewById(R.id.separator);
144        mMinuteView = (TextView) mHeaderView.findViewById(R.id.minutes);
145        mMinuteView.setOnClickListener(mClickListener);
146        mMinuteView.setAccessibilityDelegate(
147                new ClickActionDelegate(context, R.string.select_minutes));
148
149        final int headerTimeTextAppearance = a.getResourceId(
150                R.styleable.TimePicker_headerTimeTextAppearance, 0);
151        if (headerTimeTextAppearance != 0) {
152            mHourView.setTextAppearance(context, headerTimeTextAppearance);
153            mSeparatorView.setTextAppearance(context, headerTimeTextAppearance);
154            mMinuteView.setTextAppearance(context, headerTimeTextAppearance);
155        }
156
157        // Now that we have text appearances out of the way, make sure the hour
158        // and minute views are correctly sized.
159        mHourView.setMinWidth(computeStableWidth(mHourView, 24));
160        mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60));
161
162        // TODO: This can be removed once we support themed color state lists.
163        final int headerSelectedTextColor = a.getColor(
164                R.styleable.TimePicker_headerSelectedTextColor,
165                res.getColor(R.color.timepicker_default_selector_color_material));
166        mHourView.setTextColor(ColorStateList.addFirstIfMissing(mHourView.getTextColors(),
167                R.attr.state_selected, headerSelectedTextColor));
168        mMinuteView.setTextColor(ColorStateList.addFirstIfMissing(mMinuteView.getTextColors(),
169                R.attr.state_selected, headerSelectedTextColor));
170
171        // Set up AM/PM labels.
172        mAmPmLayout = mHeaderView.findViewById(R.id.ampm_layout);
173        mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label);
174        mAmLabel.setText(amPmStrings[0]);
175        mAmLabel.setOnClickListener(mClickListener);
176        mPmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.pm_label);
177        mPmLabel.setText(amPmStrings[1]);
178        mPmLabel.setOnClickListener(mClickListener);
179
180        final int headerAmPmTextAppearance = a.getResourceId(
181                R.styleable.TimePicker_headerAmPmTextAppearance, 0);
182        if (headerAmPmTextAppearance != 0) {
183            mAmLabel.setTextAppearance(context, headerAmPmTextAppearance);
184            mPmLabel.setTextAppearance(context, headerAmPmTextAppearance);
185        }
186
187        a.recycle();
188
189        // Pull disabled alpha from theme.
190        final TypedValue outValue = new TypedValue();
191        context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
192        mDisabledAlpha = outValue.getFloat();
193
194        mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById(
195                R.id.radial_picker);
196
197        setupListeners();
198
199        mAllowAutoAdvance = true;
200
201        // Set up for keyboard mode.
202        mDoublePlaceholderText = res.getString(R.string.time_placeholder);
203        mDeletedKeyFormat = res.getString(R.string.deleted_key);
204        mPlaceholderText = mDoublePlaceholderText.charAt(0);
205        mAmKeyCode = mPmKeyCode = -1;
206        generateLegalTimesTree();
207
208        // Initialize with current time
209        final Calendar calendar = Calendar.getInstance(mCurrentLocale);
210        final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
211        final int currentMinute = calendar.get(Calendar.MINUTE);
212        initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX);
213    }
214
215    private static class ClickActionDelegate extends AccessibilityDelegate {
216        private final AccessibilityAction mClickAction;
217
218        public ClickActionDelegate(Context context, int resId) {
219            mClickAction = new AccessibilityAction(
220                    AccessibilityNodeInfo.ACTION_CLICK, context.getString(resId));
221        }
222
223        @Override
224        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
225            super.onInitializeAccessibilityNodeInfo(host, info);
226
227            info.addAction(mClickAction);
228        }
229    }
230
231    private int computeStableWidth(TextView v, int maxNumber) {
232        int maxWidth = 0;
233
234        for (int i = 0; i < maxNumber; i++) {
235            final String text = String.format("%02d", i);
236            v.setText(text);
237            v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
238
239            final int width = v.getMeasuredWidth();
240            if (width > maxWidth) {
241                maxWidth = width;
242            }
243        }
244
245        return maxWidth;
246    }
247
248    private void initialize(int hourOfDay, int minute, boolean is24HourView, int index) {
249        mInitialHourOfDay = hourOfDay;
250        mInitialMinute = minute;
251        mIs24HourView = is24HourView;
252        mInKbMode = false;
253        updateUI(index);
254    }
255
256    private void setupListeners() {
257        mHeaderView.setOnKeyListener(mKeyListener);
258        mHeaderView.setOnFocusChangeListener(mFocusListener);
259        mHeaderView.setFocusable(true);
260
261        mRadialTimePickerView.setOnValueSelectedListener(this);
262    }
263
264    private void updateUI(int index) {
265        // Update RadialPicker values
266        updateRadialPicker(index);
267        // Enable or disable the AM/PM view.
268        updateHeaderAmPm();
269        // Update Hour and Minutes
270        updateHeaderHour(mInitialHourOfDay, false);
271        // Update time separator
272        updateHeaderSeparator();
273        // Update Minutes
274        updateHeaderMinute(mInitialMinute, false);
275        // Invalidate everything
276        mDelegator.invalidate();
277    }
278
279    private void updateRadialPicker(int index) {
280        mRadialTimePickerView.initialize(mInitialHourOfDay, mInitialMinute, mIs24HourView);
281        setCurrentItemShowing(index, false, true);
282    }
283
284    private void updateHeaderAmPm() {
285        if (mIs24HourView) {
286            mAmPmLayout.setVisibility(View.GONE);
287        } else {
288            // Ensure that AM/PM layout is in the correct position.
289            final String dateTimePattern = DateFormat.getBestDateTimePattern(mCurrentLocale, "hm");
290            final boolean amPmAtStart = dateTimePattern.startsWith("a");
291            final ViewGroup parent = (ViewGroup) mAmPmLayout.getParent();
292            final int targetIndex = amPmAtStart ? 0 : parent.getChildCount() - 1;
293            final int currentIndex = parent.indexOfChild(mAmPmLayout);
294            if (targetIndex != currentIndex) {
295                parent.removeView(mAmPmLayout);
296                parent.addView(mAmPmLayout, targetIndex);
297            }
298
299            updateAmPmLabelStates(mInitialHourOfDay < 12 ? AM : PM);
300        }
301    }
302
303    /**
304     * Set the current hour.
305     */
306    @Override
307    public void setCurrentHour(Integer currentHour) {
308        if (mInitialHourOfDay == currentHour) {
309            return;
310        }
311        mInitialHourOfDay = currentHour;
312        updateHeaderHour(currentHour, true);
313        updateHeaderAmPm();
314        mRadialTimePickerView.setCurrentHour(currentHour);
315        mRadialTimePickerView.setAmOrPm(mInitialHourOfDay < 12 ? AM : PM);
316        mDelegator.invalidate();
317        onTimeChanged();
318    }
319
320    /**
321     * @return The current hour in the range (0-23).
322     */
323    @Override
324    public Integer getCurrentHour() {
325        int currentHour = mRadialTimePickerView.getCurrentHour();
326        if (mIs24HourView) {
327            return currentHour;
328        } else {
329            switch(mRadialTimePickerView.getAmOrPm()) {
330                case PM:
331                    return (currentHour % HOURS_IN_HALF_DAY) + HOURS_IN_HALF_DAY;
332                case AM:
333                default:
334                    return currentHour % HOURS_IN_HALF_DAY;
335            }
336        }
337    }
338
339    /**
340     * Set the current minute (0-59).
341     */
342    @Override
343    public void setCurrentMinute(Integer currentMinute) {
344        if (mInitialMinute == currentMinute) {
345            return;
346        }
347        mInitialMinute = currentMinute;
348        updateHeaderMinute(currentMinute, true);
349        mRadialTimePickerView.setCurrentMinute(currentMinute);
350        mDelegator.invalidate();
351        onTimeChanged();
352    }
353
354    /**
355     * @return The current minute.
356     */
357    @Override
358    public Integer getCurrentMinute() {
359        return mRadialTimePickerView.getCurrentMinute();
360    }
361
362    /**
363     * Set whether in 24 hour or AM/PM mode.
364     *
365     * @param is24HourView True = 24 hour mode. False = AM/PM.
366     */
367    @Override
368    public void setIs24HourView(Boolean is24HourView) {
369        if (is24HourView == mIs24HourView) {
370            return;
371        }
372        mIs24HourView = is24HourView;
373        generateLegalTimesTree();
374        int hour = mRadialTimePickerView.getCurrentHour();
375        mInitialHourOfDay = hour;
376        updateHeaderHour(hour, false);
377        updateHeaderAmPm();
378        updateRadialPicker(mRadialTimePickerView.getCurrentItemShowing());
379        mDelegator.invalidate();
380    }
381
382    /**
383     * @return true if this is in 24 hour view else false.
384     */
385    @Override
386    public boolean is24HourView() {
387        return mIs24HourView;
388    }
389
390    @Override
391    public void setOnTimeChangedListener(TimePicker.OnTimeChangedListener callback) {
392        mOnTimeChangedListener = callback;
393    }
394
395    @Override
396    public void setEnabled(boolean enabled) {
397        mHourView.setEnabled(enabled);
398        mMinuteView.setEnabled(enabled);
399        mAmLabel.setEnabled(enabled);
400        mPmLabel.setEnabled(enabled);
401        mRadialTimePickerView.setEnabled(enabled);
402        mIsEnabled = enabled;
403    }
404
405    @Override
406    public boolean isEnabled() {
407        return mIsEnabled;
408    }
409
410    @Override
411    public int getBaseline() {
412        // does not support baseline alignment
413        return -1;
414    }
415
416    @Override
417    public void onConfigurationChanged(Configuration newConfig) {
418        updateUI(mRadialTimePickerView.getCurrentItemShowing());
419    }
420
421    @Override
422    public Parcelable onSaveInstanceState(Parcelable superState) {
423        return new SavedState(superState, getCurrentHour(), getCurrentMinute(),
424                is24HourView(), inKbMode(), getTypedTimes(), getCurrentItemShowing());
425    }
426
427    @Override
428    public void onRestoreInstanceState(Parcelable state) {
429        SavedState ss = (SavedState) state;
430        setInKbMode(ss.inKbMode());
431        setTypedTimes(ss.getTypesTimes());
432        initialize(ss.getHour(), ss.getMinute(), ss.is24HourMode(), ss.getCurrentItemShowing());
433        mRadialTimePickerView.invalidate();
434        if (mInKbMode) {
435            tryStartingKbMode(-1);
436            mHourView.invalidate();
437        }
438    }
439
440    @Override
441    public void setCurrentLocale(Locale locale) {
442        super.setCurrentLocale(locale);
443        mTempCalendar = Calendar.getInstance(locale);
444    }
445
446    @Override
447    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
448        onPopulateAccessibilityEvent(event);
449        return true;
450    }
451
452    @Override
453    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
454        int flags = DateUtils.FORMAT_SHOW_TIME;
455        if (mIs24HourView) {
456            flags |= DateUtils.FORMAT_24HOUR;
457        } else {
458            flags |= DateUtils.FORMAT_12HOUR;
459        }
460        mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour());
461        mTempCalendar.set(Calendar.MINUTE, getCurrentMinute());
462        String selectedDate = DateUtils.formatDateTime(mContext,
463                mTempCalendar.getTimeInMillis(), flags);
464        event.getText().add(selectedDate);
465    }
466
467    @Override
468    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
469        event.setClassName(TimePicker.class.getName());
470    }
471
472    @Override
473    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
474        info.setClassName(TimePicker.class.getName());
475    }
476
477    /**
478     * Set whether in keyboard mode or not.
479     *
480     * @param inKbMode True means in keyboard mode.
481     */
482    private void setInKbMode(boolean inKbMode) {
483        mInKbMode = inKbMode;
484    }
485
486    /**
487     * @return true if in keyboard mode
488     */
489    private boolean inKbMode() {
490        return mInKbMode;
491    }
492
493    private void setTypedTimes(ArrayList<Integer> typeTimes) {
494        mTypedTimes = typeTimes;
495    }
496
497    /**
498     * @return an array of typed times
499     */
500    private ArrayList<Integer> getTypedTimes() {
501        return mTypedTimes;
502    }
503
504    /**
505     * @return the index of the current item showing
506     */
507    private int getCurrentItemShowing() {
508        return mRadialTimePickerView.getCurrentItemShowing();
509    }
510
511    /**
512     * Propagate the time change
513     */
514    private void onTimeChanged() {
515        mDelegator.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
516        if (mOnTimeChangedListener != null) {
517            mOnTimeChangedListener.onTimeChanged(mDelegator,
518                    getCurrentHour(), getCurrentMinute());
519        }
520    }
521
522    /**
523     * Used to save / restore state of time picker
524     */
525    private static class SavedState extends View.BaseSavedState {
526
527        private final int mHour;
528        private final int mMinute;
529        private final boolean mIs24HourMode;
530        private final boolean mInKbMode;
531        private final ArrayList<Integer> mTypedTimes;
532        private final int mCurrentItemShowing;
533
534        private SavedState(Parcelable superState, int hour, int minute, boolean is24HourMode,
535                           boolean isKbMode, ArrayList<Integer> typedTimes,
536                           int currentItemShowing) {
537            super(superState);
538            mHour = hour;
539            mMinute = minute;
540            mIs24HourMode = is24HourMode;
541            mInKbMode = isKbMode;
542            mTypedTimes = typedTimes;
543            mCurrentItemShowing = currentItemShowing;
544        }
545
546        private SavedState(Parcel in) {
547            super(in);
548            mHour = in.readInt();
549            mMinute = in.readInt();
550            mIs24HourMode = (in.readInt() == 1);
551            mInKbMode = (in.readInt() == 1);
552            mTypedTimes = in.readArrayList(getClass().getClassLoader());
553            mCurrentItemShowing = in.readInt();
554        }
555
556        public int getHour() {
557            return mHour;
558        }
559
560        public int getMinute() {
561            return mMinute;
562        }
563
564        public boolean is24HourMode() {
565            return mIs24HourMode;
566        }
567
568        public boolean inKbMode() {
569            return mInKbMode;
570        }
571
572        public ArrayList<Integer> getTypesTimes() {
573            return mTypedTimes;
574        }
575
576        public int getCurrentItemShowing() {
577            return mCurrentItemShowing;
578        }
579
580        @Override
581        public void writeToParcel(Parcel dest, int flags) {
582            super.writeToParcel(dest, flags);
583            dest.writeInt(mHour);
584            dest.writeInt(mMinute);
585            dest.writeInt(mIs24HourMode ? 1 : 0);
586            dest.writeInt(mInKbMode ? 1 : 0);
587            dest.writeList(mTypedTimes);
588            dest.writeInt(mCurrentItemShowing);
589        }
590
591        @SuppressWarnings({"unused", "hiding"})
592        public static final Parcelable.Creator<SavedState> CREATOR = new Creator<SavedState>() {
593            public SavedState createFromParcel(Parcel in) {
594                return new SavedState(in);
595            }
596
597            public SavedState[] newArray(int size) {
598                return new SavedState[size];
599            }
600        };
601    }
602
603    private void tryVibrate() {
604        mDelegator.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK);
605    }
606
607    private void updateAmPmLabelStates(int amOrPm) {
608        final boolean isAm = amOrPm == AM;
609        mAmLabel.setChecked(isAm);
610        mAmLabel.setAlpha(isAm ? 1 : mDisabledAlpha);
611
612        final boolean isPm = amOrPm == PM;
613        mPmLabel.setChecked(isPm);
614        mPmLabel.setAlpha(isPm ? 1 : mDisabledAlpha);
615    }
616
617    /**
618     * Called by the picker for updating the header display.
619     */
620    @Override
621    public void onValueSelected(int pickerIndex, int newValue, boolean autoAdvance) {
622        switch (pickerIndex) {
623            case HOUR_INDEX:
624                if (mAllowAutoAdvance && autoAdvance) {
625                    updateHeaderHour(newValue, false);
626                    setCurrentItemShowing(MINUTE_INDEX, true, false);
627                    mDelegator.announceForAccessibility(newValue + ". " + mSelectMinutes);
628                } else {
629                    updateHeaderHour(newValue, true);
630                }
631                break;
632            case MINUTE_INDEX:
633                updateHeaderMinute(newValue, true);
634                break;
635            case AMPM_INDEX:
636                updateAmPmLabelStates(newValue);
637                break;
638            case ENABLE_PICKER_INDEX:
639                if (!isTypedTimeFullyLegal()) {
640                    mTypedTimes.clear();
641                }
642                finishKbMode();
643                break;
644        }
645
646        if (mOnTimeChangedListener != null) {
647            mOnTimeChangedListener.onTimeChanged(mDelegator, getCurrentHour(), getCurrentMinute());
648        }
649    }
650
651    private void updateHeaderHour(int value, boolean announce) {
652        final String bestDateTimePattern = DateFormat.getBestDateTimePattern(mCurrentLocale,
653                (mIs24HourView) ? "Hm" : "hm");
654        final int lengthPattern = bestDateTimePattern.length();
655        boolean hourWithTwoDigit = false;
656        char hourFormat = '\0';
657        // Check if the returned pattern is single or double 'H', 'h', 'K', 'k'. We also save
658        // the hour format that we found.
659        for (int i = 0; i < lengthPattern; i++) {
660            final char c = bestDateTimePattern.charAt(i);
661            if (c == 'H' || c == 'h' || c == 'K' || c == 'k') {
662                hourFormat = c;
663                if (i + 1 < lengthPattern && c == bestDateTimePattern.charAt(i + 1)) {
664                    hourWithTwoDigit = true;
665                }
666                break;
667            }
668        }
669        final String format;
670        if (hourWithTwoDigit) {
671            format = "%02d";
672        } else {
673            format = "%d";
674        }
675        if (mIs24HourView) {
676            // 'k' means 1-24 hour
677            if (hourFormat == 'k' && value == 0) {
678                value = 24;
679            }
680        } else {
681            // 'K' means 0-11 hour
682            value = modulo12(value, hourFormat == 'K');
683        }
684        CharSequence text = String.format(format, value);
685        mHourView.setText(text);
686        if (announce) {
687            tryAnnounceForAccessibility(text, true);
688        }
689    }
690
691    private void tryAnnounceForAccessibility(CharSequence text, boolean isHour) {
692        if (mLastAnnouncedIsHour != isHour || !text.equals(mLastAnnouncedText)) {
693            // TODO: Find a better solution, potentially live regions?
694            mDelegator.announceForAccessibility(text);
695            mLastAnnouncedText = text;
696            mLastAnnouncedIsHour = isHour;
697        }
698    }
699
700    private static int modulo12(int n, boolean startWithZero) {
701        int value = n % 12;
702        if (value == 0 && !startWithZero) {
703            value = 12;
704        }
705        return value;
706    }
707
708    /**
709     * The time separator is defined in the Unicode CLDR and cannot be supposed to be ":".
710     *
711     * See http://unicode.org/cldr/trac/browser/trunk/common/main
712     *
713     * We pass the correct "skeleton" depending on 12 or 24 hours view and then extract the
714     * separator as the character which is just after the hour marker in the returned pattern.
715     */
716    private void updateHeaderSeparator() {
717        final String bestDateTimePattern = DateFormat.getBestDateTimePattern(mCurrentLocale,
718                (mIs24HourView) ? "Hm" : "hm");
719        final String separatorText;
720        // See http://www.unicode.org/reports/tr35/tr35-dates.html for hour formats
721        final char[] hourFormats = {'H', 'h', 'K', 'k'};
722        int hIndex = lastIndexOfAny(bestDateTimePattern, hourFormats);
723        if (hIndex == -1) {
724            // Default case
725            separatorText = ":";
726        } else {
727            separatorText = Character.toString(bestDateTimePattern.charAt(hIndex + 1));
728        }
729        mSeparatorView.setText(separatorText);
730    }
731
732    static private int lastIndexOfAny(String str, char[] any) {
733        final int lengthAny = any.length;
734        if (lengthAny > 0) {
735            for (int i = str.length() - 1; i >= 0; i--) {
736                char c = str.charAt(i);
737                for (int j = 0; j < lengthAny; j++) {
738                    if (c == any[j]) {
739                        return i;
740                    }
741                }
742            }
743        }
744        return -1;
745    }
746
747    private void updateHeaderMinute(int value, boolean announceForAccessibility) {
748        if (value == 60) {
749            value = 0;
750        }
751        final CharSequence text = String.format(mCurrentLocale, "%02d", value);
752        mMinuteView.setText(text);
753        if (announceForAccessibility) {
754            tryAnnounceForAccessibility(text, false);
755        }
756    }
757
758    /**
759     * Show either Hours or Minutes.
760     */
761    private void setCurrentItemShowing(int index, boolean animateCircle, boolean announce) {
762        mRadialTimePickerView.setCurrentItemShowing(index, animateCircle);
763
764        if (index == HOUR_INDEX) {
765            if (announce) {
766                mDelegator.announceForAccessibility(mSelectHours);
767            }
768        } else {
769            if (announce) {
770                mDelegator.announceForAccessibility(mSelectMinutes);
771            }
772        }
773
774        mHourView.setSelected(index == HOUR_INDEX);
775        mMinuteView.setSelected(index == MINUTE_INDEX);
776    }
777
778    private void setAmOrPm(int amOrPm) {
779        updateAmPmLabelStates(amOrPm);
780        mRadialTimePickerView.setAmOrPm(amOrPm);
781    }
782
783    /**
784     * For keyboard mode, processes key events.
785     *
786     * @param keyCode the pressed key.
787     *
788     * @return true if the key was successfully processed, false otherwise.
789     */
790    private boolean processKeyUp(int keyCode) {
791        if (keyCode == KeyEvent.KEYCODE_DEL) {
792            if (mInKbMode) {
793                if (!mTypedTimes.isEmpty()) {
794                    int deleted = deleteLastTypedKey();
795                    String deletedKeyStr;
796                    if (deleted == getAmOrPmKeyCode(AM)) {
797                        deletedKeyStr = mAmText;
798                    } else if (deleted == getAmOrPmKeyCode(PM)) {
799                        deletedKeyStr = mPmText;
800                    } else {
801                        deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
802                    }
803                    mDelegator.announceForAccessibility(
804                            String.format(mDeletedKeyFormat, deletedKeyStr));
805                    updateDisplay(true);
806                }
807            }
808        } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
809                || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
810                || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
811                || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
812                || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
813                || (!mIs24HourView &&
814                (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
815            if (!mInKbMode) {
816                if (mRadialTimePickerView == null) {
817                    // Something's wrong, because time picker should definitely not be null.
818                    Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
819                    return true;
820                }
821                mTypedTimes.clear();
822                tryStartingKbMode(keyCode);
823                return true;
824            }
825            // We're already in keyboard mode.
826            if (addKeyIfLegal(keyCode)) {
827                updateDisplay(false);
828            }
829            return true;
830        }
831        return false;
832    }
833
834    /**
835     * Try to start keyboard mode with the specified key.
836     *
837     * @param keyCode The key to use as the first press. Keyboard mode will not be started if the
838     * key is not legal to start with. Or, pass in -1 to get into keyboard mode without a starting
839     * key.
840     */
841    private void tryStartingKbMode(int keyCode) {
842        if (keyCode == -1 || addKeyIfLegal(keyCode)) {
843            mInKbMode = true;
844            onValidationChanged(false);
845            updateDisplay(false);
846            mRadialTimePickerView.setInputEnabled(false);
847        }
848    }
849
850    private boolean addKeyIfLegal(int keyCode) {
851        // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode,
852        // we'll need to see if AM/PM have been typed.
853        if ((mIs24HourView && mTypedTimes.size() == 4) ||
854                (!mIs24HourView && isTypedTimeFullyLegal())) {
855            return false;
856        }
857
858        mTypedTimes.add(keyCode);
859        if (!isTypedTimeLegalSoFar()) {
860            deleteLastTypedKey();
861            return false;
862        }
863
864        int val = getValFromKeyCode(keyCode);
865        mDelegator.announceForAccessibility(String.format("%d", val));
866        // Automatically fill in 0's if AM or PM was legally entered.
867        if (isTypedTimeFullyLegal()) {
868            if (!mIs24HourView && mTypedTimes.size() <= 3) {
869                mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0);
870                mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0);
871            }
872            onValidationChanged(true);
873        }
874
875        return true;
876    }
877
878    /**
879     * Traverse the tree to see if the keys that have been typed so far are legal as is,
880     * or may become legal as more keys are typed (excluding backspace).
881     */
882    private boolean isTypedTimeLegalSoFar() {
883        Node node = mLegalTimesTree;
884        for (int keyCode : mTypedTimes) {
885            node = node.canReach(keyCode);
886            if (node == null) {
887                return false;
888            }
889        }
890        return true;
891    }
892
893    /**
894     * Check if the time that has been typed so far is completely legal, as is.
895     */
896    private boolean isTypedTimeFullyLegal() {
897        if (mIs24HourView) {
898            // For 24-hour mode, the time is legal if the hours and minutes are each legal. Note:
899            // getEnteredTime() will ONLY call isTypedTimeFullyLegal() when NOT in 24hour mode.
900            int[] values = getEnteredTime(null);
901            return (values[0] >= 0 && values[1] >= 0 && values[1] < 60);
902        } else {
903            // For AM/PM mode, the time is legal if it contains an AM or PM, as those can only be
904            // legally added at specific times based on the tree's algorithm.
905            return (mTypedTimes.contains(getAmOrPmKeyCode(AM)) ||
906                    mTypedTimes.contains(getAmOrPmKeyCode(PM)));
907        }
908    }
909
910    private int deleteLastTypedKey() {
911        int deleted = mTypedTimes.remove(mTypedTimes.size() - 1);
912        if (!isTypedTimeFullyLegal()) {
913            onValidationChanged(false);
914        }
915        return deleted;
916    }
917
918    /**
919     * Get out of keyboard mode. If there is nothing in typedTimes, revert to TimePicker's time.
920     */
921    private void finishKbMode() {
922        mInKbMode = false;
923        if (!mTypedTimes.isEmpty()) {
924            int values[] = getEnteredTime(null);
925            mRadialTimePickerView.setCurrentHour(values[0]);
926            mRadialTimePickerView.setCurrentMinute(values[1]);
927            if (!mIs24HourView) {
928                mRadialTimePickerView.setAmOrPm(values[2]);
929            }
930            mTypedTimes.clear();
931        }
932        updateDisplay(false);
933        mRadialTimePickerView.setInputEnabled(true);
934    }
935
936    /**
937     * Update the hours, minutes, and AM/PM displays with the typed times. If the typedTimes is
938     * empty, either show an empty display (filled with the placeholder text), or update from the
939     * timepicker's values.
940     *
941     * @param allowEmptyDisplay if true, then if the typedTimes is empty, use the placeholder text.
942     * Otherwise, revert to the timepicker's values.
943     */
944    private void updateDisplay(boolean allowEmptyDisplay) {
945        if (!allowEmptyDisplay && mTypedTimes.isEmpty()) {
946            int hour = mRadialTimePickerView.getCurrentHour();
947            int minute = mRadialTimePickerView.getCurrentMinute();
948            updateHeaderHour(hour, false);
949            updateHeaderMinute(minute, false);
950            if (!mIs24HourView) {
951                updateAmPmLabelStates(hour < 12 ? AM : PM);
952            }
953            setCurrentItemShowing(mRadialTimePickerView.getCurrentItemShowing(), true, true);
954            onValidationChanged(true);
955        } else {
956            boolean[] enteredZeros = {false, false};
957            int[] values = getEnteredTime(enteredZeros);
958            String hourFormat = enteredZeros[0] ? "%02d" : "%2d";
959            String minuteFormat = (enteredZeros[1]) ? "%02d" : "%2d";
960            String hourStr = (values[0] == -1) ? mDoublePlaceholderText :
961                    String.format(hourFormat, values[0]).replace(' ', mPlaceholderText);
962            String minuteStr = (values[1] == -1) ? mDoublePlaceholderText :
963                    String.format(minuteFormat, values[1]).replace(' ', mPlaceholderText);
964            mHourView.setText(hourStr);
965            mHourView.setSelected(false);
966            mMinuteView.setText(minuteStr);
967            mMinuteView.setSelected(false);
968            if (!mIs24HourView) {
969                updateAmPmLabelStates(values[2]);
970            }
971        }
972    }
973
974    private int getValFromKeyCode(int keyCode) {
975        switch (keyCode) {
976            case KeyEvent.KEYCODE_0:
977                return 0;
978            case KeyEvent.KEYCODE_1:
979                return 1;
980            case KeyEvent.KEYCODE_2:
981                return 2;
982            case KeyEvent.KEYCODE_3:
983                return 3;
984            case KeyEvent.KEYCODE_4:
985                return 4;
986            case KeyEvent.KEYCODE_5:
987                return 5;
988            case KeyEvent.KEYCODE_6:
989                return 6;
990            case KeyEvent.KEYCODE_7:
991                return 7;
992            case KeyEvent.KEYCODE_8:
993                return 8;
994            case KeyEvent.KEYCODE_9:
995                return 9;
996            default:
997                return -1;
998        }
999    }
1000
1001    /**
1002     * Get the currently-entered time, as integer values of the hours and minutes typed.
1003     *
1004     * @param enteredZeros A size-2 boolean array, which the caller should initialize, and which
1005     * may then be used for the caller to know whether zeros had been explicitly entered as either
1006     * hours of minutes. This is helpful for deciding whether to show the dashes, or actual 0's.
1007     *
1008     * @return A size-3 int array. The first value will be the hours, the second value will be the
1009     * minutes, and the third will be either AM or PM.
1010     */
1011    private int[] getEnteredTime(boolean[] enteredZeros) {
1012        int amOrPm = -1;
1013        int startIndex = 1;
1014        if (!mIs24HourView && isTypedTimeFullyLegal()) {
1015            int keyCode = mTypedTimes.get(mTypedTimes.size() - 1);
1016            if (keyCode == getAmOrPmKeyCode(AM)) {
1017                amOrPm = AM;
1018            } else if (keyCode == getAmOrPmKeyCode(PM)){
1019                amOrPm = PM;
1020            }
1021            startIndex = 2;
1022        }
1023        int minute = -1;
1024        int hour = -1;
1025        for (int i = startIndex; i <= mTypedTimes.size(); i++) {
1026            int val = getValFromKeyCode(mTypedTimes.get(mTypedTimes.size() - i));
1027            if (i == startIndex) {
1028                minute = val;
1029            } else if (i == startIndex+1) {
1030                minute += 10 * val;
1031                if (enteredZeros != null && val == 0) {
1032                    enteredZeros[1] = true;
1033                }
1034            } else if (i == startIndex+2) {
1035                hour = val;
1036            } else if (i == startIndex+3) {
1037                hour += 10 * val;
1038                if (enteredZeros != null && val == 0) {
1039                    enteredZeros[0] = true;
1040                }
1041            }
1042        }
1043
1044        return new int[] { hour, minute, amOrPm };
1045    }
1046
1047    /**
1048     * Get the keycode value for AM and PM in the current language.
1049     */
1050    private int getAmOrPmKeyCode(int amOrPm) {
1051        // Cache the codes.
1052        if (mAmKeyCode == -1 || mPmKeyCode == -1) {
1053            // Find the first character in the AM/PM text that is unique.
1054            KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
1055            char amChar;
1056            char pmChar;
1057            for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
1058                amChar = mAmText.toLowerCase(mCurrentLocale).charAt(i);
1059                pmChar = mPmText.toLowerCase(mCurrentLocale).charAt(i);
1060                if (amChar != pmChar) {
1061                    KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
1062                    // There should be 4 events: a down and up for both AM and PM.
1063                    if (events != null && events.length == 4) {
1064                        mAmKeyCode = events[0].getKeyCode();
1065                        mPmKeyCode = events[2].getKeyCode();
1066                    } else {
1067                        Log.e(TAG, "Unable to find keycodes for AM and PM.");
1068                    }
1069                    break;
1070                }
1071            }
1072        }
1073        if (amOrPm == AM) {
1074            return mAmKeyCode;
1075        } else if (amOrPm == PM) {
1076            return mPmKeyCode;
1077        }
1078
1079        return -1;
1080    }
1081
1082    /**
1083     * Create a tree for deciding what keys can legally be typed.
1084     */
1085    private void generateLegalTimesTree() {
1086        // Create a quick cache of numbers to their keycodes.
1087        final int k0 = KeyEvent.KEYCODE_0;
1088        final int k1 = KeyEvent.KEYCODE_1;
1089        final int k2 = KeyEvent.KEYCODE_2;
1090        final int k3 = KeyEvent.KEYCODE_3;
1091        final int k4 = KeyEvent.KEYCODE_4;
1092        final int k5 = KeyEvent.KEYCODE_5;
1093        final int k6 = KeyEvent.KEYCODE_6;
1094        final int k7 = KeyEvent.KEYCODE_7;
1095        final int k8 = KeyEvent.KEYCODE_8;
1096        final int k9 = KeyEvent.KEYCODE_9;
1097
1098        // The root of the tree doesn't contain any numbers.
1099        mLegalTimesTree = new Node();
1100        if (mIs24HourView) {
1101            // We'll be re-using these nodes, so we'll save them.
1102            Node minuteFirstDigit = new Node(k0, k1, k2, k3, k4, k5);
1103            Node minuteSecondDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
1104            // The first digit must be followed by the second digit.
1105            minuteFirstDigit.addChild(minuteSecondDigit);
1106
1107            // The first digit may be 0-1.
1108            Node firstDigit = new Node(k0, k1);
1109            mLegalTimesTree.addChild(firstDigit);
1110
1111            // When the first digit is 0-1, the second digit may be 0-5.
1112            Node secondDigit = new Node(k0, k1, k2, k3, k4, k5);
1113            firstDigit.addChild(secondDigit);
1114            // We may now be followed by the first minute digit. E.g. 00:09, 15:58.
1115            secondDigit.addChild(minuteFirstDigit);
1116
1117            // When the first digit is 0-1, and the second digit is 0-5, the third digit may be 6-9.
1118            Node thirdDigit = new Node(k6, k7, k8, k9);
1119            // The time must now be finished. E.g. 0:55, 1:08.
1120            secondDigit.addChild(thirdDigit);
1121
1122            // When the first digit is 0-1, the second digit may be 6-9.
1123            secondDigit = new Node(k6, k7, k8, k9);
1124            firstDigit.addChild(secondDigit);
1125            // We must now be followed by the first minute digit. E.g. 06:50, 18:20.
1126            secondDigit.addChild(minuteFirstDigit);
1127
1128            // The first digit may be 2.
1129            firstDigit = new Node(k2);
1130            mLegalTimesTree.addChild(firstDigit);
1131
1132            // When the first digit is 2, the second digit may be 0-3.
1133            secondDigit = new Node(k0, k1, k2, k3);
1134            firstDigit.addChild(secondDigit);
1135            // We must now be followed by the first minute digit. E.g. 20:50, 23:09.
1136            secondDigit.addChild(minuteFirstDigit);
1137
1138            // When the first digit is 2, the second digit may be 4-5.
1139            secondDigit = new Node(k4, k5);
1140            firstDigit.addChild(secondDigit);
1141            // We must now be followd by the last minute digit. E.g. 2:40, 2:53.
1142            secondDigit.addChild(minuteSecondDigit);
1143
1144            // The first digit may be 3-9.
1145            firstDigit = new Node(k3, k4, k5, k6, k7, k8, k9);
1146            mLegalTimesTree.addChild(firstDigit);
1147            // We must now be followed by the first minute digit. E.g. 3:57, 8:12.
1148            firstDigit.addChild(minuteFirstDigit);
1149        } else {
1150            // We'll need to use the AM/PM node a lot.
1151            // Set up AM and PM to respond to "a" and "p".
1152            Node ampm = new Node(getAmOrPmKeyCode(AM), getAmOrPmKeyCode(PM));
1153
1154            // The first hour digit may be 1.
1155            Node firstDigit = new Node(k1);
1156            mLegalTimesTree.addChild(firstDigit);
1157            // We'll allow quick input of on-the-hour times. E.g. 1pm.
1158            firstDigit.addChild(ampm);
1159
1160            // When the first digit is 1, the second digit may be 0-2.
1161            Node secondDigit = new Node(k0, k1, k2);
1162            firstDigit.addChild(secondDigit);
1163            // Also for quick input of on-the-hour times. E.g. 10pm, 12am.
1164            secondDigit.addChild(ampm);
1165
1166            // When the first digit is 1, and the second digit is 0-2, the third digit may be 0-5.
1167            Node thirdDigit = new Node(k0, k1, k2, k3, k4, k5);
1168            secondDigit.addChild(thirdDigit);
1169            // The time may be finished now. E.g. 1:02pm, 1:25am.
1170            thirdDigit.addChild(ampm);
1171
1172            // When the first digit is 1, the second digit is 0-2, and the third digit is 0-5,
1173            // the fourth digit may be 0-9.
1174            Node fourthDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
1175            thirdDigit.addChild(fourthDigit);
1176            // The time must be finished now. E.g. 10:49am, 12:40pm.
1177            fourthDigit.addChild(ampm);
1178
1179            // When the first digit is 1, and the second digit is 0-2, the third digit may be 6-9.
1180            thirdDigit = new Node(k6, k7, k8, k9);
1181            secondDigit.addChild(thirdDigit);
1182            // The time must be finished now. E.g. 1:08am, 1:26pm.
1183            thirdDigit.addChild(ampm);
1184
1185            // When the first digit is 1, the second digit may be 3-5.
1186            secondDigit = new Node(k3, k4, k5);
1187            firstDigit.addChild(secondDigit);
1188
1189            // When the first digit is 1, and the second digit is 3-5, the third digit may be 0-9.
1190            thirdDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
1191            secondDigit.addChild(thirdDigit);
1192            // The time must be finished now. E.g. 1:39am, 1:50pm.
1193            thirdDigit.addChild(ampm);
1194
1195            // The hour digit may be 2-9.
1196            firstDigit = new Node(k2, k3, k4, k5, k6, k7, k8, k9);
1197            mLegalTimesTree.addChild(firstDigit);
1198            // We'll allow quick input of on-the-hour-times. E.g. 2am, 5pm.
1199            firstDigit.addChild(ampm);
1200
1201            // When the first digit is 2-9, the second digit may be 0-5.
1202            secondDigit = new Node(k0, k1, k2, k3, k4, k5);
1203            firstDigit.addChild(secondDigit);
1204
1205            // When the first digit is 2-9, and the second digit is 0-5, the third digit may be 0-9.
1206            thirdDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
1207            secondDigit.addChild(thirdDigit);
1208            // The time must be finished now. E.g. 2:57am, 9:30pm.
1209            thirdDigit.addChild(ampm);
1210        }
1211    }
1212
1213    /**
1214     * Simple node class to be used for traversal to check for legal times.
1215     * mLegalKeys represents the keys that can be typed to get to the node.
1216     * mChildren are the children that can be reached from this node.
1217     */
1218    private class Node {
1219        private int[] mLegalKeys;
1220        private ArrayList<Node> mChildren;
1221
1222        public Node(int... legalKeys) {
1223            mLegalKeys = legalKeys;
1224            mChildren = new ArrayList<Node>();
1225        }
1226
1227        public void addChild(Node child) {
1228            mChildren.add(child);
1229        }
1230
1231        public boolean containsKey(int key) {
1232            for (int i = 0; i < mLegalKeys.length; i++) {
1233                if (mLegalKeys[i] == key) {
1234                    return true;
1235                }
1236            }
1237            return false;
1238        }
1239
1240        public Node canReach(int key) {
1241            if (mChildren == null) {
1242                return null;
1243            }
1244            for (Node child : mChildren) {
1245                if (child.containsKey(key)) {
1246                    return child;
1247                }
1248            }
1249            return null;
1250        }
1251    }
1252
1253    private final View.OnClickListener mClickListener = new View.OnClickListener() {
1254        @Override
1255        public void onClick(View v) {
1256
1257            final int amOrPm;
1258            switch (v.getId()) {
1259                case R.id.am_label:
1260                    setAmOrPm(AM);
1261                    break;
1262                case R.id.pm_label:
1263                    setAmOrPm(PM);
1264                    break;
1265                case R.id.hours:
1266                    setCurrentItemShowing(HOUR_INDEX, true, true);
1267                    break;
1268                case R.id.minutes:
1269                    setCurrentItemShowing(MINUTE_INDEX, true, true);
1270                    break;
1271                default:
1272                    // Failed to handle this click, don't vibrate.
1273                    return;
1274            }
1275
1276            tryVibrate();
1277        }
1278    };
1279
1280    private final View.OnKeyListener mKeyListener = new View.OnKeyListener() {
1281        @Override
1282        public boolean onKey(View v, int keyCode, KeyEvent event) {
1283            if (event.getAction() == KeyEvent.ACTION_UP) {
1284                return processKeyUp(keyCode);
1285            }
1286            return false;
1287        }
1288    };
1289
1290    private final View.OnFocusChangeListener mFocusListener = new View.OnFocusChangeListener() {
1291        @Override
1292        public void onFocusChange(View v, boolean hasFocus) {
1293            if (!hasFocus && mInKbMode && isTypedTimeFullyLegal()) {
1294                finishKbMode();
1295
1296                if (mOnTimeChangedListener != null) {
1297                    mOnTimeChangedListener.onTimeChanged(mDelegator,
1298                            mRadialTimePickerView.getCurrentHour(),
1299                            mRadialTimePickerView.getCurrentMinute());
1300                }
1301            }
1302        }
1303    };
1304}
1305