diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java index 755bb48f8a216..ee17b782ad3f9 100644 --- a/core/java/android/widget/NumberPicker.java +++ b/core/java/android/widget/NumberPicker.java @@ -477,6 +477,11 @@ public class NumberPicker extends LinearLayout { */ private int mLastHandledDownDpadKeyCode = -1; + /** + * If true then the selector wheel is hidden until the picker has focus. + */ + private boolean mHideWheelUntilFocused; + /** * Interface to listen for changes of the current value. */ @@ -598,6 +603,9 @@ public class NumberPicker extends LinearLayout { mHasSelectorWheel = (layoutResId != DEFAULT_LAYOUT_RESOURCE_ID); + mHideWheelUntilFocused = attributesArray.getBoolean( + R.styleable.NumberPicker_hideWheelUntilFocused, false); + mSolidColor = attributesArray.getColor(R.styleable.NumberPicker_solidColor, 0); mSelectionDivider = attributesArray.getDrawable(R.styleable.NumberPicker_selectionDivider); @@ -974,8 +982,8 @@ public class NumberPicker extends LinearLayout { } switch (event.getAction()) { case KeyEvent.ACTION_DOWN: - if (mWrapSelectorWheel || (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) - ? getValue() < getMaxValue() : getValue() > getMinValue()) { + if (mWrapSelectorWheel || ((keyCode == KeyEvent.KEYCODE_DPAD_DOWN) + ? getValue() < getMaxValue() : getValue() > getMinValue())) { requestFocus(); mLastHandledDownDpadKeyCode = keyCode; removeAllCallbacks(); @@ -1497,11 +1505,12 @@ public class NumberPicker extends LinearLayout { super.onDraw(canvas); return; } + final boolean showSelectorWheel = mHideWheelUntilFocused ? hasFocus() : true; float x = (mRight - mLeft) / 2; float y = mCurrentScrollOffset; // draw the virtual buttons pressed state if needed - if (mVirtualButtonPressedDrawable != null + if (showSelectorWheel && mVirtualButtonPressedDrawable != null && mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { if (mDecrementVirtualButtonPressed) { mVirtualButtonPressedDrawable.setState(PRESSED_STATE_SET); @@ -1526,14 +1535,15 @@ public class NumberPicker extends LinearLayout { // item. Otherwise, if the user starts editing the text via the // IME he may see a dimmed version of the old value intermixed // with the new one. - if (i != SELECTOR_MIDDLE_ITEM_INDEX || mInputText.getVisibility() != VISIBLE) { + if ((showSelectorWheel && i != SELECTOR_MIDDLE_ITEM_INDEX) || + (i == SELECTOR_MIDDLE_ITEM_INDEX && mInputText.getVisibility() != VISIBLE)) { canvas.drawText(scrollSelectorValue, x, y, mSelectorWheelPaint); } y += mSelectorElementHeight; } // draw the selection dividers - if (mSelectionDivider != null) { + if (showSelectorWheel && mSelectionDivider != null) { // draw the top divider int topOfTopDivider = mTopSelectionDividerTop; int bottomOfTopDivider = topOfTopDivider + mSelectionDividerHeight; diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 44125b025d18a..93bc616f892d9 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -4411,6 +4411,8 @@ + + diff --git a/core/res/res/values/styles_leanback.xml b/core/res/res/values/styles_leanback.xml index ff9d73f8a5e4c..6f9a88e0510ff 100644 --- a/core/res/res/values/styles_leanback.xml +++ b/core/res/res/values/styles_leanback.xml @@ -26,5 +26,8 @@ @layout/time_picker_legacy_leanback + diff --git a/core/res/res/values/themes_leanback.xml b/core/res/res/values/themes_leanback.xml index 15ae14c8f4780..6f6385b1f7e3c 100644 --- a/core/res/res/values/themes_leanback.xml +++ b/core/res/res/values/themes_leanback.xml @@ -19,6 +19,7 @@ @color/primary_text_leanback_dark @color/secondary_text_leanback_dark @style/AlertDialog.Leanback + @style/Widget.Leanback.NumberPicker