Merge "All Apps Search API council feedback (second round)" into sc-dev

This commit is contained in:
Hyunyoung Song
2021-05-09 19:05:04 +00:00
committed by Android (Google) Code Review
3 changed files with 40 additions and 6 deletions

View File

@@ -1528,6 +1528,9 @@ package android.app.search {
method public boolean shouldHide();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.search.SearchTarget> CREATOR;
field public static final String LAYOUT_TYPE_ICON = "icon";
field public static final String LAYOUT_TYPE_ICON_ROW = "icon_row";
field public static final String LAYOUT_TYPE_SHORT_ICON_ROW = "short_icon_row";
field public static final int RESULT_TYPE_APPLICATION = 1; // 0x1
field public static final int RESULT_TYPE_SHORTCUT = 2; // 0x2
field public static final int RESULT_TYPE_SLICE = 4; // 0x4
@@ -1541,7 +1544,7 @@ package android.app.search {
method @NonNull public android.app.search.SearchTarget.Builder setExtras(@NonNull android.os.Bundle);
method @NonNull public android.app.search.SearchTarget.Builder setPackageName(@NonNull String);
method @NonNull public android.app.search.SearchTarget.Builder setParentId(@NonNull String);
method @NonNull public android.app.search.SearchTarget.Builder setScore(float);
method @NonNull public android.app.search.SearchTarget.Builder setScore(@FloatRange(from=0.0f, to=1.0f) float);
method @NonNull public android.app.search.SearchTarget.Builder setSearchAction(@Nullable android.app.search.SearchAction);
method @NonNull public android.app.search.SearchTarget.Builder setShortcutInfo(@NonNull android.content.pm.ShortcutInfo);
method @NonNull public android.app.search.SearchTarget.Builder setShouldHide(boolean);

View File

@@ -62,7 +62,7 @@ public final class SearchContext implements Parcelable {
* @param resultTypes {@link SearchTarget.SearchResultType}s combined using bit OR operation
* @param timeoutMillis timeout before client renders its own fallback result
*/
public SearchContext(int resultTypes, int timeoutMillis) {
public SearchContext(@SearchTarget.SearchResultType int resultTypes, int timeoutMillis) {
this(resultTypes, timeoutMillis, new Bundle());
}

View File

@@ -15,9 +15,11 @@
*/
package android.app.search;
import android.annotation.FloatRange;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.annotation.SystemApi;
import android.app.slice.SliceManager;
import android.appwidget.AppWidgetProviderInfo;
@@ -66,6 +68,24 @@ public final class SearchTarget implements Parcelable {
public static final int RESULT_TYPE_SHORTCUT = 1 << 1;
public static final int RESULT_TYPE_SLICE = 1 << 2;
public static final int RESULT_TYPE_WIDGETS = 1 << 3;
// ------
// | icon |
// ------
// text
public static final String LAYOUT_TYPE_ICON = "icon";
// ------ ------ ------
// | | title |(opt)| |(opt)|
// | icon | subtitle (optional) | icon| | icon|
// ------ ------ ------
public static final String LAYOUT_TYPE_ICON_ROW = "icon_row";
// ------
// | icon | title / subtitle (optional)
// ------
public static final String LAYOUT_TYPE_SHORT_ICON_ROW = "short_icon_row";
/**
* @hide
*/
@@ -79,6 +99,17 @@ public final class SearchTarget implements Parcelable {
public @interface SearchResultType {}
private final int mResultType;
/**
* @hide
*/
@StringDef(prefix = {"LAYOUT_TYPE_"}, value = {
LAYOUT_TYPE_ICON,
LAYOUT_TYPE_ICON_ROW,
LAYOUT_TYPE_SHORT_ICON_ROW,
})
@Retention(RetentionPolicy.SOURCE)
public @interface SearchLayoutType {}
/**
* Constant to express how the group of {@link SearchTarget} should be rendered on
* the client side. (e.g., "icon", "icon_row", "short_icon_row")
@@ -178,7 +209,7 @@ public final class SearchTarget implements Parcelable {
* Retrieves the layout type.
*/
@NonNull
public String getLayoutType() {
public @SearchLayoutType String getLayoutType() {
return mLayoutType;
}
@@ -337,7 +368,7 @@ public final class SearchTarget implements Parcelable {
private Bundle mExtras;
public Builder(@SearchResultType int resultType,
@NonNull String layoutType,
@SearchLayoutType @NonNull String layoutType,
@NonNull String id) {
mId = id;
mLayoutType = Objects.requireNonNull(layoutType);
@@ -433,13 +464,13 @@ public final class SearchTarget implements Parcelable {
* Sets the score of the object.
*/
@NonNull
public Builder setScore(float score) {
public Builder setScore(@FloatRange(from = 0.0f, to = 1.0f) float score) {
mScore = score;
return this;
}
/**
* Sets whether the result should be hidden by default inside client.
* Sets whether the result should be hidden (e.g. not visible) by default inside client.
*/
@NonNull
public Builder setShouldHide(boolean shouldHide) {