16e80583aSopenharmony_ci/*
26e80583aSopenharmony_ci * Copyright (c) 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 { SettingsModel } from '../model/SettingsModel';
186e80583aSopenharmony_ciimport { StyleConstants } from '../constants/StyleConstants';
196e80583aSopenharmony_ciimport { CommonConstants } from '../constants/CommonConstants';
206e80583aSopenharmony_ciimport { PresetStyleConstants } from '../constants/PresetStyleConstants';
216e80583aSopenharmony_ciimport { layoutConfigManager } from '../layoutconfig/LayoutConfigManager';
226e80583aSopenharmony_ciimport { LauncherLayoutStyleConfig } from '../layoutconfig/LauncherLayoutStyleConfig';
236e80583aSopenharmony_ci
246e80583aSopenharmony_ciconst TAG = 'LayoutViewModel';
256e80583aSopenharmony_ci
266e80583aSopenharmony_ci/**
276e80583aSopenharmony_ci * layout viewmodel
286e80583aSopenharmony_ci */
296e80583aSopenharmony_ciexport class LayoutViewModel {
306e80583aSopenharmony_ci  private mIsPad = true;
316e80583aSopenharmony_ci  private mScreenHeight: number | undefined;
326e80583aSopenharmony_ci  private mScreenWidth: number | undefined;
336e80583aSopenharmony_ci  private mWorkSpaceHeight: number | undefined;
346e80583aSopenharmony_ci  private mDockHeight: number | undefined;
356e80583aSopenharmony_ci  private mSysUITopHeight: number | undefined;
366e80583aSopenharmony_ci  private mSysUIBottomHeight: number | undefined;
376e80583aSopenharmony_ci  private mIndicatorHeight: number | undefined;
386e80583aSopenharmony_ci  private readonly mLauncherLayoutStyleConfig: LauncherLayoutStyleConfig;
396e80583aSopenharmony_ci  private mNavigationBarStatus = false;
406e80583aSopenharmony_ci  private mDesktopGap: number | undefined;
416e80583aSopenharmony_ci  private mDesktopIconMarginLeft: number | undefined;
426e80583aSopenharmony_ci  private mDesktopIconMarginTop: number | undefined;
436e80583aSopenharmony_ci  private mDesktopNameHeight: number | undefined;
446e80583aSopenharmony_ci  private mDesktopNameLines: number | undefined;
456e80583aSopenharmony_ci  private mDesktopIconNameMargin: number | undefined;
466e80583aSopenharmony_ci  private mDesktopIconSize: number | undefined;
476e80583aSopenharmony_ci  private mDesktopItemSize: number | undefined;
486e80583aSopenharmony_ci  private mDesktopNameSize: number | undefined;
496e80583aSopenharmony_ci  private mDesktopFolderSize: number | undefined;
506e80583aSopenharmony_ci  private mGridRealHeight: number | undefined;
516e80583aSopenharmony_ci  private mCommonDialogWidth = '';
526e80583aSopenharmony_ci
536e80583aSopenharmony_ci  private constructor() {
546e80583aSopenharmony_ci    this.mLauncherLayoutStyleConfig = layoutConfigManager.getStyleConfig(
556e80583aSopenharmony_ci      LauncherLayoutStyleConfig.LAUNCHER_COMMON_STYLE_CONFIG, LauncherLayoutStyleConfig.LAUNCHER_PRODUCT_STYLE_CONFIG);
566e80583aSopenharmony_ci  }
576e80583aSopenharmony_ci
586e80583aSopenharmony_ci  /**
596e80583aSopenharmony_ci   * get the LayoutViewModel instance
606e80583aSopenharmony_ci   *
616e80583aSopenharmony_ci   * @return LayoutViewModel
626e80583aSopenharmony_ci   */
636e80583aSopenharmony_ci  static getInstance(): LayoutViewModel {
646e80583aSopenharmony_ci    if (globalThis.LayoutViewModelInstance == null) {
656e80583aSopenharmony_ci      globalThis.LayoutViewModelInstance = new LayoutViewModel();
666e80583aSopenharmony_ci      globalThis.LayoutViewModelInstance.initScreen();
676e80583aSopenharmony_ci    }
686e80583aSopenharmony_ci    return globalThis.LayoutViewModelInstance;
696e80583aSopenharmony_ci  }
706e80583aSopenharmony_ci
716e80583aSopenharmony_ci  /**
726e80583aSopenharmony_ci   * init screen info
736e80583aSopenharmony_ci   *
746e80583aSopenharmony_ci   * @param navigationBarStatus
756e80583aSopenharmony_ci   */
766e80583aSopenharmony_ci  initScreen(navigationBarStatus?: string): void {
776e80583aSopenharmony_ci    this.mScreenWidth = AppStorage.get('screenWidth');
786e80583aSopenharmony_ci    this.mScreenHeight = AppStorage.get('screenHeight');
796e80583aSopenharmony_ci    Log.showDebug(TAG, `initScreen screenWidth: ${this.mScreenWidth}, screenHeight: ${this.mScreenHeight}`);
806e80583aSopenharmony_ci    this.mSysUITopHeight = this.mLauncherLayoutStyleConfig.mSysTopHeight;
816e80583aSopenharmony_ci    this.mNavigationBarStatus = navigationBarStatus === '0' ? true : false;
826e80583aSopenharmony_ci
836e80583aSopenharmony_ci    if (!this.mNavigationBarStatus) {
846e80583aSopenharmony_ci      if (this.mScreenWidth > this.mScreenHeight) {
856e80583aSopenharmony_ci        this.mSysUIBottomHeight = this.mLauncherLayoutStyleConfig.mSysBottomHeight * this.mScreenWidth / 1280;
866e80583aSopenharmony_ci      } else {
876e80583aSopenharmony_ci        this.mSysUIBottomHeight = this.mLauncherLayoutStyleConfig.mSysBottomHeight * this.mScreenWidth / 360;
886e80583aSopenharmony_ci      }
896e80583aSopenharmony_ci    } else {
906e80583aSopenharmony_ci      this.mSysUIBottomHeight = 0;
916e80583aSopenharmony_ci    }
926e80583aSopenharmony_ci    AppStorage.setOrCreate('sysUIBottomHeight', this.mSysUIBottomHeight);
936e80583aSopenharmony_ci    this.mIndicatorHeight = this.mLauncherLayoutStyleConfig.mIndicatorHeight;
946e80583aSopenharmony_ci    Log.showDebug(TAG, `initScreen SysUIBottomHeight: ${this.mSysUIBottomHeight},
956e80583aSopenharmony_ci      IndicatorHeight: ${this.mIndicatorHeight}, SysUITopHeight: ${this.mSysUITopHeight},
966e80583aSopenharmony_ci      SysUIBottomHeight: ${this.mSysUIBottomHeight}`);
976e80583aSopenharmony_ci    this.mCommonDialogWidth = this.mLauncherLayoutStyleConfig.mCommonDialogWidth;
986e80583aSopenharmony_ci  }
996e80583aSopenharmony_ci
1006e80583aSopenharmony_ci  /**
1016e80583aSopenharmony_ci   * set device type
1026e80583aSopenharmony_ci   *
1036e80583aSopenharmony_ci   * @param deviceType: Device type
1046e80583aSopenharmony_ci   */
1056e80583aSopenharmony_ci  setDevice(deviceType: string): void {
1066e80583aSopenharmony_ci    this.mIsPad = deviceType === CommonConstants.PAD_DEVICE_TYPE;
1076e80583aSopenharmony_ci    AppStorage.setOrCreate('isPad', this.mIsPad);
1086e80583aSopenharmony_ci  }
1096e80583aSopenharmony_ci
1106e80583aSopenharmony_ci  getSysUITopHeight(): number {
1116e80583aSopenharmony_ci    return this.mSysUITopHeight;
1126e80583aSopenharmony_ci  }
1136e80583aSopenharmony_ci
1146e80583aSopenharmony_ci  getSysUIBottomHeight(): number {
1156e80583aSopenharmony_ci    return this.mSysUIBottomHeight;
1166e80583aSopenharmony_ci  }
1176e80583aSopenharmony_ci
1186e80583aSopenharmony_ci  /**
1196e80583aSopenharmony_ci   * get workSpaceHeight
1206e80583aSopenharmony_ci   */
1216e80583aSopenharmony_ci  getWorkSpaceHeight(): number {
1226e80583aSopenharmony_ci    return this.mWorkSpaceHeight;
1236e80583aSopenharmony_ci  }
1246e80583aSopenharmony_ci
1256e80583aSopenharmony_ci  /**
1266e80583aSopenharmony_ci   * get dockHeight
1276e80583aSopenharmony_ci   */
1286e80583aSopenharmony_ci  getDockHeight(): number {
1296e80583aSopenharmony_ci    return this.mDockHeight;
1306e80583aSopenharmony_ci  }
1316e80583aSopenharmony_ci
1326e80583aSopenharmony_ci  /**
1336e80583aSopenharmony_ci   * get UninstallDialogWidth
1346e80583aSopenharmony_ci   */
1356e80583aSopenharmony_ci  getCommonDialogWidth(): string {
1366e80583aSopenharmony_ci    return this.mCommonDialogWidth;
1376e80583aSopenharmony_ci  }
1386e80583aSopenharmony_ci
1396e80583aSopenharmony_ci  /**
1406e80583aSopenharmony_ci   * get indicatorHeight
1416e80583aSopenharmony_ci   */
1426e80583aSopenharmony_ci  getIndicator(): number {
1436e80583aSopenharmony_ci    return this.mIndicatorHeight;
1446e80583aSopenharmony_ci  }
1456e80583aSopenharmony_ci
1466e80583aSopenharmony_ci  /**
1476e80583aSopenharmony_ci   * calculate dock
1486e80583aSopenharmony_ci   */
1496e80583aSopenharmony_ci  calculateDock(): any {
1506e80583aSopenharmony_ci    Log.showInfo(TAG, 'calculateDock start');
1516e80583aSopenharmony_ci    let margin = this.mLauncherLayoutStyleConfig.mDockSaveMargin;
1526e80583aSopenharmony_ci    let dockGap = this.mLauncherLayoutStyleConfig.mDockGutter;
1536e80583aSopenharmony_ci    let iconSize = this.mLauncherLayoutStyleConfig.mDockIconSize;
1546e80583aSopenharmony_ci    let listItemGap = this.mLauncherLayoutStyleConfig.mDockItemGap;
1556e80583aSopenharmony_ci    let dockPadding = this.mLauncherLayoutStyleConfig.mDockPadding;
1566e80583aSopenharmony_ci    let marginBottom = this.mLauncherLayoutStyleConfig.mDockMarginBottomHideBar;
1576e80583aSopenharmony_ci    if (!this.mNavigationBarStatus) {
1586e80583aSopenharmony_ci      marginBottom = this.mLauncherLayoutStyleConfig.mDockMarginBottom;
1596e80583aSopenharmony_ci    }
1606e80583aSopenharmony_ci    let maxDockNum = 0;
1616e80583aSopenharmony_ci    let dockSpaceWidth = this.mScreenWidth - 2 * margin;
1626e80583aSopenharmony_ci    let maxRecentNum = 3;
1636e80583aSopenharmony_ci    if (this.mScreenWidth < PresetStyleConstants.DEFAULT_DOCK_RECENT_WIDTH || !this.mIsPad) {
1646e80583aSopenharmony_ci      maxRecentNum = 0;
1656e80583aSopenharmony_ci      maxDockNum = ~~((dockSpaceWidth - 2 * dockPadding + listItemGap) / (iconSize + listItemGap));
1666e80583aSopenharmony_ci    } else {
1676e80583aSopenharmony_ci      let maxNum = ~~((dockSpaceWidth - dockGap - 4 * dockPadding + 2 * listItemGap) / (iconSize + listItemGap));
1686e80583aSopenharmony_ci      maxDockNum = maxNum - maxRecentNum;
1696e80583aSopenharmony_ci    }
1706e80583aSopenharmony_ci    this.mDockHeight = iconSize + 2 * dockPadding + marginBottom;
1716e80583aSopenharmony_ci    this.mWorkSpaceHeight = this.mScreenHeight - this.mSysUIBottomHeight - this.mDockHeight;
1726e80583aSopenharmony_ci    let result = {
1736e80583aSopenharmony_ci      mDockGap: dockGap,
1746e80583aSopenharmony_ci      mIconSize: iconSize,
1756e80583aSopenharmony_ci      mListItemWidth: iconSize,
1766e80583aSopenharmony_ci      mListItemHeight: iconSize,
1776e80583aSopenharmony_ci      mListItemGap: listItemGap,
1786e80583aSopenharmony_ci      mDockPadding: dockPadding,
1796e80583aSopenharmony_ci      mMaxRecentNum: maxRecentNum,
1806e80583aSopenharmony_ci      mMaxDockNum: maxDockNum,
1816e80583aSopenharmony_ci      mDockHeight: iconSize + 2 * dockPadding,
1826e80583aSopenharmony_ci      mMarginBottom: marginBottom
1836e80583aSopenharmony_ci    };
1846e80583aSopenharmony_ci    return result;
1856e80583aSopenharmony_ci  }
1866e80583aSopenharmony_ci
1876e80583aSopenharmony_ci  /**
1886e80583aSopenharmony_ci   * calculate desktop
1896e80583aSopenharmony_ci   */
1906e80583aSopenharmony_ci  calculateDesktop(): any {
1916e80583aSopenharmony_ci    Log.showInfo(TAG, 'calculateDesktop start');
1926e80583aSopenharmony_ci    let margin = this.mLauncherLayoutStyleConfig.mMargin;
1936e80583aSopenharmony_ci    let realWidth = this.mScreenWidth - 2 * margin;
1946e80583aSopenharmony_ci    let realHeight = this.mWorkSpaceHeight - this.mIndicatorHeight - this.mSysUITopHeight;
1956e80583aSopenharmony_ci    if (this.mNavigationBarStatus) {
1966e80583aSopenharmony_ci      realHeight = realHeight - this.mLauncherLayoutStyleConfig.mSysBottomHeight;
1976e80583aSopenharmony_ci    }
1986e80583aSopenharmony_ci    let itemSize = this.mLauncherLayoutStyleConfig.mAppItemSize;
1996e80583aSopenharmony_ci    let minGutter = this.mLauncherLayoutStyleConfig.mGridGutter;
2006e80583aSopenharmony_ci    let column = ~~((realWidth + minGutter) / (itemSize + minGutter));
2016e80583aSopenharmony_ci    let userWidth = (realWidth + minGutter - (itemSize + minGutter) * column);
2026e80583aSopenharmony_ci    let gutter = (userWidth / (column - 1)) + minGutter;
2036e80583aSopenharmony_ci    let row = ~~((realHeight + gutter) / (itemSize + gutter));
2046e80583aSopenharmony_ci    let marginTop = ((realHeight + gutter - (itemSize + gutter) * row) / 2);
2056e80583aSopenharmony_ci    if (!this.mIsPad) {
2066e80583aSopenharmony_ci        if (row > 6) {
2076e80583aSopenharmony_ci            row = 6;
2086e80583aSopenharmony_ci        }
2096e80583aSopenharmony_ci
2106e80583aSopenharmony_ci        if (this.mNavigationBarStatus) {
2116e80583aSopenharmony_ci            realHeight = realHeight + this.mLauncherLayoutStyleConfig.mSysBottomHeight;
2126e80583aSopenharmony_ci        }
2136e80583aSopenharmony_ci        let remainHeight = (realHeight + gutter - (itemSize + gutter) * row)
2146e80583aSopenharmony_ci        realHeight -= remainHeight
2156e80583aSopenharmony_ci        marginTop = remainHeight / 2 + this.mSysUITopHeight
2166e80583aSopenharmony_ci    }
2176e80583aSopenharmony_ci    //set desktop icon
2186e80583aSopenharmony_ci    let ratio = this.mLauncherLayoutStyleConfig.mIconRatio;
2196e80583aSopenharmony_ci    let lines = this.mLauncherLayoutStyleConfig.mNameLines;
2206e80583aSopenharmony_ci    let appTextSize = this.mLauncherLayoutStyleConfig.mNameSize;
2216e80583aSopenharmony_ci    let nameHeight = this.mLauncherLayoutStyleConfig.mNameHeight;
2226e80583aSopenharmony_ci    let iconNameMargin = this.mLauncherLayoutStyleConfig.mIconNameGap;
2236e80583aSopenharmony_ci    let iconMarginVertical = ratio * itemSize;
2246e80583aSopenharmony_ci    let iconHeight = itemSize - 2 * iconMarginVertical - nameHeight - iconNameMargin;
2256e80583aSopenharmony_ci    let iconMarginHorizontal = (itemSize - iconHeight) / 2;
2266e80583aSopenharmony_ci    if (AppStorage.get('isPortrait') ) {
2276e80583aSopenharmony_ci      row = 11;
2286e80583aSopenharmony_ci      column = 5;
2296e80583aSopenharmony_ci    }
2306e80583aSopenharmony_ci    this.updateGrid(row, column);
2316e80583aSopenharmony_ci
2326e80583aSopenharmony_ci    this.mDesktopGap = gutter;
2336e80583aSopenharmony_ci    this.mDesktopIconMarginLeft = iconMarginHorizontal;
2346e80583aSopenharmony_ci    this.mDesktopIconMarginTop = iconMarginVertical;
2356e80583aSopenharmony_ci    this.mDesktopNameLines = lines;
2366e80583aSopenharmony_ci    this.mDesktopNameHeight = nameHeight;
2376e80583aSopenharmony_ci    this.mDesktopIconNameMargin = iconNameMargin;
2386e80583aSopenharmony_ci    this.mDesktopIconSize = iconHeight;
2396e80583aSopenharmony_ci    this.mDesktopItemSize = itemSize;
2406e80583aSopenharmony_ci    this.mDesktopNameSize = appTextSize;
2416e80583aSopenharmony_ci    this.mGridRealHeight = realHeight;
2426e80583aSopenharmony_ci    //set desktop config
2436e80583aSopenharmony_ci    let result = {
2446e80583aSopenharmony_ci      mMargin: margin,
2456e80583aSopenharmony_ci      mColumnsGap: gutter,
2466e80583aSopenharmony_ci      mRowsGap: gutter,
2476e80583aSopenharmony_ci      mColumns: column,
2486e80583aSopenharmony_ci      mRows: row,
2496e80583aSopenharmony_ci      mDesktopMarginTop: marginTop,
2506e80583aSopenharmony_ci      mGridWidth: realWidth,
2516e80583aSopenharmony_ci      mGridHeight: realHeight,
2526e80583aSopenharmony_ci      mAppItemSize: itemSize,
2536e80583aSopenharmony_ci      mNameSize: appTextSize,
2546e80583aSopenharmony_ci      mNameHeight: nameHeight,
2556e80583aSopenharmony_ci      mIconNameMargin: iconNameMargin,
2566e80583aSopenharmony_ci      mIconSize: iconHeight,
2576e80583aSopenharmony_ci      mNameLines: lines,
2586e80583aSopenharmony_ci      mIconMarginHorizontal: iconMarginHorizontal,
2596e80583aSopenharmony_ci      mIconMarginVertical: iconMarginVertical
2606e80583aSopenharmony_ci    };
2616e80583aSopenharmony_ci    return result;
2626e80583aSopenharmony_ci  }
2636e80583aSopenharmony_ci
2646e80583aSopenharmony_ci  /**
2656e80583aSopenharmony_ci   * calculate desktop folder
2666e80583aSopenharmony_ci   *
2676e80583aSopenharmony_ci   * @param layoutInfo folder layoutInfo
2686e80583aSopenharmony_ci   */
2696e80583aSopenharmony_ci  calculateFolder(layoutInfo: any): any {
2706e80583aSopenharmony_ci    Log.showInfo(TAG, 'calculateFolder start');
2716e80583aSopenharmony_ci    let itemSize = this.mLauncherLayoutStyleConfig.mAppItemSize;
2726e80583aSopenharmony_ci    let gap = this.mDesktopGap;
2736e80583aSopenharmony_ci    let iconMargin = this.mDesktopIconMarginLeft;
2746e80583aSopenharmony_ci    let gridColumn = SettingsModel.getInstance().getGridConfig().row;
2756e80583aSopenharmony_ci    let folderSize = this.mGridRealHeight / gridColumn + itemSize - iconMargin * 2;
2766e80583aSopenharmony_ci    let folderGutter = this.mLauncherLayoutStyleConfig.mFolderGutterRatio * folderSize;
2776e80583aSopenharmony_ci    let folderMargin = this.mLauncherLayoutStyleConfig.mFolderMarginRatio * folderSize;
2786e80583aSopenharmony_ci
2796e80583aSopenharmony_ci    let column = layoutInfo?.column;
2806e80583aSopenharmony_ci    let iconSize = (folderSize - folderGutter * 2 - folderMargin * 2) / column;
2816e80583aSopenharmony_ci    let nameHeight = this.mDesktopNameHeight;
2826e80583aSopenharmony_ci    let nameLines = this.mDesktopNameLines;
2836e80583aSopenharmony_ci    let iconNameMargin = this.mDesktopIconNameMargin;
2846e80583aSopenharmony_ci
2856e80583aSopenharmony_ci    this.mDesktopFolderSize = folderSize;
2866e80583aSopenharmony_ci    let result = {
2876e80583aSopenharmony_ci      mGridSize: folderSize,
2886e80583aSopenharmony_ci      mFolderAppSize: iconSize,
2896e80583aSopenharmony_ci      mFolderGridGap: folderGutter,
2906e80583aSopenharmony_ci      mGridMargin: folderMargin,
2916e80583aSopenharmony_ci      mNameHeight: nameHeight,
2926e80583aSopenharmony_ci      mNameLines: nameLines,
2936e80583aSopenharmony_ci      mIconNameMargin: iconNameMargin
2946e80583aSopenharmony_ci    };
2956e80583aSopenharmony_ci    return result;
2966e80583aSopenharmony_ci  }
2976e80583aSopenharmony_ci
2986e80583aSopenharmony_ci  /**
2996e80583aSopenharmony_ci   * calculate open folder
3006e80583aSopenharmony_ci   *
3016e80583aSopenharmony_ci   * @param openFolderConfig layoutInfo
3026e80583aSopenharmony_ci   */
3036e80583aSopenharmony_ci  calculateOpenFolder(openFolderConfig: any): any {
3046e80583aSopenharmony_ci    Log.showInfo(TAG, 'calculateOpenFolder start');
3056e80583aSopenharmony_ci    let row = openFolderConfig?.row;
3066e80583aSopenharmony_ci    let column = openFolderConfig?.column;
3076e80583aSopenharmony_ci    let gutter = this.mLauncherLayoutStyleConfig.mFolderOpenGutter;
3086e80583aSopenharmony_ci    let padding = this.mLauncherLayoutStyleConfig.mFolderOpenPADDING;
3096e80583aSopenharmony_ci    let margin = this.mLauncherLayoutStyleConfig.mFolderOpenMargin;
3106e80583aSopenharmony_ci    let title = this.mLauncherLayoutStyleConfig.mFolderOpenTitle;
3116e80583aSopenharmony_ci    let itemSize = this.mDesktopItemSize;
3126e80583aSopenharmony_ci    let layoutWidth = column * itemSize + (column - 1) * gutter + 2 * padding;
3136e80583aSopenharmony_ci    let layoutHeight = row * itemSize + (row - 1) * gutter + 2 * padding;
3146e80583aSopenharmony_ci    let layoutSwiperHeight = row * itemSize + (row - 1) * gutter + 2 * padding + itemSize;
3156e80583aSopenharmony_ci    let result = {
3166e80583aSopenharmony_ci      mOpenFolderGridWidth: layoutWidth,
3176e80583aSopenharmony_ci      mOpenFolderGridHeight: layoutHeight,
3186e80583aSopenharmony_ci      mOpenFolderSwiperHeight: layoutSwiperHeight,
3196e80583aSopenharmony_ci      mOpenFolderAddIconSize: this.mDesktopIconSize,
3206e80583aSopenharmony_ci      mOpenFolderIconSize: this.mDesktopIconSize,
3216e80583aSopenharmony_ci      mOpenFolderAppSize: this.mDesktopItemSize,
3226e80583aSopenharmony_ci      mOpenFolderAppNameSize: this.mDesktopNameSize,
3236e80583aSopenharmony_ci      mOpenFolderAppNameHeight: this.mDesktopNameHeight,
3246e80583aSopenharmony_ci      mOpenFolderGridRow: row,
3256e80583aSopenharmony_ci      mOpenFolderGridColumn: column,
3266e80583aSopenharmony_ci      mOpenFolderGridGap: gutter,
3276e80583aSopenharmony_ci      mOpenFolderGridPadding: padding,
3286e80583aSopenharmony_ci      mFolderOpenMargin: margin,
3296e80583aSopenharmony_ci      mFolderOpenTitle: title,
3306e80583aSopenharmony_ci      mOpenFolderGridIconTopPadding: this.mDesktopIconMarginTop
3316e80583aSopenharmony_ci    };
3326e80583aSopenharmony_ci    return result;
3336e80583aSopenharmony_ci  }
3346e80583aSopenharmony_ci
3356e80583aSopenharmony_ci  /**
3366e80583aSopenharmony_ci   * calculate add app
3376e80583aSopenharmony_ci   *
3386e80583aSopenharmony_ci   * @param addFolderConfig
3396e80583aSopenharmony_ci   */
3406e80583aSopenharmony_ci  calculateFolderAddList(addFolderConfig: any): any {
3416e80583aSopenharmony_ci    Log.showInfo(TAG, 'calculateFolderAddList start');
3426e80583aSopenharmony_ci    let column: number = addFolderConfig?.column;
3436e80583aSopenharmony_ci    let margin: number = this.mLauncherLayoutStyleConfig.mFolderAddGridMargin;
3446e80583aSopenharmony_ci    let saveMargin: number = PresetStyleConstants.DEFAULT_SCREEN_GRID_GAP_AND_MARGIN;
3456e80583aSopenharmony_ci    let screenGap: number = PresetStyleConstants.DEFAULT_SCREEN_GRID_GAP_AND_MARGIN;
3466e80583aSopenharmony_ci    let gap: number = this.mLauncherLayoutStyleConfig.mFolderAddGridGap;
3476e80583aSopenharmony_ci    let maxHeight: number = this.mLauncherLayoutStyleConfig.mFolderAddMaxHeight *
3486e80583aSopenharmony_ci    (this.mScreenHeight - this.mSysUITopHeight);
3496e80583aSopenharmony_ci    let toggleSize: number = this.mLauncherLayoutStyleConfig.mFolderToggleSize;
3506e80583aSopenharmony_ci    let screenColumns: number = PresetStyleConstants.DEFAULT_PHONE_GRID_APP_COLUMNS;
3516e80583aSopenharmony_ci    let textSize: number = this.mLauncherLayoutStyleConfig.mFolderAddTextSize;
3526e80583aSopenharmony_ci    let textLines: number = this.mLauncherLayoutStyleConfig.mFolderAddTextLines;
3536e80583aSopenharmony_ci    let titleSize: number = this.mLauncherLayoutStyleConfig.mFolderAddTitleSize;
3546e80583aSopenharmony_ci    let linesHeight = textSize * textLines;
3556e80583aSopenharmony_ci    let buttonSize: number = this.mLauncherLayoutStyleConfig.mFolderAddButtonSize;
3566e80583aSopenharmony_ci    let ratio: number = this.mLauncherLayoutStyleConfig.mFolderAddIconRatio;
3576e80583aSopenharmony_ci    if (this.mIsPad) {
3586e80583aSopenharmony_ci      screenColumns = PresetStyleConstants.DEFAULT_PAD_GRID_APP_COLUMNS;
3596e80583aSopenharmony_ci    }
3606e80583aSopenharmony_ci    let columnsWidth = this.mScreenWidth - 2 * saveMargin - (screenColumns - 1) * screenGap;
3616e80583aSopenharmony_ci    let columnWidth = columnsWidth / screenColumns;
3626e80583aSopenharmony_ci    let layoutWidth = columnWidth * column + (column - 1) * screenGap;
3636e80583aSopenharmony_ci    let gridSize = layoutWidth - 2 * margin;
3646e80583aSopenharmony_ci    let itemSize = (gridSize - (column - 1) * gap) / column;
3656e80583aSopenharmony_ci    let layoutHeight = layoutWidth + StyleConstants.DEFAULT_APP_ADD_TITLE_SIZE +
3666e80583aSopenharmony_ci    StyleConstants.DEFAULT_BUTTON_HEIGHT_NUMBER +
3676e80583aSopenharmony_ci    StyleConstants.DEFAULT_DIALOG_BOTTOM_MARGIN_NUMBER;
3686e80583aSopenharmony_ci    let iconSize = (1 - 2 * ratio) * itemSize - linesHeight - this.mDesktopIconNameMargin;
3696e80583aSopenharmony_ci
3706e80583aSopenharmony_ci    let result = {
3716e80583aSopenharmony_ci      mAddFolderGridWidth: gridSize,
3726e80583aSopenharmony_ci      mAddFolderDialogWidth: layoutWidth,
3736e80583aSopenharmony_ci      mAddFolderDialogHeight: layoutHeight,
3746e80583aSopenharmony_ci      mAddFolderGridGap: gap,
3756e80583aSopenharmony_ci      mAddFolderGridMargin: margin,
3766e80583aSopenharmony_ci      mAddFolderMaxHeight: maxHeight,
3776e80583aSopenharmony_ci      mFolderToggleSize: toggleSize,
3786e80583aSopenharmony_ci      mAddFolderTextSize: textSize,
3796e80583aSopenharmony_ci      mAddFolderTextLines: textLines,
3806e80583aSopenharmony_ci      mAddFolderLinesHeight: linesHeight,
3816e80583aSopenharmony_ci      mAddFolderItemSize: itemSize,
3826e80583aSopenharmony_ci      mAddFolderIconPaddingTop: itemSize * ratio,
3836e80583aSopenharmony_ci      mAddFolderIconMarginHorizontal: (itemSize - iconSize) / 2,
3846e80583aSopenharmony_ci      mAddFolderIconSize: iconSize,
3856e80583aSopenharmony_ci      mAddFolderTitleSize: titleSize,
3866e80583aSopenharmony_ci      mAddFolderButtonSize: buttonSize
3876e80583aSopenharmony_ci    };
3886e80583aSopenharmony_ci    return result;
3896e80583aSopenharmony_ci  }
3906e80583aSopenharmony_ci
3916e80583aSopenharmony_ci  /**
3926e80583aSopenharmony_ci   * calculate card form
3936e80583aSopenharmony_ci   */
3946e80583aSopenharmony_ci  calculateForm(): any {
3956e80583aSopenharmony_ci    Log.showInfo(TAG, 'calculateForm start');
3966e80583aSopenharmony_ci    let iconSize = this.mDesktopIconSize;
3976e80583aSopenharmony_ci    let folderSize = this.mDesktopFolderSize;
3986e80583aSopenharmony_ci    let itemSize = this.mDesktopItemSize;
3996e80583aSopenharmony_ci    let gap = this.mDesktopGap;
4006e80583aSopenharmony_ci    let iconMarginHorizontal = this.mDesktopIconMarginLeft;
4016e80583aSopenharmony_ci    let iconMarginVertical = this.mDesktopIconMarginTop;
4026e80583aSopenharmony_ci    let nameHeight = this.mDesktopNameHeight;
4036e80583aSopenharmony_ci    // 1x2
4046e80583aSopenharmony_ci    let widthDimension1: number = folderSize;
4056e80583aSopenharmony_ci    let heightDimension1: number = iconSize;
4066e80583aSopenharmony_ci    // 2x2
4076e80583aSopenharmony_ci    let widthDimension2 = folderSize;
4086e80583aSopenharmony_ci    let heightDimension2 = folderSize;
4096e80583aSopenharmony_ci    // 2x4
4106e80583aSopenharmony_ci    let widthDimension3 = (itemSize + gap) * 4 - gap - iconMarginHorizontal * 2;
4116e80583aSopenharmony_ci    let heightDimension3 = folderSize;
4126e80583aSopenharmony_ci    // 4x4
4136e80583aSopenharmony_ci    let widthDimension4 = widthDimension3;
4146e80583aSopenharmony_ci    let heightDimension4 = (itemSize + gap) * 4 - gap - 2 * iconMarginVertical -
4156e80583aSopenharmony_ci    nameHeight - this.mDesktopIconNameMargin;
4166e80583aSopenharmony_ci    // 2x1
4176e80583aSopenharmony_ci    let widthDimension5 = iconSize;
4186e80583aSopenharmony_ci    let heightDimension5 = folderSize;
4196e80583aSopenharmony_ci    // 1x1
4206e80583aSopenharmony_ci    let widthDimension6 = iconSize;
4216e80583aSopenharmony_ci    let heightDimension6 = iconSize;
4226e80583aSopenharmony_ci    // 6x4
4236e80583aSopenharmony_ci    let widthDimension7 = widthDimension3;
4246e80583aSopenharmony_ci    let heightDimension7 = (itemSize + gap) * 6 - gap - 2 * iconMarginVertical -
4256e80583aSopenharmony_ci      nameHeight - this.mDesktopIconNameMargin;
4266e80583aSopenharmony_ci
4276e80583aSopenharmony_ci    let result = {
4286e80583aSopenharmony_ci      widthDimension1: widthDimension1,
4296e80583aSopenharmony_ci      heightDimension1: heightDimension1,
4306e80583aSopenharmony_ci      widthDimension2: widthDimension2,
4316e80583aSopenharmony_ci      heightDimension2: heightDimension2,
4326e80583aSopenharmony_ci      widthDimension3: widthDimension3,
4336e80583aSopenharmony_ci      heightDimension3: heightDimension3,
4346e80583aSopenharmony_ci      widthDimension4: widthDimension4,
4356e80583aSopenharmony_ci      heightDimension4: heightDimension4,
4366e80583aSopenharmony_ci      widthDimension5: widthDimension5,
4376e80583aSopenharmony_ci      heightDimension5: heightDimension5,
4386e80583aSopenharmony_ci      widthDimension6: widthDimension6,
4396e80583aSopenharmony_ci      heightDimension6: heightDimension6,
4406e80583aSopenharmony_ci      widthDimension7: widthDimension7,
4416e80583aSopenharmony_ci      heightDimension7: heightDimension7,
4426e80583aSopenharmony_ci      mIconNameMargin: this.mDesktopIconNameMargin
4436e80583aSopenharmony_ci    };
4446e80583aSopenharmony_ci    return result;
4456e80583aSopenharmony_ci  }
4466e80583aSopenharmony_ci
4476e80583aSopenharmony_ci  /**
4486e80583aSopenharmony_ci   * calculate app center
4496e80583aSopenharmony_ci   */
4506e80583aSopenharmony_ci  calculateAppCenter(): any {
4516e80583aSopenharmony_ci    Log.showInfo(TAG, 'calculateAppCenter start');
4526e80583aSopenharmony_ci    let appCenterMarginLeft: number = this.mLauncherLayoutStyleConfig.mAppCenterMarginLeft;
4536e80583aSopenharmony_ci    let saveMargin: number = this.mLauncherLayoutStyleConfig.mAppCenterMargin;
4546e80583aSopenharmony_ci    let gutter: number = this.mLauncherLayoutStyleConfig.mAppCenterGutter;
4556e80583aSopenharmony_ci    let appItemSize = this.mLauncherLayoutStyleConfig.mAppCenterSize;
4566e80583aSopenharmony_ci    let width = this.mScreenWidth - 2 * appCenterMarginLeft;
4576e80583aSopenharmony_ci    let height = this.mWorkSpaceHeight;
4586e80583aSopenharmony_ci    let column = ~~((width + gutter) / (appItemSize + gutter));
4596e80583aSopenharmony_ci    let row = ~~((height + gutter) / (appItemSize + gutter));
4606e80583aSopenharmony_ci    let padding = (height - row * (appItemSize + gutter) + gutter) / 2;
4616e80583aSopenharmony_ci    let ratio = this.mLauncherLayoutStyleConfig.mAppCenterRatio;
4626e80583aSopenharmony_ci    let lines = this.mLauncherLayoutStyleConfig.mAppCenterNameLines;
4636e80583aSopenharmony_ci    let appTextSize = this.mLauncherLayoutStyleConfig.mAppCenterNameSize;
4646e80583aSopenharmony_ci    let nameHeight = lines * appTextSize;
4656e80583aSopenharmony_ci    let iconMarginVertical = ratio * appItemSize;
4666e80583aSopenharmony_ci    let iconHeight = appItemSize - 2 * iconMarginVertical - nameHeight - this.mDesktopIconNameMargin;
4676e80583aSopenharmony_ci    let result = {
4686e80583aSopenharmony_ci      mColumnsGap: gutter,
4696e80583aSopenharmony_ci      mRowsGap: gutter,
4706e80583aSopenharmony_ci      mColumns: column,
4716e80583aSopenharmony_ci      mRows: row,
4726e80583aSopenharmony_ci      mGridWidth: width,
4736e80583aSopenharmony_ci      mGridHeight: height - 2 * padding,
4746e80583aSopenharmony_ci      mPadding: padding,
4756e80583aSopenharmony_ci      mNameSize: appTextSize,
4766e80583aSopenharmony_ci      mNameHeight: nameHeight,
4776e80583aSopenharmony_ci      mIconSize: iconHeight,
4786e80583aSopenharmony_ci      mNameLines: lines,
4796e80583aSopenharmony_ci      mIconMarginVertical: iconMarginVertical,
4806e80583aSopenharmony_ci      mAppItemSize: appItemSize,
4816e80583aSopenharmony_ci      mAppCenterMarginLeft:appCenterMarginLeft
4826e80583aSopenharmony_ci    };
4836e80583aSopenharmony_ci    return result;
4846e80583aSopenharmony_ci  }
4856e80583aSopenharmony_ci
4866e80583aSopenharmony_ci  /**
4876e80583aSopenharmony_ci   * update gridConfig info
4886e80583aSopenharmony_ci   *
4896e80583aSopenharmony_ci   * @param {number} row row of grid
4906e80583aSopenharmony_ci   * @param {number} column column of grid
4916e80583aSopenharmony_ci   */
4926e80583aSopenharmony_ci  private updateGrid(row: number, column: number): void {
4936e80583aSopenharmony_ci    Log.showInfo(TAG, `updateGrid row ${row} column ${column}`);
4946e80583aSopenharmony_ci    let settingsModel = SettingsModel.getInstance();
4956e80583aSopenharmony_ci    let gridConfig = settingsModel.getGridConfig();
4966e80583aSopenharmony_ci    gridConfig.row = row;
4976e80583aSopenharmony_ci    gridConfig.column = column;
4986e80583aSopenharmony_ci    const layoutDimension = `${row}X${column}`;
4996e80583aSopenharmony_ci    gridConfig.layout = layoutDimension;
5006e80583aSopenharmony_ci    gridConfig.name = layoutDimension;
5016e80583aSopenharmony_ci  }
5026e80583aSopenharmony_ci}