From 7e839f121fa690de28c5fde8faf5da8a3c2f018a Mon Sep 17 00:00:00 2001 From: hzt Date: Tue, 13 May 2025 15:26:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BA=9F=E5=BC=83api=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- features/home/src/main/ets/view/RecommendedVideo.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/home/src/main/ets/view/RecommendedVideo.ets b/features/home/src/main/ets/view/RecommendedVideo.ets index bca7aa4..904d18c 100644 --- a/features/home/src/main/ets/view/RecommendedVideo.ets +++ b/features/home/src/main/ets/view/RecommendedVideo.ets @@ -78,7 +78,7 @@ 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. -- Gitee From 165ded3223a280332d061ffeaf58c74cd95e4c2f Mon Sep 17 00:00:00 2001 From: hzt Date: Tue, 13 May 2025 16:47:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BA=9F=E5=BC=83api=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 35 +++++++++++++++++++ .../base/src/main/ets/utils/DisplayUtil.ets | 3 +- .../home/src/main/ets/view/BannerView.ets | 2 +- .../home/src/main/ets/view/DailyVideo.ets | 2 +- .../src/main/ets/view/NewVideoRelease.ets | 2 +- .../src/main/ets/view/RecommendedVideo.ets | 8 ++--- .../src/main/ets/view/VideoDetail.ets | 6 ++-- 7 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 commons/base/src/main/ets/entryability/EntryAbility.ets 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 0000000..43b2960 --- /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 b0fd762..abb96c5 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 2fce5e9..581c95b 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 781f5fa..1cc3275 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 031e227..a7b19ff 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 904d18c..7738d54 100644 --- a/features/home/src/main/ets/view/RecommendedVideo.ets +++ b/features/home/src/main/ets/view/RecommendedVideo.ets @@ -82,10 +82,10 @@ export struct RecommendedVideo { 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 a5db64f..560d9ea 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) -- Gitee