diff --git a/en/application-dev/reference/apis/js-apis-uitest.md b/en/application-dev/reference/apis/js-apis-uitest.md index 673744bf89745e4b929bddf57db88f7de730c33f..f3ed68ea09339eec7f3b2901b7e3d2037bf47108 100644 --- a/en/application-dev/reference/apis/js-apis-uitest.md +++ b/en/application-dev/reference/apis/js-apis-uitest.md @@ -8,9 +8,9 @@ This module provides the following functions: - [Component9+](#component9): represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection. - [Driver9+](#driver9): works as the entry class and provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot. - [UiWindow9+](#uiwindow9): works as the entry class and provides APIs for obtaining window attributes, dragging windows, and adjusting window sizes. -- [By(deprecated)](#bydeprecated): provides UI component feature description APIs for component filtering and matching. This API is deprecated since API version 9. You are advised to use [On9+](#on9) instead. -- [UiComponent(deprecated)](#uicomponentdeprecated): represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection. This API is deprecated since API version 9. You are advised to use [Component9+](#component9) instead. -- [UiDriver(deprecated)](#uidriverdeprecated): works as the entry class and provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot. This API is deprecated since API version 9. You are advised to use [Driver9+](#driver9) instead. +- [By(deprecated)](#bydeprecated): provides UI component feature description APIs for component filtering and matching. This class is deprecated since API version 9. You are advised to use [On9+](#on9) instead. +- [UiComponent(deprecated)](#uicomponentdeprecated): represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection. This class is deprecated since API version 9. You are advised to use [Component9+](#component9) instead. +- [UiDriver(deprecated)](#uidriverdeprecated): works as the entry class and provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot. This class is deprecated since API version 9. You are advised to use [Driver9+](#driver9) instead. >**NOTE** > @@ -160,10 +160,8 @@ Since API version 9, the UiTest framework provides a wide range of UI component The API capabilities provided by the **On** class exhibit the following features: - Allow one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component. - - Provide multiple match patterns for component attributes. - -- Support absolute positioning and relative positioning for components. APIs such as [ON.isBefore](#isbefore9) and [ON.isAfter](#isafter9) can be used to specify the features of adjacent components to assist positioning. +- Support absolute positioning and relative positioning for components. APIs such as [ON.isBefore](#isbefore9) and [ON.isAfter](#isafter9) can be used to specify the features of adjacent components to assist positioning. All APIs provided in the **On** class are synchronous. You are advised to use the static constructor **ON** to create an **On** object in chain mode. @@ -1208,7 +1206,7 @@ For details about the error codes, see [UiTest Error Codes](../errorcodes/errorc ```js async function demo() { let driver = Driver.create(); - let button = await driver.findComponent(ON.type('Scroll')); + let scrollBar = await driver.findComponent(ON.type('Scroll')); let button = await scrollBar.scrollSearch(ON.text('next page')); } ``` @@ -2439,7 +2437,7 @@ For details about the error codes, see [UiTest Error Codes](../errorcodes/errorc ```js async function demo() { let driver = Driver.create(); - let obeserver = await driver.createUiEventObserve(); + let observer = await driver.createUIEventObserver() } ``` @@ -2950,7 +2948,7 @@ async function demo() { ## UIEventObserver10+ -UI event listener. +Implements a UI event listener. ### once('toastShow') @@ -2971,6 +2969,7 @@ Subscribes to events of the toast component. This API uses a callback to return ```js async function demo() { + let driver = Driver.create(); let observer = await driver.createUIEventObserver() let callback = (UIElementInfo)=>{ console.info(UIElementInfo.bundleName) @@ -3000,6 +2999,7 @@ Subscribes to events of the dialog component. This API uses a callback to return ```js async function demo() { + let driver = Driver.create(); let observer = await driver.createUIEventObserver() let callback = (UIElementInfo)=>{ console.info(UIElementInfo.bundleName) @@ -3013,15 +3013,16 @@ async function demo() { ## By(deprecated) The UiTest framework provides a wide range of UI component feature description APIs in the **By** class to filter and match components. -The API capabilities provided by the **By** class exhibit the following features: -- Allow one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component. +The API capabilities provided by the **By** class exhibit the following features: + +- Allow one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component. - Provide multiple match patterns for component attributes. - Support absolute positioning and relative positioning for components. APIs such as [By.isBefore(deprecated)](#isbeforedeprecated) and [By.isAfter(deprecated)](#isafterdeprecated) can be used to specify the features of adjacent components to assist positioning. All APIs provided in the **By** class are synchronous. You are advised to use the static constructor **BY** to create a **By** object in chain mode. -This API is deprecated since API version 9. You are advised to use [On9+](#on9) instead. +This class is deprecated since API version 9. You are advised to use [On9+](#on9) instead. ```js BY.text('123').type('button'); @@ -3347,7 +3348,7 @@ In **UiTest**, the **UiComponent** class represents a component on the UI and pr All APIs provided in this class use a promise to return the result and must be invoked using **await**. -This API is deprecated since API version 9. You are advised to use [Component9+](#component9) instead. +This class is deprecated since API version 9. You are advised to use [Component9+](#component9) instead. ### click(deprecated) @@ -3729,7 +3730,7 @@ The **UiDriver** class is the main entry to the UiTest framework. It provides AP All APIs provided by this class, except for **UiDriver.create()**, use a promise to return the result and must be invoked using **await**. -This API is deprecated since API version 9. You are advised to use [Driver9+](#driver9) instead. +This class is deprecated since API version 9. You are advised to use [Driver9+](#driver9) instead. ### create(deprecated) diff --git a/en/application-dev/reference/apis/js-apis-wallpaper.md b/en/application-dev/reference/apis/js-apis-wallpaper.md index 4e869d9d32db75389926d06212fe085f3781955b..0e76092672c8aaa5b85ada2d79a95eb003ddbd2b 100644 --- a/en/application-dev/reference/apis/js-apis-wallpaper.md +++ b/en/application-dev/reference/apis/js-apis-wallpaper.md @@ -137,9 +137,87 @@ try { } ``` +## wallpaper.setCustomWallpaper10+ + +setCustomWallpaper(source: string, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void + +Sets the content from a specified URI as the wallpaper. This API works only when com.ohos.sceneboard is set. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.SET_WALLPAPER + +**System capability**: SystemCapability.MiscServices.Wallpaper + +**System API**: This is a system API. + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| source | string | Yes| URI of the custom wallpaper.| +| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Example** + +```js +let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip"; +try { + wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { + if (error) { + console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); + return; + } + console.log(`success to setCustomWallpaper.`); + }); +} catch (error) { + console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); +} + +``` + +## wallpaper.setCustomWallpaper10+ + +setCustomWallpaper(source: string, wallpaperType: WallpaperType): Promise<void> + +Sets the content from a specified URI as the wallpaper. This API works only when com.ohos.sceneboard is set. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.SET_WALLPAPER + +**System capability**: SystemCapability.MiscServices.Wallpaper + +**System API**: This is a system API. + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| source | string | Yes| URI of the custom wallpaper.| +| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```js +let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip"; +try { + wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { + console.log(`success to setCustomWallpaper.`); + }).catch((error) => { + console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); + }); +} catch (error) { + console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); +} +``` + ## wallpaper.on('wallpaperChange')10+ -on(type: 'wallpaperChange', callback: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType) => void): void +on(type: 'wallpaperChange', callback: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) => void): void Subscribes to wallpaper change events. @@ -152,7 +230,7 @@ Subscribes to wallpaper change events. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is fixed at **'wallpaperChange'**.| -| callback | function | Yes| Callback used to return the wallpaper type and wallpaper resource type.
- wallpaperType
Wallpaper type.
- resourceType
Wallpaper resource type.| +| callback | function | Yes| Callback used to return the wallpaper type and wallpaper resource type.
- **wallpaperType**: wallpaper type.
- **resourceType**: wallpaper resource type.
- **uri**: URI of the wallpaper resource.| **Example** @@ -169,7 +247,7 @@ try { ## wallpaper.off('wallpaperChange')10+ -off(type: 'wallpaperChange', callback?: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType) => void): void +off(type: 'wallpaperChange', callback?: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) => void): void Unsubscribes from wallpaper change events. @@ -182,7 +260,7 @@ Unsubscribes from wallpaper change events. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. The value is fixed at **'wallpaperChange'**.| -| callback | function | No| Callback used for unsubscription. If this parameter is not set, this API unsubscribes from all callbacks of the specified event type.
- wallpaperType
Wallpaper type.
- resourceType
Wallpaper resource type.| +| callback | function | No| Callback used for unsubscription. If this parameter is not set, this API unsubscribes from all callbacks of the specified event type.
- **wallpaperType**: wallpaper type.
- **resourceType**: wallpaper resource type.
- **uri**: URI of the wallpaper resource.| **Example**