20251127_212052_680正在调试图片文件存储问题。

This commit is contained in:
2025-11-27 21:21:25 +08:00
parent bc8a63867c
commit 5aa54091e5
3 changed files with 75 additions and 32 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Thu Nov 27 19:24:29 HKT 2025
#Thu Nov 27 13:19:32 GMT 2025
stageCount=11
libraryProject=
baseVersion=15.11
publishVersion=15.11.10
buildCount=0
buildCount=19
baseBetaVersion=15.11.11

View File

@@ -35,6 +35,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import androidx.core.util.Preconditions;
public class BackgroundPictureActivity extends WinBoLLActivity implements BackgroundPicturePreviewDialog.IOnRecivedPictureListener {
@@ -53,14 +54,20 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
private File mfTakePhoto; // 拍照文件
private File mfRecivedPicture; // 接收的图片文件
private File mfTempCropPicture; // 剪裁临时文件
private File mfRecivedCropPicture; // 剪裁后的目标文件
private String preViewFileBackgroundView = "";
// 背景视图预览图片的文件名
private String preViewFilePathBackgroundView = "";
BackgroundView bvPreviewBackground;
boolean isCommitSettings = false;
// 静态变量
public static String _mszRecivedCropPicture = "RecivedCrop.jpg";
//public static String _mszRecivedCropPicture = "RecivedCrop.jpg";
// 源文件的剪裁图片保存名称
private static String _mSourceCroppedFileName = "SourceCropped.jpg";
// 源文件的剪裁图片保存文件对象
private static File _mSourceCroppedFile;
// 源文件的剪裁图片保存路径
private static String _mSourceCroppedFilePath;
private static String _mszCommonFileType = "jpeg";
private int mnPictureCompress = 100;
private static String _RecivedPictureFileName;
@@ -97,8 +104,10 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
mfTakePhoto = new File(mfPictureDir, "TakePhoto.jpg");
mfTempCropPicture = new File(mfPictureDir, "TempCrop.jpg");
mfRecivedPicture = getRecivedPictureFile(this);
mfRecivedCropPicture = new File(mfBackgroundDir, _mszRecivedCropPicture);
mfRecivedPicture = getRecivedPictureFile();
_mSourceCroppedFile = new File(mfBackgroundDir, _mSourceCroppedFileName);
_mSourceCroppedFilePath = _mSourceCroppedFile.getAbsolutePath().toString();
LogUtils.d(TAG, String.format("_mSourceCroppedFilePath : %s", _mSourceCroppedFilePath));
// 初始化工具栏
mAToolbar = (AToolbar) findViewById(R.id.toolbar);
@@ -137,11 +146,11 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
private void initEnv() {
LogUtils.d(TAG, "initEnv()");
_RecivedPictureFileName = "Recived.data";
_RecivedPictureFileName = "SourcePicture.data";
}
public static String getBackgroundFileName() {
return _mszRecivedCropPicture;
return _mSourceCroppedFileName;
}
@Override
@@ -163,17 +172,21 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
*/
public void updatePreviewBackground() {
LogUtils.d(TAG, "updatePreviewBackground");
LogUtils.d(TAG, String.format("_mSourceCroppedFilePath : %s", _mSourceCroppedFilePath));
//ImageView ivPreviewBackground = (ImageView) findViewById(R.id.activitybackgroundpictureImageView1);
bvPreviewBackground = (BackgroundView) findViewById(R.id.activitybackgroundpictureBackgroundView1);
BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(this);
utils.loadBackgroundPictureBean();
boolean isUseBackgroundFile = utils.getBackgroundPictureBean().isUseBackgroundFile();
if (isUseBackgroundFile && mfRecivedCropPicture.exists()) {
//try {
String filePath = utils.getBackgroundDir() + getBackgroundFileName();
preViewFileBackgroundView = filePath;
bvPreviewBackground.previewBackgroundImage(preViewFileBackgroundView);
LogUtils.d(TAG, String.format("isUseBackgroundFile is %s, _mSourceCroppedFile.exists() is %s ", isUseBackgroundFile, _mSourceCroppedFile.exists()));
if (isUseBackgroundFile && _mSourceCroppedFile.exists()) {
//try {
//String filePath = utils.getBackgroundDir() + getBackgroundFileName();
preViewFilePathBackgroundView = _mSourceCroppedFilePath;
LogUtils.d(TAG, String.format("preViewFilePathBackgroundView : %s", preViewFilePathBackgroundView));
bvPreviewBackground.previewBackgroundImage(preViewFilePathBackgroundView);
/*Drawable drawable = FileUtils.getImageDrawable(filePath);
if (drawable != null) {
//drawable.setAlpha(120);
@@ -186,8 +199,8 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
// }
} else {
ToastUtils.show("未使用背景图片");
preViewFileBackgroundView = "";
bvPreviewBackground.previewBackgroundImage(preViewFileBackgroundView);
preViewFilePathBackgroundView = "";
bvPreviewBackground.previewBackgroundImage(preViewFilePathBackgroundView);
// Drawable drawable = getResources().getDrawable(R.drawable.blank10x10);
// if (drawable != null) {
// drawable.setAlpha(120);
@@ -281,7 +294,7 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
public void onClick(View v) {
// 从文件路径启动像素拾取活动
//String imagePath = "/storage/emulated/0/DCIM/Camera/sample.jpg";
String imagePath = mfRecivedCropPicture.toString();
String imagePath = _mSourceCroppedFile.toString();
Intent intent = new Intent(getApplicationContext(), PixelPickerActivity.class);
intent.putExtra("imagePath", imagePath);
startActivity(intent);
@@ -306,7 +319,7 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
void compressQualityToRecivedPicture(Bitmap bitmap) {
OutputStream outStream = null;
try {
mfRecivedPicture = getRecivedPictureFile(this);
mfRecivedPicture = getRecivedPictureFile();
if (!mfRecivedPicture.exists()) {
mfRecivedPicture.createNewFile();
}
@@ -339,7 +352,7 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
public void startCropImageActivity(boolean isCropFree) {
LogUtils.d(TAG, "startCropImageActivity");
BackgroundPictureBean bean = mBackgroundPictureUtils.loadBackgroundPictureBean();
mfRecivedPicture = getRecivedPictureFile(this);
mfRecivedPicture = getRecivedPictureFile();
Uri uri = UriUtil.getUriForFile(this, mfRecivedPicture);
LogUtils.d(TAG, "uri : " + uri.toString());
@@ -425,10 +438,13 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
boolean success = scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos);
fos.flush();
if (success) {
ToastUtils.show("保存成功");
//ToastUtils.show("保存成功");
// 更新数据
mBackgroundPictureUtils.getBackgroundPictureBean().setIsUseBackgroundFile(true);
updatePreviewBackground();
BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(BackgroundPictureActivity.this);
BackgroundPictureBean bean = utils.getBackgroundPictureBean();
bean.setIsUseBackgroundFile(true);
utils.saveData();
updatePreviewBackground();
} else {
ToastUtils.show("图片压缩保存失败");
}
@@ -476,12 +492,19 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
startActivity(Intent.createChooser(shareIntent, "Share Image"));
}
public static File getRecivedPictureFile(Context context) {
BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(context);
public File getRecivedPictureFile() {
BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(this);
utils.loadBackgroundPictureBean();
return new File(utils.getBackgroundDir(), _RecivedPictureFileName);
}
public void saveToRecivedPictureFile(String srcFilePath) {
BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(this);
utils.loadBackgroundPictureBean();
File dstFile = new File(utils.getBackgroundDir(), _RecivedPictureFileName);
FileUtils.copyFile(new File(srcFilePath), dstFile);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -490,7 +513,7 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
Uri selectedImage = data.getData();
LogUtils.d(TAG, "Uri is : " + selectedImage.toString());
File fSrcImage = new File(UriUtil.getFilePathFromUri(this, selectedImage));
mfRecivedPicture = getRecivedPictureFile(this);
mfRecivedPicture = getRecivedPictureFile();
if (FileUtils.copyFile(fSrcImage, mfRecivedPicture)) {
startCropImageActivity(false);
} else {
@@ -605,8 +628,16 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
// 在需要显示对话框的地方(如网络状态监听回调中)
NetworkBackgroundDialog dialog = new NetworkBackgroundDialog(this, new NetworkBackgroundDialog.OnDialogClickListener() {
@Override
public void onConfirm() {
ToastUtils.show("onConfirm");
public void onConfirm(String szConfirmFilePath) {
//ToastUtils.show("onConfirm");
onRecivedPictureListener.onRecivedPicture(szConfirmFilePath);
//((BackgroundPicturePreviewDialog.IOnRecivedPictureListener)this).onAcceptRecivedPicture(szConfirmFilePath);
// 设置预览图
preViewFilePathBackgroundView = szConfirmFilePath;
bvPreviewBackground.previewBackgroundImage(preViewFilePathBackgroundView);
// 处理确认逻辑(如允许后台网络使用)
LogUtils.d("MainActivity", "用户允许后台网络使用");
// 执行具体业务:如开启后台网络请求服务
@@ -614,7 +645,7 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
@Override
public void onCancel() {
ToastUtils.show("onCancel");
//ToastUtils.show("onCancel");
// 处理取消逻辑(如禁止后台网络使用)
LogUtils.d("MainActivity", "用户禁止后台网络使用");
// 执行具体业务:如关闭后台网络请求
@@ -630,6 +661,18 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
}
interface OnRecivedPictureListener {
void onRecivedPicture(String srcFilePath);
}
OnRecivedPictureListener onRecivedPictureListener = new OnRecivedPictureListener(){
@Override
public void onRecivedPicture(String srcFilePath) {
saveToRecivedPictureFile(srcFilePath);
startCropImageActivity(true);
}
};
/**
* 重写finish方法确保所有退出场景都触发Toast
*/
@@ -646,7 +689,7 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
@Override
public void onYes() {
bvPreviewBackground.saveToBackgroundSources(preViewFileBackgroundView);
bvPreviewBackground.saveToBackgroundSources(preViewFilePathBackgroundView);
isCommitSettings = true;
finish();
}

View File

@@ -49,7 +49,7 @@ public class NetworkBackgroundDialog extends AlertDialog {
// 按钮点击回调接口Java7 接口实现)
public interface OnDialogClickListener {
void onConfirm(); // 确认按钮点击
void onConfirm(String szConfirmFilePath); // 确认按钮点击
void onCancel(); // 取消按钮点击
}
@@ -162,11 +162,11 @@ public class NetworkBackgroundDialog extends AlertDialog {
public void onClick(View v) {
LogUtils.d("NetworkBackgroundDialog", "确认按钮点击");
// 确定预览背景资源
bvBackgroundPreview.saveToBackgroundSources(previewFilePath);
bvBackgroundPreview.previewBackgroundImage(previewFilePath);
dismiss(); // 关闭对话框
if (listener != null) {
listener.onConfirm();
listener.onConfirm(previewFilePath);
}
}
});