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 */ 15import { ResourceManager } from '@ohos/common'; 16import { RecentsStyleConstants } from '../constants/RecentsStyleConstants'; 17 18const TAG = 'Recent-RecentMissionAppName'; 19 20/** 21 * App name component for recent missions. 22 */ 23@Component 24export default struct RecentMissionAppName { 25 @Prop @Watch("updateName") appName: string; 26 @State nameSize: number = RecentsStyleConstants.DEFAULT_FONT_SIZE; 27 @State nameMargin: number = RecentsStyleConstants.APP_NAME_MARGIN; 28 @State name: string = '' 29 @Prop bundleName: string; 30 @Prop moduleName: string; 31 @Prop labelId: string; 32 private mResourceManager; 33 34 aboutToAppear(): void { 35 this.mResourceManager = ResourceManager.getInstance(); 36 this.updateName(); 37 } 38 39 /** 40 * The callback of recent missions app name. 41 * 42 * @param {string} name - the value get from ResourceManager 43 */ 44 appNameLoadCallback(name: string): void { 45 this.name = name; 46 } 47 48 /** 49 * Update the app name of recent missions. 50 */ 51 updateName(): void { 52 if (this.bundleName && this.bundleName.length > 0 && this.mResourceManager) { 53 this.mResourceManager.getAppNameWithCache(this.labelId, 54 this.bundleName, this.moduleName, this.appName, this.appNameLoadCallback.bind(this)); 55 } 56 } 57 58 build() { 59 Column() { 60 Text(this.name) 61 .fontSize(this.nameSize) 62 .fontColor(RecentsStyleConstants.DEFAULT_FONT_COLOR) 63 .textOverflow({overflow: TextOverflow.Ellipsis}) 64 .margin({ left: this.nameMargin }) 65 } 66 } 67}