admin
2022-01-10 2800e0df4c2324b617b7cbc23945e799144dcdd8
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
package com.ysvideo.zhibo.app.util.browser;
 
import android.app.Activity;
import android.content.Intent;
import android.webkit.JavascriptInterface;
import android.widget.Toast;
 
import com.alibaba.fastjson.JSON;
import com.ysvideo.zhibo.app.R;
import com.ysvideo.zhibo.app.util.JumpActivityUtil;
import com.ysvideo.zhibo.app.util.api.HttpApiUtil;
import com.ysvideo.zhibo.lib.common.util.security.DEScrypt;
import com.ysvideo.zhibo.library_ec.AlibcTradeUtil;
import com.google.gson.Gson;
import com.ysvideo.zhibo.lib.common.util.common.ClipboardUtil;
import com.ysvideo.zhibo.lib.common.util.common.PackageUtils2;
import com.ysvideo.zhibo.lib.common.util.common.StringUtils;
import com.umeng.analytics.MobclickAgent;
 
import org.json.JSONException;
import org.json.JSONObject;
 
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
 
import static android.content.Context.MODE_PRIVATE;
 
public class BaseJavaInterface {
 
    Activity mContext;
 
    public BaseJavaInterface(Activity activity) {
        mContext = activity;
    }
 
    @JavascriptInterface
    public String getUid() {
        return mContext.getSharedPreferences("user", MODE_PRIVATE).getString("LoginUid", "");
    }
 
 
    @JavascriptInterface
    public String getVersion() {
        return PackageUtils2.getVersionCode(mContext) + "";
    }
 
 
    @JavascriptInterface
    public String getAppName() {
        return mContext.getString(R.string.app_name) + "";
    }
 
    @JavascriptInterface
    public void toast(String str) {
        Toast.makeText(mContext, str, Toast.LENGTH_LONG).show();
    }
 
    @JavascriptInterface
    public void jumpBaiChuan(String tbClientInfo, String url) {
        AlibcTradeUtil.openUrl(mContext, url, null, null, null, null);
    }
 
    @JavascriptInterface
    public void copyText(String atr) {
        ClipboardUtil.copy(mContext, atr);
    }
 
 
    @JavascriptInterface
    public String apiDecode(String result) {
        return DEScrypt.decode(result);
    }
 
 
    @JavascriptInterface
    public void jumpPage(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);
    }
 
    @JavascriptInterface
    public String getRequestBaseParams(String json) {
        LinkedHashMap<String, String> params = new LinkedHashMap<>();
        if (!StringUtils.isEmpty(json)) {
            JSONObject jsonObject = null;
            try {
                jsonObject = new JSONObject(json);
                Iterator<String> iterator = jsonObject.keys();
                while (iterator.hasNext()) {
                    String key = iterator.next();
                    params.put(key, jsonObject.optString(key));
                }
            } catch (JSONException e) {
 
            }
        }
        LinkedHashMap<String, String> map = HttpApiUtil.getRequestParams(mContext, params);
 
        Gson gson = new Gson();
        String str = gson.toJson(map);
        return str;
    }
 
    @JavascriptInterface
    public void umEventCount(String eventId, String paramsJSON) {
        Map map = JSON.parseObject(paramsJSON);
    }
 
    @JavascriptInterface
    public void umEventCompute(String eventId, String paramsJSON, int du) {
        Map map = JSON.parseObject(paramsJSON);
        MobclickAgent.onEventValue(mContext, eventId, map, du);
    }
 
 
    /**
     * 清空粘贴板
     */
    @JavascriptInterface
    public void clearClipboard() {
        ClipboardUtil.emptyClipboard(mContext);
    }
}