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

Commit 45e72a1e authored by András Klöczl's avatar András Klöczl Committed by Android (Google) Code Review
Browse files

Merge "Fix launcher navigation issue when using a controller" into sc-dev

parents 6328f34f 359d1aed
Loading
Loading
Loading
Loading
+21 −6
Original line number Diff line number Diff line
@@ -833,18 +833,25 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
            return;
        }

        // Add the current page's views as focusable and the next possible page's too. If the
        // last focus change action was left then the left neighbour's views will be added, and
        // if it was right then the right neighbour's views will be added.
        // Unfortunately mCurrentPage can be outdated if there were multiple control actions in a
        // short period of time, but mNextPage is up to date because it is always updated by
        // method snapToPage.
        int nextPage = getNextPage();
        // XXX-RTL: This will be fixed in a future CL
        if (mCurrentPage >= 0 && mCurrentPage < getPageCount()) {
            getPageAt(mCurrentPage).addFocusables(views, direction, focusableMode);
        if (nextPage >= 0 && nextPage < getPageCount()) {
            getPageAt(nextPage).addFocusables(views, direction, focusableMode);
        }
        if (direction == View.FOCUS_LEFT) {
            if (mCurrentPage > 0) {
                int nextPage = validateNewPage(mCurrentPage - 1);
            if (nextPage > 0) {
                nextPage = validateNewPage(nextPage - 1);
                getPageAt(nextPage).addFocusables(views, direction, focusableMode);
            }
        } else if (direction == View.FOCUS_RIGHT) {
            if (mCurrentPage < getPageCount() - 1) {
                int nextPage = validateNewPage(mCurrentPage + 1);
            if (nextPage < getPageCount() - 1) {
                nextPage = validateNewPage(nextPage + 1);
                getPageAt(nextPage).addFocusables(views, direction, focusableMode);
            }
        }
@@ -1414,6 +1421,14 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
    @Override
    public void requestChildFocus(View child, View focused) {
        super.requestChildFocus(child, focused);

        // In case the device is controlled by a controller, mCurrentPage isn't updated properly
        // which results in incorrect navigation
        int nextPage = getNextPage();
        if (nextPage != mCurrentPage) {
            setCurrentPage(nextPage);
        }

        int page = indexToPage(indexOfChild(child));
        if (page >= 0 && page != getCurrentPage() && !isInTouchMode()) {
            snapToPage(page);