From 37127a7627b299dd01f21d86dc468a3e699dc142 Mon Sep 17 00:00:00 2001 From: chyyy0213 Date: Thu, 4 May 2023 16:34:33 +0800 Subject: [PATCH] =?UTF-8?q?SceneBoard=20=E6=95=B0=E6=8D=AE=E4=BE=A7?= =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=8Cui=E4=BE=A7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chyyy0213 --- common/index.ets | 19 +- ...sitionEffect.ts => SCBTransitionEffect.ts} | 34 +- .../SCBGestureAction.ts} | 116 ++-- .../ets/WindowScene/common/SCBGestureModel.ts | 84 ++- .../{HWDividerParam.ts => SCBDividerParam.ts} | 50 +- ...SceneSession.ts => SCBRootSceneSession.ts} | 21 +- ...Session.ts => SCBSceneContainerSession.ts} | 82 ++- .../{HWSceneInfo.ts => SCBSceneInfo.ts} | 18 +- .../{HWSceneSession.ts => SCBSceneSession.ts} | 57 +- ...onManager.ts => SCBSceneSessionManager.ts} | 209 ++++--- .../screen/session/HWScreenSession.ts | 210 ------- .../screen/session/HWScreenSessionManager.ts | 131 ----- .../screen/session/SCBScreenSession.ts | 115 ++++ .../ets/default/constants/StyleConstants.ts | 11 +- .../default/manager/LauncherAbilityManager.ts | 8 +- .../src/main/ets/MainAbility/MainAbility.ts | 6 +- .../SCBDesktop.ets} | 292 +++++----- .../SCBDivider.ets} | 66 ++- .../SCBGestureNavBar.ets} | 97 ++-- .../src/main/ets/SceneBoard/SCBScene.ets | 112 ++++ .../main/ets/SceneBoard/SCBSceneContainer.ets | 156 ++++++ .../src/main/ets/SceneBoard/SCBScenePanel.ets | 523 ++++++++++++++++++ .../HWScreen.ets => SceneBoard/SCBScreen.ets} | 42 +- .../SCBWallpaper.ets} | 48 +- .../dropdownpanel/DropdownPanel.ets | 0 .../dropdownpanel/bannerNotification.ets | 0 .../common/ControlCenterConfig.ts | 0 .../common/StyleConfiguration.ts | 0 .../dropdownpanel/common/StyleManager.ts | 0 .../dropdownpanel/common/constants.ts | 0 .../dropdownpanel/common/navigationEvent.ts | 0 .../dropdownpanel/control.ets | 0 .../dropdownpanel/notification.ets | 0 .../screenlock/common/constants.ts | 0 .../screenlock/pages/SCBScreenLock.ets | 0 .../screenlock/pages/customPassword.ets | 0 .../screenlock/pages/customscreenlock.ets | 0 .../screenlock/pages/digitalPassword.ets | 0 .../screenlock/pages/journalscreenlock.ets | 0 .../screenlock/pages/mixedPassword.ets | 0 .../screenlock/pages/slidescreenlock.ets | 0 .../screenlock/vm/indexViewModel.ts | 0 .../screenlock/vm/slideScreenLockViewModel.ts | 0 .../statusbar/SCBStatusBar.ets | 0 .../statusbar/StatusBar.ets | 0 .../statusbar/StatusbarConfig.ts | 0 .../main/ets/WindowScene/HWSceneContainer.ets | 120 ---- .../src/main/ets/WindowScene/HWScenePanel.ets | 184 ------ .../phone/src/main/ets/pages/EntryView.ets | 85 ++- .../resources/base/profile/main_pages.json | 6 +- 50 files changed, 1673 insertions(+), 1229 deletions(-) rename common/src/main/ets/WindowScene/animation/{HWTransitionEffect.ts => SCBTransitionEffect.ts} (54%) rename common/src/main/ets/WindowScene/{scene/session/HWRecentViewParam.ts => common/SCBGestureAction.ts} (34%) rename product/phone/src/main/ets/WindowScene/HWScene.ets => common/src/main/ets/WindowScene/common/SCBGestureModel.ts (30%) rename common/src/main/ets/WindowScene/scene/session/{HWDividerParam.ts => SCBDividerParam.ts} (54%) rename common/src/main/ets/WindowScene/scene/session/{HWRootSceneSession.ts => SCBRootSceneSession.ts} (65%) rename common/src/main/ets/WindowScene/scene/session/{HWSceneContainerSession.ts => SCBSceneContainerSession.ts} (51%) rename common/src/main/ets/WindowScene/scene/session/{HWSceneInfo.ts => SCBSceneInfo.ts} (74%) rename common/src/main/ets/WindowScene/scene/session/{HWSceneSession.ts => SCBSceneSession.ts} (43%) rename common/src/main/ets/WindowScene/scene/session/{HWSceneSessionManager.ts => SCBSceneSessionManager.ts} (30%) delete mode 100644 common/src/main/ets/WindowScene/screen/session/HWScreenSession.ts delete mode 100644 common/src/main/ets/WindowScene/screen/session/HWScreenSessionManager.ts create mode 100644 common/src/main/ets/WindowScene/screen/session/SCBScreenSession.ts rename product/phone/src/main/ets/{WindowScene/HWDesktop.ets => SceneBoard/SCBDesktop.ets} (96%) rename product/phone/src/main/ets/{WindowScene/HWDivider.ets => SceneBoard/SCBDivider.ets} (45%) rename product/phone/src/main/ets/{WindowScene/HWGestureNavBar.ets => SceneBoard/SCBGestureNavBar.ets} (31%) create mode 100644 product/phone/src/main/ets/SceneBoard/SCBScene.ets create mode 100644 product/phone/src/main/ets/SceneBoard/SCBSceneContainer.ets create mode 100644 product/phone/src/main/ets/SceneBoard/SCBScenePanel.ets rename product/phone/src/main/ets/{WindowScene/HWScreen.ets => SceneBoard/SCBScreen.ets} (70%) rename product/phone/src/main/ets/{WindowScene/HWWallpaper.ets => SceneBoard/SCBWallpaper.ets} (93%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/dropdownpanel/DropdownPanel.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/dropdownpanel/bannerNotification.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/dropdownpanel/common/ControlCenterConfig.ts (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/dropdownpanel/common/StyleConfiguration.ts (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/dropdownpanel/common/StyleManager.ts (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/dropdownpanel/common/constants.ts (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/dropdownpanel/common/navigationEvent.ts (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/dropdownpanel/control.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/dropdownpanel/notification.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/common/constants.ts (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/pages/SCBScreenLock.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/pages/customPassword.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/pages/customscreenlock.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/pages/digitalPassword.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/pages/journalscreenlock.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/pages/mixedPassword.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/pages/slidescreenlock.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/vm/indexViewModel.ts (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/screenlock/vm/slideScreenLockViewModel.ts (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/statusbar/SCBStatusBar.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/statusbar/StatusBar.ets (100%) rename product/phone/src/main/ets/{WindowScene => SceneBoard}/statusbar/StatusbarConfig.ts (100%) delete mode 100644 product/phone/src/main/ets/WindowScene/HWSceneContainer.ets delete mode 100644 product/phone/src/main/ets/WindowScene/HWScenePanel.ets diff --git a/common/index.ets b/common/index.ets index def2fa4c..257845fd 100644 --- a/common/index.ets +++ b/common/index.ets @@ -87,12 +87,13 @@ export { DragArea } from './src/main/ets/default/base/DragArea' export { DragItemPosition } from './src/main/ets/default/base/DragItemPosition' // Window scene -export { HWRootSceneSession } from './src/main/ets/WindowScene/scene/session/HWRootSceneSession' -export { HWSceneInfo } from './src/main/ets/WindowScene/scene/session/HWSceneInfo' -export { HWDividerParam } from './src/main/ets/WindowScene/scene/session/HWDividerParam' -export { HWRecentViewParam } from './src/main/ets/WindowScene/scene/session/HWRecentViewParam' -export { HWSceneSession } from './src/main/ets/WindowScene/scene/session/HWSceneSession' -export { HWSceneSessionManager } from './src/main/ets/WindowScene/scene/session/HWSceneSessionManager' -export { HWScreenSession, DesktopState, SceneContainerSessionArray } from './src/main/ets/WindowScene/screen/session/HWScreenSession' -export { HWScreenSessionManager } from './src/main/ets/WindowScene/screen/session/HWScreenSessionManager' -export { HWSceneContainerSession } from './src/main/ets/WindowScene/scene/session/HWSceneContainerSession' \ No newline at end of file +export { SCBRootSceneSession } from './src/main/ets/WindowScene/scene/session/SCBRootSceneSession' +export { SCBSceneInfo } from './src/main/ets/WindowScene/scene/session/SCBSceneInfo' +export { SCBDividerParam } from './src/main/ets/WindowScene/scene/session/SCBDividerParam' +export { SCBSceneSession } from './src/main/ets/WindowScene/scene/session/SCBSceneSession' +export { SCBSceneSessionManager } from './src/main/ets/WindowScene/scene/session/SCBSceneSessionManager' +export { SCBScreenSession, SCBScreenProperty } from './src/main/ets/WindowScene/screen/session/SCBScreenSession' +export { SCBSceneContainerSession } from './src/main/ets/WindowScene/scene/session/SCBSceneContainerSession' +export { SCBSceneContainerSessionArray } from './src/main/ets/WindowScene/scene/session/SCBSceneContainerSession' +export { SCBGestureModel, SceneState } from './src/main/ets/WindowScene/common/SCBGestureModel' +export { SCBGestureActionId, SCBGestureActionOption, SCBGestureAction } from './src/main/ets/WindowScene/common/SCBGestureAction' \ No newline at end of file diff --git a/common/src/main/ets/WindowScene/animation/HWTransitionEffect.ts b/common/src/main/ets/WindowScene/animation/SCBTransitionEffect.ts similarity index 54% rename from common/src/main/ets/WindowScene/animation/HWTransitionEffect.ts rename to common/src/main/ets/WindowScene/animation/SCBTransitionEffect.ts index a369f67a..70ff532e 100644 --- a/common/src/main/ets/WindowScene/animation/HWTransitionEffect.ts +++ b/common/src/main/ets/WindowScene/animation/SCBTransitionEffect.ts @@ -21,17 +21,17 @@ export class SharedTransitionParam { } // TODO Transition configuration -export class HWTransitionEffect { - static DEFAULT: HWTransitionEffect +export class SCBTransitionEffect { + static DEFAULT: SCBTransitionEffect - static APPEAR_FROM_ITEM: HWTransitionEffect - static APPEAR_FROM_ITEM_PC: HWTransitionEffect - static APPEAR_FROM_NONE: HWTransitionEffect - static APPEAR_FROM_SCENE: HWTransitionEffect + static APPEAR_FROM_ITEM: SCBTransitionEffect + static APPEAR_FROM_ITEM_PC: SCBTransitionEffect + static APPEAR_FROM_NONE: SCBTransitionEffect + static APPEAR_FROM_SCENE: SCBTransitionEffect - static DISAPPEAR_FROM_SCENE: HWTransitionEffect - static DISAPPEAR_TO_HOME: HWTransitionEffect - static DISAPPEAR_TO_HOME_PC: HWTransitionEffect + static DISAPPEAR_FROM_SCENE: SCBTransitionEffect + static DISAPPEAR_TO_HOME: SCBTransitionEffect + static DISAPPEAR_TO_HOME_PC: SCBTransitionEffect constructor() {} @@ -51,11 +51,11 @@ export class HWTransitionEffect { animationParam: AnimateParam } -HWTransitionEffect.DEFAULT = new HWTransitionEffect() -HWTransitionEffect.APPEAR_FROM_ITEM = new HWTransitionEffect() -HWTransitionEffect.APPEAR_FROM_NONE = new HWTransitionEffect() -HWTransitionEffect.APPEAR_FROM_SCENE = new HWTransitionEffect() -HWTransitionEffect.APPEAR_FROM_ITEM_PC = new HWTransitionEffect() -HWTransitionEffect.DISAPPEAR_FROM_SCENE = new HWTransitionEffect() -HWTransitionEffect.DISAPPEAR_TO_HOME = new HWTransitionEffect() -HWTransitionEffect.DISAPPEAR_TO_HOME_PC = new HWTransitionEffect() +SCBTransitionEffect.DEFAULT = new SCBTransitionEffect() +SCBTransitionEffect.APPEAR_FROM_ITEM = new SCBTransitionEffect() +SCBTransitionEffect.APPEAR_FROM_NONE = new SCBTransitionEffect() +SCBTransitionEffect.APPEAR_FROM_SCENE = new SCBTransitionEffect() +SCBTransitionEffect.APPEAR_FROM_ITEM_PC = new SCBTransitionEffect() +SCBTransitionEffect.DISAPPEAR_FROM_SCENE = new SCBTransitionEffect() +SCBTransitionEffect.DISAPPEAR_TO_HOME = new SCBTransitionEffect() +SCBTransitionEffect.DISAPPEAR_TO_HOME_PC = new SCBTransitionEffect() diff --git a/common/src/main/ets/WindowScene/scene/session/HWRecentViewParam.ts b/common/src/main/ets/WindowScene/common/SCBGestureAction.ts similarity index 34% rename from common/src/main/ets/WindowScene/scene/session/HWRecentViewParam.ts rename to common/src/main/ets/WindowScene/common/SCBGestureAction.ts index f7eae59e..b62bf6db 100644 --- a/common/src/main/ets/WindowScene/scene/session/HWRecentViewParam.ts +++ b/common/src/main/ets/WindowScene/common/SCBGestureAction.ts @@ -13,77 +13,55 @@ * limitations under the License. */ -/** - * param of RecentView - */ -@Observed -export class HWRecentViewParam { - /** - * translateX of RecentView - */ - translateX: number = 0; - - /** - * translateY of RecentView - */ - translateY: number = 0; - - /** - * scaleX of RecentView - */ - scaleX: number = 1; - - /** - * scaleY of RecentView - */ - scaleY: number = 1; - - /** - * centerX of RecentView - */ - centerX: number | string = '50%'; - - /** - * centerY of RecentView - */ - centerY: number | string = '50%'; +import { Log } from '../../default/utils/Log' - /** - * offsetX of RecentView - */ - offsetX: number = 0; - /** - * offsetY of RecentView - */ - offsetY: number = 0; +const TAG = 'SCBGestureAction' - /** - * borderRadius of scene - */ - borderRadius: number | string = 0; +export enum SCBGestureActionId { + HOME, + FULLSCENE, + ENTER_SPLIT, + EXIT_SPILT, + ENTER_RECENT, + SLIDE_UP_BEGIN, + SLIDING_UP, + SLIDE_UP_END, + DESTROY_IN_RECENT, + EXIT_SPLIT +}; - height: number | string = '100%'; - - width: number | string = '100%'; - - margin: number | string = 0; - - /** - * init properties of RecentView - */ - public init() { - this.translateX = 0; - this.translateY = 0; - this.scaleX = 1; - this.scaleY = 1; - this.centerX = '50%'; - this.centerY = '50%'; - this.offsetX = 0; - this.offsetY = 0; - this.borderRadius = 0; - this.height = "100%" - this.width = "100%" - this.margin = 0 - } +export interface SCBGestureActionOption { + id: number; + destroyLen?: number; + screenId?: number; + gestureOffsetX?: number; + gestureOffsetY?: number; + sessionId?: number; +} +/** + * Manage info of gesture + */ +@Observed +export class SCBGestureAction { + readonly actionId: number = SCBGestureActionId.HOME; + readonly screenId: number; + readonly gestureOffsetX: number = 0; + readonly gestureOffsetY: number = 0; + readonly sessionId: number = -1; + constructor(options: SCBGestureActionOption) { + this.actionId = options.id; + if (options.screenId) { + this.screenId = options.screenId; + } + if (options.gestureOffsetX) { + this.gestureOffsetX = options.gestureOffsetX; + } + if (options.gestureOffsetY) { + this.gestureOffsetY = options.gestureOffsetY; + } + if (options.sessionId) { + this.sessionId = options.sessionId; + } + } } diff --git a/product/phone/src/main/ets/WindowScene/HWScene.ets b/common/src/main/ets/WindowScene/common/SCBGestureModel.ts similarity index 30% rename from product/phone/src/main/ets/WindowScene/HWScene.ets rename to common/src/main/ets/WindowScene/common/SCBGestureModel.ts index 098875a8..5a270669 100644 --- a/product/phone/src/main/ets/WindowScene/HWScene.ets +++ b/common/src/main/ets/WindowScene/common/SCBGestureModel.ts @@ -13,32 +13,64 @@ * limitations under the License. */ -import { HWSceneSession } from '@ohos/common' -import { StyleConstants } from '@ohos/common' -import { Log } from '@ohos/common' - -const TAG = 'HWScene' - -@Component -export struct HWScene { - sceneSession: HWSceneSession - - buildLog(sceneSession: HWSceneSession) { - if (sceneSession) { - Log.showInfo(TAG, 'HWSceneSession bundle name: ' + sceneSession.sceneInfo.bundleName + ' id: ' + sceneSession.session.persistentId); - return true; - } else { - Log.showError(TAG, 'HWSceneSession is null'); - return false; +import screenSessionManager from '@ohos.screenSessionManager' +import { SCBSceneSession } from '../scene/session/SCBSceneSession' +import { SCBSceneContainerSession } from '../scene/session/SCBSceneContainerSession' +import { Log } from '../../default/utils/Log' +import { SCBSceneInfo } from '../scene/session/SCBSceneInfo' +import { SCBDividerParam } from '../scene/session/SCBDividerParam' + +const TAG = 'SCBGestureModel' + +export enum SceneState { + HOME, + FULLSCENE, + SPLIT, + SLIDING_UP, + RECENT +} +/** + * Manage info of gesture + */ +@Observed +export class SCBGestureModel { + + sceneState: SceneState = SceneState.HOME; + + flexWidth: number | string = '100%'; + + flexHeight: number | string = '100%'; + + flexPadding: number = 0; + + flexOffsetX: number = 0; + + flexOffsetY: number = 0; + + multiViewShow: boolean = false; + + enableScroll: boolean = true; + + /** + * Constructor. + * @param session Session of the screen + */ + constructor() { + } + + public updateSceneState(state: SceneState) { + Log.showInfo(TAG, `updateSceneState from ${this.sceneState} to ${state}`); + this.sceneState = state; } - } - - build() { - Stack() { - if (this.buildLog(this.sceneSession)) { - HostWindowScene(this.sceneSession.session.persistentId) - .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) - } + /** + * init properties of all container or scene + */ + public initAll() { + this.flexWidth = "100%"; + this.flexHeight = "100%"; + this.flexPadding = 0; + this.flexOffsetX = 0; + this.flexOffsetY = 0; + this.multiViewShow = false; } - } } diff --git a/common/src/main/ets/WindowScene/scene/session/HWDividerParam.ts b/common/src/main/ets/WindowScene/scene/session/SCBDividerParam.ts similarity index 54% rename from common/src/main/ets/WindowScene/scene/session/HWDividerParam.ts rename to common/src/main/ets/WindowScene/scene/session/SCBDividerParam.ts index 44694fb1..87952eed 100644 --- a/common/src/main/ets/WindowScene/scene/session/HWDividerParam.ts +++ b/common/src/main/ets/WindowScene/scene/session/SCBDividerParam.ts @@ -13,63 +13,63 @@ * limitations under the License. */ /** - * param of HWDivider + * param of SCBDivider */ @Observed -export class HWDividerParam { +export class SCBDividerParam { /** * translateX of Divider */ - translateX: number = 0 + translateX: number = 0; /** * translateY of Divider */ - translateY: number = 0 + translateY: number = 0; /** * scaleX of Divider */ - scaleX: number = 1 + scaleX: number = 1; /** * scaleY of Divider */ - scaleY: number = 1 + scaleY: number = 1; /** - * scaleY of primary HWScene + * scaleY of primary SCBScene */ - primaryScaleY : number = 1 + primaryScaleY : number = 1; /** - * scaleY of secondary HWScene + * scaleY of secondary SCBScene */ - secondaryScaleY : number = 1 + secondaryScaleY : number = 1; /** - * Height of primary HWScene + * Height of primary SCBScene */ - primaryH : string = '100%' + primaryH : string = '100%'; /** - * translateY of secondary HWScene + * translateY of secondary SCBScene */ - secTransY: number = 0 + secTransY: number = 0; /** - * blurRadius of primary/secondary HWScene when drag divider + * blurRadius of primary/secondary SCBScene when drag divider */ - blurRadius : number = 0 + blurRadius : number = 0; public init() { - this.translateX = 0 - this.translateY = 0 - this.scaleX = 1 - this.scaleY = 1 - this.primaryScaleY = 1 - this.secondaryScaleY = 1 - this.primaryH = '100%' - this.secTransY = 0 - this.blurRadius = 0 + this.translateX = 0; + this.translateY = 0; + this.scaleX = 1; + this.scaleY = 1; + this.primaryScaleY = 1; + this.secondaryScaleY = 1; + this.primaryH = '100%'; + this.secTransY = 0; + this.blurRadius = 0; } } diff --git a/common/src/main/ets/WindowScene/scene/session/HWRootSceneSession.ts b/common/src/main/ets/WindowScene/scene/session/SCBRootSceneSession.ts similarity index 65% rename from common/src/main/ets/WindowScene/scene/session/HWRootSceneSession.ts rename to common/src/main/ets/WindowScene/scene/session/SCBRootSceneSession.ts index 8cb92aeb..8fd78f8b 100644 --- a/common/src/main/ets/WindowScene/scene/session/HWRootSceneSession.ts +++ b/common/src/main/ets/WindowScene/scene/session/SCBRootSceneSession.ts @@ -15,22 +15,21 @@ import sceneSessionManager from '@ohos.sceneSessionManager' -import { HWSceneInfo } from './HWSceneInfo' -import { HWSceneSessionManager } from './HWSceneSessionManager' -import { HWScreenSessionManager } from '../../screen/session/HWScreenSessionManager' -import { HWTransitionEffect } from '../../animation/HWTransitionEffect' +import { SCBSceneInfo } from './SCBSceneInfo' +import { SCBSceneSessionManager } from './SCBSceneSessionManager' import ServiceExtensionContext from 'application/ServiceExtensionContext' /** * Scene session of the root scene. */ -export class HWRootSceneSession { - readonly session: sceneSessionManager.RootSceneSession +export class SCBRootSceneSession { + readonly session: sceneSessionManager.RootSceneSession; + usrId: number = -1; constructor() { - this.session = sceneSessionManager.getRootSceneSession() + this.session = sceneSessionManager.getRootSceneSession(); this.session.on('pendingSceneSessionActivation', (info) => { - this.onPendingSceneSessionActivation(info) + this.onPendingSceneSessionActivation(info); }) } @@ -40,11 +39,11 @@ export class HWRootSceneSession { * @param context Context of the service extension */ public loadContent(path: string, context: ServiceExtensionContext): void { - this.session.loadContent(path, context) + this.session.loadContent(path, context); } private onPendingSceneSessionActivation(sceneInfo: sceneSessionManager.SceneInfo): void { - let hwSceneInfo = new HWSceneInfo(sceneInfo.bundleName, sceneInfo.abilityName); - HWSceneSessionManager.getInstance().startScene(hwSceneInfo) + let info = new SCBSceneInfo(sceneInfo.bundleName, sceneInfo.abilityName); + SCBSceneSessionManager.getInstance().startScene(info); } } diff --git a/common/src/main/ets/WindowScene/scene/session/HWSceneContainerSession.ts b/common/src/main/ets/WindowScene/scene/session/SCBSceneContainerSession.ts similarity index 51% rename from common/src/main/ets/WindowScene/scene/session/HWSceneContainerSession.ts rename to common/src/main/ets/WindowScene/scene/session/SCBSceneContainerSession.ts index f3254147..65f94050 100644 --- a/common/src/main/ets/WindowScene/scene/session/HWSceneContainerSession.ts +++ b/common/src/main/ets/WindowScene/scene/session/SCBSceneContainerSession.ts @@ -14,48 +14,64 @@ */ import screenSessionManager from '@ohos.screenSessionManager' -import { HWSceneSession } from './HWSceneSession' -import { HWDividerParam } from './HWDividerParam' +import { SCBSceneSession } from './SCBSceneSession' +import { SCBDividerParam } from './SCBDividerParam' +import { SCBScreenProperty } from './../../screen/session/SCBScreenSession' + import { Log } from '../../../default/utils/Log' -const TAG = 'HWSceneContainerSession' +const TAG = 'SCBSceneContainerSession' + +@Observed +export class SCBSceneContainerSessionArray extends Array { +} /** * Session of a scene. */ @Observed -export class HWSceneContainerSession { +export class SCBSceneContainerSession { readonly containerId: number; - primarySession: HWSceneSession = null; - secondarySession: HWSceneSession = null; - screenBounds: screenSessionManager.RRect; - dividerParam: HWDividerParam = new HWDividerParam(); + primarySession: SCBSceneSession = null; + secondarySession: SCBSceneSession = null; + screenProperty: SCBScreenProperty; + dividerParam: SCBDividerParam = new SCBDividerParam(); isSplit: boolean = false; isActive: boolean = false; + translateX: number = 0; translateY: number = 0; scaleX: number = 1; scaleY: number = 1; centerX: number | string = '50%'; centerY: number | string = '50%'; + width: number | string = '100%'; + height: number | string = '100%'; + offsetX: number = 0; + offsetY: number = 0; + margin: number = 0; + borderRadius: number = 0; + alpha: number = 0; private static gContainerId: number = 0; /** * Constructor. */ - constructor(primarySession: HWSceneSession, screenBounds: screenSessionManager.RRect) { - this.containerId = ++HWSceneContainerSession.gContainerId; + constructor(primarySession: SCBSceneSession, screenProperty: SCBScreenProperty) { + this.containerId = ++SCBSceneContainerSession.gContainerId; this.primarySession = primarySession; this.secondarySession = null; - this.screenBounds = screenBounds; + this.screenProperty = screenProperty; + this.width = px2vp(this.screenProperty.width); + this.height = px2vp(this.screenProperty.height); } /** * Add scene session to this container. * @param sceneSession The scene session to add. */ - public addSceneSession(sceneSession: HWSceneSession) { + public addSceneSession(sceneSession: SCBSceneSession) { if (sceneSession === null) { Log.showError(TAG, 'Add scene session failed as scene session is null!'); return; @@ -79,7 +95,7 @@ export class HWSceneContainerSession { * Remove scene session from this container. * @param sceneSession The scene session to remove. */ - public removeSceneSession(sceneSession: HWSceneSession) { + public removeSceneSession(sceneSession: SCBSceneSession) { if (sceneSession === null) { Log.showError(TAG, 'Remove scene session failed as scene session is null!'); return; @@ -98,6 +114,39 @@ export class HWSceneContainerSession { } } + public requestActivation() { + if (this.isActive) { + Log.showWarn(TAG, 'The scene is already active.'); + return; + } + + Log.showInfo(TAG, 'Request scene container session activation, id: ' + this.containerId); + this.isActive = true; + this.primarySession && this.primarySession.requestSessionActivation(); + if (this.isSplit) { + this.secondarySession && this.secondarySession.requestSessionActivation(); + } + } + + public requestBackground() { + if (!this.isActive) { + Log.showError(TAG, 'The scene is already background.'); + return; + } + + Log.showInfo(TAG, 'Request scene container session background, containerId: ' + this.containerId); + this.isActive = false; + this.primarySession && this.primarySession.requestSessionBackground(); + this.secondarySession && this.secondarySession.requestSessionBackground(); + } + + public requestDestruction() { + Log.showInfo(TAG, 'Request scene container session destruction, id: ' + this.containerId); + this.isActive = false; + this.primarySession && this.primarySession.requestSessionDestruction(); + this.secondarySession && this.secondarySession.requestSessionDestruction(); + } + public init() { this.translateX = 0; this.translateY = 0; @@ -105,5 +154,12 @@ export class HWSceneContainerSession { this.scaleY = 1; this.centerX = '50%'; this.centerY = '50%'; + this.width = px2vp(this.screenProperty.width); + this.height = px2vp(this.screenProperty.height); + this.offsetX = 0; + this.offsetY = 0; + this.margin = 0; + this.borderRadius = 0; + Log.showInfo(TAG, 'id: ' + this.containerId + ' initWidth: ' + this.width + ' initHeight: ' + this.height); } } diff --git a/common/src/main/ets/WindowScene/scene/session/HWSceneInfo.ts b/common/src/main/ets/WindowScene/scene/session/SCBSceneInfo.ts similarity index 74% rename from common/src/main/ets/WindowScene/scene/session/HWSceneInfo.ts rename to common/src/main/ets/WindowScene/scene/session/SCBSceneInfo.ts index 42a74e14..476cb36c 100644 --- a/common/src/main/ets/WindowScene/scene/session/HWSceneInfo.ts +++ b/common/src/main/ets/WindowScene/scene/session/SCBSceneInfo.ts @@ -13,39 +13,39 @@ * limitations under the License. */ -import { HWTransitionEffect } from '../../animation/HWTransitionEffect' +import { SCBTransitionEffect } from '../../animation/SCBTransitionEffect' /** * Information of a scene. */ -export class HWSceneInfo { +export class SCBSceneInfo { /** * Bundle name. */ - bundleName : string + bundleName : string; /** * Ability name. */ - abilityName: string + abilityName: string; /** * Identifier which screen the scene is displayed. default is main screen */ - screenId: number = -1 + screenId: number = -1; /** * True start a new scene otherwise priority to start the exist scene. */ - isNewInstance: boolean = false + isNewInstance: boolean = false; /** * Transition effect when scene appearing or disappearing. */ - transitionEffect: HWTransitionEffect = HWTransitionEffect.DEFAULT + transitionEffect: SCBTransitionEffect = SCBTransitionEffect.DEFAULT; constructor(bundleName: string, abilityName: string) { - this.bundleName = bundleName - this.abilityName = abilityName + this.bundleName = bundleName; + this.abilityName = abilityName; } } diff --git a/common/src/main/ets/WindowScene/scene/session/HWSceneSession.ts b/common/src/main/ets/WindowScene/scene/session/SCBSceneSession.ts similarity index 43% rename from common/src/main/ets/WindowScene/scene/session/HWSceneSession.ts rename to common/src/main/ets/WindowScene/scene/session/SCBSceneSession.ts index d1c20d82..7bca8944 100644 --- a/common/src/main/ets/WindowScene/scene/session/HWSceneSession.ts +++ b/common/src/main/ets/WindowScene/scene/session/SCBSceneSession.ts @@ -14,44 +14,57 @@ */ import sceneSessionManager from '@ohos.sceneSessionManager' -import { HWSceneInfo } from './HWSceneInfo' -import { HWSceneSessionManager } from './HWSceneSessionManager' -import { HWScreenSessionManager } from '../../screen/session/HWScreenSessionManager' -import { HWTransitionEffect } from '../../animation/HWTransitionEffect' +import { SCBSceneInfo } from './SCBSceneInfo' +import { SCBSceneSessionManager } from './SCBSceneSessionManager' +import { SCBTransitionEffect } from '../../animation/SCBTransitionEffect' /** * Session of a scene. */ @Observed -export class HWSceneSession { - readonly sceneInfo: HWSceneInfo - readonly session: sceneSessionManager.SceneSession - isActive: boolean = false - translateX: number = 0 - translateY: number = 0 - scaleX: number = 1 - scaleY: number = 1 +export class SCBSceneSession { + readonly sceneInfo: SCBSceneInfo; + readonly session: sceneSessionManager.SceneSession; + isActive: boolean = false; + translateX: number = 0; + translateY: number = 0; + scaleX: number = 1; + scaleY: number = 1; /** * Constructor. * @param session Session of the scene * @param sceneInfo Information of the scene */ - constructor(session: sceneSessionManager.SceneSession, sceneInfo: HWSceneInfo) { - this.sceneInfo = sceneInfo - this.session = session + constructor(session: sceneSessionManager.SceneSession, sceneInfo: SCBSceneInfo) { + this.sceneInfo = sceneInfo; + this.session = session; this.session.on('pendingSceneSessionActivation', (info) => { - this.onPendingSceneSessionActivation(info) + this.onPendingSceneSessionActivation(info); }) } private onPendingSceneSessionActivation(sceneInfo: sceneSessionManager.SceneInfo) { - let toSceneInfo = new HWSceneInfo(sceneInfo.bundleName, sceneInfo.abilityName); - toSceneInfo.screenId = this.sceneInfo.screenId - toSceneInfo.transitionEffect = HWTransitionEffect.APPEAR_FROM_SCENE - this.sceneInfo.transitionEffect = HWTransitionEffect.DISAPPEAR_FROM_SCENE + let toSceneInfo = new SCBSceneInfo(sceneInfo.bundleName, sceneInfo.abilityName); + toSceneInfo.screenId = this.sceneInfo.screenId; + toSceneInfo.transitionEffect = SCBTransitionEffect.APPEAR_FROM_SCENE; + this.sceneInfo.transitionEffect = SCBTransitionEffect.DISAPPEAR_FROM_SCENE; - HWSceneSessionManager.getInstance().startScene(toSceneInfo) -// HWSceneSessionManager.getInstance().requestSceneBackground(this) + SCBSceneSessionManager.getInstance().startScene(toSceneInfo); + } + + public async requestSessionActivation(): Promise { + this.isActive = true; + sceneSessionManager.requestSceneSessionActivation(this.session); + } + + public async requestSessionBackground(): Promise { + this.isActive = false; + sceneSessionManager.requestSceneSessionBackground(this.session); + } + + public async requestSessionDestruction(): Promise { + this.isActive = false; + sceneSessionManager.requestSceneSessionDestruction(this.session); } } diff --git a/common/src/main/ets/WindowScene/scene/session/HWSceneSessionManager.ts b/common/src/main/ets/WindowScene/scene/session/SCBSceneSessionManager.ts similarity index 30% rename from common/src/main/ets/WindowScene/scene/session/HWSceneSessionManager.ts rename to common/src/main/ets/WindowScene/scene/session/SCBSceneSessionManager.ts index 097a365b..1df83208 100644 --- a/common/src/main/ets/WindowScene/scene/session/HWSceneSessionManager.ts +++ b/common/src/main/ets/WindowScene/scene/session/SCBSceneSessionManager.ts @@ -13,56 +13,45 @@ * limitations under the License. */ -import sceneSessionManager from '@ohos.sceneSessionManager' import ServiceExtensionContext from 'application/ServiceExtensionContext' -import { HWRootSceneSession } from './HWRootSceneSession' -import { HWSceneInfo } from './HWSceneInfo' -import { HWSceneSession } from './HWSceneSession' -import { HWSceneContainerSession } from './HWSceneContainerSession' -import { HWScreenSession, DesktopState } from '../../screen/session/HWScreenSession' -import { HWScreenSessionManager } from '../../screen/session/HWScreenSessionManager' +import { SCBRootSceneSession } from './SCBRootSceneSession' +import { SCBSceneInfo } from './SCBSceneInfo' import { Log } from '../../../default/utils/Log' -const TAG = 'HWSceneSessionManager'; +const TAG = 'SCBSceneSessionManager'; /** * Scene session manager */ -export class HWSceneSessionManager { - private rootSceneSession: HWRootSceneSession; +export class SCBSceneSessionManager { + private rootSceneSession: SCBRootSceneSession; + private startSceneFuncMap: Map = new Map(); + private backgroundSceneFuncMap: Map = new Map(); + private destroySceneFuncMap: Map = new Map(); + private activateSceneFuncMap: Map = new Map(); + public mainScreenId: number = -1; private constructor() { - this.rootSceneSession = new HWRootSceneSession(); + this.rootSceneSession = new SCBRootSceneSession(); } /** * Get the singleton of the scene session manager. */ - static getInstance(): HWSceneSessionManager { - if (!globalThis.HWSceneSessionManagerInstance) { - globalThis.HWSceneSessionManagerInstance = new HWSceneSessionManager(); + static getInstance(): SCBSceneSessionManager { + if (!globalThis.SCBSceneSessionManagerInstance) { + globalThis.SCBSceneSessionManagerInstance = new SCBSceneSessionManager(); } - return globalThis.HWSceneSessionManagerInstance; + return globalThis.SCBSceneSessionManagerInstance; } - private async requestSceneSessionActivation(sceneSession: HWSceneSession): Promise { - sceneSessionManager.requestSceneSessionActivation(sceneSession.session); - } - - private async requestSceneSessionBackground(sceneSession: HWSceneSession): Promise { - sceneSessionManager.requestSceneSessionBackground(sceneSession.session); - } - - private async requestSceneSessionDestruction(sceneSession: HWSceneSession): Promise { - sceneSessionManager.requestSceneSessionDestruction(sceneSession.session); - } /** * Get the session of the root scene. * @return Session of the root scene */ - public getRootSceneSession(): HWRootSceneSession { + public getRootSceneSession(): SCBRootSceneSession { return this.rootSceneSession; } @@ -75,128 +64,134 @@ export class HWSceneSessionManager { this.rootSceneSession.loadContent(path, context); } - /** - * Start a scene. - * @param sceneInfo The info of the scene which to be activated - */ - public startScene(sceneInfo: HWSceneInfo) { - Log.showInfo(TAG, 'start scene:' + ' bundle:' + sceneInfo.bundleName + ' ability:' + sceneInfo.abilityName + - ' screenId:' + sceneInfo.screenId + ' isNewInstance:' + sceneInfo.isNewInstance); - let screenSession: HWScreenSession = null; - if (sceneInfo.screenId === -1) { - screenSession = HWScreenSessionManager.getInstance().getMainScreenSession(); - sceneInfo.screenId = screenSession.session.screenId; - } else { - screenSession = HWScreenSessionManager.getInstance().getScreenSession(sceneInfo.screenId); + public registerStartSceneCallback(screenId:number, callback: Function): void { + if (this.startSceneFuncMap.has(screenId)) { + Log.showError(TAG, `StartSceneFunc alreay exists with screenId: ${screenId}`); + return; } + Log.showInfo(TAG, `Register StartSceneFunc with screenId: ${screenId}`); + this.startSceneFuncMap.set(screenId, callback); + } - if (screenSession == null) { - Log.showError(TAG, 'Failed to get screen session!'); + public unRegisterSceneCallback(screenId: number): void { + if (!this.startSceneFuncMap.has(screenId)) { + Log.showError(TAG, `Failed to find startSceneFunc with screenId: ${screenId}`); return; } + this.startSceneFuncMap.delete(screenId); + this.backgroundSceneFuncMap.delete(screenId); + this.destroySceneFuncMap.delete(screenId); + this.activateSceneFuncMap.delete(screenId); + } - let sceneSession = this.requestSceneSession(sceneInfo, screenSession); - if (sceneSession == null) { - Log.showError(TAG, 'Failed to request scene session!'); + public registerActivateSceneCallback(screenId:number, callback: Function): void { + if (this.activateSceneFuncMap.has(screenId)) { + Log.showError(TAG, `ActivateSceneFunc alreay exists with screenId: ${screenId}`); return; } + this.activateSceneFuncMap.set(screenId, callback); + } - if (screenSession.desktopState === DesktopState.HOME) { - let sceneContainerSession = screenSession.getSceneContainerSession(sceneSession); - if (sceneContainerSession === null) { - sceneContainerSession = new HWSceneContainerSession(sceneSession, screenSession.bounds); - screenSession.addSceneContainerSession(sceneContainerSession); - } - this.requestSceneContainerActivation(sceneContainerSession); - screenSession.enterAppView(sceneContainerSession); - } else if (screenSession.desktopState === DesktopState.SPLIT) { - let sceneContainerSession = screenSession.getSceneContainerSession(sceneSession); - if (sceneContainerSession !== null) { - screenSession.removeSceneContainerSession(sceneContainerSession); - } - let activeSceneContainerSession = screenSession.getActiveSceneContainerSession(); - activeSceneContainerSession.addSceneSession(sceneSession); - this.requestSceneSessionActivation(sceneSession); - screenSession.enterAppView(activeSceneContainerSession); + public registerBackgroundSceneCallback(screenId:number, callback: Function): void { + if (this.backgroundSceneFuncMap.has(screenId)) { + Log.showError(TAG, `BackgroundSceneFunc alreay exists with screenId: ${screenId}`); + return; } + this.backgroundSceneFuncMap.set(screenId, callback); } - private requestSceneSession(sceneInfo: HWSceneInfo, screenSession: HWScreenSession): HWSceneSession { - if (screenSession == null) { - Log.showError(TAG, 'The screen session is null!'); - return null; + public registerDestroySceneCallback(screenId:number, callback: Function): void { + if (this.destroySceneFuncMap.has(screenId)) { + Log.showError(TAG, `DestroySceneFunc alreay exists with screenId: ${screenId}`); + return; } + this.destroySceneFuncMap.set(screenId, callback); + } - let hwSceneSession = screenSession.getSceneSession(sceneInfo); - if (hwSceneSession == null || sceneInfo.isNewInstance) { - let sceneSession = sceneSessionManager.requestSceneSession({ - bundleName: sceneInfo.bundleName, - abilityName: sceneInfo.abilityName - }); - hwSceneSession = new HWSceneSession(sceneSession, sceneInfo); + /** + * Start a scene. + * @param sceneInfo The info of the scene which to be activated + */ + public startScene(sceneInfo: SCBSceneInfo) { + Log.showInfo(TAG, 'start scene:' + ' bundle:' + sceneInfo.bundleName + ' ability:' + sceneInfo.abilityName + + ' screenId:' + sceneInfo.screenId + ' isNewInstance:' + sceneInfo.isNewInstance); + if (this.startSceneFuncMap.size == 0) { + Log.showError(TAG, 'No start scene func from scenePanel has registered!'); + return; } - - return hwSceneSession; + let screenId = -1; + if (sceneInfo.screenId === -1) { + screenId = this.mainScreenId; + } else { + screenId = sceneInfo.screenId; + } + if (!this.startSceneFuncMap.has(screenId)) { + Log.showError(TAG, `No start scene func has registered screenId: ${this.mainScreenId}!`); + return; + } + Log.showInfo(TAG, `Start scene on screen with screenId: ${screenId}!`); + this.startSceneFuncMap.get(screenId)(sceneInfo); } /** * Request the scene container session activation. * @param sceneContainerSession The session of the scene container which to be activated. */ - public requestSceneContainerActivation(sceneContainerSession: HWSceneContainerSession) { - if (sceneContainerSession === null) { - Log.showError(TAG, 'The scene container session is null!'); + public requestSceneContainerActivation(screenId: number, containerId: number) { + if (this.activateSceneFuncMap.size == 0) { + Log.showError(TAG, 'No activate scene func from scenePanel has registered!'); return; + }; + if (screenId === -1) { + screenId = this.mainScreenId; } - if (sceneContainerSession.isActive) { - Log.showError(TAG, 'The scene is already active.'); + if (!this.activateSceneFuncMap.has(screenId)) { + Log.showError(TAG, 'No activate scene func has registered screenId: ${this.mainScreenId}!`'); return; } - - Log.showInfo(TAG, 'Request scene container session activation, id: ' + sceneContainerSession.containerId); - sceneContainerSession.isActive = true; - this.requestSceneSessionActivation(sceneContainerSession.primarySession); - if (sceneContainerSession.isSplit) { - this.requestSceneSessionActivation(sceneContainerSession.secondarySession); - } + Log.showInfo(TAG, `activate scene: ${containerId} on screen with screenId: ${screenId}!`); + this.activateSceneFuncMap.get(screenId)(containerId); } /** * Request the scene container session background. * @param sceneContainerSession The session of the scene container which to be background. */ - public requestSceneContainerBackground(sceneContainerSession: HWSceneContainerSession) { - if (sceneContainerSession === null) { - Log.showError(TAG, 'The scene container session is null!'); + // todo: change with emitter + public requestSceneContainerBackground(screenId: number, containerId: number) { + if (this.backgroundSceneFuncMap.size == 0) { + Log.showError(TAG, 'No background scene func from scenePanel has registered!'); return; + }; + if (screenId === -1) { + screenId = this.mainScreenId; } - if (!sceneContainerSession.isActive) { - Log.showError(TAG, 'The scene is already background.'); + if (!this.backgroundSceneFuncMap.has(screenId)) { + Log.showError(TAG, 'No background scene func has registered screenId: ${this.mainScreenId}!`'); return; } - - Log.showInfo(TAG, 'Request scene container session background, id: ' + sceneContainerSession.containerId); - sceneContainerSession.isActive = false; - this.requestSceneSessionBackground(sceneContainerSession.primarySession); - if (sceneContainerSession.isSplit) { - this.requestSceneSessionBackground(sceneContainerSession.secondarySession); - } + Log.showInfo(TAG, `background scene on screen with screenId: ${screenId}!`); + this.backgroundSceneFuncMap.get(screenId)(containerId); } /** * Request the scene container session destruction. * @param sceneContainerSession The session of the scene container which to be destroyed. */ - public requestSceneContainerDestruction(sceneContainerSession: HWSceneContainerSession) { - if (sceneContainerSession === null) { - Log.showError(TAG, 'The scene container session is null!'); + public requestSceneContainerDestruction(screenId: number, containerId: number) { + if (this.destroySceneFuncMap.size == 0) { + Log.showError(TAG, 'No destroy scene func from scenePanel has registered!'); return; + }; + Log.showInfo(TAG, 'Request scene container session destruction, id: ' + containerId); + if (screenId === -1) { + screenId = this.mainScreenId; } - - Log.showInfo(TAG, 'Request scene container session destruction, id: ' + sceneContainerSession.containerId); - this.requestSceneSessionDestruction(sceneContainerSession.primarySession); - if (sceneContainerSession.isSplit) { - this.requestSceneSessionDestruction(sceneContainerSession.secondarySession); + if (!this.destroySceneFuncMap.has(screenId)) { + Log.showError(TAG, 'No destroy scene func has registered screenId: ${this.mainScreenId}!`'); + return; } + Log.showInfo(TAG, `Destroy scene on screen with screenId: ${screenId}!`); + this.destroySceneFuncMap.get(screenId)(containerId); } } diff --git a/common/src/main/ets/WindowScene/screen/session/HWScreenSession.ts b/common/src/main/ets/WindowScene/screen/session/HWScreenSession.ts deleted file mode 100644 index 37e93b12..00000000 --- a/common/src/main/ets/WindowScene/screen/session/HWScreenSession.ts +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2023 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 screenSessionManager from '@ohos.screenSessionManager' -import { HWSceneSession } from '../../scene/session/HWSceneSession' -import { HWSceneContainerSession } from '../../scene/session/HWSceneContainerSession' -import { HWRecentViewParam } from '../../scene/session/HWRecentViewParam'; -import { Log } from '../../../default/utils/Log' -import { HWSceneInfo } from '../../scene/session/HWSceneInfo' - -const TAG = 'HWScreenSession' - -@Observed -export class SceneContainerSessionArray extends Array { -} - -export enum DesktopState { - HOME, - APP, - SPLIT, - RECENT, - DRAGGING -} - -/** - * Session of a screen. - */ -@Observed -export class HWScreenSession { - public readonly session: screenSessionManager.ScreenSession; - // Unit: px - public bounds: screenSessionManager.RRect = { - left: 0, - top: 0, - width: 0, - height: 0, - radius: 0 - }; - public rotation: number = 0; - public sceneContainerSessionList: SceneContainerSessionArray = new SceneContainerSessionArray(); - public recentViewParam: HWRecentViewParam = new HWRecentViewParam(); - public desktopState: DesktopState = DesktopState.HOME; - - /** - * Constructor. - * @param session Session of the screen - */ - constructor(session: screenSessionManager.ScreenSession) { - this.session = session - this.session.on('connect', (screenProperty: screenSessionManager.ScreenProperty) => { - this.onScreenConnect(screenProperty) - }) - this.session.on('disconnect', () => { - this.onScreenDisconnect() - }) - this.session.on('propertyChange', (screenProperty: screenSessionManager.ScreenProperty) => { - this.onScreenPropertyChange(screenProperty) - }) - } - - private updateProperty(screenProperty: screenSessionManager.ScreenProperty) { - this.bounds = { - left: screenProperty.bounds.left, - top: screenProperty.bounds.top, - width: screenProperty.bounds.width, - height: screenProperty.bounds.height, - radius: screenProperty.bounds.radius - } - this.rotation = screenProperty.rotation - Log.showInfo(TAG, `Update screen bounds[${this.bounds.left}, ${this.bounds.top}, - ${this.bounds.width}, ${this.bounds.height}]`) - } - - private onScreenConnect(screenProperty: screenSessionManager.ScreenProperty): void { - Log.showInfo(TAG, 'On screen connection.') - this.updateProperty(screenProperty) - } - - private onScreenDisconnect(): void { - Log.showInfo(TAG, 'On screen disconnection.') - } - - private onScreenPropertyChange(screenProperty: screenSessionManager.ScreenProperty): void { - Log.showInfo(TAG, 'On screen property change.') - this.updateProperty(screenProperty) - } - - /** - * Add the scene container session to this screen. - * @param sceneContainerSession The scene container session which will be added to this screen. - */ - public addSceneContainerSession(sceneContainerSession: HWSceneContainerSession): void { - const index = this.sceneContainerSessionList.findIndex(item => { - return item.containerId === sceneContainerSession.containerId; - }); - if (index == -1) { - Log.showInfo(TAG, 'Add scene container session, id: ' + sceneContainerSession.containerId); - this.sceneContainerSessionList.push(sceneContainerSession); - } - } - - /** - * Remove the scene container session from this screen. - * @param sceneContainerSession The scene container session which will be removed from this screen. - */ - public removeSceneContainerSession(sceneContainerSession: HWSceneContainerSession): void { - const index = this.sceneContainerSessionList.findIndex((item) => { - return item.containerId === sceneContainerSession.containerId; - }); - if (index != -1) { - Log.showInfo(TAG, 'Remove scene container session, id: ' + sceneContainerSession.containerId); - this.sceneContainerSessionList.splice(index, 1); - } - } - - /** - * Get the scene session by the scene information. - * @param sceneInfo The information of the scene - * @return Session of the scene - */ - public getSceneSession(sceneInfo: HWSceneInfo): HWSceneSession { - for (let i = 0; i < this.sceneContainerSessionList.length; ++i) { - let primarySession = this.sceneContainerSessionList[i].primarySession; - let secondarySession = this.sceneContainerSessionList[i].secondarySession; - if (primarySession && - primarySession.sceneInfo.bundleName == sceneInfo.bundleName && - primarySession.sceneInfo.abilityName == sceneInfo.abilityName) { - return primarySession; - } - if (secondarySession && - secondarySession.sceneInfo.bundleName == sceneInfo.bundleName && - secondarySession.sceneInfo.abilityName == sceneInfo.abilityName) { - return secondarySession; - } - } - return null; - } - - public getSceneContainerSession(sceneSession: HWSceneSession): HWSceneContainerSession { - if (sceneSession === null) { - return null; - } - const index = this.sceneContainerSessionList.findIndex((item) => { - return item.primarySession === sceneSession || item.secondarySession === sceneSession; - }); - if (index === -1) { - return null; - } - return this.sceneContainerSessionList[index]; - } - - public getActiveSceneContainerSession(): HWSceneContainerSession { - const index = this.sceneContainerSessionList.findIndex((item) => { - return item.isActive === true; - }); - if (index === -1) { - Log.showError(TAG, 'Failed to find active scene container session.'); - return null; - } - return this.sceneContainerSessionList[index]; - } - - public enterHomeView() { - this.desktopState = DesktopState.HOME; - this.recentViewParam.init(); - } - - public enterAppView(sceneContainerSession: HWSceneContainerSession) { - this.desktopState = DesktopState.APP; - this.recentViewParam.init(); - sceneContainerSession.init(); - - // To move the sceneContainerSession to the last of list. - this.removeSceneContainerSession(sceneContainerSession); - this.addSceneContainerSession(sceneContainerSession); - } - - public enterRecentView() { - this.desktopState = DesktopState.RECENT; - this.recentViewParam.translateX = 0; - this.recentViewParam.translateY = 0; - this.recentViewParam.scaleX = 1; - this.recentViewParam.scaleY = 1; - this.recentViewParam.centerX = '50%'; - this.recentViewParam.centerY = '50%'; - this.recentViewParam.borderRadius = 35; - this.recentViewParam.offsetX = 0; - this.recentViewParam.offsetY = 0; - this.recentViewParam.width = "70%" - this.recentViewParam.height = "70%" - this.recentViewParam.margin = 0 - } - - public enterSplitView() { - this.desktopState = DesktopState.SPLIT; - this.recentViewParam.init(); - } -} diff --git a/common/src/main/ets/WindowScene/screen/session/HWScreenSessionManager.ts b/common/src/main/ets/WindowScene/screen/session/HWScreenSessionManager.ts deleted file mode 100644 index e0be604c..00000000 --- a/common/src/main/ets/WindowScene/screen/session/HWScreenSessionManager.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2023 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 screenSessionManager from '@ohos.screenSessionManager' -import { HWScreenSession } from './HWScreenSession' -import { Log } from '../../../default/utils/Log' - -const TAG = 'HWScreenSessionManager' - -/** - * Screen session manager. - */ -export class HWScreenSessionManager { - private screenSessionList: HWScreenSession[] = [] - - private constructor() { - this.screenSessionList = AppStorage.SetAndLink('screenSessionList', this.screenSessionList).get() - } - - /** - * Get the singleton of the screen session manager. - */ - static getInstance(): HWScreenSessionManager { - if (!globalThis.HWScreenSessionManagerInstance) { - globalThis.HWScreenSessionManagerInstance = new HWScreenSessionManager() - } - - return globalThis.HWScreenSessionManagerInstance - } - - /** - * Init the screen session manager. - */ - public init(): void { - this.registerScreenConnectionListener() - } - - private registerScreenConnectionListener(): void { - screenSessionManager.on('screenConnectChange', ({ screenSession, screenConnectChangeType }) => { - this.onScreenConnectChange(screenSession, screenConnectChangeType) - }) - } - - private onScreenConnectChange(session: screenSessionManager.ScreenSession, - changeType: screenSessionManager.ScreenConnectChangeType) { - Log.showInfo(TAG, 'On screen connect change, type:' + changeType + ' ' + session.screenId) - if (changeType === screenSessionManager.ScreenConnectChangeType.CONNECT) { - this.onScreenConnect(session) - } - - if (changeType === screenSessionManager.ScreenConnectChangeType.DISCONNECT) { - this.onScreenDisconnect(session) - } - } - - private onScreenConnect(session: screenSessionManager.ScreenSession): void { - Log.showInfo(TAG, 'On screen connect.') - let screenSession: HWScreenSession = new HWScreenSession(session) - this.addScreenSession(screenSession) - } - - private onScreenDisconnect(session: screenSessionManager.ScreenSession): void { - Log.showInfo(TAG, 'On screen disconnect.') - this.removeScreenSession(session.screenId) - } - - private addScreenSession(screenSession: HWScreenSession) { - const screenSessionIndex = this.screenSessionList.findIndex(item => { - return item.session.screenId === screenSession.session.screenId - }) - if (screenSessionIndex != -1) { - Log.showError(TAG, 'Failed to add screen session, screen id:' + screenSession.session.screenId) - return - } - - this.screenSessionList.push(screenSession) - } - - private removeScreenSession(screenId: number) { - const screenSessionIndex = this.screenSessionList.findIndex(item => { - return item.session.screenId === screenId - }) - if (screenSessionIndex == -1) { - Log.showError(TAG, 'Failed to remove screen session, screen id:' + screenId) - return - } - - this.screenSessionList.splice(screenSessionIndex, 1) - } - - /** - * Get the screen session by screen id. - * @param screenId Id of the screen - * @return Session of the screen - */ - public getScreenSession(screenId: number): HWScreenSession { - const screenSessionIndex = this.screenSessionList.findIndex(item => { - return item.session.screenId === screenId - }) - if (screenSessionIndex == -1) { - Log.showError(TAG, 'Failed to get screen session, screen id:' + screenId) - return null - } - - return this.screenSessionList[screenSessionIndex] - } - - /** - * Get the root screen session. - * @return Session of the main screen - */ - public getMainScreenSession(): HWScreenSession { - if (this.screenSessionList.length > 0) { - return this.screenSessionList[0] - } - - return null - } -} diff --git a/common/src/main/ets/WindowScene/screen/session/SCBScreenSession.ts b/common/src/main/ets/WindowScene/screen/session/SCBScreenSession.ts new file mode 100644 index 00000000..5e5295de --- /dev/null +++ b/common/src/main/ets/WindowScene/screen/session/SCBScreenSession.ts @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2023 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 screenSessionManager from '@ohos.screenSessionManager' +import { SCBSceneContainerSessionArray } from '../../scene/session/SCBSceneContainerSession' +import { Log } from '../../../default/utils/Log' + +const TAG = 'SCBScreenSession' + +@Observed +export class SCBScreenProperty { + left: number = 0; + top: number = 0; + width: number = 0; + height: number = 0; + radius: number = 0; + rotation: number = 0; + screenId: number = -1; + + constructor() { + } + + update(screenProperty: screenSessionManager.ScreenProperty) { + this.left = screenProperty.bounds.left; + this.top = screenProperty.bounds.top; + this.width = screenProperty.bounds.width; + this.height = screenProperty.bounds.height; + this.radius = screenProperty.bounds.radius; + this.rotation = screenProperty.rotation; + } +} + +/** + * Session of a screen. + */ +@Observed +export class SCBScreenSession { + public readonly session: screenSessionManager.ScreenSession; + // Unit: px + public bounds: screenSessionManager.RRect = { + left: 0, + top: 0, + width: 0, + height: 0, + radius: 0 + }; + public rotation: number = 0; + onPropertyChange: Function; + + /** + * Constructor. + * @param session Session of the screen + */ + constructor(session: screenSessionManager.ScreenSession) { + this.session = session; + this.session.on('connect', (screenProperty: screenSessionManager.ScreenProperty) => { + this.onScreenConnect(screenProperty); + }) + this.session.on('disconnect', () => { + this.onScreenDisconnect(); + }) + this.session.on('propertyChange', (screenProperty: screenSessionManager.ScreenProperty) => { + this.onScreenPropertyChange(screenProperty); + }) + } + + registerPropertyChange(func: Function) { + Log.showInfo(TAG, 'registerPropertyChange ') + this.onPropertyChange = func + this.onPropertyChange && this.onPropertyChange({ + bounds: this.bounds, + rotation: this.rotation, + }) + } + + public updateProperty(screenProperty: screenSessionManager.ScreenProperty) { + this.bounds = { + left: screenProperty.bounds.left, + top: screenProperty.bounds.top, + width: screenProperty.bounds.width, + height: screenProperty.bounds.height, + radius: screenProperty.bounds.radius + } + this.rotation = screenProperty.rotation; + this.onPropertyChange && this.onPropertyChange(screenProperty) + Log.showInfo(TAG, `Update screen bounds[${this.bounds.left}, ${this.bounds.top}, + ${this.bounds.width}, ${this.bounds.height}]`) + } + + private onScreenConnect(screenProperty: screenSessionManager.ScreenProperty): void { + Log.showInfo(TAG, 'On screen connection.'); + this.updateProperty(screenProperty); + } + + private onScreenDisconnect(): void { + Log.showInfo(TAG, 'On screen disconnection.'); + } + + private onScreenPropertyChange(screenProperty: screenSessionManager.ScreenProperty): void { + Log.showInfo(TAG, 'On screen property change.'); + this.updateProperty(screenProperty); + } +} diff --git a/common/src/main/ets/default/constants/StyleConstants.ts b/common/src/main/ets/default/constants/StyleConstants.ts index d6fb0e04..a560e826 100644 --- a/common/src/main/ets/default/constants/StyleConstants.ts +++ b/common/src/main/ets/default/constants/StyleConstants.ts @@ -67,7 +67,8 @@ export class StyleConstants { static readonly PERCENTAGE_75 = '75%'; static readonly PERCENTAGE_70 = '70%'; static readonly PERCENTAGE_15 = '15%'; - static readonly PERCENTAGE_DIVIDER_HEIGHT = '2%'; + static readonly DIVIDER_HEIGHT = 8; + static readonly DIVIDER_BUTTON_WIDTH = '46vp'; static readonly DEFAULT_APP_IMAGE = '/common/pics/img_app_default.png'; static readonly DEFAULT_DELETE_IMAGE = '/common/pics/ic_public_delete.svg'; static readonly DEFAULT_BACKGROUND_IMAGE_RECENT = '/common/pics/ic_wallpaper_recent.jpg'; @@ -126,6 +127,7 @@ export class StyleConstants { static readonly DEFAULT_SMART_DOCK_MISSION_MERGIN_BOTTOM = 6; static readonly DEFAULT_SMART_DOCK_MISSION_MERGIN_RIGHT = 2; static readonly DEFAULT_SMART_DOCK_MISSION_IMAGE_HEIGHT = 80; + static readonly DEFAULT_SPLIT_EXIT_RATIO = 0.1; //image resources static readonly DEFAULT_FORM_MGR_BACKGROUND_IMAGE = '/common/pics/ic_wallpaper_form_manager.jpg'; @@ -174,4 +176,11 @@ export class StyleConstants { // the dpi of phone should be 480, but it is 320 currently. // so all dimensions have to be multiplied by 1.5 static readonly DPI_RATIO = 1; + + // gesture model + static readonly GESTURE_KEY = 'gestureModel' + static readonly RECENT_MARGIN = 50 + + // recent + static readonly RECENT_SCALE = 0.7 } \ No newline at end of file diff --git a/common/src/main/ets/default/manager/LauncherAbilityManager.ts b/common/src/main/ets/default/manager/LauncherAbilityManager.ts index a2b05236..50fab10e 100644 --- a/common/src/main/ets/default/manager/LauncherAbilityManager.ts +++ b/common/src/main/ets/default/manager/LauncherAbilityManager.ts @@ -26,8 +26,8 @@ import { CommonConstants } from '../constants/CommonConstants'; import { ResourceManager } from './ResourceManager'; import { EventConstants } from '../constants/EventConstants'; import { BadgeManager } from '../manager/BadgeManager'; -import { HWSceneSessionManager } from '../../WindowScene/scene/session/HWSceneSessionManager' -import { HWSceneInfo } from '../../WindowScene/scene/session/HWSceneInfo' +import { SCBSceneSessionManager } from '../../WindowScene/scene/session/SCBSceneSessionManager' +import { SCBSceneInfo } from '../../WindowScene/scene/session/SCBSceneInfo' const TAG = 'LauncherAbilityManager'; @@ -278,8 +278,8 @@ class LauncherAbilityManager { // Log.showError(TAG, `startApplication promise error: ${JSON.stringify(err)}`); // }); - let sceneInfo = new HWSceneInfo(paramBundleName, paramAbilityName) - HWSceneSessionManager.getInstance().startScene(sceneInfo) + let sceneInfo = new SCBSceneInfo(paramBundleName, paramAbilityName) + SCBSceneSessionManager.getInstance().startScene(sceneInfo) const sysEventInfo = { domain: 'LAUNCHER_APP', diff --git a/product/phone/src/main/ets/MainAbility/MainAbility.ts b/product/phone/src/main/ets/MainAbility/MainAbility.ts index d9acf9f7..db5623d0 100644 --- a/product/phone/src/main/ets/MainAbility/MainAbility.ts +++ b/product/phone/src/main/ets/MainAbility/MainAbility.ts @@ -20,8 +20,7 @@ import { Log } from '@ohos/common'; import { windowManager } from '@ohos/common'; import { RdbStoreManager } from '@ohos/common'; import { FormConstants } from '@ohos/common'; -import { HWSceneSessionManager } from '@ohos/common' -import { HWScreenSessionManager } from '@ohos/common' +import { SCBSceneSessionManager } from '@ohos/common' import { GestureNavigationManager } from '@ohos/gesturenavigation'; import StyleConstants from '../common/constants/StyleConstants'; import { navigationBarCommonEventManager } from '@ohos/common'; @@ -70,8 +69,7 @@ export default class MainAbility extends ServiceExtensionAbility { // // load recent // windowManager.createRecentWindow(); - HWScreenSessionManager.getInstance().init(); - HWSceneSessionManager.getInstance().loadContent('pages/EntryView', this.context); + SCBSceneSessionManager.getInstance().loadContent('pages/EntryView', this.context); } private initGlobalConst(): void { diff --git a/product/phone/src/main/ets/WindowScene/HWDesktop.ets b/product/phone/src/main/ets/SceneBoard/SCBDesktop.ets similarity index 96% rename from product/phone/src/main/ets/WindowScene/HWDesktop.ets rename to product/phone/src/main/ets/SceneBoard/SCBDesktop.ets index dc98c9b9..28d5244d 100644 --- a/product/phone/src/main/ets/WindowScene/HWDesktop.ets +++ b/product/phone/src/main/ets/SceneBoard/SCBDesktop.ets @@ -1,147 +1,147 @@ -/* - * Copyright (c) 2023 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 { Log } from '@ohos/common'; -import { CommonConstants } from '@ohos/common'; -import { EventConstants } from '@ohos/common'; -import { localEventManager } from '@ohos/common'; -import { SettingsModel } from '@ohos/common'; -import { LayoutViewModel } from '@ohos/common'; -import { SmartDock } from '@ohos/smartdock'; -import { PageDesktopLayout } from '@ohos/pagedesktop'; -import { FolderOpenComponent } from '@ohos/bigfolder'; -import { BigFolderConstants } from '@ohos/bigfolder'; -import PhoneStage from '../common/PhoneStage'; -import screenSessionManager from '@ohos.screenSessionManager'; - -const TAG = "HWDesktop"; - -@Component -export struct HWDesktop { - public bounds: screenSessionManager.RRect - @StorageLink('screenWidth') screenWidth: number = 0; - @StorageLink('screenHeight') @Watch('updateScreenInfo') screenHeight: number = 0; - @StorageLink('deviceType') deviceType: string = CommonConstants.DEFAULT_DEVICE_TYPE; - @State workSpaceWidth: number = 0; - @State workSpaceHeight: number = 0; - @State dockHeight: number = 0; - private mStage: PhoneStage = new PhoneStage(); - private mLayoutViewModel: LayoutViewModel; - private navigationBarStatus: string | undefined = '0'; - - aboutToAppear(): void { - Log.showInfo(TAG, 'aboutToAppear'); - this.mStage.onCreate(); - - // init layout config - this.mLayoutViewModel = LayoutViewModel.getInstance(); - this.getWindowSize(); - this.updateScreenSize(); - - this.registerPageDesktopNavigatorStatusChangeEvent(this.mLocalEventListener); - // this.navigationBarStatus = SettingsModel.getInstance().getValue(); - } - - registerPageDesktopNavigatorStatusChangeEvent(listener): void { - localEventManager.registerEventListener(listener, [EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE]); - } - - private readonly mLocalEventListener = { - onReceiveEvent: (event, params) => { - Log.showDebug(TAG, `receive event: ${event}, params: ${params}`); - if (event === EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE) { - this.navigationBarStatus = params; - this.updateScreenInfo(); - } - } - }; - - aboutToDisappear(): void { - this.mStage.onDestroy(); - Log.showInfo(TAG, 'aboutToDisappear'); - } - - onBackPress(): boolean { - Log.showInfo(TAG, 'onBackPress'); - ContextMenu.close(); - AppStorage.SetOrCreate('dialogControllerStatus', !AppStorage.Get('dialogControllerStatus')); - AppStorage.SetOrCreate('overlayMode', CommonConstants.OVERLAY_TYPE_HIDE); - AppStorage.SetOrCreate('openFolderStatus', BigFolderConstants.OPEN_FOLDER_STATUS_CLOSE); - return true; - } - - private updateScreenInfo(): void { - Log.showDebug(TAG, 'updateScreenInfo'); - if (this.screenWidth != 0 && this.screenHeight != 0) { - this.mLayoutViewModel.initScreen(this.navigationBarStatus); - globalThis.SmartDockStyleConfig.initConfig(); - globalThis.PhonePageDesktopGridStyleConfig.initConfig(); - globalThis.BigFolderStyleConfigInstance.initConfig(); - globalThis.FormStyleConfigInstance.initConfig(); - this.updateScreenSize(); - } - } - - private async getWindowSize(): Promise { - try { - this.screenWidth = px2vp(this.bounds.width); - this.screenHeight = px2vp(this.bounds.height); - AppStorage.SetOrCreate('screenWidth', this.screenWidth); - AppStorage.SetOrCreate('screenHeight', this.screenHeight); - } catch (error) { - Log.showError(TAG, `getWindowWidth or getWindowHeight error: ${error}`); - } - } - - private updateScreenSize(): void { - this.workSpaceWidth = this.screenWidth; - this.workSpaceHeight = this.mLayoutViewModel.getWorkSpaceHeight(); - this.dockHeight = this.mLayoutViewModel.getDockHeight(); - AppStorage.SetOrCreate('workSpaceWidth', this.workSpaceWidth); - AppStorage.SetOrCreate('workSpaceHeight', this.workSpaceHeight); - AppStorage.SetOrCreate('dockHeight', this.dockHeight); - Log.showDebug(TAG, `updateScreenSize product: ${this.deviceType}, screenWidth: ${this.screenWidth}, screenHeight: ${this.screenHeight}, - workSpaceWidth: ${this.workSpaceWidth}, workSpaceHeight: ${this.workSpaceHeight}, dockHeight: ${this.dockHeight}`); - } - - build() { - Stack() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { - Column() { - PageDesktopLayout(); - } - .height(this.workSpaceHeight) - .onAreaChange((oldValue: Area, newValue: Area): void => { - Log.showDebug(TAG, `onAreaChange navigationBarStatus: ${this.navigationBarStatus}`); - if (JSON.stringify(oldValue) == JSON.stringify(newValue)) return; - if (this.navigationBarStatus == "1") { - setTimeout(() => { - SettingsModel.getInstance().setValue(this.navigationBarStatus); - }, 50) - } - }) - - Column() { - SmartDock(); - } - .height(this.dockHeight) - } - - FolderOpenComponent(); - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2023 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 { Log } from '@ohos/common'; +import { CommonConstants } from '@ohos/common'; +import { EventConstants } from '@ohos/common'; +import { localEventManager } from '@ohos/common'; +import { SettingsModel } from '@ohos/common'; +import { LayoutViewModel } from '@ohos/common'; +import { SmartDock } from '@ohos/smartdock'; +import { PageDesktopLayout } from '@ohos/pagedesktop'; +import { FolderOpenComponent } from '@ohos/bigfolder'; +import { BigFolderConstants } from '@ohos/bigfolder'; +import PhoneStage from '../common/PhoneStage'; +import screenSessionManager from '@ohos.screenSessionManager'; + +const TAG = "SCBDesktop"; + +@Component +export struct SCBDesktop { + public bounds: screenSessionManager.RRect + @StorageLink('screenWidth') screenWidth: number = 0; + @StorageLink('screenHeight') @Watch('updateScreenInfo') screenHeight: number = 0; + @StorageLink('deviceType') deviceType: string = CommonConstants.DEFAULT_DEVICE_TYPE; + @State workSpaceWidth: number = 0; + @State workSpaceHeight: number = 0; + @State dockHeight: number = 0; + private mStage: PhoneStage = new PhoneStage(); + private mLayoutViewModel: LayoutViewModel; + private navigationBarStatus: string | undefined = '0'; + + aboutToAppear(): void { + Log.showInfo(TAG, 'aboutToAppear'); + this.mStage.onCreate(); + + // init layout config + this.mLayoutViewModel = LayoutViewModel.getInstance(); + this.getWindowSize(); + this.updateScreenSize(); + + this.registerPageDesktopNavigatorStatusChangeEvent(this.mLocalEventListener); + // this.navigationBarStatus = SettingsModel.getInstance().getValue(); + } + + registerPageDesktopNavigatorStatusChangeEvent(listener): void { + localEventManager.registerEventListener(listener, [EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE]); + } + + private readonly mLocalEventListener = { + onReceiveEvent: (event, params) => { + Log.showDebug(TAG, `receive event: ${event}, params: ${params}`); + if (event === EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE) { + this.navigationBarStatus = params; + this.updateScreenInfo(); + } + } + }; + + aboutToDisappear(): void { + this.mStage.onDestroy(); + Log.showInfo(TAG, 'aboutToDisappear'); + } + + onBackPress(): boolean { + Log.showInfo(TAG, 'onBackPress'); + ContextMenu.close(); + AppStorage.SetOrCreate('dialogControllerStatus', !AppStorage.Get('dialogControllerStatus')); + AppStorage.SetOrCreate('overlayMode', CommonConstants.OVERLAY_TYPE_HIDE); + AppStorage.SetOrCreate('openFolderStatus', BigFolderConstants.OPEN_FOLDER_STATUS_CLOSE); + return true; + } + + private updateScreenInfo(): void { + Log.showDebug(TAG, 'updateScreenInfo'); + if (this.screenWidth != 0 && this.screenHeight != 0) { + this.mLayoutViewModel.initScreen(this.navigationBarStatus); + globalThis.SmartDockStyleConfig.initConfig(); + globalThis.PhonePageDesktopGridStyleConfig.initConfig(); + globalThis.BigFolderStyleConfigInstance.initConfig(); + globalThis.FormStyleConfigInstance.initConfig(); + this.updateScreenSize(); + } + } + + private async getWindowSize(): Promise { + try { + this.screenWidth = px2vp(this.bounds.width); + this.screenHeight = px2vp(this.bounds.height); + AppStorage.SetOrCreate('screenWidth', this.screenWidth); + AppStorage.SetOrCreate('screenHeight', this.screenHeight); + } catch (error) { + Log.showError(TAG, `getWindowWidth or getWindowHeight error: ${error}`); + } + } + + private updateScreenSize(): void { + this.workSpaceWidth = this.screenWidth; + this.workSpaceHeight = this.mLayoutViewModel.getWorkSpaceHeight(); + this.dockHeight = this.mLayoutViewModel.getDockHeight(); + AppStorage.SetOrCreate('workSpaceWidth', this.workSpaceWidth); + AppStorage.SetOrCreate('workSpaceHeight', this.workSpaceHeight); + AppStorage.SetOrCreate('dockHeight', this.dockHeight); + Log.showDebug(TAG, `updateScreenSize product: ${this.deviceType}, screenWidth: ${this.screenWidth}, screenHeight: ${this.screenHeight}, + workSpaceWidth: ${this.workSpaceWidth}, workSpaceHeight: ${this.workSpaceHeight}, dockHeight: ${this.dockHeight}`); + } + + build() { + Stack() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { + Column() { + PageDesktopLayout(); + } + .height(this.workSpaceHeight) + .onAreaChange((oldValue: Area, newValue: Area): void => { + Log.showDebug(TAG, `onAreaChange navigationBarStatus: ${this.navigationBarStatus}`); + if (JSON.stringify(oldValue) == JSON.stringify(newValue)) return; + if (this.navigationBarStatus == "1") { + setTimeout(() => { + SettingsModel.getInstance().setValue(this.navigationBarStatus); + }, 50) + } + }) + + Column() { + SmartDock(); + } + .height(this.dockHeight) + } + + FolderOpenComponent(); + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/product/phone/src/main/ets/WindowScene/HWDivider.ets b/product/phone/src/main/ets/SceneBoard/SCBDivider.ets similarity index 45% rename from product/phone/src/main/ets/WindowScene/HWDivider.ets rename to product/phone/src/main/ets/SceneBoard/SCBDivider.ets index 3eb2767e..4fe3749a 100644 --- a/product/phone/src/main/ets/WindowScene/HWDivider.ets +++ b/product/phone/src/main/ets/SceneBoard/SCBDivider.ets @@ -13,35 +13,27 @@ * limitations under the License. */ -import { HWDividerParam, StyleConstants } from '@ohos/common' +import { SCBDividerParam, StyleConstants } from '@ohos/common' import { Log } from '@ohos/common' -import screenSessionManager from '@ohos.screenSessionManager' +import { SCBSceneSessionManager, SCBSceneContainerSession, SCBScreenProperty } from '@ohos/common' +import { SCBGestureAction, SCBGestureActionId } from '@ohos/common' -const TAG = 'HWDivider' +const TAG = 'SCBDivider' @Component -export struct HWDivider { - @Link dividerParam: HWDividerParam - screenBounds: screenSessionManager.RRect +export struct SCBDivider { + @Link dividerParam: SCBDividerParam + @Link sceneContainerSession: SCBSceneContainerSession; + @Link screenProperty: SCBScreenProperty; + onGestureChange: Function; buildLog1() { - Log.showInfo(TAG, "Action Update " + " priScaleY: " + this.dividerParam.primaryScaleY + " secScaleY: " + this.dividerParam.secondaryScaleY) - Log.showInfo(TAG, "event.offsetY: " + this.dividerParam.translateY) - return true - } - - buildLog2() { - Log.showInfo(TAG, "Action end primaryH: " + parseFloat(this.dividerParam.primaryH) + " secondaryH: " + parseFloat(this.getSecondaryH())) - return true - } - - buildLog3() { - Log.showInfo(TAG, "Action begin primaryH: " + parseFloat(this.dividerParam.primaryH) + " secondaryH: " + parseFloat(this.getSecondaryH())) + Log.showInfo(TAG, "Action begin primaryH: " + parseFloat(this.dividerParam.primaryH)) return true } getSecondaryH(): string { - let str = (100 - parseFloat(this.dividerParam.primaryH) - parseFloat(StyleConstants.PERCENTAGE_DIVIDER_HEIGHT)).toString(); + let str = (100 - parseFloat(this.dividerParam.primaryH) - StyleConstants.DIVIDER_HEIGHT / this.screenProperty.height * 100).toString(); str += "%"; return str; } @@ -50,9 +42,10 @@ export struct HWDivider { // Divider Stack({ alignContent: Alignment.Center }) { Button() - .backgroundColor(Color.White) - .width('25%') - .height('80%') + .responseRegion({ x: 0, y: '-500%', width: '100%', height: '1100%' }) + .backgroundColor('#CCFFFFFF') + .width(StyleConstants.DIVIDER_BUTTON_WIDTH) + .height('50%') .gesture(PanGesture({ distance: 1 }) .onActionStart((event: GestureEvent) => { this.dividerParam.blurRadius = 50 @@ -60,9 +53,9 @@ export struct HWDivider { .onActionUpdate((event: GestureEvent) => { this.dividerParam.translateX = event.offsetX this.dividerParam.translateY = event.offsetY - let beginPrimaryH = px2vp(this.screenBounds.height) * parseFloat(this.dividerParam.primaryH) * 0.01 + let beginPrimaryH = px2vp(this.screenProperty.height) * parseFloat(this.dividerParam.primaryH) * 0.01 this.dividerParam.primaryScaleY = (beginPrimaryH + event.offsetY) / beginPrimaryH - let beginSecH = px2vp(this.screenBounds.height) * parseFloat(this.getSecondaryH()) * 0.01 + let beginSecH = px2vp(this.screenProperty.height) * parseFloat(this.getSecondaryH()) * 0.01 this.dividerParam.secondaryScaleY = (beginSecH - event.offsetY) / beginSecH this.dividerParam.secTransY = event.offsetY }) @@ -74,14 +67,33 @@ export struct HWDivider { this.dividerParam.secTransY = 0 this.dividerParam.primaryScaleY = 1 this.dividerParam.secondaryScaleY = 1 - let beginPrimaryH = px2vp(this.screenBounds.height) * parseFloat(this.dividerParam.primaryH) * 0.01 - this.dividerParam.primaryH = ((beginPrimaryH + event.offsetY) / px2vp(this.screenBounds.height)) * 100 + '%' + let beginPrimaryH = px2vp(this.screenProperty.height) * parseFloat(this.dividerParam.primaryH) * 0.01 + let heightRatio = (beginPrimaryH + event.offsetY) / px2vp(this.screenProperty.height); + this.dividerParam.primaryH = heightRatio * 100 + '%' this.dividerParam.blurRadius = 0 + if (this.buildLog1()){} + if (heightRatio < StyleConstants.DEFAULT_SPLIT_EXIT_RATIO) { + Log.showInfo(TAG, "exit primarySession with ratio: " + heightRatio) + this.dividerParam.init() + let action = new SCBGestureAction({ + id: SCBGestureActionId.EXIT_SPILT, + sessionId: this.sceneContainerSession.primarySession.session.persistentId, + }); + this.onGestureChange && this.onGestureChange(action); + } else if (heightRatio > (1 - StyleConstants.DEFAULT_SPLIT_EXIT_RATIO)) { + this.dividerParam.init() + Log.showInfo(TAG, "exit secondarySession with ratio: " + heightRatio) + let action = new SCBGestureAction({ + id: SCBGestureActionId.EXIT_SPILT, + sessionId: this.sceneContainerSession.secondarySession.session.persistentId, + }); + this.onGestureChange && this.onGestureChange(action); + } })) } .translate({ y: this.dividerParam.translateY }) .width('100%') - .height(StyleConstants.PERCENTAGE_DIVIDER_HEIGHT) + .height(StyleConstants.DIVIDER_HEIGHT.toString() + 'vp') .backgroundColor(Color.Black) } } diff --git a/product/phone/src/main/ets/WindowScene/HWGestureNavBar.ets b/product/phone/src/main/ets/SceneBoard/SCBGestureNavBar.ets similarity index 31% rename from product/phone/src/main/ets/WindowScene/HWGestureNavBar.ets rename to product/phone/src/main/ets/SceneBoard/SCBGestureNavBar.ets index 61bf1830..c00908d3 100644 --- a/product/phone/src/main/ets/WindowScene/HWGestureNavBar.ets +++ b/product/phone/src/main/ets/SceneBoard/SCBGestureNavBar.ets @@ -13,21 +13,19 @@ * limitations under the License. */ -import { HWSceneContainerSession, HWDividerParam, HWRecentViewParam } from '@ohos/common'; -import { HWSceneSessionManager } from '@ohos/common'; -import { HWScreenSession, DesktopState } from '@ohos/common'; -import { Log } from '@ohos/common'; +import { SCBGestureModel ,SCBSceneContainerSessionArray} from '@ohos/common'; +import { SCBSceneSessionManager } from '@ohos/common'; +import { SCBGestureAction, SCBGestureActionId} from '@ohos/common'; +import { Log, Trace } from '@ohos/common'; import { StyleConstants } from '@ohos/common'; -const TAG = 'HWGestureNavBar'; +const TAG = 'SCBGestureNavBar'; @Component -export struct HWGestureNavBar { - @Link sceneContainerSession: HWSceneContainerSession; - @Link screenSession: HWScreenSession; - @Link dividerParam: HWDividerParam; - @Link recentViewParam: HWRecentViewParam; - +export struct SCBGestureNavBar { + @ObjectLink containerSessionList: SCBSceneContainerSessionArray; + @StorageLink('gestureModel') gestureModel: SCBGestureModel = new SCBGestureModel(); + onGestureChange: Function; build() { // Gesture navigation bar Stack({ alignContent: Alignment.Center }) { @@ -39,51 +37,60 @@ export struct HWGestureNavBar { .position({ y: '97%' }) .width('100%') .height('3%') - .backgroundColor(Color.Transparent) + .opacity(0) .gesture(PanGesture() .onActionStart((event: GestureEvent) => { - this.screenSession.desktopState = DesktopState.DRAGGING; - this.recentViewParam.margin = 50 - let scrollWidth = - this.screenSession.sceneContainerSessionList.length * px2vp(this.sceneContainerSession.screenBounds.width) + - (this.screenSession.sceneContainerSessionList.length - 1) * this.recentViewParam.margin; - this.recentViewParam.offsetX = px2vp(this.sceneContainerSession.screenBounds.width) - scrollWidth; - - this.recentViewParam.centerX = - (1 - px2vp(this.sceneContainerSession.screenBounds.width) / 2 / scrollWidth) * 100 + '%'; - this.recentViewParam.centerY = '100%'; + let action = new SCBGestureAction({ + id: SCBGestureActionId.SLIDE_UP_BEGIN + }); + this.onGestureChange && this.onGestureChange(action); }) .onActionUpdate((event: GestureEvent) => { - let translateRatio = 0.6 * Math.pow(this.recentViewParam.scaleX, 2) + 0.4; - this.recentViewParam.translateX = event.offsetX * translateRatio; - if (1 + event.offsetY / px2vp(this.sceneContainerSession.screenBounds.height) * 1.3 > 0.25) { - this.recentViewParam.translateY = event.offsetY; - } - - this.recentViewParam.scaleX = - 1 + this.recentViewParam.translateY / px2vp(this.sceneContainerSession.screenBounds.height) * 1.3; - this.recentViewParam.scaleX = Math.max(this.recentViewParam.scaleX, 0.25); - this.recentViewParam.scaleX = Math.min(this.recentViewParam.scaleX, 1); - this.recentViewParam.scaleY = this.recentViewParam.scaleX; + let action = new SCBGestureAction({ + id: SCBGestureActionId.SLIDING_UP, + gestureOffsetX: event.offsetX, + gestureOffsetY: event.offsetY + }); + this.onGestureChange && this.onGestureChange(action); }) .onActionEnd((event: GestureEvent) => { + const index = this.containerSessionList.findIndex((item) => { + return item.isActive === true; + }); + if (index === -1) { + Log.showError(TAG, 'Failed to find active scene container session.'); + return null; + } + let activeSceneContainerSession = this.containerSessionList[index]; + var action; if (event.offsetY < -400) { - HWSceneSessionManager.getInstance().requestSceneContainerBackground(this.sceneContainerSession); - this.screenSession.enterHomeView(); + SCBSceneSessionManager.getInstance().requestSceneContainerBackground(activeSceneContainerSession.screenProperty.screenId, activeSceneContainerSession.containerId); + action = new SCBGestureAction({ + id: SCBGestureActionId.HOME + }); } else if (event.offsetY < -200) { - this.dividerParam.primaryH = ((100 - parseFloat(StyleConstants.PERCENTAGE_DIVIDER_HEIGHT)) / 2) + '%'; - this.sceneContainerSession.isSplit = true; - this.screenSession.enterSplitView(); + activeSceneContainerSession.dividerParam.primaryH = ((100 - StyleConstants.DIVIDER_HEIGHT / activeSceneContainerSession.screenProperty.height * 100) / 2) + '%'; + if (!activeSceneContainerSession.isSplit) { + activeSceneContainerSession.isSplit = true; + action = new SCBGestureAction({ + id: SCBGestureActionId.ENTER_SPLIT + }); + } else { + action = new SCBGestureAction({ + id: SCBGestureActionId.ENTER_RECENT + }); + } } else if (event.offsetY < -100) { - let recentViewSceneSpace = 50; - let scrollWidth = - this.screenSession.sceneContainerSessionList.length * px2vp(this.sceneContainerSession.screenBounds.width) + - (this.screenSession.sceneContainerSessionList.length - 1) * recentViewSceneSpace; - this.recentViewParam.offsetX = px2vp(this.sceneContainerSession.screenBounds.width) - scrollWidth; - this.screenSession.enterRecentView(); + action = new SCBGestureAction({ + id: SCBGestureActionId.ENTER_RECENT + }); } else { - this.screenSession.enterAppView(this.sceneContainerSession); + action = new SCBGestureAction({ + id: SCBGestureActionId.FULLSCENE + }); + SCBSceneSessionManager.getInstance().requestSceneContainerActivation(activeSceneContainerSession.screenProperty.screenId, activeSceneContainerSession.containerId); } + this.onGestureChange && this.onGestureChange(action); })) } } diff --git a/product/phone/src/main/ets/SceneBoard/SCBScene.ets b/product/phone/src/main/ets/SceneBoard/SCBScene.ets new file mode 100644 index 00000000..924f564f --- /dev/null +++ b/product/phone/src/main/ets/SceneBoard/SCBScene.ets @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2023 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 { SCBSceneSession, SCBDividerParam, SceneState, SCBGestureModel } from '@ohos/common' +import { SCBGestureActionId, SCBGestureAction } from '@ohos/common' +import { StyleConstants } from '@ohos/common' +import { Log } from '@ohos/common' + + +const TAG = 'SCBScene' + +@Component +export struct SCBScene { + @ObjectLink sceneSession: SCBSceneSession + @Link dividerParam: SCBDividerParam + @StorageLink('gestureModel') gestureModel: SCBGestureModel = new SCBGestureModel() + onGestureChange: Function; + + buildLog(sceneSession: SCBSceneSession) { + if (sceneSession) { + Log.showInfo(TAG, 'SCBSceneSession bundle name: ' + sceneSession.sceneInfo.bundleName + ' id: ' + sceneSession.session.persistentId); + } else { + Log.showError(TAG, 'SCBSceneSession is null'); + } + Log.showInfo(TAG, 'SCBScene build: ' + this.sceneSession?.sceneInfo.bundleName + ' id: ' + this.sceneSession?.session.persistentId); + return true + } + + buildLog1() { + Log.showInfo(TAG, 'SCBScene panGesture end '); + return true + } + + buildLog3() { + Log.showInfo(TAG, 'SCBScene longPress begin'); + return true + } + + enableShow() { + if (this.sceneSession) { + if (this.sceneSession.isActive) { + return true; + } + if (this.gestureModel.sceneState === SceneState.SLIDING_UP || this.gestureModel.sceneState === SceneState.RECENT) { + return true; + } + } + Log.showInfo(TAG, 'enable show is false'); + return false; + } + + build() { + if (this.enableShow()) { + Stack() { + if (this.buildLog(this.sceneSession)) { + } + HostWindowScene(this.sceneSession?.session.persistentId) + .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + if (this.gestureModel?.sceneState === SceneState.RECENT) { + Stack() { + } + .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + .priorityGesture( + GestureGroup(GestureMode.Sequence, + LongPressGesture({ repeat: true }) + .onAction((event: GestureEvent) => { + if (this.buildLog3()) { + } + }) + .onActionEnd(() => { + this.gestureModel.enableScroll = false + }), + PanGesture({ direction: PanDirection.Horizontal }) // when screen is vertical, use Vertical + .onActionStart((event: GestureEvent) => { + }) + .onActionUpdate((event: GestureEvent) => { + this.sceneSession.translateX = event.offsetX; + }) + .onActionEnd((event: GestureEvent) => { + if (this.buildLog1()) { + } + if (event.offsetX < -200 || event.offsetX > 200) { + let action = new SCBGestureAction({ + id: SCBGestureActionId.EXIT_SPILT, + sessionId: this.sceneSession.session.persistentId + }); + this.onGestureChange && this.onGestureChange(action); + } + this.dividerParam.init(); + this.sceneSession.translateX = 0; + }) + ) + ) + } + } + .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + .translate({ x: this.sceneSession?.translateX }) + } + } +} diff --git a/product/phone/src/main/ets/SceneBoard/SCBSceneContainer.ets b/product/phone/src/main/ets/SceneBoard/SCBSceneContainer.ets new file mode 100644 index 00000000..60b55a8f --- /dev/null +++ b/product/phone/src/main/ets/SceneBoard/SCBSceneContainer.ets @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2023 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 curves from '@ohos.curves' +import { SCBSceneContainerSession, SCBDividerParam, SCBGestureModel } from '@ohos/common' +import { SceneState } from '@ohos/common'; +import { SCBSceneSessionManager, SCBGestureAction, SCBGestureActionId, SCBScreenProperty } from '@ohos/common'; +import { SCBScene } from './SCBScene' +import { SCBDivider } from './SCBDivider' +import { Log } from '@ohos/common' +import { StyleConstants } from '@ohos/common' + +const TAG = 'SCBSceneContainer' + +@Component +export struct SCBSceneContainer { + @ObjectLink sceneContainerSession: SCBSceneContainerSession; + @ObjectLink dividerParam: SCBDividerParam; + @Link screenProperty: SCBScreenProperty; + @StorageLink('gestureModel') gestureModel: SCBGestureModel = new SCBGestureModel(); + + containerIdx : number; + onGestureChange: Function; + + buildLog2() { + Log.showInfo(TAG, " containerIdx: "+ this.containerIdx + " containerId: " + this.sceneContainerSession.containerId + + ' transX: ' + this.sceneContainerSession.translateX + ' transY: ' + this.sceneContainerSession.translateY + ' scaleX: ' + + this.sceneContainerSession.scaleX + ' scaleY: ' + this.sceneContainerSession.scaleY) + return true + } + + buildLog() { + return true + } + + enableShow() { + if (!this.sceneContainerSession) { + return false; + } + if (this.sceneContainerSession && this.sceneContainerSession.isActive) { + return true + } + if (this.gestureModel.sceneState === SceneState.SLIDING_UP || this.gestureModel.sceneState === SceneState.RECENT) { + return true + } + return false + } + + build() { + if (this.enableShow()) { + Stack() { + Column() { + if (this.buildLog2()) {} + if (this.sceneContainerSession.primarySession) { + SCBScene({ sceneSession: this.sceneContainerSession.primarySession, dividerParam: $dividerParam, onGestureChange: this.onGestureChange }) + .width('100%') + .height(this.dividerParam.primaryH) + .scale({ y: this.dividerParam.primaryScaleY, centerY: 0 }) + .blur(this.dividerParam.blurRadius) + } + + // divider + if (this.sceneContainerSession.isSplit) { + SCBDivider({ dividerParam: $dividerParam, sceneContainerSession: $sceneContainerSession, + screenProperty: $screenProperty, onGestureChange: this.onGestureChange}) + } + + // When primary Exit + if (this.sceneContainerSession.secondarySession) { + SCBScene({ sceneSession: this.sceneContainerSession.secondarySession, dividerParam: $dividerParam, onGestureChange: this.onGestureChange }) + .scale({ y: this.dividerParam.secondaryScaleY, centerY: 0 }) + .blur(this.dividerParam.blurRadius) + .translate({ y: this.dividerParam.secTransY }) + .flexShrink(1) + } + } + .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + + if (this.gestureModel?.sceneState === SceneState.RECENT) { + Stack() { + } + .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + .hitTestBehavior(HitTestMode.Transparent) + .onClick(() => { + SCBSceneSessionManager.getInstance().requestSceneContainerActivation(this.screenProperty.screenId, this.sceneContainerSession.containerId); + let action = new SCBGestureAction({ + id: SCBGestureActionId.FULLSCENE + }); + this.onGestureChange && this.onGestureChange(action); + }) + .parallelGesture( + PanGesture({ direction: PanDirection.Vertical }) + .onActionStart((event: GestureEvent) => { + }) + .onActionUpdate((event: GestureEvent) => { + if (event.offsetY < 100) { + this.sceneContainerSession.translateY = event.offsetY; + } + }) + .onActionEnd((event: GestureEvent) => { + var action; + if (event.offsetY < -300) { + SCBSceneSessionManager.getInstance().requestSceneContainerDestruction( + this.screenProperty.screenId, this.sceneContainerSession.containerId); + action = new SCBGestureAction({ + id: SCBGestureActionId.DESTROY_IN_RECENT + }); + } else { + this.sceneContainerSession.translateY = 0; + action = new SCBGestureAction({ + id: SCBGestureActionId.FULLSCENE + }); + } + this.onGestureChange && this.onGestureChange(action); + })) + } + + if (this.gestureModel?.sceneState !== SceneState.RECENT + && this.gestureModel?.sceneState !== SceneState.SPLIT) { + Stack({ alignContent: Alignment.Center }) { + Button() + .backgroundColor(Color.Black) + .width('35%') + .height('25%') + } + .position({ y: '97%' }) + .width('100%') + .height('3%') + .hitTestBehavior(HitTestMode.None) + } + } + .id('containerSession' + this.sceneContainerSession.containerId.toString()) + .size({ width: this.sceneContainerSession.width, height: this.sceneContainerSession.height }) + .scale({ + x: this.sceneContainerSession.scaleX, + y: this.sceneContainerSession.scaleY, + centerX: this.sceneContainerSession.centerX, + centerY: this.sceneContainerSession.centerY + }) + .translate({ x: this.sceneContainerSession.translateX, y: this.sceneContainerSession.translateY }) + } + + } +} diff --git a/product/phone/src/main/ets/SceneBoard/SCBScenePanel.ets b/product/phone/src/main/ets/SceneBoard/SCBScenePanel.ets new file mode 100644 index 00000000..2357b204 --- /dev/null +++ b/product/phone/src/main/ets/SceneBoard/SCBScenePanel.ets @@ -0,0 +1,523 @@ +/* + * Copyright (c) 2023 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 { SCBScreenProperty }from '@ohos/common'; +import { SceneState, SCBGestureModel, SCBSceneContainerSessionArray} from '@ohos/common'; +import { SCBSceneContainerSession, SCBSceneInfo } from '@ohos/common'; +import { SCBSceneSessionManager, SCBSceneSession } from '@ohos/common'; +import { SCBGestureActionId, SCBGestureAction } from '@ohos/common'; +import { SCBSceneContainer } from './SCBSceneContainer'; +import { Log, Trace } from '@ohos/common'; +import { StyleConstants } from '@ohos/common'; +import { SCBGestureNavBar } from './SCBGestureNavBar' +import sceneSessionManager from '@ohos.sceneSessionManager' +const TAG = 'SCBScenePanel'; + +@Component +export struct SCBScenePanel { + @State containerSessionList: SCBSceneContainerSessionArray = new SCBSceneContainerSessionArray(); + @Link screenProperty: SCBScreenProperty; + + @StorageLink('gestureModel') gestureModel: SCBGestureModel = new SCBGestureModel(); + @State recentViewHitTestMode: HitTestMode = HitTestMode.None; + @State scrollDirection: ScrollDirection = ScrollDirection.None; + @State mBlurRadius: number = 20; + + private scroller: Scroller = new Scroller(); + private screenWidth: number = -1 + private viewWidth: number = -1 + private currentState: number = SceneState.HOME + @State containerTranslation: number[]=[] + @State containerAlpha : number[]=[] + @State containerScale: number[]=[] + + buildLog(sceneContainerSession: SCBSceneContainerSession) { + Log.showInfo(TAG, `sceneContainerSession id: ${sceneContainerSession.containerId}`); + Log.showInfo(TAG, `sceneContainerSession isActive: ${sceneContainerSession.isActive}`); + Log.showInfo(TAG, 'sceneState:' + this.gestureModel?.sceneState + ' length: ' + this.containerSessionList.length); + return true; + } + + // sceneSessionManager 当前屏幕的scene的添加 + isRecent(): boolean { + Log.showInfo(TAG,"isRecent = " +(this.gestureModel.sceneState === SceneState.RECENT)) + Log.showInfo(TAG, "this.gestureModel.flexOffsetX: " + (this.gestureModel.flexOffsetX) + ' flexWidth: ' + (this.gestureModel.flexWidth)) + Log.showInfo(TAG, "this.scroller.currentOffset().xOffset: " + (this.scroller.currentOffset().xOffset)) + + if (this.gestureModel.sceneState === SceneState.RECENT) { + this.initRecentParams(); + this.currentState = this.gestureModel.sceneState; + Log.showInfo(TAG, "after scrollTo this.scroller.currentOffset().xOffset: " + (this.scroller.currentOffset().xOffset)) + return true; + } else { + this.containerTranslation = []; + this.containerAlpha = []; + this. containerScale = []; + this.currentState = this.gestureModel.sceneState; + return false; + } + } + + private initView() { + this.gestureModel.initAll(); + this.containerSessionList.forEach((containerSession, index)=>{ + containerSession.init(); + }); + } + + private enterRecentView() { + Log.showInfo(TAG, 'enterRecentView') + let screenW = px2vp(this.screenProperty.width); + let listLen = this.containerSessionList.length; + this.gestureModel.flexWidth = (listLen * screenW * StyleConstants.RECENT_SCALE + Number(StyleConstants.RECENT_MARGIN) * (listLen - 1)) + + this.gestureModel.flexPadding * 2 + if (listLen > 2) { + let tmpX = (screenW * StyleConstants.RECENT_SCALE - (this.gestureModel.flexPadding - Number(StyleConstants.RECENT_MARGIN))); + this.gestureModel.flexOffsetX = -(this.gestureModel.flexWidth - screenW - tmpX - this.gestureModel.flexPadding) + } else { + this.gestureModel.flexOffsetX = -(this.gestureModel.flexWidth - screenW) // decide final show pos with scroll to + } + this.gestureModel.multiViewShow = true; + for (let i = 0; i < listLen; i++) { + let containerSession = this.containerSessionList[i]; + containerSession.translateX = -this.gestureModel.flexPadding - i * (this.gestureModel.flexPadding * 2 - Number(StyleConstants.RECENT_MARGIN)) + containerSession.translateY = 0; + containerSession.scaleX = StyleConstants.RECENT_SCALE; + containerSession.scaleY = StyleConstants.RECENT_SCALE; + Log.showDebug(TAG, `idx: ${i} translateX: ${containerSession.translateX}.`); + } + Log.showDebug(TAG, `listLen: ${listLen} flexOffsetX: ${this.gestureModel.flexOffsetX}, flexWidth:${this.gestureModel.flexWidth}.`); + } + + private exitSplitView(persistentId: number) { + Log.showInfo(TAG, 'exitSplitView.'); + const index = this.containerSessionList.findIndex((item) => { + return item.primarySession.session.persistentId === persistentId || + item.secondarySession.session.persistentId === persistentId; + }); + if (index === -1) { + Log.showError(TAG, 'Failed to get scene containerSession with session id: ' + + persistentId); + return null; + } + let currContainerSession = this.containerSessionList[index] + let sceneSession = null; + if (currContainerSession.primarySession && currContainerSession.primarySession.session.persistentId === persistentId) { + sceneSession = currContainerSession.primarySession; + } else { + sceneSession = currContainerSession.secondarySession; + } + if (!sceneSession) { + Log.showError(TAG, 'Failed to get scene sceneSession with session id: ' + + persistentId); + return; + } + currContainerSession.removeSceneSession(sceneSession); + currContainerSession.init(); + currContainerSession.isSplit = false; + let newSceneContainerSession = new SCBSceneContainerSession(sceneSession, this.screenProperty); + newSceneContainerSession.isActive = false; + this.containerSessionList.splice(index, 0, newSceneContainerSession); + sceneSession.requestSessionBackground(); + if (this.gestureModel.sceneState !== SceneState.RECENT) { + let action = new SCBGestureAction({ + id: SCBGestureActionId.FULLSCENE + }); + this.onGestureChange(action); + } else { + this.enterRecentView(); + } + } + + private updateRecentView(offsetX:number, offsetY:number) { + Log.showDebug(TAG, 'updateRecentView') + let currContainerSession = this.getActiveSceneContainerSession(); + let screenH = px2vp(this.screenProperty.height); + let screenW = px2vp(this.screenProperty.width); + currContainerSession.scaleX = + 1 + currContainerSession.translateY / screenH * 1.3; + currContainerSession.scaleX = Math.max(currContainerSession.scaleX, 0.25); + currContainerSession.scaleX = Math.min(currContainerSession.scaleX, 1); + currContainerSession.scaleY = currContainerSession.scaleX; + currContainerSession.translateX = offsetX - this.gestureModel.flexPadding; + currContainerSession.translateY = offsetY + (1 - currContainerSession.scaleY) * Number(currContainerSession.height) / 2; + if (offsetY > -(screenW * 0.1)) { + this.gestureModel.multiViewShow = false + let nowFinalFlexWidth = screenW * StyleConstants.RECENT_SCALE + this.gestureModel.flexPadding * 2; + if (this.gestureModel.flexWidth !== nowFinalFlexWidth) { + this.gestureModel.flexWidth = nowFinalFlexWidth; + } + return; + } + this.gestureModel.multiViewShow = true + let listLen = this.containerSessionList.length + + let tmpFinalFlexWith = (listLen * screenW * StyleConstants.RECENT_SCALE + Number(StyleConstants.RECENT_MARGIN) * (listLen - 1)) + + this.gestureModel.flexPadding * 2 + if (this.gestureModel.flexWidth !== tmpFinalFlexWith) { + this.gestureModel.flexWidth = tmpFinalFlexWith; + } + let tmpFlexWidth = (listLen * screenW * currContainerSession.scaleX + Number(StyleConstants.RECENT_MARGIN) * (listLen - 1)) + this.gestureModel.flexPadding * 2 + let disToEndX = (tmpFlexWidth - screenW + ((1 - currContainerSession.scaleX) * screenW) - this.gestureModel.flexPadding) // final view left space to right side is pad + (1 -scaleX) * W / 2, expect (1 -scaleX) * W / 2 + for (let i = 0; i < listLen; i++) { + let containerSession = this.containerSessionList[i]; + containerSession.translateX = offsetX - i * ((1 - currContainerSession.scaleX) * screenW - Number(StyleConstants.RECENT_MARGIN)) - disToEndX + containerSession.translateY = currContainerSession.translateY; + containerSession.scaleX = currContainerSession.scaleX; + containerSession.scaleY = currContainerSession.scaleY; + } + } + + private calculateCurrViewOnSlidingBegin() { + let screenH = px2vp(this.screenProperty.height); + let screenW = px2vp(this.screenProperty.width); + this.gestureModel.flexPadding = (1 - StyleConstants.RECENT_SCALE) * screenW / 2 + this.gestureModel.flexHeight = screenH; + let listLen = this.containerSessionList.length; + this.gestureModel.flexWidth = (listLen * screenW * StyleConstants.RECENT_SCALE + Number(StyleConstants.RECENT_MARGIN) * (listLen - 1)) + + this.gestureModel.flexPadding * 2 + } + + private addSceneContainerSession(sceneContainerSession: SCBSceneContainerSession): void { + const index = this.containerSessionList.findIndex(item => { + return item.containerId === sceneContainerSession.containerId; + }); + if (index == -1) { + Log.showInfo(TAG, 'Add scene container session, id: ' + sceneContainerSession.containerId); + this.containerSessionList.push(sceneContainerSession); + } + } + + private removeSceneContainerSession(sceneContainerSession: SCBSceneContainerSession): void { + const index = this.containerSessionList.findIndex((item) => { + return item.containerId === sceneContainerSession.containerId; + }); + if (index != -1) { + Log.showInfo(TAG, 'Remove scene container session, id: ' + sceneContainerSession.containerId); + this.containerSessionList.splice(index, 1); + } + } + + private raiseSceneToTop(sceneContainerSession: SCBSceneContainerSession) { + Log.showInfo(TAG, 'raiseSceneToTop.'); + + // To move the sceneContainerSession to the last of list. + this.removeSceneContainerSession(sceneContainerSession); + this.addSceneContainerSession(sceneContainerSession); + } + + private getSceneSession(sceneInfo: SCBSceneInfo): SCBSceneSession { + for (let i = 0; i < this.containerSessionList.length; ++i) { + let primarySession = this.containerSessionList[i].primarySession; + let secondarySession = this.containerSessionList[i].secondarySession; + if (primarySession && + primarySession.sceneInfo.bundleName == sceneInfo.bundleName && + primarySession.sceneInfo.abilityName == sceneInfo.abilityName) { + return primarySession; + } + if (secondarySession && + secondarySession.sceneInfo.bundleName == sceneInfo.bundleName && + secondarySession.sceneInfo.abilityName == sceneInfo.abilityName) { + return secondarySession; + } + } + return null; + } + + private requestSceneSession(sceneInfo: SCBSceneInfo): SCBSceneSession { + let scbSceneSession = this.getSceneSession(sceneInfo); + if (scbSceneSession == null || sceneInfo.isNewInstance) { + let sceneSession = sceneSessionManager.requestSceneSession({ + bundleName: sceneInfo.bundleName, + abilityName: sceneInfo.abilityName + }); + scbSceneSession = new SCBSceneSession(sceneSession, sceneInfo); + } + return scbSceneSession; + } + + private getSceneContainerSession(sceneSession: SCBSceneSession): SCBSceneContainerSession { + if (sceneSession === null) { + return null; + } + const index = this.containerSessionList.findIndex((item) => { + return item.primarySession === sceneSession || item.secondarySession === sceneSession; + }); + if (index === -1) { + return null; + } + return this.containerSessionList[index]; + } + + private getSceneContainerSessionWithContainerId(containerId: number): SCBSceneContainerSession { + const index = this.containerSessionList.findIndex(item => { + return item.containerId === containerId; + }); + if (index === -1) { + Log.showError(TAG, `Failed to find containerSession with id:${containerId}`) + return; + } + return this.containerSessionList[index]; + } + + private getActiveSceneContainerSession(): SCBSceneContainerSession { + const index = this.containerSessionList.findIndex((item) => { + return item.isActive === true; + }); + if (index === -1) { + Log.showError(TAG, 'Failed to find active scene container session.'); + return null; + } + return this.containerSessionList[index]; + } + + onStartScene(sceneInfo: SCBSceneInfo) { + let sceneSession = this.requestSceneSession(sceneInfo); + if (sceneSession == null) { + Log.showError(TAG, 'Failed to request scene session!'); + return; + } + Log.showInfo(TAG,"sceneState: " + this.gestureModel.sceneState ); + if (this.gestureModel.sceneState === SceneState.HOME) { + let sceneContainerSession = this.getSceneContainerSession(sceneSession); + if (sceneContainerSession === null) { + sceneContainerSession = new SCBSceneContainerSession(sceneSession, this.screenProperty); + this.addSceneContainerSession(sceneContainerSession); + Log.showInfo(TAG,"start scene add new container session: " + sceneContainerSession.containerId); + } + sceneContainerSession.requestActivation(); + this.raiseSceneToTop(sceneContainerSession); + let action = new SCBGestureAction({ + id: SCBGestureActionId.FULLSCENE + }); + this.onGestureChange(action); + + } else if (this.gestureModel.sceneState === SceneState.SPLIT) { + let sceneContainerSession = this.getSceneContainerSession(sceneSession); + if (sceneContainerSession !== null && !sceneContainerSession.isActive) { + this.removeSceneContainerSession(sceneContainerSession); // delete old scene containerSession in background + Log.showInfo(TAG,"start scene split remove old fullscene container session: " + sceneContainerSession.containerId); + } + let activeSceneContainerSession = this.getActiveSceneContainerSession(); + activeSceneContainerSession.addSceneSession(sceneSession); + Log.showInfo(TAG,"start scene split after add active sceneSession container: " + activeSceneContainerSession.containerId); + sceneSession.requestSessionActivation(); + this.raiseSceneToTop(activeSceneContainerSession); + let action = new SCBGestureAction({ + id: SCBGestureActionId.FULLSCENE + }); + this.onGestureChange(action); + } + } + + onActivateScene(containerId: number) { + let containerSession = this.getSceneContainerSessionWithContainerId(containerId); + let curActiveContainerSession = this.getActiveSceneContainerSession() // just for full session + if (containerSession) { + if (containerSession.containerId !== curActiveContainerSession.containerId) { + curActiveContainerSession.requestBackground(); + } + } + containerSession.requestActivation(); + this.raiseSceneToTop(containerSession); + } + + onBackgroundScene(containerId: number) { + let containerSession = this.getSceneContainerSessionWithContainerId(containerId); + if (containerSession) { + containerSession.requestBackground(); + } + } + + onDestroyScene(containerId: number) { + let containerSession = this.getSceneContainerSessionWithContainerId(containerId); + if (containerSession) { + containerSession.requestDestruction(); + } + this.removeSceneContainerSession(containerSession); + // test + this.containerSessionList.forEach((item, index)=> { + Log.showInfo(TAG, `onDestroyScene length: ${this.containerSessionList.length}, index: ${index}, containerId:${item.containerId}}`); + }) + + + } + + onGestureChange(action: SCBGestureAction) { + Log.showInfo(TAG, `onGestureChange! action: ${action.actionId} sceneState: ${this.gestureModel.sceneState}`); + switch(action.actionId) { + case SCBGestureActionId.ENTER_SPLIT: + this.initView(); + this.gestureModel.updateSceneState(SceneState.SPLIT); + break; + case SCBGestureActionId.HOME: + this.initView(); + this.gestureModel.updateSceneState(SceneState.HOME); + break; + case SCBGestureActionId.SLIDING_UP: + this.updateRecentView(action.gestureOffsetX, action.gestureOffsetY); + break; + case SCBGestureActionId.SLIDE_UP_BEGIN: + this.calculateCurrViewOnSlidingBegin(); + this.gestureModel.updateSceneState(SceneState.SLIDING_UP); + break; + case SCBGestureActionId.ENTER_RECENT: + this.enterRecentView(); + this.gestureModel.updateSceneState(SceneState.RECENT); + break; + case SCBGestureActionId.FULLSCENE: + this.initView(); + this.gestureModel.updateSceneState(SceneState.FULLSCENE); + break; + case SCBGestureActionId.EXIT_SPILT: + this.exitSplitView(action.sessionId); + break; + case SCBGestureActionId.DESTROY_IN_RECENT: + if (this.containerSessionList.length == 0) { + this.initView(); + this.gestureModel.updateSceneState(SceneState.HOME); + } else { + // todo: need modify not scorll to final view + this.enterRecentView(); + this.gestureModel.updateSceneState(SceneState.RECENT); + } + break; + default: + break; + } + } + + aboutToAppear() { + this.onGestureChange = this.onGestureChange.bind(this) + SCBSceneSessionManager.getInstance().registerStartSceneCallback(this.screenProperty.screenId, + (sceneInfo: SCBSceneInfo) => { + this.onStartScene(sceneInfo); + }) + SCBSceneSessionManager.getInstance().registerBackgroundSceneCallback(this.screenProperty.screenId, + (containerId: number) => { + this.onBackgroundScene(containerId); + }) + + SCBSceneSessionManager.getInstance().registerDestroySceneCallback(this.screenProperty.screenId, + (containerId: number) => { + this.onDestroyScene(containerId); + }) + SCBSceneSessionManager.getInstance().registerActivateSceneCallback(this.screenProperty.screenId, + (containerId: number) => { + this.onActivateScene(containerId); + }) + } + + build() { + Stack({ alignContent: Alignment.TopStart }) { + // SLIDING_UP is needed in order to use blur when slide + if (this.gestureModel.sceneState === SceneState.FULLSCENE || this.gestureModel.sceneState === SceneState.RECENT || this.gestureModel.sceneState === SceneState.SLIDING_UP) { + Stack() { + } + .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + .blur(this.mBlurRadius) + } + Scroll(this.scroller) { + Flex({ direction: FlexDirection.Row }) { + ForEach(this.containerSessionList, (item: SCBSceneContainerSession, index) => { + if (this.buildLog(item) && this.isRecent() || (this.gestureModel.multiViewShow === true) || (this.buildLog(item) && item.isActive)) { + SCBSceneContainer({ + sceneContainerSession: item, + dividerParam: item.dividerParam, + screenProperty: $screenProperty, + containerIdx: index, + onGestureChange: this.onGestureChange + }) + .flexShrink(0) + } + }, (item: SCBSceneContainerSession) => item.containerId.toString()) + } + .flexShrink(0) + .id('flexTest1') + .size({ width: this.gestureModel.flexWidth, height: this.gestureModel.flexHeight}) + .padding({ left: this.gestureModel.flexPadding, right: this.gestureModel.flexPadding}) + .hitTestBehavior(HitTestMode.None) + } + .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + .scrollBar(BarState.Off) + .scrollable(this.gestureModel.sceneState === SceneState.RECENT ? ScrollDirection.Horizontal : ScrollDirection.None) + .edgeEffect(EdgeEffect.Spring) + .hitTestBehavior(this.gestureModel.sceneState === SceneState.RECENT ? HitTestMode.Default : HitTestMode.None) + .onClick(() => { + let activeSceneContainerSession = this.getActiveSceneContainerSession(); + activeSceneContainerSession?.requestBackground() + let action = new SCBGestureAction({ + id: SCBGestureActionId.HOME + }); + this.onGestureChange && this.onGestureChange(action); + this.containerTranslation= []; + this.containerAlpha = []; + this. containerScale = []; + }) + .onScroll((xOffset: number, yOffset: number) => { + Log.showInfo(TAG, `enableScroll: ${this.gestureModel.enableScroll}`) + if (!this.gestureModel.enableScroll) { + return + } + }) + .onScrollEnd(()=>{ + if (!this.gestureModel.enableScroll) { + return + } + }) + // Freedom scene + + if (this.gestureModel?.sceneState !== SceneState.RECENT + && this.gestureModel?.sceneState !== SceneState.SPLIT) { // todo: 放开 == recent + SCBGestureNavBar({ + containerSessionList: this.containerSessionList, + onGestureChange: this.onGestureChange + }) + } + } + .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + .hitTestBehavior(HitTestMode.None) + } + + updateView(progress:number,index:number) { + if(this.containerSessionList.length <= 1) { + this.containerScale = []; + this.containerTranslation = []; + this.containerAlpha = []; + return; + } + if (progress >= 0) { + this.containerAlpha[index] = 1; + } else { + this.containerAlpha[index] = 1 - Math.abs(progress) * 0.2; + } + this.containerScale[index] = 1 + (progress) * 0.05; + if (progress > 0) { + this.containerTranslation[index] = -Math.abs(progress) * this.screenWidth / 10; + } else { + this.containerTranslation[index] = Math.abs(progress) * this.screenWidth / 1.6; + } + } + + contentOffsetForIndex(index) : number { + let result = index * this.viewWidth - (this.screenWidth - this.viewWidth) / 2 + return result; + } + + initRecentParams() { + this.screenWidth = px2vp(this.screenProperty.width); + this.scroller.scrollTo({ xOffset: -this.gestureModel.flexOffsetX, yOffset: 0}) + } +} diff --git a/product/phone/src/main/ets/WindowScene/HWScreen.ets b/product/phone/src/main/ets/SceneBoard/SCBScreen.ets similarity index 70% rename from product/phone/src/main/ets/WindowScene/HWScreen.ets rename to product/phone/src/main/ets/SceneBoard/SCBScreen.ets index eac8d13b..ef8ac91b 100644 --- a/product/phone/src/main/ets/WindowScene/HWScreen.ets +++ b/product/phone/src/main/ets/SceneBoard/SCBScreen.ets @@ -13,15 +13,17 @@ * limitations under the License. */ -import { HWScenePanel } from './HWScenePanel'; -import { HWScreenSession } from '@ohos/common'; -import { HWDesktop } from './HWDesktop'; -import { HWWallpaper } from './HWWallpaper'; +import { SCBScenePanel } from './SCBScenePanel' +import { SCBScreenSession, SCBScreenProperty } from '@ohos/common' +import { SCBDesktop } from './SCBDesktop' +import { SCBWallpaper } from './SCBWallpaper' import { SCBStatusBar } from './statusbar/SCBStatusBar'; import { DropdownPanel } from './dropdownpanel/DropdownPanel'; import { BannerNotificationPanel } from './dropdownpanel/bannerNotification'; import { SCBVolumePanel } from '@ohos/default_volumepanel/src/main/ets/pages/SCBVolumePanel'; -import { SCBScreenLock } from './screenlock/pages/SCBScreenLock'; +import { SCBScreenLock } from './screenlock/pages/SCBScreenLock' +import screenSessionManager from '@ohos.screenSessionManager' +import { Log, Trace } from '@ohos/common'; import WindowPanelManager, { WindowInfo, WindowType, @@ -31,26 +33,42 @@ import WindowPanelManager, { } from '@ohos/common/src/main/ets/default/manager/WindowPanelManager'; const MODULE_NAME = "phone-launcher"; +const TAG = 'SCBScreen'; @Component -export struct HWScreen { - @ObjectLink screenSession: HWScreenSession; +export struct SCBScreen { + @ObjectLink screenSession: SCBScreenSession + @State scbScreenProperty: SCBScreenProperty = new SCBScreenProperty(); @StorageLink(SystemUi_DropdownPanel) mDropDownInfo: WindowInfo = WindowPanelManager.getWindowInfo(WindowType.DROPDOWN_PANEL); @StorageLink(SystemUi_BannerNotice) mBannerInfo: WindowInfo = WindowPanelManager.getWindowInfo(WindowType.BANNER_NOTICE); @StorageLink(SystemUi_VolumePanel) mVolumeInfo: WindowInfo = WindowPanelManager.getWindowInfo(WindowType.VOLUME_PANEL); + // screen 数据改变 + onScreenPropertyChange(screenProperty: screenSessionManager.ScreenProperty) { + Log.showInfo(TAG, 'scbScreenProperty'); + this.scbScreenProperty.update(screenProperty); + this.scbScreenProperty.screenId = this.screenSession.session.screenId; + Log.showInfo(TAG, `Update scbScreenProperty[${this.scbScreenProperty.left}, ${this.scbScreenProperty.top}, ${this.scbScreenProperty.width}, ${this.scbScreenProperty.height}]`) + } + + aboutToAppear() { + Log.showInfo(TAG, 'aboutToAppear'); + this.screenSession.registerPropertyChange((screenProperty: screenSessionManager.ScreenProperty) => { + this.onScreenPropertyChange(screenProperty); + }) + } + build() { Screen(this.screenSession.session.screenId) { // Wallpaper - HWWallpaper() + SCBWallpaper() // Desktop - HWDesktop({ bounds: this.screenSession.bounds }) + SCBDesktop({ bounds: this.screenSession.bounds }) // Scene - HWScenePanel({ - screenSession: this.screenSession, - recentViewParam: this.screenSession.recentViewParam + SCBScenePanel({ + screenProperty: $scbScreenProperty }) // status bar diff --git a/product/phone/src/main/ets/WindowScene/HWWallpaper.ets b/product/phone/src/main/ets/SceneBoard/SCBWallpaper.ets similarity index 93% rename from product/phone/src/main/ets/WindowScene/HWWallpaper.ets rename to product/phone/src/main/ets/SceneBoard/SCBWallpaper.ets index e9834423..98d14e6e 100644 --- a/product/phone/src/main/ets/WindowScene/HWWallpaper.ets +++ b/product/phone/src/main/ets/SceneBoard/SCBWallpaper.ets @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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 StyleConstants from '../common/constants/StyleConstants' - -@Component -export struct HWWallpaper { - - build() { - Image(StyleConstants.DEFAULT_BACKGROUND_IMAGE) - .objectFit(ImageFit.Cover) - } +/* + * Copyright (c) 2023 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 StyleConstants from '../common/constants/StyleConstants' + +@Component +export struct SCBWallpaper { + + build() { + Image(StyleConstants.DEFAULT_BACKGROUND_IMAGE) + .objectFit(ImageFit.Cover) + } } \ No newline at end of file diff --git a/product/phone/src/main/ets/WindowScene/dropdownpanel/DropdownPanel.ets b/product/phone/src/main/ets/SceneBoard/dropdownpanel/DropdownPanel.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/dropdownpanel/DropdownPanel.ets rename to product/phone/src/main/ets/SceneBoard/dropdownpanel/DropdownPanel.ets diff --git a/product/phone/src/main/ets/WindowScene/dropdownpanel/bannerNotification.ets b/product/phone/src/main/ets/SceneBoard/dropdownpanel/bannerNotification.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/dropdownpanel/bannerNotification.ets rename to product/phone/src/main/ets/SceneBoard/dropdownpanel/bannerNotification.ets diff --git a/product/phone/src/main/ets/WindowScene/dropdownpanel/common/ControlCenterConfig.ts b/product/phone/src/main/ets/SceneBoard/dropdownpanel/common/ControlCenterConfig.ts similarity index 100% rename from product/phone/src/main/ets/WindowScene/dropdownpanel/common/ControlCenterConfig.ts rename to product/phone/src/main/ets/SceneBoard/dropdownpanel/common/ControlCenterConfig.ts diff --git a/product/phone/src/main/ets/WindowScene/dropdownpanel/common/StyleConfiguration.ts b/product/phone/src/main/ets/SceneBoard/dropdownpanel/common/StyleConfiguration.ts similarity index 100% rename from product/phone/src/main/ets/WindowScene/dropdownpanel/common/StyleConfiguration.ts rename to product/phone/src/main/ets/SceneBoard/dropdownpanel/common/StyleConfiguration.ts diff --git a/product/phone/src/main/ets/WindowScene/dropdownpanel/common/StyleManager.ts b/product/phone/src/main/ets/SceneBoard/dropdownpanel/common/StyleManager.ts similarity index 100% rename from product/phone/src/main/ets/WindowScene/dropdownpanel/common/StyleManager.ts rename to product/phone/src/main/ets/SceneBoard/dropdownpanel/common/StyleManager.ts diff --git a/product/phone/src/main/ets/WindowScene/dropdownpanel/common/constants.ts b/product/phone/src/main/ets/SceneBoard/dropdownpanel/common/constants.ts similarity index 100% rename from product/phone/src/main/ets/WindowScene/dropdownpanel/common/constants.ts rename to product/phone/src/main/ets/SceneBoard/dropdownpanel/common/constants.ts diff --git a/product/phone/src/main/ets/WindowScene/dropdownpanel/common/navigationEvent.ts b/product/phone/src/main/ets/SceneBoard/dropdownpanel/common/navigationEvent.ts similarity index 100% rename from product/phone/src/main/ets/WindowScene/dropdownpanel/common/navigationEvent.ts rename to product/phone/src/main/ets/SceneBoard/dropdownpanel/common/navigationEvent.ts diff --git a/product/phone/src/main/ets/WindowScene/dropdownpanel/control.ets b/product/phone/src/main/ets/SceneBoard/dropdownpanel/control.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/dropdownpanel/control.ets rename to product/phone/src/main/ets/SceneBoard/dropdownpanel/control.ets diff --git a/product/phone/src/main/ets/WindowScene/dropdownpanel/notification.ets b/product/phone/src/main/ets/SceneBoard/dropdownpanel/notification.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/dropdownpanel/notification.ets rename to product/phone/src/main/ets/SceneBoard/dropdownpanel/notification.ets diff --git a/product/phone/src/main/ets/WindowScene/screenlock/common/constants.ts b/product/phone/src/main/ets/SceneBoard/screenlock/common/constants.ts similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/common/constants.ts rename to product/phone/src/main/ets/SceneBoard/screenlock/common/constants.ts diff --git a/product/phone/src/main/ets/WindowScene/screenlock/pages/SCBScreenLock.ets b/product/phone/src/main/ets/SceneBoard/screenlock/pages/SCBScreenLock.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/pages/SCBScreenLock.ets rename to product/phone/src/main/ets/SceneBoard/screenlock/pages/SCBScreenLock.ets diff --git a/product/phone/src/main/ets/WindowScene/screenlock/pages/customPassword.ets b/product/phone/src/main/ets/SceneBoard/screenlock/pages/customPassword.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/pages/customPassword.ets rename to product/phone/src/main/ets/SceneBoard/screenlock/pages/customPassword.ets diff --git a/product/phone/src/main/ets/WindowScene/screenlock/pages/customscreenlock.ets b/product/phone/src/main/ets/SceneBoard/screenlock/pages/customscreenlock.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/pages/customscreenlock.ets rename to product/phone/src/main/ets/SceneBoard/screenlock/pages/customscreenlock.ets diff --git a/product/phone/src/main/ets/WindowScene/screenlock/pages/digitalPassword.ets b/product/phone/src/main/ets/SceneBoard/screenlock/pages/digitalPassword.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/pages/digitalPassword.ets rename to product/phone/src/main/ets/SceneBoard/screenlock/pages/digitalPassword.ets diff --git a/product/phone/src/main/ets/WindowScene/screenlock/pages/journalscreenlock.ets b/product/phone/src/main/ets/SceneBoard/screenlock/pages/journalscreenlock.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/pages/journalscreenlock.ets rename to product/phone/src/main/ets/SceneBoard/screenlock/pages/journalscreenlock.ets diff --git a/product/phone/src/main/ets/WindowScene/screenlock/pages/mixedPassword.ets b/product/phone/src/main/ets/SceneBoard/screenlock/pages/mixedPassword.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/pages/mixedPassword.ets rename to product/phone/src/main/ets/SceneBoard/screenlock/pages/mixedPassword.ets diff --git a/product/phone/src/main/ets/WindowScene/screenlock/pages/slidescreenlock.ets b/product/phone/src/main/ets/SceneBoard/screenlock/pages/slidescreenlock.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/pages/slidescreenlock.ets rename to product/phone/src/main/ets/SceneBoard/screenlock/pages/slidescreenlock.ets diff --git a/product/phone/src/main/ets/WindowScene/screenlock/vm/indexViewModel.ts b/product/phone/src/main/ets/SceneBoard/screenlock/vm/indexViewModel.ts similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/vm/indexViewModel.ts rename to product/phone/src/main/ets/SceneBoard/screenlock/vm/indexViewModel.ts diff --git a/product/phone/src/main/ets/WindowScene/screenlock/vm/slideScreenLockViewModel.ts b/product/phone/src/main/ets/SceneBoard/screenlock/vm/slideScreenLockViewModel.ts similarity index 100% rename from product/phone/src/main/ets/WindowScene/screenlock/vm/slideScreenLockViewModel.ts rename to product/phone/src/main/ets/SceneBoard/screenlock/vm/slideScreenLockViewModel.ts diff --git a/product/phone/src/main/ets/WindowScene/statusbar/SCBStatusBar.ets b/product/phone/src/main/ets/SceneBoard/statusbar/SCBStatusBar.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/statusbar/SCBStatusBar.ets rename to product/phone/src/main/ets/SceneBoard/statusbar/SCBStatusBar.ets diff --git a/product/phone/src/main/ets/WindowScene/statusbar/StatusBar.ets b/product/phone/src/main/ets/SceneBoard/statusbar/StatusBar.ets similarity index 100% rename from product/phone/src/main/ets/WindowScene/statusbar/StatusBar.ets rename to product/phone/src/main/ets/SceneBoard/statusbar/StatusBar.ets diff --git a/product/phone/src/main/ets/WindowScene/statusbar/StatusbarConfig.ts b/product/phone/src/main/ets/SceneBoard/statusbar/StatusbarConfig.ts similarity index 100% rename from product/phone/src/main/ets/WindowScene/statusbar/StatusbarConfig.ts rename to product/phone/src/main/ets/SceneBoard/statusbar/StatusbarConfig.ts diff --git a/product/phone/src/main/ets/WindowScene/HWSceneContainer.ets b/product/phone/src/main/ets/WindowScene/HWSceneContainer.ets deleted file mode 100644 index 19413b0f..00000000 --- a/product/phone/src/main/ets/WindowScene/HWSceneContainer.ets +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2023 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 curves from '@ohos.curves' -import { HWSceneContainerSession, HWDividerParam } from '@ohos/common' -import { HWRecentViewParam } from '@ohos/common'; -import { HWScreenSession, DesktopState } from '@ohos/common'; -import { HWSceneSessionManager } from '@ohos/common'; -import { HWScene } from './HWScene' -import { HWGestureNavBar } from './HWGestureNavBar' -import { HWDivider } from './HWDivider' -import { Log } from '@ohos/common' -import { StyleConstants } from '@ohos/common' - -const TAG = 'HWSceneContainer' - -@Component -export struct HWSceneContainer { - @ObjectLink sceneContainerSession: HWSceneContainerSession; - @ObjectLink screenSession: HWScreenSession; - @ObjectLink dividerParam: HWDividerParam; - @Link recentViewParam: HWRecentViewParam; - - build() { - Stack() { - Column() { - if (this.sceneContainerSession.primarySession) { - HWScene({ sceneSession: this.sceneContainerSession.primarySession }) - .width('100%') - .height(this.dividerParam.primaryH) - .scale({ y: this.dividerParam.primaryScaleY, centerY: 0 }) - .blur(this.dividerParam.blurRadius) - } - - // divider - if (this.sceneContainerSession.isSplit) { - HWDivider({ dividerParam: $dividerParam, screenBounds: this.sceneContainerSession.screenBounds }) - } - - // When primary Exit - if (this.sceneContainerSession.secondarySession) { - HWScene({ sceneSession: this.sceneContainerSession.secondarySession }) - .scale({ y: this.dividerParam.secondaryScaleY, centerY: 0 }) - .blur(this.dividerParam.blurRadius) - .translate({ y: this.dividerParam.secTransY }) - .flexShrink(1) - } - } - .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) - - if (this.screenSession.desktopState === DesktopState.RECENT) { - Stack() { - } - .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) - .hitTestBehavior(HitTestMode.Default) - .onClick(() => { - let activeSceneContainerSession = this.screenSession.getActiveSceneContainerSession(); - if (activeSceneContainerSession && - activeSceneContainerSession.containerId !== this.sceneContainerSession.containerId) { - HWSceneSessionManager.getInstance().requestSceneContainerBackground(activeSceneContainerSession); - } - - HWSceneSessionManager.getInstance().requestSceneContainerActivation(this.sceneContainerSession); - this.screenSession.enterAppView(this.sceneContainerSession); - }) - .gesture( - PanGesture({ direction: PanDirection.Vertical }) - .onActionStart((event: GestureEvent) => { - }) - .onActionUpdate((event: GestureEvent) => { - if (event.offsetY < 100) { - this.sceneContainerSession.translateY = event.offsetY; - } - }) - .onActionEnd((event: GestureEvent) => { - if (event.offsetY < -300) { - HWSceneSessionManager.getInstance().requestSceneContainerDestruction(this.sceneContainerSession); - - this.screenSession.removeSceneContainerSession(this.sceneContainerSession); - if (this.screenSession.sceneContainerSessionList.length == 0) { - this.screenSession.enterHomeView(); - } - } else { - this.sceneContainerSession.translateY = 0; - } - })) - } - - if (this.screenSession.desktopState !== DesktopState.RECENT - && this.screenSession.desktopState !== DesktopState.SPLIT) { - HWGestureNavBar({ - sceneContainerSession: $sceneContainerSession, - screenSession: $screenSession, - dividerParam: $dividerParam, - recentViewParam: $recentViewParam, - }) - } - } - .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) - .translate({ x: this.sceneContainerSession.translateX, y: this.sceneContainerSession.translateY }) - .scale({ - x: this.sceneContainerSession.scaleX, - y: this.sceneContainerSession.scaleY, - centerX: this.sceneContainerSession.centerX, - centerY: this.sceneContainerSession.centerY - }) - } -} diff --git a/product/phone/src/main/ets/WindowScene/HWScenePanel.ets b/product/phone/src/main/ets/WindowScene/HWScenePanel.ets deleted file mode 100644 index 4c0ac4fe..00000000 --- a/product/phone/src/main/ets/WindowScene/HWScenePanel.ets +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2023 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 { HWScreenSession, DesktopState } from '@ohos/common'; -import { HWRecentViewParam } from '@ohos/common'; -import { HWSceneContainerSession } from '@ohos/common'; -import { HWSceneSessionManager } from '@ohos/common'; -import { HWSceneContainer } from './HWSceneContainer'; -import { Log } from '@ohos/common'; -import { StyleConstants } from '@ohos/common'; - -const TAG = 'HWScenePanel'; - -@Component -export struct HWScenePanel { - @ObjectLink screenSession: HWScreenSession; - @ObjectLink recentViewParam: HWRecentViewParam; - @State recentViewHitTestMode: HitTestMode = HitTestMode.None; - @State scrollDirection: ScrollDirection = ScrollDirection.None; - @State mBlurRadius: number = 20; - - private scroller: Scroller = new Scroller(); - private progress: number[] = [] - private screenWidth: number = -1 - private viewWidth: number = -1 - private currentIndex: number = 0; - private currentState: number = DesktopState.HOME - @State containerTranslation: number[]=[] - @State containerAlpha : number[]=[] - @State containerScale: number[]=[] - buildLog(sceneContainerSession: HWSceneContainerSession) { - Log.showInfo(TAG, `sceneContainerSession id: ${sceneContainerSession.containerId}`); - Log.showInfo(TAG, `sceneContainerSession isActive: ${sceneContainerSession.isActive}`); - return true; - } - - isRecent(): boolean { - Log.showInfo(TAG,"isRecent = " +(this.screenSession.desktopState === DesktopState.RECENT)) - if (this.screenSession.desktopState === this.currentState) { - return this.screenSession.desktopState === DesktopState.RECENT; - } - if (this.screenSession.desktopState == DesktopState.RECENT) { - this.initRecentParams(); - this.currentState = this.screenSession.desktopState; - return true; - } else { - this.containerTranslation = []; - this.containerAlpha = []; - this. containerScale = []; - this.currentState = this.screenSession.desktopState; - Log.showInfo(TAG,"this.containerTranslation = " +this.containerTranslation[this.screenSession.sceneContainerSessionList.length-1]) - return false; - } -} - - build() { - Stack({ alignContent: Alignment.TopStart }) { - if (this.screenSession.desktopState === DesktopState.APP || this.screenSession.desktopState === DesktopState.RECENT) { - Stack() { - } - .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) - .blur(this.mBlurRadius) - } - - Scroll(this.scroller) { -// Flex({ direction: FlexDirection.Row }) { - Row() { - ForEach(this.screenSession.sceneContainerSessionList, (item: HWSceneContainerSession, index) => { - if (this.isRecent() ||this.screenSession.desktopState === DesktopState.DRAGGING || (this.buildLog(item) && item.isActive)) { - HWSceneContainer({ - sceneContainerSession: item, - screenSession: this.screenSession, - dividerParam: item.dividerParam, - recentViewParam: $recentViewParam - }) - .size({width:this.recentViewParam.width, height:this.recentViewParam.height}) - .translate({x:this.containerTranslation[index]}) - .opacity(this.containerAlpha[index]) - .scale({x:this.containerScale[index], y:this.containerScale[index]}) - .margin({left:this.recentViewParam.margin}) - .clip(true) - .borderRadius(this.recentViewParam.borderRadius) - } - }, (item: HWSceneContainerSession) => item.containerId.toString()) - } - .hitTestBehavior(HitTestMode.None) - .translate({ x: this.recentViewParam.translateX, y: this.recentViewParam.translateY }) - .scale({ - x: this.recentViewParam.scaleX, - y: this.recentViewParam.scaleY, - centerX: this.recentViewParam.centerX, - centerY: this.recentViewParam.centerY - }) - .offset({ x: this.recentViewParam.offsetX, y: this.recentViewParam.offsetY }) - } - .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) - .scrollBar(BarState.Off) - .scrollable(this.screenSession.desktopState === DesktopState.RECENT ? ScrollDirection.Horizontal : ScrollDirection.None) - .edgeEffect(EdgeEffect.Spring) - .hitTestBehavior(this.screenSession.desktopState === DesktopState.RECENT ? HitTestMode.Default : HitTestMode.None) - .onClick(() => { - let activeSceneContainerSession = this.screenSession.getActiveSceneContainerSession(); - HWSceneSessionManager.getInstance().requestSceneContainerBackground(activeSceneContainerSession); - this.screenSession.enterHomeView(); - this.containerTranslation= []; - this.containerAlpha = []; - this. containerScale = []; - }) - .onScroll((xOffset: number, yOffset: number) => { - Log.showInfo(TAG,"this.scroller.currentOffset().xOffset = " +this.scroller.currentOffset().xOffset + ",currentindex = " + this.currentIndex) - this.currentIndex = Math.ceil((this.scroller.currentOffset().xOffset - this.viewWidth / 2) / this.viewWidth) - let currentCenter = this.scroller.currentOffset().xOffset + this.screenWidth / 2; - for (var i = this. currentIndex - 2; i <= this. currentIndex + 2; i ++) { - if (i < 0 || i > this.screenSession.sceneContainerSessionList.length) { - continue; - } - let viewCenterX = i * (this.viewWidth) + (this.viewWidth) / 2 - this.progress[i] = (viewCenterX - currentCenter) / (this.viewWidth) ; - this.updateView(this.progress[i], i) - - } - }) - .onScrollEnd(()=>{ - if (this.scroller.currentOffset().xOffset === this.contentOffsetForIndex(this.currentIndex) || this.screenSession.sceneContainerSessionList.length <=1) { - return; - } - this.scroller.scrollTo({ xOffset: this.contentOffsetForIndex(this.currentIndex), yOffset: 0, animation:{duration:100, curve: Curve.Smooth}}) - Log.showInfo(TAG,"onScrollEnd xOffset = " +this.contentOffsetForIndex(this.currentIndex)) - }) - // Freedom scene - } - .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) - .hitTestBehavior(HitTestMode.None) - } - - updateView(progress:number,index:number) { - if(this.screenSession.sceneContainerSessionList.length <= 1) { - this.containerScale = []; - this.containerTranslation = []; - this.containerAlpha = []; - return; - } - if (progress >= 0) { - this.containerAlpha[index] = 1; - } else { - this.containerAlpha[index] = 1 - Math.abs(progress) * 0.2; - } - this.containerScale[index] = 1 + (progress) * 0.05; - if (progress > 0) { - this.containerTranslation[index] = -Math.abs(progress) * this.screenWidth / 10; - } else { - this.containerTranslation[index] = Math.abs(progress) * this.screenWidth / 1.6; - } - } - - contentOffsetForIndex(index) : number { - let result = index * this.viewWidth - (this.screenWidth - this.viewWidth) / 2 - return result; - } - - initRecentParams() { - this.screenWidth = px2vp(this.screenSession.bounds.width); - this.viewWidth = this.screenWidth * 0.7; - - this.scroller.scrollTo({ xOffset: this.contentOffsetForIndex(this.screenSession.sceneContainerSessionList.length - 1), yOffset: 0 }) - this.currentIndex = Math.ceil( (this.scroller.currentOffset().xOffset - (this.viewWidth/2))/(this.viewWidth)) - this.progress[this.screenSession.sceneContainerSessionList.length - 1 - 2] = -2; - this.progress[this.screenSession.sceneContainerSessionList.length - 1 - 1] = -1; - this.updateView(-2, this.screenSession.sceneContainerSessionList.length - 1 - 2) - this.updateView(-1, this.screenSession.sceneContainerSessionList.length - 1 - 1) - } -} diff --git a/product/phone/src/main/ets/pages/EntryView.ets b/product/phone/src/main/ets/pages/EntryView.ets index ea0fa4e9..6f56b7cb 100644 --- a/product/phone/src/main/ets/pages/EntryView.ets +++ b/product/phone/src/main/ets/pages/EntryView.ets @@ -13,27 +13,90 @@ * limitations under the License. */ -import { HWRootSceneSession } from '@ohos/common' -import { HWSceneSessionManager } from '@ohos/common' -import { HWScreen } from '../WindowScene/HWScreen' -import { HWScreenSession } from '@ohos/common' -import { Log } from '@ohos/common'; +import { SCBRootSceneSession } from '@ohos/common' +import { SCBSceneSessionManager } from '@ohos/common' +import { SCBScreen } from '../SceneBoard/SCBScreen' +import { SCBScreenSession, SCBGestureModel } from '@ohos/common' +import { Log, Trace } from '@ohos/common'; import CommonStyleManager from '@ohos/common/src/main/ets/default/manager/CommonStyleManager'; +import screenSessionManager from '@ohos.screenSessionManager' -const TAG = "EntryView"; +const TAG = 'SCBEntryView'; + +@Observed +export class SCBScreenSessionArray extends Array { +} @Entry @Component struct EntryView { - @StorageLink('screenSessionList') screenSessionList: HWScreenSession[] = [] - private rootSceneSession: HWRootSceneSession = HWSceneSessionManager.getInstance().getRootSceneSession() + @State screenSessionList: SCBScreenSessionArray = new SCBScreenSessionArray() + private rootSceneSession: SCBRootSceneSession = SCBSceneSessionManager.getInstance().getRootSceneSession() + + private registerScreenConnectionListener(): void { + screenSessionManager.on('screenConnectChange', ({ screenSession, screenConnectChangeType }) => { + this.onScreenConnectChange(screenSession, screenConnectChangeType); + }) + } + + private onScreenConnectChange(session: screenSessionManager.ScreenSession, + changeType: screenSessionManager.ScreenConnectChangeType) { + Log.showInfo(TAG, 'On screen connect change, type:' + changeType + ' ' + session.screenId); + if (changeType === screenSessionManager.ScreenConnectChangeType.CONNECT) { + this.onScreenConnect(session); + } + + if (changeType === screenSessionManager.ScreenConnectChangeType.DISCONNECT) { + this.onScreenDisconnect(session); + } + } + + private onScreenConnect(session: screenSessionManager.ScreenSession): void { + Log.showInfo(TAG, 'On screen connect.'); + let screenSession: SCBScreenSession = new SCBScreenSession(session); + this.addScreenSession(screenSession); + } + + private onScreenDisconnect(session: screenSessionManager.ScreenSession): void { + Log.showInfo(TAG, 'On screen disconnect.'); + this.removeScreenSession(session.screenId); + } + + private addScreenSession(screenSession: SCBScreenSession) { + const screenSessionIndex = this.screenSessionList.findIndex(item => { + return item.session.screenId === screenSession.session.screenId; + }) + if (screenSessionIndex != -1) { + Log.showError(TAG, 'Failed to add screen session, screen id:' + screenSession.session.screenId); + return; + } + this.screenSessionList.push(screenSession); + if (SCBSceneSessionManager.getInstance().mainScreenId === -1) { + Log.showInfo(TAG, `addScreenSession after push: ${this.screenSessionList[0].session.screenId}, mainSreenId: ${SCBSceneSessionManager.getInstance().mainScreenId}`); + SCBSceneSessionManager.getInstance().mainScreenId = this.screenSessionList[0].session.screenId; + Log.showInfo(TAG, `addScreenSession after = : ${this.screenSessionList[0].session.screenId}, mainSreenId: ${SCBSceneSessionManager.getInstance().mainScreenId}`); + } + Log.showInfo(TAG, `addScreenSession with screenId: ${screenSession.session.screenId}, mainSreenId: ${SCBSceneSessionManager.getInstance().mainScreenId}`); + } + + private removeScreenSession(screenId: number) { + const screenSessionIndex = this.screenSessionList.findIndex(item => { + return item.session.screenId === screenId; + }) + if (screenSessionIndex == -1) { + Log.showError(TAG, 'Failed to remove screen session, screen id:' + screenId); + return; + } + this.screenSessionList.splice(screenSessionIndex, 1); + } aboutToAppear() { Log.showInfo(TAG, `aboutToAppear`); // 原来在StatusBar/DropdownPanel等处setAbilityPageName会相互覆盖,导致Style不对 CommonStyleManager.setAbilityPageName(TAG); + this.registerScreenConnectionListener() } aboutToDisappear() { @@ -43,8 +106,10 @@ struct EntryView { build() { RootScene(this.rootSceneSession.session) { ForEach(this.screenSessionList, (item) => { - HWScreen({screenSession: item}) - }, (item: HWScreenSession) => item.session.screenId.toString()) + SCBScreen({ + screenSession: item, + }) + }, (item: SCBScreenSession) => item.session.screenId.toString()) } } } diff --git a/product/phone/src/main/resources/base/profile/main_pages.json b/product/phone/src/main/resources/base/profile/main_pages.json index 53da1808..d0dcd93d 100644 --- a/product/phone/src/main/resources/base/profile/main_pages.json +++ b/product/phone/src/main/resources/base/profile/main_pages.json @@ -4,8 +4,8 @@ "pages/EmptyPage", "pages/EntryView", "pages/RecentView", - "WindowScene/screenlock/pages/digitalPassword", - "WindowScene/screenlock/pages/mixedPassword", - "WindowScene/screenlock/pages/customPassword" + "SceneBoard/screenlock/pages/digitalPassword", + "SceneBoard/screenlock/pages/mixedPassword", + "SceneBoard/screenlock/pages/customPassword" ] } -- Gitee