1/* 2 * Copyright (c) 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 screenManager from '@ohos/base/src/main/ets/manager/ScreenManager'; 17import { Constants } from '../model/common/Constants'; 18import { Log } from '@ohos/base/src/main/ets/utils/Log'; 19 20const IMAGE_SCREEN_RATIO = 0.8 21 22@Component 23export struct NoPhotoIndexComponent { 24 private TAG: string = 'NoPhotoIndexComponent'; 25 index: number; 26 27 // set an initial value temporarily, later change to 0. 28 @State imageSize: number = 0; 29 private reSizeFunc = this.reSizeLayout.bind(this); 30 31 aboutToAppear(): void { 32 Log.info(this.TAG, 'aboutToAppear'); 33 screenManager.on(screenManager.ON_WIN_SIZE_CHANGED, this.reSizeFunc); 34 this.updateImageSize(); 35 } 36 37 reSizeLayout() { 38 this.updateImageSize(); 39 } 40 41 updateImageSize() { 42 let winWidth = screenManager.getWinWidth(); 43 let winHeightHalf = screenManager.getWinHeight() / 2; 44 this.imageSize 45 = (winWidth < winHeightHalf) ? (winWidth * IMAGE_SCREEN_RATIO) : (winHeightHalf * IMAGE_SCREEN_RATIO); 46 Log.info(this.TAG, `window size: ${winWidth}, ${winHeightHalf} ,empty photos or album picture size = ${this.imageSize}`); 47 } 48 49 build() { 50 Row() { 51 Column() { 52 Image((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r("app.media.photo_empty") : $r("app.media.album_empty")) 53 .height(this.imageSize) 54 .width(this.imageSize) 55 .margin({ 56 bottom: $r('app.float.image_margin_horizontal'), 57 }) 58 if (Constants.DISTRIBUTED_ALBUM_PAGE_INDEX == this.index) { 59 Text($r('app.string.no_distributed_photo_head_title_album')) 60 .fontSize($r('sys.float.ohos_id_text_size_headline8')) 61 .fontFamily($r('app.string.id_text_font_family_regular')) 62 .fontColor($r('sys.color.ohos_id_color_text_primary')) 63 .margin({ 64 left: $r('app.float.max_padding_start'), 65 right: $r('app.float.max_padding_start'), 66 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'), 67 }) 68 } else { 69 Text((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.string.no_photo_head_title_timeline') 70 : $r('app.string.no_photo_head_title_album')) 71 .fontSize($r('sys.float.ohos_id_text_size_headline8')) 72 .fontWeight(FontWeight.Medium) 73 .fontColor($r('sys.color.ohos_id_color_text_primary')) 74 .margin({ 75 left: $r('app.float.max_padding_start'), 76 right: $r('app.float.max_padding_start'), 77 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'), 78 }) 79 Text((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.string.no_photo_sub_title_timeline') 80 : $r('app.string.no_photo_sub_title_album')) 81 .fontSize($r('sys.float.ohos_id_text_size_body2')) 82 .fontFamily($r('app.string.id_text_font_family_regular')) 83 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 84 .margin({ 85 left: $r('app.float.max_padding_start'), 86 right: $r('app.float.max_padding_start'), 87 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'), 88 }) 89 } 90 } 91 .width('100%') 92 .margin({ top: $r('app.float.appbar_max_height') }) 93 } 94 .width('100%') 95 .height('100%') 96 .alignItems(VerticalAlign.Top) 97 .justifyContent(FlexAlign.Start) 98 } 99}