From a60f1f2f3ca21e3c51d02f2ea31fa0a20fd54241 Mon Sep 17 00:00:00 2001 From: rex <1491721419@qq.com> Date: Thu, 30 Oct 2025 14:14:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=9F=E5=BC=83=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EntryAbilityExtactScreenAdaption.ets | 19 +++--- .../ets/pages/ExcavationScreenAdaptation.ets | 65 +++++++++++++------ 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityExtactScreenAdaption.ets index b3c40963..48d7c5ca 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 3a5702d9..6635c822 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 }) { -- Gitee