设备详情 UI 业务包

更新时间:2022-02-17 08:05:06下载pdf

设备详情 UI 业务包包含了以下功能:

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

业务包集成

创建工程

  • 在 Android Studio 中建立您的工程,接入公版 SDK 并完成业务包 框架接入
  • 主工程的assets目录下,放入 configList.json 配置文件,如果文件已存在,则在 configList.json 添加 deviceDetail 以及 devBaseInfo。具体配置入下:

    {
    	"deviceDetail": [
    		{
    		"type": "header"
    		},
    		{
    		"type": "device_info"
    		},
    		{
    		"type": "device_net_info"
    		},
    		{
            "type":"group_edit_devices"
            },
    		{
    		"type": "off_line_warn"
    		},
    		{
    		"type": "section_other"
    		},
    		{
    		  "type":"bind_multi_control_link"
    		},
    		{
            "type":"group_create"
            },
    		{
    		"type":"help_and_feedback"
    		},
    		{
    		"type":"check_device_network"
    		},
    		{
    		"type":"check_firmware_update"
    		},
    		{
    		"type": "empty",
    		"height": 10
    		},
    		{
    		"type": "footer"
    		}
    	],
    	"devBaseInfo": [
            {
              "type": "dev_icon"
            },
            {
              "type": "set_icon"
            },
            {
              "type": "set_name"
            },
            {
              "type": "set_position"
            }
          ]
    }
    

    deviceDetail type的顺序会影响设备详情页子功能展示的顺序。如果移除 type,则相应也会移除设备详情页子功能。devBaseInfo type 的顺序会影响设备基础信息子功能展示的顺序。如果移除 type,则相应也会移除功能入口。

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

module 的 build.gradle 配置

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

功能调用

参数说明

参数 说明
extra_panel_dev_id 设备ID
extra_panel_name 设备名称
extra_panel_group_id 群组ID

示例代码

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());
bundle.putLong("extra_panel_group_id",groupId);

urlBuilder.putExtras(bundle);
UrlRouter.execute(urlBuilder);

自定义子功能

  • 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"
    	}
    ],}
    
  • 实现com.tuya.smart.panel.usecase.panelmore.service.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
		}
	}

实现自定义 type 的群组点击事件

接口说明

public abstract void groupClickItem(Context context, int action, GroupBean groupBean, boolean isAdmin);

参数说明

参数 说明
context Android context
action 点击事件标识
groupBean 群组信息
isAdmin 用户是否是管理员

示例代码

@Override
public void groupClickItem(Context context, int action, GroupBean groupBean, 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 IMenuBean insertGroupMenuItem(Context context, String type, boolean isAdmin, GroupBean groupBean, float order);

参数说明

参数 说明
context Android context
type configList里面定义的 type
isAdmin 是否是管理员
groupBean 群组信息
order type在configList位置,用于生成 IMenuBean

示例代码

@Override
public IMenuBean insertGroupMenuItem(Context context, String type, boolean isAdmin, GroupBean groupBean, 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);
    }
    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
	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

接口说明

public abstract void insertGroupMenuItemAsync(Context context,String type,boolean isAdmin, GroupBean groupBean,float order,IMenuItemCallback callback);

参数说明

参数 说明
context android context
type configList里面定义的type
isAdmin 是否是管理员
groupBean 群组信息
order type在configList位置,用于生成IMenuBean
IMenuItemCallback 用于插入子功能item

示例代码

@Override
    public void insertGroupMenuItemAsync(Context context, String type, boolean isAdmin, GroupBean 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","1",
                            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());