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 AbilityConstant from '@ohos.app.ability.AbilityConstant'; 17import hilog from '@ohos.hilog'; 18import UIAbility from '@ohos.app.ability.UIAbility'; 19import Want from '@ohos.app.ability.Want'; 20import window from '@ohos.window'; 21import Constants from '../common/Constants'; 22import { GlobalContext } from '../common/MediaAssetThumbnailLoader'; 23 24export default class EntryAbility extends UIAbility { 25 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 26 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate', JSON.stringify(want), JSON.stringify(launchParam)); 27 GlobalContext.getContext().setObject('context', this.context); 28 } 29 30 onDestroy() { 31 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); 32 } 33 34 onWindowStageCreate(windowStage: window.WindowStage) { 35 // Main window is created, set main page for this ability 36 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 37 38 windowStage.loadContent('pages/Index', (err, data) => { 39 if (err.code) { 40 hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 41 return; 42 } 43 hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); 44 }); 45 windowStage.getMainWindow().then(windowClass => { 46 try { 47 windowClass.setWindowSystemBarProperties({ 48 statusBarColor: Constants.THEME_COLOR, 49 statusBarContentColor: '#000000', 50 }, (err) => { 51 if (err.code) { 52 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 53 return; 54 } 55 console.info('Succeeded in setting the system bar properties.'); 56 }) 57 let orientation = window.Orientation.AUTO_ROTATION; 58 windowClass.setPreferredOrientation(orientation, (err) => { 59 if (err.code) { 60 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err)); 61 return; 62 } 63 console.info('Succeeded in setting window orientation.'); 64 }) 65 } catch (exception) { 66 console.error('Failed to set system bar to be invisible. Cause: ' + JSON.stringify(exception)); 67 } 68 }) 69 } 70 71 onWindowStageDestroy() { 72 // Main window is destroyed, release UI related resources 73 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); 74 } 75 76 onForeground() { 77 // Ability has brought to foreground 78 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); 79 } 80 81 onBackground() { 82 // Ability has back to background 83 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); 84 } 85} 86