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