From c8478e5a9dc5570487a99f3f0344f4d2797a9587 Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Fri, 7 May 2021 10:02:06 -0700 Subject: [PATCH] All Apps Search API council feedback (second round) Bug: 186756959 Test: atest CtsSearchUiServiceTestCases Change-Id: I0c83d79ede8801f71c89e71cc6ec2c73b2d8bfcd --- core/api/system-current.txt | 5 ++- .../android/app/search/SearchContext.java | 2 +- .../java/android/app/search/SearchTarget.java | 39 +++++++++++++++++-- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index e80615a0801a0..96a23b2a25ec3 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -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 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); diff --git a/core/java/android/app/search/SearchContext.java b/core/java/android/app/search/SearchContext.java index 3e345fa93d7b9..8f584cc712c52 100644 --- a/core/java/android/app/search/SearchContext.java +++ b/core/java/android/app/search/SearchContext.java @@ -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()); } diff --git a/core/java/android/app/search/SearchTarget.java b/core/java/android/app/search/SearchTarget.java index 56c5ddf9ace7a..6d638d47f5258 100644 --- a/core/java/android/app/search/SearchTarget.java +++ b/core/java/android/app/search/SearchTarget.java @@ -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) {