• 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 '../utils/Log';
17import { AppIcon } from './AppIcon';
18import { AppName } from './AppName';
19import { AppMenu } from './AppMenu';
20import { StyleConstants } from '../constants/StyleConstants';
21import { ResourceManager } from '../manager/ResourceManager';
22import { PresetStyleConstants } from '../constants/PresetStyleConstants';
23import { LauncherDragItemInfo } from '../bean/LauncherDragItemInfo';
24
25const TAG = 'AppBubble';
26
27@Component
28export struct AppBubble {
29  @State bundleName: string = '';
30  @State abilityName: string = '';
31  @State moduleName: string = '';
32  @State appIconId: number = 0;
33  @State appLabelId: number = 0;
34  iconSize: number = 0;
35  nameHeight: number = 0;
36  nameSize: number = 0;
37  nameFontColor: string = '';
38  badgeNumber: number = 0;
39  mPaddingTop: number = StyleConstants.DEFAULT_10;
40  nameLines: number = PresetStyleConstants.DEFAULT_APP_NAME_LINES;
41  mIconNameMargin: number = PresetStyleConstants.DEFAULT_ICON_NAME_GAP;
42  private menuInfo;
43  private getMenuInfoList: Function;
44  isSelect?: boolean;
45  appName: string = '';
46  useCache: boolean = true;
47  shortCutEnabled: boolean = false;
48  dragStart: Function;
49
50  aboutToDisappear(): void {
51    this.getMenuInfoList = null;
52    this.dragStart = null;
53    this.menuInfo = null;
54  }
55
56  @Builder MenuBuilder() {
57    Column() {
58      AppMenu({
59        menuInfoList: this.menuInfo,
60        getMenuInfoList: this.getMenuInfoList,
61        closeMenu: () => {
62          AppStorage.setOrCreate('contextMenuState', false);
63        }
64      })
65    }
66    .alignItems(HorizontalAlign.Center)
67    .justifyContent(FlexAlign.Center)
68    .width(StyleConstants.CONTEXT_MENU_WIDTH)
69    .borderRadius(StyleConstants.DEFAULT_12)
70  }
71
72  build() {
73    Column() {
74      Column() {
75        Column() {
76          AppIcon({
77            iconSize: this.iconSize,
78            iconId: this.appIconId,
79            bundleName: this.bundleName,
80            moduleName: this.moduleName,
81            icon: ResourceManager.getInstance().getCachedAppIcon(this.appIconId, this.bundleName, this.moduleName),
82            badgeNumber: this.badgeNumber,
83            useCache: this.useCache
84          })
85        }
86        .onDragStart((event: DragEvent, extraParams: string) => {
87          return this.dragStart(event);
88        })
89        .bindContextMenu(this.MenuBuilder, ResponseType.LongPress)
90        .onDragEnd((event: DragEvent, extraParams: string) => {
91          AppStorage.setOrCreate<LauncherDragItemInfo>('dragItemInfo', new LauncherDragItemInfo());
92        })
93
94        AppName({
95          nameHeight: this.nameHeight,
96          nameSize: this.nameSize,
97          nameFontColor: this.nameFontColor,
98          bundleName: this.bundleName,
99          moduleName: this.moduleName,
100          appName: this.appName,
101          labelId: this.appLabelId,
102          useCache: this.useCache,
103          nameLines: this.nameLines,
104          marginTop: this.mIconNameMargin
105        })
106      }
107      .bindContextMenu(this.MenuBuilder, ResponseType.RightClick)
108      .width(this.isSelect ? this.iconSize + StyleConstants.DEFAULT_40 : StyleConstants.PERCENTAGE_100)
109      .height(StyleConstants.PERCENTAGE_100)
110      .backgroundColor(this.isSelect ? StyleConstants.DEFAULT_BROAD_COLOR : StyleConstants.DEFAULT_TRANSPARENT_COLOR)
111      .borderRadius(this.isSelect ? StyleConstants.DEFAULT_15 : StyleConstants.DEFAULT_0)
112      .padding(this.isSelect ? { left: StyleConstants.DEFAULT_20,
113                                 right: StyleConstants.DEFAULT_20, top: this.mPaddingTop } : { top: this.mPaddingTop })
114    }
115    .parallelGesture(
116      LongPressGesture({ repeat: false })
117      .onAction((event: GestureEvent) => {
118        Log.showInfo(TAG, `long press source ${event.source}`);
119        if (event.source == SourceType.Mouse) {
120          Log.showDebug(TAG, `Mouse keyName ${this.bundleName + this.abilityName + this.moduleName}`);
121          AppStorage.setOrCreate('selectDesktopAppItem', this.bundleName + this.abilityName + this.moduleName);
122        } else {
123          AppStorage.setOrCreate('selectDesktopAppItem', '');
124        }
125      })
126    )
127  }
128}