Skip to content

Commit 2f504d9

Browse files
sganovAndroid (Google) Code Review
authored andcommitted
Merge "NumberPicker incorrectly shown for the old theme." into ics-mr1
2 parents db904b4 + 9f086d8 commit 2f504d9

File tree

4 files changed

+52
-19
lines changed

4 files changed

+52
-19
lines changed

core/java/android/app/DatePickerDialog.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ public DatePickerDialog(Context context,
9191

9292
mCallBack = callBack;
9393

94-
setButton(BUTTON_POSITIVE, context.getText(R.string.date_time_set), this);
95-
setButton(BUTTON_NEGATIVE, context.getText(R.string.cancel), (OnClickListener) null);
94+
Context themeContext = getContext();
95+
setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_set), this);
96+
setButton(BUTTON_NEGATIVE, themeContext.getText(R.string.cancel), (OnClickListener) null);
9697
setIcon(0);
9798
setTitle(R.string.date_picker_dialog_title);
9899

99100
LayoutInflater inflater =
100-
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
101+
(LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
101102
View view = inflater.inflate(R.layout.date_picker_dialog, null);
102103
setView(view);
103104
mDatePicker = (DatePicker) view.findViewById(R.id.datePicker);

core/java/android/app/TimePickerDialog.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ public TimePickerDialog(Context context,
9292
mInitialMinute = minute;
9393
mIs24HourView = is24HourView;
9494

95-
setCanceledOnTouchOutside(false);
9695
setIcon(0);
9796
setTitle(R.string.time_picker_dialog_title);
9897

99-
setButton(BUTTON_POSITIVE, context.getText(R.string.date_time_set), this);
100-
setButton(BUTTON_NEGATIVE, context.getText(R.string.cancel),
98+
Context themeContext = getContext();
99+
setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_set), this);
100+
setButton(BUTTON_NEGATIVE, themeContext.getText(R.string.cancel),
101101
(OnClickListener) null);
102102

103103
LayoutInflater inflater =
104-
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
104+
(LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
105105
View view = inflater.inflate(R.layout.time_picker_dialog, null);
106106
setView(view);
107107
mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);

core/java/android/widget/NumberPicker.java

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ public class NumberPicker extends LinearLayout {
164164
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
165165
};
166166

167+
/**
168+
* Constant for unspecified size.
169+
*/
170+
private static final int SIZE_UNSPECIFIED = -1;
171+
167172
/**
168173
* Use a custom NumberPicker formatting callback to use two-digit minutes
169174
* strings like "01". Keeping a static formatter etc. is the most efficient
@@ -542,16 +547,20 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
542547
getResources().getDisplayMetrics());
543548
mSelectionDividerHeight = attributesArray.getDimensionPixelSize(
544549
R.styleable.NumberPicker_selectionDividerHeight, defSelectionDividerHeight);
545-
mMinHeight = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_minHeight, 0);
550+
mMinHeight = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_minHeight,
551+
SIZE_UNSPECIFIED);
546552
mMaxHeight = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_maxHeight,
547-
Integer.MAX_VALUE);
548-
if (mMinHeight > mMaxHeight) {
553+
SIZE_UNSPECIFIED);
554+
if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED
555+
&& mMinHeight > mMaxHeight) {
549556
throw new IllegalArgumentException("minHeight > maxHeight");
550557
}
551-
mMinWidth = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_minWidth, 0);
558+
mMinWidth = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_minWidth,
559+
SIZE_UNSPECIFIED);
552560
mMaxWidth = attributesArray.getDimensionPixelSize(R.styleable.NumberPicker_maxWidth,
553-
Integer.MAX_VALUE);
554-
if (mMinWidth > mMaxWidth) {
561+
SIZE_UNSPECIFIED);
562+
if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED
563+
&& mMinWidth > mMaxWidth) {
555564
throw new IllegalArgumentException("minWidth > maxWidth");
556565
}
557566
mComputeMaxWidth = (mMaxWidth == Integer.MAX_VALUE);
@@ -746,10 +755,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
746755
final int newHeightMeasureSpec = makeMeasureSpec(heightMeasureSpec, mMaxHeight);
747756
super.onMeasure(newWidthMeasureSpec, newHeightMeasureSpec);
748757
// Flag if we are measured with width or height less than the respective min.
749-
final int desiredWidth = Math.max(mMinWidth, getMeasuredWidth());
750-
final int desiredHeight = Math.max(mMinHeight, getMeasuredHeight());
751-
final int widthSize = resolveSizeAndState(desiredWidth, newWidthMeasureSpec, 0);
752-
final int heightSize = resolveSizeAndState(desiredHeight, newHeightMeasureSpec, 0);
758+
final int widthSize = resolveSizeAndStateRespectingMinSize(mMinWidth, getMeasuredWidth(),
759+
widthMeasureSpec);
760+
final int heightSize = resolveSizeAndStateRespectingMinSize(mMinHeight, getMeasuredHeight(),
761+
heightMeasureSpec);
753762
setMeasuredDimension(widthSize, heightSize);
754763
}
755764

@@ -1243,6 +1252,7 @@ public void setDisplayedValues(String[] displayedValues) {
12431252
}
12441253
updateInputTextView();
12451254
initializeSelectorWheelIndices();
1255+
tryComputeMaxWidth();
12461256
}
12471257

12481258
@Override
@@ -1368,6 +1378,9 @@ public void sendAccessibilityEvent(int eventType) {
13681378
* @return A measure spec greedily imposing the max size.
13691379
*/
13701380
private int makeMeasureSpec(int measureSpec, int maxSize) {
1381+
if (maxSize == SIZE_UNSPECIFIED) {
1382+
return measureSpec;
1383+
}
13711384
final int size = MeasureSpec.getSize(measureSpec);
13721385
final int mode = MeasureSpec.getMode(measureSpec);
13731386
switch (mode) {
@@ -1382,6 +1395,26 @@ private int makeMeasureSpec(int measureSpec, int maxSize) {
13821395
}
13831396
}
13841397

1398+
/**
1399+
* Utility to reconcile a desired size and state, with constraints imposed by
1400+
* a MeasureSpec. Tries to respect the min size, unless a different size is
1401+
* imposed by the constraints.
1402+
*
1403+
* @param minSize The minimal desired size.
1404+
* @param measuredSize The currently measured size.
1405+
* @param measureSpec The current measure spec.
1406+
* @return The resolved size and state.
1407+
*/
1408+
private int resolveSizeAndStateRespectingMinSize(int minSize, int measuredSize,
1409+
int measureSpec) {
1410+
if (minSize != SIZE_UNSPECIFIED) {
1411+
final int desiredWidth = Math.max(minSize, measuredSize);
1412+
return resolveSizeAndState(desiredWidth, measureSpec, 0);
1413+
} else {
1414+
return measuredSize;
1415+
}
1416+
}
1417+
13851418
/**
13861419
* Resets the selector indices and clear the cached
13871420
* string representation of these indices.

core/res/res/layout/date_picker.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<LinearLayout android:id="@+id/pickers"
3333
android:layout_width="wrap_content"
3434
android:layout_height="wrap_content"
35-
android:layout_marginRight="22dip"
3635
android:layout_weight="1"
3736
android:orientation="horizontal"
3837
android:gravity="center">
@@ -77,7 +76,7 @@
7776
android:id="@+id/calendar_view"
7877
android:layout_width="245dip"
7978
android:layout_height="280dip"
80-
android:layout_marginLeft="22dip"
79+
android:layout_marginLeft="44dip"
8180
android:layout_weight="1"
8281
android:focusable="true"
8382
android:focusableInTouchMode="true"

0 commit comments

Comments
 (0)