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 */ 15 16import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager'; 17import display from '@ohos.display' 18import Log from '../../../../../../../../common/src/main/ets/default/Log' 19import ResourceUtil from '../../../../../../../../common/src/main/ets/default/ResourceUtil' 20import CommonStyleConfiguration from '../../../../../../../../common/src/main/ets/default/StyleConfiguration' 21 22const TAG = 'StatusBarConfiguration'; 23 24var statusbarPosition; 25var shortSideLength = '0'; 26var direction = -1; 27 28var maxWidth; 29var maxHeight; 30var minHeight; 31var realWidth; 32var realHeight; 33var xCoordinate = 0; 34var yCoordinate = 0; 35 36enum Position { 37 NOT_CONFIGURED, 38 LEFT_POSITION, 39 TOP_POSITION, 40 RIGHT_POSITION, 41 BOTTOM_POSITION 42} 43 44/** 45 * Get window size. 46 */ 47class StatusBarConfiguration { 48 async initStatusBarConfiguration() { 49 Log.showInfo(TAG, 'initWindowManager'); 50 minHeight = 0; 51 52 await display.getDefaultDisplay() 53 .then(dis => { 54 Log.showInfo(TAG, `initWindowManager dis ${JSON.stringify(dis)}`); 55 maxWidth = dis.width; 56 maxHeight = dis.height; 57 Log.showInfo(TAG, `initWindowManager maxWidth ${maxWidth} maxHeight ${maxHeight} minHeight ${minHeight}`); 58 }) 59 .catch((err) => { 60 Log.showError(TAG, `getDefaultDisplay err:${JSON.stringify(err)}`); 61 }); 62 } 63 64 async getDirectionAndPosition() { 65 Log.showInfo(TAG, 'getDirectionAndPosition'); 66 await ResourceUtil.initResourceManager(AbilityManager.ABILITY_NAME_STATUS_BAR); 67 if (maxWidth > maxHeight) { 68 direction = 1; 69 } else { 70 direction = 2; 71 } 72 let style: any = CommonStyleConfiguration.getCommonStyle() 73 let deviceTypeInfo = style.deviceTypeInfo 74 if (direction == -1) { 75 Log.showInfo(TAG, 'direction is -1'); 76 statusbarPosition = await ResourceUtil.getString($r("app.string.status_bar_position_landscape")) 77 shortSideLength = deviceTypeInfo == 'phone' ? await ResourceUtil.getString($r("app.string.phone_status_bar_size_landscape")) 78 : await ResourceUtil.getString($r("app.string.status_bar_size_landscape")); 79 } else if (direction == 1) { 80 Log.showInfo(TAG, 'direction is 1'); 81 statusbarPosition = await ResourceUtil.getString($r("app.string.status_bar_position_landscape")) 82 shortSideLength = deviceTypeInfo == 'phone' ? await ResourceUtil.getString($r("app.string.phone_status_bar_size_landscape")) 83 : await ResourceUtil.getString($r("app.string.status_bar_size_landscape")); 84 } else { 85 Log.showInfo(TAG, 'direction is 2'); 86 statusbarPosition = await ResourceUtil.getString($r("app.string.status_bar_position_portrait")) 87 shortSideLength = deviceTypeInfo == 'phone' ? await ResourceUtil.getString($r("app.string.phone_status_bar_size_portrait")) 88 : await ResourceUtil.getString($r("app.string.status_bar_size_portrait")); 89 } 90 shortSideLength = parseInt(shortSideLength) + ''; 91 Log.showInfo(TAG, 'direction = ' + direction + 'statusbarPosition = ' + statusbarPosition + 92 'shortSideLength = ' + shortSideLength); 93 } 94 95/** 96 * Get status bar configuration 97 */ 98 public async getConfiguration() { 99 await this.initStatusBarConfiguration(); 100 await this.getDirectionAndPosition(); 101 let showHorizontal = false; 102 let ableToMaximize = false; 103 if (statusbarPosition == Position.TOP_POSITION || statusbarPosition == Position.BOTTOM_POSITION) { 104 Log.showInfo(TAG, `getConfiguration`); 105 showHorizontal = true; 106 minHeight = parseInt(shortSideLength); 107 realWidth = maxWidth; 108 realHeight = parseInt(shortSideLength); 109 if (statusbarPosition == Position.BOTTOM_POSITION) { 110 yCoordinate = parseInt(maxHeight) - parseInt(shortSideLength); 111 } 112 ableToMaximize = true; 113 } else if (statusbarPosition == Position.LEFT_POSITION || statusbarPosition == Position.RIGHT_POSITION) { 114 showHorizontal = false; 115 ableToMaximize = false; 116 minHeight = parseInt(shortSideLength); 117 realWidth = parseInt(shortSideLength); 118 realHeight = maxHeight; 119 if (statusbarPosition == Position.RIGHT_POSITION) { 120 xCoordinate = parseInt(maxWidth) - parseInt(shortSideLength); 121 } 122 } else { 123 realWidth = 0; 124 realHeight = 0; 125 } 126 Log.showInfo(TAG, `initWindowManager xCoordinate ${xCoordinate} yCoordinate ${yCoordinate} realWidth ${realWidth} realHeight ${realHeight}`); 127 128 var configuration = { 129 maxWidth: maxWidth, 130 maxHeight: maxHeight, 131 minHeight: minHeight, 132 showHorizontal: showHorizontal, 133 ableToMaximize: ableToMaximize, 134 direction:direction, 135 realWidth: realWidth, 136 realHeight: realHeight, 137 xCoordinate: xCoordinate, 138 yCoordinate: yCoordinate 139 } 140 return configuration; 141 } 142} 143 144let statusBarConfiguration = new StatusBarConfiguration(); 145 146export default statusBarConfiguration;