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

Commit 57cadf2a authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Fixing broken clear focus behavior.

1. In a prevous patch I fixed the issues when on clearing
   focus of the first focusable view the callback for
   gaining focus were called before the ones for losing
   focus. Since it cause some issues the patch was reverted
   and resubmitted. In this chaos some code was missed so
   tests are failing. Added the missing logic to give focus
   to the first focusable in the current touch mode when
   a view loses focus.

2. Removed clear focusForRemoval methid since it is a dup
   of unFocus();

Note: All focus tests now pass.

Change-Id: I06881d4b5a66fc5a33efca16a96f20207a7220d3
parent 75cf9e19
Loading
Loading
Loading
Loading
+16 −18
Original line number Diff line number Diff line
@@ -4032,8 +4032,9 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     * <p>
     * <strong>Note:</strong> When a View clears focus the framework is trying
     * to give focus to the first focusable View from the top. Hence, if this
     * View is the first from the top that can take focus, then its focus will
     * not be cleared nor will the focus change callback be invoked.
     * View is the first from the top that can take focus, then all callbacks
     * related to clearing focus will be invoked after wich the framework will
     * give focus to this view.
     * </p>
     */
    public void clearFocus() {
@@ -4050,25 +4051,22 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
            onFocusChanged(false, 0, null);
            refreshDrawableState();
            ensureInputFocusOnFirstFocusable();
        }
    }
    /**
     * Called to clear the focus of a view that is about to be removed.
     * Doesn't call clearChildFocus, which prevents this view from taking
     * focus again before it has been removed from the parent
     */
    void clearFocusForRemoval() {
        if ((mPrivateFlags & FOCUSED) != 0) {
            mPrivateFlags &= ~FOCUSED;
            onFocusChanged(false, 0, null);
            refreshDrawableState();
            // The view cleared focus and invoked the callbacks, so  now is the
            // time to give focus to the the first focusable from the top to
            // ensure that the gain focus is announced after clear focus.
            getRootView().requestFocus(FOCUS_FORWARD);
    void ensureInputFocusOnFirstFocusable() {
        View root = getRootView();
        if (root != null) {
            // Find the first focusble from the top.
            View next = root.focusSearch(FOCUS_FORWARD);
            if (next != null) {
                // Giving focus to the found focusable will not
                // perform a search since we found a view that is
                // guaranteed to be able to take focus.
                next.requestFocus(FOCUS_FORWARD);
            }
        }
    }
+6 −3
Original line number Diff line number Diff line
@@ -3375,7 +3375,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

        boolean clearChildFocus = false;
        if (view == mFocused) {
            view.clearFocusForRemoval();
            view.unFocus();
            clearChildFocus = true;
        }

@@ -3398,6 +3398,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

        if (clearChildFocus) {
            clearChildFocus(view);
            ensureInputFocusOnFirstFocusable();
        }
    }

@@ -3450,7 +3451,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            }

            if (view == focused) {
                view.clearFocusForRemoval();
                view.unFocus();
                clearChildFocus = view;
            }

@@ -3474,6 +3475,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

        if (clearChildFocus != null) {
            clearChildFocus(clearChildFocus);
            ensureInputFocusOnFirstFocusable();
        }
    }

@@ -3519,7 +3521,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            }

            if (view == focused) {
                view.clearFocusForRemoval();
                view.unFocus();
                clearChildFocus = view;
            }

@@ -3542,6 +3544,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

        if (clearChildFocus != null) {
            clearChildFocus(clearChildFocus);
            ensureInputFocusOnFirstFocusable();
        }
    }