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

Commit 6346b5ec authored by Winson Chung's avatar Winson Chung
Browse files

Clean up some logic around long press on nav bar buttons

- Only set the long click listeners on the buttons if we are in
  screen pinning mode since we no longer have direct actions for
  long pressing back or recents individually.

Bug: 145180234
Test: Verify talkback does not indicate long press when not in screen
      pinning and notifies long press when in screen pinning.  Also
      verify with screen pinning on/off without accessibility.

Change-Id: If86733bb00e30a285663583334b7b9b2cf707563
parent 98065fb6
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -963,13 +963,22 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
        }

        // Change the cancel pin gesture to home and back if recents button is invisible
        boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
        boolean pinningActive = ActivityManagerWrapper.getInstance().isScreenPinningActive();
        ButtonDispatcher backButton = mNavigationBarView.getBackButton();
        if (recentsVisible) {
            backButton.setOnLongClickListener(this::onLongPressBackRecents);
        ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
        if (pinningActive) {
            boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
            backButton.setOnLongClickListener(recentsVisible
                    ? this::onLongPressBackRecents
                    : this::onLongPressBackHome);
            recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
        } else {
            backButton.setOnLongClickListener(this::onLongPressBackHome);
            backButton.setOnLongClickListener(null);
            recentsButton.setOnLongClickListener(null);
        }
        // Note, this needs to be set after even if we're setting the listener to null
        backButton.setLongClickable(pinningActive);
        recentsButton.setLongClickable(pinningActive);
    }

    private void notifyNavigationBarScreenOn() {
@@ -982,11 +991,6 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
        ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
        recentsButton.setOnClickListener(this::onRecentsClick);
        recentsButton.setOnTouchListener(this::onRecentsTouch);
        recentsButton.setLongClickable(true);
        recentsButton.setOnLongClickListener(this::onLongPressBackRecents);

        ButtonDispatcher backButton = mNavigationBarView.getBackButton();
        backButton.setLongClickable(true);

        ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
        homeButton.setOnTouchListener(this::onHomeTouch);
@@ -1094,6 +1098,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
        return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
    }


    /**
     * This handles long-press of both back and recents/home. Back is the common button with
     * combination of recents if it is visible or home if recents is invisible.