| | |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.hdlsdk.device.DevicesListActivity; |
| | | import com.hdl.sdk.common.config.TopicConstant; |
| | | import com.hdl.sdk.common.event.DeleteNetworkListener; |
| | | import com.hdl.sdk.common.event.EventListener; |
| | | 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.gson.GsonConvert; |
| | | import com.hdl.sdk.connect.HDLLink; |
| | | import com.hdl.sdk.connect.bean.LinkResponse; |
| | |
| | | private RecyclerView rv; |
| | | private TextView tv; |
| | | private TextView responseTv; |
| | | private TextView localSecret; |
| | | private EditText editText; |
| | | boolean isOn; |
| | | private EventListener allTopicsListener; |
| | | private String testLightSid = "0001010D48C71B02020100010101"; |
| | | private String testLightSid = "02010131D9C03D01020300010107"; |
| | | private String secret = ""; |
| | | |
| | | @Override |
| | |
| | | public void onSuccess(String msg) { |
| | | tv.setText("认证成功"); |
| | | responseTv.setText(msg.toString()); |
| | | localSecret.setText("密钥:" + HDLLinkConfig.getInstance().getLocalSecret()); |
| | | } |
| | | }); |
| | | } |
| | |
| | | setContentView(R.layout.activity_main); |
| | | responseTv = findViewById(R.id.response_tv); |
| | | editText = findViewById(R.id.edittext); |
| | | localSecret = findViewById(R.id.local_secret); |
| | | tv = findViewById(R.id.state_tv); |
| | | rv = findViewById(R.id.rv); |
| | | rv.setLayoutManager(new LinearLayoutManager(this)); |
| | |
| | | checkIfCertified(); |
| | | initDeviceInfo();//初始化 |
| | | registerAllTopicsListener(); |
| | | HDLLink.getInstance().setDeleteNetworkListener(new DeleteNetworkListener() { |
| | | @Override |
| | | public void onSuccess(Object msg) { |
| | | LogUtils.i("setDeleteNetworkListener onSucceed = " + msg); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure() { |
| | | LogUtils.i("setDeleteNetworkListener onFailure"); |
| | | } |
| | | }); |
| | | |
| | | ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() { |
| | | @Override |
| | |
| | | break; |
| | | case 9: |
| | | //场景控制 |
| | | controlScene(); |
| | | getScene(); |
| | | break; |
| | | case 10: |
| | | //功能列表 |
| | |
| | | @Override |
| | | public void onMessage(Object msg) { |
| | | LinkResponse response = (LinkResponse) msg; |
| | | if ("/user/all/custom/gateway/broadcast_reply".equals(response.getTopic())) { |
| | | localSecret.setText("密钥:" + HDLLinkConfig.getInstance().getLocalSecret()); |
| | | } |
| | | } |
| | | }; |
| | | HDLLink.getInstance().registerAllTopicsListener(allTopicsListener); |
| | |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | responseTv.setText(msg); |
| | | Log.d("panlili", "MainActivity.java:getSceneList-----> " + msg); |
| | | } |
| | | |
| | | @Override |
| | |
| | | // {"id":"8a5eaa143ce943b987b577df5a66759b","time_stamp":"1637040217235","objects":[{"sid":"04010560D2C7170A0A0100000000","name":"回家模式","status":"off","group":"255","delay":"0","modify_time":"1634871490"},{"sid":"04010560D2C76E0A0A0100010000","name":"离家模式","status":"off","group":"255","delay":"0","modify_time":"1634785823"}]} |
| | | |
| | | /** |
| | | * 获取场景详情 |
| | | * 执行成功的话 响应code为200 |
| | | */ |
| | | void getScene() { |
| | | tv.setText("场景读取"); |
| | | responseTv.setText(""); |
| | | //场景sid列表,支持批量读取 |
| | | List<String> sids = new ArrayList<>(); |
| | | sids.add("0201034C50B53F0A0A0100011100"); |
| | | sids.add("0201037F50B53F0A0A0100021100"); |
| | | HDLLink.getInstance().getScene(sids, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | responseTv.setText(msg); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 控制场景 |
| | | * 执行成功的话 响应code为200 |
| | | */ |