修复系统分享图片的接收功能。
This commit is contained in:
@@ -6,7 +6,6 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -24,10 +23,10 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.powerbell.App;
|
||||
import cc.winboll.studio.powerbell.R;
|
||||
import cc.winboll.studio.powerbell.dialogs.BackgroundPicturePreviewDialog;
|
||||
import cc.winboll.studio.powerbell.dialogs.ColorPaletteDialog;
|
||||
import cc.winboll.studio.powerbell.dialogs.NetworkBackgroundDialog;
|
||||
import cc.winboll.studio.powerbell.dialogs.YesNoAlertDialog;
|
||||
import cc.winboll.studio.powerbell.models.BackgroundBean;
|
||||
import cc.winboll.studio.powerbell.utils.BackgroundSourceUtils;
|
||||
@@ -37,8 +36,6 @@ import cc.winboll.studio.powerbell.utils.ImageCropUtils;
|
||||
import cc.winboll.studio.powerbell.utils.UriUtils;
|
||||
import cc.winboll.studio.powerbell.views.BackgroundView;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import cc.winboll.studio.powerbell.dialogs.NetworkBackgroundDialog;
|
||||
|
||||
public class BackgroundSettingsActivity extends WinBoLLActivity {
|
||||
|
||||
@@ -432,64 +429,6 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
||||
}, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析裁剪临时文件为 Bitmap,带采样率优化
|
||||
* @param cropTempFile 裁剪临时文件
|
||||
* @return 解析后的Bitmap,失败返回null
|
||||
*/
|
||||
private Bitmap parseCropTempFileToBitmap(File cropTempFile) {
|
||||
LogUtils.d(TAG, "【工具方法】解析裁剪文件:" + (cropTempFile != null ? cropTempFile.getAbsolutePath() : "null"));
|
||||
if (cropTempFile == null || !cropTempFile.exists() || !cropTempFile.isFile() || cropTempFile.length() <= 100) {
|
||||
LogUtils.e(TAG, "【Bitmap解析】文件无效");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 计算采样率
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(cropTempFile.getAbsolutePath(), options);
|
||||
|
||||
int sampleSize = calculateSampleSize(options.outWidth, options.outHeight);
|
||||
LogUtils.d(TAG, "【Bitmap解析】采样率:" + sampleSize);
|
||||
|
||||
// 解析Bitmap
|
||||
options.inJustDecodeBounds = false;
|
||||
options.inSampleSize = sampleSize;
|
||||
options.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
options.inPurgeable = true;
|
||||
options.inInputShareable = true;
|
||||
|
||||
try {
|
||||
Bitmap cropBitmap = BitmapFactory.decodeFile(cropTempFile.getAbsolutePath(), options);
|
||||
if (!isBitmapValid(cropBitmap)) {
|
||||
LogUtils.e(TAG, "【Bitmap解析】解析失败");
|
||||
return null;
|
||||
}
|
||||
LogUtils.d(TAG, "【Bitmap解析】成功,尺寸:" + cropBitmap.getWidth() + "x" + cropBitmap.getHeight());
|
||||
return cropBitmap;
|
||||
} catch (OutOfMemoryError e) {
|
||||
LogUtils.e(TAG, "【Bitmap解析】OOM异常");
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "【Bitmap解析】异常:" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算Bitmap采样率
|
||||
* @param width 图片宽度
|
||||
* @param height 图片高度
|
||||
* @return 采样率
|
||||
*/
|
||||
private int calculateSampleSize(int width, int height) {
|
||||
int sampleSize = 1;
|
||||
while (width / sampleSize > BITMAP_MAX_SIZE || height / sampleSize > BITMAP_MAX_SIZE) {
|
||||
sampleSize *= 2;
|
||||
}
|
||||
return Math.min(sampleSize, BITMAP_MAX_SAMPLE_SIZE);
|
||||
}
|
||||
|
||||
// ====================== 业务逻辑方法(按功能分类)======================
|
||||
/**
|
||||
* 初始化核心组件(工具类+视图)
|
||||
@@ -550,11 +489,13 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
||||
* 显示分享图片预览对话框
|
||||
*/
|
||||
private void showSharePreviewDialog() {
|
||||
LogUtils.d(TAG, "showSharePreviewDialog()");
|
||||
BackgroundPicturePreviewDialog dlg = new BackgroundPicturePreviewDialog(this, new BackgroundPicturePreviewDialog.IOnRecivedPictureListener() {
|
||||
@Override
|
||||
public void onAcceptRecivedPicture(Uri uriRecivedPicture) {
|
||||
ToastUtils.show("已接收图片:" + uriRecivedPicture);
|
||||
LogUtils.d(TAG, "【分享处理】接收图片Uri:" + uriRecivedPicture);
|
||||
if (putUriFileToPreviewSource(uriRecivedPicture)) {
|
||||
startImageCrop(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
dlg.show();
|
||||
@@ -567,17 +508,14 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
||||
* @return 是图片返回true,否则false
|
||||
*/
|
||||
private boolean isImageType(String mimeType) {
|
||||
if (mimeType == null) {
|
||||
return false;
|
||||
}
|
||||
String lowerMimeType = mimeType.toLowerCase();
|
||||
return lowerMimeType.equals("image/jpeg")
|
||||
|| lowerMimeType.equals("image/png")
|
||||
|| lowerMimeType.equals("image/tiff")
|
||||
|| lowerMimeType.equals("image/jpg")
|
||||
|| lowerMimeType.equals("image/svg+xml");
|
||||
}
|
||||
|
||||
if (mimeType == null) {
|
||||
return false;
|
||||
}
|
||||
String lowerMimeType = mimeType.toLowerCase();
|
||||
LogUtils.d("isImageType", "mimeType: " + mimeType + ", lowerMimeType: " + lowerMimeType);
|
||||
return lowerMimeType.startsWith("image/");
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动图片选择器
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user