From a498657cab948bc69ed77b72467d09548ed22040 Mon Sep 17 00:00:00 2001 From: "OWNEROR-41FNVD0\\lenovo" Date: Thu, 8 May 2025 14:56:30 +0800 Subject: [PATCH] =?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 --- entry/src/main/ets/constants/CommonConstants.ets | 5 ----- entry/src/main/ets/pages/MiniWindowPage.ets | 4 ++-- entry/src/main/ets/pages/NavigationRedirectPage.ets | 4 ++-- entry/src/main/ets/pages/ResizeWindowPage.ets | 6 +++--- entry/src/main/ets/pages/RouterRedirect.ets | 5 +++-- entry/src/main/ets/pages/RouterRedirectPage.ets | 4 ++-- entry/src/main/ets/view/MiniWindowComponent.ets | 7 ++++--- entry/src/main/ets/view/NavigationRedirectComponent.ets | 3 ++- entry/src/main/ets/view/PipWindowComponent.ets | 7 ++++--- entry/src/main/ets/view/ResizeWindowComponent.ets | 3 ++- entry/src/main/ets/view/SubWindowComponentRouter.ets | 2 +- entry/src/main/ets/viewmodel/AVPlayerDemo.ets | 3 +-- 12 files changed, 26 insertions(+), 27 deletions(-) diff --git a/entry/src/main/ets/constants/CommonConstants.ets b/entry/src/main/ets/constants/CommonConstants.ets index 611729e..a3e1321 100644 --- a/entry/src/main/ets/constants/CommonConstants.ets +++ b/entry/src/main/ets/constants/CommonConstants.ets @@ -58,10 +58,5 @@ export default class CommonConstants { * Default subwindow size coefficient. */ static readonly WINDOW_COEFFICIENT: number = 0.3; - - /** - * Subwindow avoidance area. - */ - static readonly DEFAULT_HEIGHT: number = vp2px(56); } diff --git a/entry/src/main/ets/pages/MiniWindowPage.ets b/entry/src/main/ets/pages/MiniWindowPage.ets index 1a08a4b..45653f9 100644 --- a/entry/src/main/ets/pages/MiniWindowPage.ets +++ b/entry/src/main/ets/pages/MiniWindowPage.ets @@ -63,7 +63,7 @@ struct MiniWindowPage { .onActionUpdate((event: GestureEvent) => { this.windowPosition.x += event.offsetX; this.windowPosition.y += event.offsetY; - let top = CommonConstants.DEFAULT_HEIGHT; + let top = this.getUIContext().vp2px(56); let bottom = display.getDefaultDisplaySync().height - this.subWindow.getWindowProperties().windowRect.height - top; if (this.windowPosition.y < top) { @@ -80,7 +80,7 @@ struct MiniWindowPage { } else if (event.offsetX < display.getDefaultDisplaySync().width / 2) { this.windowPosition.x = 0; } - let top = CommonConstants.DEFAULT_HEIGHT; + let top = this.getUIContext().vp2px(56); let bottom = display.getDefaultDisplaySync().height - this.subWindow.getWindowProperties().windowRect.height - top; if (this.windowPosition.y < top) { diff --git a/entry/src/main/ets/pages/NavigationRedirectPage.ets b/entry/src/main/ets/pages/NavigationRedirectPage.ets index dd9299b..7287b25 100644 --- a/entry/src/main/ets/pages/NavigationRedirectPage.ets +++ b/entry/src/main/ets/pages/NavigationRedirectPage.ets @@ -65,7 +65,7 @@ struct NavigationRedirectPage { .onActionUpdate((event: GestureEvent) => { this.windowPosition.x += event.offsetX; this.windowPosition.y += event.offsetY; - let top = CommonConstants.DEFAULT_HEIGHT; + let top = this.getUIContext().vp2px(56); let bottom = display.getDefaultDisplaySync().height - this.subWindow.getWindowProperties().windowRect.height - top; if (this.windowPosition.y < top) { @@ -82,7 +82,7 @@ struct NavigationRedirectPage { } else if (event.offsetX < display.getDefaultDisplaySync().width / 2) { this.windowPosition.x = 0; } - let top = CommonConstants.DEFAULT_HEIGHT; + let top = this.getUIContext().vp2px(56); let bottom = display.getDefaultDisplaySync().height - this.subWindow.getWindowProperties().windowRect.height - top; if (this.windowPosition.y < top) { diff --git a/entry/src/main/ets/pages/ResizeWindowPage.ets b/entry/src/main/ets/pages/ResizeWindowPage.ets index 2e7f500..5076492 100644 --- a/entry/src/main/ets/pages/ResizeWindowPage.ets +++ b/entry/src/main/ets/pages/ResizeWindowPage.ets @@ -30,7 +30,7 @@ struct ResizeWindowPage { }; @StorageLink('screenWidth') screenWidth: number = 0; @StorageLink('screenHeight') screenHeight: number = 0; - listener: inspector.ComponentObserver = inspector.createComponentObserver('COMPONENT_ID'); + listener: inspector.ComponentObserver = this.getUIContext().getUIInspector().createComponentObserver('COMPONENT_ID'); private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.All }); private callback: () => void = () => { if (!this.flag) { @@ -85,7 +85,7 @@ struct ResizeWindowPage { .onActionUpdate((event: GestureEvent) => { this.windowPosition.x += event.offsetX; this.windowPosition.y += event.offsetY; - let top = CommonConstants.DEFAULT_HEIGHT; + let top = this.getUIContext().vp2px(56); let bottom = display.getDefaultDisplaySync().height - this.subWindow.getWindowProperties().windowRect.height - top; if (this.windowPosition.y < top) { @@ -102,7 +102,7 @@ struct ResizeWindowPage { } else if (event.offsetX < display.getDefaultDisplaySync().width / 2) { this.windowPosition.x = 0; } - let top = CommonConstants.DEFAULT_HEIGHT; + let top = this.getUIContext().vp2px(56); let bottom = display.getDefaultDisplaySync().height - this.subWindow.getWindowProperties().windowRect.height - top; if (this.windowPosition.y < top) { diff --git a/entry/src/main/ets/pages/RouterRedirect.ets b/entry/src/main/ets/pages/RouterRedirect.ets index 5e38ee7..97d9069 100644 --- a/entry/src/main/ets/pages/RouterRedirect.ets +++ b/entry/src/main/ets/pages/RouterRedirect.ets @@ -33,7 +33,8 @@ struct RouterRedirect { windowClass.setWindowBackgroundColor('#00000000'); }); windowClass.moveWindowTo(CommonConstants.DEFAULT_WINDOW_X, CommonConstants.DEFAULT_WINDOW_Y); - windowClass.resize(vp2px(CommonConstants.DEFAULT_WINDOW_SIZE), vp2px(CommonConstants.DEFAULT_WINDOW_SIZE)); + windowClass.resize(this.getUIContext().vp2px(CommonConstants.DEFAULT_WINDOW_SIZE), + this.getUIContext().vp2px(CommonConstants.DEFAULT_WINDOW_SIZE)); windowClass.showWindow(); windowClass.setWindowLayoutFullScreen(true); } catch (err) { @@ -60,7 +61,7 @@ struct RouterRedirect { top: $r('app.float.common_margin') }) .onClick(() => { - router.back(); + this.getUIContext().getRouter().back(); }) } .width(CommonConstants.FULL_PERCENT) diff --git a/entry/src/main/ets/pages/RouterRedirectPage.ets b/entry/src/main/ets/pages/RouterRedirectPage.ets index 053745f..2e94126 100644 --- a/entry/src/main/ets/pages/RouterRedirectPage.ets +++ b/entry/src/main/ets/pages/RouterRedirectPage.ets @@ -66,7 +66,7 @@ struct RouterRedirectPage { .onActionUpdate((event: GestureEvent) => { this.windowPosition.x += event.offsetX; this.windowPosition.y += event.offsetY; - let top = CommonConstants.DEFAULT_HEIGHT; + let top = this.getUIContext().vp2px(56); let bottom = display.getDefaultDisplaySync().height - this.subWindow.getWindowProperties().windowRect.height - top; if (this.windowPosition.y < top) { @@ -83,7 +83,7 @@ struct RouterRedirectPage { } else if (event.offsetX < display.getDefaultDisplaySync().width / 2) { this.windowPosition.x = 0; } - let top = CommonConstants.DEFAULT_HEIGHT; + let top = this.getUIContext().vp2px(56); let bottom = display.getDefaultDisplaySync().height - this.subWindow.getWindowProperties().windowRect.height - top; if (this.windowPosition.y < top) { diff --git a/entry/src/main/ets/view/MiniWindowComponent.ets b/entry/src/main/ets/view/MiniWindowComponent.ets index 7520fac..e838c75 100644 --- a/entry/src/main/ets/view/MiniWindowComponent.ets +++ b/entry/src/main/ets/view/MiniWindowComponent.ets @@ -57,11 +57,12 @@ export struct MiniWindowComponent { return; } try { - windowClass.setUIContent('pages/MiniWindowPage',()=>{ + windowClass.setUIContent('pages/MiniWindowPage', () => { windowClass.setWindowBackgroundColor('#00000000'); }); windowClass.moveWindowTo(CommonConstants.DEFAULT_WINDOW_X, CommonConstants.DEFAULT_WINDOW_Y); - windowClass.resize(vp2px(CommonConstants.DEFAULT_WINDOW_SIZE), vp2px(CommonConstants.DEFAULT_WINDOW_SIZE)); + windowClass.resize(this.getUIContext().vp2px(CommonConstants.DEFAULT_WINDOW_SIZE), + this.getUIContext().vp2px(CommonConstants.DEFAULT_WINDOW_SIZE)); windowClass.setWindowTouchable(true); windowClass.showWindow(); windowClass.setWindowBackgroundColor(Color.Transparent.toString()); @@ -71,7 +72,7 @@ export struct MiniWindowComponent { } }) }) - .onHidden(()=>{ + .onHidden(() => { window.findWindow('MiniWindowPage').destroyWindow(); }) } diff --git a/entry/src/main/ets/view/NavigationRedirectComponent.ets b/entry/src/main/ets/view/NavigationRedirectComponent.ets index 4e83216..f837c25 100644 --- a/entry/src/main/ets/view/NavigationRedirectComponent.ets +++ b/entry/src/main/ets/view/NavigationRedirectComponent.ets @@ -48,7 +48,8 @@ export struct NavigationRedirectComponent { windowClass.setWindowBackgroundColor('#00000000'); }); windowClass.moveWindowTo(CommonConstants.DEFAULT_WINDOW_X, CommonConstants.DEFAULT_WINDOW_Y); - windowClass.resize(vp2px(CommonConstants.DEFAULT_WINDOW_SIZE), vp2px(CommonConstants.DEFAULT_WINDOW_SIZE)); + windowClass.resize(this.getUIContext().vp2px(CommonConstants.DEFAULT_WINDOW_SIZE), + this.getUIContext().vp2px(CommonConstants.DEFAULT_WINDOW_SIZE)); windowClass.setWindowTouchable(true); windowClass.showWindow(); windowClass.setWindowLayoutFullScreen(true); diff --git a/entry/src/main/ets/view/PipWindowComponent.ets b/entry/src/main/ets/view/PipWindowComponent.ets index 4bebaba..51a854e 100644 --- a/entry/src/main/ets/view/PipWindowComponent.ets +++ b/entry/src/main/ets/view/PipWindowComponent.ets @@ -18,6 +18,7 @@ import { PiPWindow, window } from '@kit.ArkUI'; import { AVPlayerDemo } from '../viewmodel/AVPlayerDemo'; import Logger from '../utils/Logger'; import CommonConstants from '../constants/CommonConstants'; +import { common } from '@kit.AbilityKit'; @Component export struct PipWindowComponent { @@ -39,14 +40,14 @@ export struct PipWindowComponent { .onLoad(() => { this.surfaceId = this.mXComponentController.getXComponentSurfaceId(); this.player = new AVPlayerDemo(this.surfaceId); - this.player.avPlayerFdSrcDemo(); + this.player.avPlayerFdSrcDemo(this.getUIContext().getHostContext() as common.UIAbilityContext); }) .onDestroy(() => { Logger.info(`XComponent onDestroy`); }) .size({ width: CommonConstants.FULL_PERCENT, - height: px2vp(CommonConstants.DEFAULT_VIDEO_HEIGHT) + height: this.getUIContext().px2vp(CommonConstants.DEFAULT_VIDEO_HEIGHT) }) } .alignItems(VerticalAlign.Center) @@ -80,7 +81,7 @@ export struct PipWindowComponent { return; } let config: PiPWindow.PiPConfiguration = { - context: getContext(this), + context: this.getUIContext().getHostContext()!, componentController: this.mXComponentController, navigationId: this.navId, templateType: PiPWindow.PiPTemplateType.VIDEO_PLAY diff --git a/entry/src/main/ets/view/ResizeWindowComponent.ets b/entry/src/main/ets/view/ResizeWindowComponent.ets index e2bfaf3..fc4e393 100644 --- a/entry/src/main/ets/view/ResizeWindowComponent.ets +++ b/entry/src/main/ets/view/ResizeWindowComponent.ets @@ -50,7 +50,8 @@ export struct ResizeWindowComponent { windowClass.setWindowBackgroundColor('#00000000'); }); windowClass.moveWindowTo(CommonConstants.DEFAULT_WINDOW_X, CommonConstants.DEFAULT_WINDOW_Y); - windowClass.resize(vp2px(CommonConstants.DEFAULT_WINDOW_SIZE), vp2px(CommonConstants.DEFAULT_WINDOW_SIZE)); + windowClass.resize(this.getUIContext().vp2px(CommonConstants.DEFAULT_WINDOW_SIZE), + this.getUIContext().vp2px(CommonConstants.DEFAULT_WINDOW_SIZE)); windowClass.showWindow(); windowClass.setWindowLayoutFullScreen(true); } catch (err) { diff --git a/entry/src/main/ets/view/SubWindowComponentRouter.ets b/entry/src/main/ets/view/SubWindowComponentRouter.ets index 0a796bf..14767dd 100644 --- a/entry/src/main/ets/view/SubWindowComponentRouter.ets +++ b/entry/src/main/ets/view/SubWindowComponentRouter.ets @@ -52,7 +52,7 @@ export struct SubWindowComponentRouter { .width(CommonConstants.FULL_PERCENT) .fontSize($r('app.float.common_button_font')) .onClick(() => { - router.pushUrl({ + this.getUIContext().getRouter().pushUrl({ url: 'pages/RouterRedirect' }); }) diff --git a/entry/src/main/ets/viewmodel/AVPlayerDemo.ets b/entry/src/main/ets/viewmodel/AVPlayerDemo.ets index 3075fe0..45c09b4 100644 --- a/entry/src/main/ets/viewmodel/AVPlayerDemo.ets +++ b/entry/src/main/ets/viewmodel/AVPlayerDemo.ets @@ -79,10 +79,9 @@ export class AVPlayerDemo { }) } - async avPlayerFdSrcDemo() { + async avPlayerFdSrcDemo(context: common.UIAbilityContext) { let avPlayer: media.AVPlayer = await media.createAVPlayer(); this.setAVPlayerCallback(avPlayer); - let context = getContext() as common.UIAbilityContext; let fileDescriptor = await context.resourceManager.getRawFd('product.mp4'); let avFileDescriptor: media.AVFileDescriptor = { fd: fileDescriptor.fd, offset: fileDescriptor.offset, length: fileDescriptor.length }; -- Gitee