From 83b2f3785327560d32e8f7d796861a2bafa9e03e Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Fri, 26 Feb 2021 11:06:05 -0800 Subject: [PATCH] Make WallpaperColors hints public Per AOSP request, developers would like to access this API, which was currently marked as @SystemAPI. Test: atest WallpaperColorsTest Fixes: 142843776 Change-Id: I3970ab3ce92de78c3f1a994b6bc560518edf626c --- core/api/current.txt | 4 ++ core/api/system-current.txt | 7 ---- core/java/android/app/WallpaperColors.java | 46 +++++++++------------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index d26eb3c79d4d5..5dd457ae16db5 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -6812,14 +6812,18 @@ package android.app { public final class WallpaperColors implements android.os.Parcelable { ctor public WallpaperColors(android.os.Parcel); ctor public WallpaperColors(@NonNull android.graphics.Color, @Nullable android.graphics.Color, @Nullable android.graphics.Color); + ctor public WallpaperColors(@NonNull android.graphics.Color, @Nullable android.graphics.Color, @Nullable android.graphics.Color, int); method public int describeContents(); method public static android.app.WallpaperColors fromBitmap(@NonNull android.graphics.Bitmap); method public static android.app.WallpaperColors fromDrawable(android.graphics.drawable.Drawable); + method public int getColorHints(); method @NonNull public android.graphics.Color getPrimaryColor(); method @Nullable public android.graphics.Color getSecondaryColor(); method @Nullable public android.graphics.Color getTertiaryColor(); method public void writeToParcel(android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator CREATOR; + field public static final int HINT_SUPPORTS_DARK_TEXT = 1; // 0x1 + field public static final int HINT_SUPPORTS_DARK_THEME = 2; // 0x2 } public final class WallpaperInfo implements android.os.Parcelable { diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 8d12f3d3da769..ccc8cce3304e2 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -855,13 +855,6 @@ package android.app { method public void onVrStateChanged(boolean); } - public final class WallpaperColors implements android.os.Parcelable { - ctor public WallpaperColors(@NonNull android.graphics.Color, @Nullable android.graphics.Color, @Nullable android.graphics.Color, int); - method public int getColorHints(); - field public static final int HINT_SUPPORTS_DARK_TEXT = 1; // 0x1 - field public static final int HINT_SUPPORTS_DARK_THEME = 2; // 0x2 - } - public final class WallpaperInfo implements android.os.Parcelable { method public boolean supportsAmbientMode(); } diff --git a/core/java/android/app/WallpaperColors.java b/core/java/android/app/WallpaperColors.java index 3abba43ae0a83..0a8a73404a7b8 100644 --- a/core/java/android/app/WallpaperColors.java +++ b/core/java/android/app/WallpaperColors.java @@ -16,9 +16,9 @@ package android.app; +import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; -import android.annotation.SystemApi; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -35,6 +35,8 @@ import com.android.internal.graphics.palette.Palette; import com.android.internal.util.ContrastColorUtil; import java.io.FileOutputStream; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -50,6 +52,13 @@ import java.util.stream.Collectors; * or {@link WallpaperColors#getTertiaryColor()}. */ public final class WallpaperColors implements Parcelable { + /** + * @hide + */ + @IntDef(prefix = "HINT_", value = {HINT_SUPPORTS_DARK_TEXT, HINT_SUPPORTS_DARK_THEME}, + flag = true) + @Retention(RetentionPolicy.SOURCE) + public @interface ColorsHints {} private static final boolean DEBUG_DARK_PIXELS = false; @@ -57,18 +66,14 @@ public final class WallpaperColors implements Parcelable { * Specifies that dark text is preferred over the current wallpaper for best presentation. *

* eg. A launcher may set its text color to black if this flag is specified. - * @hide */ - @SystemApi public static final int HINT_SUPPORTS_DARK_TEXT = 1 << 0; /** * Specifies that dark theme is preferred over the current wallpaper for best presentation. *

* eg. A launcher may set its drawer color to black if this flag is specified. - * @hide */ - @SystemApi public static final int HINT_SUPPORTS_DARK_THEME = 1 << 1; /** @@ -229,15 +234,12 @@ public final class WallpaperColors implements Parcelable { * @param primaryColor Primary color. * @param secondaryColor Secondary color. * @param tertiaryColor Tertiary color. - * @param colorHints A combination of WallpaperColor hints. - * @see WallpaperColors#HINT_SUPPORTS_DARK_TEXT + * @param colorHints A combination of color hints. * @see WallpaperColors#fromBitmap(Bitmap) * @see WallpaperColors#fromDrawable(Drawable) - * @hide */ - @SystemApi public WallpaperColors(@NonNull Color primaryColor, @Nullable Color secondaryColor, - @Nullable Color tertiaryColor, int colorHints) { + @Nullable Color tertiaryColor, @ColorsHints int colorHints) { if (primaryColor == null) { throw new IllegalArgumentException("Primary color should never be null."); @@ -268,13 +270,14 @@ public final class WallpaperColors implements Parcelable { * * @param populationByColor Map with keys of colors, and value representing the number of * occurrences of color in the wallpaper. - * @param colorHints A combination of WallpaperColor hints. + * @param colorHints A combination of color hints. * @hide * @see WallpaperColors#HINT_SUPPORTS_DARK_TEXT * @see WallpaperColors#fromBitmap(Bitmap) * @see WallpaperColors#fromDrawable(Drawable) */ - public WallpaperColors(@NonNull Map populationByColor, int colorHints) { + public WallpaperColors(@NonNull Map populationByColor, + @ColorsHints int colorHints) { mAllColors = populationByColor; ArrayList> mapEntries = new ArrayList( @@ -386,26 +389,13 @@ public final class WallpaperColors implements Parcelable { } /** - * Combination of WallpaperColor hints. - * - * @see WallpaperColors#HINT_SUPPORTS_DARK_TEXT - * @return True if dark text is supported. - * @hide + * Returns the color hints for this instance. + * @return The color hints. */ - @SystemApi - public int getColorHints() { + public @ColorsHints int getColorHints() { return mColorHints; } - /** - * @param colorHints Combination of WallpaperColors hints. - * @see WallpaperColors#HINT_SUPPORTS_DARK_TEXT - * @hide - */ - public void setColorHints(int colorHints) { - mColorHints = colorHints; - } - /** * Checks if image is bright and clean enough to support light text. *