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

Commit 11a57f22 authored by Daniel Santiago Rivera's avatar Daniel Santiago Rivera
Browse files

Restrict reflection access to NumberPickers's mSelectionWheelPaint

Applications reflecting into mSelectionWheelPaint do it because there is
no API for correctly updating the text size and color at runtime. Since
the NumberPicker is composed of an EditText and an additional paint to
draw the scroll wheel numbers, developers found themselves reflecting
on the paint since updating the EditText child is not enough.

This CL restrict access to mSelectionWheelPaint but add an alternative
API for updating the NumberPicker's text size and color at runtime.

Bug: 123769712
Test: NumberPickerTest
Change-Id: I9f5a0275916a6852a6378e5ffae5a9a171b9cd51
parent 51a197d0
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -56197,6 +56197,8 @@ package android.widget {
    method public int getMaxValue();
    method public int getMinValue();
    method public int getSelectionDividerHeight();
    method @ColorInt public int getTextColor();
    method @FloatRange(from=0.0, fromInclusive=false) public float getTextSize();
    method public int getValue();
    method public boolean getWrapSelectorWheel();
    method public void setDisplayedValues(String[]);
@@ -56207,6 +56209,8 @@ package android.widget {
    method public void setOnScrollListener(android.widget.NumberPicker.OnScrollListener);
    method public void setOnValueChangedListener(android.widget.NumberPicker.OnValueChangeListener);
    method public void setSelectionDividerHeight(@IntRange(from=0) @Px int);
    method public void setTextColor(@ColorInt int);
    method public void setTextSize(@FloatRange(from=0.0, fromInclusive=false) float);
    method public void setValue(int);
    method public void setWrapSelectorWheel(boolean);
  }
+41 −1
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package android.widget;

import android.annotation.CallSuper;
import android.annotation.ColorInt;
import android.annotation.FloatRange;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.Px;
@@ -340,7 +342,7 @@ public class NumberPicker extends LinearLayout {
    /**
     * The {@link Paint} for drawing the selector.
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
    private final Paint mSelectorWheelPaint;

    /**
@@ -1715,6 +1717,44 @@ public class NumberPicker extends LinearLayout {
        return mAccessibilityNodeProvider;
    }

    /**
     * Sets the text color for all the states (normal, selected, focused) to be the given color.
     *
     * @param color A color value in the form 0xAARRGGBB.
     */
    public void setTextColor(@ColorInt int color) {
        mSelectorWheelPaint.setColor(color);
        mInputText.setTextColor(color);
        invalidate();
    }

    /**
     * @return the text color.
     */
    @ColorInt
    public int getTextColor() {
        return mSelectorWheelPaint.getColor();
    }

    /**
     * Sets the text size to the given value. This value must be > 0
     *
     * @param size The size in pixel units.
     */
    public void setTextSize(@FloatRange(from = 0.0, fromInclusive = false) float size) {
        mSelectorWheelPaint.setTextSize(size);
        mInputText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
        invalidate();
    }

    /**
     * @return the size (in pixels) of the text size in this NumberPicker.
     */
    @FloatRange(from = 0.0, fromInclusive = false)
    public float getTextSize() {
        return mSelectorWheelPaint.getTextSize();
    }

    /**
     * Makes a measure spec that tries greedily to use the max value.
     *