1. 设备详情业务包

1.1. 功能介绍

  • 设备信息编辑(设备头像、设备所在房间、名称)
  • 设备信息查询 (ID、信号等)
  • 备用网络设置
  • 离线提醒功能
  • 删除设备
  • 常见问题与反馈 (需要接入帮助中心业务包)
  • 检查固件升级(需要接入OTA业务包)

1.2. 设备详情业务包集成

1.2.1. 创建工程

  • 在 Android Studio 中建立你的工程,接入公版 SDK 并完成业务包框架接入
  • 主工程的assets目录下,放入configList.json配置文件,如果文件已存在,则在configList.json添加deviceDetail。具体配置入下:
{
  "deviceDetail": [
    {
      "type": "header"
    },
    {
      "type": "device_info"
    },
    {
      "type": "device_net_info"
    },
    {
      "type": "off_line_warn"
    },
    {
      "type": "section_other"
    },
    {
      "type":"help_and_feedback"
    },
    {
      "type":"check_device_network"
    },
    {
      "type":"check_firmware_update"
    },
    {
      "type": "empty",
      "height": 10
    },
    {
      "type": "footer"
    }
  ]
}

注意deviceDetail type的顺序会影响设备详情页子功能展示的顺序。如过移除type,则相应也会移除设备详情页子功能。

deviceDetail type 功能点
header 查看修改设备图标,名称,位置
device_info 设备信息
device_net_info 设备备用网络
off_line_warn 设备离线提醒
section_other 分区头,无实际功能
help_and_feedback 常见问题与反馈,需要集成常见问题与反馈业务包
check_firmware_update 检查固件升级,需要集成固件升级业务包
empty 空view,无实际功能
footer 移除设备

1.2.2. module 的 build.gradle 配置

dependencies {
  implementation 'com.tuya.smart:tuyasmart-bizbundle-panelmore:3.22.0-6'
}

1.3. 功能调用

参数说明

参数 说明
extra_panel_dev_id 设备ID
extra_panel_name 设备名称

示例代码

UrlBuilder urlBuilder = new UrlBuilder(PanelMoreActivity.this, "panelMore");
String devId = edt.getText().toString().trim();
DeviceBean deviceBean = TuyaHomeSdk.getDataInstance().getDeviceBean(devId);
Bundle bundle = new Bundle();
bundle.putString("extra_panel_dev_id",devId);
bundle.putString("extra_panel_name",deviceBean.getName());
urlBuilder.putExtras(bundle);
UrlRouter.execute(urlBuilder);

1.4. 自定义子功能

  • configList.json文件的deviceDetail插入自定义type。注意type值必须以“c_”开头
{"deviceDetail": [
    {
      "type": "header"
    },
    {
      "type": "device_info"
    },
    {
      "type": "device_net_info"
    },
    {
      "type": "off_line_warn"
    },
    {
      "type": "section_other"
    },
    {
      "type":"help_and_feedback"
    },
    {
      "type":"check_device_network"
    },
    {
      "type":"check_firmware_update"
    },
    {
      "type":"c_test_insert"
    },
    {
      "type":"c_test_async_insert"
    },
    {
      "type": "empty",
      "height": 10
    },
    {
      "type": "footer"
    }
  ],}
  • 实现AbsPanelMoreExpandService。
    实现自定义type的点击事件
    接口说明
    public abstract void devClickItem(Context context, int action, DeviceBean deviceBean, boolean isAdmin);
参数说明
参数 说明
context android context
action 点击事件标识
deviceBean 设备信息
isAdmin 是否是管理员
示例代码
 @Override
    public void devClickItem(Context context, int action, TextBean data, DeviceBean deviceBean, boolean isAdmin) {
        if(action == R.id.action_test_insert){
            // Complementary subfunction
        }
    }
同步插入子功能item
接口说明
    public abstract IMenuBean insertDevMenuItem(Context context, String type, boolean isAdmin, DeviceBean deviceBean, float order);
参数说明
参数 说明
context android context
type configList里面定义的type
isAdmin 是否是管理员
deviceBean 设备信息
order type在configList位置,用于生成IMenuBean
示例代码
 @Override
    public IMenuBean insertDevMenuItem(Context context, String type, boolean isAdmin, DeviceBean deviceBean, float order) {
        if(isAdmin && TextUtils.equals(type,"c_test_insert")){
          return new  IMenuBean("title","subtitle","1",
                    java.lang.String.valueOf(R.id.action_test_insert),
                    order,
                    "test_insert");
        }

        return null;
    }
异步插入子功能item
接口说明
    public abstract void insertDevMenuItemAsync(Context context, String type, boolean isAdmin, DeviceBean deviceBean, float order, IMenuItemCallback callback);
参数说明
参数 说明
context android context
type configList里面定义的type
isAdmin 是否是管理员
deviceBean 设备信息
order type在configList位置,用于生成IMenuBean
IMenuItemCallback 用于插入子功能item
示例代码
 @Override
     @Override
    public void insertDevMenuItemAsync(Context context, String type, boolean isAdmin, DeviceBean deviceBean, float order, IMenuItemCallback callback) {
        if(isAdmin && TextUtils.equals(type,"c_test_async_insert")){
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    callback.setMenuItem( new  IMenuBean("async_title","async_subtitle","0",
                            java.lang.String.valueOf(R.id.action_test_async_insert),
                            order));
                }
            },1000*5);
        }
    }
子功能item包装类IMenuBean
参数说明
参数 说明
title 标题
subTitle 子标题
click 目前只支持字符串"1"
target 点击事件标识
order 标识在列表的位置
示例代码
new  IMenuBean("title","subtitle","1",java.lang.String.valueOf(R.id.action_test_insert),order);
异步插入子功能IMenuItemCallback
接口说明
void setMenuItem(IMenuBean item);
参数说明
参数 说明
IMenuBean 子功能item包装类IMenuBean
示例代码
 callback.setMenuItem(new IMenuBean("async_title","async_subtitle","0",
                            java.lang.String.valueOf(R.id.action_test_async_insert),
                            order));
  • 注册AbsPanelMoreExpandService的实现类,建议在application#onCreate中调用该方法
    TuyaWrapper.registerService(AbsPanelMoreExpandService.class, new PanelMoreExpandServiceImpl());

results matching ""

    No results matching ""