• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 */
15import bluetooth from '@ohos.bluetooth'
16import logger from '../Model/Logger'
17
18const TAG: string = 'PinDialog'
19
20@CustomDialog
21export struct PinDialog {
22  private controller?: CustomDialogController
23  private data: bluetooth.PinRequiredParam | null = null
24  @State titleText: string = ''
25  @State pinCode: string = ''
26
27  @Builder choiceText(message: Resource, handlerClick) {
28    Text(message)
29      .width('50%')
30      .fontSize(30)
31      .textAlign(TextAlign.Center)
32      .fontColor('#ff0742ef')
33      .onClick(handlerClick)
34  }
35
36  aboutToAppear() {
37    this.titleText = `"${this.data.deviceId}"要与您配对。请确认此配对码已在"${this.data.deviceId}"上直接显示,且不是手动输入的。`
38    this.pinCode = JSON.stringify(this.data.pinCode)
39  }
40
41  build() {
42    Column({ space: 10 }) {
43      Text($r('app.string.match_request'))
44        .fontSize(30)
45        .alignSelf(ItemAlign.Start)
46      Text(this.titleText)
47        .alignSelf(ItemAlign.Start)
48        .margin({ top: 20 })
49        .fontSize(21)
50      Text(this.pinCode)
51        .fontSize(40)
52        .fontWeight(FontWeight.Bold)
53        .margin({ top: 20 })
54      Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
55        Checkbox({ name: 'checkbox' })
56          .select(false)
57          .selectedColor('#ff3d6fb8')
58          .key('checkBox')
59        Text($r('app.string.grant_permission'))
60          .fontSize(15)
61          .margin({ left: 3, top: 6 })
62      }
63      .alignSelf(ItemAlign.Start)
64      .width('95%')
65      .margin({ top: 5 })
66
67      Row() {
68        this.choiceText($r('app.string.cancel'), () => {
69          bluetooth.setDevicePairingConfirmation(this.data.deviceId, false)
70          logger.info(TAG, `setDevicePairingConfirmation = ${bluetooth.setDevicePairingConfirmation(this.data.deviceId, false)}`)
71          this.controller.close()
72        })
73
74        Divider()
75          .vertical(true)
76          .height(32)
77
78        this.choiceText($r('app.string.match'), () => {
79          bluetooth.setDevicePairingConfirmation(this.data.deviceId, true)
80          logger.info(TAG, `setDevicePairingConfirmation = ${bluetooth.setDevicePairingConfirmation(this.data.deviceId, true)}`)
81          this.controller.close()
82        })
83      }
84      .margin({ top: 20 })
85    }
86    .width('100%')
87    .padding(15)
88  }
89}