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 {LocationData} from '../common/Constants'; 20import ViewModel from '../viewmodel/LocationVM'; 21import SimpleToggleBase from '../../../../../../../../common/src/main/ets/template/SimpleToggleBase'; 22 23const TAG = 'location-ControlCenterSimpleToggleLocationComponent'; 24 25@Component 26export default struct ControlCenterSimpleToggleLocationComponent { 27 private keyId: string; 28 private mEditMode: boolean = false; 29 private mDragMode: boolean = false; 30 @State mIcon: Resource = $r("app.media.ic_controlcenter_gps"); 31 @State mLabel: Resource = $r("app.string.control_center_complex_toggle_location_title"); 32 @StorageLink('LocationVM_LocationData') LocationStatus: boolean = false 33 34 aboutToAppear() { 35 Log.showInfo(TAG, 'aboutToAppear'); 36 ViewModel.initViewModel(); 37 } 38 39 aboutToDisappear() { 40 Log.showInfo(TAG, 'aboutToDisappear'); 41 } 42 43 build() { 44 SimpleToggleBase({ 45 mToggleId: this.keyId, 46 mIcon: $mIcon, 47 mChangeSwitch: $LocationStatus, 48 mLabel: $mLabel, 49 mEditMode: this.mEditMode, 50 mDragMode: this.mDragMode, 51 mClickEvent: () => this.mClickEvent(), 52 mLongClickEvent: () => this.mLongClickEvent() 53 }) 54 } 55 56 mClickEvent() { 57 Log.showDebug(TAG, `mClickEvent, isEnabled: ${this.LocationStatus}`); 58 if (this.LocationStatus) { 59 ViewModel.disableLocation(); 60 } else { 61 ViewModel.enableLocation(); 62 }; 63 } 64 65 mLongClickEvent() { 66 Log.showDebug(TAG, `mLongClickEvent`); 67 EventManager.publish(obtainStartAbility('com.ohos.settings', 'com.ohos.settings.MainAbility')); 68 } 69}