Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/input/MonthPicker.java

Issue 23623019: Support datalist for date/time input types on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Used double to transfer value Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 java.text.DateFormatSymbols; 9 import java.text.DateFormatSymbols;
10 import java.util.Arrays; 10 import java.util.Arrays;
11 import java.util.Calendar; 11 import java.util.Calendar;
12 import java.util.Locale; 12 import java.util.Locale;
13 import java.util.TimeZone;
13 14
14 import org.chromium.content.R; 15 import org.chromium.content.R;
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 String[] mShortMonths; 20 private 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) {
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698