The **CommonEvent** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events, as well obtaining and setting the common event result code and result data.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are no longer maintained since API version 9. You are advised to use [@ohos.commonEventManager](js-apis-commonEventManager.md).
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
...
...
@@ -14,7 +15,7 @@ import CommonEvent from '@ohos.commonEvent';
## Support
Provides the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively.
The table below lists the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively.
@@ -168,7 +169,7 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. |
| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - | Indicates the common event that the airplane mode of the device has changed. |
| COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | - | Indicates the common event of screen splitting. |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has changed. |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has been updated. |
| COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. |
| COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | - | Indicates the common event that a quick fix is applied to the application. |
...
...
@@ -192,7 +193,7 @@ Publishes a common event. This API uses an asynchronous callback to return the r
| code | number | Yes | No | Result code of the common event. |
| data | string | Yes | No | Custom result data of the common event.|
| subscriberPermissions | Array\<string> | Yes | No | Permissions required for subscribers to receive the common event. |
| isOrdered | boolean | Yes | No | Whether the common event is an ordered one. |
| isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.|
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
| events | Yes | No | Array\<string> | Name of the common event to publish. |
| publisherPermission | Yes | No | string | Permissions required for publishers to publish the common event. |
| publisherDeviceId | Yes | No | string | Device ID. The value must be the ID of an existing device on the same network. |
| userId | Yes | No | number | User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.|
| priority | Yes | No | number | Subscriber priority. The value ranges from -100 to 1000. |
| events | Array\<string> | Yes | No | Name of the common event to publish. |
| publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. |
| publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of an existing device on the same network. |
| userId | number | Yes | No | User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.|
| priority | number | Yes | No | Subscriber priority. The value ranges from -100 to +1000. |
Loads an animation. Before calling this method, declare the **Animator('\__lottie\_ets')** object and check that the canvas layout is complete. This method can be used together with a lifecycle callback of the **Canvas** component, for example, **onAppear()** and **onPageShow()**.
Loads an animation. Before calling this API, declare the **Animator('__lottie_ets')** object and make sure the canvas layout is complete. This API can be used together with the lifecycle callback **onReady()** of the **Canvas** component.
| path | string | Yes | Path of the animation resource file in the HAP file. The resource file must be in JSON format. Example: **path: "common/lottie/data.json"**|
| container | object | Yes | Canvas drawing context. A **CanvasRenderingContext2D** object must be declared in advance.|
| render | string | Yes | Rendering type. The value can only be **"canvas"**. |
| loop | boolean \| number | No | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends; the default value is **true**. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays.|
| autoplay | boolean | No | Whether to automatically play the animation. The default value is **true**. |
| name | string | No | Custom animation name. In later versions, the name can be used to reference and control the animation. The default value is null. |
| autoplay | boolean | No | Whether to automatically play the animation.<br>Default value: **true** |
| name | string | No | Custom animation name. In later versions, the name can be used to reference and control the animation.<br/>Default value: null |
| initialSegment | [number, number] | No | Start frame and end frame of the animation, respectively. |
...
...
@@ -46,15 +46,16 @@ Loads an animation. Before calling this method, declare the **Animator('\__lotti
destroy(name: string): void
Destroys the animation. This method must be called when a page exits. This method can be used together with a lifecycle callback of the **Canvas** component, for example, **onDisappear()** and **onPageHide()**.
Destroys the animation. This API must be called when a page exits. This API can be used together with a lifecycle callback of the **Canvas** component, for example, **onDisappear()** and **onPageHide()**.
| name | string | Yes | Name of the animation to destroy, which is the same as the **name** in the **loadAnimation**interface. By default, all animations are destroyed.|
| name | string | Yes | Name of the animation to destroy, which is the same as the **name** in the **loadAnimation**API. By default, all animations are destroyed. |
**Example**
```ts
// xxx.ets
importlottiefrom'@ohos/lottieETS'
...
...
@@ -78,7 +79,7 @@ Destroys the animation. This method must be called when a page exits. This metho
| name | string | Yes | Name of the animation to play, which is the same as the **name** in the **loadAnimation**interface. By default, all animations are played.|
| name | string | Yes | Name of the animation to play, which is the same as the **name** in the **loadAnimation**API. By default, all animations are played. |
**Example**
...
...
@@ -152,7 +153,7 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani
| name | string | Yes | Name of the animation to pause, which is the same as the **name** in the **loadAnimation**interface. By default, all animations are paused.|
| name | string | Yes | Name of the animation to pause, which is the same as the **name** in the **loadAnimation**API. By default, all animations are paused. |
**Example**
...
...
@@ -165,13 +166,13 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani
togglePause(name: string): void
Pauses or plays a specified animation. This method is equivalent to the switching between **lottie.play()** and **lottie.pause()**.
Pauses or plays a specified animation. This API is equivalent to the switching between **lottie.play()** and **lottie.pause()**.
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation**interface. By default, all animations are paused.|
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation**API. By default, all animations are paused or played. |
**Example**
...
...
@@ -190,7 +191,7 @@ Stops the specified animation. The next time **lottie.play()** is called, the an
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation**interface. By default, all animations are paused.|
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation**API. By default, all animations are stopped. |
**Example**
...
...
@@ -209,8 +210,8 @@ Sets the playback speed of the specified animation.
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays in forward direction. If the value is less than 0, the animation plays in reversed direction. If the value is 0, the animation is paused. If the value is 1.0 or -1.0, the animation plays at the normal speed.|
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation**interface. By default, all animations are stopped.|
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays in forward direction. If the value is less than 0, the animation plays in reversed direction. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation**API. By default, all animations are set. |
**Example**
...
...
@@ -230,7 +231,7 @@ Sets the direction in which the specified animation plays.
| direction | AnimationDirection | Yes | Direction in which the animation plays. **1**: forwards; **-1**: backwards. When set to play backwards, the animation plays from the current playback progress to the first frame. When this setting is combined with **loop** being set to **true**, the animation plays backwards continuously. When the value of **speed** is less than 0, the animation also plays backwards.<br>AnimationDirection: 1 \| -1 |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation**interface. By default, all animations are set.|
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation**API. By default, all animations are set. |
**Example**
...
...
@@ -241,7 +242,7 @@ Sets the direction in which the specified animation plays.
## AnimationItem
Defines an **AnimationItem** object, which is returned by the **loadAnimation**interface and has attributes and interfaces. The attributes are described as follows:
Defines an **AnimationItem** object, which is returned by the **loadAnimation**API and has attributes and APIs. The attributes are described as follows:
@@ -253,11 +254,11 @@ Defines an **AnimationItem** object, which is returned by the **loadAnimation**
| totalFrames | number | Total number of frames in the animation segment that is being played. |
| frameRate | number | Frame rate (frame/s). |
| frameMult | number | Frame rate (frame/ms). |
| playSpeed | number | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is 0, the animation is paused.|If the value is **1.0** or **-1.0**, the animation plays at the normal speed.|
| playDirection | number | Playback direction. The options are **1** (forward) and **-1** (backward). |
| playSpeed | number | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. |
| playDirection | number | Playback direction.<br>**1**: forward.<br/>**-1**: backward. |
| playCount | number | Number of times the animation plays. |
| isPaused | boolean | Whether the current animation is paused. The value **true** means that the animation is paused. |
| autoplay | boolean | Whether to automatically play the animation upon completion of the loading. The value **false** means that the **play()**interface needs to be called to start playing.|
| autoplay | boolean | Whether to automatically play the animation upon completion of the loading. The value **false** means that the **play()**API needs to be called to start playing. |
| loop | boolean \| number | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays. |
| renderer | any | Animation rendering object, which depends on the rendering type. |
| animationID | string | Animation ID. |
...
...
@@ -309,7 +310,7 @@ Destroys an animation.
pause(name?: string): void
Pauses an animation. When the **play**interface is called next time, the animation is played from the current frame.
Pauses an animation. When the **play**API is called next time, the animation is played from the current frame.
**Parameters**
...
...
@@ -328,7 +329,7 @@ Pauses an animation. When the **play** interface is called next time, the animat
togglePause(name?: string): void
Pauses or plays an animation. This method is equivalent to the switching between **play** and **pause**.
Pauses or plays an animation. This API is equivalent to the switching between **play** and **pause**.
**Parameters**
...
...
@@ -347,7 +348,7 @@ Pauses or plays an animation. This method is equivalent to the switching between
stop(name?: string): void
Stops an animation. When the **play**interface is called next time, the animation is played from the first frame.
Stops an animation. When the **play**API is called next time, the animation is played from the first frame.
**Parameters**
...
...
@@ -372,7 +373,7 @@ Sets the playback speed of an animation.
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is 0, the animation is paused.|If the value is **1.0** or **-1.0**, the animation plays at the normal speed.|
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. |
**Example**
...
...
@@ -411,7 +412,7 @@ Sets the animation to stop at the specified frame or time.
| value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will stop. |
| isFrame | boolean | No | Whether to set the animation to stop at the specified frame. The value **true** means to set the animation to stop at the specified frame, and **false** means to set the animation to stop at the specified time progress. The default value is **false**.|
| isFrame | boolean | No | Whether to set the animation to stop at the specified frame. The value **true** means to set the animation to stop at the specified frame, and **false** means to set the animation to stop at the specified time progress.<br/>Default value: **false**|
| name | string | No | Name of the target animation. By default, the value is null. |
**Example**
...
...
@@ -435,8 +436,8 @@ Sets the animation to start from the specified frame or time progress.
| value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will start. |
| isFrame | boolean | Yes | Whether to set the animation to start from the specified frame. The value **true** means to set the animation to start from the specified frame, and **false** means to set the animation to start from the specified time progress. The default value is **false**.|
| name | string | No | Name of the target animation. By default, the value is null. |
| isFrame | boolean | Yes | Whether to set the animation to start from the specified frame. The value **true** means to set the animation to start from the specified frame, and **false** means to set the animation to start from the specified time progress.<br/>Default value: **false**|
| name | string | No | Name of the target animation.<br/>Default value: null |
**Example**
...
...
@@ -475,7 +476,7 @@ Sets the animation to play only the specified segment.
resetSegments(forceFlag: boolean): void
Resets the settings configured by the **playSegments**method to play all the frames.
Resets the settings configured by the **playSegments**API to play all the frames.
**Parameters**
...
...
@@ -526,13 +527,13 @@ Sets the precision of the **currentFrame** attribute to display floating-point n
getDuration(inFrames?: boolean): void
Obtains the duration (irrelevant to the playback speed) or number of frames for playing an animation sequence. The settings are related to the input parameter **initialSegment** of the **Lottie.loadAnimation**interface.
Obtains the duration (irrelevant to the playback speed) or number of frames for playing an animation sequence. The settings are related to the input parameter **initialSegment** of the **Lottie.loadAnimation**API.
| inFrames | boolean | No | Whether to obtain the duration or number of frames.<br>**true**: number of frames.<br>**false**: duration, in ms.<br>Default value: **false**|
| inFrames | boolean | No | Whether to obtain the duration or number of frames.<br>**true**: number of frames.<br>**false**: duration, in ms.<br/>Default value: **false**|
**Example**
...
...
@@ -545,7 +546,7 @@ Obtains the duration (irrelevant to the playback speed) or number of frames for
Adds an event listener. After the event is complete, the specified callback function is triggered. This method returns the function object that can delete the event listener.
Adds an event listener. After the event is complete, the specified callback is triggered. This API returns the function object that can delete the event listener.