• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { Log } from '@ohos/common';
17import { StyleConstants } from '@ohos/common';
18import { CommonConstants } from '@ohos/common';
19import { windowManager } from '@ohos/common';
20import { LayoutViewModel } from '@ohos/common';
21import { SmartDock } from '@ohos/smartdock/component';
22import { AppGridLayout } from '@ohos/appcenter/component';
23import { AppGridViewModel } from '@ohos/appcenter';
24import PadStage from '../common/PadStage';
25
26const TAG = "AppCenterView";
27
28interface AnimationInfo {
29  appScaleX: number;
30  appScaleY: number;
31}
32
33@Entry
34@Component
35struct AppCenterView {
36  @State workSpaceHeight: number = 0;
37  @State dockHeight: number = 0;
38  @State device: string = CommonConstants.PAD_DEVICE_TYPE;
39  private mLayoutViewModel?: LayoutViewModel;
40  mAppGridViewModel: AppGridViewModel = AppGridViewModel.getInstance();
41  @StorageLink('animationInfo_alpha') mAppAlpha: number = 1.0;
42  @StorageLink('animationInfo_scale') mAnimationInfo: AnimationInfo = {
43    appScaleX: 1.0,
44    appScaleY: 1.0,
45  }
46
47  aboutToAppear(): void {
48    Log.showInfo(TAG, 'aboutToAppear');
49    AppStorage.setOrCreate('deviceType', this.device);
50    this.mLayoutViewModel = LayoutViewModel.getInstance();
51  }
52
53  onPageShow(): void {
54    Log.showInfo(TAG, 'onPageShow');
55    // move appCenter startup front when power on
56    this.updateScreenSize();
57    this.mAppGridViewModel = AppGridViewModel.getInstance();
58    this.mAppGridViewModel.registerAppListChange();
59    this.mAppGridViewModel.registerEventListener();
60  }
61
62  onPageHide(): void {
63    Log.showInfo(TAG, 'onPageHide');
64  }
65
66  aboutToDisappear(): void {
67    Log.showInfo(TAG, 'aboutToDisappear');
68    this.mAppGridViewModel.unregisterAppListChange();
69    this.mAppGridViewModel.unregisterEventListener();
70  }
71
72  private async updateScreenSize(): Promise<void> {
73    this.workSpaceHeight = LayoutViewModel.getInstance().getWorkSpaceHeight() as number;
74    this.dockHeight = LayoutViewModel.getInstance().getDockHeight() as number;
75  }
76
77  onBackPress(): boolean {
78    Log.showInfo(TAG, `onBackPress`);
79    AppStorage.setOrCreate('selectDesktopAppItem', '');
80    windowManager.destroyWindow(windowManager.APP_CENTER_WINDOW_NAME);
81    return true;
82  }
83
84  private buildLog(): boolean {
85    Log.showDebug(TAG, `AppCenterView buildLog`);
86    return true;
87  }
88
89  build() {
90    Stack() {
91      if (this.buildLog()) {}
92      Column() {
93        Column() {
94          AppGridLayout();
95        }
96        .padding({
97          top: StyleConstants.DEFAULT_28
98        })
99        .alignItems(HorizontalAlign.Center)
100        .justifyContent(FlexAlign.Center)
101
102        Column() {
103          SmartDock();
104        }
105        .height(this.dockHeight)
106      }
107      .width('100%')
108      .height('100%')
109      .scale({ x: this.mAnimationInfo.appScaleX, y: this.mAnimationInfo.appScaleY })
110      .opacity(this.mAppAlpha)
111    }
112    .backgroundImage('/common/pics/ic_wallpaper_recent.jpg')
113    .backgroundImageSize(ImageSize.Cover)
114    .width('100%')
115    .height('100%')
116    .onClick(() => {
117      Log.showInfo(TAG, 'click appcenter area');
118      const contextFlag: boolean = AppStorage.get('contextMenuState') as boolean;
119      Log.showInfo(TAG, 'onClick contextFlag: ' + contextFlag);
120      if (contextFlag && !ContextMenu.close()) {
121        AppStorage.setOrCreate('contextMenuState', false);
122      }else {
123        this.onBackPress();
124      }
125    })
126  }
127}
128