From bea80a77251dfc9d09ca7076323447b162a1387d Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Tue, 21 Apr 2020 15:27:05 -0400 Subject: [PATCH] Make BitmapDrawable#setBitmap public Bug: 154628299 Test: I20d4f94a145474394bc660368d9ddd1897001f4a This allows displaying a new Bitmap without paying the cost of creation and GC of the BitmapDrawable. Non-SDK-API usage is low, but this is useful. Previously it was @hide and used by the system. Once BitmapDrawable is in a mainline module, the system can no longer access @hide methods. Change-Id: I6a24b3c5870b0ee7d171aab86257896261b4b8c7 --- api/current.txt | 1 + .../java/android/graphics/drawable/BitmapDrawable.java | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/current.txt b/api/current.txt index 55848001e4c96..a174e6664aa34 100644 --- a/api/current.txt +++ b/api/current.txt @@ -15784,6 +15784,7 @@ package android.graphics.drawable { method public final boolean isAutoMirrored(); method public void setAlpha(int); method public void setAntiAlias(boolean); + method public void setBitmap(@Nullable android.graphics.Bitmap); method public void setColorFilter(android.graphics.ColorFilter); method public void setDither(boolean); method public void setGravity(int); diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index 4e768c9eddfb9..0c04d3f5f7ee8 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -17,6 +17,7 @@ package android.graphics.drawable; import android.annotation.NonNull; +import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; import android.content.pm.ActivityInfo.Config; import android.content.res.ColorStateList; @@ -239,9 +240,10 @@ public class BitmapDrawable extends Drawable { } } - /** @hide */ - @UnsupportedAppUsage - public void setBitmap(Bitmap bitmap) { + /** + * Switch to a new Bitmap object. + */ + public void setBitmap(@Nullable Bitmap bitmap) { if (mBitmapState.mBitmap != bitmap) { mBitmapState.mBitmap = bitmap; computeBitmapSize();