Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.widget; |
| 18 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.res.ColorStateList; |
| 22 | import android.content.res.Configuration; |
| 23 | import android.content.res.Resources; |
| 24 | import android.content.res.TypedArray; |
| 25 | import android.os.Parcel; |
| 26 | import android.os.Parcelable; |
| 27 | import android.text.format.DateFormat; |
| 28 | import android.text.format.DateUtils; |
| 29 | import android.util.AttributeSet; |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 30 | import android.util.StateSet; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 31 | import android.view.HapticFeedbackConstants; |
| 32 | import android.view.LayoutInflater; |
| 33 | import android.view.View; |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 34 | import android.view.View.OnClickListener; |
| 35 | import android.view.ViewGroup; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 36 | import android.view.accessibility.AccessibilityEvent; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 37 | import android.view.animation.AlphaAnimation; |
| 38 | import android.view.animation.Animation; |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 39 | import android.widget.DayPickerView.OnDaySelectedListener; |
| 40 | import android.widget.YearPickerView.OnYearSelectedListener; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 41 | |
| 42 | import com.android.internal.R; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 43 | |
| 44 | import java.text.SimpleDateFormat; |
| 45 | import java.util.Calendar; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 46 | import java.util.Locale; |
| 47 | |
| 48 | /** |
| 49 | * A delegate for picking up a date (day / month / year). |
| 50 | */ |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 51 | class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate { |
Alan Viverette | 0a04bb0 | 2014-09-03 20:48:02 -0700 | [diff] [blame] | 52 | private static final int USE_LOCALE = 0; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 53 | |
| 54 | private static final int UNINITIALIZED = -1; |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 55 | private static final int VIEW_MONTH_DAY = 0; |
| 56 | private static final int VIEW_YEAR = 1; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 57 | |
| 58 | private static final int DEFAULT_START_YEAR = 1900; |
| 59 | private static final int DEFAULT_END_YEAR = 2100; |
| 60 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 61 | private static final int ANIMATION_DURATION = 300; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 62 | |
Alan Viverette | 60b674e | 2015-03-25 13:00:42 -0700 | [diff] [blame] | 63 | private static final int[] ATTRS_TEXT_COLOR = new int[] { |
| 64 | com.android.internal.R.attr.textColor}; |
| 65 | private static final int[] ATTRS_DISABLED_ALPHA = new int[] { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 66 | com.android.internal.R.attr.disabledAlpha}; |
Alan Viverette | 7119d0d | 2014-08-25 17:27:02 -0700 | [diff] [blame] | 67 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 68 | private SimpleDateFormat mYearFormat; |
| 69 | private SimpleDateFormat mMonthDayFormat; |
Alan Viverette | 7119d0d | 2014-08-25 17:27:02 -0700 | [diff] [blame] | 70 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 71 | // Top-level container. |
| 72 | private ViewGroup mContainer; |
Alan Viverette | 7119d0d | 2014-08-25 17:27:02 -0700 | [diff] [blame] | 73 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 74 | // Header views. |
| 75 | private TextView mHeaderYear; |
| 76 | private TextView mHeaderMonthDay; |
| 77 | |
| 78 | // Picker views. |
| 79 | private ViewAnimator mAnimator; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 80 | private DayPickerView mDayPickerView; |
| 81 | private YearPickerView mYearPickerView; |
| 82 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 83 | // Accessibility strings. |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 84 | private String mSelectDay; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 85 | private String mSelectYear; |
| 86 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 87 | private DatePicker.OnDateChangedListener mDateChangedListener; |
| 88 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 89 | private int mCurrentView = UNINITIALIZED; |
| 90 | |
Alan Viverette | 452fe34 | 2015-03-23 14:26:09 -0700 | [diff] [blame] | 91 | private final Calendar mCurrentDate; |
| 92 | private final Calendar mTempDate; |
| 93 | private final Calendar mMinDate; |
| 94 | private final Calendar mMaxDate; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 95 | |
Alan Viverette | 0a04bb0 | 2014-09-03 20:48:02 -0700 | [diff] [blame] | 96 | private int mFirstDayOfWeek = USE_LOCALE; |
| 97 | |
Chet Haase | 3053b2f | 2014-08-06 07:51:50 -0700 | [diff] [blame] | 98 | public DatePickerCalendarDelegate(DatePicker delegator, Context context, AttributeSet attrs, |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 99 | int defStyleAttr, int defStyleRes) { |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 100 | super(delegator, context); |
| 101 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 102 | final Locale locale = mCurrentLocale; |
Alan Viverette | 452fe34 | 2015-03-23 14:26:09 -0700 | [diff] [blame] | 103 | mCurrentDate = Calendar.getInstance(locale); |
| 104 | mTempDate = Calendar.getInstance(locale); |
| 105 | mMinDate = Calendar.getInstance(locale); |
| 106 | mMaxDate = Calendar.getInstance(locale); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 107 | |
You Kim | 49e6c4a | 2015-02-26 19:06:16 +0900 | [diff] [blame] | 108 | mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1); |
| 109 | mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 110 | |
Alan Viverette | 60727e0 | 2014-07-28 16:56:32 -0700 | [diff] [blame] | 111 | final Resources res = mDelegator.getResources(); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 112 | final TypedArray a = mContext.obtainStyledAttributes(attrs, |
| 113 | R.styleable.DatePicker, defStyleAttr, defStyleRes); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 114 | final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( |
| 115 | Context.LAYOUT_INFLATER_SERVICE); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 116 | final int layoutResourceId = a.getResourceId( |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 117 | R.styleable.DatePicker_internalLayout, R.layout.date_picker_material); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 118 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 119 | // Set up and attach container. |
| 120 | mContainer = (ViewGroup) inflater.inflate(layoutResourceId, mDelegator); |
Alan Viverette | 7119d0d | 2014-08-25 17:27:02 -0700 | [diff] [blame] | 121 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 122 | // Set up header views. |
| 123 | final ViewGroup header = (ViewGroup) mContainer.findViewById(R.id.date_picker_header); |
| 124 | mHeaderYear = (TextView) header.findViewById(R.id.date_picker_header_year); |
| 125 | mHeaderYear.setOnClickListener(mOnHeaderClickListener); |
| 126 | mHeaderMonthDay = (TextView) header.findViewById(R.id.date_picker_header_date); |
| 127 | mHeaderMonthDay.setOnClickListener(mOnHeaderClickListener); |
Alan Viverette | 60727e0 | 2014-07-28 16:56:32 -0700 | [diff] [blame] | 128 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 129 | // For the sake of backwards compatibility, attempt to extract the text |
| 130 | // color from the header month text appearance. If it's set, we'll let |
| 131 | // that override the "real" header text color. |
| 132 | ColorStateList headerTextColor = null; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 133 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 134 | @SuppressWarnings("deprecation") |
| 135 | final int monthHeaderTextAppearance = a.getResourceId( |
Alan Viverette | 4e5168f | 2015-01-08 15:24:45 -0800 | [diff] [blame] | 136 | R.styleable.DatePicker_headerMonthTextAppearance, 0); |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 137 | if (monthHeaderTextAppearance != 0) { |
| 138 | final TypedArray textAppearance = mContext.obtainStyledAttributes(null, |
| 139 | ATTRS_TEXT_COLOR, 0, monthHeaderTextAppearance); |
| 140 | final ColorStateList legacyHeaderTextColor = textAppearance.getColorStateList(0); |
| 141 | headerTextColor = applyLegacyColorFixes(legacyHeaderTextColor); |
| 142 | textAppearance.recycle(); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 145 | if (headerTextColor == null) { |
| 146 | headerTextColor = a.getColorStateList(R.styleable.DatePicker_headerTextColor); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 149 | if (headerTextColor != null) { |
| 150 | mHeaderYear.setTextColor(headerTextColor); |
| 151 | mHeaderMonthDay.setTextColor(headerTextColor); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 152 | } |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 153 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 154 | // Set up header background, if available. |
| 155 | if (a.hasValueOrEmpty(R.styleable.DatePicker_headerBackground)) { |
| 156 | header.setBackground(a.getDrawable(R.styleable.DatePicker_headerBackground)); |
| 157 | } |
| 158 | |
Alan Viverette | 60b674e | 2015-03-25 13:00:42 -0700 | [diff] [blame] | 159 | a.recycle(); |
| 160 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 161 | // Set up picker container. |
| 162 | mAnimator = (ViewAnimator) mContainer.findViewById(R.id.animator); |
| 163 | |
| 164 | // Set up day picker view. |
| 165 | mDayPickerView = (DayPickerView) mAnimator.findViewById(R.id.date_picker_day_picker); |
Alan Viverette | e763c9b | 2014-11-06 15:22:31 -0800 | [diff] [blame] | 166 | mDayPickerView.setFirstDayOfWeek(mFirstDayOfWeek); |
Alan Viverette | 4612740 | 2014-11-13 10:50:37 -0800 | [diff] [blame] | 167 | mDayPickerView.setMinDate(mMinDate.getTimeInMillis()); |
| 168 | mDayPickerView.setMaxDate(mMaxDate.getTimeInMillis()); |
| 169 | mDayPickerView.setDate(mCurrentDate.getTimeInMillis()); |
Alan Viverette | e763c9b | 2014-11-06 15:22:31 -0800 | [diff] [blame] | 170 | mDayPickerView.setOnDaySelectedListener(mOnDaySelectedListener); |
Alan Viverette | 50eb025 | 2014-10-24 14:34:26 -0700 | [diff] [blame] | 171 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 172 | // Set up year picker view. |
| 173 | mYearPickerView = (YearPickerView) mAnimator.findViewById(R.id.date_picker_year_picker); |
Alan Viverette | 2a90fa6 | 2015-02-17 13:09:04 -0800 | [diff] [blame] | 174 | mYearPickerView.setRange(mMinDate, mMaxDate); |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 175 | mYearPickerView.setDate(mCurrentDate.getTimeInMillis()); |
| 176 | mYearPickerView.setOnYearSelectedListener(mOnYearSelectedListener); |
Alan Viverette | 4e5168f | 2015-01-08 15:24:45 -0800 | [diff] [blame] | 177 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 178 | // Set up content descriptions. |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 179 | mSelectDay = res.getString(R.string.select_day); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 180 | mSelectYear = res.getString(R.string.select_year); |
| 181 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 182 | // Initialize for current locale. This also initializes the date, so no |
| 183 | // need to call onDateChanged. |
| 184 | onLocaleChanged(mCurrentLocale); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 185 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 186 | setCurrentView(VIEW_MONTH_DAY); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 190 | * The legacy text color might have been poorly defined. Ensures that it |
| 191 | * has an appropriate activated state, using the selected state if one |
| 192 | * exists or modifying the default text color otherwise. |
| 193 | * |
| 194 | * @param color a legacy text color, or {@code null} |
| 195 | * @return a color state list with an appropriate activated state, or |
| 196 | * {@code null} if a valid activated state could not be generated |
| 197 | */ |
| 198 | @Nullable |
| 199 | private ColorStateList applyLegacyColorFixes(@Nullable ColorStateList color) { |
| 200 | if (color == null || color.hasState(R.attr.state_activated)) { |
| 201 | return color; |
| 202 | } |
| 203 | |
| 204 | final int activatedColor; |
| 205 | final int defaultColor; |
| 206 | if (color.hasState(R.attr.state_selected)) { |
| 207 | activatedColor = color.getColorForState(StateSet.get( |
| 208 | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_SELECTED), 0); |
| 209 | defaultColor = color.getColorForState(StateSet.get( |
| 210 | StateSet.VIEW_STATE_ENABLED), 0); |
| 211 | } else { |
| 212 | activatedColor = color.getDefaultColor(); |
| 213 | |
| 214 | // Generate a non-activated color using the disabled alpha. |
| 215 | final TypedArray ta = mContext.obtainStyledAttributes(ATTRS_DISABLED_ALPHA); |
| 216 | final float disabledAlpha = ta.getFloat(0, 0.30f); |
| 217 | defaultColor = multiplyAlphaComponent(activatedColor, disabledAlpha); |
| 218 | } |
| 219 | |
| 220 | if (activatedColor == 0 || defaultColor == 0) { |
| 221 | // We somehow failed to obtain the colors. |
| 222 | return null; |
| 223 | } |
| 224 | |
| 225 | final int[][] stateSet = new int[][] {{ R.attr.state_activated }, {}}; |
| 226 | final int[] colors = new int[] { activatedColor, defaultColor }; |
| 227 | return new ColorStateList(stateSet, colors); |
| 228 | } |
| 229 | |
| 230 | private int multiplyAlphaComponent(int color, float alphaMod) { |
| 231 | final int srcRgb = color & 0xFFFFFF; |
| 232 | final int srcAlpha = (color >> 24) & 0xFF; |
| 233 | final int dstAlpha = (int) (srcAlpha * alphaMod + 0.5f); |
| 234 | return srcRgb | (dstAlpha << 24); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Listener called when the user selects a day in the day picker view. |
| 239 | */ |
| 240 | private final OnDaySelectedListener mOnDaySelectedListener = new OnDaySelectedListener() { |
| 241 | @Override |
| 242 | public void onDaySelected(DayPickerView view, Calendar day) { |
| 243 | mCurrentDate.setTimeInMillis(day.getTimeInMillis()); |
| 244 | onDateChanged(true, true); |
| 245 | } |
| 246 | }; |
| 247 | |
| 248 | /** |
| 249 | * Listener called when the user selects a year in the year picker view. |
| 250 | */ |
| 251 | private final OnYearSelectedListener mOnYearSelectedListener = new OnYearSelectedListener() { |
| 252 | @Override |
| 253 | public void onYearChanged(YearPickerView view, int year) { |
| 254 | // If the newly selected month / year does not contain the |
| 255 | // currently selected day number, change the selected day number |
| 256 | // to the last day of the selected month or year. |
| 257 | // e.g. Switching from Mar to Apr when Mar 31 is selected -> Apr 30 |
| 258 | // e.g. Switching from 2012 to 2013 when Feb 29, 2012 is selected -> Feb 28, 2013 |
| 259 | final int day = mCurrentDate.get(Calendar.DAY_OF_MONTH); |
| 260 | final int month = mCurrentDate.get(Calendar.MONTH); |
| 261 | final int daysInMonth = getDaysInMonth(month, year); |
| 262 | if (day > daysInMonth) { |
| 263 | mCurrentDate.set(Calendar.DAY_OF_MONTH, daysInMonth); |
| 264 | } |
| 265 | |
| 266 | mCurrentDate.set(Calendar.YEAR, year); |
| 267 | onDateChanged(true, true); |
| 268 | |
| 269 | // Automatically switch to day picker. |
| 270 | setCurrentView(VIEW_MONTH_DAY); |
| 271 | } |
| 272 | }; |
| 273 | |
| 274 | /** |
| 275 | * Listener called when the user clicks on a header item. |
| 276 | */ |
| 277 | private final OnClickListener mOnHeaderClickListener = new OnClickListener() { |
| 278 | @Override |
| 279 | public void onClick(View v) { |
| 280 | tryVibrate(); |
| 281 | |
| 282 | switch (v.getId()) { |
| 283 | case R.id.date_picker_header_year: |
| 284 | setCurrentView(VIEW_YEAR); |
| 285 | break; |
| 286 | case R.id.date_picker_header_date: |
| 287 | setCurrentView(VIEW_MONTH_DAY); |
| 288 | break; |
| 289 | } |
| 290 | } |
| 291 | }; |
| 292 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 293 | @Override |
| 294 | protected void onLocaleChanged(Locale locale) { |
| 295 | final TextView headerYear = mHeaderYear; |
| 296 | if (headerYear == null) { |
| 297 | // Abort, we haven't initialized yet. This method will get called |
| 298 | // again later after everything has been set up. |
| 299 | return; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 300 | } |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 301 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 302 | // Update the date formatter. |
| 303 | final String datePattern = DateFormat.getBestDateTimePattern(locale, "EMMMd"); |
| 304 | mMonthDayFormat = new SimpleDateFormat(datePattern, locale); |
| 305 | mYearFormat = new SimpleDateFormat("y", locale); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 306 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 307 | // Update the header text. |
| 308 | onCurrentDateChanged(false); |
| 309 | } |
| 310 | |
| 311 | private void onCurrentDateChanged(boolean announce) { |
| 312 | if (mHeaderYear == null) { |
| 313 | // Abort, we haven't initialized yet. This method will get called |
| 314 | // again later after everything has been set up. |
| 315 | return; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 318 | final String year = mYearFormat.format(mCurrentDate.getTime()); |
| 319 | mHeaderYear.setText(year); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 320 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 321 | final String monthDay = mMonthDayFormat.format(mCurrentDate.getTime()); |
| 322 | mHeaderMonthDay.setText(monthDay); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 323 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 324 | // TODO: This should use live regions. |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 325 | if (announce) { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 326 | final long millis = mCurrentDate.getTimeInMillis(); |
| 327 | final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR; |
| 328 | final String fullDateText = DateUtils.formatDateTime(mContext, millis, flags); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 329 | mAnimator.announceForAccessibility(fullDateText); |
| 330 | } |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | private void setCurrentView(final int viewIndex) { |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 334 | switch (viewIndex) { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 335 | case VIEW_MONTH_DAY: |
| 336 | mDayPickerView.setDate(mCurrentDate.getTimeInMillis()); |
| 337 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 338 | if (mCurrentView != viewIndex) { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 339 | mHeaderMonthDay.setActivated(true); |
| 340 | mHeaderYear.setActivated(false); |
| 341 | mAnimator.setDisplayedChild(VIEW_MONTH_DAY); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 342 | mCurrentView = viewIndex; |
| 343 | } |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 344 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 345 | mAnimator.announceForAccessibility(mSelectDay); |
| 346 | break; |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 347 | case VIEW_YEAR: |
| 348 | mYearPickerView.setDate(mCurrentDate.getTimeInMillis()); |
| 349 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 350 | if (mCurrentView != viewIndex) { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 351 | mHeaderMonthDay.setActivated(false); |
| 352 | mHeaderYear.setActivated(true); |
| 353 | mAnimator.setDisplayedChild(VIEW_YEAR); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 354 | mCurrentView = viewIndex; |
| 355 | } |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 356 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 357 | mAnimator.announceForAccessibility(mSelectYear); |
| 358 | break; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void init(int year, int monthOfYear, int dayOfMonth, |
| 364 | DatePicker.OnDateChangedListener callBack) { |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 365 | mCurrentDate.set(Calendar.YEAR, year); |
| 366 | mCurrentDate.set(Calendar.MONTH, monthOfYear); |
| 367 | mCurrentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); |
Alan Viverette | e6ec07f | 2014-12-10 11:24:27 -0800 | [diff] [blame] | 368 | |
Alan Viverette | e6ec07f | 2014-12-10 11:24:27 -0800 | [diff] [blame] | 369 | mDateChangedListener = callBack; |
Alan Viverette | 0cecbc9 | 2014-12-12 14:32:43 -0800 | [diff] [blame] | 370 | |
| 371 | onDateChanged(false, false); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public void updateDate(int year, int month, int dayOfMonth) { |
| 376 | mCurrentDate.set(Calendar.YEAR, year); |
| 377 | mCurrentDate.set(Calendar.MONTH, month); |
| 378 | mCurrentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); |
Alan Viverette | e6ec07f | 2014-12-10 11:24:27 -0800 | [diff] [blame] | 379 | |
Alan Viverette | 0cecbc9 | 2014-12-12 14:32:43 -0800 | [diff] [blame] | 380 | onDateChanged(false, true); |
Alan Viverette | e6ec07f | 2014-12-10 11:24:27 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Alan Viverette | 0cecbc9 | 2014-12-12 14:32:43 -0800 | [diff] [blame] | 383 | private void onDateChanged(boolean fromUser, boolean callbackToClient) { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 384 | final int year = mCurrentDate.get(Calendar.YEAR); |
| 385 | |
Alan Viverette | 0cecbc9 | 2014-12-12 14:32:43 -0800 | [diff] [blame] | 386 | if (callbackToClient && mDateChangedListener != null) { |
Alan Viverette | e6ec07f | 2014-12-10 11:24:27 -0800 | [diff] [blame] | 387 | final int monthOfYear = mCurrentDate.get(Calendar.MONTH); |
| 388 | final int dayOfMonth = mCurrentDate.get(Calendar.DAY_OF_MONTH); |
| 389 | mDateChangedListener.onDateChanged(mDelegator, year, monthOfYear, dayOfMonth); |
Alan Viverette | 9468c6a | 2014-08-21 13:56:54 -0700 | [diff] [blame] | 390 | } |
Alan Viverette | e6ec07f | 2014-12-10 11:24:27 -0800 | [diff] [blame] | 391 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 392 | mDayPickerView.setDate(mCurrentDate.getTimeInMillis()); |
| 393 | mYearPickerView.setYear(year); |
Alan Viverette | e6ec07f | 2014-12-10 11:24:27 -0800 | [diff] [blame] | 394 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 395 | onCurrentDateChanged(fromUser); |
Alan Viverette | e6ec07f | 2014-12-10 11:24:27 -0800 | [diff] [blame] | 396 | |
| 397 | if (fromUser) { |
| 398 | tryVibrate(); |
| 399 | } |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | @Override |
| 403 | public int getYear() { |
| 404 | return mCurrentDate.get(Calendar.YEAR); |
| 405 | } |
| 406 | |
| 407 | @Override |
| 408 | public int getMonth() { |
| 409 | return mCurrentDate.get(Calendar.MONTH); |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public int getDayOfMonth() { |
| 414 | return mCurrentDate.get(Calendar.DAY_OF_MONTH); |
| 415 | } |
| 416 | |
| 417 | @Override |
| 418 | public void setMinDate(long minDate) { |
| 419 | mTempDate.setTimeInMillis(minDate); |
| 420 | if (mTempDate.get(Calendar.YEAR) == mMinDate.get(Calendar.YEAR) |
| 421 | && mTempDate.get(Calendar.DAY_OF_YEAR) != mMinDate.get(Calendar.DAY_OF_YEAR)) { |
| 422 | return; |
| 423 | } |
| 424 | if (mCurrentDate.before(mTempDate)) { |
| 425 | mCurrentDate.setTimeInMillis(minDate); |
Alan Viverette | 0cecbc9 | 2014-12-12 14:32:43 -0800 | [diff] [blame] | 426 | onDateChanged(false, true); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 427 | } |
| 428 | mMinDate.setTimeInMillis(minDate); |
Alan Viverette | 4612740 | 2014-11-13 10:50:37 -0800 | [diff] [blame] | 429 | mDayPickerView.setMinDate(minDate); |
Alan Viverette | 50eb025 | 2014-10-24 14:34:26 -0700 | [diff] [blame] | 430 | mYearPickerView.setRange(mMinDate, mMaxDate); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | @Override |
| 434 | public Calendar getMinDate() { |
| 435 | return mMinDate; |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public void setMaxDate(long maxDate) { |
| 440 | mTempDate.setTimeInMillis(maxDate); |
| 441 | if (mTempDate.get(Calendar.YEAR) == mMaxDate.get(Calendar.YEAR) |
| 442 | && mTempDate.get(Calendar.DAY_OF_YEAR) != mMaxDate.get(Calendar.DAY_OF_YEAR)) { |
| 443 | return; |
| 444 | } |
| 445 | if (mCurrentDate.after(mTempDate)) { |
| 446 | mCurrentDate.setTimeInMillis(maxDate); |
Alan Viverette | 0cecbc9 | 2014-12-12 14:32:43 -0800 | [diff] [blame] | 447 | onDateChanged(false, true); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 448 | } |
| 449 | mMaxDate.setTimeInMillis(maxDate); |
Alan Viverette | 4612740 | 2014-11-13 10:50:37 -0800 | [diff] [blame] | 450 | mDayPickerView.setMaxDate(maxDate); |
Alan Viverette | 50eb025 | 2014-10-24 14:34:26 -0700 | [diff] [blame] | 451 | mYearPickerView.setRange(mMinDate, mMaxDate); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | @Override |
| 455 | public Calendar getMaxDate() { |
| 456 | return mMaxDate; |
| 457 | } |
| 458 | |
| 459 | @Override |
Alan Viverette | 0a04bb0 | 2014-09-03 20:48:02 -0700 | [diff] [blame] | 460 | public void setFirstDayOfWeek(int firstDayOfWeek) { |
| 461 | mFirstDayOfWeek = firstDayOfWeek; |
Alan Viverette | e763c9b | 2014-11-06 15:22:31 -0800 | [diff] [blame] | 462 | |
| 463 | mDayPickerView.setFirstDayOfWeek(firstDayOfWeek); |
Alan Viverette | 0a04bb0 | 2014-09-03 20:48:02 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | @Override |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 467 | public int getFirstDayOfWeek() { |
Alan Viverette | 0a04bb0 | 2014-09-03 20:48:02 -0700 | [diff] [blame] | 468 | if (mFirstDayOfWeek != USE_LOCALE) { |
| 469 | return mFirstDayOfWeek; |
| 470 | } |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 471 | return mCurrentDate.getFirstDayOfWeek(); |
| 472 | } |
| 473 | |
| 474 | @Override |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 475 | public void setEnabled(boolean enabled) { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 476 | mContainer.setEnabled(false); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | @Override |
| 480 | public boolean isEnabled() { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 481 | return mContainer.isEnabled(); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | @Override |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 485 | public CalendarView getCalendarView() { |
| 486 | throw new UnsupportedOperationException( |
| 487 | "CalendarView does not exists for the new DatePicker"); |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public void setCalendarViewShown(boolean shown) { |
| 492 | // No-op for compatibility with the old DatePicker. |
| 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public boolean getCalendarViewShown() { |
| 497 | return false; |
| 498 | } |
| 499 | |
| 500 | @Override |
| 501 | public void setSpinnersShown(boolean shown) { |
| 502 | // No-op for compatibility with the old DatePicker. |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public boolean getSpinnersShown() { |
| 507 | return false; |
| 508 | } |
| 509 | |
| 510 | @Override |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 511 | public void onConfigurationChanged(Configuration newConfig) { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 512 | setCurrentLocale(newConfig.locale); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | @Override |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 516 | public Parcelable onSaveInstanceState(Parcelable superState) { |
| 517 | final int year = mCurrentDate.get(Calendar.YEAR); |
| 518 | final int month = mCurrentDate.get(Calendar.MONTH); |
| 519 | final int day = mCurrentDate.get(Calendar.DAY_OF_MONTH); |
| 520 | |
| 521 | int listPosition = -1; |
| 522 | int listPositionOffset = -1; |
| 523 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 524 | if (mCurrentView == VIEW_MONTH_DAY) { |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 525 | listPosition = mDayPickerView.getMostVisiblePosition(); |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 526 | } else if (mCurrentView == VIEW_YEAR) { |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 527 | listPosition = mYearPickerView.getFirstVisiblePosition(); |
| 528 | listPositionOffset = mYearPickerView.getFirstPositionOffset(); |
| 529 | } |
| 530 | |
| 531 | return new SavedState(superState, year, month, day, mMinDate.getTimeInMillis(), |
| 532 | mMaxDate.getTimeInMillis(), mCurrentView, listPosition, listPositionOffset); |
| 533 | } |
| 534 | |
| 535 | @Override |
| 536 | public void onRestoreInstanceState(Parcelable state) { |
Alan Viverette | 816aa14 | 2015-04-10 15:41:10 -0700 | [diff] [blame] | 537 | final SavedState ss = (SavedState) state; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 538 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 539 | // TODO: Move instance state into DayPickerView, YearPickerView. |
Craig Mautner | a67d909 | 2014-09-16 15:38:47 -0700 | [diff] [blame] | 540 | mCurrentDate.set(ss.getSelectedYear(), ss.getSelectedMonth(), ss.getSelectedDay()); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 541 | mMinDate.setTimeInMillis(ss.getMinDate()); |
| 542 | mMaxDate.setTimeInMillis(ss.getMaxDate()); |
| 543 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 544 | onCurrentDateChanged(false); |
Alan Viverette | 816aa14 | 2015-04-10 15:41:10 -0700 | [diff] [blame] | 545 | |
| 546 | final int currentView = ss.getCurrentView(); |
| 547 | setCurrentView(currentView); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 548 | |
| 549 | final int listPosition = ss.getListPosition(); |
| 550 | if (listPosition != -1) { |
Alan Viverette | 816aa14 | 2015-04-10 15:41:10 -0700 | [diff] [blame] | 551 | if (currentView == VIEW_MONTH_DAY) { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 552 | mDayPickerView.setCurrentItem(listPosition); |
Alan Viverette | 816aa14 | 2015-04-10 15:41:10 -0700 | [diff] [blame] | 553 | } else if (currentView == VIEW_YEAR) { |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 554 | final int listPositionOffset = ss.getListPositionOffset(); |
| 555 | mYearPickerView.setSelectionFromTop(listPosition, listPositionOffset); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | @Override |
| 561 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 562 | onPopulateAccessibilityEvent(event); |
| 563 | return true; |
| 564 | } |
| 565 | |
| 566 | @Override |
| 567 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 568 | event.getText().add(mCurrentDate.getTime().toString()); |
| 569 | } |
| 570 | |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 571 | public CharSequence getAccessibilityClassName() { |
| 572 | return DatePicker.class.getName(); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 575 | public static int getDaysInMonth(int month, int year) { |
| 576 | switch (month) { |
| 577 | case Calendar.JANUARY: |
| 578 | case Calendar.MARCH: |
| 579 | case Calendar.MAY: |
| 580 | case Calendar.JULY: |
| 581 | case Calendar.AUGUST: |
| 582 | case Calendar.OCTOBER: |
| 583 | case Calendar.DECEMBER: |
| 584 | return 31; |
| 585 | case Calendar.APRIL: |
| 586 | case Calendar.JUNE: |
| 587 | case Calendar.SEPTEMBER: |
| 588 | case Calendar.NOVEMBER: |
| 589 | return 30; |
| 590 | case Calendar.FEBRUARY: |
| 591 | return (year % 4 == 0) ? 29 : 28; |
| 592 | default: |
| 593 | throw new IllegalArgumentException("Invalid Month"); |
| 594 | } |
| 595 | } |
| 596 | |
Alan Viverette | 0ef59ac | 2015-03-23 13:13:25 -0700 | [diff] [blame] | 597 | private void tryVibrate() { |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 598 | mDelegator.performHapticFeedback(HapticFeedbackConstants.CALENDAR_DATE); |
| 599 | } |
| 600 | |
Alan Viverette | e763c9b | 2014-11-06 15:22:31 -0800 | [diff] [blame] | 601 | /** |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 602 | * Class for managing state storing/restoring. |
| 603 | */ |
| 604 | private static class SavedState extends View.BaseSavedState { |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 605 | private final int mSelectedYear; |
| 606 | private final int mSelectedMonth; |
| 607 | private final int mSelectedDay; |
| 608 | private final long mMinDate; |
| 609 | private final long mMaxDate; |
| 610 | private final int mCurrentView; |
| 611 | private final int mListPosition; |
| 612 | private final int mListPositionOffset; |
| 613 | |
| 614 | /** |
| 615 | * Constructor called from {@link DatePicker#onSaveInstanceState()} |
| 616 | */ |
| 617 | private SavedState(Parcelable superState, int year, int month, int day, |
| 618 | long minDate, long maxDate, int currentView, int listPosition, |
| 619 | int listPositionOffset) { |
| 620 | super(superState); |
| 621 | mSelectedYear = year; |
| 622 | mSelectedMonth = month; |
| 623 | mSelectedDay = day; |
| 624 | mMinDate = minDate; |
| 625 | mMaxDate = maxDate; |
| 626 | mCurrentView = currentView; |
| 627 | mListPosition = listPosition; |
| 628 | mListPositionOffset = listPositionOffset; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Constructor called from {@link #CREATOR} |
| 633 | */ |
| 634 | private SavedState(Parcel in) { |
| 635 | super(in); |
| 636 | mSelectedYear = in.readInt(); |
| 637 | mSelectedMonth = in.readInt(); |
| 638 | mSelectedDay = in.readInt(); |
| 639 | mMinDate = in.readLong(); |
| 640 | mMaxDate = in.readLong(); |
| 641 | mCurrentView = in.readInt(); |
| 642 | mListPosition = in.readInt(); |
| 643 | mListPositionOffset = in.readInt(); |
| 644 | } |
| 645 | |
| 646 | @Override |
| 647 | public void writeToParcel(Parcel dest, int flags) { |
| 648 | super.writeToParcel(dest, flags); |
| 649 | dest.writeInt(mSelectedYear); |
| 650 | dest.writeInt(mSelectedMonth); |
| 651 | dest.writeInt(mSelectedDay); |
| 652 | dest.writeLong(mMinDate); |
| 653 | dest.writeLong(mMaxDate); |
| 654 | dest.writeInt(mCurrentView); |
| 655 | dest.writeInt(mListPosition); |
| 656 | dest.writeInt(mListPositionOffset); |
| 657 | } |
| 658 | |
| 659 | public int getSelectedDay() { |
| 660 | return mSelectedDay; |
| 661 | } |
| 662 | |
| 663 | public int getSelectedMonth() { |
| 664 | return mSelectedMonth; |
| 665 | } |
| 666 | |
| 667 | public int getSelectedYear() { |
| 668 | return mSelectedYear; |
| 669 | } |
| 670 | |
| 671 | public long getMinDate() { |
| 672 | return mMinDate; |
| 673 | } |
| 674 | |
| 675 | public long getMaxDate() { |
| 676 | return mMaxDate; |
| 677 | } |
| 678 | |
| 679 | public int getCurrentView() { |
| 680 | return mCurrentView; |
| 681 | } |
| 682 | |
| 683 | public int getListPosition() { |
| 684 | return mListPosition; |
| 685 | } |
| 686 | |
| 687 | public int getListPositionOffset() { |
| 688 | return mListPositionOffset; |
| 689 | } |
| 690 | |
| 691 | @SuppressWarnings("all") |
| 692 | // suppress unused and hiding |
| 693 | public static final Parcelable.Creator<SavedState> CREATOR = new Creator<SavedState>() { |
| 694 | |
| 695 | public SavedState createFromParcel(Parcel in) { |
| 696 | return new SavedState(in); |
| 697 | } |
| 698 | |
| 699 | public SavedState[] newArray(int size) { |
| 700 | return new SavedState[size]; |
| 701 | } |
| 702 | }; |
| 703 | } |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 704 | } |