diff --git a/AppScope/app.json b/AppScope/app.json index 55d2f8e50738895f7cd6966716464e1e2291574b..1ec696b88ec590325c292f7518646738933430c7 100644 --- a/AppScope/app.json +++ b/AppScope/app.json @@ -4,8 +4,8 @@ "app": { "bundleName": "com.ohos.permissionmanager", "vendor": "example", - "versionCode": 1000073, - "versionName": "1.7.3", + "versionCode": 1000074, + "versionName": "1.7.4", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 14, diff --git a/AppScope/app.json5 b/AppScope/app.json5 index 9d216377cbad5b2fd96b05e4874911e1d8afe047..3567de05f7f6f9a9353c0319e6cdbf964361e03f 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -16,8 +16,8 @@ "app": { "bundleName": "com.ohos.permissionmanager", "vendor": "example", - "versionCode": 1000073, - "versionName": "1.7.3", + "versionCode": 1000074, + "versionName": "1.7.4", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 14, diff --git a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts index 6cd22580321569ff98e8ff84ff654f3b27fbcc84..f33d1fe0adbac0b53df725626e773d11931b43e9 100644 --- a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts +++ b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts @@ -103,7 +103,6 @@ export default class SecurityExtensionAbility extends extension { } }); await win.moveWindowTo(rect.left, rect.top); - await win.resize(rect.width, rect.height); await win.loadContent('pages/securityDialog', storage); win.setWindowBackgroundColor(BG_COLOR); await win.showWindow(); diff --git a/permissionmanager/src/main/ets/common/utils/constant.ets b/permissionmanager/src/main/ets/common/utils/constant.ets index 2ad7d999292daaf78e8e8b03fff69d558646477d..80cf08488a22593b98fa8c7bb8b509315a05ab59 100644 --- a/permissionmanager/src/main/ets/common/utils/constant.ets +++ b/permissionmanager/src/main/ets/common/utils/constant.ets @@ -369,4 +369,16 @@ export default class Constants { // permission system error codes public static CREATE_WINDOW_REPEATED = 1300001; + + public static CUSTOMIZE_BUTTON_PADDING_LEFT = 16; + public static CUSTOMIZE_BUTTON_PADDING_RIGHT = 16; + public static CUSTOMIZE_BUTTON_PADDING_TOP = 11; + public static CUSTOMIZE_BUTTON_PADDING_BOTTOM = 11; + public static CUSTOMIZE_BUTTON_WIDTH = 152; + public static CUSTOMIZE_BUTTON_MARGIN_BOTTOM = 12; + public static CUSTOMIZE_BUTTON_MARGIN_TOP = 12; + public static CUSTOMIZE_BUTTON_TEXT_MIN_SIZE = 12; + public static CUSTOMIZE_BUTTON_TEXT_MAX_SIZE = 15; + public static CONTENTS_TEXT_MARGIN_LEFT = 26; + public static CONTENTS_TEXT_MARGIN_RIGHT = 26; } diff --git a/permissionmanager/src/main/ets/pages/securityDialog.ets b/permissionmanager/src/main/ets/pages/securityDialog.ets index 9d8ca196358ac25d285f46daa994545298ab090d..43a9e2b44494c7445c52e0c28b9c3b9e69f079da 100644 --- a/permissionmanager/src/main/ets/pages/securityDialog.ets +++ b/permissionmanager/src/main/ets/pages/securityDialog.ets @@ -24,18 +24,193 @@ import { Param, WantInfo } from '../common/model/typedef'; import { GlobalContext } from '../common/utils/globalContext'; import { preferences } from '@kit.ArkData'; import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; +import deviceInfo from '@ohos.deviceInfo'; let storage = LocalStorage.getShared(); const RESOURCE_TYPE: number = 10003; -@Extend(Text)function titleText() { +class DialogInfo { + index: number = 0; + securityParams: Array = []; + appName: ResourceStr = ''; + isWearable: boolean = false; +} + +@Extend(Text) +function titleText(isWearable: boolean) { .fontWeight(FontWeight.Bold) - .fontColor($r('sys.color.font_primary')) + .fontColor(isWearable ? '#FFFFFF' : $r('sys.color.font_primary')) .textAlign(TextAlign.Center) .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(Constants.SECURITY_HEADER_MAX_LINES) } +@Extend(Button) +function customizeButton() { + .padding({ + left: Constants.CUSTOMIZE_BUTTON_PADDING_LEFT, + right: Constants.CUSTOMIZE_BUTTON_PADDING_RIGHT, + top: Constants.CUSTOMIZE_BUTTON_PADDING_TOP, + bottom: Constants.CUSTOMIZE_BUTTON_PADDING_BOTTOM + }) + .width(Constants.CUSTOMIZE_BUTTON_WIDTH) + .margin({ bottom : Constants.CUSTOMIZE_BUTTON_MARGIN_BOTTOM }) +} + +@Extend(Text) +function customizeButtonText() { + .minFontSize(Constants.CUSTOMIZE_BUTTON_TEXT_MIN_SIZE) + .maxFontSize(Constants.CUSTOMIZE_BUTTON_TEXT_MAX_SIZE) + .textAlign(TextAlign.Center) + .fontSize(Constants.CUSTOMIZE_BUTTON_TEXT_MAX_SIZE) + .fontWeight(FontWeight.Medium) + .textOverflow({ overflow: TextOverflow.MARQUEE }) +} + +@Builder +function dialogTitle(index: number, securityParams: Array, isWearable: boolean) { + Column() { + if (getFontSizeScale()) { + Text(securityParams[index].label) + .titleText(isWearable) + .fontSize($r('sys.float.Title_S')) + } else { + Text(securityParams[index].label) + .titleText(isWearable) + .minFontSize(Constants.TEXT_MIDDLE_FONT_SIZE) + .maxFontSize($r('sys.float.Title_S')) + .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) + } + } + .constraintSize({ minHeight: Constants.HEADLINE_HEIGHT }) + .justifyContent(FlexAlign.Center) + .padding({ + top: Constants.DEFAULT_PADDING_TOP, + bottom: Constants.DEFAULT_PADDING_BOTTOM, + }) +} + +@Builder +function dialogContentsArea(params: DialogInfo) { + Column() { + Column() { + SymbolGlyph($r('sys.symbol.person_shield_fill')) + .width(Constants.SECURITY_ICON_WIDTH) + .height(Constants.SECURITY_ICON_HEIGHT) + .fontSize(Constants.FONT_SIZE_28) + .fontColor([$r('sys.color.brand')]) + .border({ + width: Constants.BORDER_WIDTH_1, + color: $r('app.color.icon_border'), + radius: Constants.SECURITY_ICON_WIDTH * 14 / 54 + }) + .padding(Constants.PADDING_10) + .pixelRound({ start: PixelRoundCalcPolicy.NO_FORCE_ROUND, end: PixelRoundCalcPolicy.NO_FORCE_ROUND }) + if (params.index === 1) { + Image(params.securityParams[params.index].icon) + .width(Constants.IMAGE_LENGTH_20) + .height(Constants.IMAGE_LENGTH_20) + .syncLoad(true) + .position({ x: Constants.IMAGE_POSITION_28, y: Constants.IMAGE_POSITION_28 }) + .border({ + width: Constants.BORDER_WIDTH_1, + color: $r('app.color.icon_border'), + radius: Constants.IMAGE_LENGTH_20 * 14 / 54 + }) + } else { + SymbolGlyph($r('sys.symbol.local_fill')) + .width(Constants.IMAGE_LENGTH_20) + .height(Constants.IMAGE_LENGTH_20) + .fontSize(Constants.FONT_SIZE_12) + .fontColor([Color.White]) + .backgroundColor($r('app.color.local_background_color')) + .padding(Constants.PADDING_4) + .position({ x: Constants.IMAGE_POSITION_28, y: Constants.IMAGE_POSITION_28 }) + .border({ + width: Constants.BORDER_WIDTH_1, + color: $r('app.color.icon_border'), + radius: Constants.IMAGE_LENGTH_20 * 14 / 54 + }) + } + } + .pixelRound({ start: PixelRoundCalcPolicy.NO_FORCE_ROUND, end: PixelRoundCalcPolicy.NO_FORCE_ROUND }) + .backgroundColor($r('app.color.icon_bg')) + .borderRadius(Constants.SECURITY_ICON_WIDTH * 14 / 54) + .margin(params.isWearable ? { top: Constants.CUSTOMIZE_BUTTON_MARGIN_TOP } : {}) + Column() { // content + dialogTitle(params.index, params.securityParams, params.isWearable); + Text($r(params.securityParams[params.index].description, params.appName)) + .textAlign(params.isWearable ? TextAlign.Center : TextAlign.Start) + .fontColor(params.isWearable ? '#A8FFFFFF' : $r('sys.color.font_primary') ) + .fontSize($r('sys.float.Body_L')) + .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT) + .maxFontScale(Constants.DIALOG_TEXT_MAX_SCALE) + .margin(params.isWearable ? { + left: Constants.CONTENTS_TEXT_MARGIN_LEFT, + right: Constants.CONTENTS_TEXT_MARGIN_RIGHT, + bottom: Constants.CUSTOMIZE_BUTTON_MARGIN_BOTTOM + } : {}) + } + } + .clip(true) +} + +@CustomDialog +struct CustomDialogWearable { + cancel?: () => void; + confirm?: () => void; + dialogControllerForWearable: CustomDialogController; + @Link index: number; + @Link appName: ResourceStr; + @Link securityParams: Array; + @Link isWearable: boolean; + + build() { + Scroll() { + Column() { + dialogContentsArea({ + index: this.index, + securityParams: this.securityParams, + appName: this.appName, + isWearable: this.isWearable + }) + Button({ type: ButtonType.Capsule, stateEffect: true }) { + Text($r('app.string.allow')) + .customizeButtonText() + .fontColor('#FFFFFF') + } + .customizeButton() + .backgroundColor('#1F71FF') + .onClick(() => { + Log.info('allow click start'); + this.dialogControllerForWearable?.close(); + if (this.confirm) { + this.confirm(); + } + }) + Button({ type: ButtonType.Capsule, stateEffect: true }) { + Text($r('app.string.cancel')) + .customizeButtonText() + .fontColor('#5EA1FF') + } + .customizeButton() + .backgroundColor('#405EA1FF') + .onClick(() => { + Log.info('cancel click start'); + this.dialogControllerForWearable?.close(); + if (this.cancel) { + this.cancel(); + } + }) + } + } + .edgeEffect(EdgeEffect.Spring) + .backgroundColor(Color.Black) + .width(Constants.FULL_WIDTH) + .height(Constants.FULL_HEIGHT) + } +} + @Entry(storage) @Component struct SecurityDialog { @@ -47,8 +222,9 @@ struct SecurityDialog { @State appIndex: number = 0; @State index: number = 0; @State scrollBarWidth: number = Constants.SCROLL_BAR_WIDTH_DEFAULT; + @State isWearable: boolean = false; - securityParams : Array = [ + @State securityParams : Array = [ new Param( $r('app.media.ic_location'), $r('app.string.SecurityTitle_location'), 'app.string.SecurityDescription_location' ), @@ -57,6 +233,22 @@ struct SecurityDialog { ) ] + dialogControllerForWearable: CustomDialogController | null = new CustomDialogController({ + builder: CustomDialogWearable({ + cancel: () => { + this.onCancel() + }, + confirm: () => { + this.onAccept() + }, + index: $index, + appName: $appName, + isWearable: $isWearable, + securityParams: $securityParams + }), + customStyle: true, + }) + dialogController: CustomDialogController | null = new CustomDialogController({ builder: CustomContentDialog({ contentBuilder: () => { @@ -102,89 +294,16 @@ struct SecurityDialog { } }); - @Builder - DialogTitle() { - Column() { - if (getFontSizeScale()) { - Text(this.securityParams[this.index].label) - .titleText() - .fontSize($r('sys.float.Title_S')) - } else { - Text(this.securityParams[this.index].label) - .titleText() - .minFontSize(Constants.TEXT_MIDDLE_FONT_SIZE) - .maxFontSize($r('sys.float.Title_S')) - .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) - } - } - .constraintSize({ minHeight: Constants.HEADLINE_HEIGHT }) - .justifyContent(FlexAlign.Center) - .padding({ - top: Constants.DEFAULT_PADDING_TOP, - bottom: Constants.DEFAULT_PADDING_BOTTOM, - }) - } - @Builder buildContent(): void { Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Scroll() { - Column() { - Column() { - SymbolGlyph($r('sys.symbol.person_shield_fill')) - .width(Constants.SECURITY_ICON_WIDTH) - .height(Constants.SECURITY_ICON_HEIGHT) - .fontSize(Constants.FONT_SIZE_28) - .fontColor([$r('sys.color.brand')]) - .border({ - width: Constants.BORDER_WIDTH_1, - color: $r('app.color.icon_border'), - radius: Constants.SECURITY_ICON_WIDTH * 14 / 54 - }) - .padding(Constants.PADDING_10) - .pixelRound({ start: PixelRoundCalcPolicy.NO_FORCE_ROUND, end: PixelRoundCalcPolicy.NO_FORCE_ROUND }) - if (this.index === 1) { - Image(this.securityParams[this.index].icon) - .width(Constants.IMAGE_LENGTH_20) - .height(Constants.IMAGE_LENGTH_20) - .syncLoad(true) - .position({ x: Constants.IMAGE_POSITION_28, y: Constants.IMAGE_POSITION_28 }) - .border({ - width: Constants.BORDER_WIDTH_1, - color: $r('app.color.icon_border'), - radius: Constants.IMAGE_LENGTH_20 * 14 / 54 - }) - } else { - SymbolGlyph($r('sys.symbol.local_fill')) - .width(Constants.IMAGE_LENGTH_20) - .height(Constants.IMAGE_LENGTH_20) - .fontSize(Constants.FONT_SIZE_12) - .fontColor([Color.White]) - .backgroundColor($r('app.color.local_background_color')) - .padding(Constants.PADDING_4) - .position({ x: Constants.IMAGE_POSITION_28, y: Constants.IMAGE_POSITION_28 }) - .border({ - width: Constants.BORDER_WIDTH_1, - color: $r('app.color.icon_border'), - radius: Constants.IMAGE_LENGTH_20 * 14 / 54 - }) - } - } - .pixelRound({ start: PixelRoundCalcPolicy.NO_FORCE_ROUND, end: PixelRoundCalcPolicy.NO_FORCE_ROUND }) - .backgroundColor($r('app.color.icon_bg')) - .borderRadius(Constants.SECURITY_ICON_WIDTH * 14 / 54) - Column() { // content - this.DialogTitle(); - - Text($r(this.securityParams[this.index].description, this.appName)) - .textAlign(TextAlign.Start) - .fontColor($r('sys.color.font_primary')) - .fontSize($r('sys.float.Body_L')) - .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT) - .maxFontScale(Constants.DIALOG_TEXT_MAX_SCALE) - } - } - .clip(true) + dialogContentsArea({ + index: this.index, + securityParams: this.securityParams, + appName: this.appName, + isWearable: this.isWearable + }) } .padding({ left: Constants.PADDING_24, right: Constants.PADDING_24 }) .margin({ top: Constants.MARGIN_24 }) @@ -205,7 +324,13 @@ struct SecurityDialog { Log.info('onAboutToAppear.'); this.GetAppName(); this.index = this.want.parameters['ohos.user.security.type']; - this.dialogController?.open(); + if (deviceInfo.deviceType === 'wearable') { + this.dialogControllerForWearable?.open(); + this.isWearable = true; + } else { + this.dialogController?.open(); + this.isWearable = false; + } this.dataPreferences?.on('change', (key: string) => { Log.info('dataPreferences change.'); this.appIndex === 0 ? null : this.GetAppName(); @@ -213,7 +338,26 @@ struct SecurityDialog { } aboutToDisappear() { + Log.info('aboutToDisappear.'); this.dialogController = null; + this.dialogControllerForWearable = null; + } + + onCancel() { + Log.info('Callback when the first button is clicked'); + this.win.destroyWindow(); + let dialogSet: Set = GlobalContext.load('dialogSet'); + let callerToken: number = this.want.parameters['ohos.caller.uid']; + dialogSet.delete(callerToken); + GlobalContext.store('dialogSet', dialogSet); + if (dialogSet.size === 0) { + this.context.terminateSelf(); + } + } + + onAccept() { + Log.info('Callback when the second button is clicked'); + this.destruction(); } GetAppName() {