-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathJverifyPlugin.java
More file actions
1331 lines (1136 loc) · 49.3 KB
/
JverifyPlugin.java
File metadata and controls
1331 lines (1136 loc) · 49.3 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.jiguang.jverify;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.jiguang.verifysdk.api.AuthPageEventListener;
import cn.jiguang.verifysdk.api.JVerificationInterface;
import cn.jiguang.verifysdk.api.JVerifyUIClickCallback;
import cn.jiguang.verifysdk.api.JVerifyUIConfig;
import cn.jiguang.verifysdk.api.LoginSettings;
import cn.jiguang.verifysdk.api.PreLoginListener;
import cn.jiguang.verifysdk.api.PrivacyBean;
import cn.jiguang.verifysdk.api.RequestCallback;
import cn.jiguang.verifysdk.api.VerifyListener;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
/**
* JverifyPlugin
*/
public class JverifyPlugin implements FlutterPlugin, MethodCallHandler {
// 定义日志 TAG
private static final String TAG = "| JVER | Android | -";
/// 统一 key
private static String j_result_key = "result";
/// 错误码
private static String j_code_key = "code";
/// 回调的提示信息,统一返回 flutter 为 message
private static String j_msg_key = "message";
/// 运营商信息
private static String j_opr_key = "operator";
// 默认超时时间
private static int j_default_timeout = 5000;
// 重复请求
private static int j_error_code_repeat = -1;
private Context context;
private MethodChannel channel;
@Override
public void onAttachedToEngine(FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "jverify");
channel.setMethodCallHandler(this);
context = flutterPluginBinding.getApplicationContext();
}
@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}
@Override
public void onMethodCall(MethodCall call, Result result) {
Log.d(TAG, "onMethodCall:" + call.method);
Log.d(TAG, "processMethod:" + call.method);
if (call.method.equals("setup")) {
setup(call, result);
} else if (call.method.equals("setDebugMode")) {
setDebugMode(call, result);
} else if (call.method.equals("isInitSuccess")) {
isInitSuccess(call, result);
} else if (call.method.equals("checkVerifyEnable")) {
checkVerifyEnable(call, result);
} else if (call.method.equals("getToken")) {
getToken(call, result);
} else if (call.method.equals("verifyNumber")) {
verifyNumber(call, result);
} else if (call.method.equals("preLogin")) {
preLogin(call, result);
} else if (call.method.equals("loginAuth")) {
loginAuth(call, result);
} else if (call.method.equals("loginAuthSyncApi")) {
loginAuthSyncApi(call, result);
} else if (call.method.equals("dismissLoginAuthView")) {
dismissLoginAuthView(call, result);
} else if (call.method.equals("setCustomUI")) {
// setCustomUI(call,result);
} else if (call.method.equals("setCustomAuthViewAllWidgets")) {
setCustomAuthViewAllWidgets(call, result);
} else if (call.method.equals("clearPreLoginCache")) {
clearPreLoginCache(call, result);
} else if (call.method.equals("setCustomAuthorizationView")) {
setCustomAuthorizationView(call, result);
} else if (call.method.equals("getSMSCode")) {
getSMSCode(call, result);
} else if (call.method.equals("setSmsIntervalTime")) {
setGetCodeInternal(call, result);
} else {
result.notImplemented();
}
}
// 主线程再返回数据
private void runMainThread(final Map<String, Object> map, final Result result, final String method) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
if (result == null && method != null) {
channel.invokeMethod(method, map);
} else {
result.success(map);
}
}
});
}
/**
* SDK 初始换
*/
private void setup(MethodCall call, Result result) {
Log.d(TAG, "Action - setup:");
Object timeout = getValueByKey(call, "timeout");
boolean setControlWifiSwitch = (boolean) getValueByKey(call, "setControlWifiSwitch");
if (!setControlWifiSwitch) {
Log.d(TAG, "Action - setup: setControlWifiSwitch==" + false);
setControlWifiSwitch();
}
JVerificationInterface.init(context, (Integer) timeout, new RequestCallback<String>() {
@Override
public void onResult(int code, String message) {
Map<String, Object> map = new HashMap<>();
map.put(j_code_key, code);
map.put(j_msg_key, message);
// 通过 channel 返回
runMainThread(map, null, "onReceiveSDKSetupCallBackEvent");
}
});
}
private void setControlWifiSwitch() {
try {
Class<JVerificationInterface> aClass = JVerificationInterface.class;
Method method = aClass.getDeclaredMethod("setControlWifiSwitch", boolean.class);
method.setAccessible(true);
method.invoke(aClass, false);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* SDK设置debug模式
*/
private void setDebugMode(MethodCall call, Result result) {
Log.d(TAG, "Action - setDebugMode:");
Object enable = getValueByKey(call, "debug");
if (enable != null) {
JVerificationInterface.setDebugMode((Boolean) enable);
}
Map<String, Object> map = new HashMap<>();
map.put(j_result_key, enable);
runMainThread(map, result, null);
}
/**
* 获取 SDK 初始化是否成功标识
*/
private boolean isInitSuccess(MethodCall call, Result result) {
Log.d(TAG, "Action - isInitSuccess:");
boolean isSuccess = JVerificationInterface.isInitSuccess();
if (!isSuccess) {
Log.d(TAG, "SDK 初始化失败: ");
}
Map<String, Object> map = new HashMap<>();
map.put(j_result_key, isSuccess);
runMainThread(map, result, null);
return isSuccess;
}
/**
* 设置前后两次获取验证码的时间间隔,默认 30000ms,有效范围(0,300000)
*/
private void setGetCodeInternal(MethodCall call, Result result) {
Log.d(TAG, "Action - setSmsIntervalTime:");
Object intervalTime = getValueByKey(call, "timeInterval");
JVerificationInterface.setSmsIntervalTime((Long) intervalTime);
}
/**
* 获取短信验证码
*/
private void getSMSCode(MethodCall call, final Result result) {
Object phoneNum = getValueByKey(call, "phoneNumber");
Object signId = getValueByKey(call, "signId");
Object tempId = getValueByKey(call, "tempId");
if (phoneNum == null) {
phoneNum = "0";
}
Log.d(TAG, "Action - getSmsCode:" + phoneNum);
JVerificationInterface.getSmsCode(context, (String) phoneNum, (String) signId, (String) tempId, new RequestCallback<String>() {
@Override
public void onResult(int code, String s) {
if (code == 3000) {//code: 返回码,3000代表获取成功,其他为失败
Log.d(TAG, "uuid:" + s);
} else {
Log.e(TAG, "code=" + code + ", message=" + s);
}
Map<String, Object> map = new HashMap<>();
map.put(j_code_key, code);
map.put(j_msg_key, s);
map.put(j_result_key, s);
runMainThread(map, result, null);
}
});
}
/**
* SDK 判断网络环境是否支持
*/
private boolean checkVerifyEnable(MethodCall call, Result result) {
Log.d(TAG, "Action - checkVerifyEnable:");
boolean verifyEnable = JVerificationInterface.checkVerifyEnable(context);
if (!verifyEnable) {
Log.d(TAG, "当前网络环境不支持");
}
Map<String, Object> map = new HashMap<>();
map.put(j_result_key, verifyEnable);
runMainThread(map, result, null);
return verifyEnable;
}
/**
* SDK获取号码认证token
*/
private void getToken(final MethodCall call, final Result result) {
Log.d(TAG, "Action - getToken:");
int timeOut = j_default_timeout;
if (call.hasArgument("timeOut")) {
String timeOutString = call.argument("timeOut");
try {
timeOut = Integer.valueOf(timeOutString);
} catch (Exception e) {
Log.e(TAG, "timeOut type error.");
}
}
JVerificationInterface.getToken(context, timeOut, new VerifyListener() {
@Override
public void onResult(int code, String content, String operator) {
if (code == 2000) {//code: 返回码,2000代表获取成功,其他为失败
Log.d(TAG, "token=" + content + ", operator=" + operator);
} else {
Log.e(TAG, "code=" + code + ", message=" + content);
}
Map<String, Object> map = new HashMap<>();
map.put(j_code_key, code);
map.put(j_msg_key, content);
map.put(j_opr_key, operator);
runMainThread(map, result, null);
}
});
}
/**
* SDK 发起号码认证
*/
private void verifyNumber(MethodCall call, final Result result) {
Log.d(TAG, "Action - verifyNumber:");
}
/**
* SDK 一键登录预取号
*/
private void preLogin(final MethodCall call, final Result result) {
Log.d(TAG, "Action - preLogin:" + call.arguments);
int timeOut = j_default_timeout;
if (call.hasArgument("timeOut")) {
timeOut = call.argument("timeOut");
}
JVerificationInterface.preLogin(context, timeOut, new PreLoginListener() {
@Override
public void onResult(int code, String message) {
if (code == 7000) {//code: 返回码,7000代表获取成功,其他为失败,详见错误码描述
Log.d(TAG, "verify success, message =" + message);
} else {
Log.e(TAG, "verify fail,code=" + code + ", message =" + message);
}
Map<String, Object> map = new HashMap<>();
map.put(j_code_key, code);
map.put(j_msg_key, message);
runMainThread(map, result, null);
}
});
}
/**
* SDK清除预取号缓存
*/
private void clearPreLoginCache(MethodCall call, final Result result) {
Log.d(TAG, "Action - clearPreLoginCache:");
JVerificationInterface.clearPreLoginCache();
}
/**
* SDK请求授权一键登录,异步
*/
private void loginAuth(MethodCall call, final Result result) {
Log.d(TAG, "Action - loginAuth:");
loginAuthInterface(false, call, result);
}
/**
* SDK请求授权一键登录,同步
*/
private void loginAuthSyncApi(MethodCall call, final Result result) {
Log.d(TAG, "Action - loginAuthSyncApi:");
loginAuthInterface(true, call, result);
}
private void loginAuthInterface(final Boolean isSync, final MethodCall call, final Result result) {
Log.d(TAG, "Action - loginAuthInterface:");
Object autoFinish = getValueByKey(call, "autoDismiss");
Integer timeOut = call.argument("timeout");
LoginSettings settings = new LoginSettings();
settings.setAutoFinish((Boolean) autoFinish);
settings.setTimeout(timeOut);
settings.setAuthPageEventListener(new AuthPageEventListener() {
@Override
public void onEvent(int cmd, String msg) {
Log.d(TAG, "Action - AuthPageEventListener: cmd = " + cmd);
/// 事件
final HashMap jsonMap = new HashMap();
jsonMap.put(j_code_key, cmd);
jsonMap.put(j_msg_key, msg);
runMainThread(jsonMap, null, "onReceiveAuthPageEvent");
}
});
JVerificationInterface.loginAuth(context, settings, new VerifyListener() {
@Override
public void onResult(int code, String content, String operator) {
if (code == 6000) {
Log.d(TAG, "code=" + code + ", token=" + content + " ,operator=" + operator);
} else {
Log.d(TAG, "code=" + code + ", message=" + content);
}
Map<String, Object> map = new HashMap<>();
map.put(j_code_key, code);
map.put(j_msg_key, content);
map.put(j_opr_key, operator);
if (isSync) {
// 通过 channel 返回
runMainThread(map, null, "onReceiveLoginAuthCallBackEvent");
} else {
// 通过回调返回
runMainThread(map, result, null);
}
}
});
}
/**
* SDK关闭授权页面
*/
private void dismissLoginAuthView(MethodCall call, Result result) {
Log.d(TAG, "Action - dismissLoginAuthView:");
JVerificationInterface.dismissLoginAuthActivity();
JVerificationInterface.dismissLoginAuthActivity(true, new RequestCallback<String>() {
@Override
public void onResult(int i, String s) {
}
});
}
/**
* 自定义授权界面 UI 、添加自定义控件
*/
private void setCustomAuthViewAllWidgets(MethodCall call, Result result) {
Log.d(TAG, "setCustomAuthViewAllWidgets:");
Map uiconfig = call.argument("uiconfig");
List<Map> widgetList = call.argument("widgets");
JVerifyUIConfig.Builder builder = new JVerifyUIConfig.Builder();
/// 布局 SDK 授权界面原有 UI
layoutOriginOuthView(uiconfig, builder);
if (widgetList != null) {
for (Map widgetMap : widgetList) {
/// 新增自定义的控件
String type = (String) widgetMap.get("type");
if (type.equals("textView")) {
addCustomTextWidgets(widgetMap, builder);
} else if (type.equals("button")) {
addCustomButtonWidgets(widgetMap, builder);
} else {
Log.e(TAG, "don't support widget");
}
}
}
JVerificationInterface.setCustomUIWithConfig(builder.build());
}
private void setCustomAuthorizationView(MethodCall call, Result result) {
Log.d(TAG, "setCustomAuthorizationView:");
Boolean isAutorotate = (Boolean) call.argument("isAutorotate");
Map portraitConfig = call.argument("portraitConfig");
Map landscapeConfig = call.argument("landscapeConfig");
List<Map> widgetList = call.argument("widgets");
JVerifyUIConfig.Builder portraitBuilder = new JVerifyUIConfig.Builder();
JVerifyUIConfig.Builder landscapeBuilder = new JVerifyUIConfig.Builder();
/// 布局 SDK 授权界面原有 UI
layoutOriginOuthView(portraitConfig, portraitBuilder);
if (isAutorotate) {
layoutOriginOuthView(landscapeConfig, landscapeBuilder);
}
if (widgetList != null) {
for (Map widgetMap : widgetList) {
/// 新增自定义的控件
String type = (String) widgetMap.get("type");
if (type.equals("textView")) {
addCustomTextWidgets(widgetMap, portraitBuilder);
if (isAutorotate) {
addCustomTextWidgets(widgetMap, landscapeBuilder);
}
} else if (type.equals("button")) {
addCustomButtonWidgets(widgetMap, portraitBuilder);
if (isAutorotate) {
addCustomButtonWidgets(widgetMap, landscapeBuilder);
}
} else {
Log.e(TAG, "don't support widget");
}
}
}
JVerifyUIConfig portrait = portraitBuilder.build();
if (isAutorotate) {
JVerifyUIConfig landscape = landscapeBuilder.build();
JVerificationInterface.setCustomUIWithConfig(portrait, landscape);
} else {
JVerificationInterface.setCustomUIWithConfig(portrait);
}
}
/**
* 自定义 SDK 原有的授权界面里的 UI
*/
private void layoutOriginOuthView(Map uiconfig, JVerifyUIConfig.Builder builder) {
Log.d(TAG, "layoutOriginOuthView:");
Object enterAnim = valueForKey(uiconfig, "enterAnim");
Object exitAnim = valueForKey(uiconfig, "exitAnim");
Object authBGGifPath = valueForKey(uiconfig, "authBGGifPath");
Object authBackgroundImage = valueForKey(uiconfig, "authBackgroundImage");
Object authBGVideoPath = valueForKey(uiconfig, "authBGVideoPath");
Object authBGVideoImgPath = valueForKey(uiconfig, "authBGVideoImgPath");
Object navColor = valueForKey(uiconfig, "navColor");
Object navText = valueForKey(uiconfig, "navText");
Object navTextColor = valueForKey(uiconfig, "navTextColor");
Object navTextBold = valueForKey(uiconfig, "navTextBold");
Object navReturnImgPath = valueForKey(uiconfig, "navReturnImgPath");
Object navHidden = valueForKey(uiconfig, "navHidden");
Object navReturnBtnHidden = valueForKey(uiconfig, "navReturnBtnHidden");
Object navTransparent = valueForKey(uiconfig, "navTransparent");
Object logoImgPath = valueForKey(uiconfig, "logoImgPath");
Object logoWidth = valueForKey(uiconfig, "logoWidth");
Object logoHeight = valueForKey(uiconfig, "logoHeight");
Object logoOffsetY = valueForKey(uiconfig, "logoOffsetY");
Object logoOffsetX = valueForKey(uiconfig, "logoOffsetX");
Object logoHidden = valueForKey(uiconfig, "logoHidden");
Object logoOffsetBottomY = valueForKey(uiconfig, "logoOffsetBottomY");
Object numberColor = valueForKey(uiconfig, "numberColor");
Object numberSize = valueForKey(uiconfig, "numberSize");
Object numberTextBold = valueForKey(uiconfig, "numberTextBold");
Object numFieldOffsetY = valueForKey(uiconfig, "numFieldOffsetY");
Object numFieldOffsetX = valueForKey(uiconfig, "numFieldOffsetX");
Object numberFieldOffsetBottomY = valueForKey(uiconfig, "numberFieldOffsetBottomY");
Object numberFieldWidth = valueForKey(uiconfig, "numberFieldWidth");
Object numberFieldHeight = valueForKey(uiconfig, "numberFieldHeight");
Object logBtnText = valueForKey(uiconfig, "logBtnText");
Object logBtnOffsetY = valueForKey(uiconfig, "logBtnOffsetY");
Object logBtnOffsetX = valueForKey(uiconfig, "logBtnOffsetX");
Object logBtnBottomOffsetY = valueForKey(uiconfig, "logBtnBottomOffsetY");
Object logBtnWidth = valueForKey(uiconfig, "logBtnWidth");
Object logBtnHeight = valueForKey(uiconfig, "logBtnHeight");
Object logBtnTextSize = valueForKey(uiconfig, "logBtnTextSize");
Object logBtnTextColor = valueForKey(uiconfig, "logBtnTextColor");
Object logBtnTextBold = valueForKey(uiconfig, "logBtnTextBold");
Object logBtnBackgroundPath = valueForKey(uiconfig, "logBtnBackgroundPath");
Object uncheckedImgPath = valueForKey(uiconfig, "uncheckedImgPath");
Object checkedImgPath = valueForKey(uiconfig, "checkedImgPath");
Object privacyTopOffsetY = valueForKey(uiconfig, "privacyTopOffsetY");
Object privacyOffsetY = valueForKey(uiconfig, "privacyOffsetY");
Object privacyOffsetX = valueForKey(uiconfig, "privacyOffsetX");
// Object CLAUSE_NAME = valueForKey(uiconfig, "clauseName");
// Object CLAUSE_URL = valueForKey(uiconfig, "clauseUrl");
Object CLAUSE_BASE_COLOR = valueForKey(uiconfig, "clauseBaseColor");
Object CLAUSE_COLOR = valueForKey(uiconfig, "clauseColor");
// Object CLAUSE_NAME_TWO = valueForKey(uiconfig, "clauseNameTwo");
// Object CLAUSE_URL_TWO = valueForKey(uiconfig, "clauseUrlTwo");
Object privacyTextCenterGravity = valueForKey(uiconfig, "privacyTextCenterGravity");
Object privacyText = valueForKey(uiconfig, "privacyText");
Object privacyTextSize = valueForKey(uiconfig, "privacyTextSize");
Object privacyTextBold = valueForKey(uiconfig, "privacyTextBold");
Object privacyCheckboxHidden = valueForKey(uiconfig, "privacyCheckboxHidden");
Object privacyCheckboxSize = valueForKey(uiconfig, "privacyCheckboxSize");
Object privacyWithBookTitleMark = valueForKey(uiconfig, "privacyWithBookTitleMark");
Object privacyCheckboxInCenter = valueForKey(uiconfig, "privacyCheckboxInCenter");
Object privacyState = valueForKey(uiconfig, "privacyState");
Object sloganOffsetY = valueForKey(uiconfig, "sloganOffsetY");
Object sloganTextColor = valueForKey(uiconfig, "sloganTextColor");
Object sloganOffsetX = valueForKey(uiconfig, "sloganOffsetX");
Object sloganBottomOffsetY = valueForKey(uiconfig, "sloganBottomOffsetY");
Object sloganTextSize = valueForKey(uiconfig, "sloganTextSize");
Object sloganHidden = valueForKey(uiconfig, "sloganHidden");
Object sloganTextBold = valueForKey(uiconfig, "sloganTextBold");
Object privacyUnderlineText = valueForKey(uiconfig, "privacyUnderlineText");
Object privacyNavColor = valueForKey(uiconfig, "privacyNavColor");
Object privacyNavTitleTextColor = valueForKey(uiconfig, "privacyNavTitleTextColor");
Object privacyNavTitleTextSize = valueForKey(uiconfig, "privacyNavTitleTextSize");
Object privacyNavTitleTextBold = valueForKey(uiconfig, "privacyNavTitleTextBold");
Object privacyNavReturnBtnPath = valueForKey(uiconfig, "privacyNavReturnBtnImage");
Object privacyNavTitleTitle1 = valueForKey(uiconfig, "privacyNavTitleTitle1");
Object privacyNavTitleTitle2 = valueForKey(uiconfig, "privacyNavTitleTitle2");
Object statusBarColorWithNav = valueForKey(uiconfig, "statusBarColorWithNav");
Object statusBarDarkMode = valueForKey(uiconfig, "statusBarDarkMode");
Object statusBarTransparent = valueForKey(uiconfig, "statusBarTransparent");
Object statusBarHidden = valueForKey(uiconfig, "statusBarHidden");
Object virtualButtonTransparent = valueForKey(uiconfig, "virtualButtonTransparent");
Object privacyStatusBarColorWithNav = valueForKey(uiconfig, "privacyStatusBarColorWithNav");
Object privacyStatusBarDarkMode = valueForKey(uiconfig, "privacyStatusBarDarkMode");
Object privacyStatusBarTransparent = valueForKey(uiconfig, "privacyStatusBarTransparent");
Object privacyStatusBarHidden = valueForKey(uiconfig, "privacyStatusBarHidden");
Object privacyVirtualButtonTransparent = valueForKey(uiconfig, "privacyVirtualButtonTransparent");
Object needStartAnim = valueForKey(uiconfig, "needStartAnim");
Object needCloseAnim = valueForKey(uiconfig, "needCloseAnim");
Object popViewConfig = valueForKey(uiconfig, "popViewConfig");
Object privacyHintToast = valueForKey(uiconfig, "privacyHintToast");
Object privacyItem = valueForKey(uiconfig, "privacyItem");
/************* 状态栏 ***************/
if (statusBarColorWithNav != null) {
builder.setStatusBarColorWithNav((Boolean) statusBarColorWithNav);
}
if (statusBarDarkMode != null) {
builder.setStatusBarDarkMode((Boolean) statusBarDarkMode);
}
if (statusBarTransparent != null) {
builder.setStatusBarTransparent((Boolean) statusBarTransparent);
}
if (statusBarHidden != null) {
builder.setStatusBarHidden((Boolean) statusBarHidden);
}
if (virtualButtonTransparent != null) {
builder.setVirtualButtonTransparent((Boolean) virtualButtonTransparent);
}
/************** web页 ***************/
if (privacyStatusBarColorWithNav != null) {
builder.setPrivacyStatusBarColorWithNav((Boolean) privacyStatusBarColorWithNav);
}
if (privacyStatusBarDarkMode != null) {
builder.setPrivacyStatusBarDarkMode((Boolean) privacyStatusBarDarkMode);
}
if (privacyStatusBarTransparent != null) {
builder.setPrivacyStatusBarTransparent((Boolean) privacyStatusBarTransparent);
}
if (privacyStatusBarHidden != null) {
builder.setPrivacyStatusBarHidden((Boolean) privacyStatusBarHidden);
}
if (privacyVirtualButtonTransparent != null) {
builder.setPrivacyVirtualButtonTransparent((Boolean) privacyVirtualButtonTransparent);
}
/************** 动画支持 ***************/
if (needStartAnim != null) {
builder.setNeedStartAnim((Boolean) needStartAnim);
}
if (needCloseAnim != null) {
builder.setNeedCloseAnim((Boolean) needCloseAnim);
}
int enterA;
int exitA;
if (enterAnim != null && exitAnim != null) {
enterA = ResourceUtil.getAnimId(context, (String) enterAnim);
exitA = ResourceUtil.getAnimId(context, (String) exitAnim);
if (enterA >= 0 && exitA >= 0) {
builder.overridePendingTransition(enterA, exitA);
}
}
/************** 背景 ***************/
if (authBackgroundImage != null) {
int res_id = getResourceByReflect((String) authBackgroundImage);
if (res_id > 0) {
builder.setAuthBGImgPath((String) authBackgroundImage);
}
}
if (authBGGifPath != null) {
int res_id = getResourceByReflect((String) authBGGifPath);
if (res_id > 0) {
builder.setAuthBGGifPath((String) authBGGifPath);
}
}
if (authBGVideoPath != null) {
if (!((String)authBGVideoPath).startsWith("http"))
authBGVideoPath = "android.resource://"+context.getPackageName()+"/raw/"+authBGVideoPath;
builder.setAuthBGVideoPath((String) authBGVideoPath, (String) authBGVideoImgPath);
}
/************** nav ***************/
if (navHidden != null) {
builder.setNavHidden((Boolean) navHidden);
}
if (navReturnBtnHidden != null) {
builder.setNavReturnBtnHidden((Boolean) navReturnBtnHidden);
}
if (navTransparent != null) {
builder.setNavTransparent((Boolean) navTransparent);
}
if (navColor != null) {
builder.setNavColor(exchangeObject(navColor));
}
if (navText != null) {
builder.setNavText((String) navText);
}
if (navTextColor != null) {
builder.setNavTextColor(exchangeObject(navTextColor));
}
if (navTextBold != null) {
builder.setNavTextBold((Boolean) navTextBold);
}
if (navReturnImgPath != null) {
builder.setNavReturnImgPath((String) navReturnImgPath);
}
/************** logo ***************/
if (logoWidth != null) {
builder.setLogoWidth((Integer) logoWidth);
}
if (logoHeight != null) {
builder.setLogoHeight((Integer) logoHeight);
}
if (logoOffsetY != null) {
builder.setLogoOffsetY((Integer) logoOffsetY);
}
if (logoOffsetX != null) {
builder.setLogoOffsetX((Integer) logoOffsetX);
}
if (logoHidden != null) {
builder.setLogoHidden((Boolean) logoHidden);
}
if (logoImgPath != null) {
int res_id = getResourceByReflect((String) logoImgPath);
if (res_id > 0) {
builder.setLogoImgPath((String) logoImgPath);
}
}
if (logoOffsetBottomY != null) {
builder.setLogoOffsetBottomY((Integer) logoOffsetBottomY);
}
/************** number ***************/
if (numberFieldOffsetBottomY != null) {
builder.setNumberFieldOffsetBottomY((Integer) numberFieldOffsetBottomY);
}
if (numFieldOffsetY != null) {
builder.setNumFieldOffsetY((Integer) numFieldOffsetY);
}
if (numFieldOffsetX != null) {
builder.setNumFieldOffsetX((Integer) numFieldOffsetX);
}
if (numberFieldWidth != null) {
builder.setNumberFieldWidth((Integer) numberFieldWidth);
}
if (numberFieldHeight != null) {
builder.setNumberFieldHeight((Integer) numberFieldHeight);
}
if (numberColor != null) {
builder.setNumberColor(exchangeObject(numberColor));
}
if (numberSize != null) {
builder.setNumberSize((Number) numberSize);
}
if (numberTextBold != null) {
builder.setNumberTextBold((Boolean) numberTextBold);
}
/************** slogan ***************/
if (sloganOffsetY != null) {
builder.setSloganOffsetY((Integer) sloganOffsetY);
}
if (sloganOffsetX != null) {
builder.setSloganOffsetX((Integer) sloganOffsetX);
}
if (sloganBottomOffsetY != null) {
builder.setSloganBottomOffsetY((Integer) sloganBottomOffsetY);
}
if (sloganTextSize != null) {
builder.setSloganTextSize((Integer) sloganTextSize);
}
if (sloganTextColor != null) {
builder.setSloganTextColor(exchangeObject(sloganTextColor));
}
if (sloganHidden != null) {
builder.setSloganHidden((Boolean) sloganHidden);
}
if (sloganTextBold != null) {
builder.setSloganTextBold((Boolean) sloganTextBold);
}
/************** login btn ***************/
if (logBtnOffsetY != null) {
builder.setLogBtnOffsetY((Integer) logBtnOffsetY);
}
if (logBtnOffsetX != null) {
builder.setLogBtnOffsetX((Integer) logBtnOffsetX);
}
if (logBtnBottomOffsetY != null) {
builder.setLogBtnBottomOffsetY((Integer) logBtnBottomOffsetY);
}
if (logBtnWidth != null) {
builder.setLogBtnWidth((Integer) logBtnWidth);
}
if (logBtnHeight != null) {
builder.setLogBtnHeight((Integer) logBtnHeight);
}
if (logBtnText != null) {
builder.setLogBtnText((String) logBtnText);
}
if (logBtnTextSize != null) {
builder.setLogBtnTextSize((Integer) logBtnTextSize);
}
if (logBtnTextColor != null) {
builder.setLogBtnTextColor(exchangeObject(logBtnTextColor));
}
if (logBtnTextBold != null) {
builder.setLogBtnTextBold((Boolean) logBtnTextBold);
}
if (logBtnBackgroundPath != null) {
int res_id = getResourceByReflect((String) logBtnBackgroundPath);
if (res_id > 0) {
builder.setLogBtnImgPath((String) logBtnBackgroundPath);
}
}
/************** check box ***************/
builder.setPrivacyCheckboxHidden((Boolean) privacyCheckboxHidden);
if (privacyCheckboxSize != null) {
builder.setPrivacyCheckboxSize((Integer) privacyCheckboxSize);
}
if (uncheckedImgPath != null) {
int res_id = getResourceByReflect((String) uncheckedImgPath);
if (res_id > 0) {
builder.setUncheckedImgPath((String) uncheckedImgPath);
}
}
if (checkedImgPath != null) {
int res_id = getResourceByReflect((String) checkedImgPath);
if (res_id > 0) {
builder.setCheckedImgPath((String) checkedImgPath);
}
}
/************** privacy ***************/
if (privacyOffsetY != null) {
//设置隐私条款相对于授权页面底部下边缘y偏移
builder.setPrivacyOffsetY((Integer) privacyOffsetY);
} else {
if (privacyTopOffsetY != null) {
//设置隐私条款相对导航栏下端y轴偏移。since 2.4.8
builder.setPrivacyTopOffsetY((Integer) privacyTopOffsetY);
}
}
if (privacyOffsetX != null) {
builder.setPrivacyOffsetX((Integer) privacyOffsetX);
}
if (privacyCheckboxSize != null) {
builder.setPrivacyCheckboxSize((Integer) privacyCheckboxSize);
}
if (privacyTextSize != null) {
builder.setPrivacyTextSize((Integer) privacyTextSize);
}
if (privacyText != null) {
ArrayList<String> privacyTextList = (ArrayList) privacyText;
privacyTextList.addAll(Arrays.asList("", "", "", ""));
builder.setPrivacyText(privacyTextList.get(0), privacyTextList.get(1));
}
if (privacyTextBold != null) {
builder.setPrivacyTextBold((Boolean) privacyTextBold);
}
if (privacyUnderlineText != null) {
builder.setPrivacyUnderlineText((Boolean) privacyUnderlineText);
}
builder.setPrivacyTextCenterGravity((Boolean) privacyTextCenterGravity);
builder.setPrivacyWithBookTitleMark((Boolean) privacyWithBookTitleMark);
builder.setPrivacyCheckboxInCenter((Boolean) privacyCheckboxInCenter);
builder.setPrivacyState((Boolean) privacyState);
if (privacyItem != null) {
try {
JSONArray jsonArray = new JSONArray((String) privacyItem);
int length = jsonArray.length();
JSONObject jsonObject;
PrivacyBean privacyBean;
ArrayList<PrivacyBean> privacyBeans = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
jsonObject = jsonArray.optJSONObject(i);
privacyBean = new PrivacyBean(jsonObject.optString("name"), jsonObject.optString("url"),
jsonObject.optString("separator"));
privacyBeans.add(privacyBean);
}
builder.setPrivacyNameAndUrlBeanList(privacyBeans);
} catch (JSONException e) {
e.printStackTrace();
}
}
int baseColor = -10066330;
int color = -16007674;
if (CLAUSE_BASE_COLOR != null) {
if (CLAUSE_BASE_COLOR instanceof Long) {
baseColor = ((Long) CLAUSE_BASE_COLOR).intValue();
} else {
baseColor = (Integer) CLAUSE_BASE_COLOR;
}
}
if (CLAUSE_COLOR != null) {
if (CLAUSE_COLOR instanceof Long) {
color = ((Long) CLAUSE_COLOR).intValue();
} else {
color = (Integer) CLAUSE_COLOR;
}
}
builder.setAppPrivacyColor(baseColor, color);
/************** 隐私 web 页面 ***************/
if (privacyNavColor != null) {
builder.setPrivacyNavColor(exchangeObject(privacyNavColor));
}
if (privacyNavTitleTextSize != null) {
builder.setPrivacyNavTitleTextSize(exchangeObject(privacyNavTitleTextSize));
}
if (privacyNavTitleTextColor != null) {
builder.setPrivacyNavTitleTextColor(exchangeObject(privacyNavTitleTextColor));
}
// if (privacyNavTitleTitle1 != null) {
// builder.setAppPrivacyNavTitle1((String) privacyNavTitleTitle1);
// }
// if (privacyNavTitleTitle2 != null) {
// builder.setAppPrivacyNavTitle2((String) privacyNavTitleTitle2);
// }
if (privacyNavTitleTextBold != null) {
builder.setPrivacyNavTitleTextBold((Boolean) privacyNavTitleTextBold);
}
if (privacyNavReturnBtnPath != null) {
int res_id = getResourceByReflect((String) privacyNavReturnBtnPath);
if (res_id > 0) {
builder.setPrivacyNavReturnBtnPath((String) privacyNavReturnBtnPath);
}
}
builder.enableHintToast((Boolean) privacyHintToast, null);
/************** 授权页弹窗模式 ***************/
if (popViewConfig != null) {
Map popViewConfigMap = (Map) popViewConfig;
Object isPopViewTheme = valueForKey(popViewConfigMap, "isPopViewTheme");
if ((Boolean) isPopViewTheme) {
Object width = valueForKey(popViewConfigMap, "width");
Object height = valueForKey(popViewConfigMap, "height");
Object offsetCenterX = valueForKey(popViewConfigMap, "offsetCenterX");
Object offsetCenterY = valueForKey(popViewConfigMap, "offsetCenterY");
Object isBottom = valueForKey(popViewConfigMap, "isBottom");
builder.setDialogTheme((int) width, (int) height, (int) offsetCenterX, (int) offsetCenterY, (Boolean) isBottom);
}
}
}
/** 添加自定义 widget 到 SDK 原有的授权界面里 */
/**
* 添加自定义 TextView
*/
private void addCustomTextWidgets(Map para, JVerifyUIConfig.Builder builder) {
Log.d(TAG, "addCustomTextView " + para);
TextView customView = new TextView(context);
;