| | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.res.Configuration; |
| | | import android.os.Build; |
| | | import android.os.LocaleList; |
| | | import android.os.SystemClock; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | |
| | | import com.hdl.photovoltaic.enums.LowerTagType; |
| | | import com.hdl.photovoltaic.enums.NetworkType; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | import com.hdl.photovoltaic.other.HdlFileLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlMessageLogic; |
| | | import com.hdl.photovoltaic.other.HdlResidenceLogic; |
| | |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | import com.hdl.sdk.link.core.connect.HDLUdpConnect; |
| | | import com.hdl.sdk.link.core.utils.QueueUtils; |
| | | import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; |
| | | import com.umeng.commonsdk.UMConfigure; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Locale; |
| | | import java.util.Objects; |
| | | |
| | | import cn.jpush.android.api.JPushInterface; |
| | |
| | | private Boolean isLogEnabled = true; |
| | | //三方sdk初始化标识 |
| | | private Boolean isInitThirdSDK = false; |
| | | //三方sdk初始化标识 |
| | | /** |
| | | * 三方sdk初始化标识 |
| | | * 在StartActivity里面初始化三方SDK的标识 |
| | | */ |
| | | public Boolean isStartInitThirdSDK = false; |
| | | //声明一个当前应用的实例 |
| | | private static HDLApp mHDLApp; |
| | | //声明一个公共的信息映射,可当作全局变量使用; |
| | |
| | | mHDLApp = this; |
| | | SharedPreUtils.init(this); |
| | | getAppLanguage(); |
| | | //预创建脚本json文件夹 |
| | | HdlFileLogic.getInstance().createHdlESLocalJsonDirectory(); |
| | | init(); |
| | | |
| | | |
| | | } |
| | | |
| | | public void getAppLanguage() { |
| | | String language = UserConfigManage.getInstance().getCurrentAppLanguage(); |
| | | if (TextUtils.isEmpty(language)) { |
| | | //从内存里面获取不到语言,获取当前系统的; |
| | | String str = getResources().getConfiguration().locale.getCountry(); |
| | | if (str.equals("CN") || str.equals("TW")) { |
| | | String str = getResources().getConfiguration().locale.getLanguage(); |
| | | if (str.equals(LocalManageUtil.zh)) { |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.zh); |
| | | } else { |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.en); |
| | |
| | | // //9.初始化网络工具 |
| | | // NetWorkUtil.init(this); |
| | | initAutoSize(); |
| | | //初始化极光推送 |
| | | initJPush(); |
| | | // //初始化极光推送 |
| | | // initJPush(); |
| | | initHDLLinkPMSdk(); |
| | | HDLLinkLocalSdk.getInstance().init(getInstance()); |
| | | initSocket(); |
| | |
| | | this.networkMonitoring(); |
| | | //初始化本地assets文件夹资源文件 |
| | | // this.initLocalAssetsData(); |
| | | //初始化友盟SDK |
| | | initUMengSDK(); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 初始化友盟SDK,抓闪退日志 |
| | | * 集成教程地址:https://developer.umeng.com/docs/119267/detail/118588 |
| | | */ |
| | | private void initUMengSDK() { |
| | | UMConfigure.preInit(this, "6801aec0bc47b67d833fd76d", "XenterraSolar"); |
| | | //appkey和channl必须保持和预初始化一致!!! |
| | | //deviceType:设备类型,UMConfigure.DEVICE_TYPE_PHONE为手机、UMConfigure.DEVICE_TYPE_BOX为盒子 |
| | | //pushSecret:Push推送业务的secret |
| | | UMConfigure.init(this, "6801aec0bc47b67d833fd76d", "XenterraSolar", UMConfigure.DEVICE_TYPE_PHONE, ""); |
| | | UMConfigure.setLogEnabled(false);//AppConfigManage.isDebug() |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | private void initHDLLinkPMSdk() { |
| | | //1.初始化SDK |
| | | HDLLinkPMSdk.initWithAppKey(getInstance(), AppConfigManage.getAppKey(), AppConfigManage.getAppSecret(), AppConfigManage.getAPPRegionUrl()); |
| | | HDLLinkPMSdk.initWithAppKey(this, AppConfigManage.getAppKey(), AppConfigManage.getAppSecret(), AppConfigManage.getAPPRegionUrl()); |
| | | //2.设置打印 |
| | | HDLLinkPMSdk.setLogEnabled(isLogEnabled); |
| | | |
| | | if (TextUtils.isEmpty(UserConfigManage.getInstance().getCurrentAppLanguage())) { |
| | | //默认配置接口请求语言是中文 |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.zh); |
| | | //默认配置接口请求语言是英文 |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.en); |
| | | } |
| | | //3.配置接口请求语言 |
| | | HDLLinkPMSdk.setLanguage(UserConfigManage.getInstance().getCurrentAppLanguage()); |
| | |
| | | HDLLinkPMUser.getInstance().setOnReloginListener(new IOnReloginListener() { |
| | | @Override |
| | | public void onReLogin(int type) { |
| | | HdlLogLogic.print("退到登录界面---" + type, true); |
| | | HdlLogLogic.print("监听到登录退出---" + type, true); |
| | | //type: 0:正常退出 1:极光推送强制退出 |
| | | //收到登录处理通知,关闭所有页面并打开登录页面 |
| | | AppManagerUtils.getAppManager().finishAllActivity(); |
| | |
| | | if (mInfoMap != null) { |
| | | mInfoMap.clear(); |
| | | } |
| | | // //断开mqtt连接 |
| | | // if (MqttRecvClient.getInstance() != null) { |
| | | // MqttRecvClient.getInstance().disConnect(); |
| | | // } |
| | | //断开mqtt连接 |
| | | if (MqttRecvClient.getInstance() != null) { |
| | | MqttRecvClient.getInstance().disConnect(); |
| | | } |
| | | //断开所有tcp连接且清空连接缓存 |
| | | // TODO: 10/10/23 |
| | | // TcpSocketBoot.stopAllConnectLinkGateway(); |
| | |
| | | private void initJPush() { |
| | | JPushInterface.setDebugMode(true); |
| | | JPushInterface.init(getBaseContext()); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | private void initAutoSize() { |
| | | AutoSize.initCompatMultiProcess(this); |
| | | boolean isBaseOnWidth = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; |
| | | AutoSizeConfig.getInstance() |
| | | .setBaseOnWidth(true) |
| | | .setCustomFragment(true) |
| | | .setDesignWidthInDp(375) |
| | | .setDesignHeightInDp(812) |
| | | .setUseDeviceSize(false) |
| | | .setOnAdaptListener(new onAdaptListener() { |
| | | @Override |
| | | public void onAdaptBefore(Object target, Activity activity) { |
| | | AutoSizeConfig.getInstance().setBaseOnWidth(true).setCustomFragment(true).setDesignWidthInDp(375).setDesignHeightInDp(812).setUseDeviceSize(false).setOnAdaptListener(new onAdaptListener() { |
| | | @Override |
| | | public void onAdaptBefore(Object target, Activity activity) { |
| | | |
| | | AutoSizeConfig.getInstance().setScreenWidth(ScreenUtils.getScreenSize(activity)[0]); |
| | | AutoSizeConfig.getInstance().setScreenHeight(ScreenUtils.getScreenSize(activity)[1] + |
| | | ScreenUtils.getHeightOfNavigationBar(activity) + ScreenUtils.getStatusBarHeight()); |
| | | AutoSizeConfig.getInstance().setScreenWidth(ScreenUtils.getScreenSize(activity)[0]); |
| | | AutoSizeConfig.getInstance().setScreenHeight(ScreenUtils.getScreenSize(activity)[1] + ScreenUtils.getHeightOfNavigationBar(activity) + ScreenUtils.getStatusBarHeight()); |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onAdaptAfter(Object target, Activity activity) { |
| | | @Override |
| | | public void onAdaptAfter(Object target, Activity activity) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 初始化uni app mqtt |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | protected void attachBaseContext(Context base) { |
| | | MultiDex.install(base); |
| | | super.attachBaseContext(base); |
| | | } |
| | | |
| | | /** |
| | | * 支持中英文切换 |
| | | */ |
| | | public Context getAppLocaleContext(Context context) { |
| | | try { |
| | | Locale locale = new Locale(UserConfigManage.getInstance().getCurrentAppLanguage()); |
| | | Configuration configuration = context.getResources().getConfiguration(); |
| | | configuration.setLocale(locale); |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| | | configuration.setLocales(new LocaleList(locale)); |
| | | } |
| | | return context.createConfigurationContext(configuration); |
| | | } catch (Exception e) { |
| | | return context; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 支持中英文切换 |
| | | */ |
| | | public Context getAppLocaleContext() { |
| | | try { |
| | | Locale locale = new Locale(UserConfigManage.getInstance().getCurrentAppLanguage()); |
| | | Configuration configuration = getResources().getConfiguration(); |
| | | configuration.setLocale(locale); |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| | | configuration.setLocales(new LocaleList(locale)); |
| | | } |
| | | return createConfigurationContext(configuration); |
| | | } catch (Exception e) { |
| | | return this; |
| | | } |
| | | } |
| | | } |