20251201_101834_179

This commit is contained in:
2025-12-01 10:18:45 +08:00
parent e14744b2ac
commit 04b8906a96
2 changed files with 53 additions and 24 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Mon Dec 01 01:55:32 GMT 2025
#Mon Dec 01 02:15:51 GMT 2025
stageCount=13
libraryProject=
baseVersion=15.11
publishVersion=15.11.12
buildCount=46
buildCount=48
baseBetaVersion=15.11.13

View File

@@ -1069,12 +1069,12 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
return;
}
// 内存优化:大图片缩放
// 内存优化:大图片缩放调整阈值为5MB更适配低内存机型
Bitmap scaledBitmap = bitmap;
int originalSize = bitmap.getByteCount() / 1024 / 1024; // 转换为MB
if (originalSize > 10) { // 超过10MB自动缩放
if (originalSize > 5) { // 超过5MB自动缩放
float scale = 1.0f;
while (scaledBitmap.getByteCount() / 1024 / 1024 > 5) {
while (scaledBitmap.getByteCount() / 1024 / 1024 > 2) { // 缩放至2MB以内
scale -= 0.2f;
if (scale < 0.2f) break;
scaledBitmap = scaleBitmap(scaledBitmap, scale);
@@ -1085,41 +1085,52 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
}
FileOutputStream fos = null;
// 新增:定义裁剪后新文件的文件名(与工具类保持一致的唯一命名规则)
String cropResultFileName = FileUtils.createUniqueFileName(new File("crop_result.jpg"));
try {
// 从工具类获取预览压缩图路径(统一路径管理)
String scaledCompressFilePath = mBgSourceUtils.getPreviewBackgroundScaledCompressFilePath();
File targetFile = new File(scaledCompressFilePath);
// 从工具类获取预览图片目录(统一路径管理)
String backgroundSourceDir = mBgSourceUtils.getBackgroundSourceDirPath();
// 裁剪后新图的目标路径(正式图+压缩图,路径统一)
String cropResultFilePath = backgroundSourceDir + File.separator + cropResultFileName;
String cropCompressFilePath = backgroundSourceDir + File.separator + "ScaledCompress_" + cropResultFileName;
File targetCompressFile = new File(cropCompressFilePath);
// 确保目录存在(调用工具类)
File parentDir = targetFile.getParentFile();
File parentDir = targetCompressFile.getParentFile();
if (!parentDir.exists()) {
mBgSourceUtils.copyFile(new File(""), parentDir);
}
// 清理旧文件(调用工具类)
if (targetFile.exists()) {
mBgSourceUtils.clearOldFileByExternal(targetFile, "旧裁剪结果文件");
if (targetCompressFile.exists()) {
mBgSourceUtils.clearOldFileByExternal(targetCompressFile, "旧裁剪结果文件");
}
targetFile.createNewFile();
mBgSourceUtils.setFilePermissions(targetFile); // 调用工具类设置权限
targetCompressFile.createNewFile();
mBgSourceUtils.setFilePermissions(targetCompressFile); // 调用工具类设置权限
// 压缩保存
fos = new FileOutputStream(targetFile);
Bitmap.CompressFormat format = targetFile.getName().endsWith(".png") ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG;
fos = new FileOutputStream(targetCompressFile);
Bitmap.CompressFormat format = targetCompressFile.getName().endsWith(".png") ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG;
boolean success = scaledBitmap.compress(format, 80, fos);
fos.flush();
fos.getFD().sync();
fos.getFD().sync(); // 强制同步到磁盘确保文件100%保存完成
if (success) {
ToastUtils.show("图片保存成功");
// 同步预览Bean(调用工具类
// 核心修复1同步预览Bean的「文件名+压缩图路径」(两者必须匹配
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
previewBean.setBackgroundScaledCompressFilePath(scaledCompressFilePath);
previewBean.setBackgroundFileName(cropResultFileName); // 同步正式文件名(关键!)
previewBean.setBackgroundScaledCompressFileName("ScaledCompress_" + cropResultFileName); // 同步压缩文件名
previewBean.setBackgroundScaledCompressFilePath(cropCompressFilePath); // 同步压缩路径
previewBean.setIsUseBackgroundFile(true);
mBgSourceUtils.saveSettings();
mBgSourceUtils.saveSettings(); // 持久化配置确保BackgroundView读取时生效
// 同步文件到预览目录(调用工具类
mBgSourceUtils.saveFileToPreviewBean(targetFile, scaledCompressFilePath);
// 核心修复2调用工具类同步新图到预览确保工具类路径与Bean一致
mBgSourceUtils.saveFileToPreviewBean(targetCompressFile, cropCompressFilePath);
// 核心修复3调整刷新时机——文件100%保存完成后,再触发双重刷新(避免过早刷新)
doubleRefreshPreview();
} else {
ToastUtils.show("图片保存失败");
LogUtils.e(TAG, "【保存失败】Bitmap压缩失败");
@@ -1168,14 +1179,32 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg
runOnUiThread(new Runnable() {
@Override
public void run() {
// 新增:校验预览图是否存在(避免文件未保存完成就刷新)
final String previewFilePath = mBgSourceUtils.getPreviewBackgroundFilePath();
File previewFile = new File(previewFilePath);
if (!previewFile.exists() || previewFile.length() <= 100) {
LogUtils.w(TAG, "【预览刷新】预览图未就绪延迟500ms后刷新");
// 延迟500ms重试适配大图片保存延迟
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
bvPreviewBackground.reloadPreviewBackground();
LogUtils.d(TAG, "【预览刷新】延迟重试刷新500ms");
}
}, 500);
return;
}
// 第一次刷新(立即)
bvPreviewBackground.reloadPreviewBackground();
LogUtils.d(TAG, "【预览刷新】第一次刷新(立即)");
// 延迟300ms再次刷新
LogUtils.d(TAG, "【预览刷新】第一次刷新(立即),路径:" + previewFilePath);
// 第二次刷新延迟300ms适配MIUI渲染延迟
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
bvPreviewBackground.reloadPreviewBackground();
LogUtils.d(TAG, "【预览刷新】第二次刷新延迟300ms");
LogUtils.d(TAG, "【预览刷新】第二次刷新延迟300ms,路径:" + previewFilePath);
}
}, 300);
}