源码整理
This commit is contained in:
@@ -86,7 +86,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
LogUtils.d(TAG, "生命周期 onCreate 开始初始化");
|
LogUtils.d(TAG, "生命周期 onCreate() 开始初始化");
|
||||||
setContentView(R.layout.activity_background_settings);
|
setContentView(R.layout.activity_background_settings);
|
||||||
|
|
||||||
// 初始化核心组件
|
// 初始化核心组件
|
||||||
@@ -101,33 +101,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
|
|
||||||
// 初始化预览环境并刷新
|
// 初始化预览环境并刷新
|
||||||
initPreviewEnvironment();
|
initPreviewEnvironment();
|
||||||
LogUtils.d(TAG, "生命周期 onCreate 初始化完成");
|
LogUtils.d(TAG, "生命周期 onCreate() 初始化完成");
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// protected void onPostCreate(Bundle savedInstanceState) {
|
|
||||||
// super.onPostCreate(savedInstanceState);
|
|
||||||
// LogUtils.d(TAG, "生命周期 onPostCreate 执行双重刷新预览");
|
|
||||||
//
|
|
||||||
// // 初始化配置工具类并保存默认相框尺寸
|
|
||||||
// AppConfigUtils appConfigUtils = AppConfigUtils.getInstance(this);
|
|
||||||
// appConfigUtils.loadAppConfig();
|
|
||||||
// if (mBackgroundView.getWidth() > -1 && mBackgroundView.getHeight() > -1) {
|
|
||||||
// ToastUtils.show("mBackgroundView.getWidth() > 0 && mBackgroundView.getHeight() > 0");
|
|
||||||
// appConfigUtils.mAppConfigBean.setDefaultFrameWidth(mBackgroundView.getWidth());
|
|
||||||
// appConfigUtils.mAppConfigBean.setDefaultFrameHeight(mBackgroundView.getHeight());
|
|
||||||
// appConfigUtils.saveAppConfig();
|
|
||||||
// LogUtils.d(TAG, String.format("loadImage() 保存默认相框尺寸 | width=%d | height=%d", mBackgroundView.getWidth(), mBackgroundView.getHeight()));
|
|
||||||
// }
|
|
||||||
// LogUtils.d(TAG, String.format("mBackgroundView is %s", mBackgroundView));
|
|
||||||
// LogUtils.d(TAG, String.format("mBackgroundView.getWidth() %d, mBackgroundView.getHeight() %d", mBackgroundView.getWidth(), mBackgroundView.getHeight()));
|
|
||||||
// doubleRefreshPreview();
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostCreate(Bundle savedInstanceState) {
|
protected void onPostCreate(Bundle savedInstanceState) {
|
||||||
super.onPostCreate(savedInstanceState);
|
super.onPostCreate(savedInstanceState);
|
||||||
LogUtils.d(TAG, "生命周期 onPostCreate 执行双重刷新预览");
|
LogUtils.d(TAG, "生命周期 onPostCreate() 执行双重刷新预览");
|
||||||
|
|
||||||
// 监听视图布局完成事件
|
// 监听视图布局完成事件
|
||||||
mBackgroundView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
mBackgroundView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
@@ -156,11 +136,10 @@ 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("回调触发 requestCode=%d,resultCode=%d", requestCode, resultCode));
|
LogUtils.d(TAG, String.format("回调触发 onActivityResult() | requestCode=%d | resultCode=%d", requestCode, resultCode));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (resultCode != RESULT_OK) {
|
if (resultCode != RESULT_OK) {
|
||||||
@@ -170,14 +149,14 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
}
|
}
|
||||||
handleActivityResult(requestCode, data);
|
handleActivityResult(requestCode, data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, String.format("回调异常 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 {
|
||||||
@@ -189,7 +168,7 @@ 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("权限回调 requestCode=%d,权限数量=%d", requestCode, permissions.length));
|
LogUtils.d(TAG, String.format("权限回调 onRequestPermissionsResult() | requestCode=%d | 权限数量=%d", requestCode, permissions.length));
|
||||||
if (requestCode == REQUEST_CAMERA_PERMISSION) {
|
if (requestCode == REQUEST_CAMERA_PERMISSION) {
|
||||||
handleCameraPermissionResult(grantResults);
|
handleCameraPermissionResult(grantResults);
|
||||||
}
|
}
|
||||||
@@ -199,7 +178,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private void initToolbar() {
|
private void initToolbar() {
|
||||||
mToolbar = findViewById(R.id.toolbar);
|
mToolbar = findViewById(R.id.toolbar);
|
||||||
if (mToolbar == null) {
|
if (mToolbar == null) {
|
||||||
LogUtils.e(TAG, "初始化异常 Toolbar未找到");
|
LogUtils.e(TAG, "初始化异常 initToolbar() | Toolbar未找到");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(mToolbar);
|
||||||
@@ -213,11 +192,11 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
LogUtils.d(TAG, "界面初始化 Toolbar 配置完成");
|
LogUtils.d(TAG, "界面初始化 initToolbar() | 配置完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initClickListeners() {
|
private void initClickListeners() {
|
||||||
LogUtils.d(TAG, "界面初始化 开始绑定按钮点击事件");
|
LogUtils.d(TAG, "界面初始化 initClickListeners() | 开始绑定按钮点击事件");
|
||||||
// 绑定所有按钮点击事件
|
// 绑定所有按钮点击事件
|
||||||
bindClickListener(R.id.activitybackgroundsettingsAButton1, onOriginNullClickListener);
|
bindClickListener(R.id.activitybackgroundsettingsAButton1, onOriginNullClickListener);
|
||||||
bindClickListener(R.id.activitybackgroundsettingsAButton2, onReceivedPictureClickListener);
|
bindClickListener(R.id.activitybackgroundsettingsAButton2, onReceivedPictureClickListener);
|
||||||
@@ -229,7 +208,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
bindClickListener(R.id.activitybackgroundsettingsAButton8, onPixelPickerClickListener);
|
bindClickListener(R.id.activitybackgroundsettingsAButton8, onPixelPickerClickListener);
|
||||||
bindClickListener(R.id.activitybackgroundsettingsAButton9, onColorPaletteClickListener);
|
bindClickListener(R.id.activitybackgroundsettingsAButton9, onColorPaletteClickListener);
|
||||||
bindClickListener(R.id.activitybackgroundsettingsAButton10, onCleanPixelClickListener);
|
bindClickListener(R.id.activitybackgroundsettingsAButton10, onCleanPixelClickListener);
|
||||||
LogUtils.d(TAG, "界面初始化 按钮点击事件绑定完成");
|
LogUtils.d(TAG, "界面初始化 initClickListeners() | 按钮点击事件绑定完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通用按钮绑定工具方法
|
// 通用按钮绑定工具方法
|
||||||
@@ -237,8 +216,9 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
View view = findViewById(resId);
|
View view = findViewById(resId);
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
view.setOnClickListener(listener);
|
view.setOnClickListener(listener);
|
||||||
|
LogUtils.d(TAG, String.format("绑定成功 bindClickListener() | resId=%d", resId));
|
||||||
} else {
|
} else {
|
||||||
LogUtils.e(TAG, String.format("绑定异常 未找到视图:%d", resId));
|
LogUtils.e(TAG, String.format("绑定异常 bindClickListener() | 未找到视图:%d", resId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,10 +226,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private View.OnClickListener onOriginNullClickListener = new View.OnClickListener() {
|
private View.OnClickListener onOriginNullClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "按钮点击 取消背景图片");
|
LogUtils.d(TAG, "按钮点击 onOriginNullClickListener() | 取消背景图片");
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
if (previewBean == null) {
|
if (previewBean == null) {
|
||||||
LogUtils.e(TAG, "操作异常 预览Bean为空");
|
LogUtils.e(TAG, "操作异常 onOriginNullClickListener() | 预览Bean为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
previewBean.setIsUseBackgroundFile(false);
|
previewBean.setIsUseBackgroundFile(false);
|
||||||
@@ -262,7 +242,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private View.OnClickListener onSelectPictureClickListener = new View.OnClickListener() {
|
private View.OnClickListener onSelectPictureClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "按钮点击 选择图片");
|
LogUtils.d(TAG, "按钮点击 onSelectPictureClickListener() | 选择图片");
|
||||||
launchImageSelector();
|
launchImageSelector();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -270,9 +250,11 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private View.OnClickListener onNetworkBackgroundDialog = new View.OnClickListener() {
|
private View.OnClickListener onNetworkBackgroundDialog = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
LogUtils.d(TAG, "按钮点击 onNetworkBackgroundDialog() | 打开网络背景对话框");
|
||||||
NetworkBackgroundDialog networkBackgroundDialog = new NetworkBackgroundDialog(BackgroundSettingsActivity.this, new NetworkBackgroundDialog.OnDialogClickListener() {
|
NetworkBackgroundDialog networkBackgroundDialog = new NetworkBackgroundDialog(BackgroundSettingsActivity.this, new NetworkBackgroundDialog.OnDialogClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onConfirm(String szConfirmFilePath) {
|
public void onConfirm(String szConfirmFilePath) {
|
||||||
|
LogUtils.d(TAG, String.format("网络背景确认 onConfirm() | 文件路径=%s", szConfirmFilePath));
|
||||||
// 拷贝文件到预览数据并启动裁剪
|
// 拷贝文件到预览数据并启动裁剪
|
||||||
if (putUriFileToPreviewSource(new File(szConfirmFilePath))) {
|
if (putUriFileToPreviewSource(new File(szConfirmFilePath))) {
|
||||||
startImageCrop(false);
|
startImageCrop(false);
|
||||||
@@ -281,6 +263,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel() {
|
public void onCancel() {
|
||||||
|
LogUtils.d(TAG, "网络背景取消 onCancel()");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
networkBackgroundDialog.show();
|
networkBackgroundDialog.show();
|
||||||
@@ -290,7 +273,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private View.OnClickListener onCropPictureClickListener = new View.OnClickListener() {
|
private View.OnClickListener onCropPictureClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "按钮点击 固定比例裁剪");
|
LogUtils.d(TAG, "按钮点击 onCropPictureClickListener() | 固定比例裁剪");
|
||||||
startImageCrop(false);
|
startImageCrop(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -298,7 +281,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private View.OnClickListener onCropFreePictureClickListener = new View.OnClickListener() {
|
private View.OnClickListener onCropFreePictureClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "按钮点击 自由裁剪");
|
LogUtils.d(TAG, "按钮点击 onCropFreePictureClickListener() | 自由裁剪");
|
||||||
startImageCrop(true);
|
startImageCrop(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -306,11 +289,11 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private View.OnClickListener onTakePhotoClickListener = new View.OnClickListener() {
|
private View.OnClickListener onTakePhotoClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "按钮点击 拍照");
|
LogUtils.d(TAG, "按钮点击 onTakePhotoClickListener() | 拍照");
|
||||||
// 动态申请相机权限
|
// 动态申请相机权限
|
||||||
if (ContextCompat.checkSelfPermission(BackgroundSettingsActivity.this, Manifest.permission.CAMERA)
|
if (ContextCompat.checkSelfPermission(BackgroundSettingsActivity.this, Manifest.permission.CAMERA)
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
LogUtils.d(TAG, "拍照准备 相机权限未授予,发起申请");
|
LogUtils.d(TAG, "拍照准备 onTakePhotoClickListener() | 相机权限未授予,发起申请");
|
||||||
ActivityCompat.requestPermissions(
|
ActivityCompat.requestPermissions(
|
||||||
BackgroundSettingsActivity.this,
|
BackgroundSettingsActivity.this,
|
||||||
new String[]{Manifest.permission.CAMERA},
|
new String[]{Manifest.permission.CAMERA},
|
||||||
@@ -324,10 +307,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private View.OnClickListener onReceivedPictureClickListener = new View.OnClickListener() {
|
private View.OnClickListener onReceivedPictureClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "按钮点击 恢复收到的图片");
|
LogUtils.d(TAG, "按钮点击 onReceivedPictureClickListener() | 恢复收到的图片");
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
if (previewBean == null) {
|
if (previewBean == null) {
|
||||||
LogUtils.e(TAG, "操作异常 预览Bean为空");
|
LogUtils.e(TAG, "操作异常 onReceivedPictureClickListener() | 预览Bean为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
previewBean.setIsUseBackgroundFile(true);
|
previewBean.setIsUseBackgroundFile(true);
|
||||||
@@ -340,10 +323,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private View.OnClickListener onPixelPickerClickListener = new View.OnClickListener() {
|
private View.OnClickListener onPixelPickerClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "按钮点击 像素拾取");
|
LogUtils.d(TAG, "按钮点击 onPixelPickerClickListener() | 像素拾取");
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
if (previewBean == null) {
|
if (previewBean == null) {
|
||||||
LogUtils.e(TAG, "操作异常 预览Bean为空");
|
LogUtils.e(TAG, "操作异常 onPixelPickerClickListener() | 预览Bean为空");
|
||||||
ToastUtils.show("无有效图片可拾取像素");
|
ToastUtils.show("无有效图片可拾取像素");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -351,23 +334,23 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
File targetFile = new File(targetImagePath);
|
File targetFile = new File(targetImagePath);
|
||||||
if (targetFile == null || !targetFile.exists() || targetFile.length() <= 0) {
|
if (targetFile == null || !targetFile.exists() || targetFile.length() <= 0) {
|
||||||
ToastUtils.show("无有效图片可拾取像素");
|
ToastUtils.show("无有效图片可拾取像素");
|
||||||
LogUtils.e(TAG, String.format("像素拾取失败 文件无效:%s", targetImagePath));
|
LogUtils.e(TAG, String.format("像素拾取失败 onPixelPickerClickListener() | 文件无效:%s", targetImagePath));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Intent intent = new Intent(getApplicationContext(), PixelPickerActivity.class);
|
Intent intent = new Intent(getApplicationContext(), PixelPickerActivity.class);
|
||||||
intent.putExtra("imagePath", targetImagePath);
|
intent.putExtra("imagePath", targetImagePath);
|
||||||
startActivityForResult(intent, REQUEST_PIXELPICKER);
|
startActivityForResult(intent, REQUEST_PIXELPICKER);
|
||||||
LogUtils.d(TAG, String.format("像素拾取启动 路径:%s", targetImagePath));
|
LogUtils.d(TAG, String.format("像素拾取启动 onPixelPickerClickListener() | 路径:%s", targetImagePath));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private View.OnClickListener onCleanPixelClickListener = new View.OnClickListener() {
|
private View.OnClickListener onCleanPixelClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "按钮点击 清空像素颜色");
|
LogUtils.d(TAG, "按钮点击 onCleanPixelClickListener() | 清空像素颜色");
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
if (previewBean == null) {
|
if (previewBean == null) {
|
||||||
LogUtils.e(TAG, "操作异常 预览Bean为空");
|
LogUtils.e(TAG, "操作异常 onCleanPixelClickListener() | 预览Bean为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int oldColor = previewBean.getPixelColor();
|
int oldColor = previewBean.getPixelColor();
|
||||||
@@ -376,21 +359,21 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
doubleRefreshPreview();
|
doubleRefreshPreview();
|
||||||
isPreviewBackgroundChanged = true;
|
isPreviewBackgroundChanged = true;
|
||||||
ToastUtils.show("像素颜色已清空");
|
ToastUtils.show("像素颜色已清空");
|
||||||
LogUtils.d(TAG, String.format("像素清空 旧颜色:#%08X", oldColor));
|
LogUtils.d(TAG, String.format("像素清空 onCleanPixelClickListener() | 旧颜色:#%08X", oldColor));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private View.OnClickListener onColorPaletteClickListener = new View.OnClickListener() {
|
private View.OnClickListener onColorPaletteClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "按钮点击 调色板按钮");
|
LogUtils.d(TAG, "按钮点击 onColorPaletteClickListener() | 调色板按钮");
|
||||||
final BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
final BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
if (previewBean == null) {
|
if (previewBean == null) {
|
||||||
LogUtils.e(TAG, "操作异常 预览Bean为空");
|
LogUtils.e(TAG, "操作异常 onColorPaletteClickListener() | 预览Bean为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int initialColor = previewBean.getPixelColor();
|
int initialColor = previewBean.getPixelColor();
|
||||||
LogUtils.d(TAG, String.format("调色板 初始颜色:#%08X", initialColor));
|
LogUtils.d(TAG, String.format("调色板 onColorPaletteClickListener() | 初始颜色:#%08X", initialColor));
|
||||||
ColorPaletteDialog dialog = new ColorPaletteDialog(BackgroundSettingsActivity.this, initialColor, new ColorPaletteDialog.OnColorSelectedListener() {
|
ColorPaletteDialog dialog = new ColorPaletteDialog(BackgroundSettingsActivity.this, initialColor, new ColorPaletteDialog.OnColorSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onColorSelected(int color) {
|
public void onColorSelected(int color) {
|
||||||
@@ -398,11 +381,11 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
mBgSourceUtils.saveSettings();
|
mBgSourceUtils.saveSettings();
|
||||||
doubleRefreshPreview();
|
doubleRefreshPreview();
|
||||||
isPreviewBackgroundChanged = true;
|
isPreviewBackgroundChanged = true;
|
||||||
LogUtils.d(TAG, String.format("颜色选择 选中颜色:#%08X", color));
|
LogUtils.d(TAG, String.format("颜色选择 onColorSelected() | 选中颜色:#%08X", color));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dialog.show();
|
dialog.show();
|
||||||
LogUtils.d(TAG, "调色板 对话框已显示");
|
LogUtils.d(TAG, "调色板 onColorPaletteClickListener() | 对话框已显示");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -413,9 +396,9 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* @return 适配后的Uri,失败返回null
|
* @return 适配后的Uri,失败返回null
|
||||||
*/
|
*/
|
||||||
public Uri getFileProviderUri(File file) {
|
public Uri getFileProviderUri(File file) {
|
||||||
LogUtils.d(TAG, String.format("工具方法 生成FileProvider Uri,文件路径:%s", (file != null ? file.getAbsolutePath() : "null")));
|
LogUtils.d(TAG, String.format("工具方法 getFileProviderUri() | 文件路径:%s", (file != null ? file.getAbsolutePath() : "null")));
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
LogUtils.e(TAG, "工具异常 文件为空");
|
LogUtils.e(TAG, "工具异常 getFileProviderUri() | 文件为空");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -426,7 +409,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
return Uri.fromFile(file);
|
return Uri.fromFile(file);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, String.format("工具异常 生成Uri失败:%s", e.getMessage()));
|
LogUtils.e(TAG, String.format("工具异常 getFileProviderUri() | 生成Uri失败:%s", e.getMessage()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -438,7 +421,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
*/
|
*/
|
||||||
private boolean isBitmapValid(Bitmap bitmap) {
|
private boolean isBitmapValid(Bitmap bitmap) {
|
||||||
boolean isValid = bitmap != null && !bitmap.isRecycled();
|
boolean isValid = bitmap != null && !bitmap.isRecycled();
|
||||||
LogUtils.d(TAG, String.format("工具方法 Bitmap有效性校验:%b", isValid));
|
LogUtils.d(TAG, String.format("工具方法 isBitmapValid() | Bitmap有效性校验:%b", isValid));
|
||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,7 +429,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* 双重刷新预览,确保背景加载最新数据
|
* 双重刷新预览,确保背景加载最新数据
|
||||||
*/
|
*/
|
||||||
private void doubleRefreshPreview() {
|
private void doubleRefreshPreview() {
|
||||||
LogUtils.d(TAG, "工具方法 开始双重刷新预览");
|
LogUtils.d(TAG, "工具方法 doubleRefreshPreview() | 开始双重刷新预览");
|
||||||
if (mBgSourceUtils == null || mBackgroundView == null || isFinishing()) {
|
if (mBgSourceUtils == null || mBackgroundView == null || isFinishing()) {
|
||||||
LogUtils.w(TAG, "双重刷新 跳过:对象为空或Activity已结束");
|
LogUtils.w(TAG, "双重刷新 跳过:对象为空或Activity已结束");
|
||||||
return;
|
return;
|
||||||
@@ -457,9 +440,9 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
mBgSourceUtils.loadSettings();
|
mBgSourceUtils.loadSettings();
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
mBackgroundView.loadByBackgroundBean(previewBean, true);
|
mBackgroundView.loadByBackgroundBean(previewBean, true);
|
||||||
LogUtils.d(TAG, "双重刷新 第一重完成");
|
LogUtils.d(TAG, "双重刷新 doubleRefreshPreview() | 第一重完成");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, String.format("双重刷新 第一重异常:%s", e.getMessage()));
|
LogUtils.e(TAG, String.format("双重刷新 doubleRefreshPreview() | 第一重异常:%s", e.getMessage()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,9 +455,9 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
mBgSourceUtils.loadSettings();
|
mBgSourceUtils.loadSettings();
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
mBackgroundView.loadByBackgroundBean(previewBean, true);
|
mBackgroundView.loadByBackgroundBean(previewBean, true);
|
||||||
LogUtils.d(TAG, "双重刷新 第二重完成");
|
LogUtils.d(TAG, "双重刷新 doubleRefreshPreview() | 第二重完成");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, String.format("双重刷新 第二重异常:%s", e.getMessage()));
|
LogUtils.e(TAG, String.format("双重刷新 doubleRefreshPreview() | 第二重异常:%s", e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,13 +472,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
// 初始化视图
|
// 初始化视图
|
||||||
mBackgroundView = findViewById(R.id.background_view);
|
mBackgroundView = findViewById(R.id.background_view);
|
||||||
if (mBackgroundView == null) {
|
if (mBackgroundView == null) {
|
||||||
LogUtils.e(TAG, "初始化异常 BackgroundView未找到");
|
LogUtils.e(TAG, "初始化异常 initCoreComponents() | BackgroundView未找到");
|
||||||
}
|
}
|
||||||
// 初始化工具类
|
// 初始化工具类
|
||||||
mBgSourceUtils = BackgroundSourceUtils.getInstance(this);
|
mBgSourceUtils = BackgroundSourceUtils.getInstance(this);
|
||||||
mBgSourceUtils.loadSettings();
|
mBgSourceUtils.loadSettings();
|
||||||
mBitmapCache = BitmapCacheUtils.getInstance();
|
mBitmapCache = BitmapCacheUtils.getInstance();
|
||||||
LogUtils.d(TAG, "初始化 视图与工具类加载完成");
|
LogUtils.d(TAG, "初始化 initCoreComponents() | 视图与工具类加载完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -504,9 +487,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private void handleIntentOrPreview() {
|
private void handleIntentOrPreview() {
|
||||||
if (handleShareIntent()) {
|
if (handleShareIntent()) {
|
||||||
ToastUtils.show("已接收分享图片");
|
ToastUtils.show("已接收分享图片");
|
||||||
|
LogUtils.d(TAG, "意图处理 handleIntentOrPreview() | 处理分享意图成功");
|
||||||
} else {
|
} else {
|
||||||
mBgSourceUtils.setCurrentSourceToPreview();
|
mBgSourceUtils.setCurrentSourceToPreview();
|
||||||
LogUtils.d(TAG, "预览初始化 加载当前背景配置");
|
LogUtils.d(TAG, "意图处理 handleIntentOrPreview() | 加载当前背景配置");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,6 +501,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
mBgSourceUtils.createAndUpdatePreviewEnvironmentForCropping(previewBean);
|
mBgSourceUtils.createAndUpdatePreviewEnvironmentForCropping(previewBean);
|
||||||
doubleRefreshPreview();
|
doubleRefreshPreview();
|
||||||
|
LogUtils.d(TAG, "预览环境 initPreviewEnvironment() | 初始化完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -528,7 +513,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
String type = intent.getType();
|
String type = intent.getType();
|
||||||
LogUtils.d(TAG, String.format("分享处理 action:%s,type:%s", action, type));
|
LogUtils.d(TAG, String.format("分享处理 handleShareIntent() | action:%s,type:%s", action, type));
|
||||||
if (Intent.ACTION_SEND.equals(action) && type != null && isImageType(type)) {
|
if (Intent.ACTION_SEND.equals(action) && type != null && isImageType(type)) {
|
||||||
showSharePreviewDialog();
|
showSharePreviewDialog();
|
||||||
return true;
|
return true;
|
||||||
@@ -541,17 +526,18 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* 显示分享图片预览对话框
|
* 显示分享图片预览对话框
|
||||||
*/
|
*/
|
||||||
private void showSharePreviewDialog() {
|
private void showSharePreviewDialog() {
|
||||||
LogUtils.d(TAG, "showSharePreviewDialog()");
|
LogUtils.d(TAG, "工具方法 showSharePreviewDialog()");
|
||||||
BackgroundPicturePreviewDialog dlg = new BackgroundPicturePreviewDialog(this, new BackgroundPicturePreviewDialog.IOnRecivedPictureListener() {
|
BackgroundPicturePreviewDialog dlg = new BackgroundPicturePreviewDialog(this, new BackgroundPicturePreviewDialog.IOnRecivedPictureListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAcceptRecivedPicture(Uri uriRecivedPicture) {
|
public void onAcceptRecivedPicture(Uri uriRecivedPicture) {
|
||||||
|
LogUtils.d(TAG, String.format("分享确认 onAcceptRecivedPicture() | Uri:%s", uriRecivedPicture.toString()));
|
||||||
if (putUriFileToPreviewSource(uriRecivedPicture)) {
|
if (putUriFileToPreviewSource(uriRecivedPicture)) {
|
||||||
startImageCrop(false);
|
startImageCrop(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dlg.show();
|
dlg.show();
|
||||||
LogUtils.d(TAG, "分享处理 显示图片预览对话框");
|
LogUtils.d(TAG, "分享处理 showSharePreviewDialog() | 显示图片预览对话框");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -564,7 +550,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String lowerMimeType = mimeType.toLowerCase();
|
String lowerMimeType = mimeType.toLowerCase();
|
||||||
LogUtils.d("isImageType", String.format("mimeType: %s, lowerMimeType: %s", mimeType, lowerMimeType));
|
LogUtils.d(TAG, String.format("工具方法 isImageType() | mimeType: %s, lowerMimeType: %s", mimeType, lowerMimeType));
|
||||||
return lowerMimeType.startsWith("image/");
|
return lowerMimeType.startsWith("image/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,7 +558,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* 启动图片选择器
|
* 启动图片选择器
|
||||||
*/
|
*/
|
||||||
private void launchImageSelector() {
|
private void launchImageSelector() {
|
||||||
LogUtils.d(TAG, "业务逻辑 启动图片选择器");
|
LogUtils.d(TAG, "业务逻辑 launchImageSelector() | 启动图片选择器");
|
||||||
Intent[] intents = createImageSelectorIntents();
|
Intent[] intents = createImageSelectorIntents();
|
||||||
Intent validIntent = findValidIntent(intents);
|
Intent validIntent = findValidIntent(intents);
|
||||||
|
|
||||||
@@ -610,6 +596,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
openDocIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
openDocIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
||||||
intents[2] = openDocIntent;
|
intents[2] = openDocIntent;
|
||||||
}
|
}
|
||||||
|
LogUtils.d(TAG, "业务逻辑 createImageSelectorIntents() | 意图数组创建完成");
|
||||||
return intents;
|
return intents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,9 +608,11 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private Intent findValidIntent(Intent[] intents) {
|
private Intent findValidIntent(Intent[] intents) {
|
||||||
for (Intent intent : intents) {
|
for (Intent intent : intents) {
|
||||||
if (intent != null && intent.resolveActivity(getPackageManager()) != null) {
|
if (intent != null && intent.resolveActivity(getPackageManager()) != null) {
|
||||||
|
LogUtils.d(TAG, "业务逻辑 findValidIntent() | 找到有效意图");
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LogUtils.d(TAG, "业务逻辑 findValidIntent() | 无有效意图");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,14 +624,14 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
Intent chooser = Intent.createChooser(validIntent, "选择图片");
|
Intent chooser = Intent.createChooser(validIntent, "选择图片");
|
||||||
chooser.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
chooser.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
||||||
startActivityForResult(chooser, REQUEST_SELECT_PICTURE);
|
startActivityForResult(chooser, REQUEST_SELECT_PICTURE);
|
||||||
LogUtils.d(TAG, "选图意图 启动图片选择");
|
LogUtils.d(TAG, "选图意图 launchImageChooser() | 启动图片选择");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 显示无相册应用提示对话框
|
* 显示无相册应用提示对话框
|
||||||
*/
|
*/
|
||||||
private void showNoGalleryDialog() {
|
private void showNoGalleryDialog() {
|
||||||
LogUtils.d(TAG, "选图意图 无相册应用");
|
LogUtils.d(TAG, "选图意图 showNoGalleryDialog() | 无相册应用");
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -670,8 +659,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
marketIntent.setData(Uri.parse("market://details?id=com.android.gallery3d"));
|
marketIntent.setData(Uri.parse("market://details?id=com.android.gallery3d"));
|
||||||
if (marketIntent.resolveActivity(getPackageManager()) != null) {
|
if (marketIntent.resolveActivity(getPackageManager()) != null) {
|
||||||
startActivity(marketIntent);
|
startActivity(marketIntent);
|
||||||
|
LogUtils.d(TAG, "应用商店 launchGalleryMarket() | 启动成功");
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.show("无法打开应用商店");
|
ToastUtils.show("无法打开应用商店");
|
||||||
|
LogUtils.e(TAG, "应用商店 launchGalleryMarket() | 启动失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -680,7 +671,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
*/
|
*/
|
||||||
private void handleOperationCancelOrFail() {
|
private void handleOperationCancelOrFail() {
|
||||||
mBgSourceUtils.setCurrentSourceToPreview();
|
mBgSourceUtils.setCurrentSourceToPreview();
|
||||||
LogUtils.d(TAG, "业务逻辑 操作取消或失败,恢复预览");
|
LogUtils.d(TAG, "业务逻辑 handleOperationCancelOrFail() | 操作取消或失败,恢复预览");
|
||||||
ToastUtils.show("操作取消或失败");
|
ToastUtils.show("操作取消或失败");
|
||||||
doubleRefreshPreview();
|
doubleRefreshPreview();
|
||||||
}
|
}
|
||||||
@@ -689,10 +680,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* 处理拍照逻辑(权限通过后执行)
|
* 处理拍照逻辑(权限通过后执行)
|
||||||
*/
|
*/
|
||||||
void handleTakePhoto() {
|
void handleTakePhoto() {
|
||||||
LogUtils.d(TAG, "业务逻辑 开始处理拍照");
|
LogUtils.d(TAG, "业务逻辑 handleTakePhoto() | 开始处理拍照");
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
if (previewBean == null) {
|
if (previewBean == null) {
|
||||||
LogUtils.e(TAG, "拍照失败 预览Bean为空");
|
LogUtils.e(TAG, "拍照失败 handleTakePhoto() | 预览Bean为空");
|
||||||
ToastUtils.show("拍照文件创建失败");
|
ToastUtils.show("拍照文件创建失败");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -700,7 +691,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
File takePhotoFile = new File(previewBean.getBackgroundFilePath());
|
File takePhotoFile = new File(previewBean.getBackgroundFilePath());
|
||||||
if (!takePhotoFile.exists()) {
|
if (!takePhotoFile.exists()) {
|
||||||
ToastUtils.show("拍照文件创建失败");
|
ToastUtils.show("拍照文件创建失败");
|
||||||
LogUtils.e(TAG, String.format("拍照失败 文件不存在:%s", takePhotoFile.getAbsolutePath()));
|
LogUtils.e(TAG, String.format("拍照失败 handleTakePhoto() | 文件不存在:%s", takePhotoFile.getAbsolutePath()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -712,11 +703,11 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
}
|
}
|
||||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
|
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
|
||||||
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
|
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
|
||||||
LogUtils.d(TAG, String.format("拍照启动 Uri:%s", photoUri.toString()));
|
LogUtils.d(TAG, String.format("拍照启动 handleTakePhoto() | Uri:%s", photoUri.toString()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String errMsg = "拍照启动异常:" + e.getMessage();
|
String errMsg = "拍照启动异常:" + e.getMessage();
|
||||||
ToastUtils.show(errMsg.substring(0, 20));
|
ToastUtils.show(errMsg.substring(0, 20));
|
||||||
LogUtils.e(TAG, String.format("拍照失败 %s", e.getMessage()));
|
LogUtils.e(TAG, String.format("拍照失败 handleTakePhoto() | %s", e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,6 +717,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* @param data 回调数据
|
* @param data 回调数据
|
||||||
*/
|
*/
|
||||||
private void handleActivityResult(int requestCode, Intent data) {
|
private void handleActivityResult(int requestCode, Intent data) {
|
||||||
|
LogUtils.d(TAG, String.format("业务逻辑 handleActivityResult() | 处理请求码:%d", requestCode));
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_SELECT_PICTURE:
|
case REQUEST_SELECT_PICTURE:
|
||||||
handleSelectPictureResult(data);
|
handleSelectPictureResult(data);
|
||||||
@@ -740,7 +732,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
handlePixelPickerResult();
|
handlePixelPickerResult();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LogUtils.d(TAG, String.format("回调忽略 未知requestCode:%d", requestCode));
|
LogUtils.d(TAG, String.format("回调忽略 handleActivityResult() | 未知requestCode:%d", requestCode));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -750,10 +742,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* @param data 回调数据
|
* @param data 回调数据
|
||||||
*/
|
*/
|
||||||
private void handleTakePhotoResult(Intent data) {
|
private void handleTakePhotoResult(Intent data) {
|
||||||
LogUtils.d(TAG, "业务逻辑 处理拍照结果");
|
LogUtils.d(TAG, "业务逻辑 handleTakePhotoResult() | 处理拍照结果");
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
if (previewBean == null) {
|
if (previewBean == null) {
|
||||||
LogUtils.e(TAG, "拍照结果处理 预览Bean为空");
|
LogUtils.e(TAG, "拍照结果处理 handleTakePhotoResult() | 预览Bean为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,7 +755,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
doubleRefreshPreview();
|
doubleRefreshPreview();
|
||||||
|
|
||||||
startImageCrop(false);
|
startImageCrop(false);
|
||||||
LogUtils.d(TAG, "拍照完成 已启动裁剪");
|
LogUtils.d(TAG, "拍照完成 handleTakePhotoResult() | 已启动裁剪");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -771,30 +763,30 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* @param data 回调数据
|
* @param data 回调数据
|
||||||
*/
|
*/
|
||||||
private void handleSelectPictureResult(Intent data) {
|
private void handleSelectPictureResult(Intent data) {
|
||||||
LogUtils.d(TAG, "业务逻辑 处理选图结果");
|
LogUtils.d(TAG, "业务逻辑 handleSelectPictureResult() | 处理选图结果");
|
||||||
Uri selectedImage = data.getData();
|
Uri selectedImage = data.getData();
|
||||||
if (selectedImage == null) {
|
if (selectedImage == null) {
|
||||||
ToastUtils.show("图片Uri为空");
|
ToastUtils.show("图片Uri为空");
|
||||||
LogUtils.e(TAG, "选图结果 Uri为空");
|
LogUtils.e(TAG, "选图结果 handleSelectPictureResult() | Uri为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LogUtils.d(TAG, String.format("选图回调 系统返回Uri : %s", selectedImage.toString()));
|
LogUtils.d(TAG, String.format("选图回调 handleSelectPictureResult() | 系统返回Uri : %s", selectedImage.toString()));
|
||||||
|
|
||||||
// 申请持久化权限(API33+)
|
// 申请持久化权限(API33+)
|
||||||
if (Build.VERSION.SDK_INT >= SDK_VERSION_TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= SDK_VERSION_TIRAMISU) {
|
||||||
getContentResolver().takePersistableUriPermission(
|
getContentResolver().takePersistableUriPermission(
|
||||||
selectedImage,
|
selectedImage,
|
||||||
Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
LogUtils.d(TAG, "选图权限 已添加持久化权限");
|
LogUtils.d(TAG, "选图权限 handleSelectPictureResult() | 已添加持久化权限");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 同步文件并启动裁剪
|
// 同步文件并启动裁剪
|
||||||
if (putUriFileToPreviewSource(selectedImage)) {
|
if (putUriFileToPreviewSource(selectedImage)) {
|
||||||
LogUtils.d(TAG, "选图同步 路径绑定完成");
|
LogUtils.d(TAG, "选图同步 handleSelectPictureResult() | 路径绑定完成");
|
||||||
startImageCrop(false);
|
startImageCrop(false);
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.show("图片同步失败");
|
ToastUtils.show("图片同步失败");
|
||||||
LogUtils.e(TAG, "选图同步 文件复制失败");
|
LogUtils.e(TAG, "选图同步 handleSelectPictureResult() | 文件复制失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -806,7 +798,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private boolean putUriFileToPreviewSource(Uri srcUriFile) {
|
private boolean putUriFileToPreviewSource(Uri srcUriFile) {
|
||||||
String filePath = UriUtils.getFilePathFromUri(this, srcUriFile);
|
String filePath = UriUtils.getFilePathFromUri(this, srcUriFile);
|
||||||
if (TextUtils.isEmpty(filePath)) {
|
if (TextUtils.isEmpty(filePath)) {
|
||||||
LogUtils.e(TAG, "选图同步 Uri解析路径为空");
|
LogUtils.e(TAG, "选图同步 putUriFileToPreviewSource() | Uri解析路径为空");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
File srcFile = new File(filePath);
|
File srcFile = new File(filePath);
|
||||||
@@ -819,16 +811,16 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* @return 同步成功返回true,否则false
|
* @return 同步成功返回true,否则false
|
||||||
*/
|
*/
|
||||||
private boolean putUriFileToPreviewSource(File srcFile) {
|
private boolean putUriFileToPreviewSource(File srcFile) {
|
||||||
LogUtils.d(TAG, String.format("选图同步 源文件:%s", srcFile.getAbsolutePath()));
|
LogUtils.d(TAG, String.format("选图同步 putUriFileToPreviewSource() | 源文件:%s", srcFile.getAbsolutePath()));
|
||||||
mBgSourceUtils.loadSettings();
|
mBgSourceUtils.loadSettings();
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
File dstFile = new File(previewBean.getBackgroundFilePath());
|
File dstFile = new File(previewBean.getBackgroundFilePath());
|
||||||
LogUtils.d(TAG, String.format("选图同步 目标文件:%s", dstFile.getAbsolutePath()));
|
LogUtils.d(TAG, String.format("选图同步 putUriFileToPreviewSource() | 目标文件:%s", dstFile.getAbsolutePath()));
|
||||||
if (FileUtils.copyFile(srcFile, dstFile)) {
|
if (FileUtils.copyFile(srcFile, dstFile)) {
|
||||||
LogUtils.d(TAG, "选图同步 文件拷贝成功");
|
LogUtils.d(TAG, "选图同步 putUriFileToPreviewSource() | 文件拷贝成功");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
LogUtils.d(TAG, "选图同步 文件无法拷贝");
|
LogUtils.d(TAG, "选图同步 putUriFileToPreviewSource() | 文件无法拷贝");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -837,10 +829,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
* @param data 回调数据
|
* @param data 回调数据
|
||||||
*/
|
*/
|
||||||
private void handleCropImageResult(Intent data) {
|
private void handleCropImageResult(Intent data) {
|
||||||
LogUtils.d(TAG, "业务逻辑 处理裁剪结果");
|
LogUtils.d(TAG, "业务逻辑 handleCropImageResult() | 处理裁剪结果");
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
if (previewBean == null) {
|
if (previewBean == null) {
|
||||||
LogUtils.e(TAG, "裁剪结果处理 预览Bean为空");
|
LogUtils.e(TAG, "裁剪结果处理 handleCropImageResult() | 预览Bean为空");
|
||||||
handleOperationCancelOrFail();
|
handleOperationCancelOrFail();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -865,7 +857,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
*/
|
*/
|
||||||
private void handleCropSuccess(BackgroundBean previewBean, long fileSize) {
|
private void handleCropSuccess(BackgroundBean previewBean, long fileSize) {
|
||||||
isPreviewBackgroundChanged = true;
|
isPreviewBackgroundChanged = true;
|
||||||
LogUtils.d(TAG, String.format("裁剪结果 裁剪成功,文件大小:%d", fileSize));
|
LogUtils.d(TAG, String.format("裁剪结果 handleCropSuccess() | 裁剪成功,文件大小:%d", fileSize));
|
||||||
previewBean.setIsUseBackgroundFile(true);
|
previewBean.setIsUseBackgroundFile(true);
|
||||||
previewBean.setIsUseBackgroundScaledCompressFile(true);
|
previewBean.setIsUseBackgroundScaledCompressFile(true);
|
||||||
mBgSourceUtils.saveSettings();
|
mBgSourceUtils.saveSettings();
|
||||||
@@ -880,14 +872,14 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
*/
|
*/
|
||||||
private void handleCropFailure(boolean isFileExist, boolean isFileReadable, long fileSize) {
|
private void handleCropFailure(boolean isFileExist, boolean isFileReadable, long fileSize) {
|
||||||
handleOperationCancelOrFail();
|
handleOperationCancelOrFail();
|
||||||
LogUtils.e(TAG, String.format("裁剪结果 裁剪失败,文件状态:存在=%b,可读=%b,大小=%d", isFileExist, isFileReadable, fileSize));
|
LogUtils.e(TAG, String.format("裁剪结果 handleCropFailure() | 裁剪失败,文件状态:存在=%b,可读=%b,大小=%d", isFileExist, isFileReadable, fileSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理像素拾取结果
|
* 处理像素拾取结果
|
||||||
*/
|
*/
|
||||||
private void handlePixelPickerResult() {
|
private void handlePixelPickerResult() {
|
||||||
LogUtils.d(TAG, "业务逻辑 处理像素拾取结果");
|
LogUtils.d(TAG, "业务逻辑 handlePixelPickerResult() | 处理像素拾取结果");
|
||||||
doubleRefreshPreview();
|
doubleRefreshPreview();
|
||||||
isPreviewBackgroundChanged = true;
|
isPreviewBackgroundChanged = true;
|
||||||
}
|
}
|
||||||
@@ -898,10 +890,10 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
*/
|
*/
|
||||||
private void handleCameraPermissionResult(int[] grantResults) {
|
private void handleCameraPermissionResult(int[] grantResults) {
|
||||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
LogUtils.d(TAG, "权限申请 相机权限授予成功");
|
LogUtils.d(TAG, "权限申请 handleCameraPermissionResult() | 相机权限授予成功");
|
||||||
handleTakePhoto();
|
handleTakePhoto();
|
||||||
} else {
|
} else {
|
||||||
LogUtils.d(TAG, "权限申请 相机权限授予失败");
|
LogUtils.d(TAG, "权限申请 handleCameraPermissionResult() | 相机权限授予失败");
|
||||||
ToastUtils.show("相机权限被拒绝,无法拍照");
|
ToastUtils.show("相机权限被拒绝,无法拍照");
|
||||||
// 引导用户到设置页面开启权限(用户选择不再询问时)
|
// 引导用户到设置页面开启权限(用户选择不再询问时)
|
||||||
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
|
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
|
||||||
@@ -919,7 +911,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
intent.setData(uri);
|
intent.setData(uri);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
ToastUtils.show("请在设置中开启相机权限");
|
ToastUtils.show("请在设置中开启相机权限");
|
||||||
LogUtils.d(TAG, "权限引导 启动应用设置页面");
|
LogUtils.d(TAG, "权限引导 launchAppSettings() | 启动应用设置页面");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -954,7 +946,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
private void startImageCrop(boolean isFreeCrop) {
|
private void startImageCrop(boolean isFreeCrop) {
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
if (previewBean == null) {
|
if (previewBean == null) {
|
||||||
LogUtils.e(TAG, "裁剪启动 预览Bean为空");
|
LogUtils.e(TAG, "裁剪启动 startImageCrop() | 预览Bean为空");
|
||||||
ToastUtils.show("裁剪失败:无有效图片");
|
ToastUtils.show("裁剪失败:无有效图片");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -966,7 +958,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
height,
|
height,
|
||||||
isFreeCrop,
|
isFreeCrop,
|
||||||
REQUEST_CROP_IMAGE);
|
REQUEST_CROP_IMAGE);
|
||||||
LogUtils.d(TAG, String.format("裁剪启动 是否自由裁剪:%b,目标尺寸:%dx%d", isFreeCrop, width, height));
|
LogUtils.d(TAG, String.format("裁剪启动 startImageCrop() | 是否自由裁剪:%b,目标尺寸:%dx%d", isFreeCrop, width, height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.io.IOException;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||||
* @Date 2024/04/29 17:24:53
|
* @Date 2024/04/29 17:24:53
|
||||||
* @Describe 应用运行参数类
|
* @Describe 应用运行参数类
|
||||||
* 适配 API30,支持 Serializable 持久化、Parcelable Intent 传递、JSON 序列化/反序列化
|
* 适配 API30,支持 Serializable 持久化、Parcelable Intent 传递、JSON 序列化/反序列化
|
||||||
@@ -24,12 +24,12 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
transient public static final String TAG = "AppConfigBean";
|
transient public static final String TAG = "AppConfigBean";
|
||||||
// 字段校验常量(统一阈值,避免硬编码)
|
// 字段校验常量(统一阈值,避免硬编码)
|
||||||
private static final int MIN_INTERVAL = 500; // 最小检测间隔(ms)
|
private static final int MIN_INTERVAL = 500; // 最小检测间隔(ms)
|
||||||
private static final int MIN_REMIND_INTERVAL = 1000; // 最小提醒间隔(ms)
|
private static final int MIN_REMIND_INTERVAL = 1000;// 最小提醒间隔(ms)
|
||||||
private static final int BATTERY_MIN = 0; // 电量最小值
|
private static final int BATTERY_MIN = 0; // 电量最小值
|
||||||
private static final int BATTERY_MAX = 100; // 电量最大值
|
private static final int BATTERY_MAX = 100; // 电量最大值
|
||||||
private static final int INVALID_BATTERY = -1; // 无效电量标识
|
private static final int INVALID_BATTERY = -1; // 无效电量标识
|
||||||
private static final int DEFAULT_FRAME_WIDTH = 500; // 默认相框宽度(px)
|
private static final int DEFAULT_FRAME_WIDTH = 500; // 默认相框宽度(px)
|
||||||
private static final int DEFAULT_FRAME_HEIGHT = 500; // 默认相框高度(px)
|
private static final int DEFAULT_FRAME_HEIGHT = 500;// 默认相框高度(px)
|
||||||
|
|
||||||
// ====================== 成员变量(按功能分类:提醒配置→电量状态→检测配置→相框配置) ======================
|
// ====================== 成员变量(按功能分类:提醒配置→电量状态→检测配置→相框配置) ======================
|
||||||
// 耗电提醒配置
|
// 耗电提醒配置
|
||||||
@@ -47,7 +47,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
int batteryDetectInterval = 2000; // 电量检测间隔(ms,适配 RemindThread)
|
int batteryDetectInterval = 2000; // 电量检测间隔(ms,适配 RemindThread)
|
||||||
// 相框配置
|
// 相框配置
|
||||||
int defaultFrameWidth = DEFAULT_FRAME_WIDTH; // 默认相框宽度(px)
|
int defaultFrameWidth = DEFAULT_FRAME_WIDTH; // 默认相框宽度(px)
|
||||||
int defaultFrameHeight = DEFAULT_FRAME_HEIGHT; // 默认相框高度(px)
|
int defaultFrameHeight = DEFAULT_FRAME_HEIGHT;// 默认相框高度(px)
|
||||||
|
|
||||||
// ====================== 构造方法(初始化默认配置,强化默认值校验) ======================
|
// ====================== 构造方法(初始化默认配置,强化默认值校验) ======================
|
||||||
public AppConfigBean() {
|
public AppConfigBean() {
|
||||||
@@ -60,7 +60,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
setCurrentBatteryValue(INVALID_BATTERY); // 初始化无效电量标识
|
setCurrentBatteryValue(INVALID_BATTERY); // 初始化无效电量标识
|
||||||
setDefaultFrameWidth(DEFAULT_FRAME_WIDTH); // 初始化默认相框宽度
|
setDefaultFrameWidth(DEFAULT_FRAME_WIDTH); // 初始化默认相框宽度
|
||||||
setDefaultFrameHeight(DEFAULT_FRAME_HEIGHT); // 初始化默认相框高度
|
setDefaultFrameHeight(DEFAULT_FRAME_HEIGHT); // 初始化默认相框高度
|
||||||
LogUtils.d(TAG, "AppConfigBean: 初始化默认配置完成");
|
LogUtils.d(TAG, "AppConfigBean() 初始化默认配置完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================== 核心业务方法(Setter/Getter,按字段功能分类,补充调试日志) ======================
|
// ====================== 核心业务方法(Setter/Getter,按字段功能分类,补充调试日志) ======================
|
||||||
@@ -72,7 +72,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
public void setCurrentBatteryValue(int currentBatteryValue) {
|
public void setCurrentBatteryValue(int currentBatteryValue) {
|
||||||
this.currentBatteryValue = (currentBatteryValue >= BATTERY_MIN && currentBatteryValue <= BATTERY_MAX)
|
this.currentBatteryValue = (currentBatteryValue >= BATTERY_MIN && currentBatteryValue <= BATTERY_MAX)
|
||||||
? currentBatteryValue : INVALID_BATTERY;
|
? currentBatteryValue : INVALID_BATTERY;
|
||||||
LogUtils.d(TAG, String.format("setCurrentBatteryValue: 当前电量设置为 %d(输入值:%d)",
|
LogUtils.d(TAG, String.format("setCurrentBatteryValue() 执行 | 最终电量=%d | 输入值=%d",
|
||||||
this.currentBatteryValue, currentBatteryValue));
|
this.currentBatteryValue, currentBatteryValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
*/
|
*/
|
||||||
public void setReminderIntervalTime(int reminderIntervalTime) {
|
public void setReminderIntervalTime(int reminderIntervalTime) {
|
||||||
this.reminderIntervalTime = Math.max(reminderIntervalTime, MIN_REMIND_INTERVAL);
|
this.reminderIntervalTime = Math.max(reminderIntervalTime, MIN_REMIND_INTERVAL);
|
||||||
LogUtils.d(TAG, String.format("setReminderIntervalTime: 提醒间隔设置为 %dms(输入值:%d)",
|
LogUtils.d(TAG, String.format("setReminderIntervalTime() 执行 | 最终间隔=%dms | 输入值=%dms",
|
||||||
this.reminderIntervalTime, reminderIntervalTime));
|
this.reminderIntervalTime, reminderIntervalTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
*/
|
*/
|
||||||
public void setIsCharging(boolean isCharging) {
|
public void setIsCharging(boolean isCharging) {
|
||||||
this.isCharging = isCharging;
|
this.isCharging = isCharging;
|
||||||
LogUtils.d(TAG, String.format("setIsCharging: 充电状态设置为 %b", isCharging));
|
LogUtils.d(TAG, String.format("setIsCharging() 执行 | 充电状态=%b", isCharging));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCharging() {
|
public boolean isCharging() {
|
||||||
@@ -116,7 +116,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
// --------------- 耗电提醒配置相关 ---------------
|
// --------------- 耗电提醒配置相关 ---------------
|
||||||
public void setEnableUsageReminder(boolean isEnableUsageReminder) {
|
public void setEnableUsageReminder(boolean isEnableUsageReminder) {
|
||||||
this.isEnableUsageReminder = isEnableUsageReminder;
|
this.isEnableUsageReminder = isEnableUsageReminder;
|
||||||
LogUtils.d(TAG, String.format("setEnableUsageReminder: 耗电提醒开关设置为 %b", isEnableUsageReminder));
|
LogUtils.d(TAG, String.format("setEnableUsageReminder() 执行 | 耗电提醒开关=%b", isEnableUsageReminder));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnableUsageReminder() {
|
public boolean isEnableUsageReminder() {
|
||||||
@@ -129,7 +129,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
*/
|
*/
|
||||||
public void setUsageReminderValue(int usageReminderValue) {
|
public void setUsageReminderValue(int usageReminderValue) {
|
||||||
this.usageReminderValue = Math.min(Math.max(usageReminderValue, BATTERY_MIN), BATTERY_MAX);
|
this.usageReminderValue = Math.min(Math.max(usageReminderValue, BATTERY_MIN), BATTERY_MAX);
|
||||||
LogUtils.d(TAG, String.format("setUsageReminderValue: 耗电提醒阈值设置为 %d(输入值:%d)",
|
LogUtils.d(TAG, String.format("setUsageReminderValue() 执行 | 最终阈值=%d | 输入值=%d",
|
||||||
this.usageReminderValue, usageReminderValue));
|
this.usageReminderValue, usageReminderValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
// --------------- 充电提醒配置相关 ---------------
|
// --------------- 充电提醒配置相关 ---------------
|
||||||
public void setEnableChargeReminder(boolean isEnableChargeReminder) {
|
public void setEnableChargeReminder(boolean isEnableChargeReminder) {
|
||||||
this.isEnableChargeReminder = isEnableChargeReminder;
|
this.isEnableChargeReminder = isEnableChargeReminder;
|
||||||
LogUtils.d(TAG, String.format("setEnableChargeReminder: 充电提醒开关设置为 %b", isEnableChargeReminder));
|
LogUtils.d(TAG, String.format("setEnableChargeReminder() 执行 | 充电提醒开关=%b", isEnableChargeReminder));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnableChargeReminder() {
|
public boolean isEnableChargeReminder() {
|
||||||
@@ -153,7 +153,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
*/
|
*/
|
||||||
public void setChargeReminderValue(int chargeReminderValue) {
|
public void setChargeReminderValue(int chargeReminderValue) {
|
||||||
this.chargeReminderValue = Math.min(Math.max(chargeReminderValue, BATTERY_MIN), BATTERY_MAX);
|
this.chargeReminderValue = Math.min(Math.max(chargeReminderValue, BATTERY_MIN), BATTERY_MAX);
|
||||||
LogUtils.d(TAG, String.format("setChargeReminderValue: 充电提醒阈值设置为 %d(输入值:%d)",
|
LogUtils.d(TAG, String.format("setChargeReminderValue() 执行 | 最终阈值=%d | 输入值=%d",
|
||||||
this.chargeReminderValue, chargeReminderValue));
|
this.chargeReminderValue, chargeReminderValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
*/
|
*/
|
||||||
public void setBatteryDetectInterval(int batteryDetectInterval) {
|
public void setBatteryDetectInterval(int batteryDetectInterval) {
|
||||||
this.batteryDetectInterval = Math.max(batteryDetectInterval, MIN_INTERVAL);
|
this.batteryDetectInterval = Math.max(batteryDetectInterval, MIN_INTERVAL);
|
||||||
LogUtils.d(TAG, String.format("setBatteryDetectInterval: 检测间隔设置为 %dms(输入值:%d)",
|
LogUtils.d(TAG, String.format("setBatteryDetectInterval() 执行 | 最终间隔=%dms | 输入值=%dms",
|
||||||
this.batteryDetectInterval, batteryDetectInterval));
|
this.batteryDetectInterval, batteryDetectInterval));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,11 +179,11 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
// --------------- 相框配置相关 ---------------
|
// --------------- 相框配置相关 ---------------
|
||||||
/**
|
/**
|
||||||
* 设置默认相框宽度
|
* 设置默认相框宽度
|
||||||
* @param defaultFrameWidth 相框宽度(px,范围 MIN_FRAME_SIZE - MAX_FRAME_SIZE)
|
* @param defaultFrameWidth 相框宽度(px)
|
||||||
*/
|
*/
|
||||||
public void setDefaultFrameWidth(int defaultFrameWidth) {
|
public void setDefaultFrameWidth(int defaultFrameWidth) {
|
||||||
this.defaultFrameWidth = defaultFrameWidth;
|
this.defaultFrameWidth = defaultFrameWidth;
|
||||||
LogUtils.d(TAG, String.format("setDefaultFrameWidth: 默认相框宽度设置为 %dpx(输入值:%d)",
|
LogUtils.d(TAG, String.format("setDefaultFrameWidth() 执行 | 最终宽度=%dpx | 输入值=%dpx",
|
||||||
this.defaultFrameWidth, defaultFrameWidth));
|
this.defaultFrameWidth, defaultFrameWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,11 +193,11 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置默认相框高度
|
* 设置默认相框高度
|
||||||
* @param defaultFrameHeight 相框高度(px,范围 MIN_FRAME_SIZE - MAX_FRAME_SIZE)
|
* @param defaultFrameHeight 相框高度(px)
|
||||||
*/
|
*/
|
||||||
public void setDefaultFrameHeight(int defaultFrameHeight) {
|
public void setDefaultFrameHeight(int defaultFrameHeight) {
|
||||||
this.defaultFrameHeight = defaultFrameHeight;
|
this.defaultFrameHeight = defaultFrameHeight;
|
||||||
LogUtils.d(TAG, String.format("setDefaultFrameHeight: 默认相框高度设置为 %dpx(输入值:%d)",
|
LogUtils.d(TAG, String.format("setDefaultFrameHeight() 执行 | 最终高度=%dpx | 输入值=%dpx",
|
||||||
this.defaultFrameHeight, defaultFrameHeight));
|
this.defaultFrameHeight, defaultFrameHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
return defaultFrameHeight;
|
return defaultFrameHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================== JSON 序列化/反序列化(兼容旧配置,补充调试日志) ======================
|
// ====================== 父类重写方法(JSON 序列化/反序列化,兼容旧配置) ======================
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return AppConfigBean.class.getName();
|
return AppConfigBean.class.getName();
|
||||||
@@ -214,23 +214,22 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
@Override
|
@Override
|
||||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||||
super.writeThisToJsonWriter(jsonWriter);
|
super.writeThisToJsonWriter(jsonWriter);
|
||||||
AppConfigBean bean = this;
|
|
||||||
// 原有字段序列化
|
// 原有字段序列化
|
||||||
jsonWriter.name("isEnableUsageReminder").value(bean.isEnableUsageReminder());
|
jsonWriter.name("isEnableUsageReminder").value(isEnableUsageReminder());
|
||||||
jsonWriter.name("usageReminderValue").value(bean.getUsageReminderValue());
|
jsonWriter.name("usageReminderValue").value(getUsageReminderValue());
|
||||||
jsonWriter.name("isEnableChargeReminder").value(bean.isEnableChargeReminder());
|
jsonWriter.name("isEnableChargeReminder").value(isEnableChargeReminder());
|
||||||
jsonWriter.name("chargeReminderValue").value(bean.getChargeReminderValue());
|
jsonWriter.name("chargeReminderValue").value(getChargeReminderValue());
|
||||||
jsonWriter.name("reminderIntervalTime").value(bean.getReminderIntervalTime());
|
jsonWriter.name("reminderIntervalTime").value(getReminderIntervalTime());
|
||||||
jsonWriter.name("isCharging").value(bean.isCharging());
|
jsonWriter.name("isCharging").value(isCharging());
|
||||||
// 兼容旧字段 currentValue,同步新字段 currentBatteryValue
|
// 兼容旧字段 currentValue,同步新字段 currentBatteryValue
|
||||||
jsonWriter.name("currentBatteryValue").value(bean.getCurrentBatteryValue());
|
jsonWriter.name("currentBatteryValue").value(getCurrentBatteryValue());
|
||||||
jsonWriter.name("currentValue").value(bean.getCurrentBatteryValue());
|
jsonWriter.name("currentValue").value(getCurrentBatteryValue());
|
||||||
// 新增字段序列化(检测配置)
|
// 新增字段序列化(检测配置)
|
||||||
jsonWriter.name("batteryDetectInterval").value(bean.getBatteryDetectInterval());
|
jsonWriter.name("batteryDetectInterval").value(getBatteryDetectInterval());
|
||||||
// 新增字段序列化(相框配置)
|
// 新增字段序列化(相框配置)
|
||||||
jsonWriter.name("defaultFrameWidth").value(bean.getDefaultFrameWidth());
|
jsonWriter.name("defaultFrameWidth").value(getDefaultFrameWidth());
|
||||||
jsonWriter.name("defaultFrameHeight").value(bean.getDefaultFrameHeight());
|
jsonWriter.name("defaultFrameHeight").value(getDefaultFrameHeight());
|
||||||
LogUtils.d(TAG, "writeThisToJsonWriter: JSON 序列化完成");
|
LogUtils.d(TAG, "writeThisToJsonWriter() JSON序列化完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -242,43 +241,50 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
// 兼容拼写错误字段(isEnableUsegeReminder → isEnableUsageReminder)
|
// 兼容拼写错误字段(isEnableUsegeReminder → isEnableUsageReminder)
|
||||||
if (name.equals("isEnableUsageReminder") || name.equals("isEnableUsegeReminder")) {
|
if (name.equals("isEnableUsageReminder") || name.equals("isEnableUsegeReminder")) {
|
||||||
bean.setEnableUsageReminder(jsonReader.nextBoolean());
|
bean.setEnableUsageReminder(jsonReader.nextBoolean());
|
||||||
|
LogUtils.d(TAG, String.format("readBeanFromJsonReader() 读取字段 | %s=%b", name, bean.isEnableUsageReminder()));
|
||||||
} else if (name.equals("usageReminderValue") || name.equals("usegeReminderValue")) {
|
} else if (name.equals("usageReminderValue") || name.equals("usegeReminderValue")) {
|
||||||
bean.setUsageReminderValue(jsonReader.nextInt());
|
bean.setUsageReminderValue(jsonReader.nextInt());
|
||||||
|
LogUtils.d(TAG, String.format("readBeanFromJsonReader() 读取字段 | %s=%d", name, bean.getUsageReminderValue()));
|
||||||
} else if (name.equals("isEnableChargeReminder")) {
|
} else if (name.equals("isEnableChargeReminder")) {
|
||||||
bean.setEnableChargeReminder(jsonReader.nextBoolean());
|
bean.setEnableChargeReminder(jsonReader.nextBoolean());
|
||||||
|
LogUtils.d(TAG, String.format("readBeanFromJsonReader() 读取字段 | %s=%b", name, bean.isEnableChargeReminder()));
|
||||||
} else if (name.equals("chargeReminderValue")) {
|
} else if (name.equals("chargeReminderValue")) {
|
||||||
bean.setChargeReminderValue(jsonReader.nextInt());
|
bean.setChargeReminderValue(jsonReader.nextInt());
|
||||||
|
LogUtils.d(TAG, String.format("readBeanFromJsonReader() 读取字段 | %s=%d", name, bean.getChargeReminderValue()));
|
||||||
} else if (name.equals("reminderIntervalTime")) {
|
} else if (name.equals("reminderIntervalTime")) {
|
||||||
bean.setReminderIntervalTime(jsonReader.nextInt());
|
bean.setReminderIntervalTime(jsonReader.nextInt());
|
||||||
|
LogUtils.d(TAG, String.format("readBeanFromJsonReader() 读取字段 | %s=%d", name, bean.getReminderIntervalTime()));
|
||||||
} else if (name.equals("isCharging")) {
|
} else if (name.equals("isCharging")) {
|
||||||
bean.setIsCharging(jsonReader.nextBoolean());
|
bean.setIsCharging(jsonReader.nextBoolean());
|
||||||
|
LogUtils.d(TAG, String.format("readBeanFromJsonReader() 读取字段 | %s=%b", name, bean.isCharging()));
|
||||||
} else if (name.equals("currentValue")) {
|
} else if (name.equals("currentValue")) {
|
||||||
// 优先读取旧字段,兼容历史配置
|
// 优先读取旧字段,兼容历史配置
|
||||||
bean.setCurrentBatteryValue(jsonReader.nextInt());
|
bean.setCurrentBatteryValue(jsonReader.nextInt());
|
||||||
LogUtils.d(TAG, "readBeanFromJsonReader: 读取旧字段 currentValue 完成");
|
LogUtils.d(TAG, "readBeanFromJsonReader() 读取旧字段 | currentValue=" + bean.getCurrentBatteryValue());
|
||||||
} else if (name.equals("currentBatteryValue")) {
|
} else if (name.equals("currentBatteryValue")) {
|
||||||
// 新字段覆盖旧字段,保证数据最新
|
// 新字段覆盖旧字段,保证数据最新
|
||||||
bean.setCurrentBatteryValue(jsonReader.nextInt());
|
bean.setCurrentBatteryValue(jsonReader.nextInt());
|
||||||
LogUtils.d(TAG, "readBeanFromJsonReader: 读取新字段 currentBatteryValue 完成");
|
LogUtils.d(TAG, "readBeanFromJsonReader() 读取新字段 | currentBatteryValue=" + bean.getCurrentBatteryValue());
|
||||||
} else if (name.equals("batteryDetectInterval")) {
|
} else if (name.equals("batteryDetectInterval")) {
|
||||||
bean.setBatteryDetectInterval(jsonReader.nextInt());
|
bean.setBatteryDetectInterval(jsonReader.nextInt());
|
||||||
|
LogUtils.d(TAG, String.format("readBeanFromJsonReader() 读取字段 | %s=%d", name, bean.getBatteryDetectInterval()));
|
||||||
} else if (name.equals("defaultFrameWidth")) {
|
} else if (name.equals("defaultFrameWidth")) {
|
||||||
bean.setDefaultFrameWidth(jsonReader.nextInt());
|
bean.setDefaultFrameWidth(jsonReader.nextInt());
|
||||||
LogUtils.d(TAG, "readBeanFromJsonReader: 读取字段 defaultFrameWidth 完成");
|
LogUtils.d(TAG, "readBeanFromJsonReader() 读取字段 | defaultFrameWidth=" + bean.getDefaultFrameWidth());
|
||||||
} else if (name.equals("defaultFrameHeight")) {
|
} else if (name.equals("defaultFrameHeight")) {
|
||||||
bean.setDefaultFrameHeight(jsonReader.nextInt());
|
bean.setDefaultFrameHeight(jsonReader.nextInt());
|
||||||
LogUtils.d(TAG, "readBeanFromJsonReader: 读取字段 defaultFrameHeight 完成");
|
LogUtils.d(TAG, "readBeanFromJsonReader() 读取字段 | defaultFrameHeight=" + bean.getDefaultFrameHeight());
|
||||||
} else {
|
} else {
|
||||||
jsonReader.skipValue();
|
jsonReader.skipValue();
|
||||||
LogUtils.w(TAG, String.format("readBeanFromJsonReader: 跳过未知字段 %s", name));
|
LogUtils.w(TAG, "readBeanFromJsonReader() 跳过未知字段 | " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonReader.endObject();
|
jsonReader.endObject();
|
||||||
LogUtils.d(TAG, "readBeanFromJsonReader: JSON 反序列化完成");
|
LogUtils.d(TAG, "readBeanFromJsonReader() JSON反序列化完成");
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================== Parcelable 接口实现(API30 Intent 传递必备,补充调试日志) ======================
|
// ====================== Parcelable 接口实现(API30 Intent 传递必备) ======================
|
||||||
@Override
|
@Override
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0; // 无特殊内容描述,固定返回0
|
return 0; // 无特殊内容描述,固定返回0
|
||||||
@@ -295,10 +301,9 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
dest.writeByte((byte) (isCharging ? 1 : 0));
|
dest.writeByte((byte) (isCharging ? 1 : 0));
|
||||||
dest.writeInt(currentBatteryValue);
|
dest.writeInt(currentBatteryValue);
|
||||||
dest.writeInt(batteryDetectInterval);
|
dest.writeInt(batteryDetectInterval);
|
||||||
// 新增相框配置字段写入
|
|
||||||
dest.writeInt(defaultFrameWidth);
|
dest.writeInt(defaultFrameWidth);
|
||||||
dest.writeInt(defaultFrameHeight);
|
dest.writeInt(defaultFrameHeight);
|
||||||
LogUtils.d(TAG, "writeToParcel: Parcel 序列化完成");
|
LogUtils.d(TAG, "writeToParcel() Parcel序列化完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 反序列化 Creator(必须 public static final 修饰,Java7 适配)
|
// 反序列化 Creator(必须 public static final 修饰,Java7 适配)
|
||||||
@@ -315,10 +320,9 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
|
|||||||
bean.isCharging = source.readByte() != 0;
|
bean.isCharging = source.readByte() != 0;
|
||||||
bean.currentBatteryValue = source.readInt();
|
bean.currentBatteryValue = source.readInt();
|
||||||
bean.batteryDetectInterval = source.readInt();
|
bean.batteryDetectInterval = source.readInt();
|
||||||
// 新增相框配置字段读取
|
|
||||||
bean.defaultFrameWidth = source.readInt();
|
bean.defaultFrameWidth = source.readInt();
|
||||||
bean.defaultFrameHeight = source.readInt();
|
bean.defaultFrameHeight = source.readInt();
|
||||||
LogUtils.d(TAG, "createFromParcel: Parcel 反序列化完成");
|
LogUtils.d(TAG, "createFromParcel() Parcel反序列化完成");
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public class ImageUtils {
|
|||||||
private static final int MIN_COMPRESS_QUALITY = 0;
|
private static final int MIN_COMPRESS_QUALITY = 0;
|
||||||
private static final int MAX_COMPRESS_QUALITY = 100;
|
private static final int MAX_COMPRESS_QUALITY = 100;
|
||||||
private static final int[] COLOR_ACCENT_ATTR = new int[]{R.attr.colorAccent}; // colorAccent属性数组
|
private static final int[] COLOR_ACCENT_ATTR = new int[]{R.attr.colorAccent}; // colorAccent属性数组
|
||||||
|
private static final int DEFAULT_COLOR = Color.parseColor("#FFFFFFFF"); // 默认返回颜色
|
||||||
|
|
||||||
// ================================== 主题颜色获取方法 =================================
|
// ================================== 主题颜色获取方法 =================================
|
||||||
/**
|
/**
|
||||||
@@ -42,23 +43,24 @@ public class ImageUtils {
|
|||||||
* @return 解析到的 colorAccent 颜色值,解析失败返回默认白色#FFFFFFFF
|
* @return 解析到的 colorAccent 颜色值,解析失败返回默认白色#FFFFFFFF
|
||||||
*/
|
*/
|
||||||
public static int getColorAccent(Context context) {
|
public static int getColorAccent(Context context) {
|
||||||
|
// 方法调用日志
|
||||||
LogUtils.d(TAG, "【getColorAccent】方法调用");
|
LogUtils.d(TAG, "【getColorAccent】方法调用");
|
||||||
// 参数校验
|
// 参数校验
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
LogUtils.e(TAG, "【getColorAccent】参数异常:Context为空");
|
LogUtils.e(TAG, "【getColorAccent】参数异常:Context为空");
|
||||||
return Color.parseColor("#FFFFFFFF");
|
return DEFAULT_COLOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedArray typedArray = null;
|
TypedArray typedArray = null;
|
||||||
try {
|
try {
|
||||||
// 从主题解析属性
|
// 从主题解析属性
|
||||||
typedArray = context.obtainStyledAttributes(COLOR_ACCENT_ATTR);
|
typedArray = context.obtainStyledAttributes(COLOR_ACCENT_ATTR);
|
||||||
int colorAccent = typedArray.getColor(0, Color.parseColor("#FFFFFFFF"));
|
int colorAccent = typedArray.getColor(0, DEFAULT_COLOR);
|
||||||
LogUtils.d(TAG, String.format("【getColorAccent】解析成功 | colorAccent=0x%08X", colorAccent));
|
LogUtils.d(TAG, String.format("【getColorAccent】解析成功 | colorAccent=0x%08X", colorAccent));
|
||||||
return colorAccent;
|
return colorAccent;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, "【getColorAccent】解析失败,返回默认颜色", e);
|
LogUtils.e(TAG, "【getColorAccent】解析失败,返回默认颜色", e);
|
||||||
return Color.parseColor("#FFFFFFFF");
|
return DEFAULT_COLOR;
|
||||||
} finally {
|
} finally {
|
||||||
// 回收资源
|
// 回收资源
|
||||||
if (typedArray != null) {
|
if (typedArray != null) {
|
||||||
@@ -68,7 +70,15 @@ public class ImageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ================================== 位图合成方法 =================================
|
||||||
|
/**
|
||||||
|
* 在纯色背景上绘制前景位图,实现FIT_CENTER居中效果
|
||||||
|
* @param bgColor 背景颜色
|
||||||
|
* @param originalFrameW 目标画布宽度
|
||||||
|
* @param originalFrameH 目标画布高度
|
||||||
|
* @param fgBitmap 前景位图
|
||||||
|
* @return 合成后的位图,失败返回null
|
||||||
|
*/
|
||||||
public static Bitmap drawBitmapOnSolidBackground(final int bgColor, int originalFrameW, int originalFrameH, Bitmap fgBitmap) {
|
public static Bitmap drawBitmapOnSolidBackground(final int bgColor, int originalFrameW, int originalFrameH, Bitmap fgBitmap) {
|
||||||
// 方法调用及入参日志
|
// 方法调用及入参日志
|
||||||
LogUtils.d(TAG, String.format("【drawBitmapOnSolidBackground】方法调用 | 背景色=0x%08X | 目标尺寸=%dx%d | 前景位图=%s",
|
LogUtils.d(TAG, String.format("【drawBitmapOnSolidBackground】方法调用 | 背景色=0x%08X | 目标尺寸=%dx%d | 前景位图=%s",
|
||||||
@@ -148,7 +158,6 @@ public class ImageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ================================== 核心压缩方法 =================================
|
// ================================== 核心压缩方法 =================================
|
||||||
/**
|
/**
|
||||||
* 图片质量压缩(JPEG格式),压缩后覆盖源文件
|
* 图片质量压缩(JPEG格式),压缩后覆盖源文件
|
||||||
|
|||||||
@@ -12,15 +12,12 @@ import android.view.View;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.ToastUtils;
|
|
||||||
import cc.winboll.studio.powerbell.App;
|
import cc.winboll.studio.powerbell.App;
|
||||||
import cc.winboll.studio.powerbell.models.BackgroundBean;
|
import cc.winboll.studio.powerbell.models.BackgroundBean;
|
||||||
import cc.winboll.studio.powerbell.utils.AppConfigUtils;
|
import cc.winboll.studio.powerbell.utils.AppConfigUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.ImageUtils;
|
import cc.winboll.studio.powerbell.utils.ImageUtils;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基于Java7的BackgroundView(LinearLayout+ImageView,保持原图比例居中平铺)
|
* 基于Java7的BackgroundView(LinearLayout+ImageView,保持原图比例居中平铺)
|
||||||
@@ -50,28 +47,28 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
// ====================================== 构造器(Java7兼容,按参数重载顺序排列) ======================================
|
// ====================================== 构造器(Java7兼容,按参数重载顺序排列) ======================================
|
||||||
public BackgroundView(Context context) {
|
public BackgroundView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
LogUtils.d(TAG, "BackgroundView() 构造器1启动 | context=" + context.getClass().getSimpleName());
|
LogUtils.d(TAG, String.format("【构造器1】启动 | context=%s", context.getClass().getSimpleName()));
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
initView();
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BackgroundView(Context context, AttributeSet attrs) {
|
public BackgroundView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
LogUtils.d(TAG, "BackgroundView(Context, AttributeSet) 构造器2启动 | context=" + context.getClass().getSimpleName());
|
LogUtils.d(TAG, String.format("【构造器2】启动 | context=%s", context.getClass().getSimpleName()));
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
initView();
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BackgroundView(Context context, AttributeSet attrs, int defStyleAttr) {
|
public BackgroundView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
LogUtils.d(TAG, "BackgroundView(Context, AttributeSet, int) 构造器3启动 | context=" + context.getClass().getSimpleName());
|
LogUtils.d(TAG, String.format("【构造器3】启动 | context=%s", context.getClass().getSimpleName()));
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
initView();
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================== 初始化方法(按执行顺序:主视图→子容器→图片控件→默认背景) ======================================
|
// ====================================== 初始化方法(按执行顺序:主视图→子容器→图片控件→默认背景) ======================================
|
||||||
private void initView() {
|
private void initView() {
|
||||||
LogUtils.d(TAG, "initView() 启动");
|
LogUtils.d(TAG, "【initView】启动");
|
||||||
// 1. 配置当前控件:全屏+透明
|
// 1. 配置当前控件:全屏+透明
|
||||||
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||||
// 2. 初始化主容器LinearLayout
|
// 2. 初始化主容器LinearLayout
|
||||||
@@ -80,11 +77,11 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
initImageView();
|
initImageView();
|
||||||
// 4. 初始设置透明背景
|
// 4. 初始设置透明背景
|
||||||
setDefaultEmptyBackground();
|
setDefaultEmptyBackground();
|
||||||
LogUtils.d(TAG, "initView() 完成");
|
LogUtils.d(TAG, "【initView】完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initLinearLayout() {
|
private void initLinearLayout() {
|
||||||
LogUtils.d(TAG, "initLinearLayout() 启动");
|
LogUtils.d(TAG, "【initLinearLayout】启动");
|
||||||
mLlContainer = new LinearLayout(mContext);
|
mLlContainer = new LinearLayout(mContext);
|
||||||
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(
|
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
@@ -94,11 +91,11 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
mLlContainer.setOrientation(LinearLayout.VERTICAL);
|
mLlContainer.setOrientation(LinearLayout.VERTICAL);
|
||||||
mLlContainer.setGravity(android.view.Gravity.CENTER);
|
mLlContainer.setGravity(android.view.Gravity.CENTER);
|
||||||
this.addView(mLlContainer);
|
this.addView(mLlContainer);
|
||||||
LogUtils.d(TAG, "initLinearLayout() 完成");
|
LogUtils.d(TAG, "【initLinearLayout】完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initImageView() {
|
private void initImageView() {
|
||||||
LogUtils.d(TAG, "initImageView() 启动");
|
LogUtils.d(TAG, "【initImageView】启动");
|
||||||
mIvBackground = new ImageView(mContext);
|
mIvBackground = new ImageView(mContext);
|
||||||
LinearLayout.LayoutParams ivParams = new LinearLayout.LayoutParams(
|
LinearLayout.LayoutParams ivParams = new LinearLayout.LayoutParams(
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
@@ -107,7 +104,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
mIvBackground.setLayoutParams(ivParams);
|
mIvBackground.setLayoutParams(ivParams);
|
||||||
mIvBackground.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
mIvBackground.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||||
mLlContainer.addView(mIvBackground);
|
mLlContainer.addView(mIvBackground);
|
||||||
LogUtils.d(TAG, "initImageView() 完成");
|
LogUtils.d(TAG, "【initImageView】完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================== 对外公开方法(按功能分类:Bean加载→图片加载) ======================================
|
// ====================================== 对外公开方法(按功能分类:Bean加载→图片加载) ======================================
|
||||||
@@ -116,21 +113,21 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadByBackgroundBean(BackgroundBean bean, boolean isRefresh) {
|
public void loadByBackgroundBean(BackgroundBean bean, boolean isRefresh) {
|
||||||
LogUtils.d(TAG, String.format("loadByBackgroundBean() 启动 | isRefresh=%b | bean=%s", isRefresh, bean));
|
LogUtils.d(TAG, String.format("【loadByBackgroundBean】启动 | isRefresh=%b | bean=%s", isRefresh, bean));
|
||||||
// 参数校验
|
// 参数校验
|
||||||
if (bean == null) {
|
if (bean == null) {
|
||||||
LogUtils.e(TAG, "loadByBackgroundBean() 异常:BackgroundBean为空");
|
LogUtils.e(TAG, "【loadByBackgroundBean】异常:BackgroundBean为空");
|
||||||
setDefaultEmptyBackground();
|
setDefaultEmptyBackground();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置图片背景色
|
// 设置图片背景色
|
||||||
mBgColor = bean.getPixelColor();
|
mBgColor = bean.getPixelColor();
|
||||||
LogUtils.d(TAG, String.format("loadByBackgroundBean() 背景色设置为 0x%08X", mBgColor));
|
LogUtils.d(TAG, String.format("【loadByBackgroundBean】背景色设置为 0x%08X", mBgColor));
|
||||||
|
|
||||||
// 判断是否使用背景文件
|
// 判断是否使用背景文件
|
||||||
if (!bean.isUseBackgroundFile()) {
|
if (!bean.isUseBackgroundFile()) {
|
||||||
LogUtils.d(TAG, "loadByBackgroundBean() 不使用背景文件,设置透明背景");
|
LogUtils.d(TAG, "【loadByBackgroundBean】不使用背景文件,设置透明背景");
|
||||||
setDefaultEmptyBackground();
|
setDefaultEmptyBackground();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -139,13 +136,14 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
String targetPath = bean.isUseBackgroundScaledCompressFile()
|
String targetPath = bean.isUseBackgroundScaledCompressFile()
|
||||||
? bean.getBackgroundScaledCompressFilePath()
|
? bean.getBackgroundScaledCompressFilePath()
|
||||||
: bean.getBackgroundFilePath();
|
: bean.getBackgroundFilePath();
|
||||||
LogUtils.d(TAG, String.format("loadByBackgroundBean() 目标路径=%s | 使用压缩文件=%b",
|
LogUtils.d(TAG, String.format("【loadByBackgroundBean】目标路径=%s | 使用压缩文件=%b",
|
||||||
targetPath, bean.isUseBackgroundScaledCompressFile()));
|
targetPath, bean.isUseBackgroundScaledCompressFile()));
|
||||||
|
|
||||||
// 校验文件是否存在
|
// 校验文件是否存在
|
||||||
File targetFile = new File(targetPath);
|
File targetFile = new File(targetPath);
|
||||||
if (!targetFile.exists() || !targetFile.isFile()) {
|
if (!targetFile.exists() || !targetFile.isFile()) {
|
||||||
LogUtils.e(TAG, "loadByBackgroundBean() 异常:图片文件不存在 | path=" + targetPath);
|
LogUtils.e(TAG, String.format("【loadByBackgroundBean】异常:图片文件不存在 | path=%s", targetPath));
|
||||||
|
setDefaultEmptyBackground();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +151,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadImage(int bgColor, String imagePath, boolean isRefresh) {
|
public void loadImage(int bgColor, String imagePath, boolean isRefresh) {
|
||||||
LogUtils.d(TAG, String.format("loadImage() 启动 | bgColor=0x%08X | imagePath=%s | isRefresh=%b",
|
LogUtils.d(TAG, String.format("【loadImage】启动 | bgColor=0x%08X | imagePath=%s | isRefresh=%b",
|
||||||
bgColor, imagePath, isRefresh));
|
bgColor, imagePath, isRefresh));
|
||||||
// 隐藏ImageView防止闪烁
|
// 隐藏ImageView防止闪烁
|
||||||
mIvBackground.setVisibility(View.GONE);
|
mIvBackground.setVisibility(View.GONE);
|
||||||
@@ -161,39 +159,36 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
// 初始化配置工具类并保存默认相框尺寸
|
// 初始化配置工具类并保存默认相框尺寸
|
||||||
AppConfigUtils appConfigUtils = AppConfigUtils.getInstance(mContext);
|
AppConfigUtils appConfigUtils = AppConfigUtils.getInstance(mContext);
|
||||||
appConfigUtils.loadAppConfig();
|
appConfigUtils.loadAppConfig();
|
||||||
LogUtils.d(TAG, String.format("W : %d, H : %d", appConfigUtils.mAppConfigBean.getDefaultFrameWidth(),
|
LogUtils.d(TAG, String.format("【loadImage】默认相框尺寸 | W=%d | H=%d",
|
||||||
|
appConfigUtils.mAppConfigBean.getDefaultFrameWidth(),
|
||||||
appConfigUtils.mAppConfigBean.getDefaultFrameHeight()));
|
appConfigUtils.mAppConfigBean.getDefaultFrameHeight()));
|
||||||
|
|
||||||
// 刷新逻辑:重新解码原始品质图片并更新缓存
|
// 刷新逻辑:重新解码原始品质图片并更新缓存
|
||||||
if (isRefresh) {
|
if (isRefresh) {
|
||||||
LogUtils.d(TAG, "loadImage() 执行刷新逻辑:重新解码原始品质图片");
|
LogUtils.d(TAG, "【loadImage】执行刷新逻辑:重新解码原始品质图片");
|
||||||
File imageFile = new File(imagePath);
|
File imageFile = new File(imagePath);
|
||||||
Bitmap newBitmap = decodeOriginalBitmap(imageFile);
|
Bitmap newBitmap = decodeOriginalBitmap(imageFile);
|
||||||
LogUtils.d(TAG, String.format("loadImage() 原始图片解码完成 | newBitmap=%s",
|
LogUtils.d(TAG, String.format("【loadImage】原始图片解码完成 | newBitmap=%s",
|
||||||
newBitmap != null ? newBitmap.getWidth() + "x" + newBitmap.getHeight() : "null"));
|
newBitmap != null ? newBitmap.getWidth() + "x" + newBitmap.getHeight() : "null"));
|
||||||
|
|
||||||
// 合成纯色背景图片(固定尺寸1197x2287)
|
// 合成纯色背景图片(使用配置文件中默认相框尺寸)
|
||||||
Bitmap combinedBitmap = ImageUtils.drawBitmapOnSolidBackground(bgColor,
|
Bitmap combinedBitmap = ImageUtils.drawBitmapOnSolidBackground(
|
||||||
|
bgColor,
|
||||||
appConfigUtils.mAppConfigBean.getDefaultFrameWidth(),
|
appConfigUtils.mAppConfigBean.getDefaultFrameWidth(),
|
||||||
appConfigUtils.mAppConfigBean.getDefaultFrameHeight(),
|
appConfigUtils.mAppConfigBean.getDefaultFrameHeight(),
|
||||||
newBitmap);
|
newBitmap
|
||||||
// Bitmap combinedBitmap = ImageUtils.drawBitmapOnSolidBackground(bgColor,
|
);
|
||||||
// 1200,
|
|
||||||
// 2283,
|
|
||||||
// newBitmap);
|
|
||||||
|
|
||||||
if (combinedBitmap == null) {
|
if (combinedBitmap == null) {
|
||||||
//ToastUtils.show("合成背景图片失败,使用原始图片");
|
LogUtils.e(TAG, "【loadImage】纯色背景合成失败,使用原始Bitmap");
|
||||||
LogUtils.e(TAG, "loadImage() 纯色背景合成失败,使用原始Bitmap");
|
|
||||||
combinedBitmap = newBitmap;
|
combinedBitmap = newBitmap;
|
||||||
} else {
|
} else {
|
||||||
//ToastUtils.show("合成背景图片成功");
|
LogUtils.d(TAG, String.format("【loadImage】纯色背景合成成功 | combinedBitmap=%dx%d",
|
||||||
LogUtils.d(TAG, String.format("loadImage() 纯色背景合成成功 | combinedBitmap=%dx%d",
|
|
||||||
combinedBitmap.getWidth(), combinedBitmap.getHeight()));
|
combinedBitmap.getWidth(), combinedBitmap.getHeight()));
|
||||||
// 回收原始Bitmap(避免重复缓存)
|
// 回收原始Bitmap(避免重复缓存)
|
||||||
if (newBitmap != null && !newBitmap.isRecycled() && newBitmap != combinedBitmap) {
|
if (newBitmap != null && !newBitmap.isRecycled() && newBitmap != combinedBitmap) {
|
||||||
newBitmap.recycle();
|
newBitmap.recycle();
|
||||||
LogUtils.d(TAG, "loadImage() 原始Bitmap已回收");
|
LogUtils.d(TAG, "【loadImage】原始Bitmap已回收");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,20 +197,20 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
App.sBitmapCacheUtils.cacheBitmap(imagePath, combinedBitmap);
|
App.sBitmapCacheUtils.cacheBitmap(imagePath, combinedBitmap);
|
||||||
App.sBitmapCacheUtils.increaseRefCount(imagePath);
|
App.sBitmapCacheUtils.increaseRefCount(imagePath);
|
||||||
mCurrentCachedPath = imagePath;
|
mCurrentCachedPath = imagePath;
|
||||||
LogUtils.d(TAG, String.format("loadImage() 刷新缓存成功 | path=%s", imagePath));
|
LogUtils.d(TAG, String.format("【loadImage】刷新缓存成功 | path=%s", imagePath));
|
||||||
} else {
|
} else {
|
||||||
LogUtils.e(TAG, String.format("loadImage() 刷新解码失败 | path=%s", imagePath));
|
LogUtils.e(TAG, String.format("【loadImage】刷新解码失败 | path=%s", imagePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载缓存图片
|
// 加载缓存图片
|
||||||
Bitmap cachedBitmap = App.sBitmapCacheUtils.getCachedBitmap(imagePath);
|
Bitmap cachedBitmap = App.sBitmapCacheUtils.getCachedBitmap(imagePath);
|
||||||
LogUtils.d(TAG, String.format("loadImage() 加载缓存图片 | cachedBitmap=%s",
|
LogUtils.d(TAG, String.format("【loadImage】加载缓存图片 | cachedBitmap=%s",
|
||||||
cachedBitmap != null ? cachedBitmap.getWidth() + "x" + cachedBitmap.getHeight() : "null"));
|
cachedBitmap != null ? cachedBitmap.getWidth() + "x" + cachedBitmap.getHeight() : "null"));
|
||||||
mIvBackground.setImageBitmap(cachedBitmap);
|
mIvBackground.setImageBitmap(cachedBitmap);
|
||||||
mIvBackground.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
mIvBackground.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||||
mIvBackground.setVisibility(View.VISIBLE);
|
mIvBackground.setVisibility(View.VISIBLE);
|
||||||
LogUtils.d(TAG, "loadImage() 完成");
|
LogUtils.d(TAG, "【loadImage】完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================== 内部工具方法(按功能分类:Bitmap校验→比例计算→解码→背景设置) ======================================
|
// ====================================== 内部工具方法(按功能分类:Bitmap校验→比例计算→解码→背景设置) ======================================
|
||||||
@@ -225,7 +220,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
private boolean isBitmapValid(Bitmap bitmap) {
|
private boolean isBitmapValid(Bitmap bitmap) {
|
||||||
boolean valid = bitmap != null && !bitmap.isRecycled();
|
boolean valid = bitmap != null && !bitmap.isRecycled();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
LogUtils.w(TAG, "isBitmapValid() 无效:Bitmap为空或已回收");
|
LogUtils.w(TAG, "【isBitmapValid】无效:Bitmap为空或已回收");
|
||||||
}
|
}
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
@@ -234,7 +229,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
* 计算图片宽高比
|
* 计算图片宽高比
|
||||||
*/
|
*/
|
||||||
private boolean calculateImageAspectRatio(File file) {
|
private boolean calculateImageAspectRatio(File file) {
|
||||||
LogUtils.d(TAG, String.format("calculateImageAspectRatio() 启动 | file=%s", file.getAbsolutePath()));
|
LogUtils.d(TAG, String.format("【calculateImageAspectRatio】启动 | file=%s", file.getAbsolutePath()));
|
||||||
try {
|
try {
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inJustDecodeBounds = true;
|
options.inJustDecodeBounds = true;
|
||||||
@@ -244,16 +239,16 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
int width = options.outWidth;
|
int width = options.outWidth;
|
||||||
int height = options.outHeight;
|
int height = options.outHeight;
|
||||||
if (width <= 0 || height <= 0) {
|
if (width <= 0 || height <= 0) {
|
||||||
LogUtils.e(TAG, String.format("calculateImageAspectRatio() 无效尺寸 | width=%d | height=%d", width, height));
|
LogUtils.e(TAG, String.format("【calculateImageAspectRatio】无效尺寸 | width=%d | height=%d", width, height));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算比例
|
// 计算比例
|
||||||
mImageAspectRatio = (float) width / height;
|
mImageAspectRatio = (float) width / height;
|
||||||
LogUtils.d(TAG, String.format("calculateImageAspectRatio() 完成 | 比例=%.2f", mImageAspectRatio));
|
LogUtils.d(TAG, String.format("【calculateImageAspectRatio】完成 | 比例=%.2f", mImageAspectRatio));
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, "calculateImageAspectRatio() 失败:" + e.getMessage());
|
LogUtils.e(TAG, String.format("【calculateImageAspectRatio】失败:%s", e.getMessage()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,7 +257,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
* 移除压缩逻辑:解码原始品质图片(无缩放、无色彩损失)
|
* 移除压缩逻辑:解码原始品质图片(无缩放、无色彩损失)
|
||||||
*/
|
*/
|
||||||
private Bitmap decodeOriginalBitmap(File file) {
|
private Bitmap decodeOriginalBitmap(File file) {
|
||||||
LogUtils.d(TAG, String.format("decodeOriginalBitmap() 启动 | file=%s", file.getAbsolutePath()));
|
LogUtils.d(TAG, String.format("【decodeOriginalBitmap】启动 | file=%s", file.getAbsolutePath()));
|
||||||
try {
|
try {
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
// 核心配置:原始品质
|
// 核心配置:原始品质
|
||||||
@@ -276,13 +271,13 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
// 解码图片
|
// 解码图片
|
||||||
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
LogUtils.d(TAG, String.format("decodeOriginalBitmap() 成功 | width=%d | height=%d", bitmap.getWidth(), bitmap.getHeight()));
|
LogUtils.d(TAG, String.format("【decodeOriginalBitmap】成功 | width=%d | height=%d", bitmap.getWidth(), bitmap.getHeight()));
|
||||||
} else {
|
} else {
|
||||||
LogUtils.e(TAG, "decodeOriginalBitmap() 失败:返回null");
|
LogUtils.e(TAG, "【decodeOriginalBitmap】失败:返回null");
|
||||||
}
|
}
|
||||||
return bitmap;
|
return bitmap;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, "decodeOriginalBitmap() 异常:" + e.getMessage());
|
LogUtils.e(TAG, String.format("【decodeOriginalBitmap】异常:%s", e.getMessage()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -291,18 +286,18 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
* 设置默认透明背景,仅减少引用计数,不删除缓存
|
* 设置默认透明背景,仅减少引用计数,不删除缓存
|
||||||
*/
|
*/
|
||||||
private void setDefaultEmptyBackground() {
|
private void setDefaultEmptyBackground() {
|
||||||
LogUtils.d(TAG, "setDefaultEmptyBackground() 启动");
|
LogUtils.d(TAG, "【setDefaultEmptyBackground】启动");
|
||||||
// 清空ImageView
|
// 清空ImageView
|
||||||
mIvBackground.setImageDrawable(null);
|
mIvBackground.setImageDrawable(null);
|
||||||
mImageAspectRatio = 1.0f;
|
mImageAspectRatio = 1.0f;
|
||||||
|
|
||||||
// 减少引用计数,不删除缓存
|
// 减少引用计数,不删除缓存
|
||||||
if (!TextUtils.isEmpty(mCurrentCachedPath)) {
|
if (!TextUtils.isEmpty(mCurrentCachedPath)) {
|
||||||
LogUtils.d(TAG, String.format("setDefaultEmptyBackground() 减少引用计数 | path=%s", mCurrentCachedPath));
|
LogUtils.d(TAG, String.format("【setDefaultEmptyBackground】减少引用计数 | path=%s", mCurrentCachedPath));
|
||||||
App.sBitmapCacheUtils.decreaseRefCount(mCurrentCachedPath);
|
App.sBitmapCacheUtils.decreaseRefCount(mCurrentCachedPath);
|
||||||
mCurrentCachedPath = "";
|
mCurrentCachedPath = "";
|
||||||
}
|
}
|
||||||
LogUtils.d(TAG, "setDefaultEmptyBackground() 完成");
|
LogUtils.d(TAG, "【setDefaultEmptyBackground】完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================== 重写生命周期方法(按执行顺序:绘制→尺寸变化→窗口分离) ======================================
|
// ====================================== 重写生命周期方法(按执行顺序:绘制→尺寸变化→窗口分离) ======================================
|
||||||
@@ -316,7 +311,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
||||||
Bitmap bitmap = bitmapDrawable.getBitmap();
|
Bitmap bitmap = bitmapDrawable.getBitmap();
|
||||||
if (!isBitmapValid(bitmap)) {
|
if (!isBitmapValid(bitmap)) {
|
||||||
LogUtils.e(TAG, "onDraw() 检测到已回收Bitmap,清空绘制");
|
LogUtils.e(TAG, "【onDraw】检测到已回收Bitmap,清空绘制");
|
||||||
mIvBackground.setImageDrawable(null);
|
mIvBackground.setImageDrawable(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -330,7 +325,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
LogUtils.d(TAG, String.format("onSizeChanged() 尺寸变化 | newW=%d | newH=%d | oldW=%d | oldH=%d", w, h, oldw, oldh));
|
LogUtils.d(TAG, String.format("【onSizeChanged】尺寸变化 | newW=%d | newH=%d | oldW=%d | oldH=%d", w, h, oldw, oldh));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -339,17 +334,17 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow() {
|
protected void onDetachedFromWindow() {
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
LogUtils.d(TAG, "onDetachedFromWindow() 启动");
|
LogUtils.d(TAG, "【onDetachedFromWindow】启动");
|
||||||
// 清空ImageView的Drawable,释放本地引用
|
// 清空ImageView的Drawable,释放本地引用
|
||||||
mIvBackground.setImageDrawable(null);
|
mIvBackground.setImageDrawable(null);
|
||||||
|
|
||||||
// 减少引用计数,不删除全局缓存
|
// 减少引用计数,不删除全局缓存
|
||||||
if (!TextUtils.isEmpty(mCurrentCachedPath)) {
|
if (!TextUtils.isEmpty(mCurrentCachedPath)) {
|
||||||
LogUtils.d(TAG, String.format("onDetachedFromWindow() 减少引用计数 | path=%s", mCurrentCachedPath));
|
LogUtils.d(TAG, String.format("【onDetachedFromWindow】减少引用计数 | path=%s", mCurrentCachedPath));
|
||||||
App.sBitmapCacheUtils.decreaseRefCount(mCurrentCachedPath);
|
App.sBitmapCacheUtils.decreaseRefCount(mCurrentCachedPath);
|
||||||
mCurrentCachedPath = "";
|
mCurrentCachedPath = "";
|
||||||
}
|
}
|
||||||
LogUtils.d(TAG, "onDetachedFromWindow() 完成");
|
LogUtils.d(TAG, "【onDetachedFromWindow】完成");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user