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 CallServiceProxy from "../../model/CallServiceProxy"; 17import LogUtils from '../utils/LogUtils'; 18import DefaultCallData from '../struct/TypeUtils'; 19 20const TAG = "DtmfBtn"; 21class DataListStruct { 22 value: string 23 sign: string 24} 25 26@Component 27export default struct DtmfBtn { 28 @State color: string = "rgba(255, 255, 255, 0)"; 29 @State subStr:string = ''; 30 @Link dataList: Array<DataListStruct>; 31 @Link textInput: string; 32 @Link textInputValue: string; 33 private item: DataListStruct; 34 private mCallServiceProxy; 35 callData: DefaultCallData; 36 37 public aboutToAppear(): void { 38 this.mCallServiceProxy = new CallServiceProxy(); 39 } 40 41 /** 42 * Call and press the DTMF interface 43 * 44 * @param {Object} obj - Object 45 */ 46 onBtnTouchStart(obj) { 47 this.mCallServiceProxy.startDTMF(this.callData.callId, String(obj.value)); 48 LogUtils.i(TAG, "onBtnTouchStart :"); 49 } 50 51 /** 52 * Call release and send DTMF interface 53 * 54 * @param {Object} obj - Incoming value 55 */ 56 onBtnTouchEnd() { 57 this.mCallServiceProxy.stopDTMF(this.callData.callId); 58 LogUtils.i(TAG, "onBtnTouchEnd :"); 59 } 60 61 build() { 62 Row() { 63 Column() { 64 if (this.item.value == '*') { 65 Image($r("app.media.ic_star")) 66 .width(24) 67 .height(30) 68 .margin({ bottom:10 }) 69 .padding({ top: 8 }) 70 } else if (this.item.value == '#') { 71 Image($r("app.media.ic_pound")) 72 .width(24) 73 .height(30) 74 .margin({ bottom:10 }) 75 .padding({ top: 8 }) 76 } else { 77 Text(this.item.value) 78 .fontSize(30) 79 .height(40) 80 .lineHeight(40) 81 .fontWeight(FontWeight.Medium) 82 .fontColor('#FFFFFF') 83 .margin(0.5) 84 } 85 86 if (this.item.sign == '+') { 87 Text(this.item.sign) 88 .fontSize(20) 89 .height(24) 90 .lineHeight(16) 91 .opacity(0.6) 92 .fontWeight(FontWeight.Regular) 93 .fontColor('#FFFFFF') 94 } else { 95 Text(this.item.sign) 96 .fontSize(12) 97 .height(16) 98 .lineHeight(16) 99 .opacity(0.6) 100 .fontWeight(FontWeight.Regular) 101 .fontColor('#FFFFFF') 102 } 103 } 104 .width(56.5) 105 .height(56.5) 106 .backgroundColor(this.color) 107 .borderRadius(28.25) 108 .onTouch((event: TouchEvent) => { 109 if (event.type === TouchType.Down) { 110 this.color = "rgba(255, 255, 255, 0.4)" 111 this.textInput = this.textInput + this.item.value 112 if (this.textInput.length > 19) { 113 this.subStr = this.textInput.substr(this.textInput.length - 19, this.textInput.length - 1) 114 this.textInputValue = this.subStr 115 } else { 116 this.textInputValue = this.textInput 117 } 118 AppStorage.SetOrCreate("TextInputValue", this.textInputValue) 119 AppStorage.SetOrCreate("TextInput", this.textInput) 120 LogUtils.i(TAG, "textInputValue + TextInput : %s" + JSON.stringify(AppStorage.Get("TextInputValue")) + JSON.stringify(AppStorage.Get("TextInput"))); 121 this.onBtnTouchStart(this.item) 122 } 123 if (event.type === TouchType.Up) { 124 this.color = "rgba(255, 255, 255, 0)"; 125 this.onBtnTouchEnd() 126 } 127 }) 128 } 129 } 130} 131