From 8814f3f0828e6ac652a29cc9de9f971fd55bca5b Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期三, 07 五月 2025 14:54:42 +0800 Subject: [PATCH] 2025年05月07日14:54:39 --- app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java | 140 +++++++++++++++++++++++++++++++++++++++------- 1 files changed, 119 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java index b66e48c..45e84c4 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java @@ -1,6 +1,10 @@ package com.hdl.photovoltaic.ui; +import android.app.ActivityManager; +import android.content.Context; +import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.os.Process; import android.os.SystemClock; @@ -11,6 +15,7 @@ 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.linkpm.sdk.user.HDLLinkPMUser; import com.hdl.photovoltaic.HDLApp; import com.hdl.photovoltaic.R; import com.hdl.photovoltaic.base.CustomBaseActivity; @@ -21,20 +26,20 @@ import com.hdl.photovoltaic.enums.NetworkType; import com.hdl.photovoltaic.listener.CloudCallBeak; import com.hdl.photovoltaic.other.HdlDeviceLogic; +import com.hdl.photovoltaic.other.HdlESLocalJsonLogic; 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.services.ForeService; import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo; import com.hdl.photovoltaic.ui.bean.HouseIdBean; import com.hdl.photovoltaic.ui.bean.OidBean; 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; @@ -42,8 +47,8 @@ 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 com.umeng.analytics.MobclickAgent; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; @@ -71,8 +76,8 @@ @Override public void onBindView(Bundle savedInstanceState) { - setNotificationBarBackgroundColor(CustomColor.white); - setStatusBarTextColor(); + setStatusBarTranslucent(); + getWindow().setNavigationBarColor(getColor(R.color.text_FF000000)); //C绔惎鍔ˋpp鑷姩鎵撳紑灏忕▼搴忕數绔欒鎯呯晫闈� startAppAutomaticallyOpenUni(); //娉ㄥ唽鐩戝惉 @@ -81,13 +86,50 @@ this.initMqttClient(); //涓婁紶鏋佸厜娉ㄥ唽ID鍒颁簯绔� this.pushTokens(); + //鑾峰彇浜戠鑴氭湰 + HdlESLocalJsonLogic.getInstance().getAllHdlESLocalJson(); +// mForegroundService= new Intent(this, ForeService.class); +// startService(); + } + + Intent mForegroundService; + + private void startService() { + // Android 8.0浣跨敤startForegroundService鍦ㄥ墠鍙板惎鍔ㄦ柊鏈嶅姟 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(mForegroundService); + } else { + startService(mForegroundService); + } } @Override protected void onResume() { super.onResume(); //鍚姩椤典笌mainActivity鏍峰紡涓�鏍凤紝杩欐牱鍚姩椤靛拰mainActivity鐪嬩笂鍘绘槸涓�涓晫闈紝鐩殑鏄负浜唌ainActivity閬綇涓嬩竴椤碉紱 - AppManagerUtils.getAppManager().finishActivity(StartActivity.class); +// AppManagerUtils.getAppManager().finishActivity(StartActivity.class); +// this.portConflictDialog(); + } + + public void startAppAutomaticallyOpenUni() { + new Thread(new Runnable() { + @Override + public void run() { + SystemClock.sleep(10); + runOnUiThread(new Runnable() { + @Override + public void run() { + startAppAutomaticallyOpenUni(false); +// //浣庝簬瀹夊崜14鐗堟湰 +// if (android.os.Build.VERSION.SDK_INT < 34) { +// startAppAutomaticallyOpenUni(false); +// } else { +// startAppAutomaticallyOpenUni(false); +// } + } + }); + } + }).start(); } @Subscribe(threadMode = ThreadMode.MAIN) @@ -99,7 +141,7 @@ if (TextUtils.isEmpty(event.getTopic())) { return; } - //缃戝叧鏇存柊mqtt绉橀挜鏇存柊閫氱煡 + //缃戝叧mqtt绉橀挜鏇存柊閫氱煡 if (event.getTopic().contains("/custom/mqtt/secret/change")) { String[] topics = event.getTopic().split("/"); //涓婚涓嶇鍚堣鍒欎笉澶勭悊 @@ -107,7 +149,7 @@ return; } int index = -1; - List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId()); + List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId(), null); for (int i = 0; i < list.size(); i++) { GatewayBean gatewayBean = list.get(i); if (gatewayBean.getGatewayId().equals(topics[2])) { @@ -145,7 +187,7 @@ HdlLogLogic.print(event.getTopic() + new Gson().toJson(event.getData()), true); } else if (event.getTopic().contains(ConstantManage.network_change_post)) { // String wifi_ssid = WifiUtils.getInstance().getCurrentConnectWifiSsid();//鑾峰彇WiFi鐨剆sid闇�瑕佷綅缃潈闄愮殑 - HdlLogLogic.print("鐩戝惉缃戠粶鐘舵��--->" + event.getData().toString() + "(" + event.getType() + ")", true); + HdlLogLogic.print("鐩戝惉缃戠粶鐘舵��---" + event.getData().toString() + "(" + event.getType() + ")", true); //绗竴娆″惎鍔ˋpp,浠ュ強鍒囨崲缃戠粶鐨勬椂鍊欐洿鏂� if (TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) { return; @@ -155,6 +197,9 @@ 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) { @@ -172,18 +217,52 @@ } else if (event.getTopic().contains(HDLUniMP.UNI_EVENT_REPLY_OTHER_MODEL) && event.getType().contains(HDLUniMP.UNI_EVENT_REPLY_OTHER_BACK)) { //鐗╃悊鎸夐敭杩斿洖浜嬩欢(鍖呮嫭宸︽粦绉婚櫎浜嬩欢) killProcessApp(); + } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(event.getType())) { + if (MqttRecvClient.getInstance() != null) { + MqttRecvClient.getInstance().removeAllTopic(); + } + String homeId = event.getData().toString(); + //杩涘幓浣忓畢璇︽儏uni璇诲彇閫嗗彉鍣ㄥ垪琛ㄦ垚鍔熷悗閫氱煡 + for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId, null).size(); i++) { + String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId, null).get(i).getGatewayId(); + //瀛楃涓叉槸鑷繁鎸夎鍒欐嫾鎺ョ殑,閲岄潰娉ㄥ唽涓婚鏃朵細瑙f瀽瀛楃涓�,鍙嬁getGatewayId()鍊�; + String topic = "/user/" + gatewayId + "/#"; + //杩涘幓浣忓畢璇︽儏寮�濮嬭闃呬富棰� + MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topic);//璁㈤槄銆愰�嗗彉鍣ㄣ�戞秷鎭� + + } + String topicHome = "/user/" + homeId + "/#"; + MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topicHome);//璁㈤槄銆愮數绔欍�戞秷鎭� + + } } + /** * C绔惎鍔ˋpp鑷姩鎵撳紑灏忕▼搴忕數绔欒鎯呯晫闈� */ - private void startAppAutomaticallyOpenUni() { + private void startAppAutomaticallyOpenUni(boolean delay) { +// if (delay) { +// SystemClock.sleep(2000); +// } + if (TextUtils.isEmpty(HDLLinkPMUser.getInstance().getAccessToken())) { + //鍏跺疄鍒锋柊token澶辫触宸查�氱煡閫�鍑虹櫥褰曪紝鏁版嵁宸茬粡娓呯┖锛屽洜涓虹瓑2s uni鍔犺浇鎱㈠鑷磋姹傞摼鎺ョ殑鏃跺�欏嚭鐜皌oken涓虹┖ + HdlLogLogic.print("杩斿洖鍘�---",true); + return; + } + UserConfigManage.getInstance().setUniBottomSafeDistanceBackgroundColor(0); 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 (HouseIdList.isEmpty()) { + if (TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) { + String path = HDLUniMP.UNI_EVENT_OPEN_HOME_Null_C; + HdlUniLogic.getInstance().openUniMP(path, null); + } else { + //瑙e喅闂鎵嬫満娌℃湁缃戣嚜鍔ㄧ櫥褰曡繘鏉ワ紝榛樿浼犱笂涓�娆$殑浣忓畢id + String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS_C + "?homeId=" + UserConfigManage.getInstance().getHomeId() + "&homeName=" + UserConfigManage.getInstance().getHomeName(); + HdlUniLogic.getInstance().openUniMP(path, null); + } } else { int select_home = 0; for (int i = 0; i < HouseIdList.size(); i++) { @@ -193,13 +272,13 @@ } } HouseIdBean houseIdBean = HouseIdList.get(select_home); - HdlResidenceLogic.getInstance().switchHouse(houseIdBean); + HdlResidenceLogic.getInstance().switchHouse(houseIdBean, false); String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS_C + "?homeId=" + houseIdBean.getHomeId() + "&homeName=" + houseIdBean.getHomeName() + "&powerStationStatus=" + houseIdBean.getPowerStationStatus(); HdlUniLogic.getInstance().openUniMP(path, null); } - } + // /** // * 鐗╃悊鎸夐敭杩斿洖浜嬩欢(鍖呮嫭宸︽粦绉婚櫎浜嬩欢) @@ -235,6 +314,8 @@ HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP(); } AppManagerUtils.getAppManager().finishAllActivity(); + //濡傛灉寮�鍙戣�呰皟鐢╧ill鎴栬�卐xit涔嬬被鐨勬柟娉曟潃姝昏繘绋嬶紝鎴栬�呭弻鍑籦ack閿細鏉�姝昏繘绋嬶紝璇峰姟蹇呭湪姝や箣鍓嶈皟鐢∕obclickAgent.onKillProcess鏂规硶锛岀敤鏉ヤ繚瀛樼粺璁℃暟鎹�� + MobclickAgent.onKillProcess(_mActivity); Process.killProcess(Process.myPid()); } } @@ -247,6 +328,7 @@ HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack(); //绉婚櫎鐩戝惉 HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener); +// stopService(mForegroundService); } /** @@ -287,14 +369,14 @@ UserConfigManage.getInstance().Save(); } HDLApp.getInstance().setInfoMap(registrationId_tag, "true");//璁板綍涓�涓嬬姸鎬�,鍚庡彴鏉�姝籥pp浼氭竻绌�; - HdlLogLogic.print("C绔�--->娣诲姞鏋佸厜ID鍒颁簯绔�--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); + HdlLogLogic.print("C绔�---娣诲姞鏋佸厜ID鍒颁簯绔�---registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); } @Override public void onFailure(HDLException e) { HDLApp.getInstance().setInfoMap(registrationId_tag, "false");//璁板綍涓�涓嬬姸鎬�,鍚庡彴鏉�姝籥pp浼氭竻绌�; - HdlLogLogic.print("C绔�--->娣诲姞鏋佸厜ID鍒颁簯绔け璐�--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); + HdlLogLogic.print("C绔�---娣诲姞鏋佸厜ID鍒颁簯绔け璐�---registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); } }); @@ -309,19 +391,24 @@ * 鍒濆鍖杕qtt瀹㈡埛绔� */ public void initMqttClient() { + //妫�鏌ユ柇寮�鐘舵�� + if (!MqttRecvClient.getInstance().isConnected()) { + MqttRecvClient.getInstance().reConnect(); + } 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().setConnectParam(info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord()); MqttRecvClient.getInstance().connect(); + HdlLogLogic.print("mqtt閾炬帴鎴愬姛---ClientId---" + info.getClientId(), true); } } @Override public void onFailure(HDLException e) { - HdlLogLogic.print("璇诲彇mqtt杩滅▼淇℃伅澶辫触--->" + e.getMessage(), e.getCode(), true); + HdlLogLogic.print("璇诲彇mqtt杩滅▼淇℃伅澶辫触---" + e.getMessage(), e.getCode(), true); } }); } @@ -343,7 +430,7 @@ if (response.getTopic() == null) { return; } - HdlLogLogic.print("C绔�--->鐩戝惉鍒癕odbus鏁版嵁--->" + new Gson().toJson(response), false); + HdlLogLogic.print("C绔�---鐩戝惉鍒癕odbus鏁版嵁---" + new Gson().toJson(response), false); // if (response.getTopic().endsWith("custom/native/inverter/up")) { HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); uniCallBackBaseBean.setType(response.getTopic()); @@ -388,7 +475,18 @@ } + } else if (linkResponse.getTopic().endsWith("/app/thing/property/send")) { + //璁惧鐘舵�佸彉鏇磘opic锛�/user/${homeId}/app/thing/property/send + if (linkResponse.getData() == null) { + HdlLogLogic.print("璁惧鐘舵�佸彉鏇�--->鏁版嵁涓虹┖", false); + return; + } + HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); + uniCallBackBaseBean.setType(linkResponse.getTopic()); + uniCallBackBaseBean.setData(linkResponse.getData()); + HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean); } + } } }; @@ -396,4 +494,4 @@ } -} \ No newline at end of file +} -- Gitblit v1.8.0