Device Details UI BizBundle

Last Updated on : 2024-02-21 08:18:42download

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.
  • Configure backup Wi-Fi networks.
  • Notify users of devices getting offline.
  • Remove devices.

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 files deviceDetail.json, deviceEditConfigList.json, and thingarchercell_config.json to the assets directory of the main project.

    To get the details of the configuration files, download ui-bizbundle-sample on GitHub, go to devicedetail > assets, and then check the JSON file. The following sections provide a simple description of these configuration files:

    • deviceDetail.json

      The sequence of the type parameter values in 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 following code block is used only as an example. You can get ui-bizbundle-sample on GitHub.

      [
      {
          "name": "headerSection",
          "items": [
          {
              "cellType": "header"
          },
          {
              "cellType": "device_info"
          }
          ]
      },
      {
          "name": "otherSection",
          "header": {
          "cellType": "section_other"
          },
          "items": [
          {
              "cellType": "device_from"
          },
          {
              "cellType": "bind_multi_control_link"
          },
          {
              "cellType": "sub_device_migrate"
          }
          ]
      },
      {
          "name": "footerSection",
          "header": {
          "cellType": "device_detail_empty"
          },
          "items": [
          {
              "cellType": "footer"
          }
          ],
          "margin": {
          "top": 16
          }
      }
      ]
      
      Parameter Description
      name The name of the group.
      items The list of sub-items in the group. The cellType parameter represents the name of a sub-item.
      header The header content of the group.
      footer The footer content of the group.
      margin The pitch between groups.
    • deviceEditConfigList.json

      The sequence of the type parameter values in deviceEditConfigList 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.

      {
      "deviceEdit": [
          {
          "name": "deviceEdit",
          "items": [
              {
              "cellType": "dev_icon"
              },
              {
              "cellType": "set_icon"
              },
              {
              "cellType": "set_name"
              },
              {
              "cellType": "set_position"
              }
          ]
          }
      ]
      }
      
      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.
    • thingarchercell_config.json

      To add cell or groupCell, add the information in the required format in thingarchercell_config.

      The following code block is used only as an example. You can get ui-bizbundle-sample on GitHub.

      {
      "archerGroup": [
          {
          "name": "headerSection",
          "clazz": "com.thingclips.smart.device_detail.group.HeaderGroup"
          }
      ],
      "archerCell": [
          {
          "name": "check_device_network",
          "type": 1,
          "clazz": "com.thingclips.smart.device_detail.cell.CheckDeviceNetworkArcherCell"
          },
          {
          "name": "product_instruction",
          "type": 1,
          "clazz": "com.thingclips.smart.device_detail.cell.ProductInstructionArcherCell"
          },
          {
          "name": "section_off_line_warn",
          "type": 2,
          "clazz": "com.thingclips.smart.device_detail.cell.OffLineWarnHeaderCell"
          },
          {
          "name": "location_manage",
          "type": 1,
          "clazz": "com.thingclips.smart.device_detail.cell.LocationManageArcherCell"
          },
          {
          "name": "group_edit_devices",
          "type": 1,
          "clazz": "com.thingclips.smart.device_detail.cell.GroupEditDeviceArcherCell"
          }
      ]
      }
      
      Parameter Description
      name cellType configured in deviceDetail.json
      type The type of item. Valid values:
      • 1: item
      • 2: header
      In the current section, if an item is displayed, a header must be displayed.
      clazz The class of item.

Configure build.gradle

sdk_version description

  • When the sdk_version is 2.0.0-cube.2, make sure the Cube deployed in the cloud is 2.0 or later.
  • When the sdk_version is 2.1.0-cube.1, make sure the Cube deployed in the cloud is 2.1 or later.
dependencies {
    implementation 'com.thingclips.smart:thingsmart-bizbundle-panelmore:${sdk_version}'
}

Implement features

Parameters

Parameter Description
extra_panel_dev_id The device ID.
extra_panel_name The 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 = ThingHomeSdk.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 sub-items

  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"
            }
        ]
        }
    ]
    
  2. Implement com.thingclips.smart.archer.api.cell.IArcherCell or com.thingclips.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 an 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 deviceDetailArcherCellConfig.json.

{
      "name": "c_test_insert",
      "type": 1,
      "clazz": "com.thingclips.smart.bizubundle.panelmore.demo.CTestInsertCell"
    },
    {
      "name": "c_test_async_insert",
      "type": 1,
      "clazz": "com.thingclips.smart.bizubundle.panelmore.demo.CTestAsyncInsertCell"
    }

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.thingclips.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 listener for changes in the virtual infrared sub-device status.
     *
     * @param listener
     */
    public abstract void registerInfraredSubDevDisplaySettingsListener(OnInfraredSubDevDisplaySettingsListener listener);

    /**
     * Unregisters a listener for changes in the virtual infrared sub-device status.
     *
     * @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 the list of devices.
                // `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 to implement the new cell.
PanelMoreMenuService.insertDevMenuItem/insertDevMenuItemAsync/insertDevMenuItem/ Use the preceding alternative method to implement the new cell.
PanelMoreInfraredSubDevDisplayService IPluginInfraredSubDevDisplayService