• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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 */
15import { common } from '@kit.AbilityKit';
16import { BusinessError } from '@kit.BasicServicesKit';
17import { hilog } from '@kit.PerformanceAnalysisKit';
18
19const TAG: string = 'UIAbilityContext';
20const DOMAIN: number = 0xFF00;
21
22@Entry
23@Component
24struct UIAbilityContext {
25  build() {
26    Column() {
27      Row() {
28        Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) {
29          Text($r('app.string.UIAbilityContext'))
30            .fontSize(30)
31            .fontWeight(700)
32            .textAlign(TextAlign.Start)
33            .margin({
34              top: 8,
35              bottom: 8,
36              left: 12
37            })
38        }
39      }
40      .width('100%')
41      .height('14.36%')
42      .justifyContent(FlexAlign.Start)
43      .backgroundColor($r('app.color.backGrounding'))
44
45      List({ initialIndex: 0 }) {
46        ListItem() {
47          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
48            Text($r('app.string.UIAbilityContext_moveAbilityToBackground'))
49              .textAlign(TextAlign.Start)
50              .fontWeight(500)
51              .margin({
52                top: 17,
53                bottom: 17,
54                left: 12
55              })
56              .fontSize(16)
57              .width('77.87%')
58              .height('39.29%')
59              .fontColor($r('app.color.text_color'))
60          }
61          .id('moveAbilityToBackground')
62          .onClick(() => {
63            let context = getContext(this) as common.UIAbilityContext;
64            context.moveAbilityToBackground().then(() => {
65              hilog.info(DOMAIN, TAG, 'moveAbilityToBackground success.');
66            }).catch((err: BusinessError) => {
67              hilog.info(DOMAIN, TAG, `moveAbilityToBackground error: ${JSON.stringify(err)}.`);
68            });
69          })
70        }
71        .height('8.45%')
72        .backgroundColor($r('app.color.start_window_background'))
73        .borderRadius(24)
74        .margin({ top: 12, right: 12, left: 12 })
75
76        ListItem() {
77          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
78            Text($r('app.string.UIAbilityContext_terminateSelf'))
79              .textAlign(TextAlign.Start)
80              .fontWeight(500)
81              .margin({
82                top: 17,
83                bottom: 17,
84                left: 12
85              })
86              .fontSize(16)
87              .width('77.87%')
88              .height('39.29%')
89              .fontColor($r('app.color.text_color'))
90          }
91          .id('terminateSelf')
92          .onClick(() => {
93            let context = getContext(this) as common.UIAbilityContext;
94            context.terminateSelf().then(() => {
95              hilog.info(DOMAIN, TAG, 'terminateSelf success.');
96            }).catch((err: BusinessError) => {
97              hilog.info(DOMAIN, TAG, `terminateSelf error: ${JSON.stringify(err)}.`);
98            });
99          })
100        }
101        .height('8.45%')
102        .backgroundColor($r('app.color.start_window_background'))
103        .borderRadius(24)
104        .margin({ top: 12, right: 12, left: 12 })
105      }
106      .height('86%')
107      .backgroundColor($r('app.color.backGrounding'))
108    }
109    .backgroundColor($r('app.color.backGrounding'))
110    .width('100%')
111    .height('100%')
112  }
113}