Migrate from Plugin SearchTarget to API search Target [2/3]

- Adds support for android.app.search.SearchTarget in plugin while maintaining plugin SearchTarget support
- Introduces SEARCH_TARGET_LEGACY temporary to switch between plugin and sdk variants.
- Maps resultType and layoutType pairs to the appropriate view

Bug: 177223401
Test: Manual
Change-Id: If8d4bb7c21c47a12447dcb0c56eed8781bd21e54
This commit is contained in:
Samuel Fufa 2021-01-12 20:39:46 -06:00
parent 992ab43390
commit a60d1f9be7
21 changed files with 209 additions and 111 deletions

View File

@ -18,15 +18,18 @@ package com.android.launcher3.search;
import static com.android.launcher3.allapps.AllAppsGridAdapter.VIEW_TYPE_ICON;
import android.app.search.SearchTarget;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsGridAdapter;
import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.launcher3.config.FeatureFlags;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
/**
* Provides views for on-device search results
@ -45,11 +48,13 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
public static final int VIEW_TYPE_SEARCH_WIDGET_LIVE = 1 << 15;
public static final int VIEW_TYPE_SEARCH_WIDGET_PREVIEW = 1 << 16;
private final AllAppsContainerView mAppsView;
private final SparseIntArray mViewTypeToLayoutMap = new SparseIntArray();
public DeviceSearchAdapterProvider(Launcher launcher) {
public DeviceSearchAdapterProvider(Launcher launcher, AllAppsContainerView appsView) {
super(launcher);
mAppsView = appsView;
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_ICON, R.layout.search_result_icon);
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_CORPUS_TITLE, R.layout.search_section_title);
@ -68,12 +73,16 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
@Override
public void onBindView(AllAppsGridAdapter.ViewHolder holder, int position) {
SearchAdapterItem item = (SearchAdapterItem) Launcher.getLauncher(mLauncher)
.getAppsView().getApps().getAdapterItems().get(position);
SearchAdapterItem item = (SearchAdapterItem) mAppsView.getApps().getAdapterItems().get(
position);
SearchTargetHandler
payloadResultView =
(SearchTargetHandler) holder.itemView;
payloadResultView.applySearchTarget(item.getSearchTarget());
if (FeatureFlags.SEARCH_TARGET_LEGACY.get()) {
payloadResultView.applySearchTarget(item.getSearchTargetLegacy());
} else {
payloadResultView.applySearchTarget(item.getSearchTarget());
}
}
@Override
@ -101,10 +110,23 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
@Override
public boolean onAdapterItemSelected(AllAppsGridAdapter.AdapterItem focusedItem) {
if (focusedItem instanceof SearchTargetHandler) {
SearchTarget searchTarget = ((SearchAdapterItem) focusedItem).getSearchTarget();
SearchTargetLegacy searchTarget = ((SearchAdapterItem) focusedItem)
.getSearchTargetLegacy();
SearchEventTracker.INSTANCE.get(mLauncher).quickSelect(searchTarget);
return true;
}
return false;
}
/**
* Determines what view type should be used to present search target.
* Returns -1 if viewType is not found
*/
public int getViewTypeForSearchTarget(SearchTarget t) {
//TODO: Replace with values from :SearchUi
if (t.getResultType() == 1 && t.getLayoutType().equals("icon")) {
return VIEW_TYPE_SEARCH_ICON;
}
return -1;
}
}

View File

@ -27,13 +27,16 @@ import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_WIDGET_LIVE;
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_WIDGET_PREVIEW;
import android.app.search.SearchTarget;
import com.android.launcher3.allapps.AllAppsGridAdapter;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
/**
* Extension of AdapterItem that contains an extra payload specific to item
*/
public class SearchAdapterItem extends AllAppsGridAdapter.AdapterItem {
private SearchTargetLegacy mSearchTargetLegacy;
private SearchTarget mSearchTarget;
@ -43,11 +46,21 @@ public class SearchAdapterItem extends AllAppsGridAdapter.AdapterItem {
| VIEW_TYPE_SEARCH_WIDGET_PREVIEW | VIEW_TYPE_SEARCH_WIDGET_LIVE
| VIEW_TYPE_SEARCH_SUGGEST;
public SearchAdapterItem(SearchTargetLegacy searchTargetLegacy, int type) {
mSearchTargetLegacy = searchTargetLegacy;
viewType = type;
}
public SearchAdapterItem(SearchTarget searchTarget, int type) {
mSearchTarget = searchTarget;
viewType = type;
}
public SearchTargetLegacy getSearchTargetLegacy() {
return mSearchTargetLegacy;
}
public SearchTarget getSearchTarget() {
return mSearchTarget;
}

View File

@ -23,8 +23,8 @@ import androidx.annotation.Nullable;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.systemui.plugins.AllAppsSearchPlugin;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
import java.util.WeakHashMap;
@ -34,7 +34,7 @@ import java.util.WeakHashMap;
public class SearchEventTracker {
@Nullable
private AllAppsSearchPlugin mPlugin;
private final WeakHashMap<SearchTarget, SearchTargetHandler>
private final WeakHashMap<SearchTargetLegacy, SearchTargetHandler>
mCallbacks = new WeakHashMap<>();
public static final MainThreadInitializedObject<SearchEventTracker> INSTANCE =
@ -60,26 +60,27 @@ public class SearchEventTracker {
/**
* Sends SearchTargetEvent to search provider
*/
public void notifySearchTargetEvent(SearchTargetEvent searchTargetEvent) {
public void notifySearchTargetEvent(SearchTargetEventLegacy searchTargetEvent) {
if (mPlugin != null) {
UI_HELPER_EXECUTOR.post(() -> mPlugin.notifySearchTargetEvent(searchTargetEvent));
UI_HELPER_EXECUTOR.post(() -> mPlugin.notifySearchTargetEventLegacy(searchTargetEvent));
}
}
/**
* Registers a {@link SearchTargetHandler} to handle quick launch for specified SearchTarget.
*/
public void registerWeakHandler(SearchTarget searchTarget, SearchTargetHandler targetHandler) {
public void registerWeakHandler(SearchTargetLegacy searchTarget,
SearchTargetHandler targetHandler) {
mCallbacks.put(searchTarget, targetHandler);
}
/**
* Handles quick select for SearchTarget
*/
public void quickSelect(SearchTarget searchTarget) {
public void quickSelect(SearchTargetLegacy searchTarget) {
SearchTargetHandler searchTargetHandler = mCallbacks.get(searchTarget);
if (searchTargetHandler != null) {
searchTargetHandler.handleSelection(SearchTargetEvent.QUICK_SELECT);
searchTargetHandler.handleSelection(SearchTargetEventLegacy.QUICK_SELECT);
}
}

View File

@ -20,6 +20,7 @@ import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.app.RemoteAction;
import android.app.search.SearchTarget;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ShortcutInfo;
@ -42,8 +43,8 @@ import com.android.launcher3.model.data.RemoteActionItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.util.ComponentKey;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
import java.util.function.Consumer;
@ -69,7 +70,7 @@ public class SearchResultIcon extends BubbleTextView implements
private final Launcher mLauncher;
private SearchTarget mSearchTarget;
private SearchTargetLegacy mSearchTarget;
private Consumer<ItemInfoWithIcon> mOnItemInfoChanged;
public SearchResultIcon(Context context) {
@ -100,13 +101,13 @@ public class SearchResultIcon extends BubbleTextView implements
* Applies search target with a ItemInfoWithIcon consumer to be called after itemInfo is
* constructed
*/
public void applySearchTarget(SearchTarget searchTarget, Consumer<ItemInfoWithIcon> cb) {
public void applySearchTarget(SearchTargetLegacy searchTarget, Consumer<ItemInfoWithIcon> cb) {
mOnItemInfoChanged = cb;
applySearchTarget(searchTarget);
}
@Override
public void applySearchTarget(SearchTarget searchTarget) {
public void applySearchTarget(SearchTargetLegacy searchTarget) {
mSearchTarget = searchTarget;
SearchEventTracker.getInstance(getContext()).registerWeakHandler(mSearchTarget, this);
setVisibility(VISIBLE);
@ -127,9 +128,16 @@ public class SearchResultIcon extends BubbleTextView implements
}
}
@Override
public void applySearchTarget(SearchTarget searchTarget) {
prepareUsingApp(new ComponentName(searchTarget.getPackageName(),
searchTarget.getExtras().getString("class")), searchTarget.getUserHandle());
}
private void prepareUsingApp(ComponentName componentName, UserHandle userHandle) {
AllAppsStore appsStore = mLauncher.getAppsView().getAppsStore();
AppInfo appInfo = appsStore.getApp(new ComponentKey(componentName, userHandle));
if (appInfo == null) {
setVisibility(GONE);
return;
@ -181,7 +189,8 @@ public class SearchResultIcon extends BubbleTextView implements
}
private void reportEvent(int eventType) {
SearchTargetEvent.Builder b = new SearchTargetEvent.Builder(mSearchTarget, eventType);
SearchTargetEventLegacy.Builder b = new SearchTargetEventLegacy.Builder(mSearchTarget,
eventType);
if (mSearchTarget.getItemType().equals(TARGET_TYPE_SHORTCUT)) {
b.setShortcutPosition(0);
}
@ -191,7 +200,7 @@ public class SearchResultIcon extends BubbleTextView implements
@Override
public void onClick(View view) {
handleSelection(SearchTargetEvent.SELECT);
handleSelection(SearchTargetEventLegacy.SELECT);
}
@Override
@ -199,7 +208,7 @@ public class SearchResultIcon extends BubbleTextView implements
if (!supportsLongPress(mSearchTarget.getItemType())) {
return false;
}
reportEvent(SearchTargetEvent.LONG_PRESS);
reportEvent(SearchTargetEventLegacy.LONG_PRESS);
return ItemLongClickListener.INSTANCE_ALL_APPS.onLongClick(view);
}

View File

@ -39,8 +39,8 @@ import com.android.launcher3.R;
import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.model.data.PackageItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
import java.util.ArrayList;
import java.util.List;
@ -63,7 +63,7 @@ public class SearchResultIconRow extends LinearLayout implements
private TextView mDescriptionView;
private BubbleTextView[] mShortcutViews = new BubbleTextView[2];
private SearchTarget mSearchTarget;
private SearchTargetLegacy mSearchTarget;
private PackageItemInfo mProviderInfo;
@ -100,8 +100,9 @@ public class SearchResultIconRow extends LinearLayout implements
lp.width = iconSize;
bubbleTextView.setOnClickListener(view -> {
WorkspaceItemInfo itemInfo = (WorkspaceItemInfo) bubbleTextView.getTag();
SearchTargetEvent event = new SearchTargetEvent.Builder(mSearchTarget,
SearchTargetEvent.CHILD_SELECT).setShortcutPosition(itemInfo.rank).build();
SearchTargetEventLegacy event = new SearchTargetEventLegacy.Builder(mSearchTarget,
SearchTargetEventLegacy.CHILD_SELECT).setShortcutPosition(
itemInfo.rank).build();
SearchEventTracker.getInstance(getContext()).notifySearchTargetEvent(event);
mLauncher.getItemOnClickListener().onClick(view);
});
@ -111,7 +112,7 @@ public class SearchResultIconRow extends LinearLayout implements
}
@Override
public void applySearchTarget(SearchTarget searchTarget) {
public void applySearchTarget(SearchTargetLegacy searchTarget) {
mSearchTarget = searchTarget;
mResultIcon.applySearchTarget(searchTarget, this);
String itemType = searchTarget.getItemType();

View File

@ -44,8 +44,8 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.LauncherIcons;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
import java.util.ArrayList;
@ -66,7 +66,7 @@ public class SearchResultPeopleView extends LinearLayout implements
private Intent mIntent;
private SearchTarget mSearchTarget;
private SearchTargetLegacy mSearchTarget;
public SearchResultPeopleView(Context context) {
this(context, null, 0);
@ -99,11 +99,11 @@ public class SearchResultPeopleView extends LinearLayout implements
button.getLayoutParams().width = mButtonSize;
button.getLayoutParams().height = mButtonSize;
}
setOnClickListener(v -> handleSelection(SearchTargetEvent.SELECT));
setOnClickListener(v -> handleSelection(SearchTargetEventLegacy.SELECT));
}
@Override
public void applySearchTarget(SearchTarget searchTarget) {
public void applySearchTarget(SearchTargetLegacy searchTarget) {
mSearchTarget = searchTarget;
Bundle payload = searchTarget.getExtras();
mTitleView.setText(payload.getString("title"));
@ -186,8 +186,8 @@ public class SearchResultPeopleView extends LinearLayout implements
Bundle bundle = new Bundle();
bundle.putBundle("provider", provider);
SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
new SearchTargetEvent.Builder(mSearchTarget,
SearchTargetEvent.CHILD_SELECT).setExtras(bundle).build());
new SearchTargetEventLegacy.Builder(mSearchTarget,
SearchTargetEventLegacy.CHILD_SELECT).setExtras(bundle).build());
});
}
@ -197,7 +197,7 @@ public class SearchResultPeopleView extends LinearLayout implements
Launcher launcher = Launcher.getLauncher(getContext());
launcher.startActivitySafely(this, mIntent, null);
SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
}
}
}

View File

@ -43,8 +43,8 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.icons.BitmapRenderer;
import com.android.launcher3.util.Themes;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
import java.io.IOException;
import java.net.URL;
@ -69,7 +69,7 @@ public class SearchResultPlayItem extends LinearLayout implements
private String mPackageName;
private boolean mIsInstantGame;
private SearchTarget mSearchTarget;
private SearchTargetLegacy mSearchTarget;
public SearchResultPlayItem(Context context) {
@ -101,7 +101,7 @@ public class SearchResultPlayItem extends LinearLayout implements
ViewGroup.LayoutParams iconParams = mIconView.getLayoutParams();
iconParams.height = mDeviceProfile.allAppsIconSizePx;
iconParams.width = mDeviceProfile.allAppsIconSizePx;
setOnClickListener(view -> handleSelection(SearchTargetEvent.SELECT));
setOnClickListener(view -> handleSelection(SearchTargetEventLegacy.SELECT));
}
@ -127,7 +127,7 @@ public class SearchResultPlayItem extends LinearLayout implements
@Override
public void applySearchTarget(SearchTarget searchTarget) {
public void applySearchTarget(SearchTargetLegacy searchTarget) {
mSearchTarget = searchTarget;
Bundle bundle = searchTarget.getExtras();
SearchEventTracker.INSTANCE.get(getContext()).registerWeakHandler(searchTarget, this);
@ -193,11 +193,11 @@ public class SearchResultPlayItem extends LinearLayout implements
intent.putExtra("callerId", getContext().getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(intent);
logSearchEvent(SearchTargetEvent.CHILD_SELECT);
logSearchEvent(SearchTargetEventLegacy.CHILD_SELECT);
}
private void logSearchEvent(int eventType) {
SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
}
}

View File

@ -32,8 +32,8 @@ import androidx.slice.widget.SliceView;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
/**
* A slice view wrapper with settings app icon at start
@ -50,7 +50,7 @@ public class SearchResultSettingsSlice extends LinearLayout implements
private SliceView mSliceView;
private View mIcon;
private LiveData<Slice> mSliceLiveData;
private SearchTarget mSearchTarget;
private SearchTargetLegacy mSearchTarget;
private final Launcher mLauncher;
public SearchResultSettingsSlice(Context context) {
@ -77,7 +77,7 @@ public class SearchResultSettingsSlice extends LinearLayout implements
}
@Override
public void applySearchTarget(SearchTarget searchTarget) {
public void applySearchTarget(SearchTargetLegacy searchTarget) {
reset();
mSearchTarget = searchTarget;
try {
@ -103,8 +103,8 @@ public class SearchResultSettingsSlice extends LinearLayout implements
@Override
public void handleSelection(int eventType) {
SearchEventTracker.INSTANCE.get(mLauncher).notifySearchTargetEvent(
new SearchTargetEvent.Builder(mSearchTarget,
SearchTargetEvent.CHILD_SELECT).build());
new SearchTargetEventLegacy.Builder(mSearchTarget,
SearchTargetEventLegacy.CHILD_SELECT).build());
}
private void reset() {
@ -116,7 +116,7 @@ public class SearchResultSettingsSlice extends LinearLayout implements
@Override
public void onSliceAction(@NonNull EventInfo eventInfo, @NonNull SliceItem sliceItem) {
handleSelection(SearchTargetEvent.CHILD_SELECT);
handleSelection(SearchTargetEventLegacy.CHILD_SELECT);
}
private Uri getSliceUri() {

View File

@ -36,8 +36,8 @@ import com.android.launcher3.allapps.search.SearchWidgetInfoContainer;
import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.widget.PendingAddWidgetInfo;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
/**
* displays live version of a widget upon receiving {@link AppWidgetProviderInfo} from Search
@ -58,7 +58,7 @@ public class SearchResultWidget extends RelativeLayout implements
private final AppWidgetHostView mHostView;
private final float mScaleToFit;
private SearchTarget mSearchTarget;
private SearchTargetLegacy mSearchTarget;
private AppWidgetProviderInfo mProviderInfo;
private SearchWidgetInfoContainer mInfoContainer;
@ -82,7 +82,7 @@ public class SearchResultWidget extends RelativeLayout implements
// detect tap event on widget container for search target event reporting
mClickDetector = new GestureDetector(context,
new ClickListener(() -> handleSelection(SearchTargetEvent.CHILD_SELECT)));
new ClickListener(() -> handleSelection(SearchTargetEventLegacy.CHILD_SELECT)));
mLongPressHelper = new CheckLongPressHelper(this);
mLongPressHelper.setLongPressTimeoutFactor(1);
@ -96,7 +96,7 @@ public class SearchResultWidget extends RelativeLayout implements
}
@Override
public void applySearchTarget(SearchTarget searchTarget) {
public void applySearchTarget(SearchTargetLegacy searchTarget) {
if (searchTarget.getExtras() == null
|| searchTarget.getExtras().getParcelable("provider") == null) {
setVisibility(GONE);
@ -141,7 +141,7 @@ public class SearchResultWidget extends RelativeLayout implements
@Override
public void handleSelection(int eventType) {
SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
}
@Override
@ -182,7 +182,7 @@ public class SearchResultWidget extends RelativeLayout implements
@Override
public boolean onLongClick(View view) {
ItemLongClickListener.INSTANCE_ALL_APPS.onLongClick(view);
handleSelection(SearchTargetEvent.LONG_PRESS);
handleSelection(SearchTargetEventLegacy.LONG_PRESS);
return false;
}

View File

@ -39,8 +39,8 @@ import com.android.launcher3.widget.BaseWidgetSheet;
import com.android.launcher3.widget.PendingItemDragHelper;
import com.android.launcher3.widget.WidgetCell;
import com.android.launcher3.widget.WidgetImageView;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
/**
* displays preview of a widget upon receiving {@link AppWidgetProviderInfo} from Search provider
@ -55,7 +55,7 @@ public class SearchResultWidgetPreview extends LinearLayout implements
private WidgetCell mWidgetCell;
private Toast mWidgetToast;
private SearchTarget mSearchTarget;
private SearchTargetLegacy mSearchTarget;
public SearchResultWidgetPreview(Context context) {
@ -83,7 +83,7 @@ public class SearchResultWidgetPreview extends LinearLayout implements
}
@Override
public void applySearchTarget(SearchTarget searchTarget) {
public void applySearchTarget(SearchTargetLegacy searchTarget) {
if (searchTarget.getExtras() == null
|| searchTarget.getExtras().getParcelable("provider") == null) {
setVisibility(GONE);
@ -121,19 +121,19 @@ public class SearchResultWidgetPreview extends LinearLayout implements
new PendingItemDragHelper(mWidgetCell).startDrag(
imageView.getBitmapBounds(), imageView.getBitmap().getWidth(), imageView.getWidth(),
new Point(loc[0], loc[1]), mLauncher.getAppsView(), new DragOptions());
handleSelection(SearchTargetEvent.LONG_PRESS);
handleSelection(SearchTargetEventLegacy.LONG_PRESS);
return true;
}
@Override
public void onClick(View view) {
mWidgetToast = BaseWidgetSheet.showWidgetToast(getContext(), mWidgetToast);
handleSelection(SearchTargetEvent.SELECT);
handleSelection(SearchTargetEventLegacy.SELECT);
}
@Override
public void handleSelection(int eventType) {
SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
}
}

View File

@ -21,7 +21,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
/**
* Header text view that shows a title for a given section in All apps search
@ -44,7 +44,7 @@ public class SearchSectionHeaderView extends TextView implements
}
@Override
public void applySearchTarget(SearchTarget searchTarget) {
public void applySearchTarget(SearchTargetLegacy searchTarget) {
String title = searchTarget.getExtras().getString("title");
if (title == null || !title.isEmpty()) {
setText(title);

View File

@ -38,8 +38,8 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.model.data.PackageItemInfo;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
import java.util.ArrayList;
import java.util.List;
@ -56,7 +56,7 @@ public class SearchSettingsRowView extends LinearLayout implements
private TextView mTitleView;
private TextView mBreadcrumbsView;
private Intent mIntent;
private SearchTarget mSearchTarget;
private SearchTargetLegacy mSearchTarget;
public SearchSettingsRowView(@NonNull Context context) {
@ -84,7 +84,7 @@ public class SearchSettingsRowView extends LinearLayout implements
}
@Override
public void applySearchTarget(SearchTarget searchTarget) {
public void applySearchTarget(SearchTargetLegacy searchTarget) {
mSearchTarget = searchTarget;
Bundle bundle = searchTarget.getExtras();
mIntent = bundle.getParcelable("intent");
@ -108,7 +108,7 @@ public class SearchSettingsRowView extends LinearLayout implements
@Override
public void onClick(View view) {
handleSelection(SearchTargetEvent.SELECT);
handleSelection(SearchTargetEventLegacy.SELECT);
}
@Override
@ -120,7 +120,7 @@ public class SearchSettingsRowView extends LinearLayout implements
launcher.startActivityForResult(mIntent, 0);
SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
}
/**

View File

@ -16,7 +16,9 @@
package com.android.launcher3.search;
import com.android.systemui.plugins.shared.SearchTarget;
import android.app.search.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
/**
* An interface for supporting dynamic search results
@ -24,9 +26,16 @@ import com.android.systemui.plugins.shared.SearchTarget;
public interface SearchTargetHandler {
/**
* Update view using values from {@link SearchTarget}
* Update view using values from {@link SearchTargetLegacy}
*/
void applySearchTarget(SearchTarget searchTarget);
void applySearchTarget(SearchTargetLegacy searchTarget);
/**
* Update view using values from {@link SearchTargetLegacy}
*/
default void applySearchTarget(SearchTarget searchTarget){
}
/**
* Handles selection of SearchTarget

View File

@ -35,8 +35,8 @@ import com.android.launcher3.model.data.RemoteActionItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.util.Themes;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
/**
* A view representing a high confidence app search result that includes shortcuts
@ -47,7 +47,7 @@ public class ThumbnailSearchResultView extends androidx.appcompat.widget.AppComp
public static final String TARGET_TYPE_SCREENSHOT = "screenshot";
public static final String TARGET_TYPE_SCREENSHOT_LEGACY = "screenshot_legacy";
private SearchTarget mSearchTarget;
private SearchTargetLegacy mSearchTarget;
public ThumbnailSearchResultView(Context context) {
super(context);
@ -72,11 +72,11 @@ public class ThumbnailSearchResultView extends androidx.appcompat.widget.AppComp
ItemClickHandler.onClickAppShortcut(this, (WorkspaceItemInfo) itemInfo, launcher);
}
SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
}
@Override
public void applySearchTarget(SearchTarget target) {
public void applySearchTarget(SearchTargetLegacy target) {
mSearchTarget = target;
Bitmap bitmap;
if (target.getRemoteAction() != null) {
@ -108,7 +108,7 @@ public class ThumbnailSearchResultView extends androidx.appcompat.widget.AppComp
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(null, bitmap);
drawable.setCornerRadius(Themes.getDialogCornerRadius(getContext()));
setImageDrawable(drawable);
setOnClickListener(v -> handleSelection(SearchTargetEvent.SELECT));
setOnClickListener(v -> handleSelection(SearchTargetEventLegacy.SELECT));
SearchEventTracker.INSTANCE.get(getContext()).registerWeakHandler(target, this);
}
}

View File

@ -42,6 +42,7 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Workspace;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.appprediction.PredictionRowView;
@ -266,8 +267,8 @@ public class QuickstepLauncher extends BaseQuickstepLauncher {
}
@Override
public SearchAdapterProvider createSearchAdapterProvider() {
return new DeviceSearchAdapterProvider(this);
public SearchAdapterProvider createSearchAdapterProvider(AllAppsContainerView appsView) {
return new DeviceSearchAdapterProvider(this, appsView);
}
@Override

View File

@ -43,6 +43,7 @@ import android.widget.Toast;
import androidx.annotation.Nullable;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.search.DefaultSearchAdapterProvider;
import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.logging.InstanceId;
@ -297,7 +298,7 @@ public abstract class BaseDraggingActivity extends BaseActivity
* Creates and returns {@link SearchAdapterProvider} for build variant specific search result
* views
*/
public SearchAdapterProvider createSearchAdapterProvider() {
public SearchAdapterProvider createSearchAdapterProvider(AllAppsContainerView allapps) {
return new DefaultSearchAdapterProvider(this);
}
}

View File

@ -124,7 +124,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mLauncher = BaseDraggingActivity.fromContext(context);
mLauncher.addOnDeviceProfileChangeListener(this);
mSearchAdapterProvider = mLauncher.createSearchAdapterProvider();
mSearchAdapterProvider = mLauncher.createSearchAdapterProvider(this);
mSearchQueryBuilder = new SpannableStringBuilder();
Selection.setSelection(mSearchQueryBuilder, 0);
@ -569,6 +569,10 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
return null;
}
public SearchAdapterProvider getSearchAdapterProvider() {
return mSearchAdapterProvider;
}
public RecyclerViewFastScroller getScrollBar() {
AllAppsRecyclerView rv = getActiveRecyclerView();
return rv == null ? null : rv.getScrollbar();

View File

@ -98,6 +98,10 @@ public final class FeatureFlags {
public static final BooleanFlag ENABLE_DEVICE_SEARCH = getDebugFlag(
"ENABLE_DEVICE_SEARCH", false, "Allows on device search in all apps");
public static final BooleanFlag SEARCH_TARGET_LEGACY = getDebugFlag(
"SEARCH_TARGET_LEGACY", true,
"Use SearchTarget provided by plugin lib (only during migration)");
public static final BooleanFlag DISABLE_INITIAL_IME_IN_ALLAPPS = getDebugFlag(
"DISABLE_INITIAL_IME_IN_ALLAPPS", false, "Disable default IME state in all apps");

View File

@ -19,11 +19,12 @@ package com.android.systemui.plugins;
import android.app.Activity;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Parcelable;
import android.view.View;
import com.android.systemui.plugins.annotations.ProvidesInterface;
import com.android.systemui.plugins.shared.SearchTarget;
import com.android.systemui.plugins.shared.SearchTargetEvent;
import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
import com.android.systemui.plugins.shared.SearchTargetLegacy;
import java.util.List;
import java.util.function.Consumer;
@ -34,20 +35,25 @@ import java.util.function.Consumer;
@ProvidesInterface(action = AllAppsSearchPlugin.ACTION, version = AllAppsSearchPlugin.VERSION)
public interface AllAppsSearchPlugin extends Plugin {
String ACTION = "com.android.systemui.action.PLUGIN_ALL_APPS_SEARCH_ACTIONS";
int VERSION = 8;
int VERSION = 9;
void setup(Activity activity, View view);
/**
* init plugin
*/
void setup(Activity activity, View view, boolean useLegacy);
/**
* Send launcher state related signals.
*/
void onStateTransitionStart(int fromState, int toState);
void onStateTransitionComplete(int state);
/**
* Send launcher window focus and visibility changed signals.
*/
void onWindowFocusChanged(boolean hasFocus);
void onWindowVisibilityChanged(int visibility);
/**
@ -59,22 +65,41 @@ public interface AllAppsSearchPlugin extends Plugin {
/**
* Main function that triggers search.
*
* @param input string that has been typed by a user
* @param inputArgs extra info that may be relevant for the input query
* @param results contains the result that will be rendered in all apps search surface
* @param input string that has been typed by a user
* @param inputArgs extra info that may be relevant for the input query
* @param results contains the result that will be rendered in all apps search
* surface
* @param cancellationSignal {@link CancellationSignal} can be used to share status of current
*/
void query(String input, Bundle inputArgs, Consumer<List<SearchTarget>> results,
void queryLegacy(String input, Bundle inputArgs, Consumer<List<SearchTargetLegacy>> results,
CancellationSignal cancellationSignal);
/**
* Main function that triggers search.
*
* @param input string that has been typed by a user
* @param inputArgs extra info that may be relevant for the input query
* @param results contains the result that will be rendered in all apps search
* surface
* @param cancellationSignal {@link CancellationSignal} can be used to share status of current
*/
void query(String input, Bundle inputArgs, Consumer<List<Parcelable>> results,
CancellationSignal cancellationSignal);
/**
* Send over search target interaction events to Plugin
*/
void notifySearchTargetEvent(SearchTargetEvent event);
void notifySearchTargetEventLegacy(SearchTargetEventLegacy event);
/**
* Send over search target interaction events to Plugin
*/
void notifySearchTargetEvent(Parcelable event);
/**
* Launcher activity lifecycle callbacks
*/
void onResume(int state);
void onStop(int state);
}

View File

@ -19,8 +19,11 @@ import android.os.Bundle;
/**
* Event used for the feedback loop to the plugin. (and future aiai)
*
* @deprecated Use SearchTargetEvent
*/
public class SearchTargetEvent {
@Deprecated
public class SearchTargetEventLegacy {
public static final int POSITION_NONE = -1;
public static final int SELECT = 0;
@ -28,12 +31,13 @@ public class SearchTargetEvent {
public static final int LONG_PRESS = 2;
public static final int CHILD_SELECT = 3;
private final SearchTarget mSearchTarget;
private final SearchTargetLegacy mSearchTarget;
private final int mEventType;
private final int mShortcutPosition;
private final Bundle mExtras;
public SearchTargetEvent(SearchTarget searchTarget, int eventType, int shortcutPosition,
public SearchTargetEventLegacy(SearchTargetLegacy searchTarget, int eventType,
int shortcutPosition,
Bundle extras) {
mSearchTarget = searchTarget;
mEventType = eventType;
@ -42,7 +46,7 @@ public class SearchTargetEvent {
}
public SearchTarget getSearchTarget() {
public SearchTargetLegacy getSearchTarget() {
return mSearchTarget;
}
@ -59,15 +63,15 @@ public class SearchTargetEvent {
}
/**
* A builder for {@link SearchTarget}
* A builder for {@link SearchTargetLegacy}
*/
public static final class Builder {
private final SearchTarget mSearchTarget;
private final SearchTargetLegacy mSearchTarget;
private final int mEventType;
private int mShortcutPosition = POSITION_NONE;
private Bundle mExtras;
public Builder(SearchTarget searchTarget, int eventType) {
public Builder(SearchTargetLegacy searchTarget, int eventType) {
mSearchTarget = searchTarget;
mEventType = eventType;
}
@ -82,8 +86,9 @@ public class SearchTargetEvent {
return this;
}
public SearchTargetEvent build() {
return new SearchTargetEvent(mSearchTarget, mEventType, mShortcutPosition, mExtras);
public SearchTargetEventLegacy build() {
return new SearchTargetEventLegacy(mSearchTarget, mEventType, mShortcutPosition,
mExtras);
}
}

View File

@ -25,8 +25,11 @@ import java.util.List;
/**
* Used to return all apps search targets.
*
* @deprecated Use SearchTarget
*/
public class SearchTarget implements Comparable<SearchTarget> {
@Deprecated
public class SearchTargetLegacy implements Comparable<SearchTargetLegacy> {
private final String mItemId;
private final String mItemType;
@ -39,7 +42,7 @@ public class SearchTarget implements Comparable<SearchTarget> {
private final RemoteAction mRemoteAction;
private final Bundle mExtras;
private SearchTarget(String itemId, String itemType, float score,
private SearchTargetLegacy(String itemId, String itemType, float score,
ComponentName componentName, UserHandle userHandle, List<ShortcutInfo> shortcutInfos,
RemoteAction remoteAction, Bundle extras) {
mItemId = itemId;
@ -85,12 +88,12 @@ public class SearchTarget implements Comparable<SearchTarget> {
}
@Override
public int compareTo(SearchTarget o) {
public int compareTo(SearchTargetLegacy o) {
return Float.compare(o.mScore, mScore);
}
/**
* A builder for {@link SearchTarget}
* A builder for {@link SearchTargetLegacy}
*/
public static final class Builder {
@ -158,13 +161,13 @@ public class SearchTarget implements Comparable<SearchTarget> {
}
/**
* Builds a {@link SearchTarget}
* Builds a {@link SearchTargetLegacy}
*/
public SearchTarget build() {
public SearchTargetLegacy build() {
if (mItemId == null) {
throw new IllegalStateException("Item ID is required for building SearchTarget");
}
return new SearchTarget(mItemId, mItemType, mScore, mComponentName, mUserHandle,
return new SearchTargetLegacy(mItemId, mItemType, mScore, mComponentName, mUserHandle,
mShortcutInfos,
mRemoteAction, mExtras);
}