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

Commit ed7821a6 authored by Alan Viverette's avatar Alan Viverette
Browse files

Use clearFocus() when entering touch mode

Calling unFocus() leaves the view hierarchy in an inconsistent
state. This is okay in ViewGroup, where the state is manually
updated, but causes issues in ViewRootImpl.

BUG: 9983358
Change-Id: Id63e62962d895e6bd4f816f202dcf77254ceab4e
parent 616dfe37
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -4588,6 +4588,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    /**
    /**
     * Called internally by the view system when a new view is getting focus.
     * Called internally by the view system when a new view is getting focus.
     * This is what clears the old focus.
     * This is what clears the old focus.
     * <p>
     * <b>NOTE:</b> The parent view's focused child must be updated manually
     * after calling this method. Otherwise, the view hierarchy may be left in
     * an inconstent state.
     */
     */
    void unFocus() {
    void unFocus() {
        if (DBG) {
        if (DBG) {
+17 −18
Original line number Original line Diff line number Diff line
@@ -3250,27 +3250,26 @@ public final class ViewRootImpl implements ViewParent,
    }
    }


    private boolean enterTouchMode() {
    private boolean enterTouchMode() {
        if (mView != null) {
        if (mView != null && mView.hasFocus()) {
            if (mView.hasFocus()) {
            // note: not relying on mFocusedView here because this could
            // note: not relying on mFocusedView here because this could
            // be when the window is first being added, and mFocused isn't
            // be when the window is first being added, and mFocused isn't
            // set yet.
            // set yet.
            final View focused = mView.findFocus();
            final View focused = mView.findFocus();
            if (focused != null && !focused.isFocusableInTouchMode()) {
            if (focused != null && !focused.isFocusableInTouchMode()) {
                    final ViewGroup ancestorToTakeFocus =
                final ViewGroup ancestorToTakeFocus = findAncestorToTakeFocusInTouchMode(focused);
                            findAncestorToTakeFocusInTouchMode(focused);
                if (ancestorToTakeFocus != null) {
                if (ancestorToTakeFocus != null) {
                        // there is an ancestor that wants focus after its descendants that
                    // there is an ancestor that wants focus after its
                        // is focusable in touch mode.. give it focus
                    // descendants that is focusable in touch mode.. give it
                    // focus
                    return ancestorToTakeFocus.requestFocus();
                    return ancestorToTakeFocus.requestFocus();
                } else {
                } else {
                        // nothing appropriate to have focus in touch mode, clear it out
                    // nothing appropriate to have focus in touch mode, clear it
                        focused.unFocus();
                    // out
                    focused.clearFocus();
                    return true;
                    return true;
                }
                }
            }
            }
        }
        }
        }
        return false;
        return false;
    }
    }