Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9eef3f4f authored by Craig Stout's avatar Craig Stout
Browse files

NumberPicker fixes for Android TV.

Fixed stuck dpad navigation when end of range is reached.
Adds theme attribute 'hideWheelUntilFocused'.

b/15194230

Change-Id: I9a77c6ad29a1fd930a8920d9944ad1eb15ca6b96
parent b1c28c1b
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -4411,6 +4411,8 @@
        <attr name="internalLayout" />
        <!-- @hide The drawable for pressed virtual (increment/decrement) buttons. -->
        <attr name="virtualButtonPressedDrawable" format="reference"/>
        <!-- @hide If true then the selector wheel is hidden until the picker has focus. -->
        <attr name="hideWheelUntilFocused" format="boolean"/>
    </declare-styleable>

    <declare-styleable name="TimePicker">
+3 −0
Original line number Diff line number Diff line
@@ -26,5 +26,8 @@
        <item name="legacyLayout">@layout/time_picker_legacy_leanback</item>
    </style>

    <style name="Widget.Leanback.NumberPicker" parent="Widget.Material.NumberPicker">
        <item name="hideWheelUntilFocused">true</item>
    </style>

</resources>
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
      <item name="textColorPrimary">@color/primary_text_leanback_dark</item>
      <item name="textColorSecondary">@color/secondary_text_leanback_dark</item>
      <item name="alertDialogStyle">@style/AlertDialog.Leanback</item>
      <item name="numberPickerStyle">@style/Widget.Leanback.NumberPicker</item>
    </style>

    <style name="Theme.Leanback.Light.Dialog.Alert" parent="Theme.Material.Light.Dialog.BaseAlert">
@@ -26,6 +27,7 @@
      <item name="textColorPrimary">@color/primary_text_leanback_light</item>
      <item name="textColorSecondary">@color/secondary_text_leanback_light</item>
      <item name="alertDialogStyle">@style/AlertDialog.Leanback.Light</item>
      <item name="numberPickerStyle">@style/Widget.Leanback.NumberPicker</item>
    </style>

    <style name="Theme.Leanback.Dialog.TimePicker" parent="Theme.Material.Dialog.BaseTimePicker">
@@ -34,6 +36,7 @@
      <item name="textColorSecondary">@color/secondary_text_leanback_dark</item>
      <item name="alertDialogStyle">@style/AlertDialog.Leanback</item>
      <item name="timePickerStyle">@style/Widget.Leanback.TimePicker</item>
      <item name="numberPickerStyle">@style/Widget.Leanback.NumberPicker</item>
    </style>

    <style name="Theme.Leanback.Light.Dialog.TimePicker" parent="Theme.Material.Light.Dialog.BaseTimePicker">
@@ -42,6 +45,7 @@
      <item name="textColorSecondary">@color/secondary_text_leanback_light</item>
      <item name="alertDialogStyle">@style/AlertDialog.Leanback.Light</item>
      <item name="timePickerStyle">@style/Widget.Leanback.TimePicker</item>
      <item name="numberPickerStyle">@style/Widget.Leanback.NumberPicker</item>
    </style>

    <style name="Theme.Leanback.Light.Dialog" parent="Theme.Material.Light.Dialog">