Add all the Smartspace UI templates' corresponding data classes.

- SmartspaceDefaultUiTemplateData represents the data of a Smartspace
card with the default UI template;
- Other templates' data classes are all subclasses of
SmartspaceDefaultUiTemplateData;
- SmartspaceIcon and SmartspaceTapAction are the newly-added primitives.

More details in go/ss-launcher-templated-ui.

Test: tested locally
Bug:213926964,212650337
CTS-Coverage-Bug:214471292

Change-Id: I056c49e3db7060697be4a3a8f51358802f2610b0
This commit is contained in:
Cecilia
2021-12-31 07:55:32 +00:00
parent f3366dcd87
commit 6927948dff
13 changed files with 2518 additions and 6 deletions

View File

@@ -1837,6 +1837,7 @@ package android.app.smartspace {
method @Nullable public android.net.Uri getSliceUri();
method @NonNull public String getSmartspaceTargetId();
method @Nullable public String getSourceNotificationKey();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData getTemplateData();
method @NonNull public android.os.UserHandle getUserHandle();
method @Nullable public android.appwidget.AppWidgetProviderInfo getWidget();
method public boolean isSensitive();
@@ -1867,6 +1868,14 @@ package android.app.smartspace {
field public static final int FEATURE_UPCOMING_ALARM = 23; // 0x17
field public static final int FEATURE_WEATHER = 1; // 0x1
field public static final int FEATURE_WEATHER_ALERT = 10; // 0xa
field public static final int UI_TEMPLATE_CAROUSEL = 4; // 0x4
field public static final int UI_TEMPLATE_COMBINED_CARDS = 6; // 0x6
field public static final int UI_TEMPLATE_DEFAULT = 1; // 0x1
field public static final int UI_TEMPLATE_HEAD_TO_HEAD = 5; // 0x5
field public static final int UI_TEMPLATE_SUB_CARD = 7; // 0x7
field public static final int UI_TEMPLATE_SUB_IMAGE = 2; // 0x2
field public static final int UI_TEMPLATE_SUB_LIST = 3; // 0x3
field public static final int UI_TEMPLATE_UNDEFINED = 0; // 0x0
}
public static final class SmartspaceTarget.Builder {
@@ -1885,6 +1894,7 @@ package android.app.smartspace {
method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setShouldShowExpanded(boolean);
method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setSliceUri(@NonNull android.net.Uri);
method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setSourceNotificationKey(@NonNull String);
method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setTemplateData(@Nullable android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData);
method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setWidget(@NonNull android.appwidget.AppWidgetProviderInfo);
}
@@ -1913,6 +1923,177 @@ package android.app.smartspace {
}
package android.app.smartspace.uitemplatedata {
public final class SmartspaceCarouselUiTemplateData extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData {
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getCarouselAction();
method @NonNull public java.util.List<android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData.CarouselItem> getCarouselItems();
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData> CREATOR;
}
public static final class SmartspaceCarouselUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder {
ctor public SmartspaceCarouselUiTemplateData.Builder(@NonNull java.util.List<android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData.CarouselItem>);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData build();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData.Builder setCarouselAction(@NonNull android.app.smartspace.uitemplatedata.SmartspaceTapAction);
}
public static final class SmartspaceCarouselUiTemplateData.CarouselItem implements android.os.Parcelable {
method public int describeContents();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getImage();
method @Nullable public CharSequence getLowerText();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getTapAction();
method @Nullable public CharSequence getUpperText();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData.CarouselItem> CREATOR;
}
public static final class SmartspaceCarouselUiTemplateData.CarouselItem.Builder {
ctor public SmartspaceCarouselUiTemplateData.CarouselItem.Builder();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData.CarouselItem build();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData.CarouselItem.Builder setImage(@Nullable android.app.smartspace.uitemplatedata.SmartspaceIcon);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData.CarouselItem.Builder setLowerText(@Nullable CharSequence);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData.CarouselItem.Builder setTapAction(@Nullable android.app.smartspace.uitemplatedata.SmartspaceTapAction);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceCarouselUiTemplateData.CarouselItem.Builder setUpperText(@Nullable CharSequence);
}
public final class SmartspaceCombinedCardsUiTemplateData extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData {
method @NonNull public java.util.List<android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData> getCombinedCardDataList();
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceCombinedCardsUiTemplateData> CREATOR;
}
public static final class SmartspaceCombinedCardsUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder {
ctor public SmartspaceCombinedCardsUiTemplateData.Builder(@NonNull java.util.List<android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData>);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceCombinedCardsUiTemplateData build();
}
public class SmartspaceDefaultUiTemplateData implements android.os.Parcelable {
method public int describeContents();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getPrimaryTapAction();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getSubTitleIcon();
method @Nullable public CharSequence getSubtitleText();
method @Nullable public CharSequence getSupplementalAlarmText();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getSupplementalSubtitleIcon();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getSupplementalSubtitleTapAction();
method @Nullable public CharSequence getSupplementalSubtitleText();
method public int getTemplateType();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getTitleIcon();
method @Nullable public CharSequence getTitleText();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData> CREATOR;
}
public static class SmartspaceDefaultUiTemplateData.Builder {
ctor public SmartspaceDefaultUiTemplateData.Builder(int);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData build();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setPrimaryTapAction(@NonNull android.app.smartspace.uitemplatedata.SmartspaceTapAction);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setSubTitleIcon(@NonNull android.app.smartspace.uitemplatedata.SmartspaceIcon);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setSubtitleText(@NonNull CharSequence);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setSupplementalAlarmText(@NonNull CharSequence);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setSupplementalSubtitleIcon(@NonNull android.app.smartspace.uitemplatedata.SmartspaceIcon);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setSupplementalSubtitleTapAction(@NonNull android.app.smartspace.uitemplatedata.SmartspaceTapAction);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setSupplementalSubtitleText(@NonNull CharSequence);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setTitleIcon(@NonNull android.app.smartspace.uitemplatedata.SmartspaceIcon);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setTitleText(@NonNull CharSequence);
}
public final class SmartspaceHeadToHeadUiTemplateData extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData {
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getHeadToHeadAction();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getHeadToHeadFirstCompetitorIcon();
method @Nullable public CharSequence getHeadToHeadFirstCompetitorText();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getHeadToHeadSecondCompetitorIcon();
method @Nullable public CharSequence getHeadToHeadSecondCompetitorText();
method @Nullable public CharSequence getHeadToHeadTitle();
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceHeadToHeadUiTemplateData> CREATOR;
}
public static final class SmartspaceHeadToHeadUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder {
ctor public SmartspaceHeadToHeadUiTemplateData.Builder();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceHeadToHeadUiTemplateData build();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceHeadToHeadUiTemplateData.Builder setHeadToHeadAction(@Nullable android.app.smartspace.uitemplatedata.SmartspaceTapAction);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceHeadToHeadUiTemplateData.Builder setHeadToHeadFirstCompetitorIcon(@Nullable android.app.smartspace.uitemplatedata.SmartspaceIcon);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceHeadToHeadUiTemplateData.Builder setHeadToHeadFirstCompetitorText(@Nullable CharSequence);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceHeadToHeadUiTemplateData.Builder setHeadToHeadSecondCompetitorIcon(@Nullable android.app.smartspace.uitemplatedata.SmartspaceIcon);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceHeadToHeadUiTemplateData.Builder setHeadToHeadSecondCompetitorText(@Nullable CharSequence);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceHeadToHeadUiTemplateData.Builder setHeadToHeadTitle(@Nullable CharSequence);
}
public final class SmartspaceIcon implements android.os.Parcelable {
method public int describeContents();
method @Nullable public CharSequence getContentDescription();
method @NonNull public android.graphics.drawable.Icon getIcon();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceIcon> CREATOR;
}
public static final class SmartspaceIcon.Builder {
ctor public SmartspaceIcon.Builder(@NonNull android.graphics.drawable.Icon);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceIcon build();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceIcon.Builder setContentDescription(@NonNull CharSequence);
}
public final class SmartspaceSubCardUiTemplateData extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData {
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getSubCardAction();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceIcon getSubCardIcon();
method @Nullable public CharSequence getSubCardText();
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceSubCardUiTemplateData> CREATOR;
}
public static final class SmartspaceSubCardUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder {
ctor public SmartspaceSubCardUiTemplateData.Builder(@NonNull android.app.smartspace.uitemplatedata.SmartspaceIcon);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubCardUiTemplateData build();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubCardUiTemplateData.Builder setSubCardAction(@NonNull CharSequence);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubCardUiTemplateData.Builder setSubCardAction(@NonNull android.app.smartspace.uitemplatedata.SmartspaceTapAction);
}
public final class SmartspaceSubImageUiTemplateData extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData {
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getSubImageAction();
method @NonNull public java.util.List<java.lang.CharSequence> getSubImageTexts();
method @NonNull public java.util.List<android.app.smartspace.uitemplatedata.SmartspaceIcon> getSubImages();
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceSubImageUiTemplateData> CREATOR;
}
public static final class SmartspaceSubImageUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder {
ctor public SmartspaceSubImageUiTemplateData.Builder(@NonNull java.util.List<java.lang.CharSequence>, @NonNull java.util.List<android.app.smartspace.uitemplatedata.SmartspaceIcon>);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubImageUiTemplateData build();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubImageUiTemplateData.Builder setCarouselAction(@NonNull android.app.smartspace.uitemplatedata.SmartspaceTapAction);
}
public final class SmartspaceSubListUiTemplateData extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData {
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getSubListAction();
method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getSubListIcon();
method @NonNull public java.util.List<java.lang.CharSequence> getSubListTexts();
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceSubListUiTemplateData> CREATOR;
}
public static final class SmartspaceSubListUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder {
ctor public SmartspaceSubListUiTemplateData.Builder(@NonNull java.util.List<java.lang.CharSequence>);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubListUiTemplateData build();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubListUiTemplateData.Builder setCarouselAction(@NonNull android.app.smartspace.uitemplatedata.SmartspaceTapAction);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubListUiTemplateData.Builder setSubListIcon(@NonNull android.app.smartspace.uitemplatedata.SmartspaceIcon);
}
public final class SmartspaceTapAction implements android.os.Parcelable {
method public int describeContents();
method @Nullable public android.os.Bundle getExtras();
method @Nullable public CharSequence getId();
method @Nullable public android.content.Intent getIntent();
method @Nullable public android.app.PendingIntent getPendingIntent();
method @Nullable public android.os.UserHandle getUserHandle();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.uitemplatedata.SmartspaceTapAction> CREATOR;
}
public static final class SmartspaceTapAction.Builder {
ctor public SmartspaceTapAction.Builder(@NonNull CharSequence);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceTapAction build();
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceTapAction.Builder setExtras(@NonNull android.os.Bundle);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceTapAction.Builder setIntent(@NonNull android.content.Intent);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceTapAction.Builder setPendingIntent(@NonNull android.app.PendingIntent);
method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceTapAction.Builder setUserHandle(@Nullable android.os.UserHandle);
}
}
package android.app.time {
public final class Capabilities {

View File

@@ -20,6 +20,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.net.Uri;
@@ -131,6 +132,9 @@ public final class SmartspaceTarget implements Parcelable {
@Nullable
private final AppWidgetProviderInfo mWidget;
@Nullable
private final SmartspaceDefaultUiTemplateData mTemplateData;
public static final int FEATURE_UNDEFINED = 0;
public static final int FEATURE_WEATHER = 1;
public static final int FEATURE_CALENDAR = 2;
@@ -189,6 +193,32 @@ public final class SmartspaceTarget implements Parcelable {
public @interface FeatureType {
}
public static final int UI_TEMPLATE_UNDEFINED = 0;
public static final int UI_TEMPLATE_DEFAULT = 1;
public static final int UI_TEMPLATE_SUB_IMAGE = 2;
public static final int UI_TEMPLATE_SUB_LIST = 3;
public static final int UI_TEMPLATE_CAROUSEL = 4;
public static final int UI_TEMPLATE_HEAD_TO_HEAD = 5;
public static final int UI_TEMPLATE_COMBINED_CARDS = 6;
public static final int UI_TEMPLATE_SUB_CARD = 7;
/**
* @hide
*/
@IntDef(prefix = {"UI_TEMPLATE_"}, value = {
UI_TEMPLATE_UNDEFINED,
UI_TEMPLATE_DEFAULT,
UI_TEMPLATE_SUB_IMAGE,
UI_TEMPLATE_SUB_LIST,
UI_TEMPLATE_CAROUSEL,
UI_TEMPLATE_HEAD_TO_HEAD,
UI_TEMPLATE_COMBINED_CARDS,
UI_TEMPLATE_SUB_CARD
})
@Retention(RetentionPolicy.SOURCE)
public @interface UiTemplateType {
}
private SmartspaceTarget(Parcel in) {
this.mSmartspaceTargetId = in.readString();
this.mHeaderAction = in.readTypedObject(SmartspaceAction.CREATOR);
@@ -207,6 +237,7 @@ public final class SmartspaceTarget implements Parcelable {
this.mAssociatedSmartspaceTargetId = in.readString();
this.mSliceUri = in.readTypedObject(Uri.CREATOR);
this.mWidget = in.readTypedObject(AppWidgetProviderInfo.CREATOR);
this.mTemplateData = in.readTypedObject(SmartspaceDefaultUiTemplateData.CREATOR);
}
private SmartspaceTarget(String smartspaceTargetId,
@@ -217,7 +248,7 @@ public final class SmartspaceTarget implements Parcelable {
boolean shouldShowExpanded, String sourceNotificationKey,
ComponentName componentName, UserHandle userHandle,
String associatedSmartspaceTargetId, Uri sliceUri,
AppWidgetProviderInfo widget) {
AppWidgetProviderInfo widget, SmartspaceDefaultUiTemplateData templateData) {
mSmartspaceTargetId = smartspaceTargetId;
mHeaderAction = headerAction;
mBaseAction = baseAction;
@@ -235,6 +266,7 @@ public final class SmartspaceTarget implements Parcelable {
mAssociatedSmartspaceTargetId = associatedSmartspaceTargetId;
mSliceUri = sliceUri;
mWidget = widget;
mTemplateData = templateData;
}
/**
@@ -370,6 +402,14 @@ public final class SmartspaceTarget implements Parcelable {
return mWidget;
}
/**
* Returns the UI template data.
*/
@Nullable
public SmartspaceDefaultUiTemplateData getTemplateData() {
return mTemplateData;
}
/**
* @see Parcelable.Creator
*/
@@ -405,6 +445,7 @@ public final class SmartspaceTarget implements Parcelable {
dest.writeString(this.mAssociatedSmartspaceTargetId);
dest.writeTypedObject(this.mSliceUri, flags);
dest.writeTypedObject(this.mWidget, flags);
dest.writeTypedObject(this.mTemplateData, flags);
}
@Override
@@ -432,6 +473,7 @@ public final class SmartspaceTarget implements Parcelable {
+ ", mAssociatedSmartspaceTargetId='" + mAssociatedSmartspaceTargetId + '\''
+ ", mSliceUri=" + mSliceUri
+ ", mWidget=" + mWidget
+ ", mTemplateData=" + mTemplateData
+ '}';
}
@@ -457,7 +499,8 @@ public final class SmartspaceTarget implements Parcelable {
&& Objects.equals(mAssociatedSmartspaceTargetId,
that.mAssociatedSmartspaceTargetId)
&& Objects.equals(mSliceUri, that.mSliceUri)
&& Objects.equals(mWidget, that.mWidget);
&& Objects.equals(mWidget, that.mWidget)
&& Objects.equals(mTemplateData, that.mTemplateData);
}
@Override
@@ -465,7 +508,7 @@ public final class SmartspaceTarget implements Parcelable {
return Objects.hash(mSmartspaceTargetId, mHeaderAction, mBaseAction, mCreationTimeMillis,
mExpiryTimeMillis, mScore, mActionChips, mIconGrid, mFeatureType, mSensitive,
mShouldShowExpanded, mSourceNotificationKey, mComponentName, mUserHandle,
mAssociatedSmartspaceTargetId, mSliceUri, mWidget);
mAssociatedSmartspaceTargetId, mSliceUri, mWidget, mTemplateData);
}
/**
@@ -476,6 +519,9 @@ public final class SmartspaceTarget implements Parcelable {
@SystemApi
public static final class Builder {
private final String mSmartspaceTargetId;
private final ComponentName mComponentName;
private final UserHandle mUserHandle;
private SmartspaceAction mHeaderAction;
private SmartspaceAction mBaseAction;
private long mCreationTimeMillis;
@@ -487,11 +533,10 @@ public final class SmartspaceTarget implements Parcelable {
private boolean mSensitive;
private boolean mShouldShowExpanded;
private String mSourceNotificationKey;
private final ComponentName mComponentName;
private final UserHandle mUserHandle;
private String mAssociatedSmartspaceTargetId;
private Uri mSliceUri;
private AppWidgetProviderInfo mWidget;
private SmartspaceDefaultUiTemplateData mTemplateData;
/**
* A builder for {@link SmartspaceTarget}.
@@ -639,6 +684,16 @@ public final class SmartspaceTarget implements Parcelable {
return this;
}
/**
* Sets the UI template data.
*/
@NonNull
public Builder setTemplateData(
@Nullable SmartspaceDefaultUiTemplateData templateData) {
mTemplateData = templateData;
return this;
}
/**
* Builds a new {@link SmartspaceTarget}.
*
@@ -655,7 +710,7 @@ public final class SmartspaceTarget implements Parcelable {
mHeaderAction, mBaseAction, mCreationTimeMillis, mExpiryTimeMillis, mScore,
mActionChips, mIconGrid, mFeatureType, mSensitive, mShouldShowExpanded,
mSourceNotificationKey, mComponentName, mUserHandle,
mAssociatedSmartspaceTargetId, mSliceUri, mWidget);
mAssociatedSmartspaceTargetId, mSliceUri, mWidget, mTemplateData);
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace;
import android.annotation.Nullable;
/**
* Utilities for Smartspace data.
*
* @hide
*/
public final class SmartspaceUtils {
private SmartspaceUtils() {
}
/** Returns true if the passed-in {@link CharSequence}s are equal. */
public static boolean isEqual(@Nullable CharSequence cs1, @Nullable CharSequence cs2) {
if ((cs1 == null && cs2 != null) || (cs1 != null && cs2 == null)) return false;
if (cs1 == null && cs2 == null) return true;
return cs1.toString().contentEquals(cs2);
}
}

View File

@@ -0,0 +1,360 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace.uitemplatedata;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.smartspace.SmartspaceTarget;
import android.app.smartspace.SmartspaceUtils;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import java.util.List;
import java.util.Objects;
/**
* Holds all the relevant data needed to render a Smartspace card with the carousel Ui Template.
*
* @hide
*/
@SystemApi
public final class SmartspaceCarouselUiTemplateData extends SmartspaceDefaultUiTemplateData {
/** Lists of {@link CarouselItem}. */
@NonNull
private final List<CarouselItem> mCarouselItems;
/** Tap action for the entire carousel secondary card, including the blank space */
@Nullable
private final SmartspaceTapAction mCarouselAction;
SmartspaceCarouselUiTemplateData(@NonNull Parcel in) {
super(in);
mCarouselItems = in.createTypedArrayList(CarouselItem.CREATOR);
mCarouselAction = in.readTypedObject(SmartspaceTapAction.CREATOR);
}
private SmartspaceCarouselUiTemplateData(@SmartspaceTarget.UiTemplateType int templateType,
@Nullable CharSequence titleText,
@Nullable SmartspaceIcon titleIcon,
@Nullable CharSequence subtitleText,
@Nullable SmartspaceIcon subTitleIcon,
@Nullable SmartspaceTapAction primaryTapAction,
@Nullable CharSequence supplementalSubtitleText,
@Nullable SmartspaceIcon supplementalSubtitleIcon,
@Nullable SmartspaceTapAction supplementalSubtitleTapAction,
@Nullable CharSequence supplementalAlarmText,
@NonNull List<CarouselItem> carouselItems,
@Nullable SmartspaceTapAction carouselAction) {
super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction,
supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction,
supplementalAlarmText);
mCarouselItems = carouselItems;
mCarouselAction = carouselAction;
}
@NonNull
public List<CarouselItem> getCarouselItems() {
return mCarouselItems;
}
@Nullable
public SmartspaceTapAction getCarouselAction() {
return mCarouselAction;
}
/**
* @see Parcelable.Creator
*/
@NonNull
public static final Creator<SmartspaceCarouselUiTemplateData> CREATOR =
new Creator<SmartspaceCarouselUiTemplateData>() {
@Override
public SmartspaceCarouselUiTemplateData createFromParcel(Parcel in) {
return new SmartspaceCarouselUiTemplateData(in);
}
@Override
public SmartspaceCarouselUiTemplateData[] newArray(int size) {
return new SmartspaceCarouselUiTemplateData[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeTypedList(mCarouselItems);
out.writeTypedObject(mCarouselAction, flags);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SmartspaceCarouselUiTemplateData)) return false;
if (!super.equals(o)) return false;
SmartspaceCarouselUiTemplateData that = (SmartspaceCarouselUiTemplateData) o;
return mCarouselItems.equals(that.mCarouselItems) && Objects.equals(mCarouselAction,
that.mCarouselAction);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mCarouselItems, mCarouselAction);
}
@Override
public String toString() {
return super.toString() + " + SmartspaceCarouselUiTemplateData{"
+ "mCarouselItems=" + mCarouselItems
+ ", mCarouselActions=" + mCarouselAction
+ '}';
}
/**
* A builder for {@link SmartspaceCarouselUiTemplateData} object.
*
* @hide
*/
@SystemApi
public static final class Builder extends SmartspaceDefaultUiTemplateData.Builder {
private final List<CarouselItem> mCarouselItems;
private SmartspaceTapAction mCarouselAction;
/**
* A builder for {@link SmartspaceCarouselUiTemplateData}.
*/
public Builder(@NonNull List<CarouselItem> carouselItems) {
super(SmartspaceTarget.UI_TEMPLATE_CAROUSEL);
mCarouselItems = Objects.requireNonNull(carouselItems);
}
/**
* Sets the card tap action.
*/
@NonNull
public Builder setCarouselAction(@NonNull SmartspaceTapAction carouselAction) {
mCarouselAction = carouselAction;
return this;
}
/**
* Builds a new SmartspaceCarouselUiTemplateData instance.
*
* @throws IllegalStateException if the carousel data is invalid.
*/
@NonNull
public SmartspaceCarouselUiTemplateData build() {
if (mCarouselItems.isEmpty()) {
throw new IllegalStateException("Carousel data is empty");
}
return new SmartspaceCarouselUiTemplateData(getTemplateType(), getTitleText(),
getTitleIcon(), getSubtitleText(), getSubTitleIcon(), getPrimaryTapAction(),
getSupplementalSubtitleText(), getSupplementalSubtitleIcon(),
getSupplementalSubtitleTapAction(), getSupplementalAlarmText(),
mCarouselItems,
mCarouselAction);
}
}
/** Holds all the relevant data needed to render a carousel item. */
public static final class CarouselItem implements Parcelable {
/** Text which is above the image item. */
@Nullable
private final CharSequence mUpperText;
/** Image item. Can be empty. */
@Nullable
private final SmartspaceIcon mImage;
/** Text which is under the image item. */
@Nullable
private final CharSequence mLowerText;
/**
* Tap action for this {@link CarouselItem} instance. {@code mCarouselAction} is used if not
* being set.
*/
@Nullable
private final SmartspaceTapAction mTapAction;
CarouselItem(@NonNull Parcel in) {
mUpperText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mImage = in.readTypedObject(SmartspaceIcon.CREATOR);
mLowerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mTapAction = in.readTypedObject(SmartspaceTapAction.CREATOR);
}
private CarouselItem(@Nullable CharSequence upperText, @Nullable SmartspaceIcon image,
@Nullable CharSequence lowerText, @Nullable SmartspaceTapAction tapAction) {
mUpperText = upperText;
mImage = image;
mLowerText = lowerText;
mTapAction = tapAction;
}
@Nullable
public CharSequence getUpperText() {
return mUpperText;
}
@Nullable
public SmartspaceIcon getImage() {
return mImage;
}
@Nullable
public CharSequence getLowerText() {
return mLowerText;
}
@Nullable
public SmartspaceTapAction getTapAction() {
return mTapAction;
}
/**
* @see Parcelable.Creator
*/
@NonNull
public static final Creator<CarouselItem> CREATOR =
new Creator<CarouselItem>() {
@Override
public CarouselItem createFromParcel(Parcel in) {
return new CarouselItem(in);
}
@Override
public CarouselItem[] newArray(int size) {
return new CarouselItem[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
TextUtils.writeToParcel(mUpperText, out, flags);
out.writeTypedObject(mImage, flags);
TextUtils.writeToParcel(mLowerText, out, flags);
out.writeTypedObject(mTapAction, flags);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CarouselItem)) return false;
CarouselItem that = (CarouselItem) o;
return SmartspaceUtils.isEqual(mUpperText, that.mUpperText) && Objects.equals(
mImage,
that.mImage) && SmartspaceUtils.isEqual(mLowerText, that.mLowerText)
&& Objects.equals(mTapAction, that.mTapAction);
}
@Override
public int hashCode() {
return Objects.hash(mUpperText, mImage, mLowerText, mTapAction);
}
@Override
public String toString() {
return "CarouselItem{"
+ "mUpperText=" + mUpperText
+ ", mImage=" + mImage
+ ", mLowerText=" + mLowerText
+ ", mTapAction=" + mTapAction
+ '}';
}
/**
* A builder for {@link CarouselItem} object.
*
* @hide
*/
@SystemApi
public static final class Builder {
private CharSequence mUpperText;
private SmartspaceIcon mImage;
private CharSequence mLowerText;
private SmartspaceTapAction mTapAction;
/**
* Sets the upper text.
*/
@NonNull
public Builder setUpperText(@Nullable CharSequence upperText) {
mUpperText = upperText;
return this;
}
/**
* Sets the image.
*/
@NonNull
public Builder setImage(@Nullable SmartspaceIcon image) {
mImage = image;
return this;
}
/**
* Sets the lower text.
*/
@NonNull
public Builder setLowerText(@Nullable CharSequence lowerText) {
mLowerText = lowerText;
return this;
}
/**
* Sets the tap action.
*/
@NonNull
public Builder setTapAction(@Nullable SmartspaceTapAction tapAction) {
mTapAction = tapAction;
return this;
}
/**
* Builds a new CarouselItem instance.
*
* @throws IllegalStateException if all the rendering data is empty.
*/
@NonNull
public CarouselItem build() {
if (TextUtils.isEmpty(mUpperText) && mImage == null && TextUtils.isEmpty(
mLowerText)) {
throw new IllegalStateException("Carousel data is empty");
}
return new CarouselItem(mUpperText, mImage, mLowerText, mTapAction);
}
}
}
}

View File

@@ -0,0 +1,155 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace.uitemplatedata;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.smartspace.SmartspaceTarget;
import android.os.Parcel;
import java.util.List;
import java.util.Objects;
/**
* Holds all the relevant data needed to render a Smartspace card with the combined-card Ui
* Template.
*
* We only support 1 sub-list card combined with 1 carousel card. And we may expand our supported
* combinations in the future.
*
* @hide
*/
@SystemApi
public final class SmartspaceCombinedCardsUiTemplateData extends SmartspaceDefaultUiTemplateData {
/** A list of secondary cards. */
@NonNull
private final List<SmartspaceDefaultUiTemplateData> mCombinedCardDataList;
SmartspaceCombinedCardsUiTemplateData(@NonNull Parcel in) {
super(in);
mCombinedCardDataList = in.createTypedArrayList(SmartspaceDefaultUiTemplateData.CREATOR);
}
private SmartspaceCombinedCardsUiTemplateData(@SmartspaceTarget.UiTemplateType int templateType,
@Nullable CharSequence titleText,
@Nullable SmartspaceIcon titleIcon,
@Nullable CharSequence subtitleText,
@Nullable SmartspaceIcon subTitleIcon,
@Nullable SmartspaceTapAction primaryTapAction,
@Nullable CharSequence supplementalSubtitleText,
@Nullable SmartspaceIcon supplementalSubtitleIcon,
@Nullable SmartspaceTapAction supplementalSubtitleTapAction,
@Nullable CharSequence supplementalAlarmText,
@NonNull List<SmartspaceDefaultUiTemplateData> combinedCardDataList) {
super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction,
supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction,
supplementalAlarmText);
mCombinedCardDataList = combinedCardDataList;
}
@NonNull
public List<SmartspaceDefaultUiTemplateData> getCombinedCardDataList() {
return mCombinedCardDataList;
}
/**
* @see Parcelable.Creator
*/
@NonNull
public static final Creator<SmartspaceCombinedCardsUiTemplateData> CREATOR =
new Creator<SmartspaceCombinedCardsUiTemplateData>() {
@Override
public SmartspaceCombinedCardsUiTemplateData createFromParcel(Parcel in) {
return new SmartspaceCombinedCardsUiTemplateData(in);
}
@Override
public SmartspaceCombinedCardsUiTemplateData[] newArray(int size) {
return new SmartspaceCombinedCardsUiTemplateData[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeTypedList(mCombinedCardDataList);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SmartspaceCombinedCardsUiTemplateData)) return false;
if (!super.equals(o)) return false;
SmartspaceCombinedCardsUiTemplateData that = (SmartspaceCombinedCardsUiTemplateData) o;
return mCombinedCardDataList.equals(that.mCombinedCardDataList);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mCombinedCardDataList);
}
@Override
public String toString() {
return super.toString() + " + SmartspaceCombinedCardsUiTemplateData{"
+ "mCombinedCardDataList=" + mCombinedCardDataList
+ '}';
}
/**
* A builder for {@link SmartspaceCombinedCardsUiTemplateData} object.
*
* @hide
*/
@SystemApi
public static final class Builder extends SmartspaceDefaultUiTemplateData.Builder {
private final List<SmartspaceDefaultUiTemplateData> mCombinedCardDataList;
/**
* A builder for {@link SmartspaceCombinedCardsUiTemplateData}.
*/
public Builder(@NonNull List<SmartspaceDefaultUiTemplateData> combinedCardDataList) {
super(SmartspaceTarget.UI_TEMPLATE_COMBINED_CARDS);
mCombinedCardDataList = Objects.requireNonNull(combinedCardDataList);
}
/**
* Builds a new SmartspaceCombinedCardsUiTemplateData instance.
*
* @throws IllegalStateException if any required non-null field is null
*/
@NonNull
public SmartspaceCombinedCardsUiTemplateData build() {
if (mCombinedCardDataList == null) {
throw new IllegalStateException("Please assign a value to all @NonNull args.");
}
return new SmartspaceCombinedCardsUiTemplateData(getTemplateType(), getTitleText(),
getTitleIcon(), getSubtitleText(), getSubTitleIcon(), getPrimaryTapAction(),
getSupplementalSubtitleText(), getSupplementalSubtitleIcon(),
getSupplementalSubtitleTapAction(), getSupplementalAlarmText(),
mCombinedCardDataList);
}
}
}

View File

@@ -0,0 +1,459 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace.uitemplatedata;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.app.smartspace.SmartspaceTarget.UiTemplateType;
import android.app.smartspace.SmartspaceUtils;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import java.util.Objects;
/**
* Holds all the relevant data needed to render a Smartspace card with the default Ui Template.
*
* @hide
*/
@SystemApi
@SuppressLint("ParcelNotFinal")
public class SmartspaceDefaultUiTemplateData implements Parcelable {
/**
* {@link UiTemplateType} indicating the template type of this template data.
*
* @see UiTemplateType
*/
@UiTemplateType
private final int mTemplateType;
/**
* Title text and title icon are shown at the first row. When both are absent, the date view
* will be used, which has its own tap action applied to the title area.
*/
@Nullable
private final CharSequence mTitleText;
@Nullable
private final SmartspaceIcon mTitleIcon;
/** Subtitle text and icon are shown at the second row. */
@Nullable
private final CharSequence mSubtitleText;
@Nullable
private final SmartspaceIcon mSubTitleIcon;
/**
* Primary tap action for the entire card, including the blank spaces, except: 1. When title is
* absent, the date view's default tap action is used; 2. Supplemental subtitle uses its own tap
* action if being set; 3. Secondary card uses its own tap action if being set.
*/
@Nullable
private final SmartspaceTapAction mPrimaryTapAction;
/**
* Supplemental subtitle text and icon are shown at the second row following the subtitle text.
* Mainly used for weather info on non-weather card.
*/
@Nullable
private final CharSequence mSupplementalSubtitleText;
@Nullable
private final SmartspaceIcon mSupplementalSubtitleIcon;
/**
* Tap action for the supplemental subtitle's text and icon. Will use the primary tap action if
* not being set.
*/
@Nullable
private final SmartspaceTapAction mSupplementalSubtitleTapAction;
/**
* Supplemental alarm text is specifically used for holiday alarm, which is appended to "next
* alarm".
*/
@Nullable
private final CharSequence mSupplementalAlarmText;
SmartspaceDefaultUiTemplateData(@NonNull Parcel in) {
mTemplateType = in.readInt();
mTitleText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mTitleIcon = in.readTypedObject(SmartspaceIcon.CREATOR);
mSubtitleText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mSubTitleIcon = in.readTypedObject(SmartspaceIcon.CREATOR);
mPrimaryTapAction = in.readTypedObject(SmartspaceTapAction.CREATOR);
mSupplementalSubtitleText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mSupplementalSubtitleIcon = in.readTypedObject(SmartspaceIcon.CREATOR);
mSupplementalSubtitleTapAction = in.readTypedObject(SmartspaceTapAction.CREATOR);
mSupplementalAlarmText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
}
/**
* Should ONLY used by subclasses. For the general instance creation, please use
* SmartspaceDefaultUiTemplateData.Builder.
*/
SmartspaceDefaultUiTemplateData(@UiTemplateType int templateType,
@Nullable CharSequence titleText,
@Nullable SmartspaceIcon titleIcon,
@Nullable CharSequence subtitleText,
@Nullable SmartspaceIcon subTitleIcon,
@Nullable SmartspaceTapAction primaryTapAction,
@Nullable CharSequence supplementalSubtitleText,
@Nullable SmartspaceIcon supplementalSubtitleIcon,
@Nullable SmartspaceTapAction supplementalSubtitleTapAction,
@Nullable CharSequence supplementalAlarmText) {
mTemplateType = templateType;
mTitleText = titleText;
mTitleIcon = titleIcon;
mSubtitleText = subtitleText;
mSubTitleIcon = subTitleIcon;
mPrimaryTapAction = primaryTapAction;
mSupplementalSubtitleText = supplementalSubtitleText;
mSupplementalSubtitleIcon = supplementalSubtitleIcon;
mSupplementalSubtitleTapAction = supplementalSubtitleTapAction;
mSupplementalAlarmText = supplementalAlarmText;
}
@UiTemplateType
public int getTemplateType() {
return mTemplateType;
}
@Nullable
public CharSequence getTitleText() {
return mTitleText;
}
@Nullable
public SmartspaceIcon getTitleIcon() {
return mTitleIcon;
}
@Nullable
public CharSequence getSubtitleText() {
return mSubtitleText;
}
@Nullable
public SmartspaceIcon getSubTitleIcon() {
return mSubTitleIcon;
}
@Nullable
public CharSequence getSupplementalSubtitleText() {
return mSupplementalSubtitleText;
}
@Nullable
public SmartspaceIcon getSupplementalSubtitleIcon() {
return mSupplementalSubtitleIcon;
}
@Nullable
public SmartspaceTapAction getPrimaryTapAction() {
return mPrimaryTapAction;
}
@Nullable
public SmartspaceTapAction getSupplementalSubtitleTapAction() {
return mSupplementalSubtitleTapAction;
}
@Nullable
public CharSequence getSupplementalAlarmText() {
return mSupplementalAlarmText;
}
/**
* @see Parcelable.Creator
*/
@NonNull
public static final Creator<SmartspaceDefaultUiTemplateData> CREATOR =
new Creator<SmartspaceDefaultUiTemplateData>() {
@Override
public SmartspaceDefaultUiTemplateData createFromParcel(Parcel in) {
return new SmartspaceDefaultUiTemplateData(in);
}
@Override
public SmartspaceDefaultUiTemplateData[] newArray(int size) {
return new SmartspaceDefaultUiTemplateData[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
out.writeInt(mTemplateType);
TextUtils.writeToParcel(mTitleText, out, flags);
out.writeTypedObject(mTitleIcon, flags);
TextUtils.writeToParcel(mSubtitleText, out, flags);
out.writeTypedObject(mSubTitleIcon, flags);
out.writeTypedObject(mPrimaryTapAction, flags);
TextUtils.writeToParcel(mSupplementalSubtitleText, out, flags);
out.writeTypedObject(mSupplementalSubtitleIcon, flags);
out.writeTypedObject(mSupplementalSubtitleTapAction, flags);
TextUtils.writeToParcel(mSupplementalAlarmText, out, flags);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SmartspaceDefaultUiTemplateData)) return false;
SmartspaceDefaultUiTemplateData that = (SmartspaceDefaultUiTemplateData) o;
return mTemplateType == that.mTemplateType && SmartspaceUtils.isEqual(mTitleText,
that.mTitleText)
&& Objects.equals(mTitleIcon, that.mTitleIcon)
&& SmartspaceUtils.isEqual(mSubtitleText, that.mSubtitleText)
&& Objects.equals(mSubTitleIcon, that.mSubTitleIcon)
&& Objects.equals(mPrimaryTapAction, that.mPrimaryTapAction)
&& SmartspaceUtils.isEqual(mSupplementalSubtitleText,
that.mSupplementalSubtitleText)
&& Objects.equals(mSupplementalSubtitleIcon, that.mSupplementalSubtitleIcon)
&& Objects.equals(mSupplementalSubtitleTapAction,
that.mSupplementalSubtitleTapAction)
&& SmartspaceUtils.isEqual(mSupplementalAlarmText, that.mSupplementalAlarmText);
}
@Override
public int hashCode() {
return Objects.hash(mTemplateType, mTitleText, mTitleIcon, mSubtitleText, mSubTitleIcon,
mPrimaryTapAction, mSupplementalSubtitleText, mSupplementalSubtitleIcon,
mSupplementalSubtitleTapAction, mSupplementalAlarmText);
}
@Override
public String toString() {
return "SmartspaceDefaultUiTemplateData{"
+ "mTemplateType=" + mTemplateType
+ ", mTitleText=" + mTitleText
+ ", mTitleIcon=" + mTitleIcon
+ ", mSubtitleText=" + mSubtitleText
+ ", mSubTitleIcon=" + mSubTitleIcon
+ ", mPrimaryTapAction=" + mPrimaryTapAction
+ ", mSupplementalSubtitleText=" + mSupplementalSubtitleText
+ ", mSupplementalSubtitleIcon=" + mSupplementalSubtitleIcon
+ ", mSupplementalSubtitleTapAction=" + mSupplementalSubtitleTapAction
+ ", mSupplementalAlarmText=" + mSupplementalAlarmText
+ '}';
}
/**
* A builder for {@link SmartspaceDefaultUiTemplateData} object.
*
* @hide
*/
@SystemApi
@SuppressLint("StaticFinalBuilder")
public static class Builder {
@UiTemplateType
private final int mTemplateType;
private CharSequence mTitleText;
private SmartspaceIcon mTitleIcon;
private CharSequence mSubtitleText;
private SmartspaceIcon mSubTitleIcon;
private SmartspaceTapAction mPrimaryTapAction;
private CharSequence mSupplementalSubtitleText;
private SmartspaceIcon mSupplementalSubtitleIcon;
private SmartspaceTapAction mSupplementalSubtitleTapAction;
private CharSequence mSupplementalAlarmText;
/**
* A builder for {@link SmartspaceDefaultUiTemplateData}.
*
* @param templateType the {@link UiTemplateType} of this template data.
*/
public Builder(@UiTemplateType int templateType) {
mTemplateType = templateType;
}
/** Should ONLY be used by the subclasses */
@UiTemplateType
@SuppressLint("GetterOnBuilder")
int getTemplateType() {
return mTemplateType;
}
/** Should ONLY be used by the subclasses */
@Nullable
@SuppressLint("GetterOnBuilder")
CharSequence getTitleText() {
return mTitleText;
}
/** Should ONLY be used by the subclasses */
@Nullable
@SuppressLint("GetterOnBuilder")
SmartspaceIcon getTitleIcon() {
return mTitleIcon;
}
/** Should ONLY be used by the subclasses */
@Nullable
@SuppressLint("GetterOnBuilder")
CharSequence getSubtitleText() {
return mSubtitleText;
}
/** Should ONLY be used by the subclasses */
@Nullable
@SuppressLint("GetterOnBuilder")
SmartspaceIcon getSubTitleIcon() {
return mSubTitleIcon;
}
/** Should ONLY be used by the subclasses */
@Nullable
@SuppressLint("GetterOnBuilder")
SmartspaceTapAction getPrimaryTapAction() {
return mPrimaryTapAction;
}
/** Should ONLY be used by the subclasses */
@Nullable
@SuppressLint("GetterOnBuilder")
CharSequence getSupplementalSubtitleText() {
return mSupplementalSubtitleText;
}
/** Should ONLY be used by the subclasses */
@Nullable
@SuppressLint("GetterOnBuilder")
SmartspaceIcon getSupplementalSubtitleIcon() {
return mSupplementalSubtitleIcon;
}
/** Should ONLY be used by the subclasses */
@Nullable
@SuppressLint("GetterOnBuilder")
SmartspaceTapAction getSupplementalSubtitleTapAction() {
return mSupplementalSubtitleTapAction;
}
/** Should ONLY be used by the subclasses */
@Nullable
@SuppressLint("GetterOnBuilder")
CharSequence getSupplementalAlarmText() {
return mSupplementalAlarmText;
}
/**
* Sets the card title.
*/
@NonNull
public Builder setTitleText(@NonNull CharSequence titleText) {
mTitleText = titleText;
return this;
}
/**
* Sets the card title icon.
*/
@NonNull
public Builder setTitleIcon(@NonNull SmartspaceIcon titleIcon) {
mTitleIcon = titleIcon;
return this;
}
/**
* Sets the card subtitle.
*/
@NonNull
public Builder setSubtitleText(@NonNull CharSequence subtitleText) {
mSubtitleText = subtitleText;
return this;
}
/**
* Sets the card subtitle icon.
*/
@NonNull
public Builder setSubTitleIcon(@NonNull SmartspaceIcon subTitleIcon) {
mSubTitleIcon = subTitleIcon;
return this;
}
/**
* Sets the card primary tap action.
*/
@NonNull
public Builder setPrimaryTapAction(@NonNull SmartspaceTapAction primaryTapAction) {
mPrimaryTapAction = primaryTapAction;
return this;
}
/**
* Sets the supplemental subtitle text.
*/
@NonNull
public Builder setSupplementalSubtitleText(@NonNull CharSequence supplementalSubtitleText) {
mSupplementalSubtitleText = supplementalSubtitleText;
return this;
}
/**
* Sets the supplemental subtitle icon.
*/
@NonNull
public Builder setSupplementalSubtitleIcon(
@NonNull SmartspaceIcon supplementalSubtitleIcon) {
mSupplementalSubtitleIcon = supplementalSubtitleIcon;
return this;
}
/**
* Sets the supplemental subtitle tap action. {@code mPrimaryTapAction} will be used if not
* being
* set.
*/
@NonNull
public Builder setSupplementalSubtitleTapAction(
@NonNull SmartspaceTapAction supplementalSubtitleTapAction) {
mSupplementalSubtitleTapAction = supplementalSubtitleTapAction;
return this;
}
/**
* Sets the supplemental alarm text.
*/
@NonNull
public Builder setSupplementalAlarmText(@NonNull CharSequence supplementalAlarmText) {
mSupplementalAlarmText = supplementalAlarmText;
return this;
}
/**
* Builds a new SmartspaceDefaultUiTemplateData instance.
*/
@NonNull
public SmartspaceDefaultUiTemplateData build() {
return new SmartspaceDefaultUiTemplateData(mTemplateType, mTitleText, mTitleIcon,
mSubtitleText, mSubTitleIcon, mPrimaryTapAction, mSupplementalSubtitleText,
mSupplementalSubtitleIcon, mSupplementalSubtitleTapAction,
mSupplementalAlarmText);
}
}
}

View File

@@ -0,0 +1,286 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace.uitemplatedata;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.smartspace.SmartspaceTarget;
import android.app.smartspace.SmartspaceUtils;
import android.os.Parcel;
import android.text.TextUtils;
import java.util.Objects;
/**
* Holds all the relevant data needed to render a Smartspace card with the head-to-head Ui Template.
*
* @hide
*/
@SystemApi
public final class SmartspaceHeadToHeadUiTemplateData extends SmartspaceDefaultUiTemplateData {
@Nullable
private final CharSequence mHeadToHeadTitle;
@Nullable
private final SmartspaceIcon mHeadToHeadFirstCompetitorIcon;
@Nullable
private final SmartspaceIcon mHeadToHeadSecondCompetitorIcon;
@Nullable
private final CharSequence mHeadToHeadFirstCompetitorText;
@Nullable
private final CharSequence mHeadToHeadSecondCompetitorText;
/** Tap action for the head-to-head secondary card. */
@Nullable
private final SmartspaceTapAction mHeadToHeadAction;
SmartspaceHeadToHeadUiTemplateData(@NonNull Parcel in) {
super(in);
mHeadToHeadTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mHeadToHeadFirstCompetitorIcon = in.readTypedObject(SmartspaceIcon.CREATOR);
mHeadToHeadSecondCompetitorIcon = in.readTypedObject(SmartspaceIcon.CREATOR);
mHeadToHeadFirstCompetitorText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mHeadToHeadSecondCompetitorText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mHeadToHeadAction = in.readTypedObject(SmartspaceTapAction.CREATOR);
}
private SmartspaceHeadToHeadUiTemplateData(@SmartspaceTarget.UiTemplateType int templateType,
@Nullable CharSequence titleText,
@Nullable SmartspaceIcon titleIcon,
@Nullable CharSequence subtitleText,
@Nullable SmartspaceIcon subTitleIcon,
@Nullable SmartspaceTapAction primaryTapAction,
@Nullable CharSequence supplementalSubtitleText,
@Nullable SmartspaceIcon supplementalSubtitleIcon,
@Nullable SmartspaceTapAction supplementalSubtitleTapAction,
@Nullable CharSequence supplementalAlarmText,
@Nullable CharSequence headToHeadTitle,
@Nullable SmartspaceIcon headToHeadFirstCompetitorIcon,
@Nullable SmartspaceIcon headToHeadSecondCompetitorIcon,
@Nullable CharSequence headToHeadFirstCompetitorText,
@Nullable CharSequence headToHeadSecondCompetitorText,
@Nullable SmartspaceTapAction headToHeadAction) {
super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction,
supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction,
supplementalAlarmText);
mHeadToHeadTitle = headToHeadTitle;
mHeadToHeadFirstCompetitorIcon = headToHeadFirstCompetitorIcon;
mHeadToHeadSecondCompetitorIcon = headToHeadSecondCompetitorIcon;
mHeadToHeadFirstCompetitorText = headToHeadFirstCompetitorText;
mHeadToHeadSecondCompetitorText = headToHeadSecondCompetitorText;
mHeadToHeadAction = headToHeadAction;
}
@Nullable
public CharSequence getHeadToHeadTitle() {
return mHeadToHeadTitle;
}
@Nullable
public SmartspaceIcon getHeadToHeadFirstCompetitorIcon() {
return mHeadToHeadFirstCompetitorIcon;
}
@Nullable
public SmartspaceIcon getHeadToHeadSecondCompetitorIcon() {
return mHeadToHeadSecondCompetitorIcon;
}
@Nullable
public CharSequence getHeadToHeadFirstCompetitorText() {
return mHeadToHeadFirstCompetitorText;
}
@Nullable
public CharSequence getHeadToHeadSecondCompetitorText() {
return mHeadToHeadSecondCompetitorText;
}
@Nullable
public SmartspaceTapAction getHeadToHeadAction() {
return mHeadToHeadAction;
}
/**
* @see Parcelable.Creator
*/
@NonNull
public static final Creator<SmartspaceHeadToHeadUiTemplateData> CREATOR =
new Creator<SmartspaceHeadToHeadUiTemplateData>() {
@Override
public SmartspaceHeadToHeadUiTemplateData createFromParcel(Parcel in) {
return new SmartspaceHeadToHeadUiTemplateData(in);
}
@Override
public SmartspaceHeadToHeadUiTemplateData[] newArray(int size) {
return new SmartspaceHeadToHeadUiTemplateData[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
super.writeToParcel(out, flags);
TextUtils.writeToParcel(mHeadToHeadTitle, out, flags);
out.writeTypedObject(mHeadToHeadFirstCompetitorIcon, flags);
out.writeTypedObject(mHeadToHeadSecondCompetitorIcon, flags);
TextUtils.writeToParcel(mHeadToHeadFirstCompetitorText, out, flags);
TextUtils.writeToParcel(mHeadToHeadSecondCompetitorText, out, flags);
out.writeTypedObject(mHeadToHeadAction, flags);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SmartspaceHeadToHeadUiTemplateData)) return false;
if (!super.equals(o)) return false;
SmartspaceHeadToHeadUiTemplateData that = (SmartspaceHeadToHeadUiTemplateData) o;
return SmartspaceUtils.isEqual(mHeadToHeadTitle, that.mHeadToHeadTitle) && Objects.equals(
mHeadToHeadFirstCompetitorIcon, that.mHeadToHeadFirstCompetitorIcon)
&& Objects.equals(
mHeadToHeadSecondCompetitorIcon, that.mHeadToHeadSecondCompetitorIcon)
&& SmartspaceUtils.isEqual(mHeadToHeadFirstCompetitorText,
that.mHeadToHeadFirstCompetitorText)
&& SmartspaceUtils.isEqual(mHeadToHeadSecondCompetitorText,
that.mHeadToHeadSecondCompetitorText)
&& Objects.equals(
mHeadToHeadAction, that.mHeadToHeadAction);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mHeadToHeadTitle, mHeadToHeadFirstCompetitorIcon,
mHeadToHeadSecondCompetitorIcon, mHeadToHeadFirstCompetitorText,
mHeadToHeadSecondCompetitorText,
mHeadToHeadAction);
}
@Override
public String toString() {
return super.toString() + " + SmartspaceHeadToHeadUiTemplateData{"
+ "mH2HTitle=" + mHeadToHeadTitle
+ ", mH2HFirstCompetitorIcon=" + mHeadToHeadFirstCompetitorIcon
+ ", mH2HSecondCompetitorIcon=" + mHeadToHeadSecondCompetitorIcon
+ ", mH2HFirstCompetitorText=" + mHeadToHeadFirstCompetitorText
+ ", mH2HSecondCompetitorText=" + mHeadToHeadSecondCompetitorText
+ ", mH2HAction=" + mHeadToHeadAction
+ '}';
}
/**
* A builder for {@link SmartspaceHeadToHeadUiTemplateData} object.
*
* @hide
*/
@SystemApi
public static final class Builder extends SmartspaceDefaultUiTemplateData.Builder {
private CharSequence mHeadToHeadTitle;
private SmartspaceIcon mHeadToHeadFirstCompetitorIcon;
private SmartspaceIcon mHeadToHeadSecondCompetitorIcon;
private CharSequence mHeadToHeadFirstCompetitorText;
private CharSequence mHeadToHeadSecondCompetitorText;
private SmartspaceTapAction mHeadToHeadAction;
/**
* A builder for {@link SmartspaceHeadToHeadUiTemplateData}.
*/
public Builder() {
super(SmartspaceTarget.UI_TEMPLATE_HEAD_TO_HEAD);
}
/**
* Sets the head-to-head card's title
*/
@NonNull
public Builder setHeadToHeadTitle(@Nullable CharSequence headToHeadTitle) {
mHeadToHeadTitle = headToHeadTitle;
return this;
}
/**
* Sets the head-to-head card's first competitor icon
*/
@NonNull
public Builder setHeadToHeadFirstCompetitorIcon(
@Nullable SmartspaceIcon headToHeadFirstCompetitorIcon) {
mHeadToHeadFirstCompetitorIcon = headToHeadFirstCompetitorIcon;
return this;
}
/**
* Sets the head-to-head card's second competitor icon
*/
@NonNull
public Builder setHeadToHeadSecondCompetitorIcon(
@Nullable SmartspaceIcon headToHeadSecondCompetitorIcon) {
mHeadToHeadSecondCompetitorIcon = headToHeadSecondCompetitorIcon;
return this;
}
/**
* Sets the head-to-head card's first competitor text
*/
@NonNull
public Builder setHeadToHeadFirstCompetitorText(
@Nullable CharSequence headToHeadFirstCompetitorText) {
mHeadToHeadFirstCompetitorText = headToHeadFirstCompetitorText;
return this;
}
/**
* Sets the head-to-head card's second competitor text
*/
@NonNull
public Builder setHeadToHeadSecondCompetitorText(
@Nullable CharSequence headToHeadSecondCompetitorText) {
mHeadToHeadSecondCompetitorText = headToHeadSecondCompetitorText;
return this;
}
/**
* Sets the head-to-head card's tap action
*/
@NonNull
public Builder setHeadToHeadAction(@Nullable SmartspaceTapAction headToHeadAction) {
mHeadToHeadAction = headToHeadAction;
return this;
}
/**
* Builds a new SmartspaceHeadToHeadUiTemplateData instance.
*/
@NonNull
public SmartspaceHeadToHeadUiTemplateData build() {
return new SmartspaceHeadToHeadUiTemplateData(getTemplateType(), getTitleText(),
getTitleIcon(), getSubtitleText(), getSubTitleIcon(), getPrimaryTapAction(),
getSupplementalSubtitleText(), getSupplementalSubtitleIcon(),
getSupplementalSubtitleTapAction(), getSupplementalAlarmText(),
mHeadToHeadTitle,
mHeadToHeadFirstCompetitorIcon,
mHeadToHeadSecondCompetitorIcon, mHeadToHeadFirstCompetitorText,
mHeadToHeadSecondCompetitorText,
mHeadToHeadAction);
}
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace.uitemplatedata;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.smartspace.SmartspaceUtils;
import android.graphics.drawable.Icon;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import java.util.Objects;
/**
* Holds the information for a Smartspace-card icon. Including the icon image itself, and an
* optional content description as the icon's accessibility description.
*
* @hide
*/
@SystemApi
public final class SmartspaceIcon implements Parcelable {
@NonNull
private final Icon mIcon;
@Nullable
private final CharSequence mContentDescription;
SmartspaceIcon(@NonNull Parcel in) {
mIcon = in.readTypedObject(Icon.CREATOR);
mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
}
private SmartspaceIcon(@NonNull Icon icon, @Nullable CharSequence contentDescription) {
mIcon = icon;
mContentDescription = contentDescription;
}
@NonNull
public Icon getIcon() {
return mIcon;
}
@Nullable
public CharSequence getContentDescription() {
return mContentDescription;
}
@NonNull
public static final Creator<SmartspaceIcon> CREATOR = new Creator<SmartspaceIcon>() {
@Override
public SmartspaceIcon createFromParcel(Parcel in) {
return new SmartspaceIcon(in);
}
@Override
public SmartspaceIcon[] newArray(int size) {
return new SmartspaceIcon[size];
}
};
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SmartspaceIcon)) return false;
SmartspaceIcon that = (SmartspaceIcon) o;
return mIcon.equals(that.mIcon) && SmartspaceUtils.isEqual(mContentDescription,
that.mContentDescription);
}
@Override
public int hashCode() {
return Objects.hash(mIcon, mContentDescription);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
out.writeTypedObject(mIcon, flags);
TextUtils.writeToParcel(mContentDescription, out, flags);
}
@Override
public String toString() {
return "SmartspaceIcon{"
+ "mImage=" + mIcon
+ ", mContentDescription='" + mContentDescription + '\''
+ '}';
}
/**
* A builder for {@link SmartspaceIcon} object.
*
* @hide
*/
@SystemApi
public static final class Builder {
private Icon mIcon;
private CharSequence mContentDescription;
/**
* A builder for {@link SmartspaceIcon}.
*
* @param icon the icon image of this smartspace icon.
*/
public Builder(@NonNull Icon icon) {
mIcon = Objects.requireNonNull(icon);
}
/**
* Sets the icon's content description.
*/
@NonNull
public Builder setContentDescription(@NonNull CharSequence contentDescription) {
mContentDescription = contentDescription;
return this;
}
/**
* Builds a new SmartspaceIcon instance.
*/
@NonNull
public SmartspaceIcon build() {
return new SmartspaceIcon(mIcon, mContentDescription);
}
}
}

View File

@@ -0,0 +1,198 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace.uitemplatedata;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.smartspace.SmartspaceTarget;
import android.app.smartspace.SmartspaceUtils;
import android.os.Parcel;
import android.text.TextUtils;
import java.util.Objects;
/**
* Holds all the relevant data needed to render a Smartspace card with the sub-card Ui Template.
*
* @hide
*/
@SystemApi
public final class SmartspaceSubCardUiTemplateData extends SmartspaceDefaultUiTemplateData {
/** Icon for the sub-card. */
@NonNull
private final SmartspaceIcon mSubCardIcon;
/** Text for the sub-card, which shows below the icon when being set. */
@Nullable
private final CharSequence mSubCardText;
/** Tap action for the sub-card secondary card. */
@Nullable
private final SmartspaceTapAction mSubCardAction;
SmartspaceSubCardUiTemplateData(@NonNull Parcel in) {
super(in);
mSubCardIcon = in.readTypedObject(SmartspaceIcon.CREATOR);
mSubCardText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mSubCardAction = in.readTypedObject(SmartspaceTapAction.CREATOR);
}
private SmartspaceSubCardUiTemplateData(int templateType,
@Nullable CharSequence titleText,
@Nullable SmartspaceIcon titleIcon,
@Nullable CharSequence subtitleText,
@Nullable SmartspaceIcon subTitleIcon,
@Nullable SmartspaceTapAction primaryTapAction,
@Nullable CharSequence supplementalSubtitleText,
@Nullable SmartspaceIcon supplementalSubtitleIcon,
@Nullable SmartspaceTapAction supplementalSubtitleTapAction,
@Nullable CharSequence supplementalAlarmText,
@NonNull SmartspaceIcon subCardIcon,
@Nullable CharSequence subCardText,
@Nullable SmartspaceTapAction subCardAction) {
super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction,
supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction,
supplementalAlarmText);
mSubCardIcon = subCardIcon;
mSubCardText = subCardText;
mSubCardAction = subCardAction;
}
@NonNull
public SmartspaceIcon getSubCardIcon() {
return mSubCardIcon;
}
@Nullable
public CharSequence getSubCardText() {
return mSubCardText;
}
@Nullable
public SmartspaceTapAction getSubCardAction() {
return mSubCardAction;
}
/**
* @see Parcelable.Creator
*/
@NonNull
public static final Creator<SmartspaceSubCardUiTemplateData> CREATOR =
new Creator<SmartspaceSubCardUiTemplateData>() {
@Override
public SmartspaceSubCardUiTemplateData createFromParcel(Parcel in) {
return new SmartspaceSubCardUiTemplateData(in);
}
@Override
public SmartspaceSubCardUiTemplateData[] newArray(int size) {
return new SmartspaceSubCardUiTemplateData[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeTypedObject(mSubCardIcon, flags);
TextUtils.writeToParcel(mSubCardText, out, flags);
out.writeTypedObject(mSubCardAction, flags);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SmartspaceSubCardUiTemplateData)) return false;
if (!super.equals(o)) return false;
SmartspaceSubCardUiTemplateData that = (SmartspaceSubCardUiTemplateData) o;
return mSubCardIcon.equals(that.mSubCardIcon) && SmartspaceUtils.isEqual(mSubCardText,
that.mSubCardText) && Objects.equals(mSubCardAction,
that.mSubCardAction);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mSubCardIcon, mSubCardText, mSubCardAction);
}
@Override
public String toString() {
return super.toString() + " + SmartspaceSubCardUiTemplateData{"
+ "mSubCardIcon=" + mSubCardIcon
+ ", mSubCardText=" + mSubCardText
+ ", mSubCardAction=" + mSubCardAction
+ '}';
}
/**
* A builder for {@link SmartspaceSubCardUiTemplateData} object.
*
* @hide
*/
@SystemApi
public static final class Builder extends SmartspaceDefaultUiTemplateData.Builder {
private final SmartspaceIcon mSubCardIcon;
private CharSequence mSubCardText;
private SmartspaceTapAction mSubCardAction;
/**
* A builder for {@link SmartspaceSubCardUiTemplateData}.
*/
public Builder(@NonNull SmartspaceIcon subCardIcon) {
super(SmartspaceTarget.UI_TEMPLATE_SUB_CARD);
mSubCardIcon = Objects.requireNonNull(subCardIcon);
}
/**
* Sets the card title text.
*/
@NonNull
public Builder setSubCardAction(@NonNull CharSequence subCardTitleText) {
mSubCardText = subCardTitleText;
return this;
}
/**
* Sets the card tap action.
*/
@NonNull
public Builder setSubCardAction(@NonNull SmartspaceTapAction subCardAction) {
mSubCardAction = subCardAction;
return this;
}
/**
* Builds a new SmartspaceSubCardUiTemplateData instance.
*/
@NonNull
public SmartspaceSubCardUiTemplateData build() {
return new SmartspaceSubCardUiTemplateData(getTemplateType(), getTitleText(),
getTitleIcon(), getSubtitleText(), getSubTitleIcon(), getPrimaryTapAction(),
getSupplementalSubtitleText(), getSupplementalSubtitleIcon(),
getSupplementalSubtitleTapAction(), getSupplementalAlarmText(), mSubCardIcon,
mSubCardText,
mSubCardAction);
}
}
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace.uitemplatedata;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.smartspace.SmartspaceTarget;
import android.os.Parcel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
* Holds all the relevant data needed to render a Smartspace card with the sub-image Ui Template.
*
* @hide
*/
@SystemApi
public final class SmartspaceSubImageUiTemplateData extends SmartspaceDefaultUiTemplateData {
/** Texts are shown next to the image as a vertical list */
@NonNull
private final List<CharSequence> mSubImageTexts;
/** If multiple images are passed in, they will be rendered as GIF. */
@NonNull
private final List<SmartspaceIcon> mSubImages;
/** Tap action for the sub-image secondary card. */
@Nullable
private final SmartspaceTapAction mSubImageAction;
SmartspaceSubImageUiTemplateData(@NonNull Parcel in) {
super(in);
mSubImageTexts = Arrays.asList(in.readCharSequenceArray());
mSubImages = in.createTypedArrayList(SmartspaceIcon.CREATOR);
mSubImageAction = in.readTypedObject(SmartspaceTapAction.CREATOR);
}
private SmartspaceSubImageUiTemplateData(@SmartspaceTarget.UiTemplateType int templateType,
@Nullable CharSequence titleText,
@Nullable SmartspaceIcon titleIcon,
@Nullable CharSequence subtitleText,
@Nullable SmartspaceIcon subTitleIcon,
@Nullable SmartspaceTapAction primaryTapAction,
@Nullable CharSequence supplementalSubtitleText,
@Nullable SmartspaceIcon supplementalSubtitleIcon,
@Nullable SmartspaceTapAction supplementalSubtitleTapAction,
@Nullable CharSequence supplementalAlarmText,
@NonNull List<CharSequence> subImageTexts,
@NonNull List<SmartspaceIcon> subImages,
@Nullable SmartspaceTapAction subImageAction) {
super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction,
supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction,
supplementalAlarmText);
mSubImageTexts = subImageTexts;
mSubImages = subImages;
mSubImageAction = subImageAction;
}
@NonNull
public List<CharSequence> getSubImageTexts() {
return mSubImageTexts;
}
@NonNull
public List<SmartspaceIcon> getSubImages() {
return mSubImages;
}
@Nullable
public SmartspaceTapAction getSubImageAction() {
return mSubImageAction;
}
/**
* @see Parcelable.Creator
*/
@NonNull
public static final Creator<SmartspaceSubImageUiTemplateData> CREATOR =
new Creator<SmartspaceSubImageUiTemplateData>() {
@Override
public SmartspaceSubImageUiTemplateData createFromParcel(Parcel in) {
return new SmartspaceSubImageUiTemplateData(in);
}
@Override
public SmartspaceSubImageUiTemplateData[] newArray(int size) {
return new SmartspaceSubImageUiTemplateData[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeCharSequenceList(new ArrayList<>(mSubImageTexts));
out.writeTypedList(mSubImages);
out.writeTypedObject(mSubImageAction, flags);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SmartspaceSubImageUiTemplateData)) return false;
if (!super.equals(o)) return false;
SmartspaceSubImageUiTemplateData that = (SmartspaceSubImageUiTemplateData) o;
return Objects.equals(mSubImageTexts, that.mSubImageTexts)
&& Objects.equals(mSubImages, that.mSubImages) && Objects.equals(
mSubImageAction, that.mSubImageAction);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mSubImageTexts, mSubImages, mSubImageAction);
}
@Override
public String toString() {
return super.toString() + " + SmartspaceSubImageUiTemplateData{"
+ "mSubImageTexts=" + mSubImageTexts
+ ", mSubImages=" + mSubImages
+ ", mSubImageAction=" + mSubImageAction
+ '}';
}
/**
* A builder for {@link SmartspaceSubImageUiTemplateData} object.
*
* @hide
*/
@SystemApi
public static final class Builder extends SmartspaceDefaultUiTemplateData.Builder {
private final List<CharSequence> mSubImageTexts;
private final List<SmartspaceIcon> mSubImages;
private SmartspaceTapAction mSubImageAction;
/**
* A builder for {@link SmartspaceSubImageUiTemplateData}.
*/
public Builder(@NonNull List<CharSequence> subImageTexts,
@NonNull List<SmartspaceIcon> subImages) {
super(SmartspaceTarget.UI_TEMPLATE_SUB_IMAGE);
mSubImageTexts = Objects.requireNonNull(subImageTexts);
mSubImages = Objects.requireNonNull(subImages);
}
/**
* Sets the card tap action.
*/
@NonNull
public Builder setCarouselAction(@NonNull SmartspaceTapAction subImageAction) {
mSubImageAction = subImageAction;
return this;
}
/**
* Builds a new SmartspaceSubImageUiTemplateData instance.
*/
@NonNull
public SmartspaceSubImageUiTemplateData build() {
return new SmartspaceSubImageUiTemplateData(getTemplateType(), getTitleText(),
getTitleIcon(), getSubtitleText(), getSubTitleIcon(), getPrimaryTapAction(),
getSupplementalSubtitleText(), getSupplementalSubtitleIcon(),
getSupplementalSubtitleTapAction(), getSupplementalAlarmText(), mSubImageTexts,
mSubImages,
mSubImageAction);
}
}
}

View File

@@ -0,0 +1,196 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace.uitemplatedata;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.smartspace.SmartspaceTarget;
import android.os.Parcel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
* Holds all the relevant data needed to render a Smartspace card with the sub-list Ui Template.
*
* @hide
*/
@SystemApi
public final class SmartspaceSubListUiTemplateData extends SmartspaceDefaultUiTemplateData {
@Nullable
private final SmartspaceIcon mSubListIcon;
@NonNull
private final List<CharSequence> mSubListTexts;
/** Tap action for the sub-list secondary card. */
@Nullable
private final SmartspaceTapAction mSubListAction;
SmartspaceSubListUiTemplateData(@NonNull Parcel in) {
super(in);
mSubListIcon = in.readTypedObject(SmartspaceIcon.CREATOR);
mSubListTexts = Arrays.asList(in.readCharSequenceArray());
mSubListAction = in.readTypedObject(SmartspaceTapAction.CREATOR);
}
private SmartspaceSubListUiTemplateData(@SmartspaceTarget.UiTemplateType int templateType,
@Nullable CharSequence titleText,
@Nullable SmartspaceIcon titleIcon,
@Nullable CharSequence subtitleText,
@Nullable SmartspaceIcon subTitleIcon,
@Nullable SmartspaceTapAction primaryTapAction,
@Nullable CharSequence supplementalSubtitleText,
@Nullable SmartspaceIcon supplementalSubtitleIcon,
@Nullable SmartspaceTapAction supplementalSubtitleTapAction,
@Nullable CharSequence supplementalAlarmText,
@Nullable SmartspaceIcon subListIcon,
@NonNull List<CharSequence> subListTexts,
@Nullable SmartspaceTapAction subListAction) {
super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction,
supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction,
supplementalAlarmText);
mSubListIcon = subListIcon;
mSubListTexts = subListTexts;
mSubListAction = subListAction;
}
@Nullable
public SmartspaceIcon getSubListIcon() {
return mSubListIcon;
}
@NonNull
public List<CharSequence> getSubListTexts() {
return mSubListTexts;
}
@Nullable
public SmartspaceTapAction getSubListAction() {
return mSubListAction;
}
/**
* @see Parcelable.Creator
*/
@NonNull
public static final Creator<SmartspaceSubListUiTemplateData> CREATOR =
new Creator<SmartspaceSubListUiTemplateData>() {
@Override
public SmartspaceSubListUiTemplateData createFromParcel(Parcel in) {
return new SmartspaceSubListUiTemplateData(in);
}
@Override
public SmartspaceSubListUiTemplateData[] newArray(int size) {
return new SmartspaceSubListUiTemplateData[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeTypedObject(mSubListIcon, flags);
out.writeCharSequenceList(new ArrayList<>(mSubListTexts));
out.writeTypedObject(mSubListAction, flags);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SmartspaceSubListUiTemplateData)) return false;
if (!super.equals(o)) return false;
SmartspaceSubListUiTemplateData that = (SmartspaceSubListUiTemplateData) o;
return Objects.equals(mSubListIcon, that.mSubListIcon) && Objects.equals(
mSubListTexts, that.mSubListTexts) && Objects.equals(mSubListAction,
that.mSubListAction);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mSubListIcon, mSubListTexts, mSubListAction);
}
@Override
public String toString() {
return super.toString() + " + SmartspaceSubListUiTemplateData{"
+ "mSubListIcon=" + mSubListIcon
+ ", mSubListTexts=" + mSubListTexts
+ ", mSubListAction=" + mSubListAction
+ '}';
}
/**
* A builder for {@link SmartspaceSubListUiTemplateData} object.
*
* @hide
*/
@SystemApi
public static final class Builder extends SmartspaceDefaultUiTemplateData.Builder {
private SmartspaceIcon mSubListIcon;
private final List<CharSequence> mSubListTexts;
private SmartspaceTapAction mSubListAction;
/**
* A builder for {@link SmartspaceSubListUiTemplateData}.
*/
public Builder(@NonNull List<CharSequence> subListTexts) {
super(SmartspaceTarget.UI_TEMPLATE_SUB_LIST);
mSubListTexts = Objects.requireNonNull(subListTexts);
}
/**
* Sets the sub-list card icon.
*/
@NonNull
public Builder setSubListIcon(@NonNull SmartspaceIcon subListIcon) {
mSubListIcon = subListIcon;
return this;
}
/**
* Sets the card tap action.
*/
@NonNull
public Builder setCarouselAction(@NonNull SmartspaceTapAction subListAction) {
mSubListAction = subListAction;
return this;
}
/**
* Builds a new SmartspaceSubListUiTemplateData instance.
*/
@NonNull
public SmartspaceSubListUiTemplateData build() {
return new SmartspaceSubListUiTemplateData(getTemplateType(), getTitleText(),
getTitleIcon(), getSubtitleText(), getSubTitleIcon(), getPrimaryTapAction(),
getSupplementalSubtitleText(), getSupplementalSubtitleIcon(),
getSupplementalSubtitleTapAction(), getSupplementalAlarmText(), mSubListIcon,
mSubListTexts,
mSubListAction);
}
}
}

View File

@@ -0,0 +1,232 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.smartspace.uitemplatedata;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.app.PendingIntent;
import android.app.smartspace.SmartspaceUtils;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;
import android.text.TextUtils;
import java.util.Objects;
/**
* A {@link SmartspaceTapAction} represents an action which can be taken by a user by tapping on
* either the title, the subtitle or on the icon. Supported instances are Intents and
* PendingIntents. These actions can be called from another process or within the client process.
*
* Clients can also receive ShorcutInfos in the extras bundle.
*
* @hide
*/
@SystemApi
public final class SmartspaceTapAction implements Parcelable {
/** A unique Id of this {@link SmartspaceTapAction}. */
@Nullable
private final CharSequence mId;
@Nullable
private final Intent mIntent;
@Nullable
private final PendingIntent mPendingIntent;
@Nullable
private final UserHandle mUserHandle;
@Nullable
private Bundle mExtras;
SmartspaceTapAction(@NonNull Parcel in) {
mId = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mIntent = in.readTypedObject(Intent.CREATOR);
mPendingIntent = in.readTypedObject(PendingIntent.CREATOR);
mUserHandle = in.readTypedObject(UserHandle.CREATOR);
mExtras = in.readBundle();
}
private SmartspaceTapAction(@Nullable CharSequence id, @Nullable Intent intent,
@Nullable PendingIntent pendingIntent, @Nullable UserHandle userHandle,
@Nullable Bundle extras) {
mId = id;
mIntent = intent;
mPendingIntent = pendingIntent;
mUserHandle = userHandle;
mExtras = extras;
}
@Nullable
public CharSequence getId() {
return mId;
}
@SuppressLint("IntentBuilderName")
@Nullable
public Intent getIntent() {
return mIntent;
}
@Nullable
public PendingIntent getPendingIntent() {
return mPendingIntent;
}
@Nullable
public UserHandle getUserHandle() {
return mUserHandle;
}
@Nullable
@SuppressLint("NullableCollection")
public Bundle getExtras() {
return mExtras;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
TextUtils.writeToParcel(mId, out, flags);
out.writeTypedObject(mIntent, flags);
out.writeTypedObject(mPendingIntent, flags);
out.writeTypedObject(mUserHandle, flags);
out.writeBundle(mExtras);
}
@Override
public int describeContents() {
return 0;
}
@NonNull
public static final Creator<SmartspaceTapAction> CREATOR = new Creator<SmartspaceTapAction>() {
@Override
public SmartspaceTapAction createFromParcel(Parcel in) {
return new SmartspaceTapAction(in);
}
@Override
public SmartspaceTapAction[] newArray(int size) {
return new SmartspaceTapAction[size];
}
};
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SmartspaceTapAction)) return false;
SmartspaceTapAction that = (SmartspaceTapAction) o;
return SmartspaceUtils.isEqual(mId, that.mId);
}
@Override
public int hashCode() {
return Objects.hash(mId);
}
@Override
public String toString() {
return "SmartspaceTapAction{"
+ "mId=" + mId
+ "mIntent=" + mIntent
+ ", mPendingIntent=" + mPendingIntent
+ ", mUserHandle=" + mUserHandle
+ ", mExtras=" + mExtras
+ '}';
}
/**
* A builder for {@link SmartspaceTapAction} object.
*
* @hide
*/
@SystemApi
public static final class Builder {
private CharSequence mId;
private Intent mIntent;
private PendingIntent mPendingIntent;
private UserHandle mUserHandle;
private Bundle mExtras;
/**
* A builder for {@link SmartspaceTapAction}.
*
* @param id A unique Id of this {@link SmartspaceTapAction}.
*/
public Builder(@NonNull CharSequence id) {
mId = Objects.requireNonNull(id);
}
/**
* Sets the action intent.
*/
@NonNull
public Builder setIntent(@NonNull Intent intent) {
mIntent = intent;
return this;
}
/**
* Sets the pending intent.
*/
@NonNull
public Builder setPendingIntent(@NonNull PendingIntent pendingIntent) {
mPendingIntent = pendingIntent;
return this;
}
/**
* Sets the user handle.
*/
@NonNull
@SuppressLint("UserHandleName")
public Builder setUserHandle(@Nullable UserHandle userHandle) {
mUserHandle = userHandle;
return this;
}
/**
* Sets the extras.
*/
@NonNull
public Builder setExtras(@NonNull Bundle extras) {
mExtras = extras;
return this;
}
/**
* Builds a new SmartspaceTapAction instance.
*
* @throws IllegalStateException if the tap action is empty.
*/
@NonNull
public SmartspaceTapAction build() {
if (mIntent == null && mPendingIntent == null && mExtras == null) {
throw new IllegalStateException("Please assign at least 1 valid tap field");
}
return new SmartspaceTapAction(mId, mIntent, mPendingIntent, mUserHandle, mExtras);
}
}
}

View File

@@ -20,6 +20,7 @@ import android.app.PendingIntent;
import android.app.smartspace.SmartspaceAction;
import android.app.smartspace.SmartspaceTarget;
import android.app.smartspace.SmartspaceTargetEvent;
import android.app.smartspace.uitemplatedata.SmartspaceTapAction;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.drawable.Drawable;
@@ -138,6 +139,18 @@ public interface BcSmartspaceDataPlugin extends Plugin {
}
}
default void startFromAction(SmartspaceTapAction action, View v, boolean showOnLockscreen) {
try {
if (action.getIntent() != null) {
startIntent(v, action.getIntent(), showOnLockscreen);
} else if (action.getPendingIntent() != null) {
startPendingIntent(action.getPendingIntent(), showOnLockscreen);
}
} catch (ActivityNotFoundException e) {
Log.w(TAG, "Could not launch intent for action: " + action, e);
}
}
/** Start the intent */
void startIntent(View v, Intent i, boolean showOnLockscreen);