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

Commit f380072e authored by Jiaquan He's avatar Jiaquan He
Browse files

Detect unhandled keyboard focused state.

A View uses a Drawable as its background, which changes
its appearance according to the View's state. This commit
adds an algorithm to detect undefined state_focused in
state specs for those Drawables.

Test: cts-tradefed run singleCommand cts --skip-device-info
--skip-preconditions --abi armeabi-v7a -m CtsGraphicsTestCases
-t android.graphics.drawable.cts.DefaultFocusHighlightTest
Bug: 35096940

Change-Id: I5e9f07141679881fe88f9040aa116ea2f9d537c9
parent bf01a9d1
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ import java.util.Arrays;
 * file. An item with no state spec is considered to match any set of states and is generally
 * useful as a final item to be used as a default.
 * <p>
 * If an item with no state spec if placed before other items, those items
 * If an item with no state spec is placed before other items, those items
 * will be ignored.
 *
 * <a name="ItemAttributes"></a>
@@ -520,6 +520,15 @@ public class ColorStateList extends ComplexColor implements Parcelable {
        return mStateSpecs.length >= 1 && mStateSpecs[0].length > 0;
    }

    /**
     * Return whether the state spec list has at least one item explicitly specifying
     * {@link android.R.attr#state_focused}.
     * @hide
     */
    public boolean hasFocusStateSpecified() {
        return StateSet.containsAttribute(mStateSpecs, R.attr.state_focused);
    }

    /**
     * Indicates whether this color state list is opaque, which means that every
     * color returned from {@link #getColorForState(int[], int)} has an alpha
+23 −0
Original line number Diff line number Diff line
@@ -228,6 +228,29 @@ public class StateSet {
        return true;
    }

    /**
     * Check whether a list of state specs has an attribute specified.
     * @param stateSpecs a list of state specs we're checking.
     * @param attr an attribute we're looking for.
     * @return {@code true} if the attribute is contained in the state specs.
     * @hide
     */
    public static boolean containsAttribute(int[][] stateSpecs, int attr) {
        if (stateSpecs != null) {
            for (int[] spec : stateSpecs) {
                if (spec == null) {
                    break;
                }
                for (int specAttr : spec) {
                    if (specAttr == attr || -specAttr == attr) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public static int[] trimStateSet(int[] states, int newSize) {
        if (states.length == newSize) {
            return states;
+17 −0
Original line number Diff line number Diff line
@@ -725,6 +725,12 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback
        return mLayerState.isStateful();
    }

    /** @hide */
    @Override
    public boolean hasFocusStateSpecified() {
        return mLayerState.hasFocusStateSpecified();
    }

    @Override
    protected boolean onStateChange(int[] state) {
        boolean changed = false;
@@ -1032,6 +1038,17 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback
            return isStateful;
        }

        public final boolean hasFocusStateSpecified() {
            final ChildDrawable[] array = mChildren;
            for (int i = 0; i < N_CHILDREN; i++) {
                final Drawable dr = array[i].mDrawable;
                if (dr != null && dr.hasFocusStateSpecified()) {
                    return true;
                }
            }
            return false;
        }

        public final boolean canConstantState() {
            final ChildDrawable[] array = mChildren;
            for (int i = 0; i < N_CHILDREN; i++) {
+6 −0
Original line number Diff line number Diff line
@@ -737,6 +737,12 @@ public class BitmapDrawable extends Drawable {
                || super.isStateful();
    }

    /** @hide */
    @Override
    public boolean hasFocusStateSpecified() {
        return mBitmapState.mTint != null && mBitmapState.mTint.hasFocusStateSpecified();
    }

    @Override
    public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
            throws XmlPullParserException, IOException {
+6 −0
Original line number Diff line number Diff line
@@ -207,6 +207,12 @@ public class ColorDrawable extends Drawable {
        return mColorState.mTint != null && mColorState.mTint.isStateful();
    }

    /** @hide */
    @Override
    public boolean hasFocusStateSpecified() {
        return mColorState.mTint != null && mColorState.mTint.hasFocusStateSpecified();
    }

    @Override
    public int getOpacity() {
        if (mTintFilter != null || mPaint.getColorFilter() != null) {
Loading