Lighting Scenario UI BizBundle

Last Updated on : 2024-11-18 11:33:16download

Lighting Scenario UI BizBundle supports the configurations of all smart lights in the same room. It provides abundant color picker styles and a bunch of scenario libraries. You can integrate the UI BizBundle to easily implement desired smart home lighting scenarios.

Feature overview

The Lighting Scenario UI BizBundle supports the following features:

  • Create a lighting scenario
  • Modify a lighting scenario, including the scenario icon, scenario name, and all device scenes.
  • Preview the custom scene of a single device that supports the cool white light (C), cool and warm white light (CW), colored light (RGB), cool white and colored light (RGBC), and white and colored light (RGBCW).
  • Preview the mode, color, and flashing scenes of a single device.
  • Preview a lighting scenario.
  • Adjust the brightness of a single device.
  • Adjust the brightness of all devices in a scenario.

Fast integration

The UI BizBundle relies on Smart Life App SDK. Before the following procedure, you must first finish the steps in Preparation and Fast Integration with Smart Life App SDK for Android.

  1. Create a project.

    Smart Life App SDK for Android is integrated into your project with Android Studio. The UI BizBundle is added to your project. For more information, see Integration with UI BizBundle SDK for Android.

  2. Configure the build.gradle file.

    	dependencies {
    		     implementation 'com.tuya.smart:tuyasmart-bizbundle-light_scene:4.2.0-33'
    	}
    
    
  3. Obfuscate the code.

    #fresco
    -keep class com.facebook.drawee.backends.pipeline.Fresco
    -keep @com.facebook.common.internal.DoNotStrip class *
    -keepclassmembers class * {
    @com.facebook.common.internal.DoNotStrip *;
    }
    
    #tuya
    -keep class com.tuya.**{*;}
    -dontwarn com.tuya.**
    
  4. (Optional) Configure multilingual options.

    Currently, the UI BizBundle supports Chinese and English only. However, in the following fields, you can customize value.

    • Settings in English: Copy and paste the following code block to the file res/values/strings.xml:

      <?xml version="1.0" encoding="utf-8"?>
      <resources>
          <string name="ty_light_scene_add">New Lighting Scenario</string>
          <string name="ty_light_scene_add_area_tip">Choose space to create a lighting Scenario</string>
          <string name="ty_light_lamp_add_area_empty">No Lamps</string>
          <string name="ty_light_scene_add_device_tip">Setting lamps to create a lighting Scenario</string>
          <string name="ty_light_scene_set_name_icon">Choose an icon and name you like</string>
          <string name="ty_light_scene_default_name">New lighting scenario</string>
          <string name="ty_light_scene_edit">Edit lighting scenario</string>
          <string name="ty_light_scene_manage_nav_title"></string>
          <string name="ty_light_scene_manage_delete_tips">Are you sure you want to delete?</string>
          <string name="ty_light_scene_manage_delete_scene_tips_detail">Relevant schedules in this scenario will also be deleted</string>
          <string name="ty_scene_add_lamp_offline_tip">Lamp is offline</string>
          <string name="ty_scene_add_lamp_lack_gateway">Lighting not connected to gateway</string>
          <string name="ty_scene_add_lamp_group_empty_tip">No device in this group</string>
          <string name="ty_light_scene_edit_quit_tip">Are you sure to exit?</string>
          <string name="ty_light_scene_edit_quit_tip_detail">The content will not be saved after exiting</string>
          <string name="ty_light_scene_icon_select">Select Icon</string>
          <string name="ty_light_scene_add_success">Saved</string>
          <string name="ty_light_scene_main_light">Functional lighting</string>
          <string name="ty_light_scene_secondary_light">Ambience lighting</string>
          <string name="ty_light_scene_secondary_light_source">Ambience lighting</string>
      </resources>
      
    • Settings in Chinese: Copy and paste the following code block to the file res/values-zh/strings.xml.

      <?xml version="1.0" encoding="utf-8"?>
      <resources>
          <string name="ty_light_scene_add">添加新灯光场景</string>
          <string name="ty_light_scene_add_area_tip">选择一个空间区域创建灯光环境</string>
          <string name="ty_light_lamp_add_area_empty">暂无灯具</string>
          <string name="ty_light_scene_add_device_tip">按照主次调节灯光设置整体效果</string>
          <string name="ty_light_scene_set_name_icon">选择一个自己喜欢的图标和名称</string>
          <string name="ty_light_scene_default_name">新灯光场景</string>
          <string name="ty_light_scene_edit">编辑灯光场景</string>
          <string name="ty_light_scene_manage_nav_title">场景管理</string>
          <string name="ty_light_scene_manage_delete_tips">确定要删除?</string>
          <string name="ty_light_scene_manage_delete_scene_tips_detail">该场景下的相关日程也将会被删除</string>
          <string name="ty_scene_add_lamp_offline_tip">灯具已离线</string>
          <string name="ty_scene_add_lamp_group_empty_tip">该组灯中无设备</string>
          <string name="ty_scene_add_lamp_lack_gateway">灯具未连接网关</string>
          <string name="ty_light_scene_edit_quit_tip">确认退出?</string>
          <string name="ty_light_scene_edit_quit_tip_detail">退出后所填内容将不会保存</string>
          <string name="ty_light_scene_icon_select">选择图标</string>
          <string name="ty_light_scene_add_success">添加成功</string>
          <string name="ty_light_scene_main_light">功能灯光</string>
          <string name="ty_light_scene_secondary_light">氛围灯光</string>
          <string name="ty_light_scene_secondary_light_source">氛围灯光</string>
      </resources>
      

Functional description

Data model of TuyaLightSceneBean

Property Type Description
sceneId String The unique identifier for the scenario.
code String The input parameter code to run the scenario.
parentRegionId String The room ID of the scenario.
icon String The scenario icon.
clickIcon String The single-tap icon to implement interactions in the scenario.
name String The name of the scenario.

Business API methods

Provide services

The UI BizBundle relies on the implementation of SceneLightingService to provide services.

Example

// Returns the services provided by the Lighting Scenario UI BizBundle.
SceneLightingService sceneLightingService = MicroContext.findServiceByInterface(SceneLightingService.class.getName());

Create a lighting scenario

API description

Create a lighting scenario

void gotoSceneLightingActivity(Context context, int requestCode);

Parameter description

Parameter Type Description
context Context The Context object.
requestCode int The value of requestCode must be larger than 0. After a scenario is created, you can get the code from onActivityResult().

Example

SceneLightingService sceneLightingService = MicroContext.findServiceByInterface(SceneLightingService.class.getName());
                if(null != sceneLightingService) {
                    sceneLightingService.gotoSceneLightingActivity(mContext, 100);
                }

Modify a lighting scenario

API description

Opens the page to modify a lighting scenario.

editSceneLightingActivity(Context context, TuyaLightSceneBean tuyaLightSceneBean, int requestCode);

Parameter description

Parameter Type Description
context Context The Context object.
tuyaLightSceneBean TuyaLightSceneBean The Bean data of the lighting scenario.
requestCode int The value of requestCode must be larger than 0. After a scenario is modified, you can get the code from onActivityResult().

Example

SceneLightingService sceneLightingService = MicroContext.findServiceByInterface(SceneLightingService.class.getName());
        if(null != sceneLightingService) {
            sceneLightingService.editSceneLightingActivity(v.getContext(), tuyaLightSceneBean, 101);
        }

Cloud service API methods

Class name Description
TuyaLightSceneSdk The lighting scenario SDK.

Query a list of lighting scenarios

API description

Returns a list of lighting scenarios.

void getAllLightSceneList(long gid, ITuyaLightResultCallback<ArrayList<TuyaLightSceneBean>> callback);

Parameter description

Parameter Description
gid The current home ID.
callback The callback.

Example

TuyaLightSceneSdk.getTuyaLightSceneManagerInstance().getAllLightSceneList(homeId, new ITuyaLightResultCallback<ArrayList<TuyaLightSceneBean>>() {
            @Override
            public void onSuccess(ArrayList<TuyaLightSceneBean> tuyaLightSceneBeans) {

            }

            @Override
            public void onFailure(String code, String detail) {

            }
        });

Run a lighting scenario

API description

Runs a lighting scenario

void executeLightScene(long gid, ITuyaLightResultCallback<Boolean> callback);

Parameter description

Parameter Description
code The input parameter code to run the scenario.
gid The current home ID.
callback The callback.

Example

TuyaLightSceneSdk.newLightSceneInstance(tuyaLightSceneBean.getCode()).executeLightScene(homeId, new ITuyaLightResultCallback<Boolean> (){
                    @Override
                    public void onSuccess(Boolean aBoolean) {

                    }

                    @Override
                    public void onFailure(String code, String detail) {

                    }
                });