diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index bb5a6d35c2785ea3d2c2d248bdef42c35cc55d86..0da01c684f39efe375cf9d8366b042154af4b7e0 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -18,13 +18,14 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { display, window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; +const TAG: string = '[EntryAbility]'; + export default class EntryAbility extends UIAbility { - public windowObj?: window.Window; private curBp: string = ''; private updateBreakpoint(windowWidth: number): void { try { - let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; + let windowWidthVp: number = windowWidth / display.getDefaultDisplaySync().densityPixels; let newBp: string = ''; if (windowWidthVp < 600) { newBp = 'sm'; @@ -37,13 +38,14 @@ export default class EntryAbility extends UIAbility { this.curBp = newBp; AppStorage.setOrCreate('currentBreakpoint', this.curBp); } - } catch (error) { - hilog.error(0X0000, 'testTag', 'updateBreakpoint catch err:', JSON.stringify(error) ?? ''); + } catch (err) { + hilog.error(0x0000, TAG, '%{public}s', + `Update breakpoint failed. code: ${(err as BusinessError).code}, message: ${(err as BusinessError).message}`); } } onCreate(): void { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); AppStorage.setOrCreate('systemColorMode', this.context.config.colorMode); this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); } @@ -58,68 +60,53 @@ export default class EntryAbility extends UIAbility { } onDestroy(): void { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onDestroy'); } onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - + hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); windowStage.getMainWindow().then((windowObj: window.Window) => { - let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; - let avoidArea = windowObj.getWindowAvoidArea(type); - let bottomRectHeight = avoidArea.bottomRect.height; + let type: window.AvoidAreaType = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; + let avoidArea: window.AvoidArea = windowObj.getWindowAvoidArea(type); + let bottomRectHeight: number = avoidArea.bottomRect.height; AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); - type = window.AvoidAreaType.TYPE_SYSTEM; - avoidArea = windowObj.getWindowAvoidArea(type); - let topRectHeight = avoidArea.topRect.height; - AppStorage.setOrCreate('topRectHeight', topRectHeight); - this.windowObj = windowObj; this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); - windowObj.on('windowSizeChange', (windowSize) => { - this.updateBreakpoint(windowSize.width); - }) - }); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; + try { + windowObj.on('windowSizeChange', (windowSize) => { + this.updateBreakpoint(windowSize.width); + }); + windowStage.loadContent('pages/Index', (error: BusinessError) => { + if (error.code) { + hilog.error(0x0000, TAG, '%{public}s', + `Failed to load the content. code: ${error.code}, message: ${error.message}`); + return; + } + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in loading the content.'); + }); + let windowClass: window.Window = windowStage.getMainWindowSync(); + windowClass.setWindowLayoutFullScreen(true); + let sysBarProps: window.SystemBarProperties = { statusBarContentColor: '#FFFFFF' }; + windowClass.setWindowSystemBarProperties(sysBarProps); + } catch (error) { + hilog.error(0x0000, TAG, '%{public}s', + `onWindowStageCreate failed. Cause code: ${error.code}, message: ${error.message}`); } - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); - }); - - let windowClass: window.Window | null = null; - windowStage.getMainWindow((err: BusinessError, data) => { - let errCode: number = err.code; - if (errCode) { - hilog.error(0x0000, 'testTag', 'Failed to obtain the main window. Cause: %{public}s', - JSON.stringify(err) ?? ''); - return; - } - windowClass = data; - hilog.info(0x0000, 'testTag', 'Succeeded in obtaining the main window.'); - - windowClass.setWindowLayoutFullScreen(true); - let sysBarProps: window.SystemBarProperties = { - statusBarContentColor: '#FFFFFF' - }; - windowClass.setWindowSystemBarProperties(sysBarProps); }) } onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy'); } onForeground(): void { // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground'); } onBackground(): void { // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); } } \ No newline at end of file diff --git a/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index 6b744d7eaa66e51e79fc4e0896e251292ee767c5..5c743a2db5c25b5955021742da064ad33e0eb5d9 100644 --- a/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -16,12 +16,14 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; +const TAG: string = '[EntryBackupAbility]'; + export default class EntryBackupAbility extends BackupExtensionAbility { async onBackup() { - hilog.info(0x0000, 'testTag', 'onBackup ok'); + hilog.info(0x0000, TAG, '%{public}s', 'onBackup ok'); } async onRestore(bundleVersion: BundleVersion) { - hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + hilog.info(0x0000, TAG, '%{public}s', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index de15566889267260c240ddf4b1a4fdedd9b066ee..4da68d18fe8d3c5a84ce56a8499e8a03cb67323f 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -16,8 +16,10 @@ import { common } from '@kit.AbilityKit'; import { display } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { DataSource, PhotoData } from '../util/DataSource'; import { BreakpointType, CommonConstants } from '../common//CommonConstants'; +import { DataSource, PhotoData } from '../util/DataSource'; + +const TAG: string = '[Index]' @Entry @Component @@ -56,10 +58,15 @@ struct Index { this.progressData = list; this.data = new DataSource(list); } catch (error) { - hilog.error(0X0000, 'Display catch err:', JSON.stringify(error) ?? ''); + hilog.error(0x0000, TAG, '%{public}s', + `Failed to set window. code: ${error.code}, message: ${error.message}`); } } + aboutToDisappear(): void { + display?.off('change'); + } + @Builder progressComponent() { Row({ space: CommonConstants.ROW_SPACE }) { @@ -122,8 +129,6 @@ struct Index { this.image(item) }, (item: string) => item) } - .onAnimationStart(() => { - }) .cachedCount(CommonConstants.SWIPER_CACHED_COUNT) .index($$this.slideIndex) .autoPlay(!this.slide ? true : false) @@ -153,6 +158,7 @@ struct Index { } }) } + .scrollBar(BarState.Off) .width(CommonConstants.FULL_PERCENT) .height(CommonConstants.FULL_PERCENT)