diff options
| author | Alan Viverette <alanv@google.com> | 2014-07-28 16:56:32 -0700 |
|---|---|---|
| committer | Alan Viverette <alanv@google.com> | 2014-07-29 12:49:50 -0700 |
| commit | 60727e07c6ef72e2f494266939c02494a3df28f8 (patch) | |
| tree | 93c4d59934335d43a9650819ea89e465a26c37d9 /core/java/android/widget/TimePickerDelegate.java | |
| parent | ec9c7090f845e0804dab70a73307a747dca1ba3d (diff) | |
Clean up TimePicker and DatePicker styling
Removes the time and date picker specific themes and defaults their
theme attributes to use the alert dialog theme attribute's value.
BUG: 14973897
Change-Id: Id5cc74ea0c1a379fc1ee76b354a1bb5ba329585a
Diffstat (limited to 'core/java/android/widget/TimePickerDelegate.java')
| -rw-r--r-- | core/java/android/widget/TimePickerDelegate.java | 78 |
1 files changed, 36 insertions, 42 deletions
diff --git a/core/java/android/widget/TimePickerDelegate.java b/core/java/android/widget/TimePickerDelegate.java index 45be637dbde7..c68619ca70c3 100644 --- a/core/java/android/widget/TimePickerDelegate.java +++ b/core/java/android/widget/TimePickerDelegate.java @@ -20,6 +20,7 @@ import android.animation.Keyframe; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.content.Context; +import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; @@ -79,7 +80,6 @@ class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implement // Duration in ms of the pulse animation private static final int PULSE_ANIMATOR_DURATION = 544; - private final View mMainView; private TextView mHourView; private TextView mMinuteView; private TextView mAmPmTextView; @@ -88,8 +88,6 @@ class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implement private ViewGroup mLayoutButtons; - private int mHeaderSelectedColor; - private int mHeaderUnselectedColor; private String mAmText; private String mPmText; @@ -128,7 +126,8 @@ class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implement // process style attributes final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TimePicker, defStyleAttr, defStyleRes); - + final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( + Context.LAYOUT_INFLATER_SERVICE); final Resources res = mContext.getResources(); mHourPickerDescription = res.getString(R.string.hour_picker_description); @@ -136,53 +135,52 @@ class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implement mMinutePickerDescription = res.getString(R.string.minute_picker_description); mSelectMinutes = res.getString(R.string.select_minutes); - mHeaderSelectedColor = a.getColor(R.styleable.TimePicker_headerSelectedTextColor, - res.getColor(R.color.timepicker_default_selector_color_material)); - - final int headerTimeTextAppearance = a.getResourceId( - R.styleable.TimePicker_headerTimeTextAppearance, 0); - final int headerAmPmTextAppearance = a.getResourceId( - R.styleable.TimePicker_headerAmPmTextAppearance, 0); - final int headerBackgroundColor = a.getColor( - R.styleable.TimePicker_headerBackgroundColor, Color.TRANSPARENT); - final int layoutResourceId = a.getResourceId( - R.styleable.TimePicker_internalLayout, R.layout.time_picker_holo); - - a.recycle(); - - final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - - mMainView = inflater.inflate(layoutResourceId, null); - mDelegator.addView(mMainView); + final int layoutResourceId = a.getResourceId(R.styleable.TimePicker_internalLayout, + R.layout.time_picker_holo); + final View mainView = inflater.inflate(layoutResourceId, null); + mDelegator.addView(mainView); - mHourView = (TextView) mMainView.findViewById(R.id.hours); - mSeparatorView = (TextView) mMainView.findViewById(R.id.separator); - mMinuteView = (TextView) mMainView.findViewById(R.id.minutes); - mAmPmTextView = (TextView) mMainView.findViewById(R.id.ampm_label); - mLayoutButtons = (ViewGroup) mMainView.findViewById(R.id.layout_buttons); + mHourView = (TextView) mainView.findViewById(R.id.hours); + mSeparatorView = (TextView) mainView.findViewById(R.id.separator); + mMinuteView = (TextView) mainView.findViewById(R.id.minutes); + mAmPmTextView = (TextView) mainView.findViewById(R.id.ampm_label); + mLayoutButtons = (ViewGroup) mainView.findViewById(R.id.layout_buttons); // Set up text appearances from style. + final int headerTimeTextAppearance = a.getResourceId( + R.styleable.TimePicker_headerTimeTextAppearance, 0); if (headerTimeTextAppearance != 0) { mHourView.setTextAppearance(context, headerTimeTextAppearance); mSeparatorView.setTextAppearance(context, headerTimeTextAppearance); mMinuteView.setTextAppearance(context, headerTimeTextAppearance); } + final int headerSelectedTextColor = a.getColor( + R.styleable.TimePicker_headerSelectedTextColor, + res.getColor(R.color.timepicker_default_selector_color_material)); + mHourView.setTextColor(ColorStateList.addFirstIfMissing(mHourView.getTextColors(), + R.attr.state_selected, headerSelectedTextColor)); + mMinuteView.setTextColor(ColorStateList.addFirstIfMissing(mMinuteView.getTextColors(), + R.attr.state_selected, headerSelectedTextColor)); + + final int headerAmPmTextAppearance = a.getResourceId( + R.styleable.TimePicker_headerAmPmTextAppearance, 0); if (headerAmPmTextAppearance != 0) { mAmPmTextView.setTextAppearance(context, headerAmPmTextAppearance); } + final int headerBackgroundColor = a.getColor( + R.styleable.TimePicker_headerBackgroundColor, Color.TRANSPARENT); if (headerBackgroundColor != Color.TRANSPARENT) { mLayoutButtons.setBackgroundColor(headerBackgroundColor); - mMainView.findViewById(R.id.time_header).setBackgroundColor(headerBackgroundColor); + mainView.findViewById(R.id.time_header).setBackgroundColor(headerBackgroundColor); } - // Load unselected header color from current state. - mHeaderUnselectedColor = mHourView.getCurrentTextColor(); + a.recycle(); - mRadialTimePickerView = (RadialTimePickerView) mMainView.findViewById(R.id.radial_picker); - mDoneButton = (Button) mMainView.findViewById(R.id.done_button); + mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById( + R.id.radial_picker); + mDoneButton = (Button) mainView.findViewById(R.id.done_button); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0]; @@ -785,7 +783,6 @@ class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implement separatorText = Character.toString(bestDateTimePattern.charAt(hIndex + 1)); } mSeparatorView.setText(separatorText); - mSeparatorView.setTextColor(mHeaderUnselectedColor); } static private int lastIndexOfAny(String str, char[] any) { @@ -839,10 +836,8 @@ class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implement labelToAnimate = mMinuteView; } - int hourColor = (index == HOUR_INDEX) ? mHeaderSelectedColor : mHeaderUnselectedColor; - int minuteColor = (index == MINUTE_INDEX) ? mHeaderSelectedColor : mHeaderUnselectedColor; - mHourView.setTextColor(hourColor); - mMinuteView.setTextColor(minuteColor); + mHourView.setSelected(index == HOUR_INDEX); + mMinuteView.setSelected(index == MINUTE_INDEX); ObjectAnimator pulseAnimator = getPulseAnimator(labelToAnimate, 0.85f, 1.1f); if (delayLabelAnimate) { @@ -1064,9 +1059,9 @@ class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implement String minuteStr = (values[1] == -1) ? mDoublePlaceholderText : String.format(minuteFormat, values[1]).replace(' ', mPlaceholderText); mHourView.setText(hourStr); - mHourView.setTextColor(mHeaderUnselectedColor); + mHourView.setSelected(false); mMinuteView.setText(minuteStr); - mMinuteView.setTextColor(mHeaderUnselectedColor); + mMinuteView.setSelected(false); if (!mIs24HourView) { updateAmPmDisplay(values[2]); } @@ -1143,8 +1138,7 @@ class TimePickerDelegate extends TimePicker.AbstractTimePickerDelegate implement } } - int[] ret = {hour, minute, amOrPm}; - return ret; + return new int[] { hour, minute, amOrPm }; } /** |
