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

Commit 398cfc71 authored by Yabin Huang's avatar Yabin Huang
Browse files

Fix View backward navigation bug

b/147829061 used View id to search for the next backward view. The
problem was that there might be several Views with the same ID in View
hierarchy, so it may return the wrong View with the same ID. To fix
that, ag/10111732 compared the View itself. The idea was right but there
was a bug in that CL. This CL fixed the original bug and the following
bugs.

Fixes: 148545035
Fixes: 148166620
Bug: 147829061
Test: atest TimePickerTest
Test: atest BackwardNavigationTest
Test: atest SpinnerTest
Change-Id: I4ec44f91bbaa86b0f52e10611b91fcceb2588d12
parent a3511ce6
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -12723,12 +12723,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                return findViewInsideOutShouldExist(root, mNextFocusForwardId);
            case FOCUS_BACKWARD: {
                if (mID == View.NO_ID) return null;
                return root.findViewByPredicateInsideOut(this, new Predicate<View>() {
                    @Override
                    public boolean test(View t) {
                        return t.findViewById(t.mNextFocusForwardId) == View.this;
                    }
                });
                final View rootView = root;
                final View startView = this;
                // Since we have forward links but no backward links, we need to find the view that
                // forward links to this view. We can't just find the view with the specified ID
                // because view IDs need not be unique throughout the tree.
                return root.findViewByPredicateInsideOut(startView,
                    t -> findViewInsideOutShouldExist(rootView, t, t.mNextFocusForwardId)
                            == startView);
            }
        }
        return null;
@@ -12758,11 +12760,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    }
    private View findViewInsideOutShouldExist(View root, int id) {
        return findViewInsideOutShouldExist(root, this, id);
    }
    private View findViewInsideOutShouldExist(View root, View start, int id) {
        if (mMatchIdPredicate == null) {
            mMatchIdPredicate = new MatchIdPredicate();
        }
        mMatchIdPredicate.mId = id;
        View result = root.findViewByPredicateInsideOut(this, mMatchIdPredicate);
        View result = root.findViewByPredicateInsideOut(start, mMatchIdPredicate);
        if (result == null) {
            Log.w(VIEW_LOG_TAG, "couldn't find view with id " + id);
        }