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 ? this.callData.contactName : this.callData.accountNumber) 121 .fontSize(30) 122 .height(40) 123 .lineHeight(40) 124 .fontWeight(FontWeight.Medium) 125 .fontColor('#FFFFFF') 126 .margin({ bottom: 8 }) 127 .maxLines(1) 128 .textOverflow({ overflow: TextOverflow.Ellipsis }) 129 } else if (this.isShowKeyboard && this.textInput.length != 0) { 130 Scroll() { 131 Text(this.textInputValue) 132 .height(40) 133 .fontSize(30) 134 .lineHeight(40) 135 .fontWeight(FontWeight.Medium) 136 .margin({ bottom: 8 }) 137 .fontColor('#FFFFFF') 138 .onTouch((event: TouchEvent) => { 139 if (event.type === TouchType.Move) { 140 this.textInputValue = this.textInput 141 } 142 }) 143 } 144 .scrollable(ScrollDirection.Horizontal) 145 .scrollBar(BarState.Off) 146 .width('100%') 147 } 148 149 Row() { 150 if (!this.isShowKeyboard || this.isShowKeyboard && this.textInput.length === 0) { 151 Text((this.callData.contactName || this.isEmergencyPhoneNumber) ? this.callData.accountNumber : '') 152 .fontSize(14) 153 .height(19) 154 .lineHeight(16) 155 .fontColor('#FFFFFF') 156 .margin({ bottom: 8 }) 157 .visibility((this.callData.contactName || this.isEmergencyPhoneNumber) && !this.isShowKeyboard ? Visibility.Visible : Visibility.None) 158 } 159 } 160 161 if (this.callData.callState === 1) { 162 Row() { 163 Text($r("app.string.callHold")) 164 .fontSize(14) 165 .height(19) 166 .lineHeight(19) 167 .fontColor('#FFFFFF') 168 .fontWeight(FontWeight.Medium) 169 } 170 } 171 172 if (this.callData.callState === 2) { 173 Row() { 174 Text($r("app.string.dialing")) 175 .fontSize(14) 176 .height(19) 177 .lineHeight(16) 178 .fontColor('#FFFFFF') 179 .align(Alignment.Start) 180 181 Text(this.dialing) 182 .fontColor('#FFFFFF') 183 } 184 .width(60) 185 } 186 187 if (this.callData.callState === 3) { 188 Text($r("app.string.partyIsRinging")) 189 .fontSize(14) 190 .height(19) 191 .lineHeight(16) 192 .fontColor('#FFFFFF') 193 } 194 195 if (this.isShowSim()) { 196 Image(this.callData.accountId == 1 ? $r("app.media.ic_public_phone_sim2") : $r("app.media.ic_public_phone_sim1")) 197 .margin({ right: 4 }) 198 .width(12) 199 .height(12) 200 .opacity(0.6) 201 } 202 203 if (this.isShowTime()) { 204 Row() { 205 if (this.callData.callType === 1) { 206 Image($r("app.media.ic_public_phone_HD")) 207 .margin({ right: 4 }) 208 .width(12) 209 .height(12) 210 .opacity(0.6) 211 } 212 213 Text(this.callTimeList[0]?.callTime) 214 .fontSize(14) 215 .height(19) 216 .lineHeight(19) 217 .fontColor('#FFFFFF') 218 } 219 } 220 } 221 } 222 } 223 .margin({ left: 24, right: 24 }) 224 } 225}