DatePicker.java revision e4f30650ac2b4e7b1b2a8962a3618506aec1b81a
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.widget;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
198817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viveretteimport android.annotation.IntDef;
20518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viveretteimport android.annotation.Nullable;
218817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viveretteimport android.annotation.TestApi;
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.annotation.Widget;
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.Context;
24f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganovimport android.content.res.Configuration;
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.res.TypedArray;
2668763be41cffbcb4883a0a6293fc1aa9e17a3957Alan Viveretteimport android.icu.util.Calendar;
2768763be41cffbcb4883a0a6293fc1aa9e17a3957Alan Viveretteimport android.icu.util.TimeZone;
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Parcel;
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Parcelable;
30dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanuimport android.text.format.DateUtils;
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.AttributeSet;
329668903731c272e51ce610598c052ef411c9d89fPhilip P. Moltmannimport android.util.Log;
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.SparseArray;
34d11e6151fe88314505fa7adca6278de2e772b11cSvetoslav Ganovimport android.view.View;
35305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Lemeimport android.view.ViewStructure;
368a2a89588c3889b999a8fffa2d7c7a5c3ce25eb8Svetoslav Ganovimport android.view.accessibility.AccessibilityEvent;
37640f30a7763b0a4b80c767acb84c740aac04768bFelipe Lemeimport android.view.autofill.AutofillManager;
38640f30a7763b0a4b80c767acb84c740aac04768bFelipe Lemeimport android.view.autofill.AutofillValue;
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4099441c5d7da45c10b729185852be97cbb0bdc8d5Aurimas Liutikasimport com.android.internal.R;
4199441c5d7da45c10b729185852be97cbb0bdc8d5Aurimas Liutikas
428817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viveretteimport java.lang.annotation.Retention;
438817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viveretteimport java.lang.annotation.RetentionPolicy;
44dddda8d188408ff18935b1b0e15a00fe012a03daKenny Rootimport java.util.Locale;
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
47d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * Provides a widget for selecting a date.
48d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * <p>
49d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * When the {@link android.R.styleable#DatePicker_datePickerMode} attribute is
50d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * set to {@code spinner}, the date can be selected using year, month, and day
51d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * spinners or a {@link CalendarView}. The set of spinners and the calendar
52d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * view are automatically synchronized. The client can customize whether only
53d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * the spinners, or only the calendar view, or both to be displayed.
54d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * </p>
55d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * <p>
56d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * When the {@link android.R.styleable#DatePicker_datePickerMode} attribute is
57d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * set to {@code calendar}, the month and day can be selected using a
58d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * calendar-style view while the year can be selected separately using a list.
59d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * </p>
6050f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov * <p>
614c359b76f9a030f92a302ba74a528faa170bad4eScott Main * See the <a href="{@docRoot}guide/topics/ui/controls/pickers.html">Pickers</a>
624c359b76f9a030f92a302ba74a528faa170bad4eScott Main * guide.
6350f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov * </p>
64e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * <p>
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * For a dialog using this view, see {@link android.app.DatePickerDialog}.
66e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * </p>
67e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov *
68e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_startYear
69e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_endYear
70e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_maxDate
71e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_minDate
72e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_spinnersShown
73e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_calendarViewShown
74ba9bf41a77261471a4dc9d7964aec41726b4e4e6Alan Viverette * @attr ref android.R.styleable#DatePicker_dayOfWeekBackground
7560727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_dayOfWeekTextAppearance
76ba9bf41a77261471a4dc9d7964aec41726b4e4e6Alan Viverette * @attr ref android.R.styleable#DatePicker_headerBackground
7760727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_headerMonthTextAppearance
7860727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_headerDayOfMonthTextAppearance
7960727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_headerYearTextAppearance
8060727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_yearListItemTextAppearance
8160727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_yearListSelectorColor
82bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio * @attr ref android.R.styleable#DatePicker_calendarTextColor
83d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * @attr ref android.R.styleable#DatePicker_datePickerMode
849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project@Widget
869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class DatePicker extends FrameLayout {
879668903731c272e51ce610598c052ef411c9d89fPhilip P. Moltmann    private static final String LOG_TAG = DatePicker.class.getSimpleName();
889668903731c272e51ce610598c052ef411c9d89fPhilip P. Moltmann
898817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    /**
908817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * Presentation mode for the Holo-style date picker that uses a set of
918817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * {@link android.widget.NumberPicker}s.
928817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     *
938817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * @see #getMode()
948817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * @hide Visible for testing only.
958817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     */
968817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    @TestApi
978817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    public static final int MODE_SPINNER = 1;
988817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette
998817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    /**
1008817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * Presentation mode for the Material-style date picker that uses a
1018817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * calendar.
1028817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     *
1038817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * @see #getMode()
1048817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * @hide Visible for testing only.
1058817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     */
1068817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    @TestApi
1078817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    public static final int MODE_CALENDAR = 2;
1088817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette
1098817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    /** @hide */
1108817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    @IntDef({MODE_SPINNER, MODE_CALENDAR})
1118817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    @Retention(RetentionPolicy.SOURCE)
1128817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    public @interface DatePickerMode {}
1133053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase
11460727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette    private final DatePickerDelegate mDelegate;
115bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio
1168817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    @DatePickerMode
1178817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    private final int mMode;
1188817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1200ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette     * The callback used to indicate the user changed the date.
1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface OnDateChangedListener {
1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
125e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov         * Called upon a date change.
126e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov         *
1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param view The view associated with this listener.
1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param year The year that was set.
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param monthOfYear The month that was set (0-11) for compatibility
13050f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov         *            with {@link java.util.Calendar}.
1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param dayOfMonth The day of the month that was set.
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth);
1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public DatePicker(Context context) {
1379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        this(context, null);
1389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
13950f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov
1409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public DatePicker(Context context, AttributeSet attrs) {
1414243dc394d89a93cb207efa36e9755c2424d688bSvetoslav Ganov        this(context, attrs, R.attr.datePickerStyle);
1429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
144617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    public DatePicker(Context context, AttributeSet attrs, int defStyleAttr) {
145617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette        this(context, attrs, defStyleAttr, 0);
146617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    }
147617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette
148617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    public DatePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
149617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette        super(context, attrs, defStyleAttr, defStyleRes);
1509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
151d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme        // DatePicker is important by default, unless app developer overrode attribute.
152d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme        if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) {
153d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme            setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
154d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme        }
155d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme
15660727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePicker,
15760727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette                defStyleAttr, defStyleRes);
1588817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette        final boolean isDialogMode = a.getBoolean(R.styleable.DatePicker_dialogMode, false);
1598817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette        final int requestedMode = a.getInt(R.styleable.DatePicker_datePickerMode, MODE_SPINNER);
1600a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette        final int firstDayOfWeek = a.getInt(R.styleable.DatePicker_firstDayOfWeek, 0);
161bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio        a.recycle();
162bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio
1638817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette        if (requestedMode == MODE_CALENDAR && isDialogMode) {
1648817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette            // You want MODE_CALENDAR? YOU CAN'T HANDLE MODE_CALENDAR! Well,
1658817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette            // maybe you can depending on your screen size. Let's check...
1668817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette            mMode = context.getResources().getInteger(R.integer.date_picker_mode);
1678817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette        } else {
1688817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette            mMode = requestedMode;
1698817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette        }
1708817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette
1718817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette        switch (mMode) {
1723053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase            case MODE_CALENDAR:
1733053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase                mDelegate = createCalendarUIDelegate(context, attrs, defStyleAttr, defStyleRes);
1743053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase                break;
1753053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase            case MODE_SPINNER:
1763053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase            default:
1773053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase                mDelegate = createSpinnerUIDelegate(context, attrs, defStyleAttr, defStyleRes);
1783053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase                break;
179bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio        }
1800a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette
1810a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette        if (firstDayOfWeek != 0) {
1820a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette            setFirstDayOfWeek(firstDayOfWeek);
1830a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette        }
184305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme
185305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        mDelegate.setAutoFillChangeListener((v, y, m, d) -> {
186640f30a7763b0a4b80c767acb84c740aac04768bFelipe Leme            final AutofillManager afm = context.getSystemService(AutofillManager.class);
187305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme            if (afm != null) {
1882f8fb1f62f2840701e3e16497eb8191f38b72e0bSvet Ganov                afm.notifyValueChanged(this);
189305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme            }
190305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        });
191bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio    }
192bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio
1933053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase    private DatePickerDelegate createSpinnerUIDelegate(Context context, AttributeSet attrs,
194bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio            int defStyleAttr, int defStyleRes) {
1953053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase        return new DatePickerSpinnerDelegate(this, context, attrs, defStyleAttr, defStyleRes);
196bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio    }
197bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio
1983053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase    private DatePickerDelegate createCalendarUIDelegate(Context context, AttributeSet attrs,
199bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio            int defStyleAttr, int defStyleRes) {
2003053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase        return new DatePickerCalendarDelegate(this, context, attrs, defStyleAttr,
201bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio                defStyleRes);
202bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio    }
203bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio
204bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio    /**
2058817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * @return the picker's presentation mode, one of {@link #MODE_CALENDAR} or
2068817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     *         {@link #MODE_SPINNER}
2078817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * @attr ref android.R.styleable#DatePicker_datePickerMode
2088817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     * @hide Visible for testing only.
2098817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette     */
2108817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    @DatePickerMode
2118817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    @TestApi
2128817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    public int getMode() {
2138817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette        return mMode;
2148817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    }
2158817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette
2168817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette    /**
217039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * Initialize the state. If the provided values designate an inconsistent
218039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * date the values are normalized before updating the spinners.
219039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     *
220039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @param year The initial year.
221039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @param monthOfYear The initial month <strong>starting from zero</strong>.
222039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @param dayOfMonth The initial day of the month.
223039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @param onDateChangedListener How user is notified date is changed by
224039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     *            user, can be null.
225039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     */
226039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    public void init(int year, int monthOfYear, int dayOfMonth,
227039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio                     OnDateChangedListener onDateChangedListener) {
228039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.init(year, monthOfYear, dayOfMonth, onDateChangedListener);
229039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    }
23013427a04de835677f9e5f727298f168b88faa562Svetoslav Ganov
231039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    /**
23268640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri     * Set the callback that indicates the date has been adjusted by the user.
23368640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri     *
23468640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri     * @param onDateChangedListener How user is notified date is changed by
23568640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri     *            user, can be null.
23668640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri     */
23768640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri    public void setOnDateChangedListener(OnDateChangedListener onDateChangedListener) {
23868640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri        mDelegate.setOnDateChangedListener(onDateChangedListener);
23968640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri    }
24068640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri
24168640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri    /**
242bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio     * Update the current date.
243039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     *
244039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @param year The year.
245039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @param month The month which is <strong>starting from zero</strong>.
246039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @param dayOfMonth The day of the month.
247039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     */
248039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    public void updateDate(int year, int month, int dayOfMonth) {
249039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.updateDate(year, month, dayOfMonth);
250039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    }
251e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov
252039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    /**
253039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @return The selected year.
254039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     */
255039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    public int getYear() {
256039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        return mDelegate.getYear();
257039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    }
2583fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov
259039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    /**
260039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @return The selected month.
261039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     */
262039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    public int getMonth() {
263039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        return mDelegate.getMonth();
264039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    }
2654213804541a8b05cd0587b138a2fd9a3b7fd9350Svetoslav Ganov
266039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    /**
267039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * @return The selected day of month.
268039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     */
269039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    public int getDayOfMonth() {
270039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        return mDelegate.getDayOfMonth();
271e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    }
272e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov
273e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    /**
274e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * Gets the minimal date supported by this {@link DatePicker} in
275e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * milliseconds since January 1, 1970 00:00:00 in
276e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * {@link TimeZone#getDefault()} time zone.
277e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * <p>
278e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * Note: The default minimal date is 01/01/1900.
279e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * <p>
280e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     *
281e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * @return The minimal supported date.
282e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     */
283e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    public long getMinDate() {
284bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio        return mDelegate.getMinDate().getTimeInMillis();
285e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    }
286e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov
287e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    /**
288e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * Sets the minimal date supported by this {@link NumberPicker} in
289e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * milliseconds since January 1, 1970 00:00:00 in
290e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * {@link TimeZone#getDefault()} time zone.
291e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     *
292e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * @param minDate The minimal supported date.
293e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     */
294e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    public void setMinDate(long minDate) {
295039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.setMinDate(minDate);
2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
29750f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov
29828104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov    /**
299e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * Gets the maximal date supported by this {@link DatePicker} in
300e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * milliseconds since January 1, 1970 00:00:00 in
301e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * {@link TimeZone#getDefault()} time zone.
302e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * <p>
303e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * Note: The default maximal date is 12/31/2100.
30428104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov     * <p>
30528104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov     *
306e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * @return The maximal supported date.
307e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     */
308e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    public long getMaxDate() {
309bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio        return mDelegate.getMaxDate().getTimeInMillis();
310e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    }
311e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov
312e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    /**
313e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * Sets the maximal date supported by this {@link DatePicker} in
314e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * milliseconds since January 1, 1970 00:00:00 in
315e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * {@link TimeZone#getDefault()} time zone.
316e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     *
317e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * @param maxDate The maximal supported date.
31828104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov     */
319e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    public void setMaxDate(long maxDate) {
320039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.setMaxDate(maxDate);
32128104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov    }
32228104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov
323518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette    /**
324518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette     * Sets the callback that indicates the current date is valid.
325518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette     *
326518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette     * @param callback the callback, may be null
327518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette     * @hide
328518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette     */
329518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette    public void setValidationCallback(@Nullable ValidationCallback callback) {
330518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette        mDelegate.setValidationCallback(callback);
331518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette    }
332518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette
3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @Override
3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setEnabled(boolean enabled) {
335039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        if (mDelegate.isEnabled() == enabled) {
33651c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov            return;
33751c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov        }
3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        super.setEnabled(enabled);
339039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.setEnabled(enabled);
34051c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov    }
34151c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov
34251c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov    @Override
34351c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov    public boolean isEnabled() {
344039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        return mDelegate.isEnabled();
3459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
347a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette    /** @hide */
3488a2a89588c3889b999a8fffa2d7c7a5c3ce25eb8Svetoslav Ganov    @Override
349a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette    public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
350039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        return mDelegate.dispatchPopulateAccessibilityEvent(event);
3513fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov    }
3523fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov
353a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette    /** @hide */
3543fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov    @Override
355a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette    public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
356a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette        super.onPopulateAccessibilityEventInternal(event);
357039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.onPopulateAccessibilityEvent(event);
3588a2a89588c3889b999a8fffa2d7c7a5c3ce25eb8Svetoslav Ganov    }
3598a2a89588c3889b999a8fffa2d7c7a5c3ce25eb8Svetoslav Ganov
3608a78fd4d9572dff95432fcc4ba0e87563415b728Svetoslav Ganov    @Override
361a7bb6fbeab933326d58aa806d8194b7b13239d34Dianne Hackborn    public CharSequence getAccessibilityClassName() {
362a7bb6fbeab933326d58aa806d8194b7b13239d34Dianne Hackborn        return DatePicker.class.getName();
3638a78fd4d9572dff95432fcc4ba0e87563415b728Svetoslav Ganov    }
3648a78fd4d9572dff95432fcc4ba0e87563415b728Svetoslav Ganov
3658a78fd4d9572dff95432fcc4ba0e87563415b728Svetoslav Ganov    @Override
366f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov    protected void onConfigurationChanged(Configuration newConfig) {
367f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov        super.onConfigurationChanged(newConfig);
368039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.onConfigurationChanged(newConfig);
369f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov    }
370f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov
37150f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov    /**
3720a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * Sets the first day of week.
3730a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     *
3740a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @param firstDayOfWeek The first day of the week conforming to the
3750a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     *            {@link CalendarView} APIs.
3760a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#SUNDAY
3770a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#MONDAY
3780a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#TUESDAY
3790a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#WEDNESDAY
3800a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#THURSDAY
3810a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#FRIDAY
3820a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#SATURDAY
3830a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     *
3840a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @attr ref android.R.styleable#DatePicker_firstDayOfWeek
3850a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     */
3860a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette    public void setFirstDayOfWeek(int firstDayOfWeek) {
3870a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette        if (firstDayOfWeek < Calendar.SUNDAY || firstDayOfWeek > Calendar.SATURDAY) {
3880a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette            throw new IllegalArgumentException("firstDayOfWeek must be between 1 and 7");
3890a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette        }
3900a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette        mDelegate.setFirstDayOfWeek(firstDayOfWeek);
3910a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette    }
3920a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette
3930a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette    /**
3940a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * Gets the first day of week.
3950a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     *
3960a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @return The first day of the week conforming to the {@link CalendarView}
3970a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     *         APIs.
3980a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#SUNDAY
3990a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#MONDAY
4000a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#TUESDAY
4010a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#WEDNESDAY
4020a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#THURSDAY
4030a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#FRIDAY
4040a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @see Calendar#SATURDAY
4050a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     *
4060a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     * @attr ref android.R.styleable#DatePicker_firstDayOfWeek
4070a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette     */
4080a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette    public int getFirstDayOfWeek() {
4090a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette        return mDelegate.getFirstDayOfWeek();
4100a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette    }
4110a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette
4120a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette    /**
413452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * Returns whether the {@link CalendarView} is shown.
414452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * <p>
415452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * <strong>Note:</strong> This method returns {@code false} when the
416452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set
417452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * to {@code calendar}.
418e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     *
419452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * @return {@code true} if the calendar view is shown
4205f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov     * @see #getCalendarView()
4210e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette     * @deprecated Not supported by Material-style {@code calendar} mode
422e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     */
4230e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette    @Deprecated
424e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    public boolean getCalendarViewShown() {
425039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        return mDelegate.getCalendarViewShown();
426e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    }
427e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov
428e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    /**
429452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * Returns the {@link CalendarView} used by this picker.
430d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette     * <p>
4310e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette     * <strong>Note:</strong> This method throws an
4320e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette     * {@link UnsupportedOperationException} when the
433d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette     * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set
434d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette     * to {@code calendar}.
4355f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov     *
436452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * @return the calendar view
4375f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov     * @see #getCalendarViewShown()
4380e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette     * @deprecated Not supported by Material-style {@code calendar} mode
4390e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette     * @throws UnsupportedOperationException if called when the picker is
4400e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette     *         displayed in {@code calendar} mode
4415f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov     */
4420e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette    @Deprecated
4430a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette    public CalendarView getCalendarView() {
444039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        return mDelegate.getCalendarView();
4455f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov    }
4465f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov
4475f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov    /**
448e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * Sets whether the {@link CalendarView} is shown.
449d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette     * <p>
450452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * <strong>Note:</strong> Calling this method has no effect when the
451d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette     * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set
452d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette     * to {@code calendar}.
453e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     *
454452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * @param shown {@code true} to show the calendar view, {@code false} to
455452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     *              hide it
4560e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette     * @deprecated Not supported by Material-style {@code calendar} mode
457e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     */
4580e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette    @Deprecated
459e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    public void setCalendarViewShown(boolean shown) {
460039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.setCalendarViewShown(shown);
461e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    }
462e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov
463e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    /**
464452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * Returns whether the spinners are shown.
465452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * <p>
466835d7986061bbec2cd3433058f67d2efffe1bdeeAlan Viverette     * <strong>Note:</strong> his method returns {@code false} when the
467452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set
468452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * to {@code calendar}.
469e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     *
470452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * @return {@code true} if the spinners are shown
4710e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette     * @deprecated Not supported by Material-style {@code calendar} mode
47250f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov     */
4730e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette    @Deprecated
474e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    public boolean getSpinnersShown() {
475039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        return mDelegate.getSpinnersShown();
476e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    }
477e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov
478e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    /**
479e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     * Sets whether the spinners are shown.
480452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * <p>
481452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * Calling this method has no effect when the
482452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set
483452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * to {@code calendar}.
484e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     *
485452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     * @param shown {@code true} to show the spinners, {@code false} to hide
486452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette     *              them
4870e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette     * @deprecated Not supported by Material-style {@code calendar} mode
488e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov     */
4890e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette    @Deprecated
490e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    public void setSpinnersShown(boolean shown) {
491039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.setSpinnersShown(shown);
492039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    }
493039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
494039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    @Override
495039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
496d015e3454ec1271ba6e5e3e6f0e5f7459b8b09eaAlan Viverette        dispatchThawSelfOnly(container);
497039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    }
498039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
499039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    @Override
500039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    protected Parcelable onSaveInstanceState() {
501039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        Parcelable superState = super.onSaveInstanceState();
502039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        return mDelegate.onSaveInstanceState(superState);
503039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    }
504039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
505039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    @Override
506039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    protected void onRestoreInstanceState(Parcelable state) {
507a67d9095b7731df3a6ae3f45738a2980151fd1afCraig Mautner        BaseSavedState ss = (BaseSavedState) state;
508039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        super.onRestoreInstanceState(ss.getSuperState());
509039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        mDelegate.onRestoreInstanceState(ss);
510e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    }
511e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov
512e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov    /**
513039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * A delegate interface that defined the public API of the DatePicker. Allows different
514039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * DatePicker implementations. This would need to be implemented by the DatePicker delegates
515039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * for the real behavior.
516bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio     *
517bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio     * @hide
518f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov     */
519039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio    interface DatePickerDelegate {
520039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void init(int year, int monthOfYear, int dayOfMonth,
521039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio                  OnDateChangedListener onDateChangedListener);
522f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov
52368640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri        void setOnDateChangedListener(OnDateChangedListener onDateChangedListener);
524305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        void setAutoFillChangeListener(OnDateChangedListener onDateChangedListener);
52568640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri
526039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void updateDate(int year, int month, int dayOfMonth);
527305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        void updateDate(long date);
528f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov
529039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        int getYear();
530039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        int getMonth();
531039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        int getDayOfMonth();
532305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        long getDate();
533f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov
5340a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette        void setFirstDayOfWeek(int firstDayOfWeek);
5350a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette        int getFirstDayOfWeek();
5360a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette
537039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void setMinDate(long minDate);
538bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio        Calendar getMinDate();
539949e9df25bccb736675f950591d3a286ae4052fcElliott Hughes
540039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void setMaxDate(long maxDate);
541bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio        Calendar getMaxDate();
542f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov
543039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void setEnabled(boolean enabled);
544039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        boolean isEnabled();
545039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
546bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio        CalendarView getCalendarView();
547039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
548039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void setCalendarViewShown(boolean shown);
549039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        boolean getCalendarViewShown();
550039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
551039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void setSpinnersShown(boolean shown);
552039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        boolean getSpinnersShown();
553039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
554518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette        void setValidationCallback(ValidationCallback callback);
555bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio
556039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void onConfigurationChanged(Configuration newConfig);
557039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
558039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        Parcelable onSaveInstanceState(Parcelable superState);
559039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void onRestoreInstanceState(Parcelable state);
560039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
561039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
562039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        void onPopulateAccessibilityEvent(AccessibilityEvent event);
563949e9df25bccb736675f950591d3a286ae4052fcElliott Hughes    }
564949e9df25bccb736675f950591d3a286ae4052fcElliott Hughes
565949e9df25bccb736675f950591d3a286ae4052fcElliott Hughes    /**
566039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio     * An abstract class which can be used as a start for DatePicker implementations
567f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov     */
568bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio    abstract static class AbstractDatePickerDelegate implements DatePickerDelegate {
569039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        // The delegator
570039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        protected DatePicker mDelegator;
571039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
572039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        // The context
573039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        protected Context mContext;
574039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
575dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu        protected Calendar mCurrentDate;
576dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu
577039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        // The current locale
578039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        protected Locale mCurrentLocale;
579039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
580039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        // Callbacks
581518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette        protected OnDateChangedListener mOnDateChangedListener;
582305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        protected OnDateChangedListener mAutoFillChangeListener;
583518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette        protected ValidationCallback mValidationCallback;
584039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
585bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio        public AbstractDatePickerDelegate(DatePicker delegator, Context context) {
586039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            mDelegator = delegator;
587039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            mContext = context;
588039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
589039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            setCurrentLocale(Locale.getDefault());
590f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov        }
591f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov
592039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio        protected void setCurrentLocale(Locale locale) {
5930ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette            if (!locale.equals(mCurrentLocale)) {
5940ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette                mCurrentLocale = locale;
5950ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette                onLocaleChanged(locale);
5969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
5979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
598518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette
599518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette        @Override
60068640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri        public void setOnDateChangedListener(OnDateChangedListener callback) {
60168640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri            mOnDateChangedListener = callback;
60268640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri        }
60368640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri
60468640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri        @Override
605305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        public void setAutoFillChangeListener(OnDateChangedListener callback) {
606305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme            mAutoFillChangeListener = callback;
607305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        }
608305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme
609305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        @Override
610518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette        public void setValidationCallback(ValidationCallback callback) {
611518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette            mValidationCallback = callback;
612518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette        }
613518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette
614305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        @Override
615305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        public void updateDate(long date) {
616305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme            Calendar cal = Calendar.getInstance(mCurrentLocale);
617305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme            cal.setTimeInMillis(date);
618305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme            updateDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
619305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme                    cal.get(Calendar.DAY_OF_MONTH));
620305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        }
621305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme
622305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        @Override
623305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        public long getDate() {
624305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme            return mCurrentDate.getTimeInMillis();
625305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        }
626305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme
627518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette        protected void onValidationChanged(boolean valid) {
628518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette            if (mValidationCallback != null) {
629518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette                mValidationCallback.onValidationChanged(valid);
630518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette            }
631518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette        }
6320ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette
6330ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette        protected void onLocaleChanged(Locale locale) {
6340ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette            // Stub.
6350ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette        }
636039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
637dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu        @Override
638dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu        public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
639dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu            event.getText().add(getFormattedCurrentDate());
640dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu        }
641dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu
642dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu        protected String getFormattedCurrentDate() {
643dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu           return DateUtils.formatDateTime(mContext, mCurrentDate.getTimeInMillis(),
644dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu                   DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR
645dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu                           | DateUtils.FORMAT_SHOW_WEEKDAY);
646dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu        }
647dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu
6486b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette        /**
6496b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette         * Class for managing state storing/restoring.
6506b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette         */
6516b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette        static class SavedState extends View.BaseSavedState {
6526b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            private final int mSelectedYear;
6536b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            private final int mSelectedMonth;
6546b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            private final int mSelectedDay;
6556b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            private final long mMinDate;
6566b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            private final long mMaxDate;
6576b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            private final int mCurrentView;
6586b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            private final int mListPosition;
6596b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            private final int mListPositionOffset;
6606b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette
6616b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public SavedState(Parcelable superState, int year, int month, int day, long minDate,
6626b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                    long maxDate) {
6636b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                this(superState, year, month, day, minDate, maxDate, 0, 0, 0);
664039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
665039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
6666b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            /**
6676b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette             * Constructor called from {@link DatePicker#onSaveInstanceState()}
6686b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette             */
6696b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public SavedState(Parcelable superState, int year, int month, int day, long minDate,
6706b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                    long maxDate, int currentView, int listPosition, int listPositionOffset) {
6716b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                super(superState);
6726b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mSelectedYear = year;
6736b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mSelectedMonth = month;
6746b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mSelectedDay = day;
6756b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mMinDate = minDate;
6766b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mMaxDate = maxDate;
6776b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mCurrentView = currentView;
6786b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mListPosition = listPosition;
6796b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mListPositionOffset = listPositionOffset;
680039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
681039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
6826b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            /**
6836b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette             * Constructor called from {@link #CREATOR}
6846b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette             */
6856b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            private SavedState(Parcel in) {
6866b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                super(in);
6876b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mSelectedYear = in.readInt();
6886b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mSelectedMonth = in.readInt();
6896b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mSelectedDay = in.readInt();
6906b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mMinDate = in.readLong();
6916b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mMaxDate = in.readLong();
6926b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mCurrentView = in.readInt();
6936b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mListPosition = in.readInt();
6946b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                mListPositionOffset = in.readInt();
695039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
696039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
6976b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            @Override
6986b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public void writeToParcel(Parcel dest, int flags) {
6996b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                super.writeToParcel(dest, flags);
7006b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                dest.writeInt(mSelectedYear);
7016b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                dest.writeInt(mSelectedMonth);
7026b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                dest.writeInt(mSelectedDay);
7036b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                dest.writeLong(mMinDate);
7046b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                dest.writeLong(mMaxDate);
7056b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                dest.writeInt(mCurrentView);
7066b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                dest.writeInt(mListPosition);
7076b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                dest.writeInt(mListPositionOffset);
708039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
7099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7106b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public int getSelectedDay() {
7116b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                return mSelectedDay;
712039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
7139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7146b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public int getSelectedMonth() {
7156b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                return mSelectedMonth;
716039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
717039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
7186b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public int getSelectedYear() {
7196b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                return mSelectedYear;
720039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
721039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
7226b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public long getMinDate() {
7236b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                return mMinDate;
724039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
7259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7266b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public long getMaxDate() {
7276b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                return mMaxDate;
728039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7306b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public int getCurrentView() {
7316b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                return mCurrentView;
732039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
733e3491b6b5f1d3fb871074766597b275d9f682faaKenneth Andersson
7346b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public int getListPosition() {
7356b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                return mListPosition;
736039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
737039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
7386b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public int getListPositionOffset() {
7396b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                return mListPositionOffset;
740039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio            }
741039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
7426b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            @SuppressWarnings("all")
7436b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            // suppress unused and hiding
7446b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            public static final Parcelable.Creator<SavedState> CREATOR = new Creator<SavedState>() {
745039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
7466b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                public SavedState createFromParcel(Parcel in) {
7476b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                    return new SavedState(in);
7486b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                }
749039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio
7506b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                public SavedState[] newArray(int size) {
7516b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette                    return new SavedState[size];
752039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio                }
7536b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette            };
7546304b0d58e74509a9f21b67b5227b2fee2f1b60fSvetoslav Ganov        }
7556304b0d58e74509a9f21b67b5227b2fee2f1b60fSvetoslav Ganov    }
7566304b0d58e74509a9f21b67b5227b2fee2f1b60fSvetoslav Ganov
757a53efe9923bedab4fe5d578f32eaff308e5b9e76Svetoslav Ganov    /**
7586b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette     * A callback interface for updating input validity when the date picker
7596b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette     * when included into a dialog.
7606b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette     *
7616b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette     * @hide
76250f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov     */
7636b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette    public interface ValidationCallback {
7646b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette        void onValidationChanged(boolean valid);
765e3491b6b5f1d3fb871074766597b275d9f682faaKenneth Andersson    }
766305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme
767305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme    @Override
768640f30a7763b0a4b80c767acb84c740aac04768bFelipe Leme    public void dispatchProvideAutofillStructure(ViewStructure structure, int flags) {
769640f30a7763b0a4b80c767acb84c740aac04768bFelipe Leme        // This view is self-sufficient for autofill, so it needs to call
770305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        // onProvideAutoFillStructure() to fill itself, but it does not need to call
771305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme        // dispatchProvideAutoFillStructure() to fill its children.
772e4f30650ac2b4e7b1b2a8962a3618506aec1b81aFelipe Leme        structure.setAutofillId(getAutofillId());
773640f30a7763b0a4b80c767acb84c740aac04768bFelipe Leme        onProvideAutofillStructure(structure, flags);
774305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme    }
775305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme
776305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme    @Override
777955e252a95785192902da7c9f5610f8e40f97803Felipe Leme    public void autofill(AutofillValue value) {
778955e252a95785192902da7c9f5610f8e40f97803Felipe Leme        if (!isEnabled()) return;
779305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme
780955e252a95785192902da7c9f5610f8e40f97803Felipe Leme        if (!value.isDate()) {
7819668903731c272e51ce610598c052ef411c9d89fPhilip P. Moltmann            Log.w(LOG_TAG, value + " could not be autofilled into " + this);
782955e252a95785192902da7c9f5610f8e40f97803Felipe Leme            return;
7839668903731c272e51ce610598c052ef411c9d89fPhilip P. Moltmann        }
7847b7711680244108923f0dbb4ca6e35db7e659e6aPhilip P. Moltmann
785955e252a95785192902da7c9f5610f8e40f97803Felipe Leme        mDelegate.updateDate(value.getDateValue());
786305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme    }
787305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme
788305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme    @Override
7898931e303700a5adb6e013c2b5a6cec621eede968Felipe Leme    public @AutofillType int getAutofillType() {
7908931e303700a5adb6e013c2b5a6cec621eede968Felipe Leme        return isEnabled() ? AUTOFILL_TYPE_DATE : AUTOFILL_TYPE_NONE;
791305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme    }
792305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme
793305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme    @Override
794640f30a7763b0a4b80c767acb84c740aac04768bFelipe Leme    public AutofillValue getAutofillValue() {
795640f30a7763b0a4b80c767acb84c740aac04768bFelipe Leme        return isEnabled() ? AutofillValue.forDate(mDelegate.getDate()) : null;
796305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme    }
7973fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov}
798