|
|
@@ -3,6 +3,7 @@ package com.miekir.ocr.widget;
|
|
|
import android.content.Context;
|
|
|
import android.content.res.Resources;
|
|
|
import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
import android.graphics.Canvas;
|
|
|
import android.graphics.Color;
|
|
|
import android.graphics.Paint;
|
|
|
@@ -12,6 +13,7 @@ import android.graphics.RectF;
|
|
|
import android.os.Handler;
|
|
|
import android.util.AttributeSet;
|
|
|
import android.util.DisplayMetrics;
|
|
|
+import android.util.Log;
|
|
|
import android.util.TypedValue;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
@@ -28,10 +30,11 @@ public class CropView extends View {
|
|
|
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 static final String TAG = "PhotoCropView";
|
|
|
+ private static final String TAG = "CropView";
|
|
|
|
|
|
private onLocationListener locationListener;/*listen to the Rect */
|
|
|
- private onChangeLocationlistener changeLocationlistener;/*listening position changed */
|
|
|
+ /*listening position changed */
|
|
|
+ private onChangeLocationlistener changeLocationlistener;
|
|
|
|
|
|
private int MODE;
|
|
|
private static final int MODE_OUTSIDE = 0x000000aa;/*170*/
|
|
|
@@ -39,8 +42,8 @@ public class CropView extends View {
|
|
|
private static final int MODE_POINT = 0X000000cc;/*204*/
|
|
|
private static final int MODE_ILLEGAL = 0X000000dd;/*221*/
|
|
|
|
|
|
- private static final int minWidth = 150;/*the minimum width of the rectangle*/
|
|
|
- private static final int minHeight = 250;/*the minimum height of the rectangle*/
|
|
|
+ private static int minWidth = 150;/*the minimum width of the rectangle*/
|
|
|
+ private static int minHeight = 150;/*the minimum height of the rectangle*/
|
|
|
|
|
|
private static final float EDGE_WIDTH = 1.8f;
|
|
|
// 否触发宽高改变的范围
|
|
|
@@ -56,6 +59,11 @@ public class CropView extends View {
|
|
|
private int eX;/*end X location*/
|
|
|
private int eY;/*end Y location*/
|
|
|
|
|
|
+ private int validStartX;
|
|
|
+ private int validStartY;
|
|
|
+ private int validEndX;
|
|
|
+ private int validEndY;
|
|
|
+
|
|
|
private int pressX;/*X coordinate values while finger press*/
|
|
|
private int pressY;/*Y coordinate values while finger press*/
|
|
|
|
|
|
@@ -88,6 +96,12 @@ public class CropView extends View {
|
|
|
@Override
|
|
|
public void onGlobalLayout() {
|
|
|
getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
|
|
+
|
|
|
+ BitmapFactory.Options horizontalOptions = new BitmapFactory.Options();
|
|
|
+ BitmapFactory.decodeResource(getResources(), R.mipmap.move_horizontal, horizontalOptions);
|
|
|
+ horizontalOptions.inJustDecodeBounds = true;
|
|
|
+ minWidth = horizontalOptions.outHeight * 2;
|
|
|
+ minHeight = minWidth;
|
|
|
setScanArea(SCAN_TYPE_ALL); //height is ready
|
|
|
}
|
|
|
});
|
|
|
@@ -258,6 +272,12 @@ public class CropView extends View {
|
|
|
canvas.restoreToCount(sc);
|
|
|
//在此加入4个边角...
|
|
|
drawCorners(canvas);
|
|
|
+
|
|
|
+ Log.e(TAG, "onDraw, sX:" + sX + ", sY:" + sY + " eX:" + eX + ", eY:" + eY);
|
|
|
+ validStartX = sX;
|
|
|
+ validStartY = sY;
|
|
|
+ validEndX = eX;
|
|
|
+ validEndY = eY;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -357,24 +377,27 @@ public class CropView extends View {
|
|
|
case MotionEvent.ACTION_MOVE: {
|
|
|
switch (MODE) {
|
|
|
case MODE_ILLEGAL:
|
|
|
- pressX = (int) event.getX();
|
|
|
- pressY = (int) event.getY();
|
|
|
- recoverFromIllegal(pressX, pressY);
|
|
|
- postInvalidate();
|
|
|
+// pressX = (int) event.getX();
|
|
|
+// pressY = (int) event.getY();
|
|
|
+// Log.e(TAG, "mode_illegal, x:" + pressX + ", y:" + pressY);
|
|
|
+// recoverFromIllegal(pressX, pressY);
|
|
|
+// postInvalidate();
|
|
|
break;
|
|
|
case MODE_OUTSIDE:
|
|
|
//do nothing;
|
|
|
break;
|
|
|
case MODE_INSIDE:
|
|
|
- pressX = (int) event.getX();
|
|
|
- pressY = (int) event.getY();
|
|
|
- moveByTouch(pressX, pressY);
|
|
|
- postInvalidate();
|
|
|
+// pressX = (int) event.getX();
|
|
|
+// pressY = (int) event.getY();
|
|
|
+// Log.e(TAG, "mode_inside, x:" + pressX + ", y:" + pressY);
|
|
|
+// moveByTouch(pressX, pressY);
|
|
|
+// postInvalidate();
|
|
|
break;
|
|
|
default:
|
|
|
/*MODE_POINT*/
|
|
|
pressX = (int) event.getX();
|
|
|
pressY = (int) event.getY();
|
|
|
+ Log.e(TAG, "mode_default, x:" + pressX + ", y:" + pressY);
|
|
|
mPaintLine.setColor(getContext().getResources().getColor(R.color.white));
|
|
|
moveByPoint(pressX, pressY);
|
|
|
postInvalidate();
|
|
|
@@ -385,12 +408,17 @@ public class CropView extends View {
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
mPaintLine.setColor(Color.WHITE);
|
|
|
postInvalidate();
|
|
|
-
|
|
|
- if (coverWidth > coverHeight) {
|
|
|
- AnimateManager.getInstance().setWidth(coverWidth, coverHeight, sX, sY, eX, eY);
|
|
|
- } else {
|
|
|
- AnimateManager.getInstance().setHeight(coverWidth, coverHeight, sX, sY, eX, eY);
|
|
|
- }
|
|
|
+ Log.e(TAG, "action_up, validStartX:" + validStartX + ", validStartY:" + validStartY + " validEndX:" + validEndX + ", validEndY:" + validEndY);
|
|
|
+ new Handler().postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (coverWidth > coverHeight) {
|
|
|
+ AnimateManager.getInstance().setWidth(coverWidth, coverHeight, validStartX, validStartY, validEndX, validEndY);
|
|
|
+ } else {
|
|
|
+ AnimateManager.getInstance().setHeight(coverWidth, coverHeight, validStartX, validStartY, validEndX, validEndY);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 50);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
@@ -465,6 +493,14 @@ public class CropView extends View {
|
|
|
this.eY = iey;
|
|
|
}
|
|
|
|
|
|
+ if (iex - isx < minWidth) {
|
|
|
+ this.eX = isx + minWidth;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iey - isy < minHeight) {
|
|
|
+ this.eY = isy + minHeight;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/*矩形随手指移动*/
|
|
|
@@ -502,8 +538,8 @@ public class CropView extends View {
|
|
|
}
|
|
|
|
|
|
/*检測矩形是否达到最小值*/
|
|
|
- private boolean checkLegalRect(int cHeight, int cWidth) {
|
|
|
- return (cHeight > minHeight && cWidth > minWidth);
|
|
|
+ private boolean checkLegalRect(int cWidth, int cHeight) {
|
|
|
+ return (cWidth > minWidth && cHeight > minHeight);
|
|
|
}
|
|
|
|
|
|
/*点击顶点附近时的缩放处理*/
|