2015-05-14 19:24:40 -07:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2015-05-22 11:12:27 -07:00
|
|
|
package com.android.launcher3.allapps;
|
2015-03-10 16:28:47 -07:00
|
|
|
|
2020-01-07 13:07:55 -08:00
|
|
|
import static com.android.launcher3.touch.ItemLongClickListener.INSTANCE_ALL_APPS;
|
|
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
import android.content.Context;
|
2015-07-10 12:38:30 -07:00
|
|
|
import android.content.Intent;
|
2015-03-10 16:28:47 -07:00
|
|
|
import android.content.res.Resources;
|
2015-08-19 17:26:21 -07:00
|
|
|
import android.view.Gravity;
|
2015-03-10 16:28:47 -07:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
2020-01-07 13:07:55 -08:00
|
|
|
import android.view.View.OnClickListener;
|
2016-05-09 20:43:21 -07:00
|
|
|
import android.view.View.OnFocusChangeListener;
|
2020-01-07 13:07:55 -08:00
|
|
|
import android.view.View.OnLongClickListener;
|
2015-03-10 16:28:47 -07:00
|
|
|
import android.view.ViewGroup;
|
2015-07-30 12:53:33 -07:00
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
2015-03-13 11:14:16 -07:00
|
|
|
import android.widget.TextView;
|
2016-04-28 17:39:03 -07:00
|
|
|
|
2020-08-23 15:58:39 -07:00
|
|
|
import androidx.annotation.NonNull;
|
2020-01-07 13:07:55 -08:00
|
|
|
import androidx.annotation.Nullable;
|
2019-12-10 12:19:13 -08:00
|
|
|
import androidx.core.view.accessibility.AccessibilityEventCompat;
|
|
|
|
|
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
|
|
|
|
import androidx.core.view.accessibility.AccessibilityRecordCompat;
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
2020-01-07 13:07:55 -08:00
|
|
|
import com.android.launcher3.BaseDraggingActivity;
|
2015-05-22 11:12:27 -07:00
|
|
|
import com.android.launcher3.BubbleTextView;
|
|
|
|
|
import com.android.launcher3.R;
|
2020-10-13 01:12:03 -07:00
|
|
|
import com.android.launcher3.allapps.search.AllAppsSearchBarController.SearchTargetHandler;
|
2020-08-15 09:40:26 -07:00
|
|
|
import com.android.launcher3.allapps.search.SearchSectionInfo;
|
2020-08-23 15:58:39 -07:00
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
2020-04-06 15:11:17 -07:00
|
|
|
import com.android.launcher3.model.data.AppInfo;
|
2017-05-07 11:56:00 -07:00
|
|
|
import com.android.launcher3.util.PackageManagerHelper;
|
2020-09-10 12:05:19 -07:00
|
|
|
import com.android.systemui.plugins.shared.SearchTarget;
|
2017-02-21 16:43:56 -08:00
|
|
|
|
|
|
|
|
import java.util.List;
|
2015-04-06 15:12:49 -07:00
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
/**
|
|
|
|
|
* The grid view adapter of all the apps.
|
|
|
|
|
*/
|
2020-08-23 15:58:39 -07:00
|
|
|
public class AllAppsGridAdapter extends
|
2020-09-11 13:34:25 -07:00
|
|
|
RecyclerView.Adapter<AllAppsGridAdapter.ViewHolder> {
|
2015-03-10 16:28:47 -07:00
|
|
|
|
|
|
|
|
public static final String TAG = "AppsGridAdapter";
|
|
|
|
|
|
2015-05-12 19:05:30 -07:00
|
|
|
// A normal icon
|
2016-07-07 14:47:05 -07:00
|
|
|
public static final int VIEW_TYPE_ICON = 1 << 1;
|
2015-05-12 19:05:30 -07:00
|
|
|
// The message shown when there are no filtered results
|
2018-01-30 20:52:27 -08:00
|
|
|
public static final int VIEW_TYPE_EMPTY_SEARCH = 1 << 2;
|
2016-07-19 12:11:05 -07:00
|
|
|
// The message to continue to a market search when there are no filtered results
|
2018-01-30 20:52:27 -08:00
|
|
|
public static final int VIEW_TYPE_SEARCH_MARKET = 1 << 3;
|
2016-07-07 14:47:05 -07:00
|
|
|
|
|
|
|
|
// 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
|
2018-01-30 20:52:27 -08:00
|
|
|
public static final int VIEW_TYPE_ALL_APPS_DIVIDER = 1 << 4;
|
2016-07-07 14:47:05 -07:00
|
|
|
|
2020-08-04 14:06:55 -07:00
|
|
|
public static final int VIEW_TYPE_SEARCH_CORPUS_TITLE = 1 << 5;
|
|
|
|
|
|
2020-08-23 15:58:39 -07:00
|
|
|
public static final int VIEW_TYPE_SEARCH_ROW_WITH_BUTTON = 1 << 7;
|
|
|
|
|
|
|
|
|
|
public static final int VIEW_TYPE_SEARCH_ROW = 1 << 8;
|
|
|
|
|
|
|
|
|
|
public static final int VIEW_TYPE_SEARCH_SLICE = 1 << 9;
|
2020-08-15 09:40:26 -07:00
|
|
|
|
2020-09-23 00:45:27 -07:00
|
|
|
public static final int VIEW_TYPE_SEARCH_ICON_ROW = 1 << 10;
|
2020-09-03 09:42:54 -07:00
|
|
|
|
2020-09-08 14:00:56 -07:00
|
|
|
public static final int VIEW_TYPE_SEARCH_PEOPLE = 1 << 11;
|
|
|
|
|
|
2020-09-20 11:28:18 -07:00
|
|
|
public static final int VIEW_TYPE_SEARCH_THUMBNAIL = 1 << 12;
|
|
|
|
|
|
2020-09-28 01:53:31 -07:00
|
|
|
public static final int VIEW_TYPE_SEARCH_SUGGEST = 1 << 13;
|
|
|
|
|
|
2020-10-14 10:15:07 -07:00
|
|
|
public static final int VIEW_TYPE_SEARCH_ICON = 1 << 14;
|
|
|
|
|
|
2016-07-07 14:47:05 -07:00
|
|
|
// Common view type masks
|
2018-01-30 20:52:27 -08:00
|
|
|
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
|
2020-10-14 10:15:07 -07:00
|
|
|
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON | VIEW_TYPE_SEARCH_ICON;
|
2016-07-07 14:47:05 -07:00
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
/**
|
|
|
|
|
* ViewHolder for each icon.
|
|
|
|
|
*/
|
|
|
|
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
2017-04-20 12:07:38 -07:00
|
|
|
|
2015-05-12 19:05:30 -07:00
|
|
|
public ViewHolder(View v) {
|
2015-03-10 16:28:47 -07:00
|
|
|
super(v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 09:40:26 -07:00
|
|
|
/**
|
|
|
|
|
* Info about a particular adapter item (can be either section or app)
|
|
|
|
|
*/
|
|
|
|
|
public static class AdapterItem {
|
|
|
|
|
/** Common properties */
|
|
|
|
|
// The index of this adapter item in the list
|
|
|
|
|
public int position;
|
|
|
|
|
// The type of this item
|
|
|
|
|
public int viewType;
|
|
|
|
|
|
|
|
|
|
/** App-only properties */
|
|
|
|
|
// The section name of this app. Note that there can be multiple items with different
|
|
|
|
|
// sectionNames in the same section
|
|
|
|
|
public String sectionName = null;
|
|
|
|
|
// The row that this item shows up on
|
|
|
|
|
public int rowIndex;
|
|
|
|
|
// The index of this app in the row
|
|
|
|
|
public int rowAppIndex;
|
|
|
|
|
// The associated AppInfo for the app
|
|
|
|
|
public AppInfo appInfo = null;
|
|
|
|
|
// The index of this app not including sections
|
|
|
|
|
public int appIndex = -1;
|
|
|
|
|
// Search section associated to result
|
|
|
|
|
public SearchSectionInfo searchSectionInfo = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method for AppIcon AdapterItem
|
|
|
|
|
*/
|
|
|
|
|
public static AdapterItem asApp(int pos, String sectionName, AppInfo appInfo,
|
|
|
|
|
int appIndex) {
|
|
|
|
|
AdapterItem item = new AdapterItem();
|
|
|
|
|
item.viewType = VIEW_TYPE_ICON;
|
|
|
|
|
item.position = pos;
|
|
|
|
|
item.sectionName = sectionName;
|
|
|
|
|
item.appInfo = appInfo;
|
|
|
|
|
item.appIndex = appIndex;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method for empty search results view
|
|
|
|
|
*/
|
|
|
|
|
public static AdapterItem asEmptySearch(int pos) {
|
|
|
|
|
AdapterItem item = new AdapterItem();
|
|
|
|
|
item.viewType = VIEW_TYPE_EMPTY_SEARCH;
|
|
|
|
|
item.position = pos;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method for a dividerView in AllAppsSearch
|
|
|
|
|
*/
|
|
|
|
|
public static AdapterItem asAllAppsDivider(int pos) {
|
|
|
|
|
AdapterItem item = new AdapterItem();
|
|
|
|
|
item.viewType = VIEW_TYPE_ALL_APPS_DIVIDER;
|
|
|
|
|
item.position = pos;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method for a market search button
|
|
|
|
|
*/
|
|
|
|
|
public static AdapterItem asMarketSearch(int pos) {
|
|
|
|
|
AdapterItem item = new AdapterItem();
|
|
|
|
|
item.viewType = VIEW_TYPE_SEARCH_MARKET;
|
|
|
|
|
item.position = pos;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean isCountedForAccessibility() {
|
|
|
|
|
return viewType == VIEW_TYPE_ICON
|
2020-08-23 15:58:39 -07:00
|
|
|
|| viewType == VIEW_TYPE_SEARCH_ROW_WITH_BUTTON
|
|
|
|
|
|| viewType == VIEW_TYPE_SEARCH_SLICE
|
2020-09-03 09:42:54 -07:00
|
|
|
|| viewType == VIEW_TYPE_SEARCH_ROW
|
2020-09-08 14:00:56 -07:00
|
|
|
|| viewType == VIEW_TYPE_SEARCH_PEOPLE
|
2020-09-20 11:28:18 -07:00
|
|
|
|| viewType == VIEW_TYPE_SEARCH_THUMBNAIL
|
2020-09-28 01:53:31 -07:00
|
|
|
|| viewType == VIEW_TYPE_SEARCH_ICON_ROW
|
2020-10-14 10:15:07 -07:00
|
|
|
|| viewType == VIEW_TYPE_SEARCH_ICON
|
2020-09-28 01:53:31 -07:00
|
|
|
|| viewType == VIEW_TYPE_SEARCH_SUGGEST;
|
2020-08-15 09:40:26 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extension of AdapterItem that contains an extra payload specific to item
|
|
|
|
|
*/
|
2020-10-13 01:12:03 -07:00
|
|
|
public static class SearchAdapterItem extends AdapterItem {
|
|
|
|
|
private SearchTarget mSearchTarget;
|
2020-08-15 09:40:26 -07:00
|
|
|
|
2020-10-13 01:12:03 -07:00
|
|
|
public SearchAdapterItem(SearchTarget searchTarget, int type) {
|
|
|
|
|
mSearchTarget = searchTarget;
|
2020-08-15 09:40:26 -07:00
|
|
|
viewType = type;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-13 01:12:03 -07:00
|
|
|
public SearchTarget getSearchTarget() {
|
|
|
|
|
return mSearchTarget;
|
2020-08-15 09:40:26 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-30 12:53:33 -07:00
|
|
|
/**
|
|
|
|
|
* A subclass of GridLayoutManager that overrides accessibility values during app search.
|
|
|
|
|
*/
|
|
|
|
|
public class AppsGridLayoutManager extends GridLayoutManager {
|
|
|
|
|
|
|
|
|
|
public AppsGridLayoutManager(Context context) {
|
|
|
|
|
super(context, 1, GridLayoutManager.VERTICAL, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
|
|
|
|
|
super.onInitializeAccessibilityEvent(event);
|
2015-07-10 12:38:30 -07:00
|
|
|
|
|
|
|
|
// Ensure that we only report the number apps for accessibility not including other
|
|
|
|
|
// adapter views
|
|
|
|
|
final AccessibilityRecordCompat record = AccessibilityEventCompat
|
|
|
|
|
.asRecord(event);
|
|
|
|
|
record.setItemCount(mApps.getNumFilteredApps());
|
2017-02-21 16:43:56 -08:00
|
|
|
record.setFromIndex(Math.max(0,
|
|
|
|
|
record.getFromIndex() - getRowsNotForAccessibility(record.getFromIndex())));
|
|
|
|
|
record.setToIndex(Math.max(0,
|
|
|
|
|
record.getToIndex() - getRowsNotForAccessibility(record.getToIndex())));
|
2015-07-30 12:53:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getRowCountForAccessibility(RecyclerView.Recycler recycler,
|
|
|
|
|
RecyclerView.State state) {
|
2017-02-21 16:43:56 -08:00
|
|
|
return super.getRowCountForAccessibility(recycler, state) -
|
|
|
|
|
getRowsNotForAccessibility(mApps.getAdapterItems().size() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler,
|
|
|
|
|
RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
|
|
|
|
|
super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info);
|
|
|
|
|
|
|
|
|
|
ViewGroup.LayoutParams lp = host.getLayoutParams();
|
|
|
|
|
AccessibilityNodeInfoCompat.CollectionItemInfoCompat cic = info.getCollectionItemInfo();
|
|
|
|
|
if (!(lp instanceof LayoutParams) || (cic == null)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LayoutParams glp = (LayoutParams) lp;
|
|
|
|
|
info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
|
|
|
|
|
cic.getRowIndex() - getRowsNotForAccessibility(glp.getViewAdapterPosition()),
|
|
|
|
|
cic.getRowSpan(),
|
|
|
|
|
cic.getColumnIndex(),
|
|
|
|
|
cic.getColumnSpan(),
|
|
|
|
|
cic.isHeading(),
|
|
|
|
|
cic.isSelected()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of rows before {@param adapterPosition}, including this position
|
|
|
|
|
* which should not be counted towards the collection info.
|
|
|
|
|
*/
|
|
|
|
|
private int getRowsNotForAccessibility(int adapterPosition) {
|
|
|
|
|
List<AdapterItem> items = mApps.getAdapterItems();
|
|
|
|
|
adapterPosition = Math.max(adapterPosition, mApps.getAdapterItems().size() - 1);
|
|
|
|
|
int extraRows = 0;
|
|
|
|
|
for (int i = 0; i <= adapterPosition; i++) {
|
2018-01-23 13:52:48 -08:00
|
|
|
if (!isViewType(items.get(i).viewType, VIEW_TYPE_MASK_ICON)) {
|
2017-02-21 16:43:56 -08:00
|
|
|
extraRows++;
|
|
|
|
|
}
|
2015-07-30 12:53:33 -07:00
|
|
|
}
|
2017-02-21 16:43:56 -08:00
|
|
|
return extraRows;
|
2015-07-30 12:53:33 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
/**
|
|
|
|
|
* Helper class to size the grid items.
|
|
|
|
|
*/
|
|
|
|
|
public class GridSpanSizer extends GridLayoutManager.SpanSizeLookup {
|
2015-05-05 17:21:58 -07:00
|
|
|
|
|
|
|
|
public GridSpanSizer() {
|
|
|
|
|
super();
|
|
|
|
|
setSpanIndexCacheEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
@Override
|
|
|
|
|
public int getSpanSize(int position) {
|
2020-09-20 11:28:18 -07:00
|
|
|
int viewType = mApps.getAdapterItems().get(position).viewType;
|
|
|
|
|
if (isIconViewType(viewType)) {
|
|
|
|
|
return 1 * SPAN_MULTIPLIER;
|
|
|
|
|
} else if (viewType == VIEW_TYPE_SEARCH_THUMBNAIL) {
|
|
|
|
|
return mAppsPerRow;
|
2016-07-07 14:47:05 -07:00
|
|
|
} else {
|
2017-11-24 16:40:03 +08:00
|
|
|
// Section breaks span the full width
|
2020-09-20 11:28:18 -07:00
|
|
|
return mAppsPerRow * SPAN_MULTIPLIER;
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-20 11:28:18 -07:00
|
|
|
// multiplier to support adapter item column count that is not mAppsPerRow.
|
2020-09-24 20:23:06 -07:00
|
|
|
public static final int SPAN_MULTIPLIER = 3;
|
2020-09-20 11:28:18 -07:00
|
|
|
|
2020-01-07 13:07:55 -08:00
|
|
|
private final BaseDraggingActivity mLauncher;
|
2016-03-03 11:35:59 -08:00
|
|
|
private final LayoutInflater mLayoutInflater;
|
|
|
|
|
private final AlphabeticalAppsList mApps;
|
|
|
|
|
private final GridLayoutManager mGridLayoutMgr;
|
|
|
|
|
private final GridSpanSizer mGridSizer;
|
|
|
|
|
|
2020-01-07 13:07:55 -08:00
|
|
|
private final OnClickListener mOnIconClickListener;
|
|
|
|
|
private OnLongClickListener mOnIconLongClickListener = INSTANCE_ALL_APPS;
|
|
|
|
|
|
2019-09-16 14:44:14 -07:00
|
|
|
private int mAppsPerRow;
|
2016-03-03 13:52:22 -08:00
|
|
|
|
2016-05-09 20:43:21 -07:00
|
|
|
private OnFocusChangeListener mIconFocusListener;
|
2015-07-10 12:38:30 -07:00
|
|
|
|
|
|
|
|
// The text to show when there are no search results and no market search handler.
|
2020-01-07 13:07:55 -08:00
|
|
|
protected String mEmptySearchMessage;
|
2015-07-10 12:38:30 -07:00
|
|
|
// The intent to send off to the market app, updated each time the search query changes.
|
|
|
|
|
private Intent mMarketSearchIntent;
|
2015-03-10 16:28:47 -07:00
|
|
|
|
2020-06-05 12:17:16 -07:00
|
|
|
public AllAppsGridAdapter(BaseDraggingActivity launcher, LayoutInflater inflater,
|
|
|
|
|
AlphabeticalAppsList apps) {
|
2015-07-10 12:38:30 -07:00
|
|
|
Resources res = launcher.getResources();
|
|
|
|
|
mLauncher = launcher;
|
2015-03-10 16:28:47 -07:00
|
|
|
mApps = apps;
|
2015-07-10 12:38:30 -07:00
|
|
|
mEmptySearchMessage = res.getString(R.string.all_apps_loading_message);
|
2015-03-10 16:28:47 -07:00
|
|
|
mGridSizer = new GridSpanSizer();
|
2015-07-10 12:38:30 -07:00
|
|
|
mGridLayoutMgr = new AppsGridLayoutManager(launcher);
|
2015-04-08 10:27:49 -07:00
|
|
|
mGridLayoutMgr.setSpanSizeLookup(mGridSizer);
|
2020-06-05 12:17:16 -07:00
|
|
|
mLayoutInflater = inflater;
|
2018-01-30 20:52:27 -08:00
|
|
|
|
2020-01-07 13:07:55 -08:00
|
|
|
mOnIconClickListener = launcher.getItemOnClickListener();
|
|
|
|
|
|
2019-09-16 14:44:14 -07:00
|
|
|
setAppsPerRow(mLauncher.getDeviceProfile().inv.numAllAppsColumns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAppsPerRow(int appsPerRow) {
|
|
|
|
|
mAppsPerRow = appsPerRow;
|
2020-09-20 11:28:18 -07:00
|
|
|
mGridLayoutMgr.setSpanCount(mAppsPerRow * SPAN_MULTIPLIER);
|
2017-06-06 15:41:21 -07:00
|
|
|
}
|
|
|
|
|
|
2020-01-07 13:07:55 -08:00
|
|
|
/**
|
|
|
|
|
* Sets the long click listener for icons
|
|
|
|
|
*/
|
|
|
|
|
public void setOnIconLongClickListener(@Nullable OnLongClickListener listener) {
|
|
|
|
|
mOnIconLongClickListener = listener;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-07 14:47:05 -07:00
|
|
|
public static boolean isDividerViewType(int viewType) {
|
|
|
|
|
return isViewType(viewType, VIEW_TYPE_MASK_DIVIDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isIconViewType(int viewType) {
|
|
|
|
|
return isViewType(viewType, VIEW_TYPE_MASK_ICON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isViewType(int viewType, int viewTypeMask) {
|
|
|
|
|
return (viewType & viewTypeMask) != 0;
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-09 20:43:21 -07:00
|
|
|
public void setIconFocusListener(OnFocusChangeListener focusListener) {
|
|
|
|
|
mIconFocusListener = focusListener;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-13 11:14:16 -07:00
|
|
|
/**
|
2015-07-10 12:38:30 -07:00
|
|
|
* 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.
|
2015-03-13 11:14:16 -07:00
|
|
|
*/
|
2015-07-10 12:38:30 -07:00
|
|
|
public void setLastSearchQuery(String query) {
|
|
|
|
|
Resources res = mLauncher.getResources();
|
2015-09-02 15:06:12 -07:00
|
|
|
mEmptySearchMessage = res.getString(R.string.all_apps_no_search_results, query);
|
2017-05-07 11:56:00 -07:00
|
|
|
mMarketSearchIntent = PackageManagerHelper.getMarketSearchIntent(mLauncher, query);
|
2015-03-13 11:14:16 -07:00
|
|
|
}
|
|
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
/**
|
|
|
|
|
* Returns the grid layout manager.
|
|
|
|
|
*/
|
2015-05-05 17:21:58 -07:00
|
|
|
public GridLayoutManager getLayoutManager() {
|
2015-04-08 10:27:49 -07:00
|
|
|
return mGridLayoutMgr;
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
switch (viewType) {
|
2016-07-07 14:47:05 -07:00
|
|
|
case VIEW_TYPE_ICON:
|
2015-07-06 17:14:51 -07:00
|
|
|
BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(
|
2016-07-11 18:59:18 -07:00
|
|
|
R.layout.all_apps_icon, parent, false);
|
2018-09-24 17:24:51 -04:00
|
|
|
icon.setLongPressTimeoutFactor(1f);
|
2016-05-09 20:43:21 -07:00
|
|
|
icon.setOnFocusChangeListener(mIconFocusListener);
|
2020-10-14 10:15:07 -07:00
|
|
|
icon.setOnClickListener(mOnIconClickListener);
|
|
|
|
|
icon.setOnLongClickListener(mOnIconLongClickListener);
|
2017-06-20 10:58:36 -07:00
|
|
|
// Ensure the all apps icon height matches the workspace icons in portrait mode.
|
|
|
|
|
icon.getLayoutParams().height = mLauncher.getDeviceProfile().allAppsCellHeightPx;
|
2017-06-06 20:36:24 +00:00
|
|
|
return new ViewHolder(icon);
|
2016-07-07 14:47:05 -07:00
|
|
|
case VIEW_TYPE_EMPTY_SEARCH:
|
2017-06-06 20:36:24 +00:00
|
|
|
return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
|
2015-07-10 12:38:30 -07:00
|
|
|
parent, false));
|
2016-07-07 14:47:05 -07:00
|
|
|
case VIEW_TYPE_SEARCH_MARKET:
|
2015-07-10 12:38:30 -07:00
|
|
|
View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market,
|
|
|
|
|
parent, false);
|
2019-03-26 15:03:57 -07:00
|
|
|
searchMarketView.setOnClickListener(v -> mLauncher.startActivitySafely(
|
2020-07-15 17:02:16 -07:00
|
|
|
v, mMarketSearchIntent, null));
|
2017-06-06 20:36:24 +00:00
|
|
|
return new ViewHolder(searchMarketView);
|
2017-11-24 16:40:03 +08:00
|
|
|
case VIEW_TYPE_ALL_APPS_DIVIDER:
|
2017-06-06 20:36:24 +00:00
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
2016-07-07 14:47:05 -07:00
|
|
|
R.layout.all_apps_divider, parent, false));
|
2020-10-14 10:15:07 -07:00
|
|
|
case VIEW_TYPE_SEARCH_ICON:
|
|
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
|
|
|
|
R.layout.search_result_icon, parent, false));
|
2020-07-26 19:11:14 -07:00
|
|
|
case VIEW_TYPE_SEARCH_CORPUS_TITLE:
|
|
|
|
|
return new ViewHolder(
|
|
|
|
|
mLayoutInflater.inflate(R.layout.search_section_title, parent, false));
|
2020-08-23 15:58:39 -07:00
|
|
|
case VIEW_TYPE_SEARCH_ROW_WITH_BUTTON:
|
2020-08-15 09:40:26 -07:00
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
|
|
|
|
R.layout.search_result_play_item, parent, false));
|
2020-08-23 15:58:39 -07:00
|
|
|
case VIEW_TYPE_SEARCH_ROW:
|
|
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
|
|
|
|
R.layout.search_result_settings_row, parent, false));
|
|
|
|
|
case VIEW_TYPE_SEARCH_SLICE:
|
|
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
|
|
|
|
R.layout.search_result_slice, parent, false));
|
2020-09-23 00:45:27 -07:00
|
|
|
case VIEW_TYPE_SEARCH_ICON_ROW:
|
2020-09-03 09:42:54 -07:00
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
2020-09-23 00:45:27 -07:00
|
|
|
R.layout.search_result_icon_row, parent, false));
|
2020-09-08 14:00:56 -07:00
|
|
|
case VIEW_TYPE_SEARCH_PEOPLE:
|
|
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
|
|
|
|
R.layout.search_result_people_item, parent, false));
|
2020-09-20 11:28:18 -07:00
|
|
|
case VIEW_TYPE_SEARCH_THUMBNAIL:
|
|
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
|
|
|
|
R.layout.search_result_thumbnail, parent, false));
|
2020-09-28 01:53:31 -07:00
|
|
|
case VIEW_TYPE_SEARCH_SUGGEST:
|
|
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
|
|
|
|
R.layout.search_result_suggest, parent, false));
|
2015-03-10 16:28:47 -07:00
|
|
|
default:
|
|
|
|
|
throw new RuntimeException("Unexpected view type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
2020-10-14 10:15:07 -07:00
|
|
|
if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()
|
|
|
|
|
&& holder.itemView instanceof AllAppsSectionDecorator.SelfDecoratingView) {
|
|
|
|
|
((AllAppsSectionDecorator.SelfDecoratingView) holder.itemView).removeDecoration();
|
|
|
|
|
}
|
2017-06-06 20:36:24 +00:00
|
|
|
switch (holder.getItemViewType()) {
|
2017-02-17 12:16:13 -08:00
|
|
|
case VIEW_TYPE_ICON:
|
2020-09-10 12:05:19 -07:00
|
|
|
AdapterItem adapterItem = mApps.getAdapterItems().get(position);
|
|
|
|
|
AppInfo info = adapterItem.appInfo;
|
2016-10-13 09:31:24 -07:00
|
|
|
BubbleTextView icon = (BubbleTextView) holder.itemView;
|
2017-10-26 11:28:06 -07:00
|
|
|
icon.reset();
|
2015-03-13 11:14:16 -07:00
|
|
|
icon.applyFromApplicationInfo(info);
|
|
|
|
|
break;
|
2016-07-07 14:47:05 -07:00
|
|
|
case VIEW_TYPE_EMPTY_SEARCH:
|
2016-10-13 09:31:24 -07:00
|
|
|
TextView emptyViewText = (TextView) holder.itemView;
|
2015-07-10 12:38:30 -07:00
|
|
|
emptyViewText.setText(mEmptySearchMessage);
|
2015-08-19 17:26:21 -07:00
|
|
|
emptyViewText.setGravity(mApps.hasNoFilteredResults() ? Gravity.CENTER :
|
|
|
|
|
Gravity.START | Gravity.CENTER_VERTICAL);
|
2015-07-10 12:38:30 -07:00
|
|
|
break;
|
2016-07-07 14:47:05 -07:00
|
|
|
case VIEW_TYPE_SEARCH_MARKET:
|
2016-10-13 09:31:24 -07:00
|
|
|
TextView searchView = (TextView) holder.itemView;
|
2015-07-10 12:38:30 -07:00
|
|
|
if (mMarketSearchIntent != null) {
|
|
|
|
|
searchView.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
searchView.setVisibility(View.GONE);
|
|
|
|
|
}
|
2020-08-23 15:58:39 -07:00
|
|
|
break;
|
2020-07-26 19:11:14 -07:00
|
|
|
case VIEW_TYPE_SEARCH_CORPUS_TITLE:
|
2020-08-23 15:58:39 -07:00
|
|
|
case VIEW_TYPE_SEARCH_ROW_WITH_BUTTON:
|
2020-11-02 13:45:08 -06:00
|
|
|
case VIEW_TYPE_SEARCH_SLICE:
|
2020-08-23 15:58:39 -07:00
|
|
|
case VIEW_TYPE_SEARCH_ROW:
|
2020-10-14 10:15:07 -07:00
|
|
|
case VIEW_TYPE_SEARCH_ICON:
|
2020-09-23 00:45:27 -07:00
|
|
|
case VIEW_TYPE_SEARCH_ICON_ROW:
|
2020-09-08 14:00:56 -07:00
|
|
|
case VIEW_TYPE_SEARCH_PEOPLE:
|
2020-09-20 11:28:18 -07:00
|
|
|
case VIEW_TYPE_SEARCH_THUMBNAIL:
|
2020-09-28 01:53:31 -07:00
|
|
|
case VIEW_TYPE_SEARCH_SUGGEST:
|
2020-10-13 01:12:03 -07:00
|
|
|
SearchAdapterItem item =
|
|
|
|
|
(SearchAdapterItem) mApps.getAdapterItems().get(position);
|
|
|
|
|
SearchTargetHandler payloadResultView = (SearchTargetHandler) holder.itemView;
|
2020-10-16 02:01:31 -07:00
|
|
|
payloadResultView.applySearchTarget(item.getSearchTarget());
|
2020-08-04 14:06:55 -07:00
|
|
|
break;
|
2017-11-24 16:40:03 +08:00
|
|
|
case VIEW_TYPE_ALL_APPS_DIVIDER:
|
2017-02-17 12:16:13 -08:00
|
|
|
// nothing to do
|
|
|
|
|
break;
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|
2015-08-21 11:16:27 -07:00
|
|
|
}
|
|
|
|
|
|
2020-09-10 12:05:19 -07:00
|
|
|
@Override
|
|
|
|
|
public void onViewRecycled(@NonNull ViewHolder holder) {
|
|
|
|
|
super.onViewRecycled(holder);
|
|
|
|
|
if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) return;
|
2020-10-14 10:15:07 -07:00
|
|
|
if (holder.itemView instanceof AllAppsSectionDecorator.SelfDecoratingView) {
|
|
|
|
|
((AllAppsSectionDecorator.SelfDecoratingView) holder.itemView).removeDecoration();
|
|
|
|
|
}
|
2020-09-10 12:05:19 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-21 11:16:27 -07:00
|
|
|
@Override
|
|
|
|
|
public boolean onFailedToRecycleView(ViewHolder holder) {
|
|
|
|
|
// Always recycle and we will reset the view when it is bound
|
|
|
|
|
return true;
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemCount() {
|
2015-04-06 15:12:49 -07:00
|
|
|
return mApps.getAdapterItems().size();
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemViewType(int position) {
|
2020-08-15 09:40:26 -07:00
|
|
|
AdapterItem item = mApps.getAdapterItems().get(position);
|
2015-05-12 19:05:30 -07:00
|
|
|
return item.viewType;
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|
|
|
|
|
}
|