diff --git a/commons/base/src/main/ets/utils/AvPlayerUtil.ets b/commons/base/src/main/ets/utils/AvPlayerUtil.ets index bbbe6f116d8cda1234cb4103aaa79979ab5ccc0c..dd4d00b884ff4b168ba11dcaba08cc31cfbc8199 100644 --- a/commons/base/src/main/ets/utils/AvPlayerUtil.ets +++ b/commons/base/src/main/ets/utils/AvPlayerUtil.ets @@ -20,9 +20,11 @@ import { BusinessError } from '@kit.BasicServicesKit'; import Logger from './Logger'; import { CommonConstants } from '../constants/CommonConstants'; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); + export class AvPlayerUtil { private avPlayer?: media.AVPlayer; - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + private context: common.UIAbilityContext = uiContext?.getHostContext() as common.UIAbilityContext; private url: resourceManager.RawFileDescriptor | null = null; private surfaceId: string = ''; private sliderBegin: number = 0; diff --git a/commons/base/src/main/ets/utils/DisplayUtil.ets b/commons/base/src/main/ets/utils/DisplayUtil.ets index b0fd76257966c9496f0493a39dd0598b437bddb3..f7085d1b86271f04392efce671af0a895831e22a 100644 --- a/commons/base/src/main/ets/utils/DisplayUtil.ets +++ b/commons/base/src/main/ets/utils/DisplayUtil.ets @@ -15,6 +15,8 @@ import { display } from '@kit.ArkUI'; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); + export class DisplayUtil { static getFoldCreaseRegion(): void { if(canIUse('SystemCapability.Window.SessionManager')) { @@ -22,7 +24,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), uiContext!.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 093cbb33cd5f93522aa0cf40b8f2bf8c6541addf..2de8505081585953aa3753f7e32577d0e359b40e 100644 --- a/features/home/src/main/ets/view/BannerView.ets +++ b/features/home/src/main/ets/view/BannerView.ets @@ -299,7 +299,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/IconView.ets b/features/home/src/main/ets/view/IconView.ets index 5a529e7aa2eefe3dc3baeb87a17cddaf6728cbd9..c65aac5ca80ced868d022d35dbf39ddf8f6b8765 100644 --- a/features/home/src/main/ets/view/IconView.ets +++ b/features/home/src/main/ets/view/IconView.ets @@ -78,9 +78,9 @@ export struct IconView { getSpace(windowWidth: number, currentWidthBreakpoint: string): number { // 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.TWO) - getContext(this).resourceManager.getNumber($r('app.float.icon_img_size').id) / 2; + HomeConstants.TWO) - this.getUIContext().getHostContext()!.resourceManager.getNumber($r('app.float.icon_img_size').id) / 2; if (currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_SM) { result = (result - HomeConstants.ICONVIEW_ITEM_WIDTH[0] * CommonConstants.FOUR) / CommonConstants.FOUR; } else if (currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD) { 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 228999b7a28e171f31ec741a0a0091c0b1eca22d..584af3d482d8dd4235469f5181e8bfa558b60f1f 100644 --- a/features/home/src/main/ets/view/RecommendedVideo.ets +++ b/features/home/src/main/ets/view/RecommendedVideo.ets @@ -84,14 +84,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; @@ -172,13 +172,13 @@ export struct RecommendedVideo { .gesture(PinchGesture({ fingers: 2 }).onActionUpdate((event: GestureEvent) => { if (event.scale > 1 && this.currentWidthBreakpoint !== BreakpointConstants.BREAKPOINT_SM) { if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD) { - animateTo({ + this.getUIContext().animateTo({ duration: HomeConstants.ANIMATION_DURATION }, () => { this.videoGridColumn = CommonConstants.VIDEO_GRID_COLUMNS[1]; }) } else { - animateTo({ + this.getUIContext().animateTo({ duration: HomeConstants.ANIMATION_DURATION }, () => { this.videoGridColumn = CommonConstants.VIDEO_GRID_COLUMNS[2]; @@ -186,13 +186,13 @@ export struct RecommendedVideo { } } else if (event.scale < 1 && this.currentWidthBreakpoint !== BreakpointConstants.BREAKPOINT_SM) { if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD) { - animateTo({ + this.getUIContext().animateTo({ duration: HomeConstants.ANIMATION_DURATION }, () => { this.videoGridColumn = CommonConstants.VIDEO_GRID_COLUMNS[2]; }) } else { - animateTo({ + this.getUIContext().animateTo({ duration: HomeConstants.ANIMATION_DURATION }, () => { this.videoGridColumn = CommonConstants.VIDEO_GRID_COLUMNS[3]; @@ -207,7 +207,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/home/src/main/ets/view/VideoDialog.ets b/features/home/src/main/ets/view/VideoDialog.ets index 1d5a19d5dad128c71feac118838403621b44771d..d15f85365711996ee9d304a1aaaeef383eb4f2f1 100644 --- a/features/home/src/main/ets/view/VideoDialog.ets +++ b/features/home/src/main/ets/view/VideoDialog.ets @@ -57,7 +57,7 @@ export struct VideoDialog { private xComponentController: XComponentController = new XComponentController(); private surfaceId: string = ''; private avPlayer?: media.AVPlayer; - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + private context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; private url?: resourceManager.RawFileDescriptor; private playState: boolean = true; private controller?: CustomDialogController; diff --git a/features/videoDetail/src/main/ets/view/VideoDetail.ets b/features/videoDetail/src/main/ets/view/VideoDetail.ets index 652c7ad0222126bcd4cd348c889f12bf5fb627ad..130f69e91c2a5999751b924fe3aded89517008f6 100644 --- a/features/videoDetail/src/main/ets/view/VideoDetail.ets +++ b/features/videoDetail/src/main/ets/view/VideoDetail.ets @@ -186,12 +186,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); @@ -228,7 +228,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) diff --git a/products/phone/src/main/ets/entryability/EntryAbility.ets b/products/phone/src/main/ets/entryability/EntryAbility.ets index 72bfc4ab41cfc4ce3f2eb66ad94caaed13f84d32..c2a897e34819545b07abee3e03cc3eafad532143 100644 --- a/products/phone/src/main/ets/entryability/EntryAbility.ets +++ b/products/phone/src/main/ets/entryability/EntryAbility.ets @@ -57,6 +57,7 @@ export default class EntryAbility extends UIAbility { }); // [StartExclude EntryAbility] windowStage.loadContent('pages/Index', (err, data) => { + AppStorage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return;