summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2015-03-30 17:27:01 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-03-30 17:27:03 +0000
commit523fe91af4baf26cd26e46c1418a072574959b73 (patch)
tree32c6522a5c4b027309a9d1ae47a0147eb467c1a4 /core/java/android/widget
parente9e02d52350102756e3e3e984dc0bba06638d93e (diff)
parentf2525f6802219ad5e983128dc2f7b5a89a507d9c (diff)
downloadframeworks_base-523fe91af4baf26cd26e46c1418a072574959b73.zip
frameworks_base-523fe91af4baf26cd26e46c1418a072574959b73.tar.gz
frameworks_base-523fe91af4baf26cd26e46c1418a072574959b73.tar.bz2
Merge "Clean up time picker attributes and drawing code"
Diffstat (limited to 'core/java/android/widget')
-rw-r--r--core/java/android/widget/RadialTimePickerView.java141
-rw-r--r--core/java/android/widget/TimePickerClockDelegate.java126
2 files changed, 142 insertions, 125 deletions
diff --git a/core/java/android/widget/RadialTimePickerView.java b/core/java/android/widget/RadialTimePickerView.java
index 20aa972..143dea4 100644
--- a/core/java/android/widget/RadialTimePickerView.java
+++ b/core/java/android/widget/RadialTimePickerView.java
@@ -122,8 +122,9 @@ public class RadialTimePickerView extends View {
private final Paint mPaintCenter = new Paint();
private final Paint[][] mPaintSelector = new Paint[2][3];
- private final int[][] mColorSelector = new int[2][3];
- private final IntHolder[][] mAlphaSelector = new IntHolder[2][3];
+
+ private final int mSelectorColor;
+ private final int mSelectorDotColor;
private final Paint mPaintBackground = new Paint();
@@ -147,6 +148,8 @@ public class RadialTimePickerView extends View {
private final RadialPickerTouchHelper mTouchHelper;
+ private final Path mSelectorPath = new Path();
+
private boolean mIs24HourMode;
private boolean mShowHours;
@@ -316,11 +319,6 @@ public class RadialTimePickerView extends View {
for (int i = 0; i < mAlpha.length; i++) {
mAlpha[i] = new IntHolder(ALPHA_OPAQUE);
}
- for (int i = 0; i < mAlphaSelector.length; i++) {
- for (int j = 0; j < mAlphaSelector[i].length; j++) {
- mAlphaSelector[i][j] = new IntHolder(ALPHA_OPAQUE);
- }
- }
mTextColor[HOURS] = a.getColorStateList(R.styleable.TimePicker_numbersTextColor);
mTextColor[HOURS_INNER] = a.getColorStateList(R.styleable.TimePicker_numbersInnerTextColor);
@@ -345,33 +343,28 @@ public class RadialTimePickerView extends View {
final int[] activatedStateSet = StateSet.get(
StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_ACTIVATED);
+ mSelectorColor = selectorActivatedColor;
+ mSelectorDotColor = mTextColor[HOURS].getColorForState(activatedStateSet, 0);
+
mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint();
mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true);
- mColorSelector[HOURS][SELECTOR_CIRCLE] = selectorActivatedColor;
mPaintSelector[HOURS][SELECTOR_DOT] = new Paint();
mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true);
- mColorSelector[HOURS][SELECTOR_DOT] =
- mTextColor[HOURS].getColorForState(activatedStateSet, 0);
mPaintSelector[HOURS][SELECTOR_LINE] = new Paint();
mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true);
mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2);
- mColorSelector[HOURS][SELECTOR_LINE] = selectorActivatedColor;
mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint();
mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true);
- mColorSelector[MINUTES][SELECTOR_CIRCLE] = selectorActivatedColor;
mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint();
mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true);
- mColorSelector[MINUTES][SELECTOR_DOT] =
- mTextColor[MINUTES].getColorForState(activatedStateSet, 0);
mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint();
mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true);
mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2);
- mColorSelector[MINUTES][SELECTOR_LINE] = selectorActivatedColor;
mPaintBackground.setColor(a.getColor(R.styleable.TimePicker_numbersBackgroundColor,
context.getColor(R.color.timepicker_default_numbers_background_color_material)));
@@ -600,8 +593,8 @@ public class RadialTimePickerView extends View {
// Initialize the hours and minutes numbers.
for (int i = 0; i < 12; i++) {
mHours12Texts[i] = String.format("%d", HOURS_NUMBERS[i]);
- mOuterHours24Texts[i] = String.format("%02d", HOURS_NUMBERS_24[i]);
- mInnerHours24Texts[i] = String.format("%d", HOURS_NUMBERS[i]);
+ mInnerHours24Texts[i] = String.format("%02d", HOURS_NUMBERS_24[i]);
+ mOuterHours24Texts[i] = String.format("%d", HOURS_NUMBERS[i]);
mMinutesTexts[i] = String.format("%02d", MINUTES_NUMBERS[i]);
}
}
@@ -612,22 +605,16 @@ public class RadialTimePickerView extends View {
mInnerTextHours = mInnerHours24Texts;
} else {
mOuterTextHours = mHours12Texts;
- mInnerTextHours = null;
+ mInnerTextHours = mHours12Texts;
}
mOuterTextMinutes = mMinutesTexts;
final int hoursAlpha = mShowHours ? ALPHA_OPAQUE : ALPHA_TRANSPARENT;
mAlpha[HOURS].setValue(hoursAlpha);
- mAlphaSelector[HOURS][SELECTOR_CIRCLE].setValue(hoursAlpha);
- mAlphaSelector[HOURS][SELECTOR_DOT].setValue(hoursAlpha);
- mAlphaSelector[HOURS][SELECTOR_LINE].setValue(hoursAlpha);
final int minutesAlpha = mShowHours ? ALPHA_TRANSPARENT : ALPHA_OPAQUE;
mAlpha[MINUTES].setValue(minutesAlpha);
- mAlphaSelector[MINUTES][SELECTOR_CIRCLE].setValue(minutesAlpha);
- mAlphaSelector[MINUTES][SELECTOR_DOT].setValue(minutesAlpha);
- mAlphaSelector[MINUTES][SELECTOR_LINE].setValue(minutesAlpha);
}
@Override
@@ -675,7 +662,7 @@ public class RadialTimePickerView extends View {
mOuterTextHours, mOuterTextX[HOURS], mOuterTextY[HOURS], mPaint[HOURS],
hoursAlpha, !mIsOnInnerCircle, mSelectionDegrees[HOURS], false);
- // Draw inner hours (12-23) for 24-hour time.
+ // Draw inner hours (13-00) for 24-hour time.
if (mIs24HourMode && mInnerTextHours != null) {
drawTextElements(canvas, mTextSize[HOURS_INNER], mTypeface, mTextColor[HOURS_INNER],
mInnerTextHours, mInnerTextX, mInnerTextY, mPaint[HOURS], hoursAlpha,
@@ -714,69 +701,61 @@ public class RadialTimePickerView extends View {
canvas.drawCircle(mXCenter, mYCenter, mCenterDotRadius, mPaintCenter);
}
+ private int applyAlpha(int argb, int alpha) {
+ final int srcAlpha = (argb >> 24) & 0xFF;
+ final int dstAlpha = (int) (srcAlpha * (alpha / 255.0) + 0.5f);
+ return (0xFFFFFF & argb) | (dstAlpha << 24);
+ }
+
private int getMultipliedAlpha(int argb, int alpha) {
return (int) (Color.alpha(argb) * (alpha / 255.0) + 0.5);
}
- private final Path mSelectorPath = new Path();
-
private void drawSelector(Canvas canvas, int index, Path selectorPath, float alphaMod) {
- // Calculate the current radius at which to place the selection circle.
- mLineLength[index] = mCircleRadius - mTextInset[index];
-
- final double selectionRadians = Math.toRadians(mSelectionDegrees[index]);
-
- float pointX = mXCenter + (int) (mLineLength[index] * Math.sin(selectionRadians));
- float pointY = mYCenter - (int) (mLineLength[index] * Math.cos(selectionRadians));
+ final int alpha = (int) (mAlpha[index % 2].getValue() * alphaMod + 0.5f);
+ final int color = applyAlpha(mSelectorColor, alpha);
- int color;
- int alpha;
- Paint paint;
-
- // Draw the selection circle
- color = mColorSelector[index % 2][SELECTOR_CIRCLE];
- alpha = (int) (mAlphaSelector[index % 2][SELECTOR_CIRCLE].getValue() * alphaMod + 0.5f);
- paint = mPaintSelector[index % 2][SELECTOR_CIRCLE];
+ // Calculate the current radius at which to place the selection circle.
+ final int selRadius = mSelectorRadius;
+ final int selLength = mCircleRadius - mTextInset[index];
+ final double selAngleRad = Math.toRadians(mSelectionDegrees[index]);
+ final float selCenterX = mXCenter + selLength * (float) Math.sin(selAngleRad);
+ final float selCenterY = mYCenter - selLength * (float) Math.cos(selAngleRad);
+
+ // Draw the selection circle.
+ final Paint paint = mPaintSelector[index % 2][SELECTOR_CIRCLE];
paint.setColor(color);
- paint.setAlpha(getMultipliedAlpha(color, alpha));
- canvas.drawCircle(pointX, pointY, mSelectorRadius, paint);
+ canvas.drawCircle(selCenterX, selCenterY, selRadius, paint);
// If needed, set up the clip path for later.
if (selectorPath != null) {
- mSelectorPath.reset();
- mSelectorPath.addCircle(pointX, pointY, mSelectorRadius, Path.Direction.CCW);
+ selectorPath.reset();
+ selectorPath.addCircle(selCenterX, selCenterY, selRadius, Path.Direction.CCW);
}
- // Draw the dot if needed.
+ // Draw the dot if we're between two items.
final boolean shouldDrawDot = mSelectionDegrees[index] % 30 != 0;
if (shouldDrawDot) {
- // We're not on a direct tick
- color = mColorSelector[index % 2][SELECTOR_DOT];
- alpha = (int) (mAlphaSelector[index % 2][SELECTOR_DOT].getValue() * alphaMod + 0.5f);
- paint = mPaintSelector[index % 2][SELECTOR_DOT];
- paint.setColor(color);
- paint.setAlpha(getMultipliedAlpha(color, alpha));
- canvas.drawCircle(pointX, pointY, mSelectorDotRadius, paint);
+ final Paint dotPaint = mPaintSelector[index % 2][SELECTOR_DOT];
+ dotPaint.setColor(color);
+ canvas.drawCircle(selCenterX, selCenterY, mSelectorDotRadius, dotPaint);
}
// Shorten the line to only go from the edge of the center dot to the
// edge of the selection circle.
- final double sin = Math.sin(selectionRadians);
- final double cos = Math.cos(selectionRadians);
- final int lineLength = mLineLength[index] - mSelectorRadius;
+ final double sin = Math.sin(selAngleRad);
+ final double cos = Math.cos(selAngleRad);
+ final int lineLength = selLength - selRadius;
final int centerX = mXCenter + (int) (mCenterDotRadius * sin);
final int centerY = mYCenter - (int) (mCenterDotRadius * cos);
- pointX = centerX + (int) (lineLength * sin);
- pointY = centerY - (int) (lineLength * cos);
-
- // Draw the line
- color = mColorSelector[index % 2][SELECTOR_LINE];
- alpha = (int) (mAlphaSelector[index % 2][SELECTOR_LINE].getValue() * alphaMod + 0.5f);
- paint = mPaintSelector[index % 2][SELECTOR_LINE];
- paint.setColor(color);
- paint.setStrokeWidth(mSelectorStroke);
- paint.setAlpha(getMultipliedAlpha(color, alpha));
- canvas.drawLine(mXCenter, mYCenter, pointX, pointY, paint);
+ final float linePointX = centerX + (int) (lineLength * sin);
+ final float linePointY = centerY - (int) (lineLength * cos);
+
+ // Draw the line.
+ final Paint linePaint = mPaintSelector[index % 2][SELECTOR_LINE];
+ linePaint.setColor(color);
+ linePaint.setStrokeWidth(mSelectorStroke);
+ canvas.drawLine(mXCenter, mYCenter, linePointX, linePointY, linePaint);
}
private void calculatePositionsHours() {
@@ -890,21 +869,8 @@ public class RadialTimePickerView extends View {
if (mHoursToMinutesAnims.size() == 0) {
mHoursToMinutesAnims.add(getFadeOutAnimator(mAlpha[HOURS],
ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
- mHoursToMinutesAnims.add(getFadeOutAnimator(mAlphaSelector[HOURS][SELECTOR_CIRCLE],
- ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
- mHoursToMinutesAnims.add(getFadeOutAnimator(mAlphaSelector[HOURS][SELECTOR_DOT],
- ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
- mHoursToMinutesAnims.add(getFadeOutAnimator(mAlphaSelector[HOURS][SELECTOR_LINE],
- ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
-
mHoursToMinutesAnims.add(getFadeInAnimator(mAlpha[MINUTES],
ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
- mHoursToMinutesAnims.add(getFadeInAnimator(mAlphaSelector[MINUTES][SELECTOR_CIRCLE],
- ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
- mHoursToMinutesAnims.add(getFadeInAnimator(mAlphaSelector[MINUTES][SELECTOR_DOT],
- ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
- mHoursToMinutesAnims.add(getFadeInAnimator(mAlphaSelector[MINUTES][SELECTOR_LINE],
- ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
}
if (mTransition != null && mTransition.isRunning()) {
@@ -919,21 +885,8 @@ public class RadialTimePickerView extends View {
if (mMinuteToHoursAnims.size() == 0) {
mMinuteToHoursAnims.add(getFadeOutAnimator(mAlpha[MINUTES],
ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
- mMinuteToHoursAnims.add(getFadeOutAnimator(mAlphaSelector[MINUTES][SELECTOR_CIRCLE],
- ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
- mMinuteToHoursAnims.add(getFadeOutAnimator(mAlphaSelector[MINUTES][SELECTOR_DOT],
- ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
- mMinuteToHoursAnims.add(getFadeOutAnimator(mAlphaSelector[MINUTES][SELECTOR_LINE],
- ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
-
mMinuteToHoursAnims.add(getFadeInAnimator(mAlpha[HOURS],
ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
- mMinuteToHoursAnims.add(getFadeInAnimator(mAlphaSelector[HOURS][SELECTOR_CIRCLE],
- ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
- mMinuteToHoursAnims.add(getFadeInAnimator(mAlphaSelector[HOURS][SELECTOR_DOT],
- ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
- mMinuteToHoursAnims.add(getFadeInAnimator(mAlphaSelector[HOURS][SELECTOR_LINE],
- ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
}
if (mTransition != null && mTransition.isRunning()) {
diff --git a/core/java/android/widget/TimePickerClockDelegate.java b/core/java/android/widget/TimePickerClockDelegate.java
index 9fdd718..718d216 100644
--- a/core/java/android/widget/TimePickerClockDelegate.java
+++ b/core/java/android/widget/TimePickerClockDelegate.java
@@ -16,16 +16,20 @@
package android.widget;
+import android.annotation.Nullable;
import android.content.Context;
+import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.util.Log;
+import android.util.StateSet;
import android.util.TypedValue;
import android.view.HapticFeedbackConstants;
import android.view.KeyCharacterMap;
@@ -48,7 +52,6 @@ import java.util.Locale;
*/
class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate implements
RadialTimePickerView.OnValueSelectedListener {
-
private static final String TAG = "TimePickerClockDelegate";
// Index used by RadialPickerLayout
@@ -61,14 +64,16 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
// Also NOT a real index, just used for keyboard mode.
private static final int ENABLE_PICKER_INDEX = 3;
+ private static final int[] ATTRS_TEXT_COLOR = new int[] {
+ com.android.internal.R.attr.textColor};
+ private static final int[] ATTRS_DISABLED_ALPHA = new int[] {
+ com.android.internal.R.attr.disabledAlpha};
+
// LayoutLib relies on these constants. Change TimePickerClockDelegate_Delegate if
// modifying these.
static final int AM = 0;
static final int PM = 1;
- private static final boolean DEFAULT_ENABLED_STATE = true;
- private boolean mIsEnabled = DEFAULT_ENABLED_STATE;
-
private static final int HOURS_IN_HALF_DAY = 12;
private final View mHeaderView;
@@ -83,8 +88,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
private final String mAmText;
private final String mPmText;
- private final float mDisabledAlpha;
-
+ private boolean mIsEnabled = true;
private boolean mAllowAutoAdvance;
private int mInitialHourOfDay;
private int mInitialMinute;
@@ -134,7 +138,6 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
final View mainView = inflater.inflate(layoutResourceId, delegator);
mHeaderView = mainView.findViewById(R.id.time_header);
- mHeaderView.setBackground(a.getDrawable(R.styleable.TimePicker_headerBackground));
// Set up hour/minute labels.
mHourView = (TextView) mainView.findViewById(R.id.hours);
@@ -147,14 +150,6 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
mMinuteView.setAccessibilityDelegate(
new ClickActionDelegate(context, R.string.select_minutes));
- 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);
- }
-
// Now that we have text appearances out of the way, make sure the hour
// and minute views are correctly sized.
mHourView.setMinWidth(computeStableWidth(mHourView, 24));
@@ -169,19 +164,40 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
mPmLabel.setText(amPmStrings[1]);
mPmLabel.setOnClickListener(mClickListener);
- final int headerAmPmTextAppearance = a.getResourceId(
- R.styleable.TimePicker_headerAmPmTextAppearance, 0);
- if (headerAmPmTextAppearance != 0) {
- mAmLabel.setTextAppearance(context, headerAmPmTextAppearance);
- mPmLabel.setTextAppearance(context, headerAmPmTextAppearance);
+ // For the sake of backwards compatibility, attempt to extract the text
+ // color from the header time text appearance. If it's set, we'll let
+ // that override the "real" header text color.
+ ColorStateList headerTextColor = null;
+
+ @SuppressWarnings("deprecation")
+ final int timeHeaderTextAppearance = a.getResourceId(
+ R.styleable.TimePicker_headerTimeTextAppearance, 0);
+ if (timeHeaderTextAppearance != 0) {
+ final TypedArray textAppearance = mContext.obtainStyledAttributes(null,
+ ATTRS_TEXT_COLOR, 0, timeHeaderTextAppearance);
+ final ColorStateList legacyHeaderTextColor = textAppearance.getColorStateList(0);
+ headerTextColor = applyLegacyColorFixes(legacyHeaderTextColor);
+ textAppearance.recycle();
}
- a.recycle();
+ if (headerTextColor == null) {
+ headerTextColor = a.getColorStateList(R.styleable.TimePicker_headerTextColor);
+ }
+
+ if (headerTextColor != null) {
+ mHourView.setTextColor(headerTextColor);
+ mSeparatorView.setTextColor(headerTextColor);
+ mMinuteView.setTextColor(headerTextColor);
+ mAmLabel.setTextColor(headerTextColor);
+ mPmLabel.setTextColor(headerTextColor);
+ }
+
+ // Set up header background, if available.
+ if (a.hasValueOrEmpty(R.styleable.TimePicker_headerBackground)) {
+ mHeaderView.setBackground(a.getDrawable(R.styleable.TimePicker_headerBackground));
+ }
- // Pull disabled alpha from theme.
- final TypedValue outValue = new TypedValue();
- context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
- mDisabledAlpha = outValue.getFloat();
+ a.recycle();
mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById(
R.id.radial_picker);
@@ -204,6 +220,54 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX);
}
+ /**
+ * The legacy text color might have been poorly defined. Ensures that it
+ * has an appropriate activated state, using the selected state if one
+ * exists or modifying the default text color otherwise.
+ *
+ * @param color a legacy text color, or {@code null}
+ * @return a color state list with an appropriate activated state, or
+ * {@code null} if a valid activated state could not be generated
+ */
+ @Nullable
+ private ColorStateList applyLegacyColorFixes(@Nullable ColorStateList color) {
+ if (color == null || color.hasState(R.attr.state_activated)) {
+ return color;
+ }
+
+ final int activatedColor;
+ final int defaultColor;
+ if (color.hasState(R.attr.state_selected)) {
+ activatedColor = color.getColorForState(StateSet.get(
+ StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_SELECTED), 0);
+ defaultColor = color.getColorForState(StateSet.get(
+ StateSet.VIEW_STATE_ENABLED), 0);
+ } else {
+ activatedColor = color.getDefaultColor();
+
+ // Generate a non-activated color using the disabled alpha.
+ final TypedArray ta = mContext.obtainStyledAttributes(ATTRS_DISABLED_ALPHA);
+ final float disabledAlpha = ta.getFloat(0, 0.30f);
+ defaultColor = multiplyAlphaComponent(activatedColor, disabledAlpha);
+ }
+
+ if (activatedColor == 0 || defaultColor == 0) {
+ // We somehow failed to obtain the colors.
+ return null;
+ }
+
+ final int[][] stateSet = new int[][] {{ R.attr.state_activated }, {}};
+ final int[] colors = new int[] { activatedColor, defaultColor };
+ return new ColorStateList(stateSet, colors);
+ }
+
+ private int multiplyAlphaComponent(int color, float alphaMod) {
+ final int srcRgb = color & 0xFFFFFF;
+ final int srcAlpha = (color >> 24) & 0xFF;
+ final int dstAlpha = (int) (srcAlpha * alphaMod + 0.5f);
+ return srcRgb | (dstAlpha << 24);
+ }
+
private static class ClickActionDelegate extends AccessibilityDelegate {
private final AccessibilityAction mClickAction;
@@ -604,12 +668,12 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
private void updateAmPmLabelStates(int amOrPm) {
final boolean isAm = amOrPm == AM;
+ mAmLabel.setActivated(isAm);
mAmLabel.setChecked(isAm);
- mAmLabel.setSelected(isAm);
final boolean isPm = amOrPm == PM;
+ mPmLabel.setActivated(isPm);
mPmLabel.setChecked(isPm);
- mPmLabel.setSelected(isPm);
}
/**
@@ -769,8 +833,8 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
}
}
- mHourView.setSelected(index == HOUR_INDEX);
- mMinuteView.setSelected(index == MINUTE_INDEX);
+ mHourView.setActivated(index == HOUR_INDEX);
+ mMinuteView.setActivated(index == MINUTE_INDEX);
}
private void setAmOrPm(int amOrPm) {
@@ -960,9 +1024,9 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
String minuteStr = (values[1] == -1) ? mDoublePlaceholderText :
String.format(minuteFormat, values[1]).replace(' ', mPlaceholderText);
mHourView.setText(hourStr);
- mHourView.setSelected(false);
+ mHourView.setActivated(false);
mMinuteView.setText(minuteStr);
- mMinuteView.setSelected(false);
+ mMinuteView.setActivated(false);
if (!mIs24HourView) {
updateAmPmLabelStates(values[2]);
}