OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
9 import android.os.Parcel; | 9 import android.os.Parcel; |
10 import android.os.Parcelable; | 10 import android.os.Parcelable; |
11 import android.text.format.DateUtils; | 11 import android.text.format.DateUtils; |
12 import android.util.AttributeSet; | 12 import android.util.AttributeSet; |
13 import android.util.SparseArray; | 13 import android.util.SparseArray; |
14 import android.view.LayoutInflater; | 14 import android.view.LayoutInflater; |
15 import android.view.accessibility.AccessibilityEvent; | 15 import android.view.accessibility.AccessibilityEvent; |
16 import android.widget.DatePicker; | 16 import android.widget.DatePicker; |
17 import android.widget.FrameLayout; | 17 import android.widget.FrameLayout; |
18 import android.widget.LinearLayout; | 18 import android.widget.LinearLayout; |
19 import android.widget.NumberPicker; | 19 import android.widget.NumberPicker; |
20 import android.widget.NumberPicker.OnValueChangeListener; | 20 import android.widget.NumberPicker.OnValueChangeListener; |
21 | 21 |
22 import java.util.Arrays; | 22 import java.util.Arrays; |
23 import java.util.Calendar; | 23 import java.util.Calendar; |
24 import java.util.Locale; | 24 import java.util.Locale; |
25 import java.util.TimeZone; | 25 import java.util.TimeZone; |
26 | 26 |
27 import org.chromium.content.app.AppResource; | 27 import org.chromium.content.R; |
28 | 28 |
29 // This class is heavily based on android.widget.DatePicker. | 29 // This class is heavily based on android.widget.DatePicker. |
30 public class MonthPicker extends FrameLayout { | 30 public class MonthPicker extends FrameLayout { |
31 | 31 |
32 private static final int DEFAULT_START_YEAR = 1900; | 32 private static final int DEFAULT_START_YEAR = 1900; |
33 | 33 |
34 private static final int DEFAULT_END_YEAR = 2100; | 34 private static final int DEFAULT_END_YEAR = 2100; |
35 | 35 |
36 private static final boolean DEFAULT_ENABLED_STATE = true; | 36 private static final boolean DEFAULT_ENABLED_STATE = true; |
37 | 37 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 super(context, attrs, defStyle); | 87 super(context, attrs, defStyle); |
88 | 88 |
89 // initialization based on locale | 89 // initialization based on locale |
90 setCurrentLocale(Locale.getDefault()); | 90 setCurrentLocale(Locale.getDefault()); |
91 | 91 |
92 int startYear = DEFAULT_START_YEAR; | 92 int startYear = DEFAULT_START_YEAR; |
93 int endYear = DEFAULT_END_YEAR; | 93 int endYear = DEFAULT_END_YEAR; |
94 | 94 |
95 LayoutInflater inflater = (LayoutInflater) context | 95 LayoutInflater inflater = (LayoutInflater) context |
96 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); | 96 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
97 assert AppResource.LAYOUT_MONTH_PICKER != 0; | 97 inflater.inflate(R.layout.month_picker, this, true); |
98 inflater.inflate(AppResource.LAYOUT_MONTH_PICKER, this, true); | |
99 | 98 |
100 OnValueChangeListener onChangeListener = new OnValueChangeListener() { | 99 OnValueChangeListener onChangeListener = new OnValueChangeListener() { |
101 public void onValueChange(NumberPicker picker, int oldVal, int newVa
l) { | 100 public void onValueChange(NumberPicker picker, int oldVal, int newVa
l) { |
102 mTempDate.setTimeInMillis(mCurrentDate.getTimeInMillis()); | 101 mTempDate.setTimeInMillis(mCurrentDate.getTimeInMillis()); |
103 // take care of wrapping of days and months to update greater fi
elds | 102 // take care of wrapping of days and months to update greater fi
elds |
104 if (picker == mMonthSpinner) { | 103 if (picker == mMonthSpinner) { |
105 if (oldVal == 11 && newVal == 0) { | 104 if (oldVal == 11 && newVal == 0) { |
106 mTempDate.add(Calendar.MONTH, 1); | 105 mTempDate.add(Calendar.MONTH, 1); |
107 } else if (oldVal == 0 && newVal == 11) { | 106 } else if (oldVal == 0 && newVal == 11) { |
108 mTempDate.add(Calendar.MONTH, -1); | 107 mTempDate.add(Calendar.MONTH, -1); |
109 } else { | 108 } else { |
110 mTempDate.add(Calendar.MONTH, newVal - oldVal); | 109 mTempDate.add(Calendar.MONTH, newVal - oldVal); |
111 } | 110 } |
112 } else if (picker == mYearSpinner) { | 111 } else if (picker == mYearSpinner) { |
113 mTempDate.set(Calendar.YEAR, newVal); | 112 mTempDate.set(Calendar.YEAR, newVal); |
114 } else { | 113 } else { |
115 throw new IllegalArgumentException(); | 114 throw new IllegalArgumentException(); |
116 } | 115 } |
117 // now set the date to the adjusted one | 116 // now set the date to the adjusted one |
118 setDate(mTempDate.get(Calendar.YEAR), mTempDate.get(Calendar.MON
TH)); | 117 setDate(mTempDate.get(Calendar.YEAR), mTempDate.get(Calendar.MON
TH)); |
119 updateSpinners(); | 118 updateSpinners(); |
120 notifyDateChanged(); | 119 notifyDateChanged(); |
121 } | 120 } |
122 }; | 121 }; |
123 | 122 |
124 assert AppResource.ID_MONTH_YEAR_PICKERS_CONTAINER != 0; | 123 mSpinners = (LinearLayout) findViewById(R.id.pickers); |
125 mSpinners = (LinearLayout) findViewById(AppResource.ID_MONTH_YEAR_PICKER
S_CONTAINER); | |
126 | 124 |
127 // month | 125 // month |
128 assert AppResource.ID_MONTH_PICKER != 0; | 126 mMonthSpinner = (NumberPicker) findViewById(R.id.month); |
129 mMonthSpinner = (NumberPicker) findViewById(AppResource.ID_MONTH_PICKER)
; | |
130 mMonthSpinner.setMinValue(0); | 127 mMonthSpinner.setMinValue(0); |
131 mMonthSpinner.setMaxValue(mNumberOfMonths - 1); | 128 mMonthSpinner.setMaxValue(mNumberOfMonths - 1); |
132 mMonthSpinner.setDisplayedValues(mShortMonths); | 129 mMonthSpinner.setDisplayedValues(mShortMonths); |
133 mMonthSpinner.setOnLongPressUpdateInterval(200); | 130 mMonthSpinner.setOnLongPressUpdateInterval(200); |
134 mMonthSpinner.setOnValueChangedListener(onChangeListener); | 131 mMonthSpinner.setOnValueChangedListener(onChangeListener); |
135 | 132 |
136 // year | 133 // year |
137 assert AppResource.ID_YEAR_PICKER != 0; | 134 mYearSpinner = (NumberPicker) findViewById(R.id.year); |
138 mYearSpinner = (NumberPicker) findViewById(AppResource.ID_YEAR_PICKER); | |
139 mYearSpinner.setOnLongPressUpdateInterval(100); | 135 mYearSpinner.setOnLongPressUpdateInterval(100); |
140 mYearSpinner.setOnValueChangedListener(onChangeListener); | 136 mYearSpinner.setOnValueChangedListener(onChangeListener); |
141 | 137 |
142 mTempDate.clear(); | 138 mTempDate.clear(); |
143 mTempDate.set(startYear, 0, 1); | 139 mTempDate.set(startYear, 0, 1); |
144 | 140 |
145 setMinDate(mTempDate.getTimeInMillis()); | 141 setMinDate(mTempDate.getTimeInMillis()); |
146 | 142 |
147 mTempDate.clear(); | 143 mTempDate.clear(); |
148 mTempDate.set(endYear, 11, 31); | 144 mTempDate.set(endYear, 11, 31); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 public SavedState createFromParcel(Parcel in) { | 468 public SavedState createFromParcel(Parcel in) { |
473 return new SavedState(in); | 469 return new SavedState(in); |
474 } | 470 } |
475 | 471 |
476 public SavedState[] newArray(int size) { | 472 public SavedState[] newArray(int size) { |
477 return new SavedState[size]; | 473 return new SavedState[size]; |
478 } | 474 } |
479 }; | 475 }; |
480 } | 476 } |
481 } | 477 } |
OLD | NEW |