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 EnvironmentProp from '../../../feature/EnvironmentProp'; 20import IndexPresenter from '../../../presenter/IndexPresenter'; 21import { DialerButtonView } from "../../../component/dialer/DialerButtonView"; 22 23const TAG = 'Dialer'; 24 25@Component 26struct DialButton { 27 @State button_number: string = '' 28 @State button_char: string = '' 29 @Link mPresenter: DialerPresenter 30 31 build() { 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 .onClick(() => { 69 this.mPresenter.ifNeedSpace(); 70 AppStorage.SetOrCreate("tele_number", AppStorage.Get("tele_number") + this.button_number); 71 this.mPresenter.all_number += this.button_number 72 this.mPresenter.viewNumberTextProc(); 73 this.mPresenter.playAudio(this.button_number); 74 }) 75 }.height($r("app.float.dialer_calllog_item_height")) 76 .width('33.33%') 77 } 78} 79 80@Component 81struct DialPad { 82 @Link mPresenter: DialerPresenter; 83 84 build() { 85 Column() { 86 Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceAround }) { 87 DialButton({ button_number: '1', button_char: 'ic', mPresenter: $mPresenter, }) 88 89 DialButton({ button_number: '2', button_char: 'ABC', mPresenter: $mPresenter, }) 90 91 DialButton({ button_number: '3', button_char: 'DEF', mPresenter: $mPresenter, }) 92 }.layoutWeight(1) 93 94 Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceAround }) { 95 DialButton({ button_number: '4', button_char: 'GHI', mPresenter: $mPresenter, }) 96 97 DialButton({ button_number: '5', button_char: 'JKL', mPresenter: $mPresenter, }) 98 99 DialButton({ button_number: '6', button_char: 'MNO', mPresenter: $mPresenter, }) 100 }.layoutWeight(1) 101 102 Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceAround }) { 103 DialButton({ button_number: '7', button_char: 'PQRS', mPresenter: $mPresenter, }) 104 105 DialButton({ button_number: '8', button_char: 'TUV', mPresenter: $mPresenter, }) 106 107 DialButton({ button_number: '9', button_char: 'WXYZ', mPresenter: $mPresenter, }) 108 }.layoutWeight(1) 109 110 Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceAround }) { 111 DialButton({ button_number: '*', button_char: '(P)', mPresenter: $mPresenter, }) 112 113 DialButton({ button_number: '0', button_char: '+', mPresenter: $mPresenter, }) 114 115 DialButton({ button_number: '#', button_char: '(W)', mPresenter: $mPresenter, }) 116 }.layoutWeight(1) 117 } 118 .width("100%") 119 .height(240) 120 .borderRadius(16) 121 } 122} 123 124@Component 125export default struct Call { 126 @State mPresenter: DialerPresenter = DialerPresenter.getInstance() 127 @StorageLink("tele_number") tele_number: string = ""; 128 @StorageLink("haveMultiSimCard") @Watch("onSimChanged") haveMultiSimCard: boolean = false; 129 @LocalStorageProp('breakpoint') curBp: string = 'sm'; 130 @State panWidth: number = 0; 131 @StorageLink("showDialBtn") @Watch('onShowDialBtnChange') showDialBtn: boolean = false; 132 133 onSimChanged() { 134 HiLog.i(TAG, "haveMultiSimCard change:" + JSON.stringify(this.haveMultiSimCard)); 135 this.mPresenter.dialerButtonWidth = this.haveMultiSimCard ? (this.mPresenter.btnShow ? 48 : 210) : 136 (this.mPresenter.btnShow ? 48 : 56); 137 } 138 139 onShowDialBtnChange() { 140 HiLog.i(TAG, 'onShowDialBtnChange ' + this.showDialBtn); 141 if (this.showDialBtn) { 142 HiLog.i(TAG, 'show DialBtn '); 143 this.mPresenter.callBtnClick = true; 144 animateTo({ 145 duration: 200, 146 curve: Curve.Linear, 147 onFinish: () => { 148 this.mPresenter.callBtnClick = false; 149 } 150 }, () => { 151 this.mPresenter.call_p = 0; 152 this.mPresenter.call_y = 0; 153 this.mPresenter.moveY = 0 154 this.mPresenter.dialerButtonWidth = this.haveMultiSimCard ? 210 : 56; 155 this.mPresenter.dialerButtonHeight = 56 156 }) 157 this.mPresenter.btnShow = false; 158 } else { 159 HiLog.i(TAG, 'hide DialBtn '); 160 this.mPresenter.btnShow = true; 161 animateTo({ duration: 200, curve: Curve.Linear }, () => { 162 this.mPresenter.call_p = 134; 163 this.mPresenter.call_y = 6; 164 this.mPresenter.moveY = 392; 165 this.mPresenter.dialerButtonWidth = 48; 166 this.mPresenter.dialerButtonHeight = 48; 167 }) 168 } 169 } 170 171 aboutToAppear() { 172 HiLog.i(TAG, 'aboutToAppear CallTablet '); 173 this.showDialBtn = true; 174 this.mPresenter.aboutToAppear(); 175 } 176 177 aboutToDisappear() { 178 } 179 180 build() { 181 Stack({ alignContent: Alignment.Bottom }) { 182 Column() { 183 if (this.tele_number.length > 0) { 184 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 185 Text(`${this.tele_number}`) 186 .fontSize(this.mPresenter.tele_num_size) 187 .fontColor($r('sys.color.ohos_id_color_text_primary')) 188 .maxLines(1) 189 } 190 .width('100%') 191 .height($r("app.float.dialer_telephone_number_height")) 192 } 193 if (this.tele_number.length === 0) { 194 Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start }) { 195 Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.End }) { 196 Image($r("app.media.ic_public_more")) 197 .width($r("app.float.id_card_image_small")) 198 .height($r("app.float.id_card_image_small")) 199 .margin({ right: $r("app.float.id_card_margin_max") }) 200 .opacity(0.4) 201 } 202 .width('100%') 203 .height($r("app.float.id_item_height_large")) 204 205 Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { 206 Text($r("app.string.dialer")) 207 .fontSize(30) 208 .fontWeight(FontWeight.Bold) 209 .fontColor($r("sys.color.ohos_id_color_text_primary")) 210 .margin({ left: $r("app.float.id_card_margin_max") }) 211 } 212 .width('100%') 213 .height($r("app.float.id_item_height_large")) 214 215 Flex({ 216 direction: FlexDirection.Column, 217 alignItems: ItemAlign.Center, 218 justifyContent: FlexAlign.Center 219 }) { 220 CallRecord() 221 } 222 .height('100%') 223 .zIndex(1) 224 .gesture( 225 SwipeGesture({ fingers: 1, direction: SwipeDirection.Vertical, speed: 150 }) 226 .onAction((event: GestureEvent) => { 227 if (this.mPresenter.callBtnClick) { 228 return; 229 } 230 this.mPresenter.panelShow = false; 231 this.showDialBtn = false; 232 }) 233 ) 234 } 235 .width('100%') 236 .height('100%') 237 } 238 } 239 .alignItems(HorizontalAlign.Center) 240 .width('100%') 241 .height('100%') 242 243 Column() { 244 DialerButtonView({ 245 mPresenter: $mPresenter, 246 }).visibility(this.mPresenter.btnShow ? Visibility.None : Visibility.Visible) 247 Button() { 248 Image($r("app.media.ic_contacts_dial")) 249 .width($r("app.float.id_card_margin_max")) 250 .height($r("app.float.id_card_margin_max")) 251 } 252 .width(this.mPresenter.dialerButtonWidth) 253 .height(this.mPresenter.dialerButtonHeight) 254 .backgroundColor($r('sys.color.ohos_id_color_connected')) 255 .onClick(() => { 256 this.showDialBtn = true; 257 }) 258 .visibility(this.mPresenter.btnShow ? Visibility.Visible : Visibility.None); 259 260 } 261 .justifyContent(FlexAlign.Center) 262 .width(this.haveMultiSimCard ? "210vp" : $r("app.float.dialer_calllog_item_height")) 263 .height($r("app.float.dialer_calllog_item_height")) 264 .margin({ bottom: 20 }) 265 .zIndex(3) 266 .translate({ x: this.mPresenter.call_p === 0 ? 0 : this.panWidth / 2 - 48, y: this.mPresenter.call_y }) 267 268 Stack({ alignContent: Alignment.Bottom }) { 269 if (this.tele_number.length >= 3 && !this.mPresenter.btnShow) { 270 Row() { 271 Button() { 272 Column() { 273 Image($r("app.media.ic_public_add")) 274 .width($r("app.float.id_card_image_small")) 275 .height($r("app.float.id_card_image_small")) 276 .margin({ bottom: this.curBp === 'lg' ? 0 : '3vp' }) 277 Text($r("app.string.new_contact")) 278 .fontSize($r("sys.float.ohos_id_text_size_caption1")) 279 .fontWeight(FontWeight.Medium) 280 .fontColor($r("sys.color.ohos_id_color_text_primary")) 281 } 282 } 283 .layoutWeight(1) 284 .type(ButtonType.Normal) 285 .height($r("app.float.id_item_height_large")) 286 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 287 .onClick(() => { 288 this.mPresenter.jumpToAccountants(); 289 }) 290 291 //This component is temporarily shielded because there is no requirement currently. 292 // Button() { 293 // Column() { 294 // Image($r("app.media.ic_public_contacts_group")) 295 // .width($r("app.float.id_card_image_small")) 296 // .height($r("app.float.id_card_image_small")) 297 // .margin({ bottom: this.curBp === 'lg' ? 0 : '3vp' }) 298 // Text($r("app.string.save_to_existing_contacts")) 299 // .fontSize($r("sys.float.ohos_id_text_size_caption1")) 300 // .fontWeight(FontWeight.Medium) 301 // .fontColor($r("sys.color.ohos_id_color_text_primary")) 302 // } 303 // } 304 // .layoutWeight(1) 305 // .type(ButtonType.Normal) 306 // .height($r("app.float.id_item_height_large")) 307 // .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 308 309 Button() { 310 Column() { 311 Image($r("app.media.ic_public_message")) 312 .width($r("app.float.id_card_image_small")) 313 .height($r("app.float.id_card_image_small")) 314 .margin({ bottom: this.curBp === 'lg' ? 0 : '3vp' }) 315 Text($r("app.string.send_messages")) 316 .fontSize($r("sys.float.ohos_id_text_size_caption1")) 317 .fontWeight(FontWeight.Medium) 318 .fontColor($r("sys.color.ohos_id_color_text_primary")) 319 } 320 } 321 .layoutWeight(1) 322 .type(ButtonType.Normal) 323 .height($r("app.float.id_item_height_large")) 324 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 325 .onClick(() => { 326 this.mPresenter.sendMessage(); 327 }) 328 } 329 .width('100%') 330 .height($r("app.float.id_item_height_large")) 331 .offset({ x: 0, y: -336 }) 332 .zIndex(3) 333 .padding({ top: 4 }) 334 } 335 Column() { 336 337 DialPad({ mPresenter: $mPresenter }) 338 339 Row() { 340 Column() { 341 Button() { 342 Image($r("app.media.ic_contacts_dialer")) 343 .width($r("app.float.id_card_image_small")) 344 .height($r("app.float.id_card_image_small")) 345 } 346 .type(ButtonType.Normal) 347 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 348 .width($r("app.float.dialer_calllog_item_height")) 349 .height($r("app.float.dialer_calllog_item_height")) 350 .onClick(() => { 351 this.showDialBtn = false; 352 }) 353 } 354 .layoutWeight(1) 355 .alignItems(HorizontalAlign.Center) 356 357 Blank().layoutWeight(1) 358 Blank().layoutWeight(1).visibility(this.haveMultiSimCard ? Visibility.Visible : Visibility.None) 359 Column() { 360 Button() { 361 Image($r("app.media.ic_contacts_delete")) 362 .width($r("app.float.id_card_image_small")) 363 .height($r("app.float.id_card_image_small")) 364 } 365 .type(ButtonType.Normal) 366 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 367 .width($r("app.float.dialer_calllog_item_height")) 368 .height($r("app.float.dialer_calllog_item_height")) 369 .opacity(this.tele_number.length > 0 ? 1 : 0.5) 370 .enabled(this.tele_number.length > 0 ? true : false) 371 .gesture( 372 LongPressGesture({ repeat: false, fingers: 1, duration: 700 }) 373 .onAction((event: GestureEvent) => { 374 AppStorage.SetOrCreate("tele_number", ''); 375 this.mPresenter.all_number = ''; 376 IndexPresenter.getInstance().editPhoneNumber = ""; 377 }) 378 ) 379 .onClick(() => { 380 this.mPresenter.isClickDelete = true; 381 this.mPresenter.pressVibrate(); 382 this.mPresenter.all_number = this.mPresenter.all_number.substr(0, this.mPresenter.all_number.length - 1) 383 this.mPresenter.deleteTeleNum(); 384 this.mPresenter.deleteAddSpace(); 385 this.mPresenter.viewNumberTextProc(); 386 }) 387 } 388 .layoutWeight(1) 389 .alignItems(HorizontalAlign.Center) 390 } 391 .alignItems(VerticalAlign.Top) 392 .height(80) 393 } 394 .margin({ top: this.tele_number.length >= 3 ? 55.6 : 0 }) 395 .width('100%') 396 .zIndex(this.mPresenter.panelShow ? 2 : -1) 397 } 398 .width("100%") 399 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 400 .clip(new Rect(this.tele_number.length >= 3 ? { 401 width: '100%', 402 height: '392', 403 radius: [[24, 24], [24, 24], [0, 0], [0, 0]] 404 } : { 405 width: '100%', 406 height: '336', 407 radius: [[24, 24], [24, 24], [0, 0], [0, 0]] 408 })) 409 .zIndex(2) 410 .offset({ y: this.mPresenter.moveY }) 411 .height(this.tele_number.length >= 3 ? 392 : 336) 412 .padding(this.curBp === 'lg' ? {} : { right: 24, left: 24 }) 413 .gesture( 414 PanGesture({ fingers: 1, direction: PanDirection.Down, distance: 5 }) 415 .onActionStart(() => { 416 this.mPresenter.moveY = 0 417 }) 418 ) 419 } 420 .width('100%') 421 .height('100%') 422 .backgroundColor($r('sys.color.ohos_id_color_primary_contrary')) 423 .onAreaChange((oldArea: Area, newArea: Area) => { 424 this.panWidth = newArea.width as number; 425 }) 426 } 427}