From a793fc6e2c41a1569ad59d2ab4bc6ecb8b45db69 Mon Sep 17 00:00:00 2001 From: Holly Sun Date: Mon, 3 Oct 2022 16:56:26 -0700 Subject: [PATCH] Bring up IME and focus on input when scroll to top. Do this behind a feature flag AND only when "Always show keyboard" is selected or in prefix state. Bug: 218846025 Test: keyboard shown when swiping up for QSB and AA+ (both main and work). Keyboard not shown when either the feature flag or Always show keyboard is disabled. Change-Id: I3df2e0e44a8313eaf749cd6b91b7f9d0b9b80ec3 --- .../allapps/BaseAllAppsContainerView.java | 10 +++--- .../launcher3/allapps/BaseSearchConfig.java | 7 +++++ .../allapps/LauncherAllAppsContainerView.java | 31 +++++++++++++++++++ .../launcher3/config/FeatureFlags.java | 4 +++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java index 2ff992ee9f..da86d98b5e 100644 --- a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java @@ -107,8 +107,7 @@ public abstract class BaseAllAppsContainerView { + private final RecyclerView.OnScrollListener mActivityScrollListener = + new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + int scrolledOffset = recyclerView.computeVerticalScrollOffset(); + ExtendedEditText input = mSearchUiManager.getEditText(); + // Scroll up and scroll to top + if (dy < 0 && scrolledOffset == 0 && input != null) { + boolean isImeEnabledOnSwipeUp = Launcher.getLauncher(mActivityContext) + .getSearchConfig().isImeEnabledOnSwipeUp(); + if (isImeEnabledOnSwipeUp || !TextUtils.isEmpty(input.getText())) { + input.showKeyboard(); + } + } + } + }; + + @Override + protected void onInitializeRecyclerView(RecyclerView rv) { + super.onInitializeRecyclerView(rv); + if (FeatureFlags.SCROLL_TOP_TO_RESET.get()) { + rv.addOnScrollListener(mActivityScrollListener); + } + } + public LauncherAllAppsContainerView(Context context) { this(context, null); } diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index 037a77e44f..7913c4a0cb 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -290,6 +290,10 @@ public final class FeatureFlags { public static final BooleanFlag ENABLE_WIDGET_PICKER_DEPTH = new DeviceFlag( "ENABLE_WIDGET_PICKER_DEPTH", true, "Enable changing depth in widget picker."); + public static final BooleanFlag SCROLL_TOP_TO_RESET = new DeviceFlag( + "SCROLL_TOP_TO_RESET", false, "Bring up IME and focus on " + + "input when scroll to top if 'Always show keyboard' is enabled or in prefix state"); + public static final BooleanFlag SHOW_DELIGHTFUL_PAGINATION = getDebugFlag( "SHOW_DELIGHTFUL_PAGINATION", false, "Enable showing the new 'delightful pagination' which is a brand"