• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2021 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 Ability from '@ohos.app.ability.UIAbility';
17import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
18import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
19import { GlobalContext } from '../../../../../../common/utils/src/main/ets/default/baseUtil/GlobalContext';
20
21export default class MainAbility extends Ability {
22  private funcAbilityWant;
23  onCreate(want, launchParam) {
24    LogUtil.info(ConfigData.TAG + 'Application onCreate')
25    this.funcAbilityWant = want;
26    GlobalContext.getContext().setObject(GlobalContext.globalKeyAbilityWant, want);
27    GlobalContext.getContext().setObject(GlobalContext.globalKeySettingsAbilityContext, this.context);
28  }
29
30  onDestroy() {
31    AppStorage.SetOrCreate('settingsList', []);
32    LogUtil.info(ConfigData.TAG + 'Application onDestroy')
33  }
34
35  onWindowStageCreate(windowStage) {
36    // Main window is created, set main page for this ability
37    LogUtil.log("[Main] MainAbility onWindowStageCreate")
38    let url = 'pages/settingList';
39    if (this.funcAbilityWant?.parameters?.router && this.funcAbilityWant.parameters.router === 'volumeControl') {
40      url = 'pages/volumeControl';
41    }
42    windowStage.setUIContent(this.context, url, null);
43    GlobalContext.getContext().setObject(GlobalContext.globalKeySettingsAbilityContext, this.context);
44  }
45
46  onWindowStageDestroy() {
47    // Main window is destroyed, release UI related resources
48    LogUtil.log("[Main] MainAbility onWindowStageDestroy")
49  }
50
51  onForeground() {
52    // Ability has brought to foreground
53    LogUtil.log("[Main] MainAbility onForeground")
54  }
55
56  onBackground() {
57    // Ability has back to background
58    LogUtil.log("[Main] MainAbility onBackground")
59  }
60};
61