diff --git a/README.md b/README.md index cc46eda..335356b 100644 --- a/README.md +++ b/README.md @@ -46,32 +46,58 @@ allprojects { ``` dependencies { ... - implementation 'com.github.xuexiangjys:XQRCode:1.0.3' + implementation 'com.github.xuexiangjys:XQRCode:1.0.4' } ``` ### 2.2、二维码扫描 +#### 默认二维码扫描 + 1.默认二维码扫描界面`CaptureActivity` -二维码的扫描结果通过Intent返回出来: +使用`XQRCode.startScan`直接调取默认二维码扫描。 + +``` +XQRCode.startScan(this, REQUEST_CODE); +``` + +2.二维码的扫描结果通过Intent返回出来: * `XQRCode.RESULT_TYPE`:扫描结果类型,`XQRCode.RESULT_SUCCESS`代表扫描成功,`XQRCode.RESULT_FAILED`代表扫描失败。 * `XQRCode.RESULT_DATA`:扫描二维码的数据内容。 +3.自定义默认二维码扫描界面的主题样式: + +``` + + + + +``` + +下面的二维码扫描代码仅供参考: + ``` /** * 开启二维码扫描 */ @Permission(CAMERA) -@IOThread(ThreadType.Single) private void startScan(ScanType scanType) { - switch(scanType) { - case CUSTOM: - openPageForResult(CustomCaptureFragment.class, null, REQUEST_CUSTOM_SCAN); - break; + switch (scanType) { case DEFAULT: - startActivityForResult(new Intent(getActivity(), CaptureActivity.class), REQUEST_CODE); + XQRCode.startScan(this, REQUEST_CODE); + break; + case DEFAULT_Custom: + XQRCode.startScan(this, REQUEST_CODE, R.style.XQRCodeTheme_Custom); break; case REMOTE: Intent intent = new Intent(XQRCode.ACTION_DEFAULT_CAPTURE); @@ -82,6 +108,24 @@ private void startScan(ScanType scanType) { } } +@Override +public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + //处理二维码扫描结果 + if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { + //处理扫描结果(在界面上显示) + handleScanResult(data); + } + + //选择系统图片并解析 + else if (requestCode == REQUEST_IMAGE) { + if (data != null) { + Uri uri = data.getData(); + getAnalyzeQRCodeResult(uri); + } + } +} + /** * 处理二维码扫描结果 * @param data @@ -99,11 +143,30 @@ private void handleScanResult(Intent data) { } } } + +/** + * 进行二维码解析 + * + * @param uri + */ +private void getAnalyzeQRCodeResult(Uri uri) { + XQRCode.analyzeQRCode(PathUtils.getFilePathByUri(getContext(), uri), new QRCodeAnalyzeUtils.AnalyzeCallback() { + @Override + public void onAnalyzeSuccess(Bitmap mBitmap, String result) { + ToastUtils.toast("解析结果:" + result, Toast.LENGTH_LONG); + } + + @Override + public void onAnalyzeFailed() { + ToastUtils.toast("解析二维码失败", Toast.LENGTH_LONG); + } + }); +} ``` -2.自定义二维码扫描界面 +#### 自定义二维码扫描 -(1)自定义一个扫码界面布局。自定义的扫码界面需要定义一个`SurfaceView`和一个`ViewfinderView`,且id必须是`preview_view`和`viewfinder_view`。详情见如下布局代码: +1. 自定义一个扫码界面布局。自定义的扫码界面需要定义一个`SurfaceView`和一个`ViewfinderView`,且id必须是`preview_view`和`viewfinder_view`。详情见如下布局代码: ``` @@ -140,15 +203,15 @@ ViewfinderView属性表 inner_width | dimension | 屏幕宽度的3/4 | 扫描框的宽度 inner_height | dimension | 屏幕宽度的3/4 | 扫描框的高度 inner_marginTop | dimension | 居中效果 | 扫描框距离顶部的距离 -inner_corner_color | color | #45DDDD | 扫描框四角的颜色 -inner_corner_length | dimension | 65px | 扫描框四角的长度 -inner_corner_width | dimension | 15px | 扫描框四角的宽度 +inner_corner_color | color | #0DC2FE | 扫描框四角的颜色 +inner_corner_length | dimension | 32dp | 扫描框四角的长度 +inner_corner_width | dimension | 6dp | 扫描框四角的宽度 inner_scan_bitmap | reference | R.drawable.xqrcode_ic_scan_light | 扫描控件图资源 -inner_scan_speed | integer | 5px | 扫描速度 +inner_scan_speed | dimension | 5dp | 扫描速度 inner_scan_isCircle | boolean | true | 小圆点是否展示 -(2)调用`XQRCode.getCaptureFragment`的方法,传入自定义扫描界面的布局ID,可以获得带扫描功能的Fragment-`CaptureFragment`,将其填充到页面中。 +2. 调用`XQRCode.getCaptureFragment`的方法,传入自定义扫描界面的布局ID,可以获得带扫描功能的Fragment-`CaptureFragment`,将其填充到页面中。 ``` // 为二维码扫描界面设置定制化界面 @@ -157,7 +220,14 @@ captureFragment.setAnalyzeCallback(analyzeCallback); getChildFragmentManager().beginTransaction().replace(R.id.fl_my_container, captureFragment).commit(); ``` -(3)最后为CaptureFragment设置二维码解析回调接口`AnalyzeCallback`即可。 +3. 最后为CaptureFragment设置二维码解析回调接口`AnalyzeCallback`即可。 + +#### 设置相机聚焦的间隔 + +``` +//设置相机的自动聚焦间隔 +XQRCode.setAutoFocusInterval(1500L); +``` ### 2.3、二维码生成 @@ -205,7 +275,7 @@ https://github.com/yipianfengye/android-zxingLibrary ![](https://github.com/xuexiangjys/XPage/blob/master/img/qq_group.jpg) -[xqsvg]: https://img.shields.io/badge/XQRCode-v1.0.3-brightgreen.svg +[xqsvg]: https://img.shields.io/badge/XQRCode-v1.0.4-brightgreen.svg [xq]: https://github.com/xuexiangjys/XQRCode [apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg [api]: https://android-arsenal.com/api?level=14 \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 5f5a3ec..40809c1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'com.xuexiang.xaop' //引用xaop插件 +//apply plugin: 'img-optimizer' android { compileSdkVersion build_versions.target_sdk diff --git a/app/src/main/java/com/xuexiang/xqrcodedemo/App.java b/app/src/main/java/com/xuexiang/xqrcodedemo/App.java index 92db62b..882bc52 100644 --- a/app/src/main/java/com/xuexiang/xqrcodedemo/App.java +++ b/app/src/main/java/com/xuexiang/xqrcodedemo/App.java @@ -26,6 +26,7 @@ import com.xuexiang.xpage.PageConfig; import com.xuexiang.xpage.PageConfiguration; import com.xuexiang.xpage.model.PageInfo; +import com.xuexiang.xqrcode.XQRCode; import com.xuexiang.xutil.XUtil; import com.xuexiang.xutil.common.StringUtils; import com.xuexiang.xutil.tip.ToastUtils; @@ -73,6 +74,8 @@ public void onDenied(List permissionsDenied) { @Permission(CAMERA) private void initPermission() { + //设置相机的自动聚焦间隔 + XQRCode.setAutoFocusInterval(1500L); ToastUtils.toast("相机权限已获取!"); } } diff --git a/app/src/main/java/com/xuexiang/xqrcodedemo/fragment/MainFragment.java b/app/src/main/java/com/xuexiang/xqrcodedemo/fragment/MainFragment.java index ce6edee..7822eca 100644 --- a/app/src/main/java/com/xuexiang/xqrcodedemo/fragment/MainFragment.java +++ b/app/src/main/java/com/xuexiang/xqrcodedemo/fragment/MainFragment.java @@ -49,7 +49,7 @@ import static com.xuexiang.xqrcode.XQRCode.KEY_SCAN_INTERVAL; /** - * 二维码扫描 + * 二维码扫描 * * @author xuexiang * @since 2019/1/16 下午11:56 @@ -78,6 +78,7 @@ public class MainFragment extends XPageSimpleListFragment { @Override protected List initSimpleData(List lists) { lists.add("默认扫描界面"); + lists.add("默认扫描界面(自定义主题)"); lists.add("定制化扫描界面(单次)"); lists.add("定制化扫描界面(多次)"); lists.add("远程扫描界面"); @@ -98,18 +99,21 @@ protected void onItemClick(int position) { startScan(ScanType.DEFAULT); break; case 1: - startScan(ScanType.CUSTOM_SINGLE); + startScan(ScanType.DEFAULT_Custom); break; case 2: - startScan(ScanType.CUSTOM_MULTIPLE); + startScan(ScanType.CUSTOM_SINGLE); break; case 3: - startScan(ScanType.REMOTE); + startScan(ScanType.CUSTOM_MULTIPLE); break; case 4: - openPage(QRCodeProduceFragment.class); + startScan(ScanType.REMOTE); break; case 5: + openPage(QRCodeProduceFragment.class); + break; + case 6: selectQRCode(); break; default: @@ -126,18 +130,20 @@ private void selectQRCode() { * 开启二维码扫描 */ @Permission(CAMERA) - @IOThread(ThreadType.Single) private void startScan(ScanType scanType) { switch (scanType) { + case DEFAULT: + XQRCode.startScan(this, REQUEST_CODE); + break; + case DEFAULT_Custom: + XQRCode.startScan(this, REQUEST_CODE, R.style.XQRCodeTheme_Custom); + break; case CUSTOM_SINGLE: openPageForResult(CustomCaptureFragment.class, getScanParam(false, 0), REQUEST_CUSTOM_SCAN); break; case CUSTOM_MULTIPLE: openPage(CustomCaptureFragment.class, getScanParam(true, 1000)); break; - case DEFAULT: - XQRCode.startScan(this, REQUEST_CODE, R.style.XQRCodeTheme_Custom); - break; case REMOTE: Intent intent = new Intent(XQRCode.ACTION_DEFAULT_CAPTURE); startActivityForResult(intent, REQUEST_CODE); @@ -187,6 +193,11 @@ else if (requestCode == REQUEST_IMAGE) { } } + /** + * 进行二维码解析 + * + * @param uri + */ @SuppressLint("MissingPermission") private void getAnalyzeQRCodeResult(Uri uri) { XQRCode.analyzeQRCode(PathUtils.getFilePathByUri(getContext(), uri), new QRCodeAnalyzeUtils.AnalyzeCallback() { @@ -252,6 +263,10 @@ public enum ScanType { * 默认 */ DEFAULT, + /** + * 默认(修改主题) + */ + DEFAULT_Custom, /** * 远程 */ diff --git a/app/src/main/res/layout/layout_custom_camera.xml b/app/src/main/res/layout/layout_custom_camera.xml index ca599da..39f88c6 100644 --- a/app/src/main/res/layout/layout_custom_camera.xml +++ b/app/src/main/res/layout/layout_custom_camera.xml @@ -34,7 +34,7 @@ app:inner_marginTop="80dp" app:inner_scan_bitmap="@mipmap/ic_scan_image" app:inner_scan_isCircle="false" - app:inner_scan_speed="10" + app:inner_scan_speed="10dp" app:inner_height="300dp" app:inner_width="300dp" /> diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png index a2f5908..b7d01ab 100644 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png index 1b52399..6e1def5 100644 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png index ff10afd..d9b9233 100644 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png index 115a4c7..a8d93e7 100644 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png index dcd3cd8..b2839aa 100644 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png index 459ca60..5a81753 100644 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index 8ca12fe..98e53a8 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png index 8e19b41..cfa53db 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index b824ebd..de8465c 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png index 4c19a13..b88d518 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 354d87f..b4d5c9c 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -15,6 +15,10 @@ diff --git a/build.gradle b/build.gradle index ea218bf..fa25a93 100644 --- a/build.gradle +++ b/build.gradle @@ -9,8 +9,8 @@ buildscript { classpath deps.android_maven_gradle_plugin classpath 'com.github.xuexiangjys.XAOP:xaop-plugin:1.0.1' - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.chenenyu:img-optimizer:1.1.1' // 图片压缩 + } } diff --git a/docs/README.md b/docs/README.md index a3de2bf..9126321 100644 --- a/docs/README.md +++ b/docs/README.md @@ -28,7 +28,7 @@ allprojects { ``` dependencies { ... - implementation 'com.github.xuexiangjys:XQRCode:1.0.3' + implementation 'com.github.xuexiangjys:XQRCode:1.0.4' } ``` @@ -39,7 +39,7 @@ https://github.com/yipianfengye/android-zxingLibrary [![](https://img.shields.io/badge/点击一键加入QQ交流群-602082750-blue.svg)](http://shang.qq.com/wpa/qunwpa?idkey=9922861ef85c19f1575aecea0e8680f60d9386080a97ed310c971ae074998887) -[xqsvg]: https://img.shields.io/badge/XQRCode-v1.0.3-brightgreen.svg +[xqsvg]: https://img.shields.io/badge/XQRCode-v1.0.4-brightgreen.svg [xq]: https://github.com/xuexiangjys/XQRCode [apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg [api]: https://android-arsenal.com/api?level=14 \ No newline at end of file diff --git a/xqrcode-lib/build.gradle b/xqrcode-lib/build.gradle index c5f31f6..f069e78 100644 --- a/xqrcode-lib/build.gradle +++ b/xqrcode-lib/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.library' +//apply plugin: 'img-optimizer' android { compileSdkVersion build_versions.target_sdk diff --git a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/XQRCode.java b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/XQRCode.java index 47255e5..94f9830 100644 --- a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/XQRCode.java +++ b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/XQRCode.java @@ -24,6 +24,7 @@ import android.support.v4.app.Fragment; import com.google.zxing.Result; +import com.xuexiang.xqrcode.camera.AutoFocusCallback; import com.xuexiang.xqrcode.camera.CameraManager; import com.xuexiang.xqrcode.logs.QCLog; import com.xuexiang.xqrcode.ui.CaptureActivity; @@ -35,11 +36,10 @@ import static com.xuexiang.xqrcode.util.QRCodeProduceUtils.QRCODE_BITMAP_MAX_SIZE; /** - *
- *     desc   : 二维码 XQRCode API
- *     author : xuexiang
- *     time   : 2018/5/4 上午12:33
- * 
+ * 二维码 XQRCode API + * + * @author xuexiang + * @since 2019-05-18 17:39 */ public class XQRCode { @@ -80,6 +80,11 @@ public class XQRCode { */ public static final String ACTION_DEFAULT_CAPTURE = "com.xuexiang.xqrcode.ui.captureactivity"; + /** + * 自动聚焦的间期 + */ + public static long sAutoFocusInterval = AutoFocusCallback.AUTO_FOCUS_INTERVAL_MS; + /** * 设置是否打开调试 * @@ -98,6 +103,19 @@ public static void debug(String tag) { QCLog.debug(tag); } + /** + * 设置自动聚焦的间期【默认是1500ms】 + * + * @param sAutoFocusInterval + */ + public static void setAutoFocusInterval(long sAutoFocusInterval) { + XQRCode.sAutoFocusInterval = sAutoFocusInterval; + } + + public static long getAutoFocusInterval() { + return sAutoFocusInterval; + } + //==================================调用默认二维码扫描=================================// /** diff --git a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/AutoFocusCallback.java b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/AutoFocusCallback.java index 5088be3..8da2d55 100644 --- a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/AutoFocusCallback.java +++ b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/AutoFocusCallback.java @@ -20,13 +20,20 @@ import android.os.Handler; import android.os.Message; +import com.xuexiang.xqrcode.XQRCode; import com.xuexiang.xqrcode.logs.QCLog; +/** + * 自动聚焦的回掉 + * + * @author xuexiang + * @since 2019-05-18 17:23 + */ public final class AutoFocusCallback implements Camera.AutoFocusCallback { private static final String TAG = AutoFocusCallback.class.getSimpleName(); - private static final long AUTOFOCUS_INTERVAL_MS = 1500L; + public static final long AUTO_FOCUS_INTERVAL_MS = 1500L; private Handler autoFocusHandler; private int autoFocusMessage; @@ -40,7 +47,7 @@ public void setHandler(Handler autoFocusHandler, int autoFocusMessage) { public void onAutoFocus(boolean success, Camera camera) { if (autoFocusHandler != null) { Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success); - autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS); + autoFocusHandler.sendMessageDelayed(message, XQRCode.getAutoFocusInterval()); autoFocusHandler = null; } else { QCLog.dTag(TAG, "Got auto-focus callback, but no handler for it"); diff --git a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/CameraManager.java b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/CameraManager.java index 89b754b..7580147 100644 --- a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/CameraManager.java +++ b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/CameraManager.java @@ -195,7 +195,6 @@ public void requestPreviewFrame(Handler handler, int message) { public void requestAutoFocus(Handler handler, int message) { if (camera != null && previewing) { autoFocusCallback.setHandler(handler, message); - //Log.d(TAG, "Requesting auto-focus callback"); camera.autoFocus(autoFocusCallback); } } diff --git a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/PreviewCallback.java b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/PreviewCallback.java index c15a77e..db44d7c 100644 --- a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/PreviewCallback.java +++ b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/camera/PreviewCallback.java @@ -49,8 +49,7 @@ public void onPreviewFrame(byte[] data, Camera camera) { camera.setPreviewCallback(null); } if (previewHandler != null) { - Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x, - cameraResolution.y, data); + Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x, cameraResolution.y, data); message.sendToTarget(); previewHandler = null; } else { diff --git a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/decoding/InactivityTimer.java b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/decoding/InactivityTimer.java index db5aa4f..be4441f 100644 --- a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/decoding/InactivityTimer.java +++ b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/decoding/InactivityTimer.java @@ -34,8 +34,7 @@ public final class InactivityTimer { private static final int INACTIVITY_DELAY_SECONDS = 5 * 60; - private final ScheduledExecutorService inactivityTimer = - Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory()); + private final ScheduledExecutorService inactivityTimer = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory()); private final Activity mActivity; private ScheduledFuture mInactivityFuture = null; diff --git a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/view/ViewfinderView.java b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/view/ViewfinderView.java index 9274db9..9805eee 100644 --- a/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/view/ViewfinderView.java +++ b/xqrcode-lib/src/main/java/com/xuexiang/xqrcode/view/ViewfinderView.java @@ -91,15 +91,15 @@ private void initInnerRect(Context context, AttributeSet attrs, int defStyleAttr CameraManager.FRAME_HEIGHT = ta.getDimensionPixelSize(R.styleable.ViewfinderView_inner_height, getDefaultScanSize(getContext())); // 扫描框边角颜色 - innercornercolor = ta.getColor(R.styleable.ViewfinderView_inner_corner_color, resources.getColor(R.color.default_inner_corner_color)); + cornerColor = ta.getColor(R.styleable.ViewfinderView_inner_corner_color, resources.getColor(R.color.default_inner_corner_color)); // 扫描框边角长度 - innercornerlength = ta.getDimensionPixelSize(R.styleable.ViewfinderView_inner_corner_length, resources.getDimensionPixelSize(R.dimen.default_inner_corner_length)); + cornerLength = ta.getDimensionPixelSize(R.styleable.ViewfinderView_inner_corner_length, resources.getDimensionPixelSize(R.dimen.default_inner_corner_length)); // 扫描框边角宽度 - innercornerwidth = ta.getDimensionPixelSize(R.styleable.ViewfinderView_inner_corner_width, resources.getDimensionPixelSize(R.dimen.default_inner_corner_width)); + cornerWidth = ta.getDimensionPixelSize(R.styleable.ViewfinderView_inner_corner_width, resources.getDimensionPixelSize(R.dimen.default_inner_corner_width)); // 扫描控件 scanLight = BitmapFactory.decodeResource(getResources(), ta.getResourceId(R.styleable.ViewfinderView_inner_scan_bitmap, R.drawable.xqrcode_ic_scan_light)); // 扫描速度 - scanVelocity = ta.getInt(R.styleable.ViewfinderView_inner_scan_speed, 5); + scanVelocity = ta.getDimensionPixelSize(R.styleable.ViewfinderView_inner_scan_speed, resources.getDimensionPixelSize(R.dimen.default_inner_scan_speed)); isCircle = ta.getBoolean(R.styleable.ViewfinderView_inner_scan_isCircle, true); mMaskColor = ta.getColor(R.styleable.ViewfinderView_inner_mask_color, resources.getColor(R.color.default_mask_color)); @@ -110,6 +110,7 @@ private void initInnerRect(Context context, AttributeSet attrs, int defStyleAttr @Override public void onDraw(Canvas canvas) { + //扫描的区域 Rect frame = CameraManager.get().getFramingRect(); if (frame == null) { return; @@ -120,9 +121,9 @@ public void onDraw(Canvas canvas) { // Draw the exterior (i.e. outside the framing rect) darkened mPaint.setColor(mResultBitmap != null ? mResultColor : mMaskColor); canvas.drawRect(0, 0, width, frame.top, mPaint); - canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, mPaint); - canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, mPaint); - canvas.drawRect(0, frame.bottom + 1, width, height, mPaint); + canvas.drawRect(0, frame.top, frame.left, frame.bottom, mPaint); + canvas.drawRect(frame.right, frame.top, width, frame.bottom, mPaint); + canvas.drawRect(0, frame.bottom, width, height, mPaint); if (mResultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle @@ -163,13 +164,21 @@ public void onDraw(Canvas canvas) { } } - // 扫描线移动的y + /** + * 扫描线移动的y + */ private int scanLineTop; - // 扫描线移动速度 + /** + * 扫描线移动速度 + */ private int scanVelocity; - // 扫描线 + /** + * 扫描线 + */ private Bitmap scanLight; - // 是否展示小圆点 + /** + * 是否展示小圆点 + */ private boolean isCircle; /** @@ -179,7 +188,6 @@ public void onDraw(Canvas canvas) { * @param frame */ private void drawScanLight(Canvas canvas, Rect frame) { - if (scanLineTop == 0) { scanLineTop = frame.top; } @@ -189,18 +197,23 @@ private void drawScanLight(Canvas canvas, Rect frame) { } else { scanLineTop += scanVelocity; } - Rect scanRect = new Rect(frame.left, scanLineTop, frame.right, - scanLineTop + 30); + Rect scanRect = new Rect(frame.left, scanLineTop, frame.right, scanLineTop + 30); canvas.drawBitmap(scanLight, null, scanRect, mPaint); } - // 扫描框边角颜色 - private int innercornercolor; - // 扫描框边角长度 - private int innercornerlength; - // 扫描框边角宽度 - private int innercornerwidth; + /** + * 扫描框边角颜色 + */ + private int cornerColor; + /** + * 扫描框边角长度 + */ + private int cornerLength; + /** + * 扫描框边角宽度 + */ + private int cornerWidth; /** * 绘制取景框边框 @@ -209,33 +222,23 @@ private void drawScanLight(Canvas canvas, Rect frame) { * @param frame */ private void drawFrameBounds(Canvas canvas, Rect frame) { - - mPaint.setColor(innercornercolor); + mPaint.setColor(cornerColor); mPaint.setStyle(Paint.Style.FILL); - - int corWidth = innercornerwidth; - int corLength = innercornerlength; + int corWidth = cornerWidth; + int corLength = cornerLength; // 左上角 - canvas.drawRect(frame.left, frame.top, frame.left + corWidth, frame.top - + corLength, mPaint); - canvas.drawRect(frame.left, frame.top, frame.left - + corLength, frame.top + corWidth, mPaint); + canvas.drawRect(frame.left, frame.top, frame.left + corWidth, frame.top + corLength, mPaint); + canvas.drawRect(frame.left, frame.top, frame.left + corLength, frame.top + corWidth, mPaint); // 右上角 - canvas.drawRect(frame.right - corWidth, frame.top, frame.right, - frame.top + corLength, mPaint); - canvas.drawRect(frame.right - corLength, frame.top, - frame.right, frame.top + corWidth, mPaint); + canvas.drawRect(frame.right - corWidth, frame.top, frame.right, frame.top + corLength, mPaint); + canvas.drawRect(frame.right - corLength, frame.top, frame.right, frame.top + corWidth, mPaint); // 左下角 - canvas.drawRect(frame.left, frame.bottom - corLength, - frame.left + corWidth, frame.bottom, mPaint); - canvas.drawRect(frame.left, frame.bottom - corWidth, frame.left - + corLength, frame.bottom, mPaint); + canvas.drawRect(frame.left, frame.bottom - corLength, frame.left + corWidth, frame.bottom, mPaint); + canvas.drawRect(frame.left, frame.bottom - corWidth, frame.left + corLength, frame.bottom, mPaint); // 右下角 - canvas.drawRect(frame.right - corWidth, frame.bottom - corLength, - frame.right, frame.bottom, mPaint); - canvas.drawRect(frame.right - corLength, frame.bottom - corWidth, - frame.right, frame.bottom, mPaint); + canvas.drawRect(frame.right - corWidth, frame.bottom - corLength, frame.right, frame.bottom, mPaint); + canvas.drawRect(frame.right - corLength, frame.bottom - corWidth, frame.right, frame.bottom, mPaint); } diff --git a/xqrcode-lib/src/main/res/drawable-hdpi/xqrcode_ic_scan_light.png b/xqrcode-lib/src/main/res/drawable-hdpi/xqrcode_ic_scan_light.png index 0ed22ab..774d893 100644 Binary files a/xqrcode-lib/src/main/res/drawable-hdpi/xqrcode_ic_scan_light.png and b/xqrcode-lib/src/main/res/drawable-hdpi/xqrcode_ic_scan_light.png differ diff --git a/xqrcode-lib/src/main/res/values/xqrcode_attrs.xml b/xqrcode-lib/src/main/res/values/xqrcode_attrs.xml index 86a162e..0136697 100644 --- a/xqrcode-lib/src/main/res/values/xqrcode_attrs.xml +++ b/xqrcode-lib/src/main/res/values/xqrcode_attrs.xml @@ -8,16 +8,16 @@ - + - + - - + + diff --git a/xqrcode-lib/src/main/res/values/xqrcode_colors.xml b/xqrcode-lib/src/main/res/values/xqrcode_colors.xml index 4c07fa7..838f7ed 100644 --- a/xqrcode-lib/src/main/res/values/xqrcode_colors.xml +++ b/xqrcode-lib/src/main/res/values/xqrcode_colors.xml @@ -4,5 +4,5 @@ #B0000000 #C0FFFF00 - #45DDDD + #0DC2FE diff --git a/xqrcode-lib/src/main/res/values/xqrcode_dimens.xml b/xqrcode-lib/src/main/res/values/xqrcode_dimens.xml index 6ea0ee1..e151145 100644 --- a/xqrcode-lib/src/main/res/values/xqrcode_dimens.xml +++ b/xqrcode-lib/src/main/res/values/xqrcode_dimens.xml @@ -2,7 +2,8 @@ 32dp - 8dp + 6dp + 5dp diff --git a/xqrcode-lib/src/main/res/values/xqrcode_styles.xml b/xqrcode-lib/src/main/res/values/xqrcode_styles.xml index 8c3a073..75100a1 100644 --- a/xqrcode-lib/src/main/res/values/xqrcode_styles.xml +++ b/xqrcode-lib/src/main/res/values/xqrcode_styles.xml @@ -10,7 +10,7 @@ @dimen/default_inner_corner_length @dimen/default_inner_corner_width @drawable/xqrcode_ic_scan_light - 5 + @dimen/default_inner_scan_speed true @color/default_result_color @color/default_result_point_color