设备详情 UI 业务包

更新时间:2022-02-17 07:13:43下载pdf

涂鸦 智慧居住 设备详情 UI 业务包包含了以下功能:

  • 设备信息编辑:包括设备图标、设备所在房间、设备名称等
  • 设备信息查询:包括设备 ID、连接信号等
  • 群组设备管理:您需要额外接入 设备群组 UI 业务包
  • 创建群组:您需要额外接入 设备群组 UI 业务包
  • 备用网络设置
  • 离线提醒功能
  • 删除设备

集成业务包

创建工程

  1. 在 Android Studio 中建立您的工程,接入智慧租住 App SDK,并完成业务包 业务包框架接入

  2. 主工程的 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"
    		}
    		]
    }
    
    • deviceDetailtype 的顺序会影响设备详情页子功能展示的顺序。如果移除某个 type,则相应也会移除设备详情页子功能。
    • devBaseInfotype 的顺序会影响设备基础信息子功能展示的顺序。如果移除某个 type,则相应也会移除功能入口。
    deviceDetail type 设备功能
    header 查看修改设备图标、名称、位置
    device_info 显示设备信息
    device_net_info 显示设备备用网络
    group_edit_devices 群组设备管理,您需要额外接入 设备群组 UI 业务包
    off_line_warn 设备离线提醒
    section_other 分区头,无实际功能
    group_create 创建群组,您需要额外接入 设备群组 UI 业务包
    empty 一个空的 view,无实际功能
    footer 移除设备
    devBaseInfo type 设备功能
    dev_icon 设备图标
    set_icon 图标 item
    set_name 名称 item
    set_position 位置 item

build.gradle 配置

dependencies {
	implementation 'com.tuya.smart:tuyasmart-residence-bizbundle-panelmore:1.0.0-1'
}

功能调用

参数说明

参数 说明
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);

自定义子功能

  1. configList.json 文件的 deviceDetail 插入自定义 type

    type 的值必须以 c_ 开头,例如 c_test_insert

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

实现自定义 type 的点击事件

接口说明

    public abstract void devClickItem(Context context, int action, DeviceBean deviceBean, boolean isAdmin);

参数说明

参数 说明
context 安卓 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 安卓 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
	}
}

完成以上示例代码后,实现 com.tuya.smart.panel.usecase.panelmore.service.AbsPanelMoreExpandService

同步插入子功能 item

接口说明

public abstract IMenuBean insertDevMenuItem(Context context, String type, boolean isAdmin, DeviceBean deviceBean, float order);

参数说明

参数 说明
context 安卓 Context
type 您在 configList.json 中定义的 type
isAdmin 用户是否是管理员
deviceBean 设备信息
order typeconfigList.json 中的位置,用于生成 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 安卓 Context
type 您在 configList.json 中定义的 type
isAdmin 用户是否是管理员
groupBean 群组信息
order typeconfigList.json 中的位置,用于生成 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 安卓 Context
type 您在 configList.json 中定义的 type
isAdmin 用户是否是管理员
deviceBean 设备信息
order typeconfigList.json 中的位置,用于生成 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 安卓 Context
type 您在 configList.json 中定义的 type
isAdmin 用户是否是管理员
groupBean 群组信息
order typeconfigList.json 中的位置,用于生成 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());