From 2a2c00626426dbf991d3d8d0c406497b894aa871 Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Thu, 4 Dec 2025 16:33:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=8B=BE=E5=8F=96=EF=BC=8C?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=A3=81=E5=89=AA=E4=B8=8E=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=B5=81=E7=A8=8B=E6=B5=8B=E8=AF=95=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- powerbell/build.properties | 4 +- .../BackgroundSettingsActivity.java | 131 +++++------------- 2 files changed, 34 insertions(+), 101 deletions(-) diff --git a/powerbell/build.properties b/powerbell/build.properties index d83c9e80..c287cc33 100644 --- a/powerbell/build.properties +++ b/powerbell/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Thu Dec 04 08:21:41 GMT 2025 +#Thu Dec 04 08:31:49 GMT 2025 stageCount=13 libraryProject= baseVersion=15.11 publishVersion=15.11.12 -buildCount=229 +buildCount=232 baseBetaVersion=15.11.13 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 7d376259..cc315373 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 @@ -48,7 +48,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg private AToolbar mAToolbar; private BackgroundView mBackgroundView; private File mfTakePhoto; - boolean isCommitSettings = false; + volatile boolean isCommitSettings = false; @Override public Activity getActivity() { @@ -235,13 +235,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg public void onClick(View v) { LogUtils.d(TAG, "【按钮点击】固定比例裁剪"); // 调用裁剪工具类:传入上下文、预览图、固定比例(按视图宽高)、请求码 - startSystemCrop( - mBgSourceUtils.getPreviewBackgroundBean(), - mBackgroundView.getWidth(), - mBackgroundView.getHeight(), - false, - REQUEST_CROP_IMAGE - ); + ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this, + mBgSourceUtils.getPreviewBackgroundBean(), + mBackgroundView.getWidth(), + mBackgroundView.getHeight(), + false, + REQUEST_CROP_IMAGE + ); } }; @@ -250,13 +250,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg public void onClick(View v) { LogUtils.d(TAG, "【按钮点击】自由裁剪"); // 调用裁剪工具类:传入上下文、预览图、自由裁剪(比例参数传0)、请求码 - startSystemCrop( - mBgSourceUtils.getPreviewBackgroundBean(), - 0, - 0, - true, - REQUEST_CROP_IMAGE - ); + ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this, + mBgSourceUtils.getPreviewBackgroundBean(), + 0, + 0, + true, + REQUEST_CROP_IMAGE + ); } }; @@ -409,13 +409,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg doubleRefreshPreview(); // 拍照后启动固定比例裁剪(调用工具类) - startSystemCrop( - mBgSourceUtils.getPreviewBackgroundBean(), - mBackgroundView.getWidth(), - mBackgroundView.getHeight(), - false, - REQUEST_CROP_IMAGE - ); + ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this, + mBgSourceUtils.getPreviewBackgroundBean(), + mBackgroundView.getWidth(), + mBackgroundView.getHeight(), + false, + REQUEST_CROP_IMAGE + ); LogUtils.d(TAG, "【拍照完成】已启动裁剪"); } @@ -454,7 +454,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg ToastUtils.show("拍照图片解析失败"); return null; } - + private void handleSelectPictureResult(int resultCode, Intent data) { if (resultCode != RESULT_OK || data == null) { handleOperationCancelOrFail(); @@ -477,17 +477,17 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg } mBgSourceUtils.createCropFileProviderBackgroundBean(selectedImage); - + LogUtils.d(TAG, "【选图同步】路径绑定完成"); // 选图后启动固定比例裁剪(调用工具类) mBgSourceUtils.loadSettings(); - startSystemCrop( - mBgSourceUtils.getPreviewBackgroundBean(), - mBackgroundView.getWidth(), - mBackgroundView.getHeight(), - false, - REQUEST_CROP_IMAGE - ); + ImageCropUtils.startImageCrop(BackgroundSettingsActivity.this, + mBgSourceUtils.getPreviewBackgroundBean(), + mBackgroundView.getWidth(), + mBackgroundView.getHeight(), + false, + REQUEST_CROP_IMAGE + ); } private void handleCropImageResult(int requestCode, int resultCode, Intent data) { @@ -719,7 +719,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg * @param isFreeCrop 是否自由裁剪 * @param requestCode 裁剪请求码 */ - + /** * 获取FileProvider Uri(复用方法,避免重复代码) @@ -767,72 +767,5 @@ public class BackgroundSettingsActivity extends WinBoLLActivity implements Backg }); } } - - public void startSystemCrop(BackgroundBean cropBean, int aspectX, int aspectY, boolean isFreeCrop, int requestCode) { - - LogUtils.d(TAG, "startSystemCrop: 启动系统裁剪,自由裁剪:" + isFreeCrop); - File srcFile = new File(cropBean.getBackgroundFilePath()); - - // 校验原图 - if (srcFile == null || !srcFile.exists() || srcFile.length() <= 100) { - Toast.makeText(this, "无有效图片可裁剪", Toast.LENGTH_SHORT).show(); - LogUtils.e(TAG, "startSystemCrop: 原图无效"); - return; - } - - // 生成输入Uri - Uri inputUri = getFileProviderUri(srcFile); - if (inputUri == null) { - Toast.makeText(this, "获取图片Uri失败", Toast.LENGTH_SHORT).show(); - LogUtils.e(TAG, "startSystemCrop: 输入Uri生成失败"); - return; - } - - // 生成输出文件(使用BackgroundSourceUtils的压缩路径) - BackgroundSourceUtils bgSourceUtils = BackgroundSourceUtils.getInstance(this); - bgSourceUtils.loadSettings(); - File outputFile = new File(bgSourceUtils.getPreviewBackgroundBean().getBackgroundScaledCompressFilePath()); - if (outputFile == null) { - Toast.makeText(this, "裁剪输出路径无效", Toast.LENGTH_SHORT).show(); - LogUtils.e(TAG, "startSystemCrop: 输出文件为空"); - return; - } - Uri outputUri = getFileProviderUri(outputFile); - - - Uri cropOutPutUri = outputUri; - - Intent intent = new Intent("com.android.camera.action.CROP"); - intent.setDataAndType(inputUri, "image/*"); - //intent.setDataAndType(inputUri, activity.getContentResolver().getType(inputUri)); - intent.putExtra("crop", "true"); - intent.putExtra("noFaceDetection", true); - - if (!isFreeCrop) { - intent.putExtra("aspectX", aspectX); - intent.putExtra("aspectY", aspectY); - } - - // 修复:删除return-data=true,避免与EXTRA_OUTPUT冲突 - // intent.putExtra("return-data", true); - // 修复1:明确禁用return-data,强制写入文件(关键) - intent.putExtra("return-data", false); - intent.putExtra(MediaStore.EXTRA_OUTPUT, cropOutPutUri); - intent.putExtra("scale", true); - // 修复2:启用缩放补全,确保图片适配输出尺寸(兼容性) - intent.putExtra("scaleUpIfNeeded", true); - intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); - // 修复3:授予读写权限,并添加FLAG_GRANT_PERSISTABLE_URI_PERMISSION(适配Android 11+写入权限) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION - | Intent.FLAG_GRANT_WRITE_URI_PERMISSION - | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); - // 修复4:对输出目录授予临时写入权限(解决目录无写入权限问题) - grantUriPermission("com.android.camera", outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - - startActivityForResult(intent, requestCode); - LogUtils.d(TAG, "startSystemCrop: 启动裁剪成功,输入路径:" + srcFile.getAbsolutePath() + ",输出路径:" + outputFile.getAbsolutePath()); - } - - }