1/** 2 * Copyright (c) 2023 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 CallList from './CallList' 23import callStateConst from '../constant/CallStateConst'; 24import CallUtils from '../utils/CallUtils' 25import DefaultCallData from '../struct/TypeUtils' 26import CallListStruct from '../struct/CallListStruct' 27import CallTimeListStruct from '../struct/CallTimeListStruct' 28 29const TAG = "MultiContactCard"; 30 31@Component 32export default struct MultiContactCard { 33 @State callStateText: string = ''; 34 @State dialing: string = '.'; 35 @Prop isShowKeyboard: boolean; 36 @Link callList: Array<CallListStruct>; 37 @Link callData: DefaultCallData; 38 @Link incomingData: DefaultCallData; 39 @StorageLink("TextInput") textInput: string = ''; 40 @StorageLink("TextInputValue") textInputValue: string = ''; 41 @StorageLink("CallTimeList") callTimeList: Array<CallTimeListStruct> = []; 42 @StorageLink("AccountNumber") accountNumber: string = ''; 43 @StorageLink("IsEmergencyPhoneNumber") isEmergencyPhoneNumber: boolean = false; 44 @StorageLink("hasSimCard1") hasSimCard1: boolean = false; 45 @StorageLink("hasSimCard2") hasSimCard2: boolean = false; 46 @State multiContactName: string = ''; 47 @State multiContactNumber: string = ''; 48 private mUtils: Utils; 49 private timer; 50 private emergency = $r('app.string.emergency'); 51 52 public aboutToAppear(): void { 53 LogUtils.i(TAG, "aboutToAppear"); 54 this.mUtils = Utils.getInstance(); 55 this.timer = setInterval(() => { 56 if (this.dialing === '...') { 57 this.dialing = ''; 58 } 59 this.dialing += '.'; 60 }, 500) 61 if (this.callData.callState === 3) { 62 clearInterval(this.timer) 63 } 64 65 if (this.callData.callState === 4 || this.callData.callState === 5) { 66 CallUtils.hasSimeCard(0); 67 CallUtils.hasSimeCard(1); 68 } 69 } 70 71 private isShowSim() { 72 return (this.callData.callState === CallStateConst.callStateObj.CALL_STATUS_WAITING 73 || this.callData.callState === CallStateConst.callStateObj.CALL_STATUS_INCOMING) && this.hasSimCard1 && this.hasSimCard2; 74 } 75 76 getInComingCallState() { 77 if (this.callList.length > 1) { 78 let incomingState = false; 79 this.callList.forEach((v) => { 80 if (v.callState === CallStateConst.callStateObj.CALL_STATUS_WAITING || v.callState === CallStateConst.callStateObj.CALL_STATUS_INCOMING) { 81 this.incomingData = v; 82 this.multiContactName = v.contactName; 83 this.multiContactNumber = v.accountNumber; 84 incomingState = true; 85 } 86 }); 87 LogUtils.i(TAG, "getInComingCallState incomingState:" + JSON.stringify(incomingState)); 88 return incomingState; 89 } else { 90 return this.callData.callState; 91 } 92 } 93 94 build() { 95 GridRow({ columns: { sm: 4, md: 8, lg: 12 }, gutter: 24 }) { 96 GridCol({ span: { sm: 4, md: 6, lg: 6 }, offset: { md: 1, lg: 3 } }) { 97 Column() { 98 if (!(this.isShowKeyboard && this.textInput.length != 0)) { 99 CallList({ 100 callList: $callList, 101 callData: $callData 102 }) 103 104 if (this.getInComingCallState()) { 105 Column() { 106 if (!this.isShowKeyboard || this.isShowKeyboard && this.textInput.length === 0) { 107 Text(this.isEmergencyPhoneNumber ? this.emergency : this.multiContactName ? this.multiContactName : this.multiContactNumber) 108 .fontSize(30) 109 .height(40) 110 .lineHeight(40) 111 .fontWeight(FontWeight.Medium) 112 .fontColor('#FFFFFF') 113 .margin({ bottom: 8 }) 114 115 Text((this.multiContactName || this.isEmergencyPhoneNumber) ? this.multiContactNumber : '') 116 .fontSize(14) 117 .height(19) 118 .lineHeight(19) 119 .fontColor('#FFFFFF') 120 .opacity(0.60) 121 .visibility((this.multiContactName || this.isEmergencyPhoneNumber) && !this.isShowKeyboard ? Visibility.Visible : Visibility.None) 122 } 123 } 124 .margin({ top: 56 }) 125 126 if (this.isShowSim()) { 127 Image(this.callData.accountId == 1 ? $r("app.media.ic_public_phone_sim2") : $r("app.media.ic_public_phone_sim1")) 128 .margin({ right: 4 }) 129 .width(12) 130 .height(12) 131 .opacity(0.6) 132 } 133 } 134 135 136 } else if (this.isShowKeyboard && this.textInput.length != 0) { 137 Scroll() { 138 Text(this.textInputValue) 139 .height(40) 140 .fontSize(30) 141 .lineHeight(40) 142 .fontWeight(FontWeight.Medium) 143 .margin({ bottom: 8 }) 144 .fontColor('#FFFFFF') 145 .onTouch((event: TouchEvent) => { 146 if (event.type === TouchType.Move) { 147 this.textInputValue = this.textInput 148 } 149 }) 150 } 151 .scrollable(ScrollDirection.Horizontal) 152 .scrollBar(BarState.Off) 153 .width('100%') 154 } 155 } 156 } 157 } 158 .margin({ left: 24, right: 24 }) 159 } 160}