diff options
author | Alan Viverette <alanv@google.com> | 2015-01-08 15:24:45 -0800 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2015-01-08 15:25:30 -0800 |
commit | 4e5168fae43e783a35c5bc731e500196005268fb (patch) | |
tree | eb5160b5e9a1832221bf87308e7ec2e85178868a /core/java/android/widget | |
parent | 1ea47aa0839bb33c6bd5223c37d38616edc57181 (diff) | |
download | frameworks_base-4e5168fae43e783a35c5bc731e500196005268fb.zip frameworks_base-4e5168fae43e783a35c5bc731e500196005268fb.tar.gz frameworks_base-4e5168fae43e783a35c5bc731e500196005268fb.tar.bz2 |
Update year picker to use activation colors
Change-Id: I148b592538e1e4a928bd7ebb99a3083b760b839d
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/DatePickerCalendarDelegate.java | 32 | ||||
-rw-r--r-- | core/java/android/widget/TextViewWithCircularIndicator.java | 43 | ||||
-rw-r--r-- | core/java/android/widget/YearPickerView.java | 40 |
3 files changed, 46 insertions, 69 deletions
diff --git a/core/java/android/widget/DatePickerCalendarDelegate.java b/core/java/android/widget/DatePickerCalendarDelegate.java index bfd7052..a3b834e 100644 --- a/core/java/android/widget/DatePickerCalendarDelegate.java +++ b/core/java/android/widget/DatePickerCalendarDelegate.java @@ -145,8 +145,8 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i // Use Theme attributes if possible final int dayOfWeekTextAppearanceResId = a.getResourceId( - R.styleable.DatePicker_dayOfWeekTextAppearance, -1); - if (dayOfWeekTextAppearanceResId != -1) { + R.styleable.DatePicker_dayOfWeekTextAppearance, 0); + if (dayOfWeekTextAppearanceResId != 0) { mDayOfWeekView.setTextAppearance(context, dayOfWeekTextAppearanceResId); } @@ -157,8 +157,8 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i final int headerSelectedTextColor = a.getColor( R.styleable.DatePicker_headerSelectedTextColor, defaultHighlightColor); final int monthTextAppearanceResId = a.getResourceId( - R.styleable.DatePicker_headerMonthTextAppearance, -1); - if (monthTextAppearanceResId != -1) { + R.styleable.DatePicker_headerMonthTextAppearance, 0); + if (monthTextAppearanceResId != 0) { mHeaderMonthTextView.setTextAppearance(context, monthTextAppearanceResId); } mHeaderMonthTextView.setTextColor(ColorStateList.addFirstIfMissing( @@ -166,18 +166,18 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i headerSelectedTextColor)); final int dayOfMonthTextAppearanceResId = a.getResourceId( - R.styleable.DatePicker_headerDayOfMonthTextAppearance, -1); - if (dayOfMonthTextAppearanceResId != -1) { + R.styleable.DatePicker_headerDayOfMonthTextAppearance, 0); + if (dayOfMonthTextAppearanceResId != 0) { mHeaderDayOfMonthTextView.setTextAppearance(context, dayOfMonthTextAppearanceResId); } mHeaderDayOfMonthTextView.setTextColor(ColorStateList.addFirstIfMissing( mHeaderDayOfMonthTextView.getTextColors(), R.attr.state_selected, headerSelectedTextColor)); - final int yearTextAppearanceResId = a.getResourceId( - R.styleable.DatePicker_headerYearTextAppearance, -1); - if (yearTextAppearanceResId != -1) { - mHeaderYearTextView.setTextAppearance(context, yearTextAppearanceResId); + final int headerYearTextAppearanceResId = a.getResourceId( + R.styleable.DatePicker_headerYearTextAppearance, 0); + if (headerYearTextAppearanceResId != 0) { + mHeaderYearTextView.setTextAppearance(context, headerYearTextAppearanceResId); } mHeaderYearTextView.setTextColor(ColorStateList.addFirstIfMissing( mHeaderYearTextView.getTextColors(), R.attr.state_selected, @@ -193,9 +193,15 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i mYearPickerView = new YearPickerView(mContext); mYearPickerView.init(this); - final int yearSelectedCircleColor = a.getColor(R.styleable.DatePicker_yearListSelectorColor, - defaultHighlightColor); - mYearPickerView.setYearSelectedCircleColor(yearSelectedCircleColor); + final ColorStateList yearBackgroundColor = a.getColorStateList( + R.styleable.DatePicker_yearListSelectorColor); + mYearPickerView.setYearBackgroundColor(yearBackgroundColor); + + final int yearTextAppearanceResId = a.getResourceId( + R.styleable.DatePicker_yearListItemTextAppearance, 0); + if (yearTextAppearanceResId != 0) { + mYearPickerView.setYearTextAppearance(yearTextAppearanceResId); + } final ColorStateList calendarTextColor = a.getColorStateList( R.styleable.DatePicker_calendarTextColor); diff --git a/core/java/android/widget/TextViewWithCircularIndicator.java b/core/java/android/widget/TextViewWithCircularIndicator.java index 43c0843..d3c786c 100644 --- a/core/java/android/widget/TextViewWithCircularIndicator.java +++ b/core/java/android/widget/TextViewWithCircularIndicator.java @@ -18,7 +18,6 @@ package android.widget; import android.content.Context; import android.content.res.Resources; -import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Typeface; @@ -27,14 +26,8 @@ import android.util.AttributeSet; import com.android.internal.R; class TextViewWithCircularIndicator extends TextView { - - private static final int SELECTED_CIRCLE_ALPHA = 60; - private final Paint mCirclePaint = new Paint(); - private final String mItemIsSelectedText; - private int mCircleColor; - private boolean mDrawIndicator; public TextViewWithCircularIndicator(Context context) { this(context, null); @@ -50,22 +43,11 @@ class TextViewWithCircularIndicator extends TextView { public TextViewWithCircularIndicator(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs); - - - // Use Theme attributes if possible - final TypedArray a = mContext.obtainStyledAttributes(attrs, - R.styleable.DatePicker, defStyleAttr, defStyleRes); - final int resId = a.getResourceId(R.styleable.DatePicker_yearListItemTextAppearance, -1); - if (resId != -1) { - setTextAppearance(context, resId); - } + super(context, attrs, defStyleAttr, defStyleRes); final Resources res = context.getResources(); mItemIsSelectedText = res.getString(R.string.item_is_selected); - a.recycle(); - init(); } @@ -77,33 +59,26 @@ class TextViewWithCircularIndicator extends TextView { } public void setCircleColor(int color) { - if (color != mCircleColor) { - mCircleColor = color; - mCirclePaint.setColor(mCircleColor); - mCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA); - requestLayout(); - } - } - - public void setDrawIndicator(boolean drawIndicator) { - mDrawIndicator = drawIndicator; + mCirclePaint.setColor(color); + invalidate(); } @Override public void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (mDrawIndicator) { + if (isActivated()) { final int width = getWidth(); final int height = getHeight(); - int radius = Math.min(width, height) / 2; + final int radius = Math.min(width, height) / 2; canvas.drawCircle(width / 2, height / 2, radius, mCirclePaint); } + + super.onDraw(canvas); } @Override public CharSequence getContentDescription() { - CharSequence itemText = getText(); - if (mDrawIndicator) { + final CharSequence itemText = getText(); + if (isActivated()) { return String.format(mItemIsSelectedText, itemText); } else { return itemText; diff --git a/core/java/android/widget/YearPickerView.java b/core/java/android/widget/YearPickerView.java index fb5debc..6f0465f 100644 --- a/core/java/android/widget/YearPickerView.java +++ b/core/java/android/widget/YearPickerView.java @@ -17,8 +17,10 @@ package android.widget; import android.content.Context; +import android.content.res.ColorStateList; import android.content.res.Resources; import android.util.AttributeSet; +import android.util.StateSet; import android.view.View; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; @@ -42,7 +44,7 @@ class YearPickerView extends ListView implements AdapterView.OnItemClickListener private DatePickerController mController; private int mSelectedPosition = -1; - private int mYearSelectedCircleColor; + private int mYearActivatedColor; public YearPickerView(Context context) { this(context, null); @@ -97,15 +99,14 @@ class YearPickerView extends ListView implements AdapterView.OnItemClickListener onDateChanged(); } - public void setYearSelectedCircleColor(int color) { - if (color != mYearSelectedCircleColor) { - mYearSelectedCircleColor = color; - } - requestLayout(); + public void setYearBackgroundColor(ColorStateList yearBackgroundColor) { + mYearActivatedColor = yearBackgroundColor.getColorForState( + StateSet.get(StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_ACTIVATED), 0); + invalidate(); } - public int getYearSelectedCircleColor() { - return mYearSelectedCircleColor; + public void setYearTextAppearance(int resId) { + mAdapter.setItemTextAppearance(resId); } private void updateAdapterData() { @@ -127,12 +128,8 @@ class YearPickerView extends ListView implements AdapterView.OnItemClickListener mController.onYearSelected(mAdapter.getItem(position)); } - void setItemTextAppearance(int resId) { - mAdapter.setItemTextAppearance(resId); - } - private class YearAdapter extends ArrayAdapter<Integer> { - int mItemTextAppearanceResId; + private int mItemTextAppearanceResId; public YearAdapter(Context context, int resource) { super(context, resource); @@ -140,16 +137,15 @@ class YearPickerView extends ListView implements AdapterView.OnItemClickListener @Override public View getView(int position, View convertView, ViewGroup parent) { - TextViewWithCircularIndicator v = (TextViewWithCircularIndicator) + final TextViewWithCircularIndicator v = (TextViewWithCircularIndicator) super.getView(position, convertView, parent); - v.setTextAppearance(getContext(), mItemTextAppearanceResId); - v.requestLayout(); - int year = getItem(position); - boolean selected = mController.getSelectedDay().get(Calendar.YEAR) == year; - v.setDrawIndicator(selected); - if (selected) { - v.setCircleColor(mYearSelectedCircleColor); - } + v.setTextAppearance(v.getContext(), mItemTextAppearanceResId); + v.setCircleColor(mYearActivatedColor); + + final int year = getItem(position); + final boolean selected = mController.getSelectedDay().get(Calendar.YEAR) == year; + v.setActivated(selected); + return v; } |