public class LightAgent extends Object
This class allows you to query a light based on its ID, check whether the light supports a specific blinking effect, enable the light to blink with a certain effect, and turn on or off the light.
LightEffectSystemCapability.Sensors#MISC_DEVICE| 构造器 | 说明 |
|---|---|
LightAgent() |
Default constructor used to create a
LightAgent instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
List<Integer> |
getLightIdList() |
Obtains the IDs of all lights on the device.
|
boolean |
isEffectSupport(int lightId,
String effectId) |
Checks whether a specified light supports a preset blinking effect.
|
boolean |
isSupport(int lightId) |
Checks whether a specified light exists on the hardware device.
|
boolean |
turnOff() |
Turns off this light.
|
boolean |
turnOff(int lightId) |
Turns off a specified light.
|
boolean |
turnOn(int lightId,
String effectId) |
Turns on a specified light to perform a one-shot blink with a preset blinking effect.
|
boolean |
turnOn(int lightId,
LightEffect lightEffect) |
Turns on a specified light to perform a one-shot blink with a custom effect.
|
boolean |
turnOn(String effectId) |
Turns on this light to perform a one-shot blink with a preset blinking effect.
|
boolean |
turnOn(LightEffect lightEffect) |
Turns on this light to perform a one-shot blink with a custom blinking effect.
|
public LightAgent()
LightAgent instance.public List<Integer> getLightIdList()
This method can be used when you want to query the IDs of all lights on the device.
public boolean isSupport(int lightId)
This method can be used when you do not know whether a light exists on the device.
lightId - Indicates the ID of the light. You can use the getLightIdList()
method to obtain the light ID list.true if the light exists; returns false otherwise.public boolean isEffectSupport(int lightId,
String effectId)
Call this method to check whether the light supports a specific blinking effect before enabling the light to blink with this effect.
lightId - Indicates the ID of the light. You can use the getLightIdList()
method to obtain the light ID list.effectId - Indicates the preset blinking effect, which is described in
LightEffect.true if the light supports the specified blinking effect; returns
false otherwise.public boolean turnOn(int lightId,
String effectId)
lightId - Indicates the ID of the light. You can use the getLightIdList()
method to obtain the light ID list.effectId - Indicates the preset blinking effect, which is described in
LightEffect.true if the light blinks as expected; returns false
otherwise, for example, the preset blinking effect is not supported.public boolean turnOn(int lightId,
LightEffect lightEffect)
You can customize a blinking effect in LightEffect.
lightId - Indicates the ID of the light. You can use the getLightIdList()
method to obtain the light ID list.lightEffect - Indicates a custom blinking effect. The custom blinking effects can be
obtained using LightEffect(LightBrightness, int, int).true if the light blinks as expected; returns false
otherwise, for example, the custom blinking effect is not supported.LightEffectpublic boolean turnOn(String effectId)
effectId - Indicates the preset blinking effect, which is described in
LightEffect.true if the light blinks as expected; returns false
otherwise, for example, the preset blinking effect is not supported.public boolean turnOn(LightEffect lightEffect)
You can customize a blinking effect in LightEffect.
lightEffect - Indicates a custom blinking effect. The custom blinking effects can be
obtained using LightEffect(LightBrightness, int, int).true if the light blinks as expected; returns false
otherwise, for example, the custom blinking effect is not supported.LightEffectpublic boolean turnOff(int lightId)
This method can be used to turn off the light when you no longer need it.
lightId - Indicates the ID of the light. You can use the getLightIdList()
method to obtain the light ID list.true if the light is turned off; returns false otherwise.public boolean turnOff()
This method can be used to turn off the light when you no longer need it.
true if the light is turned off; returns false otherwise.