From f477ec203272b79699d3173bf3bc4dec16c8bad1 Mon Sep 17 00:00:00 2001 From: Brian Isganitis Date: Tue, 15 Mar 2022 13:46:37 -0700 Subject: [PATCH 1/3] Refactor allapps.search package to depend on ActivityContext. Test: Manual Bug: 216683257 Change-Id: I6230498b24380b37531f8a83db1dc768270e708a --- .../launcher3/allapps/ActivityAllAppsContainerView.java | 5 ----- .../allapps/search/AllAppsSearchBarController.java | 9 ++++----- .../allapps/search/AppsSearchContainerLayout.java | 8 ++++---- .../allapps/search/DefaultSearchAdapterProvider.java | 8 ++++---- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index b94a61251b..f530b0089c 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -103,11 +103,6 @@ public class ActivityAllAppsContainerView extend } } - /** Handles selection on focused view and returns {@code true} on success. */ - public boolean launchHighlightedItem() { - return getMainAdapterProvider().launchHighlightedItem(); - } - @Override protected SearchAdapterProvider createMainAdapterProvider() { return mActivityContext.createSearchAdapterProvider(this); diff --git a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java index fd8945a0f6..a6a47a71db 100644 --- a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java +++ b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java @@ -29,14 +29,13 @@ import android.view.inputmethod.EditorInfo; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; -import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.ExtendedEditText; -import com.android.launcher3.Launcher; import com.android.launcher3.Utilities; import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.search.SearchAlgorithm; import com.android.launcher3.search.SearchCallback; +import com.android.launcher3.views.ActivityContext; /** * An interface to a search box that AllApps can command. @@ -45,7 +44,7 @@ public class AllAppsSearchBarController implements TextWatcher, OnEditorActionListener, ExtendedEditText.OnBackKeyListener, OnFocusChangeListener { - protected BaseDraggingActivity mLauncher; + protected ActivityContext mLauncher; protected SearchCallback mCallback; protected ExtendedEditText mInput; protected String mQuery; @@ -62,7 +61,7 @@ public class AllAppsSearchBarController */ public final void initialize( SearchAlgorithm searchAlgorithm, ExtendedEditText input, - BaseDraggingActivity launcher, SearchCallback callback) { + ActivityContext launcher, SearchCallback callback) { mCallback = callback; mLauncher = launcher; @@ -125,7 +124,7 @@ public class AllAppsSearchBarController mLauncher.getStatsLogManager().logger() .log(LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME); // selectFocusedView should return SearchTargetEvent that is passed onto onClick - return Launcher.getLauncher(mLauncher).getAppsView().launchHighlightedItem(); + return mLauncher.getAppsView().getMainAdapterProvider().launchHighlightedItem(); } return false; } diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java index cb459eacb3..893e547340 100644 --- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java +++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java @@ -32,7 +32,6 @@ import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup.MarginLayoutParams; -import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.DeviceProfile; import com.android.launcher3.ExtendedEditText; import com.android.launcher3.Insettable; @@ -43,6 +42,7 @@ import com.android.launcher3.allapps.AlphabeticalAppsList; import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem; import com.android.launcher3.allapps.SearchUiManager; import com.android.launcher3.search.SearchCallback; +import com.android.launcher3.views.ActivityContext; import java.util.ArrayList; @@ -53,7 +53,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText implements SearchUiManager, SearchCallback, AllAppsStore.OnUpdateListener, Insettable { - private final BaseDraggingActivity mLauncher; + private final ActivityContext mLauncher; private final AllAppsSearchBarController mSearchBarController; private final SpannableStringBuilder mSearchQueryBuilder; @@ -74,7 +74,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText public AppsSearchContainerLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - mLauncher = BaseDraggingActivity.fromContext(context); + mLauncher = ActivityContext.lookupContext(context); mSearchBarController = new AllAppsSearchBarController(); mSearchQueryBuilder = new SpannableStringBuilder(); @@ -134,7 +134,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText mApps = appsView.getApps(); mAppsView = appsView; mSearchBarController.initialize( - new DefaultAppSearchAlgorithm(mLauncher), + new DefaultAppSearchAlgorithm(getContext()), this, mLauncher, this); } diff --git a/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java b/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java index 2fe4915e2f..a95bd514da 100644 --- a/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java +++ b/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java @@ -23,20 +23,20 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; -import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.BubbleTextView; import com.android.launcher3.allapps.AllAppsGridAdapter; import com.android.launcher3.model.data.ItemInfo; +import com.android.launcher3.views.AppLauncher; /** - * Provides views for local search results + * Provides views for local search results. */ -public class DefaultSearchAdapterProvider extends SearchAdapterProvider { +public class DefaultSearchAdapterProvider extends SearchAdapterProvider { private final RecyclerView.ItemDecoration mDecoration; private View mHighlightedView; - public DefaultSearchAdapterProvider(BaseDraggingActivity launcher) { + public DefaultSearchAdapterProvider(AppLauncher launcher) { super(launcher); mDecoration = new RecyclerView.ItemDecoration() { @Override From 5eb66d8abbc120c2e07d77029b59fea55ff8613f Mon Sep 17 00:00:00 2001 From: Brian Isganitis Date: Wed, 16 Mar 2022 09:58:17 -0700 Subject: [PATCH 2/3] Refactor ActivityAllAppsContainerView to depend on ActivityContext. All of the all apps search support is in this class which is also being refactored to depend on ActivityContext. At the end of this refactor, this class can be merged with BaseAllAppsContainerView. Test: Manual Bug: 216683257 Change-Id: I8cbf21c8d9ce97cc60e9846cfe8c2a7bcb800a01 --- src/com/android/launcher3/BaseDraggingActivity.java | 1 + .../allapps/ActivityAllAppsContainerView.java | 9 +++++---- src/com/android/launcher3/views/ActivityContext.java | 12 ++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java index 3af43c021b..6de3884b93 100644 --- a/src/com/android/launcher3/BaseDraggingActivity.java +++ b/src/com/android/launcher3/BaseDraggingActivity.java @@ -216,6 +216,7 @@ public abstract class BaseDraggingActivity extends BaseActivity * Creates and returns {@link SearchAdapterProvider} for build variant specific search result * views */ + @Override public SearchAdapterProvider createSearchAdapterProvider( ActivityAllAppsContainerView allApps) { return new DefaultSearchAdapterProvider(this); diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index f530b0089c..11e0a1faae 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -26,12 +26,13 @@ import android.widget.RelativeLayout; import androidx.core.graphics.ColorUtils; import androidx.recyclerview.widget.RecyclerView; -import com.android.launcher3.BaseDraggingActivity; +import com.android.launcher3.DeviceProfile.DeviceProfileListenable; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.util.PackageManagerHelper; +import com.android.launcher3.views.AppLauncher; import java.util.Objects; @@ -40,8 +41,8 @@ import java.util.Objects; * * @param Type of context inflating all apps. */ -public class ActivityAllAppsContainerView extends - BaseAllAppsContainerView { +public class ActivityAllAppsContainerView extends BaseAllAppsContainerView { protected SearchUiManager mSearchUiManager; /** @@ -104,7 +105,7 @@ public class ActivityAllAppsContainerView extend } @Override - protected SearchAdapterProvider createMainAdapterProvider() { + protected final SearchAdapterProvider createMainAdapterProvider() { return mActivityContext.createSearchAdapterProvider(this); } diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java index 3c90eea5d1..50c09dd4d4 100644 --- a/src/com/android/launcher3/views/ActivityContext.java +++ b/src/com/android/launcher3/views/ActivityContext.java @@ -25,7 +25,9 @@ import android.view.View.AccessibilityDelegate; import androidx.annotation.Nullable; import com.android.launcher3.DeviceProfile; +import com.android.launcher3.allapps.ActivityAllAppsContainerView; import com.android.launcher3.allapps.BaseAllAppsContainerView; +import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.dot.DotInfo; import com.android.launcher3.dragndrop.DragController; import com.android.launcher3.folder.FolderIcon; @@ -190,4 +192,14 @@ public interface ActivityContext { default StringCache getStringCache() { return null; } + + /** + * Creates and returns {@link SearchAdapterProvider} for build variant specific search result + * views. + */ + @Nullable + default SearchAdapterProvider createSearchAdapterProvider( + ActivityAllAppsContainerView appsView) { + return null; + } } From d478f555cbb90f1d15b175a0c6ac54e4dba510b2 Mon Sep 17 00:00:00 2001 From: Brian Isganitis Date: Wed, 16 Mar 2022 10:53:39 -0700 Subject: [PATCH 3/3] Have taskbar all apps extend ActivityAllAppsContainerView. This step is necessary to have taskbar support search in all apps. Search is not ready yet, so a fallback search manager is included. Test: Manual Bug: 216683257 Change-Id: Id118388bc4baae4b63ef205295caf46cbd541bc8 --- quickstep/res/layout/taskbar_all_apps.xml | 6 +++ .../launcher3/taskbar/BaseTaskbarContext.java | 4 +- .../allapps/TaskbarAllAppsContainerView.java | 46 ++-------------- .../allapps/TaskbarAllAppsContext.java | 9 ++++ ...TaskbarAllAppsFallbackSearchContainer.java | 54 +++++++++++++++++++ .../launcher3/views/ActivityContext.java | 3 +- 6 files changed, 75 insertions(+), 47 deletions(-) create mode 100644 quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsFallbackSearchContainer.java diff --git a/quickstep/res/layout/taskbar_all_apps.xml b/quickstep/res/layout/taskbar_all_apps.xml index 7dc0cbe1ab..d402469833 100644 --- a/quickstep/res/layout/taskbar_all_apps.xml +++ b/quickstep/res/layout/taskbar_all_apps.xml @@ -51,6 +51,12 @@ + + diff --git a/quickstep/src/com/android/launcher3/taskbar/BaseTaskbarContext.java b/quickstep/src/com/android/launcher3/taskbar/BaseTaskbarContext.java index 27e89baa90..4e1f54c9a2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/BaseTaskbarContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/BaseTaskbarContext.java @@ -23,14 +23,14 @@ import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile.DeviceProfileListenable; import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; import com.android.launcher3.util.Themes; -import com.android.launcher3.views.ActivityContext; +import com.android.launcher3.views.AppLauncher; import java.util.ArrayList; import java.util.List; // TODO(b/218912746): Share more behavior to avoid all apps context depending directly on taskbar. /** Base for common behavior between taskbar window contexts. */ -public abstract class BaseTaskbarContext extends ContextThemeWrapper implements ActivityContext, +public abstract class BaseTaskbarContext extends ContextThemeWrapper implements AppLauncher, DeviceProfileListenable { protected final LayoutInflater mLayoutInflater; diff --git a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContainerView.java b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContainerView.java index 37cd753ba4..0ea2aa0647 100644 --- a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContainerView.java +++ b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContainerView.java @@ -17,22 +17,17 @@ package com.android.launcher3.taskbar.allapps; import android.content.Context; import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; import android.view.WindowInsets; -import androidx.recyclerview.widget.RecyclerView; - +import com.android.launcher3.allapps.ActivityAllAppsContainerView; import com.android.launcher3.allapps.AllAppsGridAdapter; import com.android.launcher3.allapps.AlphabeticalAppsList; import com.android.launcher3.allapps.BaseAdapterProvider; import com.android.launcher3.allapps.BaseAllAppsAdapter; -import com.android.launcher3.allapps.BaseAllAppsContainerView; -import com.android.launcher3.allapps.search.SearchAdapterProvider; /** All apps container accessible from taskbar. */ -public class TaskbarAllAppsContainerView extends BaseAllAppsContainerView { +public class TaskbarAllAppsContainerView extends + ActivityAllAppsContainerView { public TaskbarAllAppsContainerView(Context context, AttributeSet attrs) { this(context, attrs, 0); @@ -42,41 +37,6 @@ public class TaskbarAllAppsContainerView extends BaseAllAppsContainerView createMainAdapterProvider() { - // Taskbar all apps does not yet support search, so this implementation is minimal. - return new SearchAdapterProvider(mActivityContext) { - @Override - public boolean launchHighlightedItem() { - return false; - } - - @Override - public View getHighlightedItem() { - return null; - } - - @Override - public RecyclerView.ItemDecoration getDecorator() { - return null; - } - - @Override - public boolean isViewSupported(int viewType) { - return false; - } - - @Override - public void onBindView(AllAppsGridAdapter.ViewHolder holder, int position) { } - - @Override - public AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, - ViewGroup parent, int viewType) { - return null; - } - }; - } - @Override public WindowInsets onApplyWindowInsets(WindowInsets insets) { setInsets(insets.getInsets(WindowInsets.Type.systemBars()).toRect()); diff --git a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContext.java b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContext.java index 22fffdf317..50dfff0854 100644 --- a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContext.java @@ -32,6 +32,9 @@ import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.R; import com.android.launcher3.Utilities; +import com.android.launcher3.allapps.ActivityAllAppsContainerView; +import com.android.launcher3.allapps.search.DefaultSearchAdapterProvider; +import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.dot.DotInfo; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.popup.PopupDataProvider; @@ -154,6 +157,12 @@ class TaskbarAllAppsContext extends BaseTaskbarContext { @Override public void onPopupVisibilityChanged(boolean isVisible) {} + @Override + public SearchAdapterProvider createSearchAdapterProvider( + ActivityAllAppsContainerView appsView) { + return new DefaultSearchAdapterProvider(this); + } + /** Root drag layer for this context. */ private static class TaskbarAllAppsDragLayer extends BaseDragLayer implements OnComputeInsetsListener { diff --git a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsFallbackSearchContainer.java b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsFallbackSearchContainer.java new file mode 100644 index 0000000000..53fe06d32c --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsFallbackSearchContainer.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.taskbar.allapps; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.Nullable; + +import com.android.launcher3.ExtendedEditText; +import com.android.launcher3.allapps.ActivityAllAppsContainerView; +import com.android.launcher3.allapps.SearchUiManager; + +/** Empty search container for Taskbar All Apps used as a fallback if search is not supported. */ +public class TaskbarAllAppsFallbackSearchContainer extends View implements SearchUiManager { + public TaskbarAllAppsFallbackSearchContainer(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public TaskbarAllAppsFallbackSearchContainer( + Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public void initializeSearch(ActivityAllAppsContainerView containerView) { + // Do nothing. + } + + @Override + public void resetSearch() { + // Do nothing. + } + + @Nullable + @Override + public ExtendedEditText getEditText() { + return null; + } +} diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java index 50c09dd4d4..93078e4cf6 100644 --- a/src/com/android/launcher3/views/ActivityContext.java +++ b/src/com/android/launcher3/views/ActivityContext.java @@ -26,7 +26,6 @@ import androidx.annotation.Nullable; import com.android.launcher3.DeviceProfile; import com.android.launcher3.allapps.ActivityAllAppsContainerView; -import com.android.launcher3.allapps.BaseAllAppsContainerView; import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.dot.DotInfo; import com.android.launcher3.dragndrop.DragController; @@ -101,7 +100,7 @@ public interface ActivityContext { /** * The all apps container, if it exists in this context. */ - default BaseAllAppsContainerView getAppsView() { + default ActivityAllAppsContainerView getAppsView() { return null; }