diff --git a/commons/base/src/main/ets/entryability/EntryAbility.ets b/commons/base/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..43b29604a0a176be8138bcc6459e1e511fd6d469 --- /dev/null +++ b/commons/base/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { UIAbility } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG = 'EntryAbility'; + +export default class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage): void { + hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + AppStorage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); + hilog.info(0x0000, TAG, 'Succeeded in loading the content.'); + }); + } +} diff --git a/commons/base/src/main/ets/utils/DisplayUtil.ets b/commons/base/src/main/ets/utils/DisplayUtil.ets index b0fd76257966c9496f0493a39dd0598b437bddb3..abb96c540382b45ca6f1d818e6eb570bc9b448c7 100644 --- a/commons/base/src/main/ets/utils/DisplayUtil.ets +++ b/commons/base/src/main/ets/utils/DisplayUtil.ets @@ -14,6 +14,7 @@ */ import { display } from '@kit.ArkUI'; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); export class DisplayUtil { static getFoldCreaseRegion(): void { @@ -22,7 +23,7 @@ export class DisplayUtil { let foldRegion: display.FoldCreaseRegion = display.getCurrentFoldCreaseRegion(); let rect: display.Rect = foldRegion.creaseRects[0]; // Height of the avoidance area in the upper half screen and height of the avoidance area. - let creaseRegion: number[] = [px2vp(rect.top), px2vp(rect.height)]; + let creaseRegion: number[] = [uiContext!.px2vp(rect.top), px2vp(rect.height)]; AppStorage.setOrCreate('creaseRegion', creaseRegion); } } diff --git a/features/home/src/main/ets/view/BannerView.ets b/features/home/src/main/ets/view/BannerView.ets index 2fce5e9259888b7bc6dcb5b9bf3800d822375b05..581c95b423de7aaac0414b15e196b84ba393ceee 100644 --- a/features/home/src/main/ets/view/BannerView.ets +++ b/features/home/src/main/ets/view/BannerView.ets @@ -289,7 +289,7 @@ export struct BannerView { getBannerNewHeight(windowWidth: number): string { // Obtain the window width and subtract the blank parts on both sides. - let result: number = px2vp(windowWidth) - new BreakpointType(HomeConstants.VIDEO_GRID_MARGIN[0], + let result: number = this.getUIContext().px2vp(windowWidth) - new BreakpointType(HomeConstants.VIDEO_GRID_MARGIN[0], HomeConstants.VIDEO_GRID_MARGIN[1], HomeConstants.VIDEO_GRID_MARGIN[2]).getValue(this.currentWidthBreakpoint) - HomeConstants.LG_SIDEBAR_WIDTH; // Calculate the width of a single image based on the percent. diff --git a/features/home/src/main/ets/view/DailyVideo.ets b/features/home/src/main/ets/view/DailyVideo.ets index 781f5fa0777e9b9b552b88cf0de2fc0df2fa4bd5..1cc3275835a58b4f649047a77a9fbce5fec4df5e 100644 --- a/features/home/src/main/ets/view/DailyVideo.ets +++ b/features/home/src/main/ets/view/DailyVideo.ets @@ -245,7 +245,7 @@ export struct DailyVideo { getDailyVideoHeight(currentWidthBreakpoint: string, windowWidth: number, isMain: boolean): string { // Obtain the window width and subtract the blank parts on both sides. - let result: number = px2vp(windowWidth) - new BreakpointType(HomeConstants.VIDEO_GRID_MARGIN[0], + let result: number = this.getUIContext().px2vp(windowWidth) - new BreakpointType(HomeConstants.VIDEO_GRID_MARGIN[0], HomeConstants.VIDEO_GRID_MARGIN[1], HomeConstants.VIDEO_GRID_MARGIN[2]).getValue(this.currentWidthBreakpoint) - HomeConstants.VIDEO_GRID_ITEM_SPACE; // Calculate the width of a single image based on the number of grid columns. diff --git a/features/home/src/main/ets/view/NewVideoRelease.ets b/features/home/src/main/ets/view/NewVideoRelease.ets index 031e2279a789e5bab2493ea9e2bcb8aa7ff8e20f..a7b19ff5e0d9943d0479082b886abad9bebadebe 100644 --- a/features/home/src/main/ets/view/NewVideoRelease.ets +++ b/features/home/src/main/ets/view/NewVideoRelease.ets @@ -75,7 +75,7 @@ export struct NewVideoRelease { } getNewVideoHeight(currentWidthBreakpoint: string, windowWidth: number): string { - let result: number = px2vp(windowWidth) - new BreakpointType(HomeConstants.VIDEO_GRID_MARGIN[0], + let result: number = this.getUIContext().px2vp(windowWidth) - new BreakpointType(HomeConstants.VIDEO_GRID_MARGIN[0], HomeConstants.VIDEO_GRID_MARGIN[1], HomeConstants.VIDEO_GRID_MARGIN[2]).getValue(this.currentWidthBreakpoint); if (currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG) { result = result - HomeConstants.LG_SIDEBAR_WIDTH; diff --git a/features/home/src/main/ets/view/RecommendedVideo.ets b/features/home/src/main/ets/view/RecommendedVideo.ets index bca7aa4d93b3270b0fe1763348067319ead71d1a..7738d545f903234fb8053ee64a395ef0a941f70f 100644 --- a/features/home/src/main/ets/view/RecommendedVideo.ets +++ b/features/home/src/main/ets/view/RecommendedVideo.ets @@ -78,14 +78,14 @@ export struct RecommendedVideo { } // Obtains all attributes of a component. let modePosition: componentUtils.ComponentInfo = - componentUtils.getRectangleById(JSON.stringify(item)); + this.getUIContext().getComponentUtils().getRectangleById(JSON.stringify(item)); let windowOffset = modePosition.windowOffset; let size = modePosition.size; // Obtains the height of the component from the top. - let rectTop: number = px2vp(windowOffset.y); - let rectTop2: number = px2vp(windowOffset.y + Math.floor(size.height)); + let rectTop: number = this.getUIContext().px2vp(windowOffset.y); + let rectTop2: number = this.getUIContext().px2vp(windowOffset.y + Math.floor(size.height)); // Obtains the width of the component from the left. - let rectLeft: number = px2vp(windowOffset.x); + let rectLeft: number = this.getUIContext().px2vp(windowOffset.x); let topHeightNeeded: number = new BreakpointType(HomeConstants.VIDEO_DIALOG_HEIGHTS[0], HomeConstants.VIDEO_DIALOG_HEIGHTS[1], HomeConstants.VIDEO_DIALOG_HEIGHTS[2]) .getValue(this.currentWidthBreakpoint) + rectTop - rectTop2; @@ -197,7 +197,7 @@ export struct RecommendedVideo { getGridHeight(videoGridColumn: string, currentWidthBreakpoint: string, windowWidth: number): string { // Obtain the window width and subtract the blank parts on both sides. - let result: number = px2vp(windowWidth) - new BreakpointType(HomeConstants.VIDEO_GRID_MARGIN[0], + let result: number = this.getUIContext().px2vp(windowWidth) - new BreakpointType(HomeConstants.VIDEO_GRID_MARGIN[0], HomeConstants.VIDEO_GRID_MARGIN[1], HomeConstants.VIDEO_GRID_MARGIN[2]).getValue(this.currentWidthBreakpoint); if (currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG) { result = result - HomeConstants.LG_SIDEBAR_WIDTH; diff --git a/features/videoDetail/src/main/ets/view/VideoDetail.ets b/features/videoDetail/src/main/ets/view/VideoDetail.ets index a5db64fed2ee1d9a71b3adeedc05cc6ea7403ac8..560d9eacc906a9452ab60d369bf932eb8f302b07 100644 --- a/features/videoDetail/src/main/ets/view/VideoDetail.ets +++ b/features/videoDetail/src/main/ets/view/VideoDetail.ets @@ -180,12 +180,12 @@ export struct VideoDetail { // [StartExclude VideoDetail] let height: number = DetailConstants.COMMENT_IMAGE_MIN_HEIGHT_NUMBER + (Number(newValue.width) - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) / - (px2vp(this.windowWidth) * DetailConstants.COMMENTS_AREA_PERCENT - + (this.getUIContext().px2vp(this.windowWidth) * DetailConstants.COMMENTS_AREA_PERCENT - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) * (DetailConstants.COMMENT_IMAGE_MAX_HEIGHT_NUMBER - DetailConstants.COMMENT_IMAGE_MIN_HEIGHT_NUMBER); let width: number = DetailConstants.COMMENT_IMAGE_MIN_WIDTH_NUMBER + (Number(newValue.width) - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) / - (px2vp(this.windowWidth) * DetailConstants.COMMENTS_AREA_PERCENT - + (this.getUIContext().px2vp(this.windowWidth) * DetailConstants.COMMENTS_AREA_PERCENT - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) * (DetailConstants.COMMENT_IMAGE_MAX_WIDTH_NUMBER - DetailConstants.COMMENT_IMAGE_MIN_WIDTH_NUMBER); this.commentImgHeight = JSON.stringify(height); @@ -222,7 +222,7 @@ export struct VideoDetail { // [EndExclude VideoDetail] .sideBarWidth($r('app.float.side_bar_min_width')) .minSideBarWidth($r('app.float.side_bar_min_width')) - .maxSideBarWidth(px2vp(this.windowWidth * DetailConstants.COMMENTS_AREA_PERCENT)) + .maxSideBarWidth(this.getUIContext().px2vp(this.windowWidth * DetailConstants.COMMENTS_AREA_PERCENT)) // [End VideoDetail] } .height(CommonConstants.FULL_PERCENT)