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