| | |
| | | package com.hdl.photovoltaic; |
| | | |
| | | import android.app.Application; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageManager; |
| | | import android.location.Location; |
| | | import android.location.LocationListener; |
| | | import android.location.LocationManager; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.core.app.ActivityCompat; |
| | | |
| | | import com.hdl.hdlhttp.HxHttpConfig; |
| | | import com.hdl.linkpm.sdk.HDLLinkPMSdk; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.home.type.HomeType; |
| | | import com.hdl.linkpm.sdk.user.HDLLinkPMUser; |
| | | import com.hdl.linkpm.sdk.user.callback.IOnReloginListener; |
| | | import com.hdl.linkpm.sdk.utils.HDLSDKSPUtils; |
| | | import com.hdl.photovoltaic.bean.MqttInfo; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.enums.NetworkType; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlOtaLogic; |
| | | import com.hdl.photovoltaic.other.HdlMessageLogic; |
| | | import com.hdl.photovoltaic.other.HdlMqttLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.ui.HomeLoginActivity; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Locale; |
| | | import java.util.Objects; |
| | | |
| | | import cn.jpush.android.api.JPushInterface; |
| | | import io.dcloud.common.util.RuningAcitvityUtil; |
| | | import io.dcloud.common.util.net.NetWork; |
| | | import okhttp3.logging.HttpLoggingInterceptor; |
| | | |
| | | public class HDLApp extends Application { |
| | |
| | | //从内存里面获取不到语言,获取当前系统的; |
| | | String str = getResources().getConfiguration().locale.getCountry(); |
| | | if (str.equals("CN") || str.equals("TW")) { |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.cn); |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.zh); |
| | | } else { |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.en); |
| | | } |
| | |
| | | initSocket(); |
| | | //4.初始化OKHttpLog 是否开启 |
| | | setOKHttpLogOpen(isLogEnabled); |
| | | // initMqttClient(); |
| | | //监听网络状态变化 |
| | | this.networkMonitoring(); |
| | | //初始化本地assets文件夹资源文件 |
| | |
| | | HDLLinkPMSdk.initWithAppKey(getInstance(), AppConfigManage.getAppKey(), AppConfigManage.getAppSecret(), AppConfigManage.getAPPRegionUrl()); |
| | | //2.设置打印 |
| | | HDLLinkPMSdk.setLogEnabled(isLogEnabled); |
| | | //3.配置接口请求语言 |
| | | Locale locale = LocalManageUtil.getSystemLocale(this); |
| | | if (!locale.getLanguage().equals("zh")) { |
| | | HDLLinkPMSdk.setLanguage("en"); |
| | | } else { |
| | | HDLLinkPMSdk.setLanguage("cn"); |
| | | if (TextUtils.isEmpty(UserConfigManage.getInstance().getCurrentAppLanguage())) { |
| | | //默认配置接口请求语言是中文 |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.zh); |
| | | } |
| | | //3.配置接口请求语言 |
| | | HDLLinkPMSdk.setLanguage(UserConfigManage.getInstance().getCurrentAppLanguage()); |
| | | |
| | | // //3.配置接口请求语言 |
| | | // Locale locale = LocalManageUtil.getSystemLocale(this); |
| | | // if (!locale.getLanguage().equals("zh")) { |
| | | // HDLLinkPMSdk.setLanguage("en"); |
| | | // } else { |
| | | // HDLLinkPMSdk.setLanguage("zh"); |
| | | // } |
| | | // HDLLinkPMSdk.setLanguage("en");//强制使用英文 |
| | | //4.监听登出处理 |
| | | HDLLinkPMUser.getInstance().setOnReloginListener(new IOnReloginListener() { |
| | |
| | | //重新设定一个时间 |
| | | UserConfigManage.getInstance().setLoginDateTime(0); |
| | | UserConfigManage.getInstance().Save(); |
| | | |
| | | //清空消息缓存数据 |
| | | HdlMessageLogic.getInstance().clearListMessage(); |
| | | //清空缓存数据 |
| | | if (mInfoMap != null) { |
| | | mInfoMap.clear(); |
| | | } |
| | | |
| | | //断开mqtt连接 |
| | | if (MqttRecvClient.getInstance() != null) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化极光SDK |
| | | */ |
| | | private void initJPush() { |
| | | JPushInterface.setDebugMode(true); |
| | | JPushInterface.init(getBaseContext()); |
| | |
| | | } |
| | | } |
| | | |
| | | public void appLocationInfo() { |
| | | LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); |
| | | if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { |
| | | // TODO: Consider calling |
| | | // ActivityCompat#requestPermissions |
| | | // here to request the missing permissions, and then overriding |
| | | // public void onRequestPermissionsResult(int requestCode, String[] permissions, |
| | | // int[] grantResults) |
| | | // to handle the case where the user grants the permission. See the documentation |
| | | // for ActivityCompat#requestPermissions for more details. |
| | | return; |
| | | } |
| | | //开始定位服务,minTimeMs最小时间间隔(单位为毫秒),minDistanceM最小距离间隔(单位为米)、最小时间间隔(单位为毫秒)等参数。 |
| | | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, new LocationListener() { |
| | | /** |
| | | * 初始化mqtt客户端 |
| | | */ |
| | | public void initMqttClient() { |
| | | |
| | | HdlMqttLogic.getInstance().getMqttRemoteInfo(HomeType.A, new CloudCallBeak<MqttInfo>() { |
| | | @Override |
| | | public void onLocationChanged(@NonNull Location location) { |
| | | // 当位置发生变化时调用此方法 |
| | | double latitude = location.getLatitude(); // 获取纬度 |
| | | double longitude = location.getLongitude(); // 获取经度 |
| | | |
| | | HdlLogLogic.print("纬度--->" + latitude, true); |
| | | HdlLogLogic.print("经度--->" + longitude, true); |
| | | // 这里可以根据需求处理获取到的经纬度数据 |
| | | public void onSuccess(MqttInfo info) { |
| | | if (info != null) { |
| | | MqttRecvClient.init(HDLApp.getInstance(), info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord()); |
| | | } |
| | | } |
| | | |
| | | public void onStatusChanged(String provider, int status, Bundle extras) { |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("读取mqtt远程信息失败--->" + e.getMessage(), e.getCode(), true); |
| | | } |
| | | |
| | | public void onProviderEnabled(String provider) { |
| | | } |
| | | |
| | | public void onProviderDisabled(String provider) { |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |