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