1/** 2 * Copyright (c) 2024-2024 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 ViewModel from '../model/locationServicesImpl/LocationViewModel'; 17import Logger from '../common/utils/Logger'; 18import HeadComponent from '../common/components/headComponent'; 19import HiSysEventUtil from '../common/utils/HiSysEventUtil'; 20 21const TAG: string = 'LocationServicesPage' 22 23/** 24 * LocationServices 25 */ 26@Entry 27@Component 28struct LocationServices { 29 @StorageLink('LocationServiceStatus') locationServiceStatus: boolean = false; 30 31 build() { 32 Column() { 33 GridRow({ columns: { sm: 4, md: 6, lg: 8 }, gutter: 12 }) { 34 GridCol({ span: { sm: 4, md: 6, lg: 8 }, offset: { sm: 0, md: 1, lg: 2 } }) { 35 Column() { 36 HeadComponent({ headName: $r('app.string.locationServicesTab'), isActive: true }); 37 38 Flex({ 39 direction: FlexDirection.Row, 40 justifyContent: FlexAlign.SpaceBetween, 41 alignItems: ItemAlign.Center 42 }) { 43 Text($r('app.string.positionInformation')) 44 .fontColor($r('app.color.font_color_182431')) 45 .fontStyle(FontStyle.Normal) 46 .fontSize($r('app.float.location_font_size')) 47 .margin({ left: $r('app.float.distance_12') }) 48 49 Toggle({ type: ToggleType.Switch, isOn: this.locationServiceStatus }) 50 .margin({ right: $r('app.float.padding_or_margin_s') }) 51 .width('36vp') 52 .height('20vp') 53 .selectedColor('#007DFF') 54 .onChange((isOn: boolean) => { 55 Logger.info(TAG, 'location service status is :' + this.locationServiceStatus); 56 if (isOn) { 57 ViewModel.enableLocation(); 58 HiSysEventUtil.reportLocationFlagClick(1) 59 } else { 60 ViewModel.disableLocation(); 61 HiSysEventUtil.reportLocationFlagClick(0) 62 } 63 }); 64 } 65 .margin({ top: $r('app.float.padding_or_margin_m') }) 66 .height($r('app.float.wh_value_56')) 67 .backgroundColor($r('app.color.white_bg_color')) 68 .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) 69 } 70 } 71 } 72 .margin({ left: $r('app.float.grid_row_margin'), right: $r('app.float.grid_row_margin') }) 73 } 74 .backgroundColor($r('sys.color.ohos_id_color_sub_background')) 75 .width('100%') 76 .height('100%') 77 } 78 79 aboutToAppear(): void { 80 Logger.info(TAG, 'location service about to appear'); 81 ViewModel.initViewModel(); 82 } 83 84 aboutToDisappear(): void { 85 Logger.info(TAG, 'location service about to disappear'); 86 } 87}