From db29d92c6974d50f0ebb9328834c44a69c6054bb Mon Sep 17 00:00:00 2001 From: panlili2024 <14743743+panlili2024@user.noreply.gitee.com> Date: 星期三, 05 三月 2025 15:28:37 +0800 Subject: [PATCH] 更新版本 --- HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java | 145 +++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 117 insertions(+), 28 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 0a79a1c..c4d5f87 100644 --- a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java +++ b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java @@ -35,6 +35,7 @@ import com.hdl.sdk.common.exception.HDLLinkException; import com.hdl.sdk.common.utils.IdUtils; import com.hdl.sdk.common.utils.LogUtils; +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.LinkResponse; @@ -44,6 +45,7 @@ import com.hdl.sdk.connect.bean.request.ListSidRequest; import com.hdl.sdk.connect.bean.request.ListUploadRequest; import com.hdl.sdk.connect.bean.response.BaseLocalResponse; +import com.hdl.sdk.connect.bean.response.BindInfoBean; import com.hdl.sdk.connect.bean.response.GatewaySearchBean; import com.hdl.sdk.connect.bean.response.UpdateInfo; import com.hdl.sdk.connect.callback.HDLLinkCallBack; @@ -51,8 +53,13 @@ import com.hdl.sdk.connect.cloud.CallBackListener; import com.hdl.sdk.connect.cloud.CheckAppVersionListener; import com.hdl.sdk.connect.cloud.HDLException; +import com.hdl.sdk.connect.cloud.bean.GatewayInfo; +import com.hdl.sdk.connect.cloud.listener.GatewayListener; +import com.hdl.sdk.connect.cloud.listener.SibichiListener; +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.sourceos.utils.SPKey; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; @@ -79,21 +86,12 @@ private List<SceneBean> sceneList = new ArrayList<>(); private List<SceneDetailBean> sceneDetailList = new ArrayList<>(); private List<SceneDetailBean> roomSceneList = new ArrayList<>(); + private GatewayInfo gatewayInfo; void applyDeviceSecret() { tv.setText("寮�濮嬬敵璇疯澶囧瘑閽�..."); responseTv.setText(""); -// //姝e紡鏈嶅姟鍣� -// String appKey = "i8hR07jzrIS";//appkey -// String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret - - //娴嬭瘯鏈嶅姟鍣� - String appKey = "FcRyUJlLJFF"; - String appSecret = "wz8wn75ABidx8vXcFGUotqhwFkTaYvvJ"; - -// String appKey = "L2OZliZRxHc"; -// String appSecret = "aCIWSvJDOukXfx3kivsKW11x9xdR3IbV"; String supplier = "JINMAOYUN";//鍘傚晢 // String mac = "AA00000000000100";//璁惧鍞竴MAC鍦板潃 String mac = editText.getText().toString(); @@ -103,8 +101,8 @@ Toast.makeText(this, "mac涓嶈兘涓虹┖锛�", Toast.LENGTH_SHORT).show(); return; } - - HDLLink.getInstance().applyDeviceSecret(this, appKey, appSecret, supplier, mac, spk, new CallBackListener() { + //璋冪敤浜戠鎺ュ彛闇�鍒濆鍖朒DLLink.getInstance().initCloud(); + HDLLink.getInstance().applyDeviceSecret(supplier, mac, spk, new CallBackListener() { @Override public void onError(HDLException e) { tv.setText("鐢宠澶辫触"); @@ -126,13 +124,10 @@ tv.setText("寮�濮嬫娴嬫洿鏂�..."); responseTv.setText(""); -// //姝e紡鏈嶅姟鍣� - String appKey = "i8hR07jzrIS";//appkey - String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret - String appCode = "1697150870315999233";//appCode - HDLLink.getInstance().checkAppVersion(this, appKey, appSecret, getAppVersionName(this), appCode, new CheckAppVersionListener() { + //璋冪敤浜戠鎺ュ彛闇�鍒濆鍖朒DLLink.getInstance().initCloud(); + HDLLink.getInstance().checkAppVersion(getAppVersionName(this), appCode, new CheckAppVersionListener() { @Override public void onSuccess(UpdateInfo info) { tv.setText("鏈夋柊鏇存柊"); @@ -142,6 +137,59 @@ @Override public void onError(HDLException e) { tv.setText("妫�娴嬫洿鏂板け璐�"); + responseTv.setText(e.getMsg()); + } + }); + + } + + void getSibichiToken() { + tv.setText("鑾峰彇鎬濆繀椹皌oken..."); + responseTv.setText(""); + + BindInfoBean bindInfoBean = (BindInfoBean) SPUtils.getSerializableEntity(SPKey.BIND_HOME_INFO); + String clientId = "4ED634B5A7AD97A770A52AC00FF43805";//鎬濆繀椹癱lientId + + //璋冪敤浜戠鎺ュ彛闇�鍒濆鍖朒DLLink.getInstance().initCloud(); + HDLLink.getInstance().getSibichiToken(bindInfoBean.getHomeId(), clientId, new SibichiListener() { + @Override + public void onSuccess(AiLoginInfo info) { + tv.setText("鎬濆繀椹皌oken"); + responseTv.setText(info.toString()); + } + + @Override + public void onError(HDLException e) { + tv.setText("鑾峰彇鎬濆繀椹皌oken澶辫触"); + responseTv.setText(e.getMsg()); + } + }); + + } + + void syncMainGateway() { + tv.setText("鑾峰彇涓荤綉鍏充俊鎭�..."); + responseTv.setText(""); + + BindInfoBean bindInfoBean = (BindInfoBean) SPUtils.getSerializableEntity(SPKey.BIND_HOME_INFO); + if (bindInfoBean == null) { + Toast.makeText(this, "璇峰厛鎵爜缁戝畾浣忓畢锛�", Toast.LENGTH_SHORT).show(); + return; + } + //璋冪敤浜戠鎺ュ彛闇�鍒濆鍖朒DLLink.getInstance().initCloud(); + HDLLink.getInstance().syncMainGateway(bindInfoBean.getHomeId(), new GatewayListener() { + @Override + public void onSuccess(GatewayInfo info) { + tv.setText("鑾峰彇涓荤綉鍏充俊鎭�"); + responseTv.setText(info.toString()); + if (info != null) { + HDLLinkConfig.getInstance().setGatewayId(info.getGatewayId()); + } + } + + @Override + public void onError(HDLException e) { + tv.setText("鑾峰彇涓荤綉鍏充俊鎭け璐�"); responseTv.setText(e.getMsg()); } }); @@ -180,7 +228,7 @@ selectnetwork(); checkIfCertified(); - initDeviceInfo();//鍒濆鍖� + //initDeviceInfo();//涓嶈蛋浠庢満鍏ョ綉鐨勬柟寮忎笉闇�瑕佸垵濮嬪寲 registerAllTopicsListener(); HDLLink.getInstance().setDeleteNetworkListener(new DeleteNetworkListener() { @Override @@ -226,6 +274,9 @@ beans.add(new DemoBean("鑾峰彇鎴块棿鍦烘櫙鍒楄〃")); beans.add(new DemoBean("鑾峰彇鑷姩鍖栧垪琛�")); beans.add(new DemoBean("饩冨姩鍖栧惎饨ょ饨�")); + beans.add(new DemoBean("鐢熸垚浜岀淮鐮佺粦瀹氫綇瀹�")); + beans.add(new DemoBean("鑾峰彇鎬濆繀椹皌oken")); + beans.add(new DemoBean("鑾峰彇缃戝叧淇℃伅")); demoAdapter = new DemoAdapter(beans); rv.setAdapter(demoAdapter); @@ -313,6 +364,18 @@ case 19: //饩冨姩鍖栧惎饨ょ饨� editEnableLogic(); + break; + case 20: + //鐢熸垚浜岀淮鐮佺粦瀹氫綇瀹� + startSourceBindActivity(); + break; + case 21: + //鑾峰彇鎬濆繀椹皌oken + getSibichiToken(); + break; + case 22: + //鑾峰彇缃戝叧淇℃伅 + syncMainGateway(); break; } } @@ -418,6 +481,20 @@ } + void initLink() { + //step1:鍏堢敓鎴愪簩缁寸爜锛岀敤onpro鎵爜缁戝畾浣忓畢鑾峰彇浣忓畢淇℃伅 + BindInfoBean bindInfoBean = (BindInfoBean) SPUtils.getSerializableEntity(SPKey.BIND_HOME_INFO); + if (bindInfoBean != null) { + HDLLinkConfig.getInstance().setHomeId(bindInfoBean.getHomeId()); + HDLLinkConfig.getInstance().setLocalSecret(bindInfoBean.getLocalSecret()); + + } + //step2锛氬啀鑾峰彇缃戝叧淇℃伅 + if (gatewayInfo != null) { + HDLLinkConfig.getInstance().setGatewayId(gatewayInfo.getGatewayId());//褰撳墠涓荤綉鍏砳d + } + } + /** * 鍏ョ綉璁よ瘉 */ @@ -425,15 +502,9 @@ tv.setText("寮�濮嬪叆缃戣璇�..."); //璁よ瘉鎻愪氦鍙傛暟鍑嗗 -// 娴嬭瘯鏈嶅姟 -// String spkStr = "ir.module";//浜у搧spk -// String macStr = "AA000000000000AF";//璁惧鍞竴MAC鍦板潃 -// String secret = "44b360eb74b7ba64";//閫氳繃spk鍜宮ac鎻愪氦浜戠璁よ瘉鍚庡垎閰嶇殑secret - -// 姝e紡鏈嶅姟鍣� + //姝e紡鏈嶅姟鍣� String spkStr = "screen.mirror";//浜у搧spk String macStr = "f2c5d8bad48f";//璁惧鍞竴MAC鍦板潃 -// String secret = "e186beeb7974998e";//閫氳繃spk鍜宮ac鎻愪氦浜戠璁よ瘉鍚庡垎閰嶇殑secret String mac_key = stringToMD5(stringToMD5(macStr + secret)); String versionString = "HDL_V1.0.1";// @@ -560,7 +631,12 @@ tv.setText("璁惧鍔熻兘灞炴�ц鍙�"); responseTv.setText(""); List<String> sids = new ArrayList<>(); - sids.add(testLightSid); + if (devicesList.size() != 0) { + sids.add(devicesList.get(0).getSid()); + } else { + sids.add(testLightSid); + } + HDLLink.getInstance().getFunctionAttribute(sids, new HDLLinkCallBack() { @Override public void onSuccess(String msg) { @@ -582,7 +658,11 @@ tv.setText("璇诲彇鐘舵�佷腑..."); responseTv.setText(""); List<String> list = new ArrayList<>(); - list.add(testLightSid);//瑕佽鍙栬澶囩殑sid + if (devicesList.size() != 0) { + list.add(devicesList.get(0).getSid()); + } else { + list.add(testLightSid);//瑕佽鍙栬澶囩殑sid + } HDLLink.getInstance().propertyRead(list, new HDLLinkCallBack() { @Override public void onSuccess(String data) { @@ -608,7 +688,11 @@ isOn = !isOn; List<DeviceControlRequest> requestList = new ArrayList<>(); DeviceControlRequest request = new DeviceControlRequest(); - request.setSid(testLightSid); + if (devicesList.size() != 0) { + request.setSid(devicesList.get(0).getSid()); + } else { + request.setSid(testLightSid);//瑕佽鍙栬澶囩殑sid + } List<DeviceControlRequest.StatusBean> statusBeanList = new ArrayList<>(); DeviceControlRequest.StatusBean bean = new DeviceControlRequest.StatusBean(); bean.setKey("on_off"); @@ -905,6 +989,11 @@ startActivity(intent); } + void startSourceBindActivity() { + Intent intent = new Intent(this, SourceBindActivity.class); + startActivity(intent); + } + /** * TCP鍙戦�� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙� */ -- Gitblit v1.8.0