diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 5aab3743e8628e14cf25cb69f791d19d0a700b75..7ce1ae2009f9d4df7fb0dde85d9fd23f5b91a5cb 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { common } from '@kit.AbilityKit'; import { UIAbility , Want ,AbilityConstant } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit' @@ -32,8 +33,19 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability Logger.info(TAG, 'EntryAbility onWindowStageCreate'); - requestFullScreen(windowStage, this.context); - windowStage.loadContent('pages/Index'); + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + return; + } + }); + windowStage.getMainWindow((err, data) => { + if (err.code) { + return; + } + let windowClass: window.Window = data; + let uiContext: UIContext = windowClass.getUIContext(); + requestFullScreen(windowStage, uiContext); + }); } onWindowStageDestroy(): void { @@ -51,12 +63,9 @@ export default class EntryAbility extends UIAbility { Logger.info(TAG, 'MainAbility onBackground'); } - - - } -function requestFullScreen(windowStage: window.WindowStage, context: Context): void { +function requestFullScreen(windowStage: window.WindowStage, UIContext: UIContext): void { windowStage.getMainWindow((err: BusinessError, data: window.Window) => { if (err.code) { Logger.error(TAG, 'Failed to obtain the main window. Cause: ' + JSON.stringify(err)); @@ -71,7 +80,7 @@ function requestFullScreen(windowStage: window.WindowStage, context: Context): v let type = window.AvoidAreaType.TYPE_SYSTEM; // Get status bar height. let area: window.AvoidArea = windowClass.getWindowAvoidArea(type); - getDeviceSize(context, area); + getDeviceSize(UIContext, area); let promise: Promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); promise.then(() => { windowStage.getMainWindowSync().setWindowBackgroundColor('#F1F3F5'); @@ -85,14 +94,16 @@ function requestFullScreen(windowStage: window.WindowStage, context: Context): v }); } -function getDeviceSize(context: Context, area: window.AvoidArea): void { +function getDeviceSize(UIContext: UIContext, area: window.AvoidArea): void { + let context = UIContext.getHostContext() as common.UIAbilityContext; + // Get device height. window.getLastWindow(context).then((data: window.Window) => { let properties = data.getWindowProperties(); if (area.topRect.height > 0) { - AppStorage.setOrCreate('statusBarHeight', px2vp(area.topRect.height)); + AppStorage.setOrCreate('statusBarHeight', UIContext.px2vp(area.topRect.height)); } - AppStorage.setOrCreate('deviceHeight', px2vp(properties.windowRect.height)); - AppStorage.setOrCreate('deviceWidth', px2vp(properties.windowRect.width)); + AppStorage.setOrCreate('deviceHeight', UIContext.px2vp(properties.windowRect.height)); + AppStorage.setOrCreate('deviceWidth', UIContext.px2vp(properties.windowRect.width)); }); } \ No newline at end of file diff --git a/entry/src/main/ets/pages/ForEachListPage.ets b/entry/src/main/ets/pages/ForEachListPage.ets index 3ca74ee73410824b4ba85fde8291f5ed374bf282..dd2a827fdb904b696376cb525ecad8cf40e8eb1d 100644 --- a/entry/src/main/ets/pages/ForEachListPage.ets +++ b/entry/src/main/ets/pages/ForEachListPage.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import { common } from '@kit.AbilityKit'; import { LearningResource } from '../model/LearningResource'; import { ObservedArray } from '../utils/ObservedArray'; import { ArticleCardView } from '../components/ArticleCardView'; @@ -33,6 +34,9 @@ function bufferToString(buffer: ArrayBufferLike): string { @Entry @Component export struct ForEachListPage { + UIContext = this.getUIContext() + context = this.UIContext.getHostContext() as common.UIAbilityContext; + // [StartExclude ForEachListPage1_start] @State articleList: LearningResource[] = []; @State collectedIds: ObservedArray = ['1', '2', '3', '4', '5', '6']; @@ -48,7 +52,7 @@ export struct ForEachListPage { } getArticleModelObjFromJSON() { - getContext(this).resourceManager.getRawFileContent('article1000.json').then(value => { + this.context.resourceManager.getRawFileContent('article1000.json').then(value => { let jsonObj = JSON.parse(bufferToString(value.buffer)) as LearningResource[]; let resources: LearningResource[] = []; jsonObj.forEach((res: LearningResource) => { diff --git a/entry/src/main/ets/pages/LazyForEachListPage.ets b/entry/src/main/ets/pages/LazyForEachListPage.ets index 3b49f9126ec3b7839c474ba31a9e067ad050c5a6..e3378d5fde02d830d708d0d65a303b289c9f053e 100644 --- a/entry/src/main/ets/pages/LazyForEachListPage.ets +++ b/entry/src/main/ets/pages/LazyForEachListPage.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import { common } from '@kit.AbilityKit'; import { LearningResource } from '../model/LearningResource'; import ArticleListData from '../model/ArticleListData'; import { ObservedArray } from '../utils/ObservedArray'; @@ -37,6 +38,9 @@ function bufferToString(buffer: ArrayBufferLike): string { @Entry @Component export struct LazyForEachListPage { + UIContext = this.getUIContext() + context = this.UIContext.getHostContext() as common.UIAbilityContext; + // [StartExclude LazyForEachListPage3_start] // [StartExclude LazyForEachListPage2_start] // [StartExclude LazyForEachListPage4_start] @@ -54,7 +58,7 @@ export struct LazyForEachListPage { } getArticleModelObjFromJSON() { - getContext(this).resourceManager.getRawFileContent('article1000.json').then(value => { + this.context.resourceManager.getRawFileContent('article1000.json').then(value => { let jsonObj = JSON.parse(bufferToString(value.buffer)) as LearningResource[]; let resources: LearningResource[] = []; jsonObj.forEach((res: LearningResource) => {