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

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

Issue 85643002: Transfer date/time value to chooser as double (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@doubledate2
Patch Set: Created 7 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.util.Calendar; 11 import java.util.Calendar;
12 import java.util.TimeZone;
12 13
13 // This class is heavily based on android.widget.DatePicker. 14 // This class is heavily based on android.widget.DatePicker.
14 public class WeekPicker extends TwoFieldDatePicker { 15 public class WeekPicker extends TwoFieldDatePicker {
15 16
16 public WeekPicker(Context context, long minValue, long maxValue) { 17 public WeekPicker(Context context, long minValue, long maxValue) {
17 super(context, minValue, maxValue); 18 super(context, minValue, maxValue);
18 19
19 getPositionInYearSpinner().setContentDescription( 20 getPositionInYearSpinner().setContentDescription(
20 getResources().getString(R.string.accessibility_date_picker_week )); 21 getResources().getString(R.string.accessibility_date_picker_week ));
21 22
22 // initialize to current date 23 // initialize to current date
23 Calendar cal = Calendar.getInstance(); 24 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
24 cal.setFirstDayOfWeek(Calendar.MONDAY); 25 cal.setFirstDayOfWeek(Calendar.MONDAY);
25 cal.setMinimalDaysInFirstWeek(4); 26 cal.setMinimalDaysInFirstWeek(4);
26 cal.setTimeInMillis(System.currentTimeMillis()); 27 cal.setTimeInMillis(System.currentTimeMillis());
27 init(getISOWeekYearForDate(cal), getWeekForDate(cal), null); 28 init(getISOWeekYearForDate(cal), getWeekForDate(cal), null);
28 } 29 }
29 30
30 private Calendar createDateFromWeek(int year, int week) { 31 private Calendar createDateFromWeek(int year, int week) {
31 Calendar date = Calendar.getInstance(); 32 Calendar date = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
32 date.clear(); 33 date.clear();
33 date.setFirstDayOfWeek(Calendar.MONDAY); 34 date.setFirstDayOfWeek(Calendar.MONDAY);
34 date.setMinimalDaysInFirstWeek(4); 35 date.setMinimalDaysInFirstWeek(4);
35 date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); 36 date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
36 date.set(Calendar.YEAR, year); 37 date.set(Calendar.YEAR, year);
37 date.set(Calendar.WEEK_OF_YEAR, week); 38 date.set(Calendar.WEEK_OF_YEAR, week);
38 return date; 39 return date;
39 } 40 }
40 41
41 @Override 42 @Override
42 protected Calendar createDateFromValue(long value) { 43 protected Calendar createDateFromValue(long value) {
43 Calendar date = Calendar.getInstance(); 44 Calendar date = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
44 date.clear(); 45 date.clear();
45 date.setFirstDayOfWeek(Calendar.MONDAY); 46 date.setFirstDayOfWeek(Calendar.MONDAY);
46 date.setMinimalDaysInFirstWeek(4); 47 date.setMinimalDaysInFirstWeek(4);
47 date.setTimeInMillis(value); 48 date.setTimeInMillis(value);
48 return date; 49 return date;
49 } 50 }
50 51
52 @Override
53 protected long valueFromDate(int year, int week) {
Miguel Garcia 2013/11/26 16:07:08 another double vs long here
keishi 2013/11/27 06:58:38 Done.
54 return createDateFromWeek(year, week).getTimeInMillis();
55 }
56
51 public static int getISOWeekYearForDate(Calendar date) { 57 public static int getISOWeekYearForDate(Calendar date) {
52 int year = date.get(Calendar.YEAR); 58 int year = date.get(Calendar.YEAR);
53 int month = date.get(Calendar.MONTH); 59 int month = date.get(Calendar.MONTH);
54 int week = date.get(Calendar.WEEK_OF_YEAR); 60 int week = date.get(Calendar.WEEK_OF_YEAR);
55 if (month == 0 && week > 51) { 61 if (month == 0 && week > 51) {
56 year--; 62 year--;
57 } else if (month == 11 && week == 1) { 63 } else if (month == 11 && week == 1) {
58 year++; 64 year++;
59 } 65 }
60 return year; 66 return year;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 127 }
122 128
123 @Override 129 @Override
124 protected int getMinPositionInYear(int year) { 130 protected int getMinPositionInYear(int year) {
125 if (year == getISOWeekYearForDate(getMinDate())) { 131 if (year == getISOWeekYearForDate(getMinDate())) {
126 return getWeekForDate(getMinDate()); 132 return getWeekForDate(getMinDate());
127 } 133 }
128 return 1; 134 return 1;
129 } 135 }
130 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698