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

Commit 7b0b97a4 authored by Jason Monk's avatar Jason Monk
Browse files

Add APIs to look into whats in an Icon

Test: cts
Bug: 73943728
Change-Id: Iefbb4cecad5dd4abfcfc4d2085b0df6b62392305
parent 465f2c7b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -14819,6 +14819,10 @@ package android.graphics.drawable {
    method public static android.graphics.drawable.Icon createWithResource(android.content.Context, int);
    method public static android.graphics.drawable.Icon createWithResource(java.lang.String, int);
    method public int describeContents();
    method public int getResId();
    method public java.lang.String getResPackage();
    method public int getType();
    method public android.net.Uri getUri();
    method public android.graphics.drawable.Drawable loadDrawable(android.content.Context);
    method public void loadDrawableAsync(android.content.Context, android.os.Message);
    method public void loadDrawableAsync(android.content.Context, android.graphics.drawable.Icon.OnDrawableLoadedListener, android.os.Handler);
@@ -14827,6 +14831,11 @@ package android.graphics.drawable {
    method public android.graphics.drawable.Icon setTintMode(android.graphics.PorterDuff.Mode);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.graphics.drawable.Icon> CREATOR;
    field public static final int TYPE_ADAPTIVE_BITMAP = 5; // 0x5
    field public static final int TYPE_BITMAP = 1; // 0x1
    field public static final int TYPE_DATA = 3; // 0x3
    field public static final int TYPE_RESOURCE = 2; // 0x2
    field public static final int TYPE_URI = 4; // 0x4
  }
  public static abstract interface Icon.OnDrawableLoadedListener {
+0 −1
Original line number Diff line number Diff line
@@ -659,7 +659,6 @@ Landroid/graphics/drawable/GradientDrawable$GradientState;->mAngle:I
Landroid/graphics/drawable/GradientDrawable$GradientState;->mPadding:Landroid/graphics/Rect;
Landroid/graphics/drawable/GradientDrawable$GradientState;->mPositions:[F
Landroid/graphics/drawable/GradientDrawable;->mPadding:Landroid/graphics/Rect;
Landroid/graphics/drawable/Icon;->getResPackage()Ljava/lang/String;
Landroid/graphics/drawable/NinePatchDrawable;->mNinePatchState:Landroid/graphics/drawable/NinePatchDrawable$NinePatchState;
Landroid/graphics/drawable/NinePatchDrawable$NinePatchState;->mNinePatch:Landroid/graphics/NinePatch;
Landroid/graphics/drawable/StateListDrawable;->extractStateSet(Landroid/util/AttributeSet;)[I
+55 −19
Original line number Diff line number Diff line
@@ -18,11 +18,14 @@ package android.graphics.drawable;

import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.content.res.ColorStateList;
import android.annotation.IdRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -60,17 +63,40 @@ import java.util.Objects;
public final class Icon implements Parcelable {
    private static final String TAG = "Icon";

    /** @hide */
    /**
     * An icon that was created using {@link Icon#createWithBitmap(Bitmap)}.
     * @see #getType
     */
    public static final int TYPE_BITMAP   = 1;
    /** @hide */
    /**
     * An icon that was created using {@link Icon#createWithResource}.
     * @see #getType
     */
    public static final int TYPE_RESOURCE = 2;
    /** @hide */
    /**
     * An icon that was created using {@link Icon#createWithData(byte[], int, int)}.
     * @see #getType
     */
    public static final int TYPE_DATA     = 3;
    /** @hide */
    /**
     * An icon that was created using {@link Icon#createWithContentUri}
     * or {@link Icon#createWithFilePath(String)}.
     * @see #getType
     */
    public static final int TYPE_URI      = 4;
    /** @hide */
    /**
     * An icon that was created using {@link Icon#createWithAdaptiveBitmap}.
     * @see #getType
     */
    public static final int TYPE_ADAPTIVE_BITMAP = 5;

    /**
     * @hide
     */
    @IntDef({TYPE_BITMAP, TYPE_RESOURCE, TYPE_DATA, TYPE_URI, TYPE_ADAPTIVE_BITMAP})
    public @interface IconType {
    }

    private static final int VERSION_STREAM_SERIALIZER = 1;

    private final int mType;
@@ -99,14 +125,12 @@ public final class Icon implements Parcelable {
    private int             mInt2;

    /**
     * @return The type of image data held in this Icon. One of
     * {@link #TYPE_BITMAP},
     * {@link #TYPE_RESOURCE},
     * {@link #TYPE_DATA}, or
     * {@link #TYPE_URI}.
     * {@link #TYPE_ADAPTIVE_BITMAP}
     * @hide
     * Gets the type of the icon provided.
     * <p>
     * Note that new types may be added later, so callers should guard against other
     * types being returned.
     */
    @IconType
    public int getType() {
        return mType;
    }
@@ -179,9 +203,13 @@ public final class Icon implements Parcelable {
    }

    /**
     * @return The package containing resources for this {@link #TYPE_RESOURCE} Icon.
     * @hide
     * Gets the package used to create this icon.
     * <p>
     * Only valid for icons of type {@link #TYPE_RESOURCE}.
     * Note: This package may not be available if referenced in the future, and it is
     * up to the caller to ensure safety if this package is re-used and/or persisted.
     */
    @NonNull
    public String getResPackage() {
        if (mType != TYPE_RESOURCE) {
            throw new IllegalStateException("called getResPackage() on " + this);
@@ -190,9 +218,13 @@ public final class Icon implements Parcelable {
    }

    /**
     * @return The resource ID for this {@link #TYPE_RESOURCE} Icon.
     * @hide
     * Gets the resource used to create this icon.
     * <p>
     * Only valid for icons of type {@link #TYPE_RESOURCE}.
     * Note: This resource may not be available if the application changes at all, and it is
     * up to the caller to ensure safety if this resource is re-used and/or persisted.
     */
    @IdRes
    public int getResId() {
        if (mType != TYPE_RESOURCE) {
            throw new IllegalStateException("called getResId() on " + this);
@@ -212,9 +244,13 @@ public final class Icon implements Parcelable {
    }

    /**
     * @return The {@link android.net.Uri} for this {@link #TYPE_URI} Icon.
     * @hide
     * Gets the uri used to create this icon.
     * <p>
     * Only valid for icons of type {@link #TYPE_URI}.
     * Note: This uri may not be available in the future, and it is
     * up to the caller to ensure safety if this uri is re-used and/or persisted.
     */
    @NonNull
    public Uri getUri() {
        return Uri.parse(getUriString());
    }