diff options
author | Chet Haase <chet@google.com> | 2014-08-06 07:51:50 -0700 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2014-08-07 14:28:49 +0000 |
commit | 3053b2fdcf7486f2e2f572f9b05ce65dacdd2b4c (patch) | |
tree | 6b1b3dd6d6b7aab5472c6f8393c5f6c1ed16c0d4 /core/java/android/widget | |
parent | c4489f990f3eaa5d11eb2c08db2af4a7b3818fe7 (diff) | |
download | frameworks_base-3053b2fdcf7486f2e2f572f9b05ce65dacdd2b4c.zip frameworks_base-3053b2fdcf7486f2e2f572f9b05ce65dacdd2b4c.tar.gz frameworks_base-3053b2fdcf7486f2e2f572f9b05ce65dacdd2b4c.tar.bz2 |
Allow TimePicker/DatePicker to use legacy layout style
In L, the TimePicker was rewritten to use a clock face and the
DatePicker was rewritten to use a calendar. This
change allows developers to opt into the old style instead
(android:timePickerMode="spinner|clock" and
android:datePickerMode="spinner|calendar").)
Issue #16717952 Pre-L style android.widget.TimePicker on L
Issue #16846963 Allow developer to use legacy DatePicker appearance
Change-Id: I4ee071fcbc5bf25eab83d6a5cb6ff352a603f90a
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/DatePicker.java | 29 | ||||
-rw-r--r-- | core/java/android/widget/DatePickerCalendarDelegate.java (renamed from core/java/android/widget/DatePickerDelegate.java) | 4 | ||||
-rw-r--r-- | core/java/android/widget/TimePicker.java | 21 | ||||
-rw-r--r-- | core/java/android/widget/TimePickerClockDelegate.java (renamed from core/java/android/widget/LegacyTimePickerDelegate.java) | 6 | ||||
-rw-r--r-- | core/java/android/widget/TimePickerSpinnerDelegate.java (renamed from core/java/android/widget/TimePickerDelegate.java) | 6 |
5 files changed, 40 insertions, 26 deletions
diff --git a/core/java/android/widget/DatePicker.java b/core/java/android/widget/DatePicker.java index 74c66c8..d0a2eab 100644 --- a/core/java/android/widget/DatePicker.java +++ b/core/java/android/widget/DatePicker.java @@ -84,6 +84,9 @@ import libcore.icu.ICU; public class DatePicker extends FrameLayout { private static final String LOG_TAG = DatePicker.class.getSimpleName(); + private static final int MODE_SPINNER = 1; + private static final int MODE_CALENDAR = 2; + private final DatePickerDelegate mDelegate; /** @@ -120,24 +123,28 @@ public class DatePicker extends FrameLayout { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePicker, defStyleAttr, defStyleRes); - final boolean legacyMode = a.getBoolean(R.styleable.DatePicker_legacyMode, true); + int mode = a.getInt(R.styleable.DatePicker_datePickerMode, MODE_SPINNER); a.recycle(); - if (legacyMode) { - mDelegate = createLegacyUIDelegate(context, attrs, defStyleAttr, defStyleRes); - } else { - mDelegate = createNewUIDelegate(context, attrs, defStyleAttr, defStyleRes); + switch (mode) { + case MODE_CALENDAR: + mDelegate = createCalendarUIDelegate(context, attrs, defStyleAttr, defStyleRes); + break; + case MODE_SPINNER: + default: + mDelegate = createSpinnerUIDelegate(context, attrs, defStyleAttr, defStyleRes); + break; } } - private DatePickerDelegate createLegacyUIDelegate(Context context, AttributeSet attrs, + private DatePickerDelegate createSpinnerUIDelegate(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - return new LegacyDatePickerDelegate(this, context, attrs, defStyleAttr, defStyleRes); + return new DatePickerSpinnerDelegate(this, context, attrs, defStyleAttr, defStyleRes); } - private DatePickerDelegate createNewUIDelegate(Context context, AttributeSet attrs, + private DatePickerDelegate createCalendarUIDelegate(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - return new android.widget.DatePickerDelegate(this, context, attrs, defStyleAttr, + return new DatePickerCalendarDelegate(this, context, attrs, defStyleAttr, defStyleRes); } @@ -454,7 +461,7 @@ public class DatePicker extends FrameLayout { /** * A delegate implementing the basic DatePicker */ - private static class LegacyDatePickerDelegate extends AbstractDatePickerDelegate { + private static class DatePickerSpinnerDelegate extends AbstractDatePickerDelegate { private static final String DATE_FORMAT = "MM/dd/yyyy"; @@ -500,7 +507,7 @@ public class DatePicker extends FrameLayout { private boolean mIsEnabled = DEFAULT_ENABLED_STATE; - LegacyDatePickerDelegate(DatePicker delegator, Context context, AttributeSet attrs, + DatePickerSpinnerDelegate(DatePicker delegator, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(delegator, context); diff --git a/core/java/android/widget/DatePickerDelegate.java b/core/java/android/widget/DatePickerCalendarDelegate.java index ddc565d..c0c76ac 100644 --- a/core/java/android/widget/DatePickerDelegate.java +++ b/core/java/android/widget/DatePickerCalendarDelegate.java @@ -52,7 +52,7 @@ import java.util.Locale; /** * A delegate for picking up a date (day / month / year). */ -class DatePickerDelegate extends DatePicker.AbstractDatePickerDelegate implements +class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate implements View.OnClickListener, DatePickerController { private static final int UNINITIALIZED = -1; @@ -113,7 +113,7 @@ class DatePickerDelegate extends DatePicker.AbstractDatePickerDelegate implement private HashSet<OnDateChangedListener> mListeners = new HashSet<OnDateChangedListener>(); - public DatePickerDelegate(DatePicker delegator, Context context, AttributeSet attrs, + public DatePickerCalendarDelegate(DatePicker delegator, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(delegator, context); diff --git a/core/java/android/widget/TimePicker.java b/core/java/android/widget/TimePicker.java index 026a8ee..c488666 100644 --- a/core/java/android/widget/TimePicker.java +++ b/core/java/android/widget/TimePicker.java @@ -45,6 +45,9 @@ import java.util.Locale; */ @Widget public class TimePicker extends FrameLayout { + private static final int MODE_SPINNER = 1; + private static final int MODE_CLOCK = 2; + private final TimePickerDelegate mDelegate; /** @@ -77,15 +80,19 @@ public class TimePicker extends FrameLayout { final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.TimePicker, defStyleAttr, defStyleRes); - final boolean legacyMode = a.getBoolean(R.styleable.TimePicker_legacyMode, true); + int mode = a.getInt(R.styleable.TimePicker_timePickerMode, MODE_SPINNER); a.recycle(); - if (legacyMode) { - mDelegate = new LegacyTimePickerDelegate( - this, context, attrs, defStyleAttr, defStyleRes); - } else { - mDelegate = new android.widget.TimePickerDelegate( - this, context, attrs, defStyleAttr, defStyleRes); + switch (mode) { + case MODE_CLOCK: + mDelegate = new TimePickerSpinnerDelegate( + this, context, attrs, defStyleAttr, defStyleRes); + break; + case MODE_SPINNER: + default: + mDelegate = new TimePickerClockDelegate( + this, context, attrs, defStyleAttr, defStyleRes); + break; } } diff --git a/core/java/android/widget/LegacyTimePickerDelegate.java b/core/java/android/widget/TimePickerClockDelegate.java index 70db211..59ec6d3 100644 --- a/core/java/android/widget/LegacyTimePickerDelegate.java +++ b/core/java/android/widget/TimePickerClockDelegate.java @@ -44,7 +44,7 @@ import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_YES; /** * A delegate implementing the basic TimePicker */ -class LegacyTimePickerDelegate extends TimePicker.AbstractTimePickerDelegate { +class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate { private static final boolean DEFAULT_ENABLED_STATE = true; @@ -100,8 +100,8 @@ class LegacyTimePickerDelegate extends TimePicker.AbstractTimePickerDelegate { } }; - public LegacyTimePickerDelegate(TimePicker delegator, Context context, AttributeSet attrs, - int defStyleAttr, int defStyleRes) { + public TimePickerClockDelegate(TimePicker delegator, Context context, AttributeSet attrs, + int defStyleAttr, int defStyleRes) { super(delegator, context); // process style attributes diff --git a/core/java/android/widget/TimePickerDelegate.java b/core/java/android/widget/TimePickerSpinnerDelegate.java index c68619c..4e9a39f 100644 --- a/core/java/android/widget/TimePickerDelegate.java +++ b/core/java/android/widget/TimePickerSpinnerDelegate.java @@ -51,7 +51,7 @@ import java.util.Locale; /** * A view for selecting the time of day, in either 24 hour or AM/PM mode. */ -class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implements +class TimePickerSpinnerDelegate extends TimePicker.AbstractTimePickerDelegate implements RadialTimePickerView.OnValueSelectedListener { private static final String TAG = "TimePickerDelegate"; @@ -119,8 +119,8 @@ class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implement private Calendar mTempCalendar; - public TimePickerDelegate(TimePicker delegator, Context context, AttributeSet attrs, - int defStyleAttr, int defStyleRes) { + public TimePickerSpinnerDelegate(TimePicker delegator, Context context, AttributeSet attrs, + int defStyleAttr, int defStyleRes) { super(delegator, context); // process style attributes |