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 16/** 17 * @file: Header information display component 18 */ 19import LogUtils from '../utils/LogUtils'; 20import callStateConst from '../constant/CallStateConst'; 21import Utils from '../utils/utils' 22import CallUtils from '../utils/CallUtils' 23import DefaultCallData from '../struct/TypeUtils' 24import CallListStruct from '../struct/CallListStruct' 25import CallTimeListStruct from '../struct/CallTimeListStruct' 26 27const TAG = 'contactCard'; 28 29@Component 30export default struct ContactCard { 31 @State callStateText: string = ''; 32 @State dialing: string = '.'; 33 @Prop isShowKeyboard: boolean; 34 @Link callList: Array<CallListStruct>; 35 @Link callData: DefaultCallData; 36 @StorageLink('TextInput') textInput: string = ''; 37 @StorageLink('TextInputValue') textInputValue: string = ''; 38 @StorageLink('CallTimeList') callTimeList: Array<CallTimeListStruct> = []; 39 @StorageLink('AccountNumber') accountNumber: string = ''; 40 @StorageLink('IsEmergencyPhoneNumber') isEmergencyPhoneNumber: boolean = false; 41 @StorageLink('hasSimCard1') hasSimCard1: boolean = false; 42 @StorageLink('hasSimCard2') hasSimCard2: boolean = false; 43 private mUtils: Utils; 44 private timer; 45 private emergency = $r('app.string.emergency'); 46 47 public aboutToAppear(): void { 48 LogUtils.i(TAG, 'aboutToAppear'); 49 this.mUtils = Utils.getInstance(); 50 this.timer = setInterval(() => { 51 if (this.dialing === '...') { 52 this.dialing = ''; 53 } 54 this.dialing += '.'; 55 }, 500) 56 if (this.callData.callState === 3) { 57 clearInterval(this.timer) 58 } 59 if (this.callData.callState === 4) { 60 CallUtils.hasSimeCard(0); 61 CallUtils.hasSimeCard(1); 62 } 63 } 64 65 /** 66 * Determine whether to display the call list or the input box 67 * 68 * @return {boolean} - return success true fail false 69 */ 70 private isShowCard() { 71 return this.callList.length === 1 || (this.callList.length > 1 && this.callList.some((v) => 72 v.callState === callStateConst.CALL_STATUS_WAITING)); 73 } 74 75 /** 76 * Call status 77 * 78 * @return {number} - Call status 79 */ 80 public callState() { 81 return this.callData.callState; 82 } 83 84 /** 85 * Whether to display the time 86 * 87 * @return {boolean} - return success true fail false 88 */ 89 private isShowTime() { 90 return this.callState() === callStateConst.CALL_STATUS_ACTIVE && this.callList.length === 1; 91 } 92 93 private isShowSim() { 94 return this.callState() === callStateConst.CALL_STATUS_INCOMING && this.hasSimCard1 && this.hasSimCard2; 95 } 96 97 build() { 98 GridRow({ columns: { sm: 4, md: 8, lg: 12 }, gutter: 24 }) { 99 GridCol({ span: { sm: 4, md: 6, lg: 6 }, offset: { md: 1, lg: 3 } }) { 100 Column() { 101 if (!this.isShowKeyboard) { 102 Image($r('app.media.ic_public_avatar')) 103 .width(110) 104 .height(110) 105 .borderRadius(55) 106 .margin({ bottom: 18 }) 107 } 108 109 if (this.isShowKeyboard && this.textInput.length === 0) { 110 Text(this.callData.contactName ? this.callData.contactName : this.callData.accountNumber) 111 .fontSize(30) 112 .height(40) 113 .lineHeight(40) 114 .fontWeight(FontWeight.Medium) 115 .fontColor('#FFFFFF') 116 .margin({ bottom: 8 }) 117 .maxLines(1) 118 .textOverflow({ overflow: TextOverflow.Ellipsis }) 119 } else if (!this.isShowKeyboard) { 120 Text(this.isEmergencyPhoneNumber ? this.emergency : this.callData.contactName ? 121 this.callData.contactName : this.callData.accountNumber) 122 .fontSize(30) 123 .height(40) 124 .lineHeight(40) 125 .fontWeight(FontWeight.Medium) 126 .fontColor('#FFFFFF') 127 .margin({ bottom: 8 }) 128 .maxLines(1) 129 .textOverflow({ overflow: TextOverflow.Ellipsis }) 130 } else if (this.isShowKeyboard && this.textInput.length != 0) { 131 Scroll() { 132 Text(this.textInputValue) 133 .height(40) 134 .fontSize(30) 135 .lineHeight(40) 136 .fontWeight(FontWeight.Medium) 137 .margin({ bottom: 8 }) 138 .fontColor('#FFFFFF') 139 .onTouch((event: TouchEvent) => { 140 if (event.type === TouchType.Move) { 141 this.textInputValue = this.textInput 142 } 143 }) 144 } 145 .scrollable(ScrollDirection.Horizontal) 146 .scrollBar(BarState.Off) 147 .width('100%') 148 } 149 150 Row() { 151 if (!this.isShowKeyboard || this.isShowKeyboard && this.textInput.length === 0) { 152 Text((this.callData.contactName || this.isEmergencyPhoneNumber) ? this.callData.accountNumber : '') 153 .fontSize(14) 154 .height(19) 155 .lineHeight(16) 156 .fontColor('#FFFFFF') 157 .margin({ bottom: 8 }) 158 .visibility((this.callData.contactName || this.isEmergencyPhoneNumber) && !this.isShowKeyboard ? 159 Visibility.Visible : Visibility.None) 160 } 161 } 162 163 if (this.callData.callState === 1) { 164 Row() { 165 Text($r('app.string.callHold')) 166 .fontSize(14) 167 .height(19) 168 .lineHeight(19) 169 .fontColor('#FFFFFF') 170 .fontWeight(FontWeight.Medium) 171 } 172 } 173 174 if (this.callData.callState === 2) { 175 Row() { 176 Text($r('app.string.dialing')) 177 .fontSize(14) 178 .height(19) 179 .lineHeight(16) 180 .fontColor('#FFFFFF') 181 .align(Alignment.Start) 182 183 Text(this.dialing) 184 .fontColor('#FFFFFF') 185 } 186 .width(60) 187 } 188 189 if (this.callData.callState === 3) { 190 Text($r('app.string.partyIsRinging')) 191 .fontSize(14) 192 .height(19) 193 .lineHeight(16) 194 .fontColor('#FFFFFF') 195 } 196 197 if (this.isShowSim()) { 198 Image(this.callData.accountId == 1 ? $r('app.media.ic_public_phone_sim2') : 199 $r('app.media.ic_public_phone_sim1')) 200 .margin({ right: 4 }) 201 .width(12) 202 .height(12) 203 .opacity(0.6) 204 } 205 206 if (this.isShowTime()) { 207 Row() { 208 if (this.callData.callType === 1) { 209 Image($r('app.media.ic_public_phone_HD')) 210 .margin({ right: 4 }) 211 .width(12) 212 .height(12) 213 .opacity(0.6) 214 } 215 216 Text(this.callTimeList[0]?.callTime) 217 .fontSize(14) 218 .height(19) 219 .lineHeight(19) 220 .fontColor('#FFFFFF') 221 } 222 } 223 } 224 } 225 } 226 .margin({ left: 24, right: 24 }) 227 } 228}