From 03212c05540e2874aabcdbc41af5642fbe1ac77d Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Thu, 11 Dec 2025 19:58:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E6=AC=A1=E4=B8=8D=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E6=B8=85=E7=A9=BA=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BackgroundSettingsActivity.java | 53 ++++++++----------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundSettingsActivity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundSettingsActivity.java index d615d68..2fc4170 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundSettingsActivity.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundSettingsActivity.java @@ -15,19 +15,9 @@ import android.os.Looper; import android.provider.MediaStore; import android.text.TextUtils; import android.view.View; -import android.widget.Toast; - import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.Toolbar; import androidx.core.content.FileProvider; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.ToastUtils; import cc.winboll.studio.powerbell.App; @@ -42,6 +32,11 @@ import cc.winboll.studio.powerbell.utils.ImageCropUtils; import cc.winboll.studio.powerbell.utils.PermissionUtils; import cc.winboll.studio.powerbell.utils.UriUtil; import cc.winboll.studio.powerbell.views.BackgroundView; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; public class BackgroundSettingsActivity extends WinBoLLActivity implements BackgroundPicturePreviewDialog.IOnRecivedPictureListener { @@ -287,10 +282,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg @Override public void onClick(View v) { LogUtils.d(TAG, "【按钮点击】拍照"); - if (mfTakePhoto.exists()) { - boolean deleteSuccess = mfTakePhoto.delete(); - LogUtils.d(TAG, "【拍照准备】清理旧文件:" + (deleteSuccess ? "成功" : "失败")); - } + // 移除:旧文件删除逻辑 try { boolean createSuccess = mfTakePhoto.createNewFile(); LogUtils.d(TAG, "【拍照准备】创建新文件:" + (createSuccess ? "成功" : "失败")); @@ -390,6 +382,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg /** * 双重刷新预览,确保背景加载最新数据 + * 移除:缓存清空逻辑 */ private void doubleRefreshPreview() { LogUtils.d(TAG, "【工具方法】doubleRefreshPreview 开始执行"); @@ -398,15 +391,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg return; } - BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean(); - if (previewBean != null && previewBean.isUseBackgroundFile()) { - String bgPath = previewBean.isUseBackgroundScaledCompressFile() - ? previewBean.getBackgroundScaledCompressFilePath() - : previewBean.getBackgroundFilePath(); - mBitmapCache.removeCachedBitmap(bgPath); - LogUtils.d(TAG, "【双重刷新】已清空工具类缓存:" + bgPath); - } - + // 第一重刷新 try { mBgSourceUtils.loadSettings(); mBackgroundView.loadBackgroundBean(mBgSourceUtils.getPreviewBackgroundBean()); @@ -416,6 +401,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg return; } + // 第二重刷新(延迟执行) new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { @@ -523,6 +509,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg /** * 保存 Bitmap 到目标文件 + * 移除:原文件删除逻辑 */ private void saveScaledBitmapToFile(Bitmap bitmap, File targetFile) { LogUtils.d(TAG, "【工具方法】saveScaledBitmapToFile 保存图片:" + targetFile.getAbsolutePath()); @@ -531,11 +518,6 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg return; } - if (targetFile.exists()) { - boolean deleteSuccess = targetFile.delete(); - LogUtils.d(TAG, "【图片保存】删除原文件:" + (deleteSuccess ? "成功" : "失败")); - } - OutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(targetFile)); @@ -777,6 +759,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg /** * 处理选图结果 + * 移除:缓存清空逻辑 */ private void handleSelectPictureResult(int resultCode, Intent data) { LogUtils.d(TAG, "【业务逻辑】handleSelectPictureResult 处理选图结果"); @@ -802,7 +785,6 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg if (putUriFileToPreviewSource(selectedImage)) { LogUtils.d(TAG, "【选图同步】路径绑定完成"); - mBitmapCache.removeCachedBitmap(mBgSourceUtils.getPreviewBackgroundBean().getBackgroundFilePath()); ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this, mBgSourceUtils.getPreviewBackgroundBean(), mBackgroundView.getWidth(), @@ -831,11 +813,20 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg /** * 将 File 同步到预览 Bean + * 保留:核心修复逻辑(更新预览Bean路径) */ boolean putUriFileToPreviewSource(File srcFile) { - LogUtils.d(TAG, "【业务逻辑】putUriFileToPreviewSource 同步文件:" + srcFile.getAbsolutePath()); + LogUtils.d(TAG, String.format("putUriFileToPreviewSource(File srcFile) srcFile %s", srcFile)); mBgSourceUtils.loadSettings(); - File dstFile = new File(mBgSourceUtils.getPreviewBackgroundBean().getBackgroundFilePath()); + BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean(); + // 核心修复:将预览Bean的路径更新为选中图片的路径 + previewBean.setBackgroundFilePath(srcFile.getAbsolutePath()); + // 同步压缩图路径(避免裁剪输出路径错误) + String compressPath = mBgSourceUtils.getBackgroundSourceDirPath() + "/cache/SelectCompress_" + srcFile.getName(); + previewBean.setBackgroundScaledCompressFilePath(compressPath); + mBgSourceUtils.saveSettings(); // 保存修改后的Bean + + File dstFile = new File(previewBean.getBackgroundFilePath()); return FileUtils.copyFile(srcFile, dstFile); }