DatePicker.java revision d04a697ede5a372f96f87b80cf99a74dd12dbac4
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; 329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.SparseArray; 33d11e6151fe88314505fa7adca6278de2e772b11cSvetoslav Ganovimport android.view.View; 34305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Lemeimport android.view.ViewStructure; 358a2a89588c3889b999a8fffa2d7c7a5c3ce25eb8Svetoslav Ganovimport android.view.accessibility.AccessibilityEvent; 36305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Lemeimport android.view.autofill.AutoFillManager; 37305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Lemeimport android.view.autofill.AutoFillValue; 389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3999441c5d7da45c10b729185852be97cbb0bdc8d5Aurimas Liutikasimport com.android.internal.R; 4099441c5d7da45c10b729185852be97cbb0bdc8d5Aurimas Liutikas 418817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viveretteimport java.lang.annotation.Retention; 428817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viveretteimport java.lang.annotation.RetentionPolicy; 43dddda8d188408ff18935b1b0e15a00fe012a03daKenny Rootimport java.util.Locale; 449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 46d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * Provides a widget for selecting a date. 47d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * <p> 48d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * When the {@link android.R.styleable#DatePicker_datePickerMode} attribute is 49d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * set to {@code spinner}, the date can be selected using year, month, and day 50d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * spinners or a {@link CalendarView}. The set of spinners and the calendar 51d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * view are automatically synchronized. The client can customize whether only 52d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * the spinners, or only the calendar view, or both to be displayed. 53d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * </p> 54d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * <p> 55d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * When the {@link android.R.styleable#DatePicker_datePickerMode} attribute is 56d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * set to {@code calendar}, the month and day can be selected using a 57d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * calendar-style view while the year can be selected separately using a list. 58d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * </p> 5950f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov * <p> 604c359b76f9a030f92a302ba74a528faa170bad4eScott Main * See the <a href="{@docRoot}guide/topics/ui/controls/pickers.html">Pickers</a> 614c359b76f9a030f92a302ba74a528faa170bad4eScott Main * guide. 6250f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov * </p> 63e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * <p> 649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * For a dialog using this view, see {@link android.app.DatePickerDialog}. 65e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * </p> 66e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * 67e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_startYear 68e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_endYear 69e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_maxDate 70e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_minDate 71e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_spinnersShown 72e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @attr ref android.R.styleable#DatePicker_calendarViewShown 73ba9bf41a77261471a4dc9d7964aec41726b4e4e6Alan Viverette * @attr ref android.R.styleable#DatePicker_dayOfWeekBackground 7460727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_dayOfWeekTextAppearance 75ba9bf41a77261471a4dc9d7964aec41726b4e4e6Alan Viverette * @attr ref android.R.styleable#DatePicker_headerBackground 7660727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_headerMonthTextAppearance 7760727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_headerDayOfMonthTextAppearance 7860727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_headerYearTextAppearance 7960727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_yearListItemTextAppearance 8060727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette * @attr ref android.R.styleable#DatePicker_yearListSelectorColor 81bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio * @attr ref android.R.styleable#DatePicker_calendarTextColor 82d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * @attr ref android.R.styleable#DatePicker_datePickerMode 839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project@Widget 859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class DatePicker extends FrameLayout { 868817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette /** 878817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * Presentation mode for the Holo-style date picker that uses a set of 888817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * {@link android.widget.NumberPicker}s. 898817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * 908817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * @see #getMode() 918817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * @hide Visible for testing only. 928817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette */ 938817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette @TestApi 948817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette public static final int MODE_SPINNER = 1; 958817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette 968817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette /** 978817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * Presentation mode for the Material-style date picker that uses a 988817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * calendar. 998817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * 1008817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * @see #getMode() 1018817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * @hide Visible for testing only. 1028817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette */ 1038817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette @TestApi 1048817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette public static final int MODE_CALENDAR = 2; 1058817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette 1068817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette /** @hide */ 1078817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette @IntDef({MODE_SPINNER, MODE_CALENDAR}) 1088817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette @Retention(RetentionPolicy.SOURCE) 1098817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette public @interface DatePickerMode {} 1103053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase 11160727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette private final DatePickerDelegate mDelegate; 112bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio 1138817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette @DatePickerMode 1148817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette private final int mMode; 1158817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette 1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1170ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette * The callback used to indicate the user changed the date. 1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnDateChangedListener { 1209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 122e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * Called upon a date change. 123e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * 1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param view The view associated with this listener. 1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param year The year that was set. 1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param monthOfYear The month that was set (0-11) for compatibility 12750f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov * with {@link java.util.Calendar}. 1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dayOfMonth The day of the month that was set. 1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth); 1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public DatePicker(Context context) { 1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project this(context, null); 1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 13650f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov 1379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public DatePicker(Context context, AttributeSet attrs) { 1384243dc394d89a93cb207efa36e9755c2424d688bSvetoslav Ganov this(context, attrs, R.attr.datePickerStyle); 1399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 141617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette public DatePicker(Context context, AttributeSet attrs, int defStyleAttr) { 142617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette this(context, attrs, defStyleAttr, 0); 143617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette } 144617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette 145617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette public DatePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 146617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette super(context, attrs, defStyleAttr, defStyleRes); 1479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 148d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme // DatePicker is important by default, unless app developer overrode attribute. 149d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) { 150d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES); 151d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme } 152d04a697ede5a372f96f87b80cf99a74dd12dbac4Felipe Leme 15360727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePicker, 15460727e07c6ef72e2f494266939c02494a3df28f8Alan Viverette defStyleAttr, defStyleRes); 1558817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette final boolean isDialogMode = a.getBoolean(R.styleable.DatePicker_dialogMode, false); 1568817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette final int requestedMode = a.getInt(R.styleable.DatePicker_datePickerMode, MODE_SPINNER); 1570a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette final int firstDayOfWeek = a.getInt(R.styleable.DatePicker_firstDayOfWeek, 0); 158bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio a.recycle(); 159bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio 1608817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette if (requestedMode == MODE_CALENDAR && isDialogMode) { 1618817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette // You want MODE_CALENDAR? YOU CAN'T HANDLE MODE_CALENDAR! Well, 1628817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette // maybe you can depending on your screen size. Let's check... 1638817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette mMode = context.getResources().getInteger(R.integer.date_picker_mode); 1648817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette } else { 1658817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette mMode = requestedMode; 1668817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette } 1678817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette 1688817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette switch (mMode) { 1693053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase case MODE_CALENDAR: 1703053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase mDelegate = createCalendarUIDelegate(context, attrs, defStyleAttr, defStyleRes); 1713053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase break; 1723053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase case MODE_SPINNER: 1733053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase default: 1743053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase mDelegate = createSpinnerUIDelegate(context, attrs, defStyleAttr, defStyleRes); 1753053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase break; 176bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio } 1770a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette 1780a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette if (firstDayOfWeek != 0) { 1790a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette setFirstDayOfWeek(firstDayOfWeek); 1800a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette } 181305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 182305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme mDelegate.setAutoFillChangeListener((v, y, m, d) -> { 183305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme final AutoFillManager afm = context.getSystemService(AutoFillManager.class); 184305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme if (afm != null) { 185305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme afm.valueChanged(this); 186305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme } 187305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme }); 188bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio } 189bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio 1903053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase private DatePickerDelegate createSpinnerUIDelegate(Context context, AttributeSet attrs, 191bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio int defStyleAttr, int defStyleRes) { 1923053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase return new DatePickerSpinnerDelegate(this, context, attrs, defStyleAttr, defStyleRes); 193bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio } 194bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio 1953053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase private DatePickerDelegate createCalendarUIDelegate(Context context, AttributeSet attrs, 196bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio int defStyleAttr, int defStyleRes) { 1973053b2fdcf7486f2e2f572f9b05ce65dacdd2b4cChet Haase return new DatePickerCalendarDelegate(this, context, attrs, defStyleAttr, 198bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio defStyleRes); 199bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio } 200bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio 201bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio /** 2028817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * @return the picker's presentation mode, one of {@link #MODE_CALENDAR} or 2038817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * {@link #MODE_SPINNER} 2048817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * @attr ref android.R.styleable#DatePicker_datePickerMode 2058817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette * @hide Visible for testing only. 2068817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette */ 2078817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette @DatePickerMode 2088817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette @TestApi 2098817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette public int getMode() { 2108817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette return mMode; 2118817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette } 2128817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette 2138817aa93392b7a46402eacd7a3b252d1da6c7225Alan Viverette /** 214039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * Initialize the state. If the provided values designate an inconsistent 215039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * date the values are normalized before updating the spinners. 216039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * 217039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @param year The initial year. 218039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @param monthOfYear The initial month <strong>starting from zero</strong>. 219039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @param dayOfMonth The initial day of the month. 220039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @param onDateChangedListener How user is notified date is changed by 221039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * user, can be null. 222039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio */ 223039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio public void init(int year, int monthOfYear, int dayOfMonth, 224039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio OnDateChangedListener onDateChangedListener) { 225039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.init(year, monthOfYear, dayOfMonth, onDateChangedListener); 226039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 22713427a04de835677f9e5f727298f168b88faa562Svetoslav Ganov 228039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio /** 22968640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri * Set the callback that indicates the date has been adjusted by the user. 23068640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri * 23168640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri * @param onDateChangedListener How user is notified date is changed by 23268640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri * user, can be null. 23368640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri */ 23468640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri public void setOnDateChangedListener(OnDateChangedListener onDateChangedListener) { 23568640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri mDelegate.setOnDateChangedListener(onDateChangedListener); 23668640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri } 23768640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri 23868640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri /** 239bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio * Update the current date. 240039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * 241039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @param year The year. 242039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @param month The month which is <strong>starting from zero</strong>. 243039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @param dayOfMonth The day of the month. 244039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio */ 245039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio public void updateDate(int year, int month, int dayOfMonth) { 246039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.updateDate(year, month, dayOfMonth); 247039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 248e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov 249039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio /** 250039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @return The selected year. 251039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio */ 252039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio public int getYear() { 253039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio return mDelegate.getYear(); 254039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 2553fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov 256039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio /** 257039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @return The selected month. 258039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio */ 259039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio public int getMonth() { 260039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio return mDelegate.getMonth(); 261039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 2624213804541a8b05cd0587b138a2fd9a3b7fd9350Svetoslav Ganov 263039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio /** 264039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * @return The selected day of month. 265039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio */ 266039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio public int getDayOfMonth() { 267039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio return mDelegate.getDayOfMonth(); 268e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov } 269e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov 270e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov /** 271e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * Gets the minimal date supported by this {@link DatePicker} in 272e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * milliseconds since January 1, 1970 00:00:00 in 273e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * {@link TimeZone#getDefault()} time zone. 274e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * <p> 275e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * Note: The default minimal date is 01/01/1900. 276e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * <p> 277e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * 278e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @return The minimal supported date. 279e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov */ 280e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov public long getMinDate() { 281bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio return mDelegate.getMinDate().getTimeInMillis(); 282e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov } 283e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov 284e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov /** 285e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * Sets the minimal date supported by this {@link NumberPicker} in 286e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * milliseconds since January 1, 1970 00:00:00 in 287e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * {@link TimeZone#getDefault()} time zone. 288e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * 289e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @param minDate The minimal supported date. 290e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov */ 291e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov public void setMinDate(long minDate) { 292039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.setMinDate(minDate); 2939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 29450f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov 29528104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov /** 296e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * Gets the maximal date supported by this {@link DatePicker} in 297e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * milliseconds since January 1, 1970 00:00:00 in 298e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * {@link TimeZone#getDefault()} time zone. 299e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * <p> 300e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * Note: The default maximal date is 12/31/2100. 30128104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov * <p> 30228104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov * 303e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @return The maximal supported date. 304e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov */ 305e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov public long getMaxDate() { 306bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio return mDelegate.getMaxDate().getTimeInMillis(); 307e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov } 308e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov 309e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov /** 310e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * Sets the maximal date supported by this {@link DatePicker} in 311e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * milliseconds since January 1, 1970 00:00:00 in 312e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * {@link TimeZone#getDefault()} time zone. 313e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * 314e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * @param maxDate The maximal supported date. 31528104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov */ 316e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov public void setMaxDate(long maxDate) { 317039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.setMaxDate(maxDate); 31828104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov } 31928104e1de5595a22a6987181b13ddeb192739afdSvetoslav Ganov 320518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette /** 321518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette * Sets the callback that indicates the current date is valid. 322518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette * 323518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette * @param callback the callback, may be null 324518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette * @hide 325518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette */ 326518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette public void setValidationCallback(@Nullable ValidationCallback callback) { 327518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette mDelegate.setValidationCallback(callback); 328518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette } 329518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette 3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setEnabled(boolean enabled) { 332039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio if (mDelegate.isEnabled() == enabled) { 33351c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov return; 33451c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov } 3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project super.setEnabled(enabled); 336039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.setEnabled(enabled); 33751c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov } 33851c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov 33951c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov @Override 34051c52edad7d40697d7fb2a091f850506fa897643Svetoslav Ganov public boolean isEnabled() { 341039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio return mDelegate.isEnabled(); 3429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 344a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette /** @hide */ 3458a2a89588c3889b999a8fffa2d7c7a5c3ce25eb8Svetoslav Ganov @Override 346a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { 347039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio return mDelegate.dispatchPopulateAccessibilityEvent(event); 3483fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov } 3493fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov 350a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette /** @hide */ 3513fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov @Override 352a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { 353a54956a0bc611b1e9b3914edc7a604b59688f6b7Alan Viverette super.onPopulateAccessibilityEventInternal(event); 354039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.onPopulateAccessibilityEvent(event); 3558a2a89588c3889b999a8fffa2d7c7a5c3ce25eb8Svetoslav Ganov } 3568a2a89588c3889b999a8fffa2d7c7a5c3ce25eb8Svetoslav Ganov 3578a78fd4d9572dff95432fcc4ba0e87563415b728Svetoslav Ganov @Override 358a7bb6fbeab933326d58aa806d8194b7b13239d34Dianne Hackborn public CharSequence getAccessibilityClassName() { 359a7bb6fbeab933326d58aa806d8194b7b13239d34Dianne Hackborn return DatePicker.class.getName(); 3608a78fd4d9572dff95432fcc4ba0e87563415b728Svetoslav Ganov } 3618a78fd4d9572dff95432fcc4ba0e87563415b728Svetoslav Ganov 3628a78fd4d9572dff95432fcc4ba0e87563415b728Svetoslav Ganov @Override 363f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov protected void onConfigurationChanged(Configuration newConfig) { 364f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov super.onConfigurationChanged(newConfig); 365039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.onConfigurationChanged(newConfig); 366f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov } 367f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov 36850f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov /** 3690a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * Sets the first day of week. 3700a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * 3710a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @param firstDayOfWeek The first day of the week conforming to the 3720a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * {@link CalendarView} APIs. 3730a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#SUNDAY 3740a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#MONDAY 3750a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#TUESDAY 3760a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#WEDNESDAY 3770a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#THURSDAY 3780a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#FRIDAY 3790a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#SATURDAY 3800a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * 3810a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @attr ref android.R.styleable#DatePicker_firstDayOfWeek 3820a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette */ 3830a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette public void setFirstDayOfWeek(int firstDayOfWeek) { 3840a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette if (firstDayOfWeek < Calendar.SUNDAY || firstDayOfWeek > Calendar.SATURDAY) { 3850a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette throw new IllegalArgumentException("firstDayOfWeek must be between 1 and 7"); 3860a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette } 3870a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette mDelegate.setFirstDayOfWeek(firstDayOfWeek); 3880a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette } 3890a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette 3900a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette /** 3910a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * Gets the first day of week. 3920a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * 3930a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @return The first day of the week conforming to the {@link CalendarView} 3940a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * APIs. 3950a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#SUNDAY 3960a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#MONDAY 3970a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#TUESDAY 3980a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#WEDNESDAY 3990a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#THURSDAY 4000a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#FRIDAY 4010a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @see Calendar#SATURDAY 4020a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * 4030a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette * @attr ref android.R.styleable#DatePicker_firstDayOfWeek 4040a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette */ 4050a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette public int getFirstDayOfWeek() { 4060a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette return mDelegate.getFirstDayOfWeek(); 4070a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette } 4080a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette 4090a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette /** 410452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * Returns whether the {@link CalendarView} is shown. 411452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * <p> 412452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * <strong>Note:</strong> This method returns {@code false} when the 413452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set 414452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * to {@code calendar}. 415e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * 416452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * @return {@code true} if the calendar view is shown 4175f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov * @see #getCalendarView() 4180e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette * @deprecated Not supported by Material-style {@code calendar} mode 419e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov */ 4200e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette @Deprecated 421e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov public boolean getCalendarViewShown() { 422039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio return mDelegate.getCalendarViewShown(); 423e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov } 424e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov 425e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov /** 426452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * Returns the {@link CalendarView} used by this picker. 427d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * <p> 4280e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette * <strong>Note:</strong> This method throws an 4290e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette * {@link UnsupportedOperationException} when the 430d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set 431d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * to {@code calendar}. 4325f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov * 433452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * @return the calendar view 4345f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov * @see #getCalendarViewShown() 4350e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette * @deprecated Not supported by Material-style {@code calendar} mode 4360e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette * @throws UnsupportedOperationException if called when the picker is 4370e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette * displayed in {@code calendar} mode 4385f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov */ 4390e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette @Deprecated 4400a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette public CalendarView getCalendarView() { 441039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio return mDelegate.getCalendarView(); 4425f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov } 4435f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov 4445f3f6ce154ca1a0075f8ca13872d74f935acbe3dSvetoslav Ganov /** 445e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * Sets whether the {@link CalendarView} is shown. 446d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * <p> 447452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * <strong>Note:</strong> Calling this method has no effect when the 448d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set 449d25eb9fbb9d659aab5e8ea25d16cb8bcb458a1a9Alan Viverette * to {@code calendar}. 450e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * 451452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * @param shown {@code true} to show the calendar view, {@code false} to 452452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * hide it 4530e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette * @deprecated Not supported by Material-style {@code calendar} mode 454e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov */ 4550e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette @Deprecated 456e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov public void setCalendarViewShown(boolean shown) { 457039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.setCalendarViewShown(shown); 458e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov } 459e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov 460e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov /** 461452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * Returns whether the spinners are shown. 462452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * <p> 463835d7986061bbec2cd3433058f67d2efffe1bdeeAlan Viverette * <strong>Note:</strong> his method returns {@code false} when the 464452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set 465452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * to {@code calendar}. 466e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * 467452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * @return {@code true} if the spinners are shown 4680e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette * @deprecated Not supported by Material-style {@code calendar} mode 46950f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov */ 4700e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette @Deprecated 471e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov public boolean getSpinnersShown() { 472039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio return mDelegate.getSpinnersShown(); 473e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov } 474e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov 475e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov /** 476e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * Sets whether the spinners are shown. 477452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * <p> 478452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * Calling this method has no effect when the 479452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * {@link android.R.styleable#DatePicker_datePickerMode} attribute is set 480452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * to {@code calendar}. 481e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov * 482452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * @param shown {@code true} to show the spinners, {@code false} to hide 483452fe349841476e4c7d17ab0652bdd4d45ce4595Alan Viverette * them 4840e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette * @deprecated Not supported by Material-style {@code calendar} mode 485e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov */ 4860e672148a7c7292efdff0f641177ab06cd9d4968Alan Viverette @Deprecated 487e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov public void setSpinnersShown(boolean shown) { 488039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.setSpinnersShown(shown); 489039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 490039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 491039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio @Override 492039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { 493d015e3454ec1271ba6e5e3e6f0e5f7459b8b09eaAlan Viverette dispatchThawSelfOnly(container); 494039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 495039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 496039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio @Override 497039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio protected Parcelable onSaveInstanceState() { 498039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio Parcelable superState = super.onSaveInstanceState(); 499039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio return mDelegate.onSaveInstanceState(superState); 500039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 501039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 502039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio @Override 503039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio protected void onRestoreInstanceState(Parcelable state) { 504a67d9095b7731df3a6ae3f45738a2980151fd1afCraig Mautner BaseSavedState ss = (BaseSavedState) state; 505039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio super.onRestoreInstanceState(ss.getSuperState()); 506039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegate.onRestoreInstanceState(ss); 507e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov } 508e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov 509e9730bf3d2dcbea1879f24c18aaf9810ac57084cSvetoslav Ganov /** 510039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * A delegate interface that defined the public API of the DatePicker. Allows different 511039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * DatePicker implementations. This would need to be implemented by the DatePicker delegates 512039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * for the real behavior. 513bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio * 514bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio * @hide 515f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov */ 516039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio interface DatePickerDelegate { 517039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void init(int year, int monthOfYear, int dayOfMonth, 518039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio OnDateChangedListener onDateChangedListener); 519f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov 52068640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri void setOnDateChangedListener(OnDateChangedListener onDateChangedListener); 521305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme void setAutoFillChangeListener(OnDateChangedListener onDateChangedListener); 52268640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri 523039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void updateDate(int year, int month, int dayOfMonth); 524305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme void updateDate(long date); 525f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov 526039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio int getYear(); 527039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio int getMonth(); 528039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio int getDayOfMonth(); 529305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme long getDate(); 530f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov 5310a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette void setFirstDayOfWeek(int firstDayOfWeek); 5320a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette int getFirstDayOfWeek(); 5330a04bb0d4bf18318fe5473bf5615c2016bc26373Alan Viverette 534039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void setMinDate(long minDate); 535bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio Calendar getMinDate(); 536949e9df25bccb736675f950591d3a286ae4052fcElliott Hughes 537039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void setMaxDate(long maxDate); 538bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio Calendar getMaxDate(); 539f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov 540039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void setEnabled(boolean enabled); 541039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio boolean isEnabled(); 542039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 543bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio CalendarView getCalendarView(); 544039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 545039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void setCalendarViewShown(boolean shown); 546039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio boolean getCalendarViewShown(); 547039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 548039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void setSpinnersShown(boolean shown); 549039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio boolean getSpinnersShown(); 550039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 551518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette void setValidationCallback(ValidationCallback callback); 552bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio 553039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void onConfigurationChanged(Configuration newConfig); 554039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 555039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio Parcelable onSaveInstanceState(Parcelable superState); 556039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void onRestoreInstanceState(Parcelable state); 557039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 558039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event); 559039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio void onPopulateAccessibilityEvent(AccessibilityEvent event); 560949e9df25bccb736675f950591d3a286ae4052fcElliott Hughes } 561949e9df25bccb736675f950591d3a286ae4052fcElliott Hughes 562949e9df25bccb736675f950591d3a286ae4052fcElliott Hughes /** 563039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio * An abstract class which can be used as a start for DatePicker implementations 564f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov */ 565bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio abstract static class AbstractDatePickerDelegate implements DatePickerDelegate { 566039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio // The delegator 567039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio protected DatePicker mDelegator; 568039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 569039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio // The context 570039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio protected Context mContext; 571039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 572dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu protected Calendar mCurrentDate; 573dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu 574039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio // The current locale 575039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio protected Locale mCurrentLocale; 576039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 577039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio // Callbacks 578518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette protected OnDateChangedListener mOnDateChangedListener; 579305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme protected OnDateChangedListener mAutoFillChangeListener; 580518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette protected ValidationCallback mValidationCallback; 581039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 582bd9152f6ee156ee473f05f6f05f238605996fca4Fabrice Di Meglio public AbstractDatePickerDelegate(DatePicker delegator, Context context) { 583039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mDelegator = delegator; 584039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio mContext = context; 585039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 586039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio setCurrentLocale(Locale.getDefault()); 587f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov } 588f5926962cc665d4a2e6464f9ba9e3e9788496a6fSvetoslav Ganov 589039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio protected void setCurrentLocale(Locale locale) { 5900ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette if (!locale.equals(mCurrentLocale)) { 5910ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette mCurrentLocale = locale; 5920ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette onLocaleChanged(locale); 5939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 595518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette 596518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette @Override 59768640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri public void setOnDateChangedListener(OnDateChangedListener callback) { 59868640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri mOnDateChangedListener = callback; 59968640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri } 60068640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri 60168640b68099765461d5427fddbb925beaa9d2a6aClara Bayarri @Override 602305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme public void setAutoFillChangeListener(OnDateChangedListener callback) { 603305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme mAutoFillChangeListener = callback; 604305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme } 605305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 606305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme @Override 607518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette public void setValidationCallback(ValidationCallback callback) { 608518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette mValidationCallback = callback; 609518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette } 610518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette 611305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme @Override 612305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme public void updateDate(long date) { 613305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme Calendar cal = Calendar.getInstance(mCurrentLocale); 614305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme cal.setTimeInMillis(date); 615305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme updateDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 616305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme cal.get(Calendar.DAY_OF_MONTH)); 617305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme } 618305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 619305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme @Override 620305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme public long getDate() { 621305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme return mCurrentDate.getTimeInMillis(); 622305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme } 623305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 624518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette protected void onValidationChanged(boolean valid) { 625518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette if (mValidationCallback != null) { 626518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette mValidationCallback.onValidationChanged(valid); 627518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette } 628518ff0de95e64116ecb07706fc564d4c19197ca7Alan Viverette } 6290ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette 6300ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette protected void onLocaleChanged(Locale locale) { 6310ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette // Stub. 6320ef59ac0e57e9b99d174d4a53f7d9639357743acAlan Viverette } 633039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 634dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu @Override 635dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu public void onPopulateAccessibilityEvent(AccessibilityEvent event) { 636dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu event.getText().add(getFormattedCurrentDate()); 637dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu } 638dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu 639dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu protected String getFormattedCurrentDate() { 640dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu return DateUtils.formatDateTime(mContext, mCurrentDate.getTimeInMillis(), 641dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR 642dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu | DateUtils.FORMAT_SHOW_WEEKDAY); 643dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu } 644dd80f0065c0088bff30f9ce5e166df47ddf10690Andrei Stingaceanu 6456b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette /** 6466b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette * Class for managing state storing/restoring. 6476b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette */ 6486b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette static class SavedState extends View.BaseSavedState { 6496b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette private final int mSelectedYear; 6506b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette private final int mSelectedMonth; 6516b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette private final int mSelectedDay; 6526b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette private final long mMinDate; 6536b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette private final long mMaxDate; 6546b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette private final int mCurrentView; 6556b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette private final int mListPosition; 6566b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette private final int mListPositionOffset; 6576b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette 6586b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public SavedState(Parcelable superState, int year, int month, int day, long minDate, 6596b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette long maxDate) { 6606b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette this(superState, year, month, day, minDate, maxDate, 0, 0, 0); 661039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 662039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 6636b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette /** 6646b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette * Constructor called from {@link DatePicker#onSaveInstanceState()} 6656b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette */ 6666b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public SavedState(Parcelable superState, int year, int month, int day, long minDate, 6676b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette long maxDate, int currentView, int listPosition, int listPositionOffset) { 6686b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette super(superState); 6696b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mSelectedYear = year; 6706b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mSelectedMonth = month; 6716b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mSelectedDay = day; 6726b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mMinDate = minDate; 6736b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mMaxDate = maxDate; 6746b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mCurrentView = currentView; 6756b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mListPosition = listPosition; 6766b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mListPositionOffset = listPositionOffset; 677039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 678039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 6796b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette /** 6806b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette * Constructor called from {@link #CREATOR} 6816b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette */ 6826b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette private SavedState(Parcel in) { 6836b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette super(in); 6846b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mSelectedYear = in.readInt(); 6856b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mSelectedMonth = in.readInt(); 6866b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mSelectedDay = in.readInt(); 6876b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mMinDate = in.readLong(); 6886b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mMaxDate = in.readLong(); 6896b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mCurrentView = in.readInt(); 6906b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mListPosition = in.readInt(); 6916b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette mListPositionOffset = in.readInt(); 692039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 693039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 6946b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette @Override 6956b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public void writeToParcel(Parcel dest, int flags) { 6966b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette super.writeToParcel(dest, flags); 6976b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette dest.writeInt(mSelectedYear); 6986b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette dest.writeInt(mSelectedMonth); 6996b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette dest.writeInt(mSelectedDay); 7006b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette dest.writeLong(mMinDate); 7016b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette dest.writeLong(mMaxDate); 7026b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette dest.writeInt(mCurrentView); 7036b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette dest.writeInt(mListPosition); 7046b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette dest.writeInt(mListPositionOffset); 705039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 7069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7076b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public int getSelectedDay() { 7086b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return mSelectedDay; 709039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 7109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7116b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public int getSelectedMonth() { 7126b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return mSelectedMonth; 713039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 714039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 7156b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public int getSelectedYear() { 7166b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return mSelectedYear; 717039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 718039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 7196b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public long getMinDate() { 7206b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return mMinDate; 721039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 7229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7236b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public long getMaxDate() { 7246b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return mMaxDate; 725039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 7269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7276b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public int getCurrentView() { 7286b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return mCurrentView; 729039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 730e3491b6b5f1d3fb871074766597b275d9f682faaKenneth Andersson 7316b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public int getListPosition() { 7326b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return mListPosition; 733039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 734039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 7356b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public int getListPositionOffset() { 7366b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return mListPositionOffset; 737039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 738039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 7396b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette @SuppressWarnings("all") 7406b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette // suppress unused and hiding 7416b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public static final Parcelable.Creator<SavedState> CREATOR = new Creator<SavedState>() { 742039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 7436b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public SavedState createFromParcel(Parcel in) { 7446b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return new SavedState(in); 7456b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette } 746039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio 7476b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public SavedState[] newArray(int size) { 7486b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette return new SavedState[size]; 749039a784ea3c24625b74084be18530f81dabd4bbbFabrice Di Meglio } 7506b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette }; 7516304b0d58e74509a9f21b67b5227b2fee2f1b60fSvetoslav Ganov } 7526304b0d58e74509a9f21b67b5227b2fee2f1b60fSvetoslav Ganov } 7536304b0d58e74509a9f21b67b5227b2fee2f1b60fSvetoslav Ganov 754a53efe9923bedab4fe5d578f32eaff308e5b9e76Svetoslav Ganov /** 7556b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette * A callback interface for updating input validity when the date picker 7566b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette * when included into a dialog. 7576b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette * 7586b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette * @hide 75950f34d14f6dd3411fdbdb6a7b8b285c2b8fdbf5cSvetoslav Ganov */ 7606b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette public interface ValidationCallback { 7616b3f85f87ed95cce748aeb57c70df0d2ed72707fAlan Viverette void onValidationChanged(boolean valid); 762e3491b6b5f1d3fb871074766597b275d9f682faaKenneth Andersson } 763305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 764305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme // TODO(b/33197203): add unit/CTS tests for auto-fill methods (and make sure they handle enable) 765305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 766305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme @Override 767305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme public void dispatchProvideAutoFillStructure(ViewStructure structure, int flags) { 768305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme // This view is self-sufficient for auto-fill, so it needs to call 769305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme // onProvideAutoFillStructure() to fill itself, but it does not need to call 770305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme // dispatchProvideAutoFillStructure() to fill its children. 771305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme onProvideAutoFillStructure(structure, flags); 772305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme } 773305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 774305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme @Override 775305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme public void autoFill(AutoFillValue value) { 776305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme if (!isEnabled()) return; 777305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 778305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme mDelegate.updateDate(value.getDateValue()); 779305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme } 780305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 781305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme @Override 7828931e303700a5adb6e013c2b5a6cec621eede968Felipe Leme public @AutofillType int getAutofillType() { 7838931e303700a5adb6e013c2b5a6cec621eede968Felipe Leme return isEnabled() ? AUTOFILL_TYPE_DATE : AUTOFILL_TYPE_NONE; 784305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme } 785305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme 786305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme @Override 787305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme public AutoFillValue getAutoFillValue() { 788305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme return isEnabled() ? AutoFillValue.forDate(mDelegate.getDate()) : null; 789305b72c92568a2dd2ece08caebd610ec8bd473f4Felipe Leme } 7903fec3fe0e3a83c5e0d1264f34bcc55b158537bc6Svetoslav Ganov} 791