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;
|
}
|
}
|