| 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.input; | 5 package org.chromium.content.browser.input; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 | 8 |
| 9 import org.chromium.content.R; | 9 import org.chromium.content.R; |
| 10 | 10 |
| 11 import java.text.DateFormatSymbols; | 11 import java.text.DateFormatSymbols; |
| 12 import java.util.Arrays; | 12 import java.util.Arrays; |
| 13 import java.util.Calendar; | 13 import java.util.Calendar; |
| 14 import java.util.Locale; | 14 import java.util.Locale; |
| 15 import java.util.TimeZone; |
| 15 | 16 |
| 16 public class MonthPicker extends TwoFieldDatePicker { | 17 public class MonthPicker extends TwoFieldDatePicker { |
| 17 private static final int MONTHS_NUMBER = 12; | 18 private static final int MONTHS_NUMBER = 12; |
| 18 | 19 |
| 19 private final String[] mShortMonths; | 20 private final String[] mShortMonths; |
| 20 | 21 |
| 21 public MonthPicker(Context context, long minValue, long maxValue) { | 22 public MonthPicker(Context context, double minValue, double maxValue) { |
| 22 super(context, minValue, maxValue); | 23 super(context, minValue, maxValue); |
| 23 | 24 |
| 24 getPositionInYearSpinner().setContentDescription( | 25 getPositionInYearSpinner().setContentDescription( |
| 25 getResources().getString(R.string.accessibility_date_picker_mont
h)); | 26 getResources().getString(R.string.accessibility_date_picker_mont
h)); |
| 26 | 27 |
| 27 // initialization based on locale | 28 // initialization based on locale |
| 28 mShortMonths = | 29 mShortMonths = |
| 29 DateFormatSymbols.getInstance(Locale.getDefault()).getShortMonth
s(); | 30 DateFormatSymbols.getInstance(Locale.getDefault()).getShortMonth
s(); |
| 30 | 31 |
| 31 // initialize to current date | 32 // initialize to current date |
| 32 Calendar cal = Calendar.getInstance(); | 33 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
| 33 init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), null); | 34 init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), null); |
| 34 } | 35 } |
| 35 | 36 |
| 36 @Override | 37 /** |
| 37 protected Calendar createDateFromValue(long value) { | 38 * Creates a date object from the |value| which is months since epoch. |
| 39 */ |
| 40 public static Calendar createDateFromValue(double value) { |
| 38 int year = (int) Math.min(value / 12 + 1970, Integer.MAX_VALUE); | 41 int year = (int) Math.min(value / 12 + 1970, Integer.MAX_VALUE); |
| 39 int month = (int) (value % 12); | 42 int month = (int) (value % 12); |
| 40 Calendar cal = Calendar.getInstance(); | 43 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
| 41 cal.clear(); | 44 cal.clear(); |
| 42 cal.set(year, month, 1); | 45 cal.set(year, month, 1); |
| 43 return cal; | 46 return cal; |
| 44 } | 47 } |
| 45 | 48 |
| 46 @Override | 49 @Override |
| 50 protected Calendar getDateForValue(double value) { |
| 51 return MonthPicker.createDateFromValue(value); |
| 52 } |
| 53 |
| 54 @Override |
| 47 protected void setCurrentDate(int year, int month) { | 55 protected void setCurrentDate(int year, int month) { |
| 48 Calendar date = Calendar.getInstance(); | 56 Calendar date = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
| 49 date.set(year, month, 1); | 57 date.set(year, month, 1); |
| 50 if (date.before(getMinDate())) { | 58 if (date.before(getMinDate())) { |
| 51 setCurrentDate(getMinDate()); | 59 setCurrentDate(getMinDate()); |
| 52 } else if (date.after(getMaxDate())) { | 60 } else if (date.after(getMaxDate())) { |
| 53 setCurrentDate(getMaxDate()); | 61 setCurrentDate(getMaxDate()); |
| 54 } else { | 62 } else { |
| 55 setCurrentDate(date); | 63 setCurrentDate(date); |
| 56 } | 64 } |
| 57 } | 65 } |
| 58 | 66 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 108 } |
| 101 | 109 |
| 102 @Override | 110 @Override |
| 103 protected int getMinPositionInYear(int year) { | 111 protected int getMinPositionInYear(int year) { |
| 104 if (year == getMinDate().get(Calendar.YEAR)) { | 112 if (year == getMinDate().get(Calendar.YEAR)) { |
| 105 return getMinDate().get(Calendar.MONTH); | 113 return getMinDate().get(Calendar.MONTH); |
| 106 } | 114 } |
| 107 return 0; | 115 return 0; |
| 108 } | 116 } |
| 109 } | 117 } |
| OLD | NEW |