├── .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 |
6 |
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 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
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 |
99 |
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/#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 |
23 |
24 |
28 |
29 |
30 |
35 |
36 |
42 |
43 |
49 |
50 |
56 |
57 |
63 |
64 |
70 |
71 |
77 |
78 |
84 |
85 |
91 |
92 |
96 |
97 |
104 |
105 |
114 |
115 |
116 |
117 |
121 |
122 |
130 |
131 |
140 |
141 |
142 |
143 |
148 |
149 |
154 |
155 |
156 |
162 |
163 |
164 |
165 |
170 |
171 |
176 |
177 |
178 |
184 |
185 |
186 |
187 |
188 |
193 |
194 |
199 |
200 |
201 |
207 |
208 |
209 |
210 |
215 |
216 |
221 |
222 |
223 |
229 |
230 |
231 |
232 |
233 |
238 |
239 |
244 |
245 |
249 |
250 |
256 |
257 |
263 |
264 |
265 |
266 |
267 |
268 |
274 |
275 |
281 |
282 |
291 |
292 |
293 |
294 |
299 |
300 |
301 |
302 |
303 |
304 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
23 |
24 |
31 |
32 |
39 |
40 |
48 |
49 |
54 |
55 |
61 |
62 |
63 |
64 |
70 |
71 |
77 |
78 |
84 |
85 |
86 |
87 |
91 |
92 |
97 |
98 |
103 |
104 |
109 |
110 |
115 |
116 |
117 |
118 |
122 |
123 |
128 |
129 |
134 |
135 |
141 |
142 |
147 |
148 |
149 |
150 |
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_custom_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
19 |
20 |
28 |
29 |
37 |
38 |
39 |
40 |
47 |
48 |
55 |
56 |
62 |
63 |
70 |
71 |
72 |
73 |
80 |
81 |
86 |
87 |
93 |
94 |
95 |
96 |
103 |
104 |
109 |
110 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/array.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - L
5 | - M
6 | - Q
7 | - H
8 |
9 |
10 |
11 | - 0
12 | - 1
13 | - 2
14 | - 3
15 | - 4
16 |
17 |
18 |
19 | - 黑色
20 | - 白色
21 | - 蓝色
22 | - 绿色
23 | - 黄色
24 | - 红色
25 |
26 |
27 |
28 | - 白色
29 | - 黑色
30 | - 蓝色
31 | - 绿色
32 | - 黄色
33 | - 红色
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MLKit扫码
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/maning/mlkitscanner/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | apply from: "config.gradle"
3 |
4 | buildscript {
5 | repositories {
6 | google()
7 | jcenter()
8 | maven { url 'https://jitpack.io' }
9 | }
10 | dependencies {
11 | classpath "com.android.tools.build:gradle:4.0.0"
12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 | maven { url 'https://jitpack.io' }
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * 全局统一配置
3 | */
4 | ext {
5 |
6 | /**
7 | * 版本统一管理
8 | */
9 | versions = [
10 | versionCode : 101, //版本号
11 | versionName : "1.0.1", //版本名称
12 |
13 | compileSdkVersion: 29,
14 | minSdkVersion : 21,
15 | targetSdkVersion : 28,
16 |
17 | ]
18 |
19 | appId = [
20 | "app": "com.maning.mlkitscanner.demo",
21 | ]
22 |
23 | dependenciesGoogle = [
24 | annotation : 'androidx.annotation:annotation:1.1.0',
25 | supportv4 : 'androidx.legacy:legacy-support-v4:1.0.0',
26 | appcompat : 'androidx.appcompat:appcompat:1.2.0',
27 | design : 'com.google.android.material:material:1.0.0',
28 | recyclerView : 'androidx.recyclerview:recyclerview:1.0.0',
29 | constraintlayout: 'androidx.constraintlayout:constraintlayout:1.1.3',
30 | multidex : 'androidx.multidex:multidex:2.0.0',
31 | ]
32 |
33 | dependenciesOther = [
34 | //颜色选择器
35 | "colorpicker": 'com.github.duanhong169:colorpicker:1.1.6',
36 | "xpopup" : 'com.lxj:xpopup:2.2.19'
37 | ]
38 |
39 | dependenciesDebug = [
40 | "leakcanary": "com.squareup.leakcanary:leakcanary-android:2.5",
41 | ]
42 |
43 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Aug 20 09:04:58 CST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/mlkit-scanner/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/mlkit-scanner/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | def versions = rootProject.ext.versions
4 |
5 | android {
6 | compileSdkVersion versions.compileSdkVersion
7 | defaultConfig {
8 | minSdkVersion versions.minSdkVersion
9 | targetSdkVersion versions.targetSdkVersion
10 | versionCode versions.versionCode
11 | versionName versions.versionName
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_8
23 | targetCompatibility JavaVersion.VERSION_1_8
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: "libs", include: ["*.jar"])
29 | compileOnly 'androidx.appcompat:appcompat:1.1.0'
30 |
31 | compileOnly 'com.google.mlkit:barcode-scanning:17.0.2'
32 | compileOnly "androidx.camera:camera-core:1.0.2"
33 | compileOnly "androidx.camera:camera-camera2:1.0.2"
34 | compileOnly "androidx.camera:camera-lifecycle:1.0.2"
35 | compileOnly "androidx.camera:camera-view:1.0.0-alpha25"
36 |
37 | compileOnly 'com.google.zxing:core:3.3.3'
38 |
39 | }
--------------------------------------------------------------------------------
/mlkit-scanner/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/consumer-rules.pro
--------------------------------------------------------------------------------
/mlkit-scanner/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
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
14 |
17 |
18 |
21 |
22 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/MNScanManager.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 |
6 | import com.maning.mlkitscanner.scan.callback.act.ActResultRequest;
7 | import com.maning.mlkitscanner.scan.callback.act.MNScanCallback;
8 | import com.maning.mlkitscanner.scan.model.MNScanConfig;
9 | import com.maning.mlkitscanner.scan.ui.ScanPreviewActivity;
10 |
11 | /**
12 | * Created by maning on 2017/12/7.
13 | * 启动扫描的主类
14 | */
15 |
16 | public class MNScanManager {
17 |
18 | //常量
19 | public static final int RESULT_SUCCESS = 0;
20 | public static final int RESULT_FAIL = 1;
21 | public static final int RESULT_CANCLE = 2;
22 | public static final String INTENT_KEY_RESULT_SUCCESS = "INTENT_KEY_RESULT_SUCCESS";
23 | public static final String INTENT_KEY_RESULT_ERROR = "INTENT_KEY_RESULT_ERROR";
24 | //是否是调试模式
25 | public static final boolean isDebugMode = false;
26 |
27 |
28 | //跳转传入的数据
29 | public static final String INTENT_KEY_CONFIG_MODEL = "INTENT_KEY_CONFIG_MODEL";
30 |
31 |
32 | public static void startScan(Activity activity, MNScanCallback scanCallback) {
33 | startScan(activity, null, scanCallback);
34 | }
35 |
36 | public static void startScan(Activity activity, MNScanConfig mnScanConfig, MNScanCallback scanCallback) {
37 | if (mnScanConfig == null) {
38 | mnScanConfig = new MNScanConfig.Builder().builder();
39 | }
40 | Intent intent = new Intent(activity.getApplicationContext(), ScanPreviewActivity.class);
41 | //传递数据
42 | intent.putExtra(MNScanManager.INTENT_KEY_CONFIG_MODEL, mnScanConfig);
43 | ActResultRequest actResultRequest = new ActResultRequest(activity);
44 | actResultRequest.startForResult(intent, scanCallback);
45 | activity.overridePendingTransition(mnScanConfig.getActivityOpenAnime(), android.R.anim.fade_out);
46 | }
47 |
48 | /**
49 | * 关闭当前页面
50 | */
51 | public static void closeScanPage() {
52 | ScanPreviewActivity.closeScanPage();
53 | }
54 |
55 | /**
56 | * 打开相册扫描图片
57 | */
58 | public static void openAlbumPage() {
59 | ScanPreviewActivity.openAlbumPage();
60 | }
61 |
62 | /**
63 | * 打开手电筒
64 | */
65 | public static void openScanLight() {
66 | ScanPreviewActivity.openScanLight();
67 | }
68 |
69 | /**
70 | * 关闭手电筒
71 | */
72 | public static void closeScanLight() {
73 | ScanPreviewActivity.closeScanLight();
74 | }
75 |
76 | /**
77 | * 手电筒是否开启
78 | */
79 | public static boolean isLightOn() {
80 | return ScanPreviewActivity.isLightOn();
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/analyser/BarcodeAnalyser.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.analyser;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.util.Log;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.camera.core.ImageAnalysis;
9 | import androidx.camera.core.ImageProxy;
10 | import androidx.camera.view.PreviewView;
11 |
12 | import com.google.android.gms.tasks.OnCompleteListener;
13 | import com.google.android.gms.tasks.OnFailureListener;
14 | import com.google.android.gms.tasks.OnSuccessListener;
15 | import com.google.android.gms.tasks.Task;
16 | import com.google.mlkit.vision.barcode.BarcodeScanner;
17 | import com.google.mlkit.vision.barcode.BarcodeScannerOptions;
18 | import com.google.mlkit.vision.barcode.BarcodeScanning;
19 | import com.google.mlkit.vision.barcode.common.Barcode;
20 | import com.google.mlkit.vision.common.InputImage;
21 | import com.maning.mlkitscanner.scan.callback.OnCameraAnalyserCallback;
22 | import com.maning.mlkitscanner.scan.utils.ImageUtils;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author : maning
28 | * @date : 8/18/21
29 | * @desc :
30 | */
31 | public class BarcodeAnalyser implements ImageAnalysis.Analyzer {
32 |
33 | private OnCameraAnalyserCallback onCameraAnalyserCallback;
34 | private final BarcodeScanner barcodeScanner;
35 | /**
36 | * 是否分析
37 | */
38 | private volatile boolean isAnalyze = true;
39 | private Context context;
40 | private PreviewView mPreviewView;
41 |
42 | public BarcodeScanner getBarcodeScanner() {
43 | return barcodeScanner;
44 | }
45 |
46 | public void setAnalyze(boolean analyze) {
47 | isAnalyze = analyze;
48 | }
49 |
50 | public void setOnCameraAnalyserCallback(OnCameraAnalyserCallback onCameraAnalyserCallback) {
51 | this.onCameraAnalyserCallback = onCameraAnalyserCallback;
52 | }
53 |
54 | public BarcodeAnalyser() {
55 | BarcodeScannerOptions options = new BarcodeScannerOptions.Builder()
56 | .setBarcodeFormats(Barcode.FORMAT_ALL_FORMATS)
57 | .build();
58 | barcodeScanner = BarcodeScanning.getClient(options);
59 | }
60 |
61 | public void setPreviewView(PreviewView mPreviewView) {
62 | this.mPreviewView = mPreviewView;
63 | }
64 |
65 | private Bitmap cropBitmap(Bitmap bitmap, int cropWidth, int cropHeight) {
66 | int w = bitmap.getWidth();
67 | int h = bitmap.getHeight();
68 | return Bitmap.createBitmap(bitmap, (w - cropWidth) / 2, (h - cropHeight) / 2, cropWidth, cropHeight, null, false);
69 | }
70 |
71 | @Override
72 | public void analyze(@NonNull final ImageProxy imageProxy) {
73 | Bitmap bitmap = null;
74 | try {
75 | bitmap = ImageUtils.imageProxyToBitmap(imageProxy, imageProxy.getImageInfo().getRotationDegrees());
76 | } catch (Exception e) {
77 | e.printStackTrace();
78 | }
79 | if (mPreviewView != null) {
80 | //bitmap转为16:9
81 | int height = mPreviewView.getHeight();
82 | int width = mPreviewView.getWidth();
83 | if (bitmap.getHeight() / (float) bitmap.getWidth() > mPreviewView.getHeight() / (float) mPreviewView.getWidth()) {
84 | int newHeight = bitmap.getWidth() * height / width;
85 | bitmap = cropBitmap(bitmap, bitmap.getWidth(), newHeight);
86 | } else if (bitmap.getHeight() / (float) bitmap.getWidth() < mPreviewView.getHeight() / (float) mPreviewView.getWidth()) {
87 | int newWith = bitmap.getHeight() * width / height;
88 | bitmap = cropBitmap(bitmap, newWith, bitmap.getHeight());
89 | }
90 | //大小控制和预览一样
91 | bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
92 | }
93 | InputImage inputImage = InputImage.fromBitmap(bitmap, 0);
94 | //InputImage inputImage = InputImage.fromMediaImage(imageProxy.getImage(), imageProxy.getImageInfo().getRotationDegrees());
95 | final Bitmap finalBitmap = bitmap;
96 | barcodeScanner.process(inputImage)
97 | .addOnSuccessListener(new OnSuccessListener>() {
98 | @Override
99 | public void onSuccess(@NonNull List barcodes) {
100 | if (barcodes.size() == 0) {
101 | return;
102 | }
103 | if (!isAnalyze) {
104 | return;
105 | }
106 | isAnalyze = false;
107 | for (Barcode barcode : barcodes) {
108 | Log.i("======", "barcode-getDisplayValue:" + barcode.getDisplayValue());
109 | Log.i("======", "barcode-getRawValue:" + barcode.getRawValue());
110 | }
111 | if (onCameraAnalyserCallback != null) {
112 | onCameraAnalyserCallback.onSuccess(finalBitmap, barcodes);
113 | }
114 | }
115 | })
116 | .addOnCompleteListener(new OnCompleteListener>() {
117 | @Override
118 | public void onComplete(@NonNull Task> task) {
119 | imageProxy.close();
120 | }
121 | })
122 | .addOnFailureListener(new OnFailureListener() {
123 | @Override
124 | public void onFailure(@NonNull Exception e) {
125 | Log.e("======", "onFailure---:" + e.toString());
126 | }
127 | });
128 | }
129 | }
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/callback/MNCustomViewBindCallback.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.callback;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * 自定义View回调
7 | */
8 | public interface MNCustomViewBindCallback {
9 |
10 | void onBindView(View customView);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/callback/OnCameraAnalyserCallback.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.callback;
2 |
3 | import android.graphics.Bitmap;
4 |
5 |
6 | import com.google.mlkit.vision.barcode.common.Barcode;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * @author : maning
12 | * @date : 8/19/21
13 | * @desc : 扫码分析结果回调
14 | */
15 | public interface OnCameraAnalyserCallback {
16 | void onSuccess(Bitmap bitmap, List barcodes);
17 | }
18 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/callback/act/ActResultRequest.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.callback.act;
2 |
3 | import android.app.Activity;
4 | import android.app.FragmentManager;
5 | import android.content.Intent;
6 |
7 | /**
8 | *
9 | * author : maning
10 | * e-mail : xxx@xx
11 | * time : 2018/06/04
12 | * desc :
13 | * version: 1.0
14 | *
15 | */
16 | public class ActResultRequest {
17 | private OnActResultEventDispatcherFragment fragment;
18 |
19 | public ActResultRequest(Activity activity) {
20 | fragment = getEventDispatchFragment(activity);
21 | }
22 |
23 | private OnActResultEventDispatcherFragment getEventDispatchFragment(Activity activity) {
24 | final FragmentManager fragmentManager = activity.getFragmentManager();
25 |
26 | OnActResultEventDispatcherFragment fragment = findEventDispatchFragment(fragmentManager);
27 | if (fragment == null) {
28 | fragment = new OnActResultEventDispatcherFragment();
29 | fragmentManager
30 | .beginTransaction()
31 | .add(fragment, OnActResultEventDispatcherFragment.TAG)
32 | .commitAllowingStateLoss();
33 | fragmentManager.executePendingTransactions();
34 | }
35 | return fragment;
36 | }
37 |
38 | private OnActResultEventDispatcherFragment findEventDispatchFragment(FragmentManager manager) {
39 | return (OnActResultEventDispatcherFragment) manager.findFragmentByTag(OnActResultEventDispatcherFragment.TAG);
40 | }
41 |
42 | public void startForResult(Intent intent, MNScanCallback callback) {
43 | fragment.startForResult(intent, callback);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/callback/act/MNScanCallback.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.callback.act;
2 |
3 | import android.content.Intent;
4 |
5 | /**
6 | *
7 | * author : maning
8 | * e-mail : xxx@xx
9 | * time : 2018/06/04
10 | * desc :
11 | * version: 1.0
12 | *
13 | */
14 | public interface MNScanCallback {
15 |
16 | void onActivityResult(int resultCode, Intent data);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/callback/act/OnActResultEventDispatcherFragment.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.callback.act;
2 |
3 | import android.app.Fragment;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.util.SparseArray;
7 |
8 | /**
9 | *
10 | * author : maning
11 | * e-mail : xxx@xx
12 | * time : 2018/06/04
13 | * desc :
14 | * version: 1.0
15 | *
16 | */
17 | public class OnActResultEventDispatcherFragment extends Fragment {
18 | public static final String TAG = "on_act_result_event_dispatcher";
19 |
20 | private SparseArray mCallbacks = new SparseArray<>();
21 |
22 | @Override
23 | public void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setRetainInstance(true);
26 | }
27 |
28 | public void startForResult(Intent intent, MNScanCallback callback) {
29 | mCallbacks.put(callback.hashCode(), callback);
30 | startActivityForResult(intent, callback.hashCode());
31 | }
32 |
33 | @Override
34 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
35 | super.onActivityResult(requestCode, resultCode, data);
36 |
37 | MNScanCallback callback = mCallbacks.get(requestCode);
38 | mCallbacks.remove(requestCode);
39 |
40 | if (callback != null) {
41 | callback.onActivityResult(resultCode, data);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/camera/CameraManager.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.camera;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.view.MotionEvent;
6 | import android.view.ScaleGestureDetector;
7 | import android.view.View;
8 |
9 | import androidx.camera.core.Camera;
10 | import androidx.camera.core.CameraSelector;
11 | import androidx.camera.core.FocusMeteringAction;
12 | import androidx.camera.core.ImageAnalysis;
13 | import androidx.camera.core.MeteringPoint;
14 | import androidx.camera.core.Preview;
15 | import androidx.camera.core.ZoomState;
16 | import androidx.camera.lifecycle.ProcessCameraProvider;
17 | import androidx.camera.view.PreviewView;
18 | import androidx.core.content.ContextCompat;
19 | import androidx.lifecycle.LifecycleOwner;
20 |
21 | import com.google.common.util.concurrent.ListenableFuture;
22 | import com.google.mlkit.vision.barcode.common.Barcode;
23 | import com.maning.mlkitscanner.scan.analyser.BarcodeAnalyser;
24 | import com.maning.mlkitscanner.scan.callback.OnCameraAnalyserCallback;
25 | import com.maning.mlkitscanner.scan.model.MNScanConfig;
26 | import com.maning.mlkitscanner.scan.utils.BeepManager;
27 |
28 | import java.util.List;
29 | import java.util.concurrent.Executors;
30 |
31 | /**
32 | * @author : maning
33 | * @date : 8/19/21
34 | * @desc :
35 | */
36 | public class CameraManager {
37 |
38 | private static final int HOVER_TAP_TIMEOUT = 150;
39 | private static final int HOVER_TAP_SLOP = 20;
40 |
41 | private ListenableFuture cameraProviderFuture;
42 | private LifecycleOwner mLifecycleOwner;
43 | private Camera mCamera;
44 | private long mLastHoveTapTime;
45 | private boolean isClickTap;
46 | private float mDownX;
47 | private float mDownY;
48 | private PreviewView mPreviewView;
49 | private Context mContext;
50 | private BarcodeAnalyser barcodeAnalyser;
51 | private OnCameraAnalyserCallback onCameraAnalyserCallback;
52 | private MNScanConfig scanConfig;
53 | private BeepManager beepManager;
54 |
55 | public static CameraManager getInstance(Context mContext, PreviewView mPreviewView) {
56 | return new CameraManager(mContext, mPreviewView);
57 | }
58 |
59 | public CameraManager(Context mContext, PreviewView mPreviewView) {
60 | this.mContext = mContext;
61 | this.mPreviewView = mPreviewView;
62 | initDatas();
63 | }
64 |
65 | public BarcodeAnalyser getBarcodeAnalyser() {
66 | return barcodeAnalyser;
67 | }
68 |
69 | public void setOnCameraAnalyserCallback(OnCameraAnalyserCallback callback) {
70 | this.onCameraAnalyserCallback = callback;
71 | }
72 |
73 | public void setScanConfig(MNScanConfig config) {
74 | scanConfig = config;
75 | beepManager.setPlayBeep(scanConfig.isShowBeep());
76 | beepManager.setVibrate(scanConfig.isShowVibrate());
77 | }
78 |
79 | public void setAnalyze(boolean analyze) {
80 | barcodeAnalyser.setAnalyze(analyze);
81 | }
82 |
83 | private void initDatas() {
84 | mLifecycleOwner = (LifecycleOwner) mContext;
85 | beepManager = new BeepManager(mContext);
86 | initBarcodeAnalyser();
87 | initScaleGesture();
88 | }
89 |
90 | public void startCamera() {
91 | cameraProviderFuture = ProcessCameraProvider.getInstance(mContext);
92 | cameraProviderFuture.addListener(new Runnable() {
93 | @Override
94 | public void run() {
95 | try {
96 | ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
97 | Preview preview = new Preview.Builder().build();
98 | //绑定预览
99 | preview.setSurfaceProvider(mPreviewView.getSurfaceProvider());
100 | //使用后置相机
101 | CameraSelector cameraSelector = new CameraSelector.Builder()
102 | .requireLensFacing(CameraSelector.LENS_FACING_BACK)
103 | .build();
104 | //配置图片扫描
105 | ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
106 | .setTargetResolution(CameraSizeUtils.getSize(mContext))
107 | .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
108 | .build();
109 | imageAnalysis.setAnalyzer(Executors.newSingleThreadExecutor(), barcodeAnalyser);
110 | if (mCamera != null) {
111 | cameraProviderFuture.get().unbindAll();
112 | }
113 | //将相机绑定到当前控件的生命周期
114 | mCamera = cameraProvider.bindToLifecycle(mLifecycleOwner, cameraSelector, imageAnalysis, preview);
115 | } catch (Exception e) {
116 | }
117 | }
118 | }, ContextCompat.getMainExecutor(mContext));
119 | }
120 |
121 | private void initBarcodeAnalyser() {
122 | barcodeAnalyser = new BarcodeAnalyser();
123 | barcodeAnalyser.setPreviewView(mPreviewView);
124 | barcodeAnalyser.setAnalyze(true);
125 | barcodeAnalyser.setOnCameraAnalyserCallback(new OnCameraAnalyserCallback() {
126 | @Override
127 | public void onSuccess(Bitmap bitmap, List barcodes) {
128 | beepManager.playBeepSoundAndVibrate();
129 | if (onCameraAnalyserCallback != null) {
130 | onCameraAnalyserCallback.onSuccess(bitmap, barcodes);
131 | }
132 | }
133 | });
134 | }
135 |
136 | private void initScaleGesture() {
137 | ScaleGestureDetector scaleGestureDetector = new ScaleGestureDetector(mContext, mOnScaleGestureListener);
138 | mPreviewView.setOnTouchListener(new View.OnTouchListener() {
139 | @Override
140 | public boolean onTouch(View view, MotionEvent event) {
141 | handlePreviewViewClickTap(event);
142 | if (scanConfig != null && scanConfig.isSupportZoom()) {
143 | return scaleGestureDetector.onTouchEvent(event);
144 | }
145 | return false;
146 | }
147 | });
148 | }
149 |
150 | private ScaleGestureDetector.OnScaleGestureListener mOnScaleGestureListener = new ScaleGestureDetector.SimpleOnScaleGestureListener() {
151 | @Override
152 | public boolean onScale(ScaleGestureDetector detector) {
153 | float scale = detector.getScaleFactor();
154 | if (mCamera != null) {
155 | float ratio = mCamera.getCameraInfo().getZoomState().getValue().getZoomRatio();
156 | zoomTo(ratio * scale);
157 | }
158 | return true;
159 | }
160 |
161 | };
162 |
163 | private void handlePreviewViewClickTap(MotionEvent event) {
164 | if (event.getPointerCount() == 1) {
165 | switch (event.getAction()) {
166 | case MotionEvent.ACTION_DOWN:
167 | isClickTap = true;
168 | mDownX = event.getX();
169 | mDownY = event.getY();
170 | mLastHoveTapTime = System.currentTimeMillis();
171 | break;
172 | case MotionEvent.ACTION_MOVE:
173 | isClickTap = distance(mDownX, mDownY, event.getX(), event.getY()) < HOVER_TAP_SLOP;
174 | break;
175 | case MotionEvent.ACTION_UP:
176 | if (isClickTap && mLastHoveTapTime + HOVER_TAP_TIMEOUT > System.currentTimeMillis()) {
177 | startFocusAndMetering(event.getX(), event.getY());
178 | }
179 | break;
180 | }
181 | }
182 | }
183 |
184 | private float distance(float aX, float aY, float bX, float bY) {
185 | float xDiff = aX - bX;
186 | float yDiff = aY - bY;
187 | return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff);
188 | }
189 |
190 | public void zoomTo(float ratio) {
191 | if (mCamera != null) {
192 | ZoomState zoomState = mCamera.getCameraInfo().getZoomState().getValue();
193 | float maxRatio = zoomState.getMaxZoomRatio();
194 | float minRatio = zoomState.getMinZoomRatio();
195 | float zoom = Math.max(Math.min(ratio, maxRatio), minRatio);
196 | mCamera.getCameraControl().setZoomRatio(zoom);
197 | }
198 | }
199 |
200 | private void startFocusAndMetering(float x, float y) {
201 | if (mCamera != null) {
202 | MeteringPoint point = mPreviewView.getMeteringPointFactory().createPoint(x, y);
203 | mCamera.getCameraControl().startFocusAndMetering(new FocusMeteringAction.Builder(point).build());
204 | }
205 | }
206 |
207 | public void openLight() {
208 | if (mCamera != null) {
209 | mCamera.getCameraControl().enableTorch(true);
210 | }
211 | }
212 |
213 | public void closeLight() {
214 | if (mCamera != null) {
215 | mCamera.getCameraControl().enableTorch(false);
216 | }
217 | }
218 |
219 | public void stopCamera() {
220 | try {
221 | if (cameraProviderFuture != null) {
222 | cameraProviderFuture.get().unbindAll();
223 | }
224 | } catch (Exception e) {
225 | }
226 | }
227 |
228 | public void release() {
229 | try {
230 | mPreviewView = null;
231 | mLifecycleOwner = null;
232 | stopCamera();
233 | } catch (Exception e) {
234 | }
235 | }
236 |
237 | }
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/camera/CameraSizeUtils.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.camera;
2 |
3 | import android.content.Context;
4 | import android.util.DisplayMetrics;
5 | import android.util.Log;
6 | import android.util.Size;
7 |
8 | /**
9 | * @author : maning
10 | * @date : 8/19/21
11 | * @desc :
12 | */
13 | public class CameraSizeUtils {
14 |
15 | public static Size getSize(Context context) {
16 | Size mTargetSize;
17 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
18 | int width = displayMetrics.widthPixels;
19 | int height = displayMetrics.heightPixels;
20 | Log.i("======", String.format("displayMetrics:%d x %d", width, height));
21 | //因为为了保持流畅性和性能,限制在1080p,在此前提下尽可能的找到屏幕接近的分辨率
22 | if (width < height) {
23 | int size = Math.min(width, 1080);
24 | float ratio = width / (float) height;
25 | if (ratio > 0.7) {//一般应用于平板
26 | mTargetSize = new Size(size, (int) (size / 3.0f * 4.0f));
27 | } else {
28 | mTargetSize = new Size(size, (int) (size / 9.0f * 16.0f));
29 | }
30 | } else {
31 | int size = Math.min(height, 1080);
32 | float ratio = height / (float) width;
33 | if (ratio > 0.7) {//一般应用于平板
34 | mTargetSize = new Size((int) (size / 3.0f * 4.0f), size);
35 | } else {
36 | mTargetSize = new Size((int) (size / 9.0f * 16.0), size);
37 | }
38 | }
39 | Log.i("======", "mTargetSize:" + mTargetSize.getWidth() + "," + mTargetSize.getHeight());
40 | return mTargetSize;
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/model/MNScanConfig.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.model;
2 |
3 |
4 | import com.maning.mlkitscanner.R;
5 | import com.maning.mlkitscanner.scan.callback.MNCustomViewBindCallback;
6 |
7 | import java.io.Serializable;
8 |
9 | /**
10 | * Created by maning on 2017/12/7.
11 | * 启动Activity的一些配置参数
12 | */
13 |
14 | public class MNScanConfig implements Serializable {
15 |
16 | private static final long serialVersionUID = -5260676142223049891L;
17 |
18 | public static MNCustomViewBindCallback mCustomViewBindCallback;
19 |
20 | //枚举类型:扫描线样式
21 | public enum LaserStyle {
22 | Line,
23 | Grid,
24 | }
25 |
26 | //是否显示相册
27 | private boolean showPhotoAlbum;
28 | //扫描声音
29 | private boolean showBeep;
30 | //扫描震动
31 | private boolean showVibrate;
32 | //扫描框和扫描线的颜色
33 | private String scanColor;
34 | //扫描线的样式
35 | private LaserStyle laserStyle;
36 | //扫描提示文案
37 | private String scanHintText;
38 | //扫描提示文案颜色
39 | private String scanHintTextColor;
40 | //扫描提示文案字体大小
41 | private int scanHintTextSize;
42 | //开启Activity动画
43 | private int activityOpenAnime;
44 | //关闭Activity动画
45 | private int activityExitAnime;
46 | //是否支持手势缩放,默认支持
47 | private boolean isSupportZoom = true;
48 | //自定义View
49 | private int customShadeViewLayoutID;
50 | //扫描背景色
51 | private String bgColor;
52 | //网格扫描线的列数
53 | private int gridScanLineColumn;
54 | //网格扫描线的高度
55 | private int gridScanLineHeight;
56 | //显示闪光灯
57 | private boolean showLightController = true;
58 | //是否需要全屏扫描,默认全屏扫描
59 | private boolean isFullScreenScan = true;
60 | //扫描二维码中心点宽高
61 | private int resultPointWithdHeight = 0;
62 | //扫描二维码中心点显示圆角
63 | private int resultPointCorners = 0;
64 | //扫描二维码中心点显示描边
65 | private int resultPointStrokeWidth = 0;
66 | //扫描二维码中心点显示描边颜色
67 | private String resultPointStrokeColor;
68 | //扫描二维码中心点显示颜色
69 | private String resultPointColor;
70 | //状态栏颜色
71 | private String statusBarColor = "#00000000";
72 | //状态栏是否显示黑色字体
73 | private boolean statusBarDarkMode = false;
74 | //扫描框宽度大小比例,非全屏模式下生效,默认0.7,范围0.5-0.9
75 | private float scanFrameSizeScale = 0.7f;
76 |
77 | private MNScanConfig() {
78 |
79 | }
80 |
81 |
82 | private MNScanConfig(Builder builder) {
83 | showPhotoAlbum = builder.showPhotoAlbum;
84 | showBeep = builder.showBeep;
85 | showVibrate = builder.showVibrate;
86 | scanColor = builder.scanColor;
87 | laserStyle = builder.laserStyle;
88 | scanHintText = builder.scanHintText;
89 | activityOpenAnime = builder.activityOpenAnime;
90 | activityExitAnime = builder.activityExitAnime;
91 | customShadeViewLayoutID = builder.customShadeViewLayoutID;
92 | bgColor = builder.bgColor;
93 | gridScanLineColumn = builder.gridScanLineColumn;
94 | gridScanLineHeight = builder.gridScanLineHeight;
95 | showLightController = builder.showLightController;
96 | scanHintTextColor = builder.scanHintTextColor;
97 | scanHintTextSize = builder.scanHintTextSize;
98 | isFullScreenScan = builder.isFullScreenScan;
99 | isSupportZoom = builder.isSupportZoom;
100 | resultPointWithdHeight = builder.resultPointWithdHeight;
101 | resultPointCorners = builder.resultPointCorners;
102 | resultPointStrokeWidth = builder.resultPointStrokeWidth;
103 | resultPointStrokeColor = builder.resultPointStrokeColor;
104 | resultPointColor = builder.resultPointColor;
105 | statusBarColor = builder.statusBarColor;
106 | statusBarDarkMode = builder.statusBarDarkMode;
107 | scanFrameSizeScale = builder.scanFrameSizeScale;
108 |
109 | }
110 |
111 | public String getStatusBarColor() {
112 | return statusBarColor;
113 | }
114 |
115 | public boolean isStatusBarDarkMode() {
116 | return statusBarDarkMode;
117 | }
118 |
119 | public int getResultPointWithdHeight() {
120 | return resultPointWithdHeight;
121 | }
122 |
123 | public int getResultPointCorners() {
124 | return resultPointCorners;
125 | }
126 |
127 | public int getResultPointStrokeWidth() {
128 | return resultPointStrokeWidth;
129 | }
130 |
131 | public String getResultPointStrokeColor() {
132 | return resultPointStrokeColor;
133 | }
134 |
135 | public String getResultPointColor() {
136 | return resultPointColor;
137 | }
138 |
139 | public boolean isShowPhotoAlbum() {
140 | return showPhotoAlbum;
141 | }
142 |
143 | public boolean isShowBeep() {
144 | return showBeep;
145 | }
146 |
147 | public boolean isShowVibrate() {
148 | return showVibrate;
149 | }
150 |
151 | public String getScanColor() {
152 | return scanColor;
153 | }
154 |
155 | public LaserStyle getLaserStyle() {
156 | return laserStyle;
157 | }
158 |
159 | public String getScanHintText() {
160 | return scanHintText;
161 | }
162 |
163 | public String getScanHintTextColor() {
164 | return scanHintTextColor;
165 | }
166 |
167 | public int getScanHintTextSize() {
168 | return scanHintTextSize;
169 | }
170 |
171 | public int getActivityOpenAnime() {
172 | return activityOpenAnime;
173 | }
174 |
175 | public int getActivityExitAnime() {
176 | return activityExitAnime;
177 | }
178 |
179 | public int getCustomShadeViewLayoutID() {
180 | return customShadeViewLayoutID;
181 | }
182 |
183 | public String getBgColor() {
184 | return bgColor;
185 | }
186 |
187 | public int getGridScanLineColumn() {
188 | return gridScanLineColumn;
189 | }
190 |
191 | public int getGridScanLineHeight() {
192 | return gridScanLineHeight;
193 | }
194 |
195 | public boolean isShowLightController() {
196 | return showLightController;
197 | }
198 |
199 | public boolean isFullScreenScan() {
200 | return isFullScreenScan;
201 | }
202 |
203 | public boolean isSupportZoom() {
204 | return isSupportZoom;
205 | }
206 |
207 | public float getScanFrameSizeScale() {
208 | if (scanFrameSizeScale > 0.9) {
209 | scanFrameSizeScale = 0.9f;
210 | }
211 | if (scanFrameSizeScale < 0.5) {
212 | scanFrameSizeScale = 0.5f;
213 | }
214 | return scanFrameSizeScale;
215 | }
216 |
217 | public static class Builder {
218 | private boolean showPhotoAlbum = true;
219 | private boolean showBeep = true;
220 | private boolean showVibrate = true;
221 | //扫描颜色
222 | private String scanColor;
223 | private String bgColor;
224 | private LaserStyle laserStyle = LaserStyle.Line;
225 | private int activityOpenAnime = R.anim.mn_scan_activity_bottom_in;
226 | private int activityExitAnime = R.anim.mn_scan_activity_bottom_out;
227 | private int customShadeViewLayoutID;
228 | //网格扫描线的列数
229 | private int gridScanLineColumn;
230 | //网格扫描线的高度
231 | private int gridScanLineHeight;
232 | //闪光灯
233 | private boolean showLightController = true;
234 | //扫描提示文案
235 | private String scanHintText = "扫二维码/条形码";
236 | //扫描提示文案颜色
237 | private String scanHintTextColor;
238 | //扫描提示文案字体大小
239 | private int scanHintTextSize;
240 | //是否需要全屏扫描,默认值扫描扫描框中的二维码
241 | private boolean isFullScreenScan = true;
242 | //是否支持手势缩放,默认支持
243 | private boolean isSupportZoom = true;
244 | //扫描二维码中心点显示半径
245 | private int resultPointWithdHeight = 0;
246 | //扫描二维码中心点显示圆角
247 | private int resultPointCorners = 0;
248 | //扫描二维码中心点显示描边
249 | private int resultPointStrokeWidth = 0;
250 | //扫描二维码中心点显示描边颜色
251 | private String resultPointStrokeColor;
252 | //扫描二维码中心点显示颜色
253 | private String resultPointColor;
254 | //状态栏颜色
255 | private String statusBarColor = "#00000000";
256 | //状态栏是否显示黑色字体
257 | private boolean statusBarDarkMode = false;
258 | //扫描框宽度大小比例,非全屏模式下生效,默认0.7,范围0.5-0.9
259 | private float scanFrameSizeScale = 0.7f;
260 |
261 | public MNScanConfig builder() {
262 | return new MNScanConfig(this);
263 | }
264 |
265 | public Builder setStatusBarConfigs(String statusBarColor,
266 | boolean statusBarDarkMode) {
267 | this.statusBarColor = statusBarColor;
268 | this.statusBarDarkMode = statusBarDarkMode;
269 | return this;
270 | }
271 |
272 | /**
273 | * 设置扫描点大小圆角等(单位dp)
274 | *
275 | * @param resultPointWithdHeight
276 | * @param resultPointCorners
277 | * @param resultPointStrokeWidth
278 | * @param resultPointStrokeColor
279 | * @param resultPointColor
280 | * @return
281 | */
282 | public Builder setResultPointConfigs(int resultPointWithdHeight,
283 | int resultPointCorners,
284 | int resultPointStrokeWidth,
285 | String resultPointStrokeColor,
286 | String resultPointColor) {
287 | this.resultPointWithdHeight = resultPointWithdHeight;
288 | this.resultPointCorners = resultPointCorners;
289 | this.resultPointStrokeWidth = resultPointStrokeWidth;
290 | this.resultPointStrokeColor = resultPointStrokeColor;
291 | this.resultPointColor = resultPointColor;
292 | return this;
293 | }
294 |
295 | public Builder setLaserStyle(LaserStyle laserStyle) {
296 | this.laserStyle = laserStyle;
297 | return this;
298 | }
299 |
300 | public Builder isShowPhotoAlbum(boolean showPhotoAlbum) {
301 | this.showPhotoAlbum = showPhotoAlbum;
302 | return this;
303 | }
304 |
305 | public Builder isShowBeep(boolean showBeep) {
306 | this.showBeep = showBeep;
307 | return this;
308 | }
309 |
310 | public Builder isShowVibrate(boolean showVibrate) {
311 | this.showVibrate = showVibrate;
312 | return this;
313 | }
314 |
315 | public Builder setScanColor(String scanColor) {
316 | this.scanColor = scanColor;
317 | return this;
318 | }
319 |
320 | public Builder setScanHintText(String scanHintText) {
321 | this.scanHintText = scanHintText;
322 | return this;
323 | }
324 |
325 | public Builder setActivityOpenAnime(int activityOpenAnime) {
326 | this.activityOpenAnime = activityOpenAnime;
327 | return this;
328 | }
329 |
330 | public Builder setActivityExitAnime(int activityExitAnime) {
331 | this.activityExitAnime = activityExitAnime;
332 | return this;
333 | }
334 |
335 | public Builder setCustomShadeViewLayoutID(int customShadeViewLayoutID, MNCustomViewBindCallback mnCustomViewBindCallback) {
336 | this.customShadeViewLayoutID = customShadeViewLayoutID;
337 | mCustomViewBindCallback = mnCustomViewBindCallback;
338 | return this;
339 | }
340 |
341 | public Builder setBgColor(String bgColor) {
342 | this.bgColor = bgColor;
343 | return this;
344 | }
345 |
346 | public Builder setGridScanLineColumn(int gridScanLineColumn) {
347 | this.gridScanLineColumn = gridScanLineColumn;
348 | return this;
349 | }
350 |
351 | public Builder setGridScanLineHeight(int gridScanLineHeight) {
352 | this.gridScanLineHeight = gridScanLineHeight;
353 | return this;
354 | }
355 |
356 | public Builder isShowLightController(boolean showLightController) {
357 | this.showLightController = showLightController;
358 | return this;
359 | }
360 |
361 | public Builder setScanHintTextColor(String scanHintTextColor) {
362 | this.scanHintTextColor = scanHintTextColor;
363 | return this;
364 | }
365 |
366 | public Builder setScanHintTextSize(int scanHintTextSize) {
367 | this.scanHintTextSize = scanHintTextSize;
368 | return this;
369 | }
370 |
371 | public Builder setFullScreenScan(boolean fullScreenScan) {
372 | isFullScreenScan = fullScreenScan;
373 | return this;
374 | }
375 |
376 | public Builder setSupportZoom(boolean supportZoom) {
377 | isSupportZoom = supportZoom;
378 | return this;
379 | }
380 |
381 | public Builder setScanFrameSizeScale(float widthScale) {
382 | scanFrameSizeScale = widthScale;
383 | return this;
384 | }
385 |
386 | }
387 |
388 | }
389 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/utils/AmbientLightManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Jenly, MLKit Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.maning.mlkitscanner.scan.utils;
17 |
18 | import android.content.Context;
19 | import android.hardware.Sensor;
20 | import android.hardware.SensorEvent;
21 | import android.hardware.SensorEventListener;
22 | import android.hardware.SensorManager;
23 |
24 | /**
25 | * @author Jenly
26 | */
27 | public class AmbientLightManager implements SensorEventListener {
28 |
29 | private static final int INTERVAL_TIME = 200;
30 |
31 | protected static final float DARK_LUX = 45.0f;
32 | protected static final float BRIGHT_LUX = 100.0f;
33 |
34 | /**
35 | * 光线太暗时,默认:照度45 lux
36 | */
37 | private float darkLightLux = DARK_LUX;
38 | /**
39 | * 光线足够亮时,默认:照度100 lux
40 | */
41 | private float brightLightLux = BRIGHT_LUX;
42 |
43 | private SensorManager sensorManager;
44 | private Sensor lightSensor;
45 |
46 | private long lastTime;
47 |
48 | private boolean isLightSensorEnabled;
49 |
50 | private OnLightSensorEventListener mOnLightSensorEventListener;
51 |
52 | public AmbientLightManager(Context context) {
53 | sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
54 | lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
55 | isLightSensorEnabled = true;
56 | }
57 |
58 | public void register() {
59 | if (sensorManager != null && lightSensor != null) {
60 | sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
61 | }
62 | }
63 |
64 | public void unregister() {
65 | if (sensorManager != null && lightSensor != null) {
66 | sensorManager.unregisterListener(this);
67 | }
68 | }
69 |
70 |
71 | @Override
72 | public void onSensorChanged(SensorEvent sensorEvent) {
73 | if(isLightSensorEnabled){
74 | long currentTime = System.currentTimeMillis();
75 | if(currentTime - lastTime < INTERVAL_TIME){//降低频率
76 | return;
77 | }
78 | lastTime = currentTime;
79 |
80 | if (mOnLightSensorEventListener != null) {
81 | float lightLux = sensorEvent.values[0];
82 | mOnLightSensorEventListener.onSensorChanged(lightLux);
83 | if (lightLux <= darkLightLux) {
84 | mOnLightSensorEventListener.onSensorChanged(true,lightLux);
85 | } else if (lightLux >= brightLightLux) {
86 | mOnLightSensorEventListener.onSensorChanged(false,lightLux);
87 | }
88 | }
89 | }
90 | }
91 |
92 | /**
93 | * 设置光线足够暗的阈值(单位:lux)
94 | * @param lightLux
95 | */
96 | public void setDarkLightLux(float lightLux){
97 | this.darkLightLux = lightLux;
98 | }
99 |
100 | /**
101 | * 设置光线足够明亮的阈值(单位:lux)
102 | * @param lightLux
103 | */
104 | public void setBrightLightLux(float lightLux){
105 | this.brightLightLux = lightLux;
106 | }
107 |
108 | @Override
109 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
110 | // do nothing
111 | }
112 |
113 | public boolean isLightSensorEnabled() {
114 | return isLightSensorEnabled;
115 | }
116 |
117 | /**
118 | * 设置是否启用光线亮度传感器
119 | * @param lightSensorEnabled
120 | */
121 | public void setLightSensorEnabled(boolean lightSensorEnabled) {
122 | isLightSensorEnabled = lightSensorEnabled;
123 | }
124 |
125 | /**
126 | * 设置光线亮度传感器监听器,只有在 {@link #isLightSensorEnabled} 为{@code true} 才有效
127 | * @param listener
128 | */
129 | public void setOnLightSensorEventListener(OnLightSensorEventListener listener){
130 | mOnLightSensorEventListener = listener;
131 | }
132 |
133 | public interface OnLightSensorEventListener{
134 | /**
135 | *
136 | * @param lightLux 当前检测到的光线照度值
137 | */
138 | default void onSensorChanged(float lightLux){
139 |
140 | }
141 |
142 | /**
143 | * 传感器改变事件
144 | * @param dark 是否太暗了,当检测到的光线照度值小于{@link #darkLightLux}时,为{@code true}
145 | * @param lightLux 当前检测到的光线照度值
146 | */
147 | void onSensorChanged(boolean dark, float lightLux);
148 | }
149 | }
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/utils/BeepManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Jenly, MLKit Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.maning.mlkitscanner.scan.utils;
17 |
18 | import android.content.Context;
19 | import android.content.res.AssetFileDescriptor;
20 | import android.media.AudioManager;
21 | import android.media.MediaPlayer;
22 | import android.os.Vibrator;
23 |
24 |
25 | import com.maning.mlkitscanner.R;
26 |
27 | import java.io.Closeable;
28 |
29 | /**
30 | * @author Jenly
31 | */
32 | public final class BeepManager implements MediaPlayer.OnErrorListener, Closeable {
33 |
34 | private static final long VIBRATE_DURATION = 200L;
35 |
36 | private final Context context;
37 | private MediaPlayer mediaPlayer;
38 | private Vibrator vibrator;
39 | private boolean playBeep;
40 | private boolean vibrate;
41 |
42 | public BeepManager(Context context) {
43 | this.context = context;
44 | this.mediaPlayer = null;
45 | updatePrefs();
46 | }
47 |
48 | public void setVibrate(boolean vibrate){
49 | this.vibrate = vibrate;
50 | }
51 |
52 | public void setPlayBeep(boolean playBeep){
53 | this.playBeep = playBeep;
54 | }
55 |
56 | private synchronized void updatePrefs() {
57 | if (mediaPlayer == null) {
58 | mediaPlayer = buildMediaPlayer(context);
59 | }
60 | if(vibrator == null){
61 | vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
62 | }
63 | }
64 |
65 | public synchronized void playBeepSoundAndVibrate() {
66 | if (playBeep && mediaPlayer != null) {
67 | mediaPlayer.start();
68 | }
69 | if (vibrate) {
70 | vibrator.vibrate(VIBRATE_DURATION);
71 | }
72 | }
73 |
74 | private MediaPlayer buildMediaPlayer(Context context) {
75 | MediaPlayer mediaPlayer = new MediaPlayer();
76 | try {
77 | AssetFileDescriptor file = context.getResources().openRawResourceFd(R.raw.mn_scan_beep);
78 | mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
79 | mediaPlayer.setOnErrorListener(this);
80 | mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
81 | mediaPlayer.setLooping(false);
82 | mediaPlayer.prepare();
83 | return mediaPlayer;
84 | } catch (Exception e) {
85 | mediaPlayer.release();
86 | return null;
87 | }
88 | }
89 |
90 | @Override
91 | public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
92 | close();
93 | updatePrefs();
94 | return true;
95 | }
96 |
97 | @Override
98 | public synchronized void close() {
99 | try{
100 | if (mediaPlayer != null) {
101 | mediaPlayer.release();
102 | mediaPlayer = null;
103 | }
104 | }catch (Exception e){
105 | }
106 | }
107 |
108 | }
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/utils/CommonUtils.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 | import android.util.DisplayMetrics;
7 | import android.view.WindowManager;
8 |
9 | /**
10 | * Created by maning on 2017/11/9.
11 | */
12 |
13 | public class CommonUtils {
14 | /**
15 | * 根据手机分辨率从DP转成PX
16 | *
17 | * @param context
18 | * @param dpValue
19 | * @return
20 | */
21 | public static int dip2px(Context context, float dpValue) {
22 | float scale = context.getResources().getDisplayMetrics().density;
23 | return (int) (dpValue * scale + 0.5f);
24 | }
25 |
26 | /**
27 | * 将sp值转换为px值,保证文字大小不变
28 | *
29 | * @param spValue
30 | * @return
31 | */
32 | public static int sp2px(Context context, float spValue) {
33 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
34 | return (int) (spValue * fontScale + 0.5f);
35 | }
36 |
37 | /**
38 | * 根据手机的分辨率PX(像素)转成DP
39 | *
40 | * @param context
41 | * @param pxValue
42 | * @return
43 | */
44 | public static int px2dip(Context context, float pxValue) {
45 | float scale = context.getResources().getDisplayMetrics().density;
46 | return (int) (pxValue / scale + 0.5f);
47 | }
48 |
49 | /**
50 | * 将px值转换为sp值,保证文字大小不变
51 | *
52 | * @param pxValue
53 | * @return
54 | */
55 |
56 | public static int px2sp(Context context, float pxValue) {
57 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
58 | return (int) (pxValue / fontScale + 0.5f);
59 | }
60 |
61 | public static int getScreenWidth(Context context) {
62 | try {
63 | final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
64 | final DisplayMetrics outMetrics = new DisplayMetrics();
65 | wm.getDefaultDisplay().getMetrics(outMetrics);
66 | return outMetrics.widthPixels;
67 | } catch (Exception e) {
68 | e.printStackTrace();
69 | }
70 |
71 | return 0;
72 | }
73 |
74 | public static int getTextWidth(String text, Paint paint){
75 | Rect rect = new Rect();
76 | paint.getTextBounds(text, 0, text.length(), rect);
77 | return rect.width();
78 | }
79 |
80 | public static int getTextHeight(String text, Paint paint){
81 | Rect rect = new Rect();
82 | paint.getTextBounds(text, 0, text.length(), rect);
83 | return rect.height();
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/utils/ImageUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Jenly, MLKit Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.maning.mlkitscanner.scan.utils;
17 |
18 | import android.content.Context;
19 | import android.graphics.Bitmap;
20 | import android.graphics.BitmapFactory;
21 | import android.graphics.ImageFormat;
22 | import android.graphics.Matrix;
23 | import android.graphics.Rect;
24 | import android.graphics.YuvImage;
25 | import android.net.Uri;
26 | import android.util.DisplayMetrics;
27 |
28 | import androidx.camera.core.ImageProxy;
29 |
30 | import java.io.ByteArrayOutputStream;
31 | import java.io.IOException;
32 | import java.io.InputStream;
33 | import java.nio.ByteBuffer;
34 |
35 | /**
36 | * @author Jenly
37 | */
38 | public class ImageUtils {
39 |
40 | private ImageUtils(){
41 | throw new AssertionError();
42 | }
43 |
44 | public static Bitmap imageProxyToBitmap(ImageProxy imageProxy) throws Exception {
45 | return imageProxyToBitmap(imageProxy,0);
46 | }
47 |
48 | public static Bitmap imageProxyToBitmap(ImageProxy imageProxy, int rotationDegrees) throws Exception {
49 | ImageProxy.PlaneProxy[] plane = imageProxy.getPlanes();
50 | ByteBuffer yBuffer = plane[0].getBuffer(); // Y
51 | ByteBuffer uBuffer = plane[1].getBuffer(); // U
52 | ByteBuffer vBuffer = plane[2].getBuffer(); // V
53 |
54 | int ySize = yBuffer.remaining();
55 | int uSize = uBuffer.remaining();
56 | int vSize = vBuffer.remaining();
57 |
58 | byte[] nv21 = new byte[ySize + uSize + vSize];
59 |
60 | //U and V are swapped
61 | yBuffer.get(nv21, 0, ySize);
62 | vBuffer.get(nv21, ySize, vSize);
63 | uBuffer.get(nv21, ySize + vSize, uSize);
64 |
65 | YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, imageProxy.getWidth(), imageProxy.getHeight(), null);
66 | ByteArrayOutputStream stream = new ByteArrayOutputStream(nv21.length);
67 | yuvImage.compressToJpeg(new Rect(0, 0, yuvImage.getWidth(), yuvImage.getHeight()), 90, stream);
68 |
69 | Bitmap bitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
70 | if(rotationDegrees != 0){
71 | Matrix matrix = new Matrix();
72 | matrix.postRotate(rotationDegrees);
73 | bitmap = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(), matrix, true);
74 | }
75 |
76 | return bitmap;
77 | }
78 |
79 | public static Bitmap getBitmap(Context context,Uri uri){
80 | InputStream Stream = null;
81 | InputStream inputStream = null;
82 | try {
83 | //根据uri获取图片的流
84 | inputStream = context.getContentResolver().openInputStream(uri);
85 | BitmapFactory.Options options = new BitmapFactory.Options();
86 | //options的in系列的设置了,injustdecodebouond只解析图片的大小,而不加载到内存中去
87 | options.inJustDecodeBounds = true;
88 | //1.如果通过options.outHeight获取图片的宽高,就必须通过decodestream解析同options赋值
89 | //否则options.outheight获取不到宽高
90 | BitmapFactory.decodeStream(inputStream,null,options);
91 | //2.通过 btm.getHeight()获取图片的宽高就不需要1的解析,我这里采取第一张方式
92 | // Bitmap btm = BitmapFactory.decodeStream(inputStream);
93 | //以屏幕的宽高进行压缩
94 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
95 | int heightPixels = displayMetrics.heightPixels;
96 | int widthPixels = displayMetrics.widthPixels;
97 | //获取图片的宽高
98 | int outHeight = options.outHeight;
99 | int outWidth = options.outWidth;
100 | //heightPixels就是要压缩后的图片高度,宽度也一样
101 | int a = (int) Math.ceil((outHeight/(float)heightPixels));
102 | int b = (int) Math.ceil(outWidth/(float)widthPixels);
103 | //比例计算,一般是图片比较大的情况下进行压缩
104 | int max = Math.max(a, b);
105 | if(max > 1){
106 | options.inSampleSize = max;
107 | }
108 | //解析到内存中去
109 | options.inJustDecodeBounds = false;
110 | // 根据uri重新获取流,inputstream在解析中发生改变了
111 | Stream = context.getContentResolver().openInputStream(uri);
112 | Bitmap bitmap = BitmapFactory.decodeStream(Stream, null, options);
113 | return bitmap;
114 | } catch (Exception e) {
115 | e.printStackTrace();
116 | }finally {
117 | try {
118 | if(inputStream != null) {
119 | inputStream.close();
120 | }
121 | if(Stream != null){
122 | Stream.close();
123 | }
124 | } catch (IOException e) {
125 | e.printStackTrace();
126 | }
127 |
128 | }
129 | return null;
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/utils/StatusBarUtil.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.utils;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.graphics.Color;
7 | import android.os.Build;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.view.Window;
12 | import android.view.WindowManager;
13 |
14 | import java.lang.ref.WeakReference;
15 | import java.lang.reflect.Field;
16 | import java.lang.reflect.Method;
17 | import java.util.regex.Pattern;
18 |
19 | /**
20 | * @author:created by leaf on 2019-05-07
21 | * Github地址:https://github.com/Ye-Miao
22 | * Desc: 状态栏工具类
23 | */
24 | public class StatusBarUtil {
25 |
26 | private static final int DEFAULT_ALPHA = 0;
27 |
28 | /**
29 | * 设置状态栏颜色(自定义颜色)
30 | *
31 | * @param activity 目标activity
32 | * @param color 状态栏颜色值
33 | */
34 | public static void setColor(Activity activity, int color) {
35 | WeakReference activityWeakReference = new WeakReference<>(activity);
36 | setColor(activityWeakReference.get(), color, DEFAULT_ALPHA);
37 | }
38 |
39 | /**
40 | * 设置纯色状态栏(自定义颜色,alpha)
41 | *
42 | * @param activity 目标activity
43 | * @param color 状态栏颜色值
44 | * @param alpha 状态栏透明度
45 | */
46 | public static void setColor(Activity activity, int color, int alpha) {
47 | WeakReference activityWeakReference = new WeakReference<>(activity);
48 | Window window = activityWeakReference.get().getWindow();
49 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
50 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
51 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
52 | window.setStatusBarColor(cipherColor(color, alpha));
53 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
54 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
55 | setTranslucentView((ViewGroup) window.getDecorView(), color, alpha);
56 | setRootView(activityWeakReference.get(), true);
57 | }
58 | }
59 |
60 | /**
61 | * 设置状态栏渐变颜色
62 | *
63 | * @param activity 目标activity
64 | * @param view 目标View
65 | */
66 | public static void setGradientColor(Activity activity, View view) {
67 | WeakReference activityWeakReference = new WeakReference<>(activity);
68 | ViewGroup decorView = (ViewGroup) activityWeakReference.get().getWindow().getDecorView();
69 | View fakeStatusBarView = decorView.findViewById(android.R.id.custom);
70 | if (fakeStatusBarView != null) {
71 | decorView.removeView(fakeStatusBarView);
72 | }
73 | setRootView(activityWeakReference.get(), false);
74 | setTransparentForWindow(activityWeakReference.get());
75 | setPaddingTop(activityWeakReference.get(), view);
76 | }
77 |
78 | /**
79 | * 设置透明状态栏
80 | *
81 | * @param activity 目标界面
82 | */
83 | public static void setTransparentForWindow(Activity activity) {
84 | WeakReference activityWeakReference = new WeakReference<>(activity);
85 | Window window = activityWeakReference.get().getWindow();
86 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
87 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
88 | window.setStatusBarColor(Color.TRANSPARENT);
89 | window.getDecorView()
90 | .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
91 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
92 | window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
93 | }
94 | }
95 |
96 | /**
97 | * 增加View的paddingTop,增加的值为状态栏高度 (智能判断,并设置高度)
98 | *
99 | * @param context 目标Context
100 | * @param view 需要增高的View
101 | */
102 | public static void setPaddingTop(Context context, View view) {
103 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
104 | ViewGroup.LayoutParams lp = view.getLayoutParams();
105 | if (lp != null && lp.height > 0 && view.getPaddingTop() == 0) {
106 | lp.height += getStatusBarHeight(context);
107 | view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
108 | view.getPaddingRight(), view.getPaddingBottom());
109 | }
110 | }
111 | }
112 |
113 |
114 | /**
115 | * 设置状态栏darkMode,字体颜色及icon变黑(目前支持MIUI6以上,Flyme4以上,Android M以上)
116 | *
117 | * @param activity 目标activity
118 | */
119 | public static void setDarkMode(Activity activity) {
120 | WeakReference activityWeakReference = new WeakReference<>(activity);
121 | darkMode(activityWeakReference.get().getWindow(), true);
122 | }
123 |
124 | /**
125 | * 设置状态栏darkMode,字体颜色及icon变亮(目前支持MIUI6以上,Flyme4以上,Android M以上)
126 | *
127 | * @param activity 目标activity
128 | */
129 | public static void setLightMode(Activity activity) {
130 | WeakReference activityWeakReference = new WeakReference<>(activity);
131 | darkMode(activityWeakReference.get().getWindow(), false);
132 | }
133 |
134 | @TargetApi(Build.VERSION_CODES.M)
135 | private static void darkMode(Window window, boolean dark) {
136 | if (isFlyme4()) {
137 | setModeForFlyme4(window, dark);
138 | } else if (isMIUI6()) {
139 | setModeForMIUI6(window, dark);
140 | }
141 | darkModeForM(window, dark);
142 | }
143 |
144 |
145 | /**
146 | * android 6.0设置字体颜色
147 | *
148 | * @param window 目标window
149 | * @param dark 亮色 or 暗色
150 | */
151 | private static void darkModeForM(Window window, boolean dark) {
152 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
153 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
154 | if (dark) {
155 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
156 | } else {
157 | systemUiVisibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
158 | }
159 | window.getDecorView().setSystemUiVisibility(systemUiVisibility);
160 | }
161 | }
162 |
163 |
164 | /**
165 | * 设置MIUI6+的状态栏的darkMode,darkMode时候字体颜色及icon
166 | * http://dev.xiaomi.com/doc/p=4769/
167 | *
168 | * @param window 目标window
169 | * @param dark 亮色 or 暗色
170 | */
171 | private static void setModeForMIUI6(Window window, boolean dark) {
172 | Class extends Window> clazz = window.getClass();
173 | try {
174 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
175 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
176 | int darkModeFlag = field.getInt(layoutParams);
177 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
178 | extraFlagField.invoke(window, dark ? darkModeFlag : 0, darkModeFlag);
179 | } catch (Exception e) {
180 | Log.e("StatusBar", "darkIcon: failed");
181 | }
182 |
183 | }
184 |
185 | /**
186 | * 设置Flyme4+的状态栏的darkMode,darkMode时候字体颜色及icon
187 | * http://open-wiki.flyme.cn/index.php?title=Flyme%E7%B3%BB%E7%BB%9FAPI
188 | *
189 | * @param window 目标window
190 | * @param dark 亮色 or 暗色
191 | */
192 | private static void setModeForFlyme4(Window window, boolean dark) {
193 | try {
194 | WindowManager.LayoutParams lp = window.getAttributes();
195 | Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
196 | Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
197 | darkFlag.setAccessible(true);
198 | meizuFlags.setAccessible(true);
199 | int bit = darkFlag.getInt(null);
200 | int value = meizuFlags.getInt(lp);
201 | if (dark) {
202 | value |= bit;
203 | } else {
204 | value &= ~bit;
205 | }
206 | meizuFlags.setInt(lp, value);
207 | window.setAttributes(lp);
208 | } catch (Exception e) {
209 | Log.e("StatusBar", "darkIcon: failed");
210 | }
211 | }
212 |
213 |
214 | /**
215 | * 判断是否Flyme4以上
216 | */
217 | private static boolean isFlyme4() {
218 | return Build.FINGERPRINT.contains("Flyme_OS_4") || Build.VERSION.INCREMENTAL.contains("Flyme_OS_4")
219 | || Pattern.compile("Flyme OS [4|5]", Pattern.CASE_INSENSITIVE).matcher(Build.DISPLAY).find();
220 | }
221 |
222 | /**
223 | * 判断是否MIUI6以上
224 | */
225 | private static boolean isMIUI6() {
226 | try {
227 | Class> clz = Class.forName("android.os.SystemProperties");
228 | Method mtd = clz.getMethod("get", String.class);
229 | String val = (String) mtd.invoke(null, "ro.miui.ui.version.name");
230 | val = val.replaceAll("[vV]", "");
231 | int version = Integer.parseInt(val);
232 | return version >= 6;
233 | } catch (Exception e) {
234 | return false;
235 | }
236 | }
237 |
238 | /**
239 | * 计算alpha色值
240 | *
241 | * @param color 状态栏颜色值
242 | * @param alpha 状态栏透明度
243 | */
244 | private static int cipherColor(int color, int alpha) {
245 | if (alpha == 0) {
246 | return color;
247 | }
248 | float a = 1 - alpha / 255f;
249 | int red = color >> 16 & 0xff;
250 | int green = color >> 8 & 0xff;
251 | int blue = color & 0xff;
252 | red = (int) (red * a + 0.5);
253 | green = (int) (green * a + 0.5);
254 | blue = (int) (blue * a + 0.5);
255 | return 0xff << 24 | red << 16 | green << 8 | blue;
256 | }
257 |
258 |
259 | /**
260 | * 创建透明View
261 | *
262 | * @param viewGroup 目标视图
263 | * @param color 状态栏颜色值
264 | * @param alpha 状态栏透明度
265 | */
266 | private static void setTranslucentView(ViewGroup viewGroup, int color, int alpha) {
267 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
268 | int cipherColor = cipherColor(color, alpha);
269 | View translucentView = viewGroup.findViewById(android.R.id.custom);
270 | if (translucentView == null && cipherColor != 0) {
271 | translucentView = new View(viewGroup.getContext());
272 | translucentView.setId(android.R.id.custom);
273 | ViewGroup.LayoutParams params =
274 | new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(viewGroup.getContext()));
275 | viewGroup.addView(translucentView, params);
276 | }
277 | if (translucentView != null) {
278 | translucentView.setBackgroundColor(cipherColor);
279 | }
280 | }
281 |
282 | }
283 |
284 | /**
285 | * 设置根布局参数
286 | *
287 | * @param activity 目标activity
288 | * @param fitSystemWindows 是否预留toolbar的高度
289 | */
290 | private static void setRootView(Activity activity, boolean fitSystemWindows) {
291 | WeakReference activityWeakReference = new WeakReference<>(activity);
292 | ViewGroup parent = activityWeakReference.get().findViewById(android.R.id.content);
293 | for (int i = 0, count = parent.getChildCount(); i < count; i++) {
294 | View childView = parent.getChildAt(i);
295 | if (childView instanceof ViewGroup) {
296 | childView.setFitsSystemWindows(fitSystemWindows);
297 | ((ViewGroup) childView).setClipToPadding(fitSystemWindows);
298 | }
299 | }
300 | }
301 |
302 | /**
303 | * 获取状态栏高度
304 | *
305 | * @param context 目标Context
306 | */
307 | public static int getStatusBarHeight(Context context) {
308 | // 获得状态栏高度
309 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
310 | return context.getResources().getDimensionPixelSize(resourceId);
311 | }
312 | }
313 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/utils/ZXingUtils.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.utils;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.Color;
6 | import android.graphics.Matrix;
7 | import android.text.TextUtils;
8 |
9 | import com.google.zxing.BarcodeFormat;
10 | import com.google.zxing.BinaryBitmap;
11 | import com.google.zxing.DecodeHintType;
12 | import com.google.zxing.EncodeHintType;
13 | import com.google.zxing.MultiFormatReader;
14 | import com.google.zxing.Result;
15 | import com.google.zxing.WriterException;
16 | import com.google.zxing.common.BitMatrix;
17 | import com.google.zxing.common.HybridBinarizer;
18 | import com.google.zxing.qrcode.QRCodeWriter;
19 | import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
20 |
21 | import java.io.UnsupportedEncodingException;
22 | import java.nio.charset.Charset;
23 | import java.util.ArrayList;
24 | import java.util.EnumMap;
25 | import java.util.Hashtable;
26 | import java.util.List;
27 | import java.util.Map;
28 |
29 | /**
30 | * Created by maning on 2017/11/10.
31 | */
32 |
33 | public class ZXingUtils {
34 |
35 | public static final Map HINTS = new EnumMap<>(DecodeHintType.class);
36 |
37 | static {
38 | List allFormats = new ArrayList<>();
39 | allFormats.add(BarcodeFormat.AZTEC);
40 | allFormats.add(BarcodeFormat.CODABAR);
41 | allFormats.add(BarcodeFormat.CODE_39);
42 | allFormats.add(BarcodeFormat.CODE_93);
43 | allFormats.add(BarcodeFormat.CODE_128);
44 | allFormats.add(BarcodeFormat.DATA_MATRIX);
45 | allFormats.add(BarcodeFormat.EAN_8);
46 | allFormats.add(BarcodeFormat.EAN_13);
47 | allFormats.add(BarcodeFormat.ITF);
48 | allFormats.add(BarcodeFormat.MAXICODE);
49 | allFormats.add(BarcodeFormat.PDF_417);
50 | allFormats.add(BarcodeFormat.QR_CODE);
51 | allFormats.add(BarcodeFormat.RSS_14);
52 | allFormats.add(BarcodeFormat.RSS_EXPANDED);
53 | allFormats.add(BarcodeFormat.UPC_A);
54 | allFormats.add(BarcodeFormat.UPC_E);
55 | allFormats.add(BarcodeFormat.UPC_EAN_EXTENSION);
56 |
57 | HINTS.put(DecodeHintType.POSSIBLE_FORMATS, allFormats);
58 | HINTS.put(DecodeHintType.CHARACTER_SET, "utf-8");
59 | }
60 |
61 | public static Bitmap createQRCodeImage(String content) {
62 | return createQRCodeImage(content, 500, 0, Color.BLACK, Color.WHITE, null, null, null);
63 | }
64 |
65 | public static Bitmap createQRCodeImage(String content, int size) {
66 | return createQRCodeImage(content, size, 0, Color.BLACK, Color.WHITE, null, null, null);
67 | }
68 |
69 | public static Bitmap createQRCodeImage(String content, int size, int margin) {
70 | return createQRCodeImage(content, size, margin, Color.BLACK, Color.WHITE, null, null, null);
71 | }
72 |
73 | public static Bitmap createQRCodeImage(String text, Bitmap logo_bitmap) {
74 | return createQRCodeImage(text, 500, 0, Color.BLACK, Color.WHITE, null, logo_bitmap, null);
75 | }
76 |
77 | public static Bitmap createQRCodeImage(String text, int size, Bitmap logo_bitmap) {
78 | return createQRCodeImage(text, size, 0, Color.BLACK, Color.WHITE, null, logo_bitmap, null);
79 | }
80 |
81 |
82 | public static Bitmap createQRCodeImage(String text, int size, int margin, Bitmap logo_bitmap) {
83 | return createQRCodeImage(text, size, margin, Color.BLACK, Color.WHITE, null, logo_bitmap, null);
84 | }
85 |
86 | /**
87 | * 生成带logo的二维码,logo默认为二维码的1/5
88 | *
89 | * @param text 需要生成二维码的内容
90 | * @param size 需要生成二维码的大小
91 | * @param margin 二维码边距
92 | * @param foreground_color 二维码前景色
93 | * @param background_color 二维码背景颜色
94 | * @param error_correction_level 容错率 L:7% M:15% Q:25% H:35%
95 | * @param logo_bitmap logo文件
96 | * @return bitmap
97 | */
98 | public static Bitmap createQRCodeImage(String text, int size, int margin, int foreground_color, int background_color, String error_correction_level, Bitmap logo_bitmap) {
99 | return createQRCodeImage(text, size, margin, foreground_color, background_color, error_correction_level, logo_bitmap, null);
100 | }
101 |
102 | /**
103 | * 生成带logo的二维码,logo默认为二维码的1/5
104 | *
105 | * @param text 需要生成二维码的内容
106 | * @param size 需要生成二维码的大小
107 | * @param margin 二维码边距
108 | * @param foreground_color 二维码前景色
109 | * @param background_color 二维码背景颜色
110 | * @param error_correction_level 容错率 L:7% M:15% Q:25% H:35%
111 | * @param logo_bitmap logo文件
112 | * @param logo_bitmap 二维码前景图片,不建议使用(可能太花识别率会降低)
113 | * @return bitmap
114 | */
115 | public static Bitmap createQRCodeImage(String text, int size, int margin, int foreground_color, int background_color, String error_correction_level, Bitmap logo_bitmap, Bitmap foreground_bitmap) {
116 | try {
117 | int IMAGE_HALFWIDTH = size / 10;
118 | Hashtable hints = new Hashtable<>();
119 | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
120 | hints.put(EncodeHintType.MARGIN, Math.max(margin, 0));
121 | /*
122 | * 设置容错级别,默认为ErrorCorrectionLevel.L
123 | * 因为中间加入logo所以建议你把容错级别调至H,否则可能会出现识别不了
124 | */
125 | if (TextUtils.isEmpty(error_correction_level)) {
126 | if (logo_bitmap != null) {
127 | hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
128 | } else {
129 | hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
130 | }
131 | } else {
132 | hints.put(EncodeHintType.ERROR_CORRECTION, error_correction_level);
133 | }
134 |
135 |
136 | BitMatrix bitMatrix = new QRCodeWriter().encode(text,
137 | BarcodeFormat.QR_CODE, size, size, hints);
138 |
139 | int width = bitMatrix.getWidth();
140 | int height = bitMatrix.getHeight();
141 | int halfW = width / 2;
142 | int halfH = height / 2;
143 |
144 | if (logo_bitmap != null) {
145 | Matrix m = new Matrix();
146 | float sx = (float) 2 * IMAGE_HALFWIDTH / logo_bitmap.getWidth();
147 | float sy = (float) 2 * IMAGE_HALFWIDTH / logo_bitmap.getHeight();
148 | m.setScale(sx, sy);
149 | //设置缩放信息
150 | //将logo图片按martix设置的信息缩放
151 | logo_bitmap = Bitmap.createBitmap(logo_bitmap, 0, 0,
152 | logo_bitmap.getWidth(), logo_bitmap.getHeight(), m, false);
153 | }
154 | if (foreground_bitmap != null) {
155 | //从当前位图按一定的比例创建一个新的位图
156 | foreground_bitmap = Bitmap.createScaledBitmap(foreground_bitmap, width, height, false);
157 | }
158 |
159 | int[] pixels = new int[size * size];
160 | for (int y = 0; y < size; y++) {
161 | for (int x = 0; x < size; x++) {
162 | if (logo_bitmap != null) {
163 | if (x > halfW - IMAGE_HALFWIDTH && x < halfW + IMAGE_HALFWIDTH
164 | && y > halfH - IMAGE_HALFWIDTH
165 | && y < halfH + IMAGE_HALFWIDTH) {
166 | //该位置用于存放图片信息
167 | //记录图片每个像素信息
168 | pixels[y * width + x] = logo_bitmap.getPixel(x - halfW
169 | + IMAGE_HALFWIDTH, y - halfH + IMAGE_HALFWIDTH);
170 | } else {
171 | if (bitMatrix.get(x, y)) {
172 | if (foreground_bitmap != null) {
173 | pixels[y * width + x] = foreground_bitmap.getPixel(x, y);
174 | } else {
175 | pixels[y * width + x] = foreground_color;
176 | }
177 | } else {
178 | pixels[y * size + x] = background_color;
179 | }
180 | }
181 | } else {
182 | if (bitMatrix.get(x, y)) {
183 | if (foreground_bitmap != null) {
184 | pixels[y * width + x] = foreground_bitmap.getPixel(x, y);
185 | } else {
186 | pixels[y * width + x] = foreground_color;
187 | }
188 | } else {
189 | pixels[y * size + x] = background_color;
190 | }
191 | }
192 |
193 | }
194 | }
195 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
196 | bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
197 | return bitmap;
198 | } catch (WriterException e) {
199 | e.printStackTrace();
200 | return null;
201 | }
202 | }
203 |
204 |
205 | //------解析图片-----
206 |
207 | /**
208 | * 同步解析本地图片二维码。该方法是耗时操作,请在子线程中调用。
209 | *
210 | * @param picturePath 要解析的二维码图片本地路径
211 | * @return 返回二维码图片里的内容 或 null
212 | */
213 | public static String syncDecodeQRCode(String picturePath) {
214 | return syncDecodeQRCode(getDecodeAbleBitmap(picturePath));
215 | }
216 |
217 | /**
218 | * 同步解析bitmap二维码。该方法是耗时操作,请在子线程中调用。
219 | *
220 | * @param bitmap 要解析的二维码图片
221 | * @return 返回二维码图片里的内容 或 null
222 | */
223 | public static String syncDecodeQRCode(Bitmap bitmap) {
224 | try {
225 | int width = bitmap.getWidth();
226 | int height = bitmap.getHeight();
227 | int[] pixels = new int[width * height];
228 | bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
229 | com.google.zxing.RGBLuminanceSource source = new com.google.zxing.RGBLuminanceSource(width, height, pixels);
230 | Result result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source)), HINTS);
231 | if (result != null) {
232 | return recode(result.getText());
233 | } else {
234 | return null;
235 | }
236 | } catch (Exception e) {
237 | return null;
238 | }
239 | }
240 |
241 | /**
242 | * 将本地图片文件转换成可解码二维码的 Bitmap
243 | *
244 | * @param picturePath 本地图片文件路径
245 | * @return
246 | */
247 | private static Bitmap getDecodeAbleBitmap(String picturePath) {
248 | try {
249 | BitmapFactory.Options options = new BitmapFactory.Options();
250 | options.inJustDecodeBounds = true;
251 | BitmapFactory.decodeFile(picturePath, options);
252 | int sampleSize = options.outHeight / 400;
253 | if (sampleSize <= 0) {
254 | sampleSize = 1;
255 | }
256 | options.inSampleSize = sampleSize;
257 | options.inJustDecodeBounds = false;
258 |
259 | return BitmapFactory.decodeFile(picturePath, options);
260 | } catch (Exception e) {
261 | e.printStackTrace();
262 | return null;
263 | }
264 | }
265 |
266 | /**
267 | * 中文乱码
268 | *
269 | * @return
270 | */
271 | public static String recode(String str) {
272 | String formart = "";
273 | try {
274 | boolean ISO = Charset.forName("ISO-8859-1").newEncoder()
275 | .canEncode(str);
276 | if (ISO) {
277 | formart = new String(str.getBytes("ISO-8859-1"), "GB2312");
278 | } else {
279 | formart = str;
280 | }
281 | } catch (UnsupportedEncodingException e) {
282 | e.printStackTrace();
283 | }
284 | return formart;
285 | }
286 |
287 | }
288 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/view/ScanActionMenuView.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.widget.FrameLayout;
8 | import android.widget.ImageView;
9 | import android.widget.LinearLayout;
10 | import android.widget.RelativeLayout;
11 | import android.widget.TextView;
12 |
13 | import com.maning.mlkitscanner.R;
14 | import com.maning.mlkitscanner.scan.callback.MNCustomViewBindCallback;
15 | import com.maning.mlkitscanner.scan.model.MNScanConfig;
16 |
17 |
18 | /**
19 | * @author : maning
20 | * @date : 2020-09-04
21 | * @desc :
22 | */
23 | public class ScanActionMenuView extends FrameLayout {
24 |
25 | private LinearLayout btn_scan_light;
26 | private ImageView iv_scan_light;
27 | private TextView tv_scan_light;
28 | private LinearLayout btn_close;
29 | private LinearLayout btn_photo;
30 |
31 | private RelativeLayout rl_default_menu;
32 | private LinearLayout ll_custom_view;
33 |
34 | private OnScanActionMenuListener onScanActionMenuListener;
35 |
36 | public interface OnScanActionMenuListener {
37 | void onClose();
38 |
39 | void onLight();
40 |
41 | void onPhoto();
42 | }
43 |
44 | public void setOnScanActionMenuListener(OnScanActionMenuListener onScanActionMenuListener) {
45 | this.onScanActionMenuListener = onScanActionMenuListener;
46 | }
47 |
48 |
49 | public ScanActionMenuView(Context context) {
50 | this(context, null);
51 | }
52 |
53 | public ScanActionMenuView(Context context, AttributeSet attrs) {
54 | this(context, attrs, 0);
55 | }
56 |
57 | public ScanActionMenuView(Context context, AttributeSet attrs, int defStyleAttr) {
58 | super(context, attrs, defStyleAttr);
59 | initView();
60 | }
61 |
62 | private void initView() {
63 | //绑定
64 | LayoutInflater.from(getContext()).inflate(R.layout.mn_scan_action_menu, this);
65 |
66 | btn_scan_light = (LinearLayout) findViewById(R.id.btn_scan_light);
67 | iv_scan_light = (ImageView) findViewById(R.id.iv_scan_light);
68 | tv_scan_light = (TextView) findViewById(R.id.tv_scan_light);
69 | btn_close = (LinearLayout) findViewById(R.id.btn_close);
70 | btn_photo = (LinearLayout) findViewById(R.id.btn_photo);
71 | rl_default_menu = (RelativeLayout) findViewById(R.id.rl_default_menu);
72 | ll_custom_view = (LinearLayout) findViewById(R.id.ll_custom_view);
73 |
74 | rl_default_menu.setVisibility(View.GONE);
75 | ll_custom_view.setVisibility(View.GONE);
76 |
77 | //点击事件
78 | btn_scan_light.setOnClickListener(new OnClickListener() {
79 | @Override
80 | public void onClick(View v) {
81 | if (onScanActionMenuListener != null) {
82 | onScanActionMenuListener.onLight();
83 | }
84 | }
85 | });
86 |
87 | btn_close.setOnClickListener(new OnClickListener() {
88 | @Override
89 | public void onClick(View v) {
90 | if (onScanActionMenuListener != null) {
91 | onScanActionMenuListener.onClose();
92 | }
93 | }
94 | });
95 | btn_photo.setOnClickListener(new OnClickListener() {
96 | @Override
97 | public void onClick(View v) {
98 | if (onScanActionMenuListener != null) {
99 | onScanActionMenuListener.onPhoto();
100 | }
101 | }
102 | });
103 |
104 | }
105 |
106 | private MNScanConfig scanConfig;
107 |
108 | public void setScanConfig(MNScanConfig config, MNCustomViewBindCallback customViewBindCallback) {
109 | this.scanConfig = config;
110 |
111 | //自定义View
112 | int customShadeViewLayoutID = scanConfig.getCustomShadeViewLayoutID();
113 | if (customShadeViewLayoutID > 0 && customViewBindCallback != null) {
114 | //显示出来
115 | ll_custom_view.setVisibility(View.VISIBLE);
116 | View customView = LayoutInflater.from(getContext()).inflate(customShadeViewLayoutID, null);
117 | ll_custom_view.addView(customView);
118 | //事件绑定
119 | customViewBindCallback.onBindView(customView);
120 | } else {
121 | rl_default_menu.setVisibility(View.VISIBLE);
122 | }
123 |
124 | //闪光灯配置
125 | boolean showLightController = scanConfig.isShowLightController();
126 | if (showLightController) {
127 | btn_scan_light.setVisibility(View.VISIBLE);
128 | } else {
129 | btn_scan_light.setVisibility(View.GONE);
130 | }
131 | //其他配置
132 | if (!scanConfig.isShowPhotoAlbum()) {
133 | btn_photo.setVisibility(View.GONE);
134 | }
135 | }
136 |
137 | public void openLight() {
138 | iv_scan_light.setImageResource(R.drawable.mn_icon_scan_flash_light_on);
139 | tv_scan_light.setText("关闭手电筒");
140 | }
141 |
142 | public void closeLight() {
143 | iv_scan_light.setImageResource(R.drawable.mn_icon_scan_flash_light_off);
144 | tv_scan_light.setText("打开手电筒");
145 | }
146 |
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/java/com/maning/mlkitscanner/scan/view/ScanResultPointView.java:
--------------------------------------------------------------------------------
1 | package com.maning.mlkitscanner.scan.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Color;
6 | import android.graphics.Rect;
7 | import android.graphics.drawable.GradientDrawable;
8 | import android.os.Build;
9 | import android.text.TextUtils;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.FrameLayout;
16 | import android.widget.ImageView;
17 | import android.widget.RelativeLayout;
18 | import android.widget.TextView;
19 |
20 | import com.google.mlkit.vision.barcode.common.Barcode;
21 | import com.maning.mlkitscanner.R;
22 | import com.maning.mlkitscanner.scan.model.MNScanConfig;
23 | import com.maning.mlkitscanner.scan.utils.CommonUtils;
24 | import com.maning.mlkitscanner.scan.utils.StatusBarUtil;
25 |
26 | import java.util.List;
27 |
28 | import static android.graphics.drawable.GradientDrawable.RECTANGLE;
29 |
30 | /**
31 | * @author : maning
32 | * @date : 2021/1/7
33 | * @desc : 扫描结果点View展示
34 | */
35 | public class ScanResultPointView extends FrameLayout {
36 |
37 | private MNScanConfig scanConfig;
38 | private List resultPoint;
39 | private OnResultPointClickListener onResultPointClickListener;
40 |
41 | private int resultPointColor;
42 | private int resultPointStrokeColor;
43 | private int resultPointWithdHeight;
44 | private int resultPointRadiusCorners;
45 | private int resultPointStrokeWidth;
46 | private TextView tv_cancle;
47 | private FrameLayout fl_result_point_root;
48 | private View fakeStatusBar;
49 | private int statusBarHeight;
50 | private ImageView iv_show_result;
51 | private Bitmap barcodeBitmap;
52 |
53 | public void setOnResultPointClickListener(OnResultPointClickListener onResultPointClickListener) {
54 | this.onResultPointClickListener = onResultPointClickListener;
55 | }
56 |
57 | public interface OnResultPointClickListener {
58 | void onPointClick(String result);
59 |
60 | void onCancle();
61 | }
62 |
63 | public ScanResultPointView(Context context) {
64 | this(context, null);
65 | }
66 |
67 | public ScanResultPointView(Context context, AttributeSet attrs) {
68 | this(context, attrs, 0);
69 | }
70 |
71 | public ScanResultPointView(Context context, AttributeSet attrs, int defStyleAttr) {
72 | super(context, attrs, defStyleAttr);
73 | initView();
74 | }
75 |
76 | private void initView() {
77 | View view = LayoutInflater.from(getContext()).inflate(R.layout.mn_scan_result_point_view, this);
78 | fakeStatusBar = view.findViewById(R.id.fakeStatusBar2);
79 | iv_show_result = view.findViewById(R.id.iv_show_result);
80 | tv_cancle = view.findViewById(R.id.tv_cancle);
81 | fl_result_point_root = view.findViewById(R.id.fl_result_point_root);
82 |
83 | statusBarHeight = StatusBarUtil.getStatusBarHeight(getContext());
84 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
85 | ViewGroup.LayoutParams fakeStatusBarLayoutParams = fakeStatusBar.getLayoutParams();
86 | fakeStatusBarLayoutParams.height = statusBarHeight;
87 | fakeStatusBar.setLayoutParams(fakeStatusBarLayoutParams);
88 | }
89 |
90 | tv_cancle.setOnClickListener(new OnClickListener() {
91 | @Override
92 | public void onClick(View v) {
93 | //隐藏View
94 | if (onResultPointClickListener != null) {
95 | onResultPointClickListener.onCancle();
96 | }
97 | removeAllPoints();
98 | }
99 | });
100 | iv_show_result.setOnClickListener(new OnClickListener() {
101 | @Override
102 | public void onClick(View v) {
103 | //拦截点击事件
104 | }
105 | });
106 | }
107 |
108 | public void setScanConfig(MNScanConfig config) {
109 | scanConfig = config;
110 | initResultPointConfigs();
111 | }
112 |
113 | private void initResultPointConfigs() {
114 | if (scanConfig == null) {
115 | return;
116 | }
117 | resultPointRadiusCorners = CommonUtils.dip2px(getContext(), scanConfig.getResultPointCorners());
118 | resultPointWithdHeight = CommonUtils.dip2px(getContext(), scanConfig.getResultPointWithdHeight());
119 | resultPointStrokeWidth = CommonUtils.dip2px(getContext(), scanConfig.getResultPointStrokeWidth());
120 | String resultPointColorStr = scanConfig.getResultPointColor();
121 | String resultPointStrokeColorStr = scanConfig.getResultPointStrokeColor();
122 | if (resultPointWithdHeight == 0) {
123 | resultPointWithdHeight = CommonUtils.dip2px(getContext(), 36);
124 | }
125 | if (resultPointRadiusCorners == 0) {
126 | resultPointRadiusCorners = CommonUtils.dip2px(getContext(), 36);
127 | }
128 | if (resultPointStrokeWidth == 0) {
129 | resultPointStrokeWidth = CommonUtils.dip2px(getContext(), 3);
130 | }
131 | if (!TextUtils.isEmpty(resultPointColorStr)) {
132 | resultPointColor = Color.parseColor(resultPointColorStr);
133 | } else {
134 | resultPointColor = getContext().getResources().getColor(R.color.mn_scan_viewfinder_laser_result_point);
135 | }
136 | if (!TextUtils.isEmpty(resultPointStrokeColorStr)) {
137 | resultPointStrokeColor = Color.parseColor(resultPointStrokeColorStr);
138 | } else {
139 | resultPointStrokeColor = getContext().getResources().getColor(R.color.mn_scan_viewfinder_laser_result_point_border);
140 | }
141 | }
142 |
143 | public void setDatas(List results, Bitmap barcode) {
144 | this.resultPoint = results;
145 | this.barcodeBitmap = barcode;
146 | drawableResultPoint();
147 | }
148 |
149 | public void removeAllPoints() {
150 | fl_result_point_root.removeAllViews();
151 | }
152 |
153 | private void drawableResultPoint() {
154 | Log.e(">>>>>>", "drawableResultPoint---start");
155 | iv_show_result.setImageBitmap(barcodeBitmap);
156 | removeAllPoints();
157 | if (resultPoint == null || resultPoint.size() == 0) {
158 | if (onResultPointClickListener != null) {
159 | onResultPointClickListener.onCancle();
160 | }
161 | return;
162 | }
163 | if (scanConfig == null) {
164 | scanConfig = new MNScanConfig.Builder().builder();
165 | }
166 | if (resultPoint.size() == 1) {
167 | tv_cancle.setVisibility(View.INVISIBLE);
168 | } else {
169 | tv_cancle.setVisibility(View.VISIBLE);
170 | }
171 |
172 | for (int j = 0; j < resultPoint.size(); j++) {
173 | Barcode barcode = resultPoint.get(j);
174 | Rect boundingBox = barcode.getBoundingBox();
175 | int centerX = boundingBox.centerX();
176 | int centerY = boundingBox.centerY();
177 |
178 | View inflate = LayoutInflater.from(getContext()).inflate(R.layout.mn_scan_result_point_item_view, null);
179 | RelativeLayout rl_root = inflate.findViewById(R.id.rl_root);
180 | ImageView iv_point_bg = inflate.findViewById(R.id.iv_point_bg);
181 | ImageView iv_point_arrow = inflate.findViewById(R.id.iv_point_arrow);
182 |
183 | //位置
184 | RelativeLayout.LayoutParams lpRoot = new RelativeLayout.LayoutParams(resultPointWithdHeight, resultPointWithdHeight);
185 | rl_root.setLayoutParams(lpRoot);
186 |
187 | rl_root.setX(centerX - resultPointWithdHeight / 2.0f);
188 | rl_root.setY(centerY - resultPointWithdHeight / 2.0f);
189 |
190 | GradientDrawable gradientDrawable = new GradientDrawable();
191 | gradientDrawable.setCornerRadius(resultPointRadiusCorners);
192 | gradientDrawable.setShape(RECTANGLE);
193 | gradientDrawable.setStroke(resultPointStrokeWidth, resultPointStrokeColor);
194 | gradientDrawable.setColor(resultPointColor);
195 |
196 | iv_point_bg.setImageDrawable(gradientDrawable);
197 |
198 | //点的大小
199 | ViewGroup.LayoutParams lpPoint = iv_point_bg.getLayoutParams();
200 | lpPoint.width = resultPointWithdHeight;
201 | lpPoint.height = resultPointWithdHeight;
202 | iv_point_bg.setLayoutParams(lpPoint);
203 |
204 | //箭头大小
205 | if (resultPoint.size() > 1) {
206 | ViewGroup.LayoutParams lpArrow = iv_point_arrow.getLayoutParams();
207 | lpArrow.width = resultPointWithdHeight / 2;
208 | lpArrow.height = resultPointWithdHeight / 2;
209 | iv_point_arrow.setLayoutParams(lpArrow);
210 | iv_point_arrow.setVisibility(View.VISIBLE);
211 | } else {
212 | //一个不需要箭头
213 | iv_point_arrow.setVisibility(View.GONE);
214 | }
215 |
216 | iv_point_bg.setOnClickListener(new OnClickListener() {
217 | @Override
218 | public void onClick(View v) {
219 | if (onResultPointClickListener != null) {
220 | onResultPointClickListener.onPointClick(barcode.getDisplayValue());
221 | }
222 | }
223 | });
224 |
225 | fl_result_point_root.addView(inflate);
226 | }
227 | int childCount = fl_result_point_root.getChildCount();
228 | Log.e(">>>>>>", "fl_result_point_root---childCount:" + childCount);
229 | if (childCount <= 0) {
230 | //关闭页面
231 | if (onResultPointClickListener != null) {
232 | onResultPointClickListener.onCancle();
233 | }
234 | }
235 | Log.e(">>>>>>", "drawableResultPoint---end");
236 | }
237 |
238 | }
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/anim/mn_scan_activity_bottom_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/anim/mn_scan_activity_bottom_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_close.png
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_default_result_point_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_default_result_point_arrow.png
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_flash_light_off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_flash_light_off.png
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_flash_light_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_flash_light_on.png
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_icon_scan_photo.png
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_scan_icon_thumb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_scan_icon_thumb.png
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_scan_icon_zoom_in.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_scan_icon_zoom_in.png
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_scan_icon_zoom_out.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/src/main/res/drawable-xxhdpi/mn_scan_icon_zoom_out.png
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/drawable/mn_scan_result_point_default.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/layout/mn_scan_action_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
15 |
19 |
20 |
29 |
30 |
35 |
36 |
44 |
45 |
46 |
47 |
54 |
55 |
60 |
61 |
62 |
63 |
71 |
72 |
77 |
78 |
79 |
80 |
81 |
82 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/layout/mn_scan_activity_scan_preview.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
19 |
20 |
24 |
25 |
31 |
32 |
33 |
37 |
38 |
39 |
40 |
46 |
47 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/layout/mn_scan_result_point_item_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
22 |
23 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/layout/mn_scan_result_point_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
25 |
26 |
32 |
33 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/raw/mn_scan_beep.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/mlkit-scanner/src/main/res/raw/mn_scan_beep.ogg
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFff3535
4 | #80000000
5 | #CCFF3535
6 | #FFFFFFFF
7 |
--------------------------------------------------------------------------------
/mlkit-scanner/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
17 |
18 |
25 |
26 |
--------------------------------------------------------------------------------
/screenshots/mn_mlkit_scanner_ss_01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/screenshots/mn_mlkit_scanner_ss_01.jpg
--------------------------------------------------------------------------------
/screenshots/mn_mlkit_scanner_ss_02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/screenshots/mn_mlkit_scanner_ss_02.jpg
--------------------------------------------------------------------------------
/screenshots/mn_mlkit_scanner_ss_03.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/screenshots/mn_mlkit_scanner_ss_03.jpg
--------------------------------------------------------------------------------
/screenshots/mn_mlkit_scanner_ss_04.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/screenshots/mn_mlkit_scanner_ss_04.jpg
--------------------------------------------------------------------------------
/screenshots/mn_mlkit_scanner_ss_05.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maning0303/MNMLKitScanner/05fc2a8129f5eb78ef847d9a54280e0b3552d8b8/screenshots/mn_mlkit_scanner_ss_05.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':mlkit-scanner'
2 | include ':app'
3 | rootProject.name = "MNMLKitScanner"
--------------------------------------------------------------------------------