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

Commit 370a1b50 authored by Clara Bayarri's avatar Clara Bayarri
Browse files

Fix unsupported api usage in NumberPicker

There is unsupported access to the divider. Exposing the
drawable will be tricky as the widget counts on the drawable
being a certain shape and have certain attributes. However we can
easily expose the thickness as a new attribute and document that
you can customize the divider color via XML.

Bug: 117520784
Test: atest NumberPickerTest (with new test)
Change-Id: Ib7a65c055df3b1f68c8327943fa887c89f57e00c
parent 0ba5e3d6
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1201,6 +1201,7 @@ package android {
    field public static final int selectableItemBackgroundBorderless = 16843868; // 0x101045c
    field public static final deprecated int selectedDateVerticalBar = 16843591; // 0x1010347
    field public static final deprecated int selectedWeekBackgroundColor = 16843586; // 0x1010342
    field public static final int selectionDividerHeight = 16844190; // 0x101059e
    field public static final int sessionService = 16843837; // 0x101043d
    field public static final int settingsActivity = 16843301; // 0x1010225
    field public static final int settingsSliceUri = 16844179; // 0x1010593
@@ -54578,6 +54579,7 @@ package android.widget {
    method public java.lang.String[] getDisplayedValues();
    method public int getMaxValue();
    method public int getMinValue();
    method public int getSelectionDividerHeight();
    method public int getValue();
    method public boolean getWrapSelectorWheel();
    method public void setDisplayedValues(java.lang.String[]);
@@ -54587,6 +54589,7 @@ package android.widget {
    method public void setOnLongPressUpdateInterval(long);
    method public void setOnScrollListener(android.widget.NumberPicker.OnScrollListener);
    method public void setOnValueChangedListener(android.widget.NumberPicker.OnValueChangeListener);
    method public void setSelectionDividerHeight(int);
    method public void setValue(int);
    method public void setWrapSelectorWheel(boolean);
  }
+34 −3
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.widget;

import android.annotation.CallSuper;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.Px;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.annotation.Widget;
@@ -30,6 +32,7 @@ import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.InputType;
@@ -88,6 +91,16 @@ import java.util.Locale;
 * of the current value. Tapping on the current value allows to type in a
 * desired value.
 * </li>
 * <li>
 * If the current theme is derived from {@link android.R.style#Theme_Material}
 * the widget presents the current value as a scrolling vertical selector with
 * the selected value in the center and the previous and following numbers above
 * and below, separated by a divider. The value is changed by flinging vertically.
 * The thickness of the divider can be changed by using the
 * {@link android.R.attr#selectionDividerHeight} attribute and the color of the
 * divider can be changed by using the
 * {@link android.R.attr#colorControlNormal} attribute.
 * </li>
 * </ul>
 * <p>
 * For an example of using this widget, see {@link android.widget.TimePicker}.
@@ -436,14 +449,14 @@ public class NumberPicker extends LinearLayout {
    /**
     * Divider for showing item to be selected while scrolling
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
    private final Drawable mSelectionDivider;

    /**
     * The height of the selection divider.
     */
    @UnsupportedAppUsage
    private final int mSelectionDividerHeight;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
    private int mSelectionDividerHeight;

    /**
     * The current scroll state of the number picker.
@@ -1556,6 +1569,24 @@ public class NumberPicker extends LinearLayout {
        return mSelectorIndexToStringCache.get(getValue());
    }

    /**
     * Set the height for the divider that separates the currently selected value from the others.
     * @param height The height to be set
     */
    public void setSelectionDividerHeight(@IntRange(from = 0) @Px int height) {
        mSelectionDividerHeight = height;
        invalidate();
    }

    /**
     * Retrieve the height for the divider that separates the currently selected value from the
     * others.
     * @return The height of the divider
     */
    public int getSelectionDividerHeight() {
        return mSelectionDividerHeight;
    }

    @Override
    protected float getTopFadingEdgeStrength() {
        return TOP_AND_BOTTOM_FADING_EDGE_STRENGTH;
+1 −1
Original line number Diff line number Diff line
@@ -5532,7 +5532,7 @@
        <attr name="solidColor" format="color|reference" />
        <!-- @hide The divider for making the selection area. -->
        <attr name="selectionDivider" format="reference" />
        <!-- @hide The height of the selection divider. -->
        <!-- The height of the selection divider. -->
        <attr name="selectionDividerHeight" format="dimension" />
        <!-- @hide The distance between the two selection dividers. -->
        <attr name="selectionDividersDistance" format="dimension" />
+1 −0
Original line number Diff line number Diff line
@@ -2928,6 +2928,7 @@
        <public name="dataSharedWithThirdParty" />
        <public name="dataUsedForMonetization" />
        <public name="dataRetentionTime" />
        <public name="selectionDividerHeight" />
    </public-group>

    <public-group type="drawable" first-id="0x010800b4">