admin
2020-10-14 b2fc802bf35143ed957a86d95e2de49934ea9ea5
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
package com.weikou.beibeivideo.util.browser;
 
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import android.webkit.JavascriptInterface;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.lcjian.library.util.common.StringUtils;
import com.tencent.smtt.sdk.WebView;
import com.weikou.beibeivideo.util.AlibcTradeUtil;
import com.weikou.beibeivideo.util.JumpActivityUtil;
 
import org.json.JSONException;
import org.json.JSONObject;
 
import java.util.Iterator;
 
public class BWJavaInterface extends BaseBWJavaInterface {
 
    Activity mContext;
    TextView tv_top_bar_middle, tv_top_bar_left2, tv_top_bar_right;
    ImageView iv_right;
    WebView webview;
    private boolean boo = false;
 
    public BWJavaInterface(Activity activity, WebView webview) {
        super(activity);
        mContext = activity;
        this.webview = webview;
        boo = true;
    }
 
    public BWJavaInterface(Activity activity, TextView tv_top_bar_middle
            , TextView tv_top_bar_left2, TextView tv_top_bar_right
            , ImageView iv_right, WebView webview) {
        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;
    }
 
    @JavascriptInterface
    public void setTitle(final String 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);
                }
            });
    }
 
 
    @JavascriptInterface
    public void jumpPageWithFinishCurrentPage(String pageClassName, String 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();
    }
 
    @JavascriptInterface
    public void finishPage() {
        if (!boo)
            iv_right.post(new Runnable() {
                @Override
                public void run() {
                    mContext.finish();
                }
            });
    }
 
    /**
     * 淘宝授权
     *
     * @param url
     */
    @JavascriptInterface
    public void tbAuth(String url) {
        if (StringUtils.isEmpty(url))
            return;
        AlibcTradeUtil.openAuthLink(mContext, url);
    }
 
    // 判断权限集合 是否授权 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;
    }
}