Fixing search behavior in Launcher3
> Showing no-result found only when there are no results > Removing unnecessary view inflation in RecyclerViewPool for various search vide types > Removing unused market-search link and no-empty-result illustration Bug: 240343082 Bug: 207573083 Test: Verified Launcher3 Change-Id: Ia44799cd2385ea5dc837ef25732ca237975abde7
This commit is contained in:
1 parent
f6003ff070
commit
af95ddbadc
16 files changed
+33
-623
No files matched your search
@@ -16,7 +16,6 @@
|
||||
package com.android.launcher3.allapps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
@@ -32,7 +31,6 @@ import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem;
|
||||
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.ArrayList;
|
||||
@@ -77,13 +75,6 @@ public class ActivityAllAppsContainerView<T extends Context & AppLauncher
|
||||
|
||||
/** Updates all apps container with the latest search query. */
|
||||
public void setLastSearchQuery(String query) {
|
||||
Intent marketSearchIntent = PackageManagerHelper.getMarketSearchIntent(
|
||||
mActivityContext, query);
|
||||
OnClickListener marketSearchClickListener = (v) -> mActivityContext.startActivitySafely(v,
|
||||
marketSearchIntent, null);
|
||||
for (int i = 0; i < mAH.size(); i++) {
|
||||
mAH.get(i).mAdapter.setLastSearchQuery(query, marketSearchClickListener);
|
||||
}
|
||||
mIsSearching = true;
|
||||
rebindAdapters();
|
||||
mHeader.setCollapsed(true);
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.allapps;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.android.launcher3.LauncherAnimUtils;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.util.Themes;
|
||||
|
||||
/**
|
||||
* This is a custom composite drawable that has a fixed virtual size and dynamically lays out its
|
||||
* children images relatively within its bounds. This way, we can reduce the memory usage of a
|
||||
* single, large sparsely populated image.
|
||||
*/
|
||||
public class AllAppsBackgroundDrawable extends Drawable {
|
||||
|
||||
/**
|
||||
* A helper class to position and orient a drawable to be drawn.
|
||||
*/
|
||||
protected static class TransformedImageDrawable {
|
||||
private Drawable mImage;
|
||||
private float mXPercent;
|
||||
private float mYPercent;
|
||||
private int mGravity;
|
||||
private int mAlpha;
|
||||
|
||||
/**
|
||||
* @param gravity If one of the Gravity center values, the x and y offset will take the width
|
||||
* and height of the image into account to center the image to the offset.
|
||||
*/
|
||||
public TransformedImageDrawable(Context context, int resourceId, float xPct, float yPct,
|
||||
int gravity) {
|
||||
mImage = context.getDrawable(resourceId);
|
||||
mXPercent = xPct;
|
||||
mYPercent = yPct;
|
||||
mGravity = gravity;
|
||||
}
|
||||
|
||||
public void setAlpha(int alpha) {
|
||||
mImage.setAlpha(alpha);
|
||||
mAlpha = alpha;
|
||||
}
|
||||
|
||||
public int getAlpha() {
|
||||
return mAlpha;
|
||||
}
|
||||
|
||||
public void updateBounds(Rect bounds) {
|
||||
int width = mImage.getIntrinsicWidth();
|
||||
int height = mImage.getIntrinsicHeight();
|
||||
int left = bounds.left + (int) (mXPercent * bounds.width());
|
||||
int top = bounds.top + (int) (mYPercent * bounds.height());
|
||||
if ((mGravity & Gravity.CENTER_HORIZONTAL) == Gravity.CENTER_HORIZONTAL) {
|
||||
left -= (width / 2);
|
||||
}
|
||||
if ((mGravity & Gravity.CENTER_VERTICAL) == Gravity.CENTER_VERTICAL) {
|
||||
top -= (height / 2);
|
||||
}
|
||||
mImage.setBounds(left, top, left + width, top + height);
|
||||
}
|
||||
|
||||
public void draw(Canvas canvas) {
|
||||
mImage.draw(canvas);
|
||||
}
|
||||
|
||||
public Rect getBounds() {
|
||||
return mImage.getBounds();
|
||||
}
|
||||
}
|
||||
|
||||
protected final TransformedImageDrawable mHand;
|
||||
protected final TransformedImageDrawable[] mIcons;
|
||||
private final int mWidth;
|
||||
private final int mHeight;
|
||||
|
||||
private ObjectAnimator mBackgroundAnim;
|
||||
|
||||
public AllAppsBackgroundDrawable(Context context) {
|
||||
Resources res = context.getResources();
|
||||
mWidth = res.getDimensionPixelSize(R.dimen.all_apps_background_canvas_width);
|
||||
mHeight = res.getDimensionPixelSize(R.dimen.all_apps_background_canvas_height);
|
||||
|
||||
context = new ContextThemeWrapper(context,
|
||||
Themes.getAttrBoolean(context, R.attr.isMainColorDark)
|
||||
? R.style.AllAppsEmptySearchBackground_Dark
|
||||
: R.style.AllAppsEmptySearchBackground);
|
||||
mHand = new TransformedImageDrawable(context, R.drawable.ic_all_apps_bg_hand,
|
||||
0.575f, 0.f, Gravity.CENTER_HORIZONTAL);
|
||||
mIcons = new TransformedImageDrawable[4];
|
||||
mIcons[0] = new TransformedImageDrawable(context, R.drawable.ic_all_apps_bg_icon_1,
|
||||
0.375f, 0, Gravity.CENTER_HORIZONTAL);
|
||||
mIcons[1] = new TransformedImageDrawable(context, R.drawable.ic_all_apps_bg_icon_2,
|
||||
0.3125f, 0.2f, Gravity.CENTER_HORIZONTAL);
|
||||
mIcons[2] = new TransformedImageDrawable(context, R.drawable.ic_all_apps_bg_icon_3,
|
||||
0.475f, 0.26f, Gravity.CENTER_HORIZONTAL);
|
||||
mIcons[3] = new TransformedImageDrawable(context, R.drawable.ic_all_apps_bg_icon_4,
|
||||
0.7f, 0.125f, Gravity.CENTER_HORIZONTAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates the background alpha.
|
||||
*/
|
||||
public void animateBgAlpha(float finalAlpha, int duration) {
|
||||
int finalAlphaI = (int) (finalAlpha * 255f);
|
||||
if (getAlpha() != finalAlphaI) {
|
||||
mBackgroundAnim = cancelAnimator(mBackgroundAnim);
|
||||
mBackgroundAnim = ObjectAnimator.ofInt(this, LauncherAnimUtils.DRAWABLE_ALPHA,
|
||||
finalAlphaI);
|
||||
mBackgroundAnim.setDuration(duration);
|
||||
mBackgroundAnim.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the background alpha immediately.
|
||||
*/
|
||||
public void setBgAlpha(float finalAlpha) {
|
||||
int finalAlphaI = (int) (finalAlpha * 255f);
|
||||
if (getAlpha() != finalAlphaI) {
|
||||
mBackgroundAnim = cancelAnimator(mBackgroundAnim);
|
||||
setAlpha(finalAlphaI);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
mHand.draw(canvas);
|
||||
for (int i = 0; i < mIcons.length; i++) {
|
||||
mIcons[i].draw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
super.onBoundsChange(bounds);
|
||||
mHand.updateBounds(bounds);
|
||||
for (int i = 0; i < mIcons.length; i++) {
|
||||
mIcons[i].updateBounds(bounds);
|
||||
}
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
mHand.setAlpha(alpha);
|
||||
for (int i = 0; i < mIcons.length; i++) {
|
||||
mIcons[i].setAlpha(alpha);
|
||||
}
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAlpha() {
|
||||
return mHand.getAlpha();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter colorFilter) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return PixelFormat.TRANSLUCENT;
|
||||
}
|
||||
|
||||
private ObjectAnimator cancelAnimator(ObjectAnimator animator) {
|
||||
if (animator != null) {
|
||||
animator.cancel();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,10 @@ import static com.android.launcher3.util.LogConfig.SEARCH_LOGGING;
|
||||
import static com.android.launcher3.util.UiThreadHelper.hideKeyboardAsync;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@@ -39,7 +36,6 @@ import com.android.launcher3.FastScrollRecyclerView;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.launcher3.views.RecyclerViewFastScroller;
|
||||
@@ -89,10 +85,6 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
|
||||
}
|
||||
};
|
||||
|
||||
// The empty-search result background
|
||||
protected AllAppsBackgroundDrawable mEmptySearchBackground;
|
||||
protected int mEmptySearchBackgroundTopOffset;
|
||||
|
||||
public AllAppsRecyclerView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -108,9 +100,6 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
|
||||
public AllAppsRecyclerView(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
Resources res = getResources();
|
||||
mEmptySearchBackgroundTopOffset = res.getDimensionPixelSize(
|
||||
R.dimen.all_apps_empty_search_bg_top_offset);
|
||||
mNumAppsPerRow = LauncherAppState.getIDP(context).numColumns;
|
||||
mFastScrollHelper = new AllAppsFastScrollHelper(this);
|
||||
}
|
||||
@@ -132,7 +121,6 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
|
||||
int approxRows = (int) Math.ceil(grid.availableHeightPx / grid.allAppsIconSizePx);
|
||||
pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_EMPTY_SEARCH, 1);
|
||||
pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_ALL_APPS_DIVIDER, 1);
|
||||
pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_SEARCH_MARKET, 1);
|
||||
pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_ICON, approxRows
|
||||
* (mNumAppsPerRow + 1));
|
||||
|
||||
@@ -143,10 +131,6 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c) {
|
||||
// Draw the background
|
||||
if (mEmptySearchBackground != null && mEmptySearchBackground.getAlpha() > 0) {
|
||||
mEmptySearchBackground.draw(c);
|
||||
}
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onDraw at = " + System.currentTimeMillis());
|
||||
}
|
||||
@@ -157,34 +141,14 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
|
||||
super.onDraw(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean verifyDrawable(Drawable who) {
|
||||
return who == mEmptySearchBackground || super.verifyDrawable(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
updateEmptySearchBackgroundBounds();
|
||||
updatePoolSize();
|
||||
}
|
||||
|
||||
public void onSearchResultsChanged() {
|
||||
// Always scroll the view to the top so the user can see the changed results
|
||||
scrollToTop();
|
||||
|
||||
if (mApps.hasNoFilteredResults() && !FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
|
||||
if (mEmptySearchBackground == null) {
|
||||
mEmptySearchBackground = new AllAppsBackgroundDrawable(getContext());
|
||||
mEmptySearchBackground.setAlpha(0);
|
||||
mEmptySearchBackground.setCallback(this);
|
||||
updateEmptySearchBackgroundBounds();
|
||||
}
|
||||
mEmptySearchBackground.animateBgAlpha(1f, 150);
|
||||
} else if (mEmptySearchBackground != null) {
|
||||
// For the time being, we just immediately hide the background to ensure that it does
|
||||
// not overlap with the results
|
||||
mEmptySearchBackground.setBgAlpha(0f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,16 +172,6 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent e) {
|
||||
boolean result = super.onInterceptTouchEvent(e);
|
||||
if (!result && e.getAction() == MotionEvent.ACTION_DOWN
|
||||
&& mEmptySearchBackground != null && mEmptySearchBackground.getAlpha() > 0) {
|
||||
mEmptySearchBackground.setHotspot(e.getX(), e.getY());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the touch (from 0..1) to the adapter position that should be visible.
|
||||
*/
|
||||
@@ -393,22 +347,6 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
|
||||
return mScrollbar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the bounds of the empty search background.
|
||||
*/
|
||||
private void updateEmptySearchBackgroundBounds() {
|
||||
if (mEmptySearchBackground == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Center the empty search background on this new view bounds
|
||||
int x = (getMeasuredWidth() - mEmptySearchBackground.getIntrinsicWidth()) / 2;
|
||||
int y = mEmptySearchBackgroundTopOffset;
|
||||
mEmptySearchBackground.setBounds(x, y,
|
||||
x + mEmptySearchBackground.getIntrinsicWidth(),
|
||||
y + mEmptySearchBackground.getIntrinsicHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOverlappingRendering() {
|
||||
return false;
|
||||
|
||||
@@ -15,17 +15,12 @@
|
||||
*/
|
||||
package com.android.launcher3.allapps;
|
||||
|
||||
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_ALL_APPS_DIVIDER;
|
||||
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_EMPTY_SEARCH;
|
||||
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_SEARCH_MARKET;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
|
||||
import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.util.LabelComparator;
|
||||
@@ -172,13 +167,6 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
|
||||
return !mSearchResults.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether there are no filtered results.
|
||||
*/
|
||||
public boolean hasNoFilteredResults() {
|
||||
return hasSearchResults() && mAccessibilityResultsCount == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets results list for search
|
||||
*/
|
||||
@@ -249,15 +237,6 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
|
||||
// ordered set of sections
|
||||
if (hasSearchResults()) {
|
||||
mAdapterItems.addAll(mSearchResults);
|
||||
if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
|
||||
// Append the search market item
|
||||
if (hasNoFilteredResults()) {
|
||||
mAdapterItems.add(new AdapterItem(VIEW_TYPE_EMPTY_SEARCH));
|
||||
} else {
|
||||
mAdapterItems.add(new AdapterItem(VIEW_TYPE_ALL_APPS_DIVIDER));
|
||||
}
|
||||
mAdapterItems.add(new AdapterItem(VIEW_TYPE_SEARCH_MARKET));
|
||||
}
|
||||
} else {
|
||||
int position = 0;
|
||||
if (mWorkProviderManager != null) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import static com.android.launcher3.touch.ItemLongClickListener.INSTANCE_ALL_APP
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
@@ -54,19 +53,13 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
public static final int VIEW_TYPE_ICON = 1 << 1;
|
||||
// The message shown when there are no filtered results
|
||||
public static final int VIEW_TYPE_EMPTY_SEARCH = 1 << 2;
|
||||
// The message to continue to a market search when there are no filtered results
|
||||
public static final int VIEW_TYPE_SEARCH_MARKET = 1 << 3;
|
||||
|
||||
// We use various dividers for various purposes. They share enough attributes to reuse layouts,
|
||||
// but differ in enough attributes to require different view types
|
||||
|
||||
// A divider that separates the apps list and the search market button
|
||||
public static final int VIEW_TYPE_ALL_APPS_DIVIDER = 1 << 4;
|
||||
public static final int VIEW_TYPE_ALL_APPS_DIVIDER = 1 << 3;
|
||||
|
||||
public static final int VIEW_TYPE_WORK_EDU_CARD = 1 << 5;
|
||||
public static final int VIEW_TYPE_WORK_DISABLED_CARD = 1 << 6;
|
||||
public static final int VIEW_TYPE_WORK_EDU_CARD = 1 << 4;
|
||||
public static final int VIEW_TYPE_WORK_DISABLED_CARD = 1 << 5;
|
||||
|
||||
public static final int NEXT_ID = 7;
|
||||
public static final int NEXT_ID = 6;
|
||||
|
||||
// Common view type masks
|
||||
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
|
||||
@@ -117,7 +110,7 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
}
|
||||
|
||||
protected boolean isCountedForAccessibility() {
|
||||
return viewType == VIEW_TYPE_ICON || viewType == VIEW_TYPE_SEARCH_MARKET;
|
||||
return viewType == VIEW_TYPE_ICON;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,15 +132,12 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
protected final T mActivityContext;
|
||||
protected final AlphabeticalAppsList<T> mApps;
|
||||
// The text to show when there are no search results and no market search handler.
|
||||
protected String mEmptySearchMessage;
|
||||
protected int mAppsPerRow;
|
||||
|
||||
protected final LayoutInflater mLayoutInflater;
|
||||
protected final OnClickListener mOnIconClickListener;
|
||||
protected OnLongClickListener mOnIconLongClickListener = INSTANCE_ALL_APPS;
|
||||
protected OnFocusChangeListener mIconFocusListener;
|
||||
// The click listener to send off to the market app, updated each time the search query changes.
|
||||
private OnClickListener mMarketSearchClickListener;
|
||||
private final int mExtraHeight;
|
||||
|
||||
public BaseAllAppsAdapter(T activityContext, LayoutInflater inflater,
|
||||
@@ -155,7 +145,6 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
Resources res = activityContext.getResources();
|
||||
mActivityContext = activityContext;
|
||||
mApps = apps;
|
||||
mEmptySearchMessage = res.getString(R.string.all_apps_loading_message);
|
||||
mLayoutInflater = inflater;
|
||||
|
||||
mOnIconClickListener = mActivityContext.getItemOnClickListener();
|
||||
@@ -185,16 +174,6 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
mIconFocusListener = focusListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last search query that was made, used to show when there are no results and to also
|
||||
* seed the intent for searching the market.
|
||||
*/
|
||||
public void setLastSearchQuery(String query, OnClickListener marketSearchClickListener) {
|
||||
Resources res = mActivityContext.getResources();
|
||||
mEmptySearchMessage = res.getString(R.string.all_apps_no_search_results, query);
|
||||
mMarketSearchClickListener = marketSearchClickListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the layout manager.
|
||||
*/
|
||||
@@ -222,11 +201,6 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
case VIEW_TYPE_EMPTY_SEARCH:
|
||||
return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
|
||||
parent, false));
|
||||
case VIEW_TYPE_SEARCH_MARKET:
|
||||
View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market,
|
||||
parent, false);
|
||||
searchMarketView.setOnClickListener(mMarketSearchClickListener);
|
||||
return new ViewHolder(searchMarketView);
|
||||
case VIEW_TYPE_ALL_APPS_DIVIDER:
|
||||
return new ViewHolder(mLayoutInflater.inflate(
|
||||
R.layout.all_apps_divider, parent, false));
|
||||
@@ -248,26 +222,21 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
switch (holder.getItemViewType()) {
|
||||
case VIEW_TYPE_ICON:
|
||||
case VIEW_TYPE_ICON: {
|
||||
AdapterItem adapterItem = mApps.getAdapterItems().get(position);
|
||||
BubbleTextView icon = (BubbleTextView) holder.itemView;
|
||||
icon.reset();
|
||||
icon.applyFromApplicationInfo(adapterItem.itemInfo);
|
||||
break;
|
||||
case VIEW_TYPE_EMPTY_SEARCH:
|
||||
TextView emptyViewText = (TextView) holder.itemView;
|
||||
emptyViewText.setText(mEmptySearchMessage);
|
||||
emptyViewText.setGravity(mApps.hasNoFilteredResults() ? Gravity.CENTER :
|
||||
Gravity.START | Gravity.CENTER_VERTICAL);
|
||||
break;
|
||||
case VIEW_TYPE_SEARCH_MARKET:
|
||||
TextView searchView = (TextView) holder.itemView;
|
||||
if (mMarketSearchClickListener != null) {
|
||||
searchView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
searchView.setVisibility(View.GONE);
|
||||
}
|
||||
case VIEW_TYPE_EMPTY_SEARCH: {
|
||||
AppInfo info = mApps.getAdapterItems().get(position).itemInfo;
|
||||
if (info != null) {
|
||||
((TextView) holder.itemView).setText(mActivityContext.getString(
|
||||
R.string.all_apps_no_search_results, info.title));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIEW_TYPE_ALL_APPS_DIVIDER:
|
||||
case VIEW_TYPE_WORK_DISABLED_CARD:
|
||||
// nothing to do
|
||||
|
||||
@@ -131,7 +131,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText
|
||||
public void initializeSearch(ActivityAllAppsContainerView<?> appsView) {
|
||||
mAppsView = appsView;
|
||||
mSearchBarController.initialize(
|
||||
new DefaultAppSearchAlgorithm(getContext()),
|
||||
new DefaultAppSearchAlgorithm(getContext(), true),
|
||||
this, mLauncher, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.android.launcher3.allapps.search;
|
||||
|
||||
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_EMPTY_SEARCH;
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -44,10 +45,16 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm<AdapterItem> {
|
||||
|
||||
private final LauncherAppState mAppState;
|
||||
private final Handler mResultHandler;
|
||||
private final boolean mAddNoResultsMessage;
|
||||
|
||||
public DefaultAppSearchAlgorithm(Context context) {
|
||||
this(context, false);
|
||||
}
|
||||
|
||||
public DefaultAppSearchAlgorithm(Context context, boolean addNoResultsMessage) {
|
||||
mAppState = LauncherAppState.getInstance(context);
|
||||
mResultHandler = new Handler(MAIN_EXECUTOR.getLooper());
|
||||
mAddNoResultsMessage = addNoResultsMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,11 +70,23 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm<AdapterItem> {
|
||||
@Override
|
||||
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
|
||||
ArrayList<AdapterItem> result = getTitleMatchResult(apps.data, query);
|
||||
if (mAddNoResultsMessage && result.isEmpty()) {
|
||||
result.add(getEmptyMessageAdapterItem(query));
|
||||
}
|
||||
mResultHandler.post(() -> callback.onSearchResult(query, result));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static AdapterItem getEmptyMessageAdapterItem(String query) {
|
||||
AdapterItem item = new AdapterItem(VIEW_TYPE_EMPTY_SEARCH);
|
||||
// Add a place holder info to propagate the query
|
||||
AppInfo placeHolder = new AppInfo();
|
||||
placeHolder.title = query;
|
||||
item.itemInfo = placeHolder;
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters {@link AppInfo}s matching specified query
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user