admin
2021-07-06 abce02c7a61820f5d580f87364d542e817be429c
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
package com.tejia.lijin.app.util.web;
 
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.bumptech.glide.Glide;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTRewardVideoAd;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.kepler.jd.Listener.OpenAppAction;
import com.kepler.jd.login.KeplerApiManager;
import com.kepler.jd.sdk.bean.KeplerAttachParameter;
import com.tejia.lijin.app.Interface.WebInterface;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.callBack.GeneralBackCallback;
import com.tejia.lijin.app.callBack.PermissionInterface;
import com.tejia.lijin.app.entity.ImgText;
import com.tejia.lijin.app.entity.JumpDetail;
import com.tejia.lijin.app.entity.share.ShareImageEntity;
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
import com.tejia.lijin.app.updateApp.UpdateApp;
import com.tejia.lijin.app.util.JumpActivityUtil;
import com.tejia.lijin.app.util.PermissionHelper;
import com.tejia.lijin.app.util.ToastUtil;
import com.tejia.lijin.app.util.Tools;
import com.tejia.lijin.app.util.baichuan.AlibcTradeUtil;
import com.tejia.lijin.app.util.share.ShareImageUtil;
import com.tejia.lijin.app.util.share.ShareTextUtil;
import com.wpc.library.util.common.DimenUtils;
import com.wpc.library.util.common.StringUtils;
import com.wpc.library.util.security.MD5Utils;
import com.ysh.wpc.appupdate.download.DownLoadFile;
 
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
 
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
import androidx.core.content.ContextCompat;
import wendu.dsbridge.CompletionHandler;
 
public class RebateJavaInterfaceBS extends BaseRebateJavaInterfaceBS implements PermissionInterface {
 
    Activity mContext;
    TextView tv_top_bar_middle, tv_top_bar_left2, tv_top_bar_right;
    ImageView iv_right;
    WebView webview;
    ShapeLoadingDialog pd;
    private boolean boo = false;
    private PermissionHelper mPermissionsChecker; // 权限检测器
 
    public RebateJavaInterfaceBS(Activity activity, WebView webview) {
        super(activity);
        mContext = activity;
        this.webview = webview;
        boo = true;
    }
 
    public RebateJavaInterfaceBS(Activity activity, TextView tv_top_bar_middle
            , TextView tv_top_bar_left2, TextView tv_top_bar_right
            , ImageView iv_right, WebView webview, ShapeLoadingDialog pd) {
        super(activity);
        mContext = activity;
        this.tv_top_bar_middle = tv_top_bar_middle;
        this.tv_top_bar_left2 = tv_top_bar_left2;
        this.tv_top_bar_right = tv_top_bar_right;
        this.iv_right = iv_right;
        this.webview = webview;
        this.pd = pd;
    }
 
    @JavascriptInterface
    public void setTitle(final Object title) {
//            tv_top_bar_middle.setText(title);
        if (!boo)
            tv_top_bar_middle.post(new Runnable() {
                @Override
                public void run() {
                    if (null != title && !StringUtils.isEmpty((title + "").trim()))
                        tv_top_bar_middle.setText(title + "");
                }
            });
    }
 
    /**
     * 保存网络图片
     *
     * @param url
     */
    @JavascriptInterface
    public void savePicture(Object url) {
        if (mPermissionsChecker == null)
            mPermissionsChecker = new PermissionHelper(mContext, this);
        if (mPermissionsChecker.lacksPermissions(getPermissions())) { //存储权限未开启
            mPermissionsChecker.showNormalDialog();
        } else {//存储权限已开
            String md5 = MD5Utils.getMD532(url.toString());
            String path = com.wpc.library.util.Environment.getExternalStorageDirectory()
                    + "/tejiaapp";
            File file = new File(path + "/" + md5 + ".jpg");
            if (!file.exists()) {
                try {
                    File resultFile = Tools.saveImageFromPathToSdCard(mContext, url.toString(), path, md5 + ".jpg");
                    if (resultFile != null) {
                        Toast.makeText(mContext, "图片保存到相册成功", Toast.LENGTH_LONG).show();
                    }
                } catch (Exception e) {
                    Toast.makeText(mContext, "图片保存失败", Toast.LENGTH_LONG).show();
                    if (file.exists())
                        file.delete();
                }
 
            } else {
                Toast.makeText(mContext, "图片已经保存!", Toast.LENGTH_LONG).show();
            }
        }
    }
 
 
    /**
     * 异步保存图片
     *
     * @param args
     * @param handler
     * @throws JSONException
     */
    public void savePictureAsync(Object args, final CompletionHandler handler) throws JSONException {
        JSONObject jsonObject = new JSONObject(args.toString());
        String url = jsonObject.optString("url");
        if (mPermissionsChecker == null)
            mPermissionsChecker = new PermissionHelper(mContext, this);
        if (mPermissionsChecker.lacksPermissions(getPermissions())) { //存储权限未开启
            mPermissionsChecker.showNormalDialog();
        } else {//存储权限已开
            String md5 = MD5Utils.getMD532(url);
            String path = com.wpc.library.util.Environment.getExternalStorageDirectory()
                    + "/tejiaapp";
            File file = new File(path + "/" + md5 + ".jpg");
            if (!file.exists()) {
                try {
                    File resultFile = Tools.saveImageFromPathToSdCard(mContext, url, path, md5 + ".jpg");
                    if (resultFile != null) {
                        JSONObject result = new JSONObject();
                        result.put("code", 0);
                        result.put("msg", "保存成功");
                        handler.complete(result);
                    }
                } catch (Exception e) {
                    JSONObject result = new JSONObject();
                    result.put("code", 1);
                    result.put("msg", "图片保存失败");
                    handler.complete(result);
                    if (file.exists())
                        file.delete();
                }
 
            } else {
                JSONObject result = new JSONObject();
                result.put("code", 2);
                result.put("msg", "图片已经保存");
                handler.complete(result);
            }
        }
    }
 
 
    @JavascriptInterface
    public void savePictures(Object urls) {
        if (mPermissionsChecker == null)
            mPermissionsChecker = new PermissionHelper(mContext, this);
        if (mPermissionsChecker.lacksPermissions(getPermissions())) { //存储权限未开启
            mPermissionsChecker.showNormalDialog();
        } else {//存储权限已开
            List<String> urlList = new ArrayList<>();
            try {
                JSONArray array = new JSONArray(urls.toString());
                for (int i = 0; i < array.length(); i++) {
                    urlList.add(array.optString(i));
                }
            } catch (Exception e) {
 
            }
 
            if (urlList != null && urlList.size() > 0)
                try {
                    startDownLoadImages(urlList, type, 2);
                } catch (Exception e) {
                }
        }
    }
 
 
    @JavascriptInterface
    public void setTopMenuRightIcon(Object args) throws JSONException {
        JSONObject json = new JSONObject(args.toString());
        final String picUrl = json.optString("picUrl");
        final String jsCallback = json.optString("jsCallback");
 
        if (!boo)
            iv_right.post(new Runnable() {
                @Override
                public void run() {
                    iv_right.setVisibility(View.VISIBLE);
                    Glide.with(mContext).load(picUrl).into(iv_right);
                    iv_right.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
//                            Log.e("mResult", jsCallback);
                            webview.loadUrl("javascript:" + jsCallback);
                        }
                    });
                }
            });
    }
 
    @JavascriptInterface
    public void jumpPageWithFinishCurrentPage(Object args) throws JSONException {
        JSONObject json = new JSONObject(args.toString());
        final String pageClassName = json.optString("pageClassName");
        final String paramJson = json.optString("paramJson");
 
 
        Intent intent = null;
        JSONObject param = null;
        try {
            if (StringUtils.isEmpty(paramJson)) {
                param = null;
            } else {
                param = new JSONObject(paramJson);
            }
            if (StringUtils.isEmpty(pageClassName)) {
                return;
            } else {
                intent = new Intent(mContext, Class.forName(JumpActivityUtil.filterActivityName(pageClassName)));
            }
        } catch (JSONException e) {
            param = null;
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (null != param) {
            @SuppressWarnings("unchecked")
            Iterator<String> its = param.keys();
            while (its.hasNext()) {
                String key = its.next();
                String value = param.optString(key);
                intent.putExtra(key, value);
            }
        }
        mContext.startActivity(intent);
        if (!boo)
            mContext.finish();
    }
 
 
    /**
     * 跳转三方平台
     *
     * @param args
     * @throws JSONException
     */
    @JavascriptInterface
    public void jumpThirdPlatform(Object args) throws JSONException {
        JSONObject json = new JSONObject(args.toString());
        JumpDetail jumpDetail = new JumpDetail();
        jumpDetail.setType("thirdPlatform");
        JumpActivityUtil.jumpPage(mContext, jumpDetail, com.alibaba.fastjson.JSONObject.parseObject(json.toString()));
    }
 
 
    @JavascriptInterface
    public void hiddenTopMenuCloseBtn(Object obj) {
        if (!boo)
            tv_top_bar_left2.setVisibility(View.GONE);
    }
 
 
    @JavascriptInterface
    public void hideLoading(Object obj) {
        if (!boo)
            iv_right.post(new Runnable() {
                @Override
                public void run() {
                    if (pd != null && pd.isShowing())
                        pd.dismiss();
                }
            });
 
    }
 
    @JavascriptInterface
    public void showLoading(Object obj) {
        if (!boo)
            iv_right.post(new Runnable() {
                @Override
                public void run() {
                    if (pd == null) {
                        pd = new ShapeLoadingDialog.Builder(mContext).build();
                    }
                    pd.show();
                }
            });
 
    }
 
    @JavascriptInterface
    public void finishPage(Object obj) {
        if (!boo)
            iv_right.post(new Runnable() {
                @Override
                public void run() {
                    mContext.finish();
                }
            });
    }
 
 
    @JavascriptInterface
    public void setTopMenuRightText(Object args) throws JSONException {
        JSONObject json = new JSONObject(args.toString());
        final String callbackMethod = json.optString("callbackMethod");
        final String text = json.optString("text");
 
        if (!boo)
            tv_top_bar_right.post(new Runnable() {
                @Override
                public void run() {
                    tv_top_bar_right.setText(text);
                    tv_top_bar_right.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            webview.loadUrl("javascript:" + callbackMethod);
                        }
                    });
                }
            });
    }
 
 
    public List<ImgText> mList = new ArrayList<>();
 
    @JavascriptInterface
    public void addMenu(Object str) {
        Gson gson = new GsonBuilder().serializeNulls().create();
        List<ImgText> list = gson.fromJson(str + "", new TypeToken<List<ImgText>>() {
        }.getType());
        if (mList.size() > 0)
            mList.clear();
        mList.addAll(list);
    }
 
 
    @JavascriptInterface
    public void showSharePanel(Object obj) {
        webShareDesc.setShare();
    }
 
    //文本分享
    @JavascriptInterface
    public void shareText(Object args) throws JSONException {
        JSONObject json = new JSONObject(args.toString());
        int type = json.optInt("type");
        final String text = json.optString("text");
 
        if (type == 1) {
            ShareTextUtil.shareWXTextByIntent(mContext, text);
        } else if (type == 2) {
            ShareTextUtil.shareWXCircleTextByIntent(mContext, text);
        } else if (type == 3) {
            ShareTextUtil.shareQQTextByIntent(mContext, text);
        } else if (type == 4) {
            ShareTextUtil.shareQQZoneTextByIntent(mContext, text);
        } else {
            ShareTextUtil.shareSinaTextByIntent(mContext, text);
        }
    }
 
    //图片分享  "type":1,//1-微信  2-朋友圈  3-QQ  4-空间  5-微博 6-更多
    @JavascriptInterface
    public void shareImg(Object args) throws JSONException {
 
        JSONObject json = new JSONObject(args.toString());
        int type = json.optInt("type");
        final String url = json.optString("url");
 
        if (mPermissionsChecker == null)
            mPermissionsChecker = new PermissionHelper(mContext, this);
        if (mPermissionsChecker.lacksPermissions(getPermissions())) { //存储权限未开启
            mPermissionsChecker.showNormalDialog();
        } else {
            this.type = type;
            this.imgurl = url;
            new Thread() {
                public void run() {
                    Bitmap bitmap = getNetImage(url);//从网络下载图片
                    Message msg = new Message();
                    Bundle data = new Bundle();
                    data.putParcelable("bitmap", bitmap);
                    msg.setData(data);
                    msg.what = 1001;
                    handler.sendMessage(msg);
                }
            }.start();
        }
 
    }
 
    /**
     * 多图分享
     *
     * @param args
     */
    @JavascriptInterface
    public void shareImgs(Object args) throws JSONException {
        JSONObject json = new JSONObject(args.toString());
        int type = json.optInt("type");
        final String urls = json.optString("urls");
 
 
        if (mPermissionsChecker == null)
            mPermissionsChecker = new PermissionHelper(mContext, this);
        if (mPermissionsChecker.lacksPermissions(getPermissions())) { //存储权限未开启
            mPermissionsChecker.showNormalDialog();
        } else {
            List<String> urlList = new ArrayList<>();
            try {
                JSONArray array = new JSONArray(urls);
                for (int i = 0; i < array.length(); i++) {
                    urlList.add(array.optString(i));
                }
            } catch (Exception e) {
 
            }
 
            if (urlList != null && urlList.size() > 0)
                try {
                    startDownLoadImages(urlList, type, 1);
                } catch (Exception e) {
 
                }
        }
    }
 
    /**
     * 淘宝授权
     *
     * @param url
     */
    @JavascriptInterface
    public void tbAuth(Object url) {
        if (StringUtils.isEmpty(url + ""))
            return;
        AlibcTradeUtil.openAuthLink(mContext, url + "");
    }
 
    /**
     * 跳转到京东
     *
     * @param url
     */
    @JavascriptInterface
    public void jumpJD(Object url) {
        if (StringUtils.isEmpty(url + ""))
            return;
        KeplerApiManager.getWebViewService().openAppWebViewPage(mContext, url + "", new KeplerAttachParameter(), new OpenAppAction() {
            @Override
            public void onStatus(final int status, final String url) {
                mContext.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (status == OpenAppAction.OpenAppAction_result_APP) {
                            //呼京东成功
                            Log.e("mResult", "呼京东成功");
                        } else if (status == OpenAppAction.OpenAppAction_start) {
                            //开始状态未必一定执行,
                            Log.e("mResult", "开始呼起京东");
                        } else {
                            //唤起京东失败
                            Log.e("mResult", "唤起京东失败" + status);
                            Intent intent = new Intent(mContext, ShareBrowserActivity.class);
                            intent.putExtra("url", url);
                            mContext.startActivity(intent);
                        }
                    }
                });
            }
        });
    }
 
 
    private TTRewardVideoAd mttRewardVideoAd;
 
    @JavascriptInterface
    public void showAwardAd(Object args, final CompletionHandler handler) throws JSONException {
        JSONObject json = new JSONObject(args.toString());
        String type = json.optString("type");
        final String pid = json.optString("pid");
        final com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
 
        webview.post(new Runnable() {
            @Override
            public void run() {
 
                TTAdNative mTTAdNative = TTAdSdk.getAdManager().createAdNative(mContext);
                AdSlot adSlot = new AdSlot.Builder()
                        .setCodeId(pid)
                        .setRewardName("金币") //奖励的名称 选填
                        .setRewardAmount(3)  //奖励的数量 选填
//                        .setUserID("tag123")//tag_id
                        .setMediaExtra("media_extra") //附加参数
                        .setOrientation(TTAdConstant.VERTICAL) //必填参数,期望视频的播放方向:TTAdConstant.HORIZONTAL 或 TTAdConstant.VERTICAL
                        .build();
 
                mTTAdNative.loadRewardVideoAd(adSlot, new TTAdNative.RewardVideoAdListener() {
                    //请求广告失败
                    @Override
                    public void onError(int code, String message) {
                        com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
                        result.put("code", 1);
                        result.put("msg", message);
                        handler.complete(result);
                    }
 
                    //视频广告加载后,视频资源缓存到本地的回调,在此回调后,播放本地视频,流畅不阻塞。
                    @Override
                    public void onRewardVideoCached() {
 
                        //开发者做一个标识
                        if (mttRewardVideoAd != null) {
                            mttRewardVideoAd.showRewardVideoAd(mContext, TTAdConstant.RitScenes.CUSTOMIZE_SCENES, "scenes_test");
                            mttRewardVideoAd = null;
                        }
                        com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
                        result.put("code", 100);
                        result.put("msg", "缓存成功");
                        handler.setProgressData(result);
                    }
 
                    //视频广告的素材加载完毕,比如视频url等,在此回调后,可以播放在线视频,网络不好可能出现加载缓冲,影响体验。
                    @Override
                    public void onRewardVideoAdLoad(TTRewardVideoAd ad) {
                        //开发者做一个标识
                        mttRewardVideoAd = ad;
                        mttRewardVideoAd.setRewardAdInteractionListener(new TTRewardVideoAd.RewardAdInteractionListener() {
                            @Override
                            public void onAdShow() {
                                com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
                                result.put("code", 201);
                                result.put("msg", "广告开始展示");
                                handler.setProgressData(result);
                            }
 
                            @Override
                            public void onAdVideoBarClick() {
 
                            }
 
                            @Override
                            public void onAdClose() {
 
                            }
 
                            @Override
                            public void onVideoComplete() {
 
                            }
 
                            @Override
                            public void onVideoError() {
                                com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
                                result.put("code", 2);
                                result.put("msg", "视频出错");
                                handler.complete(result);
                            }
 
                            @Override
                            public void onRewardVerify(boolean b, int i, String s, int i1, String s1) {
                                com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
                                result.put("code", 0);
                                result.put("msg", "广告展示完成");
                                handler.complete(result);
                            }
 
                            @Override
                            public void onSkippedVideo() {
 
                            }
                        });
                    }
                });
 
            }
        });
 
    }
 
 
    @JavascriptInterface
    public void toastAwardSuccess(final Object msg) {
 
        webview.post(new Runnable() {
            @Override
            public void run() {
                View view = LayoutInflater.from(mContext).inflate(R.layout.item_reward_ad_success, null);
                TextView tv_content = view.findViewById(R.id.tv_content);
                tv_content.setText(msg + "");
                ToastUtil.showToast(view, view.getContext(), Toast.LENGTH_SHORT, Gravity.CENTER);
            }
        });
    }
 
    @JavascriptInterface
    public void toastAwardFail(final Object msg) {
        webview.post(new Runnable() {
            @Override
            public void run() {
                View view = LayoutInflater.from(mContext).inflate(R.layout.item_reward_ad_fail, null);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DimenUtils.getScreenWidth(mContext) * 4 / 5, LinearLayout.LayoutParams.WRAP_CONTENT);
                view.setLayoutParams(params);
                TextView tv_content = view.findViewById(R.id.tv_content);
                tv_content.setText(msg + "");
                ToastUtil.showToast(view, view.getContext(), Toast.LENGTH_SHORT, Gravity.CENTER);
            }
        });
    }
 
 
    @JavascriptInterface
    public void checkUpdate(Object obj) {
        UpdateApp app = new UpdateApp(mContext, mContext.getResources().getString(R.string.update_key));
        app.getUpdateInfo(new UpdateApp.UpdateJudgeCallback() {
 
            @Override
            public void onSuccess(boolean show) {
 
            }
 
            @Override
            public void closeUpdate(boolean close) {
 
            }
 
            @Override
            public void onFinish() {
 
            }
        }, true);//强制检测更新
    }
 
 
    int type;
    String imgurl;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1001) {
                Bitmap bitmap = msg.getData().getParcelable("bitmap");
                shareImg(type, "", "", bitmap);
            }
        }
    };
 
 
    private Handler shareHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            ArrayList<Uri> uriList = new ArrayList<Uri>();
            if (shareTempImgEntity != null)
                for (ShareImageEntity entity : shareTempImgEntity)
                    uriList.add(Tools.getImageContentUri(mContext, new File(entity.getFilePath())));
            switch (msg.what) {
                case 1://微信
                    ShareImageUtil.shareWXPictureByIntent(mContext, uriList);
                    break;
                case 2://朋友圈
                    ShareImageUtil.shareWXCirclePictureByIntent(mContext, uriList);
                    break;
                case 3://QQ
                    ShareImageUtil.shareQQPictureByIntent(mContext, uriList);
                    break;
 
                case 4://QQ空间
                    ShareImageUtil.shareQQZonePictureByIntent(mContext, uriList);
                    break;
                case 5://微博
                    ShareImageUtil.shareSinaPictureByIntent(mContext, uriList);
                    break;
                case 6://更多
                    Intent mulIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
                    mulIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
                    mulIntent.setType("image/png");
                    mContext.startActivity(Intent.createChooser(mulIntent, "多图文件分享"));
                    break;
            }
 
        }
    };
 
    private ArrayList<ShareImageEntity> shareTempImgEntity;
 
    /**
     * 下载图片
     *
     * @param urlList
     * @param platform
     * @param type     1-分享 2-下载
     * @throws Exception
     */
    private void startDownLoadImages(List<String> urlList, final int platform, final int type) throws Exception {
        String path = null;
 
        if (type == 1) {
            path = Environment.getExternalStorageDirectory()
                    + "/rebateshare";
        } else if (type == 2) {
            path = com.wpc.library.util.Environment.getExternalStorageDirectory()
                    + "/tejiaapp";
        }
        final File storageDir = new File(path);
        List<String> filePathList = new ArrayList<>();
        for (String picture : urlList) {
            String fileName = storageDir.getPath() + "/" + System.currentTimeMillis() + "_" + (long) (Math.random() * 10000000000L) + ".png";
            filePathList.add(fileName);
        }
 
        if (urlList.size() > 0) {
            showLoading(null);
            shareTempImgEntity = new ArrayList<>();
            //去下载
            new DownLoadFile().downloadMultiImages(urlList, filePathList, mContext, new DownLoadFile.FileDownLoadListener() {
                @Override
                public void finish(List<File> fileList) {
                    hideLoading(null);
                    //完成下载
 
                    if (fileList != null)
                        for (File f : fileList) {
                            shareTempImgEntity.add(new ShareImageEntity(f.getPath()));
                        }
                    //下载成功
                    if (type == 1)
                        shareHandler.sendEmptyMessage(platform);
                    else {
                        final String[] filePaths = new String[fileList.size()];
                        for (int i = 0; i < filePaths.length; i++)
                            filePaths[i] = fileList.get(i).getPath();
                        shareHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                MediaScannerConnection.scanFile(mContext, filePaths, null, null);
                                Toast.makeText(mContext, "保存到相册成功", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }
 
                @Override
                public void process(int count) {
                }
            });
        } else {
            hideLoading(null);
            if (type == 1)
                shareHandler.sendEmptyMessage(platform);
            else {
                shareHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mContext, "保存到相册成功", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    }
 
 
    /*******分享图片**/
    private void shareImg(final int platfrom, final String title, final String message, final Bitmap bitmap) {
        if (bitmap == null)
            return;
        int wchatAvilibleValue = Tools.isWeixinAvilible(mContext);
        int qqAvilibleValue = Tools.isQQAvilible(mContext);
        int sinaAvilibleValue = Tools.isSinaAvilible(mContext);
        if (((platfrom == 1 || platfrom == 2) && (wchatAvilibleValue == 1 || wchatAvilibleValue == 2))
                || (platfrom == 3 && (qqAvilibleValue == 1 || qqAvilibleValue == 2))
                || (platfrom == 5 && (sinaAvilibleValue == 1 || sinaAvilibleValue == 2))) {
            mContext.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(mContext, "未检测到第三方应用", Toast.LENGTH_SHORT).show();
                }
            });
        } else {
            String path = Environment.getExternalStorageDirectory()
                    + "/rebateshare";
            File storageDir = new File(path);
            if (storageDir.isDirectory()) {
                try {
                    File files[] = storageDir.listFiles();
                    for (int i = 0; i < files.length; i++) {
//                        deleteFolderFile(files[i].getAbsolutePath());
                        files[i].delete();
                    }
                    if (!storageDir.isDirectory()) {
                        storageDir.delete();
                    } else {
                        if (storageDir.listFiles().length == 0) {
                            storageDir.delete();
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
 
//            files.clear();
            final Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    File file = Tools.saveBitmap(mContext, bitmap);
                    ArrayList<ShareImageEntity> imageList = new ArrayList<>();
                    imageList.add(new ShareImageEntity(file.getPath()));
 
                    ArrayList<Uri> uriList = new ArrayList<Uri>();
                    if (imageList != null)
                        for (ShareImageEntity entity : imageList)
                            uriList.add(Tools.getImageContentUri(mContext, new File(entity.getFilePath())));
 
                    if (platfrom == 1) {
                        ShareImageUtil.shareWXPictureByIntent(mContext, uriList);
                    } else if (platfrom == 2) {
                        ShareImageUtil.shareWXCirclePictureByIntent(mContext, uriList);
                    } else if (platfrom == 3) {
                        ShareImageUtil.shareQQPictureByIntent(mContext, uriList);
                    } else if (platfrom == 4) {
                        ShareImageUtil.shareQQZonePictureByIntent(mContext, uriList);
                    } else {
                        ShareImageUtil.shareSinaPictureByIntent(mContext, uriList);
                    }
                    if (pd != null)
                        pd.dismiss();
                }
            });
            thread.start();
        }
    }
 
    private Bitmap getNetImage(String url) {
//            Log.e("mResult", "getNetImage---" + url);
        URL fileUrl = null;
        Bitmap bitmap = null;
        try {
            fileUrl = new URL(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        if (fileUrl == null)
            return null;
        try {
            HttpURLConnection conn = (HttpURLConnection) fileUrl.openConnection();
            conn.setDoInput(true);
            conn.connect();
            InputStream is = conn.getInputStream();
            bitmap = BitmapFactory.decodeStream(is);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return bitmap;
    }
 
    // 判断权限集合 是否授权 false授权 true未授权
    public boolean lacksPermissions(String... permissions) {
        for (String permission : permissions) {
            if (lacksPermission(permission)) {
                return true;
            }
        }
        return false;
    }
 
    // 判断是否缺少权限
    private boolean lacksPermission(String permission) {
        //权限未授权
        return ContextCompat.checkSelfPermission(mContext, permission) == PackageManager.PERMISSION_DENIED;
    }
 
    private WebInterface webShareDesc;  //定义
 
    public void setWebShareDesc(WebInterface WebShareDesc) {
        this.webShareDesc = WebShareDesc;
    }
 
    private GeneralBackCallback generalBackCallback;  //定义 分享图片接口 检查权限传入网页调用type url参数
 
    public void setGeneralBackCallback(GeneralBackCallback messageCallback) {
        this.generalBackCallback = messageCallback;
    }
 
    @Override
    public int getPermissionsRequestCode() {
        return 1001;
    }
 
    /**
     * 请求权限
     *
     * @return
     */
    @Override
    public String[] getPermissions() {
        return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE};
    }
 
    /**
     * 权限请求成功
     */
    @Override
    public void requestPermissionsSuccess() {
 
    }
 
    /**
     * 权限请求失败
     */
    @Override
    public void requestPermissionsFail() {
//        Toast.makeText(this, "你以拒绝权限", Toast.LENGTH_SHORT).show();
    }
 
}