diff options
author | 2020-10-16 02:01:31 -0700 | |
---|---|---|
committer | 2020-10-17 15:41:45 -0700 | |
commit | 1f79eeda76246534697e92740defc7f73c3c8d14 (patch) | |
tree | dff3c71e317e57934f519a0727b51e243d8d046d /src_plugins | |
parent | 9228ff53c2fb26850b7bd92d86214a6aaebb11d3 (diff) |
Remove hardcoded itemTypes from SearchTarget
- Introduces componentName and userHandle members to SearchTarget
- SearchTargetEvent now has searchTarget member
- Builder pattern for SearchTarget and SearchTargetEvent
- Search backend should add headers manually instead of launcher inferring sections
Bug: 171026321
Test: Manual
Change-Id: I28e0455e82b925277a17703b9aa061c8f9f15262
Diffstat (limited to 'src_plugins')
-rw-r--r-- | src_plugins/com/android/systemui/plugins/shared/SearchTarget.java | 218 | ||||
-rw-r--r-- | src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java | 76 |
2 files changed, 173 insertions, 121 deletions
diff --git a/src_plugins/com/android/systemui/plugins/shared/SearchTarget.java b/src_plugins/com/android/systemui/plugins/shared/SearchTarget.java index 3f0dc39cc1..2c7972e908 100644 --- a/src_plugins/com/android/systemui/plugins/shared/SearchTarget.java +++ b/src_plugins/com/android/systemui/plugins/shared/SearchTarget.java @@ -16,8 +16,10 @@ package com.android.systemui.plugins.shared; import android.app.RemoteAction; +import android.content.ComponentName; import android.content.pm.ShortcutInfo; import android.os.Bundle; +import android.os.UserHandle; import java.util.List; @@ -26,139 +28,145 @@ import java.util.List; */ public class SearchTarget implements Comparable<SearchTarget> { + private final String mItemId; + private final String mItemType; + private final float mScore; + + private final ComponentName mComponentName; + private final UserHandle mUserHandle; + private final List<ShortcutInfo> mShortcutInfos; + //TODO: (sfufa) replace with a list of a custom type + private final RemoteAction mRemoteAction; + private final Bundle mExtras; + + private SearchTarget(String itemId, String itemType, float score, + ComponentName componentName, UserHandle userHandle, List<ShortcutInfo> shortcutInfos, + RemoteAction remoteAction, Bundle extras) { + mItemId = itemId; + mItemType = itemType; + mScore = score; + mComponentName = componentName; + mUserHandle = userHandle; + mShortcutInfos = shortcutInfos; + mExtras = extras; + mRemoteAction = remoteAction; + } - /** - * A bundle key for boolean value of whether remote action should be started in launcher or not - */ - public static final String REMOTE_ACTION_SHOULD_START = "should_start_for_result"; - public static final String REMOTE_ACTION_TOKEN = "action_token"; + public String getItemId() { + return mItemId; + } + public String getItemType() { + return mItemType; + } - public enum ViewType { + public ComponentName getComponentName() { + return mComponentName; + } - /** - * Consists of N number of icons. (N: launcher column count) - */ - TOP_HIT(0), + public UserHandle getUserHandle() { + return mUserHandle; + } - /** - * Consists of 1 icon and two subsidiary icons. - */ - HERO(1), + public float getScore() { + return mScore; + } - /** - * Main/sub/breadcrumb texts are rendered. - */ - DETAIL(2), + public List<ShortcutInfo> getShortcutInfos() { + return mShortcutInfos; + } - /** - * Consists of an icon, three detail strings. - */ - ROW(3), + public Bundle getExtras() { + return mExtras; + } - /** - * Consists of an icon, three detail strings and a button. - */ - ROW_WITH_BUTTON(4), + public RemoteAction getRemoteAction() { + return mRemoteAction; + } - /** - * Consists of a single slice view - */ - SLICE(5), + @Override + public int compareTo(SearchTarget o) { + return Float.compare(o.mScore, mScore); + } - /** - * Similar to hero section. - */ - SHORTCUT(6), + /** + * A builder for {@link SearchTarget} + */ + public static final class Builder { - /** - * Person icon and handling app icons are rendered. - */ - PEOPLE(7), - /** - * N number of 1x1 ratio thumbnail is rendered. - * (current N = 3) - */ - THUMBNAIL(8), + private String mItemId; + + private final String mItemType; + private final float mScore; - /** - * Fallback search icon and relevant text is rendered. - */ - SUGGEST(9); - private final int mId; + private ComponentName mComponentName; + private UserHandle mUserHandle; + private List<ShortcutInfo> mShortcutInfos; + private Bundle mExtras; + private RemoteAction mRemoteAction; - ViewType(int id) { - mId = id; + public Builder(String itemType, float score) { + this(itemType, score, null, null); } - public int get() { - return mId; + public Builder(String itemType, float score, ComponentName cn, + UserHandle user) { + mItemType = itemType; + mScore = score; + mComponentName = cn; + mUserHandle = user; } - } - public enum ItemType { - PLAY_RESULTS(0, "Play Store", ViewType.DETAIL), - SETTINGS_ROW(1, "Settings", ViewType.ROW), - SETTINGS_SLICE(2, "Settings", ViewType.SLICE), - APP(3, "", ViewType.TOP_HIT), - APP_HERO(4, "", ViewType.HERO), - SHORTCUT(5, "Shortcuts", ViewType.SHORTCUT), - PEOPLE(6, "People", ViewType.PEOPLE), - SCREENSHOT(7, "Screenshots", ViewType.THUMBNAIL), - ACTION(8, "Actions", ViewType.SHORTCUT), - SUGGEST(9, "Fallback Search", ViewType.SUGGEST), - CHROME_TAB(10, "Chrome Tab", ViewType.SHORTCUT); - - private final int mId; - - /** Used to render section title. */ - private final String mTitle; - private final ViewType mViewType; - - ItemType(int id, String title, ViewType type) { - mId = id; - mTitle = title; - mViewType = type; + public String getItemId() { + return mItemId; } - public ViewType getViewType() { - return mViewType; + public float getScore() { + return mScore; } - public String getTitle() { - return mTitle; + public Builder setItemId(String itemId) { + mItemId = itemId; + return this; } - public int getId() { - return mId; + public Builder setComponentName(ComponentName componentName) { + mComponentName = componentName; + return this; + } + + public Builder setUserHandle(UserHandle userHandle) { + mUserHandle = userHandle; + return this; } - } - public ItemType type; - public List<ShortcutInfo> shortcuts; - public Bundle bundle; - public float score; - public String mSessionId; - public RemoteAction mRemoteAction; + public Builder setShortcutInfos(List<ShortcutInfo> shortcutInfos) { + mShortcutInfos = shortcutInfos; + return this; + } - /** - * Constructor to create the search target. Bundle is currently temporary to hold - * search target primitives that cannot be expressed as java primitive objects - * or AOSP native objects. - */ - public SearchTarget(ItemType itemType, List<ShortcutInfo> shortcuts, - Bundle bundle, float score, String sessionId) { - this.type = itemType; - this.shortcuts = shortcuts; - this.bundle = bundle; - this.score = score; - this.mSessionId = sessionId; - } + public Builder setExtras(Bundle extras) { + mExtras = extras; + return this; + } - @Override - public int compareTo(SearchTarget o) { - return Float.compare(o.score, score); + public Builder setRemoteAction(RemoteAction remoteAction) { + mRemoteAction = remoteAction; + return this; + } + + /** + * Builds a {@link SearchTarget} + */ + public SearchTarget build() { + if (mItemId == null) { + throw new IllegalStateException("Item ID is required for building SearchTarget"); + } + return new SearchTarget(mItemId, mItemType, mScore, mComponentName, mUserHandle, + mShortcutInfos, + mRemoteAction, mExtras); + } } } diff --git a/src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java b/src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java index 5016abc1e9..290fe54a27 100644 --- a/src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java +++ b/src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java @@ -15,32 +15,76 @@ */ package com.android.systemui.plugins.shared; -import android.app.RemoteAction; -import android.content.pm.ShortcutInfo; import android.os.Bundle; /** * Event used for the feedback loop to the plugin. (and future aiai) */ public class SearchTargetEvent { + public static final int POSITION_NONE = -1; + public static final int SELECT = 0; public static final int QUICK_SELECT = 1; public static final int LONG_PRESS = 2; public static final int CHILD_SELECT = 3; - public SearchTarget.ItemType type; - public ShortcutInfo shortcut; - public RemoteAction remoteAction; - public int eventType; - public Bundle bundle; - public int index; - public String sessionIdentifier; - - public SearchTargetEvent(SearchTarget.ItemType itemType, int eventType, int index, - String sessionId) { - this.type = itemType; - this.eventType = eventType; - this.index = index; - this.sessionIdentifier = sessionId; + private final SearchTarget mSearchTarget; + private final int mEventType; + private final int mShortcutPosition; + private final Bundle mExtras; + + public SearchTargetEvent(SearchTarget searchTarget, int eventType, int shortcutPosition, + Bundle extras) { + mSearchTarget = searchTarget; + mEventType = eventType; + mShortcutPosition = shortcutPosition; + mExtras = extras; + } + + + public SearchTarget getSearchTarget() { + return mSearchTarget; + } + + public int getShortcutPosition() { + return mShortcutPosition; + } + + public int getEventType() { + return mEventType; } + + public Bundle getExtras() { + return mExtras; + } + + /** + * A builder for {@link SearchTarget} + */ + public static final class Builder { + private final SearchTarget mSearchTarget; + private final int mEventType; + private int mShortcutPosition = POSITION_NONE; + private Bundle mExtras; + + public Builder(SearchTarget searchTarget, int eventType) { + mSearchTarget = searchTarget; + mEventType = eventType; + } + + public Builder setShortcutPosition(int shortcutPosition) { + mShortcutPosition = shortcutPosition; + return this; + } + + public Builder setExtras(Bundle extras) { + mExtras = extras; + return this; + } + + public SearchTargetEvent build() { + return new SearchTargetEvent(mSearchTarget, mEventType, mShortcutPosition, mExtras); + } + } + } |