提交 135bd4ac 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 94b29e69
......@@ -77,43 +77,48 @@ When designing a color picker, you can have the mouse pointer switched to the co
5. Set the mouse pointer to the default style.
```js
import pointer from '@ohos.multimodalInput.pointer';
import window from '@ohos.window';
// 1. Enable the color pickup function.
// 2. Obtain the window ID.
window.getTopWindow((error, windowClass) => {
windowClass.getProperties((error, data) => {
var windowId = data.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
// 3. Set the mouse pointer to the color picker style.
pointer.setPointerStyle(windowId, pointer.PointerStyle.COLOR_SUCKER).then(() => {
console.log(`Successfully set mouse pointer style`);
});
} catch (error) {
console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(message)}`);
}
});
window.getLastWindow(this.context, (error, windowClass) => {
if (error.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
return;
}
var windowId = windowClass.getWindowProperties().id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
// 3. Set the mouse pointer to the color picker style.
pointer.setPointerStyle(windowId, pointer.PointerStyle.COLOR_SUCKER).then(() => {
console.log(`Successfully set mouse pointer style`);
});
} catch (error) {
console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(`message`)}`);
}
});
// 4. End color pickup.
window.getTopWindow((error, windowClass) => {
windowClass.getProperties((error, data) => {
var windowId = data.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
// 5. Set the mouse pointer to the default style.
pointer.setPointerStyle(windowId, pointer.PointerStyle.DEFAULT).then(() => {
console.log(`Successfully set mouse pointer style`);
});
} catch (error) {
console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(message)}`);
}
});
window.getLastWindow(this.context, (error, windowClass) => {
if (error.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
return;
}
var windowId = windowClass.getWindowProperties().id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
// 5. Set the mouse pointer to the default style.
pointer.setPointerStyle(windowId, pointer.PointerStyle.DEFAULT).then(() => {
console.log(`Successfully set mouse pointer style`);
});
} catch (error) {
console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(`message`)}`);
}
});
```
......@@ -12,11 +12,11 @@ Application error management APIs are provided by the **errorManager** module. F
| API | Description |
| ------------------------------------------------------------ | ---------------------------------------------------- |
| registerErrorObserver(observer: ErrorObserver): number | Registers an observer for application errors. A callback will be invoked when an application error is detected. This API works in a synchronous manner. The return value is the SN of the registered observer.|
| unregisterErrorObserver(observerId: number, callback: AsyncCallback\<void\>): void | Unregisters an observer in callback mode. The number passed to this API is the SN of the registered observer. |
| unregisterErrorObserver(observerId: number): Promise\<void\> | Unregisters an observer in promise mode. The number passed to this API is the SN of the registered observer. |
| on(type: "error", observer: ErrorObserver): number | Registers an observer for application errors. A callback will be invoked when an application error is detected. This API works in a synchronous manner. The return value is the SN of the registered observer.|
| off(type: "error", observerId: number, callback: AsyncCallback\<void\>): void | Unregisters an observer in callback mode. The number passed to this API is the SN of the registered observer. |
| off(type: "error", observerId: number): Promise\<void\> | Unregisters an observer in promise mode. The number passed to this API is the SN of the registered observer. |
When an asynchronous callback is used, the return value can be processed directly in the callback. If a promise is used, the return value can also be processed in the promise in a similar way. For details about the result codes, see [Result Codes for Unregistering an Observer](#result-codes-for-unregistering-an-observer).
When an asynchronous callback is used, the return value can be processed directly in the callback. If a promise is used, the return value can also be processed in the promise in a similar way. For details about the result codes, see [Result Codes for Unregistering an Observer](#result codes-for-unregistering-an-observer).
**Table 2** Description of the ErrorObserver API
......@@ -36,7 +36,7 @@ When an asynchronous callback is used, the return value can be processed directl
## Development Example
```ts
import Ability from '@ohos.application.Ability'
import UIAbility from '@ohos.app.ability.UIAbility';
import errorManager from '@ohos.app.ability.errorManager';
let registerId = -1;
......@@ -45,15 +45,16 @@ let callback = {
console.log(errMsg);
}
}
export default class MainAbility extends Ability {
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate")
console.log("[Demo] EntryAbility onCreate")
registerId = errorManager.on("error", callback);
globalThis.abilityWant = want;
}
onDestroy() {
console.log("[Demo] MainAbility onDestroy")
console.log("[Demo] EntryAbility onDestroy")
errorManager.off("error", registerId, (result) => {
console.log("[Demo] result " + result.code + ";" + result.message)
});
......@@ -61,7 +62,7 @@ export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
// Main window is created for this ability.
console.log("[Demo] MainAbility onWindowStageCreate")
console.log("[Demo] EntryAbility onWindowStageCreate")
windowStage.loadContent("pages/index", (err, data) => {
if (err.code) {
......@@ -74,17 +75,17 @@ export default class MainAbility extends Ability {
onWindowStageDestroy() {
// Main window is destroyed to release UI resources.
console.log("[Demo] MainAbility onWindowStageDestroy")
console.log("[Demo] EntryAbility onWindowStageDestroy")
}
onForeground() {
// Ability is brought to the foreground.
console.log("[Demo] MainAbility onForeground")
console.log("[Demo] EntryAbility onForeground")
}
onBackground() {
// Ability is brought back to the background.
console.log("[Demo] MainAbility onBackground")
console.log("[Demo] EntryAbility onBackground")
}
};
```
# @ohos.i18n (Internationalization)
The **i18n** module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402.
The [intl](js-apis-intl.md) module provides basic i18n capabilities through the standard i18n APIs defined in ECMA 402. It works with the i18n module to provide a complete suite of i18n capabilities.
This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402.
The [Intl](js-apis-intl.md) module provides basic I18N capabilities through the standard I18N APIs defined in ECMA 402. It works with the I18N module to provide a complete suite of I18N capabilities.
> **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.
>
> - This module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402. For details about the basic i18n capabilities, see [intl](js-apis-intl.md).
> - This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402. For details about the basic I18N capabilities, see [Intl](js-apis-intl.md).
## Modules to Import
......@@ -42,7 +42,7 @@ Obtains the localized script for the specified country.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -81,7 +81,7 @@ Obtains the localized script for the specified language.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -112,7 +112,7 @@ Obtains the list of system languages. For details about languages, see [Instanti
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -149,7 +149,7 @@ Obtains the list of countries and regions supported for the specified language.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -187,7 +187,7 @@ Checks whether the system language matches the specified region.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -218,7 +218,7 @@ Obtains the system language. For details about languages, see [Instantiating the
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -239,7 +239,7 @@ static setSystemLanguage(language: string): void
Sets the system language. Currently, this API does not support real-time updating of the system language.
**System API**: This is a system API.
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
......@@ -253,7 +253,7 @@ Sets the system language. Currently, this API does not support real-time updatin
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -284,7 +284,7 @@ Obtains the system region. For details about system regions, see [Instantiating
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -305,7 +305,7 @@ static setSystemRegion(region: string): void
Sets the system region.
**System API**: This is a system API.
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
......@@ -319,7 +319,7 @@ Sets the system region.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -350,7 +350,7 @@ Obtains the system locale. For details about system locales, see [Instantiating
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -371,7 +371,7 @@ static setSystemLocale(locale: string): void
Sets the system locale.
**System API**: This is a system API.
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
......@@ -385,7 +385,7 @@ Sets the system locale.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -416,7 +416,7 @@ Checks whether the 24-hour clock is used.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -437,7 +437,7 @@ static set24HourClock(option: boolean): void
Sets the 24-hour clock.
**System API**: This is a system API.
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
......@@ -451,7 +451,7 @@ Sets the 24-hour clock.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -473,7 +473,7 @@ static addPreferredLanguage(language: string, index?: number): void
Adds a preferred language to the specified position on the preferred language list.
**System API**: This is a system API.
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
......@@ -488,7 +488,7 @@ Adds a preferred language to the specified position on the preferred language li
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -512,7 +512,7 @@ static removePreferredLanguage(index: number): void
Deletes a preferred language from the specified position on the preferred language list.
**System API**: This is a system API.
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
......@@ -526,7 +526,7 @@ Deletes a preferred language from the specified position on the preferred langua
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -547,7 +547,7 @@ For details about the error codes, see [i18n Error Codes](../errorcodes/errorcod
static getPreferredLanguageList(): Array&lt;string&gt;
Obtains the preferred language list.
Obtains the list of preferred languages.
**System capability**: SystemCapability.Global.I18n
......@@ -555,11 +555,11 @@ Obtains the preferred language list.
| Type | Description |
| ------------------- | --------- |
| Array&lt;string&gt; | Preferred language list.|
| Array&lt;string&gt; | List of preferred languages.|
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -590,7 +590,7 @@ Obtains the first language in the preferred language list.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -621,7 +621,7 @@ Obtains the preferred language of an application.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -642,7 +642,7 @@ static setUsingLocalDigit(flag: boolean): void
Specifies whether to enable use of local digits.
**System API**: This is a system API.
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
......@@ -652,11 +652,11 @@ Specifies whether to enable use of local digits.
| Name | Type | Mandatory | Description |
| ---- | ------- | ---- | ------------------------------- |
| flag | boolean | Yes | Whether to enable the local digit switch. The value **true** means to enable the local digit switch, and the value **false** indicates the opposite.|
| flag | boolean | Yes | Whether to turn on the local digit switch. The value **true** means to turn on the local digit switch, and the value **false** indicates the opposite.|
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -687,7 +687,7 @@ Checks whether use of local digits is enabled.
**Error codes**
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
......@@ -1194,7 +1194,7 @@ Creates an **IndexUtil** object.
**Example**
```js
let indexUtil= I18n.getInstance("zh-CN");
let indexUtil = I18n.getInstance("zh-CN");
```
......@@ -1267,7 +1267,7 @@ Obtains the index of a text object.
**Example**
```js
let indexUtil= I18n.getInstance("zh-CN");
let indexUtil = I18n.getInstance("zh-CN");
let index = indexUtil.getIndex("hi"); // index = "H"
```
......@@ -1382,7 +1382,7 @@ Puts the [BreakIterator](#breakiterator8) object to the first text boundary, whi
**Example**
```js
let iterator = i18n.getLineInstance("en");
let iterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let firstPos = iterator.first(); // firstPos = 0
```
......@@ -1689,7 +1689,7 @@ Obtains the list of time zone city IDs supported by the system.
static getCityDisplayName(cityID: string, locale: string): string
Obtains the localized representation of a time zone city in the specified locale.
Obtains the localized display of a time zone city in the specified locale.
**System capability**: SystemCapability.Global.I18n
......@@ -2363,7 +2363,7 @@ This API is supported since API version 8 and is deprecated since API version 9.
getPreferredLanguageList(): Array&lt;string&gt;
Obtains the preferred language list.
Obtains the list of preferred languages.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getPreferredLanguageList](#getpreferredlanguagelist9) instead.
......@@ -2373,7 +2373,7 @@ This API is supported since API version 8 and is deprecated since API version 9.
| Type | Description |
| ------------------- | --------- |
| Array&lt;string&gt; | Preferred language list.|
| Array&lt;string&gt; | List of preferred languages.|
**Example**
```js
......
......@@ -2,7 +2,8 @@
The **pointer** module provides APIs related to pointer attribute management.
> **NOTE**<br>
> **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.
## Modules to Import
......@@ -237,6 +238,8 @@ Obtains the mouse movement speed. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**System API**: This is a system API.
**Return value**
| Name | Description |
......@@ -263,8 +266,6 @@ Obtains the mouse pointer style. This API uses an asynchronous callback to retur
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
......@@ -277,21 +278,23 @@ Obtains the mouse pointer style. This API uses an asynchronous callback to retur
```js
import window from '@ohos.window';
window.getTopWindow((error, win) => {
win.getWindowProperties((error, properties) => {
let windowId = properties.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.getPointerStyle(windowId, (error, style) => {
console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
});
} catch (error) {
console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
window.getLastWindow(this.context, (error, win) => {
if (error.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
return;
}
let windowId = win.getWindowProperties().id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.getPointerStyle(windowId, (error, style) => {
console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
});
} catch (error) {
console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
```
......@@ -320,21 +323,23 @@ Obtains the mouse pointer style. This API uses a promise to return the result.
```js
import window from '@ohos.window';
window.getTopWindow((error, win) => {
win.getWindowProperties((error, properties) => {
let windowId = properties.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.getPointerStyle(windowId).then((style) => {
console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
});
} catch (error) {
console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
window.getLastWindow(this.context, (error, win) => {
if (error.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
return;
}
let windowId = win.getWindowProperties().id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.getPointerStyle(windowId).then((style) => {
console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
});
} catch (error) {
console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
```
......@@ -359,21 +364,23 @@ Sets the mouse pointer style. This API uses an asynchronous callback to return t
```js
import window from '@ohos.window';
window.getTopWindow((error, win) => {
win.getWindowProperties((error, properties) => {
let windowId = properties.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => {
console.log(`Set pointer style success`);
});
} catch (error) {
console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
window.getLastWindow(this.context, (error, win) => {
if (error.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
return;
}
let windowId = win.getWindowProperties().id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => {
console.log(`Set pointer style success`);
});
} catch (error) {
console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
```
## pointer.setPointerStyle<sup>9+</sup>
......@@ -397,21 +404,23 @@ Sets the mouse pointer style. This API uses a promise to return the result.
```js
import window from '@ohos.window';
window.getTopWindow((error, win) => {
win.getWindowProperties((error, properties) => {
let windowId = properties.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
console.log(`Set pointer style success`);
});
} catch (error) {
console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
window.getLastWindow(this.context, (error, win) => {
if (error.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
return;
}
let windowId = win.getWindowProperties().id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
console.log(`Set pointer style success`);
});
} catch (error) {
console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
```
## PointerStyle<sup>9+</sup>
......@@ -444,8 +453,8 @@ Enumerates mouse pointer styles.
| HAND_POINTING | 19 | Hand-shaped pointer |![Hand_Poniting.png](./figures/Hand_Pointing.png)|
| HELP | 20 | Help |![Help.png](./figures/Help.png)|
| MOVE | 21 | Move |![Move.png](./figures/Move.png)|
| RESIZE_LEFT_RIGHT | 22 | Left-and-right resizing|![Resize_Left_Right.png](./figures/Resize_Left_Right.png)|
| RESIZE_UP_DOWN | 23 | Up-and-down resizing|![Resize_Up_Down.png](./figures/Resize_Up_Down.png)|
| RESIZE_LEFT_RIGHT | 22 | Left and right resizing|![Resize_Left_Right.png](./figures/Resize_Left_Right.png)|
| RESIZE_UP_DOWN | 23 | Up and down resizing|![Resize_Up_Down.png](./figures/Resize_Up_Down.png)|
| SCREENSHOT_CHOOSE | 24 | Screenshot crosshair|![Screenshot_Cross.png](./figures/Screenshot_Cross.png)|
| SCREENSHOT_CURSOR | 25 | Screenshot cursor |![Screenshot_Cursor.png](./figures/Screenshot_Cursor.png)|
| TEXT_CURSOR | 26 | Text cursor |![Text_Cursor.png](./figures/Text_Cursor.png)|
......
# @ohos.usbV9 (USB Management)
# @ohos.usbV9 (USB)
The **usb** module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control on the host side as well as port management, and function switch and query on the device side.
The USB module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control on the host side as well as port management, and function switch and query on the device side.
> **NOTE**<br>
> **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.
## Modules to Import
......@@ -29,7 +30,7 @@ Obtains the list of USB devices connected to the host. If no device is connected
```js
let devicesList = usb.getDevices();
console.log(`devicesList = ${JSON.stringify(devicesList)}`);
console.log(`devicesList = ${devicesList}`);
// devicesList is a list of USB devices.
// A simple example of devicesList is provided as follows:
[
......@@ -86,7 +87,7 @@ console.log(`devicesList = ${JSON.stringify(devicesList)}`);
connectDevice(device: USBDevice): Readonly&lt;USBDevicePipe&gt;
Connects to a USB device based on the device list obtained by using **getDevices()**.
Connects to the USB device based on the device information returned by **getDevices()**.
Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and device information, and then call [usb.requestRight](#usbrequestright) to request the device access permission.
......@@ -118,13 +119,12 @@ For details about the error codes, see [USB Error Codes](../errorcodes/errorcode
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
console.log(`devicepipe = ${JSON.stringify(devicepipe)}`);
console.log(`devicepipe = ${devicepipe}`);
```
## usb.hasRight
......@@ -133,7 +133,7 @@ hasRight(deviceName: string): boolean
Checks whether the application has the permission to access the device.
The value **true** is returned if the device access permission is available; the value **false** is returned otherwise.
Checks whether the user, for example, the application or system, has the device access permissions. The value **true** is returned if the user has the device access permissions; the value **false** is returned otherwise.
**System capability**: SystemCapability.USB.USBManager
......@@ -182,7 +182,7 @@ Requests the temporary permission for the application to access a USB device. Th
```js
let devicesName="1-1";
usb.requestRight(devicesName).then((ret) => {
console.log(`requestRight = ${JSON.stringify(ret)}`);
console.log(`requestRight = ${ret}`);
});
```
......@@ -210,7 +210,7 @@ Removes the permission for the application to access a USB device.
```js
let devicesName="1-1";
if (usb.removeRight(devicesName) {
if usb.removeRight(devicesName) {
console.log(`Succeed in removing right`);
}
```
......@@ -245,7 +245,7 @@ Adds the permission for the application to access a USB device.
```js
let devicesName = "1-1";
let bundleName = "com.example.hello";
if (usb.addRight(bundleName, devicesName) {
if usb.addRight(bundleName, devicesName) {
console.log(`Succeed in adding right`);
}
```
......@@ -454,8 +454,9 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
usb.controlTransfer(devicepipe, USBControlParams).then((ret) => {
console.log(`controlTransfer = ${JSON.stringify(ret)}`);
let param = new usb.USBControlParams();
usb.controlTransfer(devicepipe, param).then((ret) => {
console.log(`controlTransfer = ${ret}`);
})
```
......@@ -491,7 +492,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device.
// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer.
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
console.log(`bulkTransfer = ${JSON.stringify(ret)}`);
console.log(`bulkTransfer = ${ret}`);
});
```
......@@ -578,7 +579,7 @@ Converts the USB function list in the numeric mask format to a string in Device
**Example**
```js
let funcs = ACM | ECM;
let funcs = usb.ACM | usb.ECM;
let ret = usb.usbFunctionsToString(funcs);
```
......@@ -607,7 +608,7 @@ Sets the current USB function list in Device mode.
**Example**
```js
let funcs = HDC;
let funcs = usb.HDC;
let ret = usb.setCurrentFunctions(funcs);
```
......@@ -710,7 +711,12 @@ Sets the role types supported by a specified port, which can be **powerRole** (f
**Example**
```js
let ret = usb.getSupportedModes(0);
let portId = 1;
usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
console.info('usb setPortRoles successfully.');
}).catch(err => {
console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
});
```
## USBEndpoint
......@@ -721,14 +727,14 @@ Represents the USB endpoint from which data is sent or received. You can obtain
| Name | Type | Mandatory |Description |
| ------------- | ------------------------------------------- | ------------- |------------- |
| address | number | Yes | Endpoint address. |
| attributes | number | Yes | Endpoint attributes. |
| interval | number | Yes | Endpoint interval. |
| maxPacketSize | number | Yes | Maximum size of data packets on the endpoint. |
| direction | [USBRequestDirection](#usbrequestdirection) | Yes | Endpoint direction. |
| number | number | Yes | Endpoint number. |
| type | number | Yes | Endpoint type. |
| interfaceId | number | Yes | Unique ID of the interface to which the endpoint belongs.|
| address | number | Yes|Endpoint address. |
| attributes | number | Yes|Endpoint attributes. |
| interval | number | Yes|Endpoint interval. |
| maxPacketSize | number | Yes|Maximum size of data packets on the endpoint. |
| direction | [USBRequestDirection](#usbrequestdirection) | Yes|Endpoint direction. |
| number | number | Yes|Endpoint number. |
| type | number | Yes|Endpoint type. |
| interfaceId | number | Yes|Unique ID of the interface to which the endpoint belongs.|
## USBInterface
......@@ -738,13 +744,13 @@ Represents a USB interface. One [USBConfig](#usbconfig) can contain multiple **U
| Name | Type | Mandatory |Description |
| ---------------- | ---------------------------------------- | ------------- |--------------------- |
| id | number | Yes | Unique ID of the USB interface. |
| protocol | number | Yes | Interface protocol. |
| clazz | number | Yes | Device type. |
| subClass | number | Yes | Device subclass. |
| alternateSetting | number | Yes | Settings for alternating between descriptors of the same USB interface.|
| name | string | Yes | Interface name. |
| endpoints | Array&lt;[USBEndpoint](#usbendpoint)&gt; | Yes | Endpoints that belong to the USB interface. |
| id | number | Yes|Unique ID of the USB interface. |
| protocol | number | Yes|Interface protocol. |
| clazz | number | Yes|Device type. |
| subClass | number | Yes|Device subclass. |
| alternateSetting | number | Yes|Settings for alternating between descriptors of the same USB interface.|
| name | string | Yes|Interface name. |
| endpoints | Array&lt;[USBEndpoint](#usbendpoint)&gt; | Yes|Endpoints that belong to the USB interface. |
## USBConfig
......@@ -754,13 +760,13 @@ Represents the USB configuration. One [USBDevice](#usbdevice) can contain multip
| Name | Type | Mandatory |Description |
| -------------- | ------------------------------------------------ | --------------- |--------------- |
| id | number | Yes | Unique ID of the USB configuration. |
| attributes | number | Yes | Configuration attributes. |
| maxPower | number | Yes | Maximum power consumption, in mA. |
| name | string | Yes | Configuration name, which can be left empty. |
| isRemoteWakeup | boolean | Yes | Support for remote wakeup.|
| isSelfPowered | boolean | Yes | Support for independent power supplies.|
| interfaces | Array&nbsp;&lt;[USBInterface](#usbinterface)&gt; | Yes | Supported interface attributes. |
| id | number | Yes|Unique ID of the USB configuration. |
| attributes | number | Yes|Configuration attributes. |
| maxPower | number | Yes|Maximum power consumption, in mA. |
| name | string | Yes|Configuration name, which can be left empty. |
| isRemoteWakeup | boolean | Yes|Support for remote wakeup.|
| isSelfPowered | boolean | Yes| Support for independent power supplies.|
| interfaces | Array&nbsp;&lt;[USBInterface](#usbinterface)&gt; | Yes|Supported interface attributes. |
## USBDevice
......@@ -770,19 +776,19 @@ Represents the USB device information.
| Name | Type | Mandatory |Description |
| ---------------- | ------------------------------------ | ---------- |---------- |
| busNum | number | Yes | Bus address. |
| devAddress | number | Yes | Device address. |
| serial | string | Yes | Sequence number. |
| name | string | Yes | Device name. |
| manufacturerName | string | Yes | Device manufacturer. |
| productName | string | Yes | Product name. |
| version | string | Yes | Version number. |
| vendorId | number | Yes | Vendor ID. |
| productId | number | Yes | Product ID. |
| clazz | number | Yes | Device class. |
| subClass | number | Yes | Device subclass. |
| protocol | number | Yes | Device protocol code. |
| configs | Array&lt;[USBConfig](#usbconfig)&gt; | Yes | Device configuration descriptor information.|
| busNum | number | Yes|Bus address. |
| devAddress | number | Yes|Device address. |
| serial | string | Yes|Sequence number. |
| name | string | Yes|Device name. |
| manufacturerName | string | Yes| Device manufacturer. |
| productName | string | Yes|Product name. |
| version | string | Yes|Version number. |
| vendorId | number | Yes|Vendor ID. |
| productId | number | Yes|Product ID. |
| clazz | number | Yes|Device class. |
| subClass | number | Yes|Device subclass. |
| protocol | number | Yes|Device protocol code. |
| configs | Array&lt;[USBConfig](#usbconfig)&gt; | Yes|Device configuration descriptor information.|
## USBDevicePipe
......@@ -803,12 +809,12 @@ Represents control transfer parameters.
| Name | Type | Mandatory |Description |
| ------- | ----------------------------------------------- | ---------------- |---------------- |
| request | number | Yes | Request type. |
| target | [USBRequestTargetType](#usbrequesttargettype) | Yes | Request target type. |
| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes | Control request type. |
| value | number | Yes | Request parameter value. |
| index | number | Yes | Index of the request parameter value.|
| data | Uint8Array | Yes | Buffer for writing or reading data. |
| request | number | Yes |Request type. |
| target | [USBRequestTargetType](#usbrequesttargettype) | Yes |Request target type. |
| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes |Control request type. |
| value | number | Yes |Request parameter value. |
| index | number | Yes |Index of the request parameter value.|
| data | Uint8Array | Yes |Buffer for writing or reading data. |
## USBPort
......@@ -820,9 +826,9 @@ Represents a USB port.
| Name | Type | Mandatory |Description |
| -------------- | ------------------------------- | ------------------- |------------------------ |
| id | number | Yes | Unique identifier of a USB port. |
| supportedModes | [PortModeType](#portmodetype) | Yes | Numeric mask combination for the supported mode list.|
| status | [USBPortStatus](#usbportstatus) | Yes | USB port role. |
| id | number | Yes |Unique identifier of a USB port. |
| supportedModes | [PortModeType](#portmodetype) | Yes |Numeric mask combination for the supported mode list.|
| status | [USBPortStatus](#usbportstatus) | Yes |USB port role. |
## USBPortStatus
......@@ -834,9 +840,9 @@ Enumerates USB port roles.
| Name | Type| Mandatory |Description |
| ---------------- | -------- | ---------------- |---------------------- |
| currentMode | number | Yes | Current USB mode. |
| currentPowerRole | number | Yes | Current power role. |
| currentDataRole | number | Yes | Current data role.|
| currentMode | number | Yes|Current USB mode. |
| currentPowerRole | number | Yes |Current power role. |
| currentDataRole | number | Yes |Current data role.|
## USBRequestTargetType
......@@ -844,12 +850,12 @@ Enumerates request target types.
**System capability**: SystemCapability.USB.USBManager
| Name | Value | Description |
| ---------------------------- | ----- | ----------- |
| USB_REQUEST_TARGET_DEVICE | 0 | Device |
| USB_REQUEST_TARGET_INTERFACE | 1 | Interface |
| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint |
| USB_REQUEST_TARGET_OTHER | 3 | Other |
| Name | Value | Description |
| ---------------------------- | ---- | ------ |
| USB_REQUEST_TARGET_DEVICE | 0 | Device|
| USB_REQUEST_TARGET_INTERFACE | 1 | Interface|
| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint|
| USB_REQUEST_TARGET_OTHER | 3 | Other|
## USBControlRequestType
......
......@@ -74,6 +74,7 @@ Before using the Docker environment, perform the following operations:
>
> You do not need to obtain the source code for the HPM-based Docker environment.
3. Perform subsequent operations as a user who has the root permission or has been granted the permission to use Docker.
## Standalone Docker Environment<a name="section2858536103611"></a>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册