/* * Copyright (c) 2022-2023 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 deviceManager from '@ohos.distributedHardware.deviceManager'; import Context from '@ohos.app.ability.common'; import Want from '@ohos.app.ability.Want'; import window from '@ohos.window'; let dmClass: deviceManager.DeviceManager | null; let TAG = '[DeviceManagerUI:PinDialog]==>' const ACTION_CANCEL_PINCODE_DISPLAY: number = 3 const MSG_CANCEL_PIN_CODE_SHOW: number = 2 @Entry @Component struct dialogPlusPage { @State messageTitle: string = 'PIN码连接' @State messageTips: string = '请在设备端输入连接码进行验证' @State pinCode: string = '' @State allow: string = '允许' @State cancel: string = '取消' @State isShow: boolean = true aboutToAppear() { this.initStatue() console.log('aboutToAppear execute') let globalWant: Want = AppStorage.get('abilityWant') as Want if (globalWant != null && globalWant.parameters != undefined) { this.pinCode = globalWant.parameters['PinCode'] as string } } aboutToDisappear() { console.log(TAG + 'aboutToDisappear executed') if (dmClass != null) { try { dmClass.off('uiStateChange') dmClass.release() } catch (error) { console.log('dmClass release failed') } dmClass = null } } initStatue() { let globalWindowNum: number = AppStorage.get('pinWindowNum') as number console.log('initStatue' + 'pinWindowNum:' + globalWindowNum) if (dmClass) { console.log('deviceManager exist') return } deviceManager.createDeviceManager('com.ohos.devicemanagerui.pin', (err: Error, dm: deviceManager.DeviceManager) => { if (err) { console.log('createDeviceManager err:' + JSON.stringify(err) + ' --fail:' + JSON.stringify(dm)) return } dmClass = dm dmClass.on('uiStateChange', (data: Record) => { console.log('uiStateChange executed, dialog closed' + JSON.stringify(data)) let tmpStr: Record = JSON.parse(data.param) let msg: number = tmpStr.uiStateMsg as number if (msg === MSG_CANCEL_PIN_CODE_SHOW) { this.destruction() } }) }); } setUserOperation(operation: number) { console.log('setUserOperation: ' + operation) if(dmClass == null) { console.log('setUserOperation: ' + 'dmClass null') return; } try { dmClass.setUserOperation(operation, 'extra') } catch (error) { console.log('dmClass setUserOperation failed') } } destruction() { let temporaryWindow: window.Window = AppStorage.get('pinWin') as window.Window temporaryWindow.destroy() let context: Context.UIAbilityContext = AppStorage.get('pinContext') as Context.UIAbilityContext context.terminateSelf() } build() { Row() { Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Column() { Text(this.messageTitle) .fontSize(35) .fontWeight(FontWeight.Bold) Text(this.messageTips) .fontSize(30) .fontWeight(FontWeight.Medium) Row() {}.height('2%') Text(this.pinCode) .fontSize(30) .fontWeight(FontWeight.Bold) Row() {}.height('2%') Button(this.cancel) .fontSize(25) .fontColor(0xffffff) .border({ width: 1.5, color: (0xe7e7e7), radius: 50 }) .fontWeight(FontWeight.Normal) .onClick(() => { this.setUserOperation(ACTION_CANCEL_PINCODE_DISPLAY) this.destruction() }) }.width('100%') }.width('100%') .height('100%') }.width('100%') } }