1313import me .devilsen .czxing .view .ScanActivityDelegate ;
1414
1515/**
16- * desc :
16+ * desc : 扫码API管理
1717 * date : 2019/07/31
1818 *
1919 * @author : dongsen
@@ -28,101 +28,214 @@ public class ScannerManager {
2828 scanOption = new ScanOption ();
2929 }
3030
31+ /**
32+ * 扫码框角颜色
33+ *
34+ * @param cornerColor 色值
35+ */
3136 public ScannerManager setCornerColor (int cornerColor ) {
3237 scanOption .cornerColor = cornerColor ;
3338 return this ;
3439 }
3540
41+ /**
42+ * 设置扫码框颜色
43+ *
44+ * @param borderColor 色值
45+ */
3646 public ScannerManager setBorderColor (int borderColor ) {
3747 scanOption .borderColor = borderColor ;
3848 return this ;
3949 }
4050
51+ /**
52+ * 设置扫码框四周颜色
53+ *
54+ * @param maskColor 色值
55+ */
56+ public ScannerManager setMaskColor (int maskColor ) {
57+ scanOption .maskColor = maskColor ;
58+ return this ;
59+ }
60+
61+ /**
62+ * 设置边框长度(扫码框大小)
63+ *
64+ * @param borderSize px
65+ */
4166 public ScannerManager setBorderSize (int borderSize ) {
4267 scanOption .borderSize = borderSize ;
4368 return this ;
4469 }
4570
71+ /**
72+ * 扫描模式,提供了三种扫码模式
73+ * ┏--------------┓
74+ * ┃ ┃
75+ * ┃ 2 ┃
76+ * ┃ ┏----┓ ┃
77+ * ┃ ┃ 1 ┃ ┃
78+ * ┃ ┗----┛ ┃
79+ * ┃ ┃
80+ * ┃ ┃
81+ * ┃ ┃
82+ * ┃ ┃
83+ * ┗--------------┛
84+ * <p>
85+ * 0:混合扫描模式(默认),扫描4次扫码框里的内容,扫描1次以屏幕宽为边长的内容
86+ * 1:只扫描扫码框里的内容
87+ * 2:扫描以屏幕宽为边长的内容
88+ *
89+ * @param scanMode 0 / 1 / 2
90+ */
4691 public ScannerManager setScanMode (int scanMode ) {
4792 scanOption .scanMode = scanMode ;
4893 return this ;
4994 }
5095
96+ /**
97+ * 设置扫码界面标题
98+ *
99+ * @param title 标题内容
100+ */
51101 public ScannerManager setTitle (String title ) {
52102 scanOption .title = title ;
53103 return this ;
54104 }
55105
106+ /**
107+ * 显示从图库选取图片按钮
108+ *
109+ * @param showAlbum true:显示 false:隐藏
110+ */
56111 public ScannerManager showAlbum (boolean showAlbum ) {
57112 scanOption .showAlbum = showAlbum ;
58113 return this ;
59114 }
60115
116+ /**
117+ * 连续扫码,当扫描出结果后不关闭扫码界面
118+ */
61119 public ScannerManager continuousScan () {
62120 scanOption .continuousScan = true ;
63121 return this ;
64122 }
65123
124+ /**
125+ * 设置闪光灯打开时的样式
126+ *
127+ * @param flashLightOnDrawable drawable
128+ */
66129 public ScannerManager setFlashLightOnDrawable (int flashLightOnDrawable ) {
67130 scanOption .flashLightOnDrawable = flashLightOnDrawable ;
68131 return this ;
69132 }
70133
134+ /**
135+ * 设置闪光灯关闭时的样式
136+ *
137+ * @param flashLightOffDrawable drawable
138+ */
71139 public ScannerManager setFlashLightOffDrawable (int flashLightOffDrawable ) {
72140 scanOption .flashLightOffDrawable = flashLightOffDrawable ;
73141 return this ;
74142 }
75143
144+ /**
145+ * 设置闪光灯打开时的提示文字
146+ *
147+ * @param lightOnText 提示文字
148+ */
76149 public ScannerManager setFlashLightOnText (String lightOnText ) {
77150 scanOption .flashLightOnText = lightOnText ;
78151 return this ;
79152 }
80153
154+ /**
155+ * 设置闪光灯关闭时的提示文字
156+ *
157+ * @param lightOffText 提示文字
158+ */
81159 public ScannerManager setFlashLightOffText (String lightOffText ) {
82160 scanOption .flashLightOffText = lightOffText ;
83161 return this ;
84162 }
85163
164+ /**
165+ * 设置扫码框下方的提示文字
166+ *
167+ * @param scanNoticeText 提示文字
168+ */
86169 public ScannerManager setScanNoticeText (String scanNoticeText ) {
87170 scanOption .scanNoticeText = scanNoticeText ;
88171 return this ;
89172 }
90173
174+ /**
175+ * 隐藏闪光灯图标及文字
176+ */
91177 public ScannerManager setFlashLightInvisible () {
92178 scanOption .dropFlashLight = true ;
93179 return this ;
94180 }
95181
182+ /**
183+ * 设置扫码线颜色,扫描线最好使用一个渐变颜色
184+ * 如:
185+ * --- === #### === ---
186+ * 我们需要一条线,将它分成5份,拿到1/5、2/5、3/5处的3个颜色就可以画出一条两边细中间粗的扫描线
187+ *
188+ * @param scanLineColors 颜色合集
189+ */
96190 public ScannerManager setScanLineColors (List <Integer > scanLineColors ) {
97191 scanOption .scanLineColors = scanLineColors ;
98192 return this ;
99193 }
100194
195+ /**
196+ * 设置扫码格式{@link BarcodeFormat}
197+ *
198+ * @param barcodeFormats 扫码格式
199+ */
101200 public ScannerManager setBarcodeFormat (BarcodeFormat ... barcodeFormats ) {
102201 scanOption .barcodeFormats = Arrays .asList (barcodeFormats );
103202 return this ;
104203 }
105204
205+ /**
206+ * 设置扫码代理,获取扫码结果
207+ *
208+ * @param delegate 扫码代理
209+ */
106210 public ScannerManager setOnScanResultDelegate (ScanActivityDelegate .OnScanDelegate delegate ) {
107211 ScanActivityDelegate .getInstance ().setScanResultDelegate (delegate );
108212 return this ;
109213 }
110214
215+ /**
216+ * 设置点击图库代理,可以通过自定义的图片选择框架,打开图库
217+ *
218+ * @param onClickAlbumDelegate 点击图库代理
219+ */
220+ public ScannerManager setOnClickAlbumDelegate (ScanActivityDelegate .OnClickAlbumDelegate onClickAlbumDelegate ) {
221+ ScanActivityDelegate .getInstance ().setOnClickAlbumDelegate (onClickAlbumDelegate );
222+ return this ;
223+ }
224+
225+ /**
226+ * 开启界面
227+ */
111228 public void start () {
112229 Intent intent = new Intent (context , ScanActivity .class );
113230 intent .putExtra ("option" , scanOption );
114231 context .startActivity (intent );
115232 }
116233
117- public ScannerManager setOnClickAlbumDelegate (ScanActivityDelegate .OnClickAlbumDelegate onClickAlbumDelegate ) {
118- ScanActivityDelegate .getInstance ().setOnClickAlbumDelegate (onClickAlbumDelegate );
119- return this ;
120- }
121-
122234 public static class ScanOption implements Parcelable {
123235
124236 private int cornerColor ;
125237 private int borderColor ;
238+ private int maskColor ;
126239 private int borderSize ;
127240 private int scanMode ;
128241 private String title ;
@@ -147,6 +260,10 @@ public int getBorderColor() {
147260 return borderColor ;
148261 }
149262
263+ public int getMaskColor () {
264+ return maskColor ;
265+ }
266+
150267 public int getBorderSize () {
151268 return borderSize ;
152269 }
@@ -208,6 +325,7 @@ public int describeContents() {
208325 public void writeToParcel (Parcel dest , int flags ) {
209326 dest .writeInt (this .cornerColor );
210327 dest .writeInt (this .borderColor );
328+ dest .writeInt (this .maskColor );
211329 dest .writeInt (this .borderSize );
212330 dest .writeInt (this .scanMode );
213331 dest .writeString (this .title );
@@ -229,6 +347,7 @@ public ScanOption() {
229347 protected ScanOption (Parcel in ) {
230348 this .cornerColor = in .readInt ();
231349 this .borderColor = in .readInt ();
350+ this .maskColor = in .readInt ();
232351 this .borderSize = in .readInt ();
233352 this .scanMode = in .readInt ();
234353 this .title = in .readString ();
0 commit comments