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

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

Issue 15057004: Week picker for android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed WebRuntimeFeatures::enableInputTypeWeek Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/input/MonthPicker.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/MonthPicker.java b/content/public/android/java/src/org/chromium/content/browser/input/MonthPicker.java
index b668c3fc71e6eb6c7aa266273dac11cce61eae98..2752f5dd98deb4a870043578eb8b99ac9df4877c 100644
--- a/content/public/android/java/src/org/chromium/content/browser/input/MonthPicker.java
+++ b/content/public/android/java/src/org/chromium/content/browser/input/MonthPicker.java
@@ -5,11 +5,7 @@
package org.chromium.content.browser.input;
import android.content.Context;
-import android.content.res.Configuration;
-import android.text.format.DateUtils;
import android.view.LayoutInflater;
-import android.view.accessibility.AccessibilityEvent;
-import android.widget.FrameLayout;
import android.widget.NumberPicker;
import android.widget.NumberPicker.OnValueChangeListener;
@@ -17,20 +13,12 @@ import java.text.DateFormatSymbols;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Locale;
-import java.util.TimeZone;
import org.chromium.content.R;
-public class MonthPicker extends FrameLayout {
+public class MonthPicker extends TwoFieldDatePicker {
private static final int MONTHS_NUMBER = 12;
- private final NumberPicker mMonthSpinner;
-
- private final NumberPicker mYearSpinner;
-
-
- private OnMonthChangedListener mMonthChangedListener;
-
private String[] mShortMonths;
// It'd be nice to use android.text.Time like in other Dialogs but
@@ -40,26 +28,8 @@ public class MonthPicker extends FrameLayout {
private Calendar mMaxDate;
- private Calendar mCurrentDate;
-
- /**
- * The callback used to indicate the user changes\d the date.
- */
- public interface OnMonthChangedListener {
-
- /**
- * Called upon a date change.
- *
- * @param view The view associated with this listener.
- * @param year The year that was set.
- * @param month The month that was set (0-11) for compatibility
- * with {@link java.util.Calendar}.
- */
- void onMonthChanged(MonthPicker view, int year, int month);
- }
-
public MonthPicker(Context context, long minMonth, long maxMonth) {
- super(context, null, android.R.attr.datePickerStyle);
+ super(context);
// initialization based on locale
mShortMonths =
@@ -76,7 +46,7 @@ public class MonthPicker extends FrameLayout {
int year = mCurrentDate.get(Calendar.YEAR);
// take care of wrapping of days and months to update greater fields
- if (picker == mMonthSpinner) {
+ if (picker == mPositionInYearSpinner) {
month = newVal;
if (oldVal == (MONTHS_NUMBER - 1) && newVal == 0) {
year += 1;
@@ -97,12 +67,12 @@ public class MonthPicker extends FrameLayout {
};
// month
- mMonthSpinner = (NumberPicker) findViewById(R.id.month);
- mMonthSpinner.setMinValue(0);
- mMonthSpinner.setMaxValue(MONTHS_NUMBER - 1);
- mMonthSpinner.setDisplayedValues(mShortMonths);
- mMonthSpinner.setOnLongPressUpdateInterval(200);
- mMonthSpinner.setOnValueChangedListener(onChangeListener);
+ mPositionInYearSpinner = (NumberPicker) findViewById(R.id.month);
+ mPositionInYearSpinner.setMinValue(0);
+ mPositionInYearSpinner.setMaxValue(MONTHS_NUMBER - 1);
+ mPositionInYearSpinner.setDisplayedValues(mShortMonths);
+ mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
+ mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);
// year
mYearSpinner = (NumberPicker) findViewById(R.id.year);
@@ -117,20 +87,6 @@ public class MonthPicker extends FrameLayout {
init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), null);
}
- private void setCurrentDate(int year, int month) {
- if (mCurrentDate == null) {
- mCurrentDate = Calendar.getInstance();
- }
- mCurrentDate.clear();
- mCurrentDate.set(year, month, 1);
- if (mCurrentDate.getTimeInMillis() < mMinDate.getTimeInMillis()) {
- mCurrentDate = (Calendar) mMinDate.clone();
- } else if (mCurrentDate.getTimeInMillis() > mMaxDate.getTimeInMillis()) {
- mCurrentDate = (Calendar) mMaxDate.clone();
- }
- updateSpinners();
- }
-
private static Calendar monthsToCalendar(long months) {
int year = (int)Math.min(months / 12 + 1970, Integer.MAX_VALUE);
int month = (int) (months % 12);
@@ -141,66 +97,36 @@ public class MonthPicker extends FrameLayout {
}
@Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
- onPopulateAccessibilityEvent(event);
- return true;
- }
-
- @Override
- public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
- super.onPopulateAccessibilityEvent(event);
-
- final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
- String selectedDateUtterance = DateUtils.formatDateTime(getContext(),
- mCurrentDate.getTimeInMillis(), flags);
- event.getText().add(selectedDateUtterance);
+ protected void setCurrentDate(int year, int month) {
+ mCurrentDate.set(year, month, 1);
+ if (mCurrentDate.before(mMinDate)) {
+ mCurrentDate.setTimeInMillis(mMinDate.getTimeInMillis());
+ } else if (mCurrentDate.after(mMaxDate)) {
+ mCurrentDate.setTimeInMillis(mMaxDate.getTimeInMillis());
+ }
}
@Override
- protected void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- }
-
- /**
- * Initialize the state. If the provided values designate an inconsistent
- * date the values are normalized before updating the spinners.
- *
- * @param year The initial year.
- * @param month The initial month <strong>starting from zero</strong>.
- * @param onMonthChangedListener How user is notified date is changed by
- * user, can be null.
- */
- public void init(int year, int month, OnMonthChangedListener onMonthChangedListener) {
- setCurrentDate(year, month);
- updateSpinners();
- mMonthChangedListener = onMonthChangedListener;
- }
-
- private boolean isNewDate(int year, int month) {
- return (mCurrentDate.get(Calendar.YEAR) != year
- || mCurrentDate.get(Calendar.MONTH) != month);
- }
-
- private void updateSpinners() {
+ protected void updateSpinners() {
// set the spinner ranges respecting the min and max dates
- mMonthSpinner.setDisplayedValues(null);
- mMonthSpinner.setMinValue(0);
- mMonthSpinner.setMaxValue(MONTHS_NUMBER - 1);
+ mPositionInYearSpinner.setDisplayedValues(null);
Miguel Garcia 2013/06/11 13:02:52 This logic is exactly the same for month and week
keishi 2013/06/12 13:23:07 Done.
+ mPositionInYearSpinner.setMinValue(0);
+ mPositionInYearSpinner.setMaxValue(MONTHS_NUMBER - 1);
if (mCurrentDate.get(Calendar.YEAR) == mMinDate.get(Calendar.YEAR)) {
- mMonthSpinner.setMinValue(mMinDate.get(Calendar.MONTH));
- mMonthSpinner.setWrapSelectorWheel(false);
+ mPositionInYearSpinner.setMinValue(mMinDate.get(Calendar.MONTH));
+ mPositionInYearSpinner.setWrapSelectorWheel(false);
} else if (mCurrentDate.get(Calendar.YEAR) == mMaxDate.get(Calendar.YEAR)) {
- mMonthSpinner.setMaxValue(mMaxDate.get(Calendar.MONTH));
- mMonthSpinner.setWrapSelectorWheel(false);
+ mPositionInYearSpinner.setMaxValue(mMaxDate.get(Calendar.MONTH));
+ mPositionInYearSpinner.setWrapSelectorWheel(false);
} else {
- mMonthSpinner.setWrapSelectorWheel(true);
+ mPositionInYearSpinner.setWrapSelectorWheel(true);
}
// make sure the month names are a zero based array
// with the months in the month spinner
String[] displayedValues = Arrays.copyOfRange(mShortMonths,
- mMonthSpinner.getMinValue(), mMonthSpinner.getMaxValue() + 1);
- mMonthSpinner.setDisplayedValues(displayedValues);
+ mPositionInYearSpinner.getMinValue(), mPositionInYearSpinner.getMaxValue() + 1);
+ mPositionInYearSpinner.setDisplayedValues(displayedValues);
// year spinner range does not change based on the current date
mYearSpinner.setMinValue(mMinDate.get(Calendar.YEAR));
@@ -209,14 +135,7 @@ public class MonthPicker extends FrameLayout {
// set the spinner values
mYearSpinner.setValue(mCurrentDate.get(Calendar.YEAR));
- mMonthSpinner.setValue(mCurrentDate.get(Calendar.MONTH));
- }
-
- /**
- * @return The selected year.
- */
- public int getYear() {
- return mCurrentDate.get(Calendar.YEAR);
+ mPositionInYearSpinner.setValue(mCurrentDate.get(Calendar.MONTH));
}
/**
@@ -226,13 +145,8 @@ public class MonthPicker extends FrameLayout {
return mCurrentDate.get(Calendar.MONTH);
}
- /**
- * Notifies the listener, if such, for a change in the selected date.
- */
- private void notifyDateChanged() {
- sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
- if (mMonthChangedListener != null) {
- mMonthChangedListener.onMonthChanged(this, getYear(), getMonth());
- }
+ @Override
+ public int getMonthOrWeek() {
+ return getMonth();
}
}

Powered by Google App Engine
This is Rietveld 408576698