詹子聪 5 роки тому
батько
коміт
6d48f759dd

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

@@ -24,9 +24,9 @@ import com.miekir.ocr.tool.AnimateManager;
 import com.miekir.ocr.tool.SystemTool;
 import com.miekir.ocr.ui.IOperationView;
 import com.miekir.ocr.ui.OperationPresenter;
-import com.miekir.ocr.widget.CropView;
 import com.miekir.ocr.widget.GlideV4ImageEngine;
 import com.miekir.ocr.widget.IndicatorText;
+import com.miekir.ocr.widget.cropview.CropView;
 import com.zhihu.matisse.Matisse;
 import com.zhihu.matisse.MimeType;
 
@@ -56,7 +56,7 @@ public class OtaOperationActivity extends OtaCameraActivity implements CropView.
     private String mLandscapeString;
     private String mPortraitString;
 
-    protected CropView pcv_scan;
+    protected CropView cv_main;
 
     @Override
     public void initViews(Bundle savedInstanceState) {
@@ -66,9 +66,9 @@ public class OtaOperationActivity extends OtaCameraActivity implements CropView.
         ViewTool.setOnClickListener(this, clickIds, this);
 
         // 裁剪View
-        pcv_scan = findViewById(R.id.pcv_scan);
-        pcv_scan.setLocationListener(this);
-        pcv_scan.setOnTouchUpListener(new CropView.onTouchUpListener() {
+        cv_main = findViewById(R.id.cv_main);
+        cv_main.setLocationListener(this);
+        cv_main.setOnTouchUpListener(new CropView.OnTouchUpListener() {
             @Override
             public void onTouch(MotionEvent event) {
                 if (camera != null) {
@@ -128,7 +128,7 @@ public class OtaOperationActivity extends OtaCameraActivity implements CropView.
                 if (tv_orientation.getVisibility() == View.VISIBLE) {
                     // 切换横竖屏
                     AnimateManager.getInstance().stopAnimation();
-                    pcv_scan.switchOrientation();
+                    cv_main.switchOrientation();
                 }
                 break;
             default:
@@ -151,13 +151,13 @@ public class OtaOperationActivity extends OtaCameraActivity implements CropView.
                 indicatorText.onIndicatorRelease();
             }
         }
-        pcv_scan.setScanArea(mCurrentType);
+        cv_main.setScanArea(mCurrentType);
     }
 
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        pcv_scan.setLocationListener(null);
+        cv_main.setLocationListener(null);
     }
 
     @Override
@@ -167,7 +167,7 @@ public class OtaOperationActivity extends OtaCameraActivity implements CropView.
             List<Uri> selectedList = Matisse.obtainResult(data);
             if (selectedList != null && selectedList.size() > 0) {
                 if (tv_orientation.getVisibility() == View.VISIBLE) {
-                    mOperationPresenter.startOcrFromUri(this, selectedList.get(0), mCurrentScene, pcv_scan.isLandscape());
+                    mOperationPresenter.startOcrFromUri(this, selectedList.get(0), mCurrentScene, cv_main.isLandscape());
                 } else {
                     mOperationPresenter.startOcrFromUri(this, selectedList.get(0), mCurrentScene, false);
                 }
@@ -308,7 +308,7 @@ 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");
         if (tv_orientation.getVisibility() == View.VISIBLE) {
-            mOperationPresenter.startOcrFromBitmap(this, bitmap, rectData, file, mCurrentScene, pcv_scan.isLandscape());
+            mOperationPresenter.startOcrFromBitmap(this, bitmap, rectData, file, mCurrentScene, cv_main.isLandscape());
         } else {
             mOperationPresenter.startOcrFromBitmap(this, bitmap, rectData, file, mCurrentScene, false);
         }

+ 110 - 0
app/src/main/java/com/miekir/ocr/widget/cropview/CropView.java

@@ -1891,4 +1891,114 @@ public class CropView extends AppCompatImageView {
             }
         };
     }
+
+
+
+
+
+
+
+
+
+
+
+    public static final int SCAN_TYPE_POSTAL = 0;
+    public static final int SCAN_TYPE_ADDRESS = 1;
+    public static final int SCAN_TYPE_NAME = 2;
+    public static final int SCAN_TYPE_ALL = 3;
+    public static final String[] SCAN_SCENES = {"postcode", "address", "name", "all"};
+    public static final int[] SCAN_TYPES = {SCAN_TYPE_POSTAL, SCAN_TYPE_ADDRESS, SCAN_TYPE_NAME, SCAN_TYPE_ALL};
+
+
+    private OnRectChangeListener locationListener;/*listen to the Rect */
+    public void setLocationListener(OnRectChangeListener locationListener) {
+        this.locationListener = locationListener;
+    }
+    public interface OnRectChangeListener {
+        public void locationRect(int startX, int startY, int endX, int endY);
+    }
+
+    private OnTouchUpListener onTouchUpListener;
+    public void setOnTouchUpListener(OnTouchUpListener onTouchUpListener) {
+        this.onTouchUpListener = onTouchUpListener;
+    }
+    public interface OnTouchUpListener {
+        public void onTouch(MotionEvent event);
+    }
+
+    private boolean isLandscape = true;
+
+    public boolean isLandscape() {
+        return isLandscape;
+    }
+
+
+    /**
+     * 设置扫描区域
+     */
+    public void setScanArea(int scanType) {
+//        AnimateManager.getInstance().stopAnimation();
+//        switch (scanType) {
+//            case SCAN_TYPE_POSTAL:
+//                // 邮箱
+//                coverWidth = (int) (getWidth()*0.815);
+//                // 最小高度不能小于图片的高度
+//                coverHeight = Math.max(minHeight, (int)(getWidth()*0.3));
+//                sX = (getWidth()-coverWidth)/2;
+//                sY = (int) (getWidth()*0.177);
+//                break;
+//            case SCAN_TYPE_ADDRESS:
+//            case SCAN_TYPE_NAME:
+//                coverWidth = (int) (getWidth()*0.815);
+//                coverHeight = (int) (getWidth()*0.625);
+//                sX = (getWidth()-coverWidth)/2;
+//                sY = (getHeight()-coverHeight)/2;
+//                break;
+//            case SCAN_TYPE_ALL:
+//                isLandscape = true;
+//                coverHeight = getHeight();
+//                coverWidth = (int) (coverHeight/1.73);
+//
+//                // 起始位置
+//                sX = (getWidth()-coverWidth)/2;
+//                sY = 0;
+//                break;
+//            default:
+//                return;
+//        }
+//
+//        init();
+    }
+
+    /**
+     * 切换横竖屏
+     */
+    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();
+    }
+
+
+
+
+
+
+
+
+
 }

+ 23 - 3
app/src/main/res/layout/activity_otalia_camera.xml

@@ -84,10 +84,30 @@
                 android:layout_height="0dp"
                 android:layout_weight="370">
                 <!--灰色遮罩-->
-                <com.miekir.ocr.widget.CropView
-                    android:id="@+id/pcv_scan"
+                <com.miekir.ocr.widget.cropview.CropView
+                    android:id="@+id/cv_main"
                     android:layout_width="match_parent"
-                    android:layout_height="match_parent"/>
+                    android:layout_height="583dp"
+                    android:layout_above="@+id/rv"
+                    android:layout_alignParentTop="true"
+                    android:layout_centerHorizontal="true"
+                    android:padding="10dp"
+                    app:crop_enabled="true"
+                    app:crop_mode="free"
+                    app:background_color="#66FFFFFF"
+                    app:frame_color="@android:color/white"
+                    app:frame_stroke_weight="2dp"
+                    app:guide_color="@android:color/transparent"
+                    app:guide_show_mode="show_always"
+                    app:guide_stroke_weight="2dp"
+                    app:handle_color="@android:color/white"
+                    app:handle_show_mode="show_always"
+                    app:handle_size="24dp"
+                    app:handle_width="3dp"
+                    app:initial_frame_scale="1"
+                    app:min_frame_size="100dp"
+                    app:overlay_color="#AA1C1C1C"
+                    app:touch_padding="8dp" />
 
                 <com.miekir.ocr.widget.ScalableImageView
                     android:id="@+id/iv_animation"