1/* 2 * Copyright (c) 2021-2023 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 SimpleToggleBase from '../../../../../../../common/src/main/ets/template/SimpleToggleBase'; 17import Log from '../../../../../../../common/src/main/ets/default/Log'; 18import ViewModel from '../viewmodel/AirplaneVM'; 19 20const TAG = 'airplane-ControlCenterSimpleToggleAirplaneComponent'; 21 22@Component 23export default struct ControlCenterSimpleToggleAirplaneComponent { 24 private keyId: string; 25 private mEditMode: boolean = false; 26 private mDragMode: boolean = false; 27 @State mIcon: Resource = $r("app.media.airplane"); 28 @State mLabel: Resource = $r("app.string.airplane_mode"); 29 @StorageLink('Airplane_Status') airplaneStatus: boolean = false; 30 31 aboutToAppear() { 32 ViewModel.startVM(); 33 Log.showInfo(TAG, 'aboutToAppear'); 34 Log.showInfo(TAG, `mIcon: ${JSON.stringify(this.mIcon)} ${JSON.stringify(this.mLabel)}`) 35 } 36 37 aboutToDisappear() { 38 Log.showInfo(TAG, 'aboutToDisappear'); 39 } 40 41 build() { 42 SimpleToggleBase({ 43 mToggleId: this.keyId, 44 mChangeSwitch: $airplaneStatus, 45 mIcon: $mIcon, 46 mLabel: $mLabel, 47 mEditMode: this.mEditMode, 48 mDragMode: this.mDragMode, 49 mClickEvent: () => this.mClickEvent() 50 }) 51 } 52 53 mClickEvent() { 54 ViewModel.handleClick(); 55 } 56}