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 aboutToDisappear(): void { 38 screenManager.off(screenManager.ON_WIN_SIZE_CHANGED, this.reSizeFunc); 39 this.reSizeFunc = null; 40 } 41 42 reSizeLayout() { 43 this.updateImageSize(); 44 } 45 46 updateImageSize() { 47 let winWidth = screenManager.getWinWidth(); 48 let winHeightHalf = screenManager.getWinHeight() / 2; 49 this.imageSize 50 = (winWidth < winHeightHalf) ? (winWidth * IMAGE_SCREEN_RATIO) : (winHeightHalf * IMAGE_SCREEN_RATIO); 51 Log.info(this.TAG, `window size: ${winWidth}, ${winHeightHalf} ,empty photos or album picture size = ${this.imageSize}`); 52 } 53 54 build() { 55 Row() { 56 Column() { 57 Image((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r("app.media.photo_empty") : $r("app.media.album_empty")) 58 .height(this.imageSize) 59 .width(this.imageSize) 60 .margin({ 61 bottom: $r('app.float.image_margin_horizontal'), 62 }) 63 if (Constants.DISTRIBUTED_ALBUM_PAGE_INDEX == this.index) { 64 Text($r('app.string.no_distributed_photo_head_title_album')) 65 .fontSize($r('sys.float.ohos_id_text_size_headline8')) 66 .fontFamily($r('app.string.id_text_font_family_regular')) 67 .fontColor($r('sys.color.ohos_id_color_text_primary')) 68 .margin({ 69 left: $r('app.float.max_padding_start'), 70 right: $r('app.float.max_padding_start'), 71 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'), 72 }) 73 } else { 74 Text((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.string.no_photo_head_title_timeline') 75 : $r('app.string.no_photo_head_title_album')) 76 .fontSize($r('sys.float.ohos_id_text_size_headline8')) 77 .fontWeight(FontWeight.Medium) 78 .fontColor($r('sys.color.ohos_id_color_text_primary')) 79 .margin({ 80 left: $r('app.float.max_padding_start'), 81 right: $r('app.float.max_padding_start'), 82 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'), 83 }) 84 Text((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.string.no_photo_sub_title_timeline') 85 : $r('app.string.no_photo_sub_title_album')) 86 .fontSize($r('sys.float.ohos_id_text_size_body2')) 87 .fontFamily($r('app.string.id_text_font_family_regular')) 88 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 89 .margin({ 90 left: $r('app.float.max_padding_start'), 91 right: $r('app.float.max_padding_start'), 92 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'), 93 }) 94 } 95 } 96 .width('100%') 97 .margin({ top: $r('app.float.appbar_max_height') }) 98 } 99 .width('100%') 100 .height('100%') 101 .alignItems(VerticalAlign.Top) 102 .justifyContent(FlexAlign.Start) 103 } 104}