111
hxb
2022-11-24 0a3e07f10937484145f33c7560607b4b2353cb81
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
package com.mm.android.deviceaddmodule.mobilecommon.utils;
 
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.text.TextPaint;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.EditText;
import android.widget.TextView;
 
import com.mm.android.deviceaddmodule.R;
 
import java.lang.reflect.Field;
import java.util.List;
 
public class UIUtils {
    private static final String TAG = "UIUtils";
    private static long mLastClickTime;
 
    private static float sDensity = -1;
 
    /**
     * 获取屏幕像素密度
     */
    public static float getScreenDensity(Context context) {
        if(context == null)return sDensity;
        DisplayMetrics  dm =  context.getApplicationContext().getResources().getDisplayMetrics();
        sDensity = dm.density;
 
        return dm.density;
    }
 
 
    // 将px值转换为dip或dp值,保证尺寸大小不变
    public static int px2dip(DisplayMetrics dM, float pxValue) {
        final float scale = dM.density;
        return (int) (pxValue / scale + 0.5f);
    }
 
    // 将dip或dp值转换为px值,保证尺寸大小不变
    public static int dip2px(DisplayMetrics dM, float dipValue) {
        final float scale = dM.density;
        return (int) (dipValue * scale + 0.5f);
    }
 
    /**
     * 获取当前屏幕宽度
     */
    public static int getDefaultDialogWidth(Context context) {
        return getScreenWidth(context) * 4 / 5;
    }
    /**
     * 获取当前屏幕宽度
     */
    public static int getScreenWidth(Context context) {
        if(context == null)return -1;
        DisplayMetrics  dm =  context.getApplicationContext().getResources().getDisplayMetrics();
        return dm.widthPixels;
    }
 
    public static int getDefaultDialogWidthWithLandscape(Context context){
        return getScreenHeight(context) * 4 / 5;
    }
 
    /**
     * 获取当前屏幕高度
     */
    public static int getScreenHeight(Context context) {
        if(context == null)return -1;
        DisplayMetrics  dm =  context.getApplicationContext().getResources().getDisplayMetrics();
        return dm.heightPixels;
    }
 
    // 将px值转换为dip或dp值,保证尺寸大小不变
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }
 
    // 将dip或dp值转换为px值,保证尺寸大小不变
    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }
 
 
    // 将px值转换为sp值,保证文字大小不变
    public static int px2sp(Context context, float pxValue) {
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (pxValue / fontScale + 0.5f);
    }
 
    // 将sp值转换为px值,保证文字大小不变
    public static int sp2px(Context context, float spValue) {
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * fontScale + 0.5f);
    }
 
    // 屏幕宽度(像素)
    public static int getWindowWidth(Activity context) {
        DisplayMetrics metric = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(metric);
        return metric.widthPixels;
    }
 
    // 屏幕高度(像素)
    public static int getWindowHeight(Activity context) {
        DisplayMetrics metric = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(metric);
        return metric.heightPixels;
    }
 
 
    /**
     * 检测是否重复点击事件,默认时间为800毫秒
     *
     * @return
     */
    public static boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        long timeD = time - mLastClickTime;
        if (0 < timeD && timeD < 800) {
            return true;
        }
        mLastClickTime = time;
        return false;
    }
 
    /**
     * 将当前activity拉到前台
     *
     * @param paramActivity
     */
    public static void goForeground(Activity paramActivity) {
        if (paramActivity == null) return;
        Window localWindow = paramActivity.getWindow();
        if (localWindow != null) {
            localWindow.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            localWindow.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
            localWindow.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
        }
    }
 
 
    /**
     * 检测在规定的时间里面是否重复点击事件
     *
     * @return
     */
    public static boolean isFastDoubleClick(long elapse) {
        long time = System.currentTimeMillis();
        long timeD = time - mLastClickTime;
        if (0 < timeD && timeD < elapse) {
            return true;
        }
        mLastClickTime = time;
        return false;
    }
    /**
     * 检测在100ms规定的时间里面是否快速触发相同方法两次,针对误触发情况的兼容
     *
     * @return
     */
    public static boolean isFastCallFuncTwice() {
        long time = System.currentTimeMillis();
        long timeD = time - mLastClickTime;
        if (0 < timeD && timeD < 100) {
            return true;
        }
        mLastClickTime = time;
        return false;
    }
    /**
     * 进入全屏
     *
     * @param activity
     */
    public static void setFullScreen(Activity activity) {
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
 
    /**
     * 退出全屏
     *
     * @param activity
     */
    public static void quitFullScreen(Activity activity) {
        if (activity == null) {
            return;
        }
        final WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
        attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
        activity.getWindow().setAttributes(attrs);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }
 
    /**
     * 输入框禁止复制,粘贴
     *
     * @param editText
     */
    public static void UnCopyAble(EditText editText) {
        if (editText == null) {
            return;
        }
        editText.setLongClickable(false);
    }
 
    /**
     * 获取状态栏高度
     * <p>
     * </p>
     */
    public static int getStatusBarHeight(Context context) {
        Class<?> c = null;
        Object object = null;
        Field field = null;
        int x = 0;
        int statusBar = 0;
        try {
            c = Class.forName("com.android.internal.R$dimen");
            object = c.newInstance();
            field = c.getField("status_bar_height");
            x = Integer.parseInt(field.get(object).toString());
            statusBar = context.getResources().getDimensionPixelSize(x);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return statusBar == 0 ? dp2px(context, 20) : statusBar;
    }
 
    /**
     * 设置按钮选中与否
     * <p>
     * </p>
     *
     * @param selected
     * @param views
     */
    public static void setSelected(boolean selected, View... views) {
        for (View view : views) {
            view.setSelected(selected);
        }
    }
 
    public static void setSelected(boolean selected, ViewGroup... viewGroups) {
        for (ViewGroup viewGroup : viewGroups) {
            viewGroup.setSelected(selected);
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                View v = viewGroup.getChildAt(i);
                if (v instanceof ViewGroup) {
                    setSelected(selected, (ViewGroup) v);
                } else {
                    setSelected(selected, v);
                }
            }
        }
    }
 
    /**
     * 设置空间是否可用(不置灰)
     * <p>
     * </p>
     *
     * @param enabled
     * @param views
     */
    public static void setEnabled(boolean enabled, View... views) {
        for (View view : views) {
            view.setEnabled(enabled);
        }
    }
 
    /**
     * 启用/禁用控件,包括所有子控件
     */
    public static void setEnabledSub(boolean enabled, ViewGroup... viewGroups) {
        for (ViewGroup viewGroup : viewGroups) {
            viewGroup.setEnabled(enabled);
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                View v = viewGroup.getChildAt(i);
                if (v instanceof ViewGroup) {
                    setEnabledSub(enabled, (ViewGroup) v);
                } else {
                    setEnabled(enabled, v);
                }
            }
        }
    }
 
    /**
     * 启用/禁用 item
     * <p></p>
     * @param enabled
     * @param viewGroup
     * @param tv
     */
    public static void setDevDetailItemEnable(boolean enabled, ViewGroup viewGroup, TextView tv) {
        setEnabledSub(enabled, viewGroup);
 
        if (tv == null) {
            return;
        }
        if (enabled) {
            tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.mobile_common_icon_nextarrow, 0);
        } else {
            tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        }
    }
 
    /**
     * 设置控件可用与否 (置灰)
     *
     * @param views   被设置的控件
     * @param enabled 是否可用
     */
    public static void setEnabledEX(boolean enabled, View... views) {
        for (View view : views) {
            if (enabled) {
                view.setEnabled(enabled);
                view.clearAnimation();
            } else {
                Animation aniAlp = new AlphaAnimation(1f, 0.5f);
                aniAlp.setDuration(0);
                aniAlp.setInterpolator(new AccelerateDecelerateInterpolator());
                aniAlp.setFillEnabled(true);
                aniAlp.setFillAfter(true);
                view.startAnimation(aniAlp);
                view.setEnabled(enabled);
            }
        }
    }
 
    /**
     * 遍历布局,禁用/启用所有子控件
     * <p>
     * </p>
     *
     * @param viewGroup
     * @param enabled
     */
    public static void setEnabledSubControls(ViewGroup viewGroup, boolean enabled) {
        setEnabledEX(enabled, viewGroup);
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View v = viewGroup.getChildAt(i);
            if (v instanceof ViewGroup) {
                setEnabledSubControls((ViewGroup) v, enabled);
            } else {
                setEnabledEX(enabled, v);
            }
        }
    }
 
    /**
     * 隐藏/显示
     * <p>
     * </p>
     *
     * @param visibility
     * @param views
     */
    public static void setVisibility(int visibility, View... views) {
        for (View view : views) {
            view.setVisibility(visibility);
        }
    }
 
    public static void expandViewTouchDelegate(final View view, final int top, final int bottom, final int left,
                                               final int right) {
 
        ((View) view.getParent()).post(new Runnable() {
 
            @Override
            public void run() {
                Rect bounds = new Rect();
                view.setEnabled(true);
                view.getHitRect(bounds);
 
                bounds.top -= top;
                bounds.bottom += bottom;
                bounds.left -= left;
                bounds.right += right;
 
                TouchDelegate touchDelegate = new TouchDelegate(bounds, view);
 
                if (View.class.isInstance(view.getParent())) {
                    ((View) view.getParent()).setTouchDelegate(touchDelegate);
                }
 
            }
        });
    }
 
 
    /**
     * 设置一组控件显隐
     *
     * @param views
     * @param flags
     */
    public static void setViewsVisibility(View[] views, int[] flags) {
        if (views == null) {
            return;
        }
        for (int i = 0; i < views.length; i++) {
            if (views[i] != null) views[i].setVisibility(i < flags.length ? flags[i] : View.GONE);
        }
    }
 
    /**
     * 设置控件显隐
     *
     * @param view
     * @param flag
     */
    public static void setViewVisibility(View view, int flag) {
        if (view == null) {
            return;
        }
        view.setVisibility(flag);
    }
 
    public static void setEnableWithAlphaChanged(View view, boolean enable) {
        if (view == null) {
            return;
        }
        view.setEnabled(enable);
        view.setAlpha(enable ? 1f : 0.5f);
    }
 
    public static void setEnabledAllInGroup(ViewGroup viewGroup, boolean enabled) {
        if (viewGroup == null) {
            return;
        }
        viewGroup.setEnabled(enabled);
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View v = viewGroup.getChildAt(i);
            if (v instanceof ViewGroup) {
                setEnabledAllInGroup((ViewGroup) v, enabled);
            } else {
                v.setEnabled(enabled);
            }
        }
    }
 
    public static int getEncryV2(int byAuthMode, int byEncrAlgr) {
        int nEncryption = 0;
 
        if(byAuthMode == 6 && byEncrAlgr == 0)
        {
            nEncryption = 0;
        }
        else if(byAuthMode == 0 && byEncrAlgr == 0)
        {
            nEncryption = 1;
        }
        else  if(byAuthMode == 0 && byEncrAlgr == 4)
        {
            nEncryption = 2;
        }
        else  if(byAuthMode == 1 && byEncrAlgr == 4)
        {
            nEncryption = 3;
        }
        else  if(byAuthMode == 2 && byEncrAlgr == 5)
        {
            nEncryption = 4;
        }
        else  if(byAuthMode == 3 && byEncrAlgr == 5)
        {
            nEncryption = 5;
        }
        else  if(byAuthMode == 4 && byEncrAlgr == 5)
        {
            nEncryption = 6;
        }
        else  if(byAuthMode == 5 && byEncrAlgr == 5)
        {
            nEncryption = 7;
        }
        else  if(byAuthMode == 2 && byEncrAlgr == 6)
        {
            nEncryption = 8;
        }
        else  if(byAuthMode == 3 && byEncrAlgr == 6)
        {
            nEncryption = 9;
        }
        else  if(byAuthMode == 4 && byEncrAlgr == 6)
        {
            nEncryption = 10;
        }
        else  if(byAuthMode == 5 && byEncrAlgr == 6)
        {
            nEncryption = 11;
        }
        else  if(byAuthMode == 2 && byEncrAlgr == 7)
        {
            nEncryption = 8;  // 4或者8
        }
        else  if(byAuthMode == 3 && byEncrAlgr == 7)
        {
            nEncryption = 9;  // 5或9
        }
        else  if(byAuthMode == 4 && byEncrAlgr == 7)
        {
            nEncryption = 10;  // 6或10
        }
        else  if(byAuthMode == 5 && byEncrAlgr == 7)
        {
            nEncryption = 11;  // 7或11
        }
        else if(byAuthMode == 7)  // 混合模式WPA-PSK|WPA2-PSK   3或5
        {
            if(byEncrAlgr == 5) {
                nEncryption = 7;  // 5或7
            }
            else if(byEncrAlgr == 6)
            {
                nEncryption = 11;  // 9或11
            }
            else if(byEncrAlgr == 7)
            {
                nEncryption = 11;  // 5或7或9或11
            }
            else
            {
                nEncryption = 12;
            }
        }
        else if(byAuthMode == 8)  // 混合模式WPA|WPA2    2或4
        {
            if(byEncrAlgr == 5) {
                nEncryption = 6;  // 4或6
            }
            else if(byEncrAlgr == 6)
            {
                nEncryption = 10;  // 8或10
            }
            else if(byEncrAlgr == 7)
            {
                nEncryption = 10;  // 4或6或8或10
            }
            else
            {
                nEncryption = 12;
            }
        }
        else if(byAuthMode == 9)  // 混合模式WPA|WPA-PSK  2或3
        {
            if(byEncrAlgr == 5) {
                nEncryption = 5;  // 4或5
            }
            else if(byEncrAlgr == 6)
            {
                nEncryption = 9;  // 8或9
            }
            else if(byEncrAlgr == 7)
            {
                nEncryption = 9;  // 4或5或8或9
            }
            else
            {
                nEncryption = 12;
            }
        }
        else if(byAuthMode == 10)  // 混合模式WPA2|WPA2-PSK  4或5
        {
            if(byEncrAlgr == 5) {
                nEncryption = 7;  // 6或7
            }
            else if(byEncrAlgr == 6)
            {
                nEncryption = 11;  // 10或11
            }
            else if(byEncrAlgr == 7)
            {
                nEncryption = 11;  // 6或7或10或11
            }
            else
            {
                nEncryption = 12;
            }
        }
        else if(byAuthMode == 11)  // 混合模式WPA|WPA-PSK|WPA2|WPA2-PSK  2或3或4或5
        {
            if(byEncrAlgr == 5) {
                nEncryption = 7;  // 4或5或6或7
            }
            else if(byEncrAlgr == 6)
            {
                nEncryption = 11;  // 8或9或10或11
            }
            else if(byEncrAlgr == 7)
            {
                nEncryption = 11;  // 4或5或6或7或8或9或10或11
            }
            else
            {
                nEncryption = 12;
            }
        } else {
            nEncryption = 12;
        }
        return nEncryption;
    }
 
    public static int getEncry(int byAuthMode, int byEncrAlgr) {
        int nEncryption = 0;
 
        if(byAuthMode == 6 && byEncrAlgr == 0)
        {
            nEncryption = 0;
        }
        else if(byAuthMode == 0 && byEncrAlgr == 0)
        {
            nEncryption = 1;
        }
        else  if(byAuthMode == 0 && byEncrAlgr == 1)
        {
            nEncryption = 2;
        }
        else  if(byAuthMode == 1 && byEncrAlgr == 1)
        {
            nEncryption = 3;
        }
        else  if(byAuthMode == 2 && byEncrAlgr == 2)
        {
            nEncryption = 4;
        }
        else  if(byAuthMode == 3 && byEncrAlgr == 2)
        {
            nEncryption = 5;
        }
        else  if(byAuthMode == 4 && byEncrAlgr == 2)
        {
            nEncryption = 6;
        }
        else  if(byAuthMode == 5 && byEncrAlgr == 2)
        {
            nEncryption = 7;
        }
        else  if(byAuthMode == 2 && byEncrAlgr == 3)
        {
            nEncryption = 8;
        }
        else  if(byAuthMode == 3 && byEncrAlgr == 3)
        {
            nEncryption = 9;
        }
        else  if(byAuthMode == 4 && byEncrAlgr == 3)
        {
            nEncryption = 10;
        }
        else  if(byAuthMode == 5 && byEncrAlgr == 3)
        {
            nEncryption = 11;
        }
        else  if(byAuthMode == 2 && byEncrAlgr == 4)
        {
            nEncryption = 8;  // 4或者8
        }
        else  if(byAuthMode == 3 && byEncrAlgr == 4)
        {
            nEncryption = 9;  // 5或9
        }
        else  if(byAuthMode == 4 && byEncrAlgr == 4)
        {
            nEncryption = 10;  // 6或10
        }
        else  if(byAuthMode == 5 && byEncrAlgr == 4)
        {
            nEncryption = 11;  // 7或11
        }
        else if(byAuthMode == 7)  // 混合模式WPA-PSK|WPA2-PSK   3或5
        {
            if(byEncrAlgr == 2) {
                nEncryption = 7;  // 5或7
            }
            else if(byEncrAlgr == 3)
            {
                nEncryption = 11;  // 9或11
            }
            else if(byEncrAlgr == 4)
            {
                nEncryption = 11;  // 5或7或9或11
            }
            else
            {
                nEncryption = 12;
            }
        }
        else if(byAuthMode == 8)  // 混合模式WPA|WPA2    2或4
        {
            if(byEncrAlgr == 2) {
                nEncryption = 6;  // 4或6
            }
            else if(byEncrAlgr == 3)
            {
                nEncryption = 10;  // 8或10
            }
            else if(byEncrAlgr == 4)
            {
                nEncryption = 10;  // 4或6或8或10
            }
            else
            {
                nEncryption = 12;
            }
        }
        else if(byAuthMode == 9)  // 混合模式WPA|WPA-PSK  2或3
        {
            if(byEncrAlgr == 2) {
                nEncryption = 5;  // 4或5
            }
            else if(byEncrAlgr == 3)
            {
                nEncryption = 9;  // 8或9
            }
            else if(byEncrAlgr == 4)
            {
                nEncryption = 9;  // 4或5或8或9
            }
            else
            {
                nEncryption = 12;
            }
        }
        else if(byAuthMode == 10)  // 混合模式WPA2|WPA2-PSK  4或5
        {
            if(byEncrAlgr == 2) {
                nEncryption = 7;  // 6或7
            }
            else if(byEncrAlgr == 3)
            {
                nEncryption = 11;  // 10或11
            }
            else if(byEncrAlgr == 4)
            {
                nEncryption = 11;  // 6或7或10或11
            }
            else
            {
                nEncryption = 12;
            }
        }
        else if(byAuthMode == 11)  // 混合模式WPA|WPA-PSK|WPA2|WPA2-PSK  2或3或4或5
        {
            if(byEncrAlgr == 2) {
                nEncryption = 7;  // 4或5或6或7
            }
            else if(byEncrAlgr == 3)
            {
                nEncryption = 11;  // 8或9或10或11
            }
            else if(byEncrAlgr == 4)
            {
                nEncryption = 11;  // 4或5或6或7或8或9或10或11
            }
            else
            {
                nEncryption = 12;
            }
        } else {
            nEncryption = 12;
        }
        return nEncryption;
    }
 
    public static int getEncry4Sc(int byAuthMode, int byEncrAlgr) {
 
        int nEncryption = 0;
 
        if (byAuthMode == 6 && byEncrAlgr == 0) {
            nEncryption = 0;
        } else if (byAuthMode == 0 && byEncrAlgr == 0) {
            nEncryption = 1;
        } else if (byAuthMode == 0 && byEncrAlgr == 4) {
            nEncryption = 13;
        } else if (byAuthMode == 1 && byEncrAlgr == 4) {
            nEncryption = 14;
        } else if (byAuthMode == 2 && byEncrAlgr == 5) {
            nEncryption = 8;
        } else if (byAuthMode == 3 && byEncrAlgr == 5) {
            nEncryption = 4;
        } else if (byAuthMode == 4 && byEncrAlgr == 5) {
            nEncryption = 10;
        } else if (byAuthMode == 5 && byEncrAlgr == 5) {
            nEncryption = 6;
        } else if (byAuthMode == 2 && byEncrAlgr == 6) {
            nEncryption = 9;
        } else if (byAuthMode == 3 && byEncrAlgr == 6) {
            nEncryption = 5;
        } else if (byAuthMode == 4 && byEncrAlgr == 6) {
            nEncryption = 11;
        } else if (byAuthMode == 5 && byEncrAlgr == 6) {
            nEncryption = 7;
        } else if (byAuthMode == 2 && byEncrAlgr == 7) {
            nEncryption = 9;  // 8或者9
        } else if (byAuthMode == 3 && byEncrAlgr == 7) {
            nEncryption = 5;  // 4或5
        } else if (byAuthMode == 4 && byEncrAlgr == 7) {
            nEncryption = 11;  // 10或11
        } else if (byAuthMode == 5 && byEncrAlgr == 7) {
            nEncryption = 7;  // 6或7
        } else if (byAuthMode == 7)  // 混合模式WPA-PSK|WPA2-PSK   3或5
        {
            if (byEncrAlgr == 5) {
                nEncryption = 6;  // 4或6
            } else if (byEncrAlgr == 6) {
                nEncryption = 7;  // 5或7
            } else if (byEncrAlgr == 7) {
                nEncryption = 7;  // 4或5或6或7
            } else {
                nEncryption = 12;
            }
        } else if (byAuthMode == 8)  // 混合模式WPA|WPA2    2或4
        {
            if (byEncrAlgr == 5) {
                nEncryption = 10;  // 8或10
            } else if (byEncrAlgr == 6) {
                nEncryption = 11;  // 9或11
            } else if (byEncrAlgr == 7) {
                nEncryption = 10;  // 8或9或10或11
            } else {
                nEncryption = 12;
            }
        } else if (byAuthMode == 9)  // 混合模式WPA|WPA-PSK  2或3
        {
            if (byEncrAlgr == 5) {
                nEncryption = 8;  // 4或8
            } else if (byEncrAlgr == 6) {
                nEncryption = 9;  // 5或9
            } else if (byEncrAlgr == 7) {
                nEncryption = 9;  // 4或5或8或9
            } else {
                nEncryption = 12;
            }
        } else if (byAuthMode == 10)  // 混合模式WPA2|WPA2-PSK  4或5
        {
            if (byEncrAlgr == 5) {
                nEncryption = 10;  // 6或10
            } else if (byEncrAlgr == 6) {
                nEncryption = 11;  // 7或11
            } else if (byEncrAlgr == 7) {
                nEncryption = 11;  // 6或7或10或11
            } else {
                nEncryption = 12;
            }
        } else if (byAuthMode == 11)  // 混合模式WPA|WPA-PSK|WPA2|WPA2-PSK  2或3或4或5
        {
            if (byEncrAlgr == 5) {
                nEncryption = 10;  // 4或6或8或10
            } else if (byEncrAlgr == 6) {
                nEncryption = 11;  // 5或7或9或11
            } else if (byEncrAlgr == 7) {
                nEncryption = 11;  // 4或5或6或7或8或9或10或11
            } else {
                nEncryption = 12;
            }
        } else {
            nEncryption = 12;
        }
        return nEncryption;
    }
 
    public static Fragment getVisibleFragment(FragmentActivity activity) {
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        @SuppressLint("RestrictedApi") List<android.support.v4.app.Fragment> fragments = fragmentManager.getFragments();
        for (Fragment fragment : fragments) {
            if (fragment != null && fragment.isVisible()) {
                return fragment;
            }
        }
 
        return null;
    }
 
    public static boolean isAppOnForeground(Context context) {
        if (context == null) {
            return false;
        }
        ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        if (mActivityManager == null) {
            return false;
        }
        List<ActivityManager.RunningTaskInfo> tasksInfo = mActivityManager.getRunningTasks(1);
        if (tasksInfo != null && tasksInfo.size() > 0) {
            // 应用程序位于堆栈的顶层
            ComponentName componentName = tasksInfo.get(0).topActivity;
            if (componentName != null && context.getPackageName().equals(componentName.getPackageName())) {
                return true;
            }
        }
        return false;
    }
 
    public static boolean isAssignClass(Context context, String className){
        if (context == null) {
            return false;
        }
        ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        if (mActivityManager == null) {
            return false;
        }
        List<ActivityManager.RunningTaskInfo> tasksInfo = mActivityManager.getRunningTasks(1);
        if (tasksInfo != null && tasksInfo.size() > 0) {
            ComponentName componentName = tasksInfo.get(0).topActivity;
            if (componentName != null) {
                LogUtil.debugLog("32752", "className->"+componentName.getClassName() + " & packageName->" + componentName.getPackageName());
                if (componentName.getClassName().contains(className)) {
                    return true;
                }
            }
        }
        return false;
    }
 
    public static boolean listIsEmpty(List list){
        return list == null || list.isEmpty();
    }
 
    /**
     * 测量字符高度
     *
     * @param text
     * @return
     */
    public static int getTextHeight(TextPaint textPaint, String text) {
        Rect bounds = new Rect();
        textPaint.getTextBounds(text, 0, text.length(), bounds);
        return bounds.height();
    }
 
    public static boolean isFragmentExist(Fragment fragment){
        return fragment != null && fragment.isAdded() && fragment.isVisible();
    }
 
    public static GradientDrawable createShape(int color, int radius, Context context){
        GradientDrawable drawable = new GradientDrawable();
        drawable.setCornerRadius(UIUtils.dip2px(context, radius));
        drawable.setColor(color);
        return drawable;
    }
 
    public static int makeDropDownMeasureSpec(int measureSpec){
        int mode;
        if(measureSpec == ViewGroup.LayoutParams.WRAP_CONTENT){
            mode = View.MeasureSpec.UNSPECIFIED;
        }else{
            mode = View.MeasureSpec.EXACTLY;
        }
        return View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(measureSpec), mode);
    }
 
    public static int dp2px(Context context, float dpValue){
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dpValue,context.getResources().getDisplayMetrics());
    }
 
    public static float px2dp(Context context, float dpValue){
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,dpValue,context.getResources().getDisplayMetrics());
    }
 
    // 设置view 的margin值
    public static void setMargins(View v, int l, int t, int r, int b) {
        if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
            p.setMargins(l, t, r, b);
            v.requestLayout();
        }
    }
}