The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Alan Viverette | 518ff0d | 2014-08-15 14:20:35 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.annotation.Widget; |
| 22 | import android.content.Context; |
Svetoslav Ganov | f592696 | 2011-07-12 12:26:20 -0700 | [diff] [blame] | 23 | import android.content.res.Configuration; |
Svetoslav Ganov | 4243dc3 | 2011-01-18 19:39:57 -0800 | [diff] [blame] | 24 | import android.content.res.TypedArray; |
Alan Viverette | 6b3f85f | 2016-03-01 16:48:04 -0500 | [diff] [blame] | 25 | import android.os.Parcel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.os.Parcelable; |
Alan Viverette | 6b3f85f | 2016-03-01 16:48:04 -0500 | [diff] [blame] | 27 | import android.os.Parcelable.Creator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.util.AttributeSet; |
Alan Viverette | 6b3f85f | 2016-03-01 16:48:04 -0500 | [diff] [blame] | 29 | import android.view.View; |
Svetoslav Ganov | 8a2a895 | 2011-01-27 17:40:13 -0800 | [diff] [blame] | 30 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav Ganov | a53efe9 | 2011-09-08 18:08:36 -0700 | [diff] [blame] | 31 | import com.android.internal.R; |
| 32 | |
Svetoslav Ganov | f592696 | 2011-07-12 12:26:20 -0700 | [diff] [blame] | 33 | import java.util.Locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Alan Viverette | b3f2463 | 2015-10-22 16:01:48 -0400 | [diff] [blame] | 35 | import libcore.icu.LocaleData; |
| 36 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | /** |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 38 | * A widget for selecting the time of day, in either 24-hour or AM/PM mode. |
Alan Viverette | 5134478 | 2014-07-16 17:39:27 -0700 | [diff] [blame] | 39 | * <p> |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 40 | * For a dialog using this view, see {@link android.app.TimePickerDialog}. See |
| 41 | * the <a href="{@docRoot}guide/topics/ui/controls/pickers.html">Pickers</a> |
| 42 | * guide for more information. |
| 43 | * |
| 44 | * @attr ref android.R.styleable#TimePicker_timePickerMode |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | */ |
| 46 | @Widget |
| 47 | public class TimePicker extends FrameLayout { |
Chet Haase | 3053b2f | 2014-08-06 07:51:50 -0700 | [diff] [blame] | 48 | private static final int MODE_SPINNER = 1; |
| 49 | private static final int MODE_CLOCK = 2; |
| 50 | |
Alan Viverette | 5134478 | 2014-07-16 17:39:27 -0700 | [diff] [blame] | 51 | private final TimePickerDelegate mDelegate; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 52 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | /** |
| 54 | * The callback interface used to indicate the time has been adjusted. |
| 55 | */ |
| 56 | public interface OnTimeChangedListener { |
| 57 | |
| 58 | /** |
| 59 | * @param view The view associated with this listener. |
| 60 | * @param hourOfDay The current hour. |
| 61 | * @param minute The current minute. |
| 62 | */ |
| 63 | void onTimeChanged(TimePicker view, int hourOfDay, int minute); |
| 64 | } |
| 65 | |
| 66 | public TimePicker(Context context) { |
| 67 | this(context, null); |
| 68 | } |
Svetoslav Ganov | 4243dc3 | 2011-01-18 19:39:57 -0800 | [diff] [blame] | 69 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | public TimePicker(Context context, AttributeSet attrs) { |
Svetoslav Ganov | 4243dc3 | 2011-01-18 19:39:57 -0800 | [diff] [blame] | 71 | this(context, attrs, R.attr.timePickerStyle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 74 | public TimePicker(Context context, AttributeSet attrs, int defStyleAttr) { |
| 75 | this(context, attrs, defStyleAttr, 0); |
| 76 | } |
| 77 | |
| 78 | public TimePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 79 | super(context, attrs, defStyleAttr, defStyleRes); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 80 | |
Alan Viverette | 5134478 | 2014-07-16 17:39:27 -0700 | [diff] [blame] | 81 | final TypedArray a = context.obtainStyledAttributes( |
| 82 | attrs, R.styleable.TimePicker, defStyleAttr, defStyleRes); |
Alan Viverette | 518ff0d | 2014-08-15 14:20:35 -0700 | [diff] [blame] | 83 | final int mode = a.getInt(R.styleable.TimePicker_timePickerMode, MODE_SPINNER); |
Fabrice Di Meglio | dfaa6c7 | 2014-07-10 19:33:33 -0700 | [diff] [blame] | 84 | a.recycle(); |
| 85 | |
Chet Haase | 3053b2f | 2014-08-06 07:51:50 -0700 | [diff] [blame] | 86 | switch (mode) { |
| 87 | case MODE_CLOCK: |
Alan Viverette | daf33ed | 2014-10-23 13:34:17 -0700 | [diff] [blame] | 88 | mDelegate = new TimePickerClockDelegate( |
Chet Haase | 3053b2f | 2014-08-06 07:51:50 -0700 | [diff] [blame] | 89 | this, context, attrs, defStyleAttr, defStyleRes); |
| 90 | break; |
| 91 | case MODE_SPINNER: |
| 92 | default: |
Alan Viverette | daf33ed | 2014-10-23 13:34:17 -0700 | [diff] [blame] | 93 | mDelegate = new TimePickerSpinnerDelegate( |
Chet Haase | 3053b2f | 2014-08-06 07:51:50 -0700 | [diff] [blame] | 94 | this, context, attrs, defStyleAttr, defStyleRes); |
| 95 | break; |
Fabrice Di Meglio | dfaa6c7 | 2014-07-10 19:33:33 -0700 | [diff] [blame] | 96 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | } |
Svetoslav Ganov | 50f34d1 | 2010-12-03 16:05:40 -0800 | [diff] [blame] | 98 | |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 99 | /** |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 100 | * Sets the currently selected hour using 24-hour time. |
| 101 | * |
| 102 | * @param hour the hour to set, in the range (0-23) |
| 103 | * @see #getHour() |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 104 | */ |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 105 | public void setHour(int hour) { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 106 | mDelegate.setHour(hour); |
Fabrice Di Meglio | 64902bd | 2013-08-15 17:49:49 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 109 | /** |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 110 | * Returns the currently selected hour using 24-hour time. |
| 111 | * |
| 112 | * @return the currently selected hour, in the range (0-23) |
| 113 | * @see #setHour(int) |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 114 | */ |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 115 | public int getHour() { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 116 | return mDelegate.getHour(); |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Sets the currently selected minute.. |
| 121 | * |
| 122 | * @param minute the minute to set, in the range (0-59) |
| 123 | * @see #getMinute() |
| 124 | */ |
| 125 | public void setMinute(int minute) { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 126 | mDelegate.setMinute(minute); |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Returns the currently selected minute. |
| 131 | * |
| 132 | * @return the currently selected minute, in the range (0-59) |
| 133 | * @see #setMinute(int) |
| 134 | */ |
| 135 | public int getMinute() { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 136 | return mDelegate.getMinute(); |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Sets the current hour. |
| 141 | * |
| 142 | * @deprecated Use {@link #setHour(int)} |
| 143 | */ |
| 144 | @Deprecated |
| 145 | public void setCurrentHour(@NonNull Integer currentHour) { |
| 146 | setHour(currentHour); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * @return the current hour in the range (0-23) |
| 151 | * @deprecated Use {@link #getHour()} |
| 152 | */ |
| 153 | @NonNull |
| 154 | @Deprecated |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 155 | public Integer getCurrentHour() { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 156 | return mDelegate.getHour(); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 157 | } |
Fabrice Di Meglio | 64902bd | 2013-08-15 17:49:49 -0700 | [diff] [blame] | 158 | |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Set the current minute (0-59). |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 161 | * |
| 162 | * @deprecated Use {@link #setMinute(int)} |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 163 | */ |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 164 | @Deprecated |
| 165 | public void setCurrentMinute(@NonNull Integer currentMinute) { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 166 | mDelegate.setMinute(currentMinute); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /** |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 170 | * @return the current minute |
| 171 | * @deprecated Use {@link #getMinute()} |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 172 | */ |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 173 | @NonNull |
| 174 | @Deprecated |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 175 | public Integer getCurrentMinute() { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 176 | return mDelegate.getMinute(); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /** |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 180 | * Sets whether this widget displays time in 24-hour mode or 12-hour mode |
| 181 | * with an AM/PM picker. |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 182 | * |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 183 | * @param is24HourView {@code true} to display in 24-hour mode, |
| 184 | * {@code false} for 12-hour mode with AM/PM |
| 185 | * @see #is24HourView() |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 186 | */ |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 187 | public void setIs24HourView(@NonNull Boolean is24HourView) { |
| 188 | if (is24HourView == null) { |
| 189 | return; |
| 190 | } |
| 191 | |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 192 | mDelegate.setIs24Hour(is24HourView); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
Alan Viverette | 646a0f8 | 2015-03-18 13:24:07 -0700 | [diff] [blame] | 196 | * @return {@code true} if this widget displays time in 24-hour mode, |
| 197 | * {@code false} otherwise} |
| 198 | * @see #setIs24HourView(Boolean) |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 199 | */ |
| 200 | public boolean is24HourView() { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 201 | return mDelegate.is24Hour(); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Set the callback that indicates the time has been adjusted by the user. |
| 206 | * |
| 207 | * @param onTimeChangedListener the callback, should not be null. |
| 208 | */ |
| 209 | public void setOnTimeChangedListener(OnTimeChangedListener onTimeChangedListener) { |
| 210 | mDelegate.setOnTimeChangedListener(onTimeChangedListener); |
Fabrice Di Meglio | 64902bd | 2013-08-15 17:49:49 -0700 | [diff] [blame] | 211 | } |
| 212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | @Override |
| 214 | public void setEnabled(boolean enabled) { |
| 215 | super.setEnabled(enabled); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 216 | mDelegate.setEnabled(enabled); |
Svetoslav Ganov | 51c52ed | 2010-12-28 13:45:03 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public boolean isEnabled() { |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 221 | return mDelegate.isEnabled(); |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public int getBaseline() { |
| 226 | return mDelegate.getBaseline(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Svetoslav Ganov | f592696 | 2011-07-12 12:26:20 -0700 | [diff] [blame] | 229 | @Override |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 230 | protected Parcelable onSaveInstanceState() { |
| 231 | Parcelable superState = super.onSaveInstanceState(); |
| 232 | return mDelegate.onSaveInstanceState(superState); |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | protected void onRestoreInstanceState(Parcelable state) { |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 237 | BaseSavedState ss = (BaseSavedState) state; |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 238 | super.onRestoreInstanceState(ss.getSuperState()); |
| 239 | mDelegate.onRestoreInstanceState(ss); |
| 240 | } |
| 241 | |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 242 | @Override |
| 243 | public CharSequence getAccessibilityClassName() { |
| 244 | return TimePicker.class.getName(); |
| 245 | } |
| 246 | |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 247 | /** @hide */ |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 248 | @Override |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 249 | public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 250 | return mDelegate.dispatchPopulateAccessibilityEvent(event); |
| 251 | } |
| 252 | |
Svetoslav Ganov | f592696 | 2011-07-12 12:26:20 -0700 | [diff] [blame] | 253 | /** |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 254 | * A delegate interface that defined the public API of the TimePicker. Allows different |
| 255 | * TimePicker implementations. This would need to be implemented by the TimePicker delegates |
| 256 | * for the real behavior. |
Svetoslav Ganov | f592696 | 2011-07-12 12:26:20 -0700 | [diff] [blame] | 257 | */ |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 258 | interface TimePickerDelegate { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 259 | void setHour(int hour); |
| 260 | int getHour(); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 261 | |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 262 | void setMinute(int minute); |
| 263 | int getMinute(); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 264 | |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 265 | void setIs24Hour(boolean is24Hour); |
| 266 | boolean is24Hour(); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 267 | |
| 268 | void setOnTimeChangedListener(OnTimeChangedListener onTimeChangedListener); |
| 269 | |
| 270 | void setEnabled(boolean enabled); |
| 271 | boolean isEnabled(); |
| 272 | |
| 273 | int getBaseline(); |
| 274 | |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 275 | Parcelable onSaveInstanceState(Parcelable superState); |
| 276 | void onRestoreInstanceState(Parcelable state); |
| 277 | |
| 278 | boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event); |
| 279 | void onPopulateAccessibilityEvent(AccessibilityEvent event); |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Alan Viverette | b3f2463 | 2015-10-22 16:01:48 -0400 | [diff] [blame] | 282 | static String[] getAmPmStrings(Context context) { |
| 283 | final Locale locale = context.getResources().getConfiguration().locale; |
| 284 | final LocaleData d = LocaleData.get(locale); |
| 285 | |
| 286 | final String[] result = new String[2]; |
| 287 | result[0] = d.amPm[0].length() > 4 ? d.narrowAm : d.amPm[0]; |
| 288 | result[1] = d.amPm[1].length() > 4 ? d.narrowPm : d.amPm[1]; |
| 289 | return result; |
| 290 | } |
| 291 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 292 | /** |
| 293 | * An abstract class which can be used as a start for TimePicker implementations |
| 294 | */ |
| 295 | abstract static class AbstractTimePickerDelegate implements TimePickerDelegate { |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 296 | protected final TimePicker mDelegator; |
| 297 | protected final Context mContext; |
| 298 | protected final Locale mLocale; |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 299 | |
Alan Viverette | 518ff0d | 2014-08-15 14:20:35 -0700 | [diff] [blame] | 300 | protected OnTimeChangedListener mOnTimeChangedListener; |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 301 | |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 302 | public AbstractTimePickerDelegate(@NonNull TimePicker delegator, @NonNull Context context) { |
Fabrice Di Meglio | 9e4009e | 2013-08-19 13:16:46 -0700 | [diff] [blame] | 303 | mDelegator = delegator; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 304 | mContext = context; |
Alan Viverette | 4420ae8 | 2015-11-16 16:10:56 -0500 | [diff] [blame] | 305 | mLocale = context.getResources().getConfiguration().locale; |
Alan Viverette | 518ff0d | 2014-08-15 14:20:35 -0700 | [diff] [blame] | 306 | } |
Alan Viverette | 6b3f85f | 2016-03-01 16:48:04 -0500 | [diff] [blame] | 307 | |
| 308 | protected static class SavedState extends View.BaseSavedState { |
| 309 | private final int mHour; |
| 310 | private final int mMinute; |
| 311 | private final boolean mIs24HourMode; |
| 312 | private final int mCurrentItemShowing; |
| 313 | |
| 314 | public SavedState(Parcelable superState, int hour, int minute, boolean is24HourMode) { |
| 315 | this(superState, hour, minute, is24HourMode, 0); |
| 316 | } |
| 317 | |
| 318 | public SavedState(Parcelable superState, int hour, int minute, boolean is24HourMode, |
| 319 | int currentItemShowing) { |
| 320 | super(superState); |
| 321 | mHour = hour; |
| 322 | mMinute = minute; |
| 323 | mIs24HourMode = is24HourMode; |
| 324 | mCurrentItemShowing = currentItemShowing; |
| 325 | } |
| 326 | |
| 327 | private SavedState(Parcel in) { |
| 328 | super(in); |
| 329 | mHour = in.readInt(); |
| 330 | mMinute = in.readInt(); |
| 331 | mIs24HourMode = (in.readInt() == 1); |
| 332 | mCurrentItemShowing = in.readInt(); |
| 333 | } |
| 334 | |
| 335 | public int getHour() { |
| 336 | return mHour; |
| 337 | } |
| 338 | |
| 339 | public int getMinute() { |
| 340 | return mMinute; |
| 341 | } |
| 342 | |
| 343 | public boolean is24HourMode() { |
| 344 | return mIs24HourMode; |
| 345 | } |
| 346 | |
| 347 | public int getCurrentItemShowing() { |
| 348 | return mCurrentItemShowing; |
| 349 | } |
| 350 | |
| 351 | @Override |
| 352 | public void writeToParcel(Parcel dest, int flags) { |
| 353 | super.writeToParcel(dest, flags); |
| 354 | dest.writeInt(mHour); |
| 355 | dest.writeInt(mMinute); |
| 356 | dest.writeInt(mIs24HourMode ? 1 : 0); |
| 357 | dest.writeInt(mCurrentItemShowing); |
| 358 | } |
| 359 | |
| 360 | @SuppressWarnings({"unused", "hiding"}) |
| 361 | public static final Creator<SavedState> CREATOR = new Creator<SavedState>() { |
| 362 | public SavedState createFromParcel(Parcel in) { |
| 363 | return new SavedState(in); |
| 364 | } |
| 365 | |
| 366 | public SavedState[] newArray(int size) { |
| 367 | return new SavedState[size]; |
| 368 | } |
| 369 | }; |
| 370 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | } |