mirror of
https://gitee.com/openharmony/applications_settings
synced 2025-02-17 07:37:45 +00:00
辅助功能快捷方式的监听刷新修改
Signed-off-by: hlj_wang_hanxiao <17750237002@163.com>
This commit is contained in:
parent
c3bbcb8bf9
commit
78f3470b19
@ -15,11 +15,12 @@
|
||||
|
||||
import accessibility from '@ohos.accessibility';
|
||||
import config from '@ohos.accessibility.config';
|
||||
import bundleMonitor from '@ohos.bundle.bundleMonitor';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
|
||||
import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
|
||||
import HeadComponent from '../../../../../../common/component/src/main/ets/default/headComponent';
|
||||
import { AccessibilitySettingModel } from '../model/accessibilityImpl/AccessibilitySettingModel';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
const TAG = ConfigData.TAG + 'Accessibility ShortKey: ';
|
||||
const BASIC_ABILITY_HIGH_CONTRAST_TEXT = 'HIGH_CONTRAST_TEXT';
|
||||
@ -50,16 +51,16 @@ struct AccessibilityShortKey {
|
||||
Column() {
|
||||
GridContainer({ gutter: ConfigData.GRID_CONTAINER_GUTTER_24, margin: ConfigData.GRID_CONTAINER_MARGIN_24 }) {
|
||||
Column() {
|
||||
HeadComponent({ headName: $r("app.string.accessibility_shortcuts"), isActive: true });
|
||||
Text($r("app.string.accessibility_shortcuts_tips"))
|
||||
HeadComponent({ headName: $r('app.string.accessibility_shortcuts'), isActive: true });
|
||||
Text($r('app.string.accessibility_shortcuts_tips'))
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
.fontWeight(FontWeight.Regular)
|
||||
.fontSize($r("app.float.font_14"))
|
||||
.lineHeight($r("app.float.lineHeight_19"))
|
||||
.fontColor($r("app.color.font_color_182431"))
|
||||
.fontSize($r('app.float.font_14'))
|
||||
.lineHeight($r('app.float.lineHeight_19'))
|
||||
.fontColor($r('app.color.font_color_182431'))
|
||||
.margin({
|
||||
bottom: $r("app.float.distance_36"),
|
||||
top: $r("app.float.distance_24"),
|
||||
bottom: $r('app.float.distance_36'),
|
||||
top: $r('app.float.distance_24'),
|
||||
left: $r("app.float.distance_12"),
|
||||
right: $r("app.float.distance_12"),
|
||||
})
|
||||
@ -88,7 +89,7 @@ struct AccessibilityShortKey {
|
||||
.height($r('app.float.wh_value_56'))
|
||||
.width(ConfigData.WH_100_100)
|
||||
.alignItems(VerticalAlign.Center)
|
||||
.padding({ left: $r("app.float.wh_value_12"), right: $r('app.float.wh_value_6') })
|
||||
.padding({ left: $r('app.float.wh_value_12'), right: $r('app.float.wh_value_6') })
|
||||
.backgroundColor($r("app.color.white_bg_color"))
|
||||
.borderRadius($r('app.float.radius_24'));
|
||||
}
|
||||
@ -105,7 +106,7 @@ struct AccessibilityShortKey {
|
||||
.fontColor($r('sys.color.ohos_fa_text_primary'))
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontSize($r("sys.float.ohos_id_text_size_body1"));
|
||||
.fontSize($r('sys.float.ohos_id_text_size_body1'));
|
||||
}
|
||||
.alignItems(HorizontalAlign.Start);
|
||||
|
||||
@ -178,9 +179,9 @@ struct AccessibilityShortKey {
|
||||
async getShortKeyStateAndTarget(): Promise<void> {
|
||||
await config.shortkey.get().then((data) => {
|
||||
this.shortKeyIsOn = data;
|
||||
LogUtil.info(TAG + 'get shortKeyIsOn success : ' + data);
|
||||
LogUtil.info(`${TAG} get shortKeyIsOn success : ${data}`);
|
||||
}).catch((err: BusinessError) => {
|
||||
LogUtil.error(TAG + 'failed to get shortKeyIsOn, because ' + JSON.stringify(err));
|
||||
LogUtil.error(`${TAG} failed to get shortKeyIsOn, because ${JSON.stringify(err)}`);
|
||||
});
|
||||
|
||||
await config.shortkeyTarget.get().then((data) => {
|
||||
@ -200,27 +201,93 @@ struct AccessibilityShortKey {
|
||||
this.shortKeyStatusText = data.split('/')[1];
|
||||
}
|
||||
}).catch((err: BusinessError) => {
|
||||
LogUtil.error(TAG + 'failed to get shortKeyTarget, because ' + JSON.stringify(err));
|
||||
LogUtil.error(`${TAG} failed to get shortKeyTarget, because ${JSON.stringify(err)}`);
|
||||
});
|
||||
}
|
||||
|
||||
aboutToAppear(): void {
|
||||
LogUtil.info(`${TAG} aboutToAppear in`);
|
||||
this.getShortKeyStateAndTarget();
|
||||
generateAllAbilityNameList(): Array<string> {
|
||||
let basicAbilities = [BASIC_ABILITY_HIGH_CONTRAST_TEXT, BASIC_ABILITY_SINGLE_AUDIO];
|
||||
return basicAbilities.concat(this.extAbilityNameList);
|
||||
}
|
||||
|
||||
updateAccessibilityExtensionList() {
|
||||
accessibility.getAccessibilityExtensionList('all', 'install').then((data) => {
|
||||
LogUtil.info(`${TAG} get accessibilityAbilityList success, service length: ${JSON.stringify(data.length)}`);
|
||||
if (data.length > 0) {
|
||||
data.forEach(item => this.extAbilityNameList.push(item.id));
|
||||
}
|
||||
}).catch((err: BusinessError) => {
|
||||
LogUtil.error(TAG + 'failed to get accessibilityAbilityList, because ' + JSON.stringify(err));
|
||||
LogUtil.error(`${TAG} failed to get accessibilityAbilityList, because ${JSON.stringify(err)}`);
|
||||
})
|
||||
}
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.openAbilitySelectListener();
|
||||
LogUtil.info(`${TAG} aboutToAppear in`);
|
||||
this.getShortKeyStateAndTarget();
|
||||
this.updateAccessibilityExtensionList();
|
||||
LogUtil.info(`${TAG} aboutToAppear out`);
|
||||
}
|
||||
|
||||
aboutToDisappear(): void {
|
||||
LogUtil.info(`${TAG} aboutToDisappear`);
|
||||
}
|
||||
|
||||
onPageHide(): void {
|
||||
this.closeAbilitySelectListener();
|
||||
}
|
||||
|
||||
openAbilitySelectListener(): void {
|
||||
try {
|
||||
bundleMonitor.on('add', (bundleChangeInfo) => {
|
||||
this.extAbilityNameList = [];
|
||||
this.AllAbilityNameList = [];
|
||||
this.updateAccessibilityExtensionList();
|
||||
this.AllAbilityNameList = this.generateAllAbilityNameList();
|
||||
LogUtil.info(`bundleName:${bundleChangeInfo.bundleName} userId:${bundleChangeInfo.userId}`);
|
||||
})
|
||||
} catch (errData) {
|
||||
let message = (errData as BusinessError).message;
|
||||
let errCode = (errData as BusinessError).code;
|
||||
LogUtil.error(`errData is errCode :${errCode} message:${message}`);
|
||||
}
|
||||
try {
|
||||
bundleMonitor.on('remove', (bundleChangeInfo) => {
|
||||
this.extAbilityNameList = [];
|
||||
this.AllAbilityNameList = [];
|
||||
this.updateAccessibilityExtensionList();
|
||||
this.AllAbilityNameList = this.generateAllAbilityNameList();
|
||||
if (this.AllAbilityNameList.indexOf(this.shortKeyStatusText) === -1) {
|
||||
this.shortKeyStatusText = (Object)($r('app.string.disabled'));
|
||||
this.setShortcutsFunctionState(false);
|
||||
this.SelectAbilityScalingDialog.close();
|
||||
this.getShortKeyStateAndTarget();
|
||||
}
|
||||
LogUtil.info(`bundleName:${bundleChangeInfo.bundleName} userId:${bundleChangeInfo.userId}`);
|
||||
})
|
||||
} catch (errData) {
|
||||
let message = (errData as BusinessError).message;
|
||||
let errCode = (errData as BusinessError).code;
|
||||
LogUtil.error(`errData is errCode :${errCode} message:${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
closeAbilitySelectListener(): void {
|
||||
try {
|
||||
bundleMonitor.off('add');
|
||||
} catch (errData) {
|
||||
let message = (errData as BusinessError).message;
|
||||
let errCode = (errData as BusinessError).code;
|
||||
LogUtil.error(`errData is errCode :${errCode} message:${message}`);
|
||||
}
|
||||
try {
|
||||
bundleMonitor.off('remove');
|
||||
} catch (errData) {
|
||||
let message = (errData as BusinessError).message;
|
||||
let errCode = (errData as BusinessError).code;
|
||||
LogUtil.error(`errData is errCode :${errCode} message:${message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@CustomDialog
|
||||
@ -231,16 +298,58 @@ struct SelectAbilityScalingInformation {
|
||||
@Link extAbilityNameList: Array<string>;
|
||||
@Link AllAbilityNameList: Array<string>;
|
||||
|
||||
updateAccessibilityExtensionList() {
|
||||
accessibility.getAccessibilityExtensionList('all', 'install').then((data) => {
|
||||
LogUtil.info(`${TAG} get accessibilityAbilityList success, service length: ${JSON.stringify(data.length)}`);
|
||||
if (data.length > 0) {
|
||||
data.forEach(item => this.extAbilityNameList.push(item.id));
|
||||
}
|
||||
}).catch((err: BusinessError) => {
|
||||
LogUtil.error(`${TAG} failed to get accessibilityAbilityList, because ${JSON.stringify(err)}`);
|
||||
})
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
LogUtil.info(`${TAG} aboutToAppear Accessibility Functions list`);
|
||||
this.AllAbilityNameList = this.generateAllAbilityNameList();
|
||||
LogUtil.info(JSON.stringify(this.AllAbilityNameList));
|
||||
try {
|
||||
bundleMonitor.on('add', (bundleChangeInfo) => {
|
||||
this.extAbilityNameList = [];
|
||||
this.AllAbilityNameList = [];
|
||||
this.updateAccessibilityExtensionList();
|
||||
this.AllAbilityNameList = this.generateAllAbilityNameList();
|
||||
this.controller?.close();
|
||||
LogUtil.info(`bundleName:${bundleChangeInfo.bundleName} userId:${bundleChangeInfo.userId}`);
|
||||
})
|
||||
} catch (errData) {
|
||||
let message = (errData as BusinessError).message;
|
||||
let errCode = (errData as BusinessError).code;
|
||||
LogUtil.error(`errData is errCode :${errCode} message:${message}`);
|
||||
}
|
||||
try {
|
||||
bundleMonitor.on('remove', (bundleChangeInfo) => {
|
||||
this.extAbilityNameList = [];
|
||||
this.AllAbilityNameList = [];
|
||||
this.updateAccessibilityExtensionList();
|
||||
this.AllAbilityNameList = this.generateAllAbilityNameList();
|
||||
if (this.AllAbilityNameList.indexOf(this.shortKeyStatusText) === -1) {
|
||||
this.shortKeyStatusText = (Object)($r('app.string.disabled'));
|
||||
}
|
||||
this.controller?.close();
|
||||
LogUtil.info(`bundleName:${bundleChangeInfo.bundleName} userId:${bundleChangeInfo.userId}`);
|
||||
})
|
||||
} catch (errData) {
|
||||
let message = (errData as BusinessError).message;
|
||||
let errCode = (errData as BusinessError).code;
|
||||
LogUtil.error(`errData is errCode :${errCode} message:${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Column() {
|
||||
Text($r("app.string.accessibility_select_ability"))
|
||||
Text($r('app.string.accessibility_select_ability'))
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
.fontSize($r('sys.float.ohos_id_text_size_headline8'))
|
||||
.fontWeight(FontWeight.Medium)
|
||||
@ -248,7 +357,7 @@ struct SelectAbilityScalingInformation {
|
||||
.alignSelf(ItemAlign.Start);
|
||||
|
||||
List() {
|
||||
ForEach(this.AllAbilityNameList, (item: string, index) => {
|
||||
ForEach(Array.from(new Set(this.AllAbilityNameList)), (item: string, index) => {
|
||||
ListItem() {
|
||||
Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
|
||||
Text((item === BASIC_ABILITY_HIGH_CONTRAST_TEXT) ? $r('app.string.highContrast_text') :
|
||||
@ -276,7 +385,7 @@ struct SelectAbilityScalingInformation {
|
||||
})
|
||||
}
|
||||
|
||||
Text($r("app.string.Cancel_Animation"))
|
||||
Text($r('app.string.Cancel_Animation'))
|
||||
.fontSize($r('sys.float.ohos_id_text_size_button1'))
|
||||
.fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
|
||||
.alignSelf(ItemAlign.Center)
|
||||
|
Loading…
x
Reference in New Issue
Block a user