提交 d8367186 编写于 作者: 马靖涛 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/docs into master

# Sensor Development
## When to Use
- Data provided by the compass sensor denotes the current orientation of the user device, which helps your application accurately navigate for the user.
- Data provided by the proximity sensor denotes the distance between the device and a visible object, which enables the device to automatically turn on or off its screen accordingly to prevent accidental touch on the screen.
- Data provided by the barometer sensor helps your application accurately determine the altitude of the device.
- Data provided by the ambient light sensor helps your device automatically adjust its backlight.
- Data provided by the Hall effect sensor implements the smart cover mode of your device.
- Data provided by the heart rate sensor helps your application track the health of a user.
- Data provided by the pedometer sensor helps your application obtain the number steps a user has walked.
- Data provided by the wear detection sensor helps your application detect whether a user is wearing a wearable device.
## Available APIs
| Module | API | Description |
| -------- | -------- | -------- |
| ohos.sensor | sensor.on(sensorType,callback:AsyncCallback<Response>):void | Subscribes to data changes of a type of sensor. |
| ohos.sensor | sensor.once(sensorType,callback:AsyncCallback<Response>):void | Subscribes to only one data change of a type of sensor. |
| ohos.sensor | sensor.off(sensorType,callback:AsyncCallback<void>):void | Unsubscribes from sensor data changes. |
## How to Develop
1. To obtain data from a type of sensor, configure the request permissions in the **config.json** file.
```
"reqPermissions":[
{
"name":"ohos.permission.ACCELEROMETER",
"reason"":"",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
}
},
{
"name":"ohos.permission.GYROSCOPE",
"reason"":"",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
}
},
{
"name":"ohos.permission.ACTIVITY_MOTION",
"reason"":"ACTIVITY_MOTION_TEST",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
}
},
{
"name":"ohos.permission.READ_HEALTH_DATA",
"reason"":"HEALTH_DATA_TEST",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
}
},
{
"name":"ohos.permission.VIBRATE",
"reason"":"",
"usedScene":{
"ability": [".MainAbility"],
"when":"inuse"
}
},
]
```
2. Subscribe to data changes of a type of sensor.
```
import sensor from "@ohos.sensor"
sensor.on(type:sensorType,function(error,data){
if (error) {// The call fails, and error.code and error.message are printed.
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
};
console.info("Subscription succeeded. data = "+ data);// The call is successful, and the obtained sensor data is printed.
}
);
```
The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**.
![en-us_image_0000001241693881](figures/en-us_image_0000001241693881.png)
3. Unsubscribe from sensor data changes.
```
import sensor from "@ohos.sensor"
sensor.off(type:sensorType,function(error) {
if (error) {// The unsubscription fails, and error.code and error.message are printed.
console.error("Failed to unsubscribe from acceleration sensor data. Error code: " + error.code + "; message: " + error.message);
return;
};
console.info("Succeeded in unsubscribing from acceleration sensor data.");// The unsubscription is successful, and the result is printed.
}
);
```
The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**.
![en-us_image_0000001196654004](figures/en-us_image_0000001196654004.png)
4. Subscribe to only one data change of a type of sensor.
```
import sensor from "@ohos.sensor"
sensor.once(tyep:sensorType,function(error, data) {
if (error) {// The call fails, and error.code and error.message are printed.
console.error("Failed to obtain data. Error code: " + error.code + "; message: " + error.message);
return;
};
console.info("Data obtained successfully. data="+data);// The call is successful, and the obtained sensor data is printed.
}
);
```
The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**.
![en-us_image_0000001241733907](figures/en-us_image_0000001241733907.png)
# Sensor Overview
Sensors in OpenHarmony are an abstraction of underlying hardware-based sensors. Your application can access the underlying sensors via OpenHarmony sensors. Using the APIs provided by OpenHarmony sensors, you can query sensors on your device, subscribe to sensor data, customize algorithms based on sensor data, and develop various sensor-based applications, such as compass, fitness and health, and games applications.
The sensors are classified into the following categories based on their functions: motion, environment, orientation, light, body, and other categories (such as Hall effect sensors). Each category includes different sensor types. A sensor type may be a single physical sensor or a composite of multiple physical sensors.
**Table1** Motion - ohos.sensor.agent.CategoryMotionAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_ACCELEROMETER | Acceleration sensor | Measures the acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s<sup>2</sup>. | Detecting the motion status |
| SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED | Uncalibrated acceleration sensor | Measures the uncalibrated acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s<sup>2</sup>. | Measuring the acceleration bias estimation |
| SENSOR_TYPE_LINEAR_ACCELERATION | Linear acceleration sensor | Measures the linear acceleration (excluding the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s<sup>2</sup>. | Detecting the linear acceleration in each axis |
| SENSOR_TYPE_GRAVITY | Gravity sensor | Measures the gravity acceleration applied to a device on three physical axes (X, Y, and Z), in the unit of m/s<sup>2</sup>. | Measuring the gravity |
| SENSOR_TYPE_GYROSCOPE | Gyroscope sensor | Measures the rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s. | Measuring the rotation angular velocity |
| SENSOR_TYPE_GYROSCOPE_UNCALIBRATED | Uncalibrated gyroscope sensor | Measures the uncalibrated rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s. | Measuring the bias estimation of the rotation angular velocity |
| SENSOR_TYPE_SIGNIFICANT_MOTION | Significant motion sensor | Checks whether a device has a significant motion on three physical axes (X, Y, and Z). The value can be **0** (having no significant motion) or **1** (having a significant motion). | Detecting significant motions of a device |
| SENSOR_TYPE_DROP_DETECTION | Drop detection sensor | Detects the device drop status. The value can be **0** (the device is not dropped) or **1** (the device is dropped). | Detecting whether a device is dropped |
| SENSOR_TYPE_PEDOMETER_DETECTION | Pedometer detection sensor | Detects whether a user takes a step. The value can be **0** (the user does not take a step) or **1** (the user takes a step). | Detecting whether a user takes a step |
| SENSOR_TYPE_PEDOMETER | Pedometer sensor | Records the number of steps a user has walked. | Providing the number of steps a user has walked |
**Table2** Environment - ohos.sensor.agent.CategoryOrientationAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_AMBIENT_TEMPERATURE | Ambient temperature sensor. | Measures the ambient temperature, in the unit of degree Celsius (°C). | Measuring the ambient temperature |
| SENSOR_TYPE_MAGNETIC_FIELD | Magnetic field sensor | Measures the magnetic field on three physical axes (X, Y, and Z), in the unit of μT. | Creating a compass |
| SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED | Uncalibrated magnetic field sensor | Measures the uncalibrated magnetic field on three physical axes (X, Y, and Z), in the unit of μT. | Measuring the magnetic field bias estimation |
| SENSOR_TYPE_HUMIDITY | Humidity sensor | Measures the ambient relative humidity, in a percentage (%). | Monitoring the dew point, absolute humidity, and relative humidity |
| SENSOR_TYPE_BAROMETER | Barometer sensor | Measures the barometric pressure, in the unit of hPa or mbar. | Measuring the barometric pressure |
| SENSOR_TYPE_SAR | Specific Absorption Rate (SAR) sensor | Measures the SAR, in the unit of W/kg. | Measuring the SAR of electromagnetic waves for a device |
**Table3** Orientation - ohos.sensor.agent.CategoryOrientationAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_6DOF | Degrees of Freedom (DoF) sensor | Measures the forward/backward, up/down, and left/right translational movement of a device on the three axes (X, Y, and Z) in the unit of m or mm as well as the roll, pitch, and yaw rotation angles on the three axes (X, Y, and Z) in the unit of rad. | Positioning an object by detecting its freedom of translational and rotational motions, for example, VR |
| SENSOR_TYPE_SCREEN_ROTATION | Screen rotation sensor | Checks the rotation status of the device screen. | Detecting whether the device screen is rotating |
| SENSOR_TYPE_DEVICE_ORIENTATION | Device orientation sensor | Measures the rotation angles of the device, in the unit of rad. | Measuring the angles that a device has rotated |
| SENSOR_TYPE_ORIENTATION | Orientation sensor | Measures the rotation angles of a device on three physical axes (X, Y, and Z), in the unit of rad. | Providing the three orientation angles of the screen |
| SENSOR_TYPE_ROTATION_VECTOR | Rotation vector sensor | Measures the rotation vector of a device. It is a composite sensor that generates data from the acceleration sensor, magnetic field sensor, and gyroscope sensor. | Detecting the orientation of a device in the East, North, Up (ENU) Cartesian coordinate system |
| SENSOR_TYPE_GAME_ROTATION_VECTOR<br/>SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR | Game rotation vector sensor<br/>Geomagnetic rotation vector sensor | Measures the game rotation vector of a device. It is a composite sensor that generates data from the acceleration sensor and gyroscope sensor.<br/>Measures the geomagnetic rotation vector of a device. It is a composite sensor that generates data from the acceleration sensor and magnetic field sensor. | Applied in games<br/>Measuring the geomagnetic rotation vector |
**Table4** Light - ohos.sensor.agent.CategoryLightAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_PROXIMITY | Proximity sensor | Measures the distance between a visible object and the device screen. | Measuring the distance between a person and the device during a call |
| SENSOR_TYPE_TOF | Time of flight (ToF) sensor | Measures the time required for light to travel a distance in the medium. | Facial recognition |
| SENSOR_TYPE_AMBIENT_LIGHT | Ambient light sensor | Measures the ambient light intensity of a device, in the unit of lux. | Automatically adjusting the screen brightness and checking whether the screen is covered on the top |
| SENSOR_TYPE_COLOR_TEMPERATURE | Color temperature sensor | Measures the ambient color temperature. | Image processing on the device |
| SENSOR_TYPE_COLOR_RGB | RGB color sensor | Measures the ambient RGB color values. | Color detection implemented by the reflectance of RGB colors |
| SENSOR_TYPE_COLOR_XYZ | XYZ color sensor | Measures the ambient XYZ color values. | Identifying true-color spots to reproduce more natural colors |
**Table5** Body - ohos.sensor.agent.CategoryBodyAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_HEART_RATE | Heart rate sensor | Measures the heart rate of a user. | Providing users' heart rate data |
| SENSOR_TYPE_WEAR_DETECTION | Wear detection sensor | Checks whether a user is wearing a wearable device. | Detecting wearables |
**Table6** Others
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_HALL | Hall effect sensor | Detects a magnetic field around a device. | Smart cover mode of the device |
| SENSOR_TYPE_GRIP_DETECTOR | Grip detection sensor | Detects grip force applied on a device. | Detecting whether the device is gripped on its sides |
| SENSOR_TYPE_MAGNET_BRACKET | Magnet bracket sensor | Checks whether a device is magnetized. | Detecting an in-vehicle or indoor device |
| SENSOR_TYPE_PRESSURE_DETECTOR | Pressure detection sensor | Detects pressure force applied on a device. | Detecting pressure on the top of the device |
## How a Service Is Shared Using Huawei Share
The following modules work cooperatively to implement OpenHarmony sensors: Sensor API, Sensor Framework, Sensor Service, and HD_IDL.
**Figure1** Working principles for OpenHarmony sensors
![en-us_image_0000001226521897](figures/en-us_image_0000001226521897.png)
- Sensor API: provides APIs for performing basic operations on sensors, including querying the sensor list, subscribing to or unsubscribing from sensor data, and executing control commands. This module makes application development simpler.
- Sensor Framework: manages sensor data subscription, creates and destroys data channels, subscribes to or unsubscribes from sensor data, and implements communication with the Sensor Service module.
- Sensor Service: interacts with the HD_IDL module to receive, parse, and distribute data, manages foreground and background policies and sensors of a device, and controls sensor permissions.
- HD_IDL: selects proper policies based on the hardware first in first out (FIFO) and frequency, and adapts to different devices.
## Limitations and Constraints
To obtain data of the following sensors, you must claim the required permissions.
**Table7** Sensor data permission
| Sensor | Permission Name | Sensitivity | Permission Description |
| -------- | -------- | -------- | -------- |
| Acceleration sensor, uncalibrated acceleration sensor, and linear acceleration sensor | ohos.permission.ACCELEROMETER | system_grant | Allows your application to subscribe to data of these acceleration-related sensors in the motion category. |
| Gyroscope sensor and uncalibrated gyroscope sensor | ohos.permission.GYROSCOPE | system_grant | Allows your application to subscribe to data of these gyroscope-related sensors in the motion category. |
| Pedometer sensor | ohos.permission.ACTIVITY_MOTION | user_grant | Allows your application to subscribe to the motion status. |
| Heart rate sensor | ohos.permission.READ_HEALTH_DATA | user_grant | Allows your application to read health data. |
The APIs for subscribing to and unsubscribing from sensor data work in pairs. If you do not need sensor data, call the unsubscription API to stop sensor data reporting.
# Combination Key
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to Import
```
import inputConsumer from '@ohos.multimodalInput.inputConsumer';
```
## inputConsumer.on
on(type: "key", keyOption: KeyOption, callback: Callback&lt;KeyOption&gt;): void
Enables listening for combination key events. When a combination key event that meets the specified conditions occurs, **keyOption** will be passed as an input parameter to **callback**.
**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the key input event to listen for. Only **key** is supported. |
| keyOption | [KeyOption](#keyoption) | Yes | Key option, which specifies the condition for combination key input. |
| callback | Callback&lt;KeyOption&gt; | Yes | Callback function. When a key input event that meets the specified options occurs, **keyOption** will be passed as an input parameter to **callback**. |
**Example**
```
let keyOption = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0}
let callback = function(keyOption) {
console.info("preKeys: " + keyOption.preKeys, "finalKey: " + keyOption.finalKey,
"isFinalKeyDown: " + keyOption.isFinalKeyDown, "finalKeyDownDuration: " + keyOption.finalKeyDownDuration)
}
inputConsumer.on('key', keyOption, callback);
```
## inputConsumer.off
off(type: "key", keyOption: KeyOption, callback: Callback&lt;KeyOption&gt;): void
Stops listening for combination key events.
**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the key input event to listen for. Only **key** is supported. |
| keyOption | [KeyOption](#keyoption) | Yes | Key option passed to the key input event when listening starts. |
| callback | Callback&lt;KeyOption&gt; | Yes | Callback function passed to the key input event with the key option when listening starts. |
**Example**
```
let keyOption = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0}
let callback = function(keyOption) {
console.info("preKeys: " + keyOption.preKeys, "finalKey: " + keyOption.finalKey,
"isFinalKeyDown: " + keyOption.isFinalKeyDown, "finalKeyDownDuration: " + keyOption.finalKeyDownDuration)
}
inputConsumer.off('key', keyOption, callback);
```
## KeyOption
Defines the key options that are met when a combination key input event occurs.
**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| preKeys | Array | Yes | Array of precedent keys. This parameter can be left empty. There is no requirement on the sequence of precedent keys. |
| finalKey | Number | Yes | Final key in the combination key. This parameter cannot be left blank. |
| isFinalKeyDown | boolean | Yes | Indicates whether the final key is pressed or released. By default, the final key is pressed. |
| finalKeyDownDuration | Number | Yes | Duration for pressing the final key. By default, there is no requirement on the duration. |
# Input Device
The input device management module is used to listen for the connection, disconnection, and updates of input devices and display information about input devices. For example, it can be used to listen for mouse insertion and removal and obtain information such as the ID, name, and pointer speed of the mouse.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import inputDevice from '@ohos.multimodalInput.inputDevice';
```
## inputDevice.getDeviceIds
getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Obtains the IDs of all input devices. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result. |
**Example**
```
data: {
deviceIds: Array,
},
callback: function(ids) {
this.deviceIds = ids;
},
testGetDeviceIds: function () {
console.info("InputDeviceJsTest---start---testGetDeviceIds");
inputDevice.getDeviceIds(this.callback);
console.info("InputDeviceJsTest---end---testGetDeviceIds");
}
```
## inputDevice.getDevice
getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void
Obtains the information about an input device. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| deviceId | number | Yes | ID of the input device whose information is to be obtained. |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the **InputDeviceData** object. |
**Example**
```
InputDeviceData {
deviceId : 0,
name : "NA",
sources : Array,
axisRanges : Array,
},
callback: function(deviceData) {
this.InputDeviceData = deviceData;
},
testGetDevice: function () {
// The example is used to obtain the information about the device whose ID is 1.
console.info("InputDeviceJsTest---start---testGetDevice");
inputDevice.getDevice(1, this.callback);
console.info("InputDeviceJsTest---end---testGetDevice");
}
```
## InputDeviceData
Defines the information about an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| -------- | -------- | -------- |
| id | number | Unique identifier of an input device. If the same physical device is repeatedly inserted and removed, its ID changes. |
| name | string | Name of the input device. |
| sources | Array&lt;[SourceType](#sourcetype)&gt; | Source types of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad. |
## SourceType
Enumerates the input source types.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Description |
| -------- | -------- | -------- |
| keyboard | string | The input device is a keyboard. |
| touchscreen | string | The input device is a touchscreen. |
| mouse | string | The input device is a mouse. |
| trackball | string | The input device is a trackball. |
| touchpad | string | The input device is a touchpad. |
| joystick | string | The input device is a joystick. |
# Input Monitor
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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 of this module are system APIs and cannot be called by third-party applications.
## Modules to Import
```
import inputMonitor from '@ohos.multimodalInput.inputMonitor';
```
## Required Permissions
ohos.permission.INPUT_MONITORING
## inputMonitor.on
on(type: "touch", receiver: TouchEventReceiver): void
Starts listening for global input events.
**Required permissions**: ohos.permission.INPUT_MONITORING
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
**Parameters**
| Parameter | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;input&nbsp;event.&nbsp;Currently,&nbsp;only&nbsp;**touch**&nbsp;events&nbsp;are&nbsp;supported. |
| receiver | [TouchEventReceiver](#toucheventreceiver) | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;touch&nbsp;event. |
**Example**
```
callback: function (value) {
if (checkEvent(value)) {
// The event meets the service requirement and is consumed.
return true;
} else {
// The event does not meet the service requirement and is not consumed.
return false;
}
},
testOn: function () {
console.info("InputMonitorJsTest---start---testOn");
inputMonitor.on(
"touch",
this.callback
);
console.info("InputMonitorJsTest---end---testOn");
}
```
## inputMonitor.off
off(type: "touch", receiver: TouchEventReceiver): void
Stops listening for global input events.
**Required permissions**: ohos.permission.INPUT_MONITORING
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
**Parameters**
| Parameter | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Type&nbsp;of&nbsp;the&nbsp;input&nbsp;event.&nbsp;Currently,&nbsp;only&nbsp;**touch**&nbsp;events&nbsp;are&nbsp;supported. |
| receiver | [TouchEventReceiver](#toucheventreceiver) | No | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;touch&nbsp;event. |
**Example**
```
callback: function (value) {
if (checkEvent(value)) {
// The event meets the service requirement and is consumed.
return true;
} else {
// The event does not meet the service requirement and is not consumed.
return false;
}
},
testOff: function () {
console.info("InputMonitorJsTest---start---testOff");
inputMonitor.off(
"touch",
this.callback
);
console.info("InputMonitorJsTest---end---testOff");
}
```
## TouchEventReceiver
Represents the class of the callback used to return the touch event. The value **true** indicates that the touch event has been consumed, and the value **false** indicates the opposite.
### (touchEvent: TouchEvent): Boolean
Represents the callback used to return the touch event. You need to define the name of the callback function in the correct format. Ensure that the input parameter is of the **TouchEvent** type, and the return value is of the **Boolean** type.
**System capability**: SystemCapability.MultimodalInput.Input.InputMonitor
**Parameters**
| Parameter | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| touchEvent | [TouchEvent](../arkui-js/js-components-common-events.md) | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;touch&nbsp;event. |
**Return value**
| Type | Description |
| -------- | -------- |
| Boolean | Result&nbsp;indicating&nbsp;whether&nbsp;the&nbsp;touch&nbsp;event&nbsp;has&nbsp;been&nbsp;consumed&nbsp;by&nbsp;the&nbsp;input&nbsp;monitor.&nbsp;The&nbsp;value&nbsp;**true**&nbsp;indicates&nbsp;that&nbsp;the&nbsp;touch&nbsp;event&nbsp;has&nbsp;been&nbsp;consumed,&nbsp;and&nbsp;the&nbsp;value&nbsp;**false**&nbsp;indicates&nbsp;the&nbsp;opposite. |
**Example**
```
callback: function (value) {// Implementation of the (touchEvent:TouchEvent): Boolean API.
if (checkEvent(value)) {
// The event meets the service requirement and is consumed.
return true;
} else {
// The event does not meet the service requirement and is not consumed.
return false;
}
},
testOff: function () {
console.info("InputMonitorJsTest---start---testOff");
inputMonitor.off(
"touch",
this.callback
);
console.info("InputMonitorJsTest---end---testOff");
}
```
...@@ -114,7 +114,7 @@ child.getErrorOutput.then(val=>{ ...@@ -114,7 +114,7 @@ child.getErrorOutput.then(val=>{
### close ### close
close(): void close(): void
Closes the child process in running. Closes the child process in running.
...@@ -167,7 +167,7 @@ var result = process.isIsolatedProcess(); ...@@ -167,7 +167,7 @@ var result = process.isIsolatedProcess();
## process.isAppUid<sup>8+</sup> ## process.isAppUid<sup>8+</sup>
isAppUid(v:number): boolean isAppUid(v: number): boolean
Checks whether a UID belongs to this app. Checks whether a UID belongs to this app.
...@@ -211,7 +211,7 @@ var ressult = process.is64Bit(); ...@@ -211,7 +211,7 @@ var ressult = process.is64Bit();
## process.getUidForName<sup>8+</sup> ## process.getUidForName<sup>8+</sup>
getUidForName(v:string): number getUidForName(v: string): number
Obtains the process UID based on the process name. Obtains the process UID based on the process name.
...@@ -236,7 +236,7 @@ var pres = process.getUidForName("tool") ...@@ -236,7 +236,7 @@ var pres = process.getUidForName("tool")
## process.getThreadPriority<sup>8+</sup> ## process.getThreadPriority<sup>8+</sup>
getThreadPriority(v:number): number getThreadPriority(v: number): number
Obtains the thread priority based on the specified TID. Obtains the thread priority based on the specified TID.
...@@ -278,9 +278,9 @@ Obtains the duration, in milliseconds, from the time the system starts to the ti ...@@ -278,9 +278,9 @@ Obtains the duration, in milliseconds, from the time the system starts to the ti
var realtime = process.getStartRealtime(); var realtime = process.getStartRealtime();
``` ```
## process.getPastCputime<sup>8+</sup> ## process.getPastCpuTime<sup>8+</sup>
getPastCputime(): number getPastCpuTime(): number
Obtains the CPU time (in milliseconds) from the time the process starts to the current time. Obtains the CPU time (in milliseconds) from the time the process starts to the current time.
...@@ -293,13 +293,13 @@ Obtains the CPU time (in milliseconds) from the time the process starts to the c ...@@ -293,13 +293,13 @@ Obtains the CPU time (in milliseconds) from the time the process starts to the c
**Example** **Example**
``` ```
var result = process.getPastCputime() ; var result = process.getPastCpuTime() ;
``` ```
## process.getSystemConfig<sup>8+</sup> ## process.getSystemConfig<sup>8+</sup>
getSystemConfig(name:number): number getSystemConfig(name: number): number
Obtains the system configuration. Obtains the system configuration.
...@@ -325,7 +325,7 @@ var pres = process.getSystemConfig(_SC_ARG_MAX) ...@@ -325,7 +325,7 @@ var pres = process.getSystemConfig(_SC_ARG_MAX)
## process.getEnvironmentVar<sup>8+</sup> ## process.getEnvironmentVar<sup>8+</sup>
getEnvironmentVar(name:string): string getEnvironmentVar(name: string): string
Obtains the value of an environment variable. Obtains the value of an environment variable.
...@@ -416,7 +416,7 @@ Stores the events triggered by the user. ...@@ -416,7 +416,7 @@ Stores the events triggered by the user.
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| EventListener&nbsp;=&nbsp;(evt:&nbsp;Object)&nbsp;=&gt;&nbsp;void | Event to store.| | EventListener&nbsp;=&nbsp;(evt: &nbsp;Object)&nbsp;=&gt;&nbsp;void | Event to store.|
**Example** **Example**
...@@ -527,7 +527,7 @@ var time = process.uptime(); ...@@ -527,7 +527,7 @@ var time = process.uptime();
## process.kill ## process.kill
kill(pid: number, signal: number): boolean kill(pid: number, signal: number ): boolean
Sends a signal to the specified process to terminate it. Sends a signal to the specified process to terminate it.
......
此差异已折叠。
...@@ -28,6 +28,28 @@ None ...@@ -28,6 +28,28 @@ None
| target<sup>8+</sup> | EventTarget | Target element that is clicked. | | target<sup>8+</sup> | EventTarget | Target element that is clicked. |
| timestamp | number | Timestamp of the event. | | timestamp | number | Timestamp of the event. |
- EventTarget<sup>8+</sup> attributes
| Name | Type | Description |
| -------- | -------- | -------- |
| area | Area | Area information of the target element.|
- Area<sup>8+</sup> attributes
| Name | Type | Description |
| -------- | -------- | -------- |
| width | number | Width of the target element, in vp. |
| height | number | Height of the target element, in vp. |
| pos | Position | Position of the upper left corner of the target element relative to that of the parent element. |
| globalPos | Position | Position of the upper left corner of the target element relative to that of the page. |
- Position<sup>8+</sup> attributes
| Name | Type | Description |
| -------- | -------- | -------- |
| x | number | X-coordinate, in vp. |
| y | number | Y-coordinate, in vp. |
## Example ## Example
......
# Learn About OpenHarmony
- [OpenHarmony Project](OpenHarmony-Overview.md)
- [Glossary](device-dev/glossary/glossary.md)
- OpenHarmony Release Notes
- OpenHarmony 3.x Releases
- [OpenHarmony v3.1 Beta (2021-12-31)](release-notes/OpenHarmony-v3.1-beta.md)
- [OpenHarmony v3.0.1 LTS (2022-01-12)](release-notes/OpenHarmony-v3.0.1-LTS.md)
- [OpenHarmony v3.0 LTS (2021-09-30)](release-notes/OpenHarmony-v3.0-LTS.md)
- OpenHarmony 2.x Releases
- [OpenHarmony v2.2 beta2 (2021-08-04)](release-notes/OpenHarmony-v2.2-beta2.md)
- [OpenHarmony 2.0 Canary (2021-06-01)](release-notes/OpenHarmony-2-0-Canary.md)
- OpenHarmony 1.x Releases
- [OpenHarmony v1.1.4 LTS (2022-02-11)](release-notes/OpenHarmony-v1-1-4-LTS.md)
- [OpenHarmony v1.1.3 LTS (2021-09-30)](release-notes/OpenHarmony-v1-1-3-LTS.md)
- [OpenHarmony v1.1.2 LTS (2021-08-04)](release-notes/OpenHarmony-v1.1.2-LTS.md)
- [OpenHarmony 1.1.1 LTS (2021-06-22)](release-notes/OpenHarmony-1-1-1-LTS.md)
- [OpenHarmony 1.1.0 LTS (2021-04-01)](release-notes/OpenHarmony-1-1-0-LTS.md)
- [OpenHarmony 1.0 (2020-09-10)](release-notes/OpenHarmony-1-0.md)
- Contribution
- [Contribution](contribute/contribution.md)
- [Code of Conduct](contribute/code-of-conduct.md)
- [Code Contribution](contribute/code-contribution.md)
- [Contribution Process](contribute/contribution-process.md)
- [Auto-Test](readme/test_subsystem.md)
- [Documentation Contribution](contribute/documentation-contribution.md)
- [Writing Instructions](contribute/writing-instructions.md)
- [Communication in Community](contribute/communication-in-community.md)
- [FAQs](contribute/FAQ.md)
\ No newline at end of file
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
- [设备管理](device/Readme-CN.md) - [设备管理](device/Readme-CN.md)
- [设备使用信息统计](device-usage-statistics/Readme-CN.md) - [设备使用信息统计](device-usage-statistics/Readme-CN.md)
- [DFX](dfx/Readme-CN.md) - [DFX](dfx/Readme-CN.md)
- [国际化](internationalization/Readme-CN.md)
- 工具 - 工具
- [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md) - [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- 示例教程 - 示例教程
......
...@@ -2,9 +2,60 @@ ...@@ -2,9 +2,60 @@
应用开发文档用于指导开发者通过OpenHarmony提供的接口完成应用开发。当前应用开发文档提供了在标准系统上开发应用的JS接口。 应用开发文档用于指导开发者通过OpenHarmony提供的接口完成应用开发。当前应用开发文档提供了在标准系统上开发应用的JS接口。
这部分中,开发者可以通过“[入门](quick-start/Readme-CN.md)”来了解应用开发的基本方法。完整的接口清单和参考使用指导可参见“[开发参考](reference/Readme-CN.md)”。 应用开发的文档中,您可以获取到如下几方面的内容:
除此之外,为方便开发者对常用功能进行深入理解,还提供了[UI](ui/Readme-CN.md)[媒体](media/Readme-CN.md)[网络与连接](connectivity/Readme-CN.md)三个模块的开发指南。 ### 入门
如果需要了解各子系统的原理和基本信息,可以参考“docs/zh-cn/readme”目录中各子系统readme的介绍。 [入门部分](quick-start/Readme-CN.md),可以帮助开发者了解应用开发的基本方法。
这一部分包含了IDE工具DevEco Studio的基本使用方法,以及快速构建首个应用的快速入门。
此外,还在此部分详述了OpenHarmony应用包的包结构,以及资源文件的使用指导。
### 开发
为了帮助开发者更好的理解OpenHarmony提供的能力,我们对重点功能提供了开发指导,辅助开发者完成应用的开发。
首先,提供了支撑OpenHarmony应用的两个重要框架:
- 应用程序的框架:[Ability开发](ability/Readme-CN.md)
- UI的框架:[UI开发](ui/Readme-CN.md)
所有应用都应该在这两个框架下填充和完善功能内容。
在此基础上,还提供了如下功能的开发指导:
- [窗口管理](windowmanager/Readme-CN.md)
- [WebGL](webgl/Readme-CN.md)
- [媒体](media/Readme-CN.md)
- [安全](security/Readme-CN.md)
- [网络与连接](connectivity/Readme-CN.md)
- [数据管理](database/Readme-CN.md)
- [后台代理提醒](background-agent-scheduled-reminder/Readme-CN.md)
- [后台任务管理](background-task-management/Readme-CN.md)
- [设备管理](device/Readme-CN.md)
- [设备使用信息统计](device-usage-statistics/Readme-CN.md)
- [DFX](dfx/Readme-CN.md)
### 工具
DevEco Studio工具是OpenHarmony应用开发的推荐IDE工具。
[工具](quick-start/deveco-studio-user-guide-for-openharmony.md)部分,讲解了DevEco Studio工具的详细用法,包括使用该工具进行工程创建、应用签名、应用调试、应用安装运行的指导。
### 示例教程
我们提供了[Sample工程](https://gitee.com/openharmony/app_samples/blob/master/README_zh.md)[Codelab](https://gitee.com/openharmony/codelabs/blob/master/README.md)这两种形式的示例教程,为开发者提供更丰富的开发参考,辅助开发者理解功能逻辑,提升开发效率。
### API参考
API参考提供了OpenHarmony全量组件和接口的参考文档,可以帮助开发者快速查找到指定接口的详细描述和调用方法。
内容包括:
- [组件参考(基于JS扩展的类Web开发范式)](reference/arkui-js/Readme-CN.md)
- [组件参考(基于TS扩展的声明式开发范式)](reference/arkui-ts/Readme-CN.md)
- [接口参考](reference/apis/Readme-CN.md)
### Readme
如果需要了解各子系统的原理和基本信息,可以参考“[docs/zh-cn/readme](../readme)”目录中各子系统readme的介绍。
...@@ -36,7 +36,13 @@ ...@@ -36,7 +36,13 @@
- [通过导入Sample方式创建新工程](quick-start/import-sample-to-create-project.md) - [通过导入Sample方式创建新工程](quick-start/import-sample-to-create-project.md)
- [配置OpenHarmony应用签名信息](quick-start/configuring-openharmony-app-signature.md) - [配置OpenHarmony应用签名信息](quick-start/configuring-openharmony-app-signature.md)
- [安装运行OpenHarmony应用](quick-start/installing-openharmony-app.md) - [安装运行OpenHarmony应用](quick-start/installing-openharmony-app.md)
- 快速入门
- [前言](start-overview.md)
- [使用eTS语言开发](start-with-ets.md)
- [使用JS语言开发(传统代码方式)](start-with-js.md)
- [使用JS语言开发(低代码方式)](start-with-js-low-code.md)
- [应用开发包结构说明](quick-start/quick-start/package-structure.md) - [应用开发包结构说明](quick-start/quick-start/package-structure.md)
- [资源文件的分类](quick-start/basic-resource-file-categories.md)
- 开发 - 开发
- [Ability开发](ability/Readme-CN.md) - [Ability开发](ability/Readme-CN.md)
- [Ability框架概述](ability/ability-brief.md) - [Ability框架概述](ability/ability-brief.md)
...@@ -84,22 +90,46 @@ ...@@ -84,22 +90,46 @@
- [动画](ui/ui-js-building-ui-animation.md) - [动画](ui/ui-js-building-ui-animation.md)
- [事件](ui/ui-js-building-ui-event.md) - [事件](ui/ui-js-building-ui-event.md)
- [页面路由](ui/ui-js-building-ui-routes.md) - [页面路由](ui/ui-js-building-ui-routes.md)
- 常见组件开发指导 - 常见组件开发指导
- [Text](ui/ui-js-components-text.md) - 容器组件
- [Input](ui/ui-js-components-input.md) - [List开发指导](ui/ui-js-components-list.md)
- [Button](ui/ui-js-components-button.md) - [Dialog开发指导](ui/ui-js-components-dialog.md)
- [List](ui/ui-js-components-list.md) - [Form开发指导](ui/ui-js-components-form.md)
- [Picker](ui/ui-js-components-picker.md) - [Stepper开发指导](ui/ui-js-components-stepper.md)
- [Dialog](ui/ui-js-components-dialog.md) - [Tabs开发指导](ui/ui-js-component-tabs.md)
- [Form](ui/ui-js-components-form.md) - [Swiper开发指导](ui/ui-js-components-swiper.md)
- [Stepper](ui/ui-js-components-stepper.md) - 基础组件
- [Tabs](ui/ui-js-component-tabs.md) - [Text开发指导](ui/ui-js-components-text.md)
- [Image](ui/ui-js-components-images.md) - [Input开发指导](ui/ui-js-components-input.md)
- [Button开发指导](ui/ui-js-components-button.md)
- [Picker开发指导](ui/ui-js-components-picker.md)
- [Image开发指导](ui/ui-js-components-images.md)
- [Image-animator开发指导](ui/ui-js-components-image-animator.md)
- [Rating开发指导](ui/ui-js-components-rating.md)
- [Slider开发指导](ui/ui-js-components-slider.md)
- [Chart开发指导](ui/ui-js-components-chart.md)
- [Switch开发指导](ui/ui-js-components-switch.md)
- [Toolbar开发指导](ui/ui-js-components-toolbar.md)
- [Menu开发指导](ui/ui-js-components-menu.md)
- [Marquee开发指导](ui/ui-js-components-marquee.md)
- [Qrcode开发指导](ui/ui-js-components-qrcode.md)
- [Search开发指导](ui/ui-js-components-search.md)
- Canvas开发指导
- [CanvasRenderingContext2D对象](ui/ui-js-components-canvasrenderingcontext2d.md)
- [Path2D对象](ui/ui-js-components-path2d.md)
- [OffscreenCanvas对象](ui/ui-js-components-offscreencanvas.md)
- [栅格布局](ui/ui-js-components-calendar.md)
- Svg开发指导
- [基础知识](ui/ui-js-components-svg-overview.md)
- [绘制图形](ui/ui-js-components-svg-graphics.md)
- [绘制路径](ui/ui-js-components-svg-path.md)
- [绘制文本](ui/ui-js-components-svg-text.md)
- 动效开发指导 - 动效开发指导
- CSS动画 - CSS动画
- [属性样式动画](ui/ui-js-animate-attribute-style.md) - [属性样式动画](ui/ui-js-animate-attribute-style.md)
- [transform样式动画](ui/ui-js-animate-transform.md) - [transform样式动画](ui/ui-js-animate-transform.md)
- [background-position样式动画](ui/ui-js-animate-background-position-style.md) - [background-position样式动画](ui/ui-js-animate-background-position-style.md)
- [svg动画](ui/ui-js-animate-svg.md)
- JS动画 - JS动画
- [组件动画](ui/ui-js-animate-component.md) - [组件动画](ui/ui-js-animate-component.md)
- 插值器动画 - 插值器动画
...@@ -242,6 +272,12 @@ ...@@ -242,6 +272,12 @@
- [位置开发概述](device/device-location-overview.md) - [位置开发概述](device/device-location-overview.md)
- [获取设备的位置信息](device/device-location-info.md) - [获取设备的位置信息](device/device-location-info.md)
- [(逆)地理编码转化](device/device-location-geocoding.md) - [(逆)地理编码转化](device/device-location-geocoding.md)
- 传感器
- [传感器开发概述](device/sensor-overview.md)
- [传感器开发指导](device/sensor-guidelines.md)
- 振动
- [振动开发概述](device/vibrator-guidelines.md)
- [振动开发指导](device/vibrator-guidelines.md)
- [设备使用信息统计](device-usage-statistics/Readme-CN.md) - [设备使用信息统计](device-usage-statistics/Readme-CN.md)
- [设备使用信息统计概述](device-usage-statistics/device-usage-statistics-overview.md) - [设备使用信息统计概述](device-usage-statistics/device-usage-statistics-overview.md)
- [设备使用信息统计开发指导](device-usage-statistics/device-usage-statistics-dev-guide.md) - [设备使用信息统计开发指导](device-usage-statistics/device-usage-statistics-dev-guide.md)
...@@ -255,6 +291,10 @@ ...@@ -255,6 +291,10 @@
- 分布式跟踪 - 分布式跟踪
- [分布式跟踪概述](dfx/hitracechain-overview.md) - [分布式跟踪概述](dfx/hitracechain-overview.md)
- [分布式跟踪开发指导](dfx/hitracechain-guidelines.md) - [分布式跟踪开发指导](dfx/hitracechain-guidelines.md)
- [国际化](international/Readme-CN.md)
- [国际化开发概述](international/international-overview.md)
- [Intl开发指导](international/intl-guidelines.md)
- [I18n开发指导](international/i18n-guidelines.md)
- 工具 - 工具
- [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md) - [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- [概述](quick-start/deveco-studio-overview.md) - [概述](quick-start/deveco-studio-overview.md)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
**表1** 分布式数据对象实例创建接口 **表1** 分布式数据对象实例创建接口
| 包名 | 接口名 | 描述 | | 包名 | 接口名 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | 创建一个分布式数据对象实例,用于数据操作 | | ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | 创建一个分布式数据对象实例,用于数据操作 <br>-&nbsp;source:设置distributedObject的属性。<br>-&nbsp;DistributedObject:返回值是创建好的分布式对象。|
### 创建分布式数据对象sessionId ### 创建分布式数据对象sessionId
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
**表3** 分布式数据对象sessionId设置接口 **表3** 分布式数据对象sessionId设置接口
| 类名 | 接口名 | 描述 | | 类名 | 接口名 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| DistributedDataObject | setSessionId(sessionId?: string): boolean | 为分布式数据对象设置sessionId | | DistributedDataObject | setSessionId(sessionId?: string): boolean | 为分布式数据对象设置sessionId <br>&nbsp;sessionId:如果指定sessionId,则退出指定分布式组网;如果不指定,则全部退出。|
### 订阅数据变更 ### 订阅数据变更
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
| 类名 | 接口名 | 描述 | | 类名 | 接口名 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | 订阅数据变更。 | | DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | 订阅数据变更。 |
| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | 注销订阅。 | | DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | 注销订阅。需要删除的变更回调,若不设置则删除该对象所有的变更回调。 |
### 订阅数据对象上下线 ### 订阅数据对象上下线
...@@ -83,12 +83,12 @@ ...@@ -83,12 +83,12 @@
//发起方 //发起方
var local_object = distributedObject.createDistributedObject({name:"jack", age:18, isVis:true, var local_object = distributedObject.createDistributedObject({name:"jack", age:18, isVis:true,
parent:{mother:"jack mom",father:"jack Dad"},[{mother:"jack mom"}, {father:"jack Dad"}]}; parent:{mother:"jack mom",father:"jack Dad"},[{mother:"jack mom"}, {father:"jack Dad"}]};
local_object.setsessionId(sessionId); local_object.setSessionId(sessionId);
//被起方 //被起方
var remote_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true, var remote_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true,
parent:undefined, list:undefined}); parent:undefined, list:undefined});
remote_object.setsessionId(sessionId); remote_object.setSessionId(sessionId);
//收到status上线后remote_object同步数据,即name变成jack,age是18 //收到status上线后remote_object同步数据,即name变成jack,age是18
``` ```
......
...@@ -207,12 +207,12 @@ ...@@ -207,12 +207,12 @@
示例代码如下: 示例代码如下:
``` ```
import dataRdb from '@ohos.data.rdb'; import data_rdb from '@ohos.data.rdb'
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {name: "rdbstore.db",} const STORE_CONFIG = {name: "rdbstore.db",}
let rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); let rdbStore = await data_rdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST); await rdbStore.executeSql(CREATE_TABLE_TEST);
``` ```
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
示例代码如下: 示例代码如下:
``` ```
let predicates = new dataRdb.RdbPredicates("test"); let predicates = new data_rdb.RdbPredicates("test");
predicates.equalTo("name", "Tom") predicates.equalTo("name", "Tom")
let resultSet = await rdbStore.query(predicates) let resultSet = await rdbStore.query(predicates)
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
示例代码如下: 示例代码如下:
``` ```
let predicate = new dataRdb.RdbPredicates('test') let predicate = new data_rdb.RdbPredicates('test')
predicate.inDevices(['12345678abcde']) predicate.inDevices(['12345678abcde'])
let promise = rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate) let promise = rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate)
promise.then(result) { promise.then(result) {
......
...@@ -7,3 +7,9 @@ ...@@ -7,3 +7,9 @@
- [位置开发概述](device-location-overview.md) - [位置开发概述](device-location-overview.md)
- [获取设备的位置信息](device-location-info.md) - [获取设备的位置信息](device-location-info.md)
- [(逆)地理编码转化](device-location-geocoding.md) - [(逆)地理编码转化](device-location-geocoding.md)
- 传感器
- [传感器开发概述](sensor-overview.md)
- [传感器开发指导](sensor-guidelines.md)
- 振动
- [振动开发概述](vibrator-guidelines.md)
- [振动开发指导](vibrator-guidelines.md)
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
应用事件JS打点接口由hiAppEvent模块提供。 应用事件JS打点接口由hiAppEvent模块提供。
以下仅提供简单的接口介绍,API接口的具体使用说明(参数使用限制、具体取值范围等),请参考[应用事件打点API文档](../reference/apis/js-apis-hiappevent.md)
**打点接口功能介绍:** **打点接口功能介绍:**
| 接口名 | 返回值 | 描述 | | 接口名 | 返回值 | 描述 |
...@@ -15,25 +17,6 @@ ...@@ -15,25 +17,6 @@
| write(string eventName, EventType type, object keyValues, AsyncCallback\<void> callback): void | void | 应用事件异步打点方法,使用callback方式作为异步回调。 | | write(string eventName, EventType type, object keyValues, AsyncCallback\<void> callback): void | void | 应用事件异步打点方法,使用callback方式作为异步回调。 |
| write(string eventName, EventType type, object keyValues): Promise\<void> | Promise\<void> | 应用事件异步打点方法,使用promise方式作为异步回调。 | | write(string eventName, EventType type, object keyValues): Promise\<void> | Promise\<void> | 应用事件异步打点方法,使用promise方式作为异步回调。 |
- 参数eventName:开发者自定义事件名称。事件名称在48个字符以内,有效的字符是0-9、a-z、下划线,只能以字母开头。
- 参数type:事件所属的类型,取值为枚举EventType,具体值如下表。
| 类型 | 描述 |
| --------- | -------------- |
| FAULT | 故障类型事件。 |
| STATISTIC | 统计类型事件。 |
| SECURITY | 安全类型事件。 |
| BEHAVIOR | 行为类型事件。 |
- 参数keyValues:事件参数键值对,如果是变长参数类型,则依次输入事件的参数名与参数值。如果是Json对象类型,则Json对象的key是事件的参数名,value是事件的参数值。
- 参数名只支持string类型,参数值只支持boolean、number、string、Array(数组参数值为基本类型)。
- 事件的参数个数必须小于等于32。
- 参数名在16个字符以内,有效的字符是0-9、a-z、下划线,只能以字母开头,不能以下划线结尾。
- string类型参数值在8*1024个字符内。
- Array类型参数值的元素个数必须在100个以内,超出时会进行截断处理。
- 参数callback:回调函数,可以在回调函数中处理接口返回值。返回值为0表示事件参数校验成功,事件正常异步写入事件文件;大于0表示事件存在异常参数,事件在忽略异常参数后再异步写入事件文件;小于0表示事件校验失败,不执行事件异步打点操作。
当采用callback作为异步回调时,可以在callback中进行下一步处理。当采用Promise对象返回时,可以在Promise对象中类似地处理接口返回值。具体结果码说明见[事件校验结果码](hiappevent-overview.md#事件校验结果码) 当采用callback作为异步回调时,可以在callback中进行下一步处理。当采用Promise对象返回时,可以在Promise对象中类似地处理接口返回值。具体结果码说明见[事件校验结果码](hiappevent-overview.md#事件校验结果码)
**打点配置接口功能介绍:** **打点配置接口功能介绍:**
...@@ -42,29 +25,6 @@ ...@@ -42,29 +25,6 @@
| ------------------------------ | ------- | ------------------------------------------------------------ | | ------------------------------ | ------- | ------------------------------------------------------------ |
| configure(ConfigOption config) | boolean | 应用事件打点配置方法,可以对打点功能进行自定义配置。返回true表示配置成功,false表示配置失败。 | | configure(ConfigOption config) | boolean | 应用事件打点配置方法,可以对打点功能进行自定义配置。返回true表示配置成功,false表示配置失败。 |
- 参数config:应用事件打点配置项对象。应用打点配置选项ConfigOption如下表。
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------- | ---- | ------------------------------------------------------------ |
| disable | boolean | 否 | 应用打点功能开关,例如配置值为true表示关闭打点功能。 |
| maxStorage | string | 否 | 打点落盘文件存放目录的配额大小,默认限额为“10M”,超出限额后会对存放目录进行清理。 |
**预定义事件名称常量接口Event:**
| 常量名 | 类型 | 描述 |
| ------------------------- | ------ | ------------------------ |
| USER_LOGIN | string | 用户登录事件名称。 |
| USER_LOGOUT | string | 用户登出事件名称。 |
| DISTRIBUTED_SERVICE_START | string | 分布式服务启动事件名称。 |
**预定义参数名称常量接口Param:**
| 常量名 | 类型 | 描述 |
| ------------------------------- | ------ | ------------------ |
| USER_ID | string | 用户自定义ID。 |
| DISTRIBUTED_SERVICE_NAME | string | 分布式服务名称。 |
| DISTRIBUTED_SERVICE_INSTANCE_ID | string | 分布式服务示例ID。 |
## 开发步骤 ## 开发步骤
在应用启动执行页面加载后,执行一个应用事件打点,用于记录应用的初始页面加载事件。 在应用启动执行页面加载后,执行一个应用事件打点,用于记录应用的初始页面加载事件。
...@@ -112,6 +72,4 @@ ...@@ -112,6 +72,4 @@
} }
``` ```
2. 运行项目,点击应用界面上的运行按钮。 2. 运行项目,点击应用界面上的运行按钮。
\ No newline at end of file
# 国际化 # 国际化
- [国际化开发概述](international-overview.md) - [国际化开发概述](international-overview.md)
- [Intl开发指导](intl-guidelines.md) - [Intl开发指导](intl-guidelines.md)
- [I18n开发指导](i18n-guidelines.md) - [I18n开发指导](i18n-guidelines.md)
...@@ -137,7 +137,7 @@ createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<Audio ...@@ -137,7 +137,7 @@ createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<Audio
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------- | :--- | :--------------- | | :------- | :---------------------------------------------- | :--- | :--------------- |
| options | [AudioCapturerOptions](#AudioCapturerOptions) | 是 | 配置音频采集器。 | | options | [AudioCapturerOptions](#audiocaptureroptions8) | 是 | 配置音频采集器。 |
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | 是 | 音频采集器对象。 | | callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | 是 | 音频采集器对象。 |
**示例:** **示例:**
...@@ -181,9 +181,9 @@ createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\> ...@@ -181,9 +181,9 @@ createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| :------ | :------------------- | :--- | :--------------- | | :------ | :--------------------------------------------- | :--- | :--------------- |
| options | AudioCapturerOptions | 是 | 配置音频采集器。 | | options | [AudioCapturerOptions](#audiocaptureroptions8) | 是 | 配置音频采集器。 |
**返回值:** **返回值:**
...@@ -571,6 +571,17 @@ let audioCapturer = await audio.createAudioCapturer(audioCapturerOptions); ...@@ -571,6 +571,17 @@ let audioCapturer = await audio.createAudioCapturer(audioCapturerOptions);
| CONNECT | 0 | 设备连接。 | | CONNECT | 0 | 设备连接。 |
| DISCONNECT | 1 | 断开设备连接。 | | DISCONNECT | 1 | 断开设备连接。 |
## AudioCapturerOptions<sup>8+</sup>
音频采集器选项信息。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Capturer
| 名称 | 类型 | 必填 | 说明 |
| ------------ | --------------------------------------- | ---- | ---------------- |
| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | 是 | 表示音频流信息。 |
| rendererInfo | [AudioCapturerInfo](#audiocapturerinfo) | 是 | 表示采集器信息。 |
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a> ## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
描述音频采集器信息。 描述音频采集器信息。
...@@ -2698,9 +2709,9 @@ getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void ...@@ -2698,9 +2709,9 @@ getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| :------- | :-------------------------------------------------------- | :--- | :------------------------------- | | :------- | :--------------------------------------------------- | :--- | :------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#AudioRendererOptions8)\> | 是 | 使用callback方式异步返回流信息。 | | callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是 | 使用callback方式异步返回流信息。 |
**示例:** **示例:**
...@@ -2728,9 +2739,9 @@ getStreamInfo(): Promise<AudioStreamInfo\> ...@@ -2728,9 +2739,9 @@ getStreamInfo(): Promise<AudioStreamInfo\>
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| :-------------------------------------------------- | :------------------------------ | | :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#AudioRendererOptions8)\> | 使用Promise方式异步返回流信息。 | | Promise<[AudioStreamInfo](#audiostreaminfo8)\> | 使用Promise方式异步返回流信息。 |
**示例:** **示例:**
......
...@@ -461,7 +461,7 @@ queryMyCard(attrs?: ContactAttributes): Promise&lt;Contact&gt; ...@@ -461,7 +461,7 @@ queryMyCard(attrs?: ContactAttributes): Promise&lt;Contact&gt;
## contact.selectContact ## contact.selectContact
selectContact(AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void selectContact(callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
选择联系人,使用callback方式作为异步方法。 选择联系人,使用callback方式作为异步方法。
......
...@@ -21,12 +21,12 @@ write(eventName: string, eventType: EventType, keyValues: object, callback: Asyn ...@@ -21,12 +21,12 @@ write(eventName: string, eventType: EventType, keyValues: object, callback: Asyn
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | --------- | ------------------------- | ---- | ------------------------------------------------------------ |
| eventName | string | 是 | 应用事件名称。 | | eventName | string | 是 | 应用事件名称。<br/>由开发者自定义。事件名称在48个字符以内,有效的字符是0-9、a-z、下划线,只能以字母开头。 |
| eventType | [EventType](#eventtype) | 是 | 应用事件类型。 | | eventType | [EventType](#eventtype) | 是 | 应用事件类型。 |
| keyValues | object | 是 | 应用事件的参数,key类型只能为string,value类型只能为string、number、boolean、Array(数组数据类型只能为string、number、boolean)。 | | keyValues | object | 是 | 事件参数键值对,如果是变长参数类型,则依次输入事件的参数名与参数值。如果是Json对象类型,则Json对象的key是事件的参数名,value是事件的参数值。<br/>- key类型只能为string,value类型只能为string、number、boolean、Array(数组数据类型只能为string、number、boolean)。<br/>- 事件的参数个数必须小于等于32。<br/>- 参数名在16个字符以内,有效的字符是0-9、a-z、下划线,只能以字母开头,不能以下划线结尾。<br/>- string类型参数值在8*1024个字符内。<br/>- Array类型参数值的元素个数必须在100个以内,超出时会进行截断处理。 |
| callback | AsyncCallback&lt;void&gt; | 否 | 回调函数,可以在回调函数中处理接口返回值。<br/>-&nbsp;返回值为0表示事件校验成功,事件正常异步写入事件文件;<br/>-&nbsp;大于0表示事件校验存在异常参数,在忽略异常参数后将事件异步写入事件文件;<br/>-&nbsp;小于0表示事件校验失败,不将事件写入事件文件。 | | callback | AsyncCallback&lt;void&gt; | 否 | 回调函数,可以在回调函数中处理接口返回值。<br/>-&nbsp;返回值为0表示事件校验成功,事件正常异步写入事件文件;<br/>-&nbsp;大于0表示事件校验存在异常参数,在忽略异常参数后将事件异步写入事件文件;<br/>-&nbsp;小于0表示事件校验失败,不将事件写入事件文件。 |
**示例:** **示例:**
...@@ -54,16 +54,16 @@ write(eventName: string, eventType: EventType, keyValues: object): Promise&lt;vo ...@@ -54,16 +54,16 @@ write(eventName: string, eventType: EventType, keyValues: object): Promise&lt;vo
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | --------- | ----------------------- | ---- | ------------------------------------------------------------ |
| eventName | string | 是 | 应用事件名称。 | | eventName | string | 是 | 应用事件名称。<br/>由开发者自定义。事件名称在48个字符以内,有效的字符是0-9、a-z、下划线,只能以字母开头。 |
| eventType | [EventType](#eventtype) | 是 | 应用事件类型。 | | eventType | [EventType](#eventtype) | 是 | 应用事件类型。 |
| keyValues | object | 是 | 应用事件的参数,key类型只能为string,value类型只能为string、number、boolean、Array(数组数据类型只能为string、number、boolean)。 | | keyValues | object | 是 | 事件参数键值对,如果是变长参数类型,则依次输入事件的参数名与参数值。如果是Json对象类型,则Json对象的key是事件的参数名,value是事件的参数值。<br/>- key类型只能为string,value类型只能为string、number、boolean、Array(数组数据类型只能为string、number、boolean)。<br/>- 事件的参数个数必须小于等于32。<br/>- 参数名在16个字符以内,有效的字符是0-9、a-z、下划线,只能以字母开头,不能以下划线结尾。<br/>- string类型参数值在8*1024个字符内。<br/>- Array类型参数值的元素个数必须在100个以内,超出时会进行截断处理。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | ------------------- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | Promise实例,可以在其then()、catch()方法中分别对事件写入成功、写入异常的情况进行回调处理。 | | Promise&lt;void&gt; | Promise实例,可以在其then()、catch()方法中分别对事件写入成功、写入异常的情况进行回调处理。 |
**示例:** **示例:**
...@@ -90,14 +90,14 @@ configure(config: ConfigOption): boolean ...@@ -90,14 +90,14 @@ configure(config: ConfigOption): boolean
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | ------ | ----------------------------- | ---- | ------------------------ |
| config | [ConfigOption](#configoption) | 是 | 应用事件打点配置项对象。 | | config | [ConfigOption](#configoption) | 是 | 应用事件打点配置项对象。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | ------- | ----------------------------------------------------------- |
| boolean | 配置结果,true&nbsp;表示配置成功,false&nbsp;表示配置失败。 | | boolean | 配置结果,true&nbsp;表示配置成功,false&nbsp;表示配置失败。 |
**示例:** **示例:**
...@@ -120,10 +120,10 @@ hiAppEvent.configure({ ...@@ -120,10 +120,10 @@ hiAppEvent.configure({
**系统能力:** 以下各项对应的系统能力均为SystemCapability.HiviewDFX.HiAppEvent。 **系统能力:** 以下各项对应的系统能力均为SystemCapability.HiviewDFX.HiAppEvent。
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | ---------- | ------- | ---- | ------------------------------------------------------------ |
| disable | boolean | 否 | 应用打点功能开关。配置值为true表示关闭打点功能,false表示不关闭打点功能。 | | disable | boolean | 否 | 应用打点功能开关。配置值为true表示关闭打点功能,false表示不关闭打点功能。 |
| maxStorage | string | 否 | 打点数据本地存储文件所在目录的配额大小,默认限额为“10M”。所在目录大小超出限额后会对目录进行清理操作,会按从旧到新的顺序逐个删除打点数据文件,直到目录大小不超出限额时停止。 | | maxStorage | string | 否 | 打点数据本地存储文件所在目录的配额大小,默认限额为“10M”。所在目录大小超出限额后会对目录进行清理操作,会按从旧到新的顺序逐个删除打点数据文件,直到目录大小不超出限额时停止。 |
## EventType ## EventType
...@@ -132,12 +132,12 @@ hiAppEvent.configure({ ...@@ -132,12 +132,12 @@ hiAppEvent.configure({
**系统能力:** 以下各项对应的系统能力均为SystemCapability.HiviewDFX.HiAppEvent。 **系统能力:** 以下各项对应的系统能力均为SystemCapability.HiviewDFX.HiAppEvent。
| 名称 | 默认值 | 说明 | | 名称 | 默认值 | 说明 |
| -------- | -------- | -------- | | --------- | ------ | -------------- |
| FAULT | 1 | 故障类型事件。 | | FAULT | 1 | 故障类型事件。 |
| STATISTIC | 2 | 统计类型事件。 | | STATISTIC | 2 | 统计类型事件。 |
| SECURITY | 3 | 安全类型事件。 | | SECURITY | 3 | 安全类型事件。 |
| BEHAVIOR | 4 | 行为类型事件。 | | BEHAVIOR | 4 | 行为类型事件。 |
## Event ## Event
...@@ -146,11 +146,11 @@ hiAppEvent.configure({ ...@@ -146,11 +146,11 @@ hiAppEvent.configure({
**系统能力:** 以下各项对应的系统能力均为SystemCapability.HiviewDFX.HiAppEvent。 **系统能力:** 以下各项对应的系统能力均为SystemCapability.HiviewDFX.HiAppEvent。
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | ------------------------- | -------- | ---- | ---- | -------------------- |
| USER_LOGIN | string | 是 | 否 | 用户登录事件。 | | USER_LOGIN | string | 是 | 否 | 用户登录事件。 |
| USER_LOGOUT | string | 是 | 否 | 用户登出事件。 | | USER_LOGOUT | string | 是 | 否 | 用户登出事件。 |
| DISTRIBUTED_SERVICE_START | string | 是 | 否 | 分布式服务启动事件。 | | DISTRIBUTED_SERVICE_START | string | 是 | 否 | 分布式服务启动事件。 |
## Param ## Param
...@@ -159,8 +159,8 @@ hiAppEvent.configure({ ...@@ -159,8 +159,8 @@ hiAppEvent.configure({
**系统能力:** 以下各项对应的系统能力均为SystemCapability.HiviewDFX.HiAppEvent。 **系统能力:** 以下各项对应的系统能力均为SystemCapability.HiviewDFX.HiAppEvent。
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | ------------------------------- | -------- | ---- | ---- | ------------------ |
| USER_ID | string | 是 | 否 | 用户自定义ID。 | | USER_ID | string | 是 | 否 | 用户自定义ID。 |
| DISTRIBUTED_SERVICE_NAME | string | 是 | 否 | 分布式服务名称。 | | DISTRIBUTED_SERVICE_NAME | string | 是 | 否 | 分布式服务名称。 |
| DISTRIBUTED_SERVICE_INSTANCE_ID | string | 是 | 否 | 分布式服务实例ID。 | | DISTRIBUTED_SERVICE_INSTANCE_ID | string | 是 | 否 | 分布式服务实例ID。 |
\ No newline at end of file
# 输入监听
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> - 本模块接口均为系统接口,三方应用不支持调用。
## 导入模块
```
import inputMonitor from '@ohos.multimodalInput.inputMonitor';
```
## 权限
ohos.permission.INPUT_MONITORING
## inputMonitor.on
on(type: "touch", receiver: TouchEventReceiver): void
开始监听全局输入。
**需要权限:**ohos.permission.INPUT_MONITORING
**系统能力:**SystemCapability.MultimodalInput.Input.InputMonitor
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 监听输入事件类型,只支持“touch”。 |
| receiver | [TouchEventReceiver](#toucheventreceiver) | 是 | 触摸输入事件回调函数。 |
**示例:**
```
callback: function (value) {
if (checkEvent(value)) {
//事件满足业务要求,事件被消费
return true;
} else {
//事件不满足业务要求,事件未被消费
return false;
}
},
testOn: function () {
console.info("InputMonitorJsTest---start---testOn");
inputMonitor.on(
"touch",
this.callback
);
console.info("InputMonitorJsTest---end---testOn");
}
```
## inputMonitor.off
off(type: "touch", receiver: TouchEventReceiver): void
停止监听全局输入。
**需要权限:**ohos.permission.INPUT_MONITORING
**系统能力:**SystemCapability.MultimodalInput.Input.InputMonitor
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 监听输入事件类型,只支持“touch”。 |
| receiver | [TouchEventReceiver](#toucheventreceiver) | 否 | 触摸输入事件回调函数。 |
**示例:**
```
callback: function (value) {
if (checkEvent(value)) {
//事件满足业务要求,事件被消费
return true;
} else {
//事件不满足业务要求,事件未被消费
return false;
}
},
testOff: function () {
console.info("InputMonitorJsTest---start---testOff");
inputMonitor.off(
"touch",
this.callback
);
console.info("InputMonitorJsTest---end---testOff");
}
```
## TouchEventReceiver
触摸输入事件的回调函数,如果返回true,则触摸输入将被监听器消耗(系统执行关闭动作)。
### (touchEvent: TouchEvent): Boolean
触摸输入事件的回调函数。函数名由使用者定义,这里是函数调用时必须符合的格式,传入参数必须为TouchEvent类型,返回值为Boolean类型。
**系统能力:**SystemCapability.MultimodalInput.Input.InputMonitor
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| touchEvent | [TouchEvent](../arkui-js/js-components-common-events.md) | 是 | 触摸输入事件回调函数,返回true表示输触事件被监听器消费,false表示输触事件未被监听器消费。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Boolean | 返回true表示输触事件被监听器消费,false表示输触事件未被监听器消费。 |
**示例:**
```
callback: function (value) { //此处为(touchEvent:TouchEvent): Boolean 方法的实现
if (checkEvent(value)) {
//事件满足业务要求,事件被消费
return true;
} else {
//事件不满足业务要求,事件未被消费
return false;
}
},
testOff: function () {
console.info("InputMonitorJsTest---start---testOff");
inputMonitor.off(
"touch",
this.callback
);
console.info("InputMonitorJsTest---end---testOff");
}
```
...@@ -1346,6 +1346,12 @@ setSpeed(speed:number): Promise\<number> ...@@ -1346,6 +1346,12 @@ setSpeed(speed:number): Promise\<number>
| ------ | ------ | ---- | ---------------------------------------------------------- | | ------ | ------ | ---- | ---------------------------------------------------------- |
| speed | number | 是 | 指定播放视频速度,具体见[PlaybackSpeed](#playbackspeed8)。 | | speed | number | 是 | 指定播放视频速度,具体见[PlaybackSpeed](#playbackspeed8)。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | ------------------------- |
| Promise\<number> | 通过Promise获取设置结果。 |
**示例:** **示例:**
```js ```js
...@@ -1632,7 +1638,7 @@ audioRecorder.pause(); ...@@ -1632,7 +1638,7 @@ audioRecorder.pause();
resume():void resume():void
暂停录制,需要在[pause](#audiorecorder_on)事件成功触发后,才能调用resume方法。 恢复录制,需要在[pause](#audiorecorder_on)事件成功触发后,才能调用resume方法。
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **系统能力:** SystemCapability.Multimedia.Media.AudioRecorder
...@@ -2401,7 +2407,7 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -2401,7 +2407,7 @@ on(type: 'error', callback: ErrorCallback): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | ------------------------------------------------------------ | | -------- | ------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 录制错误事件回调类型'error'。<br/>-&nbsp;'error':频录制过程中发生错误,触发该事件。 | | type | string | 是 | 录制错误事件回调类型'error'。<br/>-&nbsp;'error':频录制过程中发生错误,触发该事件。 |
| callback | ErrorCallback | 是 | 录制错误事件回调方法。 | | callback | ErrorCallback | 是 | 录制错误事件回调方法。 |
**示例:** **示例:**
......
...@@ -121,7 +121,7 @@ child.getErrorOutput.then(val=>{ ...@@ -121,7 +121,7 @@ child.getErrorOutput.then(val=>{
### close ### close
close(): void close(): void
关闭正在运行的子进程。 关闭正在运行的子进程。
...@@ -180,7 +180,7 @@ var result = process.isIsolatedProcess(); ...@@ -180,7 +180,7 @@ var result = process.isIsolatedProcess();
## process.isAppUid<sup>8+</sup> ## process.isAppUid<sup>8+</sup>
isAppUid(v:number): boolean isAppUid(v: number): boolean
判断uid是否属于应用程序。 判断uid是否属于应用程序。
...@@ -228,7 +228,7 @@ var ressult = process.is64Bit(); ...@@ -228,7 +228,7 @@ var ressult = process.is64Bit();
## process.getUidForName<sup>8+</sup> ## process.getUidForName<sup>8+</sup>
getUidForName(v:string): number getUidForName(v: string): number
通过进程名获取进程uid。 通过进程名获取进程uid。
...@@ -255,7 +255,7 @@ var pres = process.getUidForName("tool") ...@@ -255,7 +255,7 @@ var pres = process.getUidForName("tool")
## process.getThreadPriority<sup>8+</sup> ## process.getThreadPriority<sup>8+</sup>
getThreadPriority(v:number): number getThreadPriority(v: number): number
根据指定的tid获取线程优先级。 根据指定的tid获取线程优先级。
...@@ -324,7 +324,7 @@ var result = process.getPastCpuTime() ; ...@@ -324,7 +324,7 @@ var result = process.getPastCpuTime() ;
## process.getSystemConfig<sup>8+</sup> ## process.getSystemConfig<sup>8+</sup>
getSystemConfig(name:number): number getSystemConfig(name: number): number
获取系统配置信息。 获取系统配置信息。
...@@ -352,7 +352,7 @@ var pres = process.getSystemConfig(_SC_ARG_MAX) ...@@ -352,7 +352,7 @@ var pres = process.getSystemConfig(_SC_ARG_MAX)
## process.getEnvironmentVar<sup>8+</sup> ## process.getEnvironmentVar<sup>8+</sup>
getEnvironmentVar(name:string): string getEnvironmentVar(name: string): string
用该方法获取环境变量对应的值。 用该方法获取环境变量对应的值。
...@@ -451,7 +451,7 @@ on(type: string, listener: EventListener): void ...@@ -451,7 +451,7 @@ on(type: string, listener: EventListener): void
| 名称 | 说明 | | 名称 | 说明 |
| -------- | -------- | | -------- | -------- |
| EventListener&nbsp;=&nbsp;(evt:&nbsp;Object)&nbsp;=&gt;&nbsp;void | 用户存储的事件。 | | EventListener&nbsp;=&nbsp;(evt: &nbsp;Object)&nbsp;=&gt;&nbsp;void | 用户存储的事件。 |
**示例:** **示例:**
......
...@@ -1708,8 +1708,8 @@ readException(): void ...@@ -1708,8 +1708,8 @@ readException(): void
} }
}; };
let want = { let want = {
"bundleName": "com.huawei.server", "bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
...@@ -2563,8 +2563,8 @@ sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options ...@@ -2563,8 +2563,8 @@ sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options
} }
}; };
let want = { let want = {
"bundleName": "com.huawei.server", "bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
...@@ -2608,8 +2608,8 @@ sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options ...@@ -2608,8 +2608,8 @@ sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options
} }
}; };
let want = { let want = {
"bundleName": "com.huawei.server", "bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
...@@ -2672,8 +2672,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -2672,8 +2672,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
} }
}; };
let want = { let want = {
"bundleName": "com.huawei.server", "bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
function sendRequestCallback(result) { function sendRequestCallback(result) {
if (result.errCode === 0) { if (result.errCode === 0) {
...@@ -2734,8 +2734,8 @@ queryLocalInterface(interface: string): IRemoteBroker ...@@ -2734,8 +2734,8 @@ queryLocalInterface(interface: string): IRemoteBroker
} }
}; };
let want = { let want = {
"bundleName":"com.huawei.server", "bundleName":"com.ohos.server",
"abilityName":"com.huawei.server.MainAbility", "abilityName":"com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
let broker = proxy.queryLocalInterface("testObject"); let broker = proxy.queryLocalInterface("testObject");
...@@ -2780,8 +2780,8 @@ addDeathRecipient(recipient : DeathRecipient, flags : number): boolean ...@@ -2780,8 +2780,8 @@ addDeathRecipient(recipient : DeathRecipient, flags : number): boolean
} }
}; };
let want = { let want = {
"bundleName": "com.huawei.server", "bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
class MyDeathRecipient { class MyDeathRecipient {
...@@ -2831,8 +2831,8 @@ removeDeathRecipient(recipient : DeathRecipient, flags : number): boolean ...@@ -2831,8 +2831,8 @@ removeDeathRecipient(recipient : DeathRecipient, flags : number): boolean
} }
}; };
let want = { let want = {
"bundleName": "com.huawei.server", "bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
class MyDeathRecipient { class MyDeathRecipient {
...@@ -2877,8 +2877,8 @@ getInterfaceDescriptor(): string ...@@ -2877,8 +2877,8 @@ getInterfaceDescriptor(): string
} }
}; };
let want = { let want = {
"bundleName": "com.huawei.server", "bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
let descriptor = proxy.getInterfaceDescriptor(); let descriptor = proxy.getInterfaceDescriptor();
...@@ -2917,8 +2917,8 @@ isObjectDead(): boolean ...@@ -2917,8 +2917,8 @@ isObjectDead(): boolean
} }
}; };
let want = { let want = {
"bundleName": "com.huawei.server", "bundleName": "com.ohos.server",
"abilityName": "com.huawei.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
let isDead = proxy.isObjectDead(); let isDead = proxy.isObjectDead();
......
...@@ -416,9 +416,9 @@ setTimezone(timezone: string): Promise&lt;void&gt; ...@@ -416,9 +416,9 @@ setTimezone(timezone: string): Promise&lt;void&gt;
``` ```
## systemTime.getTimeZone<sup>8+</sup> ## systemTime.getTimezone<sup>8+</sup>
getTimeZone(callback: AsyncCallback&lt;string&gt;): void getTimezone(callback: AsyncCallback&lt;string&gt;): void
获取系统时区,使用callback形式返回结果。 获取系统时区,使用callback形式返回结果。
...@@ -432,19 +432,19 @@ getTimeZone(callback: AsyncCallback&lt;string&gt;): void ...@@ -432,19 +432,19 @@ getTimeZone(callback: AsyncCallback&lt;string&gt;): void
- 示例: - 示例:
``` ```
systemTime.getTimeZone((error, data) => { systemTime.getTimezone((error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.getTimeZone because ` + JSON.stringify(error)); console.error(`failed to systemTime.getTimezone because ` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.getTimeZone success data : ` + JSON.stringify(data)); console.log(`systemTime.getTimezone success data : ` + JSON.stringify(data));
}); });
``` ```
## systemTime.getTimeZone<sup>8+</sup> ## systemTime.getTimezone<sup>8+</sup>
getTimeZone(): Promise&lt;string&gt; getTimezone(): Promise&lt;string&gt;
获取系统时区,使用Promise形式返回结果。 获取系统时区,使用Promise形式返回结果。
...@@ -458,9 +458,9 @@ getTimeZone(): Promise&lt;string&gt; ...@@ -458,9 +458,9 @@ getTimeZone(): Promise&lt;string&gt;
- 示例: - 示例:
``` ```
systemTime.getDate().then((data) => { systemTime.getTimezone().then((data) => {
console.log(`systemTime.getTimeZone success data : ` + JSON.stringify(data)); console.log(`systemTime.getTimezone success data : ` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.getTimeZone because ` + JSON.stringify(error)); console.error(`failed to systemTime.getTimezone because ` + JSON.stringify(error));
}); });
``` ```
此差异已折叠。
...@@ -358,7 +358,7 @@ reset(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void ...@@ -358,7 +358,7 @@ reset(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
- 示例: - 示例:
``` ```
wallpaper.reset((error, data) => { wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) { if (error) {
console.error(`failed to reset because: ` + JSON.stringify(error)); console.error(`failed to reset because: ` + JSON.stringify(error));
return; return;
...@@ -391,7 +391,7 @@ reset(wallpaperType: WallpaperType): Promise&lt;void&gt; ...@@ -391,7 +391,7 @@ reset(wallpaperType: WallpaperType): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
wallpaper.reset(wallpaper.WALLPAPER_SYSTEM).then((data) => { wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to reset.`); console.log(`success to reset.`);
}).catch((error) => { }).catch((error) => {
console.error(`failed to reset because: ` + JSON.stringify(error)); console.error(`failed to reset because: ` + JSON.stringify(error));
...@@ -401,7 +401,7 @@ reset(wallpaperType: WallpaperType): Promise&lt;void&gt; ...@@ -401,7 +401,7 @@ reset(wallpaperType: WallpaperType): Promise&lt;void&gt;
## wallpaper.setWallpaper ## wallpaper.setWallpaper
setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
将指定资源设置为指定类型的壁纸。 将指定资源设置为指定类型的壁纸。
...@@ -412,16 +412,16 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp ...@@ -412,16 +412,16 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uriOrPixelMap | string&nbsp;\|[PixelMap](js-apis-image.md#pixelmap7) | | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 | | source | string&nbsp;\|[PixelMap](js-apis-image.md#pixelmap7) | | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 | | wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,调用成功则返回是返回设置的结果,调用失败则返回error信息。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,调用成功则返回是返回设置的结果,调用失败则返回error信息。 |
- 示例: - 示例:
``` ```
// uriOrPixelMap类型为string // source类型为string
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WALLPAPER_SYSTEM, (error, data) => { wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) { if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error)); console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return; return;
...@@ -429,7 +429,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp ...@@ -429,7 +429,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp
console.log(`success to setWallpaper.`); console.log(`success to setWallpaper.`);
}); });
// uriOrPixelMap类型为image.PixelMap // source类型为image.PixelMap
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath); let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = { let opts = {
...@@ -439,7 +439,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp ...@@ -439,7 +439,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp
} }
}; };
imageSource.createPixelMap(opts).then((pixelMap) => { imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WALLPAPER_SYSTEM, (error, data) => { wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) { if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error)); console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return; return;
...@@ -454,7 +454,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp ...@@ -454,7 +454,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp
## wallpaper.setWallpaper ## wallpaper.setWallpaper
setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt; setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;
将指定资源设置为指定类型的壁纸。 将指定资源设置为指定类型的壁纸。
...@@ -465,7 +465,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp ...@@ -465,7 +465,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uriOrPixelMap | string&nbsp;\|[PixelMap](js-apis-image.md#pixelmap7) | 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 | | source | string&nbsp;\|[PixelMap](js-apis-image.md#pixelmap7) | 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 | | wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
- 返回值: - 返回值:
...@@ -476,15 +476,15 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp ...@@ -476,15 +476,15 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp
- 示例: - 示例:
``` ```
// uriOrPixelMap类型为string // source类型为string
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WALLPAPER_SYSTEM).then((data) => { wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`); console.log(`success to setWallpaper.`);
}).catch((error) => { }).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error)); console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
}); });
// uriOrPixelMap类型为image.PixelMap // source类型为image.PixelMap
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath); let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = { let opts = {
...@@ -494,7 +494,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp ...@@ -494,7 +494,7 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp
} }
}; };
imageSource.createPixelMap(opts).then((pixelMap) => { imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WALLPAPER_SYSTEM).then((data) => { wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`); console.log(`success to setWallpaper.`);
}).catch((error) => { }).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error)); console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
...@@ -503,6 +503,62 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp ...@@ -503,6 +503,62 @@ setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperTyp
console.error(`failed to createPixelMap because: ` + JSON.stringify(error)); console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
}); });
``` ```
## wallpaper.getFile<sup>8+</sup>
getFile(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void
获取指定类型的壁纸文件。
**需要权限**:ohos.permission.SET_WALLPAPER、ohos.permission.READ_USER_STORAGE
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,调用成功则返回壁纸文件描述符ID,调用失败则返回error信息。 |
- 示例:
```
wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to getFile because: ` + JSON.stringify(error));
return;
}
console.log(`success to getFile: ` + JSON.stringify(data));
});
```
## wallpaper.getFile<sup>8+</sup>
getFile(wallpaperType: WallpaperType): Promise&lt;number&gt;
获取指定类型的壁纸文件。
**需要权限:** ohos.permission.SET_WALLPAPER、ohos.permission.READ_USER_STORAGE
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;number&gt; | 调用成功则返回壁纸文件描述符ID,调用失败则返回error信息。 |
- 示例:
```
wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to getFile: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to getFile because: ` + JSON.stringify(error));
});
```
## wallpaper.on('colorChange') ## wallpaper.on('colorChange')
......
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
- [QRCode](ts-basic-components-qrcode.md) - [QRCode](ts-basic-components-qrcode.md)
- [Radio](ts-basic-components-radio.md) - [Radio](ts-basic-components-radio.md)
- [Rating](ts-basic-components-rating.md) - [Rating](ts-basic-components-rating.md)
- [Search](ts-basic-components-search.md)
- [Select](ts-basic-components-select.md) - [Select](ts-basic-components-select.md)
- [Slider](ts-basic-components-slider.md) - [Slider](ts-basic-components-slider.md)
- [Span](ts-basic-components-span.md) - [Span](ts-basic-components-span.md)
......
...@@ -28,11 +28,11 @@ Navigation() ...@@ -28,11 +28,11 @@ Navigation()
| 名称 | 参数类型 | 默认值 | 描述 | | 名称 | 参数类型 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| title | string&nbsp;\|&nbsp;[CustomBuilder](../../ui/ts-types.md#custombuilder类型8+)<sup>8+</sup> | - | 页面标题。 | | title | string&nbsp;\|&nbsp;[CustomBuilder](../../ui/ts-types.md#CustomBuilder类型)<sup>8+</sup> | - | 页面标题。 |
| subtitle | string | - | 页面副标题。 | | subtitle | string | - | 页面副标题。 |
| menus | Array<NavigationMenuItem&gt;&nbsp;\|&nbsp;[CustomBuilder](../../ui/ts-types.md#custombuilder类型8+)<sup>8+</sup> | - | 页面右上角菜单。 | | menus | Array<NavigationMenuItem&gt;&nbsp;\|&nbsp;[CustomBuilder](../../ui/ts-types.md#CustomBuilder类型)<sup>8+</sup> | - | 页面右上角菜单。 |
| titleMode | NavigationTitleMode | NavigationTitleMode.Free | 页面标题栏显示模式。 | | titleMode | NavigationTitleMode | NavigationTitleMode.Free | 页面标题栏显示模式。 |
| toolBar | {<br/>items:[<br/>Object<br/>]&nbsp;}<br/>\|&nbsp;[CustomBuilder](../../ui/ts-types.md#custombuilder类型8+)<sup>8+</sup> | - | 设置工具栏内容。<br/>items:&nbsp;工具栏所有项。 | | toolBar | {<br/>items:[<br/>Object<br/>]&nbsp;}<br/>\|&nbsp;[CustomBuilder](../../ui/ts-types.md#CustomBuilder类型)<sup>8+</sup> | - | 设置工具栏内容。<br/>items:&nbsp;工具栏所有项。 |
| hideToolBar | boolean | false | 设置隐藏/显示工具栏:<br/>true:&nbsp;隐藏工具栏。<br/>false:&nbsp;显示工具栏。 | | hideToolBar | boolean | false | 设置隐藏/显示工具栏:<br/>true:&nbsp;隐藏工具栏。<br/>false:&nbsp;显示工具栏。 |
| hideTitleBar | boolean | false | 隐藏标题栏。 | | hideTitleBar | boolean | false | 隐藏标题栏。 |
| hideBackButton | boolean | false | 隐藏返回键。 | | hideBackButton | boolean | false | 隐藏返回键。 |
...@@ -64,9 +64,9 @@ Navigation() ...@@ -64,9 +64,9 @@ Navigation()
## 事件 ## 事件
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onTitleModeChanged(callback:&nbsp;(titleMode:&nbsp;NavigationTitleMode)&nbsp;=&gt;&nbsp;void) | 当titleMode为NavigationTitleMode.Free时,随着可滚动组件的滑动标题栏模式发生变化时触发此回调。 | | onTitleModeChange(callback:&nbsp;(titleMode:&nbsp;NavigationTitleMode)&nbsp;=&gt;&nbsp;void) | 当titleMode为NavigationTitleMode.Free时,随着可滚动组件的滑动标题栏模式发生变化时触发此回调。 |
## 示例 ## 示例
...@@ -138,7 +138,7 @@ struct NavigationExample { ...@@ -138,7 +138,7 @@ struct NavigationExample {
.titleMode(NavigationTitleMode.Free) .titleMode(NavigationTitleMode.Free)
.hideTitleBar(false) .hideTitleBar(false)
.hideBackButton(false) .hideBackButton(false)
.onTitleModeChanged((titleModel: NavigationTitleMode) => { .onTitleModeChange((titleModel: NavigationTitleMode) => {
console.log('titleMode') console.log('titleMode')
}) })
.toolBar({ items: [ .toolBar({ items: [
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
## 接口 ## 接口
ScrollBar(value: ScrollBarOption) ScrollBar(value: ScrollBarOptions)
- ScrollBarOption的参数描述 - ScrollBarOptions的参数描述
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| scroller | [Scroller](ts-container-scroll.md#scroller) | 是 | - | 可滚动组件的控制器。用于与可滚动组件进行绑定。 | | scroller | [Scroller](ts-container-scroll.md#scroller) | 是 | - | 可滚动组件的控制器。用于与可滚动组件进行绑定。 |
......
# Search
> ![](public_sys-resources/icon-note.gif) **说明:** 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
提供搜索框组件,用于提供用户搜索内容的输入区域。
## 权限列表
## 子组件
## 接口
Search(options?: { value?: string; placeholder?: string; icon?: string; controller?: SearchController })
- 参数
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- |
| value | string | 否 | - | 搜索文本值。 |
| placeholder | string | 否 | - | 无输入时的提示文本。|
| icon | string | 否 | - | 搜索图标路径,默认使用系统搜索图标,支持的图标格式: svg, jpg和png。 |
| controller | SearchController | 否 | - | 控制器。|
## 属性
| 名称 | 参数类型 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- |
| searchButton | string | 无 | 搜索框末尾搜索按钮文本值,默认无搜索按钮。|
| placeholderColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置placeholder颜色。|
| placeholderFont | [Font](../../ui/ts-types.md#Font) | - | 设置placeholder文本样式。|
| textFont | [Font](../../ui/ts-types.md#Font) | - | 设置搜索框内文本样式。|
## 事件
| 名称 | 功能描述 |
| -------- | -------- |
| onSubmit(callback: (value: string) => void) | 点击搜索图标、搜索按钮或者按下软键盘搜索按钮时触发。<br> -value: 当前输入文本框的内容。|
| onChange(callback: (value: string) => void) | 输入内容发生变化时,触发回调。<br> -value: 当前输入文本框的内容。|
| onCopy(callback: (value: string) => void) | 组件触发系统剪切板复制操作。<br> -value: 复制的文本内容。|
| onCut(callback: (value: string) => void) | 组件触发系统剪切板剪切操作。<br> -value: 剪切的文本内容。|
| onPaste(callback: (value: string) => void) | 组件触发系统剪切板粘贴操作。<br> -value: 粘贴的文本内容。|
## SearchController
Search组件的控制器,通过它操作Search组件。
#### 导入对象
```
controller: SearchController = new SearchController()
```
#### caretPosition
creatPosition(value: number): viod
设置输入光标的位置。
- 参数
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| ---- | ------ | ---- | ---- | --------------------- |
| value | number | 是 | - | 从字符串开始到光标所在位置的长度。 |
## 示例
```
@Entry
@Component
struct SearchExample {
@State changevalue: string = ''
@State submitvalue: string = ''
controller: SearchController = new SearchController()
build() {
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
Text(this.submitvalue)
Text(this.changevalue)
Search({value: '', placeholder: 'Type to search', controller: this.controller})
.searchButton('Search')
.width(400)
.height(35)
.backgroundColor(Color.White)
.placeholderColor(Color.Grey)
.placeholderFont({ size: 50, weight: 10, family: 'serif', style: FontStyle.Normal })
.onSubmit((value: string) => {
this.submitvalue = value
})
.onChange((value: string) => {
this.changevalue = value
})
.margin({ top: 30 })
}
}
}
```
...@@ -29,20 +29,20 @@ Select(options: Array<SelectOption>) ...@@ -29,20 +29,20 @@ Select(options: Array<SelectOption>)
| ----------------------- | --------------------------------------------------- | ------ | ----------------------------------------------- | | ----------------------- | --------------------------------------------------- | ------ | ----------------------------------------------- |
| selected | number | - | 设置下拉菜单初始选择项的索引,第一项的索引为0。 | | selected | number | - | 设置下拉菜单初始选择项的索引,第一项的索引为0。 |
| value | string | - | 设置下拉按钮本身的文本显示。 | | value | string | - | 设置下拉按钮本身的文本显示。 |
| font | [Font](../../ui/ts-types.md#Font) | - | 设置下拉按钮本身的文本样式: | | font | [Font](../../ui/ts-types.md#Font类型) | - | 设置下拉按钮本身的文本样式: |
| fontColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉按钮本身的文本颜色。 | | fontColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉按钮本身的文本颜色。 |
| selectedOptionBgColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉菜单选中项的背景色。 | | selectedOptionBgColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉菜单选中项的背景色。 |
| selectedOptionFont | [Font](../../ui/ts-types.md#Font) | - | 设置下拉菜单选中项的文本样式: | | selectedOptionFont | [Font](../../ui/ts-types.md#Font类型) | - | 设置下拉菜单选中项的文本样式: |
| selectedOptionFontColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉菜单选中项的文本颜色。 | | selectedOptionFontColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉菜单选中项的文本颜色。 |
| optionBgColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉菜单项的背景色。 | | optionBgColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉菜单项的背景色。 |
| optionFont | [Font](../../ui/ts-types.md#Font) | - | 设置下拉菜单项的文本样式: | | optionFont | [Font](../../ui/ts-types.md#Font类型) | - | 设置下拉菜单项的文本样式: |
| optionFontColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉菜单项的文本颜色。 | | optionFontColor | [ResourceColor](../../ui/ts-types.md#ResourceColor) | - | 设置下拉菜单项的文本颜色。 |
## 事件 ## 事件
| 名称 | 功能描述 | | 名称 | 功能描述 |
| ------------------------------------------------------------ | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| onSelected(callback: (index: number, value?:string) => void) | 下拉菜单选中某一项的回调。index:选中项的索引。value:选中项的值。 | | onSelect(callback: (index: number, value?:string) => void) | 下拉菜单选中某一项的回调。index:选中项的索引。value:选中项的值。 |
## 示例 ## 示例
...@@ -61,7 +61,7 @@ struct SliderExample { ...@@ -61,7 +61,7 @@ struct SliderExample {
.font({size: 30, weight:400, family: 'serif', style: FontStyle.Normal }) .font({size: 30, weight:400, family: 'serif', style: FontStyle.Normal })
.selectedOptionFont({size: 40, weight: 500, family: 'serif', style: FontStyle.Normal }) .selectedOptionFont({size: 40, weight: 500, family: 'serif', style: FontStyle.Normal })
.optionFont({size: 30, weight: 400, family: 'serif', style: FontStyle.Normal }) .optionFont({size: 30, weight: 400, family: 'serif', style: FontStyle.Normal })
.onSelected((index:number)=>{ .onSelect((index:number)=>{
console.info("Select:" + index) console.info("Select:" + index)
}) })
} }
......
...@@ -86,7 +86,8 @@ caretPosition(value:&nbsp;number): void ...@@ -86,7 +86,8 @@ caretPosition(value:&nbsp;number): void
| -------- | -------- | | -------- | -------- |
| onChange(value:&nbsp;string)&nbsp;=&gt;&nbsp;void | 输入发生变化时,触发回调。 | | onChange(value:&nbsp;string)&nbsp;=&gt;&nbsp;void | 输入发生变化时,触发回调。 |
| onSubmit(callback:&nbsp;(enterKey:&nbsp;EnterKeyType)&nbsp;=&gt;&nbsp;void) | 回车键或者软键盘回车键触发该回调,参数为当前软键盘回车键类型。 | | onSubmit(callback:&nbsp;(enterKey:&nbsp;EnterKeyType)&nbsp;=&gt;&nbsp;void) | 回车键或者软键盘回车键触发该回调,参数为当前软键盘回车键类型。 |
| onEditChanged(callback:&nbsp;(isEditing:&nbsp;boolean)&nbsp;=&gt;&nbsp;void) | 输入状态变化时,触发回调。 | | onEditChanged(callback:&nbsp;(isEditing:&nbsp;boolean)&nbsp;=&gt;&nbsp;void)<sup>(deprecated) </sup> | 输入状态变化时,触发回调。 |
| onEditChange(callback:&nbsp;(isEditing:&nbsp;boolean)&nbsp;=&gt;&nbsp;void) <sup>8+</sup>| 输入状态变化时,触发回调。 |
| onCopy<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板复制按钮,触发回调。<br/>value:复制的文本内容。 | | onCopy<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板复制按钮,触发回调。<br/>value:复制的文本内容。 |
| onCut<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板剪切按钮,触发回调。<br/>value:剪切的文本内容。 | | onCut<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板剪切按钮,触发回调。<br/>value:剪切的文本内容。 |
| onPaste<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板粘贴按钮,触发回调。<br/>value:粘贴的文本内容。 | | onPaste<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板粘贴按钮,触发回调。<br/>value:粘贴的文本内容。 |
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册