summaryrefslogtreecommitdiff
path: root/core/java/android/widget/NumberPicker.java
diff options
context:
space:
mode:
authorCraig Stout <cstout@google.com>2014-06-23 14:13:43 -0700
committerCraig Stout <cstout@google.com>2014-07-08 00:10:05 +0000
commit9eef3f4fb92d4abd4e217c13cdf72bd4fc3e59f2 (patch)
tree322b3d8d230558f9f968e5c32b34f5914f13b0bc /core/java/android/widget/NumberPicker.java
parentb1c28c1b03750043dcb254545619c455bb75eb9c (diff)
NumberPicker fixes for Android TV.
Fixed stuck dpad navigation when end of range is reached. Adds theme attribute 'hideWheelUntilFocused'. b/15194230 Change-Id: I9a77c6ad29a1fd930a8920d9944ad1eb15ca6b96
Diffstat (limited to 'core/java/android/widget/NumberPicker.java')
-rw-r--r--core/java/android/widget/NumberPicker.java20
1 files changed, 15 insertions, 5 deletions
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
@@ -478,6 +478,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.
*/
public interface OnValueChangeListener {
@@ -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;