• 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 CallRecord from '../../dialer/callRecord/CallRecord';
17import { HiLog } from '../../../../../../../common/src/main/ets/util/HiLog';
18import DialerPresenter from './../../../presenter/dialer/DialerPresenter';
19import { DialerButtonView } from '../../../component/dialer/DialerButtonView';
20import { PhoneNumber } from '../../../../../../../feature/phonenumber/src/main/ets/PhoneNumber';
21
22const TAG = 'Dialer';
23
24@Component
25struct DialButton {
26  @State button_number: string = ''
27  @State button_char: string = ''
28  @Link mPresenter: DialerPresenter
29
30  build() {
31    Column() {
32      Column() {
33        Button() {
34          Column() {
35            if (`${this.button_number}` == '*') {
36              Image($r('app.media.symbol_phone'))
37                .width(24)
38                .height(24)
39            } else if (`${this.button_number}` == '#') {
40              Image($r('app.media.symbols_phone'))
41                .width(24)
42                .height(24)
43            } else {
44              Text(`${this.button_number}`)
45                .fontSize(25)
46                .fontColor($r('sys.color.ohos_id_color_text_primary'))
47                .fontWeight(FontWeight.Medium)
48            }
49            if ((this.button_char == 'ic')) {
50              Image($r('app.media.ic_contacts_voicemail_mini'))
51                .width(14)
52                .height(14)
53            } else if ((this.button_char == '+')) {
54              Text(`${this.button_char}`)
55                .fontColor($r('sys.color.ohos_id_color_text_secondary'))
56                .fontSize(17.5)
57            } else {
58              Text(`${this.button_char}`)
59                .fontColor($r('sys.color.ohos_id_color_text_secondary'))
60                .fontSize($r('sys.float.ohos_id_text_size_chart1'))
61            }
62          }
63        }
64        .backgroundColor($r('sys.color.ohos_id_color_panel_bg'))
65        .type(ButtonType.Circle)
66        .height('100%')
67        .width('100%')
68      }
69      .justifyContent(FlexAlign.Center)
70      .width('100%')
71      .onTouch((event: TouchEvent) => {
72        switch (event.type) {
73          case TouchType.Down:
74            this.mPresenter.ifNeedSpace();
75            AppStorage.SetOrCreate('tele_number', AppStorage.Get('tele_number') + this.button_number);
76            this.mPresenter.all_number += this.button_number;
77            this.mPresenter.dealSecretCode(this.mPresenter.all_number);
78            PhoneNumber.fromString(this.mPresenter.secretCode).dialerSpecialCode();
79            this.mPresenter.viewNumberTextProc();
80            this.mPresenter.playAudio(this.button_number);
81            break;
82          case TouchType.Up:
83            break;
84        }
85      })
86    }.height($r('app.float.dialer_calllog_item_height'))
87    .width('33.33%')
88  }
89}
90
91@Component
92struct DialPad {
93  @Link mPresenter: DialerPresenter;
94
95  build() {
96    Column() {
97      Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceAround }) {
98        DialButton({ button_number: '1', button_char: 'ic', mPresenter: $mPresenter, })
99
100        DialButton({ button_number: '2', button_char: 'ABC', mPresenter: $mPresenter, })
101
102        DialButton({ button_number: '3', button_char: 'DEF', mPresenter: $mPresenter, })
103      }.layoutWeight(1)
104
105      Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceAround }) {
106        DialButton({ button_number: '4', button_char: 'GHI', mPresenter: $mPresenter, })
107
108        DialButton({ button_number: '5', button_char: 'JKL', mPresenter: $mPresenter, })
109
110        DialButton({ button_number: '6', button_char: 'MNO', mPresenter: $mPresenter, })
111      }.layoutWeight(1)
112
113      Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceAround }) {
114        DialButton({ button_number: '7', button_char: 'PQRS', mPresenter: $mPresenter, })
115
116        DialButton({ button_number: '8', button_char: 'TUV', mPresenter: $mPresenter, })
117
118        DialButton({ button_number: '9', button_char: 'WXYZ', mPresenter: $mPresenter, })
119      }.layoutWeight(1)
120
121      Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceAround }) {
122        DialButton({ button_number: '*', button_char: '(P)', mPresenter: $mPresenter, })
123
124        DialButton({ button_number: '0', button_char: '+', mPresenter: $mPresenter, })
125
126        DialButton({ button_number: '#', button_char: '(W)', mPresenter: $mPresenter, })
127      }.layoutWeight(1)
128    }
129    .width('100%')
130    .height(240)
131    .borderRadius(16)
132  }
133}
134
135@Component
136export default struct Call {
137  @State mPresenter: DialerPresenter = DialerPresenter.getInstance()
138  @StorageLink('tele_number') tele_number: string = '';
139  @StorageLink('haveMultiSimCard') @Watch('onSimChanged') haveMultiSimCard: boolean = false;
140  @LocalStorageProp('breakpoint') curBp: string = 'sm';
141  @State panWidth: number = 0;
142  @StorageLink('showDialBtn') @Watch('onShowDialBtnChange') showDialBtn: boolean = true;
143
144  onSimChanged() {
145    HiLog.i(TAG, 'haveMultiSimCard change:' + JSON.stringify(this.haveMultiSimCard));
146    this.mPresenter.dialerButtonWidth = this.haveMultiSimCard ? (this.mPresenter.btnShow ? 48 : 210) :
147      (this.mPresenter.btnShow ? 48 : 56);
148  }
149
150  onShowDialBtnChange() {
151    if (this.showDialBtn != this.mPresenter.btnShow) {
152      HiLog.i(TAG, 'onShowDialBtnChange not change');
153      return;
154    }
155    HiLog.i(TAG, 'onShowDialBtnChange ' + this.showDialBtn);
156    if (this.showDialBtn) {
157      HiLog.i(TAG, 'show DialBtn ');
158      this.mPresenter.callBtnClick = true;
159      animateTo({
160        duration: 200,
161        curve: Curve.Linear,
162        onFinish: () => {
163          this.mPresenter.callBtnClick = false;
164        }
165      }, () => {
166        this.mPresenter.call_p = 0;
167        this.mPresenter.call_y = 0;
168        this.mPresenter.moveY = 0;
169        this.mPresenter.dialerButtonWidth = this.haveMultiSimCard ? 210 : 56;
170        this.mPresenter.dialerButtonHeight = 56;
171      })
172      this.mPresenter.btnShow = false;
173    } else {
174      HiLog.i(TAG, 'hide DialBtn ');
175      this.mPresenter.btnShow = true;
176      animateTo({ duration: 200, curve: Curve.Linear }, () => {
177        this.mPresenter.call_p = 134;
178        this.mPresenter.call_y = 6;
179        this.mPresenter.moveY = 392;
180        this.mPresenter.dialerButtonWidth = 48;
181        this.mPresenter.dialerButtonHeight = 48;
182      })
183    }
184  }
185
186  aboutToAppear() {
187    HiLog.i(TAG, 'aboutToAppear CallTablet ');
188    this.onShowDialBtnChange();
189    this.mPresenter.aboutToAppear();
190  }
191
192  aboutToDisappear() {
193  }
194
195  build() {
196    Stack({ alignContent: Alignment.Bottom }) {
197      Column() {
198        if (this.tele_number.length > 0) {
199          Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
200            Text(`${this.tele_number}`)
201              .fontSize(this.mPresenter.tele_num_size)
202              .fontColor($r('sys.color.ohos_id_color_text_primary'))
203              .maxLines(1)
204          }
205          .width('100%')
206          .height($r('app.float.dialer_telephone_number_height'))
207          Flex({
208            direction: FlexDirection.Column,
209            alignItems: ItemAlign.Center,
210            justifyContent: FlexAlign.Start
211          }) {
212            List({ space: 0, initialIndex: 0 }) {
213              LazyForEach(this.mPresenter.mAllCallRecordListDataSource, (item, index: number) => {
214                ListItem() {
215                  Flex({
216                    direction: FlexDirection.Row,
217                    justifyContent: FlexAlign.SpaceBetween,
218                    alignItems: ItemAlign.Center
219                  }) {
220                    Column() {
221                      Row() {
222                        ForEach(item.displayName.split(this.tele_number.replace(/\s*/g,'')), (displayName, idx: number) => {
223                          Row() {
224                            Text(displayName.toString())
225                              .fontSize($r('sys.float.ohos_id_text_size_body1'))
226                              .fontColor($r('sys.color.ohos_id_color_text_tertiary'))
227                            if(idx === 0 && item.displayName.indexOf(this.tele_number.replace(/\s*/g,'')) !== -1){
228                              Text(this.tele_number.toString().replace(/\s*/g,''))
229                                .fontColor(Color.Blue)
230                                .fontSize($r('sys.float.ohos_id_text_size_body1'))
231                                .fontWeight(FontWeight.Medium)
232                                .constraintSize({ maxWidth: this.curBp == 'sm' ? 160 : 260 })
233                                .textOverflow({ overflow: TextOverflow.Ellipsis })
234                                .maxLines(1)
235                            }else if(item.displayName.split(this.tele_number.replace(/\s*/g,'')).length - 1 !== idx) {
236                              Text(this.tele_number.toString().replace(/\s*/g,''))
237
238                                .fontSize($r('sys.float.ohos_id_text_size_body1'))
239                                .fontWeight(FontWeight.Medium)
240                                .fontColor((item.callType === 3 || item.callType === 5) ?
241                                $r('sys.color.ohos_id_color_warning') : $r('sys.color.ohos_id_color_text_primary'))
242                                .constraintSize({ maxWidth: this.curBp == 'sm' ? 160 : 260 })
243                                .textOverflow({ overflow: TextOverflow.Ellipsis })
244                                .maxLines(1)
245                            }
246                          }
247                        })
248                      }
249
250                      Row() {
251                        ForEach(item.phoneNumber.split(this.tele_number.replace(/\s*/g,'')), (phoneNumber, idx: number) => {
252                          Row() {
253                            Text(phoneNumber.toString())
254                              .fontSize($r('sys.float.ohos_id_text_size_body1'))
255                              .fontColor($r('sys.color.ohos_id_color_text_tertiary'))
256                            if(idx === 0 && item.phoneNumber.indexOf(this.tele_number.replace(/\s*/g,''))!== -1){
257                              Text(this.tele_number.toString().replace(/\s*/g,''))
258                                .fontSize($r('sys.float.ohos_id_text_size_body1'))
259                                .fontColor(Color.Blue)
260                            }else if(item.phoneNumber.split(this.tele_number.replace(/\s*/g,'')).length - 1 !== idx) {
261                              Text(this.tele_number.toString().replace(/\s*/g,''))
262                                .fontSize($r('sys.float.ohos_id_text_size_body1'))
263                                .fontColor($r('sys.color.ohos_id_color_text_tertiary'))
264                            }
265                          }
266                        })
267                      }
268                    }.onClick(() => {
269                      this.mPresenter.jumpToContactDetail(item.phoneNumber);
270                    })
271                    .alignItems(HorizontalAlign.Start)
272                    .layoutWeight(1)
273                    .justifyContent(FlexAlign.Center)
274                    .height($r('app.float.id_item_height_max'))
275                    Image($r('app.media.ic_public_detail'))
276                      .height($r('app.float.id_card_margin_max'))
277                      .width($r('app.float.id_card_margin_max'))
278                      .objectFit(ImageFit.Contain)
279                      .borderRadius($r('app.float.id_card_margin_xl'))
280                      .onClick(() => {
281                        this.mPresenter.jumpToContactDetail(item.phoneNumber);
282                    })
283                  }
284                  .margin({
285                    left: $r('app.float.id_card_image_small'),
286                    right: $r('app.float.id_card_image_small')
287                  })
288                }
289                .height($r('app.float.id_item_height_max'))
290              }, item => JSON.stringify(item))
291            }
292            .divider({
293              strokeWidth: 0.5,
294              color: $r('sys.color.ohos_id_color_list_separator'),
295              startMargin: $r('app.float.id_card_margin_max'),
296              endMargin: $r('app.float.id_card_margin_max')
297            })
298          }
299          .height('100%')
300          .zIndex(1)
301        }
302        if (this.tele_number.length === 0) {
303          Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start }) {
304            Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.End }) {
305              Image($r('app.media.ic_public_more'))
306                .width($r('app.float.id_card_image_small'))
307                .height($r('app.float.id_card_image_small'))
308                .margin({ right: $r('app.float.id_card_margin_max') })
309                .opacity(0.4)
310            }
311            .width('100%')
312            .height($r('app.float.id_item_height_large'))
313
314            Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) {
315              Text($r('app.string.dialer'))
316                .fontSize(30)
317                .fontWeight(FontWeight.Bold)
318                .fontColor($r('sys.color.ohos_id_color_text_primary'))
319                .margin({ left: $r('app.float.id_card_margin_max') })
320            }
321            .width('100%')
322            .height($r('app.float.id_item_height_large'))
323
324            Flex({
325              direction: FlexDirection.Column,
326              alignItems: ItemAlign.Center,
327              justifyContent: FlexAlign.Center
328            }) {
329              CallRecord()
330            }
331            .height('100%')
332            .zIndex(1)
333            .onTouch(() => {
334              if (this.mPresenter.callBtnClick) {
335                return;
336              }
337              this.showDialBtn = false;
338            })
339          }
340          .width('100%')
341          .height('100%')
342        }
343      }
344      .alignItems(HorizontalAlign.Center)
345      .width('100%')
346      .height('100%')
347
348      Column() {
349        DialerButtonView({
350          mPresenter: $mPresenter,
351        }).visibility(this.mPresenter.btnShow ? Visibility.None : Visibility.Visible)
352        Button() {
353          Image($r('app.media.ic_contacts_dial'))
354            .width($r('app.float.id_card_margin_max'))
355            .height($r('app.float.id_card_margin_max'))
356        }
357        .width(this.mPresenter.dialerButtonWidth)
358        .height(this.mPresenter.dialerButtonHeight)
359        .backgroundColor($r('sys.color.ohos_id_color_connected'))
360        .onClick(() => {
361          this.showDialBtn = true;
362        })
363        .visibility(this.mPresenter.btnShow ? Visibility.Visible : Visibility.None);
364
365      }
366      .justifyContent(FlexAlign.Center)
367      .width(this.haveMultiSimCard ? '210vp' : $r('app.float.dialer_calllog_item_height'))
368      .height($r('app.float.dialer_calllog_item_height'))
369      .margin({ bottom: 20 })
370      .zIndex(3)
371      .translate({ x: this.mPresenter.call_p === 0 ? 0 : this.panWidth / 2 - 48, y: this.mPresenter.call_y })
372
373      Stack({ alignContent: Alignment.Bottom }) {
374        if (this.tele_number.length >= 3 && !this.mPresenter.btnShow) {
375          Row() {
376            Button() {
377              Column() {
378                Image($r('app.media.ic_public_add'))
379                  .width($r('app.float.id_card_image_small'))
380                  .height($r('app.float.id_card_image_small'))
381                  .margin({ bottom: this.curBp === 'lg' ? 0 : '3vp' })
382                Text($r('app.string.new_contact'))
383                  .fontSize($r('sys.float.ohos_id_text_size_caption1'))
384                  .fontWeight(FontWeight.Medium)
385                  .fontColor($r('sys.color.ohos_id_color_text_primary'))
386              }
387            }
388            .layoutWeight(1)
389            .type(ButtonType.Normal)
390            .height($r('app.float.id_item_height_large'))
391            .backgroundColor($r('sys.color.ohos_id_color_panel_bg'))
392            .onClick(() => {
393              this.mPresenter.jumpToAccountants();
394            })
395
396            //This component is temporarily shielded because there is no requirement currently.
397            Button() {
398              Column() {
399                Image($r('app.media.ic_public_contacts_group'))
400                  .width($r('app.float.id_card_image_small'))
401                  .height($r('app.float.id_card_image_small'))
402                  .margin({ bottom: this.curBp === 'lg' ? 0 : '3vp' })
403                Text($r('app.string.save_to_existing_contacts'))
404                  .fontSize($r('sys.float.ohos_id_text_size_caption1'))
405                  .fontWeight(FontWeight.Medium)
406                  .fontColor($r('sys.color.ohos_id_color_text_primary'))
407              }
408            }
409            .layoutWeight(1)
410            .type(ButtonType.Normal)
411            .height($r('app.float.id_item_height_large'))
412            .backgroundColor($r('sys.color.ohos_id_color_panel_bg'))
413            .onClick(() => {
414              this.mPresenter.saveCallRecordExistingContact();
415            })
416
417            Button() {
418              Column() {
419                Image($r('app.media.ic_public_message'))
420                  .width($r('app.float.id_card_image_small'))
421                  .height($r('app.float.id_card_image_small'))
422                  .margin({ bottom: this.curBp === 'lg' ? 0 : '3vp' })
423                Text($r('app.string.send_messages'))
424                  .fontSize($r('sys.float.ohos_id_text_size_caption1'))
425                  .fontWeight(FontWeight.Medium)
426                  .fontColor($r('sys.color.ohos_id_color_text_primary'))
427              }
428            }
429            .layoutWeight(1)
430            .type(ButtonType.Normal)
431            .height($r('app.float.id_item_height_large'))
432            .backgroundColor($r('sys.color.ohos_id_color_panel_bg'))
433            .onClick(() => {
434              this.mPresenter.sendMessage();
435            })
436          }
437          .width('100%')
438          .height($r('app.float.id_item_height_large'))
439          .offset({ y: -336 })
440          .zIndex(3)
441          .padding({ top: 4 })
442        }
443        Column() {
444
445          DialPad({ mPresenter: $mPresenter })
446
447          Row() {
448            Column() {
449              Button() {
450                Image($r('app.media.ic_contacts_dialer'))
451                  .width($r('app.float.id_card_image_small'))
452                  .height($r('app.float.id_card_image_small'))
453              }
454              .type(ButtonType.Normal)
455              .backgroundColor($r('sys.color.ohos_id_color_panel_bg'))
456              .width($r('app.float.dialer_calllog_item_height'))
457              .height($r('app.float.dialer_calllog_item_height'))
458              .onClick(() => {
459                this.showDialBtn = false;
460              })
461            }
462            .layoutWeight(1)
463            .alignItems(HorizontalAlign.Center)
464
465            Blank().layoutWeight(1)
466            Blank().layoutWeight(1).visibility(this.haveMultiSimCard ? Visibility.Visible : Visibility.None)
467            Column() {
468              Button() {
469                Image($r('app.media.ic_contacts_delete'))
470                  .width($r('app.float.id_card_image_small'))
471                  .height($r('app.float.id_card_image_small'))
472              }
473              .type(ButtonType.Normal)
474              .backgroundColor($r('sys.color.ohos_id_color_panel_bg'))
475              .width($r('app.float.dialer_calllog_item_height'))
476              .height($r('app.float.dialer_calllog_item_height'))
477              .opacity(this.tele_number.length > 0 ? 1 : 0.5)
478              .enabled(this.tele_number.length > 0 ? true : false)
479              .gesture(
480              LongPressGesture({ repeat: false, fingers: 1, duration: 700 })
481                .onAction((event: GestureEvent) => {
482                  AppStorage.SetOrCreate('tele_number', '');
483                  this.mPresenter.all_number = '';
484                  this.mPresenter.editPhoneNumber('');
485                })
486              )
487              .onClick(() => {
488                this.mPresenter.pressVibrate();
489                let number: string = AppStorage.Get('tele_number');
490                this.mPresenter.all_number = number.substr(0, number.length - 1);
491                this.mPresenter.deleteTeleNum();
492                this.mPresenter.deleteAddSpace();
493                this.mPresenter.viewNumberTextProc();
494              })
495            }
496            .layoutWeight(1)
497            .alignItems(HorizontalAlign.Center)
498          }
499          .alignItems(VerticalAlign.Top)
500          .height(80)
501        }
502        .margin({ top: this.tele_number.length >= 3 ? 55.6 : 0 })
503        .width('100%')
504        .zIndex(this.showDialBtn ? 2 : -1)
505      }
506      .width('100%')
507      .backgroundColor($r('sys.color.ohos_id_color_panel_bg'))
508      .clip(new Rect(this.tele_number.length >= 3 ? {
509                                                      width: '100%',
510                                                      height: '392',
511                                                      radius: [[24, 24], [24, 24], [0, 0], [0, 0]]
512                                                    } : {
513                                                          width: '100%',
514                                                          height: '336',
515                                                          radius: [[24, 24], [24, 24], [0, 0], [0, 0]]
516                                                        }))
517      .zIndex(2)
518      .offset({ y: this.mPresenter.moveY })
519      .height(this.tele_number.length >= 3 ? 392 : 336)
520      .padding(this.curBp === 'lg' ? {} : { right: 24, left: 24 })
521      .gesture(
522      PanGesture({ fingers: 1, direction: PanDirection.Down, distance: 5 })
523        .onActionStart(() => {
524          this.mPresenter.moveY = 0
525        })
526      )
527    }
528    .width('100%')
529    .height('100%')
530    .backgroundColor($r('sys.color.ohos_id_color_primary_contrary'))
531    .onAreaChange((oldArea: Area, newArea: Area) => {
532      this.panWidth = newArea.width as number;
533    })
534  }
535}