暴露ViewfinderView中的labelText相关属性,支持代码修改labelText相关属性。

This commit is contained in:
jenly1314
2018-11-16 18:23:54 +08:00
parent 36d511c64d
commit e188576610
5 changed files with 41 additions and 15 deletions

Binary file not shown.

View File

@@ -36,17 +36,17 @@ ZXingLite for Android 是ZXing的精简版优化扫码和生成二维码功
<dependency>
<groupId>com.king.zxing</groupId>
<artifactId>zxing-lite</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<type>pom</type>
</dependency>
```
### Gradle:
```gradle
implementation 'com.king.zxing:zxing-lite:1.0.2'
implementation 'com.king.zxing:zxing-lite:1.0.3'
```
### Lvy:
```lvy
<dependency org='com.king.zxing' name='zxing-lite' rev='1.0.2'>
<dependency org='com.king.zxing' name='zxing-lite' rev='1.0.3'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
```
@@ -84,6 +84,9 @@ api 'com.google.zxing:core:3.3.3'
代码示例 (二维码/条形码)
```Java
//跳转的默认扫码界面
startActivityForResult(new Intent(context,CaptureActivity.class),requestCode);
//生成二维码
CodeUtils.createQRCode(content,600,logo);
//生成条形码

View File

@@ -28,6 +28,7 @@ import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.support.annotation.ColorRes;
import android.support.v4.content.ContextCompat;
import android.text.Layout;
import android.text.StaticLayout;
@@ -81,10 +82,10 @@ public final class ViewfinderView extends View {
//扫描区域提示文本
private String labelText;
//扫描区域提示文本颜色
private final int labelTextColor;
private final float labelTextSize;
public static int scannerStart = 0;
public static int scannerEnd = 0;
private int labelTextColor;
private float labelTextSize;
public int scannerStart = 0;
public int scannerEnd = 0;
private boolean isShowResultPoint;
private List<ResultPoint> possibleResultPoints;
@@ -142,6 +143,22 @@ public final class ViewfinderView extends View {
this.cameraManager = cameraManager;
}
public void setLabelText(String labelText) {
this.labelText = labelText;
}
public void setLabelTextColor(int color) {
this.labelTextColor = color;
}
public void setLabelTextColorResource(@ColorRes int id){
this.labelTextColor = ContextCompat.getColor(getContext(),id);
}
public void setLabelTextSize(float textSize) {
this.labelTextSize = textSize;
}
@SuppressLint("DrawAllocation")
@Override
public void onDraw(Canvas canvas) {

View File

@@ -58,6 +58,7 @@ public final class CameraManager {
private int requestedCameraId = OpenCameraInterface.NO_REQUESTED_CAMERA;
private int requestedFramingRectWidth;
private int requestedFramingRectHeight;
/**
* Preview frames are delivered here, which we pass on to the registered handler. Make sure to
* clear the handler so it will only receive one message.
@@ -229,9 +230,11 @@ public final class CameraManager {
int width = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
int height = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
int leftOffset = (screenResolution.x - width) / 2;
int topOffset = (screenResolution.y - height) / 2;
framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
int size = Math.min(width,height);
int leftOffset = (screenResolution.x - size) / 2;
int topOffset = (screenResolution.y - size) / 2;
framingRect = new Rect(leftOffset, topOffset, leftOffset + size, topOffset + size);
Log.d(TAG, "Calculated framing rect: " + framingRect);
}
return framingRect;
@@ -334,9 +337,12 @@ public final class CameraManager {
if (rect == null) {
return null;
}
int size = Math.min(width,height);
int left = (width-size)/2;
int top = (height-size)/2;
// Go ahead and assume it's YUV rather than die.
return new PlanarYUVLuminanceSource(data, width, height, 0, 0,
width, height, false);
return new PlanarYUVLuminanceSource(data, width, height, left, top,
left + size, top + size, false);
}
}

View File

@@ -1,7 +1,7 @@
//App
def app_version = [:]
app_version.versionCode = 3
app_version.versionName = "1.0.2"
app_version.versionCode = 4
app_version.versionName = "1.0.3"
ext.app_version = app_version
//build version