1/* 2 * Copyright (c) 2023 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 { StateManager, UpdateAction } from '../manager/StateManager'; 17 18/** 19 * 获取显示进度值 20 * 21 * @param progress 进度值 22 * @return 显示进度值 23 */ 24function getDisplayProgress(progress): number { 25 let displayProgress = 0; 26 if (!isNaN(progress)) { 27 displayProgress = (progress).toFixed(0); 28 } 29 return displayProgress; 30} 31 32/** 33 * 下载进度组件 34 * 35 * @since 2022-06-06 36 */ 37@Component 38export struct ProgressContent { 39 @StorageProp('updateStatus') 40 private updateStatus: number = AppStorage.Get('updateStatus'); 41 @StorageProp('downloadProgress') 42 private downloadProgress: number = AppStorage.Get('downloadProgress'); 43 44 @Builder ProgressView() { 45 Stack({ alignContent: Alignment.Center }) { 46 Progress({ value: this.downloadProgress, style: ProgressStyle.Ring }) 47 .style({ strokeWidth: $r('app.float.progress_stroke_width') }) 48 .color($r('app.color.blue')) 49 .width($r('app.float.new_version_progress_bar_size')) 50 Flex({ alignItems: ItemAlign.Baseline, justifyContent: FlexAlign.Center }) { 51 Text(`${getDisplayProgress(this.downloadProgress)}`) 52 .fontColor(Color.Black) 53 .fontSize($r('app.float.text_size_progress_bar')) 54 .fontWeight(FontWeight.Medium) 55 .margin({ right: $r('app.float.progress_number_margin_right') }) 56 Text('%') 57 .fontColor(Color.Black) 58 .fontSize($r('app.float.text_size_progress_bar_percent')) 59 .fontWeight(FontWeight.Medium) 60 .opacity(0.6) 61 } 62 } 63 .width($r('app.float.new_version_progress_bar_size')) 64 .height($r('app.float.new_version_progress_bar_size')) 65 } 66 67 build() { 68 Column() { 69 if (StateManager.isAllowExecute(this.updateStatus, UpdateAction.SHOW_PROCESS_VIEW)) { 70 Flex().height($r('app.float.new_version_progress_bar_margin_top')) 71 this.ProgressView() 72 Flex().height($r('app.float.new_version_progress_bar_margin_bottom')) 73 Text(StateManager.getDownloadStateText(this.updateStatus)) 74 .fontSize($r('app.float.text_size_body')) 75 .fontWeight(FontWeight.Regular) 76 .opacity(0.6) 77 .margin({ bottom: $r('app.float.new_version_download_status_label_margin_bottom')}) 78 } else { 79 Column() { 80 Image($r('app.media.logo')) 81 .height($r('app.float.progress_logo_other_height')) 82 .width($r('app.float.progress_logo_other_width')) 83 } 84 .padding({ 85 top: $r('app.float.progress_logo_other_padding_top'), 86 bottom: $r('app.float.progress_logo_other_padding_bottom') 87 }) 88 } 89 }.flexShrink(0) 90 } 91}