diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets index b3c40963b8bdb39a4ff02bac91ed7c934a9fe4e8..48d7c5ca0b9628bd20fca1d728108eb621b8cd1a 100644 --- a/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets @@ -38,17 +38,20 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { AppStorage.setOrCreate('context', windowStage); windowStage.getMainWindow((err: BusinessError, data) => { - let errCode: number = err.code; // The settings window is displayed in full screen - data.setWindowLayoutFullScreen(true); + data.setWindowLayoutFullScreen(true) + .then(() => { + console.info('Succeeded in setting the window layout to full-screen mode.'); + }).catch((err: BusinessError) => { + console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); + }); // Set the top status bar to be hidden let names: Array<'status' | 'navigation'> = []; - data.setWindowSystemBarEnable(names, (err: BusinessError) => { - if (err.code) { - console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the system bar to be visible.'); + data.setWindowSystemBarEnable(names) + .then(() => { + console.info('Succeeded in setting the system bar to be invisible.'); + }).catch((err: BusinessError) => { + console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); }); }) // ... diff --git a/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets b/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets index 3a5702d9d5cc9b12ef0100cf1c6995d250e58280..6635c82299749469c60f268405654db48fbf6361 100644 --- a/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets +++ b/ArkUI/entry/src/main/ets/pages/ExcavationScreenAdaptation.ets @@ -20,7 +20,8 @@ // [Start extract_screen_adaption_page] import { display, window } from '@kit.ArkUI'; import { common } from '@kit.AbilityKit'; -import { batteryInfo } from '@kit.BasicServicesKit'; +import { BusinessError, batteryInfo } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; class TextMargin { left: number = 0; // Status bar left offset @@ -40,15 +41,20 @@ struct Index { AppStorage.get('context'); // Get UIAbilityContext aboutToAppear(): void { - this.displayClass = display.getDefaultDisplaySync(); - display.getDefaultDisplaySync().getCutoutInfo((err, data) => { - if (err.code !== 0) { - console.log('getCutoutInfo failed. error is:', JSON.stringify(err)); - return; - } - this.boundingRect = data.boundingRects; - this.topTextMargin = this.getBoundingRectPosition(); - }) + try { + this.displayClass = display.getDefaultDisplaySync(); + display.getDefaultDisplaySync().getCutoutInfo((err, data) => { + if (err.code !== 0) { + console.log('getCutoutInfo failed. error is:', JSON.stringify(err)); + return; + } + this.boundingRect = data.boundingRects; + this.topTextMargin = this.getBoundingRectPosition(); + }) + } catch (error) { + let err = error as BusinessError; + hilog.error(0x000, 'testTag', `err.code=${err.code}, err.message=${err.message}`); + } // Get hour let hours = this.date.getHours(); // Get minute @@ -63,17 +69,31 @@ struct Index { window.getLastWindow(this.context, async (err, data) => { if (err.code !== 0) { console.log('getLastWindow failed. error is:', JSON.stringify(err)); - data.setWindowSystemBarEnable(['status', 'navigation']); - data.setWindowLayoutFullScreen(false); + data.setWindowSystemBarEnable(['status', 'navigation']) + .then(() => { + hilog.info(0x000, 'testTag', `setWindowSystemBarEnable succeed.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', + `setWindowSystemBarEnable failed. err.code=${err.code}, err.message=${err.message}`); + }) + data.setWindowLayoutFullScreen(false) + .then(() => { + hilog.info(0x000, 'testTag', `setWindowLayoutFullScreen succeed.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', + `setWindowLayoutFullScreen failed. err.code=${err.code}, err.message=${err.message}`); + }) } }) } } - /** - * Calculate the left and right margins of the unusable areas of the punch hole screen - * @returns {TextMargin} Objects that include left/right offsets - */ + /** + * Calculate the left and right margins of the unusable areas of the punch hole screen + * @returns {TextMargin} Objects that include left/right offsets + */ getBoundingRectPosition(): TextMargin { if (this.boundingRect !== null && this.displayClass !== null && this.boundingRect[0] !== undefined) { // Distance from the right of the unavailable area to the right edge of the screen: screen width minus left width and unavailable area width @@ -103,10 +123,15 @@ struct Index { .width('100%') .height('100%') .onClick(() => { - this.getUIContext().getPromptAction().showToast({ - message: 'This function is not yet developed', - duration: 2000 - }) + try { + this.getUIContext().getPromptAction().showToast({ + message: 'This function is not yet developed', + duration: 2000 + }) + } catch (error) { + let err = error as BusinessError; + hilog.error(0x000, 'testTag', `showToast failed. err.code=${err.code}, err.message=${err.message}`); + } }) Column() { Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween }) {