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 { ResourceManager } from '../manager/ResourceManager'; 176e80583aSopenharmony_ciimport { PresetStyleConstants } from '../constants/PresetStyleConstants'; 186e80583aSopenharmony_ci 196e80583aSopenharmony_ci@Component 206e80583aSopenharmony_ciexport struct AppName { 216e80583aSopenharmony_ci nameSize: number = 0; 226e80583aSopenharmony_ci nameHeight: number = 0; 236e80583aSopenharmony_ci bundleName: string = ''; 246e80583aSopenharmony_ci moduleName: string = ''; 256e80583aSopenharmony_ci labelId: number = 0; 266e80583aSopenharmony_ci nameFontColor: string = '#ffffff'; 276e80583aSopenharmony_ci @State @Watch('updateName') appName: string = ''; 286e80583aSopenharmony_ci useCache: boolean = true; 296e80583aSopenharmony_ci nameLines: number = PresetStyleConstants.DEFAULT_APP_NAME_LINES; 306e80583aSopenharmony_ci marginTop: number = PresetStyleConstants.DEFAULT_ICON_NAME_GAP; 316e80583aSopenharmony_ci marginLeft: number = PresetStyleConstants.DEFAULT_DESKTOP_NAME_MARGIN; 326e80583aSopenharmony_ci private mResourceManager = ResourceManager.getInstance(); 336e80583aSopenharmony_ci 346e80583aSopenharmony_ci aboutToAppear(): void { 356e80583aSopenharmony_ci this.mResourceManager = ResourceManager.getInstance(); 366e80583aSopenharmony_ci this.updateName(); 376e80583aSopenharmony_ci } 386e80583aSopenharmony_ci 396e80583aSopenharmony_ci public appNameLoadCallback = (name: string) => { 406e80583aSopenharmony_ci this.appName = name; 416e80583aSopenharmony_ci } 426e80583aSopenharmony_ci 436e80583aSopenharmony_ci private updateName() { 446e80583aSopenharmony_ci if (this.mResourceManager) { 456e80583aSopenharmony_ci this.mResourceManager.getAppNameWithCache(this.labelId, this.bundleName, this.moduleName, 466e80583aSopenharmony_ci this.appName, this.appNameLoadCallback); 476e80583aSopenharmony_ci } 486e80583aSopenharmony_ci } 496e80583aSopenharmony_ci 506e80583aSopenharmony_ci build() { 516e80583aSopenharmony_ci Column() { 526e80583aSopenharmony_ci Text(this.appName) 536e80583aSopenharmony_ci .fontSize(this.nameSize) 546e80583aSopenharmony_ci .fontColor(this.nameFontColor) 556e80583aSopenharmony_ci .textOverflow({overflow: TextOverflow.Ellipsis}) 566e80583aSopenharmony_ci .textAlign(TextAlign.Center) 576e80583aSopenharmony_ci .maxLines(this.nameLines) 586e80583aSopenharmony_ci .lineHeight(this.nameSize) 596e80583aSopenharmony_ci } 606e80583aSopenharmony_ci .height(this.nameHeight) 616e80583aSopenharmony_ci .margin({top: this.marginTop,left: this.marginLeft, right: this.marginLeft}) 626e80583aSopenharmony_ci } 636e80583aSopenharmony_ci}