20251201_101834_179
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user