Skip to content

Commit

Permalink
修复高版本拍照无法裁剪和保存的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
weimingjue committed Jul 7, 2023
1 parent 550d827 commit 0bfeb5a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions simple/src/main/java/org/devio/simple/CustomHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.devio.simple;

import android.net.Uri;
import android.os.Environment;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
Expand All @@ -11,6 +10,7 @@
import org.devio.takephoto.model.CropOptions;
import org.devio.takephoto.model.LubanOptions;
import org.devio.takephoto.model.TakePhotoOptions;
import org.devio.takephoto.uitl.TFileUtils;

import java.io.File;

Expand Down Expand Up @@ -73,7 +73,7 @@ private void init() {
}

public void onClick(View view, TakePhoto takePhoto) {
File file = new File(Environment.getExternalStorageDirectory(), "/temp/" + System.currentTimeMillis() + ".jpg");
File file = new File(TFileUtils.getSuggestCacheDir(view.getContext()), "/temp/" + System.currentTimeMillis() + ".jpg");
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
Expand Down
4 changes: 3 additions & 1 deletion simple/src/main/res/layout/common_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:checked="true"
android:checked="false"
android:enabled="false"
android:text="第三方" />

<RadioButton
android:id="@+id/rbCropOwn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="TakePhoto自带" />
</RadioGroup>
</LinearLayout>
Expand Down
4 changes: 3 additions & 1 deletion takephoto_library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

<application android:allowBackup="true">
<application
android:allowBackup="true"
android:requestLegacyExternalStorage="true">
<activity
android:name="com.soundcloud.android.crop.CropImageActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.devio.takephoto.model;

import android.support.annotation.RequiresApi;

import java.io.Serializable;

/**
Expand All @@ -11,7 +13,7 @@ public class CropOptions implements Serializable {
/**
* 使用TakePhoto自带的裁切工具进行裁切
*/
private boolean withOwnCrop;
private boolean withOwnCrop = true;
private int aspectX;
private int aspectY;
private int outputX;
Expand Down Expand Up @@ -56,8 +58,13 @@ public boolean isWithOwnCrop() {
return withOwnCrop;
}

/**
* 修改为内部文件,不支持系统裁剪
*/
@RequiresApi(9999)
@Deprecated
public void setWithOwnCrop(boolean withOwnCrop) {
this.withOwnCrop = withOwnCrop;
// this.withOwnCrop = withOwnCrop;
}

public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ public static void delete(String path) {
e.printStackTrace();
}
}

public static File getSuggestCacheDir(Context context) {
File ef = context.getExternalCacheDir();
if (ef == null) {
return context.getCacheDir();
}
return ef;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
Expand Down Expand Up @@ -55,7 +54,7 @@ public static Uri convertFileUriToFileProviderUri(Context context, Uri uri) {
*/
public static Uri getTempUri(Context context) {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
File file = new File(Environment.getExternalStorageDirectory(), "/images/" + timeStamp + ".jpg");
File file = new File(TFileUtils.getSuggestCacheDir(context), "/images/" + timeStamp + ".jpg");
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
Expand Down

0 comments on commit 0bfeb5a

Please sign in to comment.