diff options
| author | 2017-04-15 04:52:20 +0000 | |
|---|---|---|
| committer | 2017-04-15 04:52:24 +0000 | |
| commit | 6acf7a7b45ea0cf54d14f28ad8538e3b7e309819 (patch) | |
| tree | 39e4949c90ec19be267c9faa57a0dfcb3944c751 | |
| parent | 0d8890474413700bec1cbf9c264b8bfaf7f782f0 (diff) | |
| parent | c40608c041b1eb8b8cb4b96347c7ca29f4f79169 (diff) | |
Merge "Wallpaper color extraction API stub" into oc-dev
| -rw-r--r-- | api/current.txt | 21 | ||||
| -rw-r--r-- | api/system-current.txt | 21 | ||||
| -rw-r--r-- | api/test-current.txt | 21 | ||||
| -rw-r--r-- | core/java/android/app/WallpaperColors.java | 97 | ||||
| -rw-r--r-- | core/java/android/app/WallpaperManager.java | 54 | ||||
| -rw-r--r-- | core/java/android/service/wallpaper/WallpaperService.java | 20 |
6 files changed, 234 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index c1d63492ff52..98db4f78f833 100644 --- a/api/current.txt +++ b/api/current.txt @@ -6092,6 +6092,17 @@ package android.app { method public void onDetached(); } + public final class WallpaperColors implements android.os.Parcelable { + ctor public WallpaperColors(android.os.Parcel); + ctor public WallpaperColors(java.util.List<android.util.Pair<android.graphics.Color, java.lang.Integer>>); + ctor public WallpaperColors(java.util.List<android.util.Pair<android.graphics.Color, java.lang.Integer>>, boolean); + method public int describeContents(); + method public java.util.List<android.util.Pair<android.graphics.Color, java.lang.Integer>> getColors(); + method public boolean supportsDarkText(); + method public void writeToParcel(android.os.Parcel, int); + field public static final android.os.Parcelable.Creator<android.app.WallpaperColors> CREATOR; + } + public final class WallpaperInfo implements android.os.Parcelable { ctor public WallpaperInfo(android.content.Context, android.content.pm.ResolveInfo) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; method public int describeContents(); @@ -6114,6 +6125,8 @@ package android.app { } public class WallpaperManager { + method public void addOnColorsChangedListener(android.app.WallpaperManager.OnColorsChangedListener); + method public void addOnColorsChangedListener(android.app.WallpaperManager.OnColorsChangedListener, android.os.Handler); method public void clear() throws java.io.IOException; method public void clear(int) throws java.io.IOException; method public void clearWallpaperOffsets(android.os.IBinder); @@ -6128,6 +6141,7 @@ package android.app { method public android.graphics.drawable.Drawable getDrawable(); method public android.graphics.drawable.Drawable getFastDrawable(); method public static android.app.WallpaperManager getInstance(android.content.Context); + method public android.app.WallpaperColors getWallpaperColors(int); method public android.os.ParcelFileDescriptor getWallpaperFile(int); method public int getWallpaperId(int); method public android.app.WallpaperInfo getWallpaperInfo(); @@ -6136,6 +6150,7 @@ package android.app { method public boolean isWallpaperSupported(); method public android.graphics.drawable.Drawable peekDrawable(); method public android.graphics.drawable.Drawable peekFastDrawable(); + method public void removeOnColorsChangedListener(android.app.WallpaperManager.OnColorsChangedListener); method public void sendWallpaperCommand(android.os.IBinder, java.lang.String, int, int, int, android.os.Bundle); method public void setBitmap(android.graphics.Bitmap) throws java.io.IOException; method public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException; @@ -6160,6 +6175,10 @@ package android.app { field public static final java.lang.String WALLPAPER_PREVIEW_META_DATA = "android.wallpaper.preview"; } + public static abstract interface WallpaperManager.OnColorsChangedListener { + method public abstract void onColorsChanged(android.app.WallpaperColors, int); + } + } package android.app.admin { @@ -37783,10 +37802,12 @@ package android.service.wallpaper { method public int getDesiredMinimumHeight(); method public int getDesiredMinimumWidth(); method public android.view.SurfaceHolder getSurfaceHolder(); + method public void invalidateColors(); method public boolean isPreview(); method public boolean isVisible(); method public void onApplyWindowInsets(android.view.WindowInsets); method public android.os.Bundle onCommand(java.lang.String, int, int, int, android.os.Bundle, boolean); + method public android.app.WallpaperColors onComputeWallpaperColors(); method public void onCreate(android.view.SurfaceHolder); method public void onDesiredSizeChanged(int, int); method public void onDestroy(); diff --git a/api/system-current.txt b/api/system-current.txt index ec089c03ec2c..2767fd56c707 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6296,6 +6296,17 @@ package android.app { method public void setPersistentVrModeEnabled(boolean); } + public final class WallpaperColors implements android.os.Parcelable { + ctor public WallpaperColors(android.os.Parcel); + ctor public WallpaperColors(java.util.List<android.util.Pair<android.graphics.Color, java.lang.Integer>>); + ctor public WallpaperColors(java.util.List<android.util.Pair<android.graphics.Color, java.lang.Integer>>, boolean); + method public int describeContents(); + method public java.util.List<android.util.Pair<android.graphics.Color, java.lang.Integer>> getColors(); + method public boolean supportsDarkText(); + method public void writeToParcel(android.os.Parcel, int); + field public static final android.os.Parcelable.Creator<android.app.WallpaperColors> CREATOR; + } + public final class WallpaperInfo implements android.os.Parcelable { ctor public WallpaperInfo(android.content.Context, android.content.pm.ResolveInfo) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; method public int describeContents(); @@ -6318,6 +6329,8 @@ package android.app { } public class WallpaperManager { + method public void addOnColorsChangedListener(android.app.WallpaperManager.OnColorsChangedListener); + method public void addOnColorsChangedListener(android.app.WallpaperManager.OnColorsChangedListener, android.os.Handler); method public void clear() throws java.io.IOException; method public void clear(int) throws java.io.IOException; method public void clearWallpaper(); @@ -6334,6 +6347,7 @@ package android.app { method public android.graphics.drawable.Drawable getDrawable(); method public android.graphics.drawable.Drawable getFastDrawable(); method public static android.app.WallpaperManager getInstance(android.content.Context); + method public android.app.WallpaperColors getWallpaperColors(int); method public android.os.ParcelFileDescriptor getWallpaperFile(int); method public int getWallpaperId(int); method public android.app.WallpaperInfo getWallpaperInfo(); @@ -6342,6 +6356,7 @@ package android.app { method public boolean isWallpaperSupported(); method public android.graphics.drawable.Drawable peekDrawable(); method public android.graphics.drawable.Drawable peekFastDrawable(); + method public void removeOnColorsChangedListener(android.app.WallpaperManager.OnColorsChangedListener); method public void sendWallpaperCommand(android.os.IBinder, java.lang.String, int, int, int, android.os.Bundle); method public void setBitmap(android.graphics.Bitmap) throws java.io.IOException; method public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException; @@ -6369,6 +6384,10 @@ package android.app { field public static final java.lang.String WALLPAPER_PREVIEW_META_DATA = "android.wallpaper.preview"; } + public static abstract interface WallpaperManager.OnColorsChangedListener { + method public abstract void onColorsChanged(android.app.WallpaperColors, int); + } + } package android.app.admin { @@ -41042,10 +41061,12 @@ package android.service.wallpaper { method public int getDesiredMinimumHeight(); method public int getDesiredMinimumWidth(); method public android.view.SurfaceHolder getSurfaceHolder(); + method public void invalidateColors(); method public boolean isPreview(); method public boolean isVisible(); method public void onApplyWindowInsets(android.view.WindowInsets); method public android.os.Bundle onCommand(java.lang.String, int, int, int, android.os.Bundle, boolean); + method public android.app.WallpaperColors onComputeWallpaperColors(); method public void onCreate(android.view.SurfaceHolder); method public void onDesiredSizeChanged(int, int); method public void onDestroy(); diff --git a/api/test-current.txt b/api/test-current.txt index ba5094971658..090df83b39fe 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -6112,6 +6112,17 @@ package android.app { method public void onDetached(); } + public final class WallpaperColors implements android.os.Parcelable { + ctor public WallpaperColors(android.os.Parcel); + ctor public WallpaperColors(java.util.List<android.util.Pair<android.graphics.Color, java.lang.Integer>>); + ctor public WallpaperColors(java.util.List<android.util.Pair<android.graphics.Color, java.lang.Integer>>, boolean); + method public int describeContents(); + method public java.util.List<android.util.Pair<android.graphics.Color, java.lang.Integer>> getColors(); + method public boolean supportsDarkText(); + method public void writeToParcel(android.os.Parcel, int); + field public static final android.os.Parcelable.Creator<android.app.WallpaperColors> CREATOR; + } + public final class WallpaperInfo implements android.os.Parcelable { ctor public WallpaperInfo(android.content.Context, android.content.pm.ResolveInfo) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; method public int describeContents(); @@ -6134,6 +6145,8 @@ package android.app { } public class WallpaperManager { + method public void addOnColorsChangedListener(android.app.WallpaperManager.OnColorsChangedListener); + method public void addOnColorsChangedListener(android.app.WallpaperManager.OnColorsChangedListener, android.os.Handler); method public void clear() throws java.io.IOException; method public void clear(int) throws java.io.IOException; method public void clearWallpaperOffsets(android.os.IBinder); @@ -6148,6 +6161,7 @@ package android.app { method public android.graphics.drawable.Drawable getDrawable(); method public android.graphics.drawable.Drawable getFastDrawable(); method public static android.app.WallpaperManager getInstance(android.content.Context); + method public android.app.WallpaperColors getWallpaperColors(int); method public android.os.ParcelFileDescriptor getWallpaperFile(int); method public int getWallpaperId(int); method public android.app.WallpaperInfo getWallpaperInfo(); @@ -6156,6 +6170,7 @@ package android.app { method public boolean isWallpaperSupported(); method public android.graphics.drawable.Drawable peekDrawable(); method public android.graphics.drawable.Drawable peekFastDrawable(); + method public void removeOnColorsChangedListener(android.app.WallpaperManager.OnColorsChangedListener); method public void sendWallpaperCommand(android.os.IBinder, java.lang.String, int, int, int, android.os.Bundle); method public void setBitmap(android.graphics.Bitmap) throws java.io.IOException; method public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException; @@ -6180,6 +6195,10 @@ package android.app { field public static final java.lang.String WALLPAPER_PREVIEW_META_DATA = "android.wallpaper.preview"; } + public static abstract interface WallpaperManager.OnColorsChangedListener { + method public abstract void onColorsChanged(android.app.WallpaperColors, int); + } + } package android.app.admin { @@ -37977,10 +37996,12 @@ package android.service.wallpaper { method public int getDesiredMinimumHeight(); method public int getDesiredMinimumWidth(); method public android.view.SurfaceHolder getSurfaceHolder(); + method public void invalidateColors(); method public boolean isPreview(); method public boolean isVisible(); method public void onApplyWindowInsets(android.view.WindowInsets); method public android.os.Bundle onCommand(java.lang.String, int, int, int, android.os.Bundle, boolean); + method public android.app.WallpaperColors onComputeWallpaperColors(); method public void onCreate(android.view.SurfaceHolder); method public void onDesiredSizeChanged(int, int); method public void onDestroy(); diff --git a/core/java/android/app/WallpaperColors.java b/core/java/android/app/WallpaperColors.java new file mode 100644 index 000000000000..5ed66cac5f8f --- /dev/null +++ b/core/java/android/app/WallpaperColors.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 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; + +import android.graphics.Color; +import android.os.Parcel; +import android.os.Parcelable; + +import android.util.Pair; + +import java.util.List; + +/** + * A class containing information about the colors of a wallpaper. + */ +public final class WallpaperColors implements Parcelable { + + public WallpaperColors(Parcel parcel) { + } + + /** + * Wallpaper color details containing a list of colors and their weights, + * as if it were an histogram. + * This list can be extracted from a bitmap by the Palette API. + * + * Dark text support will be calculated internally based on the histogram. + * + * @param colors list of pairs where each pair contains a color + * and number of occurrences/influence. + */ + public WallpaperColors(List<Pair<Color, Integer>> colors) { + } + + /** + * Wallpaper color details containing a list of colors and their weights, + * as if it were an histogram. + * Explicit dark text support. + * + * @param colors list of pairs where each pair contains a color + * and number of occurrences/influence. + * @param supportsDarkText can have dark text on top or not + */ + public WallpaperColors(List<Pair<Color, Integer>> colors, boolean supportsDarkText) { + } + + public static final Creator<WallpaperColors> CREATOR = new Creator<WallpaperColors>() { + @Override + public WallpaperColors createFromParcel(Parcel in) { + return new WallpaperColors(in); + } + + @Override + public WallpaperColors[] newArray(int size) { + return new WallpaperColors[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + } + + /** + * List of colors with their occurrences. The bigger the int, the more relevant the color. + * @return list of colors paired with their weights. + */ + public List<Pair<Color, Integer>> getColors() { + return null; + } + + /** + * Whether or not dark text is legible on top of this wallpaper. + * + * @return true if dark text is supported + */ + public boolean supportsDarkText() { + return false; + } +} diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index aa0eaaebf975..0676bca0e796 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -17,6 +17,8 @@ package android.app; import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.RawRes; import android.annotation.SystemApi; import android.content.ComponentName; @@ -741,6 +743,43 @@ public class WallpaperManager { return getWallpaperFile(which, mContext.getUserId()); } + + /** + * Registers a listener to get notified when the wallpaper colors change. + * Callback might be called from an arbitrary background thread. + * + * @param listener A listener to register + */ + public void addOnColorsChangedListener(@NonNull OnColorsChangedListener listener) { + } + + /** + * Registers a listener to get notified when the wallpaper colors change + * @param listener A listener to register + * @param handler Where to call it from. Might be called from a background thread + * if null. + */ + public void addOnColorsChangedListener(@NonNull OnColorsChangedListener listener, + @Nullable Handler handler) { + } + + /** + * Stop listening to color updates. + * @param callback A callback to unsubscribe + */ + public void removeOnColorsChangedListener(@NonNull OnColorsChangedListener callback) { + } + + /** + * Get the primary colors of a wallpaper + * @param which wallpaper type. Must be either {@link #FLAG_SYSTEM} or + * {@link #FLAG_LOCK} + * @return a list of colors ordered by priority + */ + public @Nullable WallpaperColors getWallpaperColors(int which) { + return null; + } + /** * Version of {@link #getWallpaperFile(int)} that can access the wallpaper data * for a given user. The caller must hold the INTERACT_ACROSS_USERS_FULL @@ -1732,4 +1771,19 @@ public class WallpaperManager { mLatch.countDown(); } } + + /** + * Interface definition for a callback to be invoked when colors change on a wallpaper. + */ + public interface OnColorsChangedListener { + /** + * Called when colors change. + * A {@link android.app.WallpaperColors} object containing a simplified + * color histogram will be given. + * + * @param colors Wallpaper color info + * @param which A combination of {@link #FLAG_LOCK} and {@link #FLAG_SYSTEM} + */ + void onColorsChanged(WallpaperColors colors, int which); + } } diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 6bbb0ff9861b..98780a7d73d5 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -16,6 +16,8 @@ package android.service.wallpaper; +import android.annotation.Nullable; +import android.app.WallpaperColors; import android.content.res.TypedArray; import android.graphics.Canvas; import android.util.MergedConfiguration; @@ -542,6 +544,24 @@ public abstract class WallpaperService extends Service { */ public void onSurfaceDestroyed(SurfaceHolder holder) { } + + /** + * Notifies the engine that wallpaper colors changed significantly. + * This will trigger a {@link #onComputeWallpaperColors()} call. + */ + public void invalidateColors() { + } + + /** + * Notifies the system about what colors the wallpaper is using. + * You might return null if no color information is available at the moment. In that case + * you might want to call {@link #invalidateColors()} in a near future. + * + * @return List of wallpaper colors and their weights. + */ + public @Nullable WallpaperColors onComputeWallpaperColors() { + return null; + } protected void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) { out.print(prefix); out.print("mInitializing="); out.print(mInitializing); |