詹子聪 5 лет назад
Родитель
Сommit
b5287e625d

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

@@ -114,7 +114,8 @@ public class OperationActivity extends CameraActivity implements CropView.onLoca
                 }
 
                 if (tv_orientation.getVisibility() == View.VISIBLE) {
-                    // todo 切换横竖屏
+                    // 切换横竖屏
+                    pcv_scan.switchOrientation();
                 }
                 break;
             default:

+ 29 - 2
app/src/main/java/com/miekir/ocr/widget/CropView.java

@@ -103,10 +103,12 @@ public class CropView extends View {
                 sY = (getHeight()-coverHeight)/2;
                 break;
             case SCAN_TYPE_ALL:
-                coverWidth = getWidth();
+                isLandscape = true;
                 coverHeight = getHeight();
+                coverWidth = (int) (coverHeight/1.73);
+
                 // 起始位置
-                sX = 0;
+                sX = (getWidth()-coverWidth)/2;
                 sY = 0;
                 break;
             default:
@@ -116,6 +118,31 @@ public class CropView extends View {
         init();
     }
 
+    private boolean isLandscape = true;
+    /**
+     * 切换横竖屏
+     */
+    public void switchOrientation() {
+        if (isLandscape) {
+            coverWidth = getWidth();
+            coverHeight = (int) (coverWidth/1.73);
+            isLandscape = false;
+            sX = 0;
+            sY = (getHeight()-coverHeight)/2;
+        } else {
+            coverHeight = getHeight();
+            coverWidth = (int) (coverHeight/1.73);
+            isLandscape = true;
+            sX = (getWidth()-coverWidth)/2;
+            sY = 0;
+        }
+
+
+        // 起始位置
+
+        init();
+    }
+
     @SuppressWarnings("deprecation")
     private void init() {