mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 07:16:54 +00:00
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:
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user