diff --git a/zxinglibrary/src/main/java/com/yzq/zxinglibrary/bean/ZxingConfig.java b/zxinglibrary/src/main/java/com/yzq/zxinglibrary/bean/ZxingConfig.java index faeca6a..ab3be6e 100644 --- a/zxinglibrary/src/main/java/com/yzq/zxinglibrary/bean/ZxingConfig.java +++ b/zxinglibrary/src/main/java/com/yzq/zxinglibrary/bean/ZxingConfig.java @@ -38,6 +38,8 @@ public class ZxingConfig implements Serializable { @ColorRes private int frameLineColor = -1; + private int cameraId; + /*扫描线颜色*/ @ColorRes @@ -122,4 +124,12 @@ public boolean isShowAlbum() { public void setShowAlbum(boolean showAlbum) { isShowAlbum = showAlbum; } + + public int getCameraId() { + return cameraId; + } + + public void setCameraId(int cameraId) { + this.cameraId = cameraId; + } } diff --git a/zxinglibrary/src/main/java/com/yzq/zxinglibrary/camera/CameraManager.java b/zxinglibrary/src/main/java/com/yzq/zxinglibrary/camera/CameraManager.java index 9a97baf..1bfefa6 100644 --- a/zxinglibrary/src/main/java/com/yzq/zxinglibrary/camera/CameraManager.java +++ b/zxinglibrary/src/main/java/com/yzq/zxinglibrary/camera/CameraManager.java @@ -70,6 +70,9 @@ public CameraManager(Context context, ZxingConfig config) { this.configManager = new CameraConfigurationManager(context); previewCallback = new PreviewCallback(configManager); this.config = config; + if (config != null) { + setManualCameraId(config.getCameraId()); + } } // public static void init(Context context) { @@ -248,14 +251,16 @@ public synchronized Rect getFramingRect() { } int screenResolutionX = screenResolution.x; - - int width = (int) (screenResolutionX * 0.6); + int screenResolutionY = screenResolution.y; + // 取下最小值 + int minWidth = Math.min(screenResolutionX, screenResolutionY); + int width = (int) (minWidth * 0.6); int height = width; /*水平居中 偏上显示*/ int leftOffset = (screenResolution.x - width) / 2; - int topOffset = (screenResolution.y - height) / 5; + int topOffset = (screenResolution.y - height) / 2-80; framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);