diff --git a/common/mediaCommon/src/main/ets/utils/BreakpointSystem.ets b/common/mediaCommon/src/main/ets/utils/BreakpointSystem.ets index d19517a620447ed29eb180f8b6cc1eab42735371..e1a5789bf1ad5e9f625c222fa741adea9454d318 100644 --- a/common/mediaCommon/src/main/ets/utils/BreakpointSystem.ets +++ b/common/mediaCommon/src/main/ets/utils/BreakpointSystem.ets @@ -22,6 +22,8 @@ declare interface BreakPointTypeOption { lg?: T } +const uiContext: UIContext | undefined = AppStorage.get('uiContext') as UIContext; + export class BreakpointType { options: BreakPointTypeOption; @@ -43,9 +45,9 @@ export class BreakpointType { export class BreakpointSystem { private currentBreakpoint: string = BreakpointConstants.BREAKPOINT_SM; - private smListener: mediaquery.MediaQueryListener = mediaquery.matchMediaSync(BreakpointConstants.RANGE_SM); - private mdListener: mediaquery.MediaQueryListener = mediaquery.matchMediaSync(BreakpointConstants.RANGE_MD); - private lgListener: mediaquery.MediaQueryListener = mediaquery.matchMediaSync(BreakpointConstants.RANGE_LG); + private smListener: mediaquery.MediaQueryListener | undefined = uiContext?.getMediaQuery().matchMediaSync(BreakpointConstants.RANGE_SM); + private mdListener: mediaquery.MediaQueryListener | undefined = uiContext?.getMediaQuery().matchMediaSync(BreakpointConstants.RANGE_MD); + private lgListener: mediaquery.MediaQueryListener | undefined = uiContext?.getMediaQuery().matchMediaSync(BreakpointConstants.RANGE_LG); private updateCurrentBreakpoint(breakpoint: string): void { if (this.currentBreakpoint !== breakpoint) { @@ -71,17 +73,17 @@ export class BreakpointSystem { } public register(): void { - this.smListener = mediaquery.matchMediaSync(BreakpointConstants.RANGE_SM); - this.smListener.on('change', this.isBreakpointSM); - this.mdListener = mediaquery.matchMediaSync(BreakpointConstants.RANGE_MD); - this.mdListener.on('change', this.isBreakpointMD); - this.lgListener = mediaquery.matchMediaSync(BreakpointConstants.RANGE_LG); - this.lgListener.on('change', this.isBreakpointLG); + this.smListener = uiContext?.getMediaQuery().matchMediaSync(BreakpointConstants.RANGE_SM); + this.smListener?.on('change', this.isBreakpointSM); + this.mdListener = uiContext?.getMediaQuery().matchMediaSync(BreakpointConstants.RANGE_MD); + this.mdListener?.on('change', this.isBreakpointMD); + this.lgListener = uiContext?.getMediaQuery().matchMediaSync(BreakpointConstants.RANGE_LG); + this.lgListener?.on('change', this.isBreakpointLG); } public unregister(): void { - this.smListener.off('change', this.isBreakpointSM); - this.mdListener.off('change', this.isBreakpointMD); - this.lgListener.off('change', this.isBreakpointLG); + this.smListener?.off('change', this.isBreakpointSM); + this.mdListener?.off('change', this.isBreakpointMD); + this.lgListener?.off('change', this.isBreakpointLG); } } \ No newline at end of file diff --git a/features/musicList/src/main/ets/components/Header.ets b/features/musicList/src/main/ets/components/Header.ets index de5c031bd1bea9366caa797bd4d04abef0f6c7eb..eee4c830125a8a161fa57cc230aaaf4d50be7e68 100644 --- a/features/musicList/src/main/ets/components/Header.ets +++ b/features/musicList/src/main/ets/components/Header.ets @@ -63,7 +63,7 @@ export struct Header { if (canIUse(HeaderConstants.SYSCAP_ETHERNET)) { menuItem.value = HeaderConstants.AUDIO_DEVICE_SERVICE; menuItem.action = (): void => { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: HeaderConstants.AUDIO_DEVICE_SERVICE, duration: HeaderConstants.TOAST_DURATION }); diff --git a/features/musicList/src/main/ets/components/Player.ets b/features/musicList/src/main/ets/components/Player.ets index 0180f13c81970f281eec767d3d44b869d6c5b54b..de49d77050c9e74b81b20aa39aeeee7c45a553e7 100644 --- a/features/musicList/src/main/ets/components/Player.ets +++ b/features/musicList/src/main/ets/components/Player.ets @@ -20,6 +20,7 @@ import { BreakpointConstants, StyleConstants } from '@ohos/constantsCommon'; import { BreakpointType, Logger, MediaService, SongItem } from '@ohos/mediaCommon'; import { PlayerConstants } from '../constants/PlayerConstants'; import { MusicControlComponent } from './MusicControlComponent'; +import { common } from '@kit.AbilityKit'; @Preview @Component @@ -36,6 +37,7 @@ export struct Player { @StorageLink('deviceHeight') deviceHeight: number = 0; private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Vertical }); private backDisplaySyncSlow: displaySync.DisplaySync | undefined = undefined; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; private drawFrame: (value: displaySync.IntervalInfo) => void = (value: displaySync.IntervalInfo) => { if (this.imageRotate >= 360 ) { this.imageRotate = 0; @@ -191,11 +193,11 @@ export struct Player { .justifyContent(FlexAlign.End) .transition(TransitionEffect.translate({ y: 1000 }).animation({ curve: curves.springMotion(0.6, 0.8) })) .onAppear(() => { - window.getLastWindow(getContext(this)).then((windowStage: window.Window) => { + window.getLastWindow(this.context).then((windowStage: window.Window) => { let area = windowStage.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); - this.topArea = px2vp(area.topRect.height); + this.topArea = this.getUIContext().px2vp(area.topRect.height); let bottomArea = windowStage.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); - this.bottomArea = px2vp(bottomArea.bottomRect.height); + this.bottomArea = this.getUIContext().px2vp(bottomArea.bottomRect.height); Logger.info('bottomArea ' + this.bottomArea) if (this.topArea > 0) { windowStage.setWindowLayoutFullScreen(true); @@ -211,9 +213,9 @@ export struct Player { .onDisAppear(() => { this.componentHeight = 0; this.isShowPlay = false; - window.getLastWindow(getContext(this)).then((windowStage: window.Window) => { + window.getLastWindow(this.context).then((windowStage: window.Window) => { let area = windowStage.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); - let topHeight = px2vp(area.topRect.height); + let topHeight = this.getUIContext().px2vp(area.topRect.height); if (topHeight > 0) { windowStage.setWindowLayoutFullScreen(false); } diff --git a/features/musicList/src/main/ets/lyric/LrcView.ets b/features/musicList/src/main/ets/lyric/LrcView.ets index 84e85529867ef8923d85cd17fb0d11874b28d4f9..eb714005d4f7b46a9221cd75f9ff03a4059a6cf8 100644 --- a/features/musicList/src/main/ets/lyric/LrcView.ets +++ b/features/musicList/src/main/ets/lyric/LrcView.ets @@ -81,7 +81,7 @@ export default struct shiLrcView { * Initial position of the first line of the lyrics. */ private initFirstLineY: number = 0; - private animator: AnimatorResult = Animator.create({ + private animator: AnimatorResult = this.getUIContext().createAnimator({ duration: 400, easing: 'linear', delay: 0, @@ -207,7 +207,7 @@ export default struct shiLrcView { this.animator.finish(); } - this.animator = Animator.create({ + this.animator = this.getUIContext().createAnimator({ duration: 400, easing: 'linear', delay: 0, diff --git a/products/phone/src/main/ets/entryability/EntryAbility.ets b/products/phone/src/main/ets/entryability/EntryAbility.ets index 1540b53fd6b1f0cbfb9f34728f39e87a574e7ec5..e617cbb6e1da95de9b9e2571e0b526a291d47dbd 100644 --- a/products/phone/src/main/ets/entryability/EntryAbility.ets +++ b/products/phone/src/main/ets/entryability/EntryAbility.ets @@ -42,6 +42,7 @@ export default class EntryAbility extends UIAbility { }) windowStage.loadContent('pages/Index', (err) => { + 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;