From 663abefa00a73a3d532558cdd146d00899fa9096 Mon Sep 17 00:00:00 2001 From: Cecilia Date: Wed, 9 Feb 2022 08:10:06 +0000 Subject: Modify the documentations for the UI template APIs - Rename the classes to be less verbose; - Add the template layout descriptions to its corresponding data classes; - Documents for all getter/setter methods. Fixes: 217554855 Test: atest CtsSmartspaceServiceTestCases Change-Id: Id5abcea0210b19b40c96cc8183e439c8af95bf85 --- core/api/system-current.txt | 266 ++++++------ .../android/app/smartspace/SmartspaceTarget.java | 24 +- .../android/app/smartspace/SmartspaceUtils.java | 10 +- .../uitemplatedata/BaseTemplateData.java | 476 +++++++++++++++++++++ .../uitemplatedata/CarouselTemplateData.java | 376 ++++++++++++++++ .../uitemplatedata/CombinedCardsTemplateData.java | 160 +++++++ .../uitemplatedata/HeadToHeadTemplateData.java | 298 +++++++++++++ .../app/smartspace/uitemplatedata/Icon.java | 174 ++++++++ .../SmartspaceCarouselUiTemplateData.java | 360 ---------------- .../SmartspaceCombinedCardsUiTemplateData.java | 155 ------- .../SmartspaceDefaultUiTemplateData.java | 459 -------------------- .../SmartspaceHeadToHeadUiTemplateData.java | 285 ------------ .../smartspace/uitemplatedata/SmartspaceIcon.java | 172 -------- .../SmartspaceSubCardUiTemplateData.java | 197 --------- .../SmartspaceSubImageUiTemplateData.java | 190 -------- .../SmartspaceSubListUiTemplateData.java | 195 --------- .../uitemplatedata/SmartspaceTapAction.java | 232 ---------- .../smartspace/uitemplatedata/SmartspaceText.java | 143 ------- .../uitemplatedata/SubCardTemplateData.java | 206 +++++++++ .../uitemplatedata/SubImageTemplateData.java | 203 +++++++++ .../uitemplatedata/SubListTemplateData.java | 206 +++++++++ .../app/smartspace/uitemplatedata/TapAction.java | 237 ++++++++++ .../app/smartspace/uitemplatedata/Text.java | 170 ++++++++ .../systemui/plugins/BcSmartspaceDataPlugin.java | 4 +- 24 files changed, 2664 insertions(+), 2534 deletions(-) create mode 100644 core/java/android/app/smartspace/uitemplatedata/BaseTemplateData.java create mode 100644 core/java/android/app/smartspace/uitemplatedata/CarouselTemplateData.java create mode 100644 core/java/android/app/smartspace/uitemplatedata/CombinedCardsTemplateData.java create mode 100644 core/java/android/app/smartspace/uitemplatedata/HeadToHeadTemplateData.java create mode 100644 core/java/android/app/smartspace/uitemplatedata/Icon.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceCarouselUiTemplateData.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceCombinedCardsUiTemplateData.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceDefaultUiTemplateData.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceHeadToHeadUiTemplateData.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceIcon.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceSubCardUiTemplateData.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceSubImageUiTemplateData.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceSubListUiTemplateData.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceTapAction.java delete mode 100644 core/java/android/app/smartspace/uitemplatedata/SmartspaceText.java create mode 100644 core/java/android/app/smartspace/uitemplatedata/SubCardTemplateData.java create mode 100644 core/java/android/app/smartspace/uitemplatedata/SubImageTemplateData.java create mode 100644 core/java/android/app/smartspace/uitemplatedata/SubListTemplateData.java create mode 100644 core/java/android/app/smartspace/uitemplatedata/TapAction.java create mode 100644 core/java/android/app/smartspace/uitemplatedata/Text.java diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 3e58379dea80..8578f4bd71e9 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -1837,7 +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 @Nullable public android.app.smartspace.uitemplatedata.BaseTemplateData getTemplateData(); method @NonNull public android.os.UserHandle getUserHandle(); method @Nullable public android.appwidget.AppWidgetProviderInfo getWidget(); method public boolean isSensitive(); @@ -1894,7 +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 setTemplateData(@Nullable android.app.smartspace.uitemplatedata.BaseTemplateData); method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setWidget(@NonNull android.appwidget.AppWidgetProviderInfo); } @@ -1925,156 +1925,156 @@ 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 getCarouselItems(); - field @NonNull public static final android.os.Parcelable.Creator CREATOR; + public class BaseTemplateData implements android.os.Parcelable { + method public int describeContents(); + method @Nullable public android.app.smartspace.uitemplatedata.TapAction getPrimaryTapAction(); + method @Nullable public android.app.smartspace.uitemplatedata.Icon getSubtitleIcon(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getSubtitleText(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getSupplementalAlarmText(); + method @Nullable public android.app.smartspace.uitemplatedata.Icon getSupplementalSubtitleIcon(); + method @Nullable public android.app.smartspace.uitemplatedata.TapAction getSupplementalSubtitleTapAction(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getSupplementalSubtitleText(); + method public int getTemplateType(); + method @Nullable public android.app.smartspace.uitemplatedata.Icon getTitleIcon(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getTitleText(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + + public static class BaseTemplateData.Builder { + ctor public BaseTemplateData.Builder(int); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData build(); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData.Builder setPrimaryTapAction(@NonNull android.app.smartspace.uitemplatedata.TapAction); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData.Builder setSubtitleIcon(@NonNull android.app.smartspace.uitemplatedata.Icon); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData.Builder setSubtitleText(@NonNull android.app.smartspace.uitemplatedata.Text); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData.Builder setSupplementalAlarmText(@NonNull android.app.smartspace.uitemplatedata.Text); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData.Builder setSupplementalSubtitleIcon(@NonNull android.app.smartspace.uitemplatedata.Icon); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData.Builder setSupplementalSubtitleTapAction(@NonNull android.app.smartspace.uitemplatedata.TapAction); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData.Builder setSupplementalSubtitleText(@NonNull android.app.smartspace.uitemplatedata.Text); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData.Builder setTitleIcon(@NonNull android.app.smartspace.uitemplatedata.Icon); + method @NonNull public android.app.smartspace.uitemplatedata.BaseTemplateData.Builder setTitleText(@NonNull android.app.smartspace.uitemplatedata.Text); + } + + public final class CarouselTemplateData extends android.app.smartspace.uitemplatedata.BaseTemplateData { + method @Nullable public android.app.smartspace.uitemplatedata.TapAction getCarouselAction(); + method @NonNull public java.util.List getCarouselItems(); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; } - public static final class SmartspaceCarouselUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder { - ctor public SmartspaceCarouselUiTemplateData.Builder(@NonNull java.util.List); - 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 CarouselTemplateData.Builder extends android.app.smartspace.uitemplatedata.BaseTemplateData.Builder { + ctor public CarouselTemplateData.Builder(@NonNull java.util.List); + method @NonNull public android.app.smartspace.uitemplatedata.CarouselTemplateData build(); + method @NonNull public android.app.smartspace.uitemplatedata.CarouselTemplateData.Builder setCarouselAction(@NonNull android.app.smartspace.uitemplatedata.TapAction); } - public static final class SmartspaceCarouselUiTemplateData.CarouselItem implements android.os.Parcelable { + public static final class CarouselTemplateData.CarouselItem implements android.os.Parcelable { method public int describeContents(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getImage(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceText getLowerText(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getTapAction(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceText getUpperText(); + method @Nullable public android.app.smartspace.uitemplatedata.Icon getImage(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getLowerText(); + method @Nullable public android.app.smartspace.uitemplatedata.TapAction getTapAction(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getUpperText(); method public void writeToParcel(@NonNull android.os.Parcel, int); - field @NonNull public static final android.os.Parcelable.Creator CREATOR; + field @NonNull public static final android.os.Parcelable.Creator 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 android.app.smartspace.uitemplatedata.SmartspaceText); - 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 android.app.smartspace.uitemplatedata.SmartspaceText); + public static final class CarouselTemplateData.CarouselItem.Builder { + ctor public CarouselTemplateData.CarouselItem.Builder(); + method @NonNull public android.app.smartspace.uitemplatedata.CarouselTemplateData.CarouselItem build(); + method @NonNull public android.app.smartspace.uitemplatedata.CarouselTemplateData.CarouselItem.Builder setImage(@Nullable android.app.smartspace.uitemplatedata.Icon); + method @NonNull public android.app.smartspace.uitemplatedata.CarouselTemplateData.CarouselItem.Builder setLowerText(@Nullable android.app.smartspace.uitemplatedata.Text); + method @NonNull public android.app.smartspace.uitemplatedata.CarouselTemplateData.CarouselItem.Builder setTapAction(@Nullable android.app.smartspace.uitemplatedata.TapAction); + method @NonNull public android.app.smartspace.uitemplatedata.CarouselTemplateData.CarouselItem.Builder setUpperText(@Nullable android.app.smartspace.uitemplatedata.Text); } - public final class SmartspaceCombinedCardsUiTemplateData extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData { - method @NonNull public java.util.List getCombinedCardDataList(); - field @NonNull public static final android.os.Parcelable.Creator CREATOR; + public final class CombinedCardsTemplateData extends android.app.smartspace.uitemplatedata.BaseTemplateData { + method @NonNull public java.util.List getCombinedCardDataList(); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; } - public static final class SmartspaceCombinedCardsUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder { - ctor public SmartspaceCombinedCardsUiTemplateData.Builder(@NonNull java.util.List); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceCombinedCardsUiTemplateData build(); + public static final class CombinedCardsTemplateData.Builder extends android.app.smartspace.uitemplatedata.BaseTemplateData.Builder { + ctor public CombinedCardsTemplateData.Builder(@NonNull java.util.List); + method @NonNull public android.app.smartspace.uitemplatedata.CombinedCardsTemplateData 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 android.app.smartspace.uitemplatedata.SmartspaceText getSubtitleText(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceText getSupplementalAlarmText(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getSupplementalSubtitleIcon(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceTapAction getSupplementalSubtitleTapAction(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceText getSupplementalSubtitleText(); - method public int getTemplateType(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getTitleIcon(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceText getTitleText(); - method public void writeToParcel(@NonNull android.os.Parcel, int); - field @NonNull public static final android.os.Parcelable.Creator 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 android.app.smartspace.uitemplatedata.SmartspaceText); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder setSupplementalAlarmText(@NonNull android.app.smartspace.uitemplatedata.SmartspaceText); - 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 android.app.smartspace.uitemplatedata.SmartspaceText); - 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 android.app.smartspace.uitemplatedata.SmartspaceText); - } - - 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 android.app.smartspace.uitemplatedata.SmartspaceText getHeadToHeadFirstCompetitorText(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceIcon getHeadToHeadSecondCompetitorIcon(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceText getHeadToHeadSecondCompetitorText(); - method @Nullable public android.app.smartspace.uitemplatedata.SmartspaceText getHeadToHeadTitle(); - field @NonNull public static final android.os.Parcelable.Creator 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 android.app.smartspace.uitemplatedata.SmartspaceText); - 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 android.app.smartspace.uitemplatedata.SmartspaceText); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceHeadToHeadUiTemplateData.Builder setHeadToHeadTitle(@Nullable android.app.smartspace.uitemplatedata.SmartspaceText); - } - - public final class SmartspaceIcon implements android.os.Parcelable { + public final class HeadToHeadTemplateData extends android.app.smartspace.uitemplatedata.BaseTemplateData { + method @Nullable public android.app.smartspace.uitemplatedata.TapAction getHeadToHeadAction(); + method @Nullable public android.app.smartspace.uitemplatedata.Icon getHeadToHeadFirstCompetitorIcon(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getHeadToHeadFirstCompetitorText(); + method @Nullable public android.app.smartspace.uitemplatedata.Icon getHeadToHeadSecondCompetitorIcon(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getHeadToHeadSecondCompetitorText(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getHeadToHeadTitle(); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + + public static final class HeadToHeadTemplateData.Builder extends android.app.smartspace.uitemplatedata.BaseTemplateData.Builder { + ctor public HeadToHeadTemplateData.Builder(); + method @NonNull public android.app.smartspace.uitemplatedata.HeadToHeadTemplateData build(); + method @NonNull public android.app.smartspace.uitemplatedata.HeadToHeadTemplateData.Builder setHeadToHeadAction(@Nullable android.app.smartspace.uitemplatedata.TapAction); + method @NonNull public android.app.smartspace.uitemplatedata.HeadToHeadTemplateData.Builder setHeadToHeadFirstCompetitorIcon(@Nullable android.app.smartspace.uitemplatedata.Icon); + method @NonNull public android.app.smartspace.uitemplatedata.HeadToHeadTemplateData.Builder setHeadToHeadFirstCompetitorText(@Nullable android.app.smartspace.uitemplatedata.Text); + method @NonNull public android.app.smartspace.uitemplatedata.HeadToHeadTemplateData.Builder setHeadToHeadSecondCompetitorIcon(@Nullable android.app.smartspace.uitemplatedata.Icon); + method @NonNull public android.app.smartspace.uitemplatedata.HeadToHeadTemplateData.Builder setHeadToHeadSecondCompetitorText(@Nullable android.app.smartspace.uitemplatedata.Text); + method @NonNull public android.app.smartspace.uitemplatedata.HeadToHeadTemplateData.Builder setHeadToHeadTitle(@Nullable android.app.smartspace.uitemplatedata.Text); + } + + public final class Icon implements android.os.Parcelable { method public int describeContents(); method @Nullable public CharSequence getContentDescription(); method @NonNull public android.graphics.drawable.Icon getIcon(); method public boolean shouldTint(); method public void writeToParcel(@NonNull android.os.Parcel, int); - field @NonNull public static final android.os.Parcelable.Creator CREATOR; + field @NonNull public static final android.os.Parcelable.Creator 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); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceIcon.Builder setShouldTint(boolean); + public static final class Icon.Builder { + ctor public Icon.Builder(@NonNull android.graphics.drawable.Icon); + method @NonNull public android.app.smartspace.uitemplatedata.Icon build(); + method @NonNull public android.app.smartspace.uitemplatedata.Icon.Builder setContentDescription(@NonNull CharSequence); + method @NonNull public android.app.smartspace.uitemplatedata.Icon.Builder setShouldTint(boolean); } - 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 android.app.smartspace.uitemplatedata.SmartspaceText getSubCardText(); - field @NonNull public static final android.os.Parcelable.Creator CREATOR; + public final class SubCardTemplateData extends android.app.smartspace.uitemplatedata.BaseTemplateData { + method @Nullable public android.app.smartspace.uitemplatedata.TapAction getSubCardAction(); + method @NonNull public android.app.smartspace.uitemplatedata.Icon getSubCardIcon(); + method @Nullable public android.app.smartspace.uitemplatedata.Text getSubCardText(); + field @NonNull public static final android.os.Parcelable.Creator 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 android.app.smartspace.uitemplatedata.SmartspaceTapAction); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubCardUiTemplateData.Builder setSubCardText(@NonNull android.app.smartspace.uitemplatedata.SmartspaceText); + public static final class SubCardTemplateData.Builder extends android.app.smartspace.uitemplatedata.BaseTemplateData.Builder { + ctor public SubCardTemplateData.Builder(@NonNull android.app.smartspace.uitemplatedata.Icon); + method @NonNull public android.app.smartspace.uitemplatedata.SubCardTemplateData build(); + method @NonNull public android.app.smartspace.uitemplatedata.SubCardTemplateData.Builder setSubCardAction(@NonNull android.app.smartspace.uitemplatedata.TapAction); + method @NonNull public android.app.smartspace.uitemplatedata.SubCardTemplateData.Builder setSubCardText(@NonNull android.app.smartspace.uitemplatedata.Text); } - 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 getSubImageTexts(); - method @NonNull public java.util.List getSubImages(); - field @NonNull public static final android.os.Parcelable.Creator CREATOR; + public final class SubImageTemplateData extends android.app.smartspace.uitemplatedata.BaseTemplateData { + method @Nullable public android.app.smartspace.uitemplatedata.TapAction getSubImageAction(); + method @NonNull public java.util.List getSubImageTexts(); + method @NonNull public java.util.List getSubImages(); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; } - public static final class SmartspaceSubImageUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder { - ctor public SmartspaceSubImageUiTemplateData.Builder(@NonNull java.util.List, @NonNull java.util.List); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubImageUiTemplateData build(); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubImageUiTemplateData.Builder setSubImageAction(@NonNull android.app.smartspace.uitemplatedata.SmartspaceTapAction); + public static final class SubImageTemplateData.Builder extends android.app.smartspace.uitemplatedata.BaseTemplateData.Builder { + ctor public SubImageTemplateData.Builder(@NonNull java.util.List, @NonNull java.util.List); + method @NonNull public android.app.smartspace.uitemplatedata.SubImageTemplateData build(); + method @NonNull public android.app.smartspace.uitemplatedata.SubImageTemplateData.Builder setSubImageAction(@NonNull android.app.smartspace.uitemplatedata.TapAction); } - 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 getSubListTexts(); - field @NonNull public static final android.os.Parcelable.Creator CREATOR; + public final class SubListTemplateData extends android.app.smartspace.uitemplatedata.BaseTemplateData { + method @Nullable public android.app.smartspace.uitemplatedata.TapAction getSubListAction(); + method @Nullable public android.app.smartspace.uitemplatedata.Icon getSubListIcon(); + method @NonNull public java.util.List getSubListTexts(); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; } - public static final class SmartspaceSubListUiTemplateData.Builder extends android.app.smartspace.uitemplatedata.SmartspaceDefaultUiTemplateData.Builder { - ctor public SmartspaceSubListUiTemplateData.Builder(@NonNull java.util.List); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubListUiTemplateData build(); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubListUiTemplateData.Builder setSubListAction(@NonNull android.app.smartspace.uitemplatedata.SmartspaceTapAction); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceSubListUiTemplateData.Builder setSubListIcon(@NonNull android.app.smartspace.uitemplatedata.SmartspaceIcon); + public static final class SubListTemplateData.Builder extends android.app.smartspace.uitemplatedata.BaseTemplateData.Builder { + ctor public SubListTemplateData.Builder(@NonNull java.util.List); + method @NonNull public android.app.smartspace.uitemplatedata.SubListTemplateData build(); + method @NonNull public android.app.smartspace.uitemplatedata.SubListTemplateData.Builder setSubListAction(@NonNull android.app.smartspace.uitemplatedata.TapAction); + method @NonNull public android.app.smartspace.uitemplatedata.SubListTemplateData.Builder setSubListIcon(@NonNull android.app.smartspace.uitemplatedata.Icon); } - public final class SmartspaceTapAction implements android.os.Parcelable { + public final class TapAction implements android.os.Parcelable { method public int describeContents(); method @Nullable public android.os.Bundle getExtras(); method @Nullable public CharSequence getId(); @@ -2082,31 +2082,33 @@ package android.app.smartspace.uitemplatedata { 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 CREATOR; + field @NonNull public static final android.os.Parcelable.Creator 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); + public static final class TapAction.Builder { + ctor public TapAction.Builder(@NonNull CharSequence); + method @NonNull public android.app.smartspace.uitemplatedata.TapAction build(); + method @NonNull public android.app.smartspace.uitemplatedata.TapAction.Builder setExtras(@NonNull android.os.Bundle); + method @NonNull public android.app.smartspace.uitemplatedata.TapAction.Builder setIntent(@NonNull android.content.Intent); + method @NonNull public android.app.smartspace.uitemplatedata.TapAction.Builder setPendingIntent(@NonNull android.app.PendingIntent); + method @NonNull public android.app.smartspace.uitemplatedata.TapAction.Builder setUserHandle(@Nullable android.os.UserHandle); } - public final class SmartspaceText implements android.os.Parcelable { + public final class Text implements android.os.Parcelable { method public int describeContents(); + method public int getMaxLines(); method @NonNull public CharSequence getText(); method @NonNull public android.text.TextUtils.TruncateAt getTruncateAtType(); method public void writeToParcel(@NonNull android.os.Parcel, int); - field @NonNull public static final android.os.Parcelable.Creator CREATOR; + field @NonNull public static final android.os.Parcelable.Creator CREATOR; } - public static final class SmartspaceText.Builder { - ctor public SmartspaceText.Builder(@NonNull CharSequence); - ctor public SmartspaceText.Builder(@NonNull CharSequence, @NonNull android.text.TextUtils.TruncateAt); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceText build(); - method @NonNull public android.app.smartspace.uitemplatedata.SmartspaceText.Builder setTruncateAtType(@NonNull android.text.TextUtils.TruncateAt); + public static final class Text.Builder { + ctor public Text.Builder(@NonNull CharSequence); + ctor public Text.Builder(@NonNull CharSequence, @NonNull android.text.TextUtils.TruncateAt); + method @NonNull public android.app.smartspace.uitemplatedata.Text build(); + method @NonNull public android.app.smartspace.uitemplatedata.Text.Builder setMaxLines(int); + method @NonNull public android.app.smartspace.uitemplatedata.Text.Builder setTruncateAtType(@NonNull android.text.TextUtils.TruncateAt); } } diff --git a/core/java/android/app/smartspace/SmartspaceTarget.java b/core/java/android/app/smartspace/SmartspaceTarget.java index 78f51be78828..fd7088f48aed 100644 --- a/core/java/android/app/smartspace/SmartspaceTarget.java +++ b/core/java/android/app/smartspace/SmartspaceTarget.java @@ -20,7 +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.app.smartspace.uitemplatedata.BaseTemplateData; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.net.Uri; @@ -133,7 +133,7 @@ public final class SmartspaceTarget implements Parcelable { private final AppWidgetProviderInfo mWidget; @Nullable - private final SmartspaceDefaultUiTemplateData mTemplateData; + private final BaseTemplateData mTemplateData; public static final int FEATURE_UNDEFINED = 0; public static final int FEATURE_WEATHER = 1; @@ -194,15 +194,25 @@ public final class SmartspaceTarget implements Parcelable { } public static final int UI_TEMPLATE_UNDEFINED = 0; + // Default template whose data is represented by {@link BaseTemplateData}. The default + // template is also a base card for the other types of templates. public static final int UI_TEMPLATE_DEFAULT = 1; + // Sub-image template whose data is represented by {@link SubImageTemplateData} public static final int UI_TEMPLATE_SUB_IMAGE = 2; + // Sub-list template whose data is represented by {@link SubListTemplateData} public static final int UI_TEMPLATE_SUB_LIST = 3; + // Carousel template whose data is represented by {@link CarouselTemplateData} public static final int UI_TEMPLATE_CAROUSEL = 4; + // Head-to-head template whose data is represented by {@link HeadToHeadTemplateData} public static final int UI_TEMPLATE_HEAD_TO_HEAD = 5; + // Combined-cards template whose data is represented by {@link CombinedCardsTemplateData} public static final int UI_TEMPLATE_COMBINED_CARDS = 6; + // Sub-card template whose data is represented by {@link SubCardTemplateData} public static final int UI_TEMPLATE_SUB_CARD = 7; /** + * The types of the Smartspace ui templates. + * * @hide */ @IntDef(prefix = {"UI_TEMPLATE_"}, value = { @@ -237,7 +247,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); + this.mTemplateData = in.readTypedObject(BaseTemplateData.CREATOR); } private SmartspaceTarget(String smartspaceTargetId, @@ -248,7 +258,7 @@ public final class SmartspaceTarget implements Parcelable { boolean shouldShowExpanded, String sourceNotificationKey, ComponentName componentName, UserHandle userHandle, String associatedSmartspaceTargetId, Uri sliceUri, - AppWidgetProviderInfo widget, SmartspaceDefaultUiTemplateData templateData) { + AppWidgetProviderInfo widget, BaseTemplateData templateData) { mSmartspaceTargetId = smartspaceTargetId; mHeaderAction = headerAction; mBaseAction = baseAction; @@ -406,7 +416,7 @@ public final class SmartspaceTarget implements Parcelable { * Returns the UI template data. */ @Nullable - public SmartspaceDefaultUiTemplateData getTemplateData() { + public BaseTemplateData getTemplateData() { return mTemplateData; } @@ -536,7 +546,7 @@ public final class SmartspaceTarget implements Parcelable { private String mAssociatedSmartspaceTargetId; private Uri mSliceUri; private AppWidgetProviderInfo mWidget; - private SmartspaceDefaultUiTemplateData mTemplateData; + private BaseTemplateData mTemplateData; /** * A builder for {@link SmartspaceTarget}. @@ -689,7 +699,7 @@ public final class SmartspaceTarget implements Parcelable { */ @NonNull public Builder setTemplateData( - @Nullable SmartspaceDefaultUiTemplateData templateData) { + @Nullable BaseTemplateData templateData) { mTemplateData = templateData; return this; } diff --git a/core/java/android/app/smartspace/SmartspaceUtils.java b/core/java/android/app/smartspace/SmartspaceUtils.java index 4545f43a8260..cad44537a007 100644 --- a/core/java/android/app/smartspace/SmartspaceUtils.java +++ b/core/java/android/app/smartspace/SmartspaceUtils.java @@ -17,7 +17,7 @@ package android.app.smartspace; import android.annotation.Nullable; -import android.app.smartspace.uitemplatedata.SmartspaceText; +import android.app.smartspace.uitemplatedata.Text; import android.text.TextUtils; /** @@ -30,13 +30,13 @@ public final class SmartspaceUtils { private SmartspaceUtils() { } - /** Returns true if the passed in {@link SmartspaceText} is null or its content is empty. */ - public static boolean isEmpty(@Nullable SmartspaceText text) { + /** Returns true if the passed in {@link Text} is null or its content is empty. */ + public static boolean isEmpty(@Nullable Text text) { return text == null || TextUtils.isEmpty(text.getText()); } - /** Returns true if the passed-in {@link SmartspaceText}s are equal. */ - public static boolean isEqual(@Nullable SmartspaceText text1, @Nullable SmartspaceText text2) { + /** Returns true if the passed-in {@link Text}s are equal. */ + public static boolean isEqual(@Nullable Text text1, @Nullable Text text2) { if (text1 == null && text2 == null) return true; if (text1 == null || text2 == null) return false; return text1.equals(text2); diff --git a/core/java/android/app/smartspace/uitemplatedata/BaseTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/BaseTemplateData.java new file mode 100644 index 000000000000..a07af689e06b --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/BaseTemplateData.java @@ -0,0 +1,476 @@ +/* + * 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 java.util.Objects; + +/** + * Holds all the relevant data needed to render a Smartspace card with the default Ui Template. + *
    + *
  • title_text (may contain a start drawable)
  • + *
  • subtitle_text (may contain a start drawable) . supplemental_subtitle_text (may + * contain a start drawable)
  • + *
  • next_alarm_text (contain a start drawable) + supplemental_alarm_text . + * do_not_disturb_view
  • + *
+ * + * @hide + */ +@SystemApi +@SuppressLint("ParcelNotFinal") +public class BaseTemplateData 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 Text mTitleText; + + @Nullable + private final Icon mTitleIcon; + + /** Subtitle text and icon are shown at the second row. */ + @Nullable + private final Text mSubtitleText; + + @Nullable + private final Icon 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 TapAction 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 Text mSupplementalSubtitleText; + + @Nullable + private final Icon mSupplementalSubtitleIcon; + + /** + * Tap action for the supplemental subtitle's text and icon. Will use the primary tap action if + * not being set. + */ + @Nullable + private final TapAction mSupplementalSubtitleTapAction; + + /** + * Supplemental alarm text is specifically used for holiday alarm, which is appended to "next + * alarm". + */ + @Nullable + private final Text mSupplementalAlarmText; + + BaseTemplateData(@NonNull Parcel in) { + mTemplateType = in.readInt(); + mTitleText = in.readTypedObject(Text.CREATOR); + mTitleIcon = in.readTypedObject(Icon.CREATOR); + mSubtitleText = in.readTypedObject(Text.CREATOR); + mSubtitleIcon = in.readTypedObject(Icon.CREATOR); + mPrimaryTapAction = in.readTypedObject(TapAction.CREATOR); + mSupplementalSubtitleText = in.readTypedObject(Text.CREATOR); + mSupplementalSubtitleIcon = in.readTypedObject(Icon.CREATOR); + mSupplementalSubtitleTapAction = in.readTypedObject(TapAction.CREATOR); + mSupplementalAlarmText = in.readTypedObject(Text.CREATOR); + } + + /** + * Should ONLY used by subclasses. For the general instance creation, please use + * SmartspaceDefaultUiTemplateData.Builder. + */ + BaseTemplateData(@UiTemplateType int templateType, + @Nullable Text titleText, + @Nullable Icon titleIcon, + @Nullable Text subtitleText, + @Nullable Icon subtitleIcon, + @Nullable TapAction primaryTapAction, + @Nullable Text supplementalSubtitleText, + @Nullable Icon supplementalSubtitleIcon, + @Nullable TapAction supplementalSubtitleTapAction, + @Nullable Text supplementalAlarmText) { + mTemplateType = templateType; + mTitleText = titleText; + mTitleIcon = titleIcon; + mSubtitleText = subtitleText; + mSubtitleIcon = subtitleIcon; + mPrimaryTapAction = primaryTapAction; + mSupplementalSubtitleText = supplementalSubtitleText; + mSupplementalSubtitleIcon = supplementalSubtitleIcon; + mSupplementalSubtitleTapAction = supplementalSubtitleTapAction; + mSupplementalAlarmText = supplementalAlarmText; + } + + /** Returns the template type. By default is UNDEFINED. */ + @UiTemplateType + public int getTemplateType() { + return mTemplateType; + } + + /** Returns the title's text. */ + @Nullable + public Text getTitleText() { + return mTitleText; + } + + /** Returns the title's icon. */ + @Nullable + public Icon getTitleIcon() { + return mTitleIcon; + } + + /** Returns the subtitle's text. */ + @Nullable + public Text getSubtitleText() { + return mSubtitleText; + } + + /** Returns the subtitle's icon. */ + @Nullable + public Icon getSubtitleIcon() { + return mSubtitleIcon; + } + + /** Returns the card's primary tap action. */ + @Nullable + public TapAction getPrimaryTapAction() { + return mPrimaryTapAction; + } + + /** Returns the supplemental subtitle's text. */ + @Nullable + public Text getSupplementalSubtitleText() { + return mSupplementalSubtitleText; + } + + /** Returns the supplemental subtitle's icon. */ + @Nullable + public Icon getSupplementalSubtitleIcon() { + return mSupplementalSubtitleIcon; + } + + /** Returns the supplemental subtitle's tap action. Can be null if not being set. */ + @Nullable + public TapAction getSupplementalSubtitleTapAction() { + return mSupplementalSubtitleTapAction; + } + + /** Returns the supplemental alarm text. */ + @Nullable + public Text getSupplementalAlarmText() { + return mSupplementalAlarmText; + } + + /** + * @see Parcelable.Creator + */ + @NonNull + public static final Creator CREATOR = + new Creator() { + @Override + public BaseTemplateData createFromParcel(Parcel in) { + return new BaseTemplateData(in); + } + + @Override + public BaseTemplateData[] newArray(int size) { + return new BaseTemplateData[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel out, int flags) { + out.writeInt(mTemplateType); + out.writeTypedObject(mTitleText, flags); + out.writeTypedObject(mTitleIcon, flags); + out.writeTypedObject(mSubtitleText, flags); + out.writeTypedObject(mSubtitleIcon, flags); + out.writeTypedObject(mPrimaryTapAction, flags); + out.writeTypedObject(mSupplementalSubtitleText, flags); + out.writeTypedObject(mSupplementalSubtitleIcon, flags); + out.writeTypedObject(mSupplementalSubtitleTapAction, flags); + out.writeTypedObject(mSupplementalAlarmText, flags); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof BaseTemplateData)) return false; + BaseTemplateData that = (BaseTemplateData) 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 BaseTemplateData} object. + * + * @hide + */ + @SystemApi + @SuppressLint("StaticFinalBuilder") + public static class Builder { + @UiTemplateType + private final int mTemplateType; + private Text mTitleText; + private Icon mTitleIcon; + private Text mSubtitleText; + private Icon mSubtitleIcon; + private TapAction mPrimaryTapAction; + private Text mSupplementalSubtitleText; + private Icon mSupplementalSubtitleIcon; + private TapAction mSupplementalSubtitleTapAction; + private Text mSupplementalAlarmText; + + /** + * A builder for {@link BaseTemplateData}. + * + * @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") + Text getTitleText() { + return mTitleText; + } + + /** Should ONLY be used by the subclasses */ + @Nullable + @SuppressLint("GetterOnBuilder") + Icon getTitleIcon() { + return mTitleIcon; + } + + /** Should ONLY be used by the subclasses */ + @Nullable + @SuppressLint("GetterOnBuilder") + Text getSubtitleText() { + return mSubtitleText; + } + + /** Should ONLY be used by the subclasses */ + @Nullable + @SuppressLint("GetterOnBuilder") + Icon getSubtitleIcon() { + return mSubtitleIcon; + } + + /** Should ONLY be used by the subclasses */ + @Nullable + @SuppressLint("GetterOnBuilder") + TapAction getPrimaryTapAction() { + return mPrimaryTapAction; + } + + /** Should ONLY be used by the subclasses */ + @Nullable + @SuppressLint("GetterOnBuilder") + Text getSupplementalSubtitleText() { + return mSupplementalSubtitleText; + } + + /** Should ONLY be used by the subclasses */ + @Nullable + @SuppressLint("GetterOnBuilder") + Icon getSupplementalSubtitleIcon() { + return mSupplementalSubtitleIcon; + } + + /** Should ONLY be used by the subclasses */ + @Nullable + @SuppressLint("GetterOnBuilder") + TapAction getSupplementalSubtitleTapAction() { + return mSupplementalSubtitleTapAction; + } + + /** Should ONLY be used by the subclasses */ + @Nullable + @SuppressLint("GetterOnBuilder") + Text getSupplementalAlarmText() { + return mSupplementalAlarmText; + } + + /** + * Sets the card title. + */ + @NonNull + public Builder setTitleText(@NonNull Text titleText) { + mTitleText = titleText; + return this; + } + + /** + * Sets the card title icon. + */ + @NonNull + public Builder setTitleIcon(@NonNull Icon titleIcon) { + mTitleIcon = titleIcon; + return this; + } + + /** + * Sets the card subtitle. + */ + @NonNull + public Builder setSubtitleText(@NonNull Text subtitleText) { + mSubtitleText = subtitleText; + return this; + } + + /** + * Sets the card subtitle icon. + */ + @NonNull + public Builder setSubtitleIcon(@NonNull Icon subtitleIcon) { + mSubtitleIcon = subtitleIcon; + return this; + } + + /** + * Sets the card primary tap action. + */ + @NonNull + public Builder setPrimaryTapAction(@NonNull TapAction primaryTapAction) { + mPrimaryTapAction = primaryTapAction; + return this; + } + + /** + * Sets the supplemental subtitle text. + */ + @NonNull + public Builder setSupplementalSubtitleText( + @NonNull Text supplementalSubtitleText) { + mSupplementalSubtitleText = supplementalSubtitleText; + return this; + } + + /** + * Sets the supplemental subtitle icon. + */ + @NonNull + public Builder setSupplementalSubtitleIcon( + @NonNull Icon 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 TapAction supplementalSubtitleTapAction) { + mSupplementalSubtitleTapAction = supplementalSubtitleTapAction; + return this; + } + + /** + * Sets the supplemental alarm text. + */ + @NonNull + public Builder setSupplementalAlarmText(@NonNull Text supplementalAlarmText) { + mSupplementalAlarmText = supplementalAlarmText; + return this; + } + + /** + * Builds a new SmartspaceDefaultUiTemplateData instance. + */ + @NonNull + public BaseTemplateData build() { + return new BaseTemplateData(mTemplateType, mTitleText, mTitleIcon, + mSubtitleText, mSubtitleIcon, mPrimaryTapAction, mSupplementalSubtitleText, + mSupplementalSubtitleIcon, mSupplementalSubtitleTapAction, + mSupplementalAlarmText); + } + } +} diff --git a/core/java/android/app/smartspace/uitemplatedata/CarouselTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/CarouselTemplateData.java new file mode 100644 index 000000000000..feb1c34337fb --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/CarouselTemplateData.java @@ -0,0 +1,376 @@ +/* + * 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 java.util.List; +import java.util.Objects; + +/** + * Holds all the relevant data needed to render a Smartspace card with the carousel Ui Template. + * + * This template will add a sub-card displaying a list of carousel items within the default-template + * card: + *
    + *
  • carouselItem1, carouselItem2, carouselItem3...
  • + *
+ * + * @hide + */ +@SystemApi +public final class CarouselTemplateData extends BaseTemplateData { + + /** Lists of {@link CarouselItem}. */ + @NonNull + private final List mCarouselItems; + + /** Tap action for the entire carousel secondary card, including the blank space */ + @Nullable + private final TapAction mCarouselAction; + + CarouselTemplateData(@NonNull Parcel in) { + super(in); + mCarouselItems = in.createTypedArrayList(CarouselItem.CREATOR); + mCarouselAction = in.readTypedObject(TapAction.CREATOR); + } + + private CarouselTemplateData(@SmartspaceTarget.UiTemplateType int templateType, + @Nullable Text titleText, + @Nullable Icon titleIcon, + @Nullable Text subtitleText, + @Nullable Icon subTitleIcon, + @Nullable TapAction primaryTapAction, + @Nullable Text supplementalSubtitleText, + @Nullable Icon supplementalSubtitleIcon, + @Nullable TapAction supplementalSubtitleTapAction, + @Nullable Text supplementalAlarmText, + @NonNull List carouselItems, + @Nullable TapAction carouselAction) { + super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction, + supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction, + supplementalAlarmText); + mCarouselItems = carouselItems; + mCarouselAction = carouselAction; + } + + /** Returns the list of {@link CarouselItem}. Can be empty if not being set. */ + @NonNull + public List getCarouselItems() { + return mCarouselItems; + } + + /** Returns the card's tap action. */ + @Nullable + public TapAction getCarouselAction() { + return mCarouselAction; + } + + /** + * @see Parcelable.Creator + */ + @NonNull + public static final Creator CREATOR = + new Creator() { + @Override + public CarouselTemplateData createFromParcel(Parcel in) { + return new CarouselTemplateData(in); + } + + @Override + public CarouselTemplateData[] newArray(int size) { + return new CarouselTemplateData[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 CarouselTemplateData)) return false; + if (!super.equals(o)) return false; + CarouselTemplateData that = (CarouselTemplateData) 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 CarouselTemplateData} object. + * + * @hide + */ + @SystemApi + public static final class Builder extends BaseTemplateData.Builder { + + private final List mCarouselItems; + private TapAction mCarouselAction; + + /** + * A builder for {@link CarouselTemplateData}. + */ + public Builder(@NonNull List carouselItems) { + super(SmartspaceTarget.UI_TEMPLATE_CAROUSEL); + mCarouselItems = Objects.requireNonNull(carouselItems); + } + + /** + * Sets the card tap action. + */ + @NonNull + public Builder setCarouselAction(@NonNull TapAction carouselAction) { + mCarouselAction = carouselAction; + return this; + } + + /** + * Builds a new {@link CarouselTemplateData} instance. + * + * @throws IllegalStateException if the carousel data is invalid. + */ + @NonNull + public CarouselTemplateData build() { + if (mCarouselItems.isEmpty()) { + throw new IllegalStateException("Carousel data is empty"); + } + + return new CarouselTemplateData(getTemplateType(), getTitleText(), + getTitleIcon(), getSubtitleText(), getSubtitleIcon(), getPrimaryTapAction(), + getSupplementalSubtitleText(), getSupplementalSubtitleIcon(), + getSupplementalSubtitleTapAction(), getSupplementalAlarmText(), mCarouselItems, + mCarouselAction); + } + } + + /** + * Holds all the relevant data needed to render a carousel item. + * + *
    + *
  • upper text
  • + *
  • image
  • + *
  • lower text
  • + *
+ */ + public static final class CarouselItem implements Parcelable { + + /** Text which is above the image item. */ + @Nullable + private final Text mUpperText; + + /** Image item. Can be empty. */ + @Nullable + private final Icon mImage; + + /** Text which is under the image item. */ + @Nullable + private final Text mLowerText; + + /** + * Tap action for this {@link CarouselItem} instance. {@code mCarouselAction} is used if not + * being set. + */ + @Nullable + private final TapAction mTapAction; + + CarouselItem(@NonNull Parcel in) { + mUpperText = in.readTypedObject(Text.CREATOR); + mImage = in.readTypedObject(Icon.CREATOR); + mLowerText = in.readTypedObject(Text.CREATOR); + mTapAction = in.readTypedObject(TapAction.CREATOR); + } + + private CarouselItem(@Nullable Text upperText, @Nullable Icon image, + @Nullable Text lowerText, @Nullable TapAction tapAction) { + mUpperText = upperText; + mImage = image; + mLowerText = lowerText; + mTapAction = tapAction; + } + + @Nullable + public Text getUpperText() { + return mUpperText; + } + + @Nullable + public Icon getImage() { + return mImage; + } + + @Nullable + public Text getLowerText() { + return mLowerText; + } + + @Nullable + public TapAction getTapAction() { + return mTapAction; + } + + /** + * @see Parcelable.Creator + */ + @NonNull + public static final Creator CREATOR = + new Creator() { + @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) { + out.writeTypedObject(mUpperText, flags); + out.writeTypedObject(mImage, flags); + out.writeTypedObject(mLowerText, 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 Text mUpperText; + private Icon mImage; + private Text mLowerText; + private TapAction mTapAction; + + /** + * Sets the upper text. + */ + @NonNull + public Builder setUpperText(@Nullable Text upperText) { + mUpperText = upperText; + return this; + } + + /** + * Sets the image. + */ + @NonNull + public Builder setImage(@Nullable Icon image) { + mImage = image; + return this; + } + + + /** + * Sets the lower text. + */ + @NonNull + public Builder setLowerText(@Nullable Text lowerText) { + mLowerText = lowerText; + return this; + } + + /** + * Sets the tap action. + */ + @NonNull + public Builder setTapAction(@Nullable TapAction tapAction) { + mTapAction = tapAction; + return this; + } + + /** + * Builds a new CarouselItem instance. + * + * @throws IllegalStateException if all the rendering data is empty. + */ + @NonNull + public CarouselItem build() { + if (SmartspaceUtils.isEmpty(mUpperText) && mImage == null + && SmartspaceUtils.isEmpty( + mLowerText)) { + throw new IllegalStateException("Carousel data is empty"); + } + return new CarouselItem(mUpperText, mImage, mLowerText, mTapAction); + } + } + } +} diff --git a/core/java/android/app/smartspace/uitemplatedata/CombinedCardsTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/CombinedCardsTemplateData.java new file mode 100644 index 000000000000..13091e2c530d --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/CombinedCardsTemplateData.java @@ -0,0 +1,160 @@ +/* + * 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 adding a 1 sub-list card combined with 1 sub-card card (may expand our supported + * combinations in the future) within the default-template card: + * + *
    + *
  • sub-list card, sub-card card
  • + *
+ * + * @hide + */ +@SystemApi +public final class CombinedCardsTemplateData extends BaseTemplateData { + + /** A list of secondary cards. */ + @NonNull + private final List mCombinedCardDataList; + + CombinedCardsTemplateData(@NonNull Parcel in) { + super(in); + mCombinedCardDataList = in.createTypedArrayList(BaseTemplateData.CREATOR); + } + + private CombinedCardsTemplateData(@SmartspaceTarget.UiTemplateType int templateType, + @Nullable Text titleText, + @Nullable Icon titleIcon, + @Nullable Text subtitleText, + @Nullable Icon subTitleIcon, + @Nullable TapAction primaryTapAction, + @Nullable Text supplementalSubtitleText, + @Nullable Icon supplementalSubtitleIcon, + @Nullable TapAction supplementalSubtitleTapAction, + @Nullable Text supplementalAlarmText, + @NonNull List combinedCardDataList) { + super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction, + supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction, + supplementalAlarmText); + mCombinedCardDataList = combinedCardDataList; + } + + /** Returns the list of secondary cards. Can be null if not being set. */ + @NonNull + public List getCombinedCardDataList() { + return mCombinedCardDataList; + } + + /** + * @see Parcelable.Creator + */ + @NonNull + public static final Creator CREATOR = + new Creator() { + @Override + public CombinedCardsTemplateData createFromParcel(Parcel in) { + return new CombinedCardsTemplateData(in); + } + + @Override + public CombinedCardsTemplateData[] newArray(int size) { + return new CombinedCardsTemplateData[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 CombinedCardsTemplateData)) return false; + if (!super.equals(o)) return false; + CombinedCardsTemplateData that = (CombinedCardsTemplateData) 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 CombinedCardsTemplateData} object. + * + * @hide + */ + @SystemApi + public static final class Builder extends BaseTemplateData.Builder { + + private final List mCombinedCardDataList; + + /** + * A builder for {@link CombinedCardsTemplateData}. + */ + public Builder(@NonNull List 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 CombinedCardsTemplateData build() { + if (mCombinedCardDataList == null) { + throw new IllegalStateException("Please assign a value to all @NonNull args."); + } + return new CombinedCardsTemplateData(getTemplateType(), getTitleText(), + getTitleIcon(), getSubtitleText(), getSubtitleIcon(), getPrimaryTapAction(), + getSupplementalSubtitleText(), getSupplementalSubtitleIcon(), + getSupplementalSubtitleTapAction(), getSupplementalAlarmText(), + mCombinedCardDataList); + } + } +} diff --git a/core/java/android/app/smartspace/uitemplatedata/HeadToHeadTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/HeadToHeadTemplateData.java new file mode 100644 index 000000000000..eb56e93e6c1b --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/HeadToHeadTemplateData.java @@ -0,0 +1,298 @@ +/* + * 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 java.util.Objects; + +/** + * Holds all the relevant data needed to render a Smartspace card with the head-to-head Ui Template. + * + * This template will add a head-to-head card within the default-template card: + *
    + *
  • head-to-head title
  • + *
  • first-competitor icon second-competitor icon
  • + *
  • first-competitor text second-competitor text
  • + *
+ * + * @hide + */ +@SystemApi +public final class HeadToHeadTemplateData extends BaseTemplateData { + + @Nullable + private final Text mHeadToHeadTitle; + @Nullable + private final Icon mHeadToHeadFirstCompetitorIcon; + @Nullable + private final Icon mHeadToHeadSecondCompetitorIcon; + @Nullable + private final Text mHeadToHeadFirstCompetitorText; + @Nullable + private final Text mHeadToHeadSecondCompetitorText; + + /** Tap action for the head-to-head secondary card. */ + @Nullable + private final TapAction mHeadToHeadAction; + + HeadToHeadTemplateData(@NonNull Parcel in) { + super(in); + mHeadToHeadTitle = in.readTypedObject(Text.CREATOR); + mHeadToHeadFirstCompetitorIcon = in.readTypedObject(Icon.CREATOR); + mHeadToHeadSecondCompetitorIcon = in.readTypedObject(Icon.CREATOR); + mHeadToHeadFirstCompetitorText = in.readTypedObject(Text.CREATOR); + mHeadToHeadSecondCompetitorText = in.readTypedObject(Text.CREATOR); + mHeadToHeadAction = in.readTypedObject(TapAction.CREATOR); + } + + private HeadToHeadTemplateData(@SmartspaceTarget.UiTemplateType int templateType, + @Nullable Text titleText, + @Nullable Icon titleIcon, + @Nullable Text subtitleText, + @Nullable Icon subTitleIcon, + @Nullable TapAction primaryTapAction, + @Nullable Text supplementalSubtitleText, + @Nullable Icon supplementalSubtitleIcon, + @Nullable TapAction supplementalSubtitleTapAction, + @Nullable Text supplementalAlarmText, + @Nullable Text headToHeadTitle, + @Nullable Icon headToHeadFirstCompetitorIcon, + @Nullable Icon headToHeadSecondCompetitorIcon, + @Nullable Text headToHeadFirstCompetitorText, + @Nullable Text headToHeadSecondCompetitorText, + @Nullable TapAction headToHeadAction) { + super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction, + supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction, + supplementalAlarmText); + mHeadToHeadTitle = headToHeadTitle; + mHeadToHeadFirstCompetitorIcon = headToHeadFirstCompetitorIcon; + mHeadToHeadSecondCompetitorIcon = headToHeadSecondCompetitorIcon; + mHeadToHeadFirstCompetitorText = headToHeadFirstCompetitorText; + mHeadToHeadSecondCompetitorText = headToHeadSecondCompetitorText; + mHeadToHeadAction = headToHeadAction; + } + + /** Returns the head-to-head card's title. */ + @Nullable + public Text getHeadToHeadTitle() { + return mHeadToHeadTitle; + } + + /** Returns the first competitor's icon. */ + @Nullable + public Icon getHeadToHeadFirstCompetitorIcon() { + return mHeadToHeadFirstCompetitorIcon; + } + + /** Returns the second competitor's icon. */ + @Nullable + public Icon getHeadToHeadSecondCompetitorIcon() { + return mHeadToHeadSecondCompetitorIcon; + } + + /** Returns the first competitor's text. */ + @Nullable + public Text getHeadToHeadFirstCompetitorText() { + return mHeadToHeadFirstCompetitorText; + } + + /** Returns the second competitor's text. */ + @Nullable + public Text getHeadToHeadSecondCompetitorText() { + return mHeadToHeadSecondCompetitorText; + } + + /** Returns the head-to-head card's tap action. */ + @Nullable + public TapAction getHeadToHeadAction() { + return mHeadToHeadAction; + } + + /** + * @see Parcelable.Creator + */ + @NonNull + public static final Creator CREATOR = + new Creator() { + @Override + public HeadToHeadTemplateData createFromParcel(Parcel in) { + return new HeadToHeadTemplateData(in); + } + + @Override + public HeadToHeadTemplateData[] newArray(int size) { + return new HeadToHeadTemplateData[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel out, int flags) { + super.writeToParcel(out, flags); + out.writeTypedObject(mHeadToHeadTitle, flags); + out.writeTypedObject(mHeadToHeadFirstCompetitorIcon, flags); + out.writeTypedObject(mHeadToHeadSecondCompetitorIcon, flags); + out.writeTypedObject(mHeadToHeadFirstCompetitorText, flags); + out.writeTypedObject(mHeadToHeadSecondCompetitorText, flags); + out.writeTypedObject(mHeadToHeadAction, flags); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof HeadToHeadTemplateData)) return false; + if (!super.equals(o)) return false; + HeadToHeadTemplateData that = (HeadToHeadTemplateData) 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 HeadToHeadTemplateData} object. + * + * @hide + */ + @SystemApi + public static final class Builder extends BaseTemplateData.Builder { + + private Text mHeadToHeadTitle; + private Icon mHeadToHeadFirstCompetitorIcon; + private Icon mHeadToHeadSecondCompetitorIcon; + private Text mHeadToHeadFirstCompetitorText; + private Text mHeadToHeadSecondCompetitorText; + private TapAction mHeadToHeadAction; + + /** + * A builder for {@link HeadToHeadTemplateData}. + */ + public Builder() { + super(SmartspaceTarget.UI_TEMPLATE_HEAD_TO_HEAD); + } + + /** + * Sets the head-to-head card's title + */ + @NonNull + public Builder setHeadToHeadTitle(@Nullable Text headToHeadTitle) { + mHeadToHeadTitle = headToHeadTitle; + return this; + } + + /** + * Sets the head-to-head card's first competitor icon + */ + @NonNull + public Builder setHeadToHeadFirstCompetitorIcon( + @Nullable Icon headToHeadFirstCompetitorIcon) { + mHeadToHeadFirstCompetitorIcon = headToHeadFirstCompetitorIcon; + return this; + } + + /** + * Sets the head-to-head card's second competitor icon + */ + @NonNull + public Builder setHeadToHeadSecondCompetitorIcon( + @Nullable Icon headToHeadSecondCompetitorIcon) { + mHeadToHeadSecondCompetitorIcon = headToHeadSecondCompetitorIcon; + return this; + } + + /** + * Sets the head-to-head card's first competitor text + */ + @NonNull + public Builder setHeadToHeadFirstCompetitorText( + @Nullable Text headToHeadFirstCompetitorText) { + mHeadToHeadFirstCompetitorText = headToHeadFirstCompetitorText; + return this; + } + + /** + * Sets the head-to-head card's second competitor text + */ + @NonNull + public Builder setHeadToHeadSecondCompetitorText( + @Nullable Text headToHeadSecondCompetitorText) { + mHeadToHeadSecondCompetitorText = headToHeadSecondCompetitorText; + return this; + } + + /** + * Sets the head-to-head card's tap action + */ + @NonNull + public Builder setHeadToHeadAction(@Nullable TapAction headToHeadAction) { + mHeadToHeadAction = headToHeadAction; + return this; + } + + /** + * Builds a new SmartspaceHeadToHeadUiTemplateData instance. + */ + @NonNull + public HeadToHeadTemplateData build() { + return new HeadToHeadTemplateData(getTemplateType(), getTitleText(), + getTitleIcon(), getSubtitleText(), getSubtitleIcon(), getPrimaryTapAction(), + getSupplementalSubtitleText(), getSupplementalSubtitleIcon(), + getSupplementalSubtitleTapAction(), getSupplementalAlarmText(), + mHeadToHeadTitle, + mHeadToHeadFirstCompetitorIcon, + mHeadToHeadSecondCompetitorIcon, mHeadToHeadFirstCompetitorText, + mHeadToHeadSecondCompetitorText, + mHeadToHeadAction); + } + } +} diff --git a/core/java/android/app/smartspace/uitemplatedata/Icon.java b/core/java/android/app/smartspace/uitemplatedata/Icon.java new file mode 100644 index 000000000000..2b1f420f0d1d --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/Icon.java @@ -0,0 +1,174 @@ +/* + * 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.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 Icon implements Parcelable { + + @NonNull + private final android.graphics.drawable.Icon mIcon; + + @Nullable + private final CharSequence mContentDescription; + + private final boolean mShouldTint; + + Icon(@NonNull Parcel in) { + mIcon = in.readTypedObject(android.graphics.drawable.Icon.CREATOR); + mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); + mShouldTint = in.readBoolean(); + } + + private Icon(@NonNull android.graphics.drawable.Icon icon, + @Nullable CharSequence contentDescription, + boolean shouldTint) { + mIcon = icon; + mContentDescription = contentDescription; + mShouldTint = shouldTint; + } + + /** Returns the icon image. */ + @NonNull + public android.graphics.drawable.Icon getIcon() { + return mIcon; + } + + /** Returns the content description of the icon image. */ + @Nullable + public CharSequence getContentDescription() { + return mContentDescription; + } + + /** Return shouldTint value. The default value is true. */ + public boolean shouldTint() { + return mShouldTint; + } + + @NonNull + public static final Creator CREATOR = new Creator() { + @Override + public Icon createFromParcel(Parcel in) { + return new Icon(in); + } + + @Override + public Icon[] newArray(int size) { + return new Icon[size]; + } + }; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Icon)) return false; + Icon that = (Icon) o; + return mIcon.toString().equals(that.mIcon.toString()) && SmartspaceUtils.isEqual( + mContentDescription, + that.mContentDescription) && mShouldTint == that.mShouldTint; + } + + @Override + public int hashCode() { + return Objects.hash(mIcon.toString(), mContentDescription, mShouldTint); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel out, int flags) { + out.writeTypedObject(mIcon, flags); + TextUtils.writeToParcel(mContentDescription, out, flags); + out.writeBoolean(mShouldTint); + } + + @Override + public String toString() { + return "SmartspaceIcon{" + + "mIcon=" + mIcon + + ", mContentDescription=" + mContentDescription + + ", mShouldTint=" + mShouldTint + + '}'; + } + + /** + * A builder for {@link Icon} object. + * + * @hide + */ + @SystemApi + public static final class Builder { + + private android.graphics.drawable.Icon mIcon; + private CharSequence mContentDescription; + private boolean mShouldTint; + + /** + * A builder for {@link Icon}, which sets shouldTint to true by default. + * + * @param icon the icon image of this {@link Icon} instance. + */ + public Builder(@NonNull android.graphics.drawable.Icon icon) { + mIcon = Objects.requireNonNull(icon); + mShouldTint = true; + } + + /** + * Sets the icon's content description. + */ + @NonNull + public Builder setContentDescription(@NonNull CharSequence contentDescription) { + mContentDescription = contentDescription; + return this; + } + + /** + * Sets should tint icon. + */ + @NonNull + public Builder setShouldTint(boolean shouldTint) { + mShouldTint = shouldTint; + return this; + } + + /** + * Builds a new SmartspaceIcon instance. + */ + @NonNull + public Icon build() { + return new Icon(mIcon, mContentDescription, mShouldTint); + } + } +} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceCarouselUiTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceCarouselUiTemplateData.java deleted file mode 100644 index e996056291bc..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceCarouselUiTemplateData.java +++ /dev/null @@ -1,360 +0,0 @@ -/* - * 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 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 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 SmartspaceText titleText, - @Nullable SmartspaceIcon titleIcon, - @Nullable SmartspaceText subtitleText, - @Nullable SmartspaceIcon subTitleIcon, - @Nullable SmartspaceTapAction primaryTapAction, - @Nullable SmartspaceText supplementalSubtitleText, - @Nullable SmartspaceIcon supplementalSubtitleIcon, - @Nullable SmartspaceTapAction supplementalSubtitleTapAction, - @Nullable SmartspaceText supplementalAlarmText, - @NonNull List carouselItems, - @Nullable SmartspaceTapAction carouselAction) { - super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction, - supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction, - supplementalAlarmText); - mCarouselItems = carouselItems; - mCarouselAction = carouselAction; - } - - @NonNull - public List getCarouselItems() { - return mCarouselItems; - } - - @Nullable - public SmartspaceTapAction getCarouselAction() { - return mCarouselAction; - } - - /** - * @see Parcelable.Creator - */ - @NonNull - public static final Creator CREATOR = - new Creator() { - @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 mCarouselItems; - private SmartspaceTapAction mCarouselAction; - - /** - * A builder for {@link SmartspaceCarouselUiTemplateData}. - */ - public Builder(@NonNull List 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 SmartspaceText mUpperText; - - /** Image item. Can be empty. */ - @Nullable - private final SmartspaceIcon mImage; - - /** Text which is under the image item. */ - @Nullable - private final SmartspaceText 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 = in.readTypedObject(SmartspaceText.CREATOR); - mImage = in.readTypedObject(SmartspaceIcon.CREATOR); - mLowerText = in.readTypedObject(SmartspaceText.CREATOR); - mTapAction = in.readTypedObject(SmartspaceTapAction.CREATOR); - } - - private CarouselItem(@Nullable SmartspaceText upperText, @Nullable SmartspaceIcon image, - @Nullable SmartspaceText lowerText, @Nullable SmartspaceTapAction tapAction) { - mUpperText = upperText; - mImage = image; - mLowerText = lowerText; - mTapAction = tapAction; - } - - @Nullable - public SmartspaceText getUpperText() { - return mUpperText; - } - - @Nullable - public SmartspaceIcon getImage() { - return mImage; - } - - @Nullable - public SmartspaceText getLowerText() { - return mLowerText; - } - - @Nullable - public SmartspaceTapAction getTapAction() { - return mTapAction; - } - - /** - * @see Parcelable.Creator - */ - @NonNull - public static final Creator CREATOR = - new Creator() { - @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) { - out.writeTypedObject(mUpperText, flags); - out.writeTypedObject(mImage, flags); - out.writeTypedObject(mLowerText, 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 SmartspaceText mUpperText; - private SmartspaceIcon mImage; - private SmartspaceText mLowerText; - private SmartspaceTapAction mTapAction; - - /** - * Sets the upper text. - */ - @NonNull - public Builder setUpperText(@Nullable SmartspaceText 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 SmartspaceText 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 (SmartspaceUtils.isEmpty(mUpperText) && mImage == null - && SmartspaceUtils.isEmpty( - mLowerText)) { - throw new IllegalStateException("Carousel data is empty"); - } - return new CarouselItem(mUpperText, mImage, mLowerText, mTapAction); - } - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceCombinedCardsUiTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceCombinedCardsUiTemplateData.java deleted file mode 100644 index 9d4c8e23242c..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceCombinedCardsUiTemplateData.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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 mCombinedCardDataList; - - SmartspaceCombinedCardsUiTemplateData(@NonNull Parcel in) { - super(in); - mCombinedCardDataList = in.createTypedArrayList(SmartspaceDefaultUiTemplateData.CREATOR); - } - - private SmartspaceCombinedCardsUiTemplateData(@SmartspaceTarget.UiTemplateType int templateType, - @Nullable SmartspaceText titleText, - @Nullable SmartspaceIcon titleIcon, - @Nullable SmartspaceText subtitleText, - @Nullable SmartspaceIcon subTitleIcon, - @Nullable SmartspaceTapAction primaryTapAction, - @Nullable SmartspaceText supplementalSubtitleText, - @Nullable SmartspaceIcon supplementalSubtitleIcon, - @Nullable SmartspaceTapAction supplementalSubtitleTapAction, - @Nullable SmartspaceText supplementalAlarmText, - @NonNull List combinedCardDataList) { - super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction, - supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction, - supplementalAlarmText); - mCombinedCardDataList = combinedCardDataList; - } - - @NonNull - public List getCombinedCardDataList() { - return mCombinedCardDataList; - } - - /** - * @see Parcelable.Creator - */ - @NonNull - public static final Creator CREATOR = - new Creator() { - @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 mCombinedCardDataList; - - /** - * A builder for {@link SmartspaceCombinedCardsUiTemplateData}. - */ - public Builder(@NonNull List 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); - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceDefaultUiTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceDefaultUiTemplateData.java deleted file mode 100644 index a7ac9c7ed4bf..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceDefaultUiTemplateData.java +++ /dev/null @@ -1,459 +0,0 @@ -/* - * 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 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 SmartspaceText mTitleText; - - @Nullable - private final SmartspaceIcon mTitleIcon; - - /** Subtitle text and icon are shown at the second row. */ - @Nullable - private final SmartspaceText 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 SmartspaceText 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 SmartspaceText mSupplementalAlarmText; - - SmartspaceDefaultUiTemplateData(@NonNull Parcel in) { - mTemplateType = in.readInt(); - mTitleText = in.readTypedObject(SmartspaceText.CREATOR); - mTitleIcon = in.readTypedObject(SmartspaceIcon.CREATOR); - mSubtitleText = in.readTypedObject(SmartspaceText.CREATOR); - mSubtitleIcon = in.readTypedObject(SmartspaceIcon.CREATOR); - mPrimaryTapAction = in.readTypedObject(SmartspaceTapAction.CREATOR); - mSupplementalSubtitleText = in.readTypedObject(SmartspaceText.CREATOR); - mSupplementalSubtitleIcon = in.readTypedObject(SmartspaceIcon.CREATOR); - mSupplementalSubtitleTapAction = in.readTypedObject(SmartspaceTapAction.CREATOR); - mSupplementalAlarmText = in.readTypedObject(SmartspaceText.CREATOR); - } - - /** - * Should ONLY used by subclasses. For the general instance creation, please use - * SmartspaceDefaultUiTemplateData.Builder. - */ - SmartspaceDefaultUiTemplateData(@UiTemplateType int templateType, - @Nullable SmartspaceText titleText, - @Nullable SmartspaceIcon titleIcon, - @Nullable SmartspaceText subtitleText, - @Nullable SmartspaceIcon subtitleIcon, - @Nullable SmartspaceTapAction primaryTapAction, - @Nullable SmartspaceText supplementalSubtitleText, - @Nullable SmartspaceIcon supplementalSubtitleIcon, - @Nullable SmartspaceTapAction supplementalSubtitleTapAction, - @Nullable SmartspaceText 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 SmartspaceText getTitleText() { - return mTitleText; - } - - @Nullable - public SmartspaceIcon getTitleIcon() { - return mTitleIcon; - } - - @Nullable - public SmartspaceText getSubtitleText() { - return mSubtitleText; - } - - @Nullable - public SmartspaceIcon getSubtitleIcon() { - return mSubtitleIcon; - } - - @Nullable - public SmartspaceTapAction getPrimaryTapAction() { - return mPrimaryTapAction; - } - - @Nullable - public SmartspaceText getSupplementalSubtitleText() { - return mSupplementalSubtitleText; - } - - @Nullable - public SmartspaceIcon getSupplementalSubtitleIcon() { - return mSupplementalSubtitleIcon; - } - - @Nullable - public SmartspaceTapAction getSupplementalSubtitleTapAction() { - return mSupplementalSubtitleTapAction; - } - - @Nullable - public SmartspaceText getSupplementalAlarmText() { - return mSupplementalAlarmText; - } - - /** - * @see Parcelable.Creator - */ - @NonNull - public static final Creator CREATOR = - new Creator() { - @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); - out.writeTypedObject(mTitleText, flags); - out.writeTypedObject(mTitleIcon, flags); - out.writeTypedObject(mSubtitleText, flags); - out.writeTypedObject(mSubtitleIcon, flags); - out.writeTypedObject(mPrimaryTapAction, flags); - out.writeTypedObject(mSupplementalSubtitleText, flags); - out.writeTypedObject(mSupplementalSubtitleIcon, flags); - out.writeTypedObject(mSupplementalSubtitleTapAction, flags); - out.writeTypedObject(mSupplementalAlarmText, 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 SmartspaceText mTitleText; - private SmartspaceIcon mTitleIcon; - private SmartspaceText mSubtitleText; - private SmartspaceIcon mSubtitleIcon; - private SmartspaceTapAction mPrimaryTapAction; - private SmartspaceText mSupplementalSubtitleText; - private SmartspaceIcon mSupplementalSubtitleIcon; - private SmartspaceTapAction mSupplementalSubtitleTapAction; - private SmartspaceText 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") - SmartspaceText 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") - SmartspaceText 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") - SmartspaceText 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") - SmartspaceText getSupplementalAlarmText() { - return mSupplementalAlarmText; - } - - /** - * Sets the card title. - */ - @NonNull - public Builder setTitleText(@NonNull SmartspaceText 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 SmartspaceText 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 SmartspaceText 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 SmartspaceText 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); - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceHeadToHeadUiTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceHeadToHeadUiTemplateData.java deleted file mode 100644 index bcd12eb0f527..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceHeadToHeadUiTemplateData.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * 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 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 SmartspaceText mHeadToHeadTitle; - @Nullable - private final SmartspaceIcon mHeadToHeadFirstCompetitorIcon; - @Nullable - private final SmartspaceIcon mHeadToHeadSecondCompetitorIcon; - @Nullable - private final SmartspaceText mHeadToHeadFirstCompetitorText; - @Nullable - private final SmartspaceText mHeadToHeadSecondCompetitorText; - - /** Tap action for the head-to-head secondary card. */ - @Nullable - private final SmartspaceTapAction mHeadToHeadAction; - - SmartspaceHeadToHeadUiTemplateData(@NonNull Parcel in) { - super(in); - mHeadToHeadTitle = in.readTypedObject(SmartspaceText.CREATOR); - mHeadToHeadFirstCompetitorIcon = in.readTypedObject(SmartspaceIcon.CREATOR); - mHeadToHeadSecondCompetitorIcon = in.readTypedObject(SmartspaceIcon.CREATOR); - mHeadToHeadFirstCompetitorText = in.readTypedObject(SmartspaceText.CREATOR); - mHeadToHeadSecondCompetitorText = in.readTypedObject(SmartspaceText.CREATOR); - mHeadToHeadAction = in.readTypedObject(SmartspaceTapAction.CREATOR); - } - - private SmartspaceHeadToHeadUiTemplateData(@SmartspaceTarget.UiTemplateType int templateType, - @Nullable SmartspaceText titleText, - @Nullable SmartspaceIcon titleIcon, - @Nullable SmartspaceText subtitleText, - @Nullable SmartspaceIcon subTitleIcon, - @Nullable SmartspaceTapAction primaryTapAction, - @Nullable SmartspaceText supplementalSubtitleText, - @Nullable SmartspaceIcon supplementalSubtitleIcon, - @Nullable SmartspaceTapAction supplementalSubtitleTapAction, - @Nullable SmartspaceText supplementalAlarmText, - @Nullable SmartspaceText headToHeadTitle, - @Nullable SmartspaceIcon headToHeadFirstCompetitorIcon, - @Nullable SmartspaceIcon headToHeadSecondCompetitorIcon, - @Nullable SmartspaceText headToHeadFirstCompetitorText, - @Nullable SmartspaceText 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 SmartspaceText getHeadToHeadTitle() { - return mHeadToHeadTitle; - } - - @Nullable - public SmartspaceIcon getHeadToHeadFirstCompetitorIcon() { - return mHeadToHeadFirstCompetitorIcon; - } - - @Nullable - public SmartspaceIcon getHeadToHeadSecondCompetitorIcon() { - return mHeadToHeadSecondCompetitorIcon; - } - - @Nullable - public SmartspaceText getHeadToHeadFirstCompetitorText() { - return mHeadToHeadFirstCompetitorText; - } - - @Nullable - public SmartspaceText getHeadToHeadSecondCompetitorText() { - return mHeadToHeadSecondCompetitorText; - } - - @Nullable - public SmartspaceTapAction getHeadToHeadAction() { - return mHeadToHeadAction; - } - - /** - * @see Parcelable.Creator - */ - @NonNull - public static final Creator CREATOR = - new Creator() { - @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); - out.writeTypedObject(mHeadToHeadTitle, flags); - out.writeTypedObject(mHeadToHeadFirstCompetitorIcon, flags); - out.writeTypedObject(mHeadToHeadSecondCompetitorIcon, flags); - out.writeTypedObject(mHeadToHeadFirstCompetitorText, flags); - out.writeTypedObject(mHeadToHeadSecondCompetitorText, 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 SmartspaceText mHeadToHeadTitle; - private SmartspaceIcon mHeadToHeadFirstCompetitorIcon; - private SmartspaceIcon mHeadToHeadSecondCompetitorIcon; - private SmartspaceText mHeadToHeadFirstCompetitorText; - private SmartspaceText 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 SmartspaceText 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 SmartspaceText headToHeadFirstCompetitorText) { - mHeadToHeadFirstCompetitorText = headToHeadFirstCompetitorText; - return this; - } - - /** - * Sets the head-to-head card's second competitor text - */ - @NonNull - public Builder setHeadToHeadSecondCompetitorText( - @Nullable SmartspaceText 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); - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceIcon.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceIcon.java deleted file mode 100644 index 1efbaeb8bd3c..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceIcon.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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; - - private final boolean mShouldTint; - - SmartspaceIcon(@NonNull Parcel in) { - mIcon = in.readTypedObject(Icon.CREATOR); - mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - mShouldTint = in.readBoolean(); - } - - private SmartspaceIcon(@NonNull Icon icon, @Nullable CharSequence contentDescription, - boolean shouldTint) { - mIcon = icon; - mContentDescription = contentDescription; - mShouldTint = shouldTint; - } - - @NonNull - public Icon getIcon() { - return mIcon; - } - - @Nullable - public CharSequence getContentDescription() { - return mContentDescription; - } - - /** Return shouldTint value. The default value is true. */ - public boolean shouldTint() { - return mShouldTint; - } - - @NonNull - public static final Creator CREATOR = new Creator() { - @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.toString().equals(that.mIcon.toString()) && SmartspaceUtils.isEqual( - mContentDescription, - that.mContentDescription) && mShouldTint == that.mShouldTint; - } - - @Override - public int hashCode() { - return Objects.hash(mIcon.toString(), mContentDescription, mShouldTint); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(@NonNull Parcel out, int flags) { - out.writeTypedObject(mIcon, flags); - TextUtils.writeToParcel(mContentDescription, out, flags); - out.writeBoolean(mShouldTint); - } - - @Override - public String toString() { - return "SmartspaceIcon{" - + "mIcon=" + mIcon - + ", mContentDescription=" + mContentDescription - + ", mShouldTint=" + mShouldTint - + '}'; - } - - /** - * A builder for {@link SmartspaceIcon} object. - * - * @hide - */ - @SystemApi - public static final class Builder { - - private Icon mIcon; - private CharSequence mContentDescription; - private boolean mShouldTint; - - /** - * A builder for {@link SmartspaceIcon}, which sets shouldTint to true by default. - * - * @param icon the icon image of this {@link SmartspaceIcon} instance. - */ - public Builder(@NonNull Icon icon) { - mIcon = Objects.requireNonNull(icon); - mShouldTint = true; - } - - /** - * Sets the icon's content description. - */ - @NonNull - public Builder setContentDescription(@NonNull CharSequence contentDescription) { - mContentDescription = contentDescription; - return this; - } - - /** - * Sets should tint icon. - */ - @NonNull - public Builder setShouldTint(boolean shouldTint) { - mShouldTint = shouldTint; - return this; - } - - /** - * Builds a new SmartspaceIcon instance. - */ - @NonNull - public SmartspaceIcon build() { - return new SmartspaceIcon(mIcon, mContentDescription, mShouldTint); - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceSubCardUiTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceSubCardUiTemplateData.java deleted file mode 100644 index 2db13d31bba1..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceSubCardUiTemplateData.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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 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 SmartspaceText 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 = in.readTypedObject(SmartspaceText.CREATOR); - mSubCardAction = in.readTypedObject(SmartspaceTapAction.CREATOR); - } - - private SmartspaceSubCardUiTemplateData(int templateType, - @Nullable SmartspaceText titleText, - @Nullable SmartspaceIcon titleIcon, - @Nullable SmartspaceText subtitleText, - @Nullable SmartspaceIcon subTitleIcon, - @Nullable SmartspaceTapAction primaryTapAction, - @Nullable SmartspaceText supplementalSubtitleText, - @Nullable SmartspaceIcon supplementalSubtitleIcon, - @Nullable SmartspaceTapAction supplementalSubtitleTapAction, - @Nullable SmartspaceText supplementalAlarmText, - @NonNull SmartspaceIcon subCardIcon, - @Nullable SmartspaceText 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 SmartspaceText getSubCardText() { - return mSubCardText; - } - - @Nullable - public SmartspaceTapAction getSubCardAction() { - return mSubCardAction; - } - - /** - * @see Parcelable.Creator - */ - @NonNull - public static final Creator CREATOR = - new Creator() { - @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); - out.writeTypedObject(mSubCardText, 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 SmartspaceText 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 text. - */ - @NonNull - public Builder setSubCardText(@NonNull SmartspaceText subCardText) { - mSubCardText = subCardText; - 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); - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceSubImageUiTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceSubImageUiTemplateData.java deleted file mode 100644 index 2fe4cf87984a..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceSubImageUiTemplateData.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * 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 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 mSubImageTexts; - - /** If multiple images are passed in, they will be rendered as GIF. */ - @NonNull - private final List mSubImages; - - /** Tap action for the sub-image secondary card. */ - @Nullable - private final SmartspaceTapAction mSubImageAction; - - SmartspaceSubImageUiTemplateData(@NonNull Parcel in) { - super(in); - mSubImageTexts = in.createTypedArrayList(SmartspaceText.CREATOR); - mSubImages = in.createTypedArrayList(SmartspaceIcon.CREATOR); - mSubImageAction = in.readTypedObject(SmartspaceTapAction.CREATOR); - } - - private SmartspaceSubImageUiTemplateData(@SmartspaceTarget.UiTemplateType int templateType, - @Nullable SmartspaceText titleText, - @Nullable SmartspaceIcon titleIcon, - @Nullable SmartspaceText subtitleText, - @Nullable SmartspaceIcon subTitleIcon, - @Nullable SmartspaceTapAction primaryTapAction, - @Nullable SmartspaceText supplementalSubtitleText, - @Nullable SmartspaceIcon supplementalSubtitleIcon, - @Nullable SmartspaceTapAction supplementalSubtitleTapAction, - @Nullable SmartspaceText supplementalAlarmText, - @NonNull List subImageTexts, - @NonNull List subImages, - @Nullable SmartspaceTapAction subImageAction) { - super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction, - supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction, - supplementalAlarmText); - mSubImageTexts = subImageTexts; - mSubImages = subImages; - mSubImageAction = subImageAction; - } - - @NonNull - public List getSubImageTexts() { - return mSubImageTexts; - } - - @NonNull - public List getSubImages() { - return mSubImages; - } - - @Nullable - public SmartspaceTapAction getSubImageAction() { - return mSubImageAction; - } - - /** - * @see Parcelable.Creator - */ - @NonNull - public static final Creator CREATOR = - new Creator() { - @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.writeTypedList(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 mSubImageTexts; - private final List mSubImages; - private SmartspaceTapAction mSubImageAction; - - /** - * A builder for {@link SmartspaceSubImageUiTemplateData}. - */ - public Builder(@NonNull List subImageTexts, - @NonNull List subImages) { - super(SmartspaceTarget.UI_TEMPLATE_SUB_IMAGE); - mSubImageTexts = Objects.requireNonNull(subImageTexts); - mSubImages = Objects.requireNonNull(subImages); - } - - /** - * Sets the card tap action. - */ - @NonNull - public Builder setSubImageAction(@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); - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceSubListUiTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceSubListUiTemplateData.java deleted file mode 100644 index 9512c7fb130e..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceSubListUiTemplateData.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 sub-list Ui Template. - * - * @hide - */ -@SystemApi -public final class SmartspaceSubListUiTemplateData extends SmartspaceDefaultUiTemplateData { - - @Nullable - private final SmartspaceIcon mSubListIcon; - @NonNull - private final List 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 = in.createTypedArrayList(SmartspaceText.CREATOR); - mSubListAction = in.readTypedObject(SmartspaceTapAction.CREATOR); - } - - private SmartspaceSubListUiTemplateData(@SmartspaceTarget.UiTemplateType int templateType, - @Nullable SmartspaceText titleText, - @Nullable SmartspaceIcon titleIcon, - @Nullable SmartspaceText subtitleText, - @Nullable SmartspaceIcon subTitleIcon, - @Nullable SmartspaceTapAction primaryTapAction, - @Nullable SmartspaceText supplementalSubtitleText, - @Nullable SmartspaceIcon supplementalSubtitleIcon, - @Nullable SmartspaceTapAction supplementalSubtitleTapAction, - @Nullable SmartspaceText supplementalAlarmText, - @Nullable SmartspaceIcon subListIcon, - @NonNull List 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 getSubListTexts() { - return mSubListTexts; - } - - @Nullable - public SmartspaceTapAction getSubListAction() { - return mSubListAction; - } - - /** - * @see Parcelable.Creator - */ - @NonNull - public static final Creator CREATOR = - new Creator() { - @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.writeTypedList(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 mSubListTexts; - private SmartspaceTapAction mSubListAction; - - /** - * A builder for {@link SmartspaceSubListUiTemplateData}. - */ - public Builder(@NonNull List 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 setSubListAction(@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); - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceTapAction.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceTapAction.java deleted file mode 100644 index 27d8e5fed3b1..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceTapAction.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * 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 CREATOR = new Creator() { - @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); - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SmartspaceText.java b/core/java/android/app/smartspace/uitemplatedata/SmartspaceText.java deleted file mode 100644 index 25d13e6521c6..000000000000 --- a/core/java/android/app/smartspace/uitemplatedata/SmartspaceText.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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.SystemApi; -import android.app.smartspace.SmartspaceUtils; -import android.os.Parcel; -import android.os.Parcelable; -import android.text.TextUtils; - -import java.util.Objects; - -/** - * Holds the information for a Smartspace-card text: the text content and - * the truncate_at information. - * - * @hide - */ -@SystemApi -public final class SmartspaceText implements Parcelable { - - @NonNull - private final CharSequence mText; - - private final TextUtils.TruncateAt mTruncateAtType; - - SmartspaceText(Parcel in) { - mText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - mTruncateAtType = TextUtils.TruncateAt.valueOf(in.readString()); - } - - private SmartspaceText(@NonNull CharSequence text, TextUtils.TruncateAt truncateAtType) { - mText = text; - mTruncateAtType = truncateAtType; - } - - @NonNull - public CharSequence getText() { - return mText; - } - - @NonNull - public TextUtils.TruncateAt getTruncateAtType() { - return mTruncateAtType; - } - - @NonNull - public static final Creator CREATOR = new Creator() { - @Override - public SmartspaceText createFromParcel(Parcel in) { - return new SmartspaceText(in); - } - - @Override - public SmartspaceText[] newArray(int size) { - return new SmartspaceText[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SmartspaceText)) return false; - SmartspaceText that = (SmartspaceText) o; - return mTruncateAtType == that.mTruncateAtType && SmartspaceUtils.isEqual(mText, - that.mText); - } - - @Override - public int hashCode() { - return Objects.hash(mText, mTruncateAtType); - } - - @Override - public void writeToParcel(@NonNull Parcel out, int flags) { - TextUtils.writeToParcel(mText, out, flags); - out.writeString(mTruncateAtType.name()); - } - - /** - * A builder for {@link SmartspaceText} object. - * - * @hide - */ - @SystemApi - public static final class Builder { - private final CharSequence mText; - private TextUtils.TruncateAt mTruncateAtType; - - /** - * A builder for {@link SmartspaceText}, which sets TruncateAtType to AT_END by default. - */ - public Builder(@NonNull CharSequence text) { - mText = Objects.requireNonNull(text); - mTruncateAtType = TextUtils.TruncateAt.END; - } - - /** - * A builder for {@link SmartspaceText}. - */ - public Builder(@NonNull CharSequence text, @NonNull TextUtils.TruncateAt truncateAtType) { - mText = Objects.requireNonNull(text); - mTruncateAtType = Objects.requireNonNull(truncateAtType); - } - - /** - * Sets truncateAtType. - */ - @NonNull - public Builder setTruncateAtType(@NonNull TextUtils.TruncateAt truncateAtType) { - mTruncateAtType = Objects.requireNonNull(truncateAtType); - return this; - } - - /** - * Builds a new SmartspaceText instance. - */ - @NonNull - public SmartspaceText build() { - return new SmartspaceText(mText, mTruncateAtType); - } - } -} diff --git a/core/java/android/app/smartspace/uitemplatedata/SubCardTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SubCardTemplateData.java new file mode 100644 index 000000000000..9c8330d1fcc6 --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/SubCardTemplateData.java @@ -0,0 +1,206 @@ +/* + * 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 java.util.Objects; + +/** + * Holds all the relevant data needed to render a Smartspace card with the sub-card Ui Template. + * + * This template will add a sub-card card within the default-template card: + *
    + *
  • sub-card icon
  • + *
  • sub-card text
  • + *
+ * + * @hide + */ +@SystemApi +public final class SubCardTemplateData extends BaseTemplateData { + + /** Icon for the sub-card. */ + @NonNull + private final Icon mSubCardIcon; + + /** Text for the sub-card, which shows below the icon when being set. */ + @Nullable + private final Text mSubCardText; + + /** Tap action for the sub-card secondary card. */ + @Nullable + private final TapAction mSubCardAction; + + SubCardTemplateData(@NonNull Parcel in) { + super(in); + mSubCardIcon = in.readTypedObject(Icon.CREATOR); + mSubCardText = in.readTypedObject(Text.CREATOR); + mSubCardAction = in.readTypedObject(TapAction.CREATOR); + } + + private SubCardTemplateData(int templateType, + @Nullable Text titleText, + @Nullable Icon titleIcon, + @Nullable Text subtitleText, + @Nullable Icon subTitleIcon, + @Nullable TapAction primaryTapAction, + @Nullable Text supplementalSubtitleText, + @Nullable Icon supplementalSubtitleIcon, + @Nullable TapAction supplementalSubtitleTapAction, + @Nullable Text supplementalAlarmText, + @NonNull Icon subCardIcon, + @Nullable Text subCardText, + @Nullable TapAction subCardAction) { + super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction, + supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction, + supplementalAlarmText); + mSubCardIcon = subCardIcon; + mSubCardText = subCardText; + mSubCardAction = subCardAction; + } + + /** Returns the sub-card card's icon. */ + @NonNull + public Icon getSubCardIcon() { + return mSubCardIcon; + } + + /** Returns the sub-card card's text. */ + @Nullable + public Text getSubCardText() { + return mSubCardText; + } + + /** Returns the sub-card card's tap action. */ + @Nullable + public TapAction getSubCardAction() { + return mSubCardAction; + } + + /** + * @see Parcelable.Creator + */ + @NonNull + public static final Creator CREATOR = + new Creator() { + @Override + public SubCardTemplateData createFromParcel(Parcel in) { + return new SubCardTemplateData(in); + } + + @Override + public SubCardTemplateData[] newArray(int size) { + return new SubCardTemplateData[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel out, int flags) { + super.writeToParcel(out, flags); + out.writeTypedObject(mSubCardIcon, flags); + out.writeTypedObject(mSubCardText, flags); + out.writeTypedObject(mSubCardAction, flags); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SubCardTemplateData)) return false; + if (!super.equals(o)) return false; + SubCardTemplateData that = (SubCardTemplateData) 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 SubCardTemplateData} object. + * + * @hide + */ + @SystemApi + public static final class Builder extends BaseTemplateData.Builder { + + private final Icon mSubCardIcon; + private Text mSubCardText; + private TapAction mSubCardAction; + + /** + * A builder for {@link SubCardTemplateData}. + */ + public Builder(@NonNull Icon subCardIcon) { + super(SmartspaceTarget.UI_TEMPLATE_SUB_CARD); + mSubCardIcon = Objects.requireNonNull(subCardIcon); + } + + /** + * Sets the card text. + */ + @NonNull + public Builder setSubCardText(@NonNull Text subCardText) { + mSubCardText = subCardText; + return this; + } + + /** + * Sets the card tap action. + */ + @NonNull + public Builder setSubCardAction(@NonNull TapAction subCardAction) { + mSubCardAction = subCardAction; + return this; + } + + /** + * Builds a new SmartspaceSubCardUiTemplateData instance. + */ + @NonNull + public SubCardTemplateData build() { + return new SubCardTemplateData(getTemplateType(), getTitleText(), + getTitleIcon(), getSubtitleText(), getSubtitleIcon(), getPrimaryTapAction(), + getSupplementalSubtitleText(), getSupplementalSubtitleIcon(), + getSupplementalSubtitleTapAction(), getSupplementalAlarmText(), mSubCardIcon, + mSubCardText, + mSubCardAction); + } + } +} diff --git a/core/java/android/app/smartspace/uitemplatedata/SubImageTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SubImageTemplateData.java new file mode 100644 index 000000000000..7df523858a76 --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/SubImageTemplateData.java @@ -0,0 +1,203 @@ +/* + * 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 sub-image Ui Template. + * + * This template will add a sub-image card within the default-template card: + *
    + *
  • sub-image text1
    • + *
    • sub-image text2
    • image (can be a GIF) + * ...
    + *
+ * + * @hide + */ +@SystemApi +public final class SubImageTemplateData extends BaseTemplateData { + + /** Texts are shown next to the image as a vertical list */ + @NonNull + private final List mSubImageTexts; + + /** If multiple images are passed in, they will be rendered as GIF. */ + @NonNull + private final List mSubImages; + + /** Tap action for the sub-image secondary card. */ + @Nullable + private final TapAction mSubImageAction; + + SubImageTemplateData(@NonNull Parcel in) { + super(in); + mSubImageTexts = in.createTypedArrayList(Text.CREATOR); + mSubImages = in.createTypedArrayList(Icon.CREATOR); + mSubImageAction = in.readTypedObject(TapAction.CREATOR); + } + + private SubImageTemplateData(@SmartspaceTarget.UiTemplateType int templateType, + @Nullable Text titleText, + @Nullable Icon titleIcon, + @Nullable Text subtitleText, + @Nullable Icon subTitleIcon, + @Nullable TapAction primaryTapAction, + @Nullable Text supplementalSubtitleText, + @Nullable Icon supplementalSubtitleIcon, + @Nullable TapAction supplementalSubtitleTapAction, + @Nullable Text supplementalAlarmText, + @NonNull List subImageTexts, + @NonNull List subImages, + @Nullable TapAction subImageAction) { + super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction, + supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction, + supplementalAlarmText); + mSubImageTexts = subImageTexts; + mSubImages = subImages; + mSubImageAction = subImageAction; + } + + /** Returns the list of sub-image card's texts. Can be empty if not being set. */ + @NonNull + public List getSubImageTexts() { + return mSubImageTexts; + } + + /** + * Returns the list of sub-image card's image. It's a single-element list if it's a static + * image, or a multi-elements list if it's a GIF. + */ + @NonNull + public List getSubImages() { + return mSubImages; + } + + /** Returns the sub-image card's tap action. */ + @Nullable + public TapAction getSubImageAction() { + return mSubImageAction; + } + + /** + * @see Parcelable.Creator + */ + @NonNull + public static final Creator CREATOR = + new Creator() { + @Override + public SubImageTemplateData createFromParcel(Parcel in) { + return new SubImageTemplateData(in); + } + + @Override + public SubImageTemplateData[] newArray(int size) { + return new SubImageTemplateData[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel out, int flags) { + super.writeToParcel(out, flags); + out.writeTypedList(mSubImageTexts); + out.writeTypedList(mSubImages); + out.writeTypedObject(mSubImageAction, flags); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SubImageTemplateData)) return false; + if (!super.equals(o)) return false; + SubImageTemplateData that = (SubImageTemplateData) 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 SubImageTemplateData} object. + * + * @hide + */ + @SystemApi + public static final class Builder extends BaseTemplateData.Builder { + + private final List mSubImageTexts; + private final List mSubImages; + private TapAction mSubImageAction; + + /** + * A builder for {@link SubImageTemplateData}. + */ + public Builder(@NonNull List subImageTexts, + @NonNull List subImages) { + super(SmartspaceTarget.UI_TEMPLATE_SUB_IMAGE); + mSubImageTexts = Objects.requireNonNull(subImageTexts); + mSubImages = Objects.requireNonNull(subImages); + } + + /** + * Sets the card tap action. + */ + @NonNull + public Builder setSubImageAction(@NonNull TapAction subImageAction) { + mSubImageAction = subImageAction; + return this; + } + + /** + * Builds a new SmartspaceSubImageUiTemplateData instance. + */ + @NonNull + public SubImageTemplateData build() { + return new SubImageTemplateData(getTemplateType(), getTitleText(), + getTitleIcon(), getSubtitleText(), getSubtitleIcon(), getPrimaryTapAction(), + getSupplementalSubtitleText(), getSupplementalSubtitleIcon(), + getSupplementalSubtitleTapAction(), getSupplementalAlarmText(), mSubImageTexts, + mSubImages, + mSubImageAction); + } + } +} diff --git a/core/java/android/app/smartspace/uitemplatedata/SubListTemplateData.java b/core/java/android/app/smartspace/uitemplatedata/SubListTemplateData.java new file mode 100644 index 000000000000..6f6034da55dd --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/SubListTemplateData.java @@ -0,0 +1,206 @@ +/* + * 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 sub-list Ui Template. + * + * This template will add a sub-list card within the default-template card: + *
    + *
  • sub-list text1 sub-list icon
  • + *
  • sub-list text2
  • + *
  • sub-list text3
  • + * ... + *
+ * + * @hide + */ +@SystemApi +public final class SubListTemplateData extends BaseTemplateData { + + @Nullable + private final Icon mSubListIcon; + @NonNull + private final List mSubListTexts; + + /** Tap action for the sub-list secondary card. */ + @Nullable + private final TapAction mSubListAction; + + SubListTemplateData(@NonNull Parcel in) { + super(in); + mSubListIcon = in.readTypedObject(Icon.CREATOR); + mSubListTexts = in.createTypedArrayList(Text.CREATOR); + mSubListAction = in.readTypedObject(TapAction.CREATOR); + } + + private SubListTemplateData(@SmartspaceTarget.UiTemplateType int templateType, + @Nullable Text titleText, + @Nullable Icon titleIcon, + @Nullable Text subtitleText, + @Nullable Icon subTitleIcon, + @Nullable TapAction primaryTapAction, + @Nullable Text supplementalSubtitleText, + @Nullable Icon supplementalSubtitleIcon, + @Nullable TapAction supplementalSubtitleTapAction, + @Nullable Text supplementalAlarmText, + @Nullable Icon subListIcon, + @NonNull List subListTexts, + @Nullable TapAction subListAction) { + super(templateType, titleText, titleIcon, subtitleText, subTitleIcon, primaryTapAction, + supplementalSubtitleText, supplementalSubtitleIcon, supplementalSubtitleTapAction, + supplementalAlarmText); + mSubListIcon = subListIcon; + mSubListTexts = subListTexts; + mSubListAction = subListAction; + } + + /** Returns the sub-list card's icon. */ + @Nullable + public Icon getSubListIcon() { + return mSubListIcon; + } + + /** Returns the sub-list card's texts list. */ + @NonNull + public List getSubListTexts() { + return mSubListTexts; + } + + /** Returns the sub-list card's tap action. */ + @Nullable + public TapAction getSubListAction() { + return mSubListAction; + } + + /** + * @see Parcelable.Creator + */ + @NonNull + public static final Creator CREATOR = + new Creator() { + @Override + public SubListTemplateData createFromParcel(Parcel in) { + return new SubListTemplateData(in); + } + + @Override + public SubListTemplateData[] newArray(int size) { + return new SubListTemplateData[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.writeTypedList(mSubListTexts); + out.writeTypedObject(mSubListAction, flags); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SubListTemplateData)) return false; + if (!super.equals(o)) return false; + SubListTemplateData that = (SubListTemplateData) 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 SubListTemplateData} object. + * + * @hide + */ + @SystemApi + public static final class Builder extends BaseTemplateData.Builder { + + private Icon mSubListIcon; + private final List mSubListTexts; + private TapAction mSubListAction; + + /** + * A builder for {@link SubListTemplateData}. + */ + public Builder(@NonNull List subListTexts) { + super(SmartspaceTarget.UI_TEMPLATE_SUB_LIST); + mSubListTexts = Objects.requireNonNull(subListTexts); + } + + /** + * Sets the sub-list card icon. + */ + @NonNull + public Builder setSubListIcon(@NonNull Icon subListIcon) { + mSubListIcon = subListIcon; + return this; + } + + /** + * Sets the card tap action. + */ + @NonNull + public Builder setSubListAction(@NonNull TapAction subListAction) { + mSubListAction = subListAction; + return this; + } + + /** + * Builds a new SmartspaceSubListUiTemplateData instance. + */ + @NonNull + public SubListTemplateData build() { + return new SubListTemplateData(getTemplateType(), getTitleText(), + getTitleIcon(), getSubtitleText(), getSubtitleIcon(), getPrimaryTapAction(), + getSupplementalSubtitleText(), getSupplementalSubtitleIcon(), + getSupplementalSubtitleTapAction(), getSupplementalAlarmText(), mSubListIcon, + mSubListTexts, + mSubListAction); + } + } +} diff --git a/core/java/android/app/smartspace/uitemplatedata/TapAction.java b/core/java/android/app/smartspace/uitemplatedata/TapAction.java new file mode 100644 index 000000000000..83ff6abfa7dd --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/TapAction.java @@ -0,0 +1,237 @@ +/* + * 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 TapAction} 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 TapAction implements Parcelable { + + /** A unique Id of this {@link TapAction}. */ + @Nullable + private final CharSequence mId; + + @Nullable + private final Intent mIntent; + + @Nullable + private final PendingIntent mPendingIntent; + + @Nullable + private final UserHandle mUserHandle; + + @Nullable + private Bundle mExtras; + + TapAction(@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 TapAction(@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; + } + + /** Returns the unique id of the tap action. */ + @Nullable + public CharSequence getId() { + return mId; + } + + /** Returns the intent of the tap action. */ + @SuppressLint("IntentBuilderName") + @Nullable + public Intent getIntent() { + return mIntent; + } + + /** Returns the pending intent of the tap action. */ + @Nullable + public PendingIntent getPendingIntent() { + return mPendingIntent; + } + + /** Returns the user handle of the tap action. */ + @Nullable + public UserHandle getUserHandle() { + return mUserHandle; + } + + /** Returns the extras bundle of the tap action. */ + @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 CREATOR = new Creator() { + @Override + public TapAction createFromParcel(Parcel in) { + return new TapAction(in); + } + + @Override + public TapAction[] newArray(int size) { + return new TapAction[size]; + } + }; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof TapAction)) return false; + TapAction that = (TapAction) 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 TapAction} 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 TapAction}. + * + * @param id A unique Id of this {@link TapAction}. + */ + 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 TapAction build() { + if (mIntent == null && mPendingIntent == null && mExtras == null) { + throw new IllegalStateException("Please assign at least 1 valid tap field"); + } + return new TapAction(mId, mIntent, mPendingIntent, mUserHandle, mExtras); + } + } +} diff --git a/core/java/android/app/smartspace/uitemplatedata/Text.java b/core/java/android/app/smartspace/uitemplatedata/Text.java new file mode 100644 index 000000000000..b733394a1ae6 --- /dev/null +++ b/core/java/android/app/smartspace/uitemplatedata/Text.java @@ -0,0 +1,170 @@ +/* + * 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.SystemApi; +import android.app.smartspace.SmartspaceUtils; +import android.os.Parcel; +import android.os.Parcelable; +import android.text.TextUtils; + +import java.util.Objects; + +/** + * Holds the information for a Smartspace-card text: the text content and + * the truncate_at information. + * + * @hide + */ +@SystemApi +public final class Text implements Parcelable { + + @NonNull + private final CharSequence mText; + + private final TextUtils.TruncateAt mTruncateAtType; + + private final int mMaxLines; + + Text(Parcel in) { + mText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); + mTruncateAtType = TextUtils.TruncateAt.valueOf(in.readString()); + mMaxLines = in.readInt(); + } + + private Text(@NonNull CharSequence text, TextUtils.TruncateAt truncateAtType, int maxLines) { + mText = text; + mTruncateAtType = truncateAtType; + mMaxLines = maxLines; + } + + /** Returns the text content. */ + @NonNull + public CharSequence getText() { + return mText; + } + + /** Returns the {@link TextUtils.TruncateAt} type of the text content. */ + @NonNull + public TextUtils.TruncateAt getTruncateAtType() { + return mTruncateAtType; + } + + /** Returns the allowed max lines for presenting the text content. */ + public int getMaxLines() { + return mMaxLines; + } + + @NonNull + public static final Creator CREATOR = new Creator() { + @Override + public Text createFromParcel(Parcel in) { + return new Text(in); + } + + @Override + public Text[] newArray(int size) { + return new Text[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Text)) return false; + Text that = (Text) o; + return mTruncateAtType == that.mTruncateAtType && SmartspaceUtils.isEqual(mText, + that.mText) && mMaxLines == that.mMaxLines; + } + + @Override + public int hashCode() { + return Objects.hash(mText, mTruncateAtType, mMaxLines); + } + + @Override + public void writeToParcel(@NonNull Parcel out, int flags) { + TextUtils.writeToParcel(mText, out, flags); + out.writeString(mTruncateAtType.name()); + out.writeInt(mMaxLines); + } + + /** + * A builder for {@link Text} object. + * + * @hide + */ + @SystemApi + public static final class Builder { + private final CharSequence mText; + private TextUtils.TruncateAt mTruncateAtType; + private int mMaxLines; + + /** + * A builder for {@link Text}, which by default sets TruncateAtType to AT_END, and the max + * lines to 1. + */ + public Builder(@NonNull CharSequence text) { + mText = Objects.requireNonNull(text); + mTruncateAtType = TextUtils.TruncateAt.END; + mMaxLines = 1; + } + + /** + * A builder for {@link Text} with specifying {@link TextUtils.TruncateAt} type, and by + * default set the max lines to 1. + */ + public Builder(@NonNull CharSequence text, @NonNull TextUtils.TruncateAt truncateAtType) { + mText = Objects.requireNonNull(text); + mTruncateAtType = Objects.requireNonNull(truncateAtType); + mMaxLines = 1; + } + + /** + * Sets truncateAtType, where the text content should be truncated if not all the content + * can be presented. + */ + @NonNull + public Builder setTruncateAtType(@NonNull TextUtils.TruncateAt truncateAtType) { + mTruncateAtType = Objects.requireNonNull(truncateAtType); + return this; + } + + /** + * Sets the allowed max lines for the text content. + */ + @NonNull + public Builder setMaxLines(int maxLines) { + mMaxLines = maxLines; + return this; + } + + /** + * Builds a new SmartspaceText instance. + */ + @NonNull + public Text build() { + return new Text(mText, mTruncateAtType, mMaxLines); + } + } +} diff --git a/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java b/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java index ce3c599067ca..d3f4ab017fd7 100644 --- a/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java +++ b/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java @@ -20,7 +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.app.smartspace.uitemplatedata.TapAction; import android.content.ActivityNotFoundException; import android.content.Intent; import android.graphics.drawable.Drawable; @@ -139,7 +139,7 @@ public interface BcSmartspaceDataPlugin extends Plugin { } } - default void startFromAction(SmartspaceTapAction action, View v, boolean showOnLockscreen) { + default void startFromAction(TapAction action, View v, boolean showOnLockscreen) { try { if (action.getIntent() != null) { startIntent(v, action.getIntent(), showOnLockscreen); -- cgit v1.2.3-59-g8ed1b