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 .onTouch(() => { 225 if (this.mPresenter.callBtnClick) { 226 return; 227 } 228 this.mPresenter.panelShow = false; 229 this.showDialBtn = false; 230 }) 231 } 232 .width('100%') 233 .height('100%') 234 } 235 } 236 .alignItems(HorizontalAlign.Center) 237 .width('100%') 238 .height('100%') 239 240 Column() { 241 DialerButtonView({ 242 mPresenter: $mPresenter, 243 }).visibility(this.mPresenter.btnShow ? Visibility.None : Visibility.Visible) 244 Button() { 245 Image($r("app.media.ic_contacts_dial")) 246 .width($r("app.float.id_card_margin_max")) 247 .height($r("app.float.id_card_margin_max")) 248 } 249 .width(this.mPresenter.dialerButtonWidth) 250 .height(this.mPresenter.dialerButtonHeight) 251 .backgroundColor($r('sys.color.ohos_id_color_connected')) 252 .onClick(() => { 253 this.showDialBtn = true; 254 }) 255 .visibility(this.mPresenter.btnShow ? Visibility.Visible : Visibility.None); 256 257 } 258 .justifyContent(FlexAlign.Center) 259 .width(this.haveMultiSimCard ? "210vp" : $r("app.float.dialer_calllog_item_height")) 260 .height($r("app.float.dialer_calllog_item_height")) 261 .margin({ bottom: 20 }) 262 .zIndex(3) 263 .translate({ x: this.mPresenter.call_p === 0 ? 0 : this.panWidth / 2 - 48, y: this.mPresenter.call_y }) 264 265 Stack({ alignContent: Alignment.Bottom }) { 266 if (this.tele_number.length >= 3 && !this.mPresenter.btnShow) { 267 Row() { 268 Button() { 269 Column() { 270 Image($r("app.media.ic_public_add")) 271 .width($r("app.float.id_card_image_small")) 272 .height($r("app.float.id_card_image_small")) 273 .margin({ bottom: this.curBp === 'lg' ? 0 : '3vp' }) 274 Text($r("app.string.new_contact")) 275 .fontSize($r("sys.float.ohos_id_text_size_caption1")) 276 .fontWeight(FontWeight.Medium) 277 .fontColor($r("sys.color.ohos_id_color_text_primary")) 278 } 279 } 280 .layoutWeight(1) 281 .type(ButtonType.Normal) 282 .height($r("app.float.id_item_height_large")) 283 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 284 .onClick(() => { 285 this.mPresenter.jumpToAccountants(); 286 }) 287 288 //This component is temporarily shielded because there is no requirement currently. 289 // Button() { 290 // Column() { 291 // Image($r("app.media.ic_public_contacts_group")) 292 // .width($r("app.float.id_card_image_small")) 293 // .height($r("app.float.id_card_image_small")) 294 // .margin({ bottom: this.curBp === 'lg' ? 0 : '3vp' }) 295 // Text($r("app.string.save_to_existing_contacts")) 296 // .fontSize($r("sys.float.ohos_id_text_size_caption1")) 297 // .fontWeight(FontWeight.Medium) 298 // .fontColor($r("sys.color.ohos_id_color_text_primary")) 299 // } 300 // } 301 // .layoutWeight(1) 302 // .type(ButtonType.Normal) 303 // .height($r("app.float.id_item_height_large")) 304 // .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 305 306 Button() { 307 Column() { 308 Image($r("app.media.ic_public_message")) 309 .width($r("app.float.id_card_image_small")) 310 .height($r("app.float.id_card_image_small")) 311 .margin({ bottom: this.curBp === 'lg' ? 0 : '3vp' }) 312 Text($r("app.string.send_messages")) 313 .fontSize($r("sys.float.ohos_id_text_size_caption1")) 314 .fontWeight(FontWeight.Medium) 315 .fontColor($r("sys.color.ohos_id_color_text_primary")) 316 } 317 } 318 .layoutWeight(1) 319 .type(ButtonType.Normal) 320 .height($r("app.float.id_item_height_large")) 321 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 322 .onClick(() => { 323 this.mPresenter.sendMessage(); 324 }) 325 } 326 .width('100%') 327 .height($r("app.float.id_item_height_large")) 328 .offset({ x: 0, y: -336 }) 329 .zIndex(3) 330 .padding({ top: 4 }) 331 } 332 Column() { 333 334 DialPad({ mPresenter: $mPresenter }) 335 336 Row() { 337 Column() { 338 Button() { 339 Image($r("app.media.ic_contacts_dialer")) 340 .width($r("app.float.id_card_image_small")) 341 .height($r("app.float.id_card_image_small")) 342 } 343 .type(ButtonType.Normal) 344 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 345 .width($r("app.float.dialer_calllog_item_height")) 346 .height($r("app.float.dialer_calllog_item_height")) 347 .onClick(() => { 348 this.showDialBtn = false; 349 }) 350 } 351 .layoutWeight(1) 352 .alignItems(HorizontalAlign.Center) 353 354 Blank().layoutWeight(1) 355 Blank().layoutWeight(1).visibility(this.haveMultiSimCard ? Visibility.Visible : Visibility.None) 356 Column() { 357 Button() { 358 Image($r("app.media.ic_contacts_delete")) 359 .width($r("app.float.id_card_image_small")) 360 .height($r("app.float.id_card_image_small")) 361 } 362 .type(ButtonType.Normal) 363 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 364 .width($r("app.float.dialer_calllog_item_height")) 365 .height($r("app.float.dialer_calllog_item_height")) 366 .opacity(this.tele_number.length > 0 ? 1 : 0.5) 367 .enabled(this.tele_number.length > 0 ? true : false) 368 .gesture( 369 LongPressGesture({ repeat: false, fingers: 1, duration: 700 }) 370 .onAction((event: GestureEvent) => { 371 AppStorage.SetOrCreate("tele_number", ''); 372 this.mPresenter.all_number = ''; 373 IndexPresenter.getInstance().editPhoneNumber = ""; 374 }) 375 ) 376 .onClick(() => { 377 this.mPresenter.isClickDelete = true; 378 this.mPresenter.pressVibrate(); 379 this.mPresenter.all_number = this.mPresenter.all_number.substr(0, this.mPresenter.all_number.length - 1) 380 this.mPresenter.deleteTeleNum(); 381 this.mPresenter.deleteAddSpace(); 382 this.mPresenter.viewNumberTextProc(); 383 }) 384 } 385 .layoutWeight(1) 386 .alignItems(HorizontalAlign.Center) 387 } 388 .alignItems(VerticalAlign.Top) 389 .height(80) 390 } 391 .margin({ top: this.tele_number.length >= 3 ? 55.6 : 0 }) 392 .width('100%') 393 .zIndex(this.mPresenter.panelShow ? 2 : -1) 394 } 395 .width("100%") 396 .backgroundColor($r('sys.color.ohos_id_color_panel_bg')) 397 .clip(new Rect(this.tele_number.length >= 3 ? { 398 width: '100%', 399 height: '392', 400 radius: [[24, 24], [24, 24], [0, 0], [0, 0]] 401 } : { 402 width: '100%', 403 height: '336', 404 radius: [[24, 24], [24, 24], [0, 0], [0, 0]] 405 })) 406 .zIndex(2) 407 .offset({ y: this.mPresenter.moveY }) 408 .height(this.tele_number.length >= 3 ? 392 : 336) 409 .padding(this.curBp === 'lg' ? {} : { right: 24, left: 24 }) 410 .gesture( 411 PanGesture({ fingers: 1, direction: PanDirection.Down, distance: 5 }) 412 .onActionStart(() => { 413 this.mPresenter.moveY = 0 414 }) 415 ) 416 } 417 .width('100%') 418 .height('100%') 419 .backgroundColor($r('sys.color.ohos_id_color_primary_contrary')) 420 .onAreaChange((oldArea: Area, newArea: Area) => { 421 this.panWidth = newArea.width as number; 422 }) 423 } 424}