diff options
author | Alan Viverette <alanv@google.com> | 2014-11-12 09:31:22 -0800 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-11-12 09:31:22 -0800 |
commit | d9f3fdf45bd3e3b5b02f2d21b6df6598cbaf1c70 (patch) | |
tree | 705061fa918a2fa78e35dc3a0518382027226f4b /core/java/android | |
parent | e6ef98cf0528cbc2722b979e5ad86ba859fa78b0 (diff) | |
download | frameworks_base-d9f3fdf45bd3e3b5b02f2d21b6df6598cbaf1c70.zip frameworks_base-d9f3fdf45bd3e3b5b02f2d21b6df6598cbaf1c70.tar.gz frameworks_base-d9f3fdf45bd3e3b5b02f2d21b6df6598cbaf1c70.tar.bz2 |
Ensure time picker dialog fits on small screens
Also fixes dialog padding in landscape mode and a bug in the
ColorStateList method used to apply a selected color.
BUG: 18251582
Change-Id: Id5b8c7893ec42fd4d5f4a7520e6ac170839d3143
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/content/res/ColorStateList.java | 2 | ||||
-rw-r--r-- | core/java/android/widget/TimePickerClockDelegate.java | 72 |
2 files changed, 32 insertions, 42 deletions
diff --git a/core/java/android/content/res/ColorStateList.java b/core/java/android/content/res/ColorStateList.java index 3c290f7..68a39d3 100644 --- a/core/java/android/content/res/ColorStateList.java +++ b/core/java/android/content/res/ColorStateList.java @@ -353,7 +353,7 @@ public class ColorStateList implements Parcelable { for (int i = 0; i < inputStates.length; i++) { final int[] inputState = inputStates[i]; for (int j = 0; j < inputState.length; j++) { - if (inputState[i] == state) { + if (inputState[j] == state) { return colorStateList; } } diff --git a/core/java/android/widget/TimePickerClockDelegate.java b/core/java/android/widget/TimePickerClockDelegate.java index 78ee247..5592af0 100644 --- a/core/java/android/widget/TimePickerClockDelegate.java +++ b/core/java/android/widget/TimePickerClockDelegate.java @@ -23,7 +23,6 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.os.Parcel; import android.os.Parcelable; -import android.text.TextUtils; import android.text.format.DateFormat; import android.text.format.DateUtils; import android.util.AttributeSet; @@ -100,9 +99,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private int mPmKeyCode; // Accessibility strings. - private String mHourPickerDescription; private String mSelectHours; - private String mMinutePickerDescription; private String mSelectMinutes; // Most recent time announcement values for accessibility. @@ -122,9 +119,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl Context.LAYOUT_INFLATER_SERVICE); final Resources res = mContext.getResources(); - mHourPickerDescription = res.getString(R.string.hour_picker_description); mSelectHours = res.getString(R.string.select_hours); - mMinutePickerDescription = res.getString(R.string.minute_picker_description); mSelectMinutes = res.getString(R.string.select_minutes); String[] amPmStrings = TimePickerSpinnerDelegate.getAmPmStrings(context); @@ -153,6 +148,11 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl 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)); + 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, @@ -206,6 +206,23 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX); } + private int computeStableWidth(TextView v, int maxNumber) { + int maxWidth = 0; + + for (int i = 0; i < maxNumber; i++) { + final String text = String.format("%02d", i); + v.setText(text); + v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); + + final int width = v.getMeasuredWidth(); + if (width > maxWidth) { + maxWidth = width; + } + } + + return maxWidth; + } + private void initialize(int hourOfDay, int minute, boolean is24HourView, int index) { mInitialHourOfDay = hourOfDay; mInitialMinute = minute; @@ -242,48 +259,21 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl setCurrentItemShowing(index, false, true); } - private int computeMaxWidthOfNumbers(int max) { - TextView tempView = new TextView(mContext); - tempView.setTextAppearance(mContext, R.style.TextAppearance_Material_TimePicker_TimeLabel); - ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT); - tempView.setLayoutParams(lp); - int maxWidth = 0; - for (int minutes = 0; minutes < max; minutes++) { - final String text = String.format("%02d", minutes); - tempView.setText(text); - tempView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); - maxWidth = Math.max(maxWidth, tempView.getMeasuredWidth()); - } - return maxWidth; - } - private void updateHeaderAmPm() { if (mIs24HourView) { mAmPmLayout.setVisibility(View.GONE); } else { - final String bestDateTimePattern = DateFormat.getBestDateTimePattern( - mCurrentLocale, "hm"); - boolean amPmOnLeft = bestDateTimePattern.startsWith("a"); - if (TextUtils.getLayoutDirectionFromLocale(mCurrentLocale) == - View.LAYOUT_DIRECTION_RTL) { - amPmOnLeft = !amPmOnLeft; + // Ensure that AM/PM layout is in the correct position. + final String dateTimePattern = DateFormat.getBestDateTimePattern(mCurrentLocale, "hm"); + final boolean amPmAtStart = dateTimePattern.startsWith("a"); + final ViewGroup parent = (ViewGroup) mAmPmLayout.getParent(); + final int targetIndex = amPmAtStart ? 0 : parent.getChildCount() - 1; + final int currentIndex = parent.indexOfChild(mAmPmLayout); + if (targetIndex != currentIndex) { + parent.removeView(mAmPmLayout); + parent.addView(mAmPmLayout, targetIndex); } - final ViewGroup.MarginLayoutParams params = - (ViewGroup.MarginLayoutParams) mAmPmLayout.getLayoutParams(); - - if (amPmOnLeft) { - params.leftMargin = 0; - params.rightMargin = computeMaxWidthOfNumbers(12 /* for hours */); - } else { - params.leftMargin = computeMaxWidthOfNumbers(60 /* for minutes */); - params.rightMargin = 0; - } - - mAmPmLayout.setLayoutParams(params); - mAmPmLayout.setVisibility(View.VISIBLE); - updateAmPmLabelStates(mInitialHourOfDay < 12 ? AM : PM); } } |