From 8b6649c5ae93560e9d4b453970985c0cf3cb893e Mon Sep 17 00:00:00 2001 From: wzp Date: Wed, 6 Dec 2023 21:41:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:service=E8=BF=9B=E7=A8=8B=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wzp --- .../ets/default/bean/GridLayoutItemInfo.ts | 3 +- .../ets/default/manager/CommonEventManager.ts | 24 ++-- .../NavigationBarCommonEventManager.ts | 122 +++++++++--------- .../default/manager/SettingsDataManager.ts | 25 ++-- .../main/ets/default/manager/WindowManager.ts | 79 ++++++------ .../main/ets/default/model/SettingsModel.ts | 12 +- .../ets/default/viewmodel/AppListViewModel.ts | 7 +- .../ets/default/view/FormServiceComponent.ets | 1 + .../ets/default/viewmodel/FormViewModel.ts | 12 +- .../common/GestureNavigationManager.ts | 21 ++- .../ets/default/layout/PageDesktopLayout.ets | 2 +- .../view/RecentMissionsSingleLayout.ets | 1 - .../ets/common/presenter/SettingsPresenter.ts | 10 +- .../settings/src/main/ets/pages/Settings.ets | 31 ++--- .../main/ets/default/layout/RecentLayout.ets | 1 + .../ets/default/layout/ResidentLayout.ets | 2 +- .../src/main/ets/default/layout/SmartDock.ets | 1 + product/pad/src/main/ets/pages/EntryView.ets | 33 ++++- .../phone/src/main/ets/pages/EntryView.ets | 9 +- 19 files changed, 217 insertions(+), 179 deletions(-) diff --git a/common/src/main/ets/default/bean/GridLayoutItemInfo.ts b/common/src/main/ets/default/bean/GridLayoutItemInfo.ts index e08f9ddc..babd5d53 100644 --- a/common/src/main/ets/default/bean/GridLayoutItemInfo.ts +++ b/common/src/main/ets/default/bean/GridLayoutItemInfo.ts @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { AppItemInfo } from './AppItemInfo'; import GridLayoutItemBuilder from './GridLayoutItemBuilder'; @@ -96,7 +97,7 @@ export default class GridLayoutItemInfo { /** * GridLayoutItemInfo: bigFolder apps info */ - layoutInfo: any | undefined; + layoutInfo: AppItemInfo[][] | undefined; /** * GridLayoutItemInfo: extend1 diff --git a/common/src/main/ets/default/manager/CommonEventManager.ts b/common/src/main/ets/default/manager/CommonEventManager.ts index d8c1b939..e3bb6f17 100644 --- a/common/src/main/ets/default/manager/CommonEventManager.ts +++ b/common/src/main/ets/default/manager/CommonEventManager.ts @@ -13,10 +13,8 @@ * limitations under the License. */ -import CommonEvent from '@ohos.commonEvent'; import { AsyncCallback } from '@ohos.base'; -import { CommonEventData } from 'commonEvent/commonEventData'; -import { CommonEventSubscriber } from 'commonEvent/commonEventSubscriber'; +import commonEventMgr from '@ohos.commonEventManager'; const TAG = 'CommonEventManager'; @@ -27,8 +25,8 @@ class CommonEventManager { RECENT_FULL_SCREEN = 'CREATE_RECENT_WINDOW_EVENT'; RECENT_SPLIT_SCREEN = 'common.event.SPLIT_SCREEN'; - private callbackList: AsyncCallback[] = []; - private subscriberList: CommonEventSubscriber[] = []; + private callbackList: AsyncCallback[] = []; + private subscriberList: commonEventMgr.CommonEventSubscriber[] = []; /** * get CommonEventManager instance @@ -48,11 +46,12 @@ class CommonEventManager { /** * Register common event listener. */ - public registerCommonEvent(subscriber: CommonEventSubscriber, eventCallback: AsyncCallback): void { - if (this.subscriberList.indexOf(subscriber) != -1) { + public registerCommonEvent(subscriber: commonEventMgr.CommonEventSubscriber, + eventCallback: AsyncCallback): void { + if (this.subscriberList.indexOf(subscriber) !== -1) { return; } - CommonEvent.subscribe(subscriber, eventCallback); + commonEventMgr.subscribe(subscriber, eventCallback); this.subscriberList.push(subscriber); this.callbackList.push(eventCallback); } @@ -60,14 +59,15 @@ class CommonEventManager { /** * Unregister common event listener. */ - public unregisterCommonEvent(subscriber: CommonEventSubscriber, eventCallback: AsyncCallback): void { + public unregisterCommonEvent(subscriber: commonEventMgr.CommonEventSubscriber, + eventCallback: AsyncCallback): void { const subscriberIndex: number = this.subscriberList.indexOf(subscriber); const callbackIndex: number = this.callbackList.indexOf(eventCallback); - if (subscriberIndex != -1) { - CommonEvent.unsubscribe(subscriber); + if (subscriberIndex !== -1) { + commonEventMgr.unsubscribe(subscriber); this.subscriberList.splice(subscriberIndex, 1); } - callbackIndex != -1 && this.callbackList.splice(callbackIndex, 1); + callbackIndex !== -1 && this.callbackList.splice(callbackIndex, 1); } } diff --git a/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts b/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts index 7c59c2b8..8079089a 100644 --- a/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts +++ b/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts @@ -13,11 +13,8 @@ * limitations under the License. */ -import CommonEvent from '@ohos.commonEvent'; import { AsyncCallback, BusinessError} from '@ohos.base'; -import { CommonEventData } from 'commonEvent/commonEventData'; -import { CommonEventSubscriber } from 'commonEvent/commonEventSubscriber'; -import { CommonEventSubscribeInfo } from 'commonEvent/commonEventSubscribeInfo'; +import commonEventMgr from '@ohos.commonEventManager'; import { EventConstants } from '../constants/EventConstants'; import { localEventManager } from './LocalEventManager'; import commonEventManager from './CommonEventManager'; @@ -29,71 +26,74 @@ const TAG = 'NavigationBarCommonEventManager'; * Wrapper class for NavigationBarCommonEvent interfaces. */ class NavigationBarCommonEventManager { - private static NAVIGATION_BAR_HIDE = 'systemui.event.NAVIGATIONBAR_HIDE'; - private static subscriber: CommonEventSubscriber; - private static eventCallback: AsyncCallback; + private static NAVIGATION_BAR_HIDE = 'systemui.event.NAVIGATIONBAR_HIDE'; + private static subscriber: commonEventMgr.CommonEventSubscriber; + private static eventCallback: AsyncCallback; - /** - * get NavigationBarCommonEvent instance - * - * @return NavigationBarCommonEvent singleton - */ - static getInstance(): NavigationBarCommonEventManager { - if (globalThis.NavigationBarCommonEvent == null) { - globalThis.NavigationBarCommonEvent = new NavigationBarCommonEventManager(); - this.eventCallback = this.navigationBarEventCallback.bind(this); - this.initSubscriber(); - } - return globalThis.NavigationBarCommonEvent; + /** + * get NavigationBarCommonEvent instance + * + * @return NavigationBarCommonEvent singleton + */ + static getInstance(): NavigationBarCommonEventManager { + if (globalThis.NavigationBarCommonEvent == null) { + globalThis.NavigationBarCommonEvent = new NavigationBarCommonEventManager(); + this.eventCallback = this.navigationBarEventCallback.bind(this); + this.initSubscriber(); } + return globalThis.NavigationBarCommonEvent; + } - private static initSubscriber() { - if (NavigationBarCommonEventManager.subscriber != null) { - return; - } - const subscribeInfo: CommonEventSubscribeInfo = { - events: [NavigationBarCommonEventManager.NAVIGATION_BAR_HIDE] - }; - CommonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber: CommonEventSubscriber) => { - Log.showDebug(TAG, "init SPLIT_SCREEN subscriber success"); - NavigationBarCommonEventManager.subscriber = commonEventSubscriber; - }, (err) => { - Log.showError(TAG, `Failed to createSubscriber ${err}`) - }) + private static initSubscriber() { + if (NavigationBarCommonEventManager.subscriber != null) { + return; } + const subscribeInfo: commonEventMgr.CommonEventSubscribeInfo = { + events: [NavigationBarCommonEventManager.NAVIGATION_BAR_HIDE] + }; + commonEventMgr.createSubscriber(subscribeInfo).then( + (commonEventSubscriber: commonEventMgr.CommonEventSubscriber) => { + Log.showDebug(TAG, "init SPLIT_SCREEN subscriber success"); + NavigationBarCommonEventManager.subscriber = commonEventSubscriber; + }, (err) => { + Log.showError(TAG, `Failed to createSubscriber ${err}`); + }) + } - /** - * Register navigationBar event listener. - */ - public registerNavigationBarEvent() { - commonEventManager.registerCommonEvent(NavigationBarCommonEventManager.subscriber, NavigationBarCommonEventManager.eventCallback); - } + /** + * Register navigationBar event listener. + */ + public registerNavigationBarEvent() { + commonEventManager.registerCommonEvent(NavigationBarCommonEventManager.subscriber, + NavigationBarCommonEventManager.eventCallback); + } - /** - * Unregister navigationBar event listener. - */ - public unregisterNavigationBarEvent() { - commonEventManager.unregisterCommonEvent(NavigationBarCommonEventManager.subscriber, NavigationBarCommonEventManager.eventCallback); - } + /** + * Unregister navigationBar event listener. + */ + public unregisterNavigationBarEvent() { + commonEventManager.unregisterCommonEvent(NavigationBarCommonEventManager.subscriber, + NavigationBarCommonEventManager.eventCallback); + } - /** - * navigationBar event handler. - */ - private static async navigationBarEventCallback(error: BusinessError, data: CommonEventData) { - Log.showDebug(TAG,`navigationBarEventCallback receive data: ${JSON.stringify(data)}.`); - if (error.code != 0) { - Log.showError(TAG, `navigationBarEventCallback error: ${JSON.stringify(error)}`); - return; - } - switch (data.event) { - case NavigationBarCommonEventManager.NAVIGATION_BAR_HIDE: - setTimeout(() => { - localEventManager.sendLocalEventSticky(EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE, '0'); - }, 30) - default: - break; - } + /** + * navigationBar event handler. + */ + private static async navigationBarEventCallback(error: BusinessError, data: commonEventMgr.CommonEventData) { + Log.showDebug(TAG,`navigationBarEventCallback receive data: ${JSON.stringify(data)}.`); + if (data.code !== 0) { + Log.showError(TAG, `navigationBarEventCallback error: ${JSON.stringify(error)}`); + return; + } + switch (data.event) { + case NavigationBarCommonEventManager.NAVIGATION_BAR_HIDE: + setTimeout(() => { + localEventManager.sendLocalEventSticky(EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE, '0'); + }, 30) + default: + break; } + } } export const navigationBarCommonEventManager = NavigationBarCommonEventManager.getInstance(); \ No newline at end of file diff --git a/common/src/main/ets/default/manager/SettingsDataManager.ts b/common/src/main/ets/default/manager/SettingsDataManager.ts index 2d1c91de..1c0339b7 100644 --- a/common/src/main/ets/default/manager/SettingsDataManager.ts +++ b/common/src/main/ets/default/manager/SettingsDataManager.ts @@ -15,9 +15,10 @@ */ import { Log } from '../utils/Log'; -import { DataAbilityHelper } from 'ability/dataAbilityHelper'; import settings from '@ohos.settings'; import dataShare from '@ohos.data.dataShare'; +import common from '@ohos.app.ability.common'; +import { Context } from '@ohos.abilityAccessCtrl'; const TAG = 'SettingsDataManager' /** @@ -25,7 +26,7 @@ const TAG = 'SettingsDataManager' */ class SettingsDataManager { private readonly uriShare: string = 'datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key='; - private dataShareHelper; + private dataShareHelper: dataShare.DataShareHelper | null = null; private constructor() { } @@ -54,9 +55,13 @@ class SettingsDataManager { /** * Update settingData by settingDataKey. */ - setValue(helper: any, settingDataKey: string, value: string): void { + setValue(helper: dataShare.DataShareHelper | null, settingDataKey: string, value: string): void { Log.showInfo(TAG, "setValue:" + value) - settings.setValueSync(globalThis.desktopContext, settingDataKey, value); + if (typeof globalThis.desktopContext === 'undefined') { + settings.setValueSync(globalThis.settingsContext as Context, settingDataKey, value); + } else { + settings.setValueSync(globalThis.desktopContext as Context, settingDataKey, value); + } } /** @@ -64,8 +69,13 @@ class SettingsDataManager { * * @return settingsDataValue by settingDataKey. */ - getValue(helper: any, settingDataKey: string, defaultValue: string): string { - let value: string = settings.getValueSync(globalThis.desktopContext, settingDataKey, defaultValue); + getValue(helper: dataShare.DataShareHelper | null, settingDataKey: string, defaultValue: string): string { + let value: string = '1'; + if (typeof globalThis.desktopContext === 'undefined') { + value = settings.getValueSync(globalThis.settingsContext as Context, settingDataKey, defaultValue); + } else { + value = settings.getValueSync(globalThis.desktopContext as Context, settingDataKey, defaultValue); + } Log.showInfo(TAG, "getValue:" + value); return value; } @@ -84,8 +94,7 @@ class SettingsDataManager { * * @return settingDataHelper by settingDataUri. */ - getHelper(context: any, uri: string): any{ - // @ts-ignore api8 d.ts + getHelper(context: common.Context, uri: string): dataShare.DataShareHelper | null { return this.dataShareHelper; } } diff --git a/common/src/main/ets/default/manager/WindowManager.ts b/common/src/main/ets/default/manager/WindowManager.ts index feeb442c..e4fabe2f 100644 --- a/common/src/main/ets/default/manager/WindowManager.ts +++ b/common/src/main/ets/default/manager/WindowManager.ts @@ -15,14 +15,10 @@ import Window from '@ohos.window'; import display from '@ohos.display'; -import CommonEvent from '@ohos.commonEvent'; -import featureAbility from '@ohos.ability.featureAbility'; -import ServiceExtensionContext from 'application/ServiceExtensionContext'; -import { AsyncCallback, BusinessError} from '@ohos.base'; -import { CommonEventData } from 'commonEvent/commonEventData'; -import { CommonEventSubscriber } from 'commonEvent/commonEventSubscriber'; -import { CommonEventSubscribeInfo } from 'commonEvent/commonEventSubscribeInfo'; - +import commonEventMgr from '@ohos.commonEventManager'; +import common from '@ohos.app.ability.common'; +import { AsyncCallback, BusinessError } from '@ohos.base'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; import commonEventManager from './CommonEventManager' import { Log } from '../utils/Log'; import { StyleConstants } from '../constants/StyleConstants'; @@ -33,11 +29,11 @@ const TAG = 'WindowManager'; * Wrapper class for window interfaces. */ class WindowManager { - private mDisplayData = null; + private mDisplayData: display.Display | null = null; - private static subscriber: CommonEventSubscriber; + private static subscriber: commonEventMgr.CommonEventSubscriber; - private static eventCallback: AsyncCallback; + private static eventCallback: AsyncCallback; RECENT_WINDOW_NAME = 'RecentView'; @@ -76,11 +72,11 @@ class WindowManager { * * @return windowWidth */ - async getWindowWidth() { + getWindowWidth(): number { if (this.mDisplayData == null) { - this.mDisplayData = await this.getWindowDisplayData(); + this.mDisplayData = this.getWindowDisplayData(); } - return px2vp(this.mDisplayData.width); + return this.mDisplayData?.width as number; } /** @@ -88,27 +84,26 @@ class WindowManager { * * @return windowHeight */ - async getWindowHeight() { + getWindowHeight(): number { if (this.mDisplayData == null) { - this.mDisplayData = await this.getWindowDisplayData(); + this.mDisplayData = this.getWindowDisplayData(); } - return px2vp(this.mDisplayData.height); + return this.mDisplayData?.height as number; } - private async getWindowDisplayData() { - let displayData = null; - await display.getDefaultDisplay() - .then((res)=>{ - displayData = res; - }).catch((err)=>{ - Log.showError(TAG, 'getWindowDisplayData error:' + err); - }); + private getWindowDisplayData(): display.Display | null { + let displayData: display.Display | null = null; + try { + displayData = display.getDefaultDisplaySync(); + } catch(err) { + Log.showError(TAG, `display.getDefaultDisplaySync error: ${JSON.stringify(err)}`); + } return displayData; } isSplitWindowMode(mode): boolean { - if ((mode == featureAbility.AbilityWindowConfiguration.WINDOW_MODE_SPLIT_PRIMARY) || - (mode == featureAbility.AbilityWindowConfiguration.WINDOW_MODE_SPLIT_SECONDARY)) { + if ((mode === AbilityConstant.WindowMode.WINDOW_MODE_SPLIT_PRIMARY) || + (mode === AbilityConstant.WindowMode.WINDOW_MODE_SPLIT_SECONDARY)) { return true; } return false; @@ -121,8 +116,8 @@ class WindowManager { * @param height window height */ async setWindowSize(width: number, height: number): Promise { - const abilityWindow = await Window.getTopWindow(); - void abilityWindow.resetSize(width, height); + const abilityWindow = await Window.getLastWindow(globalThis.desktopContext as common.BaseContext); + void abilityWindow.resize(width, height); } /** @@ -132,8 +127,8 @@ class WindowManager { * @param y coordinate y */ async setWindowPosition(x: number, y: number): Promise { - const abilityWindow = await Window.getTopWindow(); - void abilityWindow.moveTo(x, y); + const abilityWindow = await Window.getLastWindow(globalThis.desktopContext as common.BaseContext); + void abilityWindow.moveWindowTo(x, y); } /** @@ -172,7 +167,7 @@ class WindowManager { }) } - createWindow(context: ServiceExtensionContext, name: string, windowType: number, loadContent: string, + createWindow(context: common.ServiceExtensionContext, name: string, windowType: number, loadContent: string, isShow: boolean, callback?: Function) { Window.create(context, name, windowType).then((win) => { void win.setPreferredOrientation(Window.Orientation.AUTO_ROTATION_RESTRICTED); @@ -203,7 +198,7 @@ class WindowManager { }); } - createWindowIfAbsent(context: ServiceExtensionContext, name: string, windowType: number, loadContent: string): void { + createWindowIfAbsent(context: common.ServiceExtensionContext, name: string, windowType: number, loadContent: string): void { Log.showDebug(TAG, `create, name ${name}`); Window.find(name).then(win => { void win.show().then(() => { @@ -297,7 +292,7 @@ class WindowManager { windowManager.recentMode = mode; win.setWindowMode(mode).then(); } : (win) => { - windowManager.recentMode = featureAbility.AbilityWindowConfiguration.WINDOW_MODE_FULLSCREEN; + windowManager.recentMode = AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN; win.setFullScreen(true).then(() => { Log.showDebug(TAG, `${this.RECENT_WINDOW_NAME} setFullScreen`); }); @@ -346,10 +341,10 @@ class WindowManager { if (WindowManager.subscriber != null) { return; } - const subscribeInfo: CommonEventSubscribeInfo = { + const subscribeInfo: commonEventMgr.CommonEventSubscribeInfo = { events: [commonEventManager.RECENT_FULL_SCREEN, commonEventManager.RECENT_SPLIT_SCREEN] }; - CommonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber: CommonEventSubscriber) => { + commonEventMgr.createSubscriber(subscribeInfo).then((commonEventSubscriber: commonEventMgr.CommonEventSubscriber) => { Log.showDebug(TAG, "init SPLIT_SCREEN subscriber success"); WindowManager.subscriber = commonEventSubscriber; }, (err) => { @@ -374,9 +369,9 @@ class WindowManager { /** * Window event handler. */ - private static async winEventCallback(error: BusinessError, data: CommonEventData) { + private static async winEventCallback(error: BusinessError, data: commonEventMgr.CommonEventData) { Log.showDebug(TAG,`Launcher WindowManager winEventCallback receive data: ${JSON.stringify(data)}.`); - if (error.code != 0) { + if (data.code !== 0) { Log.showError(TAG, `get winEventCallback error: ${JSON.stringify(error)}`); return; } @@ -389,15 +384,15 @@ class WindowManager { case commonEventManager.RECENT_SPLIT_SCREEN: // split window mode const windowModeMap = { - 'Primary': featureAbility.AbilityWindowConfiguration.WINDOW_MODE_SPLIT_PRIMARY, - 'Secondary': featureAbility.AbilityWindowConfiguration.WINDOW_MODE_SPLIT_SECONDARY + 'Primary': AbilityConstant.WindowMode.WINDOW_MODE_SPLIT_PRIMARY, + 'Secondary': AbilityConstant.WindowMode.WINDOW_MODE_SPLIT_SECONDARY }; - if (data.parameters.windowMode != 'Primary' && data.parameters.windowMode != 'Secondary') { + if (data.parameters.windowMode !== 'Primary' && data.parameters.windowMode !== 'Secondary') { break; } windowManager.createRecentWindow(windowModeMap[data.parameters.windowMode]); globalThis.splitMissionId = data.parameters.missionId; - await WindowManager.subscriber.setCode(0) + await WindowManager.subscriber.setCode(0); await WindowManager.subscriber.finishCommonEvent(); break; default: diff --git a/common/src/main/ets/default/model/SettingsModel.ts b/common/src/main/ets/default/model/SettingsModel.ts index 2179be33..e32b1386 100644 --- a/common/src/main/ets/default/model/SettingsModel.ts +++ b/common/src/main/ets/default/model/SettingsModel.ts @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { DataAbilityHelper } from 'ability/dataAbilityHelper'; import { Log } from '../utils/Log'; import FileUtils from '../utils/FileUtils'; @@ -26,6 +25,7 @@ import { PageDesktopLayoutConfig } from '../layoutconfig/PageDesktopLayoutConfig import { PageDesktopAppModeConfig } from '../layoutconfig/PageDesktopAppModeConfig'; import { SettingsModelObserver } from './SettingsModelObserver'; import GridLayoutConfigs from '../configs/GridLayoutConfigs'; +import dataShare from '@ohos.data.dataShare'; const TAG = 'SettingsModel'; @@ -41,12 +41,12 @@ export class SettingsModel { private readonly mPageDesktopAppModeConfig: PageDesktopAppModeConfig; private mGridConfig = 1; private mGridLayoutTable = GridLayoutConfigs.GridLayoutTable; - private readonly uri: string = null; - private helper: any = null; + private readonly uri: string = ''; + private helper: dataShare.DataShareHelper | null = null; private readonly mObserverList: SettingsModelObserver[] = []; private constructor() { - this.mPageDesktopModeConfig = layoutConfigManager.getModeConfig(PageDesktopModeConfig.DESKTOP_MODE_CONFIG); + this.mPageDesktopModeConfig = PageDesktopModeConfig.getInstance(); const deviceType = this.mPageDesktopModeConfig.getDeviceType(); if (deviceType == CommonConstants.DEFAULT_DEVICE_TYPE) { this.mGridLayoutTable = GridLayoutConfigs.GridLayoutTable; @@ -287,7 +287,9 @@ export class SettingsModel { */ registerListenForDataChanges(callback): void { this.helper = settingsDataManager.getHelper(globalThis.desktopContext, this.uri); - this.helper.on('dataChange', this.uri, callback); + if (this.helper !== null) { + this.helper.on('dataChange', this.uri, callback); + } } private updateMenuId(): void { diff --git a/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts b/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts index 44cf0fb6..b1cf3ad2 100644 --- a/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts +++ b/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts @@ -23,6 +23,11 @@ import AppCenterGridStyleConfig from '../common/AppCenterGridStyleConfig'; const TAG = 'AppListViewModel'; +interface AnimationInfo { + appScaleX: number; + appScaleY: number; +} + const KEY_NAME = "name"; export class AppListViewModel extends BaseViewModel { @@ -62,7 +67,7 @@ export class AppListViewModel extends BaseViewModel { onFinish: () => { } }, () => { - let animationInfo:any = { + let animationInfo: AnimationInfo = { appScaleX: 0.97, appScaleY: 0.97 } diff --git a/feature/form/src/main/ets/default/view/FormServiceComponent.ets b/feature/form/src/main/ets/default/view/FormServiceComponent.ets index 7fa7fc07..918252ff 100644 --- a/feature/form/src/main/ets/default/view/FormServiceComponent.ets +++ b/feature/form/src/main/ets/default/view/FormServiceComponent.ets @@ -328,6 +328,7 @@ export struct FormServiceComponent { } }, (item: AppItemInfo) => JSON.stringify(item)) } + .scrollBar(BarState.Off) .divider({ strokeWidth: ThisStyleConstants.SERVICE_FORM_APP_ITEM_GROUP_DIVIDER_WIDTH, color: ThisStyleConstants.FORM_SERVICE_APP_LIST_DIVIDER_COLOR, diff --git a/feature/form/src/main/ets/default/viewmodel/FormViewModel.ts b/feature/form/src/main/ets/default/viewmodel/FormViewModel.ts index 8de43499..8c175bf9 100644 --- a/feature/form/src/main/ets/default/viewmodel/FormViewModel.ts +++ b/feature/form/src/main/ets/default/viewmodel/FormViewModel.ts @@ -19,7 +19,9 @@ import { PageDesktopModel, CommonConstants, layoutConfigManager, - FormListInfoCacheManager + FormListInfoCacheManager, + CardItemInfo, + LauncherDragItemInfo } from '@ohos/common'; import { FormStyleConfig } from '../common/FormStyleConfig'; import FeatureConstants from '../common/constants/FeatureConstants'; @@ -36,7 +38,7 @@ export class FormViewModel { private readonly mPageDesktopModel: PageDesktopModel; private readonly mFormStyleConfig: FormStyleConfig; private readonly mFormListInfoCacheManager: FormListInfoCacheManager; - private mAllFormsInfo; + private mAllFormsInfo?: CardItemInfo[]; private constructor() { Log.showInfo(TAG, 'constructor start'); @@ -74,15 +76,15 @@ export class FormViewModel { * * @param {any} appInfo */ - async isSupportForm(appInfo) { + async isSupportForm(appInfo: LauncherDragItemInfo) { const formInfoList = await this.mFormModel.getAllFormsInfo(); - const formInfo: any = formInfoList.find(item => { + const formInfo: CardItemInfo = formInfoList.find(item => { if (item.bundleName === appInfo.bundleName) { return true; } }); let isSupportForm = false; - if (formInfo.length > 0) { + if (formInfo) { isSupportForm = true; } return isSupportForm; diff --git a/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts b/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts index af0146d1..2f42caf6 100644 --- a/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts +++ b/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts @@ -18,15 +18,19 @@ import inputMonitor from '@ohos.multimodalInput.inputMonitor'; import { Log, CommonConstants, - settingsDataManager + settingsDataManager, + localEventManager, + EventConstants } from '@ohos/common'; +import dataShare from '@ohos.data.dataShare'; import GestureNavigationExecutors from './GestureNavigationExecutors'; +import display from '@ohos.display'; const TAG = 'GestureNavigationManage'; export class GestureNavigationManager { private readonly uri: string | null = null; - private helper: any = null; + private helper: dataShare.DataShareHelper; private readonly sGestureNavigationExecutors: GestureNavigationExecutors = GestureNavigationExecutors.getInstance(); private touchEventCallback: inputMonitor.TouchEventReceiver | null = null; @@ -53,7 +57,7 @@ export class GestureNavigationManager { this.helper.on('dataChange', this.uri, callback); } - initWindowSize(display: any) { + initWindowSize(display: display.Display) { if (globalThis.sGestureNavigationExecutors) { globalThis.sGestureNavigationExecutors.setScreenWidth(display.width); globalThis.sGestureNavigationExecutors.setScreenHeight(display.height); @@ -66,12 +70,16 @@ export class GestureNavigationManager { private getGestureNavigationStatus() { Log.showDebug(TAG, 'getGestureNavigationStatus enter'); let gestureNavigationStatus = null; - try{ + try { gestureNavigationStatus = this.getValue(); Log.showDebug(TAG, `getGestureNavigationStatus gestureNavigationStatus: ${gestureNavigationStatus}`); this.handleEventSwitches(gestureNavigationStatus); + + // 初始化时保持弹窗的距离底部的位置和(打开/关闭)三键时的位置一致 + AppStorage.setOrCreate('NavigationBarStatusValue', gestureNavigationStatus === '0' ? true : false); + this.registerListenForDataChanges(this.dataChangesCallback.bind(this)); - }catch (error) { + } catch (error) { Log.showError(TAG, `getGestureNavigationStatus error: ${JSON.stringify(error)}`); } } @@ -80,7 +88,8 @@ export class GestureNavigationManager { Log.showInfo(TAG, "dataChangesCallback data:" + data); const getRetValue = this.getValue(); this.handleEventSwitches(getRetValue); - AppStorage.setOrCreate('NavigationBarStatusValue', getRetValue == '0' ? true : false); + AppStorage.setOrCreate('NavigationBarStatusValue', getRetValue === '0' ? true : false); + localEventManager.sendLocalEventSticky(EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE, getRetValue); } private turnOnTouchEventCallback() { diff --git a/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets b/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets index 33b9c31d..58dcab55 100644 --- a/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets +++ b/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets @@ -118,7 +118,7 @@ export struct PageDesktopLayout { @CustomDialog struct settingDialog { @StorageLink('NavigationBarStatusValue') navigationBarStatusValue: boolean = false; - controller?: CustomDialogController + controller?: CustomDialogController; cancel = () => {}; confirm = () => {}; onAccept = () => {}; diff --git a/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets b/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets index dfad85ba..30eedf10 100644 --- a/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets +++ b/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets @@ -55,7 +55,6 @@ export struct RecentMissionsSingleLayout { } }, (item: RecentMissionInfo) => JSON.stringify(item)) } - .cachedCount(3) .scrollBar(BarState.Off) .listDirection(Axis.Horizontal) .height(RecentsStyleConstants.SINGLE_LIST_MISSION_HEIGHT) diff --git a/feature/settings/src/main/ets/common/presenter/SettingsPresenter.ts b/feature/settings/src/main/ets/common/presenter/SettingsPresenter.ts index eb32aa01..5306b294 100644 --- a/feature/settings/src/main/ets/common/presenter/SettingsPresenter.ts +++ b/feature/settings/src/main/ets/common/presenter/SettingsPresenter.ts @@ -205,21 +205,17 @@ export default class SettingsPresenter { sendLocalEvent(value: string) { Log.showDebug(TAG, `setValue value: ${value}`); - if (value != '1' && value != '0') { + if (value !== '1' && value !== '0') { Log.showDebug(TAG, 'setValue error'); return; } - if (value == '0') { - this.mSettingsModel.setValue(value); - } else { - localEventManager.sendLocalEventSticky(EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE, value); - } + this.mSettingsModel.setValue(value); } initNavigationBarStatusValue() { try { const initValue = this.mSettingsModel.getValue(); - const navigationBarStatusValue = initValue == '0' ? true : false; + const navigationBarStatusValue = initValue === '0' ? true : false; Log.showDebug(TAG, `initNavigationBarStatusValue initValue:${initValue}, navigationBarStatusValue:${navigationBarStatusValue}`); AppStorage.setOrCreate('NavigationBarStatusValue', navigationBarStatusValue); } catch (e) { diff --git a/feature/settings/src/main/ets/pages/Settings.ets b/feature/settings/src/main/ets/pages/Settings.ets index 37061168..d328b565 100644 --- a/feature/settings/src/main/ets/pages/Settings.ets +++ b/feature/settings/src/main/ets/pages/Settings.ets @@ -28,15 +28,16 @@ const TAG = 'Settings'; @Entry @Component struct Index { - private mSettingsStage = new SettingsStage(); + private mSettingsStage: SettingsStage = new SettingsStage(); private mDevice = SettingsStyleConstants.DEFAULT_DEVICE_TYPE_PHONE; + @State mSettingsPresenter: SettingsPresenter | null = null; onPageShow(): void { } aboutToAppear(): void { this.getDeviceType(); this.mSettingsStage.onCreate(); - mSettingsPresenter = SettingsPresenter.getInstance(); + this.mSettingsPresenter = SettingsPresenter.getInstance(); } aboutToDisappear(): void { @@ -45,13 +46,13 @@ struct Index { async getDeviceType() { try { - let sysWidth = await windowManager.getWindowWidth(); - let sysHeigh = await windowManager.getWindowHeight(); - if (sysWidth > sysHeigh) { + let sysWidth = px2vp(windowManager.getWindowWidth()); + let sysHeight = px2vp(windowManager.getWindowHeight()); + if (sysWidth > sysHeight) { this.mDevice = SettingsStyleConstants.DEFAULT_DEVICE_TYPE_PAD; } } catch (e) { - Log.showError(TAG, 'getWindowWidth or getWindowHeight error:' + e); + Log.showError(TAG, `getWindowWidth or getWindowHeight error: ${JSON.stringify(e)}`); } } @@ -109,7 +110,7 @@ struct top_bar { .width(SettingsStyleConstants.DEFAULT_VP_24) .height(SettingsStyleConstants.DEFAULT_VP_24) .onClick(() => { - mSettingsPresenter.backToTheDesktop(); + SettingsPresenter.getInstance().backToTheDesktop(); }) Text($r('app.string.into_settings')) @@ -128,14 +129,10 @@ struct SettingPage { @State SettingList: SettingItemInfo[] = []; aboutToAppear(): void { - this.SettingList = mSettingsPresenter.getSettingList(); + this.SettingList = SettingsPresenter.getInstance().getSettingList(); Log.showInfo(TAG, `aboutToAppear SettingList length: ${this.SettingList.length}`); } - onPageShow(): void { - this.SettingList = mSettingsPresenter.getSettingList(); - } - build() { Column() { ForEach(this.SettingList, (item: SettingItemInfo) => { @@ -177,9 +174,9 @@ struct SettingItem { } aboutToAppear(): void { - mSettingsPresenter.initNavigationBarStatusValue(); + SettingsPresenter.getInstance().initNavigationBarStatusValue(); if (this.settingType == 1) { - mSettingsPresenter.registerValueCallback(this.ida, this.callback); + SettingsPresenter.getInstance().registerValueCallback(this.ida, this.callback); } } @@ -232,7 +229,7 @@ struct SettingItem { .height(40) .onChange((isOn: boolean) => { Log.showDebug(TAG, `SettingItemToggle onChange for GestureNavigation Enable: ${isOn}`); - mSettingsPresenter.sendLocalEvent(isOn ? '0' : '1'); + SettingsPresenter.getInstance().sendLocalEvent(isOn ? '0' : '1'); }) } } @@ -278,8 +275,8 @@ struct SettingsDialog { }.width(SettingsStyleConstants.PERCENTAGE_100) .height(SettingsStyleConstants.DEFAULT_VP_80) .onClick(() => { - mSettingsPresenter.changeSettingValue(this.ida, item.name); - mSettingsPresenter.setSettingsValue(this.ida, item.value); + SettingsPresenter.getInstance().changeSettingValue(this.ida, item.name); + SettingsPresenter.getInstance().setSettingsValue(this.ida, item.value); if (this.controller) { this.controller.close(); } diff --git a/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets b/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets index e7aa2d71..f9c0cec3 100644 --- a/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets +++ b/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets @@ -188,6 +188,7 @@ export default struct RecentLayout { }) }, (item: DockItemInfo) => JSON.stringify(item)) } + .scrollBar(BarState.Off) .padding(this.dockPadding) .width(this.getListWidth()) .height(this.mSmartDockStyleConfig?.mDockHeight as number) diff --git a/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets b/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets index b3ecf48c..50428967 100644 --- a/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets +++ b/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets @@ -94,12 +94,12 @@ export default struct ResidentLayout { } }, (item: DockItemInfo) => JSON.stringify(item)) } + .scrollBar(BarState.Off) .height('100%') .animation({ curve: Curve.Friction }) .listDirection(Axis[this.mSmartDockStyleConfig.mListDirection]) - .editMode(false) } .backgroundColor(this.mSmartDockStyleConfig.mBackgroundColor) .borderRadius(this.mSmartDockStyleConfig.mDockRadius) diff --git a/feature/smartdock/src/main/ets/default/layout/SmartDock.ets b/feature/smartdock/src/main/ets/default/layout/SmartDock.ets index 8bc8ecfd..3a060897 100644 --- a/feature/smartdock/src/main/ets/default/layout/SmartDock.ets +++ b/feature/smartdock/src/main/ets/default/layout/SmartDock.ets @@ -186,6 +186,7 @@ export struct SmartDock { }) } } + .scrollBar(BarState.Off) .hitTestBehavior(this.desktopEventResponse ? HitTestMode.Default : HitTestMode.Block) .alignListItem(ListItemAlign.Center) .height(SmartDockConstants.PERCENTAGE_100) diff --git a/product/pad/src/main/ets/pages/EntryView.ets b/product/pad/src/main/ets/pages/EntryView.ets index efac2707..76ce788a 100644 --- a/product/pad/src/main/ets/pages/EntryView.ets +++ b/product/pad/src/main/ets/pages/EntryView.ets @@ -33,6 +33,7 @@ import { FormStyleConfig } from '@ohos/form'; import AppCenterGridStyleConfig from '@ohos/appcenter/src/main/ets/default/common/AppCenterGridStyleConfig'; import PadPageDesktopGridStyleConfig from '../common/PadPageDesktopGridStyleConfig'; import { SmartDockStyleConfig } from '@ohos/smartdock'; +import display from '@ohos.display'; const RAW_IMAGE_CACHE_SIZE = 20000000; const TAG = 'EntryView'; @@ -57,16 +58,34 @@ struct EntryView { @State mAppScaleY: number = 1.0; @State mAppAlpha: number = 1.0; @StorageLink('IsSetImageRawDataCacheSize') IsSetImageRawDataCacheSize?: boolean = undefined; + async onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) { + if (mediaQueryResult.matches) { + Log.showInfo(TAG, 'screen change to landscape'); + AppStorage.setOrCreate('isPortrait', false); + } else { + Log.showInfo(TAG, 'screen change to portrait'); + AppStorage.setOrCreate('isPortrait', true); + } + let dis: display.Display | null = null; + try { + dis = display.getDefaultDisplaySync(); + Log.showInfo(TAG, `change to display: ${JSON.stringify(dis)}`); + AppStorage.setOrCreate('screenWidth', px2vp(dis.width)); + AppStorage.setOrCreate('screenHeight', px2vp(dis.height)); + Log.showDebug(TAG, `screenWidth and screenHeight: ${AppStorage.get('screenWidth')},${AppStorage.get('screenHeight')}`); + } catch (err) { + Log.showError(TAG, `display.getDefaultDisplaySync err: ${JSON.stringify(err)}`) + } + } aboutToAppear(): void { Log.showInfo(TAG, 'aboutToAppear'); this.mStage.onCreate(); - + this.navigationBarStatus = SettingsModel.getInstance().getValue(); this.getWindowSize(); this.updateScreenSize(); - this.mOrientationListener.on('change', windowManager.onPortrait); + this.mOrientationListener.on('change', this.onPortrait); this.registerPageDesktopNavigatorStatusChangeEvent(this.mLocalEventListener); - this.navigationBarStatus = SettingsModel.getInstance().getValue(); } registerPageDesktopNavigatorStatusChangeEvent(listener: LocalEventListener): void { @@ -139,10 +158,10 @@ struct EntryView { } } - private async getWindowSize(): Promise { + private getWindowSize(): void { try { - this.screenWidth = await windowManager.getWindowWidth(); - this.screenHeight = await windowManager.getWindowHeight(); + this.screenWidth = px2vp(windowManager.getWindowWidth()); + this.screenHeight = px2vp(windowManager.getWindowHeight()); AppStorage.setOrCreate('screenWidth', this.screenWidth); AppStorage.setOrCreate('screenHeight', this.screenHeight); } catch (error) { @@ -161,7 +180,7 @@ struct EntryView { } aboutToDisappear(): void { - this.mOrientationListener.off('change', windowManager.onPortrait); + this.mOrientationListener.off('change', this.onPortrait); this.mStage.onDestroy(); } diff --git a/product/phone/src/main/ets/pages/EntryView.ets b/product/phone/src/main/ets/pages/EntryView.ets index 3508e586..f264d0e2 100644 --- a/product/phone/src/main/ets/pages/EntryView.ets +++ b/product/phone/src/main/ets/pages/EntryView.ets @@ -59,11 +59,12 @@ struct EntryView { aboutToAppear(): void { Log.showInfo(TAG, 'aboutToAppear'); this.mStage.onCreate(); + this.navigationBarStatus = SettingsModel.getInstance().getValue(); this.getWindowSize(); this.updateScreenSize(); this.registerPageDesktopNavigatorStatusChangeEvent(this.mLocalEventListener); - this.navigationBarStatus = SettingsModel.getInstance().getValue(); + } registerPageDesktopNavigatorStatusChangeEvent(listener: LocalEventListener): void { @@ -105,10 +106,10 @@ struct EntryView { } } - private async getWindowSize(): Promise { + private getWindowSize(): void { try { - this.screenWidth = await windowManager.getWindowWidth(); - this.screenHeight = await windowManager.getWindowHeight(); + this.screenWidth = px2vp(windowManager.getWindowWidth()); + this.screenHeight = px2vp(windowManager.getWindowHeight()); AppStorage.setOrCreate('screenWidth', this.screenWidth); AppStorage.setOrCreate('screenHeight', this.screenHeight); } catch (error) { -- Gitee