mirror of
https://gitee.com/openharmony/applications_screenshot
synced 2024-11-26 16:50:22 +00:00
add privacy dialog
Signed-off-by: 李一鸣 <liyiming21@huawei.com>
This commit is contained in:
parent
ef9042501e
commit
a47892f203
@ -4,9 +4,9 @@
|
|||||||
{
|
{
|
||||||
"name": "default",
|
"name": "default",
|
||||||
"signingConfig": "release",
|
"signingConfig": "release",
|
||||||
"compileSdkVersion": 11,
|
"compileSdkVersion": 12,
|
||||||
"compatibleSdkVersion": 11,
|
"compatibleSdkVersion": 12,
|
||||||
"targetSdkVersion": 11,
|
"targetSdkVersion": 12,
|
||||||
"runtimeOS": "OpenHarmony",
|
"runtimeOS": "OpenHarmony",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
64
product/phone/src/main/ets/PrivacyDialog/DialogAbility.ets
Normal file
64
product/phone/src/main/ets/PrivacyDialog/DialogAbility.ets
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
|
||||||
|
import media from '@ohos.multimedia.media';
|
||||||
|
import Log from '../../../../../../common/src/main/ets/default/Log';
|
||||||
|
import Want from '@ohos.app.ability.Want';
|
||||||
|
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||||
|
import { BusinessError } from '@ohos.base';
|
||||||
|
|
||||||
|
const TAG = 'AVScreenCapture-DiaLogUIExtensionAbility';
|
||||||
|
|
||||||
|
export default class DialogAbility extends UIExtensionAbility {
|
||||||
|
onCreate(): void {
|
||||||
|
Log.showInfo(TAG, 'DialogAbility onCreate');
|
||||||
|
globalThis.sessionId = -1;
|
||||||
|
globalThis.userChoice = 'false';
|
||||||
|
}
|
||||||
|
|
||||||
|
onForeground(): void {
|
||||||
|
Log.showInfo(TAG, 'DialogAbility onForeground');
|
||||||
|
}
|
||||||
|
|
||||||
|
onBackground(): void {
|
||||||
|
Log.showInfo(TAG, 'DialogAbility onBackground');
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy(): void {
|
||||||
|
Log.showInfo(TAG, `Report user choice sessionId(${globalThis.sessionId}), userChoice(${globalThis.userChoice})`);
|
||||||
|
media.reportAVScreenCaptureUserChoice(Number(globalThis.sessionId), globalThis.userChoice);
|
||||||
|
}
|
||||||
|
|
||||||
|
onSessionCreate(want: Want, session: UIExtensionContentSession): void {
|
||||||
|
globalThis.dialogContext = this.context;
|
||||||
|
globalThis.dialogWant = want;
|
||||||
|
globalThis.dialogSession = session;
|
||||||
|
globalThis.sessionId = want.parameters?.sessionId as number;
|
||||||
|
let param: Record<string, UIExtensionContentSession> = {
|
||||||
|
'session': session
|
||||||
|
}
|
||||||
|
let storage: LocalStorage = new LocalStorage(param);
|
||||||
|
try {
|
||||||
|
session.loadContent('PrivacyDialog/DialogPage', storage);
|
||||||
|
} catch (err) {
|
||||||
|
Log.showError(TAG, 'session loadContent error: ' + (err as BusinessError).message);
|
||||||
|
}
|
||||||
|
session.setWindowBackgroundColor('#00ffffff');
|
||||||
|
}
|
||||||
|
|
||||||
|
onSessionDestroy(session: UIExtensionContentSession): void {
|
||||||
|
Log.showInfo(TAG, 'UIExtAbility onSessionDestroy');
|
||||||
|
}
|
||||||
|
}
|
185
product/phone/src/main/ets/PrivacyDialog/DialogPage.ets
Normal file
185
product/phone/src/main/ets/PrivacyDialog/DialogPage.ets
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
import Log from '../../../../../../common/src/main/ets/default/Log';
|
||||||
|
import Want from '@ohos.app.ability.Want';
|
||||||
|
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||||
|
import measure from '@ohos.measure';
|
||||||
|
import display from '@ohos.display'
|
||||||
|
|
||||||
|
const TAG = 'AVScreenCapture-DiaLogPage';
|
||||||
|
|
||||||
|
@CustomDialog
|
||||||
|
struct PrivacyWindowDialog {
|
||||||
|
cancel?: () => void;
|
||||||
|
confirm?: () => void;
|
||||||
|
controller: CustomDialogController;
|
||||||
|
appLabel: string = '';
|
||||||
|
overflow: boolean = false;
|
||||||
|
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
if (this.overflow) {
|
||||||
|
Row() {
|
||||||
|
Text($r('app.string.avscreencapture_privacy_window_title'))
|
||||||
|
.fontWeight(FontWeight.Bold)
|
||||||
|
.textAlign(TextAlign.Start)
|
||||||
|
.width('100%')
|
||||||
|
.textOverflow({ overflow: TextOverflow.Ellipsis})
|
||||||
|
.maxLines(2)
|
||||||
|
.fontSize(16)
|
||||||
|
}
|
||||||
|
.alignItems(VerticalAlign.Center)
|
||||||
|
.padding({ top: 16, bottom: 16 })
|
||||||
|
.margin({ left: 24, right: 24})
|
||||||
|
} else {
|
||||||
|
Row() {
|
||||||
|
Text($r('app.string.avscreencapture_privacy_window_title'))
|
||||||
|
.fontWeight(FontWeight.Bold)
|
||||||
|
.textAlign(TextAlign.Start)
|
||||||
|
.width('100%')
|
||||||
|
.fontSize($r('sys.float.ohos_id_text_size_headline8'))
|
||||||
|
}
|
||||||
|
.alignItems(VerticalAlign.Center)
|
||||||
|
.margin({ left: 24, right: 24 })
|
||||||
|
.height(56)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column() {
|
||||||
|
Text($r('app.string.avscreencapture_privacy_window_content', this.appLabel))
|
||||||
|
.fontSize($r('sys.float.ohos_id_text_size_body1'))
|
||||||
|
.fontColor($r('sys.color.ohos_id_color_text_primary'))
|
||||||
|
.width('100%')
|
||||||
|
}
|
||||||
|
.margin({ left: 24, right: 24 })
|
||||||
|
|
||||||
|
Flex({ justifyContent: FlexAlign.SpaceAround}) {
|
||||||
|
Column() {
|
||||||
|
Button($r('app.string.avscreencapture_privacy_window_cancel'), { type: ButtonType.Capsule })
|
||||||
|
.onClick(() => {
|
||||||
|
this.controller.close();
|
||||||
|
if (this.cancel) {
|
||||||
|
this.cancel();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.backgroundColor(Color.Transparent)
|
||||||
|
.fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
|
||||||
|
.fontSize($r('sys.float.ohos_id_text_size_button1'))
|
||||||
|
.width('100%')
|
||||||
|
.height('100%')
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
|
||||||
|
Column() {
|
||||||
|
Column()
|
||||||
|
.backgroundColor($r('sys.color.ohos_id_color_list_separator'))
|
||||||
|
.height(24)
|
||||||
|
.width(1)
|
||||||
|
}
|
||||||
|
.margin({ left: 2, right: 2, top: 8 })
|
||||||
|
.justifyContent(FlexAlign.Center)
|
||||||
|
|
||||||
|
Column() {
|
||||||
|
Button($r('app.string.avscreencapture_privacy_window_agree'), { type: ButtonType.Capsule })
|
||||||
|
.onClick(() => {
|
||||||
|
this.controller.close();
|
||||||
|
if (this.confirm) {
|
||||||
|
this.confirm();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.backgroundColor(Color.Transparent)
|
||||||
|
.fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
|
||||||
|
.fontSize($r('sys.float.ohos_id_text_size_button1'))
|
||||||
|
.width('100%')
|
||||||
|
.height('100%')
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
}
|
||||||
|
.height(40)
|
||||||
|
.margin({ top: 8, bottom: 16, left: 16, right: 16 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const MARGIN_DISTANCE = 24;
|
||||||
|
const BORDER_DISTANCE = 16;
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
export struct DialogPage {
|
||||||
|
private want = globalThis.dialogWant as Want;
|
||||||
|
private session = globalThis.dialogSession as UIExtensionContentSession;
|
||||||
|
private appLabel: string = '';
|
||||||
|
private overflow: boolean = false;
|
||||||
|
|
||||||
|
dialogController: CustomDialogController = new CustomDialogController({
|
||||||
|
builder: PrivacyWindowDialog({
|
||||||
|
cancel: () => { this.onCancel() },
|
||||||
|
confirm: () => { this.onConfirm() },
|
||||||
|
appLabel: this.appLabel,
|
||||||
|
overflow: this.overflow
|
||||||
|
}),
|
||||||
|
alignment: DialogAlignment.Center,
|
||||||
|
autoCancel: false,
|
||||||
|
backgroundColor: Color.White
|
||||||
|
})
|
||||||
|
|
||||||
|
getTextLength(text: Resource, fontSize: Resource): void {
|
||||||
|
let textLength: number = measure.measureText({
|
||||||
|
textContent: text,
|
||||||
|
fontSize: fontSize
|
||||||
|
});
|
||||||
|
let windowWidth = display.getDefaultDisplaySync().width;
|
||||||
|
let textMaxLength = px2vp(windowWidth) - BORDER_DISTANCE - MARGIN_DISTANCE;
|
||||||
|
if (px2vp(textLength) > textMaxLength) {
|
||||||
|
Log.showInfo(TAG, 'title overflow, need change line');
|
||||||
|
this.overflow = true;
|
||||||
|
} else {
|
||||||
|
this.overflow = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async onCancel(): Promise<void> {
|
||||||
|
Log.showInfo(TAG, 'Cancel is clicked');
|
||||||
|
globalThis.userChoice = 'false';
|
||||||
|
await this.session.terminateSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
async onConfirm(): Promise<void> {
|
||||||
|
Log.showInfo(TAG, 'Agree is clicked');
|
||||||
|
globalThis.userChoice = 'true';
|
||||||
|
await this.session.terminateSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
async onPageShow(): Promise<void> {
|
||||||
|
this.getTextLength($r('app.string.avscreencapture_privacy_window_title'),
|
||||||
|
$r('sys.float.ohos_id_text_size_headline8'));
|
||||||
|
this.getAppName();
|
||||||
|
Log.showInfo(TAG, 'onPageShow');
|
||||||
|
this.dialogController.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
onPageHide(): void {
|
||||||
|
Log.showInfo(TAG, 'onPageHide')
|
||||||
|
}
|
||||||
|
|
||||||
|
getAppName(): void {
|
||||||
|
if (this.want.parameters?.callingLabel) {
|
||||||
|
this.appLabel = (this.want.parameters?.appLabel).toString();
|
||||||
|
Log.showInfo(TAG, `appLabel: ${this.appLabel}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build(){}
|
||||||
|
}
|
@ -39,6 +39,12 @@
|
|||||||
"resource": "$profile:main_pages"
|
"resource": "$profile:main_pages"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "com.ohos.screenshot.DialogAbility",
|
||||||
|
"srcEntry": "./ets/PrivacyDialog/DialogAbility.ets",
|
||||||
|
"visible": true,
|
||||||
|
"type": "sys/commonUI"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"requestPermissions": [
|
"requestPermissions": [
|
||||||
|
@ -23,6 +23,22 @@
|
|||||||
{
|
{
|
||||||
"name": "write_media_reason",
|
"name": "write_media_reason",
|
||||||
"value": "Screenshot apps need to write media files"
|
"value": "Screenshot apps need to write media files"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_title",
|
||||||
|
"value": "Privacy notice"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_content",
|
||||||
|
"value": "%s will be able to record or project everything that's shown on your screen, as well as system sounds. Be sure to safeguard sensitive personal information such as passwords, payment information, photos, videos, and conversations."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_cancel",
|
||||||
|
"value": "Cancel"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_agree",
|
||||||
|
"value": "Agree"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"src": [
|
"src": [
|
||||||
"pages/index"
|
"pages/index",
|
||||||
|
"PrivacyDialog/DialogPage"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,22 @@
|
|||||||
{
|
{
|
||||||
"name": "write_media_reason",
|
"name": "write_media_reason",
|
||||||
"value": "Screenshot apps need to write media files"
|
"value": "Screenshot apps need to write media files"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_title",
|
||||||
|
"value": "Privacy notice"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_content",
|
||||||
|
"value": "%s will be able to record or project everything that's shown on your screen, as well as system sounds. Be sure to safeguard sensitive personal information such as passwords, payment information, photos, videos, and conversations."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_cancel",
|
||||||
|
"value": "Cancel"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_agree",
|
||||||
|
"value": "Agree"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -27,6 +27,22 @@
|
|||||||
{
|
{
|
||||||
"name": "write_media_reason",
|
"name": "write_media_reason",
|
||||||
"value": "Screenshot apps need to write media files"
|
"value": "Screenshot apps need to write media files"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_title",
|
||||||
|
"value": "录屏投屏管理"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_content",
|
||||||
|
"value": "\"%s\"将录制/投射您屏幕上显示的内容和系统声音。请注意保护个人敏感信息,如密码、付款信息、照片、录像、聊天记录等。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_cancel",
|
||||||
|
"value": "取消"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "avscreencapture_privacy_window_agree",
|
||||||
|
"value": "确定"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user