From 84bb9a10e795b8839d9770eeb37aab71bf22e107 Mon Sep 17 00:00:00 2001 From: panlili2024 <14743743+panlili2024@user.noreply.gitee.com> Date: 星期一, 29 九月 2025 10:13:18 +0800 Subject: [PATCH] 代码优化 --- HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java | 75 ++++++++++++++++++------------------- 1 files changed, 36 insertions(+), 39 deletions(-) diff --git a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java index 20e7579..b1021cd 100644 --- a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java +++ b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java @@ -38,6 +38,7 @@ import com.hdl.sdk.common.utils.SPUtils; import com.hdl.sdk.common.utils.gson.GsonConvert; import com.hdl.sdk.connect.HDLLink; +import com.hdl.sdk.connect.bean.LinkFunctionInfo; import com.hdl.sdk.connect.bean.LinkResponse; import com.hdl.sdk.connect.bean.request.AttributesRequest; import com.hdl.sdk.connect.bean.request.AuthenticateRequest; @@ -50,6 +51,7 @@ import com.hdl.sdk.connect.bean.response.UpdateInfo; import com.hdl.sdk.connect.callback.HDLLinkCallBack; import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack; +import com.hdl.sdk.connect.callback.HDLLinkTCallBack; import com.hdl.sdk.connect.cloud.CallBackListener; import com.hdl.sdk.connect.cloud.CheckAppVersionListener; import com.hdl.sdk.connect.cloud.HDLException; @@ -59,6 +61,7 @@ import com.hdl.sdk.connect.cloud.bean.AiLoginInfo; import com.hdl.sdk.connect.config.HDLLinkConfig; import com.hdl.sdk.connect.socket.HDLAuthSocket; +import com.hdl.sdk.connect.socket.HDLSocket; import com.hdl.sdk.sourceos.utils.SPKey; import java.io.UnsupportedEncodingException; @@ -81,8 +84,8 @@ private EventListener allTopicsListener; private String testLightSid = "020101A19B485D02020100010101"; private String secret = ""; - private List<FunctionBean> devicesList = new ArrayList<>(); - private List<FunctionBean> roomDevicesList = new ArrayList<>(); + private List<LinkFunctionInfo> devicesList = new ArrayList<>(); + private List<LinkFunctionInfo> roomDevicesList = new ArrayList<>(); private List<SceneBean> sceneList = new ArrayList<>(); private List<SceneDetailBean> sceneDetailList = new ArrayList<>(); private List<SceneDetailBean> roomSceneList = new ArrayList<>(); @@ -93,8 +96,8 @@ responseTv.setText(""); String supplier = "JINMAOYUN";//鍘傚晢 -// String mac = "AA00000000000100";//璁惧鍞竴MAC鍦板潃 - String mac = editText.getText().toString(); + String mac = "f2c5d8bad48f";//璁惧鍞竴MAC鍦板潃 +// String mac = editText.getText().toString(); String spk = "screen.touch";//浜у搧spk if (TextUtils.isEmpty(mac)) { @@ -228,7 +231,7 @@ selectnetwork(); checkIfCertified(); - //initDeviceInfo();//涓嶈蛋浠庢満鍏ョ綉鐨勬柟寮忎笉闇�瑕佸垵濮嬪寲 + initDeviceInfo();//涓嶈蛋浠庢満鍏ョ綉鐨勬柟寮忎笉闇�瑕佸垵濮嬪寲锛岃蛋浠庢満鍏ョ綉鍒欓渶瑕佸垵濮嬪寲 registerAllTopicsListener(); HDLLink.getInstance().setDeleteNetworkListener(new DeleteNetworkListener() { @Override @@ -410,9 +413,14 @@ public void onMessage(Object msg) { LinkResponse response = (LinkResponse) msg; Log.i("onMessage", "response.getTopic():" + response.getTopic()); + String topic = String.format(TopicConstant.GATEWAY_LOGIN, + HDLLinkConfig.getInstance().getGatewayId()) + "_reply"; + ; + if ("/user/all/custom/gateway/broadcast_reply".equals(response.getTopic())) { localSecret.setText("瀵嗛挜锛�" + HDLLinkConfig.getInstance().getLocalSecret()); - + } else if (topic.equals(response.getTopic())) { + //tcp杩炴帴鎴愬姛锛屽鐞嗕笟鍔¢�昏緫 } } }; @@ -469,8 +477,8 @@ infoBean.setDeviceName("榄旈暅");//璁惧鍚嶅瓧 infoBean.setDeviceModel("HDLSDK");//璁惧鍨嬪彿 infoBean.setAccessMode("WIFI"); - infoBean.setIPGateway("192.168.31.1"); - infoBean.setIPAddress("192.168.31.103"); + infoBean.setIPGateway("192.168.1.1"); + infoBean.setIPAddress("192.168.1.103"); infoBean.setGateway_type("screen.touch"); infoBean.setHw_version("HW2.0"); infoBean.setFw_version("Fw1.0"); @@ -503,7 +511,7 @@ //璁よ瘉鎻愪氦鍙傛暟鍑嗗 //姝e紡鏈嶅姟鍣� - String spkStr = "screen.mirror";//浜у搧spk + String spkStr = "screen.touch";//浜у搧spk String macStr = "f2c5d8bad48f";//璁惧鍞竴MAC鍦板潃 String mac_key = stringToMD5(stringToMD5(macStr + secret)); @@ -592,37 +600,23 @@ void getFunctionList() { tv.setText("鑾峰彇璁惧鍒楄〃涓�..."); responseTv.setText(""); - HDLLink.getInstance().getFunctionList(new HDLLinkCallBack() { + HDLLink.getInstance().getFunctionInfoList(new HDLLinkTCallBack<List<LinkFunctionInfo>>() { + @Override + public void onSuccess(List<LinkFunctionInfo> data) { + if (data != null && data.size() != 0) { + devicesList.clear(); + devicesList.addAll(data); + + tv.setText("鑾峰彇璁惧鍒楄〃鎴愬姛"); + responseTv.setText(data.toString()); + } + } + @Override public void onError(HDLLinkException error) { tv.setText(error.getMsg()); } - - @Override - public void onSuccess(String data) { - tv.setText("鑾峰彇璁惧鍒楄〃鎴愬姛"); - responseTv.setText(data); - - handelFunctionList(data); - } }); - } - - void handelFunctionList(String data) { - try { - final LinkResponse linkResponse = GsonConvert.getGson().fromJson(data, new TypeToken<LinkResponse>() { - }.getType()); - - final BaseLocalResponse<List<FunctionBean>> bean = GsonConvert.getGson().fromJson(linkResponse.getData(), new TypeToken<BaseLocalResponse<List<FunctionBean>>>() { - }.getType()); - devicesList.clear(); - devicesList.addAll(bean.getObjects()); - - Log.d(TAG, "handelFunList-----> " + devicesList.toString()); - } catch (Exception e) { - Log.e(TAG, "handelFunList: " + e.getMessage()); - } - } /** @@ -639,10 +633,12 @@ sids.add(testLightSid); } - HDLLink.getInstance().getFunctionAttribute(sids, new HDLLinkCallBack() { + HDLLink.getInstance().getFunctionAttributeInfo(sids, new HDLLinkTCallBack<List<LinkFunctionInfo>>() { @Override - public void onSuccess(String msg) { - responseTv.setText(msg); + public void onSuccess(List<LinkFunctionInfo> data) { + if (data != null && data.size() != 0) { + responseTv.setText(data.toString()); + } } @Override @@ -703,7 +699,7 @@ request.setStatus(statusBeanList); requestList.add(request); - HDLLink.getInstance().propertyDown(requestList, new HDLLinkCallBack() { + HDLLink.getInstance().propertyDownDevice(requestList, new HDLLinkTCallBack<String>() { @Override public void onSuccess(String data) { responseTv.setText(data); @@ -1005,6 +1001,7 @@ String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); String bodyStr = getPropertyDownBodyStr(); HDLLink.getInstance().tcpSendMsg(propertyDownTopic, bodyStr); + } /** -- Gitblit v1.8.0