• 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 */
15
16import sim from '@ohos.telephony.sim'
17import Logger from '../model/Logger'
18
19const TAG = '[SimView]'
20const card1 = 0
21const card2 = 1
22
23@Component
24export struct SimView {
25  @State data: string = ''
26  @State sim1Color: string = '#FFFFFF'
27  @State sim2Color: string = '#FFFFFF'
28
29  async getDefaultVoice(num: number) {
30    let color: string
31    try {
32      let result = await sim.getDefaultVoiceSlotId()
33      Logger.info(TAG, `color result is ${result}`)
34      color = result === num ? '#0D9FFB' : '#FFFFFF'
35      Logger.info(TAG, `color is ${JSON.stringify(color)}`)
36    } catch (err) {
37      color = '#FFFFFF'
38      Logger.info(TAG, `err is ${JSON.stringify(err)} color fail is ${JSON.stringify(color)}`)
39    }
40    return color
41  }
42
43  async aboutToAppear() {
44    [this.sim1Color, this.sim2Color] = await Promise.all([this.getDefaultVoice(card1), this.getDefaultVoice(card2)])
45    Logger.info(TAG, `sim1Color is ${this.sim1Color} sim2Color is ${this.sim2Color}`)
46  }
47
48  build() {
49    Column() {
50      Row() {
51        Text($r('app.string.voice'))
52          .fontSize(20)
53          .fontColor(Color.Gray)
54        Blank()
55        Row() {
56          Button() {
57            Text($r('app.string.sim1_id'))
58              .fontSize(18)
59              .fontColor(Color.Black)
60              .textAlign(TextAlign.Center)
61          }
62          .width('50%')
63          .height('85%')
64          .padding(5)
65          .borderRadius(10)
66          .backgroundColor(this.sim1Color)
67
68          Button() {
69            Text($r('app.string.sim2_id'))
70              .fontSize(18)
71              .fontColor(Color.Black)
72              .textAlign(TextAlign.Center)
73          }
74          .width('50%')
75          .height('85%')
76          .padding(5)
77          .borderRadius(10)
78          .backgroundColor(this.sim2Color)
79        }
80        .width('40%')
81        .height('95%')
82        .borderRadius(50)
83        .backgroundColor('#F1F1F1')
84      }
85      .margin(8)
86      .padding(10)
87      .width('95%')
88      .height('8%')
89      .borderRadius(10)
90      .backgroundColor(Color.White)
91    }
92  }
93}