詹子聪 преди 5 години
родител
ревизия
9560a3f4bb

+ 2 - 2
app/build.gradle

@@ -7,8 +7,8 @@ android {
         applicationId "com.miekir.ocr"
         minSdkVersion versions.minSdk
         targetSdkVersion versions.targetSdk
-        versionCode 17
-        versionName "1.0.17"
+        versionCode 18
+        versionName "1.0.18"
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
     }
 

+ 2 - 2
app/src/main/java/com/miekir/ocr/ui/OperationPresenter.java

@@ -34,7 +34,7 @@ import io.reactivex.annotations.NonNull;
 import io.reactivex.schedulers.Schedulers;
 import top.zibin.luban.Luban;
 
-import static android.os.Environment.DIRECTORY_PICTURES;
+import static com.miekir.ocr.ui.camera.otalia.OtaOperationActivity.DIR_PICTURE;
 
 /**
  * @author 詹子聪
@@ -85,7 +85,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                     }
 
                     if (multi > 1) {
-                        File file = new File(Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES) + "/" + System.currentTimeMillis() + ".jpg");
+                        File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + DIR_PICTURE  + "/" + System.currentTimeMillis() + ".jpg");
                         if (!file.getParentFile().exists()) {
                             file.getParentFile().mkdirs();
                         }

+ 5 - 3
app/src/main/java/com/miekir/ocr/ui/camera/otalia/OtaOperationActivity.java

@@ -32,8 +32,6 @@ import com.zhihu.matisse.MimeType;
 import java.io.File;
 import java.util.List;
 
-import static android.os.Environment.DIRECTORY_PICTURES;
-
 /**
  * Copyright (C), 2019-2020, Genlot
  *
@@ -43,6 +41,7 @@ import static android.os.Environment.DIRECTORY_PICTURES;
  */
 public class OtaOperationActivity extends OtaCameraActivity implements CropView.OnRectChangeListener, View.OnClickListener, IOperationView {
     private static final int REQUEST_CODE_CHOOSE = 6;
+    public static final String DIR_PICTURE = "ocr_pictures";
 
     @InjectPresenter
     OperationPresenter mOperationPresenter;
@@ -303,7 +302,10 @@ public class OtaOperationActivity extends OtaCameraActivity implements CropView.
         }
         // 得到裁剪后的图片数据
         int[] rectData = new int[]{mLeft, mTop, mRight, mBottom};
-        File file = new File(Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES) + "/" + System.currentTimeMillis() + ".jpg");
+        File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + DIR_PICTURE + "/" + System.currentTimeMillis() + ".jpg");
+        if (!file.getParentFile().exists()) {
+            file.getParentFile().mkdirs();
+        }
         if (tv_orientation.getVisibility() == View.VISIBLE) {
             mOperationPresenter.startOcrFromBitmap(this, bitmap, rectData, file, mCurrentScene, pcv_scan.isLandscape());
         } else {

+ 7 - 8
app/src/main/java/com/miekir/ocr/widget/CropView.java

@@ -182,12 +182,7 @@ public class CropView extends View {
 
     @SuppressWarnings("deprecation")
     private void init() {
-        float handleLineLeftX = mFrameRectF.left - mHandleWidth;
-        float handleLineRightX = mFrameRectF.right + mHandleWidth;
-        float handleLineTopY = mFrameRectF.top - mHandleWidth;
-        float handleLineBottomY = mFrameRectF.bottom + mHandleWidth;
-        coverWidth = (int) (handleLineRightX - handleLineLeftX);
-        coverHeight = (int) (handleLineBottomY - handleLineTopY);
+        onCropRectChanged();
 
         WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
         int width = manager.getDefaultDisplay().getWidth();
@@ -263,8 +258,7 @@ public class CropView extends View {
         //doLayout(mViewWidth, mViewHeight);
     }
 
-    @Override
-    public boolean onTouchEvent(MotionEvent event) {
+    private void onCropRectChanged() {
         float handleLineLeftX = mFrameRectF.left - mHandleWidth;
         float handleLineRightX = mFrameRectF.right + mHandleWidth;
         float handleLineTopY = mFrameRectF.top - mHandleWidth;
@@ -274,6 +268,11 @@ public class CropView extends View {
         if (locationListener != null) {
             locationListener.locationRect((int)handleLineLeftX, (int)handleLineTopY, (int)handleLineRightX, (int)handleLineBottomY);
         }
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent event) {
+        onCropRectChanged();
 
         mBitmapRectBlack = makeBitmap(coverWidth, coverHeight, 0xff000000, coverWidth, coverHeight);
         switch (event.getAction()) {