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 prompt from '@system.prompt';
17import { BusinessError } from '@ohos.base';
18import common from '@ohos.app.ability.common';
19import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
20import { GlobalContext } from '../../../../../../common/utils/src/main/ets/default/baseUtil/GlobalContext';
21import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
22import HeadComponent from '../../../../../../common/component/src/main/ets/default/headComponent';
23import ResourceUtil from '../../../../../../common/search/src/main/ets/default/common/ResourceUtil';
24import { SubEntryComponent } from '../../../../../../common/component/src/main/ets/default/subEntryComponent';
25
26/**
27 * Home Page Of Privacy Settings
28 */
29@Entry
30@Component
31struct PrivacySettings {
32  private TAG = `${ConfigData.TAG} PrivacySettings `;
33
34  build() {
35    Column() {
36      GridContainer({ gutter: ConfigData.GRID_CONTAINER_GUTTER_24, margin: ConfigData.GRID_CONTAINER_MARGIN_24 }) {
37        Column() {
38          HeadComponent({ headName: $r('app.string.privacy'), isActive: true });
39
40          PermissionComponent()
41            .margin({ top: $r("app.float.distance_8"), bottom: $r('sys.float.ohos_id_card_margin_start') })
42
43          SubEntryComponent({ targetPage: 'pages/locationServices', title: $r('app.string.locationServicesTab') });
44        }
45        .useSizeType({
46          sm: { span: 4, offset: 0 },
47          md: { span: 6, offset: 1 },
48          lg: { span: 8, offset: 2 }
49        })
50      }
51      .width(ConfigData.WH_100_100)
52      .height(ConfigData.WH_100_100)
53    }
54    .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
55    .width(ConfigData.WH_100_100)
56    .height(ConfigData.WH_100_100)
57  }
58
59  aboutToAppear() {
60    LogUtil.info(`${this.TAG} aboutToAppear in`);
61    LogUtil.info(`${this.TAG} aboutToAppear out`);
62  }
63}
64
65/**
66 * Permission Manager Component
67 */
68@Component
69export struct PermissionComponent {
70  @State isTouched: boolean = false;
71  private TAG = `${ConfigData.TAG} PrivacySettings PermissionComponent `;
72
73  build() {
74    Column() {
75      Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
76        Text($r('app.string.permissionManager'))
77          .fontSize($r('app.float.font_16'))
78          .lineHeight($r('app.float.wh_value_22'))
79          .fontColor($r('app.color.font_color_182431'))
80          .fontWeight(FontWeight.Medium)
81          .margin({ left: $r('app.float.distance_8') })
82          .textAlign(TextAlign.Start);
83
84        Image('/res/image/ic_settings_arrow.svg')
85          .width($r('app.float.wh_value_12'))
86          .height($r('app.float.wh_value_24'))
87          .margin({ right: $r('app.float.distance_8') })
88          .fillColor($r("sys.color.ohos_id_color_primary"))
89          .opacity($r("app.float.opacity_0_2"))
90      }
91      .height(ConfigData.WH_100_100)
92      .width(ConfigData.WH_100_100)
93      .borderRadius($r('app.float.radius_20'))
94      .linearGradient(this.isTouched ? {
95        angle: 90,
96        direction: GradientDirection.Right,
97        colors: [[$r("app.color.DCEAF9"), 0.0], [$r("app.color.FAFAFA"), 1.0]]
98      } : {
99        angle: 90,
100        direction: GradientDirection.Right,
101        colors: [[$r("sys.color.ohos_id_color_foreground_contrary"), 1], [$r("sys.color.ohos_id_color_foreground_contrary"), 1]]
102      })
103      .onTouch((event?: TouchEvent) => {
104        if (event?.type === TouchType.Down) {
105          this.isTouched = true;
106        }
107
108        if (event?.type === TouchType.Up) {
109          this.isTouched = false;
110        }
111      })
112    }
113    .padding($r('app.float.distance_4'))
114    .backgroundColor('#FFFFFF')
115    .height($r('app.float.wh_value_56'))
116    .borderRadius($r('app.float.radius_24'))
117    .onClick(() => {
118      let context = GlobalContext.getContext()
119        .getObject(GlobalContext.globalKeySettingsAbilityContext) as common.UIAbilityContext;
120      context.startAbility({
121        bundleName: ConfigData.PERMISSION_MANAGER_BUNDLE_NAME,
122        abilityName: ConfigData.PERMISSION_MANAGER_ABILITY_NAME,
123      })
124        .then((data) => {
125          LogUtil.info(`${this.TAG}, ${ConfigData.PERMISSION_MANAGER_BUNDLE_NAME} start successful. Data: ${JSON.stringify(data)}`);
126        })
127        .catch((error: BusinessError) => {
128          ResourceUtil.getString($r("app.string.permissionFailed")).then(value => {
129            prompt.showToast({
130              message: value,
131              duration: 2000,
132            });
133            LogUtil.error(`${this.TAG}, ${ConfigData.PERMISSION_MANAGER_BUNDLE_NAME} start failed. Cause: ${JSON.stringify(error)}`);
134          })
135        })
136    });
137  }
138}