From 93f388642dbf2bff52a2e35af2bf9ca2fed209e2 Mon Sep 17 00:00:00 2001 From: liuqi Date: Tue, 25 Apr 2023 10:07:00 +0800 Subject: [PATCH] add specific session Signed-off-by: liuqi --- common/index.ets | 3 +- .../scene/session/HWSceneSession.ts | 87 +++++++++++++++++-- .../scene/session/HWSceneSessionManager.ts | 2 +- .../scene/session/HWSpecificSession.ts | 87 +++++++++++++++++++ .../ets/com/ohos/view/component/statusBar.ets | 74 ++++++++-------- .../src/main/ets/WindowScene/HWScene.ets | 69 ++++++++++++++- .../main/ets/WindowScene/HWSceneContainer.ets | 6 +- .../src/main/ets/WindowScene/HWScenePanel.ets | 7 +- .../src/main/ets/WindowScene/HWSubScene.ets | 60 +++++++++++++ 9 files changed, 339 insertions(+), 56 deletions(-) create mode 100644 common/src/main/ets/WindowScene/scene/session/HWSpecificSession.ts create mode 100644 product/phone/src/main/ets/WindowScene/HWSubScene.ets diff --git a/common/index.ets b/common/index.ets index 80b6cda6..9b21c0de 100644 --- a/common/index.ets +++ b/common/index.ets @@ -91,7 +91,8 @@ export { HWRootSceneSession } from './src/main/ets/WindowScene/scene/session/HWR 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 { HWSceneSession, SpecificSessionArray } from './src/main/ets/WindowScene/scene/session/HWSceneSession' +export { HWSpecificSession } from './src/main/ets/WindowScene/scene/session/HWSpecificSession' 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' diff --git a/common/src/main/ets/WindowScene/scene/session/HWSceneSession.ts b/common/src/main/ets/WindowScene/scene/session/HWSceneSession.ts index d1c20d82..2bb83ff2 100644 --- a/common/src/main/ets/WindowScene/scene/session/HWSceneSession.ts +++ b/common/src/main/ets/WindowScene/scene/session/HWSceneSession.ts @@ -18,19 +18,37 @@ import { HWSceneInfo } from './HWSceneInfo' import { HWSceneSessionManager } from './HWSceneSessionManager' import { HWScreenSessionManager } from '../../screen/session/HWScreenSessionManager' import { HWTransitionEffect } from '../../animation/HWTransitionEffect' +import { HWSpecificSession } from './HWSpecificSession' +import { Log } from '../../../default/utils/Log' +const TAG = 'HWSceneSession' + +@Observed +export class SpecificSessionArray extends Array { +} /** * 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 + readonly sceneInfo: HWSceneInfo; + readonly session: sceneSessionManager.SceneSession; + sessionState: sceneSessionManager.SessionState; + isActive: boolean = false; + translateX: number = 0; + translateY: number = 0; + scaleX: number = 1; + scaleY: number = 1; + rect: sceneSessionManager.SessionRect = { + posX_: 0, + posY_: 0, + width: 0, + height: 0 + }; + sessionRectChangeCallback: Function + createSubSessionCallback: Function; + subSessionStateChangeCallback: Function + subSessionList: SpecificSessionArray = new SpecificSessionArray(); /** * Constructor. @@ -40,9 +58,43 @@ export class HWSceneSession { constructor(session: sceneSessionManager.SceneSession, sceneInfo: HWSceneInfo) { this.sceneInfo = sceneInfo this.session = session + this.rect = session.sessionRect this.session.on('pendingSceneSessionActivation', (info) => { this.onPendingSceneSessionActivation(info) }) + this.session.on('createSpecificSession', (specificSession) => { + this.onCreateSpecificSession(specificSession) + }) + + this.session.on('sessionStateChange', (state) => { + this.sessionStateChange(state) + }) + + this.session.on('sessionRectChange', (rect) => { + this.sessionRectChange(rect) + }) + } + + public handleSubSessionStateChange(state: sceneSessionManager.SessionState, sessionId: Number) { + Log.showInfo(TAG, `liuqi handleSubSessionStateChange, state: ${state}, sessionId: ${sessionId}`); + if (this.subSessionStateChangeCallback) { + this.subSessionStateChangeCallback(sessionId, state); + } + } + + public registerCreateSubSessionCallback(callback: Function) { + Log.showInfo(TAG, `====== liuqi registerCreateSubSessionCallback`); + this.createSubSessionCallback = callback; + } + + public registerSubSessionActiveStatueChangeCallback(callback: Function) { + Log.showInfo(TAG, `====== liuqi registerSubSessionActiveStatueChangeCallback`); + this.subSessionStateChangeCallback = callback; + } + + public registerSessionRectChangeCallback(callback: Function) { + Log.showInfo(TAG, `====== liuqi registerSessionRectChangeCallback`); + this.sessionRectChangeCallback = callback; } private onPendingSceneSessionActivation(sceneInfo: sceneSessionManager.SceneInfo) { @@ -52,6 +104,25 @@ export class HWSceneSession { this.sceneInfo.transitionEffect = HWTransitionEffect.DISAPPEAR_FROM_SCENE HWSceneSessionManager.getInstance().startScene(toSceneInfo) -// HWSceneSessionManager.getInstance().requestSceneBackground(this) + } + + private onCreateSpecificSession(specificSession: sceneSessionManager.SceneSession) { + Log.showError(TAG, 'onCreateSpecificSession'); + if (this.createSubSessionCallback) { + this.createSubSessionCallback(specificSession); + } + } + + private sessionStateChange(state: sceneSessionManager.SessionState) { + Log.showInfo(TAG, `onSessionStageChange, state: ${state}`); + this.sessionState = state; + } + + private sessionRectChange(rect: sceneSessionManager.SessionRect) { + Log.showInfo(TAG, `sessionRectChange, rect.posX: ${rect.posX_}, rect.posY: ${rect.posY_}, rect.width: ${rect.width}, rect.height: ${rect.height}`); + if (this.sessionRectChangeCallback) { + this.sessionRectChangeCallback(rect); + } } } + diff --git a/common/src/main/ets/WindowScene/scene/session/HWSceneSessionManager.ts b/common/src/main/ets/WindowScene/scene/session/HWSceneSessionManager.ts index 097a365b..ef09a1ae 100644 --- a/common/src/main/ets/WindowScene/scene/session/HWSceneSessionManager.ts +++ b/common/src/main/ets/WindowScene/scene/session/HWSceneSessionManager.ts @@ -121,7 +121,7 @@ export class HWSceneSessionManager { } } - private requestSceneSession(sceneInfo: HWSceneInfo, screenSession: HWScreenSession): HWSceneSession { + private RequestSceneSession(sceneInfo: HWSceneInfo, screenSession: HWScreenSession): HWSceneSession { if (screenSession == null) { Log.showError(TAG, 'The screen session is null!'); return null; diff --git a/common/src/main/ets/WindowScene/scene/session/HWSpecificSession.ts b/common/src/main/ets/WindowScene/scene/session/HWSpecificSession.ts new file mode 100644 index 00000000..5bd77097 --- /dev/null +++ b/common/src/main/ets/WindowScene/scene/session/HWSpecificSession.ts @@ -0,0 +1,87 @@ +/* + * 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 sceneSessionManager from '@ohos.sceneSessionManager' +import { Log } from '../../../default/utils/Log' + +const TAG = 'HWSpecificSession' + +//interface Callback { +// (state: sceneSessionManager.SessionState, sessionId: Number): void; +//} + +export type Callback = (state: sceneSessionManager.SessionState, sessionId: Number) => void; + +/** + * Session of a scene. + */ +@Observed +export class HWSpecificSession { + readonly session: sceneSessionManager.SceneSession + sessionState: sceneSessionManager.SessionState + isActive: boolean = false + rect: sceneSessionManager.SessionRect = { + posX_: 0, + posY_: 0, + width: 0, + height: 0 + }; + translateX: number = 0 + translateY: number = 0 + scaleX: number = 1 + scaleY: number = 1 + caller:any + stateChangeCallback: Callback + sessionRectChangeCallback: Function + + + /** + * Constructor. + * @param session Session of the scene + * @param sceneInfo Information of the scene + */ + constructor(session: sceneSessionManager.SceneSession, caller:any, callback: Callback) { + Log.showInfo(TAG, 'constructor'); + this.session = session; + this.stateChangeCallback = callback; + this.caller = caller; + this.isActive = false; + this.rect = session.sessionRect + this.sessionState = sceneSessionManager.SessionState.STATE_CONNECT; + this.session.on('sessionStateChange', (state) => { + this.sessionStateChange(state); + }) + this.session.on('sessionRectChange', (rect) => { + this.sessionRectChange(rect) + }) + } + + public registerSessionRectChangeCallback(callback: Function) { + Log.showInfo(TAG, `====== liuqi registerSessionRectChangeCallback`); + this.sessionRectChangeCallback = callback; + } + + private sessionStateChange(state: sceneSessionManager.SessionState) { + this.stateChangeCallback.call(this.caller, state, this.session.persistentId); + Log.showInfo(TAG, `onSessionStageChange, state: ${state}, isActive: ${this.isActive}`); + } + + private sessionRectChange(rect: sceneSessionManager.SessionRect) { + Log.showInfo(TAG, `sessionRectChange, rect.posX: ${rect.posX_}, rect.posY: ${rect.posY_}, rect.width: ${rect.width}, rect.height: ${rect.height}`); + if (this.sessionRectChangeCallback) { + this.sessionRectChangeCallback(rect); + } + } +} diff --git a/feature/systemui/screenlock/src/main/ets/com/ohos/view/component/statusBar.ets b/feature/systemui/screenlock/src/main/ets/com/ohos/view/component/statusBar.ets index 595cfd17..c17d989f 100644 --- a/feature/systemui/screenlock/src/main/ets/com/ohos/view/component/statusBar.ets +++ b/feature/systemui/screenlock/src/main/ets/com/ohos/view/component/statusBar.ets @@ -14,12 +14,12 @@ */ import { Log } from '@ohos/common/src/main/ets/default/utils/Log'; -import ViewModel from '../../vm/StatusBarVM' -import Constants from '../../common/constants' -import BatteryIcon from '@ohos/batterycomponent/src/main/ets/default/pages/batteryIcon' -import ClockIcon from '@ohos/clockcomponent/src/main/ets/default/pages/clockIcon' -import WifiIcon from '@ohos/wificomponent/src/main/ets/default/pages/wifiIcon' -import SignalIcon from '@ohos/signalcomponent/src/main/ets/default/pages/signalIcon' +//import ViewModel from '../../vm/StatusBarVM' +//import Constants from '../../common/constants' +//import BatteryIcon from '@ohos/batterycomponent/src/main/ets/default/pages/batteryIcon' +//import ClockIcon from '@ohos/clockcomponent/src/main/ets/default/pages/clockIcon' +//import WifiIcon from '@ohos/wificomponent/src/main/ets/default/pages/wifiIcon' +//import SignalIcon from '@ohos/signalcomponent/src/main/ets/default/pages/signalIcon' import deviceInfo from '@ohos.deviceInfo'; const deviceTypeInfo = deviceInfo.deviceType @@ -29,38 +29,38 @@ const TAG = 'ScreenLock-StatusBar' export default struct statusBar { private isShow: boolean - aboutToAppear() { - Log.showInfo(TAG, `aboutToAppear`) - if (deviceTypeInfo === "phone" || deviceTypeInfo === "default") { - this.isShow = false - } else { - this.isShow = true - } - } +// aboutToAppear() { +// Log.showInfo(TAG, `aboutToAppear`) +// if (deviceTypeInfo === "phone" || deviceTypeInfo === "default") { +// this.isShow = false +// } else { +// this.isShow = true +// } +// } build() { - Row() { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { - SignalIcon() - WifiIcon() - }.width(Constants.HALF_CONTAINER_WIDTH) - .height(Constants.FULL_CONTAINER_HEIGHT) - - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.End }) { - BatteryIcon() - if (this.isShow) { - ClockIcon() - } - }.width(Constants.HALF_CONTAINER_WIDTH) - .height(Constants.FULL_CONTAINER_HEIGHT) - } - .width(Constants.FULL_CONTAINER_WIDTH) - .height($r("app.float.status_bar_height")) - .padding({ - left: $r("app.float.status_bar_padding_left_right"), - right: $r("app.float.status_bar_padding_left_right") - }) - .margin({ top: $r("app.float.status_bar_margin_top") }) - .opacity($r("app.float.status_bar_opacity")) +// Row() { +// Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { +// SignalIcon() +// WifiIcon() +// }.width(Constants.HALF_CONTAINER_WIDTH) +// .height(Constants.FULL_CONTAINER_HEIGHT) +// +// Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.End }) { +// BatteryIcon() +// if (this.isShow) { +// ClockIcon() +// } +// }.width(Constants.HALF_CONTAINER_WIDTH) +// .height(Constants.FULL_CONTAINER_HEIGHT) +// } +// .width(Constants.FULL_CONTAINER_WIDTH) +// .height($r("app.float.status_bar_height")) +// .padding({ +// left: $r("app.float.status_bar_padding_left_right"), +// right: $r("app.float.status_bar_padding_left_right") +// }) +// .margin({ top: $r("app.float.status_bar_margin_top") }) +// .opacity($r("app.float.status_bar_opacity")) } } \ No newline at end of file diff --git a/product/phone/src/main/ets/WindowScene/HWScene.ets b/product/phone/src/main/ets/WindowScene/HWScene.ets index 098875a8..620efb23 100644 --- a/product/phone/src/main/ets/WindowScene/HWScene.ets +++ b/product/phone/src/main/ets/WindowScene/HWScene.ets @@ -12,17 +12,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import { HWSceneSession } from '@ohos/common' +import sceneSessionManager from '@ohos.sceneSessionManager' +import { HWSceneSession, SpecificSessionArray } from '@ohos/common' +import { HWSpecificSession } from '@ohos/common' import { StyleConstants } from '@ohos/common' import { Log } from '@ohos/common' +import { HWSubScene } from './HWSubScene' const TAG = 'HWScene' +let activateStatusMap: Map = new Map([ + [sceneSessionManager.SessionState.STATE_CONNECT, false], + [sceneSessionManager.SessionState.STATE_FOREGROUND, true], + [sceneSessionManager.SessionState.STATE_ACTIVE, true], + [sceneSessionManager.SessionState.STATE_INACTIVE, true], + [sceneSessionManager.SessionState.STATE_BACKGROUND, false], + [sceneSessionManager.SessionState.STATE_DISCONNECT, false], +]); @Component export struct HWScene { - sceneSession: HWSceneSession + @ObjectLink sceneSession: HWSceneSession; +// @State @Watch("subSessionUpdate") subList: SpecificSessionArray = new SpecificSessionArray(); + @ObjectLink subList: SpecificSessionArray; + subSessionUpdate() { + Log.showError(TAG, 'subSessionUpdate=================='); + } buildLog(sceneSession: HWSceneSession) { if (sceneSession) { Log.showInfo(TAG, 'HWSceneSession bundle name: ' + sceneSession.sceneInfo.bundleName + ' id: ' + sceneSession.session.persistentId); @@ -32,13 +47,61 @@ export struct HWScene { return false; } } + aboutToAppear() { + Log.showInfo(TAG, `====== aboutToAppear`); + + // registerCreateSubSessionCallback + this.sceneSession.registerCreateSubSessionCallback((specificSession: sceneSessionManager.SceneSession) => { + const indexInAll = this.subList.findIndex(item => { + return item.session.persistentId === specificSession.persistentId; + }); + if (indexInAll == -1) { + Log.showInfo(TAG, `Add specific session, id: ${specificSession.persistentId}, index: ${indexInAll}`); + let hwSceneSession = new HWSpecificSession(specificSession, this.sceneSession, this.sceneSession.handleSubSessionStateChange.bind(this.sceneSession)); + this.subList.push(hwSceneSession); + } else { + Log.showInfo(TAG, `Session is already in subList, id: ${specificSession.persistentId}, index: ${indexInAll}`); + } + Log.showInfo(TAG, `onCreateSubSession, new sublist length: ${this.subList.length}`); + }); + + // registerSubSessionActiveStatueChangeCallback + this.sceneSession.registerSubSessionActiveStatueChangeCallback((persistentId:number, state: sceneSessionManager.SessionState) => { + Log.showInfo(TAG, `onSubSessionActiveStatueChange persistentId: ${persistentId}, state: ${state}`); + const index = this.subList.findIndex(item => { + return item.session.persistentId == persistentId; + }); + if (index != -1) { + let isActive = activateStatusMap.get(state) + if (isActive != undefined) { + this.subList[index].isActive = isActive + } + if (state == sceneSessionManager.SessionState.STATE_DISCONNECT) { + this.subList.splice(index, 1); + } + this.subList[index].sessionState = state; + Log.showInfo(TAG, `onSubSessionActiveStatueChange persistentId: ${persistentId}, isActive: ${this.subList[index].isActive}`); + } + }); + + this.sceneSession.registerSessionRectChangeCallback((rect: sceneSessionManager.SessionRect) => { + Log.showInfo(TAG, `registerSessionRectChangeCallback, rect.posX: ${rect.posX_}, rect.posY: ${rect.posY_}, rect.width: ${rect.width}, rect.height: ${rect.height}`); + this.sceneSession.translateX = rect.posX_; + this.sceneSession.translateY = rect.posY_; + this.sceneSession.rect = rect; + }); + } build() { Stack() { if (this.buildLog(this.sceneSession)) { HostWindowScene(this.sceneSession.session.persistentId) .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + .translate({x: this.sceneSession.translateX, y: this.sceneSession.translateY}) } + ForEach(this.subList, (item: HWSpecificSession) => { + HWSubScene({subSession: item}) + }, (item: HWSpecificSession) => item.session.persistentId.toString()) } } } diff --git a/product/phone/src/main/ets/WindowScene/HWSceneContainer.ets b/product/phone/src/main/ets/WindowScene/HWSceneContainer.ets index 19413b0f..1cac4a9a 100644 --- a/product/phone/src/main/ets/WindowScene/HWSceneContainer.ets +++ b/product/phone/src/main/ets/WindowScene/HWSceneContainer.ets @@ -14,7 +14,7 @@ */ import curves from '@ohos.curves' -import { HWSceneContainerSession, HWDividerParam } from '@ohos/common' +import { HWSceneContainerSession, HWDividerParam, SpecificSessionArray } from '@ohos/common' import { HWRecentViewParam } from '@ohos/common'; import { HWScreenSession, DesktopState } from '@ohos/common'; import { HWSceneSessionManager } from '@ohos/common'; @@ -37,7 +37,7 @@ export struct HWSceneContainer { Stack() { Column() { if (this.sceneContainerSession.primarySession) { - HWScene({ sceneSession: this.sceneContainerSession.primarySession }) + HWScene({ sceneSession: this.sceneContainerSession.primarySession, subList: this.sceneContainerSession.primarySession.subSessionList}) .width('100%') .height(this.dividerParam.primaryH) .scale({ y: this.dividerParam.primaryScaleY, centerY: 0 }) @@ -51,7 +51,7 @@ export struct HWSceneContainer { // When primary Exit if (this.sceneContainerSession.secondarySession) { - HWScene({ sceneSession: this.sceneContainerSession.secondarySession }) + HWScene({ sceneSession: this.sceneContainerSession.secondarySession, subList: this.sceneContainerSession.secondarySession.subSessionList }) .scale({ y: this.dividerParam.secondaryScaleY, centerY: 0 }) .blur(this.dividerParam.blurRadius) .translate({ y: this.dividerParam.secTransY }) diff --git a/product/phone/src/main/ets/WindowScene/HWScenePanel.ets b/product/phone/src/main/ets/WindowScene/HWScenePanel.ets index 4c0ac4fe..7aa6ab84 100644 --- a/product/phone/src/main/ets/WindowScene/HWScenePanel.ets +++ b/product/phone/src/main/ets/WindowScene/HWScenePanel.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { HWScreenSession, DesktopState } from '@ohos/common'; +import { HWScreenSession, DesktopState, SpecificSessionArray } from '@ohos/common'; import { HWRecentViewParam } from '@ohos/common'; import { HWSceneContainerSession } from '@ohos/common'; import { HWSceneSessionManager } from '@ohos/common'; @@ -40,6 +40,7 @@ export struct HWScenePanel { @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}`); @@ -58,7 +59,7 @@ export struct HWScenePanel { } else { this.containerTranslation = []; this.containerAlpha = []; - this. containerScale = []; + this.containerScale = []; this.currentState = this.screenSession.desktopState; Log.showInfo(TAG,"this.containerTranslation = " +this.containerTranslation[this.screenSession.sceneContainerSessionList.length-1]) return false; @@ -85,7 +86,7 @@ export struct HWScenePanel { dividerParam: item.dividerParam, recentViewParam: $recentViewParam }) - .size({width:this.recentViewParam.width, height:this.recentViewParam.height}) + .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]}) diff --git a/product/phone/src/main/ets/WindowScene/HWSubScene.ets b/product/phone/src/main/ets/WindowScene/HWSubScene.ets new file mode 100644 index 00000000..2bc029cf --- /dev/null +++ b/product/phone/src/main/ets/WindowScene/HWSubScene.ets @@ -0,0 +1,60 @@ +/* + * 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 sceneSessionManager from '@ohos.sceneSessionManager' +import { HWSceneSession, SpecificSessionArray } from '@ohos/common' +import { HWSpecificSession } from '@ohos/common' +import { StyleConstants } from '@ohos/common' +import { Log } from '@ohos/common' + +const TAG = 'HWSubScene'; + +@Component +export struct HWSubScene { + @ObjectLink @Watch("HWSubScene") subSession: HWSpecificSession; + callback: Function + isActive: boolean + HWSubScene() { + Log.showError(TAG, 'Build HWSubScene'); + } + buildSubLog(subSession: HWSpecificSession) { + if (subSession) { + Log.showInfo(TAG, `liuqi subSession id: ${subSession.session.persistentId}, x: ${subSession.translateX}`); + Log.showInfo(TAG, `liuqi subSession isActive: ${subSession.isActive}`); + } else { + Log.showError(TAG, 'HWSpecificSession is null'); + } + return true; + } + + aboutToAppear() { + Log.showInfo(TAG, `====== aboutToAppear`); + + // registerSubSessionActiveStatueChangeCallback + this.subSession.registerSessionRectChangeCallback((rect: sceneSessionManager.SessionRect) => { + Log.showInfo(TAG, `registerSessionRectChangeCallback, rect.posX: ${rect.posX_}, rect.posY: ${rect.posY_}, rect.width: ${rect.width}, rect.height: ${rect.height}`); + this.subSession.translateX = rect.posX_; + this.subSession.translateY = rect.posY_; + this.subSession.rect = rect; + }); + } + + build() { + if (this.buildSubLog(this.subSession) && this.subSession.isActive) { + HostWindowScene(this.subSession.session.persistentId) + .size({ width: StyleConstants.PERCENTAGE_100, height: StyleConstants.PERCENTAGE_100 }) + .translate({x: this.subSession.translateX, y: this.subSession.translateY}) + } + } +} -- Gitee