| | |
| | | import android.os.Process; |
| | | import android.os.SystemClock; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | |
| | | |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | 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.Subscribe; |
| | |
| | | setNotificationBarBackgroundColor(CustomColor.white); |
| | | setStatusBarTextColor(); |
| | | //C端启动App自动打开小程序电站详情界面 |
| | | // startAppAutomaticallyOpenUni(); |
| | | startAppAutomaticallyOpenUni(); |
| | | //注册监听 |
| | | this.registerAllTopicsListener(); |
| | | //初始化mqtt客户端 |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | setTheme(R.style.NoAnimationTheme); |
| | | } |
| | | |
| | | @Override |
| | | protected void onResume() { |
| | | super.onResume(); |
| | | //启动页与mainActivity样式一样,这样启动页和mainActivity看上去是一个界面,目的是为了mainActivity遮住下一页; |
| | | // AppManagerUtils.getAppManager().finishActivity(StartActivity.class); |
| | | this.portConflictDialog(); |
| | | startAppAutomaticallyOpenUni(); |
| | | // this.portConflictDialog(); |
| | | } |
| | | |
| | | public void startAppAutomaticallyOpenUni() { |
| | | //低于安卓14版本 |
| | | if (android.os.Build.VERSION.SDK_INT < 34) { |
| | | startAppAutomaticallyOpenUni(false); |
| | | } else { |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | SystemClock.sleep(10); |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | SystemClock.sleep(10); |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //低于安卓14版本 |
| | | if (android.os.Build.VERSION.SDK_INT < 34) { |
| | | startAppAutomaticallyOpenUni(false); |
| | | } else { |
| | | startAppAutomaticallyOpenUni(true); |
| | | } |
| | | }); |
| | | } |
| | | }).start(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | |
| | | if (TextUtils.isEmpty(event.getTopic())) { |
| | | return; |
| | | } |
| | | //网关更新mqtt秘钥更新通知 |
| | | //网关mqtt秘钥更新通知 |
| | | if (event.getTopic().contains("/custom/mqtt/secret/change")) { |
| | | String[] topics = event.getTopic().split("/"); |
| | | //主题不符合规则不处理 |
| | |
| | | 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) { |
| | |
| | | */ |
| | | private void startAppAutomaticallyOpenUni(boolean delay) { |
| | | |
| | | if(delay) { |
| | | if (delay) { |
| | | SystemClock.sleep(2000); |
| | | } |
| | | List<HouseIdBean> HouseIdList = HdlResidenceLogic.getInstance().getHouseIdList(); |
| | | if (HouseIdList.size() == 0) { |
| | | String path = HDLUniMP.UNI_EVENT_OPEN_HOME_Null_C; |
| | | HdlUniLogic.getInstance().openUniMP(path, null); |
| | | if(delay){ |
| | | HdlUniLogic.getInstance().openUniMPDelay(path, null); |
| | | }else { |
| | | HdlUniLogic.getInstance().openUniMP(path, null); |
| | | } |
| | | } else { |
| | | int select_home = 0; |
| | | for (int i = 0; i < HouseIdList.size(); i++) { |
| | |
| | | HouseIdBean houseIdBean = HouseIdList.get(select_home); |
| | | HdlResidenceLogic.getInstance().switchHouse(houseIdBean); |
| | | String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS_C + "?homeId=" + houseIdBean.getHomeId() + "&homeName=" + houseIdBean.getHomeName() + "&powerStationStatus=" + houseIdBean.getPowerStationStatus(); |
| | | HdlUniLogic.getInstance().openUniMP(path, null); |
| | | if(delay) { |
| | | HdlUniLogic.getInstance().openUniMPDelay(path, null); |
| | | }else { |
| | | HdlUniLogic.getInstance().openUniMP(path, null); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * 初始化mqtt客户端 |
| | | */ |
| | | public void initMqttClient() { |
| | | //检查断开状态 |
| | | if (!MqttRecvClient.getInstance().isConnected()) { |
| | | MqttRecvClient.getInstance().reConnect(); |
| | | } |
| | | if (!MqttRecvClient.getInstance().isInit()) { |
| | | HdlMqttLogic.getInstance().getMqttRemoteInfo(HomeType.A, new CloudCallBeak<MqttInfo>() { |
| | | @Override |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 端口冲突 |
| | | */ |
| | | private void portConflictDialog() { |
| | | if (!HDLUdpConnect.getInstance().isBindSuccess()) { |
| | | ConfirmationTipDialog dialog = new ConfirmationTipDialog(_mActivity); |
| | | dialog.show(); |
| | | dialog.setTitle(getString(R.string.home_account_registered_successfully)); |
| | | dialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | finish(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |