注:本帖为转载系列,征得“半颗心脏”博主(我老乡)的同意。哎呀,老家人才还是蛮多的
原贴地址:第一篇:认识开源框架结构,导入PK、APP的id和secret。
第二篇:详细分析在设备列表的代码块,如何修改自定义的设备图片。
第三篇 : 分析设备详情界面的中如何发送各种指令到云端:boolean、int、String类型。
第四篇 : 分析怎么做好自己的指令是否成功发送到云端对应的逻辑处理
1、 认识无所不在的类 Gi1、 必须涉及到的类 GizWifiDeviceListener.class。
- private GizWifiDeviceListener listener = new GizWifiDeviceListener() {
- @Override
- public void didReceiveData(GizWifiErrorCode result, GizWifiDevice device, ConcurrentHashMap<String, Object> dataMap, int sn) {
- super.didReceiveData(result, device, dataMap, sn);
- //先判断是否为正确回调
- if (result == GizWifiErrorCode.GIZ_SDK_SUCCESS) {
- //首先从回调的数据中判断这个回调设备是否为当前界面的设备,通过唯一的mac地址
- if (device.getMacAddress().equals(mDevice.getMacAddress())) {
- //判断dataMap是否为null
- if (dataMap.get("data") != null) {
- ConcurrentHashMap<String, Object> mtempData = (ConcurrentHashMap<String, Object>) dataMap.get("data");
- if (mtempData.get("iswater") != null) {
- iswater = (boolean) mtempData.get("iswater");
- }
- if (mtempData.get("open_off") != null) {
- open_off = (boolean) mtempData.get("open_off");
- }
- mHandler.sendEmptyMessage(101);
- }
- }
- }
- }
- };
2、 比如可以这样子做,实现回调和UI交互。- 如下所示,现在全局变量声明一个 弹窗 ProgressDialog 对象。当有数据回调时候,就把它显示出来,当回调回来码为正确的话(表示正确回调)就会把这个弹窗关闭,否则没有回调表示没有成功的话,一直在转。
- //弹窗
- private ProgressDialog mProgressDialog ;
- private GizWifiDeviceListener listener = new GizWifiDeviceListener() {
- @Override
- public void didReceiveData(GizWifiErrorCode result, GizWifiDevice device, ConcurrentHashMap<String, Object> dataMap, int sn) {
- super.didReceiveData(result, device, dataMap, sn);
- mProgressDialog =new ProgressDialog(GosDeviceControlActivity.this);
- mProgressDialog.setTitle("正在同步云端数据!");
- //弹窗设置不可点击
- mProgressDialog.setCancelable(false);
- //显示弹窗
- mProgressDialog.show();
- //先判断是否为正确回调
- if (result == GizWifiErrorCode.GIZ_SDK_SUCCESS) {
- //关闭弹窗
- mProgressDialog.dismiss();
- //首先从回调的数据中判断这个回调设备是否为当前界面的设备,通过唯一的mac地址
- if (device.getMacAddress().equals(mDevice.getMacAddress())) {
- if (dataMap.get("data") != null) {
- ConcurrentHashMap<String, Object> mtempData = (ConcurrentHashMap<String, Object>) dataMap.get("data");
- if (mtempData.get("iswater") != null) {
- iswater = (boolean) mtempData.get("iswater");
- }
- if (mtempData.get("open_off") != null) {
- open_off = (boolean) mtempData.get("open_off");
- }
- mHandler.sendEmptyMessage(101);
- }
- }
- }
- }
- };
- 如果回调不成功,表示设备未能正常接受到数据,就这样显示效果啦!一直在转,转不停!
-
|