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

Commit d7596cff authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Ensure AbsListView's drawable state reflects its actual state"

parents 1cfec7c3 f723c83f
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -577,6 +577,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     */
    private boolean mIsChildViewEnabled;

    /**
     * The cached drawable state for the selector. Accounts for child enabled
     * state, but otherwise identical to the view's own drawable state.
     */
    private int[] mSelectorState;

    /**
     * The last scroll state reported to clients through {@link OnScrollListener}.
     */
@@ -2789,7 +2795,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    void updateSelectorState() {
        if (mSelector != null) {
            if (shouldShowSelector()) {
                mSelector.setState(getDrawableState());
                mSelector.setState(getDrawableStateForSelector());
            } else {
                mSelector.setState(StateSet.NOTHING);
            }
@@ -2802,12 +2808,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        updateSelectorState();
    }

    @Override
    protected int[] onCreateDrawableState(int extraSpace) {
    private int[] getDrawableStateForSelector() {
        // If the child view is enabled then do the default behavior.
        if (mIsChildViewEnabled) {
            // Common case
            return super.onCreateDrawableState(extraSpace);
            return super.getDrawableState();
        }

        // The selector uses this View's drawable state. The selected child view
@@ -2815,10 +2820,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        // states.
        final int enabledState = ENABLED_STATE_SET[0];

        // If we don't have any extra space, it will return one of the static state arrays,
        // and clearing the enabled state on those arrays is a bad thing!  If we specify
        // we need extra space, it will create+copy into a new array that safely mutable.
        int[] state = super.onCreateDrawableState(extraSpace + 1);
        // If we don't have any extra space, it will return one of the static
        // state arrays, and clearing the enabled state on those arrays is a
        // bad thing! If we specify we need extra space, it will create+copy
        // into a new array that is safely mutable.
        final int[] state = onCreateDrawableState(1);

        int enabledPos = -1;
        for (int i = state.length - 1; i >= 0; i--) {
            if (state[i] == enabledState) {