mac
2023-11-14 54a8c79222bba0644b02fe1dbc5d75e26ea50b5d
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
package com.hdl.linkpm.sdk;
 
import android.app.Application;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.os.Looper;
import android.widget.Toast;
 
import com.hdl.hdlhttp.HxHttpConfig;
import com.hdl.linkpm.sdk.core.interceptor.HDLEncryptInterceptor;
import com.hdl.linkpm.sdk.core.interceptor.HDLLoginInterceptor;
import com.hdl.linkpm.sdk.core.interceptor.HDLSmartHeaderInterceptor;
import com.hdl.linkpm.sdk.utils.HDLSDKLog;
 
import java.util.Locale;
 
import static android.content.Context.MODE_PRIVATE;
 
/**
 * Created by jlchen on 12/2/21.
 * HDLLinkPMSdk 调试宝、调试软件项目管理SDK
 * 针对B端账号
 */
public class HDLLinkPMSdk {
    public static final String SDK_NAME = "HDLLinkPMSdk";
    private static String appKey;
    private static String appSecret;
    private static String userRegionUrl;
    private static String initUrl;
    private static Application context;
    private static String language = "zh";//配置接口请求响应的语言,不配置默认中文
 
    /**
     * 获取当前Context
     * @return
     */
    public Application getApplication()
    {
        return context;
    }
    /**
     * 初始化SDK
     * @param appKeyStr
     * @param appSecretStr
     */
    public static void initWithAppKey(Application ctx, String appKeyStr, String appSecretStr,String url){
        context = ctx;
        appKey = appKeyStr;
        appSecret = appSecretStr;
        initUrl = url;
        userRegionUrl=url;
        initHxHttpConfig();
//        HDLSDKLog.i("init HDLLinkPMSdk:"+regionUrlStr);
    }
 
 
    public static boolean isDebugVersion() {
        try {
            ApplicationInfo info = context.getApplicationInfo();
            return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
 
    public static void showToast(String msg){
//        runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
//                try {
//                    if (toast == null) {
//                        toast = Toast.makeText(HDLGlobal.getInstance().getContext(), message, Toast.LENGTH_SHORT);
//                    } else {
//                        toast.setText(message);
//                    }
//                    toast.show();
//                } catch (Exception ignored) {
//
//                }
//            }
//
//        });
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }
 
    public static void runOnUiThread(Runnable run) {
        //判读是否已经在主线程
        if (Looper.getMainLooper() == Looper.myLooper()) {
            run.run();
        }
    }
 
 
    public static String getInitUrl() {
        return initUrl == null ? "" : initUrl;
    }
 
    public static String get_USER_REGIONURL_ONLINE(){
        SharedPreferences sp1 = context.getSharedPreferences("USER_REGIONURL_ONLINE", MODE_PRIVATE);
        //如果SoundCode,获取的值是空的,则会弹出后面的默认值
        String obtain = sp1.getString("USER_REGIONURL_ONLINE", "https://nearest.hdlcontrol.com");
 
        return obtain;
    }
 
    public static void edit_USER_REGIONURL_ONLINE(String url){
        userRegionUrl =url;
        SharedPreferences sp = context.getSharedPreferences("USER_REGIONURL_ONLINE", MODE_PRIVATE);
        sp.edit().putString("USER_REGIONURL_ONLINE",url).apply();//apply才会写入到xml配置文件里面
    }
 
    /**
     * 初初始化网络请求库配置
     * 注意!!!
     * 请求参数不是数组或对象类型的不能用表单.params(XXX)的方式添加请求参数
     */
    static void initHxHttpConfig(){
        HxHttpConfig.getInstance().init(context, userRegionUrl)
                //.setConnectTimeout()//配置默认请求超时时间
                .addInterceptor(new HDLLoginInterceptor(),
                        new HDLEncryptInterceptor(),
                        new HDLSmartHeaderInterceptor());
    }
 
    public static void destroy() {
 
    }
 
 
    /**
     * 设置打印是否开启
     * @param enable-
     */
    public static void setLogEnabled(boolean enable){
        HDLSDKLog.setHDLSDKLogOpen(enable);
    }
 
    public static String getAppKey() {
        return appKey;
    }
 
    public static String getAppSecret() {
        return appSecret;
    }
 
    public static String getUserRegionUrl() {
        if (userRegionUrl == null) {
            userRegionUrl = get_USER_REGIONURL_ONLINE();
        }
        return userRegionUrl;
    }
 
    public static boolean isZh() {
        Locale locale = getContext().getResources().getConfiguration().locale;
        String language = locale.getLanguage();
        if (language.endsWith("zh"))
            return true;
        else
            return false;
    }
 
    public static Application getContext() {
        return context;
    }
 
    public static String getLanguage() {
        return language;
    }
 
    public static void setLanguage(String language) {
        HDLLinkPMSdk.language = language;
    }
}