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

Commit 6318e36a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Restoring last focused view when teleporting to a cluster."

parents 42bf224e 01d8c49e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43430,6 +43430,7 @@ package android.view {
    method public static int resolveSize(int, int);
    method public static int resolveSizeAndState(int, int, int);
    method public void restoreHierarchyState(android.util.SparseArray<android.os.Parcelable>);
    method public boolean restoreLastFocus();
    method public void saveHierarchyState(android.util.SparseArray<android.os.Parcelable>);
    method public void scheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable, long);
    method public void scrollBy(int, int);
+1 −0
Original line number Diff line number Diff line
@@ -46605,6 +46605,7 @@ package android.view {
    method public static int resolveSize(int, int);
    method public static int resolveSizeAndState(int, int, int);
    method public void restoreHierarchyState(android.util.SparseArray<android.os.Parcelable>);
    method public boolean restoreLastFocus();
    method public void saveHierarchyState(android.util.SparseArray<android.os.Parcelable>);
    method public void scheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable, long);
    method public void scrollBy(int, int);
+1 −0
Original line number Diff line number Diff line
@@ -43720,6 +43720,7 @@ package android.view {
    method public static int resolveSize(int, int);
    method public static int resolveSizeAndState(int, int, int);
    method public void restoreHierarchyState(android.util.SparseArray<android.os.Parcelable>);
    method public boolean restoreLastFocus();
    method public void saveHierarchyState(android.util.SparseArray<android.os.Parcelable>);
    method public void scheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable, long);
    method public void scrollBy(int, int);
+15 −0
Original line number Diff line number Diff line
@@ -6106,6 +6106,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            if (mParent != null) {
                mParent.requestChildFocus(this, this);
                if (!isKeyboardNavigationCluster() && mParent instanceof ViewGroup) {
                    ((ViewGroup) mParent).saveFocus();
                }
            }
            if (mAttachInfo != null) {
@@ -9440,6 +9443,18 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return requestFocus(View.FOCUS_DOWN);
    }
    /**
     * Gives focus to the last focused view in the view hierarchy that has this view as a root.
     * If the last focused view cannot be found, fall back to calling {@link #requestFocus()}.
     * Nested keyboard navigation clusters are excluded from the hierarchy considered for saving the
     * last focus.
     *
     * @return Whether this view or one of its descendants actually took focus.
     */
    public boolean restoreLastFocus() {
        return requestFocus();
    }
    /**
     * Call this to try to give focus to a specific view or to one of its
     * descendants and give it a hint about what direction focus is heading.
+46 −0
Original line number Diff line number Diff line
@@ -136,6 +136,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

    // The view contained within this ViewGroup that has or contains focus.
    private View mFocused;
    // The last view contained within this ViewGroup (excluding nested keyboard navigation clusters)
    // that had or contained focus.
    private View mLastFocused;

    /**
     * A Transformation used when drawing children, to
@@ -719,6 +722,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        if (mFocused != null) {
            mFocused.unFocus(this);
            mFocused = null;
            mLastFocused = null;
        }
        super.handleFocusGainInternal(direction, previouslyFocusedRect);
    }
@@ -748,6 +752,20 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        }
    }

    /**
     * Saves the current focus as the last focus for this view and all its ancestors.
     * If the view is inside a keyboard navigation cluster, stops at the root of the cluster since
     * the cluster forms a separate keyboard navigation hierarchy from the focus saving point of
     * view.
     */
    void saveFocus() {
        mLastFocused = mFocused;

        if (!isKeyboardNavigationCluster() && mParent instanceof ViewGroup) {
            ((ViewGroup) mParent).saveFocus();
        }
    }

    @Override
    public void focusableViewAvailable(View v) {
        if (mParent != null
@@ -3045,6 +3063,17 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        return false;
    }

    @Override
    public boolean restoreLastFocus() {
        if (mLastFocused != null && !mLastFocused.isKeyboardNavigationCluster()
                && getDescendantFocusability() != FOCUS_BLOCK_DESCENDANTS
                && (mLastFocused.mViewFlags & VISIBILITY_MASK) == VISIBLE
                && mLastFocused.restoreLastFocus()) {
            return true;
        }
        return super.restoreLastFocus();
    }

    /**
     * {@inheritDoc}
     *
@@ -4897,6 +4926,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            view.unFocus(null);
            clearChildFocus = true;
        }
        if (view == mLastFocused) {
            mLastFocused = null;
        }

        view.clearAccessibilityFocus();

@@ -5007,6 +5039,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                view.unFocus(null);
                clearChildFocus = true;
            }
            if (view == mLastFocused) {
                mLastFocused = null;
            }

            view.clearAccessibilityFocus();

@@ -5080,6 +5115,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        boolean clearChildFocus = false;

        needGlobalAttributesUpdate(false);
        mLastFocused = null;

        for (int i = count - 1; i >= 0; i--) {
            final View view = children[i];
@@ -5151,6 +5187,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        if (child == mFocused) {
            child.clearFocus();
        }
        if (child == mLastFocused) {
            mLastFocused = null;
        }

        child.clearAccessibilityFocus();

@@ -6153,6 +6192,13 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            output = debugIndent(depth);
            output += "mFocused";
            Log.d(VIEW_LOG_TAG, output);
            mFocused.debug(depth + 1);
        }
        if (mLastFocused != null) {
            output = debugIndent(depth);
            output += "mLastFocused";
            Log.d(VIEW_LOG_TAG, output);
            mLastFocused.debug(depth + 1);
        }
        if (mChildrenCount != 0) {
            output = debugIndent(depth);
Loading