• 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 {
17  CommonConstants,
18  LayoutViewModel,
19  AppListStyleConfig
20} from '@ohos/common';
21import FeatureConstants from './constants/FeatureConstants';
22
23/**
24 * Form style config
25 */
26export class FormStyleConfig extends AppListStyleConfig {
27
28  mFormWidth: Map<string,number> = new Map<string,number>();
29
30  mFormHeight: Map<string,number> = new Map<string,number>();
31
32  /**
33   * Form name size
34   */
35  mFormNameSize = 20;
36
37  /**
38   * Form name height
39   */
40  mFolderNameHeight = 25;
41
42  /**
43   * Form dimension width 1 * 2
44   */
45  mDimensionWidth_1_2 = 54;
46
47  /**
48   * Form dimension height 1 * 2
49   */
50  mDimensionHeight_1_2 = 128;
51
52  /**
53   * Form dimension width 2 * 2
54   */
55  mDimensionWidth_2_2 = 128;
56
57  /**
58   * Form dimension height 2 * 2
59   */
60  mDimensionHeight_2_2 = 128;
61
62  /**
63   * Form dimension width 2 * 4
64   */
65  mDimensionWidth_2_4 = 128;
66
67  /**
68   * Form dimension height 2 * 4
69   */
70  mDimensionHeight_2_4 = 202;
71
72  /**
73   * Form dimension width 4 * 4
74   */
75  mDimensionWidth_4_4 = 202;
76
77  /**
78   * Form dimension height 4 * 4
79   */
80  mDimensionHeight_4_4 = 202;
81
82  /**
83   * Form list blur
84   */
85  mBackdropBlur = 20;
86
87  protected constructor() {
88    super();
89  }
90
91  /**
92   * Get form style configuration instance.
93   *
94   * @return {object} FormStyleConfig singleton
95   */
96  static getInstance(): FormStyleConfig {
97    if (globalThis.FormStyleConfigInstance == null) {
98      globalThis.FormStyleConfigInstance = new FormStyleConfig();
99    }
100    globalThis.FormStyleConfigInstance.initConfig();
101    return globalThis.FormStyleConfigInstance;
102  }
103
104  /**
105   * Init form style configuration.
106   */
107  initConfig(): void {
108    const result = LayoutViewModel.getInstance().calculateForm();
109    this.mFormWidth.set(CommonConstants.CARD_DIMENSION_1x2.toString(), result.widthDimension1);
110    this.mFormHeight.set(CommonConstants.CARD_DIMENSION_1x2.toString(), result.heightDimension1);
111
112    this.mFormWidth.set(CommonConstants.CARD_DIMENSION_2x2.toString(), result.widthDimension2);
113    this.mFormHeight.set(CommonConstants.CARD_DIMENSION_2x2.toString(), result.heightDimension2);
114
115    this.mFormWidth.set(CommonConstants.CARD_DIMENSION_2x4.toString(), result.widthDimension3);
116    this.mFormHeight.set(CommonConstants.CARD_DIMENSION_2x4.toString(), result.heightDimension3);
117
118    this.mFormWidth.set(CommonConstants.CARD_DIMENSION_4x4.toString(), result.widthDimension4);
119    this.mFormHeight.set(CommonConstants.CARD_DIMENSION_4x4.toString(), result.heightDimension4);
120
121    this.mFormWidth.set(CommonConstants.CARD_DIMENSION_2x1.toString(), result.widthDimension5);
122    this.mFormHeight.set(CommonConstants.CARD_DIMENSION_2x1.toString(), result.heightDimension5);
123
124    this.mFormWidth.set(CommonConstants.CARD_DIMENSION_1x1.toString(), result.widthDimension6);
125    this.mFormHeight.set(CommonConstants.CARD_DIMENSION_1x1.toString(), result.heightDimension6);
126
127    this.mFormWidth.set(CommonConstants.CARD_DIMENSION_6x4.toString(), result.widthDimension7);
128    this.mFormHeight.set(CommonConstants.CARD_DIMENSION_6x4.toString(), result.heightDimension7);
129
130    this.mIconNameMargin = result.mIconNameMargin;
131  }
132
133  /**
134   * Get form style configuration level.
135   *
136   * @return {string} feature-level layout configuration
137   */
138  getConfigLevel(): string {
139    return CommonConstants.LAYOUT_CONFIG_LEVEL_FEATURE;
140  }
141
142  /**
143   * Get form style feature name.
144   *
145   * @return {string} feature name
146   */
147  getFeatureName(): string {
148    return FeatureConstants.FEATURE_NAME;
149  }
150}
151