diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 2bafd45442deb2d29e51ba7259d4743a668db8da..60cb1d6da59ded6e12ec872a63dc97b48065583d 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -23,38 +23,71 @@ const DOMAIN = 0x0000; let modelDataList: ModelData[] = []; export default class EntryAbility extends UIAbility { + // [Start LifeCycle_Ability_Create] onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); // Get eventHub. let eventhub = this.context.eventHub; modelDataList.push(new ModelData('Ability Create', new Date().toLocaleString())); + // [StartExclude LifeCycle_Ability_Create] + // [Start LifeCycle_Ability_Create_Emit] eventhub.emit('ability', modelDataList); + // [End LifeCycle_Ability_Create_Emit] + // [EndExclude LifeCycle_Ability_Create] hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } + // [End LifeCycle_Ability_Create] + // [Start LifeCycle_Ability_Destroy] + // [Start LifeCycle_Ability_Destroy_Emit] + // [Start LifeCycle_Ability_Destroy_Off] onDestroy(): void { + // [StartExclude LifeCycle_Ability_Destroy_Emit] + // [StartExclude LifeCycle_Ability_Destroy_Off] let eventhub = this.context.eventHub; modelDataList.push(new ModelData('Ability Destroy', new Date().toLocaleString())); + // [EndExclude LifeCycle_Ability_Destroy_Emit] + // [StartExclude LifeCycle_Ability_Destroy] eventhub.emit('ability', modelDataList); + // [EndExclude LifeCycle_Ability_Destroy_Off] + // [StartExclude LifeCycle_Ability_Destroy_Emit] this.context.eventHub.off('ability'); + // [EndExclude LifeCycle_Ability_Destroy_Emit] + // [EndExclude LifeCycle_Ability_Destroy] hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); } - + // [End LifeCycle_Ability_Destroy_Off] + // [End LifeCycle_Ability_Destroy_Emit] + // [End LifeCycle_Ability_Destroy] + + // [Start LifeCycle_Ability_WindowStage] + // [Start LifeCycle_Ability_WindowStage_Emit] + // [Start LifeCycle_Ability_WindowStage_AppStorage] + // [Start LifeCycle_Ability_WindowStage_LoadContent] onWindowStageCreate(windowStage: window.WindowStage): void { + // [StartExclude LifeCycle_Ability_WindowStage_Emit] + // [StartExclude LifeCycle_Ability_WindowStage_AppStorage] + // [StartExclude LifeCycle_Ability_WindowStage_LoadContent] // Main window is created, set main page for this ability. hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); let eventhub = this.context.eventHub; modelDataList.push(new ModelData('WindowStage Create', new Date().toLocaleString())); + // [EndExclude LifeCycle_Ability_WindowStage_Emit] + // [StartExclude LifeCycle_Ability_WindowStage] eventhub.emit('ability', modelDataList); + // [EndExclude LifeCycle_Ability_WindowStage_AppStorage] + // [StartExclude LifeCycle_Ability_WindowStage_Emit] // Storage parameters. AppStorage.setOrCreate("modelDataList", modelDataList); + // [EndExclude LifeCycle_Ability_WindowStage_LoadContent] + // [StartExclude LifeCycle_Ability_WindowStage_AppStorage] // Set UI loading. windowStage.loadContent('pages/Index', (err) => { if (err.code) { @@ -63,32 +96,57 @@ export default class EntryAbility extends UIAbility { } hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); }); + // [EndExclude LifeCycle_Ability_WindowStage_AppStorage] + // [EndExclude LifeCycle_Ability_WindowStage_Emit] + // [EndExclude LifeCycle_Ability_WindowStage] } + // [End LifeCycle_Ability_WindowStage_LoadContent] + // [End LifeCycle_Ability_WindowStage_AppStorage] onWindowStageDestroy(): void { + // [StartExclude LifeCycle_Ability_WindowStage_Emit] let eventhub = this.context.eventHub; modelDataList.push(new ModelData('WindowStage Destroy', new Date().toLocaleString())); + // [EndExclude LifeCycle_Ability_WindowStage_Emit] + // [StartExclude LifeCycle_Ability_WindowStage] eventhub.emit('ability', modelDataList); + // [EndExclude LifeCycle_Ability_WindowStage] + // [StartExclude LifeCycle_Ability_WindowStage_Emit] // Main window is destroyed, release UI related resources. hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + // [EndExclude LifeCycle_Ability_WindowStage_Emit] } + // [End LifeCycle_Ability_WindowStage_Emit] + // [End LifeCycle_Ability_WindowStage] + // [Start LifeCycle_Ability_Fore_Back] + // [Start LifeCycle_Ability_Fore_Back_Emit] onForeground(): void { + // [StartExclude LifeCycle_Ability_Fore_Back_Emit] let eventhub = this.context.eventHub; modelDataList.push(new ModelData('Ability Foreground', new Date().toLocaleString())); + // [EndExclude LifeCycle_Ability_Fore_Back_Emit] + // [StartExclude LifeCycle_Ability_Fore_Back] eventhub.emit('ability', modelDataList); + // [EndExclude LifeCycle_Ability_Fore_Back] // Ability has brought to foreground. hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); } onBackground(): void { + // [StartExclude LifeCycle_Ability_Fore_Back_Emit] let eventhub = this.context.eventHub; modelDataList.push(new ModelData('Ability Background', new Date().toLocaleString())); + // [EndExclude LifeCycle_Ability_Fore_Back_Emit] + // [StartExclude LifeCycle_Ability_Fore_Back] eventhub.emit('ability', modelDataList); + // [EndExclude LifeCycle_Ability_Fore_Back] // Ability has back to background. hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); } + // [End LifeCycle_Ability_Fore_Back_Emit] + // [Start LifeCycle_Ability_Fore_Back] } \ 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 f1dfae97873c04a0ae9816c9c8381a771730f995..a04d7bc8f8affdcfaff02a172eb1b550cf85a7fc 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -13,22 +13,27 @@ * limitations under the License. */ +// [Start LifeCycle_Index_List] import { common } from '@kit.AbilityKit'; import { ModelData } from '../model/ModelData'; +// [Start LifeCycle_Index_Title] +// src/main/ets/pages/Index.ets @Entry @Component struct Index { - private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + // [StartExclude LifeCycle_Index_Title] @StorageProp('modelDataList') modelDataList: ModelData[] = []; - private listScroller: ListScroller = new ListScroller(); + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; aboutToAppear(): void { this.context.eventHub.on('ability', (modelDataList: ModelData[]) => { this.modelDataList = modelDataList; }) } + // [EndExclude LifeCycle_Index_Title] + // [StartExclude LifeCycle_Index_List] @Builder titleBuilder() { Column() { @@ -48,10 +53,14 @@ struct Index { }) .height(36) } + // [EndExclude LifeCycle_Index_List] build() { Navigation() { + // [StartExclude LifeCycle_Index_Title] + // [Start LifeCycle_Index_Content] Column() { + // [StartExclude LifeCycle_Index_List] Row() { Text($r('app.string.home_log')) .width(158) @@ -65,8 +74,9 @@ struct Index { .height(56) .justifyContent(FlexAlign.Start) .padding({ left: 12 }) + // [EndExclude LifeCycle_Index_List] - List({ space: 5, scroller: this.listScroller }) { + List({ space: 5 }) { ForEach(this.modelDataList, (modelData: ModelData) => { ListItem() { Row({ space: 10 }) { @@ -95,9 +105,15 @@ struct Index { .height('100%') .width('100%') .padding(16) + // [End LifeCycle_Index_Content] + // [EndExclude LifeCycle_Index_Title] } + // [StartExclude LifeCycle_Index_List] .title({ builder: this.titleBuilder, height: 112 }) .navBarWidth(300) .backgroundColor('rgb(241, 243, 245)') + // [EndExclude LifeCycle_Index_List] } -} \ No newline at end of file +} +// [End LifeCycle_Index_Title] +// [Start LifeCycle_Index_List] \ No newline at end of file