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