更新CameraX至v1.2.2

This commit is contained in:
Jenly
2023-04-15 16:45:34 +08:00
parent 863f1ab1b4
commit 2359695964
33 changed files with 734 additions and 319 deletions

View File

@@ -8,6 +8,7 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Point;
@@ -26,8 +27,6 @@ import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import com.king.zxing.util.LogUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
@@ -216,6 +215,10 @@ public class ViewfinderView extends View {
private Bitmap laserBitmap;
private float laserBitmapRatio;
private float laserBitmapWidth;
private int viewfinderStyle = ViewfinderStyle.CLASSIC;
private List<Point> pointList;
@@ -248,7 +251,7 @@ public class ViewfinderView extends View {
*/
public enum LaserStyle {
NONE(0), LINE(1), GRID(2), IMAGE(3);
private int mValue;
private final int mValue;
LaserStyle(int value) {
mValue = value;
@@ -270,7 +273,7 @@ public class ViewfinderView extends View {
public enum TextLocation {
TOP(0), BOTTOM(1);
private int mValue;
private final int mValue;
TextLocation(int value) {
mValue = value;
@@ -292,7 +295,7 @@ public class ViewfinderView extends View {
public enum FrameGravity {
CENTER(0), LEFT(1), TOP(2), RIGHT(3), BOTTOM(4);
private int mValue;
private final int mValue;
FrameGravity(int value) {
mValue = value;
@@ -369,6 +372,7 @@ public class ViewfinderView extends View {
isShowPointAnim = array.getBoolean(R.styleable.ViewfinderView_showPointAnim, true);
Drawable pointDrawable = array.getDrawable(R.styleable.ViewfinderView_pointDrawable);
Drawable laserDrawable = array.getDrawable(R.styleable.ViewfinderView_laserDrawable);
laserBitmapRatio = array.getFloat(R.styleable.ViewfinderView_laserDrawableRatio, 0.625f);
viewfinderStyle = array.getInt(R.styleable.ViewfinderView_viewfinderStyle, ViewfinderStyle.CLASSIC);
array.recycle();
@@ -433,6 +437,24 @@ public class ViewfinderView extends View {
this.laserStyle = laserStyle;
}
/**
* 设置激光扫描自定义图片
*
* @param drawableResId
*/
public void setLaserDrawable(@DrawableRes int drawableResId) {
setLaserBitmap(BitmapFactory.decodeResource(getResources(), drawableResId));
}
/**
* 设置激光扫描自定义图片
*
* @param laserBitmap
*/
public void setLaserBitmap(Bitmap laserBitmap) {
this.laserBitmap = laserBitmap;
scaleLaserBitmap();
}
public void setPointImageResource(@DrawableRes int drawable) {
setPointBitmap(BitmapFactory.decodeResource(getResources(), drawable));
}
@@ -448,10 +470,26 @@ public class ViewfinderView extends View {
initFrame(getWidth(),getHeight());
}
private void scaleLaserBitmap() {
if (laserBitmap != null && laserBitmapWidth > 0) {
float ratio = laserBitmapWidth / laserBitmap.getWidth();
Matrix matrix = new Matrix();
matrix.postScale(ratio, ratio);
int w = laserBitmap.getWidth();
int h = laserBitmap.getHeight();
laserBitmap = Bitmap.createBitmap(laserBitmap, 0, 0, w, h, matrix, true);
}
}
private void initFrame(int width, int height) {
int size = (int) (Math.min(width, height) * frameRatio);
if (laserBitmapWidth <= 0) {
laserBitmapWidth = Math.min(width, height) * laserBitmapRatio;
scaleLaserBitmap();
}
if (frameWidth <= 0 || frameWidth > width) {
frameWidth = size;
}
@@ -582,7 +620,7 @@ public class ViewfinderView extends View {
private void drawImageScanner(Canvas canvas, Rect frame) {
if (laserBitmap != null) {
paint.setColor(Color.WHITE);
canvas.drawBitmap(laserBitmap, frame.left, scannerStart, paint);
canvas.drawBitmap(laserBitmap, (getWidth() - laserBitmap.getWidth()) / 2, scannerStart, paint);
if (scannerStart < scannerEnd) {
scannerStart += scannerLineMoveDistance;
} else {
@@ -591,7 +629,6 @@ public class ViewfinderView extends View {
} else {
drawLineScanner(canvas, frame);
}
}
/**