diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index 0ed640a766..4cf79facb5 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -426,10 +426,14 @@ public class ActivityAllAppsContainerView return mSearchContainer; } - /** Invoke when the current search session is finished. */ + /** Clears displayed search results. */ public void onClearSearchResult() { getMainAdapterProvider().clearHighlightedItem(); - animateToSearchState(false); + ExtendedEditText editText = mSearchUiManager.getEditText(); + // An empty, focused query is still an active search session. + boolean keepSearchFocus = editText != null && editText.isFocused() + && editText.getText().length() == 0; + animateToSearchState(false, DEFAULT_SEARCH_TRANSITION_DURATION_MS, keepSearchFocus); rebindAdapters(); } @@ -467,6 +471,11 @@ public class ActivityAllAppsContainerView } void animateToSearchState(boolean goingToSearch, long durationMs) { + animateToSearchState(goingToSearch, durationMs, false); + } + + private void animateToSearchState(boolean goingToSearch, long durationMs, + boolean keepSearchFocus) { if (!mSearchTransitionController.isRunning() && goingToSearch == isSearching()) { return; } @@ -498,7 +507,7 @@ public class ActivityAllAppsContainerView if (mViewPager != null) { mViewPager.setCurrentPage(previousPage); } - onActivePageChanged(previousPage); + onActivePageChanged(previousPage, keepSearchFocus); mSearchExitInProgress = false; } }); @@ -648,11 +657,15 @@ public class ActivityAllAppsContainerView @Override public void onActivePageChanged(int currentActivePage) { + onActivePageChanged(currentActivePage, false); + } + + private void onActivePageChanged(int currentActivePage, boolean keepSearchFocus) { if (mSearchTransitionController.isRunning()) { // Will be called at the end of the animation. return; } - if (currentActivePage != SEARCH) { + if (currentActivePage != SEARCH && !keepSearchFocus) { mActivityContext.hideKeyboard(); } if (mAH.get(currentActivePage).mRecyclerView != null) { @@ -661,7 +674,7 @@ public class ActivityAllAppsContainerView } // Header keeps track of active recycler view to properly render header protection. mHeader.setActiveRV(currentActivePage); - reset(true /* animate */, !isSearching() /* exitSearch */); + reset(true /* animate */, !isSearching() && !keepSearchFocus /* exitSearch */); mWorkManager.onActivePageChanged(currentActivePage); }