Chromium Code Reviews| 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, long minValue, long 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 @Override |
| 37 protected Calendar createDateFromValue(long value) { | 38 protected Calendar createDateFromValue(long value) { |
| 38 int year = (int) Math.min(value / 12 + 1970, Integer.MAX_VALUE); | 39 int year = (int) Math.min(value / 12 + 1970, Integer.MAX_VALUE); |
| 39 int month = (int) (value % 12); | 40 int month = (int) (value % 12); |
| 40 Calendar cal = Calendar.getInstance(); | 41 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
| 41 cal.clear(); | 42 cal.clear(); |
| 42 cal.set(year, month, 1); | 43 cal.set(year, month, 1); |
| 43 return cal; | 44 return cal; |
| 44 } | 45 } |
| 45 | 46 |
| 46 @Override | 47 @Override |
| 48 protected long valueFromDate(int year, int month) { | |
|
Miguel Garcia
2013/11/26 16:07:08
shouldn't this return a double? That's what you ar
keishi
2013/11/27 06:58:38
Done. Changed to double.
| |
| 49 return (year - 1970) * 12 + month; | |
| 50 } | |
| 51 | |
| 52 @Override | |
| 47 protected void setCurrentDate(int year, int month) { | 53 protected void setCurrentDate(int year, int month) { |
| 48 Calendar date = Calendar.getInstance(); | 54 Calendar date = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
| 49 date.set(year, month, 1); | 55 date.set(year, month, 1); |
| 50 if (date.before(getMinDate())) { | 56 if (date.before(getMinDate())) { |
| 51 setCurrentDate(getMinDate()); | 57 setCurrentDate(getMinDate()); |
| 52 } else if (date.after(getMaxDate())) { | 58 } else if (date.after(getMaxDate())) { |
| 53 setCurrentDate(getMaxDate()); | 59 setCurrentDate(getMaxDate()); |
| 54 } else { | 60 } else { |
| 55 setCurrentDate(date); | 61 setCurrentDate(date); |
| 56 } | 62 } |
| 57 } | 63 } |
| 58 | 64 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 } | 106 } |
| 101 | 107 |
| 102 @Override | 108 @Override |
| 103 protected int getMinPositionInYear(int year) { | 109 protected int getMinPositionInYear(int year) { |
| 104 if (year == getMinDate().get(Calendar.YEAR)) { | 110 if (year == getMinDate().get(Calendar.YEAR)) { |
| 105 return getMinDate().get(Calendar.MONTH); | 111 return getMinDate().get(Calendar.MONTH); |
| 106 } | 112 } |
| 107 return 0; | 113 return 0; |
| 108 } | 114 } |
| 109 } | 115 } |
| OLD | NEW |