| | |
| | | package com.hdl.photovoltaic.ui; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | import androidx.core.app.ActivityCompat; |
| | | |
| | | import android.Manifest; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.IntentFilter; |
| | | import android.content.UriPermission; |
| | | import android.content.pm.PackageManager; |
| | | import android.location.LocationManager; |
| | | import android.os.Bundle; |
| | | import android.os.Process; |
| | | import android.os.SystemClock; |
| | | import android.provider.Settings; |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | | |
| | |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.home.type.HomeType; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.bean.MqttInfo; |
| | | import com.hdl.photovoltaic.broadcast.NetworkChangeReceiver; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.ActivityMyPowerStationBinding; |
| | | import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch; |
| | | import com.hdl.photovoltaic.enums.NetworkType; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlCommonLogic; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlMqttLogic; |
| | | import com.hdl.photovoltaic.other.HdlOtaLogic; |
| | | import com.hdl.photovoltaic.other.HdlResidenceLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.other.HdlUniLogic; |
| | | import com.hdl.photovoltaic.ui.bean.BUserInfo; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo; |
| | | import com.hdl.photovoltaic.ui.bean.OidBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | import com.hdl.photovoltaic.utils.GPSManagerUtils; |
| | | import com.hdl.photovoltaic.utils.PermissionUtils; |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog; |
| | | import com.hdl.photovoltaic.widget.ConfirmationTipDialog; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | import com.hdl.sdk.link.common.event.EventListener; |
| | | import com.hdl.sdk.link.core.bean.LinkResponse; |
| | |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | import com.hdl.sdk.link.core.bean.gateway.GatewayBean; |
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig; |
| | | import com.hdl.sdk.link.core.connect.HDLUdpConnect; |
| | | import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | |
| | | import java.lang.reflect.Type; |
| | | import java.util.List; |
| | | |
| | | import cn.jpush.android.api.JPushInterface; |
| | | |
| | | |
| | | /** |
| | | * 我的电站界面 |
| | | * B端-电站界面 |
| | | */ |
| | | public class MyPowerStationActivity extends CustomBaseActivity { |
| | | |
| | | |
| | | private ActivityMyPowerStationBinding viewBinding; |
| | | private int currentFragmentIndex = 1; |
| | | private int currentFragmentIndex = 0; |
| | | private EventListener allTopicsListener; |
| | | |
| | | private int backPressTimes; |
| | | |
| | | private NetworkChangeReceiver networkChangeReceiver; |
| | | |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setNotificationBarBackgroundColor(CustomColor.blue); |
| | | // setNotificationBarBackgroundColor(CustomColor.blue); |
| | | setStatusBarTranslucent(); |
| | | //初始化 |
| | | this.initView(); |
| | | //初始化界面监听器 |
| | |
| | | this.registerAllTopicsListener(); |
| | | //初始化mqtt客户端 |
| | | this.initMqttClient(); |
| | | //监听网络状态变化 |
| | | this.networkMonitoring(); |
| | | //上传极光注册ID到云端 |
| | | this.pushTokens(); |
| | | //点击极光通知栏消息进来 |
| | | this.clickJpushNotificationMessage(); |
| | | //通知限权 |
| | | this.notificationSet(); |
| | | //初始化权限 |
| | | this.requestPermissions(); |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | protected void onResume() { |
| | | super.onResume(); |
| | | //启动页与mainActivity样式一样,这样启动页和mainActivity看上去是一个界面,目的是为了mainActivity遮住下一页; |
| | | // AppManagerUtils.getAppManager().finishActivity(StartActivity.class); |
| | | portConflictDialog(); |
| | | // Intent intent = new Intent(_mActivity, MyPowerStationActivity.class); |
| | | // intent.setFlags(Intent.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); |
| | | // intent.putExtra("skip", "skip");//里面判断有这个标识就跳转到消息中心界面 |
| | | // _mActivity.startActivity(intent); |
| | | //点击极光通知栏消息进来 |
| | | // this.clickJpushNotificationMessage(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 上传极光注册ID到云端 |
| | | */ |
| | | private void pushTokens() { |
| | | String registrationId_tag = "registrationID_" + UserConfigManage.getInstance().getUserId(); |
| | | String is_registrationID = HDLApp.getInstance().getKey(registrationId_tag); |
| | | if (is_registrationID.equals("true")) { |
| | | //上过就没有必要在上传啦 |
| | | return; |
| | | } |
| | | |
| | | HdlThreadLogic.runSubThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | String registrationID = JPushInterface.getRegistrationID(_mActivity); |
| | | int addCount = 0; |
| | | while (TextUtils.isEmpty(registrationID)) { |
| | | SystemClock.sleep(1000);//1s休眠 |
| | | registrationID = JPushInterface.getRegistrationID(_mActivity); |
| | | addCount++; |
| | | if (addCount > 5) { |
| | | //5s超时 |
| | | break; |
| | | } |
| | | } |
| | | if (!TextUtils.isEmpty(registrationID)) { |
| | | UserConfigManage.getInstance().setRegistrationID(registrationID); |
| | | UserConfigManage.getInstance().Save(); |
| | | String finalRegistrationID = registrationID; |
| | | HdlResidenceLogic.getInstance().pushAdd(new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String pushId) { |
| | | |
| | | if (!TextUtils.isEmpty(pushId)) { |
| | | UserConfigManage.getInstance().setPushId(pushId); |
| | | UserConfigManage.getInstance().Save(); |
| | | } |
| | | HDLApp.getInstance().setInfoMap(registrationId_tag, "true");//记录一下状态,后台杀死app会清空; |
| | | HdlLogLogic.print("添加极光ID到云端--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLApp.getInstance().setInfoMap(registrationId_tag, "false");//记录一下状态,后台杀死app会清空; |
| | | HdlLogLogic.print("添加极光ID到云端失败--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | |
| | | boolean isBoolean = PermissionUtils.isNotificationEnabled(_mActivity); |
| | | if (!isBoolean) { |
| | | ConfirmationCancelDialog confirmationCancelDialog = new ConfirmationCancelDialog(_mActivity); |
| | | confirmationCancelDialog.setTitle("提示"); |
| | | confirmationCancelDialog.setContent("通知权限没开启,将无法收到推送信息."); |
| | | confirmationCancelDialog.setConfirmation("前往设置"); |
| | | confirmationCancelDialog.setTitle(getString(R.string.loading_title_tip)); |
| | | confirmationCancelDialog.setContent(getString(R.string.no_permissions_unable_to_receive_push)); |
| | | confirmationCancelDialog.setConfirmation(getString(R.string.go_to_settings)); |
| | | confirmationCancelDialog.show(); |
| | | confirmationCancelDialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 监听网络状态变化 |
| | | */ |
| | | private void networkMonitoring() { |
| | | IntentFilter intentFilter = new IntentFilter(); |
| | | intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE"); |
| | | networkChangeReceiver = new NetworkChangeReceiver(); |
| | | registerReceiver(networkChangeReceiver, intentFilter); |
| | | } |
| | | |
| | | private void initEvent() { |
| | | viewBinding.myPowerStationBottomIl0.clickTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (currentFragmentIndex == 0) { |
| | | return; |
| | | } |
| | | currentFragmentIndex = 0; |
| | | bottomViewChangeOfStyle(); |
| | | postEventBus(HomepageTitleTabSwitch.homepage); |
| | | } |
| | | }); |
| | | viewBinding.myPowerStationBottomIl1.clickTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (currentFragmentIndex == 1) { |
| | | return; |
| | | } |
| | | currentFragmentIndex = 1; |
| | | bottomViewChangeOfStyle(); |
| | | postEventBus(HomepageTitleTabSwitch.powerstation); |
| | |
| | | viewBinding.myMessageBottomIl2.clickTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (currentFragmentIndex == 2) { |
| | | return; |
| | | } |
| | | currentFragmentIndex = 2; |
| | | bottomViewChangeOfStyle(); |
| | | postEventBus(HomepageTitleTabSwitch.message); |
| | |
| | | viewBinding.myMeBottomIl3.clickTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (currentFragmentIndex == 3) { |
| | | return; |
| | | } |
| | | currentFragmentIndex = 3; |
| | | bottomViewChangeOfStyle(); |
| | | postEventBus(HomepageTitleTabSwitch.me); |
| | |
| | | HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack(); |
| | | //移除监听 |
| | | HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener); |
| | | //移除监听网络状态变化 |
| | | unregisterReceiver(networkChangeReceiver); |
| | | |
| | | } |
| | | |
| | | private void initView() { |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setText("首页");// |
| | | viewBinding.myPowerStationBottomIl0.titleTv.setText(R.string.power_shome_page); |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setText(R.string.power_station); |
| | | viewBinding.myMessageBottomIl2.titleTv.setText(R.string.message); |
| | | viewBinding.myMeBottomIl3.titleTv.setText(R.string.power_station_me); |
| | | this.bottomViewChangeOfStyle(); |
| | | |
| | | } |
| | | |
| | | private void bottomViewChangeOfStyle() { |
| | | if (this.currentFragmentIndex == 1) { |
| | | if (this.currentFragmentIndex == 0) { |
| | | viewBinding.myHomePageFcv0.setVisibility(View.VISIBLE);//显示首页界面 |
| | | viewBinding.myPowerStationFcv1.setVisibility(View.GONE);//显示电站界面 |
| | | viewBinding.myMessageFcv2.setVisibility(View.GONE);//隐藏消息界面 |
| | | viewBinding.myMeFcv3.setVisibility(View.GONE);//隐藏我的界面 |
| | | viewBinding.myPowerStationBottomIl0.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.home_page_selected)); |
| | | viewBinding.myPowerStationBottomIl0.titleTv.setTextColor(getColor(R.color.text_90000000)); |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.power_station_unselected)); |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_unselected)); |
| | | viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.me_unselected)); |
| | | viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | } else if (this.currentFragmentIndex == 1) { |
| | | viewBinding.myHomePageFcv0.setVisibility(View.GONE);//隐藏首页界面 |
| | | viewBinding.myPowerStationFcv1.setVisibility(View.VISIBLE);//显示电站界面 |
| | | viewBinding.myMessageFcv2.setVisibility(View.GONE);//隐藏消息界面 |
| | | viewBinding.myMeFcv3.setVisibility(View.GONE);//隐藏我的界面 |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.selectedpowerstation)); |
| | | viewBinding.myPowerStationBottomIl0.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.home_page_unselected)); |
| | | viewBinding.myPowerStationBottomIl0.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.power_station_selected)); |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_90000000)); |
| | | viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_unselected)); |
| | | viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedme)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.me_unselected)); |
| | | viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | } else if (this.currentFragmentIndex == 2) { |
| | | viewBinding.myHomePageFcv0.setVisibility(View.GONE);//隐藏首页界面 |
| | | viewBinding.myPowerStationFcv1.setVisibility(View.GONE);//隐藏电站界面 |
| | | viewBinding.myMessageFcv2.setVisibility(View.VISIBLE);//显示消息界面 |
| | | viewBinding.myMeFcv3.setVisibility(View.GONE);//隐藏我的界面 |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedpowerstation)); |
| | | viewBinding.myPowerStationBottomIl0.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.home_page_unselected)); |
| | | viewBinding.myPowerStationBottomIl0.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.power_station_unselected)); |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_select)); |
| | | viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_90000000)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedme)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.me_unselected)); |
| | | viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | } else if (this.currentFragmentIndex == 3) { |
| | | viewBinding.myHomePageFcv0.setVisibility(View.GONE);//隐藏首页界面 |
| | | viewBinding.myPowerStationFcv1.setVisibility(View.GONE);//隐藏电站界面 |
| | | viewBinding.myMessageFcv2.setVisibility(View.GONE);//隐藏消息界面 |
| | | viewBinding.myMeFcv3.setVisibility(View.VISIBLE);//显示我的界面 |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedpowerstation)); |
| | | viewBinding.myPowerStationBottomIl0.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.home_page_unselected)); |
| | | viewBinding.myPowerStationBottomIl0.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.power_station_unselected)); |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_unselected)); |
| | | viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.selectedme)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.me_selected)); |
| | | viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_90000000)); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | public void requestPermissions() { |
| | | String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}); |
| | | //消息通知限权 |
| | | this.notificationSet(); |
| | | //ACCESS_FINE_LOCATION 允许使用GPS定位 |
| | | //ACCESS_COARSE_LOCATION 允许使用WIFI热点或基站来获取粗略的定位 |
| | | String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}); |
| | | if (ary.length > 0) { |
| | | requestPermissions(ary, PermissionUtils.STATUS_SUCCESS); |
| | | this.requestPermissions(ary, PermissionUtils.STATUS_SUCCESS); |
| | | } else { |
| | | if (mPermissionsResultCallback != null) { |
| | | mPermissionsResultCallback.succeed(); |
| | | } |
| | | locationUpdates(); |
| | | } |
| | | } |
| | | |
| | |
| | | if (requestCode == PermissionUtils.STATUS_SUCCESS) { |
| | | for (int i = 0; i < permissions.length; i++) { |
| | | if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { |
| | | if (mPermissionsResultCallback != null) { |
| | | mPermissionsResultCallback.succeed(); |
| | | switch (permissions[i]) { |
| | | case Manifest.permission.ACCESS_FINE_LOCATION: { |
| | | locationUpdates(); |
| | | } |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | private PermissionsResultCallback mPermissionsResultCallback; |
| | | |
| | | public void setPermissionsResultCallback(PermissionsResultCallback permissionsResultCallback) { |
| | | mPermissionsResultCallback = permissionsResultCallback; |
| | | } |
| | | |
| | | public interface PermissionsResultCallback { |
| | | |
| | | void succeed(); |
| | | |
| | | void failing(); |
| | | |
| | | } |
| | | |
| | |
| | | HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); |
| | | uniCallBackBaseBean.setType(response.getTopic()); |
| | | uniCallBackBaseBean.setData(response.getData()); |
| | | // if (com.hdl.photovoltaic.ui.test.UniAppMqtt.getInstance().getUni()) { |
| | | // try { |
| | | // String t = String.format("AndroidToPC/%s/%s", System.currentTimeMillis(), HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL); |
| | | // com.hdl.photovoltaic.ui.test.UniAppMqtt.getInstance().publish(t, JSONObject.toJSON(uniCallBackBaseBean).toString()); |
| | | // } catch (Exception ignored) { |
| | | // } |
| | | // } else { |
| | | HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean); |
| | | // } |
| | | // } |
| | | |
| | | } else if (msg instanceof LinkResponse) { |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | ; |
| | | HDLLinkLocalSdk.getInstance(). |
| | | |
| | | registerAllTopicsListener(allTopicsListener); |
| | | }; |
| | | HDLLinkLocalSdk.getInstance().registerAllTopicsListener(allTopicsListener); |
| | | } |
| | | |
| | | /** |
| | | * 初始化mqtt客户端 |
| | | */ |
| | | public void initMqttClient() { |
| | | HdlMqttLogic.getInstance().getMqttRemoteInfo(HomeType.A, new CloudCallBeak<MqttInfo>() { |
| | | @Override |
| | | public void onSuccess(MqttInfo info) { |
| | | if (info != null) { |
| | | MqttRecvClient.init(_mActivity, info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord()); |
| | | if (!MqttRecvClient.getInstance().isInit()) { |
| | | HdlMqttLogic.getInstance().getMqttRemoteInfo(HomeType.A, new CloudCallBeak<MqttInfo>() { |
| | | @Override |
| | | public void onSuccess(MqttInfo info) { |
| | | if (info != null) { |
| | | MqttRecvClient.getInstance().setConnectParam(info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord(), null); |
| | | MqttRecvClient.getInstance().connect(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("读取mqtt远程信息失败--->" + e.getMessage(), e.getCode(), true); |
| | | } |
| | | }); |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("读取mqtt远程信息失败--->" + e.getMessage(), e.getCode(), true); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | |
| | | HdlThreadLogic.runSubThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //防止app启动的时候没有网络(app也登录不了),导致获取不了mqtt远程连接信息; |
| | | initMqttClient(); |
| | | HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<GatewayBean>>() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> obj) { |
| | |
| | | |
| | | |
| | | /** |
| | | * 物理按键返回事件 |
| | | * 物理按键返回事件(包括左滑移除事件) |
| | | */ |
| | | @Override |
| | | public void onBackPressed() { |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 初始化【开启定位】和【位置信息】权限 |
| | | */ |
| | | private void locationUpdates() { |
| | | // 初始化LocationManager对象 |
| | | LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); |
| | | GPSManagerUtils.getInstance().getLocation(this); |
| | | // 判断设备是否支持定位功能 |
| | | if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { |
| | | // 提示用户打开定位功能或者引导用户去系统设置页面打开定位功能 |
| | | ConfirmationCancelDialog confirmationCancelDialog = new ConfirmationCancelDialog(_mActivity); |
| | | confirmationCancelDialog.setTitle(getString(R.string.loading_title_tip)); |
| | | confirmationCancelDialog.setContent(getString(R.string.system_positioning_switch)); |
| | | confirmationCancelDialog.setConfirmation(getString(R.string.go_to_settings)); |
| | | confirmationCancelDialog.show(); |
| | | confirmationCancelDialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | confirmationCancelDialog.dismiss(); |
| | | Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | HDLApp.getInstance().startActivity(intent); |
| | | |
| | | } |
| | | }); |
| | | confirmationCancelDialog.setNoOnclickListener(new ConfirmationCancelDialog.onNoOnclickListener() { |
| | | @Override |
| | | public void Cancel() { |
| | | confirmationCancelDialog.dismiss(); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 端口冲突 |
| | | */ |
| | | private void portConflictDialog() { |
| | | if (!HDLUdpConnect.getInstance().isBindSuccess()) { |
| | | ConfirmationTipDialog dialog = new ConfirmationTipDialog(_mActivity); |
| | | dialog.show(); |
| | | dialog.setTitle(getString(R.string.loading_title_tip)); |
| | | dialog.setContent(getString(R.string.port_conflict)); |
| | | dialog.setConfirmation(getString(R.string.home_login_affirm)); |
| | | dialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | dialog.dismiss(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | } |