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