• 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  @Builder MenuBuilder() {
50    Column() {
51      AppMenu({
52        menuInfoList: this.menuInfo,
53        getMenuInfoList: this.getMenuInfoList,
54        closeMenu: () => {
55          AppStorage.SetOrCreate('contextMenuState', false);
56        }
57      })
58    }
59    .alignItems(HorizontalAlign.Center)
60    .justifyContent(FlexAlign.Center)
61    .width(StyleConstants.CONTEXT_MENU_WIDTH)
62    .borderRadius(StyleConstants.DEFAULT_12)
63  }
64
65  build() {
66    Column() {
67      Column() {
68        AppIcon({
69          iconSize: this.iconSize,
70          iconId: this.appIconId,
71          bundleName: this.bundleName,
72          moduleName: this.moduleName,
73          icon: ResourceManager.getInstance().getCachedAppIcon(this.appIconId, this.bundleName, this.moduleName),
74          badgeNumber: this.badgeNumber,
75          useCache: this.useCache
76        })
77        AppName({
78          nameHeight: this.nameHeight,
79          nameSize: this.nameSize,
80          nameFontColor: this.nameFontColor,
81          bundleName: this.bundleName,
82          moduleName: this.moduleName,
83          appName: this.appName,
84          labelId: this.appLabelId,
85          useCache: this.useCache,
86          nameLines: this.nameLines,
87          marginTop: this.mIconNameMargin
88        })
89      }
90      .onDragStart((event: DragEvent, extraParams: string) => {
91        return this.dragStart(event);
92      })
93      .bindContextMenu(this.MenuBuilder, ResponseType.LongPress)
94      .bindContextMenu(this.MenuBuilder, ResponseType.RightClick)
95      .width(this.isSelect ? this.iconSize + StyleConstants.DEFAULT_40 : StyleConstants.PERCENTAGE_100)
96      .height(StyleConstants.PERCENTAGE_100)
97      .backgroundColor(this.isSelect ? StyleConstants.DEFAULT_BROAD_COLOR : StyleConstants.DEFAULT_TRANSPARENT_COLOR)
98      .borderRadius(this.isSelect ? StyleConstants.DEFAULT_15 : StyleConstants.DEFAULT_0)
99      .padding(this.isSelect ? { left: StyleConstants.DEFAULT_20,
100                                 right: StyleConstants.DEFAULT_20, top: this.mPaddingTop } : { top: this.mPaddingTop })
101    }
102    .parallelGesture(
103      LongPressGesture({ repeat: false })
104      .onAction((event: GestureEvent) => {
105        Log.showInfo(TAG, `long press source ${event.source}`);
106        if (event.source == SourceType.Mouse) {
107          Log.showDebug(TAG, `Mouse keyName ${this.bundleName + this.abilityName + this.moduleName}`);
108          AppStorage.SetOrCreate('selectDesktopAppItem', this.bundleName + this.abilityName + this.moduleName);
109        } else {
110          AppStorage.SetOrCreate('selectDesktopAppItem', '');
111        }
112      })
113    )
114  }
115}