源码整理
This commit is contained in:
@@ -126,6 +126,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
|
|
||||||
// 设置图片背景色
|
// 设置图片背景色
|
||||||
mBgColor = bean.getPixelColor();
|
mBgColor = bean.getPixelColor();
|
||||||
|
LogUtils.d(TAG, String.format("loadByBackgroundBean() 背景色设置为 0x%08X", mBgColor));
|
||||||
|
|
||||||
// 判断是否使用背景文件
|
// 判断是否使用背景文件
|
||||||
if (!bean.isUseBackgroundFile()) {
|
if (!bean.isUseBackgroundFile()) {
|
||||||
@@ -138,7 +139,8 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
String targetPath = bean.isUseBackgroundScaledCompressFile()
|
String targetPath = bean.isUseBackgroundScaledCompressFile()
|
||||||
? bean.getBackgroundScaledCompressFilePath()
|
? bean.getBackgroundScaledCompressFilePath()
|
||||||
: bean.getBackgroundFilePath();
|
: bean.getBackgroundFilePath();
|
||||||
LogUtils.d(TAG, String.format("loadByBackgroundBean() 目标路径=%s", targetPath));
|
LogUtils.d(TAG, String.format("loadByBackgroundBean() 目标路径=%s | 使用压缩文件=%b",
|
||||||
|
targetPath, bean.isUseBackgroundScaledCompressFile()));
|
||||||
|
|
||||||
// 校验文件是否存在
|
// 校验文件是否存在
|
||||||
File targetFile = new File(targetPath);
|
File targetFile = new File(targetPath);
|
||||||
@@ -151,7 +153,8 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadImage(int bgColor, String imagePath, boolean isRefresh) {
|
public void loadImage(int bgColor, String imagePath, boolean isRefresh) {
|
||||||
LogUtils.d(TAG, String.format("loadImage() 启动 | bgColor=0x%08X | imagePath=%s | isRefresh=%b", bgColor, imagePath, isRefresh));
|
LogUtils.d(TAG, String.format("loadImage() 启动 | bgColor=0x%08X | imagePath=%s | isRefresh=%b",
|
||||||
|
bgColor, imagePath, isRefresh));
|
||||||
// 隐藏ImageView防止闪烁
|
// 隐藏ImageView防止闪烁
|
||||||
mIvBackground.setVisibility(View.GONE);
|
mIvBackground.setVisibility(View.GONE);
|
||||||
|
|
||||||
@@ -168,24 +171,25 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
// 刷新逻辑:重新解码原始品质图片并更新缓存
|
// 刷新逻辑:重新解码原始品质图片并更新缓存
|
||||||
if (isRefresh) {
|
if (isRefresh) {
|
||||||
LogUtils.d(TAG, "loadImage() 执行刷新逻辑:重新解码原始品质图片");
|
LogUtils.d(TAG, "loadImage() 执行刷新逻辑:重新解码原始品质图片");
|
||||||
Bitmap newBitmap = decodeOriginalBitmap(new File(imagePath));
|
File imageFile = new File(imagePath);
|
||||||
// 合成纯色背景图片
|
Bitmap newBitmap = decodeOriginalBitmap(imageFile);
|
||||||
// Bitmap combinedBitmap = ImageUtils.drawBitmapOnSolidBackground(bgColor,
|
LogUtils.d(TAG, String.format("loadImage() 原始图片解码完成 | newBitmap=%s",
|
||||||
// appConfigUtils.mAppConfigBean.getDefaultFrameWidth(),
|
newBitmap != null ? newBitmap.getWidth() + "x" + newBitmap.getHeight() : "null"));
|
||||||
// appConfigUtils.mAppConfigBean.getDefaultFrameHeight(),
|
|
||||||
// newBitmap);
|
// 合成纯色背景图片(固定尺寸1197x2287)
|
||||||
Bitmap combinedBitmap = ImageUtils.drawBitmapOnSolidBackground(bgColor,
|
Bitmap combinedBitmap = ImageUtils.drawBitmapOnSolidBackground(bgColor,
|
||||||
1197,
|
1197,
|
||||||
2287,
|
2287,
|
||||||
newBitmap);
|
newBitmap);
|
||||||
|
|
||||||
if (combinedBitmap == null) {
|
if (combinedBitmap == null) {
|
||||||
ToastUtils.show("合成背景图片失败,使用原始图片");
|
ToastUtils.show("合成背景图片失败,使用原始图片");
|
||||||
LogUtils.e(TAG, "loadImage() 纯色背景合成失败,使用原始Bitmap");
|
LogUtils.e(TAG, "loadImage() 纯色背景合成失败,使用原始Bitmap");
|
||||||
combinedBitmap = newBitmap;
|
combinedBitmap = newBitmap;
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.show("合成背景图片成功");
|
ToastUtils.show("合成背景图片成功");
|
||||||
LogUtils.d(TAG, "loadImage() 纯色背景合成成功");
|
LogUtils.d(TAG, String.format("loadImage() 纯色背景合成成功 | combinedBitmap=%dx%d",
|
||||||
|
combinedBitmap.getWidth(), combinedBitmap.getHeight()));
|
||||||
// 回收原始Bitmap(避免重复缓存)
|
// 回收原始Bitmap(避免重复缓存)
|
||||||
if (newBitmap != null && !newBitmap.isRecycled() && newBitmap != combinedBitmap) {
|
if (newBitmap != null && !newBitmap.isRecycled() && newBitmap != combinedBitmap) {
|
||||||
newBitmap.recycle();
|
newBitmap.recycle();
|
||||||
@@ -206,6 +210,8 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
|
|
||||||
// 加载缓存图片
|
// 加载缓存图片
|
||||||
Bitmap cachedBitmap = App.sBitmapCacheUtils.getCachedBitmap(imagePath);
|
Bitmap cachedBitmap = App.sBitmapCacheUtils.getCachedBitmap(imagePath);
|
||||||
|
LogUtils.d(TAG, String.format("loadImage() 加载缓存图片 | cachedBitmap=%s",
|
||||||
|
cachedBitmap != null ? cachedBitmap.getWidth() + "x" + cachedBitmap.getHeight() : "null"));
|
||||||
mIvBackground.setImageBitmap(cachedBitmap);
|
mIvBackground.setImageBitmap(cachedBitmap);
|
||||||
mIvBackground.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
mIvBackground.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||||
mIvBackground.setVisibility(View.VISIBLE);
|
mIvBackground.setVisibility(View.VISIBLE);
|
||||||
|
|||||||
Reference in New Issue
Block a user