1/* 2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 17import commonEventManager from '@ohos.commonEventManager'; 18 19let TAG = '[Location-Privacy]==>'; 20const LOCATION_PRIVACY_ACCEPT_EVENT: string = 'usual.event.LOCATION_PRIVACY_ACCEPT'; 21const LOCATION_PRIVACY_REJECT_EVENT: string = 'usual.event.LOCATION_PRIVACY_REJECT'; 22 23@Entry 24@Component 25struct dialogPlusPage { 26 @State title: string = ''; 27 @State message: string = ''; 28 29 aboutToAppear() { 30 console.info(TAG, 'aboutToAppear execute LocationPrivacyDialog') 31 AlertDialog.show( 32 { 33 title: $r('app.string.location_target_statement_title'), 34 message: $r('app.string.location_target_statement_content'), 35 autoCancel: false, 36 primaryButton: { 37 value: $r('app.string.cancel_button'), 38 action: () => { 39 this.onCancel(); 40 } 41 }, 42 secondaryButton: { 43 enabled: true, 44 defaultFocus: true, 45 style: DialogButtonStyle.HIGHLIGHT, 46 value: $r('app.string.confirm_button'), 47 action: () => { 48 this.onAccept(); 49 } 50 }, 51 } 52 ) 53 } 54 55 aboutToDisappear() { 56 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 57 if (session) { 58 session.terminateSelf(); 59 } 60 } 61 62 onCancel() { 63 console.info(TAG, 'Callback when the first button is clicked') 64 65 const options: commonEventManager.CommonEventPublishData = { 66 code: 0, 67 data: 'message', 68 isSticky: false, 69 parameters: { 'message': 'reject' } 70 } 71 72 commonEventManager.publish(LOCATION_PRIVACY_REJECT_EVENT, options, (err) => { 73 if (err) { 74 console.info(TAG, '[CommonEvent] PublishCallBack err=' + JSON.stringify(err)); 75 } else { 76 console.info(TAG, '[CommonEvent] Publish success') 77 } 78 }) 79 80 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 81 if (session) { 82 session.terminateSelf(); 83 } 84 } 85 86 onAccept() { 87 console.info(TAG, 'Callback when the second button is clicked') 88 89 const options: commonEventManager.CommonEventPublishData = { 90 code: 0, 91 data: 'message', 92 isSticky: false, 93 parameters: { 'message': 'accept' } 94 } 95 96 commonEventManager.publish(LOCATION_PRIVACY_ACCEPT_EVENT, options, (err) => { 97 if (err) { 98 console.info(TAG, '[CommonEvent] PublishCallBack err=' + JSON.stringify(err)); 99 } else { 100 console.info(TAG, '[CommonEvent] Publish success') 101 } 102 }) 103 104 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 105 if (session) { 106 session.terminateSelf(); 107 } 108 } 109 110 existApp() { 111 console.info(TAG, 'Click the callback in the blank area') 112 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 113 if (session) { 114 session.terminateSelf(); 115 } 116 } 117 118 build() { 119 } 120}