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 EnvironmentProp from '../../feature/EnvironmentProp'; 17import DialerPresenter from '../../presenter/dialer/DialerPresenter'; 18import { MutiDialerButtonView } from "../mutisim/MutiDialerButtonView" 19import { PhoneNumber } from '../../../../../../feature/phonenumber'; 20import { HiLog } from '../../../../../../common/src/main/ets/util/HiLog'; 21 22const TAG = 'DialerButtonView'; 23@Component 24export struct DialerButtonView { 25 emergencyNum: string; 26 @Link mPresenter: DialerPresenter; 27 @StorageLink("tele_number") tele_number: string = ""; 28 @StorageLink("haveSimCard") haveSimCard: boolean = false; 29 @StorageLink("haveMultiSimCard") haveMultiSimCard: boolean = false; 30 @StorageLink("haveVoLteReg") haveVoLteReg: boolean = false; 31 32 dialClick() { 33 this.mPresenter.callBtnClick = true; 34 if (!this.haveSimCard) { 35 HiLog.i(TAG, "No SIM card!"); 36 this.emergencyNum = this.mPresenter.all_number; 37 //TODO Pop-up window for dialing without a SIM card 38 PhoneNumber.fromString(this.mPresenter.all_number).isDialEmergencyNum().then((res) => { 39 this.mPresenter.isEmergencyNum = res; 40 if (!this.mPresenter.isEmergencyNum) { 41 HiLog.i(TAG, "Is not Emergency Phone Number!"); 42 return; 43 } else { 44 this.mPresenter.dialing(this.emergencyNum); 45 } 46 }) 47 } else { 48 if (this.tele_number.length > 0) { 49 this.mPresenter.dialing(this.mPresenter.all_number); 50 } 51 } 52 AppStorage.SetOrCreate("tele_number", ''); 53 this.mPresenter.all_number = ''; 54 this.mPresenter.callBtnClick = false; 55 } 56 57 build() { 58 Row() { 59 if (!this.haveMultiSimCard) { 60 if (this.haveSimCard && this.haveVoLteReg) { 61 Button() { 62 Image($r('app.media.dial_single_button_hd')) 63 .width($r("app.float.id_item_height_large")) 64 .height($r("app.float.id_item_height_large")) 65 } 66 .width(this.mPresenter.dialerButtonHeight) 67 .height(this.mPresenter.dialerButtonHeight) 68 .backgroundColor($r('sys.color.ohos_id_color_connected')) 69 .opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard 70 ? 1 : $r('sys.float.ohos_id_alpha_disabled')) 71 .onClick(() => { 72 this.dialClick(); 73 }) 74 } else { 75 Button() { 76 Image($r("app.media.ic_public_phone_filled_white")) 77 .width($r("app.float.id_card_margin_xxxxl")) 78 .height($r("app.float.id_card_margin_xxxxl")) 79 } 80 .width(this.mPresenter.dialerButtonHeight) 81 .height(this.mPresenter.dialerButtonHeight) 82 .backgroundColor($r('sys.color.ohos_id_color_connected')) 83 .opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard 84 ? 1 : $r('sys.float.ohos_id_alpha_disabled')) 85 .onClick(() => { 86 this.dialClick(); 87 }) 88 } 89 } else { 90 MutiDialerButtonView({ 91 mPresenter: $mPresenter, 92 }).height(this.mPresenter.dialerButtonHeight) 93 } 94 }.width(this.mPresenter.dialerButtonWidth) 95 .height(this.mPresenter.dialerButtonHeight) 96 .justifyContent(FlexAlign.Center) 97 } 98}