diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/TimePickerDialog.java | 80 | ||||
| -rw-r--r-- | core/java/android/content/res/ColorStateList.java | 40 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 8 | ||||
| -rwxr-xr-x | core/java/android/widget/DatePickerCalendarDelegate.java | 11 | ||||
| -rw-r--r-- | core/java/android/widget/RadialTimePickerView.java | 3 | ||||
| -rw-r--r-- | core/java/android/widget/RelativeLayout.java | 19 | ||||
| -rw-r--r-- | core/java/android/widget/TimePickerClockDelegate.java | 38 |
7 files changed, 92 insertions, 107 deletions
diff --git a/core/java/android/app/TimePickerDialog.java b/core/java/android/app/TimePickerDialog.java index 3a2c21b13dfd..a3b3022fc69c 100644 --- a/core/java/android/app/TimePickerDialog.java +++ b/core/java/android/app/TimePickerDialog.java @@ -31,20 +31,21 @@ import android.widget.TimePicker.ValidationCallback; import com.android.internal.R; /** - * A dialog that prompts the user for the time of day using a {@link TimePicker}. + * A dialog that prompts the user for the time of day using a + * {@link TimePicker}. * - * <p>See the <a href="{@docRoot}guide/topics/ui/controls/pickers.html">Pickers</a> - * guide.</p> + * <p> + * See the <a href="{@docRoot}guide/topics/ui/controls/pickers.html">Pickers</a> + * guide. */ public class TimePickerDialog extends AlertDialog implements OnClickListener, OnTimeChangedListener { - private static final String HOUR = "hour"; private static final String MINUTE = "minute"; private static final String IS_24_HOUR = "is24hour"; private final TimePicker mTimePicker; - private final OnTimeSetListener mTimeSetCallback; + private final OnTimeSetListener mTimeSetListener; private final int mInitialHourOfDay; private final int mInitialMinute; @@ -52,59 +53,70 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, /** * The callback interface used to indicate the user is done filling in - * the time (they clicked on the 'Done' button). + * the time (e.g. they clicked on the 'OK' button). */ public interface OnTimeSetListener { - /** - * @param view The view associated with this listener. - * @param hourOfDay The hour that was set. - * @param minute The minute that was set. + * Called when the user is done setting a new time and the dialog has + * closed. + * + * @param view the view associated with this listener + * @param hourOfDay the hour that was set + * @param minute the minute that was set */ - void onTimeSet(TimePicker view, int hourOfDay, int minute); + public void onTimeSet(TimePicker view, int hourOfDay, int minute); } /** - * @param context Parent. - * @param callBack How parent is notified. - * @param hourOfDay The initial hour. - * @param minute The initial minute. - * @param is24HourView Whether this is a 24 hour view, or AM/PM. + * Creates a new time picker dialog. + * + * @param context the parent context + * @param listener the listener to call when the time is set + * @param hourOfDay the initial hour + * @param minute the initial minute + * @param is24HourView whether this is a 24 hour view or AM/PM */ - public TimePickerDialog(Context context, - OnTimeSetListener callBack, - int hourOfDay, int minute, boolean is24HourView) { - this(context, 0, callBack, hourOfDay, minute, is24HourView); + public TimePickerDialog(Context context, OnTimeSetListener listener, int hourOfDay, int minute, + boolean is24HourView) { + this(context, 0, listener, hourOfDay, minute, is24HourView); } - static int resolveDialogTheme(Context context, int resid) { - if (resid == 0) { + static int resolveDialogTheme(Context context, int resId) { + if (resId == 0) { final TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.timePickerDialogTheme, outValue, true); return outValue.resourceId; } else { - return resid; + return resId; } } /** - * @param context Parent. - * @param theme the theme to apply to this dialog - * @param callBack How parent is notified. - * @param hourOfDay The initial hour. - * @param minute The initial minute. + * Creates a new time picker dialog with the specified theme. + * + * @param context the parent context + * @param themeResId the resource ID of the theme to apply to this dialog + * @param listener the listener to call when the time is set + * @param hourOfDay the initial hour + * @param minute the initial minute * @param is24HourView Whether this is a 24 hour view, or AM/PM. */ - public TimePickerDialog(Context context, int theme, OnTimeSetListener callBack, int hourOfDay, - int minute, boolean is24HourView) { - super(context, resolveDialogTheme(context, theme)); + public TimePickerDialog(Context context, int themeResId, OnTimeSetListener listener, + int hourOfDay, int minute, boolean is24HourView) { + super(context, resolveDialogTheme(context, themeResId)); - mTimeSetCallback = callBack; + mTimeSetListener = listener; mInitialHourOfDay = hourOfDay; mInitialMinute = minute; mIs24HourView = is24HourView; final Context themeContext = getContext(); + + + final TypedValue outValue = new TypedValue(); + context.getTheme().resolveAttribute(R.attr.timePickerDialogTheme, outValue, true); + final int layoutResId = outValue.resourceId; + final LayoutInflater inflater = LayoutInflater.from(themeContext); final View view = inflater.inflate(R.layout.time_picker_dialog, null); setView(view); @@ -129,8 +141,8 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, public void onClick(DialogInterface dialog, int which) { switch (which) { case BUTTON_POSITIVE: - if (mTimeSetCallback != null) { - mTimeSetCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(), + if (mTimeSetListener != null) { + mTimeSetListener.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute()); } break; diff --git a/core/java/android/content/res/ColorStateList.java b/core/java/android/content/res/ColorStateList.java index b42d8bcb9c4e..ace402a2b1f7 100644 --- a/core/java/android/content/res/ColorStateList.java +++ b/core/java/android/content/res/ColorStateList.java @@ -462,46 +462,6 @@ public class ColorStateList implements Parcelable { return mColors; } - /** - * If the color state list does not already have an entry matching the - * specified state, prepends a state set and color pair to a color state - * list. - * <p> - * This is a workaround used in TimePicker and DatePicker until we can - * add support for theme attributes in ColorStateList. - * - * @param colorStateList the source color state list - * @param state the state to prepend - * @param color the color to use for the given state - * @return a new color state list, or the source color state list if there - * was already a matching state set - * - * @hide Remove when we can support theme attributes. - */ - public static ColorStateList addFirstIfMissing( - ColorStateList colorStateList, int state, int color) { - final int[][] inputStates = colorStateList.getStates(); - for (int i = 0; i < inputStates.length; i++) { - final int[] inputState = inputStates[i]; - for (int j = 0; j < inputState.length; j++) { - if (inputState[j] == state) { - return colorStateList; - } - } - } - - final int[][] outputStates = new int[inputStates.length + 1][]; - System.arraycopy(inputStates, 0, outputStates, 1, inputStates.length); - outputStates[0] = new int[] { state }; - - final int[] inputColors = colorStateList.getColors(); - final int[] outputColors = new int[inputColors.length + 1]; - System.arraycopy(inputColors, 0, outputColors, 1, inputColors.length); - outputColors[0] = color; - - return new ColorStateList(outputStates, outputColors); - } - @Override public String toString() { return "ColorStateList{" + diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 71baa437b4a7..5ee3c16c8ace 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -10047,6 +10047,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @return The measured width of this view as a bit mask. */ + @ViewDebug.ExportedProperty(category = "measurement", flagMapping = { + @ViewDebug.FlagToString(mask = MEASURED_STATE_MASK, equals = MEASURED_STATE_TOO_SMALL, + name = "MEASURED_STATE_TOO_SMALL"), + }) public final int getMeasuredWidthAndState() { return mMeasuredWidth; } @@ -10071,6 +10075,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @return The measured width of this view as a bit mask. */ + @ViewDebug.ExportedProperty(category = "measurement", flagMapping = { + @ViewDebug.FlagToString(mask = MEASURED_STATE_MASK, equals = MEASURED_STATE_TOO_SMALL, + name = "MEASURED_STATE_TOO_SMALL"), + }) public final int getMeasuredHeightAndState() { return mMeasuredHeight; } diff --git a/core/java/android/widget/DatePickerCalendarDelegate.java b/core/java/android/widget/DatePickerCalendarDelegate.java index 42bc7f2ee7cf..3568522e1a6f 100755 --- a/core/java/android/widget/DatePickerCalendarDelegate.java +++ b/core/java/android/widget/DatePickerCalendarDelegate.java @@ -154,34 +154,23 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i dateLayout.setBackground(a.getDrawable(R.styleable.DatePicker_headerBackground)); - final int headerSelectedTextColor = a.getColor( - R.styleable.DatePicker_headerSelectedTextColor, defaultHighlightColor); final int monthTextAppearanceResId = a.getResourceId( R.styleable.DatePicker_headerMonthTextAppearance, 0); if (monthTextAppearanceResId != 0) { mHeaderMonthTextView.setTextAppearance(context, monthTextAppearanceResId); } - mHeaderMonthTextView.setTextColor(ColorStateList.addFirstIfMissing( - mHeaderMonthTextView.getTextColors(), R.attr.state_selected, - headerSelectedTextColor)); final int dayOfMonthTextAppearanceResId = a.getResourceId( 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 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, - headerSelectedTextColor)); mDayPickerView = new DayPickerView(mContext); mDayPickerView.setFirstDayOfWeek(mFirstDayOfWeek); diff --git a/core/java/android/widget/RadialTimePickerView.java b/core/java/android/widget/RadialTimePickerView.java index dc4d93201d88..28b4db251302 100644 --- a/core/java/android/widget/RadialTimePickerView.java +++ b/core/java/android/widget/RadialTimePickerView.java @@ -157,6 +157,7 @@ public class RadialTimePickerView extends View { private boolean mIsOnInnerCircle; private int mSelectorRadius; + private int mSelectorStroke; private int mSelectorDotRadius; private int mCenterDotRadius; @@ -377,6 +378,7 @@ public class RadialTimePickerView extends View { mPaintBackground.setAntiAlias(true); mSelectorRadius = res.getDimensionPixelSize(R.dimen.timepicker_selector_radius); + mSelectorStroke = res.getDimensionPixelSize(R.dimen.timepicker_selector_stroke); mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.timepicker_selector_dot_radius); mCenterDotRadius = res.getDimensionPixelSize(R.dimen.timepicker_center_dot_radius); @@ -772,6 +774,7 @@ public class RadialTimePickerView extends View { 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); } diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java index fef56b888e2b..6166c02e231e 100644 --- a/core/java/android/widget/RelativeLayout.java +++ b/core/java/android/widget/RelativeLayout.java @@ -1358,6 +1358,7 @@ public class RelativeLayout extends ViewGroup { * {@link android.widget.RelativeLayout RelativeLayout}, such as * ALIGN_WITH_PARENT_LEFT. * @see #addRule(int, int) + * @see #getRule(int) */ public void addRule(int verb) { mRules[verb] = TRUE; @@ -1378,6 +1379,7 @@ public class RelativeLayout extends ViewGroup { * for true or 0 for false). For verbs that don't refer to another sibling * (for example, ALIGN_WITH_PARENT_BOTTOM) just use -1. * @see #addRule(int) + * @see #getRule(int) */ public void addRule(int verb, int anchor) { mRules[verb] = anchor; @@ -1393,6 +1395,7 @@ public class RelativeLayout extends ViewGroup { * ALIGN_WITH_PARENT_LEFT. * @see #addRule(int) * @see #addRule(int, int) + * @see #getRule(int) */ public void removeRule(int verb) { mRules[verb] = 0; @@ -1400,6 +1403,22 @@ public class RelativeLayout extends ViewGroup { mRulesChanged = true; } + /** + * Returns the layout rule associated with a specific verb. + * + * @param verb one of the verbs defined by {@link RelativeLayout}, such + * as ALIGN_WITH_PARENT_LEFT + * @return the id of another view to use as an anchor, a boolean value + * (represented as {@link RelativeLayout#TRUE} for true + * or 0 for false), or -1 for verbs that don't refer to another + * sibling (for example, ALIGN_WITH_PARENT_BOTTOM) + * @see #addRule(int) + * @see #addRule(int, int) + */ + public int getRule(int verb) { + return mRules[verb]; + } + private boolean hasRelativeRules() { return (mInitialRules[START_OF] != 0 || mInitialRules[END_OF] != 0 || mInitialRules[ALIGN_START] != 0 || mInitialRules[ALIGN_END] != 0 || diff --git a/core/java/android/widget/TimePickerClockDelegate.java b/core/java/android/widget/TimePickerClockDelegate.java index ed052afc4cf1..3b88b21656d1 100644 --- a/core/java/android/widget/TimePickerClockDelegate.java +++ b/core/java/android/widget/TimePickerClockDelegate.java @@ -132,19 +132,19 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl mPmText = amPmStrings[1]; final int layoutResourceId = a.getResourceId(R.styleable.TimePicker_internalLayout, - R.layout.time_picker_holo); + R.layout.time_picker_material); 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) mHeaderView.findViewById(R.id.hours); + mHourView = (TextView) mainView.findViewById(R.id.hours); mHourView.setOnClickListener(mClickListener); mHourView.setAccessibilityDelegate( new ClickActionDelegate(context, R.string.select_hours)); - mSeparatorView = (TextView) mHeaderView.findViewById(R.id.separator); - mMinuteView = (TextView) mHeaderView.findViewById(R.id.minutes); + mSeparatorView = (TextView) mainView.findViewById(R.id.separator); + mMinuteView = (TextView) mainView.findViewById(R.id.minutes); mMinuteView.setOnClickListener(mClickListener); mMinuteView.setAccessibilityDelegate( new ClickActionDelegate(context, R.string.select_minutes)); @@ -162,17 +162,8 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl mHourView.setMinWidth(computeStableWidth(mHourView, 24)); mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60)); - // TODO: This can be removed once we support themed color state lists. - 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)); - // Set up AM/PM labels. - mAmPmLayout = mHeaderView.findViewById(R.id.ampm_layout); + mAmPmLayout = mainView.findViewById(R.id.ampm_layout); mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label); mAmLabel.setText(amPmStrings[0]); mAmLabel.setOnClickListener(mClickListener); @@ -304,12 +295,15 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mAmPmLayout.getLayoutParams(); - if (isAmPmAtStart) { - params.removeRule(RelativeLayout.RIGHT_OF); - params.addRule(RelativeLayout.LEFT_OF, mHourView.getId()); - } else { - params.removeRule(RelativeLayout.LEFT_OF); - params.addRule(RelativeLayout.RIGHT_OF, mMinuteView.getId()); + if (params.getRule(RelativeLayout.RIGHT_OF) != 0 || + params.getRule(RelativeLayout.LEFT_OF) != 0) { + if (isAmPmAtStart) { + params.removeRule(RelativeLayout.RIGHT_OF); + params.addRule(RelativeLayout.LEFT_OF, mHourView.getId()); + } else { + params.removeRule(RelativeLayout.LEFT_OF); + params.addRule(RelativeLayout.RIGHT_OF, mMinuteView.getId()); + } } mAmPmLayout.setLayoutParams(params); @@ -613,11 +607,11 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private void updateAmPmLabelStates(int amOrPm) { final boolean isAm = amOrPm == AM; mAmLabel.setChecked(isAm); - mAmLabel.setAlpha(isAm ? 1 : mDisabledAlpha); + mAmLabel.setSelected(isAm); final boolean isPm = amOrPm == PM; mPmLabel.setChecked(isPm); - mPmLabel.setAlpha(isPm ? 1 : mDisabledAlpha); + mPmLabel.setSelected(isPm); } /** |
