16e80583aSopenharmony_ci/**
26e80583aSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
36e80583aSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
46e80583aSopenharmony_ci * you may not use this file except in compliance with the License.
56e80583aSopenharmony_ci * You may obtain a copy of the License at
66e80583aSopenharmony_ci *
76e80583aSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
86e80583aSopenharmony_ci *
96e80583aSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
106e80583aSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
116e80583aSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126e80583aSopenharmony_ci * See the License for the specific language governing permissions and
136e80583aSopenharmony_ci * limitations under the License.
146e80583aSopenharmony_ci */
156e80583aSopenharmony_ci
166e80583aSopenharmony_ciimport { Log } from '../utils/Log';
176e80583aSopenharmony_ciimport { AppIcon } from './AppIcon';
186e80583aSopenharmony_ciimport { AppName } from './AppName';
196e80583aSopenharmony_ciimport { AppMenu } from './AppMenu';
206e80583aSopenharmony_ciimport { StyleConstants } from '../constants/StyleConstants';
216e80583aSopenharmony_ciimport { ResourceManager } from '../manager/ResourceManager';
226e80583aSopenharmony_ciimport { PresetStyleConstants } from '../constants/PresetStyleConstants';
236e80583aSopenharmony_ciimport { LauncherDragItemInfo } from '../bean/LauncherDragItemInfo';
246e80583aSopenharmony_ciimport { MenuInfo } from '../bean';
256e80583aSopenharmony_ci
266e80583aSopenharmony_ciconst TAG = 'AppBubble';
276e80583aSopenharmony_ci
286e80583aSopenharmony_ci@Component
296e80583aSopenharmony_ciexport struct AppBubble {
306e80583aSopenharmony_ci  @State bundleName: string = '';
316e80583aSopenharmony_ci  @State abilityName: string = '';
326e80583aSopenharmony_ci  @State moduleName: string = '';
336e80583aSopenharmony_ci  @State appIconId: number = 0;
346e80583aSopenharmony_ci  @State appLabelId: number = 0;
356e80583aSopenharmony_ci  iconSize: number = 0;
366e80583aSopenharmony_ci  nameHeight: number = 0;
376e80583aSopenharmony_ci  nameSize: number = 0;
386e80583aSopenharmony_ci  nameFontColor: string = '';
396e80583aSopenharmony_ci  badgeNumber: number = 0;
406e80583aSopenharmony_ci  mPaddingTop: number = StyleConstants.DEFAULT_10;
416e80583aSopenharmony_ci  nameLines: number = PresetStyleConstants.DEFAULT_APP_NAME_LINES;
426e80583aSopenharmony_ci  mIconNameMargin: number = PresetStyleConstants.DEFAULT_ICON_NAME_GAP;
436e80583aSopenharmony_ci  private menuInfo: MenuInfo[] = [];
446e80583aSopenharmony_ci  private getMenuInfoList?: Function;
456e80583aSopenharmony_ci  isSelect?: boolean;
466e80583aSopenharmony_ci  appName: string = '';
476e80583aSopenharmony_ci  useCache: boolean = true;
486e80583aSopenharmony_ci  shortCutEnabled: boolean = false;
496e80583aSopenharmony_ci  dragStart: Function = (event: DragEvent) => {};
506e80583aSopenharmony_ci
516e80583aSopenharmony_ci  aboutToDisappear(): void {
526e80583aSopenharmony_ci  }
536e80583aSopenharmony_ci
546e80583aSopenharmony_ci  @Builder MenuBuilder() {
556e80583aSopenharmony_ci    Column() {
566e80583aSopenharmony_ci      AppMenu({
576e80583aSopenharmony_ci        menuInfoList: this.menuInfo,
586e80583aSopenharmony_ci        getMenuInfoList: this.getMenuInfoList,
596e80583aSopenharmony_ci        closeMenu: () => {
606e80583aSopenharmony_ci          AppStorage.setOrCreate('contextMenuState', false);
616e80583aSopenharmony_ci        }
626e80583aSopenharmony_ci      })
636e80583aSopenharmony_ci    }
646e80583aSopenharmony_ci    .alignItems(HorizontalAlign.Center)
656e80583aSopenharmony_ci    .justifyContent(FlexAlign.Center)
666e80583aSopenharmony_ci    .width(StyleConstants.CONTEXT_MENU_WIDTH)
676e80583aSopenharmony_ci    .borderRadius(StyleConstants.DEFAULT_12)
686e80583aSopenharmony_ci  }
696e80583aSopenharmony_ci
706e80583aSopenharmony_ci  build() {
716e80583aSopenharmony_ci    Column() {
726e80583aSopenharmony_ci      Column() {
736e80583aSopenharmony_ci        Column() {
746e80583aSopenharmony_ci          AppIcon({
756e80583aSopenharmony_ci            iconSize: this.iconSize,
766e80583aSopenharmony_ci            iconId: this.appIconId,
776e80583aSopenharmony_ci            bundleName: this.bundleName,
786e80583aSopenharmony_ci            moduleName: this.moduleName,
796e80583aSopenharmony_ci            icon: ResourceManager.getInstance().getCachedAppIcon(this.appIconId, this.bundleName, this.moduleName),
806e80583aSopenharmony_ci            badgeNumber: this.badgeNumber,
816e80583aSopenharmony_ci            useCache: this.useCache
826e80583aSopenharmony_ci          })
836e80583aSopenharmony_ci        }
846e80583aSopenharmony_ci        .onDragStart((event: DragEvent, extraParams: string) => {
856e80583aSopenharmony_ci          return this.dragStart(event);
866e80583aSopenharmony_ci        })
876e80583aSopenharmony_ci        .bindContextMenu(this.MenuBuilder, ResponseType.LongPress)
886e80583aSopenharmony_ci        .onDragEnd((event: DragEvent, extraParams: string) => {
896e80583aSopenharmony_ci          AppStorage.setOrCreate<LauncherDragItemInfo>('dragItemInfo', new LauncherDragItemInfo());
906e80583aSopenharmony_ci        })
916e80583aSopenharmony_ci
926e80583aSopenharmony_ci        AppName({
936e80583aSopenharmony_ci          nameHeight: this.nameHeight,
946e80583aSopenharmony_ci          nameSize: this.nameSize,
956e80583aSopenharmony_ci          nameFontColor: this.nameFontColor,
966e80583aSopenharmony_ci          bundleName: this.bundleName,
976e80583aSopenharmony_ci          moduleName: this.moduleName,
986e80583aSopenharmony_ci          appName: this.appName,
996e80583aSopenharmony_ci          labelId: this.appLabelId,
1006e80583aSopenharmony_ci          useCache: this.useCache,
1016e80583aSopenharmony_ci          nameLines: this.nameLines,
1026e80583aSopenharmony_ci          marginTop: this.mIconNameMargin
1036e80583aSopenharmony_ci        })
1046e80583aSopenharmony_ci      }
1056e80583aSopenharmony_ci      .bindContextMenu(this.MenuBuilder, ResponseType.RightClick)
1066e80583aSopenharmony_ci      .width(this.isSelect ? this.iconSize + StyleConstants.DEFAULT_40 : StyleConstants.PERCENTAGE_100)
1076e80583aSopenharmony_ci      .height(StyleConstants.PERCENTAGE_100)
1086e80583aSopenharmony_ci      .backgroundColor(this.isSelect ? StyleConstants.DEFAULT_BROAD_COLOR : StyleConstants.DEFAULT_TRANSPARENT_COLOR)
1096e80583aSopenharmony_ci      .borderRadius(this.isSelect ? StyleConstants.DEFAULT_15 : StyleConstants.DEFAULT_0)
1106e80583aSopenharmony_ci      .padding(this.isSelect ? { left: StyleConstants.DEFAULT_20,
1116e80583aSopenharmony_ci                                 right: StyleConstants.DEFAULT_20, top: this.mPaddingTop } : { top: this.mPaddingTop })
1126e80583aSopenharmony_ci    }
1136e80583aSopenharmony_ci    .parallelGesture(
1146e80583aSopenharmony_ci      LongPressGesture({ repeat: false })
1156e80583aSopenharmony_ci      .onAction((event: GestureEvent) => {
1166e80583aSopenharmony_ci        Log.showInfo(TAG, `long press source ${event.source}`);
1176e80583aSopenharmony_ci        if (event.source == SourceType.Mouse) {
1186e80583aSopenharmony_ci          Log.showDebug(TAG, `Mouse keyName ${this.bundleName + this.abilityName + this.moduleName}`);
1196e80583aSopenharmony_ci          AppStorage.setOrCreate('selectDesktopAppItem', this.bundleName + this.abilityName + this.moduleName);
1206e80583aSopenharmony_ci        } else {
1216e80583aSopenharmony_ci          AppStorage.setOrCreate('selectDesktopAppItem', '');
1226e80583aSopenharmony_ci        }
1236e80583aSopenharmony_ci      })
1246e80583aSopenharmony_ci    )
1256e80583aSopenharmony_ci  }
1266e80583aSopenharmony_ci}