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