From 0ac7580a4c902520aa6f533a99fc84f160cd795b Mon Sep 17 00:00:00 2001 From: Santiago Etchebehere Date: Wed, 21 Aug 2019 16:34:57 -0700 Subject: Make CenterCropBitmapTask public Also change to a less restrictive View type, so it can be used from other classes Bug: 139828164 Change-Id: I5354d82df400417c1c391cadc8160e93f2816bb6 --- src/com/android/wallpaper/asset/Asset.java | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/com/android/wallpaper/asset/Asset.java b/src/com/android/wallpaper/asset/Asset.java index c1d2252..498fad7 100755 --- a/src/com/android/wallpaper/asset/Asset.java +++ b/src/com/android/wallpaper/asset/Asset.java @@ -27,6 +27,7 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; import android.os.AsyncTask; +import android.view.View; import android.widget.ImageView; import androidx.annotation.Nullable; @@ -44,7 +45,7 @@ public abstract class Asset { */ protected static Drawable getPlaceholderDrawable( Context context, ImageView imageView, int placeholderColor) { - Point imageViewDimensions = getImageViewDimensions(imageView); + Point imageViewDimensions = getViewDimensions(imageView); Bitmap placeholderBitmap = Bitmap.createBitmap(imageViewDimensions.x, imageViewDimensions.y, Config.ARGB_8888); placeholderBitmap.eraseColor(placeholderColor); @@ -55,13 +56,10 @@ public abstract class Asset { * Returns the visible height and width in pixels of the provided ImageView, or if it hasn't been * laid out yet, then gets the absolute value of the layout params. */ - private static Point getImageViewDimensions(ImageView imageView) { - int width = imageView.getWidth() > 0 - ? imageView.getWidth() - : Math.abs(imageView.getLayoutParams().width); - int height = imageView.getHeight() > 0 - ? imageView.getHeight() - : Math.abs(imageView.getLayoutParams().height); + private static Point getViewDimensions(View view) { + int width = view.getWidth() > 0 ? view.getWidth() : Math.abs(view.getLayoutParams().width); + int height = view.getHeight() > 0 ? view.getHeight() + : Math.abs(view.getLayoutParams().height); return new Point(width, height); } @@ -191,7 +189,7 @@ public abstract class Asset { final int transitionDurationMillis, @Nullable final DrawableLoadedListener drawableLoadedListener, int placeholderColor) { - Point imageViewDimensions = getImageViewDimensions(imageView); + Point imageViewDimensions = getViewDimensions(imageView); // Transition from a placeholder ColorDrawable to the decoded bitmap when the ImageView in // question is empty. @@ -275,7 +273,7 @@ public abstract class Asset { * Custom AsyncTask which returns a copy of the given bitmap which is center cropped and scaled to * fit in the given ImageView. */ - protected static class CenterCropBitmapTask extends AsyncTask { + public static class CenterCropBitmapTask extends AsyncTask { private Bitmap mBitmap; private BitmapReceiver mBitmapReceiver; @@ -283,12 +281,12 @@ public abstract class Asset { private int mImageViewWidth; private int mImageViewHeight; - public CenterCropBitmapTask(Bitmap bitmap, ImageView imageView, + public CenterCropBitmapTask(Bitmap bitmap, View view, BitmapReceiver bitmapReceiver) { mBitmap = bitmap; mBitmapReceiver = bitmapReceiver; - Point imageViewDimensions = getImageViewDimensions(imageView); + Point imageViewDimensions = getViewDimensions(view); mImageViewWidth = imageViewDimensions.x; mImageViewHeight = imageViewDimensions.y; @@ -307,7 +305,8 @@ public abstract class Asset { (float) bitmapHeight / measuredHeight); Bitmap scaledBitmap = Bitmap.createScaledBitmap( - mBitmap, Math.round(bitmapWidth / scale), Math.round(bitmapHeight / scale), true); + mBitmap, Math.round(bitmapWidth / scale), Math.round(bitmapHeight / scale), + true); int horizontalGutterPx = Math.max(0, (scaledBitmap.getWidth() - measuredWidth) / 2); int verticalGutterPx = Math.max(0, (scaledBitmap.getHeight() - measuredHeight) / 2); -- cgit v1.2.3