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

Commit 0fa5ada2 authored by Tony Wickham's avatar Tony Wickham
Browse files

Fullscreen pages (e.g. Now) are focusable via keyboard.

Change-Id: I962551651aeb9ac7b57bb51b195adc3140db30d8
parent af78b59a
Loading
Loading
Loading
Loading
+43 −1
Original line number Diff line number Diff line
@@ -45,6 +45,23 @@ class HotseatIconKeyEventListener implements View.OnKeyListener {
    }
}

/**
 * A keyboard listener we set on full screen pages (e.g. custom content).
 */
class FullscreenKeyEventListener implements View.OnKeyListener {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
                || keyCode == KeyEvent.KEYCODE_PAGE_DOWN || keyCode == KeyEvent.KEYCODE_PAGE_UP) {
            // Handle the key event just like a workspace icon would in these cases. In this case,
            // it will basically act as if there is a single icon in the top left (so you could
            // think of the fullscreen page as a focusable fullscreen widget).
            return FocusHelper.handleIconKeyEvent(v, keyCode, event);
        }
        return false;
    }
}

public class FocusHelper {

    private static final String TAG = "FocusHelper";
@@ -287,11 +304,25 @@ public class FocusHelper {
            case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN:
                // Go to the previous page but keep the focus on the same hotseat icon.
                workspace.snapToPage(pageIndex - 1);
                // If the page we are going to is fullscreen, have it take the focus from hotseat.
                CellLayout prevPage = (CellLayout) workspace.getPageAt(pageIndex - 1);
                boolean isPrevPageFullscreen = ((CellLayout.LayoutParams) prevPage
                        .getShortcutsAndWidgets().getChildAt(0).getLayoutParams()).isFullscreen;
                if (isPrevPageFullscreen) {
                    workspace.getPageAt(pageIndex - 1).requestFocus();
                }
                break;
            case FocusLogic.NEXT_PAGE_LEFT_COLUMN:
            case FocusLogic.NEXT_PAGE_RIGHT_COLUMN:
                // Go to the next page but keep the focus on the same hotseat icon.
                workspace.snapToPage(pageIndex + 1);
                // If the page we are going to is fullscreen, have it take the focus from hotseat.
                CellLayout nextPage = (CellLayout) workspace.getPageAt(pageIndex + 1);
                boolean isNextPageFullscreen = ((CellLayout.LayoutParams) nextPage
                        .getShortcutsAndWidgets().getChildAt(0).getLayoutParams()).isFullscreen;
                if (isNextPageFullscreen) {
                    workspace.getPageAt(pageIndex + 1).requestFocus();
                }
                break;
        }
        if (parent == iconParent && newIconIndex >= iconParent.getChildCount()) {
@@ -413,6 +444,7 @@ public class FocusHelper {
                workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex - 1);
                newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
                if (newIcon == null) {
                    // Check the hotseat if no focusable item was found on the workspace.
                    newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
                    workspace.snapToPage(pageIndex - 1);
                }
@@ -451,12 +483,14 @@ public class FocusHelper {
            case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
                newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
                if (newIcon == null) {
                    // Check the hotseat if no focusable item was found on the workspace.
                    newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
                }
                break;
            case FocusLogic.CURRENT_PAGE_LAST_ITEM:
                newIcon = getFirstFocusableIconInReverseReadingOrder(workspaceLayout, isRtl);
                if (newIcon == null) {
                    // Check the hotseat if no focusable item was found on the workspace.
                    newIcon = getFirstFocusableIconInReverseReadingOrder(hotseatLayout, isRtl);
                }
                break;
@@ -536,9 +570,13 @@ public class FocusHelper {

    private static View handlePreviousPageLastItem(Workspace workspace, CellLayout hotseatLayout,
            int pageIndex, boolean isRtl) {
        if (pageIndex - 1 < 0) {
            return null;
        }
        CellLayout workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex - 1);
        View newIcon = getFirstFocusableIconInReverseReadingOrder(workspaceLayout, isRtl);
        if (newIcon == null) {
            // Check the hotseat if no focusable item was found on the workspace.
            newIcon = getFirstFocusableIconInReverseReadingOrder(hotseatLayout,isRtl);
            workspace.snapToPage(pageIndex - 1);
        }
@@ -547,9 +585,13 @@ public class FocusHelper {

    private static View handleNextPageFirstItem(Workspace workspace, CellLayout hotseatLayout,
            int pageIndex, boolean isRtl) {
        if (pageIndex + 1 >= workspace.getPageCount()) {
            return null;
        }
        CellLayout workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex + 1);
        View newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
        if (newIcon == null) {
            // Check the hotseat if no focusable item was found on the workspace.
            newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
            workspace.snapToPage(pageIndex + 1);
        }
+2 −0
Original line number Diff line number Diff line
@@ -651,6 +651,8 @@ public class Workspace extends PagedView
            parent.removeView(customContent);
        }
        customScreen.removeAllViews();
        customContent.setFocusable(true);
        customContent.setOnKeyListener(new FullscreenKeyEventListener());
        customScreen.addViewToCellLayout(customContent, 0, 0, lp, true);
        mCustomContentDescription = description;