• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
17import Want from '@ohos.app.ability.Want';
18import AbilityConstant from '@ohos.app.ability.AbilityConstant';
19import window from '@ohos.window';
20import { BusinessError } from '@ohos.base';
21import GlobalContext from '../common/GlobalContext';
22import Constants from '../common/constant';
23
24const TAG = '[DLPManager_Alert]';
25export default class AlertAbility extends UIAbility {
26  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
27    console.info(TAG, 'onCreate');
28    GlobalContext.store('abilityWant', want);
29    GlobalContext.store('alertContext', this.context)
30  }
31
32  onDestroy(): void {
33    console.info(TAG, 'onDestroy');
34  }
35
36  onWindowStageCreate(windowStage: window.WindowStage): void {
37    // Main window is created, set main page for this ability
38    console.info(TAG, 'onWindowStageCreate');
39    windowStage.loadContent('pages/alert', (err: BusinessError) => {
40      if (err.code !== 0) {
41        console.error(TAG, 'setUIContent failed', err.code, err.message);
42      }
43    });
44    windowStage.disableWindowDecor();
45    let mainWindow: window.Window | undefined = undefined;
46
47    windowStage.getMainWindow((err, data) => {
48      if (err.code) {
49        console.error(TAG, 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
50        return;
51      }
52      mainWindow = data;
53      GlobalContext.store('mainWindow', mainWindow);
54      try {
55        mainWindow.setWindowBackgroundColor(Constants.TRANSPARENT_BACKGROUND_COLOR);
56      } catch (exception) {
57        console.error(TAG, 'Failed to set the background color. Cause: ' + JSON.stringify(exception));
58      }
59
60      let enabled = false;
61      mainWindow.setResizeByDragEnabled(enabled, (err: BusinessError) => {
62        if (err.code) {
63          console.error(TAG, 'Failed to set the function of disabling the resize by dragg window. Cause: ' + JSON.stringify(err));
64          return;
65        }
66        console.info(TAG, 'Succeeded in setting the function of disabling the resize by dragg window.');
67      });
68    })
69  }
70
71  onWindowStageDestroy(): void {
72    // Main window is destroyed, release UI related resources
73    console.info(TAG, 'onWindowStageDestroy');
74  }
75
76  onForeground(): void {
77    // Ability has brought to foreground
78    console.info(TAG, 'onForeground');
79  }
80
81  onBackground(): void {
82    // Ability has back to background
83    console.info(TAG, 'onBackground');
84  }
85};
86