diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index 09a65cea53e545c3afb58924b498512242a9285f..7b5257160b8dbb88637d17c8946ea49028638166 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -28,6 +28,8 @@ - application/[FormExtensionContext](js-apis-formextensioncontext.md) - application/[PermissionRequestResult](js-apis-permissionrequestresult.md) - application/[ServiceExtensionContext](js-apis-service-extension-context.md) + - [InputMethodExtensionAbility](js-apis-inputmethod-extension-ability.md) + - [InputMethodExtensionContext](js-apis-inputmethod-extension-context.md) - FA and Stage Models - [@ohos.ability.dataUriUtils](js-apis-DataUriUtils.md) - [@ohos.ability.errorCode](js-apis-ability-errorCode.md) diff --git a/en/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md b/en/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md new file mode 100644 index 0000000000000000000000000000000000000000..eb94104e5e3dfc430db1f395f48ac0302d1e0a1c --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-inputmethod-extension-ability.md @@ -0,0 +1,66 @@ +# InputMethodExtensionAbility + +The **InputMethodExtensionAbility** module provides the **InputMethodExtensionAbility** and **InputMethodExtensionContext** APIs that you can implement to develop input methods and manage their lifecycles. + +> **NOTE** +> +> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> The APIs of this module can be used only in the stage model. + +## Modules to Import + +``` +import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; +``` + +## Attributes + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| context | [InputMethodExtensionContext](js-apis-inputmethod-extension-context.md) | Yes| No| Context of the **InputMethodExtension**, which is inherited from **ExtensionContext**.| + + +## InputMethodExtensionAbility.onCreate() + +onCreate(want: Want): void; + +Called when the **InputMethodExtension** ability is started to implement initialization. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-Want.md) | Yes| Information related to the **InputMethodExtension** ability, including the ability name and bundle name. | + +**Example** + + ```js + class InputMethodExt extends InputMethodExtensionAbility { + onCreate(want) { + console.log('onCreate, want:' + want.abilityName); + } + } + ``` + + +## InputMethodExtensionAbility.onDestroy() + +onDestroy(): void; + +Called when this **InputMethodExtension** ability is destroyed to clear resources. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Example** + + ```js + class InputMethodExt extends InputMethodExtensionAbility { + onDestroy() { + console.log('onDestroy'); + } + } + ``` diff --git a/en/application-dev/reference/apis/js-apis-inputmethod-extension-context.md b/en/application-dev/reference/apis/js-apis-inputmethod-extension-context.md new file mode 100644 index 0000000000000000000000000000000000000000..ae8312d452b3a7a0fdea35b0330b5f092ddef05d --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-inputmethod-extension-context.md @@ -0,0 +1,169 @@ +# InputMethodExtensionContext + +The **InputMethodExtensionContext** module, inherited from **ExtensionContext**, provides context for **InputMethodExtension** abilities. + +You can use the APIs of this module to start, terminate, connect, and disconnect abilities. + +> **NOTE** +> +> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> The APIs of this module can be used only in the stage model. + +## Modules to Import + +``` +import InputMethodExtensionContext from '@ohos.inputmethodextensioncontext'; +``` + +## Usage + +Before using the **InputMethodExtensionContext** module, you must define a child class that inherits from **InputMethodExtensionAbility**. + +```js + import InputMethodExtensionAbility from '@ohos.inputmethodextensionability'; + class MainAbility extends InputMethodExtensionAbility { + onCreate() { + let context = this.context; + } + } +``` + +## InputMethodExtensionContext.startAbility + +startAbility(want: Want, callback: AsyncCallback<void>): void; + +Starts an ability with the **want** parameter. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability, such as the ability name and bundle name.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result.| + +**Example** + + ```js + let want = { + "bundleName": "com.example.myapp", + "abilityName": "MyAbility"}; + this.context.startAbility(want, (err) => { + console.log('startAbility result:' + JSON.stringify(err)); + }); + ``` + +## InputMethodExtensionContext.startAbility + +startAbility(want: Want, options?: StartOptions): Promise\; + +Starts an ability with the mandatory **want** and optional **options** parameters. This API uses a promise to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability, such as the ability name and bundle name.| +| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.| + +**Return value** + + | Type| Description| + | -------- | -------- | + | Promise<void> | Promise used to return the result.| + +**Example** + + ```js + let want = { + "bundleName": "com.example.myapp", + "abilityName": "MyAbility" + }; + this.context.startAbility(want).then((data) => { + console.log('success:' + JSON.stringify(data)); + }).catch((error) => { + console.log('failed:' + JSON.stringify(error)); + }); + + ``` + +## InputMethodExtensionContext.startAbility + +startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void + +Starts an ability with the **want** and **options** parameters. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.| +| options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Parameters used for starting the ability.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result.| + +**Example** + + ```js + var want = { + "deviceId": "", + "bundleName": "com.extreme.test", + "abilityName": "MainAbility" + }; + var options = { + windowMode: 0, + }; + this.context.startAbility(want, options, (error) => { + console.log("error.code = " + error.code) + }) + ``` + +## InputMethodExtensionContext.terminateSelf + +terminateSelf(callback: AsyncCallback<void>): void; + +Terminates this ability. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | -------------------------------------- | +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| + +**Example** + + ```js +this.context.terminateSelf((err) => { + console.log('terminateSelf result:' + JSON.stringify(err)); +}); + ``` + +## InputMethodExtensionContext.terminateSelf + +terminateSelf(): Promise<void>; + +Terminates this ability. This API uses a promise to return the result. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + + | Type| Description| + | -------- | -------- | + | Promise<void> | Promise used to return the result.| + +**Example** + + ```js + this.context.terminateSelf().then((data) => { + console.log('success:' + JSON.stringify(data)); + }).catch((error) => { + console.log('failed:' + JSON.stringify(error)); + }); + ``` diff --git a/en/application-dev/reference/apis/js-apis-inputmethod.md b/en/application-dev/reference/apis/js-apis-inputmethod.md index 47f0d3429179406f598940f977baab87ef7b3482..f29975c5b4459acfd3d22e1a0f40b0579969ba24 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethod.md +++ b/en/application-dev/reference/apis/js-apis-inputmethod.md @@ -45,8 +45,8 @@ Obtains an **[InputMethodController](#inputmethodcontroller)** instance. **Return value** -| Type | Description | -| ----------------------------------------- | ---------------------------- | +| Type | Description | +| ----------------------------------------------- | ------------------------ | | [InputMethodController](#inputmethodcontroller) | Returns the current **InputMethodController** instance.| **Example** @@ -77,9 +77,9 @@ Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance. ``` ## inputMethod.switchInputMethod9+ -switchInputMethod(target: InputmethodProperty, callback: AsyncCallback<boolean>): void; +switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void -Switches to another input method. This API uses an asynchronous callback to return the result. This API can be used only in the stage model. +Switches to another input method. This API can be used only in the stage model. It uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -88,20 +88,28 @@ Switches to another input method. This API uses an asynchronous callback to retu | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |target | [InputmethodProperty](#inputmethodproperty8) | Yes| Input method to switch to.| -| callback | AsyncCallback<boolean> | Yes| Callback used to return the execution result. | +| callback | AsyncCallback<boolean> | Yes| Callback used to return the execution result.| **Example** ```js - inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => { - prompt.showToast({message:"Input method switched." + this.imeList[this.flag].packageName, duration: 200}); - }); +inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard", methodId:"com.example.kikakeyboard"} ,(err,result) => { + if (err) { + console.error("switchInputMethod err: " + JSON.stringify(err)); + return; + } + if (result) { + console.info("Success to switchInputMethod.(callback)"); + } else { + console.error("Failed to switchInputMethod.(callback)"); + } +}); ``` ## inputMethod.switchInputMethod9+ -switchInputMethod(target: InputmethodProperty): Promise<boolean> +switchInputMethod(target: InputMethodProperty): Promise<boolean> -Switches to another input method. This API uses a promise to return the result. This API can be used only in the stage model. +Switches to another input method. This API can be used only in the stage model. It uses a promise to return the result. If the required parameter is not passed in, an exception is thrown. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -112,27 +120,55 @@ Switches to another input method. This API uses a promise to return the result. |target | [InputmethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| **Return value** + | Type | Description | | ----------------------------------------- | ---------------------------- | -| Promise\ | Promise used to return the execution result. | +| Promise\ | Promise used to return the execution result.| **Example** ```js - inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => { - prompt.showToast({message:"Input method switched." + this.imeList[this.flag].packageName, duration: 200}); - }); +inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard", methodId:"com.example.kikakeyboard"}).then((result) => { + if (result) { + console.info("Success to switchInputMethod.(promise)"); + } else { + console.error("Failed to switchInputMethod.(promise)"); + } +}).catch((err) => { + console.error("switchInputMethod promise err: " + err); +}) +``` +## inputMethod.getCurrentInputMethod9+ + +getCurrentInputMethod(): InputMethodProperty + +Obtains the current input method. This API synchronously returns the **InputmethodProperty** instance of the current input method. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type | Description | +| -------------------------------------------- | ------------------------ | +| [InputmethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method. | + +**Example** + + +```js +var currentIme = inputMethod.getCurrentInputMethod(); ``` + ## InputMethodController -In the following API examples, you must first use [getInputMethodController](#inputmethodgetinputmethodcontroller) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. +In the following API examples, you must first use **[getInputMethodController](#inputmethodgetinputmethodcontroller)** to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. ### stopInput stopInput(callback: AsyncCallback<boolean>): void -Hides the keyboard. This API uses an asynchronous callback to return the result. +Hides the keyboard. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -145,16 +181,24 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. **Example** ```js - InputMethodController.stopInput((error)=>{ - console.info('stopInput'); - }); +InputMethodController.stopInput((error, result) => { + if (error) { + console.error("failed to stopInput because: " + JSON.stringify(error)); + return; + } + if (result) { + console.info("Success to stopInput.(callback)"); + } else { + console.error("Failed to stopInput.(callback)"); + } +}); ``` ### stopInput stopInput(): Promise<boolean> -Hides the keyboard. This API uses an asynchronous callback to return the result. +Hides the keyboard. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -162,29 +206,200 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. | Type| Description| | -------- | -------- | -| Promise<boolean> | Promise used to return whether the keyboard is successfully hidden. | +| Promise<boolean> | Promise used to return whether the keyboard is successfully hidden.| **Example** ```js - var isSuccess = InputMethodController.stopInput(); - console.info('stopInput isSuccess = ' + isSuccess); +InputMethodController.stopInput().then((result) => { + if (result) { + console.info("Success to stopInput.(promise)"); + } else { + console.error("Failed to stopInput.(promise)"); + } +}).catch((err) => { + console.error("stopInput promise err: " + err); +}) +``` + +### showSoftKeyboard9+ ### + +showSoftKeyboard(callback: AsyncCallback<void>): void + +Shows this soft keyboard. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| callback | AsyncCallback<void> | Yes | Callback used to return the execution result.| + +**Example** + +```js +InputMethodController.showSoftKeyboard((err) => { + if (err == undefined) { + console.info('showSoftKeyboard success'); + } else { + console.error('showSoftKeyboard failed because : ' + JSON.stringify(err)); + } +}) +``` + + +### showSoftKeyboard9+ ### + +showSoftKeyboard(): Promise<void> + +Shows this soft keyboard. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type | Description | +| ------------------- | ------------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```js +InputMethodController.showSoftKeyboard().then(async (err) => { + console.log('showSoftKeyboard success'); +}).catch((err) => { + console.error('showSoftKeyboard promise err: ' + JSON.stringify(err)); +}); +``` + +### hideSoftKeyboard9+ ### + +hideSoftKeyboard(callback: AsyncCallback<void>): void + +Hides this soft keyboard. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| callback | AsyncCallback<void> | Yes | Callback used to return the execution result.| + +**Example** + +```js +InputMethodController.hideSoftKeyboard((err) => { + if (err == undefined) { + console.info('hideSoftKeyboard success'); + } else { + console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err)); + } +}) +``` + + +### hideSoftKeyboard9+ ### + +hideSoftKeyboard(): Promise<void> + +Hides this soft keyboard. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Return value** + +| Type | Description | +| ------------------- | ------------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```js +InputMethodController.hideSoftKeyboard().then(async (err) => { + console.log('hideSoftKeyboard success'); +}).catch((err) => { + console.error('hideSoftKeyboard promise err: ' + JSON.stringify(err)); +}); ``` ## InputMethodSetting8+ -In the following API examples, you must first use [getInputMethodSetting](#inputmethodgetinputmethodcontroller) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. +In the following API examples, you must first use **[getInputMethodSetting](#inputmethodgetinputmethodcontroller)** to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. + +### listInputMethod9+ + +listInputMethod(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void + +Obtains a list of activated or deactivated input methods. This API uses an asynchronous callback to return the result. If the required two parameters are not passed in, an exception is thrown. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------- | ---- | ----------------------------- | +| enable | boolean | Yes | Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods. | +| callback | Array<[InputMethodProperty](#inputmethodproperty8)> | Yes | Callback used to return a list of activated or deactivated input methods. | + +**Example** + +```js +imeList: Array = null +InputMethodSetting.listInputMethod(true, (err,data) => { + if (err) { + console.error("listInputMethod failed because: " + JSON.stringify(err)); + return; + } + console.log("listInputMethod success"); + this.imeList = data; + }); +``` + +### listInputMethod9+ + +listInputMethod(enable: boolean): Promise<Array<InputMethodProperty>> + +Obtains a list of activated or deactivated input methods. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. + +**System capability**: SystemCapability.MiscServices.InputMethodFramework + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------- | ---- | ----------------------- | +| enable | boolean | Yes | Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.| + +**Return value** + +| Type | Description | +| ------------------------------------------------------------ | ----------------------------- | +| Promise> | Promise used to return a list of activated or deactivated input methods. | + +**Example** + +```js +imeList: Array = null +InputMethodSetting.listInputMethod(true).then((data) => { + console.info("listInputMethod success"); + this.imeList = data; +}).catch((err) => { + console.error("listInputMethod promise err: " + err); +}) +``` ### listInputMethod listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void -Obtains the list of installed input methods. This API uses an asynchronous callback to return the result. +Obtains a list of installed input methods. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** + | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | | callback | Array<[InputMethodProperty](#inputmethodproperty8)> | Yes | Callback used to return the list of installed input methods.| @@ -192,42 +407,48 @@ Obtains the list of installed input methods. This API uses an asynchronous callb **Example** ```js - InputMethodSetting.listInputMethod((properties)=>{ - for (var i = 0;i < properties.length; i++) { - var property = properties[i]; - console.info(property.packageName + "/" + property.methodId); +imeList: Array = null +InputMethodSetting.listInputMethod((err,data) => { + if (err) { + console.error("listInputMethod failed because: " + JSON.stringify(err)); + return; } - }); + console.log("listInputMethod success"); + this.imeList = data; + }); ``` ### listInputMethod -listInputMethod(): Array<InputMethodProperty> +listInputMethod(): Promise<Array<InputMethodProperty>> -Obtains the list of installed input methods. This API uses an asynchronous callback to return the result. +Obtains a list of installed input methods. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** + | Type | Description | | ----------------------------------------------------------- | ---------------------- | -| Promise> | Promise used to return the list of installed input methods. | +| Promise> | Promise used to return the list of installed input methods.| **Example** ```js - var properties = InputMethodSetting.listInputMethod(); - for (var i = 0;i < properties.length; i++) { - var property = properties[i]; - console.info(property.packageName + "/" + property.methodId); - } +imeList: Array = null +InputMethodSetting.listInputMethod().then((data) => { + console.info("listInputMethod success"); + this.imeList = data; +}).catch((err) => { + console.error("listInputMethod promise err: " + err); +}) ``` ### displayOptionalInputMethod displayOptionalInputMethod(callback: AsyncCallback<void>): void -Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. +Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. If the required parameter is not passed in, an exception is thrown. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -240,16 +461,20 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono **Example** ```js - InputMethodSetting.displayOptionalInputMethod(()=>{ - console.info('displayOptionalInputMethod is called'); - }); +InputMethodSetting.displayOptionalInputMethod((err) => { + if (err) { + console.error("displayOptionalInputMethod failed because: " + JSON.stringify(err)); + return; + } + console.info("displayOptionalInputMethod success"); +}); ``` ### displayOptionalInputMethod displayOptionalInputMethod(): Promise<void> -Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. +Displays a dialog box for selecting an input method. This API uses a promise to return the result. If any parameter is passed in, an exception is thrown. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -257,10 +482,14 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono | Type| Description| | -------- | -------- | -| Promise<void> | Promise used to return the execution result. | +| Promise<void> | Promise that returns no value.| **Example** ```js - InputMethodSetting.displayOptionalInputMethod(); +InputMethodSetting.displayOptionalInputMethod().then(() => { + console.info("displayOptionalInputMethod success.(promise)"); +}).catch((err) => { + console.error("displayOptionalInputMethod promise err: " + err); +}) ``` diff --git a/en/application-dev/reference/apis/js-apis-timer.md b/en/application-dev/reference/apis/js-apis-timer.md index f9e174b5147370f465e140d03aeba6b3802380a0..cf8ca596bd72517835c6bd277c0bf29ebf2b7213 100644 --- a/en/application-dev/reference/apis/js-apis-timer.md +++ b/en/application-dev/reference/apis/js-apis-timer.md @@ -1,5 +1,10 @@ # Timer +The **Timer** module provides basic timer capabilities. You can use the APIs of this module to execute functions at the specified time. + +> **NOTE** +> +> The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## setTimeout @@ -7,6 +12,8 @@ setTimeout(handler[,delay[,…args]]): number Sets a timer for the system to call a function after the timer goes off. +**System capability**: SystemCapability.ArkUI.ArkUI.Full + **Parameters** | Name| Type| Mandatory| Description| @@ -23,15 +30,15 @@ Sets a timer for the system to call a function after the timer goes off. **Example** -```js -export default { - setTimeOut() { - var timeoutID = setTimeout(function() { - console.log('delay 1s'); - }, 1000); + ```js + export default { + setTimeOut() { + var timeoutID = setTimeout(function() { + console.log('delay 1s'); + }, 1000); + } } -} -``` + ``` ## clearTimeout @@ -40,6 +47,8 @@ clearTimeout(timeoutID: number): void Cancels the timer created via **setTimeout()**. +**System capability**: SystemCapability.ArkUI.ArkUI.Full + **Parameters** | Name| Type| Mandatory| Description| @@ -48,16 +57,16 @@ Cancels the timer created via **setTimeout()**. **Example** -```js -export default { - clearTimeOut() { - var timeoutID = setTimeout(function() { - console.log('do after 1s delay.'); - }, 1000); - clearTimeout(timeoutID); + ```js + export default { + clearTimeOut() { + var timeoutID = setTimeout(function() { + console.log('do after 1s delay.'); + }, 1000); + clearTimeout(timeoutID); + } } -} -``` + ``` ## setInterval @@ -66,6 +75,8 @@ setInterval(handler[, delay[, ...args]]): number Sets a repeating timer for the system to repeatedly call a function at a fixed interval. +**System capability**: SystemCapability.ArkUI.ArkUI.Full + **Parameters** | Name| Type| Mandatory| Description| @@ -82,15 +93,15 @@ Sets a repeating timer for the system to repeatedly call a function at a fixed i **Example** -```js -export default { - setInterval() { - var intervalID = setInterval(function() { - console.log('do very 1s.'); - }, 1000); + ```js + export default { + setInterval() { + var intervalID = setInterval(function() { + console.log('do very 1s.'); + }, 1000); + } } -} -``` + ``` ## clearInterval @@ -99,6 +110,8 @@ clearInterval(intervalID: number): void Cancels the repeating timer set via **setInterval()**. +**System capability**: SystemCapability.ArkUI.ArkUI.Full + **Parameters** | Name| Type| Mandatory| Description| @@ -107,13 +120,13 @@ Cancels the repeating timer set via **setInterval()**. **Example** -```js -export default { - clearInterval() { - var intervalID = setInterval(function() { - console.log('do very 1s.'); - }, 1000); - clearInterval(intervalID); + ```js + export default { + clearInterval() { + var intervalID = setInterval(function() { + console.log('do very 1s.'); + }, 1000); + clearInterval(intervalID); + } } -} -``` \ No newline at end of file + ```