From d723fee177238df0dbab80eb788876ebd154927d Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期四, 24 十月 2024 11:55:46 +0800 Subject: [PATCH] Update HDLLoginInterceptor.java --- HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/HDLLinkPMSdk.java | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 174 insertions(+), 0 deletions(-) diff --git a/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/HDLLinkPMSdk.java b/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/HDLLinkPMSdk.java new file mode 100644 index 0000000..938a708 --- /dev/null +++ b/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/HDLLinkPMSdk.java @@ -0,0 +1,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 璋冭瘯瀹濄�佽皟璇曡蒋浠堕」鐩鐞哠DK + * 閽堝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; + } + /** + * 鍒濆鍖朣DK + * @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鎵嶄細鍐欏叆鍒皒ml閰嶇疆鏂囦欢閲岄潰 + } + + /** + * 鍒濆垵濮嬪寲缃戠粶璇锋眰搴撻厤缃� + * 娉ㄦ剰锛侊紒锛� + * 璇锋眰鍙傛暟涓嶆槸鏁扮粍鎴栧璞$被鍨嬬殑涓嶈兘鐢ㄨ〃鍗�.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; + } +} \ No newline at end of file -- Gitblit v1.8.0