summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/allapps/AllAppsContainerView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/allapps/AllAppsContainerView.java')
-rw-r--r--src/com/android/launcher3/allapps/AllAppsContainerView.java149
1 files changed, 17 insertions, 132 deletions
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 7be8e8f0e..0ea61f430 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -20,15 +20,9 @@ import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.InsetDrawable;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.text.Selection;
-import android.text.Spannable;
-import android.text.SpannableString;
import android.text.SpannableStringBuilder;
-import android.text.TextUtils;
-import android.text.method.TextKeyListener;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -42,7 +36,6 @@ import com.android.launcher3.DeleteDropTarget;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
-import com.android.launcher3.ExtendedEditText;
import com.android.launcher3.Insettable;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
@@ -50,18 +43,14 @@ import com.android.launcher3.PromiseAppInfo;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
-import com.android.launcher3.discovery.AppDiscoveryItem;
-import com.android.launcher3.discovery.AppDiscoveryUpdateState;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
-import com.android.launcher3.graphics.TintedDrawableSpan;
import com.android.launcher3.keyboard.FocusedItemDecorator;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageUserKey;
-import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -69,7 +58,7 @@ import java.util.Set;
* The all apps view container.
*/
public class AllAppsContainerView extends BaseContainerView implements DragSource,
- View.OnLongClickListener, AllAppsSearchBarController.Callbacks, Insettable {
+ View.OnLongClickListener, Insettable {
private final Launcher mLauncher;
private final AlphabeticalAppsList mApps;
@@ -77,12 +66,8 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
private final RecyclerView.LayoutManager mLayoutManager;
private AllAppsRecyclerView mAppsRecyclerView;
- private AllAppsSearchBarController mSearchBarController;
-
+ private SearchUiManager mSearchUiManager;
private View mSearchContainer;
- private int mSearchContainerMinHeight;
- private ExtendedEditText mSearchInput;
- private HeaderElevationController mElevationController;
private SpannableStringBuilder mSearchQueryBuilder = null;
@@ -106,8 +91,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
mApps.setAdapter(mAdapter);
mLayoutManager = mAdapter.getLayoutManager();
mSearchQueryBuilder = new SpannableStringBuilder();
- mSearchContainerMinHeight
- = getResources().getDimensionPixelSize(R.dimen.all_apps_search_bar_height);
Selection.setSelection(mSearchQueryBuilder, 0);
}
@@ -149,7 +132,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
*/
public void addApps(List<AppInfo> apps) {
mApps.addApps(apps);
- mSearchBarController.refreshSearchResult();
+ mSearchUiManager.refreshSearchResult();
}
/**
@@ -157,7 +140,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
*/
public void updateApps(List<AppInfo> apps) {
mApps.updateApps(apps);
- mSearchBarController.refreshSearchResult();
+ mSearchUiManager.refreshSearchResult();
}
public void updatePromiseAppProgress(PromiseAppInfo app) {
@@ -176,34 +159,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
*/
public void removeApps(List<AppInfo> apps) {
mApps.removeApps(apps);
- mSearchBarController.refreshSearchResult();
- }
-
- public void setSearchBarVisible(boolean visible) {
- if (visible) {
- mSearchBarController.setVisibility(View.VISIBLE);
- } else {
- mSearchBarController.setVisibility(View.INVISIBLE);
- }
- }
-
- /**
- * Sets the search bar that shows above the a-z list.
- */
- public void setSearchBarController(AllAppsSearchBarController searchController) {
- if (mSearchBarController != null) {
- throw new RuntimeException("Expected search bar controller to only be set once");
- }
- mSearchBarController = searchController;
- mSearchBarController.initialize(mApps, mSearchInput, mLauncher, this);
- mAdapter.setSearchController(mSearchBarController);
- }
-
- /**
- * Scrolls this list view to the top.
- */
- public void scrollToTop() {
- mAppsRecyclerView.scrollToTop();
+ mSearchUiManager.refreshSearchResult();
}
/**
@@ -238,9 +194,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
* Focuses the search field and begins an app search.
*/
public void startAppsSearch() {
- if (mSearchBarController != null) {
- mSearchBarController.focusSearchField();
- }
+ mSearchUiManager.startAppsSearch();
}
/**
@@ -248,9 +202,8 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
*/
public void reset() {
// Reset the search bar and base recycler view after transitioning home
- scrollToTop();
- mSearchBarController.reset();
- mAppsRecyclerView.reset();
+ mAppsRecyclerView.scrollToTop();
+ mSearchUiManager.reset();
}
@Override
@@ -268,28 +221,17 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
}
});
- mSearchContainer = findViewById(R.id.search_container);
- mSearchInput = (ExtendedEditText) findViewById(R.id.search_box_input);
-
- // Update the hint to contain the icon.
- // Prefix the original hint with two spaces. The first space gets replaced by the icon
- // using span. The second space is used for a singe space character between the hint
- // and the icon.
- SpannableString spanned = new SpannableString(" " + mSearchInput.getHint());
- spanned.setSpan(new TintedDrawableSpan(getContext(), R.drawable.ic_allapps_search),
- 0, 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
- mSearchInput.setHint(spanned);
-
- mElevationController = new HeaderElevationController(mSearchContainer);
-
// Load the all apps recycler view
mAppsRecyclerView = (AllAppsRecyclerView) findViewById(R.id.apps_list_view);
mAppsRecyclerView.setApps(mApps);
mAppsRecyclerView.setLayoutManager(mLayoutManager);
mAppsRecyclerView.setAdapter(mAdapter);
mAppsRecyclerView.setHasFixedSize(true);
- mAppsRecyclerView.addOnScrollListener(mElevationController);
- mAppsRecyclerView.setElevationController(mElevationController);
+
+ mSearchContainer = findViewById(R.id.search_container);
+ mSearchUiManager = (SearchUiManager) mSearchContainer;
+ mSearchUiManager.initialize(mApps, mAppsRecyclerView);
+
FocusedItemDecorator focusedItemDecorator = new FocusedItemDecorator(mAppsRecyclerView);
mAppsRecyclerView.addItemDecoration(focusedItemDecorator);
@@ -309,12 +251,11 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
}
@Override
- public void onBoundsChanged(Rect newBounds) { }
-
- @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
DeviceProfile grid = mLauncher.getDeviceProfile();
+ // Update the number of items in the grid before we measure the view
grid.updateAppsViewNumCols();
+
if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
if (mNumAppsPerRow != grid.inv.numColumns ||
mNumPredictedAppsPerRow != grid.inv.numColumns) {
@@ -325,22 +266,11 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
mAdapter.setNumAppsPerRow(mNumAppsPerRow);
mApps.setNumAppsPerRow(mNumAppsPerRow, mNumPredictedAppsPerRow);
}
- if (!grid.isVerticalBarLayout()) {
- MarginLayoutParams searchContainerLp =
- (MarginLayoutParams) mSearchContainer.getLayoutParams();
-
- searchContainerLp.height = mLauncher.getDragLayer().getInsets().top
- + mSearchContainerMinHeight;
- mSearchContainer.setLayoutParams(searchContainerLp);
- }
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return;
}
// --- remove START when {@code FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP} is enabled. ---
-
- // Update the number of items in the grid before we measure the view
- grid.updateAppsViewNumCols();
if (mNumAppsPerRow != grid.allAppsNumCols ||
mNumPredictedAppsPerRow != grid.allAppsNumPredictiveCols) {
mNumAppsPerRow = grid.allAppsNumCols;
@@ -357,22 +287,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
- // Determine if the key event was actual text, if so, focus the search bar and then dispatch
- // the key normally so that it can process this key event
- if (!mSearchBarController.isSearchFieldFocused() &&
- event.getAction() == KeyEvent.ACTION_DOWN) {
- final int unicodeChar = event.getUnicodeChar();
- final boolean isKeyNotWhitespace = unicodeChar > 0 &&
- !Character.isWhitespace(unicodeChar) && !Character.isSpaceChar(unicodeChar);
- if (isKeyNotWhitespace) {
- boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder,
- event.getKeyCode(), event);
- if (gotKey && mSearchQueryBuilder.length() > 0) {
- mSearchBarController.focusSearchField();
- }
- }
- }
-
+ mSearchUiManager.preDispatchKeyEvent(event);
return super.dispatchKeyEvent(event);
}
@@ -440,42 +355,12 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
}
@Override
- public void onSearchResult(String query, ArrayList<ComponentKey> apps) {
- if (apps != null) {
- mApps.setOrderedFilter(apps);
- mAppsRecyclerView.onSearchResultsChanged();
- mAdapter.setLastSearchQuery(query);
- }
- }
-
- @Override
- public void onAppDiscoverySearchUpdate(@Nullable AppDiscoveryItem app,
- @NonNull AppDiscoveryUpdateState state) {
- if (!mLauncher.isDestroyed()) {
- mApps.onAppDiscoverySearchUpdate(app, state);
- mAppsRecyclerView.onSearchResultsChanged();
- }
- }
-
- @Override
- public void clearSearchResult() {
- if (mApps.setOrderedFilter(null)) {
- mAppsRecyclerView.onSearchResultsChanged();
- }
-
- // Clear the search query
- mSearchQueryBuilder.clear();
- mSearchQueryBuilder.clearSpans();
- Selection.setSelection(mSearchQueryBuilder, 0);
- }
-
- @Override
public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) {
targetParent.containerType = mAppsRecyclerView.getContainerType(v);
}
public boolean shouldRestoreImeState() {
- return !TextUtils.isEmpty(mSearchInput.getText());
+ return mSearchUiManager.shouldRestoreImeState();
}
@Override