1/* 2 * Copyright (c) 2021-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 Log from '../../../../../../../../common/src/main/ets/default/Log'; 17import EventManager from "../../../../../../../../common/src/main/ets/default/event/EventManager"; 18import {obtainStartAbility} from "../../../../../../../../common/src/main/ets/default/event/EventUtil"; 19import ViewModel from '../viewmodel/BluetoothVM'; 20import iconTitleBase from '../../../../../../../../common/src/main/ets/template/iconTitleBase'; 21 22const TAG = 'bluetooth-ControlCenterComplexToggleBluetoothComponent'; 23 24@Component 25export default struct ControlCenterComplexToggleBluetoothComponent { 26 private IconInfo: any[] = [ 27 $r("app.media.ic_controlcenter_bt_d"), 28 $r("app.media.ic_controlcenter_bt"), 29 ]; 30 @State mTitle: Resource = $r("app.string.control_center_complex_toggle_bluetooth_title"); 31 @StorageLink('BluetoothOpenStatus') BluetoothOpenStatus: boolean = false; 32 33 aboutToAppear() { 34 Log.showInfo(TAG, 'aboutToAppear'); 35 ViewModel.initViewModel(); 36 } 37 38 aboutToDisappear() { 39 Log.showInfo(TAG, 'aboutToDisappear'); 40 } 41 42 build() { 43 Column() { 44 iconTitleBase({ 45 iconOff: this.IconInfo[0], 46 iconOn: this.IconInfo[1], 47 mTitle: $mTitle, 48 changeSwitch: $BluetoothOpenStatus, 49 mClickEvent: () => this.mClickEvent(), 50 mLongClickEvent: () => this.mLongClickEvent() 51 }) 52 }.width('100%') 53 .height('100%') 54 } 55 56 mClickEvent() { 57 Log.showDebug(TAG, `mClickEvent, BluetoothOpenStatus: ${this.BluetoothOpenStatus}`); 58 if (this.BluetoothOpenStatus) { 59 ViewModel.disableBluetooth(); 60 } else { 61 ViewModel.enableBluetooth(); 62 }; 63 } 64 65 mLongClickEvent() { 66 Log.showDebug(TAG, `mLongClickEvent, BluetoothOpenStatus: ${this.BluetoothOpenStatus}`); 67 EventManager.publish(obtainStartAbility('com.ohos.settings', 'com.ohos.settings.BluetoothAbility')); 68 } 69}