From f37cdedae930fa265db9b41c1d8e731a513516be Mon Sep 17 00:00:00 2001
From: zpzpzpzp <362020984@qq.com>
Date: Mon, 9 Aug 2021 15:00:31 +0800
Subject: [PATCH 1/2] fix:add custom attributes in xml file
---
README.md | 11 +-
build.gradle | 11 +
entry/build.gradle | 13 -
entry/src/main/config.json | 4 -
.../slice/ZbarTestScanAbilitySlice.java | 1 -
.../resources/base/layout/zbarscan_layout.xml | 252 +++++++++--------
.../base/layout/zxingscan_layout.xml | 259 ++++++++++--------
qrcodecore/build.gradle | 1 +
qrcodecore/src/main/config.json | 3 +-
.../qrcode/core/QRCodeView.java | 2 +-
.../qrcode/core/ResourceUtil.java | 84 +++++-
.../qrcode/core/ScanBoxView.java | 153 ++++++-----
.../qrcode/core/TypedAttrUtils.java | 21 ++
.../media/qrcode_default_grid_scan_line.png | Bin
.../base/media/qrcode_default_scan_line.png | Bin 0 -> 1981 bytes
zbar/build.gradle | 16 +-
zbar/src/main/config.json | 3 +-
zxing/build.gradle | 1 +
zxing/src/main/config.json | 3 +-
19 files changed, 502 insertions(+), 336 deletions(-)
rename {entry => qrcodecore}/src/main/resources/base/media/qrcode_default_grid_scan_line.png (100%)
create mode 100644 qrcodecore/src/main/resources/base/media/qrcode_default_scan_line.png
diff --git a/README.md b/README.md
index 84e22f1..69e5bae 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@
| 扫码页面|识别图中码 |
|:---:|:---:|
-|||
+|||
## 集成
@@ -32,17 +32,18 @@
添加zxing.har,zbar.har,qrcodecore.har到entry下的libs文件夹内
entry的build.gradle内添加如下代码
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
-将arm64-v8a文件夹其中包含(libiconv.so,libzbarjni.so)添加到entry的libs包中
+将zbar模块下编译生成的(libiconv.so,libzbarjni.so)添加到entry的libs包中
方式二
+使用远程依赖方式,classpath最低版本要求是2.4.2.7
allprojects {
repositories {
mavenCentral()
}
}
-implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-zbar:1.0.4'
-implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-zxing:1.0.3'
-implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-core:1.0.3'
+implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-zbar:1.0.5'
+implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-zxing:1.0.4'
+implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-core:1.0.4'
```
diff --git a/build.gradle b/build.gradle
index afabb4a..57af7c3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -35,4 +35,15 @@ allprojects {
mavenCentral()
jcenter()
}
+}
+rootProject.ext {
+ DEFAULT_GROUP_ID = "io.openharmony.tpc.thirdlib"
+ DEFAULT_ARTIFACT_ID = "BGAQRCode-zbar"
+ DEFAULT_VERSION = "1.0.5"
+ DEFAULT_GITEE_URL = "https://gitee.com/openharmony-tpc/" + "BGAQRCode-ohos"
+ HPM_NAME = "@opensource/" + rootProject.ext.DEFAULT_ARTIFACT_ID
+ HPM_DESCRIPTION = "BGAQRCode can Scan the QR code and bar code"
+ HPM_TAG = "Tool"
+ HPM_KEYWORDS = 'qrcode'
+ HPM_DIRS = '{"lib":["build/outputs/*ar/release/*.*ar"]}'
}
\ No newline at end of file
diff --git a/entry/build.gradle b/entry/build.gradle
index 483f913..cdef4be 100644
--- a/entry/build.gradle
+++ b/entry/build.gradle
@@ -5,19 +5,6 @@ ohos {
defaultConfig {
compatibleSdkVersion 5
}
- externalNativeBuild {
- path "../zbar/src/main/cpp/CMakeLists.txt"
- arguments "-v"
- abiFilters "arm64-v8a"
- cppFlags ""
- }
- sourceSets {
- main {
- java {
- srcDir 'libs'
- }
- }
- }
}
dependencies {
diff --git a/entry/src/main/config.json b/entry/src/main/config.json
index 8e03399..8703f66 100644
--- a/entry/src/main/config.json
+++ b/entry/src/main/config.json
@@ -62,10 +62,6 @@
]
}
],
- "orientation_menu": [
- "landscape",
- "portrait"
- ],
"orientation": "portrait",
"name": "com.bingoogolapple.qrcode.MainAbility",
"icon": "$media:icon",
diff --git a/entry/src/main/java/com/bingoogolapple/qrcode/slice/ZbarTestScanAbilitySlice.java b/entry/src/main/java/com/bingoogolapple/qrcode/slice/ZbarTestScanAbilitySlice.java
index d2c71f4..1a99a8d 100644
--- a/entry/src/main/java/com/bingoogolapple/qrcode/slice/ZbarTestScanAbilitySlice.java
+++ b/entry/src/main/java/com/bingoogolapple/qrcode/slice/ZbarTestScanAbilitySlice.java
@@ -156,7 +156,6 @@ public class ZbarTestScanAbilitySlice extends AbilitySlice implements Component.
public void onScanQRCodeOpenCameraError() {
LogUtil.info("openCameraError");
}
-
/**
* 按钮点击事件
*
diff --git a/entry/src/main/resources/base/layout/zbarscan_layout.xml b/entry/src/main/resources/base/layout/zbarscan_layout.xml
index 7a80927..0538027 100644
--- a/entry/src/main/resources/base/layout/zbarscan_layout.xml
+++ b/entry/src/main/resources/base/layout/zbarscan_layout.xml
@@ -1,289 +1,317 @@
-
+ ohos:orientation="vertical">
+ ohos:height="match_parent"
+ ohos:width="match_parent"
+ app:qrcv_animTime="1000"
+ app:qrcv_barcodeRectHeight="120vp"
+ app:qrcv_borderColor="#ffffff"
+ app:qrcv_borderSize="1vp"
+ app:qrcv_cornerColor="#f57257"
+ app:qrcv_cornerDisplayType="center"
+ app:qrcv_cornerLength="20vp"
+ app:qrcv_cornerSize="3vp"
+ app:qrcv_customScanLineDrawable="$media:qrcode_default_scan_line"
+ app:qrcv_isBarcode="false"
+ app:qrcv_isScanLineReverse="true"
+ app:qrcv_isShowDefaultGridScanLineDrawable="false"
+ app:qrcv_isShowDefaultScanLineDrawable="true"
+ app:qrcv_maskColor="#33FFFFFF"
+ app:qrcv_rectWidth="200vp"
+ app:qrcv_scanLineColor="#f57257"
+ app:qrcv_scanLineMargin="0vp"
+ app:qrcv_scanLineSize="1vp"
+ app:qrcv_toolbarHeight="56vp"
+ app:qrcv_topOffset="65vp"
+ app:qrcv_verticalBias="-1"/>
+
+ ohos:orientation="horizontal">
+ ohos:text_color="#000000"/>
+
+ ohos:height="50vp"
+ ohos:width="match_parent"
+ ohos:text_color="#000000"/>
+
+ ohos:visibility="hide"/>
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:align_parent_bottom="$+id:dplt"
+ ohos:bottom_margin="60fp">
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:orientation="horizontal">
+ ohos:weight="1"/>
+
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:orientation="horizontal">
+ ohos:visibility="hide"
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:orientation="horizontal">
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:orientation="horizontal">
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:visibility="hide"
+ ohos:weight="1"/>
diff --git a/entry/src/main/resources/base/layout/zxingscan_layout.xml b/entry/src/main/resources/base/layout/zxingscan_layout.xml
index a3aada0..00c03af 100644
--- a/entry/src/main/resources/base/layout/zxingscan_layout.xml
+++ b/entry/src/main/resources/base/layout/zxingscan_layout.xml
@@ -1,289 +1,320 @@
-
+
+ ohos:height="match_parent"
+ ohos:width="match_parent"
+ app:qrcv_animTime="1000"
+ app:qrcv_barcodeRectHeight="120vp"
+ app:qrcv_borderColor="#ffffff"
+ app:qrcv_borderSize="1vp"
+ app:qrcv_cornerColor="#f57257"
+ app:qrcv_cornerDisplayType="center"
+ app:qrcv_cornerLength="20vp"
+ app:qrcv_cornerSize="3vp"
+ app:qrcv_customScanLineDrawable="$media:qrcode_default_scan_line"
+ app:qrcv_isAutoZoom="true"
+ app:qrcv_isBarcode="false"
+ app:qrcv_isOnlyDecodeScanBoxArea="false"
+ app:qrcv_isScanLineReverse="true"
+ app:qrcv_isShowDefaultGridScanLineDrawable="false"
+ app:qrcv_isShowDefaultScanLineDrawable="true"
+ app:qrcv_maskColor="#33FFFFFF"
+ app:qrcv_rectWidth="200vp"
+ app:qrcv_scanLineColor="#f57257"
+ app:qrcv_scanLineMargin="0vp"
+ app:qrcv_scanLineSize="1vp"
+ app:qrcv_toolbarHeight="56vp"
+ app:qrcv_topOffset="65vp"
+ app:qrcv_verticalBias="-1"
+ />
+
+ ohos:orientation="horizontal">
+ ohos:text_color="#000000"/>
+
+ ohos:height="50vp"
+ ohos:width="match_parent"
+ ohos:text_color="#000000"/>
+
+ ohos:visibility="hide"/>
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:align_parent_bottom="$+id:dplt"
+ ohos:bottom_margin="60fp">
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:orientation="horizontal">
+ ohos:weight="1"/>
+
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:orientation="horizontal">
+ ohos:visibility="hide"
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:orientation="horizontal">
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:height="match_content"
+ ohos:width="match_parent"
+ ohos:orientation="horizontal">
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:weight="1"/>
+ ohos:visibility="hide"
+ ohos:weight="1"/>
diff --git a/qrcodecore/build.gradle b/qrcodecore/build.gradle
index 115ec9d..c91ba73 100644
--- a/qrcodecore/build.gradle
+++ b/qrcodecore/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.huawei.ohos.library'
+//apply from:'../upload.gradle'
ohos {
compileSdkVersion 5
defaultConfig {
diff --git a/qrcodecore/src/main/config.json b/qrcodecore/src/main/config.json
index d0daf09..b4a32e9 100644
--- a/qrcodecore/src/main/config.json
+++ b/qrcodecore/src/main/config.json
@@ -8,8 +8,7 @@
},
"apiVersion": {
"compatible": 5,
- "target": 5,
- "releaseType": "Beta1"
+ "target": 5
}
},
"deviceConfig": {},
diff --git a/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/QRCodeView.java b/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/QRCodeView.java
index c50fad5..dc16c5b 100644
--- a/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/QRCodeView.java
+++ b/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/QRCodeView.java
@@ -44,7 +44,7 @@ public abstract class QRCodeView extends DependentLayout implements CameraPrevie
LogUtil.info("initView...");
LogUtil.error("Qrcodeview....initView...");
mScanBoxView = new ScanBoxView(context);
- mScanBoxView.init(this, attrSet);
+ mScanBoxView.init(this, attrSet,context);
onImageArrivalHandler = new EventHandler(EventRunner.create("onImageArrival"));
mCameraPreview = new CameraPreview(context, this);
diff --git a/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/ResourceUtil.java b/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/ResourceUtil.java
index 82a8459..34d646e 100644
--- a/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/ResourceUtil.java
+++ b/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/ResourceUtil.java
@@ -17,15 +17,16 @@ package com.bingoogolapple.qrcode.core;
import ohos.app.Context;
import ohos.app.Environment;
+import ohos.global.resource.NotExistException;
import ohos.global.resource.RawFileEntry;
import ohos.global.resource.Resource;
+import ohos.global.resource.ResourceManager;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;
+import ohos.media.image.common.PixelFormat;
+import ohos.media.image.common.Size;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.util.Optional;
import java.util.UUID;
@@ -139,6 +140,81 @@ public class ResourceUtil {
return null;
}
+ /**
+ * 转成图片
+ * @param context context
+ * @param mResource mResource
+ * @return PixelMap
+ * @throws IOException ex
+ * @throws NotExistException ex
+ */
+ public static PixelMap getPixelmap(Context context, int mResource) throws IOException, NotExistException {
+ ResourceManager rsrc = context.getResourceManager();
+ if (rsrc == null) {
+ return null;
+ }
+ Resource resource = null;
+ if (mResource != 0) {
+ resource = rsrc.getResource(mResource);
+ }
+ ImageSource.SourceOptions srcOpts = new ImageSource.SourceOptions();
+ ImageSource imageSource = null;
+ try {
+ imageSource = ImageSource.create(readResource(resource), srcOpts);
+ } finally {
+ close(resource);
+ }
+ if (imageSource == null) {
+ throw new FileNotFoundException();
+ }
+ ImageSource.DecodingOptions decodingOpts = new ImageSource.DecodingOptions();
+ decodingOpts.desiredSize = new Size(0, 0);
+ decodingOpts.desiredRegion = new ohos.media.image.common.Rect(0, 0, 0, 0);
+ decodingOpts.desiredPixelFormat = PixelFormat.ARGB_8888;
+
+ PixelMap pixelmap = imageSource.createPixelmap(decodingOpts);
+ return pixelmap;
+ }
+
+ private static byte[] readResource(Resource resource) {
+ final int bufferSize = 1024;
+ final int ioEnd = -1;
+
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ byte[] buffer = new byte[bufferSize];
+ while (true) {
+ try {
+ int readLen = resource.read(buffer, 0, bufferSize);
+ if (readLen == ioEnd) {
+ break;
+ }
+ output.write(buffer, 0, readLen);
+ } catch (IOException e) {
+ LogUtil.error(e.getMessage());
+ break;
+ } finally {
+ try {
+ output.close();
+ } catch (IOException e) {
+ LogUtil.error(e.getMessage());
+ }
+ }
+ }
+ return output.toByteArray();
+ }
+
+ private static void close(Resource resource) {
+ if (resource != null) {
+ try {
+ resource.close();
+ } catch (IOException e) {
+ LogUtil.error(e.getMessage());
+ }
+ }
+ }
+
+
+
/**
* 根据存在的路径创建pixelMap
* @param context 上下文
diff --git a/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/ScanBoxView.java b/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/ScanBoxView.java
index 9158d02..ea6e5ad 100644
--- a/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/ScanBoxView.java
+++ b/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/ScanBoxView.java
@@ -2,6 +2,7 @@ package com.bingoogolapple.qrcode.core;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
+import ohos.agp.components.element.PixelMapElement;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.render.PixelMapHolder;
@@ -10,13 +11,17 @@ import ohos.agp.utils.Point;
import ohos.agp.utils.Rect;
import ohos.agp.utils.RectFloat;
import ohos.app.Context;
+import ohos.eventhandler.EventHandler;
+import ohos.eventhandler.EventRunner;
+import ohos.eventhandler.InnerEvent;
+import ohos.global.resource.NotExistException;
import ohos.media.image.PixelMap;
-public class ScanBoxView extends Component implements Component.DrawTask {
+import java.io.IOException;
- private String RES_PIX_LINE = "entry/resources/base/media/qrcode_default_scan_line.png";
- private String RES_PIX_GRID = "entry/resources/base/media/qrcode_default_grid_scan_line.png";
+public class ScanBoxView extends Component implements Component.DrawTask {
+ private static final long ANIMATION_DELAY = 10L;
private int mMoveStepDistance;
private int mAnimDelayTime;
@@ -80,6 +85,8 @@ public class ScanBoxView extends Component implements Component.DrawTask {
private boolean mSizeChange;
private QRCodeView mQRCodeView;
+ private PixelMapElement mScanLineElement;
+ private EventHandler eventHandler;
public ScanBoxView(Context context) {
super(context);
@@ -89,7 +96,6 @@ public class ScanBoxView extends Component implements Component.DrawTask {
LogUtil.info("ScanBoxView..");
this.addDrawTask(this);
-
mPaint = new Paint();
mPaint.setAntiAlias(true);
mMaskColor = Color.getIntColor("#33FFFFFF");
@@ -149,52 +155,68 @@ public class ScanBoxView extends Component implements Component.DrawTask {
super(context, attrSet, resId);
}
- void init(QRCodeView qrCodeView,AttrSet attrSet) {
+ void init(QRCodeView qrCodeView, AttrSet attrSet, Context context) {
mQRCodeView = qrCodeView;
- mTopOffset= TypedAttrUtils.getDimensionPixelSize(attrSet,"qrcv_topOffset",mTopOffset);
- mCornerSize= TypedAttrUtils.getDimensionPixelSize(attrSet,"qrcv_cornerSize",mCornerSize);
- mCornerLength= TypedAttrUtils.getDimensionPixelSize(attrSet,"qrcv_cornerLength",mCornerLength);
- mScanLineSize= TypedAttrUtils.getDimensionPixelSize(attrSet,"qrcv_scanLineSize",mScanLineSize);
- mRectWidth= TypedAttrUtils.getDimensionPixelSize(attrSet,"qrcv_rectWidth",mRectWidth);
- mMaskColor= TypedAttrUtils.getIntColor(attrSet,"qrcv_maskColor",mMaskColor);
- mCornerColor= TypedAttrUtils.getIntColor(attrSet,"qrcv_cornerColor",mCornerColor);
- mScanLineColor= TypedAttrUtils.getIntColor(attrSet,"qrcv_scanLineColor",mScanLineColor);
- mScanLineMargin= TypedAttrUtils.getDimensionPixelSize(attrSet,"qrcv_scanLineMargin",mScanLineMargin);
- mIsShowDefaultScanLineDrawable= TypedAttrUtils.getBoolean(attrSet,"qrcv_isShowDefaultScanLineDrawable",mIsShowDefaultScanLineDrawable);
- mBorderSize= TypedAttrUtils.getDimensionPixelSize(attrSet,"qrcv_borderSize",mBorderSize);
- mBorderColor= TypedAttrUtils.getIntColor(attrSet,"qrcv_borderColor",mBorderColor);
- mAnimTime= TypedAttrUtils.getInteger(attrSet,"qrcv_animTime",mAnimTime);
- mVerticalBias= TypedAttrUtils.getFloat(attrSet,"qrcv_verticalBias",mVerticalBias);
- mCornerDisplayType= TypedAttrUtils.getInteger(attrSet,"qrcv_cornerDisplayType",mCornerDisplayType);
- mBarcodeRectHeight= TypedAttrUtils.getDimensionPixelSize(attrSet,"qrcv_barcodeRectHeight",mBarcodeRectHeight);
- mIsBarcode= TypedAttrUtils.getBoolean(attrSet,"qrcv_isBarcode",mIsBarcode);
- mIsScanLineReverse= TypedAttrUtils.getBoolean(attrSet,"qrcv_isScanLineReverse",mIsScanLineReverse);
- mIsShowDefaultGridScanLineDrawable= TypedAttrUtils.getBoolean(attrSet,"qrcv_isShowDefaultGridScanLineDrawable",mIsShowDefaultGridScanLineDrawable);
- mIsOnlyDecodeScanBoxArea= TypedAttrUtils.getBoolean(attrSet,"qrcv_isOnlyDecodeScanBoxArea",mIsOnlyDecodeScanBoxArea);
- mIsShowLocationPoint= TypedAttrUtils.getBoolean(attrSet,"qrcv_isShowLocationPoint",mIsShowLocationPoint);
- mIsAutoZoom= TypedAttrUtils.getBoolean(attrSet,"qrcv_isAutoZoom",mIsAutoZoom);
-
- afterInitCustomAttrs();
- }
-
- private void afterInitCustomAttrs() {
-
- if (mOriginQRCodeGridScanLineBitmap == null) {
- mOriginQRCodeGridScanLineBitmap = ResourceUtil.getPixelMapByResPath(getContext(),RES_PIX_GRID);
- mOriginQRCodeGridScanLineBitmap = BGAQRCodeUtil.makeTintBitmap(mOriginQRCodeGridScanLineBitmap, mScanLineColor);
+ mTopOffset = TypedAttrUtils.getDimensionPixelSize(attrSet, "qrcv_topOffset", mTopOffset);
+ mCornerSize = TypedAttrUtils.getDimensionPixelSize(attrSet, "qrcv_cornerSize", mCornerSize);
+ mCornerLength = TypedAttrUtils.getDimensionPixelSize(attrSet, "qrcv_cornerLength", mCornerLength);
+ mScanLineSize = TypedAttrUtils.getDimensionPixelSize(attrSet, "qrcv_scanLineSize", mScanLineSize);
+ mRectWidth = TypedAttrUtils.getDimensionPixelSize(attrSet, "qrcv_rectWidth", mRectWidth);
+ mMaskColor = TypedAttrUtils.getIntColor(attrSet, "qrcv_maskColor", mMaskColor);
+ mScanLineElement=(PixelMapElement)TypedAttrUtils.getElementFromAttr(attrSet,"qrcv_customScanLineDrawable",new PixelMapElement(ResourceUtil.decodeResource(context,ResourceTable.Media_qrcode_default_scan_line)));
+ mCornerColor = TypedAttrUtils.getIntColor(attrSet, "qrcv_cornerColor", mCornerColor);
+ mScanLineColor = TypedAttrUtils.getIntColor(attrSet, "qrcv_scanLineColor", mScanLineColor);
+ mScanLineMargin = TypedAttrUtils.getDimensionPixelSize(attrSet, "qrcv_scanLineMargin", mScanLineMargin);
+ mIsShowDefaultScanLineDrawable = TypedAttrUtils.getBoolean(attrSet, "qrcv_isShowDefaultScanLineDrawable", mIsShowDefaultScanLineDrawable);
+ mBorderSize = TypedAttrUtils.getDimensionPixelSize(attrSet, "qrcv_borderSize", mBorderSize);
+ mBorderColor = TypedAttrUtils.getIntColor(attrSet, "qrcv_borderColor", mBorderColor);
+ mAnimTime = TypedAttrUtils.getInteger(attrSet, "qrcv_animTime", mAnimTime);
+ mVerticalBias = TypedAttrUtils.getFloat(attrSet, "qrcv_verticalBias", mVerticalBias);
+ String mDisplayType=TypedAttrUtils.getString(attrSet, "qrcv_cornerDisplayType", "center");
+ if("center".equals(mDisplayType)){
+ mCornerDisplayType=1;
+ }else{
+ mCornerDisplayType=2;
}
- mOriginBarCodeGridScanLineBitmap = BGAQRCodeUtil.adjustPhotoRotation(mOriginQRCodeGridScanLineBitmap, 90);
- mOriginBarCodeGridScanLineBitmap = BGAQRCodeUtil.adjustPhotoRotation(mOriginBarCodeGridScanLineBitmap, 90);
- mOriginBarCodeGridScanLineBitmap = BGAQRCodeUtil.adjustPhotoRotation(mOriginBarCodeGridScanLineBitmap, 90);
-
+ mBarcodeRectHeight = TypedAttrUtils.getDimensionPixelSize(attrSet, "qrcv_barcodeRectHeight", mBarcodeRectHeight);
+ mIsBarcode = TypedAttrUtils.getBoolean(attrSet, "qrcv_isBarcode", mIsBarcode);
+ mIsScanLineReverse = TypedAttrUtils.getBoolean(attrSet, "qrcv_isScanLineReverse", mIsScanLineReverse);
+ mIsShowDefaultGridScanLineDrawable = TypedAttrUtils.getBoolean(attrSet, "qrcv_isShowDefaultGridScanLineDrawable", mIsShowDefaultGridScanLineDrawable);
+ mIsOnlyDecodeScanBoxArea = TypedAttrUtils.getBoolean(attrSet, "qrcv_isOnlyDecodeScanBoxArea", mIsOnlyDecodeScanBoxArea);
+ mIsShowLocationPoint = TypedAttrUtils.getBoolean(attrSet, "qrcv_isShowLocationPoint", mIsShowLocationPoint);
+ mIsAutoZoom = TypedAttrUtils.getBoolean(attrSet, "qrcv_isAutoZoom", mIsAutoZoom);
+
+ afterInitCustomAttrs(context);
+ }
+
+ private void afterInitCustomAttrs(Context context) {
+ eventHandler=new EventHandler(EventRunner.current()){
+ @Override
+ protected void processEvent(InnerEvent event) {
+ invalidate();
+ }
+ };
+ try {
+ if(mIsShowDefaultScanLineDrawable){
+ mOriginQRCodeScanLineBitmap = ResourceUtil.getPixelmap(context, ResourceTable.Media_qrcode_default_scan_line);
+ mOriginBarCodeScanLineBitmap = BGAQRCodeUtil.adjustPhotoRotation(mOriginQRCodeScanLineBitmap, 90);
- if (mOriginQRCodeScanLineBitmap == null) {
- mOriginQRCodeScanLineBitmap = ResourceUtil.getPixelMapByResPath(getContext(),RES_PIX_LINE);
- mOriginQRCodeScanLineBitmap = BGAQRCodeUtil.makeTintBitmap(mOriginQRCodeScanLineBitmap, mScanLineColor);
+ }else{
+ mOriginQRCodeScanLineBitmap = mScanLineElement.getPixelMap();
+ mOriginBarCodeScanLineBitmap = BGAQRCodeUtil.adjustPhotoRotation(mOriginQRCodeScanLineBitmap, 90);
+ }
+ if(mIsShowDefaultGridScanLineDrawable){
+ mOriginQRCodeGridScanLineBitmap=ResourceUtil.getPixelmap(context, ResourceTable.Media_qrcode_default_grid_scan_line);
+ mOriginBarCodeGridScanLineBitmap = BGAQRCodeUtil.adjustPhotoRotation(mOriginQRCodeGridScanLineBitmap, 90);
+ mOriginBarCodeGridScanLineBitmap = BGAQRCodeUtil.adjustPhotoRotation(mOriginBarCodeGridScanLineBitmap, 90);
+ mOriginBarCodeGridScanLineBitmap = BGAQRCodeUtil.adjustPhotoRotation(mOriginBarCodeGridScanLineBitmap, 90);
+ }
+ }catch (IOException e){
+ LogUtil.error(e.getMessage());
+ }catch (NotExistException e){
+ LogUtil.error(e.getMessage());
}
- mOriginBarCodeScanLineBitmap = BGAQRCodeUtil.adjustPhotoRotation(mOriginQRCodeScanLineBitmap, 90);
-
mTopOffset += mToolbarHeight;
mHalfCornerSize = 1.0f * mCornerSize / 2;
@@ -202,10 +224,8 @@ public class ScanBoxView extends Component implements Component.DrawTask {
}
- void onSizeChanged()
- {
- if(!mSizeChange)
- {
+ void onSizeChanged() {
+ if (!mSizeChange) {
return;
}
mSizeChange = false;
@@ -218,7 +238,7 @@ public class ScanBoxView extends Component implements Component.DrawTask {
onSizeChanged();
// 画遮罩层
- drawMask(component,canvas);
+ drawMask(component, canvas);
// 画边框线
drawBorderLine(canvas);
@@ -231,13 +251,14 @@ public class ScanBoxView extends Component implements Component.DrawTask {
// 移动扫描线的位置
moveScanLine();
+ eventHandler.sendEvent(0,ANIMATION_DELAY);
}
private void calFramingRect() {
int leftOffset = (getWidth() - mRectWidth) / 2;
mFramingRect = new Rect(leftOffset, mTopOffset, leftOffset + mRectWidth, mTopOffset + mRectHeight);
-
+
if (mIsBarcode) {
mGridScanLineRight = mScanLineLeft = mFramingRect.left + mHalfCornerSize + 0.5f;
} else {
@@ -313,7 +334,7 @@ public class ScanBoxView extends Component implements Component.DrawTask {
new Point(mFramingRect.right, mFramingRect.bottom + mHalfCornerSize - mCornerLength), mPaint);
} else if (mCornerDisplayType == 2) {
canvas.drawLine(new Point(mFramingRect.left, mFramingRect.top + mHalfCornerSize),
- new Point(mFramingRect.left + mCornerLength, mFramingRect.top + mHalfCornerSize),
+ new Point(mFramingRect.left + mCornerLength, mFramingRect.top + mHalfCornerSize),
mPaint);
canvas.drawLine(new Point(mFramingRect.left + mHalfCornerSize, mFramingRect.top),
new Point(mFramingRect.left + mHalfCornerSize, mFramingRect.top + mCornerLength),
@@ -361,7 +382,7 @@ public class ScanBoxView extends Component implements Component.DrawTask {
} else if (mScanLineBitmap != null) {
RectFloat lineRect = new RectFloat(mScanLineLeft, mFramingRect.top + mHalfCornerSize + mScanLineMargin, mScanLineLeft + mScanLineBitmap.getImageInfo().size.width,
mFramingRect.bottom - mHalfCornerSize - mScanLineMargin);
- canvas.drawPixelMapHolderRect(new PixelMapHolder(mScanLineBitmap), null, lineRect, mPaint);
+ canvas.drawPixelMapHolderRect(new PixelMapHolder(mScanLineBitmap), new RectFloat(0,0,mScanLineBitmap.getImageInfo().size.width,mScanLineBitmap.getImageInfo().size.height), lineRect, mPaint);
} else {
mPaint.setStyle(Paint.Style.FILL_STYLE);
@@ -386,7 +407,7 @@ public class ScanBoxView extends Component implements Component.DrawTask {
RectFloat lineRect = new RectFloat(mFramingRect.left + mHalfCornerSize + mScanLineMargin, mScanLineTop,
mFramingRect.right - mHalfCornerSize - mScanLineMargin,
mScanLineTop + mScanLineBitmap.getImageInfo().size.height);
- canvas.drawPixelMapHolderRect(new PixelMapHolder(mScanLineBitmap), null, lineRect, mPaint);
+ canvas.drawPixelMapHolderRect(new PixelMapHolder(mScanLineBitmap), new RectFloat(0,0,mScanLineBitmap.getImageInfo().size.width,mScanLineBitmap.getImageInfo().size.height), lineRect, mPaint);
} else {
mPaint.setStyle(Paint.Style.FILL_STYLE);
mPaint.setColor(new Color(mScanLineColor));
@@ -397,7 +418,6 @@ public class ScanBoxView extends Component implements Component.DrawTask {
}
-
/**
* 移动扫描线的位置
*/
@@ -434,16 +454,14 @@ public class ScanBoxView extends Component implements Component.DrawTask {
mScanLineTop += mMoveStepDistance;
int scanLineSize = mScanLineSize;
if (mScanLineBitmap != null) {
- scanLineSize = mScanLineBitmap.getImageInfo().size.width;
+ scanLineSize = mScanLineBitmap.getImageInfo().size.height;
}
-
if (mIsScanLineReverse) {
if (mScanLineTop + scanLineSize > mFramingRect.bottom - mHalfCornerSize || mScanLineTop < mFramingRect.top + mHalfCornerSize) {
mMoveStepDistance = -mMoveStepDistance;
}
} else {
-
if (mScanLineTop + scanLineSize > mFramingRect.bottom - mHalfCornerSize) {
mScanLineTop = mFramingRect.top + mHalfCornerSize + 0.5f;
}
@@ -457,11 +475,6 @@ public class ScanBoxView extends Component implements Component.DrawTask {
}
}
-
- getContext().getUITaskDispatcher().delayDispatch(() -> {
- invalidate();
- },20);
-
}
public Rect getScanBoxAreaRect(int previewHeight) {
@@ -493,7 +506,7 @@ public class ScanBoxView extends Component implements Component.DrawTask {
}
private void refreshScanBox() {
- if ( mIsShowDefaultGridScanLineDrawable) {
+ if (mIsShowDefaultGridScanLineDrawable) {
if (mIsBarcode) {
mGridScanLineBitmap = mOriginBarCodeGridScanLineBitmap;
} else {
@@ -517,15 +530,6 @@ public class ScanBoxView extends Component implements Component.DrawTask {
mAnimDelayTime = (int) ((1.0f * mAnimTime * mMoveStepDistance) / mRectHeight);
}
-// if (!TextUtils.isEmpty(mTipText)) {
-// if (mIsShowTipTextAsSingleLine) {
-// mTipTextSl = new StaticLayout(mTipText, mTipPaint, BGAQRCodeUtil.getScreenResolution(getContext()).x, Layout.Alignment.ALIGN_CENTER, 1.0f, 0,
-// true);
-// } else {
-// mTipTextSl = new StaticLayout(mTipText, mTipPaint, mRectWidth - 2 * mTipBackgroundRadius, Layout.Alignment.ALIGN_CENTER, 1.0f, 0, true);
-// }
-// }
-
if (mVerticalBias != -1) {
int screenHeight = BGAQRCodeUtil.getScreenResolution(getContext()).getPointYToInt() - BGAQRCodeUtil.getStatusBarHeight(getContext());
if (mToolbarHeight == 0) {
@@ -541,7 +545,6 @@ public class ScanBoxView extends Component implements Component.DrawTask {
}
-
public boolean getIsBarcode() {
return mIsBarcode;
}
@@ -764,7 +767,7 @@ public class ScanBoxView extends Component implements Component.DrawTask {
public void setTipTextSize(int tipTextSize) {
mTipTextSize = tipTextSize;
- // mTipPaint.setTextSize(mTipTextSize);
+ // mTipPaint.setTextSize(mTipTextSize);
refreshScanBox();
}
diff --git a/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/TypedAttrUtils.java b/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/TypedAttrUtils.java
index 6fe9c46..5aac474 100644
--- a/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/TypedAttrUtils.java
+++ b/qrcodecore/src/main/java/com/bingoogolapple/qrcode/core/TypedAttrUtils.java
@@ -16,6 +16,7 @@
package com.bingoogolapple.qrcode.core;
import ohos.agp.components.AttrSet;
+import ohos.agp.components.element.Element;
import ohos.agp.utils.Color;
/**
@@ -135,4 +136,24 @@ public class TypedAttrUtils {
return defValue;
}
}
+
+ /**
+ * 返回自定义Element值
+ *
+ * @param attrs AttrSet类
+ * @param attrName 自定义属性名
+ * @param defValue 默认值
+ * @return 自定义Element值
+ */
+ public static Element getElementFromAttr(AttrSet attrs, String attrName, Element defValue) {
+ Element value=defValue;
+ try{
+ if (attrs.getAttr(attrName)!= null&&attrs.getAttr(attrName).isPresent()) {
+ value = attrs.getAttr(attrName).get().getElement();
+ }
+ }catch (Exception e){
+ LogUtil.error(e.getMessage());
+ }
+ return value;
+ }
}
diff --git a/entry/src/main/resources/base/media/qrcode_default_grid_scan_line.png b/qrcodecore/src/main/resources/base/media/qrcode_default_grid_scan_line.png
similarity index 100%
rename from entry/src/main/resources/base/media/qrcode_default_grid_scan_line.png
rename to qrcodecore/src/main/resources/base/media/qrcode_default_grid_scan_line.png
diff --git a/qrcodecore/src/main/resources/base/media/qrcode_default_scan_line.png b/qrcodecore/src/main/resources/base/media/qrcode_default_scan_line.png
new file mode 100644
index 0000000000000000000000000000000000000000..6b1780841b2adea60a7fd3af5997f8d017a6be00
GIT binary patch
literal 1981
zcmeH{`#aMM0LH&ruA%5Umve?VEIE@zxfOF+F0n`sVoQp$Y%*qXiaEqGm&|3X<7g_^
z+|68a>A1!iD{Qh7Epmw>Y>vO{{5_
zAQ{k3qXX2)03h+n)yds<8vuUhCxQPx0qhdlXy^LtcaSa@cS(SDOG?Yg?NQjfPig<5
z!(dhQUm!=df73g5{CAj{uQ9#ej&7!6}Op3b~eHVK>BWG#u!s*J*`y|Sv{L-f8A>P!d+UlqO
zc-pfpnQ#E<5dVIg9DoRzy^o5T!wT@qyw?~eVOZ|^?0i|!I4jGKp={zp+x9l|^Hj-2EeQ6^YSN
zhUrhI+~?gPnL(3O5Cy4TrLTBBJ?E~%(MeYKJHV1WdXP}KfB_riXhm*yb{=gPb&D(c
zLZb^`@m}5^t!iOixd#vBm=nclR$E^cPUM(*#-pO>VF@;-ryGpNu
zT0ccjM47Lh3V-OB9@a)JxD_-W#*0mEaC^b`Suh~6eCzgt8oUo&2i8^_rAEirg6l0u
zxb8QjOB)N
zi0Fe_ipoa_3=0pDJqR~g9E)!aiYggtk_xRyZTK^Xkj?4&dw8xyx+;2GQU{%#`@Y
Date: Tue, 10 Aug 2021 09:04:45 +0800
Subject: [PATCH 2/2] change:add custom attributes in readme file
---
README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 74 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 69e5bae..1e34353 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,28 @@ implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-core:1.0.4'
+ ohos:width="match_parent"
+ app:qrcv_animTime="1000"
+ app:qrcv_barcodeRectHeight="120vp"
+ app:qrcv_borderColor="#ffffff"
+ app:qrcv_borderSize="1vp"
+ app:qrcv_cornerColor="#f57257"
+ app:qrcv_cornerDisplayType="center"
+ app:qrcv_cornerLength="20vp"
+ app:qrcv_cornerSize="3vp"
+ app:qrcv_customScanLineDrawable="$media:qrcode_default_scan_line"
+ app:qrcv_isBarcode="false"
+ app:qrcv_isScanLineReverse="true"
+ app:qrcv_isShowDefaultGridScanLineDrawable="false"
+ app:qrcv_isShowDefaultScanLineDrawable="true"
+ app:qrcv_maskColor="#33FFFFFF"
+ app:qrcv_rectWidth="200vp"
+ app:qrcv_scanLineColor="#f57257"
+ app:qrcv_scanLineMargin="0vp"
+ app:qrcv_scanLineSize="1vp"
+ app:qrcv_toolbarHeight="56vp"
+ app:qrcv_topOffset="65vp"
+ app:qrcv_verticalBias="-1"/>
```
>ZBar
@@ -62,10 +83,61 @@ implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-core:1.0.4'
+ ohos:width="match_parent"
+ app:qrcv_animTime="1000"
+ app:qrcv_barcodeRectHeight="120vp"
+ app:qrcv_borderColor="#ffffff"
+ app:qrcv_borderSize="1vp"
+ app:qrcv_cornerColor="#f57257"
+ app:qrcv_cornerDisplayType="center"
+ app:qrcv_cornerLength="20vp"
+ app:qrcv_cornerSize="3vp"
+ app:qrcv_customScanLineDrawable="$media:qrcode_default_scan_line"
+ app:qrcv_isBarcode="false"
+ app:qrcv_isScanLineReverse="true"
+ app:qrcv_isShowDefaultGridScanLineDrawable="false"
+ app:qrcv_isShowDefaultScanLineDrawable="true"
+ app:qrcv_maskColor="#33FFFFFF"
+ app:qrcv_rectWidth="200vp"
+ app:qrcv_scanLineColor="#f57257"
+ app:qrcv_scanLineMargin="0vp"
+ app:qrcv_scanLineSize="1vp"
+ app:qrcv_toolbarHeight="56vp"
+ app:qrcv_topOffset="65vp"
+ app:qrcv_verticalBias="-1"
+ />
+
+
```
+## 自定义属性说明
+
+属性名 | 说明 | 默认值
+:----------- | :----------- | :-----------
+qrcv_topOffset | 扫描框距离 toolbar 底部的距离 | 90dp
+qrcv_cornerSize | 扫描框边角线的宽度 | 3dp
+qrcv_cornerLength | 扫描框边角线的长度 | 20dp
+qrcv_cornerColor | 扫描框边角线的颜色 | @android:color/white
+qrcv_cornerDisplayType | 扫描框边角线显示位置(相对于边框),默认值为中间 | center
+qrcv_rectWidth | 扫描框的宽度 | 200dp
+qrcv_barcodeRectHeight | 条码扫样式描框的高度 | 140dp
+qrcv_maskColor | 除去扫描框,其余部分阴影颜色 | #33FFFFFF
+qrcv_scanLineSize | 扫描线的宽度 | 1dp
+qrcv_scanLineColor | 扫描线的颜色「扫描线和默认的扫描线图片的颜色」 | @android:color/white
+qrcv_scanLineMargin | 扫描线距离上下或者左右边框的间距 | 0dp
+qrcv_isShowDefaultScanLineDrawable | 是否显示默认的图片扫描线「设置该属性后 qrcv_scanLineSize 将失效,可以通过 qrcv_scanLineColor 设置扫描线的颜色,避免让你公司的UI单独给你出特定颜色的扫描线图片」 | false
+qrcv_customScanLineDrawable | 扫描线的图片资源「默认的扫描线图片样式不能满足你的需求时使用,设置该属性后 qrcv_isShowDefaultScanLineDrawable、qrcv_scanLineSize、qrcv_scanLineColor 将失效」 | null
+qrcv_borderSize | 扫描边框的宽度 | 1dp
+qrcv_borderColor | 扫描边框的颜色 | @android:color/white
+qrcv_animTime | 扫描线从顶部移动到底部的动画时间「单位为毫秒」 | 1000
+qrcv_verticalBias | 扫描框中心点在屏幕垂直方向的比例,当设置此值时,会忽略 qrcv_topOffset 属性 | -1
+qrcv_toolbarHeight | Toolbar 的高度,通过该属性来修正由 Toolbar 导致扫描框在垂直方向上的偏差 | 0dp
+qrcv_isBarcode | 扫描框的样式是否为扫条形码样式 | false
+qrcv_isScanLineReverse | 扫描线是否来回移动 | true
+qrcv_isShowDefaultGridScanLineDrawable | 是否显示默认的网格图片扫描线 | false
+qrcv_customGridScanLineDrawable | 扫描线的网格图片资源 | nulll
+
## 接口说明
>QRCodeView
--
Gitee