diff options
author | Austin Wang <wangaustin@google.com> | 2023-03-31 18:19:55 +0800 |
---|---|---|
committer | Austin Wang <wangaustin@google.com> | 2023-04-06 07:19:16 +0000 |
commit | e5005ee41ee3c143be7feb12b4d88cc425cf069f (patch) | |
tree | d38adc29df98c4e3aff1f85565ce99c6947e0bbd | |
parent | 6e393258111e9a3c413347621f37f8c44ebc3dc0 (diff) |
Calculate LiveWallpaper thumbnail raw dimension
`LiveWallpaper` has no implementation to calculate the raw thumbnail
dimension, in this case when saving the thumbnail it's stretched to fill
the thumbnail tile size (based on display width) instead of scale to fit
in the tile size.
Bug: 276238490
Test: set livewallpaper from inner/outer screen
Change-Id: I03d774c1554cac989d02d9959124e525a52c6a76
-rwxr-xr-x | src/com/android/wallpaper/asset/LiveWallpaperThumbAsset.java | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/com/android/wallpaper/asset/LiveWallpaperThumbAsset.java b/src/com/android/wallpaper/asset/LiveWallpaperThumbAsset.java index 1f4fb674..3e4d58bd 100755 --- a/src/com/android/wallpaper/asset/LiveWallpaperThumbAsset.java +++ b/src/com/android/wallpaper/asset/LiveWallpaperThumbAsset.java @@ -21,16 +21,21 @@ import android.content.res.AssetFileDescriptor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; +import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.util.Log; import android.widget.ImageView; import androidx.annotation.WorkerThread; +import com.android.wallpaper.module.DrawableLayerResolver; +import com.android.wallpaper.module.InjectorProvider; + import com.bumptech.glide.Glide; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.MultiTransformation; @@ -59,6 +64,7 @@ public class LiveWallpaperThumbAsset extends Asset { protected final Context mContext; protected final android.app.WallpaperInfo mInfo; + protected final DrawableLayerResolver mLayerResolver; // The content Uri of thumbnail protected Uri mUri; private Drawable mThumbnailDrawable; @@ -66,6 +72,7 @@ public class LiveWallpaperThumbAsset extends Asset { public LiveWallpaperThumbAsset(Context context, android.app.WallpaperInfo info) { mContext = context.getApplicationContext(); mInfo = info; + mLayerResolver = InjectorProvider.getInjector().getDrawableLayerResolver(); } public LiveWallpaperThumbAsset(Context context, android.app.WallpaperInfo info, Uri uri) { @@ -114,7 +121,21 @@ public class LiveWallpaperThumbAsset extends Asset { @Override public void decodeRawDimensions(Activity unused, DimensionsReceiver receiver) { - receiver.onDimensionsDecoded(null); + // TODO(b/277166654): Reuse the logic for all thumb asset decoding + sExecutorService.execute(() -> { + Bitmap result = null; + Drawable thumb = mInfo.loadThumbnail(mContext.getPackageManager()); + if (thumb instanceof BitmapDrawable) { + result = ((BitmapDrawable) thumb).getBitmap(); + } else if (thumb instanceof LayerDrawable) { + Drawable layer = mLayerResolver.resolveLayer((LayerDrawable) thumb); + if (layer instanceof BitmapDrawable) { + result = ((BitmapDrawable) layer).getBitmap(); + } + } + receiver.onDimensionsDecoded( + result == null ? null : new Point(result.getWidth(), result.getHeight())); + }); } @Override |