Pārlūkot izejas kodu

暂时不需要hdr

詹子聪 5 gadi atpakaļ
vecāks
revīzija
daa0e143be

+ 27 - 24
app/src/main/java/com/miekir/ocr/OCRApplication.java

@@ -2,6 +2,9 @@ package com.miekir.ocr;
 
 import android.app.Application;
 
+import com.yc.toollib.crash.CrashHandler;
+import com.yc.toollib.crash.CrashListener;
+
 
 /**
  *
@@ -16,29 +19,29 @@ public class OCRApplication extends Application {
 
         //RxActivityResult.register(this);
 
-//        CrashHandler.getInstance().init(this, new CrashListener() {
-//            /**
-//             * 重启app
-//             */
-//            @Override
-//            public void againStartApp() {
-//                //CrashToolUtils.reStartApp1(App.this,1000);
-//                //CrashToolUtils.reStartApp2(App.this,1000, MainActivity.class);
-//                //CrashToolUtils.reStartApp3(AppManager.getAppManager().currentActivity());
-//            }
-//
-//            /**
-//             * 自定义上传crash,支持开发者上传自己捕获的crash数据
-//             * @param ex                        ex
-//             */
-//            @Override
-//            public void recordException(Throwable ex) {
-//                //崩溃文件存储路径:/storage/emulated/0/Android/data/你的包名/cache/crashLogs
-//                //崩溃文件存储路径:/storage/emulated/0/Android/data/com.miekir.ocr/cache/crashLogs
-//                //崩溃页面截图存储路径:/storage/emulated/0/Android/data/你的包名/cache/crashPics
-//                //自定义上传crash,支持开发者上传自己捕获的crash数据
-//                //StatService.recordException(getApplication(), ex);
-//            }
-//        });
+        CrashHandler.getInstance().init(this, new CrashListener() {
+            /**
+             * 重启app
+             */
+            @Override
+            public void againStartApp() {
+                //CrashToolUtils.reStartApp1(App.this,1000);
+                //CrashToolUtils.reStartApp2(App.this,1000, MainActivity.class);
+                //CrashToolUtils.reStartApp3(AppManager.getAppManager().currentActivity());
+            }
+
+            /**
+             * 自定义上传crash,支持开发者上传自己捕获的crash数据
+             * @param ex                        ex
+             */
+            @Override
+            public void recordException(Throwable ex) {
+                //崩溃文件存储路径:/storage/emulated/0/Android/data/你的包名/cache/crashLogs
+                //崩溃文件存储路径:/storage/emulated/0/Android/data/com.miekir.ocr/cache/crashLogs
+                //崩溃页面截图存储路径:/storage/emulated/0/Android/data/你的包名/cache/crashPics
+                //自定义上传crash,支持开发者上传自己捕获的crash数据
+                //StatService.recordException(getApplication(), ex);
+            }
+        });
     }
 }

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

@@ -30,6 +30,7 @@ import io.reactivex.Observable;
 import io.reactivex.ObservableEmitter;
 import io.reactivex.ObservableOnSubscribe;
 import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.annotations.NonNull;
 import io.reactivex.schedulers.Schedulers;
 import top.zibin.luban.Luban;
 
@@ -275,21 +276,25 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                             .ignoreBy(400)
                             .setTargetDir(file.getParentFile().getAbsolutePath())
                             .get();
-                    File compressedFile = fileList.get(0);
+                    if (fileList != null && fileList.size() == 1) {
+                        File compressedFile = fileList.get(0);
 
-                    if (!TextUtils.equals(compressedFile.getAbsolutePath(), file.getAbsolutePath())) {
-                        file.delete();
-                    }
+                        if (!TextUtils.equals(compressedFile.getAbsolutePath(), file.getAbsolutePath())) {
+                            file.delete();
+                        }
 
-                    // 通知相册去获取
-                    MediaScannerConnection.scanFile(context, new String[] { compressedFile.getAbsolutePath() }, new String[] { "image/jpeg" }, null);
-                    // 保存最终截图成功
-                    // 根据URI获取图片的base64字符串
-                    String photoBase64 = Base64Tool.getBase64FromFilePath(compressedFile.getAbsolutePath());
-                    if (TextUtils.isEmpty(photoBase64)) {
-                        emitter.onError(new Exception("Empty image"));
+                        // 通知相册去获取
+                        MediaScannerConnection.scanFile(context, new String[] { compressedFile.getAbsolutePath() }, new String[] { "image/jpeg" }, null);
+                        // 保存最终截图成功
+                        // 根据URI获取图片的base64字符串
+                        String photoBase64 = Base64Tool.getBase64FromFilePath(compressedFile.getAbsolutePath());
+                        if (TextUtils.isEmpty(photoBase64)) {
+                            emitter.onError(new Exception("Empty image"));
+                        } else {
+                            emitter.onNext(photoBase64);
+                        }
                     } else {
-                        emitter.onNext(photoBase64);
+                        emitter.onNext("Empty image");
                     }
                 } else {
                     emitter.onError(new Exception("Empty image"));
@@ -399,7 +404,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                             .load(file)
                             .ignoreBy(400)
                             .setTargetDir(file.getParentFile().getAbsolutePath()).get();
-                    if (fileList.size() == 1) {
+                    if (fileList != null && fileList.size() == 1) {
                         File compressedFile = fileList.get(0);
                         // 通知相册去获取
                         MediaScannerConnection.scanFile(context, new String[] { compressedFile.getAbsolutePath() }, new String[] { "image/jpeg" }, null);
@@ -455,6 +460,11 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                     getView().onOcrResult(null);
                 }
             }
+
+            @Override
+            public void onError(@NonNull Throwable e) {
+                super.onError(e);
+            }
         });
     }
 

+ 1 - 0
app/src/main/java/com/miekir/ocr/ui/camera/otalia/OtaCameraActivity.java

@@ -50,6 +50,7 @@ public class OtaCameraActivity extends BaseCameraActivity {
         camera.addCameraListener(new Listener());
         camera.setPlaySounds(false);
         camera.setSoundEffectsEnabled(false);
+        //camera.setHdr(Hdr.ON);
 
         View fl_camera_size = findViewById(R.id.fl_camera_size);
         fl_camera_size.post(new Runnable() {