20251204_025812_384

This commit is contained in:
2025-12-04 02:58:16 +08:00
parent 59992542c4
commit 8a16728609
3 changed files with 30 additions and 98 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Wed Dec 03 16:25:43 GMT 2025 #Wed Dec 03 18:54:44 GMT 2025
stageCount=13 stageCount=13
libraryProject= libraryProject=
baseVersion=15.11 baseVersion=15.11
publishVersion=15.11.12 publishVersion=15.11.12
buildCount=158 buildCount=178
baseBetaVersion=15.11.13 baseBetaVersion=15.11.13

View File

@@ -780,6 +780,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
* 处理裁剪回调(调用工具类获取裁剪文件) * 处理裁剪回调(调用工具类获取裁剪文件)
*/ */
private void handleCropImageResult(int requestCode, int resultCode, Intent data) { private void handleCropImageResult(int requestCode, int resultCode, Intent data) {
LogUtils.d(TAG, "handleCropImageResult");
// 从工具类获取裁剪临时文件(唯一入口) // 从工具类获取裁剪临时文件(唯一入口)
File cropTempFile = new File(mBgSourceUtils.getPreviewBackgroundBean().getBackgroundScaledCompressFilePath()); File cropTempFile = new File(mBgSourceUtils.getPreviewBackgroundBean().getBackgroundScaledCompressFilePath());
boolean isFileExist = cropTempFile.exists(); boolean isFileExist = cropTempFile.exists();
@@ -788,10 +789,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
// 适配MIUI仅resultCode=RESULT_OK且文件有效时视为成功 // 适配MIUI仅resultCode=RESULT_OK且文件有效时视为成功
boolean isCropSuccess = (resultCode == RESULT_OK) && isFileExist && isFileReadable && fileSize > 100; boolean isCropSuccess = (resultCode == RESULT_OK) && isFileExist && isFileReadable && fileSize > 100;
if (isCropSuccess) { if (isCropSuccess) {
LogUtils.d(TAG, "isCropSuccess == true");
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean(); BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
previewBean.setIsUseBackgroundScaledCompressFile(isCropSuccess); previewBean.setIsUseBackgroundFile(true);
previewBean.setIsUseBackgroundScaledCompressFile(true);
mBgSourceUtils.saveSettings(); mBgSourceUtils.saveSettings();
doubleRefreshPreview(); mBackgroundView.loadBackground(previewBean);
LogUtils.d(TAG, "isCropSuccess == true && mBackgroundView.loadBackground");
} else { } else {
// 其他失败场景 // 其他失败场景
handleOperationCancelOrFail(); handleOperationCancelOrFail();

View File

@@ -34,8 +34,6 @@ public class BackgroundView extends RelativeLayout {
private RelativeLayout mrlMain; private RelativeLayout mrlMain;
// 背景图片显示控件核心子View // 背景图片显示控件核心子View
private ImageView mivBackground; private ImageView mivBackground;
// 背景资源工具类(单例实例,避免重复创建)
private BackgroundSourceUtils mBackgroundSourceUtils;
// 图片原始宽高比(控制图片不拉伸的核心参数,宽/高) // 图片原始宽高比(控制图片不拉伸的核心参数,宽/高)
private float mnImageAspectRatio = 1.0f; private float mnImageAspectRatio = 1.0f;
@@ -99,24 +97,16 @@ public class BackgroundView extends RelativeLayout {
private void initView() { private void initView() {
LogUtils.d(TAG, "=== initView视图初始化启动 ==="); LogUtils.d(TAG, "=== initView视图初始化启动 ===");
//mllMain = inflate(mContext, R.layout.view_background, null); // 1. 配置当前控件:完全填充父视图 + 全透明背景 + 无内边距
// mllMain.setBackgroundColor(0x00000000); // 全透明背景ARGB透明通道+黑色,无视觉影响) setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
// mllMain.setBackground(new ColorDrawable(0x00000000)); // 双重保障兼容Android低版本确保背景透明 setPadding(0, 0, 0, 0); // 取消自身内边距,避免父容器与控件间出现缝隙
// setBackgroundColor(0x00000000); // 全透明背景ARGB透明通道+黑色,无视觉影响)
// 1. 配置当前控件:完全填充父视图 + 全透明背景 + 无内边距 setBackground(new ColorDrawable(0x00000000)); // 双重保障兼容Android低版本确保背景透明
// setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
// setPadding(0, 0, 0, 0); // 取消自身内边距,避免父容器与控件间出现缝隙 initBackgroundImageView();
// setBackgroundColor(0x00000000); // 全透明背景ARGB透明通道+黑色,无视觉影响)
// setBackground(new ColorDrawable(0x00000000)); // 双重保障兼容Android低版本确保背景透明
//
// // 2. 初始化背景资源工具类(单例模式,全局唯一实例)
// mBackgroundSourceUtils = BackgroundSourceUtils.getInstance(mContext);
//
// 3. 初始化内部ImageView背景图片显示核心控件
initBackgroundImageView();
// 4. 初始加载:默认加载正式模式背景 // 4. 初始加载:默认加载正式模式背景
setDefaultBackground(); setDefaultTransparentBackground();
LogUtils.d(TAG, "=== initView视图初始化完成 ==="); LogUtils.d(TAG, "=== initView视图初始化完成 ===");
} }
@@ -129,22 +119,7 @@ public class BackgroundView extends RelativeLayout {
mrlMain = (RelativeLayout)inflate(mContext, R.layout.view_background, null); mrlMain = (RelativeLayout)inflate(mContext, R.layout.view_background, null);
mrlMain.setBackgroundColor(0x00000000); // 全透明背景ARGB透明通道+黑色,无视觉影响) mrlMain.setBackgroundColor(0x00000000); // 全透明背景ARGB透明通道+黑色,无视觉影响)
mrlMain.setBackground(new ColorDrawable(0x00000000)); // 双重保障兼容Android低版本确保背景透明 mrlMain.setBackground(new ColorDrawable(0x00000000)); // 双重保障兼容Android低版本确保背景透明
mivBackground = mrlMain.findViewById(R.id.bg_imageview); mivBackground = mrlMain.findViewById(R.id.bg_imageview);
//mivBackground = new ImageView(mContext);
// 配置ImageView布局参数宽高自适应 + 居中显示 + 无内边距/外边距
// RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
// LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); // 核心让ImageView在当前控件中居中
// layoutParams.setMargins(0, 0, 0, 0); // 取消外边距避免ImageView与控件间出现缝隙
// mivBackground.setLayoutParams(layoutParams);
// 配置ImageView显示属性保持比例 + 全透明背景
// mivBackground.setScaleType(ImageView.ScaleType.FIT_CENTER); // 缩放模式:保持比例,完整显示图片
// mivBackground.setPadding(0, 0, 0, 0); // 取消内边距避免图片与ImageView间出现缝隙
// mivBackground.setBackgroundColor(0x00000000); // ImageView自身背景全透明
// mivBackground.setBackground(new ColorDrawable(0x00000000)); // 低版本兼容,确保透明
// 将ImageView添加到当前控件父容器 // 将ImageView添加到当前控件父容器
this.addView(mrlMain); this.addView(mrlMain);
LogUtils.d(TAG, "=== initBackgroundImageView内部ImageView初始化完成 ==="); LogUtils.d(TAG, "=== initBackgroundImageView内部ImageView初始化完成 ===");
@@ -157,31 +132,15 @@ public class BackgroundView extends RelativeLayout {
public void loadBackground(BackgroundBean backgroundBean) { public void loadBackground(BackgroundBean backgroundBean) {
LogUtils.d(TAG, "=== loadBackground加载预览背景启动 ==="); LogUtils.d(TAG, "=== loadBackground加载预览背景启动 ===");
// 校验预览Bean是否为空为空则直接显示默认背景 // 校验预览Bean是否为空为空则直接显示默认背景
if (backgroundBean == null || backgroundBean.isUseBackgroundFile()) { if (backgroundBean == null || !backgroundBean.isUseBackgroundFile()) {
LogUtils.e(TAG, "【loadBackground】预览Bean为空正在加载默认图片"); LogUtils.e(TAG, "【loadBackground】预览Bean为空正在加载默认图片");
setDefaultBackground(); setDefaultTransparentBackground();
return;
} else if (backgroundBean.isUseBackgroundFile()) {
LogUtils.e(TAG, "【loadBackground】设置为不使用图片正在加载默认图片");
setDefaultBackground();
return; return;
} }
// 加载背景图片路径 // 加载背景图片路径
String szBackgroundPath = backgroundBean.isUseBackgroundScaledCompressFile() ? backgroundBean.getBackgroundScaledCompressFilePath() : backgroundBean.getBackgroundFilePath(); String szBackgroundPath = backgroundBean.isUseBackgroundScaledCompressFile() ? backgroundBean.getBackgroundScaledCompressFilePath() : backgroundBean.getBackgroundFilePath();
loadAndSetImageViewBackground(szBackgroundPath); loadAndSetImageViewBackground(szBackgroundPath);
LogUtils.d(TAG, "=== loadBackground 加载背景完成===");
}
/**
* 预览模式兜底:设置默认透明背景(无有效图片时使用,避免显示白色背景)
*/
public void setDefaultBackground() {
LogUtils.d(TAG, "=== setDefaultBackground设置预览默认透明背景启动 ===");
setBackgroundColor(0x00000000); // 当前控件背景全透明
adjustImageViewSize(); // 调整ImageView尺寸确保居中且不占位异常
LogUtils.d(TAG, "【setDefaultBackground】已设置预览默认透明背景");
LogUtils.d(TAG, "=== setDefaultBackground设置预览默认透明背景完成 ===");
} }
/** /**
@@ -190,12 +149,13 @@ public class BackgroundView extends RelativeLayout {
* @param imagePath 图片绝对路径(可为空) * @param imagePath 图片绝对路径(可为空)
*/ */
private void loadAndSetImageViewBackground(String imagePath) { private void loadAndSetImageViewBackground(String imagePath) {
LogUtils.d(TAG, "=== loadAndSetImageViewBackground加载并设置图片启动 ==="); LogUtils.d(TAG, "=== loadAndSetImageViewBackground加载并设置图片启动 ===");
LogUtils.d(TAG, String.format("imagePath %s", imagePath));
// 1. 路径校验:路径为空/空字符串,直接显示默认透明背景 // 1. 路径校验:路径为空/空字符串,直接显示默认透明背景
if (imagePath == null || imagePath.isEmpty()) { if (imagePath == null || imagePath.isEmpty()) {
LogUtils.e(TAG, "【loadAndSetImageViewBackground】加载失败图片路径为空"); LogUtils.e(TAG, "【loadAndSetImageViewBackground】加载失败图片路径为空");
setDefaultTransparentBackground(); setDefaultTransparentBackground();
LogUtils.d(TAG, "=== loadAndSetImageViewBackground加载并设置图片完成路径为空===");
return; return;
} }
@@ -204,7 +164,6 @@ public class BackgroundView extends RelativeLayout {
if (!backgroundFile.exists() || !backgroundFile.isFile()) { if (!backgroundFile.exists() || !backgroundFile.isFile()) {
LogUtils.e(TAG, "【loadAndSetImageViewBackground】加载失败文件不存在或无效路径" + imagePath); LogUtils.e(TAG, "【loadAndSetImageViewBackground】加载失败文件不存在或无效路径" + imagePath);
setDefaultTransparentBackground(); setDefaultTransparentBackground();
LogUtils.d(TAG, "=== loadAndSetImageViewBackground加载并设置图片完成文件无效===");
return; return;
} }
@@ -212,7 +171,6 @@ public class BackgroundView extends RelativeLayout {
if (!calculateImageAspectRatio(backgroundFile)) { if (!calculateImageAspectRatio(backgroundFile)) {
LogUtils.e(TAG, "【loadAndSetImageViewBackground】加载失败图片宽高比计算失败路径" + imagePath); LogUtils.e(TAG, "【loadAndSetImageViewBackground】加载失败图片宽高比计算失败路径" + imagePath);
setDefaultTransparentBackground(); setDefaultTransparentBackground();
LogUtils.d(TAG, "=== loadAndSetImageViewBackground加载并设置图片完成宽高比计算失败===");
return; return;
} }
@@ -221,17 +179,13 @@ public class BackgroundView extends RelativeLayout {
if (bitmap == null) { if (bitmap == null) {
LogUtils.e(TAG, "【loadAndSetImageViewBackground】加载失败图片压缩加载失败路径" + imagePath); LogUtils.e(TAG, "【loadAndSetImageViewBackground】加载失败图片压缩加载失败路径" + imagePath);
setDefaultTransparentBackground(); setDefaultTransparentBackground();
LogUtils.d(TAG, "=== loadAndSetImageViewBackground加载并设置图片完成Bitmap加载失败==="); return;
return;
} }
// 5. 设置图片到ImageView兼容低版本系统 // 5. 设置图片到ImageView兼容低版本系统
Drawable backgroundDrawable = new BitmapDrawable(mContext.getResources(), bitmap); Drawable backgroundDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { mivBackground.setImageDrawable(backgroundDrawable);
mivBackground.setBackground(backgroundDrawable); // API 16+ 方法
} else {
mivBackground.setBackgroundDrawable(backgroundDrawable); // 低版本兼容方法
}
// 6. 调整ImageView尺寸按图片比例扩展到父控件确保不拉伸 // 6. 调整ImageView尺寸按图片比例扩展到父控件确保不拉伸
adjustImageViewSize(); adjustImageViewSize();
@@ -262,19 +216,14 @@ public class BackgroundView extends RelativeLayout {
// 校验宽高有效性(宽/高必须大于0否则视为无效图片 // 校验宽高有效性(宽/高必须大于0否则视为无效图片
if (imageWidth <= 0 || imageHeight <= 0) { if (imageWidth <= 0 || imageHeight <= 0) {
LogUtils.e(TAG, "【calculateImageAspectRatio】计算失败图片尺寸无效" + imageWidth + ",高:" + imageHeight); LogUtils.e(TAG, "【calculateImageAspectRatio】计算失败图片尺寸无效" + imageWidth + ",高:" + imageHeight);
LogUtils.d(TAG, "=== calculateImageAspectRatio计算图片宽高比完成尺寸无效==="); return false;
return false;
} }
// 计算并保存图片原始宽高比(宽/高) // 计算并保存图片原始宽高比(宽/高)
mnImageAspectRatio = (float) imageWidth / imageHeight; mnImageAspectRatio = (float) imageWidth / imageHeight;
LogUtils.d(TAG, "【calculateImageAspectRatio】计算成功"); LogUtils.d(TAG, "【calculateImageAspectRatio】计算成功");
LogUtils.d(TAG, "→ 图片原始尺寸:" + imageWidth + "x" + imageHeight);
LogUtils.d(TAG, "→ 图片宽高比:" + mnImageAspectRatio);
LogUtils.d(TAG, "=== calculateImageAspectRatio计算图片宽高比完成计算成功===");
return true; return true;
} catch (Exception e) { } catch (Exception e) {
LogUtils.e(TAG, "【calculateImageAspectRatio】计算失败" + e.getMessage(), e);
LogUtils.d(TAG, "=== calculateImageAspectRatio计算图片宽高比完成发生异常==="); LogUtils.d(TAG, "=== calculateImageAspectRatio计算图片宽高比完成发生异常===");
return false; return false;
} }
@@ -286,17 +235,10 @@ public class BackgroundView extends RelativeLayout {
* 适配场景:控件初始化、图片加载后、父容器尺寸变化(如屏幕旋转) * 适配场景:控件初始化、图片加载后、父容器尺寸变化(如屏幕旋转)
*/ */
private void adjustImageViewSize() { private void adjustImageViewSize() {
LogUtils.d(TAG, "=== adjustImageViewSize调整ImageView尺寸启动 ===");
// 1. 绑定布局控件匹配xml中bg_main容器和bg_imageview
if (mrlMain == null || mivBackground == null) {
LogUtils.e(TAG, "【调整失败】布局控件绑定失败bg_main或bg_imageview为空");
return;
}
// 2. 获取根容器bg_main尺寸以bg_main为基准实现居中平铺 // 2. 获取根容器bg_main尺寸以bg_main为基准实现居中平铺
int parentWidth = mrlMain.getWidth(); int parentWidth = mrlMain.getWidth();
int parentHeight = mrlMain.getHeight(); int parentHeight = mrlMain.getHeight();
// 3. bg_main未测量完成宽/高为0延迟调整避免尺寸计算错误 // 3. bg_main未测量完成宽/高为0延迟调整避免尺寸计算错误
if (parentWidth == 0 || parentHeight == 0) { if (parentWidth == 0 || parentHeight == 0) {
postDelayed(new Runnable() { postDelayed(new Runnable() {
@@ -333,19 +275,11 @@ public class BackgroundView extends RelativeLayout {
mivBackground.setLayoutParams(layoutParams); mivBackground.setLayoutParams(layoutParams);
// 6. 关键设置缩放模式匹配xml布局+保持比例+居中平铺) // 6. 关键设置缩放模式匹配xml布局+保持比例+居中平铺)
mivBackground.setScaleType(ImageView.ScaleType.FIT_CENTER); mivBackground.setScaleType(ImageView.ScaleType.MATRIX);
// 确保ImageView背景透明避免遮挡适配布局视觉效果 // 确保ImageView背景透明避免遮挡适配布局视觉效果
mivBackground.setBackgroundColor(0x00000000); mivBackground.setBackgroundColor(0x00000000);
LogUtils.d(TAG, "【适配布局】设置FIT_CENTER缩放模式+透明背景匹配xml布局的居中平铺需求");
// 7. 日志验证(确保比例一致+适配成功)
LogUtils.d(TAG, "【adjustImageViewSize】尺寸调整成功适配bg_main布局保持原图比例+居中平铺)");
LogUtils.d(TAG, "→ bg_main容器尺寸" + parentWidth + "x" + parentHeight);
LogUtils.d(TAG, "→ bg_imageview调整后尺寸" + imageViewWidth + "x" + imageViewHeight);
LogUtils.d(TAG, "→ 原图宽高比:" + mnImageAspectRatio + ",调整后宽高比:" + (float)imageViewWidth/imageViewHeight); // 验证比例无变形
LogUtils.d(TAG, "=== adjustImageViewSize调整ImageView尺寸完成调整成功===");
} }
/** /**
* 带压缩的Bitmap解码通用方法 * 带压缩的Bitmap解码通用方法
@@ -402,9 +336,6 @@ public class BackgroundView extends RelativeLayout {
mivBackground.setBackground(new ColorDrawable(0x00000000)); // ImageView背景全透明 mivBackground.setBackground(new ColorDrawable(0x00000000)); // ImageView背景全透明
mivBackground.setImageBitmap(null); // 清空ImageView的图片 mivBackground.setImageBitmap(null); // 清空ImageView的图片
mnImageAspectRatio = 1.0f; // 重置宽高比(避免影响下次图片加载) mnImageAspectRatio = 1.0f; // 重置宽高比(避免影响下次图片加载)
adjustImageViewSize(); // 调整ImageView尺寸确保居中且不占位异常
LogUtils.d(TAG, "【setDefaultTransparentBackground】已设置通用默认透明背景");
LogUtils.d(TAG, "=== setDefaultTransparentBackground设置通用默认透明背景完成 ===");
} }
// ====================================== 重写父类方法 ====================================== // ====================================== 重写父类方法 ======================================
@@ -419,10 +350,7 @@ public class BackgroundView extends RelativeLayout {
@Override @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);
LogUtils.d(TAG, "=== onSizeChanged控件尺寸变化启动 ===");
LogUtils.d(TAG, "【onSizeChanged】尺寸变化旧尺寸=" + oldw + "x" + oldh + ",新尺寸=" + w + "x" + h);
adjustImageViewSize(); // 重新调整ImageView尺寸适配新的控件尺寸 adjustImageViewSize(); // 重新调整ImageView尺寸适配新的控件尺寸
LogUtils.d(TAG, "=== onSizeChanged控件尺寸变化完成 ==="); }
}
} }