未验证 提交 4a45fdb5 编写于 作者: O openharmony_ci 提交者: Gitee

!21849 翻译完成 21550+21149+20673+20609:剪贴板资料优化+【screenlock】示例规范整改

Merge pull request !21849 from ester.zhou/TR-21550
......@@ -50,7 +50,7 @@ Creates a **PasteData** object of a custom type.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mimeType | string | Yes| MIME type of custom data.|
| mimeType | string | Yes| MIME type of custom data. The value can a predefined MIME type listed in [Constants](#constants), including HTML, WANT, plain text, URI, and pixel map, or a custom MIME type.|
| value | [ValueType](#valuetype9) | Yes| Content of custom data.|
**Return value**
......@@ -59,13 +59,21 @@ Creates a **PasteData** object of a custom type.
| -------- | -------- |
| [PasteData](#pastedata) | **PasteData** object.|
**Example**
**Example 1**
```js
let dataXml = new ArrayBuffer(256);
let pasteData = pasteboard.createData('app/xml', dataXml);
let pasteData = pasteboard.createData('app/xml', dataXml);
```
**Example 2**
```js
let dataText = 'hello';
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, dataText);
```
## pasteboard.createRecord<sup>9+</sup>
createRecord(mimeType: string, value: ValueType):PasteDataRecord;
......@@ -78,7 +86,7 @@ Creates a **PasteDataRecord** object of the custom type.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mimeType | string | Yes| MIME type of custom data.|
| mimeType | string | Yes| MIME type of custom data. The value can a predefined MIME type listed in [Constants](#constants), including HTML, WANT, plain text, URI, and pixel map, or a custom MIME type. |
| value | [ValueType](#valuetype9) | Yes| Content of custom data.|
**Return value**
......@@ -87,13 +95,20 @@ Creates a **PasteDataRecord** object of the custom type.
| -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the custom type.|
**Example**
**Example 1**
```js
let dataXml = new ArrayBuffer(256);
let pasteDataRecord = pasteboard.createRecord('app/xml', dataXml);
```
**Example 2**
```js
let dataUri = 'dataability:///com.example.myapplication1/user.txt';
let record = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, dataUri);
```
## pasteboard.getSystemPasteboard
getSystemPasteboard(): SystemPasteboard
......@@ -751,27 +766,53 @@ Sets a [PasteDataProperty](#pastedataproperty7) object.
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, 'application/xml');
let prop = pasteData.getProperty();
prop.shareOption = pasteboard.ShareOption.INAPP;
prop.additions['TestOne'] = 123;
prop.additions['TestOne'] = {'Test' : 123};
prop.additions['TestTwo'] = {'Test' : 'additions'};
prop.tag = 'TestTag';
pasteData.setProperty(prop);
```
The **localOnly** and **shareOption** attributes of [PasteDataProperty](#pastedataproperty7) are mutually exclusive. The **shareOption** attribute prevails, and its value affect the value of **localOnly**.
```js
prop.shareOption = pasteboard.ShareOption.INAPP;
prop.localOnly = false;
pasteData.setProperty(prop);
pasteData.localOnly //true
prop.shareOption = pasteboard.ShareOption.LOCALDEVICE;
prop.localOnly = false;
pasteData.setProperty(prop);
pasteData.localOnly //true
prop.shareOption = pasteboard.ShareOption.CROSSDEVICE;
prop.localOnly = true;
pasteData.setProperty(prop);
pasteData.localOnly //false
(async function() {
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let prop = pasteData.getProperty();
prop.shareOption = pasteboard.ShareOption.INAPP;
prop.localOnly = false;
pasteData.setProperty(prop);
let systemPasteboard = pasteboard.getSystemPasteboard();
await systemPasteboard.setData(pasteData).then(async () => {
console.info('Succeeded in setting PasteData.');
await systemPasteboard.getData().then(pasteData => {
let prop = pasteData.getProperty();
prop.localOnly //true
});
});
prop.shareOption = pasteboard.ShareOption.LOCALDEVICE;
prop.localOnly = false;
pasteData.setProperty(prop);
await systemPasteboard.setData(pasteData).then(async () => {
console.info('Succeeded in setting PasteData.');
await systemPasteboard.getData().then(pasteData => {
let prop = pasteData.getProperty();
prop.localOnly; //true
});
});
prop.shareOption = pasteboard.ShareOption.CROSSDEVICE;
prop.localOnly = true;
pasteData.setProperty(prop);
await systemPasteboard.setData(pasteData).then(async () => {
console.info('Succeeded in setting PasteData.');
await systemPasteboard.getData().then(pasteData => {
let prop = pasteData.getProperty();
prop.localOnly; //false
});
});
})()
```
......@@ -1301,7 +1342,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er
**Example**
```js
let pasteData = pasteboard.createPlainTextData('content');
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'content');
let systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setData(pasteData, (err, data) => {
if (err) {
......@@ -1344,7 +1385,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er
**Example**
```js
let pasteData = pasteboard.createPlainTextData('content');
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'content');
let systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setData(pasteData).then((data) => {
console.info('Succeeded in setting PasteData.');
......
......@@ -9,7 +9,7 @@ The **screenlock** module is a system module in OpenHarmony. It provides APIs fo
## Modules to Import
```js
import screenlock from '@ohos.screenLock';
import screenLock from '@ohos.screenLock';
```
## EventType<sup>9+</sup>
......@@ -50,7 +50,7 @@ Defines the structure of the system event callback.
| eventType | [EventType](#eventtype9) | Yes | System event type.|
| params | string | Yes | System event parameters.|
## screenlock.isLocked<sup>9+</sup>
## screenLock.isLocked<sup>9+</sup>
isLocked(): boolean
......@@ -69,10 +69,10 @@ Checks whether the screen is locked.
**Example**
```js
let isLocked = screenlock.isLocked();
let isLocked = screenLock.isLocked();
```
## screenlock.unlock<sup>9+</sup>
## screenLock.unlock<sup>9+</sup>
unlock(callback: AsyncCallback&lt;boolean&gt;): void
......@@ -98,17 +98,17 @@ For details about the error codes, see [Screen Lock Management Error Codes](../e
**Example**
```js
screenlock.unlock((err, data) => {
```js
screenLock.unlock((err, data) => {
if (err) {
console.error(`Failed to unlock the screen, because: ${err.message}`);
return;
console.error(`Failed to unlock the screen. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`unlock the screen successfully. result: ${data}`);
});
```
console.info(`Succeeded in unlocking the screen. Result: ${data}`);
});
```
## screenlock.unlock<sup>9+</sup>
## screenLock.unlock<sup>9+</sup>
unlock(): Promise&lt;boolean&gt;
......@@ -134,15 +134,15 @@ For details about the error codes, see [Screen Lock Management Error Codes](../e
**Example**
```js
screenlock.unlock().then((data) => {
console.info(`unlock the screen successfully. result: ${data}`);
}).catch((err) => {
console.error(`Failed to unlock the screen, because: ${err.message}`);
});
```
```js
screenLock.unlock().then((data) => {
console.info(`Succeeded in unlocking the screen. Result: ${data}`);
}).catch((err) => {
console.error(`Failed to unlock the screen, Code: ${err.code}, message: ${err.message}`);
});
```
## screenlock.lock<sup>9+</sup>
## screenLock.lock<sup>9+</sup>
lock(callback: AsyncCallback&lt;boolean&gt;): void
......@@ -170,17 +170,17 @@ For details about the error codes, see [Screen Lock Management Error Codes](../e
**Example**
```js
screenlock.lock((err, data) => {
```js
screenLock.lock((err, data) => {
if (err) {
console.error(`Failed to lock the screen, because: ${err.message}`);
return;
console.error(`Failed to lock the screen. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`lock the screen successfully. result: ${data}`);
});
```
console.info(`Succeeded in locking the screen. result: ${data}`);
});
```
## screenlock.lock<sup>9+</sup>
## screenLock.lock<sup>9+</sup>
lock(): Promise&lt;boolean&gt;
......@@ -208,15 +208,15 @@ For details about the error codes, see [Screen Lock Management Error Codes](../e
**Example**
```js
screenlock.lock().then((data) => {
console.info(`lock the screen successfully. result: ${data}`);
}).catch((err) => {
console.error(`Failed to lock the screen, because: ${err.message}`);
});
```
```js
screenLock.lock().then((data) => {
console.info(`Succeeded in locking the screen. Result: ${data}`);
}).catch((err) => {
console.error(`Failed to lock the screen. Code: ${err.code}, message: ${err.message}`);
});
```
## screenlock.onSystemEvent<sup>9+</sup>
## screenLock.onSystemEvent<sup>9+</sup>
onSystemEvent(callback: Callback&lt;SystemEvent&gt;): boolean
......@@ -250,17 +250,17 @@ For details about the error codes, see [Screen Lock Management Error Codes](../e
**Example**
```js
try {
let isSuccess = screenlock.onSystemEvent((event) => {
console.log(`Register the system event which related to screenlock successfully. eventType: ${event.eventType}`)
```js
try {
let isSuccess = screenLock.onSystemEvent((event) => {
console.log(`Succeeded in registering the system event related to screenlock. eventType: ${event.eventType}`)
});
} catch (err) {
console.error(`Failed to register the system event which related to screenlock, because: ${err.message}`)
}
```
} catch (err) {
console.error(`Failed to register the system event related to screenlock. Code: ${err.code}, message: ${err.message}`)
}
```
## screenlock.sendScreenLockEvent<sup>9+</sup>
## screenLock.sendScreenLockEvent<sup>9+</sup>
sendScreenLockEvent(event: String, parameter: number, callback: AsyncCallback&lt;boolean&gt;): void
......@@ -290,17 +290,17 @@ For details about the error codes, see [Screen Lock Management Error Codes](../e
**Example**
```js
screenlock.sendScreenLockEvent('unlockScreenResult', 0, (err, result) => {
```js
screenLock.sendScreenLockEvent('unlockScreenResult', 0, (err, result) => {
if (err) {
console.error(`Failed to send screenlock event, because: ${err.message}`);
return;
console.error(`Failed to send the screenlock event. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Send screenlock event successfully. result: ${result}`);
});
```
console.info(`Succeeded in sending the screenlock event. result: ${result}`);
});
```
## screenlock.sendScreenLockEvent<sup>9+</sup>
## screenLock.sendScreenLockEvent<sup>9+</sup>
sendScreenLockEvent(event: String, parameter: number): Promise&lt;boolean&gt;
......@@ -335,15 +335,15 @@ For details about the error codes, see [Screen Lock Management Error Codes](../e
**Example**
```js
screenlock.sendScreenLockEvent('unlockScreenResult', 0).then((result) => {
console.info(`Send screenlock event successfully. result: ${result}`);
}).catch((err) => {
console.error(`Failed to send screenlock event, because: ${err.message}`);
});
```
```js
screenLock.sendScreenLockEvent('unlockScreenResult', 0).then((result) => {
console.info(`Succeeded in sending the screenlock event. Result: ${result}`);
}).catch((err) => {
console.error(`Failed to send the screenlock event. Code: ${err.code}, message: ${err.message}`);
});
```
## screenlock.isScreenLocked<sup>(deprecated)</sup>
## screenLock.isScreenLocked<sup>(deprecated)</sup>
isScreenLocked(callback: AsyncCallback&lt;boolean&gt;): void
......@@ -363,17 +363,17 @@ Checks whether the screen is locked. This API uses an asynchronous callback to r
**Example**
```js
screenlock.isScreenLocked((err, data)=>{
```js
screenLock.isScreenLocked((err, data)=>{
if (err) {
console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`);
return;
console.error(`Failed to obtain whether the screen is locked. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Obtain whether the screen is locked successfully. result: ${data}`);
});
```
console.info(`Succeeded in obtaining whether the screen is locked. Result: ${data}`);
});
```
## screenlock.isScreenLocked<sup>(deprecated)</sup>
## screenLock.isScreenLocked<sup>(deprecated)</sup>
isScreenLocked(): Promise&lt;boolean&gt;
......@@ -393,15 +393,15 @@ Checks whether the screen is locked. This API uses a promise to return the resul
**Example**
```js
screenlock.isScreenLocked().then((data) => {
console.info(`Obtain whether the screen is locked successfully. result: ${data}`);
}).catch((err) => {
console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`);
});
```
```js
screenLock.isScreenLocked().then((data) => {
console.info(`Succeeded in obtaining whether the screen is locked. Result: ${data}`);
}).catch((err) => {
console.error(`Failed to obtain whether the screen is locked. Code: ${err.code}, message: ${err.message}`);
});
```
## screenlock.isSecureMode<sup>(deprecated)</sup>
## screenLock.isSecureMode<sup>(deprecated)</sup>
isSecureMode(callback: AsyncCallback&lt;boolean&gt;): void
......@@ -421,17 +421,17 @@ Checks whether the device is in secure mode. When the device is in secure mode,
**Example**
```js
screenlock.isSecureMode((err, data)=>{
```js
screenLock.isSecureMode((err, data)=>{
if (err) {
console.error(`Failed to obtain whether the device is in secure mode, because: ${err.message}`);
return;
console.error(`Failed to obtain whether the device is in secure mode. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Obtain whether the device is in secure mode successfully. result: ${data}`);
});
```
console.info(`Succeeded in obtaining whether the device is in secure mode. Result: ${data}`);
});
```
## screenlock.isSecureMode<sup>(deprecated)</sup>
## screenLock.isSecureMode<sup>(deprecated)</sup>
isSecureMode(): Promise&lt;boolean&gt;
......@@ -451,14 +451,15 @@ Checks whether the device is in secure mode. When the device is in secure mode,
**Example**
```js
screenlock.isSecureMode().then((data) => {
console.info(`Obtain whether the device is in secure mode successfully. result: ${data}`);
}).catch((err) => {
console.error(`Failed to obtain whether the device is in secure mode, because: ${err.message}`);
});
```
## screenlock.unlockScreen<sup>(deprecated)</sup>
```js
screenLock.isSecureMode().then((data) => {
console.info(`Succeeded in obtaining whether the device is in secure mode. Result: ${data}`);
}).catch((err) => {
console.error(`Failed to obtain whether the device is in secure mode. Code: ${err.code}, message: ${err.message}`);
});
```
## screenLock.unlockScreen<sup>(deprecated)</sup>
unlockScreen(callback: AsyncCallback&lt;void&gt;): void
......@@ -478,17 +479,17 @@ Unlocks the screen. This API uses an asynchronous callback to return the result.
**Example**
```js
screenlock.unlockScreen((err) => {
```js
screenLock.unlockScreen((err) => {
if (err) {
console.error(`Failed to unlock the screen, because: ${err.message}`);
return;
console.error(`Failed to unlock the screen. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info('unlock the screen successfully.');
});
```
console.info(`Succeeded in unlocking the screen.`);
});
```
## screenlock.unlockScreen<sup>(deprecated)</sup>
## screenLock.unlockScreen<sup>(deprecated)</sup>
unlockScreen(): Promise&lt;void&gt;
......@@ -508,10 +509,10 @@ Unlocks the screen. This API uses a promise to return the result.
**Example**
```js
screenlock.unlockScreen().then(() => {
console.info('unlock the screen successfully.');
}).catch((err) => {
console.error(`Failed to unlock the screen, because: ${err.message}`);
});
```
```js
screenLock.unlockScreen().then(() => {
console.info('Succeeded in unlocking the screen.');
}).catch((err) => {
console.error(`Failed to unlock the screen. Code: ${err.code}, message: ${err.message}`);
});
```
# Theme Framework Subsystem – Screen Lock Management Service Changelog
## cl.screenlock.1 Instance Name Change
Changed the name of the instance for importing the **@ohos.screenLock** module from **screenlock** to **screenLock**.
**Change Impact**
None.
**Key API/Component Changes**
Before change:
```js
screenlock.isLocked();
screenlock.unlock();
screenlock.lock();
screenlock.onSystemEvent(event=>{});
screenlock.sendScreenLockEvent('unlockScreenResult', 0);
screenlock.isScreenLocked()
screenlock.isSecureMode();
screenlock.unlockScreen();
```
After change:
```js
screenLock.isLocked();
screenLock.unlock();
screenLock.lock();
screenLock.onSystemEvent(event=>{});
screenLock.sendScreenLockEvent('unlockScreenResult', 0);
screenLock.isScreenLocked()
screenLock.isSecureMode();
screenLock.unlockScreen();
```
**Adaptation Guide**
Use **screenLock** in the **import** statement.
Before change:
```js
import screenlock from '@ohos.screenLock';
```
After change:
```js
import screenLock from '@ohos.screenLock';
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册