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

Commit 23114d68 authored by Evan Rosky's avatar Evan Rosky
Browse files

Added redundant focusable attribute read in TextView

Some apps were relying on TextView favoring focusable over
focusableInTouchMode when they were explicitly set to
opposite values in XML (usually because they start with an
EditText and only set focusable=false). This behavior is
undefined (and is, in-fact opposite to every other View).
In order to keep backwards-compatibility, this restores
the old behavior.

Bug: 36497135
Bug: 37916052
Test: Tested those apps and they behave like they used to.
      TextView CTS still passes.

Change-Id: I65bd1b343a6dfb087f41c9fc8af4b5c1e4c71493
parent e96d66db
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -1639,12 +1639,21 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        boolean canInputOrMove = (mMovement != null || getKeyListener() != null);
        boolean clickable = canInputOrMove || isClickable();
        boolean longClickable = canInputOrMove || isLongClickable();
        int focusable = getFocusable();

        n = a.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);

            switch (attr) {
                case com.android.internal.R.styleable.View_focusable:
                    TypedValue val = new TypedValue();
                    if (a.getValue(attr, val)) {
                        focusable = (val.type == TypedValue.TYPE_INT_BOOLEAN)
                                ? (val.data == 0 ? NOT_FOCUSABLE : FOCUSABLE)
                                : val.data;
                    }

                case com.android.internal.R.styleable.View_clickable:
                    clickable = a.getBoolean(attr, clickable);
                    break;
@@ -1656,6 +1665,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
        a.recycle();

        // Some apps were relying on the undefined behavior of focusable winning over
        // focusableInTouchMode != focusable in TextViews if both were specified in XML (usually
        // when starting with EditText and setting only focusable=false). To keep those apps from
        // breaking, re-apply the focusable attribute here.
        if (focusable != getFocusable()) {
            setFocusable(focusable);
        }
        setClickable(clickable);
        setLongClickable(longClickable);