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 { CommonConstants } from '@ohos/common'; 17import { PresetStyleConstants } from '@ohos/common'; 18import { LayoutViewModel } from '@ohos/common'; 19import { AppGridStyleConfig } from '@ohos/common'; 20import AppcenterConstants from './constants/AppcenterConstants'; 21 22/** 23 * style config of AppCenter 24 */ 25export default class AppCenterGridStyleConfig extends AppGridStyleConfig { 26 27 mPadding = PresetStyleConstants.DEFAULT_APP_CENTER_PADDING; 28 29 protected constructor() { 30 super(); 31 } 32 33 /** 34 * Obtains the AppCenterGridStyleConfig instance. 35 * 36 * @return AppCenterGridStyleConfig 37 */ 38 static getInstance(): AppCenterGridStyleConfig { 39 if (globalThis.AppCenterGridStyleConfigInstance == null) { 40 globalThis.AppCenterGridStyleConfigInstance = new AppCenterGridStyleConfig(); 41 } 42 globalThis.AppCenterGridStyleConfigInstance.initConfig(); 43 return globalThis.AppCenterGridStyleConfigInstance; 44 } 45 46 initConfig(): void { 47 const result = LayoutViewModel.getInstance().calculateAppCenter(); 48 this.mColumnsGap = result.mColumnsGap; 49 this.mRowsGap = result.mRowsGap; 50 this.mColumns = result.mColumns; 51 this.mRows = result.mRows; 52 this.mGridWidth = result.mGridWidth; 53 this.mGridHeight = result.mGridHeight; 54 this.mPadding = result.mPadding; 55 this.mNameSize = result.mNameSize; 56 this.mNameHeight = result.mNameHeight; 57 this.mIconSize = result.mIconSize; 58 this.mNameLines = result.mNameLines; 59 this.mIconMarginVertical = result.mIconMarginVertical; 60 this.mAppItemSize = result.mAppItemSize; 61 this.mAppCenterMarginLeft=result.mAppCenterMarginLeft 62 } 63 64 getConfigLevel(): string { 65 return CommonConstants.LAYOUT_CONFIG_LEVEL_FEATURE; 66 } 67 68 getFeatureName(): string { 69 return AppcenterConstants.FEATURE_NAME; 70 } 71}