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