Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c40608c0 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Wallpaper color extraction API stub

Now it's possible to listen to changes on wallpaper colors by
registering a listener on WallpaperManager. It's also possible
to get the current wallpaper text color hints.

Bug: 36856508
Test: compilation
Change-Id: I5102cb7be9a4af60b85fc8913154a79dfe5c21a0
parent d210ce63
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -6090,6 +6090,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();
@@ -6112,6 +6123,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);
@@ -6126,6 +6139,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();
@@ -6134,6 +6148,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;
@@ -6158,6 +6173,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 {
@@ -37728,10 +37747,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();
+21 −0
Original line number Diff line number Diff line
@@ -6294,6 +6294,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();
@@ -6316,6 +6327,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();
@@ -6332,6 +6345,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();
@@ -6340,6 +6354,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;
@@ -6367,6 +6382,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 {
@@ -40986,10 +41005,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();
+21 −0
Original line number Diff line number Diff line
@@ -6110,6 +6110,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();
@@ -6132,6 +6143,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);
@@ -6146,6 +6159,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();
@@ -6154,6 +6168,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;
@@ -6178,6 +6193,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 {
@@ -37922,10 +37941,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();
+97 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}
+54 −0
Original line number Diff line number Diff line
@@ -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);
    }
}
Loading