diff --git a/common/src/main/ets/default/base/BaseViewModel.ts b/common/src/main/ets/default/base/BaseViewModel.ts index d84bd9e4e8a167013f9b68687e75fb0ff0c68d53..802dfbe809930479f1f798030041e359025e6f57 100644 --- a/common/src/main/ets/default/base/BaseViewModel.ts +++ b/common/src/main/ets/default/base/BaseViewModel.ts @@ -19,6 +19,7 @@ import { AppModel } from '../model/AppModel'; import { ResourceManager } from '../manager/ResourceManager'; import { CommonConstants } from '../constants/CommonConstants'; import { launcherAbilityManager } from '../manager/LauncherAbilityManager'; +import { AsyncCallback } from '@ohos.base'; const TAG = 'BaseViewModel'; @@ -27,7 +28,7 @@ const KEY_NAME = 'name'; /** * Base class for view models. */ - export class BaseViewModel { +export class BaseViewModel { protected mAppModel: AppModel; protected mResourceManager: ResourceManager; private readonly listener; @@ -66,6 +67,10 @@ const KEY_NAME = 'name'; this.jumpTo(CommonConstants.SETTING_ABILITY, CommonConstants.LAUNCHER_BUNDLE, CommonConstants.SETTING_MODULE); } + private uninstallAppCallback = (resultCode: number): void => { + this.informUninstallResult(resultCode); + } + /** * Uninstall target app by bundle name. * @@ -76,14 +81,10 @@ const KEY_NAME = 'name'; if (!isUninstallable) { this.informUninstallResult(CommonConstants.UNINSTALL_FORBID); } else { - void launcherAbilityManager.uninstallLauncherAbility(uninstallBundleName, this.uninstallAppCallback.bind(this)); + void launcherAbilityManager.uninstallLauncherAbility(uninstallBundleName, this.uninstallAppCallback); } } - private uninstallAppCallback(resultData: {code: number}): void { - this.informUninstallResult(resultData.code); - } - registerAppListChangeCallback(): void { this.mAppModel.registerStateChangeListener(this.listener); } @@ -101,7 +102,7 @@ const KEY_NAME = 'name'; } informUninstallResult(resultCode: number): void { - Log.showDebug(TAG, `Launcher AppListView getUninstallApp uninstallationResult: ${resultCode}`); + Log.showDebug(TAG, `Launcher AppListView getUninstallApp uninstallationResult: ${resultCode}`); if (resultCode === CommonConstants.UNINSTALL_FORBID) { Prompt.showToast({ message: $r("app.string.disable_uninstall") diff --git a/common/src/main/ets/default/bean/AppItemInfo.ts b/common/src/main/ets/default/bean/AppItemInfo.ts index e4131db5e3b8c73a5fd1d0a1ddbb932a38cb7180..647a06a1aff8ef1590e3f54ca093055205caa5d9 100644 --- a/common/src/main/ets/default/bean/AppItemInfo.ts +++ b/common/src/main/ets/default/bean/AppItemInfo.ts @@ -62,9 +62,9 @@ export class AppItemInfo { */ badgeNumber: number | undefined; - checked?: boolean | undefined; + checked: boolean | undefined; - installTime?: string | undefined; + installTime: string | undefined; moduleName: string | undefined; diff --git a/common/src/main/ets/default/bean/GridLayoutItemInfo.ts b/common/src/main/ets/default/bean/GridLayoutItemInfo.ts index e08f9ddce35ae2ebc23c1df471e4344295122987..8c5d9542f6f03442e85e40db6a04b66fd400d6a0 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 d8c1b939f748184878f0725dca1ce763a5368b85..e3bb6f17b3e7ee5607a7b6b0e9a62be934914c3c 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/InputMethodManager.ts b/common/src/main/ets/default/manager/InputMethodManager.ts index 7432175add65849cac6c0190be864e56df939844..76713bcfb1c13376498a794286260e2ea92e1e8a 100644 --- a/common/src/main/ets/default/manager/InputMethodManager.ts +++ b/common/src/main/ets/default/manager/InputMethodManager.ts @@ -28,6 +28,6 @@ export class InputMethodManager { } stopInput(): void { - inputMethod.getInputMethodController()?.stopInput(); + inputMethod.getController()?.stopInputSession(); } } \ 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 7f32c184f40e1e10441ceccaae1d27d1e060593c..772d55ab2522d520dc8939731aaab920c48d06b2 100644 --- a/common/src/main/ets/default/manager/LauncherAbilityManager.ts +++ b/common/src/main/ets/default/manager/LauncherAbilityManager.ts @@ -13,43 +13,48 @@ * limitations under the License. */ -import bundleMgr from '@ohos.bundle'; +import installer from '@ohos.bundle.installer'; +import bundleMonitor from '@ohos.bundle.bundleMonitor'; import osAccount from '@ohos.account.osAccount'; import hiSysEvent from '@ohos.hiSysEvent'; -import launcherBundleMgr from '@ohos.bundle.innerBundleManager'; -import { LauncherAbilityInfo } from 'bundle/launcherAbilityInfo'; +import launcherBundleManager from '@ohos.bundle.launcherBundleManager'; import { Log } from '../utils/Log'; -import { Trace } from '../utils/Trace'; import { CheckEmptyUtils } from '../utils/CheckEmptyUtils'; import { AppItemInfo } from '../bean/AppItemInfo'; import { CommonConstants } from '../constants/CommonConstants'; import { ResourceManager } from './ResourceManager'; import { EventConstants } from '../constants/EventConstants'; import { BadgeManager } from '../manager/BadgeManager'; +import { BusinessError } from '@ohos.base'; const TAG = 'LauncherAbilityManager'; +interface BundleStatusCallback { + add: (bundleName: string, userId: number) => void; + remove: (bundleName: string, userId: number) => void; + update: (bundleName: string, userId: number) => void; +} + /** * Wrapper class for innerBundleManager and formManager interfaces. */ class LauncherAbilityManager { private static readonly CURRENT_USER_ID = -2; - private static readonly BUNDLE_STATUS_CHANGE_KEY = 'BundleStatusChange'; private readonly mAppMap = new Map(); private mUserId: number = 100; - private readonly mBundleStatusCallback: any = { + private readonly mBundleStatusCallback: BundleStatusCallback = { add: (bundleName, userId) => { - Log.showDebug(TAG, `mBundleStatusCallback add bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); - this.mUserId == userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_ADDED, bundleName, userId); + Log.showDebug(TAG, `PACKAGE_ADDED bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); + this.mUserId === userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_ADDED, bundleName, userId); }, remove: (bundleName, userId) => { - Log.showDebug(TAG, `mBundleStatusCallback remove bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); - this.mUserId == userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_REMOVED, bundleName, userId); + Log.showDebug(TAG, `PACKAGE_REMOVED bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); + this.mUserId === userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_REMOVED, bundleName, userId); }, update: (bundleName, userId) => { - Log.showDebug(TAG, `mBundleStatusCallback update bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); - this.mUserId == userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_CHANGED, bundleName, userId); + Log.showDebug(TAG, `PACKAGE_CHANGED bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); + this.mUserId === userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_CHANGED, bundleName, userId); } }; @@ -87,11 +92,25 @@ class LauncherAbilityManager { registerLauncherAbilityChangeListener(listener: any): void { if (listener != null) { if (this.mLauncherAbilityChangeListeners.length == 0) { - launcherBundleMgr.on(LauncherAbilityManager.BUNDLE_STATUS_CHANGE_KEY, this.mBundleStatusCallback).then(data => { - Log.showDebug(TAG, `registerCallback success: ${JSON.stringify(data)}`); - }).catch(err => { - Log.showError(TAG, `registerCallback fail: ${JSON.stringify(err)}`); - }); + try { + bundleMonitor.on('add', (bundleChangeInfo) => { + Log.showInfo(TAG, `add bundleName: ${bundleChangeInfo.bundleName} userId: ${bundleChangeInfo.userId}`); + this.mBundleStatusCallback.add(bundleChangeInfo.bundleName, bundleChangeInfo.userId); + }); + bundleMonitor.on('update', (bundleChangeInfo) => { + Log.showInfo(TAG, `update bundleName: ${bundleChangeInfo.bundleName} userId: ${bundleChangeInfo.userId}`); + this.mBundleStatusCallback.update(bundleChangeInfo.bundleName, bundleChangeInfo.userId); + }); + bundleMonitor.on('remove', (bundleChangeInfo) => { + Log.showInfo(TAG, `remove bundleName: ${bundleChangeInfo.bundleName} userId: ${bundleChangeInfo.userId}`); + this.mBundleStatusCallback.remove(bundleChangeInfo.bundleName, bundleChangeInfo.userId); + }); + Log.showInfo(TAG, `registerCallback success`); + } catch (errData) { + let message = (errData as BusinessError).message; + let errCode = (errData as BusinessError).code; + Log.showError(TAG, `registerCallback fail errCode:${errCode}, message:${message}`); + } } const index = this.mLauncherAbilityChangeListeners.indexOf(listener); if (index == CommonConstants.INVALID_VALUE) { @@ -112,11 +131,16 @@ class LauncherAbilityManager { this.mLauncherAbilityChangeListeners.splice(index, 1); } if (this.mLauncherAbilityChangeListeners.length == 0) { - launcherBundleMgr.off(LauncherAbilityManager.BUNDLE_STATUS_CHANGE_KEY).then(data => { - Log.showDebug(TAG, 'unregisterCallback success'); - }).catch(err => { - Log.showError(TAG, `unregisterCallback fail: ${JSON.stringify(err)}`); - }); + try { + bundleMonitor.off('add'); + bundleMonitor.off('update'); + bundleMonitor.off('remove'); + Log.showInfo(TAG, 'unregisterCallback success'); + } catch (errData) { + let message = (errData as BusinessError).message; + let errCode = (errData as BusinessError).code; + Log.showError(TAG, `unregisterCallback fail errCode:${errCode}, message:${message}`); + } } } } @@ -132,7 +156,7 @@ class LauncherAbilityManager { */ async getLauncherAbilityList(): Promise { let abilityList = null; - await launcherBundleMgr.getAllLauncherAbilityInfos(LauncherAbilityManager.CURRENT_USER_ID) + await launcherBundleManager.getAllLauncherAbilityInfo(LauncherAbilityManager.CURRENT_USER_ID) .then((res) => { abilityList = res; }) @@ -158,8 +182,8 @@ class LauncherAbilityManager { * @return List of entry capabilities information of the target application */ async getLauncherAbilityInfo(bundleName: string): Promise { - let abilityInfos: LauncherAbilityInfo[]; - await launcherBundleMgr.getLauncherAbilityInfos(bundleName, this.mUserId) + let abilityInfos: launcherBundleManager.LauncherAbilityInfo[]; + await launcherBundleManager.getLauncherAbilityInfo(bundleName, this.mUserId) .then((res) => { abilityInfos = res; }) @@ -193,15 +217,15 @@ class LauncherAbilityManager { return appItemInfo; } // get from system - let abilityInfos = new Array(); - await launcherBundleMgr.getLauncherAbilityInfos(bundleName, LauncherAbilityManager.CURRENT_USER_ID) + let abilityInfos = new Array(); + await launcherBundleManager.getLauncherAbilityInfo(bundleName, LauncherAbilityManager.CURRENT_USER_ID) .then((res)=>{ if (res && res.length) { abilityInfos = res; } }) .catch((err)=>{ - Log.showError(TAG, `getAppInfoByBundleName launcherBundleMgr getLauncherAbilityInfos error: ${JSON.stringify(err)}`); + Log.showError(TAG, `getAppInfoByBundleName getLauncherAbilityInfo error: ${JSON.stringify(err)}`); }); if (!abilityInfos || abilityInfos.length === 0) { Log.showDebug(TAG, `${bundleName} has no launcher ability`); @@ -247,17 +271,28 @@ class LauncherAbilityManager { * @params bundleName application bundleName * @params callback to get result */ - async uninstallLauncherAbility(bundleName: string, callback): Promise { + async uninstallLauncherAbility(bundleName: string, callback: (resultCode: number) => void): Promise { Log.showInfo(TAG, `uninstallLauncherAbility bundleName: ${bundleName}`); - const bundlerInstaller = await bundleMgr.getBundleInstaller(); - bundlerInstaller.uninstall(bundleName, { - userId: this.mUserId, - installFlag: 0, - isKeepData: false - }, (result) => { - Log.showDebug(TAG, `uninstallLauncherAbility result => ${JSON.stringify(result)}`); - callback(result); - }); + try { + const bundlerInstaller = await installer.getBundleInstaller(); + bundlerInstaller.uninstall(bundleName, { + userId: this.mUserId, + installFlag: 0, + isKeepData: false + }, (err: BusinessError) => { + if (err) { + callback(CommonConstants.INVALID_VALUE); + Log.showError(TAG, `uninstallLauncherAbility failed: ${JSON.stringify(err)}`); + } else { + callback(CommonConstants.UNINSTALL_SUCCESS); + Log.showDebug(TAG, `uninstallLauncherAbility successfully: ${JSON.stringify(err)}`); + } + }); + } catch (err) { + let errCode = (err as BusinessError).code; + let errMsg = (err as BusinessError).message; + Log.showError(TAG, `uninstallLauncherAbility errCode: ${errCode}, errMsg: ${errMsg}`); + } } /** @@ -321,9 +356,9 @@ class LauncherAbilityManager { }); } - async getShortcutInfo(paramBundleName, callback) { + async getShortcutInfo(paramBundleName: string, callback) { Log.showDebug(TAG, `getShortcutInfo bundleName: ${paramBundleName}`); - await launcherBundleMgr.getShortcutInfos(paramBundleName) + await launcherBundleManager.getShortcutInfo(paramBundleName) .then(shortcutInfo => { callback(paramBundleName, shortcutInfo); }) @@ -337,7 +372,7 @@ class LauncherAbilityManager { * @params paramBundleName application bundle name * @params paramAbilityName application abilit uri */ - startLauncherAbilityByUri(paramBundleName, abilityUri) { + startLauncherAbilityByUri(paramBundleName: string, abilityUri) { Log.showInfo(TAG, `startLauncherAbilityByUri bundleName:${paramBundleName} abilityUri:${abilityUri}`); const result = globalThis.desktopContext.startAbility({ bundleName: paramBundleName, diff --git a/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts b/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts index 7c59c2b8c27ee5f44ac6df57a0eb09f9e208df2e..8079089a5814e6cb5cce87efccd262cc4a0b8cb6 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/RdbStoreManager.ts b/common/src/main/ets/default/manager/RdbStoreManager.ts index b5d5f857fc5893da6cc4954678ee8114cd70338d..4db8ae6e4b127080a9cf3cc825d3b5edaec75a8c 100644 --- a/common/src/main/ets/default/manager/RdbStoreManager.ts +++ b/common/src/main/ets/default/manager/RdbStoreManager.ts @@ -13,7 +13,9 @@ * limitations under the License. */ -import dataRdb from '@ohos.data.rdb'; +import relationalStore from '@ohos.data.relationalStore'; +import { BusinessError } from '@ohos.base'; +import deviceInfo from '@ohos.deviceInfo'; import hiSysEvent from '@ohos.hiSysEvent'; import { Log } from '../utils/Log'; import { CheckEmptyUtils } from '../utils/CheckEmptyUtils'; @@ -34,7 +36,7 @@ const TAG = 'RdbStoreManager'; * Wrapper class for rdb interfaces. */ export class RdbStoreManager { - private mRdbStore; + private mRdbStore: relationalStore.RdbStore; private constructor() { } @@ -52,20 +54,23 @@ export class RdbStoreManager { async initRdbConfig(): Promise { Log.showInfo(TAG, 'initRdbConfig start'); - await dataRdb.getRdbStore(globalThis.desktopContext, { - name: RdbStoreConfig.DB_NAME - }, RdbStoreConfig.DB_VERSION) - .then((rdbStore) => { - this.mRdbStore = rdbStore; - }) - .catch((error) => { - Log.showError(TAG, `initRdbConfig Failed to obtain the rdbStore. Cause: ${error.message}`); - }); + try { + const STORE_CONFIG: relationalStore.StoreConfig = { + name: RdbStoreConfig.DB_NAME, + securityLevel: relationalStore.SecurityLevel.S3 + }; + + this.mRdbStore = await relationalStore.getRdbStore(globalThis.desktopContext, STORE_CONFIG); + } catch (error) { + let err = error as BusinessError; + Log.showError(TAG, `initRdbConfig Failed. code: ${err.code}, message: ${err.message}`); + } } async createTable(): Promise { Log.showDebug(TAG, 'create table start'); try { + await this.mRdbStore.executeSql(RdbStoreConfig.Settings.CREATE_TABLE); await this.mRdbStore.executeSql(RdbStoreConfig.Badge.CREATE_TABLE); await this.mRdbStore.executeSql(RdbStoreConfig.Form.CREATE_TABLE); await this.mRdbStore.executeSql(RdbStoreConfig.SmartDock.CREATE_TABLE); @@ -75,24 +80,24 @@ export class RdbStoreManager { // set default settings data await this.updateSettings(); } catch (error) { - Log.showError(TAG, `create table error: ${error}`); + Log.showError(TAG, `createTable error: ${JSON.stringify(error)}`); } Log.showDebug(TAG, 'create table end'); } async getAllBadge(): Promise { Log.showDebug(TAG, 'getAllBadge start'); - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); const resultList: BadgeItemInfo[] = []; try { let resultSet = await this.mRdbStore.query(predicates, []); let isLast = resultSet.goToFirstRow(); while (isLast) { const itemInfo: BadgeItemInfo = new BadgeItemInfo(); - itemInfo.id = resultSet.getLong(resultSet.getColumnIndex('id')); + itemInfo.id = resultSet.getString(resultSet.getColumnIndex('id')); itemInfo.bundleName = resultSet.getString(resultSet.getColumnIndex('bundle_name')); itemInfo.badgeNumber = resultSet.getLong(resultSet.getColumnIndex('badge_number')); - itemInfo.display = resultSet.getLong(resultSet.getColumnIndex('display')); + itemInfo.display = this.numberToBoolean(resultSet.getLong(resultSet.getColumnIndex('display'))); itemInfo.userId = resultSet.getLong(resultSet.getColumnIndex('user_id')); resultList.push(itemInfo); isLast = resultSet.goToNextRow(); @@ -112,16 +117,16 @@ export class RdbStoreManager { return resultList; } try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); predicates.equalTo('bundle_name', bundleName); let resultSet = await this.mRdbStore.query(predicates, []); let isLast = resultSet.goToFirstRow(); while (isLast) { const itemInfo: BadgeItemInfo = new BadgeItemInfo(); - itemInfo.id = resultSet.getLong(resultSet.getColumnIndex('id')); + itemInfo.id = resultSet.getString(resultSet.getColumnIndex('id')); itemInfo.bundleName = resultSet.getString(resultSet.getColumnIndex('bundle_name')); itemInfo.badgeNumber = resultSet.getLong(resultSet.getColumnIndex('badge_number')); - itemInfo.display = resultSet.getLong(resultSet.getColumnIndex('display')); + itemInfo.display = this.numberToBoolean(resultSet.getLong(resultSet.getColumnIndex('display'))); itemInfo.userId = resultSet.getLong(resultSet.getColumnIndex('user_id')); resultList.push(itemInfo); isLast = resultSet.goToNextRow(); @@ -141,7 +146,7 @@ export class RdbStoreManager { return result; } try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); predicates.equalTo('bundle_name', bundleName); const updateBucket = { 'badge_number': badgeNum @@ -172,7 +177,7 @@ export class RdbStoreManager { return result; } try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); predicates.equalTo('bundle_name', bundleName); const changeRows = await this.mRdbStore.delete(predicates); if (changeRows == 1) { @@ -192,7 +197,7 @@ export class RdbStoreManager { */ async getAllFormInfos(cardId = CommonConstants.INVALID_VALUE): Promise { Log.showDebug(TAG, 'getAllFormInfos start'); - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); if (cardId != CommonConstants.INVALID_VALUE) { predicates.equalTo('card_id', cardId); } @@ -237,7 +242,7 @@ export class RdbStoreManager { Log.showDebug(TAG, 'updateFormInfoById start'); let result = false; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); predicates.equalTo('card_id', cardItemInfo.cardId); const updateBucket = { 'card_name': cardItemInfo.cardName, @@ -275,7 +280,7 @@ export class RdbStoreManager { Log.showDebug(TAG, 'deleteFormInfoById start'); let result = false; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); predicates.equalTo('card_id', cardId); const changeRows = await this.mRdbStore.delete(predicates); if (changeRows == 1) { @@ -291,7 +296,7 @@ export class RdbStoreManager { Log.showDebug(TAG, 'deleteFormInfoByBundle start'); let result = false; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); predicates.equalTo('bundle_name', bundleName); const changeRows = await this.mRdbStore.delete(predicates); if (changeRows == 1) { @@ -315,7 +320,7 @@ export class RdbStoreManager { let result = false; try { // get deviceType - let deviceType = AppStorage.get('deviceType'); + let deviceType = deviceInfo.deviceType; // init default settings config if (CheckEmptyUtils.isEmpty(key) || CheckEmptyUtils.isEmpty(value)) { @@ -332,7 +337,7 @@ export class RdbStoreManager { } else { // update settings by key and value let sql = `UPDATE ${RdbStoreConfig.Settings.TABLE_NAME} SET ${key} = '${value}' WHERE id = 1`; - await this.mRdbStore.executeSql(sql) + await this.mRdbStore.executeSql(sql); } } catch (e) { Log.showError(TAG, 'updateSettings error:' + JSON.stringify(e)); @@ -410,7 +415,7 @@ export class RdbStoreManager { async querySmartDock(): Promise { const resultList: DockItemInfo[] = []; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.SmartDock.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.SmartDock.TABLE_NAME); let resultSet = await this.mRdbStore.query(predicates, []); let isLast = resultSet.goToFirstRow(); while (isLast) { @@ -503,7 +508,7 @@ export class RdbStoreManager { async queryDesktopApplication(): Promise { const resultList: AppItemInfo[] = []; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.DesktopApplicationInfo.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.DesktopApplicationInfo.TABLE_NAME); let resultSet = await this.mRdbStore.query(predicates, []); let isLast = resultSet.goToFirstRow(); while (isLast) { @@ -595,6 +600,7 @@ export class RdbStoreManager { } Log.showDebug(TAG, `element prev: ${JSON.stringify(element)}`); let ret: number = await this.mRdbStore.insert(RdbStoreConfig.GridLayoutInfo.TABLE_NAME, item); + Log.showDebug(TAG, `element ret: ${JSON.stringify(ret)}`); if (ret > 0) { await this.insertLayoutInfo(element.layoutInfo, ret); } @@ -649,7 +655,7 @@ export class RdbStoreManager { async queryGridLayoutInfo(): Promise { const resultList: GridLayoutItemInfo[] = []; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.GridLayoutInfo.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.GridLayoutInfo.TABLE_NAME); predicates.equalTo(GridLayoutInfoColumns.CONTAINER, -100); let resultSet = await this.mRdbStore.query(predicates, []); let isLast = resultSet.goToFirstRow(); @@ -664,7 +670,7 @@ export class RdbStoreManager { resultList.push(builder.buildGridLayoutItem()); isLast = resultSet.goToNextRow(); } - resultSet.close() + resultSet.close(); resultSet = null; } catch (e) { Log.showError(TAG, 'queryGridLayoutInfo error:' + JSON.stringify(e)); @@ -675,7 +681,7 @@ export class RdbStoreManager { private async queryLayoutInfo(container: number): Promise { const resultList: AppItemInfo[] = []; try { - let layoutPredicates = new dataRdb.RdbPredicates(RdbStoreConfig.GridLayoutInfo.TABLE_NAME); + let layoutPredicates = new relationalStore.RdbPredicates(RdbStoreConfig.GridLayoutInfo.TABLE_NAME); layoutPredicates.equalTo("container", container); let columns = [GridLayoutInfoColumns.APP_NAME, GridLayoutInfoColumns.IS_SYSTEM_APP, diff --git a/common/src/main/ets/default/manager/SettingsDataManager.ts b/common/src/main/ets/default/manager/SettingsDataManager.ts index 2d1c91dea316648b7af2f2661fc65439d2a681fa..1c0339b78df0d660e362b8f94c2773262d9a090e 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 feeb442c13cb21f3652547acd000852e1717672e..6a0e1cf9f288728e91a95710d1f4d74ec06458b8 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(() => { @@ -258,11 +253,16 @@ class WindowManager { } minimizeAllApps(): void { - display.getDefaultDisplay().then(dis => { + try { + let dis: display.Display = display.getDefaultDisplaySync(); Window.minimizeAll(dis.id).then(() => { Log.showDebug(TAG, 'Launcher minimizeAll'); }); - }); + } catch (err) { + let errCode = (err as BusinessError).code; + let errMsg = (err as BusinessError).message; + Log.showError(TAG, `minimizeAllApps errCode: ${errCode}, errMsg: ${errMsg}`); + } this.destroyWindow(this.FORM_MANAGER_WINDOW_NAME); this.destroyWindow(this.FORM_SERVICE_WINDOW_NAME); } @@ -297,7 +297,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 +346,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 +374,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 +389,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 2179be33bb76e25caec0335d4097a19561e4f943..e32b13862d00cfa27f4437938411d9f1e3836d48 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/common/src/main/ets/default/uicomponents/AppIcon.ets b/common/src/main/ets/default/uicomponents/AppIcon.ets index 2d1e00e4de5fb71ad9eb86d659c5562295d36ded..6884f14c1a12e703d72c9a403f53a99c4f640f9e 100644 --- a/common/src/main/ets/default/uicomponents/AppIcon.ets +++ b/common/src/main/ets/default/uicomponents/AppIcon.ets @@ -17,11 +17,13 @@ import { Log } from '../utils/Log'; import { BadgeManager } from '../manager/BadgeManager'; import { StyleConstants } from '../constants/StyleConstants'; import { ResourceManager } from '../manager/ResourceManager'; +import { LauncherDragItemInfo } from '../bean/LauncherDragItemInfo'; const TAG = 'AppIcon'; @Component export struct AppIcon { + @StorageLink('dragItemInfo') @Watch('updateIconScale') mDragItemInfo: LauncherDragItemInfo = new LauncherDragItemInfo(); iconSize: number = 0; iconId: number = 0; bundleName: string = ''; @@ -35,6 +37,15 @@ export struct AppIcon { private mBadgeManager = BadgeManager.getInstance(); private mDefaultAppIcon: ResourceStr = ''; + /** + * 拖动图标到无效区域,松手后图标缩放恢复原有尺寸 + */ + updateIconScale() { + if (!this.mDragItemInfo.isDragging) { + this.iconScale = 1; + } + } + aboutToAppear(): void { this.mResourceManager = ResourceManager.getInstance(); this.mBadgeManager = BadgeManager.getInstance(); diff --git a/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts b/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts index 44cf0fb6eb64ea7e58beeea8c42877964df33b6a..b1cf3ad2ed5057536dc345401e7b1534aa04c008 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 7fa7fc074a9a02bcfca4218a65a6ebb121331579..918252ff665d0d32248b1a0390afa34aaee7880a 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 8de43499498c9ce1dbd337cfa1148bfd4491a709..8c175bf9e3bd27ada65bdb4930eb85ed893b6242 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/GestureNavigationExecutors.ts b/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationExecutors.ts index ffdbd647085b60c098180665244289f2d8414acc..42a6508588231d7f827d93e080e3c2ca39350241 100644 --- a/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationExecutors.ts +++ b/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationExecutors.ts @@ -199,7 +199,7 @@ export default class GestureNavigationExecutors { private recentEventCall() { Log.showInfo(TAG, 'recentEventCall recentEvent start'); - globalThis.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); } private isRecentsViewShowOfDistanceLimit(eventY: number) { diff --git a/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts b/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts index af0146d135f517579e9425a074ab33352acfd8ef..2f42caf6cc74cb2033e938136787f564454e2295 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/common/components/GridSwiper.ets b/feature/pagedesktop/src/main/ets/default/common/components/GridSwiper.ets index 0845d60267d9440c51cabbd5915eb24fecd06c1e..864c58fda4849aed98b1a1e53b15ef489f0a3de2 100644 --- a/feature/pagedesktop/src/main/ets/default/common/components/GridSwiper.ets +++ b/feature/pagedesktop/src/main/ets/default/common/components/GridSwiper.ets @@ -140,7 +140,7 @@ export default struct GridSwiper { .gesture( LongPressGesture({ repeat: false }) .onAction((event: GestureEvent) => { - this.dialogController?.open() + this.dialogController?.open(); }) ) .bindContextMenu(this.MenuBuilder, ResponseType.RightClick) diff --git a/feature/pagedesktop/src/main/ets/default/common/components/SwiperPage.ets b/feature/pagedesktop/src/main/ets/default/common/components/SwiperPage.ets index 3531c093074395004aeffb709ae84327d870d1fa..c5129f062bee8d55e6da373f6ab71f3174d1f419 100644 --- a/feature/pagedesktop/src/main/ets/default/common/components/SwiperPage.ets +++ b/feature/pagedesktop/src/main/ets/default/common/components/SwiperPage.ets @@ -220,13 +220,10 @@ export default struct SwiperPage { left: this.mMargin }) .onMouse((event: MouseEvent) => { - if (event.button == MouseButton.Right) { + if (event.button === MouseButton.Right || event.button === MouseButton.Left) { AppStorage.setOrCreate('selectDesktopAppItem', ''); } }) - .onClick((event: ClickEvent) => { - AppStorage.setOrCreate('selectDesktopAppItem', '') - }) .onDragEnter((event: DragEvent, extraParams: string) => { Log.showInfo(TAG, `onDragEnter extraParams: ${extraParams}, event: [${event.getWindowX()}, ${event.getWindowY()}]`); }) diff --git a/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets b/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets index 33b9c31df2d9d6c47801c230527d45d06d07ea36..58dcab551c26b9b981f22adb660a93eda3cf9d0c 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/pagedesktop/src/main/ets/default/viewmodel/PageDesktopViewModel.ts b/feature/pagedesktop/src/main/ets/default/viewmodel/PageDesktopViewModel.ts index a8296fe00aff755fc4ab36c41427dc7c08b7982d..0f635490f083d0c970a07a96e7b217bc9dd3aa13 100644 --- a/feature/pagedesktop/src/main/ets/default/viewmodel/PageDesktopViewModel.ts +++ b/feature/pagedesktop/src/main/ets/default/viewmodel/PageDesktopViewModel.ts @@ -67,7 +67,7 @@ export class PageDesktopViewModel extends BaseViewModel { private desktopSwiperController: SwiperController; async showFormManager(params) { - globalThis.createWindowWithName(windowManager.FORM_MANAGER_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.FORM_MANAGER_WINDOW_NAME, windowManager.RECENT_RANK); } setSwiperController(swiperController: SwiperController): void { @@ -1045,7 +1045,7 @@ export class PageDesktopViewModel extends BaseViewModel { let menuInfoList = new Array(); const shortcutInfo: any = this.mAppModel.getShortcutInfo(appInfo.bundleName); if (shortcutInfo) { - let menu = null; + let menu: MenuInfo | null = null; shortcutInfo.forEach((value) => { menu = new MenuInfo(); menu.menuType = CommonConstants.MENU_TYPE_DYNAMIC; @@ -1110,7 +1110,7 @@ export class PageDesktopViewModel extends BaseViewModel { formCenterMenu.onMenuClick = (): void => { Log.showInfo(TAG, 'Launcher click menu into form center view.'); if (!this.isPad) { - globalThis.createWindowWithName(windowManager.FORM_SERVICE_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.FORM_SERVICE_WINDOW_NAME, windowManager.RECENT_RANK); } }; menuInfoList.push(formCenterMenu); @@ -1204,7 +1204,7 @@ export class PageDesktopViewModel extends BaseViewModel { formCenterMenu.onMenuClick = (): void => { Log.showInfo(TAG, 'Launcher click menu into form center view.'); if (!this.isPad) { - globalThis.createWindowWithName(windowManager.FORM_SERVICE_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.FORM_SERVICE_WINDOW_NAME, windowManager.RECENT_RANK); } }; menuInfoList.push(formCenterMenu); diff --git a/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets b/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets index dfad85baa1ab7a78555b1e8bfc8e9a8c380e6153..30eedf103ec15eb2d442c9145b637ed9f5aefcf7 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 eb32aa0102b060c82077d8a87037cef5f972eab8..5306b2944c382482b4b3115390eaf9763a49e63c 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 3706116846420998f3e56653bd7b6ea48b7f847c..d328b565ca43fb19d0c08079635925b65dc5c446 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 e7aa2d7157bdcf485937992baf28d78e6ab09173..513df6bc13e19e0b9ffc6afdb13cef7e0aaa5a49 100644 --- a/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets +++ b/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets @@ -188,6 +188,8 @@ export default struct RecentLayout { }) }, (item: DockItemInfo) => JSON.stringify(item)) } + .enableScrollInteraction(false) + .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 b3ecf48c30773c55c34a324ebe3965b1b584d5fb..237bb5247698c57a57093cffa1c9ecb6518a2e91 100644 --- a/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets +++ b/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets @@ -94,12 +94,13 @@ export default struct ResidentLayout { } }, (item: DockItemInfo) => JSON.stringify(item)) } + .enableScrollInteraction(false) + .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 8bc8ecfd6b5eddfb30c156e61954c9b359a0f70e..34a8ea907c20f781a500df1a01dc9cca2bb7179e 100644 --- a/feature/smartdock/src/main/ets/default/layout/SmartDock.ets +++ b/feature/smartdock/src/main/ets/default/layout/SmartDock.ets @@ -39,7 +39,7 @@ interface DockRecentPopup { @Component export struct SmartDock { popup: DockRecentPopup = { show: false, showItem: '', popup: null }; - showAppCenter: Function = () => {}; + showAppCenter: () => void = () => {}; @StorageLink('showDock') showDock: boolean = false; @StorageLink('recentList') recentList: Array = []; @StorageLink('missionInfoList') missionInfoList: Array = []; @@ -97,7 +97,7 @@ export struct SmartDock { this.mSmartDockViewModel?.deleteDockItem({ bundleName: undefined, keyName: this.mSelectedItem?.keyName - }, this.mSelectedDockType); + } as DockItemInfo, this.mSelectedDockType); } else { this.mSmartDockViewModel?.uninstallApp(this.mSelectedItem?.bundleName, this.mSelectedItem?.isUninstallAble); } @@ -105,8 +105,8 @@ export struct SmartDock { } showDialog = () => { - this.mSelectedItem = this.mSmartDockViewModel?.getSelectedItem(); - this.mSelectedDockType = this.mSmartDockViewModel?.getSelectedDockType(); + this.mSelectedItem = this.mSmartDockViewModel?.getSelectedItem() as DockItemInfo|null; + this.mSelectedDockType = this.mSmartDockViewModel?.getSelectedDockType() as number; this.mDialogController?.open(); } @@ -186,6 +186,8 @@ export struct SmartDock { }) } } + .enableScrollInteraction(false) + .scrollBar(BarState.Off) .hitTestBehavior(this.desktopEventResponse ? HitTestMode.Default : HitTestMode.Block) .alignListItem(ListItemAlign.Center) .height(SmartDockConstants.PERCENTAGE_100) diff --git a/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts b/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts index 68bfc6c74b47edf8df661b82e49bfa801e3339e1..762d5359a38385706dcf18ff6a347b90a344d612 100644 --- a/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts +++ b/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts @@ -36,6 +36,7 @@ import { SmartDockStyleConfig } from '../config/SmartDockStyleConfig'; import { SmartDockLayoutConfig } from '../config/SmartDockLayoutConfig'; import SmartDockConstants from '../common/constants/SmartDockConstants'; import { RecentMissionInfo } from '@ohos/common'; +import launcherBundleManager from '@ohos.bundle.launcherBundleManager'; const TAG = 'SmartDockModel'; const KEY_NAME = 'name'; @@ -197,7 +198,7 @@ export default class SmartDockModel { * @param dockItem * @param dockType */ - deleteDockItem(dockItem: {bundleName: string | undefined, keyName: string | undefined}, dockType: number): boolean { + deleteDockItem(dockItem: DockItemInfo, dockType: number): boolean { if (SmartDockConstants.RESIDENT_DOCK_TYPE === dockType) { return this.deleteResistDockItem(dockItem); } @@ -221,7 +222,7 @@ export default class SmartDockModel { if (this.checkDockNum(dockItemCount)) { return false; } - const flag = this.idDuplicate(this.mResidentList, appInfo); + const flag = this.idDuplicate(this.mResidentList, appInfo as AppItemInfo); if (flag) { const dockItemInfo = new DockItemInfo(); dockItemInfo.itemType = CommonConstants.TYPE_APP; @@ -521,7 +522,7 @@ export default class SmartDockModel { * get ShortcutInfo by bundleName * @param bundleName */ - getShortcutInfo(bundleName: string): any { + getShortcutInfo(bundleName: string): launcherBundleManager.ShortcutInfo[] | undefined { return this.mAppModel.getShortcutInfo(bundleName); } diff --git a/feature/smartdock/src/main/ets/default/viewmodel/SmartDockViewModel.ts b/feature/smartdock/src/main/ets/default/viewmodel/SmartDockViewModel.ts index 7e4d6c6c83ec23c799dc6c338aaa8f687651ce0f..bd3b33d44421a90cc85a070a143d530b3c58316e 100644 --- a/feature/smartdock/src/main/ets/default/viewmodel/SmartDockViewModel.ts +++ b/feature/smartdock/src/main/ets/default/viewmodel/SmartDockViewModel.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { Log } from '@ohos/common'; +import { LauncherDragItemInfo, Log, RecentBundleMissionInfo, ResourceManager } from '@ohos/common'; import { Trace } from '@ohos/common'; import { CheckEmptyUtils } from '@ohos/common'; import { MenuInfo } from '@ohos/common'; @@ -34,6 +34,10 @@ import { SmartDockLayoutConfig } from '../config/SmartDockLayoutConfig'; const TAG = 'SmartDockViewModel'; +class StartAppItemInfo extends LauncherDragItemInfo { + icon?: ResourceStr; +} + /** * SmartDock Viewmodel */ @@ -43,7 +47,7 @@ export default class SmartDockViewModel extends BaseViewModel { private readonly mSmartDockDragHandler: SmartDockDragHandler; private readonly mSmartDockStartAppHandler: SmartDockStartAppHandler; private readonly mSmartDockModel: SmartDockModel; - private mSelectedItem: DockItemInfo; + private mSelectedItem: DockItemInfo | null = null; private mSelectedDockType = 0; private mDevice = CommonConstants.DEFAULT_DEVICE_TYPE; @@ -76,7 +80,7 @@ export default class SmartDockViewModel extends BaseViewModel { * @param item * @param callback */ - residentOnClick(event, item, callback?) { + residentOnClick(event: ClickEvent | null, item: DockItemInfo, callback?: () => void) { // AppCenter entry AppStorage.setOrCreate('startAppTypeFromPageDesktop', CommonConstants.OVERLAY_TYPE_APP_RESIDENTIAL); if (item.abilityName == CommonConstants.APPCENTER_ABILITY && callback != null) { @@ -84,13 +88,13 @@ export default class SmartDockViewModel extends BaseViewModel { return; } if (item.abilityName == CommonConstants.RECENT_ABILITY) { - globalThis.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); Trace.start(Trace.CORE_METHOD_START_RECENTS); return; } // app entry Trace.start(Trace.CORE_METHOD_START_APP_ANIMATION); - this.setStartAppInfo(item); + this.setStartAppInfo(item as StartAppItemInfo); launcherAbilityManager.startLauncherAbility(item.abilityName, item.bundleName, item.moduleName); } @@ -99,9 +103,9 @@ export default class SmartDockViewModel extends BaseViewModel { * @param event * @param item */ - public recentOnClick(event, item, callback?) { + public recentOnClick(event: ClickEvent | null, item: DockItemInfo, callback?: () => void) { AppStorage.setOrCreate('startAppTypeFromPageDesktop', CommonConstants.OVERLAY_TYPE_APP_RECENT); - let missionInfoList = []; + let missionInfoList: RecentBundleMissionInfo[] = []; missionInfoList = AppStorage.get('missionInfoList'); Log.showDebug(TAG, `recentOnClick missionInfoList.length: ${missionInfoList.length}`); if (!CheckEmptyUtils.isEmptyArr(missionInfoList)) { @@ -117,7 +121,7 @@ export default class SmartDockViewModel extends BaseViewModel { amsMissionManager.moveMissionToFront(missionId).then(() => {}, () => {}); // set start app info Trace.start(Trace.CORE_METHOD_START_APP_ANIMATION); - this.setStartAppInfo(item); + this.setStartAppInfo(item as StartAppItemInfo); } break; } @@ -136,14 +140,16 @@ export default class SmartDockViewModel extends BaseViewModel { * update drag effective area when dockList changed */ async updateDockParams() { - const screenWidth: number = AppStorage.get('screenWidth'); - const screenHeight: number = AppStorage.get('screenHeight'); - const sysUIBottomHeight: number = AppStorage.get('sysUIBottomHeight'); - const dockHeight: number = AppStorage.get('dockHeight'); + const screenWidth: number = AppStorage.get('screenWidth') as number; + const screenHeight: number = AppStorage.get('screenHeight') as number; + const sysUIBottomHeight: number = AppStorage.get('sysUIBottomHeight') as number; + const dockHeight: number = AppStorage.get('dockHeight') as number; let mResidentWidth: number = this.getListWidth(AppStorage.get('residentList')); - if (AppStorage.get("deviceType") === CommonConstants.DEFAULT_DEVICE_TYPE) { + if ((AppStorage.get('deviceType') as string) === CommonConstants.DEFAULT_DEVICE_TYPE) { const maxDockNum = this.getStyleConfig().mMaxDockNum; - mResidentWidth = this.mSmartDockStyleConfig.mDockPadding * 2 + maxDockNum * (this.mSmartDockStyleConfig.mListItemWidth) + (maxDockNum - 1) * (this.mSmartDockStyleConfig.mListItemGap); + mResidentWidth = this.mSmartDockStyleConfig.mDockPadding * 2 + + maxDockNum * (this.mSmartDockStyleConfig.mListItemWidth) + + (maxDockNum - 1) * (this.mSmartDockStyleConfig.mListItemGap); } AppStorage.setOrCreate('residentWidth', mResidentWidth); AppStorage.setOrCreate("dockPadding", this.getDockPadding(mResidentWidth)); @@ -152,7 +158,7 @@ export default class SmartDockViewModel extends BaseViewModel { if (typeof (this.mSmartDockDragHandler) != 'undefined') { let left = mResidentWidth === 0 ? 0 : (screenWidth - mResidentWidth - (mRecentWidth === 0 ? 0 : (this.mSmartDockStyleConfig.mDockGap + mRecentWidth))) / 2; let right = mResidentWidth === 0 ? screenWidth : (screenWidth - mResidentWidth - (mRecentWidth === 0 ? 0 : (this.mSmartDockStyleConfig.mDockGap + mRecentWidth))) / 2 + mResidentWidth; - if (AppStorage.get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE) { + if ((AppStorage.get('deviceType') as string) == CommonConstants.DEFAULT_DEVICE_TYPE) { left = (screenWidth - mResidentWidth) / 2; right = screenWidth - left; } @@ -181,11 +187,11 @@ export default class SmartDockViewModel extends BaseViewModel { * @param dockType * @param callback */ - buildMenuInfoList(appInfo, dockType, showAppcenter, callback?) { + buildMenuInfoList(appInfo: DockItemInfo, dockType: number, showAppcenter: () => void, callback?: () => void) { const menuInfoList = new Array(); const shortcutInfo = this.mSmartDockModel.getShortcutInfo(appInfo.bundleName); if (shortcutInfo) { - let menu = null; + let menu: MenuInfo | null = null; shortcutInfo.forEach((value) => { menu = new MenuInfo(); menu.menuType = CommonConstants.MENU_TYPE_DYNAMIC; @@ -197,7 +203,8 @@ export default class SmartDockViewModel extends BaseViewModel { menu.moduleName = value.moduleName; menu.onMenuClick = () => { Trace.start(Trace.CORE_METHOD_START_APP_ANIMATION); - launcherAbilityManager.startLauncherAbility(value.wants[0].targetClass, value.wants[0].targetBundle, value.wants[0].targetModule); + launcherAbilityManager.startLauncherAbility(value.wants[0].targetAbility, + value.wants[0].targetBundle, value.wants[0].targetModule); }; value.bundleName == appInfo.bundleName && value.moduleName == appInfo.moduleName && menuInfoList.push(menu); }); @@ -213,7 +220,7 @@ export default class SmartDockViewModel extends BaseViewModel { menuInfoList.push(open); if (appInfo.itemType != CommonConstants.TYPE_FUNCTION) { - this.mDevice = AppStorage.get('deviceType'); + this.mDevice = AppStorage.get('deviceType') as string; if (this.mDevice === CommonConstants.PAD_DEVICE_TYPE && dockType === SmartDockConstants.RESIDENT_DOCK_TYPE) { const addToWorkSpaceMenu = new MenuInfo(); addToWorkSpaceMenu.menuType = CommonConstants.MENU_TYPE_FIXED; @@ -250,16 +257,16 @@ export default class SmartDockViewModel extends BaseViewModel { return menuInfoList; } - deleteDockItem(dockItem: {bundleName: string | undefined, keyName: string | undefined}, dockType: number) { + deleteDockItem(dockItem: DockItemInfo, dockType: number) { this.mSmartDockModel.deleteDockItem(dockItem, dockType); } - getSelectedItem(): any { + getSelectedItem(): DockItemInfo | null { Log.showDebug(TAG, `getSelectedItem: ${JSON.stringify(this.mSelectedItem)}`); return this.mSelectedItem; } - getSelectedDockType(): any { + getSelectedDockType(): number { Log.showDebug(TAG, `getSelectedDockType: ${JSON.stringify(this.mSelectedDockType)}`); return this.mSelectedDockType; } @@ -268,7 +275,7 @@ export default class SmartDockViewModel extends BaseViewModel { * calcaulate dock list width after list change * @param itemList */ - private getListWidth(itemList: []): number { + private getListWidth(itemList: RecentBundleMissionInfo[]): number { let width = 0; if (typeof itemList === 'undefined' || itemList == null || itemList.length === 0) { return width; @@ -300,12 +307,12 @@ export default class SmartDockViewModel extends BaseViewModel { /** * set start app info */ - private setStartAppInfo(item) { + private setStartAppInfo(item: StartAppItemInfo) { if (CheckEmptyUtils.isEmpty(item)) { Log.showError(TAG, `setStartAppInfo with item`) return; } - item.icon = globalThis.ResourceManager.getCachedAppIcon(item.appIconId, item.bundleName, item.moduleName) + item.icon = ResourceManager.getInstance().getCachedAppIcon(item.appIconId, item.bundleName, item.moduleName) AppStorage.setOrCreate('startAppItemInfo', item); this.mSmartDockStartAppHandler.setAppIconSize(this.mSmartDockStyleConfig.mIconSize); this.mSmartDockStartAppHandler.setAppIconInfo(); diff --git a/product/pad/src/main/ets/MainAbility/MainAbility.ts b/product/pad/src/main/ets/MainAbility/MainAbility.ts index 351e8b821305a95bbd8994734d1e13c250c0b102..7c18983d62eb7424d659f27c562521813bda1bb2 100644 --- a/product/pad/src/main/ets/MainAbility/MainAbility.ts +++ b/product/pad/src/main/ets/MainAbility/MainAbility.ts @@ -110,7 +110,7 @@ export default class MainAbility extends ServiceExtension { isFinalKeyDown: true }, () => { Log.showInfo(TAG, 'RECENT inputConsumer recentEvent start'); - globalThis.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); }); } diff --git a/product/pad/src/main/ets/pages/EntryView.ets b/product/pad/src/main/ets/pages/EntryView.ets index efac2707795393b8a60647e7b477d4bfe0a843a5..76ce788ab31a674b25588e0f2790e5e10426103a 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/MainAbility/MainAbility.ts b/product/phone/src/main/ets/MainAbility/MainAbility.ts index b7fa99cad08bc64f35da23ad84ecde0ad68c3993..77d5fc833102d4a1169c8ce4c239189c5cdc5e29 100644 --- a/product/phone/src/main/ets/MainAbility/MainAbility.ts +++ b/product/phone/src/main/ets/MainAbility/MainAbility.ts @@ -110,7 +110,7 @@ export default class MainAbility extends ServiceExtension { isFinalKeyDown: true }, () => { Log.showInfo(TAG, 'RECENT inputConsumer recentEvent start'); - globalThis.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); }); } diff --git a/product/phone/src/main/ets/pages/EntryView.ets b/product/phone/src/main/ets/pages/EntryView.ets index 3508e586b98b2726c95c4c21969f1af3c26e724a..f264d0e274b8d4a9d1caa416563e22de5dea313d 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) {