├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── compiler.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml ├── jarRepositories.xml ├── misc.xml └── vcs.xml ├── LICENSE ├── README.md ├── apk └── demo.apk ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── maning │ │ └── mlkitscanner │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── maning │ │ │ └── mlkitscanner │ │ │ └── demo │ │ │ ├── CustomConfigActivity.java │ │ │ └── MainActivity.java │ └── res │ │ ├── anim │ │ ├── activity_anmie_in.xml │ │ └── activity_anmie_out.xml │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xxhdpi │ │ ├── ic_wx.png │ │ ├── icon_custom_back.png │ │ ├── icon_custom_light_close.png │ │ ├── icon_custom_light_open.png │ │ ├── icon_custom_my_card.png │ │ ├── icon_custom_photo.png │ │ ├── icon_custom_record.png │ │ └── tmp.png │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_custom_config.xml │ │ ├── activity_main.xml │ │ └── layout_custom_view.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── array.xml │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── maning │ └── mlkitscanner │ └── ExampleUnitTest.java ├── build.gradle ├── config.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mlkit-scanner ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── maning │ │ └── mlkitscanner │ │ └── scan │ │ ├── MNScanManager.java │ │ ├── analyser │ │ └── BarcodeAnalyser.java │ │ ├── callback │ │ ├── MNCustomViewBindCallback.java │ │ ├── OnCameraAnalyserCallback.java │ │ └── act │ │ │ ├── ActResultRequest.java │ │ │ ├── MNScanCallback.java │ │ │ └── OnActResultEventDispatcherFragment.java │ │ ├── camera │ │ ├── CameraManager.java │ │ └── CameraSizeUtils.java │ │ ├── model │ │ └── MNScanConfig.java │ │ ├── ui │ │ └── ScanPreviewActivity.java │ │ ├── utils │ │ ├── AmbientLightManager.java │ │ ├── BeepManager.java │ │ ├── CommonUtils.java │ │ ├── ImageUtils.java │ │ ├── StatusBarUtil.java │ │ └── ZXingUtils.java │ │ └── view │ │ ├── ScanActionMenuView.java │ │ ├── ScanResultPointView.java │ │ └── ViewfinderView.java │ └── res │ ├── anim │ ├── mn_scan_activity_bottom_in.xml │ └── mn_scan_activity_bottom_out.xml │ ├── drawable-xxhdpi │ ├── mn_icon_scan_close.png │ ├── mn_icon_scan_default_result_point_arrow.png │ ├── mn_icon_scan_flash_light_off.png │ ├── mn_icon_scan_flash_light_on.png │ ├── mn_icon_scan_photo.png │ ├── mn_scan_icon_thumb.png │ ├── mn_scan_icon_zoom_in.png │ └── mn_scan_icon_zoom_out.png │ ├── drawable │ └── mn_scan_result_point_default.xml │ ├── layout │ ├── mn_scan_action_menu.xml │ ├── mn_scan_activity_scan_preview.xml │ ├── mn_scan_result_point_item_view.xml │ └── mn_scan_result_point_view.xml │ ├── raw │ └── mn_scan_beep.ogg │ └── values │ ├── colors.xml │ └── styles.xml ├── screenshots ├── mn_mlkit_scanner_ss_01.jpg ├── mn_mlkit_scanner_ss_02.jpg ├── mn_mlkit_scanner_ss_03.jpg ├── mn_mlkit_scanner_ss_04.jpg └── mn_mlkit_scanner_ss_05.jpg └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 45 | 46 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 100 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MNMLKitScanner 基于Google MLKit 快速集成二维码扫描,速度比zxing快 2 | 3 | ## 基于Google MLKit 快速集成二维码扫描,速度比zxing快,可配置相册,闪光灯,相机可以调整焦距放大缩小,自定义扫描线颜色,自定义背景颜色,自定义遮罩层,支持同时扫多个二维码和条形码 4 | [![](https://jitpack.io/v/maning0303/MNMLKitScanner.svg)](https://jitpack.io/#maning0303/MNMLKitScanner) 5 | 6 | ## 功能: 7 | 1:二维码扫描,手势缩放,无拉伸,样式自定义 8 | 2:相册中选取图片识别 9 | 3: 相机可以调整焦距放大缩小 10 | 4: 完全自定义遮罩层 11 | 5: 支持微信多个二维码/条形码同时扫描 12 | 6: 可调整扫描框大小 13 | 14 | 15 | ## 截图: 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | ## 如何添加 26 | ### Gradle添加: 27 | #### 1.在Project的build.gradle中添加仓库地址 28 | 29 | ``` gradle 30 | allprojects { 31 | repositories { 32 | ... 33 | maven { url "https://jitpack.io" } 34 | } 35 | } 36 | ``` 37 | 38 | #### 2.在Module目录下的build.gradle中添加依赖 39 | ``` gradle 40 | dependencies { 41 | 42 | implementation 'com.github.maning0303:MNMLKitScanner:V1.0.4' 43 | //下面版本自己控制,barcode-scanning>=17.0.2 44 | implementation 'com.google.mlkit:barcode-scanning:17.0.2' 45 | implementation "androidx.camera:camera-core:1.0.2" 46 | implementation "androidx.camera:camera-camera2:1.0.2" 47 | implementation "androidx.camera:camera-lifecycle:1.0.2" 48 | implementation "androidx.camera:camera-view:1.0.0-alpha25" 49 | 50 | } 51 | ``` 52 | 53 | #### 3.如果想加入二维码生成功能 54 | ``` gradle 55 | dependencies { 56 | 57 | implementation 'com.google.zxing:core:3.3.3' 58 | 59 | } 60 | ``` 61 | com.maning.mlkitscanner.scan.utils.ZXingUtils 有具体的方法,详细可以查看Demo 62 | 63 | 64 | ## 使用方法: 65 | ### 进入需要提前申请相机权限;进入需要提前申请相机权限;进入需要提前申请相机权限; 66 | 67 | 68 | ``` java 69 | 1:开始扫描: 70 | //默认扫描 71 | MNScanManager.startScan(this, new MNScanCallback() { 72 | @Override 73 | public void onActivityResult(int resultCode, Intent data) { 74 | switch (resultCode) { 75 | case MNScanManager.RESULT_SUCCESS: 76 | ArrayList results = data.getStringArrayListExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS); 77 | break; 78 | case MNScanManager.RESULT_FAIL: 79 | String resultError = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_ERROR); 80 | break; 81 | case MNScanManager.RESULT_CANCLE: 82 | showToast("取消扫码"); 83 | break; 84 | } 85 | } 86 | }); 87 | 88 | //自定义扫描 89 | MNScanConfig scanConfig = new MNScanConfig.Builder() 90 | //设置完成震动 91 | .isShowVibrate(true) 92 | //扫描完成声音 93 | .isShowBeep(true) 94 | //显示相册功能 95 | .isShowPhotoAlbum(true) 96 | //显示闪光灯 97 | .isShowLightController(true) 98 | //打开扫描页面的动画 99 | .setActivityOpenAnime(R.anim.activity_anmie_in) 100 | //退出扫描页面动画 101 | .setActivityExitAnime(R.anim.activity_anmie_out) 102 | //自定义文案 103 | .setScanHintText("xxxx") 104 | .setScanHintTextColor("#FF0000") 105 | .setScanHintTextSize(14) 106 | //扫描线的颜色 107 | .setScanColor("#FF0000") 108 | //是否支持手势缩放 109 | .setSupportZoom(true) 110 | //扫描线样式 111 | .setLaserStyle(MNScanConfig.LaserStyle.Grid/MNScanConfig.LaserStyle.Line) 112 | //背景颜色 113 | .setBgColor("") 114 | //网格扫描线的列数 115 | .setGridScanLineColumn(30) 116 | //网格高度 117 | .setGridScanLineHeight(300) 118 | //是否全屏扫描,默认全屏 119 | .setFullScreenScan(true) 120 | //单位dp 121 | .setResultPointConfigs(36, 12, 3, colorResultPointStroke, colorResultPoint) 122 | //状态栏设置 123 | .setStatusBarConfigs(colorStatusBar, true) 124 | //扫描框宽度大小比例,非全屏模式下生效,默认0.7,范围0.5-0.9 125 | .setScanFrameSizeScale(0.7f) 126 | //自定义遮罩 127 | .setCustomShadeViewLayoutID(R.layout.layout_custom_view, new MNCustomViewBindCallback() { 128 | @Override 129 | public void onBindView(View customView) { 130 | //TODO:通过findviewById 获取View 131 | } 132 | }) 133 | .builder(); 134 | MNScanManager.startScan(this, scanConfig, new MNScanCallback() { 135 | @Override 136 | public void onActivityResult(int resultCode, Intent data) { 137 | switch (resultCode) { 138 | case MNScanManager.RESULT_SUCCESS: 139 | String resultSuccess = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS); 140 | break; 141 | case MNScanManager.RESULT_FAIL: 142 | String resultError = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_ERROR); 143 | break; 144 | case MNScanManager.RESULT_CANCLE: 145 | showToast("取消扫码"); 146 | break; 147 | } 148 | } 149 | }); 150 | 151 | 2.提供扫描界面相关方法(自定义遮罩层会使用): 152 | /** 153 | * 关闭当前页面 154 | */ 155 | MNScanManager.closeScanPage(); 156 | 157 | /** 158 | * 打开相册扫描图片 159 | */ 160 | MNScanManager.openAlbumPage(); 161 | 162 | /** 163 | * 打开手电筒 164 | */ 165 | MNScanManager.openScanLight(); 166 | 167 | /** 168 | * 关闭手电筒 169 | */ 170 | MNScanManager.closeScanLight(); 171 | 172 | /** 173 | * 手电筒是否开启 174 | */ 175 | MNScanManager.isLightOn(); 176 | ``` 177 | 178 | 179 | ## 感谢: 180 | 181 | [googlesamples/mlkit](https://github.com/googlesamples/mlkit) 182 | 183 | [jenly1314/MLKit](https://github.com/jenly1314/MLKit) 184 | 185 | [Ye-Miao/StatusBarUtil](https://github.com/Ye-Miao/StatusBarUtil) 186 | 187 | 感谢所有开源的人; 188 | 189 | 190 | 191 | ## 推荐: 192 | Name | Describe | 193 | --- | --- | 194 | [GankMM](https://github.com/maning0303/GankMM) | (Material Design & MVP & Retrofit + OKHttp & RecyclerView ...)Gank.io Android客户端:每天一张美女图片,一个视频短片,若干Android,iOS等程序干货,周一到周五每天更新,数据全部由 干货集中营 提供,持续更新。 | 195 | [MNUpdateAPK](https://github.com/maning0303/MNUpdateAPK) | Android APK 版本更新的下载和安装,适配7.0,简单方便。 | 196 | [MNImageBrowser](https://github.com/maning0303/MNImageBrowser) | 交互特效的图片浏览框架,微信向下滑动动态关闭 | 197 | [MNZXingCode](https://github.com/maning0303/MNZXingCode) | 快速集成二维码扫描和生成二维码 | 198 | [MNMLKitScanner](https://github.com/maning0303/MNMLKitScanner) | 基于Google MLKit 快速集成二维码扫描,速度比zxing快 | 199 | [MNPasswordEditText](https://github.com/maning0303/MNPasswordEditText) | 类似微信支付宝的密码输入框。 | 200 | [MClearEditText](https://github.com/maning0303/MClearEditText) | 带有删除功能的EditText | 201 | [MNCrashMonitor](https://github.com/maning0303/MNCrashMonitor) | Debug监听程序崩溃日志,展示崩溃日志列表,方便自己平时调试。 | 202 | [MNProgressHUD](https://github.com/maning0303/MNProgressHUD) | MNProgressHUD是对常用的自定义弹框封装,加载ProgressDialog,状态显示的StatusDialog和自定义Toast,支持背景颜色,圆角,边框和文字的自定义。 | 203 | [SwitcherView](https://github.com/maning0303/SwitcherView) | 垂直滚动的广告栏文字展示。 | 204 | [MNVideoPlayer](https://github.com/maning0303/MNVideoPlayer) | SurfaceView + MediaPlayer 实现的视频播放器,支持横竖屏切换,手势快进快退、调节音量,亮度等。------代码简单,新手可以看一看。 | 205 | [MNChangeSkin](https://github.com/maning0303/MNChangeSkin) | Android夜间模式,通过Theme实现 | 206 | [MNXUtilsDB](https://github.com/maning0303/MNXUtilsDB) | xUtils3 数据库模块单独抽取出来,方便使用。 | 207 | [MNCalendar](https://github.com/maning0303/MNCalendar) | 简单的日历控件练习,水平方向日历支持手势滑动切换,跳转月份;垂直方向日历选取区间范围。 | 208 | [MNSwipeToLoadDemo](https://github.com/maning0303/MNSwipeToLoadDemo) | 利用SwipeToLoadLayout实现的各种下拉刷新效果(饿了吗,京东,百度外卖,美团外卖,天猫下拉刷新等)。 | 209 | 210 | -------------------------------------------------------------------------------- /apk/demo.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/apk/demo.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | def versions = rootProject.ext.versions 4 | def appId = rootProject.ext.appId 5 | def dependenciesGoogle = rootProject.ext.dependenciesGoogle 6 | def dependenciesOther = rootProject.ext.dependenciesOther 7 | 8 | android { 9 | compileSdkVersion versions.compileSdkVersion 10 | ndkVersion "20.1.5948944" 11 | defaultConfig { 12 | applicationId appId.app 13 | minSdkVersion versions.minSdkVersion 14 | targetSdkVersion versions.targetSdkVersion 15 | versionCode versions.versionCode 16 | versionName versions.versionName 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | } 31 | 32 | dependencies { 33 | implementation fileTree(dir: "libs", include: ["*.jar"]) 34 | implementation 'androidx.appcompat:appcompat:1.1.0' 35 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 36 | // 循环引入库 37 | dependenciesGoogle.each { k, v -> api v } 38 | dependenciesOther.each { k, v -> api v } 39 | dependenciesDebug.each { k, v -> debugImplementation v } 40 | 41 | //扫码核心库 42 | implementation project(path: ':mlkit-scanner') 43 | // implementation 'com.github.maning0303:MNMLKitScanner:V1.0.4' 44 | 45 | implementation 'com.google.mlkit:barcode-scanning:17.0.2' 46 | implementation 'androidx.camera:camera-core:1.0.2' 47 | implementation 'androidx.camera:camera-camera2:1.0.2' 48 | implementation 'androidx.camera:camera-lifecycle:1.0.2' 49 | implementation 'androidx.camera:camera-view:1.0.0-alpha25' 50 | 51 | implementation 'com.google.zxing:core:3.3.3' 52 | 53 | 54 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/maning/mlkitscanner/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.maning.mlkitscanner; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | assertEquals("com.maning.mlkitscanner", appContext.getPackageName()); 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/maning/mlkitscanner/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.maning.mlkitscanner.demo; 2 | 3 | import android.Manifest; 4 | import android.content.Intent; 5 | import android.content.pm.PackageManager; 6 | import android.graphics.Bitmap; 7 | import android.graphics.BitmapFactory; 8 | import android.graphics.Color; 9 | import android.os.Build; 10 | import android.os.Bundle; 11 | import android.text.TextUtils; 12 | import android.view.View; 13 | import android.widget.AdapterView; 14 | import android.widget.Button; 15 | import android.widget.CheckBox; 16 | import android.widget.EditText; 17 | import android.widget.ImageView; 18 | import android.widget.Spinner; 19 | import android.widget.TextView; 20 | import android.widget.Toast; 21 | 22 | import androidx.appcompat.app.AppCompatActivity; 23 | 24 | import com.maning.mlkitscanner.scan.MNScanManager; 25 | import com.maning.mlkitscanner.scan.callback.act.MNScanCallback; 26 | import com.maning.mlkitscanner.scan.utils.ZXingUtils; 27 | 28 | import java.util.ArrayList; 29 | 30 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 31 | 32 | private Button btnScanDefault; 33 | private Button btnScanCustom; 34 | private TextView tvResults; 35 | 36 | private ImageView imageView; 37 | private EditText editText; 38 | private CheckBox checkbox; 39 | private CheckBox checkbox2; 40 | private Spinner mSpColorBlack; 41 | private Spinner mSpColorWhite; 42 | private Spinner mSpMargin; 43 | 44 | private String error_correction_level; 45 | private int margin = 0; 46 | private int color_black = Color.BLACK; 47 | private int color_white = Color.WHITE; 48 | private Spinner mSpErrorCorrectionLevel; 49 | 50 | @Override 51 | protected void onCreate(Bundle savedInstanceState) { 52 | super.onCreate(savedInstanceState); 53 | setContentView(R.layout.activity_main); 54 | initView(); 55 | requestCameraPerm(); 56 | } 57 | 58 | private void initView() { 59 | btnScanDefault = (Button) findViewById(R.id.btn_scan_default); 60 | btnScanCustom = (Button) findViewById(R.id.btn_scan_custom); 61 | btnScanDefault.setOnClickListener(this); 62 | btnScanCustom.setOnClickListener(this); 63 | tvResults = (TextView) findViewById(R.id.tv_results); 64 | 65 | imageView = (ImageView) findViewById(R.id.imageView); 66 | editText = (EditText) findViewById(R.id.editText); 67 | checkbox = (CheckBox) findViewById(R.id.checkbox); 68 | checkbox2 = (CheckBox) findViewById(R.id.checkbox2); 69 | mSpColorBlack = (Spinner) findViewById(R.id.sp_color_black); 70 | mSpColorWhite = (Spinner) findViewById(R.id.sp_color_white); 71 | mSpMargin = (Spinner) findViewById(R.id.sp_margin); 72 | mSpMargin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 73 | @Override 74 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 75 | margin = Integer.parseInt(getResources().getStringArray(R.array.spinarr_margin)[position]); 76 | } 77 | 78 | @Override 79 | public void onNothingSelected(AdapterView parent) { 80 | 81 | } 82 | }); 83 | mSpColorBlack.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 84 | @Override 85 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 86 | String str_color_black = getResources().getStringArray(R.array.spinarr_color_black)[position]; 87 | if (str_color_black.equals("黑色")) { 88 | color_black = Color.BLACK; 89 | } else if (str_color_black.equals("白色")) { 90 | color_black = Color.WHITE; 91 | } else if (str_color_black.equals("蓝色")) { 92 | color_black = Color.BLUE; 93 | } else if (str_color_black.equals("绿色")) { 94 | color_black = Color.GREEN; 95 | } else if (str_color_black.equals("黄色")) { 96 | color_black = Color.YELLOW; 97 | } else if (str_color_black.equals("红色")) { 98 | color_black = Color.RED; 99 | } else { 100 | color_black = Color.BLACK; 101 | } 102 | 103 | } 104 | 105 | @Override 106 | public void onNothingSelected(AdapterView parent) { 107 | 108 | } 109 | }); 110 | mSpColorWhite.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 111 | @Override 112 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 113 | String str_color_white = getResources().getStringArray(R.array.spinarr_color_white)[position]; 114 | if (str_color_white.equals("黑色")) { 115 | color_white = Color.BLACK; 116 | } else if (str_color_white.equals("白色")) { 117 | color_white = Color.WHITE; 118 | } else if (str_color_white.equals("蓝色")) { 119 | color_white = Color.BLUE; 120 | } else if (str_color_white.equals("绿色")) { 121 | color_white = Color.GREEN; 122 | } else if (str_color_white.equals("黄色")) { 123 | color_white = Color.YELLOW; 124 | } else if (str_color_white.equals("红色")) { 125 | color_white = Color.RED; 126 | } else { 127 | color_white = Color.WHITE; 128 | } 129 | } 130 | 131 | @Override 132 | public void onNothingSelected(AdapterView parent) { 133 | 134 | } 135 | }); 136 | mSpErrorCorrectionLevel = (Spinner) findViewById(R.id.sp_error_correction_level); 137 | mSpErrorCorrectionLevel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 138 | @Override 139 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 140 | error_correction_level = getResources().getStringArray(R.array.spinarr_error_correction)[position]; 141 | } 142 | 143 | @Override 144 | public void onNothingSelected(AdapterView parent) { 145 | 146 | } 147 | }); 148 | } 149 | 150 | public void requestCameraPerm() { 151 | //判断权限 152 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 153 | if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { 154 | requestPermissions(new String[]{Manifest.permission.CAMERA}, 10010); 155 | } 156 | } 157 | } 158 | 159 | @Override 160 | public void onClick(View view) { 161 | if (view.getId() == R.id.btn_scan_default) { 162 | MNScanManager.startScan(this, new MNScanCallback() { 163 | @Override 164 | public void onActivityResult(int resultCode, Intent data) { 165 | handlerResult(resultCode, data); 166 | } 167 | }); 168 | }else if (view.getId() == R.id.btn_scan_custom) { 169 | //跳转到自定义界面 170 | startActivity(new Intent(this, CustomConfigActivity.class)); 171 | } 172 | } 173 | 174 | private void handlerResult(int resultCode, Intent data) { 175 | if (data == null) { 176 | return; 177 | } 178 | switch (resultCode) { 179 | default: 180 | break; 181 | case MNScanManager.RESULT_SUCCESS: 182 | ArrayList results = data.getStringArrayListExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS); 183 | StringBuilder resultStr = new StringBuilder(); 184 | for (int i = 0; i < results.size(); i++) { 185 | resultStr.append("第" + (i + 1) + "条:"); 186 | resultStr.append(results.get(i)); 187 | resultStr.append("\n"); 188 | } 189 | tvResults.setText(resultStr.toString()); 190 | break; 191 | case MNScanManager.RESULT_FAIL: 192 | String resultError = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_ERROR); 193 | showToast(resultError); 194 | break; 195 | case MNScanManager.RESULT_CANCLE: 196 | showToast("取消扫码"); 197 | break; 198 | } 199 | } 200 | 201 | private void showToast(String msg) { 202 | Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); 203 | } 204 | 205 | 206 | public void createQRImage(View view) { 207 | String str = editText.getText().toString(); 208 | 209 | if (TextUtils.isEmpty(str)) { 210 | Toast.makeText(this, "字符串不能为空", Toast.LENGTH_SHORT).show(); 211 | return; 212 | } 213 | 214 | Bitmap qrImage; 215 | Bitmap logo = null; 216 | Bitmap foreground_bitmap = null; 217 | if (checkbox.isChecked()) { 218 | logo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_wx); 219 | } 220 | if (checkbox2.isChecked()) { 221 | foreground_bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tmp); 222 | } 223 | qrImage = ZXingUtils.createQRCodeImage(str, 500, margin, color_black, color_white, error_correction_level, logo, foreground_bitmap); 224 | if (qrImage != null) { 225 | imageView.setImageBitmap(qrImage); 226 | } else { 227 | Toast.makeText(this, "生成失败", Toast.LENGTH_SHORT).show(); 228 | } 229 | 230 | } 231 | } -------------------------------------------------------------------------------- /app/src/main/res/anim/activity_anmie_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 12 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/anim/activity_anmie_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 12 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_wx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/drawable-xxhdpi/ic_wx.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/icon_custom_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/drawable-xxhdpi/icon_custom_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/icon_custom_light_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/drawable-xxhdpi/icon_custom_light_close.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/icon_custom_light_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/drawable-xxhdpi/icon_custom_light_open.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/icon_custom_my_card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/drawable-xxhdpi/icon_custom_my_card.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/icon_custom_photo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/drawable-xxhdpi/icon_custom_photo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/icon_custom_record.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/drawable-xxhdpi/icon_custom_record.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/tmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/drawable-xxhdpi/tmp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_custom_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 |