提交 9e4cf9e1 编写于 作者: Z zaki

update sample codes in docs of accessibility

Signed-off-by: Nzaki <zhoujun141@huawei.com>
Change-Id: I5e09d76b2b83a022e0b458d60277629efd24075c
上级 d9e76943
...@@ -44,6 +44,5 @@ constructor(durationTime: number); ...@@ -44,6 +44,5 @@ constructor(durationTime: number);
**示例:** **示例:**
```ts ```ts
let durationTime = 20; let gesturePath = new GesturePath.GesturePath(20);
let gesturePath = new GesturePath(durationTime);
``` ```
...@@ -45,7 +45,5 @@ constructor(positionX: number, positionY: number); ...@@ -45,7 +45,5 @@ constructor(positionX: number, positionY: number);
**示例:** **示例:**
```ts ```ts
let positionX = 1; let gesturePoint = new GesturePoint.GesturePoint(1, 2);
let positionY = 2;
let gesturePoint = new GesturePoint(positionX, positionY);
``` ```
...@@ -65,7 +65,7 @@ enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;): ...@@ -65,7 +65,7 @@ enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;):
```ts ```ts
let name = 'com.ohos.example/axExtension'; let name = 'com.ohos.example/axExtension';
let capability = ['retrieve']; let capability : accessibility.Capability[] = ['retrieve'];
try { try {
config.enableAbility(name, capability).then(() => { config.enableAbility(name, capability).then(() => {
console.info('enable ability succeed'); console.info('enable ability succeed');
...@@ -75,7 +75,7 @@ try { ...@@ -75,7 +75,7 @@ try {
} catch (exception) { } catch (exception) {
console.error('failed to enable ability, because ' + JSON.stringify(exception)); console.error('failed to enable ability, because ' + JSON.stringify(exception));
}; };
``` ```
## enableAbility ## enableAbility
...@@ -106,9 +106,9 @@ enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;, c ...@@ -106,9 +106,9 @@ enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;, c
```ts ```ts
let name = 'com.ohos.example/axExtension'; let name = 'com.ohos.example/axExtension';
let capability = ['retrieve']; let capability : accessibility.Capability[] = ['retrieve'];
try { try {
config.enableAbility(name, capability, (err, data) => { config.enableAbility(name, capability, (err) => {
if (err) { if (err) {
console.error('failed to enable ability, because ' + JSON.stringify(err)); console.error('failed to enable ability, because ' + JSON.stringify(err));
return; return;
...@@ -153,7 +153,7 @@ disableAbility(name: string): Promise&lt;void&gt;; ...@@ -153,7 +153,7 @@ disableAbility(name: string): Promise&lt;void&gt;;
```ts ```ts
let name = 'com.ohos.example/axExtension'; let name = 'com.ohos.example/axExtension';
try { try {
config.enableAbility(name).then(() => { config.disableAbility(name).then(() => {
console.info('disable ability succeed'); console.info('disable ability succeed');
}).catch((err) => { }).catch((err) => {
console.error('failed to disable ability, because ' + JSON.stringify(err)); console.error('failed to disable ability, because ' + JSON.stringify(err));
...@@ -224,12 +224,9 @@ on(type: 'enabledAccessibilityExtensionListChange', callback: Callback&lt;void&g ...@@ -224,12 +224,9 @@ on(type: 'enabledAccessibilityExtensionListChange', callback: Callback&lt;void&g
try { try {
config.on('enabledAccessibilityExtensionListChange', () => { config.on('enabledAccessibilityExtensionListChange', () => {
console.info('subscribe enabled accessibility extension list change state success'); console.info('subscribe enabled accessibility extension list change state success');
}).catch((err) => {
console.error('failed to subscribe enabled accessibility extension list change state, because ' +
JSON.stringify(err));
}); });
} catch (exception) { } catch (exception) {
console.error('failed to subscribe enabled accessibility extension list change state, because ' + console.error('failed to subscribe enabled accessibility extension list change state, because ' +
JSON.stringify(exception)); JSON.stringify(exception));
}; };
``` ```
...@@ -254,13 +251,10 @@ off(type: 'enabledAccessibilityExtensionListChange', callback?: Callback&lt;void ...@@ -254,13 +251,10 @@ off(type: 'enabledAccessibilityExtensionListChange', callback?: Callback&lt;void
```ts ```ts
try { try {
config.off('enabledAccessibilityExtensionListChange', () => { config.off('enabledAccessibilityExtensionListChange', () => {
console.info('unSubscribe enabled accessibility extension list change state success'); console.info('Unsubscribe enabled accessibility extension list change state success');
}).catch((err) => {
console.error('failed to unSubscribe enabled accessibility extension list change state, because ' +
JSON.stringify(err));
}); });
} catch (exception) { } catch (exception) {
console.error('failed to unSubscribe enabled accessibility extension list change state, because ' + console.error('failed to Unsubscribe enabled accessibility extension list change state, because ' +
JSON.stringify(exception)); JSON.stringify(exception));
}; };
``` ```
...@@ -408,12 +402,8 @@ on(callback: Callback&lt;T&gt;): void; ...@@ -408,12 +402,8 @@ on(callback: Callback&lt;T&gt;): void;
```ts ```ts
try { try {
config.highContrastText.on((err, data) => { config.highContrastText.on((data) => {
if (err) { console.info('subscribe highContrastText success, result: ' + JSON.stringify(data));
console.error('failed subscribe highContrastText, because ' + JSON.stringify(err));
return;
}
console.info('subscribe highContrastText success');
}); });
} catch (exception) { } catch (exception) {
console.error('failed subscribe highContrastText, because ' + JSON.stringify(exception)); console.error('failed subscribe highContrastText, because ' + JSON.stringify(exception));
...@@ -437,12 +427,8 @@ off(callback?: Callback&lt;T&gt;): void; ...@@ -437,12 +427,8 @@ off(callback?: Callback&lt;T&gt;): void;
**示例:** **示例:**
```ts ```ts
config.highContrastText.off((err, data) => { config.highContrastText.off((data) => {
if (err) { console.info('Unsubscribe highContrastText success, result: ' + JSON.stringify(data));
console.error('failed unSubscribe highContrastText, because ' + JSON.stringify(err));
return;
}
console.info('unSubscribe highContrastText success');
}); });
``` ```
......
...@@ -171,16 +171,10 @@ on(type: 'enableChange', callback: Callback&lt;boolean&gt;): void; ...@@ -171,16 +171,10 @@ on(type: 'enableChange', callback: Callback&lt;boolean&gt;): void;
**示例:** **示例:**
```ts ```ts
let result = false;
let captionsManager = accessibility.getCaptionsManager(); let captionsManager = accessibility.getCaptionsManager();
try { try {
captionsManager.on('enableChange', (err, data) => { captionsManager.on('enableChange', (data) => {
if (err) { console.info('subscribe caption manager enable state change, result: ' + JSON.stringify(data));
console.error('failed to subscribe caption manager enable state change, because ' + JSON.stringify(err));
return;
}
result = data;
console.info('subscribe caption manager enable state change success');
}); });
} catch (exception) { } catch (exception) {
console.error('failed to subscribe caption manager enable state change, because ' + JSON.stringify(exception)); console.error('failed to subscribe caption manager enable state change, because ' + JSON.stringify(exception));
...@@ -206,13 +200,9 @@ on(type: 'styleChange', callback: Callback&lt;CaptionsStyle&gt;): void; ...@@ -206,13 +200,9 @@ on(type: 'styleChange', callback: Callback&lt;CaptionsStyle&gt;): void;
let captionStyle; let captionStyle;
let captionsManager = accessibility.getCaptionsManager(); let captionsManager = accessibility.getCaptionsManager();
try { try {
captionsManager.on('styleChange', (err, data) => { captionsManager.on('styleChange', (data) => {
if (err) {
console.error('failed to subscribe caption manager style state change, because ' + JSON.stringify(err));
return;
}
captionStyle = data; captionStyle = data;
console.info('subscribe caption manager style state change success'); console.info('subscribe caption manager style state change, result: ' + JSON.stringify(data));
}); });
} catch (exception) { } catch (exception) {
console.error('failed to subscribe caption manager style state change, because ' + JSON.stringify(exception)); console.error('failed to subscribe caption manager style state change, because ' + JSON.stringify(exception));
...@@ -235,19 +225,13 @@ off(type: 'enableChange', callback?: Callback&lt;boolean&gt;): void; ...@@ -235,19 +225,13 @@ off(type: 'enableChange', callback?: Callback&lt;boolean&gt;): void;
**示例:** **示例:**
```ts ```ts
let result = false;
let captionsManager = accessibility.getCaptionsManager(); let captionsManager = accessibility.getCaptionsManager();
try { try {
captionsManager.off('enableChange', (err, data) => { captionsManager.off('enableChange', (data) => {
if (err) { console.info('Unsubscribe caption manager enable state change, result: ' + JSON.stringify(data));
console.error('failed to unSubscribe caption manager enable state change, because ' + JSON.stringify(err));
return;
}
result = data;
console.info('unSubscribe caption manager enable state change success');
}); });
} catch (exception) { } catch (exception) {
console.error('failed to unSubscribe caption manager enable state change, because ' + JSON.stringify(exception)); console.error('failed to Unsubscribe caption manager enable state change, because ' + JSON.stringify(exception));
} }
``` ```
...@@ -270,16 +254,12 @@ off(type: 'styleChange', callback?: Callback&lt;CaptionsStyle&gt;): void; ...@@ -270,16 +254,12 @@ off(type: 'styleChange', callback?: Callback&lt;CaptionsStyle&gt;): void;
let captionStyle; let captionStyle;
let captionsManager = accessibility.getCaptionsManager(); let captionsManager = accessibility.getCaptionsManager();
try { try {
captionsManager.off('styleChange', (err, data) => { captionsManager.off('styleChange', (data) => {
if (err) {
console.error('failed to unSubscribe caption manager style state change, because ' + JSON.stringify(err));
return;
}
captionStyle = data; captionStyle = data;
console.info('unSubscribe caption manager style state change success'); console.info('Unsubscribe caption manager style state change, result: ' + JSON.stringify(data));
}); });
} catch (exception) { } catch (exception) {
console.error('failed to unSubscribe caption manager style state change, because ' + JSON.stringify(exception)); console.error('failed to Unsubscribe caption manager style state change, because ' + JSON.stringify(exception));
} }
``` ```
...@@ -503,9 +483,9 @@ getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState) ...@@ -503,9 +483,9 @@ getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState)
**示例:** **示例:**
```ts ```ts
let abilityType = 'spoken'; let abilityType : accessibility.AbilityType = 'spoken';
let abilityState = 'enable'; let abilityState : accessibility.AbilityState = 'enable';
let extensionList: accessibility.AccessibilityInfo[]; let extensionList: accessibility.AccessibilityAbilityInfo[] = [];
try { try {
accessibility.getAccessibilityExtensionList(abilityType, abilityState).then((data) => { accessibility.getAccessibilityExtensionList(abilityType, abilityState).then((data) => {
for (let item of data) { for (let item of data) {
...@@ -526,7 +506,7 @@ try { ...@@ -526,7 +506,7 @@ try {
## accessibility.getAccessibilityExtensionList<sup>9+</sup> ## accessibility.getAccessibilityExtensionList<sup>9+</sup>
getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState,callback: AsyncCallback&lt;Array&lt;AccessibilityAbilityInfo&gt;&gt;): void getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState, callback: AsyncCallback&lt;Array&lt;AccessibilityAbilityInfo&gt;&gt;): void
查询辅助应用列表,使用callback异步回调。 查询辅助应用列表,使用callback异步回调。
...@@ -543,9 +523,9 @@ getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState, ...@@ -543,9 +523,9 @@ getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState,
**示例:** **示例:**
```ts ```ts
let abilityType = 'spoken'; let abilityType : accessibility.AbilityType = 'spoken';
let abilityState = 'enable'; let abilityState : accessibility.AbilityState = 'enable';
let extensionList: accessibility.AccessibilityInfo[]; let extensionList: accessibility.AccessibilityAbilityInfo[] = [];
try { try {
accessibility.getAccessibilityExtensionList(abilityType, abilityState, (err, data) => { accessibility.getAccessibilityExtensionList(abilityType, abilityState, (err, data) => {
if (err) { if (err) {
...@@ -560,8 +540,6 @@ try { ...@@ -560,8 +540,6 @@ try {
extensionList.push(item); extensionList.push(item);
} }
console.info('get accessibility extension list success'); console.info('get accessibility extension list success');
}).catch((err) => {
console.error('failed to get accessibility extension list because ' + JSON.stringify(err));
}); });
} catch (exception) { } catch (exception) {
console.error('failed to get accessibility extension list because ' + JSON.stringify(exception)); console.error('failed to get accessibility extension list because ' + JSON.stringify(exception));
...@@ -607,12 +585,8 @@ on(type: 'accessibilityStateChange', callback: Callback&lt;boolean&gt;): void ...@@ -607,12 +585,8 @@ on(type: 'accessibilityStateChange', callback: Callback&lt;boolean&gt;): void
```ts ```ts
try { try {
accessibility.on('accessibilityStateChange', (err, data) => { accessibility.on('accessibilityStateChange', (data) => {
if (err) { console.info('subscribe accessibility state change, result: ' + JSON.stringify(data));
console.error('failed to subscribe accessibility state change, because ' + JSON.stringify(err));
return;
}
console.info('subscribe accessibility state change success');
}); });
} catch (exception) { } catch (exception) {
console.error('failed to subscribe accessibility state change, because ' + JSON.stringify(exception)); console.error('failed to subscribe accessibility state change, because ' + JSON.stringify(exception));
...@@ -638,12 +612,8 @@ on(type: 'touchGuideStateChange', callback: Callback&lt;boolean&gt;): void ...@@ -638,12 +612,8 @@ on(type: 'touchGuideStateChange', callback: Callback&lt;boolean&gt;): void
```ts ```ts
try { try {
accessibility.on('touchGuideStateChange', (err, data) => { accessibility.on('touchGuideStateChange', (data) => {
if (err) { console.info('subscribe touch guide state change, result: ' + JSON.stringify(data));
console.error('failed to subscribe touch guide state change, because ' + JSON.stringify(err));
return;
}
console.info('subscribe touch guide state change success');
}); });
} catch (exception) { } catch (exception) {
console.error('failed to subscribe touch guide state change, because ' + JSON.stringify(exception)); console.error('failed to subscribe touch guide state change, because ' + JSON.stringify(exception));
...@@ -669,15 +639,11 @@ off(type: 'accessibilityStateChange', callback?: Callback&lt;boolean&gt;): void ...@@ -669,15 +639,11 @@ off(type: 'accessibilityStateChange', callback?: Callback&lt;boolean&gt;): void
```ts ```ts
try { try {
accessibility.on('accessibilityStateChange', (err, data) => { accessibility.off('accessibilityStateChange', (data) => {
if (err) { console.info('Unsubscribe accessibility state change, result: ' + JSON.stringify(data));
console.error('failed to unSubscribe accessibility state change, because ' + JSON.stringify(err));
return;
}
console.info('unSubscribe accessibility state change success');
}); });
} catch (exception) { } catch (exception) {
console.error('failed to unSubscribe accessibility state change, because ' + JSON.stringify(exception)); console.error('failed to Unsubscribe accessibility state change, because ' + JSON.stringify(exception));
} }
``` ```
...@@ -700,15 +666,11 @@ off(type: 'touchGuideStateChange', callback?: Callback&lt;boolean&gt;): void ...@@ -700,15 +666,11 @@ off(type: 'touchGuideStateChange', callback?: Callback&lt;boolean&gt;): void
```ts ```ts
try { try {
accessibility.on('touchGuideStateChange', (err, data) => { accessibility.off('touchGuideStateChange', (data) => {
if (err) { console.info('Unsubscribe touch guide state change, result: ' + JSON.stringify(data));
console.error('failed to unSubscribe touch guide state change, because ' + JSON.stringify(err));
return;
}
console.info('unSubscribe touch guide state change success');
}); });
} catch (exception) { } catch (exception) {
console.error('failed to unSubscribe touch guide state change, because ' + JSON.stringify(exception)); console.error('failed to Unsubscribe touch guide state change, because ' + JSON.stringify(exception));
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册