Device Details UI BizBundle

Last Updated on : 2023-06-28 03:36:47download

Device Details UI BizBundle supports the following features:

  • Modify device information, such as the device icon, device name, and room.
  • Query device information, such as device ID and signal strength.
  • Provide FAQ and feedback. FAQ UI BizBundle must be additionally integrated.
  • Check for firmware updates. OTA UI BizBundle must be additionally integrated.
  • Manage group devices. Group Management UI BizBundle must be additionally integrated.
  • Create device groups. Group Management UI BizBundle must be additionally integrated.
  • Enable multi-control linkage. Multi-Control Association UI BizBundle must be additionally integrated.
  • Configure backup Wi-Fi networks.
  • Notify users of devices getting offline.
  • Remove devices.
  • Add shortcuts to the home screen.

Integrate with the UI BizBundle

Create a project

  1. Integrate Smart Life App SDK for Android into your project with Android Studio and add the framework of the UI BizBundle to your project. For more information, see Integrate with Framework.

  2. Add the configuration file deviceDetail.json and [deviceEditConfigList.json] to the assets directory of the main project. Example:

    [
      {
        "name": "headerSection",
        "items": [
          {
            "cellType": "header"
          },
          {
            "cellType": "device_info"
          },
          {
            "cellType": "net_setting"
         },
         {
            "cellType": "group_edit_devices"
          }
        ]
      },
      {
        "name": "offLineWarnSection",
        "header": {
          "cellType": "section_off_line_warn"
        },
        "items": [
          {
            "cellType": "off_line_warn"
          }
        ]
      },
      {
        "name": "otherSection",
        "header": {
          "cellType": "section_other"
        },
        "items": [
          {
            "cellType": "bind_multi_control_link"
          },
          {
            "cellType": "group_create"
          },
          {
            "cellType": "help_and_feedback"
          },
          {
            "cellType": "add_icon_to_home_screen"
          },
          {
            "cellType": "show_infrared_gateway_sub_device"
          },
          {
            "cellType": "check_device_network"
          },
          {
            "cellType": "check_firmware_update"
          },
          {
            "cellType": "c_test_insert"
          },
          {
            "cellType": "c_test_async_insert"
          }
        ]
      },
      {
        "name": "footerSection",
        "header": {
          "cellType": "device_detail_empty"
        },
        "items": [
          {
            "cellType": "footer"
          }
        ],
        "margin": {
          "top": 16
        }
      }
    ]
    
  • deviceEditConfigList.json

    {
    "deviceEdit": [
        {
        "name": "deviceEdit",
        "items": [
            {
            "cellType": "dev_icon"
            },
            {
            "cellType": "set_icon"
            },
            {
            "cellType": "set_name"
            },
            {
            "cellType": "set_position"
            }
        ]
        }
    ]
    }
    
    
    
    • The type parameter of deviceDetail determines the sequence in which sub-items of device details are displayed. If type is removed from a sub-item, this sub-item will also be removed.
    • The type parameter of devBaseInfo determines the sequence in which sub-items of basic device information are displayed. If type is removed from a sub-item, this sub-item will also be removed.
type of deviceDetail Device feature
header View and modify the device icon, device name, and location.
device_info Display device information.
net_setting Display backup Wi-Fi networks.
group_edit_devices Manage group devices. Group Management UI BizBundle must be additionally integrated.
off_line_warn Notify users of devices getting offline.
section_other This is a section header and serves no purpose.
bind_multi_control_link Multi-Control Association UI BizBundle
group_create Create device groups. Group Management UI BizBundle must be additionally integrated.
help_and_feedback Provide FAQ and feedback. FAQ UI BizBundle must be additionally integrated.
check_firmware_update Check for firmware updates. OTA UI BizBundle must be additionally integrated.
show_infrared_gateway_sub_device Show remote controls.
device_detail_empty This is an empty view and serves no purpose.
footer Remove devices.
type of deviceEdit Device feature
dev_icon The device icon.
set_icon The item of the icon.
set_name The item of the name.
set_position The item of the location.

Configure build.gradle

dependencies {
	implementation 'com.tuya.smart:tuyasmart-bizbundle-panelmore:4.2.0-33'
}

Implement features

Parameters

Parameter Description
extra_panel_dev_id The device ID.
extra_panel_name Device Name
extra_panel_group_id The group ID.

Example

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);

Customize specific features

  1. You can add the custom parameter type to deviceDetail in configList.json.

    The value of type must start with c_, for example, c_test_insert.

    [
        {
        "name": "headerSection",
        "items": [
            {
            "cellType": "header"
            },
            {
            "cellType": "device_info"
            },
            {
            "cellType": "net_setting"
            },
            {
            "cellType": "group_edit_devices"
            }
        ]
        },
        {
        "name": "offLineWarnSection",
        "header": {
            "cellType": "section_off_line_warn"
        },
        "items": [
            {
            "cellType": "off_line_warn"
            }
        ]
        },
        {
        "name": "otherSection",
        "header": {
            "cellType": "section_other"
        },
        "items": [
            {
            "cellType": "bind_multi_control_link"
            },
            {
            "cellType": "group_create"
            },
            {
            "cellType": "help_and_feedback"
            },
            {
            "cellType": "add_icon_to_home_screen"
            },
            {
            "cellType": "show_infrared_gateway_sub_device"
            },
            {
            "cellType": "check_device_network"
            },
            {
            "cellType": "check_firmware_update"
            },
            {
            "cellType": "c_test_insert"
            },
            {
            "cellType": "c_test_async_insert"
            }
        ]
        },
        {
        "name": "footerSection",
        "header": {
            "cellType": "device_detail_empty"
        },
        "items": [
            {
            "cellType": "footer"
            }
        ],
        "margin": {
            "top": 16
        }
        }
    ]
    
  2. Implement com.tuya.smart.archer.api.cell.IArcherCell or com.tuya.smart.archer.api.AbsBaseArcherCell.

Initialize settings

API description

    override fun onCreate(context: Context?) {} 

Parameters

Parameter Description
context The context for Android.

Set display logic

To implement AbsBaseArcherCell, getContainerControl().updateCell(this) must be triggered for update. Otherwise, show() will not be called.

To implement IArcherCell, getContainerControl().updateCall(this) cannot be called, but show() is called automatically.

override suspend fun show(): Boolean {}

Set and bind a view

The click event can be implemented in onBindView.

 override fun onCreateView(parent: ViewGroup): View? {}
 override fun onBindView(view: View): ITYBaseData?{}

Display configuration

Configure the current class in tyarchercell_config.

    {
      "name": "c_test_insert",
      "type": 1,
      "clazz": "com.tuya.smart.bizubundle.panelmore.demo.CTestInsertCell"
    },
    {
      "name": "c_test_async_insert",
      "type": 1,
      "clazz": "com.tuya.smart.bizubundle.panelmore.demo.CTestAsyncInsertCell"
    }
Parameter Description
name cellType configured in deviceDetail.json
type The type of item. Valid values: 1 indicates an item and 2 indicates a header. In the current section, if an item is displayed, a header must be displayed.
clazz The class of item.

Get device or group information based on device details

 val service:IPluginDeviceDetailInfoService? = MicroServiceManager.getInstance()
            .findServiceByInterface(IPluginDeviceDetailInfoService::class.java.name)
        val deviceId = service?.getCurrentDevId();
        val groupId = service?.getCurrentGroupId();

Check whether current user is home administrator

val absDevBaseInfoService: AbsDevBaseInfoService? by lazy {
        MicroServiceManager.getInstance()
            .findServiceByInterface(AbsDevBaseInfoService::class.java.name)
    }
val isAdmin = absDevBaseInfoService.getIsAdmin()

Add shortcuts to home screen

You need to develop a navigation method that allows shortcuts to be added to the home screen. Meanwhile, your app must be granted permissions to create shortcuts. Perform the following steps:

  1. Define activity-alias and set the entry activity startup mode to singleTask.

    <activity-alias
    			android:name="com.tuya.smart.hometab.activity.shortcut"
    			android:exported="true"
    			android:targetActivity=".MainActivity">  // This is the entry to implement navigation to `activity`.
    
  2. Implement route parsing with RouterPresenter of the app module.

    if (PINNED_SHORTCUT_ALIAS.equals(intent.getComponent().getClassName())) {
    			String url = null;
    			try {
    				url = intent.getStringExtra("url");
    			} catch (Throwable t) {
    				LogUtil.e(TAG, "get url error", t);
    			}
    			L.d(TAG, "schemeJump: " + url);
    			if (TextUtils.isEmpty(url)) {
    				return null;
    			}
    			if (isInnerRouter(url)) {
    				return new RouterPresenter(url, intent.getExtras());
    			}
    			return null;
    
    		}
    		return null;
    ...
    
  3. Rewrite the method onNewIntent and call Router to parse the route.

  4. Implement route-based navigation in onResume.

Display infrared sub-devices

API description

 /**
     * Indicates whether infrared sub-devices are displayed on the homepage.
     *
     * @param homeId
     * @param devId
     * @return
     */
    public abstract boolean getInfraredSubDevDisplaySettings(long homeId, String devId);

Parameters

Parameter Description
homeId The home ID.
devId The device ID.

API description

/**
	* Get the logic that indicates whether to display infrared sub-devices.
	* @param homeId
	* @param devId
	* @return
	*/
public abstract boolean getInfraredDevDisplaySettings(long homeId, String devId);

Parameters

Parameter Description
homeId The home ID.
devId The infrared device ID.

API description

/**
	* Registers a sub-device status listener.
	*
	* @param listener
	*/
public abstract void registerInfraredSubDevDisplaySettingsListener(OnInfraredSubDevDisplaySettingsListener listener);

/**
	* Unregisters a sub-device status listener.
	*
	* @param listener
	*/
public abstract void unregisterInfraredSubDevDisplaySettingsListener(OnInfraredSubDevDisplaySettingsListener listener);

Parameters

Parameter Description
homeId The home ID.
devId The infrared device ID.

Example

                IPluginInfraredSubDevDisplayService service = MicroServiceManager.getInstance().findServiceByInterface(IPluginInfraredSubDevDisplayService.class.getName());
		service.registerInfraredSubDevDisplaySettingsListener(new OnInfraredSubDevDisplaySettingsListener() {
			@Override
			public void onDisplaySettingsChanged(Long homeId, String gwId, Boolean shown) {
				// Updates and returns the device list.
				// `gwId`: the infrared device ID.
				// `devId`: the infrared sub-device ID.
				//  service.getInfraredSubDevDisplaySettings(homeId,devId) Returns the setting of whether to display infrared sub-devices on the homepage.

				Log.e(TAG, " changed " + "homeId: " + homeId + " devId" + gwId + " show" + shown);
				Toast.makeText(DeviceDetailActivity.this, "infrared Changed", Toast.LENGTH_LONG).show();
			}

			@Override
			public void onDisplaySettingsRemoved(Long homeId, String gwId) {
				Log.e(TAG, " removed " + "homeId: " + homeId + " devId" + gwId);
				Toast.makeText(DeviceDetailActivity.this, "infrared removed", Toast.LENGTH_LONG).show();
			}
		});

Deprecated API

Deprecated API Alternative method
PanelMoreItemClickService.devClickItem Implement IArcherCell or AbsArcherCell.
PanelMoreItemClickService.devClickItem Implement IArcherCell or AbsArcherCell.
PanelMoreMenuService.insertDevMenuItemAsync Use the preceding alternative method.
PanelMoreMenuService.insertDevMenuItem/insertDevMenuItemAsync/insertDevMenuItem/ Use the preceding alternative method.
PanelMoreInfraredSubDevDisplayService IPluginInfraredSubDevDisplayService