• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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 Ability from '@ohos.application.Ability'
17import display from '@ohos.display'
18
19export default class MainAbility extends Ability {
20  async onCreate(want, launchParam) {
21    console.log("[Demo] MainAbility onCreate")
22  }
23
24  onDestroy() {
25    console.log("[Demo] MainAbility onDestroy")
26  }
27
28  async onWindowStageCreate(windowStage) {
29    console.log("[Demo] MainAbility onWindowStageCreate")
30    let abilityDisplay = await display.getDefaultDisplay()
31    let abilityDisplayWidth = abilityDisplay.width
32    const displayWidth: number = 2500
33    if (abilityDisplayWidth > displayWidth) {
34      windowStage.loadContent("pages/index", (err, data) => {
35        if (err.code) {
36          console.error('Failed to load the content. Cause:' + JSON.stringify(err));
37          return;
38        }
39        console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
40      });
41    } else {
42      windowStage.loadContent("pages/phoneMain", (err, data) => {
43        if (err.code) {
44          console.error('Failed to load the content. Cause:' + JSON.stringify(err));
45          return;
46        }
47        console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
48      });
49    }
50
51  }
52
53  onWindowStageDestroy() {
54    console.log("[Demo] MainAbility onWindowStageDestroy")
55  }
56
57  onForeground() {
58    console.log("[Demo] MainAbility onForeground")
59  }
60
61  onBackground() {
62    console.log("[Demo] MainAbility onBackground")
63  }
64}
65