1/* 2 * Copyright (c) 2024-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'; 18import common from '@ohos.app.ability.common'; 19import deviceInfo from '@ohos.deviceInfo'; 20 21let TAG = '[AGNSS-NI:ConfirmDialog]==>'; 22const AGNSS_NI_ACCEPT_EVENT: string = 'usual.event.AGNSS_NI_ACCEPT'; 23const AGNSS_NI_REJECT_EVENT: string = 'usual.event.AGNSS_NI_REJECT'; 24const DEVICE_TYPE_WEARABLE = 'wearable'; 25 26@Entry 27@Component 28struct dialogPlusPage { 29 @State title: string = ''; 30 @State message: string = ''; 31 private context = getContext(this) as common.UIAbilityContext; 32 33 aboutToAppear() { 34 console.info(TAG, 'aboutToAppear') 35 console.info(TAG, 'aboutToAppear execute ConfirmCustomDialog') 36 if (AppStorage.get('title') != null) { // SA侧传过来的参数 37 this.title = AppStorage.get('title') as string 38 console.log('title is ' + this.title) 39 } 40 if (AppStorage.get('message') != null) { // SA侧传过来的参数 41 this.message = AppStorage.get('message') as string 42 console.log('message is ' + this.message) 43 } 44 if (this.message == '') { 45 this.message = 'SUPL Service' 46 } 47 if (deviceInfo.deviceType != DEVICE_TYPE_WEARABLE) { 48 AlertDialog.show( 49 { 50 title: $r('app.string.ni_notify_title'), 51 message: this.message, 52 textStyle: { wordBreak: WordBreak.NORMAL }, 53 autoCancel: false, 54 primaryButton: { 55 value: $r('app.string.cancel_button'), 56 action: () => { 57 this.onCancel(); 58 } 59 }, 60 secondaryButton: { 61 enabled: true, 62 defaultFocus: true, 63 style: DialogButtonStyle.HIGHLIGHT, 64 value: $r('app.string.confirm_button'), 65 action: () => { 66 this.onAccept(); 67 } 68 }, 69 } 70 ) 71 } 72 } 73 74 aboutToDisappear() { 75 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 76 if (session) { 77 session.terminateSelf(); 78 } 79 } 80 81 onCancel() { 82 console.info(TAG, 'Callback when the first button is clicked') 83 84 const options: commonEventManager.CommonEventPublishData = { 85 code: 0, 86 data: 'message', 87 isSticky: false, 88 parameters: { 'message': 'agnss-ni-reject' } 89 } 90 91 commonEventManager.publish(AGNSS_NI_REJECT_EVENT, options, (err) => { 92 if (err) { 93 console.info('[AGNSS-NI:ConfirmDialog]==>', '[CommonEvent] PublishCallBack err=' + JSON.stringify(err)); 94 } else { 95 console.info('[AGNSS-NI:ConfirmDialog]==>', '[CommonEvent] Publish success') 96 } 97 }) 98 99 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 100 if (session) { 101 session.terminateSelf(); 102 } 103 } 104 105 onAccept() { 106 console.info(TAG, 'Callback when the second button is clicked') 107 108 const options: commonEventManager.CommonEventPublishData = { 109 code: 0, 110 data: 'message', 111 isSticky: false, 112 parameters: { 'message': 'agnss-ni-accept' } 113 } 114 115 commonEventManager.publish(AGNSS_NI_ACCEPT_EVENT, options, (err) => { 116 if (err) { 117 console.info('[AGNSS-NI:ConfirmDialog]==>', '[CommonEvent] PublishCallBack err=' + JSON.stringify(err)); 118 } else { 119 console.info('[AGNSS-NI:ConfirmDialog]==>', '[CommonEvent] Publish success') 120 } 121 }) 122 123 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 124 if (session) { 125 session.terminateSelf(); 126 } 127 } 128 129 existApp() { 130 console.info(TAG, 'Click the callback in the blank area') 131 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 132 if (session) { 133 session.terminateSelf(); 134 } 135 } 136 137 build() { 138 if (deviceInfo.deviceType == DEVICE_TYPE_WEARABLE) { 139 Scroll() { 140 Column() { 141 Text($r('app.string.ni_notify_title')) 142 .fontSize(18) 143 .fontColor(Color.White) 144 .width(181) 145 .margin({ top: 20, left: 26, right: 26 }) 146 .textAlign(TextAlign.Center); 147 148 Text(this.message) 149 .fontSize(16) 150 .fontColor(Color.White) 151 .width(181) 152 .margin({ top: 20, left: 26, right: 26 }) 153 .textAlign(TextAlign.Center); 154 155 Button($r('app.string.confirm_button')) 156 .margin({ top: 16 }) 157 .width(116) 158 .height(40) 159 .borderRadius(20) 160 .onClick(() => { 161 this.onAccept(); 162 this.context.terminateSelf(); 163 }) 164 165 Button($r('app.string.cancel_button')) 166 .margin({ top: 12, bottom: 40 }) 167 .width(116) 168 .height(40) 169 .backgroundColor(Color.Grey) 170 .borderRadius(20) 171 .onClick(() => { 172 this.onCancel(); 173 this.context.terminateSelf(); 174 }) 175 } 176 .backgroundColor(Color.Black) 177 .width('100%') 178 .alignItems(HorizontalAlign.Center); 179 } 180 .scrollable(ScrollDirection.Vertical) 181 .scrollBar(BarState.Auto) 182 .scrollBarColor(Color.White); 183 } 184 } 185}