From 9eef3f4fb92d4abd4e217c13cdf72bd4fc3e59f2 Mon Sep 17 00:00:00 2001 From: Craig Stout Date: Mon, 23 Jun 2014 14:13:43 -0700 Subject: NumberPicker fixes for Android TV. Fixed stuck dpad navigation when end of range is reached. Adds theme attribute 'hideWheelUntilFocused'. b/15194230 Change-Id: I9a77c6ad29a1fd930a8920d9944ad1eb15ca6b96 --- core/java/android/widget/NumberPicker.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'core/java/android/widget/NumberPicker.java') diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java index 755bb48f8a21..ee17b782ad3f 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; -- cgit v1.2.3