源码整理

This commit is contained in:
2025-12-26 18:00:24 +08:00
parent 35f4aa8730
commit f4a2a1585d

View File

@@ -25,7 +25,6 @@ import androidx.core.content.FileProvider;
import cc.winboll.studio.libaes.dialogs.YesNoAlertDialog; import cc.winboll.studio.libaes.dialogs.YesNoAlertDialog;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils; import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.powerbell.App;
import cc.winboll.studio.powerbell.MainActivity; import cc.winboll.studio.powerbell.MainActivity;
import cc.winboll.studio.powerbell.R; import cc.winboll.studio.powerbell.R;
import cc.winboll.studio.powerbell.dialogs.BackgroundPicturePreviewDialog; import cc.winboll.studio.powerbell.dialogs.BackgroundPicturePreviewDialog;
@@ -48,16 +47,19 @@ import java.io.File;
* @Author 豆包&ZhanGSKen<zhangsken@qq.com> * @Author 豆包&ZhanGSKen<zhangsken@qq.com>
*/ */
public class BackgroundSettingsActivity extends WinBoLLActivity { public class BackgroundSettingsActivity extends WinBoLLActivity {
// ====================== 常量定义(按功能分类)====================== // ====================== 常量定义(按功能分类排序======================
public static final String TAG = "BackgroundSettingsActivity"; public static final String TAG = "BackgroundSettingsActivity";
// 系统版本常量 // 系统版本常量
private static final int SDK_VERSION_TIRAMISU = 33; private static final int SDK_VERSION_TIRAMISU = 33;
// 请求码(按功能分组)
// 请求码(按功能分组,从小到大排序)
public static final int REQUEST_SELECT_PICTURE = 0; public static final int REQUEST_SELECT_PICTURE = 0;
public static final int REQUEST_TAKE_PHOTO = 1; public static final int REQUEST_TAKE_PHOTO = 1;
public static final int REQUEST_CROP_IMAGE = 2; public static final int REQUEST_CROP_IMAGE = 2;
private static final int REQUEST_PIXELPICKER = 1001; private static final int REQUEST_PIXELPICKER = 1001;
private static final int REQUEST_CAMERA_PERMISSION = 1004; private static final int REQUEST_CAMERA_PERMISSION = 1004;
// Bitmap解析常量 // Bitmap解析常量
private static final int BITMAP_MAX_SIZE = 2048; private static final int BITMAP_MAX_SIZE = 2048;
private static final int BITMAP_MAX_SAMPLE_SIZE = 16; private static final int BITMAP_MAX_SAMPLE_SIZE = 16;
@@ -66,9 +68,11 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
// 工具类实例 // 工具类实例
private BackgroundSourceUtils mBgSourceUtils; private BackgroundSourceUtils mBgSourceUtils;
private BitmapCacheUtils mBitmapCache; private BitmapCacheUtils mBitmapCache;
// 视图组件 // 视图组件
private Toolbar mToolbar; private Toolbar mToolbar;
private BackgroundView mBackgroundView; private BackgroundView mBackgroundView;
// 状态标记volatile保证多线程可见性 // 状态标记volatile保证多线程可见性
private volatile boolean isCommitSettings = false; private volatile boolean isCommitSettings = false;
private volatile boolean isPreviewBackgroundChanged = false; private volatile boolean isPreviewBackgroundChanged = false;
@@ -92,16 +96,16 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
// 初始化核心组件 // 初始化核心组件
initCoreComponents(); initCoreComponents();
// 初始化界面与事件 // 初始化Toolbar与点击事件
initToolbar(); initToolbar();
initClickListeners(); initClickListeners();
LogUtils.d(TAG, "界面与事件绑定完成"); LogUtils.d(TAG, "onCreate() 视图与事件绑定完成");
// 处理分享意图或初始化预览 // 处理分享意图或初始化预览
handleIntentOrPreview(); handleIntentOrPreview();
// 初始化预览环境并刷新 // 初始化预览环境并刷新
initPreviewEnvironment(); initPreviewEnvironment();
LogUtils.d(TAG, "onCreate() 初始化完成"); LogUtils.d(TAG, "onCreate() 初始化完成");
} }
@@ -124,13 +128,14 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
// 此时已获取真实宽高 // 此时已获取真实宽高
int width = mBackgroundView.getWidth(); int width = mBackgroundView.getWidth();
int height = mBackgroundView.getHeight(); int height = mBackgroundView.getHeight();
LogUtils.d(TAG, String.format("onPostCreate() 获取视图尺寸 | width=%d | height=%d", width, height));
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
AppConfigUtils appConfigUtils = AppConfigUtils.getInstance(BackgroundSettingsActivity.this); AppConfigUtils appConfigUtils = AppConfigUtils.getInstance(BackgroundSettingsActivity.this);
appConfigUtils.loadAppConfig(); appConfigUtils.loadAppConfig();
appConfigUtils.mAppConfigBean.setDefaultFrameWidth(width); appConfigUtils.mAppConfigBean.setDefaultFrameWidth(width);
appConfigUtils.mAppConfigBean.setDefaultFrameHeight(height); appConfigUtils.mAppConfigBean.setDefaultFrameHeight(height);
appConfigUtils.saveAppConfig(); appConfigUtils.saveAppConfig();
LogUtils.d(TAG, String.format("保存默认相框尺寸 | width=%d | height=%d", width, height)); LogUtils.d(TAG, "onPostCreate() 保存默认相框尺寸成功");
doubleRefreshPreview(); doubleRefreshPreview();
} }
} }
@@ -140,24 +145,27 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
LogUtils.d(TAG, String.format("onActivityResult() | requestCode=%d | resultCode=%d", requestCode, resultCode)); LogUtils.d(TAG, String.format("onActivityResult() | requestCode=%d | resultCode=%d | data=%s",
requestCode, resultCode, data != null ? data.toString() : "null"));
try { try {
if (resultCode != RESULT_OK) { if (resultCode != RESULT_OK) {
LogUtils.d(TAG, "结果非RESULT_OK执行取消逻辑"); LogUtils.d(TAG, String.format("onActivityResult() 操作取消 | requestCode=%d", requestCode));
handleOperationCancelOrFail(); handleOperationCancelOrFail();
return; return;
} }
handleActivityResult(requestCode, data); handleActivityResult(requestCode, data);
} catch (Exception e) { } catch (Exception e) {
LogUtils.e(TAG, String.format("onActivityResult() 异常 | requestCode=%d | 异常信息=%s", requestCode, e.getMessage())); LogUtils.e(TAG, String.format("onActivityResult() 异常 | requestCode=%d | 异常信息=%s",
requestCode, e.getMessage()));
ToastUtils.show("操作失败"); ToastUtils.show("操作失败");
} }
} }
@Override @Override
public void finish() { public void finish() {
LogUtils.d(TAG, String.format("finish() | isCommitSettings=%b | isPreviewBackgroundChanged=%b", isCommitSettings, isPreviewBackgroundChanged)); LogUtils.d(TAG, String.format("finish() | isCommitSettings=%b | isPreviewBackgroundChanged=%b",
isCommitSettings, isPreviewBackgroundChanged));
if (isCommitSettings) { if (isCommitSettings) {
super.finish(); super.finish();
} else { } else {
@@ -169,7 +177,8 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
LogUtils.d(TAG, String.format("onRequestPermissionsResult() | requestCode=%d | 权限数量=%d", requestCode, permissions.length)); LogUtils.d(TAG, String.format("onRequestPermissionsResult() | requestCode=%d | 权限数量=%d | 结果数量=%d",
requestCode, permissions.length, grantResults.length));
if (requestCode == REQUEST_CAMERA_PERMISSION) { if (requestCode == REQUEST_CAMERA_PERMISSION) {
handleCameraPermissionResult(grantResults); handleCameraPermissionResult(grantResults);
} }
@@ -883,7 +892,8 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
* @param fileSize 文件大小 * @param fileSize 文件大小
*/ */
private void handleCropFailure(boolean isFileExist, boolean isFileReadable, long fileSize) { private void handleCropFailure(boolean isFileExist, boolean isFileReadable, long fileSize) {
LogUtils.e(TAG, String.format("handleCropFailure() | 裁剪失败,文件状态:存在=%b可读=%b大小=%d", isFileExist, isFileReadable, fileSize)); LogUtils.e(TAG, String.format("handleCropFailure() | 裁剪失败,文件状态:存在=%b可读=%b大小=%d",
isFileExist, isFileReadable, fileSize));
handleOperationCancelOrFail(); handleOperationCancelOrFail();
} }
@@ -939,16 +949,17 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
mBgSourceUtils.commitPreviewSourceToCurrent(); mBgSourceUtils.commitPreviewSourceToCurrent();
isCommitSettings = true; isCommitSettings = true;
finish(); finish();
//App.notifyMessage(TAG, "startActivity");
Intent mainIntent = new Intent(BackgroundSettingsActivity.this, MainActivity.class); Intent mainIntent = new Intent(BackgroundSettingsActivity.this, MainActivity.class);
mainIntent.putExtra(MainActivity.EXTRA_ISRELOAD_BACKGROUNDVIEW, true); mainIntent.putExtra(MainActivity.EXTRA_ISRELOAD_BACKGROUNDVIEW, true);
startActivity(mainIntent); startActivity(mainIntent);
LogUtils.d(TAG, "handleFinishConfirmation() | 确认设置启动MainActivity并刷新背景");
} }
@Override @Override
public void onNo() { public void onNo() {
isCommitSettings = true; isCommitSettings = true;
finish(); finish();
LogUtils.d(TAG, "handleFinishConfirmation() | 取消设置,关闭页面");
} }
}); });
} else { } else {