From 8343cf3b427726b248c3086a3e93df7fe60a872b Mon Sep 17 00:00:00 2001 From: r00498791 Date: Mon, 11 Apr 2022 12:54:14 +0800 Subject: [PATCH] update systemui code from std Signed-off-by: r00498791 --- ...CheckEmptyUtils.ets => CheckEmptyUtils.ts} | 2 +- common/src/main/ets/default/Constants.ts | 47 ++ common/src/main/ets/default/Decorators.ts | 45 ++ common/src/main/ets/default/InitSystemUi.ts | 29 + .../src/main/ets/default/{Log.ets => Log.ts} | 27 +- .../ets/default/MultimodalInputManager.ts | 96 +++ .../{ReadConfigUtil.ets => ReadConfigUtil.ts} | 4 +- .../{ResourceUtil.ets => ResourceUtil.ts} | 7 +- .../src/main/ets/default/ScreenLockManager.ts | 63 ++ common/src/main/ets/default/SettingsUtil.ts | 65 +++ .../main/ets/default/SingleInstanceHelper.ts | 36 ++ .../main/ets/default/StyleConfiguration.ts | 32 + common/src/main/ets/default/StyleManager.ts | 41 ++ .../main/ets/default/SwitchUserManager.ets | 101 ---- .../src/main/ets/default/SwitchUserManager.ts | 111 ++++ common/src/main/ets/default/TimeManager.ts | 120 ++++ .../src/main/ets/default/TintStateManager.ts | 101 ++++ common/src/main/ets/default/WindowManager.ets | 99 ---- common/src/main/ets/default/WindowManager.ts | 119 ++++ .../default/abilitymanager/abilityManager.ts | 69 +++ .../default/abilitymanager/bundleManager.ets | 38 -- .../default/abilitymanager/bundleManager.ts | 38 ++ ...tyManager.ets => featureAbilityManager.ts} | 4 +- ...tionManager.ets => notificationManager.ts} | 4 +- .../default/commonEvent/CommonEventManager.ts | 97 +++ common/src/main/ets/default/event/EventBus.ts | 76 +++ .../main/ets/default/event/EventManager.ts | 94 +++ .../src/main/ets/default/event/EventUtil.ts | 81 +++ ...htConfigUtils.ets => HeightConfigUtils.ts} | 4 +- .../PluginDataSourceAdapter.ets | 114 ---- .../PluginDataSourceAdapter.ts | 130 +++++ .../PluginDataSourceManager.ets | 62 -- .../PluginDataSourceManager.ts | 118 ++++ .../common/BundleParseUtil.ts | 116 ++++ .../ets/plugindatasource/common/Constants.ets | 58 -- .../ets/plugindatasource/common/Constants.ts | 76 +++ .../sourceloader/BaseMetaSourceLoader.ets | 216 ------- .../sourceloader/DataAbilitySourceLoader.ets | 31 - .../sourceloader/DataAbilitySourceLoader.ts | 33 ++ .../sourceloader/MetaSourceLoader.ts | 96 +++ ...SourceLoader.ets => PluginSourceLoader.ts} | 33 +- .../sourceloader/SourceLoader.ets | 42 -- .../sourceloader/SourceLoader.ts | 53 ++ .../sourceloader/SourceLoaderFactory.ets | 47 -- .../sourceloader/SourceLoaderFactory.ts | 49 ++ .../main/ets/template/SimpleToggleBase.ets | 141 +++-- .../src/main/ets/template/UniformConfig.ets | 51 -- .../ets/template/common/StyleConfiguration.ts | 87 +++ .../src/main/ets/template/iconComponent.ets | 38 +- .../src/main/ets/template/iconTitleBase.ets | 94 +-- doc/Instructions.md | 2 +- entry/{ => pc}/.gitignore | 0 entry/{ => pc}/build.gradle | 0 entry/{ => pc}/package.json | 0 entry/pc/src/main/config.json | 91 +++ entry/pc/src/main/ets/AbilityStage.ts | 24 + .../ServiceExtAbility/ServiceExtAbility.ts | 64 ++ .../src/main/ets/ServiceExtAbility}/app.ets | 0 .../ets/ServiceExtAbility}/pages/index.ets | 2 +- .../main/resources/base/element/string.json | 16 + .../src/main/resources/base/media/icon.png | Bin entry/phone/.gitignore | 1 + .../phone}/build.gradle | 2 - .../phone}/package.json | 0 entry/phone/src/main/config.json | 88 +++ entry/phone/src/main/ets/AbilityStage.ts | 24 + .../ServiceExtAbility/ServiceExtAbility.ts | 58 ++ .../src/main/ets/ServiceExtAbility/app.ets | 20 +- .../ets/ServiceExtAbility/pages/index.ets | 27 + .../main/resources/base/element/string.json | 16 + .../src/main/resources/base/media/icon.png | Bin infra/config_exts.gradle | 2 +- .../{ => default}/navigationBar/.gitignore | 0 product/default/navigationBar/build.gradle | 16 + .../navigationBar}/package.json | 0 .../navigationBar/src/main/config.json | 18 +- .../src/main/ets/AbilityStage.ts | 23 + .../ServiceExtAbility/ServiceExtAbility.ts | 73 +++ .../src/main/ets/ServiceExtAbility}/app.ets | 21 +- .../common/NavBarConfiguration.ts} | 24 +- .../common/StyleConfiguration.ts | 33 ++ .../ServiceExtAbility/common/StyleManager.ts | 77 +++ .../ServiceExtAbility/common/constants.ts} | 13 +- .../common/utils/configReader.ts} | 6 +- .../ets/ServiceExtAbility}/i18n/en-US.json | 0 .../ets/ServiceExtAbility}/i18n/zh-CN.json | 0 .../ets/ServiceExtAbility}/pages/index.ets | 32 +- .../ServiceExtAbility}/pages/keyButton.ets | 28 +- .../ServiceExtAbility}/pages/oneLayout.ets | 10 +- .../ServiceExtAbility}/pages/threeLayout.ets | 22 +- .../viewmodel/NavigationBarViewModel.ts | 158 +++++ .../main/resources/base/element/color.json | 4 - .../main/resources/base/element/float.json | 24 + .../main/resources/base/element/string.json | 8 +- .../resources/base/media/ic_systemui_back.svg | 10 + .../resources/base/media/ic_systemui_home.svg | 10 + .../base/media/ic_systemui_recent.svg | 10 + .../src/main/resources/base/media/icon.png | Bin .../main/resources/en_US}/element/string.json | 8 +- .../rawfile/navigationBarLayoutConfig.json | 0 .../main/resources/zh_CN}/element/string.json | 8 +- .../notificationmanagement/.gitignore | 0 .../notificationmanagement/build.gradle | 5 +- .../notificationmanagement}/package.json | 0 .../src/main/config.json | 18 +- .../src/main/ets/AbilityStage.ts | 23 + .../src/main/ets/MainAbility/MainAbility.ts | 48 ++ .../src/main/ets/MainAbility}/app.ets | 0 .../main/ets/MainAbility/common/constants.ts} | 5 +- .../ets/MainAbility/pages/batchSetEnable.ets | 101 ++++ .../main/ets/MainAbility/pages/noDisturb.ets | 551 ++++++++++++++++++ .../ets/MainAbility/pages/noDisturbPre.ets | 102 ++++ .../pages/notificationManagenment.ets | 205 +++++++ .../main/ets/MainAbility/pages/setEnable.ets | 124 ++++ .../ets/MainAbility/pages/slotSetting.ets | 233 ++++++++ .../ets/MainAbility/vm/noDisturbViewModel.ts | 141 +++++ .../vm/notificationManagenmentViewModel.ts | 62 ++ .../main/resources/base/element/string.json | 25 + .../src/main/resources/base/media/ic_back.svg | 0 .../base/media/ic_settings_arrow.svg | 0 .../src/main/resources/base/media/icon.png | Bin .../main/resources/en_US/element/string.json | 24 + .../main/resources/zh_CN/element/string.json | 24 + product/default/volumepanel/.gitignore | 1 + product/default/volumepanel/build.gradle | 16 + product/default/volumepanel/package.json | 1 + .../default/volumepanel/src/main/config.json | 56 ++ .../volumepanel/src/main/ets/AbilityStage.ts | 23 + .../ServiceExtAbility/ServiceExtAbility.ts | 55 ++ .../src/main/ets/ServiceExtAbility/app.ets | 49 ++ .../common/StyleConfiguration.ts | 27 + .../ServiceExtAbility/common/StyleManager.ts | 73 +++ .../ets/ServiceExtAbility/common/constants.ts | 18 + .../ets/ServiceExtAbility/pages/index.ets | 50 ++ .../main/resources/base}/element/string.json | 2 +- .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../main/resources/en_US}/element/string.json | 2 +- .../main/resources/zh_CN}/element/string.json | 3 +- .../src/main/ets/default/app.ets | 34 -- .../main/resources/base/element/float.json | 32 - .../base/media/ic_navigation_back.png | Bin 409 -> 0 bytes .../base/media/ic_navigation_home.png | Bin 420 -> 0 bytes .../base/media/ic_navigation_recent.png | Bin 221 -> 0 bytes .../main/ets/default/pages/batchSetEnable.ets | 81 --- .../src/main/ets/default/pages/noDisturb.ets | 250 -------- .../default/pages/notificationManagenment.ets | 97 --- .../src/main/ets/default/pages/setEnable.ets | 89 --- .../ets/default/vm/noDisturbViewModel.ets | 70 --- .../main/resources/base/element/color.json | 32 - .../main/resources/base/element/float.json | 80 --- .../{statusbar => pc/controlpanel}/.gitignore | 0 product/pc/controlpanel/build.gradle | 22 + product/pc/controlpanel/package.json | 1 + product/pc/controlpanel/src/main/config.json | 67 +++ .../controlpanel/src/main/ets/AbilityStage.ts | 23 + .../ServiceExtAbility/ServiceExtAbility.ts | 55 ++ .../src/main/ets/ServiceExtAbility/app.ets | 23 + .../pages/common/ControlCenterConfig.ts | 48 ++ .../pages/common/StyleConfiguration.ts | 29 + .../pages/common/StyleManager.ts | 270 +++++++++ .../pages/common/constants.ts | 18 + .../ets/ServiceExtAbility/pages/control.ets | 45 ++ .../ets/ServiceExtAbility/pages/index.ets | 232 ++++++++ .../workers/PluginDataSourceWorker.js | 52 +- .../main/resources/base/element/color.json | 12 + .../main/resources/base/element/float.json | 8 + .../main/resources/base/element/string.json | 0 .../base/media/ic_controlcenter_oh.png | Bin 0 -> 1161 bytes .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../main/resources/en_US/element/string.json | 12 + .../main/resources/zh_CN/element/string.json | 12 + product/pc/notificationpanel/.gitignore | 1 + product/pc/notificationpanel/build.gradle | 15 + product/pc/notificationpanel/package.json | 1 + .../pc/notificationpanel/src/main/config.json | 70 +++ .../src/main/ets/AbilityStage.ts | 23 + .../ServiceExtAbility/ServiceExtAbility.ts | 71 +++ .../src/main/ets/ServiceExtAbility/app.ets | 23 + .../pages/bannerNotification.ets | 133 +++++ .../pages/common/StyleConfiguration.ts | 29 + .../pages/common/StyleManager.ts | 52 ++ .../pages/common/constants.ts | 21 + .../ets/ServiceExtAbility/pages/index.ets | 168 ++++++ .../ServiceExtAbility/pages/notification.ets | 103 ++++ .../main/resources/base/element/color.json | 24 + .../main/resources/base/element/float.json | 120 ++++ .../main/resources/base/element/string.json | 24 +- .../main/resources/base/media/delete_all.png | Bin .../base/media/ic_message_filled.png | Bin 0 -> 1375 bytes .../resources/base/media/ic_public_delete.svg | 13 + .../base/media/ic_public_settings.svg | 13 + .../main/resources/base/media/ic_settings.png | Bin .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../main/resources/en_US/element/string.json | 24 +- .../main/resources/zh_CN/element/string.json | 24 +- product/pc/statusbar/.gitignore | 1 + product/{ => pc}/statusbar/build.gradle | 6 +- product/pc/statusbar/package.json | 1 + product/pc/statusbar/src/main/config.json | 51 ++ .../pc/statusbar/src/main/ets/AbilityStage.ts | 23 + .../ServiceExtAbility/ServiceExtAbility.ts | 62 ++ .../src/main/ets/ServiceExtAbility/app.ets | 38 ++ .../pages/common/StatusbarConfig.ts | 92 +++ .../pages/common/StyleConfiguration.ts | 27 + .../pages/common/StyleManager.ts | 174 ++++++ .../pages/common/constants.ts | 17 + .../ets/ServiceExtAbility/pages/index.ets | 80 +++ .../workers/PluginDataSourceWorker.js | 86 +++ .../main/resources/base/element/color.json | 12 + .../main/resources/base/element/string.json | 28 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../main/resources/en_US/element/string.json | 28 + .../main/resources/zh_CN/element/string.json | 28 + product/phone/dropdownpanel/.gitignore | 1 + product/phone/dropdownpanel/build.gradle | 28 + product/phone/dropdownpanel/package.json | 1 + .../phone/dropdownpanel}/src/main/config.json | 38 +- .../src/main/ets/AbilityStage.ts | 23 + .../ServiceExtAbility/ServiceExtAbility.ts | 64 ++ .../src/main/ets/ServiceExtAbility/app.ets | 20 +- .../pages/bannerNotification.ets | 132 +++++ .../pages/common/ControlCenterConfig.ts | 48 ++ .../pages/common/StyleConfiguration.ts | 73 +++ .../pages/common/StyleManager.ts | 267 +++++++++ .../pages/common/constants.ts} | 13 +- .../pages/common/navigationEvent.ts} | 4 +- .../ets/ServiceExtAbility/pages/control.ets | 124 ++++ .../ets/ServiceExtAbility/pages/index.ets | 323 ++++++++++ .../ServiceExtAbility/pages/notification.ets | 232 ++++++++ .../workers/PluginDataSourceWorker.js | 86 +++ .../main/resources/base/element/color.json | 23 + .../main/resources/base/element/float.json | 60 ++ .../main/resources/base/element/string.json | 52 ++ .../main/resources/base/media/delete_all.png | Bin 0 -> 4061 bytes .../main/resources/base/media/ic_settings.png | Bin 0 -> 1060 bytes .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../main/resources/en_US/element/string.json | 52 ++ .../main/resources/zh_CN/element/string.json | 52 ++ product/phone/statusbar/.gitignore | 1 + product/phone/statusbar/build.gradle | 24 + product/phone/statusbar/package.json | 1 + .../statusbar/src/main/config.json | 17 +- .../statusbar/src/main/ets/AbilityStage.ts | 23 + .../ServiceExtAbility/ServiceExtAbility.ts | 50 ++ .../src/main/ets/ServiceExtAbility/app.ets | 38 ++ .../pages/common/StatusbarConfig.ts | 109 ++++ .../pages/common/StyleConfiguration.ts | 27 + .../pages/common/StyleManager.ts | 51 ++ .../pages/common/constants.ts | 20 + .../ets/ServiceExtAbility/pages/index.ets | 153 +++++ .../workers/PluginDataSourceWorker.js | 86 +++ .../main/resources/base/element/color.json | 12 + .../main/resources/base/element/string.json | 28 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../main/resources/en_US/element/string.json | 28 + .../main/resources/zh_CN/element/string.json | 28 + .../src/main/ets/default/pages/control.ets | 101 ---- .../src/main/ets/default/pages/index.ets | 160 ----- .../main/ets/default/pages/notification.ets | 227 -------- .../main/resources/base/element/color.json | 36 -- .../main/resources/base/element/float.json | 68 --- .../main/resources/base/media/airplane.svg | 14 - .../main/resources/base/media/airplane_d.svg | 14 - .../src/main/resources/base/media/wifi.svg | 17 - .../src/main/resources/base/media/wifi_d.svg | 17 - .../rawfile/controlcentercomponentConfig.json | 24 - .../rawfile/statusbarcomponentConfig.json | 46 -- settings.gradle | 17 +- signature/systemui.p7b | Bin 3421 -> 3436 bytes 269 files changed, 10268 insertions(+), 2760 deletions(-) rename common/src/main/ets/default/{CheckEmptyUtils.ets => CheckEmptyUtils.ts} (96%) create mode 100644 common/src/main/ets/default/Constants.ts create mode 100644 common/src/main/ets/default/Decorators.ts create mode 100644 common/src/main/ets/default/InitSystemUi.ts rename common/src/main/ets/default/{Log.ets => Log.ts} (62%) create mode 100644 common/src/main/ets/default/MultimodalInputManager.ts rename common/src/main/ets/default/{ReadConfigUtil.ets => ReadConfigUtil.ts} (95%) rename common/src/main/ets/default/{ResourceUtil.ets => ResourceUtil.ts} (86%) create mode 100644 common/src/main/ets/default/ScreenLockManager.ts create mode 100644 common/src/main/ets/default/SettingsUtil.ts create mode 100644 common/src/main/ets/default/SingleInstanceHelper.ts create mode 100644 common/src/main/ets/default/StyleConfiguration.ts create mode 100644 common/src/main/ets/default/StyleManager.ts delete mode 100644 common/src/main/ets/default/SwitchUserManager.ets create mode 100644 common/src/main/ets/default/SwitchUserManager.ts create mode 100644 common/src/main/ets/default/TimeManager.ts create mode 100644 common/src/main/ets/default/TintStateManager.ts delete mode 100644 common/src/main/ets/default/WindowManager.ets create mode 100644 common/src/main/ets/default/WindowManager.ts create mode 100644 common/src/main/ets/default/abilitymanager/abilityManager.ts delete mode 100644 common/src/main/ets/default/abilitymanager/bundleManager.ets create mode 100644 common/src/main/ets/default/abilitymanager/bundleManager.ts rename common/src/main/ets/default/abilitymanager/{featureAbilityManager.ets => featureAbilityManager.ts} (96%) rename common/src/main/ets/default/abilitymanager/{notificationManager.ets => notificationManager.ts} (95%) create mode 100644 common/src/main/ets/default/commonEvent/CommonEventManager.ts create mode 100644 common/src/main/ets/default/event/EventBus.ts create mode 100644 common/src/main/ets/default/event/EventManager.ts create mode 100644 common/src/main/ets/default/event/EventUtil.ts rename common/src/main/ets/default/heightcofigUtils/{HeightConfigUtils.ets => HeightConfigUtils.ts} (92%) delete mode 100644 common/src/main/ets/plugindatasource/PluginDataSourceAdapter.ets create mode 100644 common/src/main/ets/plugindatasource/PluginDataSourceAdapter.ts delete mode 100644 common/src/main/ets/plugindatasource/PluginDataSourceManager.ets create mode 100644 common/src/main/ets/plugindatasource/PluginDataSourceManager.ts create mode 100644 common/src/main/ets/plugindatasource/common/BundleParseUtil.ts delete mode 100644 common/src/main/ets/plugindatasource/common/Constants.ets create mode 100644 common/src/main/ets/plugindatasource/common/Constants.ts delete mode 100644 common/src/main/ets/plugindatasource/sourceloader/BaseMetaSourceLoader.ets delete mode 100644 common/src/main/ets/plugindatasource/sourceloader/DataAbilitySourceLoader.ets create mode 100644 common/src/main/ets/plugindatasource/sourceloader/DataAbilitySourceLoader.ts create mode 100644 common/src/main/ets/plugindatasource/sourceloader/MetaSourceLoader.ts rename common/src/main/ets/plugindatasource/sourceloader/{PluginSourceLoader.ets => PluginSourceLoader.ts} (52%) delete mode 100644 common/src/main/ets/plugindatasource/sourceloader/SourceLoader.ets create mode 100644 common/src/main/ets/plugindatasource/sourceloader/SourceLoader.ts delete mode 100644 common/src/main/ets/plugindatasource/sourceloader/SourceLoaderFactory.ets create mode 100644 common/src/main/ets/plugindatasource/sourceloader/SourceLoaderFactory.ts delete mode 100644 common/src/main/ets/template/UniformConfig.ets create mode 100644 common/src/main/ets/template/common/StyleConfiguration.ts rename entry/{ => pc}/.gitignore (100%) mode change 100755 => 100644 rename entry/{ => pc}/build.gradle (100%) mode change 100755 => 100644 rename entry/{ => pc}/package.json (100%) mode change 100755 => 100644 create mode 100644 entry/pc/src/main/config.json create mode 100644 entry/pc/src/main/ets/AbilityStage.ts create mode 100644 entry/pc/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts rename entry/{src/main/ets/default => pc/src/main/ets/ServiceExtAbility}/app.ets (100%) rename entry/{src/main/ets/default => pc/src/main/ets/ServiceExtAbility}/pages/index.ets (93%) create mode 100644 entry/pc/src/main/resources/base/element/string.json rename entry/{ => pc}/src/main/resources/base/media/icon.png (100%) create mode 100644 entry/phone/.gitignore rename {product/navigationBar => entry/phone}/build.gradle (82%) rename {product/navigationBar => entry/phone}/package.json (100%) create mode 100644 entry/phone/src/main/config.json create mode 100644 entry/phone/src/main/ets/AbilityStage.ts create mode 100644 entry/phone/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts rename common/src/main/ets/default/DateAndTimeUtil.ets => entry/phone/src/main/ets/ServiceExtAbility/app.ets (67%) create mode 100644 entry/phone/src/main/ets/ServiceExtAbility/pages/index.ets create mode 100644 entry/phone/src/main/resources/base/element/string.json rename {product/navigationBar => entry/phone}/src/main/resources/base/media/icon.png (100%) rename product/{ => default}/navigationBar/.gitignore (100%) create mode 100644 product/default/navigationBar/build.gradle rename product/{notificationmanagement => default/navigationBar}/package.json (100%) rename product/{ => default}/navigationBar/src/main/config.json (75%) create mode 100644 product/default/navigationBar/src/main/ets/AbilityStage.ts create mode 100644 product/default/navigationBar/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts rename product/{statusbar/src/main/ets/default => default/navigationBar/src/main/ets/ServiceExtAbility}/app.ets (52%) rename product/{navigationBar/src/main/ets/default/common/NavBarConfiguration.ets => default/navigationBar/src/main/ets/ServiceExtAbility/common/NavBarConfiguration.ts} (88%) create mode 100644 product/default/navigationBar/src/main/ets/ServiceExtAbility/common/StyleConfiguration.ts create mode 100644 product/default/navigationBar/src/main/ets/ServiceExtAbility/common/StyleManager.ts rename product/{navigationBar/src/main/ets/default/common/constants.ets => default/navigationBar/src/main/ets/ServiceExtAbility/common/constants.ts} (81%) rename product/{navigationBar/src/main/ets/default/common/utils/configReader.ets => default/navigationBar/src/main/ets/ServiceExtAbility/common/utils/configReader.ts} (89%) rename product/{navigationBar/src/main/ets/default => default/navigationBar/src/main/ets/ServiceExtAbility}/i18n/en-US.json (100%) rename product/{navigationBar/src/main/ets/default => default/navigationBar/src/main/ets/ServiceExtAbility}/i18n/zh-CN.json (100%) rename product/{navigationBar/src/main/ets/default => default/navigationBar/src/main/ets/ServiceExtAbility}/pages/index.ets (50%) rename product/{navigationBar/src/main/ets/default => default/navigationBar/src/main/ets/ServiceExtAbility}/pages/keyButton.ets (61%) rename product/{navigationBar/src/main/ets/default => default/navigationBar/src/main/ets/ServiceExtAbility}/pages/oneLayout.ets (83%) rename product/{navigationBar/src/main/ets/default => default/navigationBar/src/main/ets/ServiceExtAbility}/pages/threeLayout.ets (76%) create mode 100644 product/default/navigationBar/src/main/ets/ServiceExtAbility/viewmodel/NavigationBarViewModel.ts rename product/{ => default}/navigationBar/src/main/resources/base/element/color.json (70%) create mode 100644 product/default/navigationBar/src/main/resources/base/element/float.json rename product/{ => default}/navigationBar/src/main/resources/base/element/string.json (89%) create mode 100644 product/default/navigationBar/src/main/resources/base/media/ic_systemui_back.svg create mode 100644 product/default/navigationBar/src/main/resources/base/media/ic_systemui_home.svg create mode 100644 product/default/navigationBar/src/main/resources/base/media/ic_systemui_recent.svg rename product/{notificationmanagement => default/navigationBar}/src/main/resources/base/media/icon.png (100%) rename product/{navigationBar/src/main/resources/zh_CN => default/navigationBar/src/main/resources/en_US}/element/string.json (89%) rename product/{ => default}/navigationBar/src/main/resources/rawfile/navigationBarLayoutConfig.json (100%) rename product/{navigationBar/src/main/resources/en_US => default/navigationBar/src/main/resources/zh_CN}/element/string.json (89%) rename product/{ => default}/notificationmanagement/.gitignore (100%) rename product/{ => default}/notificationmanagement/build.gradle (73%) rename product/{statusbar => default/notificationmanagement}/package.json (100%) rename product/{ => default}/notificationmanagement/src/main/config.json (80%) create mode 100644 product/default/notificationmanagement/src/main/ets/AbilityStage.ts create mode 100644 product/default/notificationmanagement/src/main/ets/MainAbility/MainAbility.ts rename product/{notificationmanagement/src/main/ets/default => default/notificationmanagement/src/main/ets/MainAbility}/app.ets (100%) rename product/{notificationmanagement/src/main/ets/default/common/constants.ets => default/notificationmanagement/src/main/ets/MainAbility/common/constants.ts} (89%) create mode 100644 product/default/notificationmanagement/src/main/ets/MainAbility/pages/batchSetEnable.ets create mode 100644 product/default/notificationmanagement/src/main/ets/MainAbility/pages/noDisturb.ets create mode 100644 product/default/notificationmanagement/src/main/ets/MainAbility/pages/noDisturbPre.ets create mode 100644 product/default/notificationmanagement/src/main/ets/MainAbility/pages/notificationManagenment.ets create mode 100644 product/default/notificationmanagement/src/main/ets/MainAbility/pages/setEnable.ets create mode 100644 product/default/notificationmanagement/src/main/ets/MainAbility/pages/slotSetting.ets create mode 100644 product/default/notificationmanagement/src/main/ets/MainAbility/vm/noDisturbViewModel.ts create mode 100644 product/default/notificationmanagement/src/main/ets/MainAbility/vm/notificationManagenmentViewModel.ts create mode 100644 product/default/notificationmanagement/src/main/resources/base/element/string.json rename product/{ => default}/notificationmanagement/src/main/resources/base/media/ic_back.svg (100%) rename product/{ => default}/notificationmanagement/src/main/resources/base/media/ic_settings_arrow.svg (100%) rename product/{statusbar => default/notificationmanagement}/src/main/resources/base/media/icon.png (100%) create mode 100644 product/default/notificationmanagement/src/main/resources/en_US/element/string.json create mode 100644 product/default/notificationmanagement/src/main/resources/zh_CN/element/string.json create mode 100644 product/default/volumepanel/.gitignore create mode 100644 product/default/volumepanel/build.gradle create mode 100644 product/default/volumepanel/package.json create mode 100644 product/default/volumepanel/src/main/config.json create mode 100644 product/default/volumepanel/src/main/ets/AbilityStage.ts create mode 100644 product/default/volumepanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts create mode 100644 product/default/volumepanel/src/main/ets/ServiceExtAbility/app.ets create mode 100644 product/default/volumepanel/src/main/ets/ServiceExtAbility/common/StyleConfiguration.ts create mode 100644 product/default/volumepanel/src/main/ets/ServiceExtAbility/common/StyleManager.ts create mode 100644 product/default/volumepanel/src/main/ets/ServiceExtAbility/common/constants.ts create mode 100644 product/default/volumepanel/src/main/ets/ServiceExtAbility/pages/index.ets rename product/{notificationmanagement/src/main/resources/en_US => default/volumepanel/src/main/resources/base}/element/string.json (80%) create mode 100644 product/default/volumepanel/src/main/resources/base/media/icon.png rename product/{notificationmanagement/src/main/resources/zh_CN => default/volumepanel/src/main/resources/en_US}/element/string.json (80%) rename product/{notificationmanagement/src/main/resources/base => default/volumepanel/src/main/resources/zh_CN}/element/string.json (79%) delete mode 100644 product/navigationBar/src/main/ets/default/app.ets delete mode 100644 product/navigationBar/src/main/resources/base/element/float.json delete mode 100644 product/navigationBar/src/main/resources/base/media/ic_navigation_back.png delete mode 100644 product/navigationBar/src/main/resources/base/media/ic_navigation_home.png delete mode 100644 product/navigationBar/src/main/resources/base/media/ic_navigation_recent.png delete mode 100644 product/notificationmanagement/src/main/ets/default/pages/batchSetEnable.ets delete mode 100644 product/notificationmanagement/src/main/ets/default/pages/noDisturb.ets delete mode 100644 product/notificationmanagement/src/main/ets/default/pages/notificationManagenment.ets delete mode 100644 product/notificationmanagement/src/main/ets/default/pages/setEnable.ets delete mode 100644 product/notificationmanagement/src/main/ets/default/vm/noDisturbViewModel.ets delete mode 100644 product/notificationmanagement/src/main/resources/base/element/color.json delete mode 100644 product/notificationmanagement/src/main/resources/base/element/float.json rename product/{statusbar => pc/controlpanel}/.gitignore (100%) create mode 100644 product/pc/controlpanel/build.gradle create mode 100644 product/pc/controlpanel/package.json create mode 100644 product/pc/controlpanel/src/main/config.json create mode 100644 product/pc/controlpanel/src/main/ets/AbilityStage.ts create mode 100644 product/pc/controlpanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts create mode 100644 product/pc/controlpanel/src/main/ets/ServiceExtAbility/app.ets create mode 100644 product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/ControlCenterConfig.ts create mode 100644 product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts create mode 100644 product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts create mode 100644 product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts create mode 100644 product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/control.ets create mode 100644 product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/index.ets rename product/{statusbar/src/main/ets/default => pc/controlpanel/src/main/ets/ServiceExtAbility}/workers/PluginDataSourceWorker.js (59%) create mode 100644 product/pc/controlpanel/src/main/resources/base/element/color.json create mode 100644 product/pc/controlpanel/src/main/resources/base/element/float.json rename {entry => product/pc/controlpanel}/src/main/resources/base/element/string.json (100%) create mode 100644 product/pc/controlpanel/src/main/resources/base/media/ic_controlcenter_oh.png create mode 100644 product/pc/controlpanel/src/main/resources/base/media/icon.png create mode 100644 product/pc/controlpanel/src/main/resources/en_US/element/string.json create mode 100644 product/pc/controlpanel/src/main/resources/zh_CN/element/string.json create mode 100644 product/pc/notificationpanel/.gitignore create mode 100644 product/pc/notificationpanel/build.gradle create mode 100644 product/pc/notificationpanel/package.json create mode 100644 product/pc/notificationpanel/src/main/config.json create mode 100644 product/pc/notificationpanel/src/main/ets/AbilityStage.ts create mode 100644 product/pc/notificationpanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts create mode 100644 product/pc/notificationpanel/src/main/ets/ServiceExtAbility/app.ets create mode 100644 product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/bannerNotification.ets create mode 100644 product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts create mode 100644 product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts create mode 100644 product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts create mode 100644 product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/index.ets create mode 100644 product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/notification.ets create mode 100644 product/pc/notificationpanel/src/main/resources/base/element/color.json create mode 100644 product/pc/notificationpanel/src/main/resources/base/element/float.json rename product/{statusbar => pc/notificationpanel}/src/main/resources/base/element/string.json (73%) rename product/{statusbar => pc/notificationpanel}/src/main/resources/base/media/delete_all.png (100%) create mode 100644 product/pc/notificationpanel/src/main/resources/base/media/ic_message_filled.png create mode 100644 product/pc/notificationpanel/src/main/resources/base/media/ic_public_delete.svg create mode 100644 product/pc/notificationpanel/src/main/resources/base/media/ic_public_settings.svg rename product/{statusbar => pc/notificationpanel}/src/main/resources/base/media/ic_settings.png (100%) create mode 100644 product/pc/notificationpanel/src/main/resources/base/media/icon.png rename product/{statusbar => pc/notificationpanel}/src/main/resources/en_US/element/string.json (73%) rename product/{statusbar => pc/notificationpanel}/src/main/resources/zh_CN/element/string.json (73%) create mode 100644 product/pc/statusbar/.gitignore rename product/{ => pc}/statusbar/build.gradle (93%) create mode 100644 product/pc/statusbar/package.json create mode 100644 product/pc/statusbar/src/main/config.json create mode 100644 product/pc/statusbar/src/main/ets/AbilityStage.ts create mode 100644 product/pc/statusbar/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts create mode 100644 product/pc/statusbar/src/main/ets/ServiceExtAbility/app.ets create mode 100644 product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StatusbarConfig.ts create mode 100644 product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts create mode 100644 product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts create mode 100644 product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/constants.ts create mode 100644 product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/index.ets create mode 100644 product/pc/statusbar/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js create mode 100644 product/pc/statusbar/src/main/resources/base/element/color.json create mode 100644 product/pc/statusbar/src/main/resources/base/element/string.json create mode 100644 product/pc/statusbar/src/main/resources/base/media/icon.png create mode 100644 product/pc/statusbar/src/main/resources/en_US/element/string.json create mode 100644 product/pc/statusbar/src/main/resources/zh_CN/element/string.json create mode 100644 product/phone/dropdownpanel/.gitignore create mode 100644 product/phone/dropdownpanel/build.gradle create mode 100644 product/phone/dropdownpanel/package.json rename {entry => product/phone/dropdownpanel}/src/main/config.json (55%) mode change 100755 => 100644 create mode 100644 product/phone/dropdownpanel/src/main/ets/AbilityStage.ts create mode 100644 product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts rename common/src/main/ets/plugindatasource/sourceloader/MetaSourceLoader.ets => product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/app.ets (58%) create mode 100644 product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/bannerNotification.ets create mode 100644 product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/ControlCenterConfig.ts create mode 100644 product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts create mode 100644 product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts rename product/{statusbar/src/main/ets/default/pages/common/constants.ets => phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts} (72%) rename product/{statusbar/src/main/ets/default/pages/common/navigationEvent.ets => phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/navigationEvent.ts} (94%) create mode 100644 product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/control.ets create mode 100644 product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/index.ets create mode 100644 product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/notification.ets create mode 100644 product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js create mode 100644 product/phone/dropdownpanel/src/main/resources/base/element/color.json create mode 100644 product/phone/dropdownpanel/src/main/resources/base/element/float.json create mode 100644 product/phone/dropdownpanel/src/main/resources/base/element/string.json create mode 100644 product/phone/dropdownpanel/src/main/resources/base/media/delete_all.png create mode 100644 product/phone/dropdownpanel/src/main/resources/base/media/ic_settings.png create mode 100644 product/phone/dropdownpanel/src/main/resources/base/media/icon.png create mode 100644 product/phone/dropdownpanel/src/main/resources/en_US/element/string.json create mode 100644 product/phone/dropdownpanel/src/main/resources/zh_CN/element/string.json create mode 100644 product/phone/statusbar/.gitignore create mode 100644 product/phone/statusbar/build.gradle create mode 100644 product/phone/statusbar/package.json rename product/{ => phone}/statusbar/src/main/config.json (76%) create mode 100644 product/phone/statusbar/src/main/ets/AbilityStage.ts create mode 100644 product/phone/statusbar/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts create mode 100644 product/phone/statusbar/src/main/ets/ServiceExtAbility/app.ets create mode 100644 product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StatusbarConfig.ts create mode 100644 product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts create mode 100644 product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts create mode 100644 product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/constants.ts create mode 100644 product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/index.ets create mode 100644 product/phone/statusbar/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js create mode 100644 product/phone/statusbar/src/main/resources/base/element/color.json create mode 100644 product/phone/statusbar/src/main/resources/base/element/string.json create mode 100644 product/phone/statusbar/src/main/resources/base/media/icon.png create mode 100644 product/phone/statusbar/src/main/resources/en_US/element/string.json create mode 100644 product/phone/statusbar/src/main/resources/zh_CN/element/string.json delete mode 100644 product/statusbar/src/main/ets/default/pages/control.ets delete mode 100644 product/statusbar/src/main/ets/default/pages/index.ets delete mode 100644 product/statusbar/src/main/ets/default/pages/notification.ets delete mode 100644 product/statusbar/src/main/resources/base/element/color.json delete mode 100644 product/statusbar/src/main/resources/base/element/float.json delete mode 100644 product/statusbar/src/main/resources/base/media/airplane.svg delete mode 100644 product/statusbar/src/main/resources/base/media/airplane_d.svg delete mode 100644 product/statusbar/src/main/resources/base/media/wifi.svg delete mode 100644 product/statusbar/src/main/resources/base/media/wifi_d.svg delete mode 100644 product/statusbar/src/main/resources/rawfile/controlcentercomponentConfig.json delete mode 100644 product/statusbar/src/main/resources/rawfile/statusbarcomponentConfig.json diff --git a/common/src/main/ets/default/CheckEmptyUtils.ets b/common/src/main/ets/default/CheckEmptyUtils.ts similarity index 96% rename from common/src/main/ets/default/CheckEmptyUtils.ets rename to common/src/main/ets/default/CheckEmptyUtils.ts index fb5f3ff5..5061c49c 100644 --- a/common/src/main/ets/default/CheckEmptyUtils.ets +++ b/common/src/main/ets/default/CheckEmptyUtils.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/common/src/main/ets/default/Constants.ts b/common/src/main/ets/default/Constants.ts new file mode 100644 index 00000000..df5fbd9b --- /dev/null +++ b/common/src/main/ets/default/Constants.ts @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const WindowNameMap = { + 2112: 'navigation', + 2108: 'status', + 2111: 'volume' +}; + +export interface Rect { + left: number; + top: number; + width: number; + height: number; +}; + +export type WindowType = 'status' | 'navigation' | 'volume'; + +export default class Constants { + static URI_VAR: string = 'dataability:///com.ohos.settingsdata.DataAbility'; +} + +export enum FASlotName { + AUTO_ROTATE = "auto_rotate", + AIR_PLANE = "air_plane", + BATTERY = 'battery', + BLUETOOTH = 'bluetooth', + CAPSULE = 'capsule', + CLOCK = 'clock', + EMPTY = 'empty', + LOCATION = 'location', + NOTIFICATION = 'notification', + RING_MODE = 'ring_mode', + SIGNAL = 'signal', + WIFI = 'wifi', +} diff --git a/common/src/main/ets/default/Decorators.ts b/common/src/main/ets/default/Decorators.ts new file mode 100644 index 00000000..85cf5c58 --- /dev/null +++ b/common/src/main/ets/default/Decorators.ts @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from "./Log"; + +const TAG = "Decorators"; + +export function debounce(timeout: number) { + return function inner(target: any, propKey: string, descriptor: PropertyDescriptor) { + let curFunc: number = 0; + const original = descriptor.value; + descriptor.value = function (...args: string[]) { + Log.showInfo(TAG, `debounce invoke ${propKey} curFunc: ${curFunc}`); + curFunc && clearTimeout(curFunc); + curFunc = setTimeout(() => original.call(this, ...args), timeout); + }; + }; +} + +export function throttle(waitTime: number) { + return function inner(target: any, propKey: string, descriptor: PropertyDescriptor) { + let lastTime: number = 0; + const original = descriptor.value; + descriptor.value = function (...args: string[]) { + let curTime = Date.now(); + Log.showInfo(TAG, `throttle invoke ${propKey} timeInterval: ${curTime - lastTime}`); + if (curTime - lastTime >= waitTime) { + original.call(this, ...args); + lastTime = curTime; + } + }; + }; +} diff --git a/common/src/main/ets/default/InitSystemUi.ts b/common/src/main/ets/default/InitSystemUi.ts new file mode 100644 index 00000000..bf023152 --- /dev/null +++ b/common/src/main/ets/default/InitSystemUi.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import EventManager from "./event/EventManager"; +import Log from "./Log"; +import ScreenLockManager from "./ScreenLockManager"; +import ServiceExtensionContext from "application/ServiceExtensionContext"; +import TimeManager from "./TimeManager"; + +const TAG = "initSystemui"; + +export default function initSystemUi(context: ServiceExtensionContext) { + EventManager.setContext(context); + ScreenLockManager.init(); + TimeManager.init(context); + Log.showDebug(TAG, `init done, ctx: ${context}`); +} diff --git a/common/src/main/ets/default/Log.ets b/common/src/main/ets/default/Log.ts similarity index 62% rename from common/src/main/ets/default/Log.ets rename to common/src/main/ets/default/Log.ts index e41d7395..0a5170ae 100644 --- a/common/src/main/ets/default/Log.ets +++ b/common/src/main/ets/default/Log.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,20 +13,35 @@ * limitations under the License. */ -const TAG = 'SystemUI_Default'; +const TAG = "SystemUI_Default"; +const FILTER_KEYS = [ + new RegExp('hide', "gi") +] + +export function filterKey(target: any, propKey: string, descriptor: PropertyDescriptor) { + const original = descriptor.value; + descriptor.value = function (...args: string[]) { + let filterResult = args.map((str) => { + let tempStr = str + FILTER_KEYS.forEach((filterKey) => tempStr = tempStr.replace(filterKey, "**")) + return tempStr + }); + const result = original.call(this, ...filterResult); + return result; + }; +} /** * Basic log class */ export default class Log { - /** * print info level log * * @param {string} tag - Page or class tag * @param {string} log - Log needs to be printed */ - static showInfo(tag, log) { + static showInfo(tag: string, log: string) { console.info(`${TAG} tag: ${tag} --> ${log}`); } @@ -36,7 +51,7 @@ export default class Log { * @param {string} tag - Page or class tag * @param {string} log - Log needs to be printed */ - static showDebug(tag, log) { + static showDebug(tag: string, log: string) { console.debug(`${TAG} tag: ${tag} --> ${log}`); } @@ -46,7 +61,7 @@ export default class Log { * @param {string} tag - Page or class tag * @param {string} log - Log needs to be printed */ - static showError(tag, log) { + static showError(tag: string, log: string) { console.error(`${TAG} tag: ${tag} --> ${log}`); } } diff --git a/common/src/main/ets/default/MultimodalInputManager.ts b/common/src/main/ets/default/MultimodalInputManager.ts new file mode 100644 index 00000000..85d80349 --- /dev/null +++ b/common/src/main/ets/default/MultimodalInputManager.ts @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import inputConsumer from "@ohos.multimodalInput.inputConsumer"; +import Log from "./Log"; +import createOrGet from "./SingleInstanceHelper"; + +export type MultiCallback = (keyOptions: typeof inputConsumer.KeyOptions) => void; +export enum MultiKeyCode { + WIN = 2076, + N = 2030, + I = 2025, +} + +const TAG = "MultimodalInputManager"; + +class MultimodalInputManager { + //win + N + notificationKeyOptions: any = { + preKeys: [2076], + finalKey: 2030, + isFinalKeyDown: true, + finalKeyDownDuration: 0, + }; + //win + I + controlKeyOptions: any = { + preKeys: [2076], + finalKey: 2025, + isFinalKeyDown: true, + finalKeyDownDuration: 0, + }; + + subscribeCombinationKey(keys: MultiKeyCode[], cb: MultiCallback): () => void { + if (keys.length <= 1) { + Log.showError(TAG, `Invalid keys, can't subscribe.`); + return () => {}; + } + let keyOptions = { + preKeys: keys.slice(0, keys.length - 1), + finalKey: keys[keys.length - 1], + isFinalKeyDown: true, + finalKeyDownDuration: 0, + }; + inputConsumer.on("key", keyOptions, (err, options) => { + Log.showInfo(TAG, `on CombinationKey, options:${JSON.stringify(options)}, err: ${JSON.stringify(err)}`); + cb(options); + }); + Log.showInfo(TAG, `subscribe CombinationKey, keys:${JSON.stringify(keys)}`); + return () => { + inputConsumer.off("key", keyOptions, (err, data) => {}); + }; + } + + registerControlListener(callback) { + Log.showInfo(TAG, `registerListener control`); + inputConsumer.on("key", this.controlKeyOptions, (err, data) => { + Log.showInfo(TAG, `controlRegisterCallBack err: ${JSON.stringify(err)} data: ${JSON.stringify(data)}`); + callback.onControlShowOrHide(err, data); + }); + Log.showInfo(TAG, `registerListener end`); + } + + registerNotificationListener(callback) { + Log.showInfo(TAG, `registerListener notification`); + inputConsumer.on("key", this.notificationKeyOptions, (err, data) => { + Log.showInfo(TAG, `notificationRegisterCallBack err: ${JSON.stringify(err)} data: ${JSON.stringify(data)}`); + callback.onNotificationShowOrHide(err, data); + }); + Log.showInfo(TAG, `registerListener end`); + } + + unregisterListener() { + Log.showInfo(TAG, `unregisterListener start`); + inputConsumer.off("key", this.notificationKeyOptions, (err, data) => { + Log.showInfo(TAG, `notificationUnregisterCallBack err: ${JSON.stringify(err)} data: ${JSON.stringify(data)}`); + }); + inputConsumer.off("key", this.controlKeyOptions, (err, data) => { + Log.showInfo(TAG, `controlUnregisterCallBack err: ${JSON.stringify(err)} data: ${JSON.stringify(data)}`); + }); + Log.showInfo(TAG, `unregisterListener end`); + } +} +let sMultimodalInputManager = createOrGet(MultimodalInputManager, TAG); + +export default sMultimodalInputManager as MultimodalInputManager; diff --git a/common/src/main/ets/default/ReadConfigUtil.ets b/common/src/main/ets/default/ReadConfigUtil.ts similarity index 95% rename from common/src/main/ets/default/ReadConfigUtil.ets rename to common/src/main/ets/default/ReadConfigUtil.ts index 587704de..c7eb8b90 100644 --- a/common/src/main/ets/default/ReadConfigUtil.ets +++ b/common/src/main/ets/default/ReadConfigUtil.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,7 +13,7 @@ * limitations under the License. */ -import Log from './Log.ets'; +import Log from './Log'; import FileIo from '@ohos.fileio'; const DFAULT_SIZE = 4096; diff --git a/common/src/main/ets/default/ResourceUtil.ets b/common/src/main/ets/default/ResourceUtil.ts similarity index 86% rename from common/src/main/ets/default/ResourceUtil.ets rename to common/src/main/ets/default/ResourceUtil.ts index 7d741e81..b01b922a 100644 --- a/common/src/main/ets/default/ResourceUtil.ets +++ b/common/src/main/ets/default/ResourceUtil.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import ResMgr from '@ohos.resourceManager'; +import AbilityManager from './abilitymanager/abilityManager' /** * Resource util @@ -25,7 +25,8 @@ export class ResourceUtil { */ async initResourceManager(): Promise { if (!this.resMgr) { - this.resMgr = await ResMgr.getResourceManager('com.ohos.systemui'); + let context = AbilityManager.getContext(); + this.resMgr = await context.resourceManager; } return this.resMgr; } diff --git a/common/src/main/ets/default/ScreenLockManager.ts b/common/src/main/ets/default/ScreenLockManager.ts new file mode 100644 index 00000000..d38431d5 --- /dev/null +++ b/common/src/main/ets/default/ScreenLockManager.ts @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import commonEvent from "@ohos.commonEvent"; +import { CommonEventSubscriber } from "commonEvent/commonEventSubscriber"; +import createOrGet from "./SingleInstanceHelper"; +import EventManager from "./event/EventManager"; +import Log from "./Log"; +import { obtainLocalEvent } from "./event/EventUtil"; +import { debounce } from "./Decorators"; +export const SCREEN_CHANGE_EVENT = "screenChangeEvent"; + +const TAG = "ScreenLockManager"; +const SCREEN_COMMON_EVENT_INFO = { + events: [commonEvent.Support.COMMON_EVENT_SCREEN_OFF, commonEvent.Support.COMMON_EVENT_SCREEN_ON], +}; +const debounceTimeout = 500; + +class ScreenLockManager { + mSubscriber: CommonEventSubscriber | undefined; + + async init() { + this.mSubscriber = await commonEvent.createSubscriber(SCREEN_COMMON_EVENT_INFO); + commonEvent.subscribe(this.mSubscriber, (err, data) => { + if (err.code != 0) { + Log.showError(TAG, `Can't handle screen change, err: ${JSON.stringify(err)}`); + return; + } + Log.showDebug(TAG, `screenChange, err: ${JSON.stringify(err)} data: ${JSON.stringify(data)}`); + switch (data.event) { + case commonEvent.Support.COMMON_EVENT_SCREEN_OFF: + this.notifyScreenEvent(false); + break; + case commonEvent.Support.COMMON_EVENT_SCREEN_ON: + this.notifyScreenEvent(true); + break; + default: + Log.showError(TAG, `unknow event`); + } + }); + } + + @debounce(debounceTimeout) + notifyScreenEvent(isScreenOn: boolean) { + EventManager.publish(obtainLocalEvent(SCREEN_CHANGE_EVENT, isScreenOn)); + Log.showDebug(TAG, `publish ${SCREEN_CHANGE_EVENT} screenState: ${isScreenOn}`); + } +} + +let sScreenLockManager = createOrGet(ScreenLockManager, TAG); +export default sScreenLockManager as ScreenLockManager; \ No newline at end of file diff --git a/common/src/main/ets/default/SettingsUtil.ts b/common/src/main/ets/default/SettingsUtil.ts new file mode 100644 index 00000000..6c025e59 --- /dev/null +++ b/common/src/main/ets/default/SettingsUtil.ts @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import settings from "@ohos.settings"; +import {DataAbilityHelper} from "ability/dataAbilityHelper"; +import featureAbility from "@ohos.ability.featureAbility"; +import Log from "./Log"; +import Constants from "./Constants"; +import createOrGet from "./SingleInstanceHelper"; +import AbilityManager from "./abilitymanager/abilityManager"; + +const TAG = "SettingsUtil"; + +export class SettingsUtil { + helper: DataAbilityHelper; + + constructor() { + Log.showInfo(TAG, `constructor`); + try { + this.helper = featureAbility.acquireDataAbilityHelper(AbilityManager.getContext(), Constants.URI_VAR); + } catch (e) { + Log.showInfo(TAG, `constructor, acquire helper error: ${e.toString()}`); + } + } + + getValue(name: string, defValue?: string): string { + Log.showInfo(TAG, `getValue, name: ${name} defValue: ${defValue}`); + let value: string = null; + try { + value = settings.getValueSync(this.helper, name, defValue ? defValue : ""); + } catch (e) { + Log.showInfo(TAG, `getValue e: ${e.toString()}`); + } + Log.showInfo(TAG, `getValue, value: ${value}`); + return value; + } + + setValue(name: string, value: string): boolean { + Log.showInfo(TAG, `setValue, name: ${name} value: ${value}`); + let result = false; + try { + result = settings.setValueSync(this.helper, name, value); + } catch (e) { + Log.showInfo(TAG, `setValue e: ${e.toString()}`); + } + Log.showInfo(TAG, `setValue, result: ${result}`); + return result; + } +} + +let sSettingsUtil = createOrGet(SettingsUtil, TAG); + +export default sSettingsUtil as SettingsUtil; \ No newline at end of file diff --git a/common/src/main/ets/default/SingleInstanceHelper.ts b/common/src/main/ets/default/SingleInstanceHelper.ts new file mode 100644 index 00000000..b4ffcae7 --- /dev/null +++ b/common/src/main/ets/default/SingleInstanceHelper.ts @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from './Log'; +import audio from '@ohos.multimedia.audio'; + +const TAG = "SingleInstanceHelper"; +const AUDIO_MANAGER_KEY = 'MultiMediaAudioManager'; + +export default function createOrGet(objectClass: { new(): T }, storageKey: string): T { + if (!globalThis[storageKey]) { + globalThis[storageKey] = new objectClass(); + Log.showInfo(TAG, `Create key of ${storageKey}`); + } + return globalThis[storageKey]; +} + +export function getAudioManager() { + if (!globalThis[AUDIO_MANAGER_KEY]) { + globalThis[AUDIO_MANAGER_KEY] = audio.getAudioManager(); + Log.showInfo(TAG, `Create Audio Manager.`); + } + return globalThis[AUDIO_MANAGER_KEY]; +} diff --git a/common/src/main/ets/default/StyleConfiguration.ts b/common/src/main/ets/default/StyleConfiguration.ts new file mode 100644 index 00000000..1d8f3e26 --- /dev/null +++ b/common/src/main/ets/default/StyleConfiguration.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import StyleManager from './StyleManager'; + +const TAG = 'Common-StyleConfiguration'; + +export default class StyleConfiguration { + static getCommonStyle() { + const key: string = TAG + "-Common"; + return StyleManager.getStyle(key, () => { + return { + statusBarFontSize: '16fp', + statusBarIconWidth: '24vp', + statusBarIconHeight: '24vp', + statusBarMarginLeftRight: '5vp', + }; + }); + } +} \ No newline at end of file diff --git a/common/src/main/ets/default/StyleManager.ts b/common/src/main/ets/default/StyleManager.ts new file mode 100644 index 00000000..d9e49622 --- /dev/null +++ b/common/src/main/ets/default/StyleManager.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from './Log'; + +const TAG = 'Common-StyleManager'; + +export class StyleManager { + mAbilityPageName: string = ''; + + setAbilityPageName(name: string): void{ + Log.showInfo(TAG, `setAbilityPageName, name: ${name}`); + this.mAbilityPageName = name; + } + + getStyle(key: string, generateDefaultFunction: Function) { + let newKey = this.mAbilityPageName + '-' + key; + if (!AppStorage.Has(newKey)) { + let defaultStyle = generateDefaultFunction(); + AppStorage.SetOrCreate(newKey, defaultStyle); + Log.showInfo(TAG, `Create storageKey of ${newKey}`); + } + return AppStorage.Get(newKey); + } +} + +let styleManager = new StyleManager(); + +export default styleManager as StyleManager; \ No newline at end of file diff --git a/common/src/main/ets/default/SwitchUserManager.ets b/common/src/main/ets/default/SwitchUserManager.ets deleted file mode 100644 index d78cb2f1..00000000 --- a/common/src/main/ets/default/SwitchUserManager.ets +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import AccountManager from '@ohos.account.osAccount'; -import Log from './Log.ets'; - -const STORAGE_KEY = 'SwitchUserManager_AppStorage' -const TAG = 'SwitchUserManager' -const SUBSCRIBE_KEY = 'SystemUiAccount' -const USER_CHANGE_EVENT = 'activate' -const INVALID_USER_ID = -1; - -interface UserChangeListener { - userChange: Function -} - -export class UserInfo { - userId: number = INVALID_USER_ID; - userName: string = ''; - userIcon: string | Resource = ''; - [key: string]: any ; -} - -async function getCurrentAccountInfo() { - let currentAccountInfo = {}; - let accountInfos = await AccountManager.getAccountManager().queryAllCreatedOsAccounts(); - for (let accountInfo of accountInfos) { - Log.showInfo(TAG, `accountInfo: ${accountInfo.localId}, isActive: ${accountInfo.isActived}`); - if (accountInfo.isActived) { - return accountInfo; - } - } - return new UserInfo(); -} - -function parseAccountInfo(accountInfo): UserInfo { - return { - userId: accountInfo.localId, - userName: accountInfo.localName, - userIcon: accountInfo.photo - } -} - -export default class SwitchUserManager { - mUserInfo: UserInfo = new UserInfo(); - mListeners = new Set(); - - static getInstance(): SwitchUserManager { - if (!AppStorage.Has(STORAGE_KEY)) { - let mamanger = new SwitchUserManager(); - AppStorage.SetOrCreate(STORAGE_KEY, mamanger); - } - return AppStorage.Get(STORAGE_KEY); - } - - constructor() { - Log.showInfo(TAG, `SwitchUserManager constructor`); - AccountManager.getAccountManager().on(USER_CHANGE_EVENT, SUBSCRIBE_KEY, this.handleUserChange.bind(this)); - } - - public async getCurrentUserInfo(): Promise { - if (this.mUserInfo.userId == INVALID_USER_ID) { - let accountInfo = await getCurrentAccountInfo(); - this.mUserInfo = parseAccountInfo(accountInfo); - } - return this.mUserInfo; - } - - public registerListener(listener: UserChangeListener) { - this.mListeners.add(listener) - } - - public unregisterListener(listener: UserChangeListener) { - this.mListeners.delete(listener) - } - - handleUserChange(accountId) { - AccountManager.getAccountManager().queryOsAccountById(accountId).then((accountInfo) => { - Log.showInfo(TAG, `userChange, accountInfo: ${JSON.stringify(accountInfo)}`); - this.mUserInfo = parseAccountInfo(accountInfo) - this.notifyUserChange(); - }) - } - - notifyUserChange() { - this.mListeners.forEach((listener) => listener.userChange(this.mUserInfo)) - } -} \ No newline at end of file diff --git a/common/src/main/ets/default/SwitchUserManager.ts b/common/src/main/ets/default/SwitchUserManager.ts new file mode 100644 index 00000000..b352e6c9 --- /dev/null +++ b/common/src/main/ets/default/SwitchUserManager.ts @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AccountManager from "@ohos.account.osAccount"; +import Log from "./Log"; +import getSingleInstance from "./SingleInstanceHelper"; + +const TAG = "SwitchUserManager"; +const SUBSCRIBE_KEY = "SystemUiAccount"; +const USER_CHANGE_EVENT = "activate"; +const DELAY_TIME = 3 * 1000; +export const INVALID_USER_ID = -1; + +type AccountInfo = { + localId: number; + localName: string; + photo: string; +}; +export type UserChangeListener = { + userChange: (data: UserInfo) => void; +}; + +export class UserInfo { + userId: number = INVALID_USER_ID; + userName: string = ""; + userIcon: string | Resource = ""; + [key: string]: any; +} + +async function getCurrentAccountInfo(): Promise { + let accountInfos = await AccountManager.getAccountManager().queryAllCreatedOsAccounts(); + for (let accountInfo of accountInfos) { + Log.showInfo(TAG, `accountInfo: ${accountInfo.localId}, isActive: ${accountInfo.isActived}`); + if (accountInfo.isActived) { + return accountInfo; + } + } + return { localId: INVALID_USER_ID, localName: "", photo: "" }; +} + +function parseAccountInfo(accountInfo: AccountInfo): UserInfo { + return { + userId: accountInfo.localId, + userName: accountInfo.localName, + userIcon: accountInfo.photo, + }; +} + +export default class SwitchUserManager { + mUserInfo: UserInfo = new UserInfo(); + mListeners = new Set(); + mHasWait: boolean = false; + + static getInstance(): SwitchUserManager { + return getSingleInstance(SwitchUserManager, TAG); + } + + constructor() { + Log.showInfo(TAG, `SwitchUserManager constructor`); + AccountManager.getAccountManager().on(USER_CHANGE_EVENT, SUBSCRIBE_KEY, this.handleUserChange.bind(this)); + } + + public async getCurrentUserInfo(): Promise { + if (this.mUserInfo.userId == INVALID_USER_ID) { + this.mUserInfo = parseAccountInfo(await getCurrentAccountInfo()); + while (!this.mHasWait && this.mUserInfo.userId == INVALID_USER_ID) { + await new Promise((resolve) => setTimeout(resolve, DELAY_TIME)); + this.mUserInfo = parseAccountInfo(await getCurrentAccountInfo()); + } + this.mHasWait = true; + this.mUserInfo = parseAccountInfo(await getCurrentAccountInfo()); + } + Log.showInfo(TAG, `getCurrentUserInfo userId: ${this.mUserInfo.userId}`); + return this.mUserInfo; + } + + public registerListener(listener: UserChangeListener) { + this.mListeners.add(listener); + } + + public unregisterListener(listener: UserChangeListener) { + this.mListeners.delete(listener); + } + + handleUserChange(accountId: number): void { + AccountManager.getAccountManager() + .queryOsAccountById(accountId) + .then((accountInfo) => { + Log.showInfo(TAG, `userChange, accountInfo: ${JSON.stringify(accountInfo)}`); + this.mUserInfo = parseAccountInfo(accountInfo); + this.notifyUserChange(); + }) + .catch((err) => Log.showError(TAG, `Can't query account by ${accountId}, err: ${err}`)); + } + + notifyUserChange() { + this.mListeners.forEach((listener) => listener.userChange(this.mUserInfo)); + } +} diff --git a/common/src/main/ets/default/TimeManager.ts b/common/src/main/ets/default/TimeManager.ts new file mode 100644 index 00000000..7fbdf1f1 --- /dev/null +++ b/common/src/main/ets/default/TimeManager.ts @@ -0,0 +1,120 @@ +/** + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import settings from "@ohos.settings"; +import commonEvent from "@ohos.commonEvent"; +import featureAbility from "@ohos.ability.featureAbility"; +import { DataAbilityHelper } from "ability/dataAbilityHelper"; +import Log from "./Log"; +import EventManager from "./event/EventManager"; +import createOrGet from "./SingleInstanceHelper"; +import { obtainLocalEvent } from "./event/EventUtil"; +import { CommonEventManager, getCommonEventManager, POLICY } from "./commonEvent/CommonEventManager"; + +export const TIME_CHANGE_EVENT = "Time_Change_Event"; + +export type TimeEventArgs = { + date: Date; + timeFormat: boolean; +}; + +const TAG = "TimeManager"; +const URI_VAR = "dataability:///com.ohos.settingsdata.DataAbility"; +const TIME_FORMAT_KEY = "settings.time.format"; +const TIME_SUBSCRIBE_INFO = { + events: [ + commonEvent.Support.COMMON_EVENT_TIME_CHANGED, + commonEvent.Support.COMMON_EVENT_TIMEZONE_CHANGED, + commonEvent.Support.COMMON_EVENT_TIME_TICK, + ], +}; + +function fill(value: number) { + return (value > 9 ? "" : "0") + value; +} + +export function concatTime(h: number, m: number) { + return `${fill(h)}:${fill(m)}`; +} + +class TimeManager { + private mUse24hFormat: boolean = false; + private mSettingsHelper?: DataAbilityHelper; + private mManager?: CommonEventManager; + + public init(context: any) { + this.mManager = getCommonEventManager( + TAG, + TIME_SUBSCRIBE_INFO, + () => this.notifyTimeChange(), + (isSubscribe) => isSubscribe && this.notifyTimeChange() + ); + this.mManager.subscriberCommonEvent(); + this.mManager.applyPolicy([POLICY.SCREEN_POLICY]); + this.initTimeFormat(context); + } + + public release() { + this.mManager?.release(); + this.mManager = undefined; + this.mSettingsHelper?.off("dataChange", settings.getUriSync(TIME_FORMAT_KEY)); + } + + public formatTime(date: Date) { + return concatTime(date.getHours() % (this.mUse24hFormat ? 24 : 12), date.getMinutes()); + } + + private initTimeFormat(context: any) { + Log.showInfo(TAG, "initTimeFormat"); + this.mSettingsHelper = featureAbility.acquireDataAbilityHelper(context, URI_VAR); + + const handleTimeFormatChange = () => { + if (!this.mSettingsHelper) { + Log.showError(TAG, `Can't get dataAbility helper.`); + return; + } + let timeString = settings.getValueSync(this.mSettingsHelper, TIME_FORMAT_KEY, "24"); + Log.showDebug(TAG, `timeFormat change: ${timeString}`); + this.mUse24hFormat = timeString == "24"; + this.notifyTimeChange(); + }; + + try { + this.mSettingsHelper.on("dataChange", settings.getUriSync(TIME_FORMAT_KEY), (err) => { + if (err.code !== 0) { + Log.showError(TAG, `failed to getAbilityWant, code: ${err.code}.`); + return; + } + handleTimeFormatChange(); + }); + } catch (e) { + Log.showError(TAG, `Can't listen timeformate change.`); + } + handleTimeFormatChange(); + } + + private notifyTimeChange() { + Log.showInfo(TAG, "notifyTimeChange"); + let args: TimeEventArgs = { + date: new Date(), + timeFormat: this.mUse24hFormat, + }; + EventManager.publish(obtainLocalEvent(TIME_CHANGE_EVENT, args)); + } +} + +let sTimeManager = createOrGet(TimeManager, TAG); + +export default sTimeManager as TimeManager; diff --git a/common/src/main/ets/default/TintStateManager.ts b/common/src/main/ets/default/TintStateManager.ts new file mode 100644 index 00000000..887f47ec --- /dev/null +++ b/common/src/main/ets/default/TintStateManager.ts @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Window from "@ohos.window"; +import display from "@ohos.display"; +import Log from "./Log"; +import {WindowType, Rect, WindowNameMap} from "./Constants"; +import getSingleInstance from "./SingleInstanceHelper"; + +const TAG = "TintStateManager"; +const LISTENER_SYSTEM_BAR_TINT_CHANGE = "systemBarTintChange"; + +export type TintStateListener = { onTintStateChange: (state: TintState) => void } +; + +export interface TintState { + isEnable?: boolean; + region?: Rect; + backgroundColor?: string; + contentColor?: string; +} + +export class TintContentInfo { + contentColor: string = "#FFFFFFFF"; +} + +export function getOrCreateTintContentInfo(key: string): TintContentInfo { + let storageKey = 'SystemUI_TintContentInfo_' + key; + if (!AppStorage.Has(storageKey)) { + AppStorage.SetOrCreate(storageKey, new TintContentInfo()); + Log.showInfo(TAG, `getOrCreateTintContentInfo, Create storageKey of ${storageKey}`); + } + return AppStorage.Get(storageKey); +} + +export default class TintStateManager { + mListeners: Map = new Map(); + mStates: Map = new Map(); + + static getInstance(): TintStateManager { + return getSingleInstance(TintStateManager, TAG); + } + + constructor() { + Log.showInfo(TAG, `init TintStateManager. ${LISTENER_SYSTEM_BAR_TINT_CHANGE}`); + Window.on(LISTENER_SYSTEM_BAR_TINT_CHANGE, this.onSystemBarTintChange.bind(this)); + } + + registerListener(windowType: WindowType, listener: TintStateListener) { + let tintState = this.mStates.get(windowType); + tintState && listener.onTintStateChange(tintState); + let res = this.mListeners.set(windowType, listener); + Log.showInfo(TAG, `registser listenerSize: ${res.size}`); + } + + unregisterListener(windowType: WindowType) { + let res = this.mListeners.delete(windowType); + Log.showInfo(TAG, `unregistser ${windowType}, res: ${res}`); + } + + async onSystemBarTintChange(data) { + Log.showInfo(TAG, `onSystemBarTintChange, data: ${JSON.stringify(data)}`); + if (!Array.isArray(data.regionTint)) { + Log.showInfo(TAG, `regionTint is not array.`); + return; + } + let dis = await display.getDefaultDisplay(); + if (dis.id != data.displayId) { + Log.showInfo(TAG, `Needn't change, displayId: ${data.displayId}`); + return; + } + data.regionTint.forEach((regionTintData) => { + Log.showInfo(TAG, `onSystemBarTintChange, type: ${WindowNameMap[regionTintData["type"]]}`); + let windowType = WindowNameMap[regionTintData["type"]]; + if (!windowType) { + return; + } + let tintState: TintState = { + isEnable: regionTintData.isEnable, + region: regionTintData.region, + backgroundColor: regionTintData.backgroundColor, + contentColor: regionTintData.contentColor, + }; + Log.showInfo(TAG, `tintState: ${JSON.stringify(tintState)}`); + this.mStates.set(windowType, tintState); + this.mListeners.get(windowType)?.onTintStateChange(tintState); + }); + } +} diff --git a/common/src/main/ets/default/WindowManager.ets b/common/src/main/ets/default/WindowManager.ets deleted file mode 100644 index 55534f3f..00000000 --- a/common/src/main/ets/default/WindowManager.ets +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Window from '@ohos.window'; -import display from '@ohos.display' -import Log from './Log.ets'; -import ResourceUtil from './ResourceUtil.ets'; - -const TAG = 'WindowManager'; - -var maxWidth; -var maxHeight; -var minHeight; - -/** - * Manage window size changes. - */ -export default class WindowManager { - async initWindowManager() { - Log.showInfo(TAG, 'initWindowManager'); - maxWidth = AppStorage.SetAndLink("maxWidth", 0); - maxHeight = AppStorage.SetAndLink("maxHeight", 0); - minHeight = AppStorage.SetAndLink("minHeight", 0); - - await display.getDefaultDisplay() - .then(dis => { - maxWidth.set(dis.width); - maxHeight.set(dis.height); - Log.showInfo(TAG, `initWindowManager maxWidth ${maxWidth.get()} maxHeight ${maxHeight.get()} minHeight ${minHeight.get()}`); - }) - } - - /** - * Set the window to the maximum size. - * - * @param {Object} callback - Callback function. - */ - setWindowMax(callback) { - Log.showInfo(TAG, 'enter setWindowMax ================='); - Window.getTopWindow() - .then((windowData) => { - Log.showInfo(TAG, 'enter setWindowMin maxWidth =================' + maxWidth.get() + " minHeight " + minHeight.get()); - windowData.resetSize(parseInt(maxWidth.get()), parseInt(maxHeight.get())) - .then((result) => { - Log.showInfo(TAG, result); - callback(result); - }); - - windowData.moveTo(0, 0) - .then((result) => { - Log.showInfo(TAG, result); - }); - }); - } - - /** - * Set the window to the minimum size. - * - * @param {Object} callback - Callback function. - */ - setWindowMin(callback) { - Log.showInfo(TAG, 'enter setWindowMin ================='); - Window.getTopWindow() - .then((windowData) => { - Log.showInfo(TAG, 'enter setWindowMin maxWidth =================' + maxWidth.get() + " minHeight " + minHeight.get()); - windowData.resetSize(parseInt(maxWidth.get()), parseInt(minHeight.get())) - .then((result) => { - Log.showInfo(TAG, result); - callback(result); - }); - }); - } - - /** - * Set the window to the minimum size. - * - * @param {Object} callback - Callback function. - */ - async initWindowMin(width, height, x, y) { - AppStorage.Set("showStatusBar", true); - Log.showInfo(TAG, 'enter initWindowMin ================='); - Log.showInfo(TAG, 'width:' + width + ' height:' + height + ' x:' + x + ' y:' + y); - let abilityWindow = await Window.getTopWindow(); - await abilityWindow.moveTo(parseInt(x), parseInt(y)); - await abilityWindow.resetSize(parseInt(width), parseInt(height)); - } -} \ No newline at end of file diff --git a/common/src/main/ets/default/WindowManager.ts b/common/src/main/ets/default/WindowManager.ts new file mode 100644 index 00000000..9f3f23c7 --- /dev/null +++ b/common/src/main/ets/default/WindowManager.ts @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Window from "@ohos.window"; +import Log from "./Log"; +import EventManager from "./event/EventManager"; +import { obtainLocalEvent } from "./event/EventUtil"; +import { Rect } from "./Constants"; +import createOrGet from "./SingleInstanceHelper"; + +export type WindowInfo = { + visibility: boolean; + rect: Rect; +}; +export enum WindowType { + STATUS_BAR = "SystemUi_StatusBar", + NAVIGATION_BAR = "SystemUi_NavigationBar", + DROPDOWN_PANEL = "SystemUi_DropdownPanel", + NOTIFICATION_PANEL = "SystemUi_NotificationPanel", + CONTROL_PANEL = "SystemUi_ControlPanel", + VOLUME_PANEL = "SystemUi_VolumePanel", + BANNER_NOTICE = 'SystemUi_BannerNotice' +} + +export const WINDOW_SHOW_HIDE_EVENT = "WindowShowHideEvent"; +export const WINDOW_RESIZE_EVENT = "WindowResizeEvent"; + +type WindowHandle = typeof Window.Window; +const TAG = "WindowManager"; +const SYSTEM_WINDOW_TYPE_MAP: { [key in WindowType]: number } = { + SystemUi_StatusBar: 2108, + SystemUi_NavigationBar: 2112, + SystemUi_DropdownPanel: 2109, + SystemUi_NotificationPanel: 2111, + SystemUi_ControlPanel: 2111, + SystemUi_VolumePanel: 2111, + SystemUi_BannerNotice: 2111, +}; +const DEFAULT_WINDOW_INFO: WindowInfo = { + visibility: false, + rect: { left: 0, top: 0, width: 0, height: 0 }, +}; + +/** + * Manage window size changes. + */ +class WindowManager { + mWindowInfos: Map = new Map(); + + async createWindow(context: any, name: WindowType, rect: Rect, loadContent: string): Promise { + Log.showInfo(TAG, `createWindow name: ${name}, rect: ${JSON.stringify(rect)}, url: ${loadContent}`); + let winHandle = await Window.create(context, name, SYSTEM_WINDOW_TYPE_MAP[name]); + await winHandle.moveTo(rect.left, rect.top); + await winHandle.resetSize(rect.width, rect.height); + await winHandle.loadContent(loadContent); + this.mWindowInfos.set(name, { visibility: false, rect }); + Log.showInfo(TAG, `create window[${name}] success.`); + return winHandle; + } + + async resetSizeWindow(name: WindowType, rect: Rect): Promise { + let window = await Window.find(name); + await window.moveTo(rect.left, rect.top); + await window.resetSize(rect.width, rect.height); + this.mWindowInfos.set(name, { ...(this.mWindowInfos.get(name) ?? DEFAULT_WINDOW_INFO), rect }); + EventManager.publish( + obtainLocalEvent(WINDOW_RESIZE_EVENT, { + windowName: name, + rect, + }) + ); + Log.showInfo(TAG, `resize window[${name}] success, rect: ${JSON.stringify(rect)}.`); + } + + async showWindow(name: WindowType): Promise { + let window = await Window.find(name); + await window.show(); + this.mWindowInfos.set(name, { ...(this.mWindowInfos.get(name) ?? DEFAULT_WINDOW_INFO), visibility: true }); + EventManager.publish( + obtainLocalEvent(WINDOW_SHOW_HIDE_EVENT, { + windowName: name, + isShow: true, + }) + ); + Log.showInfo(TAG, `show window[${name}] success.`); + } + + async hideWindow(name: WindowType): Promise { + let window = await Window.find(name); + await window.hide(); + this.mWindowInfos.set(name, { ...(this.mWindowInfos.get(name) ?? DEFAULT_WINDOW_INFO), visibility: false }); + EventManager.publish( + obtainLocalEvent(WINDOW_SHOW_HIDE_EVENT, { + windowName: name, + isShow: false, + }) + ); + Log.showInfo(TAG, `hide window[${name}] success.`); + } + + getWindowInfo(name: WindowType): WindowInfo | undefined { + return this.mWindowInfos.get(name); + } +} + +let sWindowManager = createOrGet(WindowManager, TAG); +export default sWindowManager as WindowManager; diff --git a/common/src/main/ets/default/abilitymanager/abilityManager.ts b/common/src/main/ets/default/abilitymanager/abilityManager.ts new file mode 100644 index 00000000..0d2ee9f7 --- /dev/null +++ b/common/src/main/ets/default/abilitymanager/abilityManager.ts @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../Log'; + +const TAG = 'AbilityManager'; + +export default class AbilityManager { + static ABILITY_NAME_ENTRY = 'SystemUi_Entry'; + static ABILITY_NAME_STATUS_BAR = 'SystemUi_StatusBar'; + static ABILITY_NAME_NAVIGATION_BAR = 'SystemUi_NavigationBar'; + static ABILITY_NAME_VOLUME_PANEL = 'SystemUi_VolumePanel'; + static ABILITY_NAME_NOTIFICATION_MANAGEMENT = 'SystemUi_NotificationManagement'; + static ABILITY_NAME_DROPDOWN_PANEL = 'SystemUi_DropdownPanel'; + static ABILITY_NAME_NOTIFICATION_PANEL = 'SystemUi_NotificationPanel'; + static ABILITY_NAME_CONTROL_PANEL = 'SystemUi_ControlPanel'; + static ABILITY_NAME_BANNER_NOTICE = 'SystemUi_BannerNotice'; + + static ABILITY_NAME_OWNER_WANT = 'Owner_Want'; + + static setContext(abilityName: string, context) { + Log.showInfo(TAG, `setContext, abilityName: ${abilityName}`); + globalThis[abilityName + '_Context'] = context; + } + + static getContext(abilityName?: string) { + Log.showInfo(TAG, `getContext, abilityName: ${abilityName}`); + if (!abilityName) { + abilityName = AbilityManager.ABILITY_NAME_ENTRY; + } + return globalThis[abilityName + '_Context']; + } + + static setAbilityData(abilityName, key, data) { + Log.showInfo(TAG, `setAbilityData, abilityName: ${abilityName} key: ${key} data: ${JSON.stringify(data)}`); + globalThis[abilityName + '_data_' + key] = data; + } + + static getAbilityData(abilityName, key) { + Log.showInfo(TAG, `getAbilityData, abilityName: ${abilityName} key: ${key} `); + return globalThis[abilityName + '_data_' + key]; + } + + static startAbility(want, callback?: Function) { + Log.showInfo(TAG, `startAbility, want: ${JSON.stringify(want)}`); + let context = AbilityManager.getContext(); + context.startAbility(want).then(() => { + Log.showInfo(TAG, `startAbility, then`); + if (callback) { + callback(null); + } + }).catch((error) => { + Log.showInfo(TAG, `startAbility, error: ${JSON.stringify(error)}`); + callback(error); + }) + } +} diff --git a/common/src/main/ets/default/abilitymanager/bundleManager.ets b/common/src/main/ets/default/abilitymanager/bundleManager.ets deleted file mode 100644 index ddb020b6..00000000 --- a/common/src/main/ets/default/abilitymanager/bundleManager.ets +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import BundleMgr from '@ohos.bundle'; -import Resmgr from '@ohos.resourceManager'; -import Log from '../Log.ets'; - -const TAG = 'BRManager'; - -export default class BundleManager { - static async getResourceManager(tag, bundleName, then?: Function) { - Log.showInfo(TAG, `getResourceManager from: ${tag}`); - if (!then) { - return await Resmgr.getResourceManager(bundleName); - } - Resmgr.getResourceManager(bundleName).then(then); - } - - static async getBundleInfo(tag, bundleName, getInfo, then?: Function) { - Log.showInfo(TAG, `getBundleInfo from: ${tag}`); - if (!then) { - return await BundleMgr.getBundleInfo(bundleName, getInfo); - } - BundleMgr.getBundleInfo(bundleName, getInfo).then(then); - } -} \ No newline at end of file diff --git a/common/src/main/ets/default/abilitymanager/bundleManager.ts b/common/src/main/ets/default/abilitymanager/bundleManager.ts new file mode 100644 index 00000000..b38fdc5b --- /dev/null +++ b/common/src/main/ets/default/abilitymanager/bundleManager.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import BundleMgr from "@ohos.bundle"; +import Context from "application/ServiceExtensionContext"; +import Log from "../Log"; +import SwitchUserManager from "../SwitchUserManager"; + +const TAG = "BRManager"; + +export default class BundleManager { + static async getResourceManager(tag: string, context: Context, bundleName: string) { + Log.showInfo(TAG, `getResourceManager from: ${tag}`); + let bundleContext = await context.createBundleContext(bundleName); + return await bundleContext.resourceManager; + } + + static async getBundleInfo(tag: string, bundleName: string, getInfo: + any, requestId?: number) { + let userInfo = { + userId: requestId ?? (await SwitchUserManager.getInstance().getCurrentUserInfo()).userId, + }; + Log.showInfo(TAG, `getBundleInfo from: ${tag}, userId: ${userInfo.userId}`); + return await BundleMgr.getBundleInfo(bundleName, getInfo, userInfo); + } +} \ No newline at end of file diff --git a/common/src/main/ets/default/abilitymanager/featureAbilityManager.ets b/common/src/main/ets/default/abilitymanager/featureAbilityManager.ts similarity index 96% rename from common/src/main/ets/default/abilitymanager/featureAbilityManager.ets rename to common/src/main/ets/default/abilitymanager/featureAbilityManager.ts index 730f8fa5..876cd06f 100644 --- a/common/src/main/ets/default/abilitymanager/featureAbilityManager.ets +++ b/common/src/main/ets/default/abilitymanager/featureAbilityManager.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,7 +14,7 @@ */ import FeatureAbility from '@ohos.ability.featureAbility'; -import Log from '../Log.ets'; +import Log from '../Log'; const TAG = 'FeatureAbilityManager'; diff --git a/common/src/main/ets/default/abilitymanager/notificationManager.ets b/common/src/main/ets/default/abilitymanager/notificationManager.ts similarity index 95% rename from common/src/main/ets/default/abilitymanager/notificationManager.ets rename to common/src/main/ets/default/abilitymanager/notificationManager.ts index 04895620..ad137fc6 100644 --- a/common/src/main/ets/default/abilitymanager/notificationManager.ets +++ b/common/src/main/ets/default/abilitymanager/notificationManager.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,7 +15,7 @@ //import { NotificationSubscriber } from './notification/notificationSubscriber'; import Notification from '@ohos.notification'; -import Log from '../Log.ets'; +import Log from '../Log'; const TAG = 'NotificationManager'; diff --git a/common/src/main/ets/default/commonEvent/CommonEventManager.ts b/common/src/main/ets/default/commonEvent/CommonEventManager.ts new file mode 100644 index 00000000..bdd974a7 --- /dev/null +++ b/common/src/main/ets/default/commonEvent/CommonEventManager.ts @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import commonEvent from "@ohos.commonEvent"; +import { CommonEventData } from "commonEvent/commonEventData"; +import EventManager from "../event/EventManager"; +import Log from "../Log"; +import { SCREEN_CHANGE_EVENT } from "../ScreenLockManager"; + +export type CommonEventManager = { + subscriberCommonEvent: () => Promise; + unSubscriberCommonEvent: () => void; + applyPolicy: (policys: Array) => void; + release: () => void; +}; + +export enum POLICY { + SCREEN_POLICY = "screenOnOffPolicy", +} + +type ClearPolicy = () => void; +type InnerManager = { subscriberCommonEvent: () => void; unSubscriberCommonEvent: () => void }; +const policyMap: { [key in POLICY]: (manager: InnerManager) => ClearPolicy } = { + screenOnOffPolicy: ScreenPolicy, +}; + +export function getCommonEventManager( + tag: string, + subscribeInfos: { events: Array }, + commonEventCallback: (data: CommonEventData) => void, + subscribeStateChange?: (isSubscribe: boolean) => void +): CommonEventManager { + const TAG = `CommonEvent_${tag}`; + const SUBSCRIBE_INFOS = subscribeInfos; + let unSubcribers: Array<() => void> = []; + let policyClearCb: Map | undefined = undefined; + + async function subscriberCommonEvent() { + Log.showInfo(TAG, "registerSubscriber start"); + let subscriber = await commonEvent.createSubscriber(SUBSCRIBE_INFOS); + commonEvent.subscribe(subscriber, (err, data) => { + if (err.code != 0) { + Log.showError(TAG, `Can't handle common event, err: ${JSON.stringify(err)}`); + return; + } + Log.showInfo(TAG, `handle common event: ${data.event}`); + commonEventCallback(data); + }); + unSubcribers.push(() => commonEvent.unsubscribe(subscriber)); + subscribeStateChange && subscribeStateChange(true); + Log.showInfo(TAG, `registerSubscriber success, size: ${unSubcribers.length}`); + } + + function unSubscriberCommonEvent() { + Log.showInfo(TAG, `UnSubcribers size: ${unSubcribers.length}`); + unSubcribers.forEach((unsubscribe) => unsubscribe()); + unSubcribers.length = 0; + subscribeStateChange && subscribeStateChange(false); + } + + function applyPolicy(policys: Array) { + const innerManager = { subscriberCommonEvent, unSubscriberCommonEvent }; + policyClearCb = policyClearCb ?? new Map(); + policys.forEach((policy) => { + if (policyClearCb) { + !policyClearCb.has(policy) && policyClearCb.set(policy, policyMap[policy](innerManager)); + Log.showInfo(TAG, `apply policy: ${policy}`); + } + }); + } + + function release() { + policyClearCb?.forEach((cb) => cb()); + policyClearCb?.clear(); + unSubscriberCommonEvent(); + } + + return { subscriberCommonEvent, unSubscriberCommonEvent, applyPolicy, release }; +} + +function ScreenPolicy(manager: InnerManager): ClearPolicy { + return EventManager.subscribe(SCREEN_CHANGE_EVENT, (isScreenOn: boolean) => { + isScreenOn ? manager.subscriberCommonEvent() : manager.unSubscriberCommonEvent(); + }); +} diff --git a/common/src/main/ets/default/event/EventBus.ts b/common/src/main/ets/default/event/EventBus.ts new file mode 100644 index 00000000..9195cc25 --- /dev/null +++ b/common/src/main/ets/default/event/EventBus.ts @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Log from "../Log"; + +export type Callback = (args: any) => void; +const TAG = "EventBus"; + +export interface EventBus { + on(event: T | T[], cb: Callback): () => void; + once(event: T, cb: Callback): () => void; + off(event: T | T[] | undefined, cb: Callback): void; + emit(event: T, args: any): void; +} + +export function createEventBus(): EventBus { + let _cbs: { [key: string]: Set } = {}; + + function on(events: T | T[], cb: Callback): () => void { + if (Array.isArray(events)) { + events.forEach((e) => on(e, cb)); + } else { + (_cbs[events] || (_cbs[events] = new Set())).add(cb); + Log.showInfo(TAG, `add event[${events}] callback, size: ${_cbs[events]?.size}`); + } + return () => off(events, cb); + } + + function once(event: T, cb: Callback): () => void { + let newCallback = (args: any) => { + cb(args); + removeSelf(); + }; + function removeSelf() { + off(event, newCallback); + } + return on(event, newCallback); + } + + function off(event: T | T[] | undefined, cb: Callback) { + if (!event) { + _cbs = {}; + Log.showInfo(TAG, `remove event[${event}] all callback`); + return; + } + if (Array.isArray(event)) { + event.forEach((e) => off(e, cb)); + return; + } + _cbs[event]?.delete(cb); + Log.showInfo(TAG, `remove event[${event}] callback, size: ${_cbs[event]?.size}`); + } + + function emit(event: T, args: any) { + _cbs[event]?.forEach((cb) => cb(args)); + } + + function stickyEmit(event: T, argument: any[]) {} + return { + on, + once, + off, + emit, + }; +} \ No newline at end of file diff --git a/common/src/main/ets/default/event/EventManager.ts b/common/src/main/ets/default/event/EventManager.ts new file mode 100644 index 00000000..c6764345 --- /dev/null +++ b/common/src/main/ets/default/event/EventManager.ts @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ServiceExtensionContext from "application/ServiceExtensionContext"; +import Log from "../Log"; +import createOrGet from "../SingleInstanceHelper"; +import { EventParser, START_ABILITY_EVENT, Event, LocalEvent } from "./EventUtil"; +import { Callback, createEventBus, EventBus } from "./EventBus"; + +export type unsubscribe = () => void; +export type Events = string | string[]; + +const TAG = "EventManager"; + +class EventManager { + mEventBus: EventBus; + eventParser: EventParser; + mContext: ServiceExtensionContext | undefined; + + constructor() { + this.mEventBus = createEventBus(); + this.eventParser = { + local: this.publishLocalEvent, + ability: this.startAbility, + commonEvent: this.publishCommonEvent, + remote: this.publishRemoteEvent, + }; + } + + setContext(ctx: ServiceExtensionContext) { + this.mContext = ctx; + } + + publish(event: Event): boolean { + return this.eventParser[event.target].call(this, event.data); + } + + subscribe(eventType: Events, callback: Callback): unsubscribe { + return this.mEventBus.on(eventType, callback); + } + + subscribeOnce(eventType: string, callback: Callback): unsubscribe { + return this.mEventBus.once(eventType, callback); + } + + private publishLocalEvent(data: LocalEvent): boolean { + Log.showInfo(TAG, `publish localEvent type: ${data.eventName}`); + if (data.eventName) { + this.mEventBus.emit(data.eventName, data.args); + return true; + } + return false; + } + + private startAbility(data: { [key: string]: any }): boolean { + Log.showInfo(TAG, `start Ability: ${data.abilityName}`); + if (data.bundleName && data.abilityName && this.mContext) { + this.mEventBus.emit(START_ABILITY_EVENT, { abilityName: data.abilityName }); + this.mContext.startAbility({ + bundleName: data.bundleName, + abilityName: data.abilityName, + parameters: data.args??undefined + }); + return true; + } + return false; + } + + private publishRemoteEvent(data: { [key: string]: any }): boolean { + // todo publish to remote device + return false; + } + + private publishCommonEvent(data: { [key: string]: any }): boolean { + // todo publish commonEvent to other app + return false; + } +} + +let sEventManager = createOrGet(EventManager, TAG); + +export default sEventManager as EventManager; \ No newline at end of file diff --git a/common/src/main/ets/default/event/EventUtil.ts b/common/src/main/ets/default/event/EventUtil.ts new file mode 100644 index 00000000..33ba707e --- /dev/null +++ b/common/src/main/ets/default/event/EventUtil.ts @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from "../Log"; + +export type EventTarget = "local" | "remote" | "ability" | "commonEvent"; +export type Event = { + target: EventTarget; + data: { [key: string]: any }; +}; +export type EventParser = { + [key in EventTarget]: (data: any) => boolean; +}; +export type LocalEvent = { + eventName: string; + args: any; +}; + +export const START_ABILITY_EVENT = "startAbilityEvent"; +export const PUBLISH_COMMON_EVENT = "publishCommonEvent"; + +const TAG = "EventUtil"; +const LOCAL_EVENT_TYPE = "local"; +const START_ABILITY_TYPE = "ability"; + +export function obtainLocalEvent(event: string, args: any): Event & { data: LocalEvent } { + return { + target: LOCAL_EVENT_TYPE, + data: { + eventName: event, + args, + }, + }; +} + +export function obtainStartAbility(bundleName: string, abilityName: string, args?: any): Event { + return { + target: START_ABILITY_TYPE, + data: { + bundleName, + abilityName, + args + }, + }; +} + +export function parseEventString(eventString: string | undefined): Event | undefined { + // string must be "local=eventName|args" or "ability=bundleName|abilityName" + if (!eventString) { + return; + } + let [eventType, eventData] = eventString.split("="); + if (eventType == LOCAL_EVENT_TYPE && eventData) { + let [localEventName, args] = eventData.split("|"); + if (localEventName) { + Log.showDebug(TAG, `parseEventData name:${localEventName}, args: ${args}`); + return obtainLocalEvent(localEventName, args); + } + } + if (eventType == START_ABILITY_TYPE && eventData) { + let [bundleName, abilityName] = eventData.split("|"); + if (bundleName && abilityName) { + Log.showDebug(TAG, `parseEventData bundleName:${bundleName}, abilityName: ${abilityName}`); + return obtainStartAbility(bundleName, abilityName); + } + } + Log.showError(TAG, `Can't parse event data: ${eventString}`); + return undefined; +} diff --git a/common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ets b/common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ts similarity index 92% rename from common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ets rename to common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ts index a6518c89..28bbbbe7 100644 --- a/common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ets +++ b/common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Log from '../Log.ets'; +import Log from '../Log'; const STATUS_BAR_MIN_HEIGHT = 24 const STATUS_BAR_COEFFICIENT = 1.0 diff --git a/common/src/main/ets/plugindatasource/PluginDataSourceAdapter.ets b/common/src/main/ets/plugindatasource/PluginDataSourceAdapter.ets deleted file mode 100644 index 7abf6e98..00000000 --- a/common/src/main/ets/plugindatasource/PluginDataSourceAdapter.ets +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Log from '../default/Log.ets'; -import worker from '@ohos.worker'; -import Constants, {obtainMsg} from './common/Constants.ets'; - -const TAG = 'PluginDataSourceAdapter'; -const WORKER_JS_URL = 'workers/PluginDataSourceWorker.js'; - -export default class PluginDataSourceAdapter { - mWorker: any; - mName: any; - mListener: any; - - constructor(name: String) { - Log.showInfo(TAG, `constructor, name: ${name}`) - this.mName = name; - this.mWorker = new worker.Worker(WORKER_JS_URL, { - type: "classic", name: this.mName - }); - - this.mWorker.onmessage = this.onMessage.bind(this); - this.mWorker.onmessageerror = this.onMessageError.bind(this); - this.mWorker.onexit = this.onExit.bind(this); - this.mWorker.onerror = this.onError.bind(this); - } - - initDataSource(configs) { - Log.showInfo(TAG, `initDataSource, configs: ${JSON.stringify(configs)}`) - this.mWorker.postMessage(obtainMsg(Constants.INIT_CONFIG, configs)); - } - - loadData(userId) { - Log.showInfo(TAG, `loadData`) - this.mWorker.postMessage(obtainMsg(Constants.LOAD_DATA, userId)); - } - - clearAll() { - Log.showInfo(TAG, `clearAll`) - this.mWorker.postMessage(obtainMsg(Constants.CLEAR_ALL, {})); - } - - onMessage(msg) { - Log.showInfo(TAG, `onMessage, msg: ${JSON.stringify(msg)}`) - let data = msg.data; - switch (data.action) { - case Constants.INIT_FINISH: - this.onInitFinish(); - break; - case Constants.ADD_ITEM: - this.onItemAdd(data.data); - break; - case Constants.REMOVE_ITEM: - this.onItemRemove(data.data); - break; - default: - Log.showError(TAG, `unknown type: ${JSON.stringify(msg)}`) - } - } - - onInitFinish() { - Log.showInfo(TAG, `onInitFinish`) - this.mListener.initFinish(); - } - - onItemAdd(itemData) { - Log.showInfo(TAG, `onItemAdd, itemData: ${JSON.stringify(itemData)}`) - this.mListener.addItem(itemData); - } - - onItemRemove(itemData) { - Log.showInfo(TAG, `onItemRemove, itemData: ${JSON.stringify(itemData)}`) - this.mListener.removeItem(itemData); - } - - registerListener(listener: { - 'initFinish': Function, - 'addItem': Function, - 'removeItem': Function - }) { - Log.showInfo(TAG, `registerListener`) - this.mListener = listener; - } - - unregisterListener() { - Log.showInfo(TAG, `mListener`) - this.mListener = null; - } - - onMessageError(event) { - Log.showInfo(TAG, `mWorker.onmessageerror, event: ${event}`) - }; - - onExit(code) { - Log.showInfo(TAG, `mWorker.onexit, code: ${code}`) - }; - - onError(err) { - Log.showInfo(TAG, `mWorker.onerror, err: ${JSON.stringify(err)}`) - }; -} diff --git a/common/src/main/ets/plugindatasource/PluginDataSourceAdapter.ts b/common/src/main/ets/plugindatasource/PluginDataSourceAdapter.ts new file mode 100644 index 00000000..2928aaf1 --- /dev/null +++ b/common/src/main/ets/plugindatasource/PluginDataSourceAdapter.ts @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from "@ohos.worker"; +import Log from "../default/Log"; +import BundleManager from "../default/abilitymanager/bundleManager"; +import Constants, { ItemComponentData, obtainMsg, RootConfigInfo } from "./common/Constants"; +import Context from "application/ServiceExtensionContext"; + +export type pluginWorkerListener = { + initFinish: () => void; + onItemAdd: (data: ItemComponentData) => void; + onItemRemove: (data: ItemComponentData) => void; +}; + +const TAG = "PluginDataSourceAdapter"; +const WORKER_JS_URL = "workers/PluginDataSourceWorker.js"; + +export default class PluginDataSourceAdapter { + mContext: Context; + mWorker: any; + mName: string; + mListener: pluginWorkerListener; + + constructor(name: string, context: Context, listener: pluginWorkerListener) { + Log.showInfo(TAG, `constructor, name: ${name}`); + this.mName = name; + this.mContext = context; + this.mListener = listener; + this.mWorker = new worker.Worker(WORKER_JS_URL, { + type: "classic", + name: this.mName, + }); + + this.mWorker.onmessage = this.onMessage.bind(this); + this.mWorker.onmessageerror = this.onMessageError.bind(this); + this.mWorker.onexit = this.onExit.bind(this); + this.mWorker.onerror = this.onError.bind(this); + } + + initDataSource(configs: RootConfigInfo) { + Log.showInfo(TAG, `initDataSource, configs: ${JSON.stringify(configs)}`); + this.mWorker.postMessage(obtainMsg(Constants.INIT_CONFIG, configs)); + } + + loadData(userId: number) { + Log.showInfo(TAG, `loadData`); + this.mWorker.postMessage(obtainMsg(Constants.LOAD_DATA, userId)); + } + + clearAll() { + Log.showInfo(TAG, `clearAll`); + this.mWorker.postMessage(obtainMsg(Constants.CLEAR_ALL, {})); + } + + onMessage(msg: { data: any }) { + Log.showInfo(TAG, `onMessage, msg: ${JSON.stringify(msg)}`); + let data = msg.data; + switch (data.action) { + case Constants.INIT_FINISH: + this.onInitFinish(); + break; + case Constants.ADD_ITEM: + this.onItemAdd(data.data); + break; + case Constants.REMOVE_ITEM: + this.onItemRemove(data.data); + break; + default: + Log.showError(TAG, `unknown type: ${JSON.stringify(msg)}`); + } + } + + onInitFinish() { + Log.showInfo(TAG, `onInitFinish`); + this.mListener.initFinish(); + } + + async onItemAdd(itemData: ItemComponentData) { + Log.showInfo(TAG, `onItemAdd, itemData: ${JSON.stringify(itemData)}`); + itemData.label && (itemData.label = decodeURIComponent(itemData.label)); + if (itemData.label && itemData.iconUrl) { + this.mListener.onItemAdd(itemData); + return; + } + let manager = await BundleManager.getResourceManager(TAG, this.mContext, itemData.bundleName); + Log.showInfo(TAG, `${itemData.id} Can't find label or icon, fetch data from ${manager}`); + if (manager) { + Promise.all([ + itemData.iconUrl ?? manager.getMediaBase64(itemData.abilityIconId), + itemData.label ?? manager.getString(itemData.abilityLabelId), + ]) + .then(([iconValue, labelValue]) => { + iconValue && (itemData.iconUrl = iconValue); + labelValue && (itemData.label = labelValue); + this.mListener.onItemAdd(itemData); + }) + .catch((err) => Log.showError(TAG, `Can't get bundle info, err: ${JSON.stringify(err)}`)); + } + } + + onItemRemove(itemData: ItemComponentData) { + Log.showInfo(TAG, `onItemRemove, itemData: ${JSON.stringify(itemData)}`); + this.mListener.onItemRemove(itemData); + } + + onMessageError(event: any) { + Log.showInfo(TAG, `mWorker.onmessageerror, event: ${event}`); + } + + onExit(code: any) { + Log.showInfo(TAG, `mWorker.onexit, code: ${code}`); + } + + onError(err: any) { + Log.showInfo(TAG, `mWorker.onerror, err: ${JSON.stringify(err)}`); + } +} diff --git a/common/src/main/ets/plugindatasource/PluginDataSourceManager.ets b/common/src/main/ets/plugindatasource/PluginDataSourceManager.ets deleted file mode 100644 index 97bb4f25..00000000 --- a/common/src/main/ets/plugindatasource/PluginDataSourceManager.ets +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Log from '../default/Log.ets'; -import SourceLoaderFactory from './sourceloader/SourceLoaderFactory.ets'; -import SourceLoader from './sourceloader/SourceLoader.ets'; - -const TAG = "PluginDataSourceManager"; - -export default class PluginDataSourceManager { - mLoaders: Map = new Map(); - - initDataSource(configs) { - Log.showInfo(TAG, `initDataSource, configs: ${JSON.stringify(configs)}`); - let factory = new SourceLoaderFactory({ - 'add': this.onItemAdd.bind(this), - 'remove': this.onItemRemove.bind(this) - }); - for (let pluginType in configs) { - factory.getSourceLoader(pluginType, configs[pluginType], (sourceLoader) => { - Log.showInfo(TAG, `getSourceLoader callback`); - if (sourceLoader instanceof SourceLoader) { - this.mLoaders.set(pluginType, sourceLoader); - Log.showInfo(TAG, `getSourceLoader callback, plugin: ${pluginType} ${this.mLoaders.get(pluginType)}`); - } - }) - } - } - - onItemAdd(itemData) { - Log.showInfo(TAG, `onItemAdd, itemData: ${JSON.stringify(itemData)}`); - } - - onItemRemove(itemData) { - Log.showInfo(TAG, `onItemRemove, itemData: ${JSON.stringify(itemData)}`); - } - - clearAll() { - Log.showInfo(TAG, `clearAll`); - this.mLoaders.forEach((sourceLoader) => sourceLoader.stopLoad()); - this.mLoaders.clear(); - } - - loadData(userId) { - Log.showInfo(TAG, `loadData`); - this.mLoaders.forEach((sourceLoader) => { - sourceLoader.loadData(userId); - }); - } -} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/PluginDataSourceManager.ts b/common/src/main/ets/plugindatasource/PluginDataSourceManager.ts new file mode 100644 index 00000000..a5e6a102 --- /dev/null +++ b/common/src/main/ets/plugindatasource/PluginDataSourceManager.ts @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from "../default/Log"; +import SourceLoaderFactory from "./sourceloader/SourceLoaderFactory"; +import SourceLoader from "./sourceloader/SourceLoader"; +import { FilterData, ItemComponentData, RootConfigInfo } from "./common/Constants"; +import { + AbilityInfoWithId, + BundleEventType, + ListenerHandle, + queryAbility, + registerBundleListener, +} from "./common/BundleParseUtil"; +import { AbilityInfo } from "bundle/abilityInfo"; + +export type PluginListener = { + onItemAdd: (itemData: ItemComponentData) => void; + onItemRemove: (itemData: ItemComponentData) => void; +}; + +const TAG = "PluginDataSourceManager"; +const INVALID_USERID = -1; + +export default class PluginDataSourceManager { + mAction: string = ""; + mUserId: number = INVALID_USERID; + mListenerHandle: ListenerHandle | undefined = undefined; + mFilterDatas: Map = new Map(); + mLoaders: Map = new Map(); + mFactory: SourceLoaderFactory; + + constructor(listener: PluginListener) { + this.mFactory = new SourceLoaderFactory({ + add: listener.onItemAdd, + remove: listener.onItemRemove, + }); + } + + initDataSource(configs: RootConfigInfo) { + Log.showInfo(TAG, `initDataSource, configs: ${JSON.stringify(configs)}`); + this.mAction = configs.action; + configs.filterDatas.forEach((data: FilterData) => this.mFilterDatas.set(data.abilityName, data.id)); + for (let pluginType in configs.loaderConfig) { + const sourceLoader = this.mFactory.getSourceLoader(pluginType, configs.loaderConfig[pluginType]); + if (sourceLoader instanceof SourceLoader) { + this.mLoaders.set(pluginType, sourceLoader); + Log.showInfo(TAG, `getSourceLoader plugin: ${pluginType}, loader${this.mLoaders.get(pluginType)}`); + } + } + Log.showInfo(TAG, `action:${this.mAction}, filterData: ${JSON.stringify(this.mFilterDatas)}`); + registerBundleListener(this, (handle) => { + this.mListenerHandle = handle; + }); + } + + async onBundleNotify(bundleName: string, event: BundleEventType) { + Log.showInfo(TAG, `onBundleNotify, bundleName: ${bundleName}, event: ${event}`); + if (event == BundleEventType.BUNDLE_CHANGE || event == BundleEventType.BUNDLE_REMOVE) { + this.mLoaders.forEach((loader) => loader.onBundleRemove(bundleName)); + } + if (event == BundleEventType.BUNDLE_CHANGE || event == BundleEventType.BUNDLE_ADD) { + let abilityInfos = await queryAbility(this.mAction, this.mUserId, bundleName); + Log.showInfo(TAG, `abilityInfos: ${JSON.stringify(abilityInfos)}`); + abilityInfos.forEach((info) => this.notifyAbilityAdd(info)); + } + } + + clearAll() { + Log.showInfo(TAG, `clearAll`); + this.unregisterListener(); + this.mLoaders.forEach((sourceLoader) => sourceLoader.clearData()); + } + + async loadData(userId: number) { + if (this.mUserId != userId) { + this.mUserId = userId; + this.mLoaders.forEach((sourceLoader) => sourceLoader.clearData()); + let abilityInfos = await queryAbility(this.mAction, this.mUserId); + abilityInfos.forEach((info) => this.notifyAbilityAdd(info)); + } + this.mLoaders.forEach((sourceLoader) => sourceLoader.reloadData(this.mUserId)); + } + + private notifyAbilityAdd(info: AbilityInfo) { + let itemId = this.mFilterDatas.get(info.name); + if (!itemId) { + Log.showInfo(TAG, `notifyAbilityAdd, can't find itemId, ability:${info.name}`); + return; + } + let abilityInfo: AbilityInfoWithId = { + ...info, + itemId: itemId, + }; + if (!abilityInfo.metaData || !abilityInfo.metaData.length) { + Log.showInfo(TAG, `Can't find metaData, abilityId: ${abilityInfo.name}`); + return; + } + this.mLoaders.forEach((loader) => loader.onAbilityAdd(abilityInfo)); + } + + private unregisterListener() { + this.mListenerHandle?.unRegister(); + this.mListenerHandle = undefined; + } +} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/common/BundleParseUtil.ts b/common/src/main/ets/plugindatasource/common/BundleParseUtil.ts new file mode 100644 index 00000000..50ac335e --- /dev/null +++ b/common/src/main/ets/plugindatasource/common/BundleParseUtil.ts @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import bundleManager from "@ohos.bundle"; +import commonEvent from "@ohos.commonEvent"; +import { AbilityInfo } from "bundle/abilityInfo"; +import Log from "../../default/Log"; + +export type AbilityInfoWithId = AbilityInfo & { itemId: string }; +export type BundleListener = { + onBundleNotify: (bundleName: string, event: BundleEventType) => void; +}; +export type ListenerHandle = { + unRegister: () => void; +}; +export type PluginData = { + [key: string | number]: any; +}; + +export enum BundleEventType { + BUNDLE_ADD, + BUNDLE_CHANGE, + BUNDLE_REMOVE, + UNKNOWN_EVENT, +} + +const TAG = "SourceLoader-BundleParseUtil"; +const DEFAULT_BUNDLE_FLAG = + bundleManager.BundleFlag.GET_ABILITY_INFO_WITH_METADATA | bundleManager.BundleFlag.GET_ABILITY_INFO_WITH_PERMISSION; +const BUNDLE_SUBSCRIBE_INFO = { + events: [ + commonEvent.Support.COMMON_EVENT_PACKAGE_ADDED, + commonEvent.Support.COMMON_EVENT_PACKAGE_REMOVED, + commonEvent.Support.COMMON_EVENT_PACKAGE_CHANGED, + ], +}; + +export async function queryAbility(action: string, userId: number, bundleName?: string): Promise> { + if (bundleName) { + return await bundleManager.queryAbilityByWant( + { + action: action, + bundleName: bundleName, + }, + DEFAULT_BUNDLE_FLAG, + userId + ); + } + return await bundleManager.queryAbilityByWant({ action: action }, DEFAULT_BUNDLE_FLAG, userId); +} + +export function filterAbilityInfo(info: AbilityInfoWithId, filterKey: string): PluginData | undefined { + let pluginDatas = info.metaData.filter((data) => data.name == filterKey); + if (!pluginDatas.length) { + Log.showDebug(TAG, `filterKey: ${filterKey}, metaData: ${JSON.stringify(info.metaData.values)}`); + return undefined; + } + let pluginData = JSON.parse("{" + pluginDatas[0].extra + "}"); + if (!pluginData) { + Log.showError(TAG, `Can't parse pluginData: ${pluginDatas[0]}, filterKey: ${filterKey}`); + return undefined; + } + Log.showInfo(TAG, `createItemComponentData, pluginData: ${JSON.stringify(pluginData)}`); + return pluginData; +} + +export function registerBundleListener(listener: BundleListener, callback: (handle: ListenerHandle) => void) { + commonEvent.createSubscriber(BUNDLE_SUBSCRIBE_INFO, (err, handle) => { + Log.showDebug(TAG, `registerBundleListener, err: ${JSON.stringify(err)}, handle: ${handle}`); + if (err.code != 0) { + Log.showError(TAG, `Can't regitser bundle subscribe, err: ${JSON.stringify(err)}`); + return; + } + commonEvent.subscribe(handle, (err, data) => { + Log.showDebug(TAG, `bundle change, err: ${JSON.stringify(err)} data: ${JSON.stringify(data)}`); + if (err.code != 0) { + Log.showError(TAG, `Can't handle bundle change, err: ${JSON.stringify(err)}`); + return; + } + let event = BundleEventType.UNKNOWN_EVENT; + switch (data.event) { + case commonEvent.Support.COMMON_EVENT_PACKAGE_ADDED: + event = BundleEventType.BUNDLE_ADD; + break; + case commonEvent.Support.COMMON_EVENT_PACKAGE_CHANGED: + event = BundleEventType.BUNDLE_CHANGE; + break; + case commonEvent.Support.COMMON_EVENT_PACKAGE_REMOVED: + event = BundleEventType.BUNDLE_REMOVE; + break; + default: + Log.showError(TAG, `unknow event: ${event}`); + } + listener.onBundleNotify(data.bundleName ?? "unkown", event); + }); + callback({ + unRegister: () => { + commonEvent.unsubscribe(handle, () => { + Log.showInfo(TAG, `unRegister bundle info listener, handle: ${handle}`); + }); + }, + }); + }); +} diff --git a/common/src/main/ets/plugindatasource/common/Constants.ets b/common/src/main/ets/plugindatasource/common/Constants.ets deleted file mode 100644 index 86218d6b..00000000 --- a/common/src/main/ets/plugindatasource/common/Constants.ets +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export default class Constants { - static INIT_CONFIG = "initConfig"; - static INIT_FINISH = "initFinish"; - static CLEAR_ALL = "clearAll"; - static ADD_ITEM = "addItem"; - static REMOVE_ITEM = "removeItem"; - static LOAD_DATA = "loadData"; - static DEFAULT_USER_ID = 0; - static DEFAULT_BUNDLE_FLAG = 0x00000020 | 0x00000008; -} - -export enum PluginType { - SIMPLE = 1, - OBSERVER = 2, - LISTENER = 3, -} - -export function obtainMsg(action, data) { - return { "action": action, "data": data }; -} - -export class ItemComponentData { - id: string; - pluginType: number; - deviceId: string; - bundleName: string; - abilityName: string; - abilityLabelId: number; - abilityIconId: number; - label: string; - iconUrl: Resource | string; - template?: string; - state?: any; - actionData?: ActionData; -} - -export class ActionData { - clickAction?: string; - longClickAction?: string; - launchType?: number; - pluginData?: any; - extra?: any; -} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/common/Constants.ts b/common/src/main/ets/plugindatasource/common/Constants.ts new file mode 100644 index 00000000..323c9617 --- /dev/null +++ b/common/src/main/ets/plugindatasource/common/Constants.ts @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Event } from "../../default/Event/EventUtil"; + +export default class Constants { + static INIT_CONFIG = "initConfig"; + static INIT_FINISH = "initFinish"; + static CLEAR_ALL = "clearAll"; + static ADD_ITEM = "addItem"; + static REMOVE_ITEM = "removeItem"; + static LOCAL_DEVICE = "local"; + static LOAD_DATA = "loadData"; +} + +export type FilterData = { + id: string; + abilityName: string; +}; + +export type RootConfigInfo = { + action: string; + filterDatas: FilterData[]; + loaderConfig: { + [key in any]: LoaderConfigInfo; + }; +}; + +export type LoaderConfigInfo = { + [key: string]: any; +}; + +export enum PluginType { + META = 1, + DATA_ABILITY = 2, + PLUGIN_COMPONENT = 3, +} + +export function obtainMsg(action: string, data: any) { + return { action: action, data: data }; +} + +export type ItemComponentData = { + id: string; + pluginType: number; + deviceId: string; + bundleName: string; + abilityName: string; + abilityLabelId: number; + abilityIconId: number; + label?: string; + iconUrl?: Resource | string; + template?: string; + state?: any; + actionData?: ActionData; +} + +export class ActionData { + clickAction?: Event; + longClickAction?: Event; + launchType?: number; + pluginData?: any; + extra?: any; +} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/sourceloader/BaseMetaSourceLoader.ets b/common/src/main/ets/plugindatasource/sourceloader/BaseMetaSourceLoader.ets deleted file mode 100644 index 977c1767..00000000 --- a/common/src/main/ets/plugindatasource/sourceloader/BaseMetaSourceLoader.ets +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import bundleManager from "@ohos.bundle"; -import commonEvent from '@ohos.commonEvent'; -import Log from '../../default/Log.ets'; -import CheckEmptyUtils from '../../default/CheckEmptyUtils.ets'; -import SourceLoader from './SourceLoader.ets'; -import Constants, {ItemComponentData, ActionData} from '../common/Constants.ets'; - -const TAG = "BaseMetaSourceLoader"; - -let mCommonEventSubscribeInfo = { - events: [ - commonEvent.Support.COMMON_EVENT_PACKAGE_ADDED, - commonEvent.Support.COMMON_EVENT_PACKAGE_REMOVED, - commonEvent.Support.COMMON_EVENT_PACKAGE_CHANGED - ] -}; - -export default abstract class BaseMetaSourceLoader extends SourceLoader { - mAction: string = null; - mPermission: string = null; - mFilterIds: string[] = null; - mPluginType: number = null; - mItemComponentDatas: ItemComponentData[] = []; - mCommonEventSubscriber = null; - mUserId: string = null; - - constructor(config, channel, pluginType) { - super(channel); - Log.showInfo(TAG, `constructor, config: ${JSON.stringify(config)} channel: ${channel} pluginType: ${pluginType}`) - this.mPluginType = pluginType; - this.initSourceLoader(config); - } - - initSourceLoader(config) { - Log.showInfo(TAG, `init loader, config: ${JSON.stringify(config)}`) - - this.mAction = config.action; - this.mPermission = config.permission; - this.mFilterIds = config.filterIds; - - Log.showInfo(TAG, `init loader, mCommonEventSubscribeInfo: ${JSON.stringify(mCommonEventSubscribeInfo)}`) - commonEvent.createSubscriber( - mCommonEventSubscribeInfo, - this.createCommonEventSubscriberCallBack.bind(this) - ); - } - - stopLoad() { - Log.showInfo(TAG, `stop loader`) - this.unRegisterCommonEventListener(); - this.removeAllItemComponentData(); - } - - loadData(userId) { - Log.showInfo(TAG, `load loader userId = ` + userId) - this.mUserId = userId; - this.removeAllItemComponentData(); - this.addAbilityItemComponentData({ - "action": this.mAction - }); - } - - createCommonEventSubscriberCallBack(err, data) { - Log.showInfo(TAG, `createCommonEventSubscriberCallBack, err: ${JSON.stringify(err)}`); - if (err.code != 0) { - return; - } - - this.mCommonEventSubscriber = data; - commonEvent.subscribe(this.mCommonEventSubscriber, this.procCommonEventSubscriberCallBack.bind(this)); - } - - procCommonEventSubscriberCallBack(err, data) { - Log.showInfo(TAG, `procCommonEventSubscriberCallBack, err: ${JSON.stringify(err)} data: ${JSON.stringify(data)}`); - if (err.code != 0) { - return; - } - - let event = data.event; - let bundleName = data.bundleName; - if (event == commonEvent.Support.COMMON_EVENT_PACKAGE_CHANGED || event == commonEvent.Support.COMMON_EVENT_PACKAGE_REMOVED) { - this.removeItemComponentData(bundleName); - } - if (event == commonEvent.Support.COMMON_EVENT_PACKAGE_ADDED || event == commonEvent.Support.COMMON_EVENT_PACKAGE_CHANGED) { - this.addAbilityItemComponentData({ - "bundleName": bundleName, - "action": this.mAction - }); - } - } - - unRegisterCommonEventListener() { - Log.showInfo(TAG, 'unRegisterCommonEventListener') - commonEvent.unsubscribe(this.mCommonEventSubscriber, () => { - Log.showInfo(TAG, 'unRegisterCommonEventListener unregister Listener ==============='); - }); - } - - removeAllItemComponentData(): void{ - Log.showInfo(TAG, `removeAllItemComponentData`); - for (let itemComponentData of this.mItemComponentDatas) { - this.removeItem(itemComponentData); - } - this.mItemComponentDatas = []; - } - - addAbilityItemComponentData(want): void{ - Log.showInfo(TAG, `addAbilityItemComponentData, want: ${JSON.stringify(want)} BundleFlag: ${Constants.DEFAULT_BUNDLE_FLAG}this.mUserId:${this.mUserId}`); - bundleManager.queryAbilityByWant(want, Constants.DEFAULT_BUNDLE_FLAG, this.mUserId ? this.mUserId : Constants.DEFAULT_USER_ID, - (err, abilityInfos) => { - Log.showInfo(TAG, `addAbilityItemComponentData queryAbilityByWant callback, want: ${JSON.stringify(want)} err: ${JSON.stringify(err)} abilityInfos: ${abilityInfos.length} ${JSON.stringify(abilityInfos)} `) - if (err != 0) { - return; - } - for (let abilityInfo of abilityInfos) { - this.createItemComponentData(abilityInfo, (itemComponentData) => { - this.addItemComponentData(itemComponentData); - }); - } - Log.showInfo(TAG, `addAbilityItemComponentData, mItemComponentDatas: ${JSON.stringify(this.mItemComponentDatas)} `) - }); - } - - createItemComponentData(abilityInfo, callback: Function): void{ - Log.showInfo(TAG, `createItemComponentData, abilityInfo: ${JSON.stringify(abilityInfo)}`); - - let pluginData: any = null; - Log.showInfo(TAG, `abilityInfo.metaData: ${JSON.stringify(abilityInfo.metaData)}`); - if (abilityInfo.metaData) { - for (let index in abilityInfo.metaData) { - if (abilityInfo.metaData[index].name == this.mAction) { - Log.showInfo(TAG, `customizeData.extra: ${abilityInfo.metaData[index].extra}`); - pluginData = JSON.parse("{" + abilityInfo.metaData[index].extra + "}"); - break; - } - } - } - Log.showInfo(TAG, `createItemComponentData, pluginData: ${JSON.stringify(pluginData)}`); - if (!pluginData && parseInt(pluginData.pluginType) != this.mPluginType) { - return; - } - if (this.mFilterIds.indexOf(pluginData.id) < 0) { - return; - } - - let itemComponentData = new ItemComponentData(); - { - itemComponentData.id = pluginData.id; - itemComponentData.pluginType = this.mPluginType; - itemComponentData.deviceId = null; - itemComponentData.bundleName = abilityInfo.bundleName; - itemComponentData.abilityName = abilityInfo.name; - itemComponentData.abilityLabelId = abilityInfo.labelId; - itemComponentData.abilityIconId = abilityInfo.iconId; - if (!CheckEmptyUtils.isEmpty(pluginData.label)) { - itemComponentData.label = encodeURIComponent(pluginData.label); - } - if (!CheckEmptyUtils.isEmpty(pluginData.icon)) { - itemComponentData.iconUrl = pluginData.icon; - } - if (!CheckEmptyUtils.isEmpty(pluginData.template)) { - itemComponentData.template = pluginData.template; - } - { - let actionData = new ActionData(); - actionData.clickAction = pluginData.clickAction; - actionData.longClickAction = pluginData.longClickAction; - actionData.launchType = pluginData.launchType; - actionData.pluginData = pluginData.pluginData; - actionData.extra = pluginData.extra; - itemComponentData.actionData = actionData; - } - } - - Log.showInfo(TAG, `createItemComponentData, itemComponentData: ${JSON.stringify(itemComponentData)}`); - callback(itemComponentData); - } - - addItemComponentData(itemComponentData): void { - Log.showInfo(TAG, `addItemComponentData, itemComponentData: ${JSON.stringify(itemComponentData)} `); - this.addItem(itemComponentData); - this.mItemComponentDatas.push(itemComponentData); - } - - removeItemComponentData(bundleName): void { - Log.showInfo(TAG, `removeItemComponentData, bundleName: ${bundleName}`); - let deleteIndexs = []; - for (let i = 0;i < this.mItemComponentDatas.length; i++) { - if (this.mItemComponentDatas[i].bundleName == bundleName) { - deleteIndexs.push(i); - } - } - Log.showInfo(TAG, `removeItemComponentData, deleteIndexs: ${JSON.stringify(deleteIndexs)}`); - for (let i = (deleteIndexs.length - 1);i >= 0; i--) { - let itemComponentData = this.mItemComponentDatas[deleteIndexs[i]]; - this.removeItem(itemComponentData); - this.mItemComponentDatas.splice(deleteIndexs[i], 1); - } - Log.showInfo(TAG, `removeItemComponentData, mItemComponentDatas: ${JSON.stringify(this.mItemComponentDatas)}`); - } -} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/sourceloader/DataAbilitySourceLoader.ets b/common/src/main/ets/plugindatasource/sourceloader/DataAbilitySourceLoader.ets deleted file mode 100644 index d3254473..00000000 --- a/common/src/main/ets/plugindatasource/sourceloader/DataAbilitySourceLoader.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Log from '../../default/Log.ets'; -import BaseMetaSourceLoader from './BaseMetaSourceLoader.ets'; -import {PluginType} from '../common/Constants.ets'; - -const TAG = "DataAbilitySourceLoader"; - -export default class DataAbilitySourceLoader extends BaseMetaSourceLoader { - // config = {"methodName":"xxx/xx/xx"} - - constructor(config, channel) { - super(config, channel, PluginType.OBSERVER); - Log.showInfo(TAG, `constructor, config: ${JSON.stringify(config)} channel: ${channel}`) - } - - // todo 启动监听,监听call方法,数据转换为ItemComponentData,通过addItem/removewItem传输 -} diff --git a/common/src/main/ets/plugindatasource/sourceloader/DataAbilitySourceLoader.ts b/common/src/main/ets/plugindatasource/sourceloader/DataAbilitySourceLoader.ts new file mode 100644 index 00000000..424e43d2 --- /dev/null +++ b/common/src/main/ets/plugindatasource/sourceloader/DataAbilitySourceLoader.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from "../../default/Log"; +import { AbilityInfoWithId } from "../common/BundleParseUtil"; +import { LoaderConfigInfo } from "../common/Constants"; +import SourceLoader from "./SourceLoader"; + +const TAG = "DataAbilitySourceLoader"; + +export default class DataAbilitySourceLoader extends SourceLoader { + constructor(config: LoaderConfigInfo) { + super(config); + Log.showInfo(TAG, `constructor`); + } + + clearData(): void {} + reloadData(userId: number): void {} + onAbilityAdd(abilityInfo: AbilityInfoWithId): void {} + onBundleRemove(bundleName: string): void {} +} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/sourceloader/MetaSourceLoader.ts b/common/src/main/ets/plugindatasource/sourceloader/MetaSourceLoader.ts new file mode 100644 index 00000000..5a4944a4 --- /dev/null +++ b/common/src/main/ets/plugindatasource/sourceloader/MetaSourceLoader.ts @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from "../../default/Log"; +import SourceLoader from "./SourceLoader"; +import Constants, { PluginType, ItemComponentData, LoaderConfigInfo } from "../common/Constants"; +import { AbilityInfoWithId, filterAbilityInfo, PluginData } from "../common/BundleParseUtil"; +import { parseEventString } from "../../default/Event/EventUtil"; + +const TAG = "MetaSourceLoader"; + +export default class MetaSourceLoader extends SourceLoader { + mPluginFilter: string = ""; + mPermission: string = ""; + mItemDatas: ItemComponentData[] = []; + + constructor(config: LoaderConfigInfo) { + super(config); + this.mPluginFilter = config.action; + this.mPermission = config.permission; + Log.showInfo(TAG, `init loader, mPluginFilter: ${this.mPluginFilter}, mPermission: ${this.mPermission}`); + } + + onAbilityAdd(abilityInfo: AbilityInfoWithId): void { + let pluginData: PluginData | undefined = filterAbilityInfo(abilityInfo, this.mPluginFilter); + if (pluginData) { + let itemData = parseData(abilityInfo, pluginData); + if (!itemData) { + return; + } + this.mItemDatas.push(itemData); + this.addItem(itemData); + Log.showInfo(TAG, `item[${itemData.id}] add success, name: ${abilityInfo.name}`); + return; + } + Log.showDebug(TAG, `Can't filter ${abilityInfo.name}.`); + } + + onBundleRemove(bundleName: string): void { + for (let i = this.mItemDatas.length - 1; i >= 0; i--) { + if (bundleName == this.mItemDatas[i].bundleName) { + Log.showDebug(TAG, `remove item index: ${i}, abilityname: ${this.mItemDatas[i].abilityName}`); + this.removeItem(this.mItemDatas[i]); + this.mItemDatas.splice(i, 1); + } + } + } + + clearData(): void { + Log.showDebug(TAG, `clear all, size: ${this.mItemDatas.length}`); + this.mItemDatas.forEach((data) => this.removeItem(data)); + this.mItemDatas.length = 0; + } + + reloadData(userId: number): void { + Log.showDebug(TAG, `reloadData userId: ${userId}`); + } +} + +function parseData(info: AbilityInfoWithId, data: PluginData): ItemComponentData { + let { label, pluginType, icon, template, clickAction, longClickAction, launchType, ...extra } = data; + if (pluginType.toString() != PluginType.META.toString()) { + return undefined; + } + let itemData: ItemComponentData = { + id: info.itemId, + pluginType: PluginType.META, + deviceId: Constants.LOCAL_DEVICE, + bundleName: info.bundleName, + abilityName: info.name, + abilityLabelId: info.labelId, + abilityIconId: info.iconId, + label: label, + iconUrl: icon, + template: template, + actionData: { + clickAction: parseEventString(clickAction), + longClickAction: parseEventString(longClickAction), + launchType: launchType, + extra: extra, + }, + }; + return itemData; +} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/sourceloader/PluginSourceLoader.ets b/common/src/main/ets/plugindatasource/sourceloader/PluginSourceLoader.ts similarity index 52% rename from common/src/main/ets/plugindatasource/sourceloader/PluginSourceLoader.ets rename to common/src/main/ets/plugindatasource/sourceloader/PluginSourceLoader.ts index 866e509d..797806dd 100644 --- a/common/src/main/ets/plugindatasource/sourceloader/PluginSourceLoader.ets +++ b/common/src/main/ets/plugindatasource/sourceloader/PluginSourceLoader.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,28 +13,21 @@ * limitations under the License. */ -import Log from '../../default/Log.ets'; -import SourceLoader from './SourceLoader.ets'; +import Log from "../../default/Log"; +import { AbilityInfoWithId } from "../common/BundleParseUtil"; +import { LoaderConfigInfo } from "../common/Constants"; +import SourceLoader from "./SourceLoader"; const TAG = "PluginSourceLoader"; export default class PluginSourceLoader extends SourceLoader { - constructor(config, channel) { - super(channel); - this.initSourceLoader(config); - } + constructor(config: LoaderConfigInfo) { + super(config); + Log.showInfo(TAG, `constructor`); + } - initSourceLoader(config) { - Log.showInfo(TAG, `init loader, config: ${JSON.stringify(config)}`) - // todo 配置解析, config格式配置 - // todo 启动监听,数据转换为ItemComponentData,通过addItem/removewItem传输 - } - - stopLoad() { - // todo 停止监听,清除数据 - } - - loadData(userId) { - // todo 重新获取一次数据 - } + clearData(): void {} + reloadData(userId: number): void {} + onAbilityAdd(abilityInfo: AbilityInfoWithId): void {} + onBundleRemove(bundleName: string): void {} } \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/sourceloader/SourceLoader.ets b/common/src/main/ets/plugindatasource/sourceloader/SourceLoader.ets deleted file mode 100644 index 6405beaf..00000000 --- a/common/src/main/ets/plugindatasource/sourceloader/SourceLoader.ets +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Log from '../../default/Log.ets'; -import {ItemComponentData} from '../common/Constants.ets'; - -const TAG = "SourceLoader"; - -export default abstract class SourceLoader { - mChannel: any; - - constructor(channel) { - Log.showInfo(TAG, `constructor, channel: ${channel}`) - this.mChannel = channel; - } - - abstract stopLoad(): void; - - abstract loadData(userId): void; - - addItem(itemData: ItemComponentData) { - Log.showInfo(TAG, `addItem, itemData: ${JSON.stringify(itemData)}`) - this.mChannel.add(itemData); - } - - removeItem(itemData:ItemComponentData) { - Log.showInfo(TAG, `remove, itemData: ${JSON.stringify(itemData)}`) - this.mChannel.remove(itemData); - } -} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/sourceloader/SourceLoader.ts b/common/src/main/ets/plugindatasource/sourceloader/SourceLoader.ts new file mode 100644 index 00000000..bec6e183 --- /dev/null +++ b/common/src/main/ets/plugindatasource/sourceloader/SourceLoader.ts @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from "../../default/Log"; +import { ItemComponentData, LoaderConfigInfo } from "../common/Constants"; +import { AbilityInfoWithId } from "../common/BundleParseUtil"; + +const TAG = "SourceLoader"; + +export type LoaderChannel = { + add: (item: ItemComponentData) => void; + remove: (item: ItemComponentData) => void; +}; + +export default abstract class SourceLoader { + mChannel: LoaderChannel | undefined; + + constructor(config: LoaderConfigInfo) { + Log.showInfo(TAG, `constructor`); + } + + public setChannel(channel: LoaderChannel) { + this.mChannel = channel; + } + + protected addItem(itemData: ItemComponentData) { + this.mChannel?.add(itemData); + } + + protected removeItem(itemData: ItemComponentData) { + this.mChannel?.remove(itemData); + } + + abstract clearData(): void; + + abstract onBundleRemove(bundleName: string): void; + + abstract reloadData(userId: number): void; + + abstract onAbilityAdd(abilityInfo: AbilityInfoWithId): void; +} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/sourceloader/SourceLoaderFactory.ets b/common/src/main/ets/plugindatasource/sourceloader/SourceLoaderFactory.ets deleted file mode 100644 index 55b437b6..00000000 --- a/common/src/main/ets/plugindatasource/sourceloader/SourceLoaderFactory.ets +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Log from '../../default/Log.ets'; -import DataAbilitySourceLoader from './DataAbilitySourceLoader.ets' -import MetaSourceLoader from './MetaSourceLoader.ets' -import PluginSourceLoader from './PluginSourceLoader.ets' - -const TAG = "SourceLoaderFactory"; - -const classMap = new Map([ - ["MetaSource", MetaSourceLoader], - ["PluginSourceLoader", PluginSourceLoader], - ["DataAbilitySourceLoader", DataAbilitySourceLoader] -]); - -export default class SourceLoaderFactory { - mChannel: any; - - constructor(channel: { - add: Function, - remove: Function - }) { - Log.showInfo(TAG, `constructor, channel: ${channel}`) - this.mChannel = channel; - } - - getSourceLoader(pluginType, config, callback) { - Log.showInfo(TAG, `getSourceLoader, pluginType: ${pluginType} config: ${JSON.stringify(config)}`) - if (!classMap.has(pluginType)) { - return; - } - callback(new (classMap.get(pluginType))(config, this.mChannel)); - } -} \ No newline at end of file diff --git a/common/src/main/ets/plugindatasource/sourceloader/SourceLoaderFactory.ts b/common/src/main/ets/plugindatasource/sourceloader/SourceLoaderFactory.ts new file mode 100644 index 00000000..8487bdad --- /dev/null +++ b/common/src/main/ets/plugindatasource/sourceloader/SourceLoaderFactory.ts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from "../../default/Log"; +import SourceLoader, { LoaderChannel } from "./SourceLoader"; +import DataAbilitySourceLoader from "./DataAbilitySourceLoader"; +import MetaSourceLoader from "./MetaSourceLoader"; +import PluginSourceLoader from "./PluginSourceLoader"; +import { LoaderConfigInfo } from "../common/Constants"; + +const TAG = "SourceLoaderFactory"; + +const classMap: { [key: string]: any } = { + MetaSource: MetaSourceLoader, + PluginSourceLoader: PluginSourceLoader, + DataAbilitySourceLoader: DataAbilitySourceLoader, +}; + +export default class SourceLoaderFactory { + mChannel: LoaderChannel; + + constructor(channel: LoaderChannel) { + Log.showInfo(TAG, `constructor, channel: ${channel}`); + this.mChannel = channel; + } + + getSourceLoader(pluginType: string, config: LoaderConfigInfo): null | SourceLoader { + let clz = classMap[pluginType]; + if (!clz) { + Log.showError(TAG, `Can't find pluginType: ${pluginType}`); + return null; + } + let loader: SourceLoader = new clz(config); + loader.setChannel(this.mChannel); + return loader; + } +} \ No newline at end of file diff --git a/common/src/main/ets/template/SimpleToggleBase.ets b/common/src/main/ets/template/SimpleToggleBase.ets index 73092462..cc035858 100644 --- a/common/src/main/ets/template/SimpleToggleBase.ets +++ b/common/src/main/ets/template/SimpleToggleBase.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,106 +13,105 @@ * limitations under the License. */ -import Log from '../default/Log.ets' -import UniformConfig from './UniformConfig.ets' +import Log from '../default/Log' +import StyleConfiguration from './common/StyleConfiguration' -const TAG = 'SimpleToggleBase.ets' +const TAG = 'SimpleToggleBase' @Component export default struct SimpleToggleBase { - private mConfig = UniformConfig.config - @Prop mToggleId: string - @Link @Watch('onIconUpdated') mIcon: string | Resource - @State @Watch('onIconStrUpdated') mIconStr: string = '' + private mToggleId: string + @Link mIcon: string | Resource + @State mIconStr: string = '' private mUseIconStr: boolean = false private mAutoIconColor: boolean = false - @Link @Watch('onChangeSwitchUpdated') mChangeSwitch: boolean + @Prop mChangeSwitch: boolean @Link mLabel: string | Resource @State mLabelStr: string = '' private mUseLabelStr: boolean = false - @Prop mShowLabel: boolean - @Prop mEditMode: boolean + private mIconOnBG: string | Resource + private mEditMode: boolean = false + private mDragMode: boolean = false private mClickEvent: Function private mLongClickEvent: Function - private appStorageIconKey: string - private appStorageChangeSwitchKey: string + @State mIconIsHover: boolean = false + @State mTextIsHover: boolean = false + @State style: any = StyleConfiguration.getSimpleToggleBaseStyle() aboutToAppear() { Log.showInfo(TAG, `aboutToAppear, mToggleId: ${this.mToggleId}`) Log.showInfo(TAG, `aboutToAppear, mLabel: ${JSON.stringify(this.mLabel)}`) - if (this.mEditMode) { - this.appStorageIconKey = "TOGGLE_ICON_" + this.mToggleId - this.appStorageChangeSwitchKey = "TOGGLE_CHANGE_SWITCH_" + this.mToggleId - if (this.mUseIconStr) { - AppStorage.SetOrCreate(this.appStorageIconKey, this.mIconStr) - } else { - AppStorage.SetOrCreate(this.appStorageIconKey, this.mIcon) - } - AppStorage.SetOrCreate(this.appStorageChangeSwitchKey, this.mChangeSwitch) - } + Log.showInfo(TAG, `aboutToAppear, mEditMode: ${this.mEditMode} mDragMode: ${this.mDragMode}`) } aboutToDisappear() { Log.showInfo(TAG, 'aboutToDisappear') } - onIconUpdated(propName: string): void { - Log.showInfo(TAG, `onIconUpdated, propName: ${propName} mIcon: ${JSON.stringify(this.mIcon)}`) - if (this.mEditMode) { - AppStorage.SetOrCreate(this.appStorageIconKey, this.mIcon) - } - } - - onIconStrUpdated(propName: string): void { - Log.showInfo(TAG, `onIconStrUpdated, propName: ${propName} mIconStr: ${this.mIconStr}`) - if (this.mEditMode) { - AppStorage.SetOrCreate(this.appStorageIconKey, this.mIconStr) - } - } - - onChangeSwitchUpdated(propName: string): void { - Log.showInfo(TAG, `onIconUpdated, propName: ${propName} mChangeSwitch: ${this.mChangeSwitch}`) - if (this.mEditMode) { - AppStorage.SetOrCreate(this.appStorageChangeSwitchKey, this.mChangeSwitch) - } - } - build() { Column() { Stack() { Flex() - .backgroundColor(this.mChangeSwitch == false ? this.mConfig.iconOffBG : this.mConfig.iconOnBG) - .clip(new Circle({ width: this.mConfig.circleWidth, height: this.mConfig.circleHeight })) - .width(this.mConfig.circleWidth) - .height(this.mConfig.circleHeight) - if (this.mAutoIconColor) { - Image(this.mUseIconStr ? this.mIconStr : this.mIcon) - .size({ width: this.mConfig.iconWidth, height: this.mConfig.iconHeight }) - .objectFit(ImageFit.Contain) - .fillColor(this.mChangeSwitch ? this.mConfig.iconOnColor : this.mConfig.iconOffColor) - } else { - Image(this.mUseIconStr ? this.mIconStr : this.mIcon) - .size({ width: this.mConfig.iconWidth, height: this.mConfig.iconHeight }) - .objectFit(ImageFit.Contain) + .backgroundColor(this.mChangeSwitch ? (this.mIconOnBG ? this.mIconOnBG : this.style.iconOnBG) : this.style.iconOffBG) + .clip(new Circle({ + width: this.mDragMode ? this.style.dragCircleWidth : this.style.circleWidth, + height: this.mDragMode ? this.style.dragCircleHeight : this.style.circleHeight + })) + .width(this.mDragMode ? this.style.dragCircleWidth : this.style.circleWidth) + .height(this.mDragMode ? this.style.dragCircleHeight : this.style.circleHeight) + if (!this.mDragMode) { + Flex() + .backgroundColor(this.mIconIsHover ? this.style.hoverColor : this.style.transparentColor) + .clip(new Circle({ width: this.style.circleWidth, height: this.style.circleHeight })) + .width(this.style.circleWidth) + .height(this.style.circleHeight) + } + Image(this.mUseIconStr ? this.mIconStr : this.mIcon) + .size({ + width: this.mDragMode ? this.style.dragIconWidth : this.style.iconWidth, + height: this.mDragMode ? this.style.dragIconHeight : this.style.iconHeight }) + .objectFit(ImageFit.Contain) + .fillColor(this.mChangeSwitch ? this.style.iconOnColor : this.style.iconOffColor) + .onHover((isHover) => { + this.mIconIsHover = isHover; + }) + } + .width(this.mDragMode ? this.style.dragCircleWidth : this.style.circleWidth) + .height(this.mDragMode ? this.style.dragCircleHeight : this.style.circleHeight) + .onClick(this.onIconItemClick.bind(this)) + + if (!this.mDragMode) { + Column() + .width('100%') + .height(this.style.componentGap) + Stack() { + Flex() + .backgroundColor(this.mTextIsHover ? this.style.hoverColor : this.style.transparentColor) + .clip(new Rect({ + width: this.style.textHoverWidth, + height: this.style.textHoverHeight + }).radius(this.style.textHoverRadius)) + .width(this.style.textHoverWidth) + .height(this.style.textHoverHeight) + Text(this.mUseLabelStr ? this.mLabelStr : this.mLabel) + .fontSize(this.style.titleSize) + .fontColor(this.style.titleColor) + .textAlign(TextAlign.Center) + .maxLines(2) + .onHover((isHover) => { + this.mTextIsHover = isHover; + }) } } - .width(this.mConfig.circleWidth) - .height(this.mConfig.circleHeight) - - if (this.mShowLabel) { - Column() - .width(this.mConfig.circleWidth) - .height(10) - - Text(this.mUseLabelStr ? this.mLabelStr : this.mLabel) - .fontSize(this.mConfig.simpleToggleTitleSize) - } } - .onClick(this.onIconItemClick.bind(this)) - .gesture(LongPressGesture({ repeat: false }).onAction(this.onIconItemLongPressGesture.bind(this))) + .width('100%') + .height('100%') } onIconItemClick(event: ClickEvent) { + if (this.mDragMode) { + return + } Log.showInfo(TAG, `onIconItemClick`) if (this.mClickEvent) { this.mClickEvent() @@ -120,7 +119,7 @@ export default struct SimpleToggleBase { } onIconItemLongPressGesture(event: GestureEvent) { - if (this.mEditMode) { + if (this.mEditMode || this.mDragMode) { return } Log.showInfo(TAG, `onIconItemLongPressGesture, event: ${JSON.stringify(event)}`) diff --git a/common/src/main/ets/template/UniformConfig.ets b/common/src/main/ets/template/UniformConfig.ets deleted file mode 100644 index cadfa00c..00000000 --- a/common/src/main/ets/template/UniformConfig.ets +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export default class UniformConfig { - - static config = { - iconOnBG: "#0A59F7", - iconOffBG: "#F5F5F5", - iconOnColor: "#FFFFFF", - iconOffColor: "#404345", - baseColor: "#CCFFFFFF", - circleWidth: '80px', - circleHeight: '80px', - iconWidth: '50px', - iconHeight: '50px', - titleSize: '20px', - baseBorderRadius: 15, - simpleToggleTitleSize: '18px' - } - - static initParams(params?) { - console.log('----initParams(params)----ing'); - UniformConfig.config = params || { - iconOnBG: "#0A59F7", - iconOffBG: "#F5F5F5", - iconOnColor: "#FFFFFF", - iconOffColor: "#404345", - baseColor: "#CCFFFFFF", - circleWidth: '80px', - circleHeight: '80px', - iconWidth: '50px', - iconHeight: '50px', - titleSize: '20px', - baseBorderRadius: 15, - simpleToggleTitleSize: '18px' - } - console.log('----initParams(params)----finish'); - } -} diff --git a/common/src/main/ets/template/common/StyleConfiguration.ts b/common/src/main/ets/template/common/StyleConfiguration.ts new file mode 100644 index 00000000..180b8c50 --- /dev/null +++ b/common/src/main/ets/template/common/StyleConfiguration.ts @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import StyleManager from '../../default/StyleManager'; + +const TAG = 'CommonTemplate-StyleConfiguration'; + +export default class StyleConfiguration { + static getIconTitleBaseStyle() { + const key: string = TAG + "-IconTitleBase"; + return StyleManager.getStyle(key, () => { + return { + marginLeft: '24vp', + marginRight: '16vp', + componentGap: '8vp', + titleSize: '24vp', + titleColor:$r("sys.color.ohos_id_color_text_secondary"), + borderRadius: '48vp', + backgroundColor: '#ffffff', + textMargin: '8vp', + textHoverHeight: '52vp', + textHoverWidth: '136vp', + textHoverRadius: '8vp', + hoverColor: 'rgba(0, 0, 0, 0.05)', + transparentColor: 'rgba(255, 255, 255, 0)', + }; + }); + } + + static getIconComponentStyle() { + const key: string = TAG + "-IconComponent"; + return StyleManager.getStyle(key, () => { + return { + circleWidth: '96vp', + circleHeight: '96vp', + iconWidth: '48vp', + iconHeight: '48vp', + iconOffBG: '#1A000000', + iconOnBG: '#FF007DFF', + iconOnColor: '#FFFFFFFF', + iconOffColor: $r("sys.color.ohos_id_color_secondary"), + hoverColor: 'rgba(0, 0, 0, 0.05)', + transparentColor: 'rgba(255, 255, 255, 0)', + }; + }); + } + + static getSimpleToggleBaseStyle() { + const key: string = TAG + "-SimpleToggleBase"; + return StyleManager.getStyle(key, () => { + return { + circleWidth: '96vp', + circleHeight: '96vp', + iconWidth: '48vp', + iconHeight: '48vp', + dragCircleWidth: '120vp', + dragCircleHeight: '120vp', + dragIconWidth: '72vp', + dragIconHeight: '72vp', + iconOffBG: '#1A000000', + iconOnBG: '#FF007DFF', + iconOnColor: '#FFFFFFFF', + iconOffColor: $r("sys.color.ohos_id_color_secondary"), + componentGap: '10vp', + titleSize: '24fp', + titleColor: $r("sys.color.ohos_id_color_text_secondary"), + textHoverWidth: '136vp', + textHoverHeight: '36vp', + textHoverRadius: '8vp', + hoverColor: 'rgba(0, 0, 0, 0.05)', + transparentColor: 'rgba(255, 255, 255, 0)', + }; + }); + } +} \ No newline at end of file diff --git a/common/src/main/ets/template/iconComponent.ets b/common/src/main/ets/template/iconComponent.ets index a190fa43..bf118848 100644 --- a/common/src/main/ets/template/iconComponent.ets +++ b/common/src/main/ets/template/iconComponent.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,23 +13,25 @@ * limitations under the License. */ -import Log from '../default/Log.ets'; -import UniformConfig from './UniformConfig.ets' +import Log from '../default/Log'; +import StyleConfiguration from './common/StyleConfiguration' -const TAG= 'iconComponent.ets' +const TAG = 'iconComponent' @Component export default struct iconComponent { - private mConfig = UniformConfig.config; @State iconOff: any = "" @State iconOn: any = "" @Prop iconOffStr: string @Prop iconOnStr: string private useIconStr = false + @State mIconIsHover: boolean = false + @Link changeSwitch: boolean + @State style: any = StyleConfiguration.getIconComponentStyle() aboutToAppear() { Log.showInfo(TAG,`aboutToAppear, ${this.changeSwitch} ${JSON.stringify(this.iconOff)} ${JSON.stringify(this.iconOn)}`) @@ -44,15 +46,25 @@ struct iconComponent { Column() { Stack() { Flex() - .backgroundColor(this.changeSwitch == false? this.mConfig.iconOffBG : this.mConfig.iconOnBG) - .clip(Circle({ width: this.mConfig.circleWidth, height: this.mConfig.circleHeight })) - .width(this.mConfig.circleWidth ) - .height(this.mConfig.circleHeight ) - Image(this.changeSwitch == false? (this.useIconStr ? this.iconOffStr : this.iconOff): (this.useIconStr ? this.iconOnStr : this.iconOn)) - .size({ width: this.mConfig.iconWidth, height: this.mConfig.iconHeight}) + .backgroundColor(this.changeSwitch? this.style.iconOnBG: this.style.iconOffBG) + .clip(new Circle({ width: this.style.circleWidth, height: this.style.circleHeight })) + .width(this.style.circleWidth) + .height(this.style.circleHeight) + Flex() + .backgroundColor(this.mIconIsHover? this.style.hoverColor: this.style.transparentColor) + .clip(new Circle({ width: this.style.circleWidth, height: this.style.circleHeight })) + .width(this.style.circleWidth) + .height(this.style.circleHeight) + Image(this.changeSwitch == false ? (this.useIconStr ? this.iconOffStr : this.iconOff) : (this.useIconStr ? this.iconOnStr : this.iconOn)) + .size({ width: this.style.iconWidth, height: this.style.iconHeight }) .objectFit(ImageFit.Contain) - }.margin({ left: 10 }) + .fillColor(this.changeSwitch ? this.style.iconOnColor : this.style.iconOffColor) + .onHover((isHover) => { + this.mIconIsHover = isHover; + }) + } + .width(this.style.circleWidth) + .height(this.style.circleHeight) } - .flexShrink(0) } } diff --git a/common/src/main/ets/template/iconTitleBase.ets b/common/src/main/ets/template/iconTitleBase.ets index 77e79173..69385c69 100644 --- a/common/src/main/ets/template/iconTitleBase.ets +++ b/common/src/main/ets/template/iconTitleBase.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,11 +13,11 @@ * limitations under the License. */ -import UniformConfig from './UniformConfig.ets' -import Log from '../default/Log.ets'; -import iconComponent from './iconComponent.ets' +import Log from '../default/Log'; +import StyleConfiguration from './common/StyleConfiguration' +import iconComponent from './iconComponent' -const TAG= 'iconTitleBase.ets' +const TAG= 'iconTitleBase' @Component export default @@ -31,11 +31,14 @@ struct iconBaseComponent { @State mTitleStr: string = "" private useIconStr = false private useTitleStr = false - private mConfig = UniformConfig.config; private mClickEvent: Function private mLongClickEvent: Function + @State mTextIsHover: boolean = false + @Link changeSwitch: boolean + @State style: any = StyleConfiguration.getIconTitleBaseStyle() + aboutToAppear() { Log.showInfo(TAG,'aboutToAppear') } @@ -45,44 +48,57 @@ struct iconBaseComponent { } build() { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - iconComponent({ - useIconStr: this.useIconStr, - iconOff: this.iconOff, - iconOn: this.iconOn, - iconOffStr: this.iconOffStr, - iconOnStr: this.iconOnStr, - changeSwitch: $changeSwitch, + Row() { + Column().width(this.style.marginLeft).height('100%').layoutWeight(0) + Row() { + Row() { + iconComponent({ + useIconStr: this.useIconStr, + iconOff: this.iconOff, + iconOn: this.iconOn, + iconOffStr: this.iconOffStr, + iconOnStr: this.iconOnStr, + changeSwitch: $changeSwitch, + }) + } + .onClick(() => { + console.log(`start clickEvent ${this.changeSwitch}`) + if (this.mClickEvent) { + this.mClickEvent() + } + console.log(`end clickEvent ${this.changeSwitch}`) }) } - .flexShrink(0) .height('100%') - .onClick(() => { - console.log(`start clickEvent ${this.changeSwitch}`) - if(this.mClickEvent){ - this.mClickEvent() + .layoutWeight(0) + Column().width(this.style.componentGap).height('100%').layoutWeight(0) + Row(){ + Row() { + Column().width(this.style.textMargin).height('100%').layoutWeight(0) + Text(this.useTitleStr ? this.mTitleStr : this.mTitle) + .fontSize(this.style.titleSize) + .fontColor(this.style.titleColor) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(2) + .layoutWeight(1) + .onHover((isHover) => { + this.mTextIsHover = isHover; + }) + Column().width(this.style.textMargin).height('100%').layoutWeight(0) } - console.log(`end clickEvent ${this.changeSwitch}`) - }) - .gesture(LongPressGesture({ repeat: false }).onAction(()=>{ - console.log(`start longClickEvent ${this.changeSwitch}`) - if(this.mLongClickEvent){ - this.mLongClickEvent() - } - console.log(`end longClickEvent ${this.changeSwitch}`) - })) - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Center }) { - Text(this.useTitleStr ? this.mTitleStr : this.mTitle) - .fontSize(this.mConfig.titleSize) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(2) - .margin({ left: 10, right: 10 }) - } - .height('100%') + .width('100%') + .height(this.style.textHoverHeight) + .width(this.style.textHoverWidth) + .backgroundColor(this.mTextIsHover? this.style.hoverColor: this.style.transparentColor) + .borderRadius(this.style.textHoverRadius) + .clip(true) + }.height('100%') + .layoutWeight(1) + Column().width(this.style.marginRight).height('100%').layoutWeight(0) } - .borderRadius(this.mConfig.baseBorderRadius) - .backgroundColor(this.mConfig.baseColor) + .borderRadius(this.style.borderRadius) + .clip(true) + .backgroundColor(this.style.backgroundColor) .height('100%') .width('100%') } diff --git a/doc/Instructions.md b/doc/Instructions.md index a5a15616..9ad3abb5 100644 --- a/doc/Instructions.md +++ b/doc/Instructions.md @@ -17,7 +17,7 @@ ``` ### 环境搭建 -打开DevEco Studio链接下载安装,安装步骤及安装说明详见开发者网站 +打开DevEco Studio链接下载安装,安装步骤及安装说明详见下载地址([下载地址](https://developer.harmonyos.com/cn/develop/deveco-studio#download)) ## 基础开发说明 ### 系统接口调用 diff --git a/entry/.gitignore b/entry/pc/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from entry/.gitignore rename to entry/pc/.gitignore diff --git a/entry/build.gradle b/entry/pc/build.gradle old mode 100755 new mode 100644 similarity index 100% rename from entry/build.gradle rename to entry/pc/build.gradle diff --git a/entry/package.json b/entry/pc/package.json old mode 100755 new mode 100644 similarity index 100% rename from entry/package.json rename to entry/pc/package.json diff --git a/entry/pc/src/main/config.json b/entry/pc/src/main/config.json new file mode 100644 index 00000000..25c8b944 --- /dev/null +++ b/entry/pc/src/main/config.json @@ -0,0 +1,91 @@ +{ + "app": { + "bundleName": "com.ohos.systemui", + "vendor": "ohos", + "version": { + "code": 1, + "name": "1.0" + }, + "singleton": true + }, + "deviceConfig": {}, + "module": { + "package": "com.ohos.systemui", + "name": ".MyApplication", + "deviceType": [ + "tablet" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "pc_entry", + "moduleType": "entry" + }, + "abilities": [ + { + "visible": true, + "srcPath": "ServiceExtAbility", + "name": ".ServiceExtAbility", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_mainability", + "label": "$string:app_name", + "type": "service" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "name": "ServiceExtAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + }, + "pages": ["pages/index"] + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS" + }, + { + "name": "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION" + }, + { + "name": "ohos.permission.NOTIFICATION_CONTROLLER" + }, + { + "name": "ohos.permission.GET_WIFI_INFO" + }, + { + "name": "ohos.permission.SET_WIFI_INFO" + }, + { + "name": "ohos.permission.MANAGE_WIFI_CONNECTION" + }, + { + "name": "ohos.permission.GET_NETWORK_INFO" + }, + { + "name": "ohos.permission.USE_BLUETOOTH" + }, + { + "name": "ohos.permission.DISCOVER_BLUETOOTH" + }, + { + "name": "ohos.permission.MANAGE_BLUETOOTH" + }, + { + "name": "ohos.permission.CAPTURE_SCREEN" + }, + { + "name": "ohos.permission.MANAGE_SECURE_SETTINGS" + } + ] + } +} \ No newline at end of file diff --git a/entry/pc/src/main/ets/AbilityStage.ts b/entry/pc/src/main/ets/AbilityStage.ts new file mode 100644 index 00000000..288fb504 --- /dev/null +++ b/entry/pc/src/main/ets/AbilityStage.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" +import Log from '../../../../../common/src/main/ets/default/Log' + +const TAG = "SystemUI_AbilityStage" + +export default class MainAbilityStage extends AbilityStage { + onCreate() { + Log.showInfo(TAG, "onCreate") + } +} \ No newline at end of file diff --git a/entry/pc/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts b/entry/pc/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts new file mode 100644 index 00000000..b9b90861 --- /dev/null +++ b/entry/pc/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import ServiceExtension from '@ohos.application.ServiceExtensionAbility' +import Log from '../../../../../../common/src/main/ets/default/Log' +import AbilityManager from '../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import initSystemUi from '../../../../../../common/src/main/ets/default/InitSystemUi' + +const TAG = "SystemUI_ServiceExtAbility" + +var statusBarWant = { + "bundleName": "com.ohos.systemui", + "abilityName": "com.ohos.systemui.statusbar.ServiceExtAbility" +} + +var navigationBarWant = { + "bundleName": "com.ohos.systemui", + "abilityName": "com.ohos.systemui.navigationbar.ServiceExtAbility" +} + +var volumePanelWant = { + "bundleName": "com.ohos.systemui", + "abilityName": "com.ohos.systemui.volumepanel.ServiceExtAbility" +} + +var controlPanelWant = { + "bundleName": "com.ohos.systemui", + "abilityName": "com.ohos.systemui.controlpanel.ServiceExtAbility" +} + +var notificationPanelWant = { + "bundleName": "com.ohos.systemui", + "abilityName": "com.ohos.systemui.notificationpanel.ServiceExtAbility" +} + +class ServiceExtAbility extends ServiceExtension { + onCreate(want) { + Log.showInfo(TAG, `api8New onCreate, want: ${JSON.stringify(want)}`) + initSystemUi(this.context); + AbilityManager.setContext(AbilityManager.ABILITY_NAME_ENTRY, this.context) + AbilityManager.startAbility(statusBarWant) + AbilityManager.startAbility(navigationBarWant) + AbilityManager.startAbility(volumePanelWant) + AbilityManager.startAbility(controlPanelWant) + AbilityManager.startAbility(notificationPanelWant) + } + + onDestroy() { + Log.showInfo(TAG, 'api8New onDestroy') + } +} + +export default ServiceExtAbility \ No newline at end of file diff --git a/entry/src/main/ets/default/app.ets b/entry/pc/src/main/ets/ServiceExtAbility/app.ets similarity index 100% rename from entry/src/main/ets/default/app.ets rename to entry/pc/src/main/ets/ServiceExtAbility/app.ets diff --git a/entry/src/main/ets/default/pages/index.ets b/entry/pc/src/main/ets/ServiceExtAbility/pages/index.ets similarity index 93% rename from entry/src/main/ets/default/pages/index.ets rename to entry/pc/src/main/ets/ServiceExtAbility/pages/index.ets index 936ef95d..d2ddea6c 100644 --- a/entry/src/main/ets/default/pages/index.ets +++ b/entry/pc/src/main/ets/ServiceExtAbility/pages/index.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/entry/pc/src/main/resources/base/element/string.json b/entry/pc/src/main/resources/base/element/string.json new file mode 100644 index 00000000..c962e718 --- /dev/null +++ b/entry/pc/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SystemUI" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "description_mainability", + "value": "SystemUI ServiceExtension" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/icon.png b/entry/pc/src/main/resources/base/media/icon.png similarity index 100% rename from entry/src/main/resources/base/media/icon.png rename to entry/pc/src/main/resources/base/media/icon.png diff --git a/entry/phone/.gitignore b/entry/phone/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/entry/phone/.gitignore @@ -0,0 +1 @@ +/build diff --git a/product/navigationBar/build.gradle b/entry/phone/build.gradle similarity index 82% rename from product/navigationBar/build.gradle rename to entry/phone/build.gradle index 38239b95..b3f8b49d 100644 --- a/product/navigationBar/build.gradle +++ b/entry/phone/build.gradle @@ -4,11 +4,9 @@ ohos { defaultConfig { compatibleSdkVersion rootProject.ext.version.compatibleSdk } - entryModules "entry" } dependencies { - entryImplementation project(':entry') implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testCompile 'junit:junit:4.12' } diff --git a/product/navigationBar/package.json b/entry/phone/package.json similarity index 100% rename from product/navigationBar/package.json rename to entry/phone/package.json diff --git a/entry/phone/src/main/config.json b/entry/phone/src/main/config.json new file mode 100644 index 00000000..daa15157 --- /dev/null +++ b/entry/phone/src/main/config.json @@ -0,0 +1,88 @@ +{ + "app": { + "bundleName": "com.ohos.systemui", + "vendor": "ohos", + "version": { + "code": 1, + "name": "1.0" + }, + "singleton": true + }, + "deviceConfig": {}, + "module": { + "package": "com.ohos.systemui", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "phone_entry", + "moduleType": "entry" + }, + "abilities": [ + { + "visible": true, + "srcPath": "ServiceExtAbility", + "name": ".ServiceExtAbility", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_mainability", + "label": "$string:app_name", + "type": "service" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "name": "ServiceExtAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + }, + "pages": ["pages/index"] + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS" + }, + { + "name": "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION" + }, + { + "name": "ohos.permission.NOTIFICATION_CONTROLLER" + }, + { + "name": "ohos.permission.GET_WIFI_INFO" + }, + { + "name": "ohos.permission.SET_WIFI_INFO" + }, + { + "name": "ohos.permission.MANAGE_WIFI_CONNECTION" + }, + { + "name": "ohos.permission.USE_BLUETOOTH" + }, + { + "name": "ohos.permission.DISCOVER_BLUETOOTH" + }, + { + "name": "ohos.permission.MANAGE_BLUETOOTH" + }, + { + "name": "ohos.permission.CAPTURE_SCREEN" + }, + { + "name": "ohos.permission.MANAGE_SECURE_SETTINGS" + } + ] + } +} \ No newline at end of file diff --git a/entry/phone/src/main/ets/AbilityStage.ts b/entry/phone/src/main/ets/AbilityStage.ts new file mode 100644 index 00000000..288fb504 --- /dev/null +++ b/entry/phone/src/main/ets/AbilityStage.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" +import Log from '../../../../../common/src/main/ets/default/Log' + +const TAG = "SystemUI_AbilityStage" + +export default class MainAbilityStage extends AbilityStage { + onCreate() { + Log.showInfo(TAG, "onCreate") + } +} \ No newline at end of file diff --git a/entry/phone/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts b/entry/phone/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts new file mode 100644 index 00000000..38ddf9ec --- /dev/null +++ b/entry/phone/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import ServiceExtension from '@ohos.application.ServiceExtensionAbility' +import Log from '../../../../../../common/src/main/ets/default/Log' +import AbilityManager from '../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import initSystemUi from '../../../../../../common/src/main/ets/default/InitSystemUi' + +const TAG = "SystemUI_ServiceExtAbility" + +var statusBarWant = { + "bundleName": "com.ohos.systemui", + "abilityName": "com.ohos.systemui.statusbar.ServiceExtAbility" +} + +var navigationBarWant = { + "bundleName": "com.ohos.systemui", + "abilityName": "com.ohos.systemui.navigationbar.ServiceExtAbility" +} + +var volumePanelWant = { + "bundleName": "com.ohos.systemui", + "abilityName": "com.ohos.systemui.volumepanel.ServiceExtAbility" +} + +var dropdownPanelWant = { + "bundleName": "com.ohos.systemui", + "abilityName": "com.ohos.systemui.dropdownpanel.ServiceExtAbility" +} + +class ServiceExtAbility extends ServiceExtension { + onCreate(want) { + Log.showInfo(TAG, `api8New onCreate, want: ${JSON.stringify(want)}`) + initSystemUi(this.context) + AbilityManager.setContext(AbilityManager.ABILITY_NAME_ENTRY, this.context) + AbilityManager.startAbility(statusBarWant) + AbilityManager.startAbility(navigationBarWant) + AbilityManager.startAbility(volumePanelWant) + AbilityManager.startAbility(dropdownPanelWant) + } + + onDestroy() { + Log.showInfo(TAG, 'api8New onDestroy') + } +} + +export default ServiceExtAbility \ No newline at end of file diff --git a/common/src/main/ets/default/DateAndTimeUtil.ets b/entry/phone/src/main/ets/ServiceExtAbility/app.ets similarity index 67% rename from common/src/main/ets/default/DateAndTimeUtil.ets rename to entry/phone/src/main/ets/ServiceExtAbility/app.ets index d0392fa1..e105593e 100644 --- a/common/src/main/ets/default/DateAndTimeUtil.ets +++ b/entry/phone/src/main/ets/ServiceExtAbility/app.ets @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,12 @@ * limitations under the License. */ -export class DateAndTimeUtil { - concatTime(hours, minutes) { - return `${this.fill(hours)}:${this.fill(minutes)}`; - }; - fill(value) { - return (value > 9 ? "" : "0") + value; - }; +export default { + onCreate() { + console.info('SystemUI entry Application onDestroy') + }, + onDestroy() { + console.info('SystemUI entry Application onDestroy') + }, } - -let dateAndTimeUtil = new DateAndTimeUtil(); - -export default dateAndTimeUtil as DateAndTimeUtil diff --git a/entry/phone/src/main/ets/ServiceExtAbility/pages/index.ets b/entry/phone/src/main/ets/ServiceExtAbility/pages/index.ets new file mode 100644 index 00000000..d2ddea6c --- /dev/null +++ b/entry/phone/src/main/ets/ServiceExtAbility/pages/index.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Index { + + build() { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/entry/phone/src/main/resources/base/element/string.json b/entry/phone/src/main/resources/base/element/string.json new file mode 100644 index 00000000..c962e718 --- /dev/null +++ b/entry/phone/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SystemUI" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "description_mainability", + "value": "SystemUI ServiceExtension" + } + ] +} \ No newline at end of file diff --git a/product/navigationBar/src/main/resources/base/media/icon.png b/entry/phone/src/main/resources/base/media/icon.png similarity index 100% rename from product/navigationBar/src/main/resources/base/media/icon.png rename to entry/phone/src/main/resources/base/media/icon.png diff --git a/infra/config_exts.gradle b/infra/config_exts.gradle index f84c6933..eb7b7f5e 100644 --- a/infra/config_exts.gradle +++ b/infra/config_exts.gradle @@ -1,6 +1,6 @@ ext { version = [ compileSdk: 8, - compatibleSdk: 4 + compatibleSdk: 8 ] } \ No newline at end of file diff --git a/product/navigationBar/.gitignore b/product/default/navigationBar/.gitignore similarity index 100% rename from product/navigationBar/.gitignore rename to product/default/navigationBar/.gitignore diff --git a/product/default/navigationBar/build.gradle b/product/default/navigationBar/build.gradle new file mode 100644 index 00000000..9ca65e26 --- /dev/null +++ b/product/default/navigationBar/build.gradle @@ -0,0 +1,16 @@ +apply plugin: 'com.huawei.ohos.hap' +ohos { + compileSdkVersion rootProject.ext.version.compileSdk + defaultConfig { + compatibleSdkVersion rootProject.ext.version.compatibleSdk + } + entryModules "phone_entry,pc_entry" +} + +dependencies { + entryImplementation project(':phone_entry') + entryImplementation project(':pc_entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testCompile 'junit:junit:4.12' + implementation project(':features:navigationservice') +} diff --git a/product/notificationmanagement/package.json b/product/default/navigationBar/package.json similarity index 100% rename from product/notificationmanagement/package.json rename to product/default/navigationBar/package.json diff --git a/product/navigationBar/src/main/config.json b/product/default/navigationBar/src/main/config.json similarity index 75% rename from product/navigationBar/src/main/config.json rename to product/default/navigationBar/src/main/config.json index 06021a60..21b0b03b 100644 --- a/product/navigationBar/src/main/config.json +++ b/product/default/navigationBar/src/main/config.json @@ -5,30 +5,31 @@ "version": { "code": 1, "name": "1.0" - } + }, + "singleton": true }, "deviceConfig": {}, "module": { "package": "com.ohos.systemui.navigationbar", "name": ".MyApplication", "deviceType": [ - "phone" + "phone", "tablet" ], "distro": { "deliveryWithInstall": true, - "moduleName": "navigationBar", + "moduleName": "default_navigationBar", "moduleType": "feature" }, "abilities": [ { "visible": true, - "name": "com.ohos.systemui.navigationbar.MainAbility", + "name": "com.ohos.systemui.navigationbar.ServiceExtAbility", "icon": "$media:icon", "description": "$string:mainability_description", "label": "$string:app_name", - "type": "page", + "type": "service", "launchType": "singleton", - "srcPath": "default", + "srcPath": "ServiceExtAbility", "srcLanguage": "ets" } ], @@ -40,13 +41,12 @@ "pages": [ "pages/index" ], - "name": "default", + "name": "ServiceExtAbility", "window": { "designWidth": 720, "autoDesignWidth": false } } - ], - "srcPath": "default" + ] } } \ No newline at end of file diff --git a/product/default/navigationBar/src/main/ets/AbilityStage.ts b/product/default/navigationBar/src/main/ets/AbilityStage.ts new file mode 100644 index 00000000..e89d59b8 --- /dev/null +++ b/product/default/navigationBar/src/main/ets/AbilityStage.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" +import Log from '../../../../../../common/src/main/ets/default/Log' + +const TAG = "NavigationBar_AbilityStage" +export default class MainAbilityStage extends AbilityStage { + onCreate() { + Log.showInfo(TAG, "onCreate") + } +} \ No newline at end of file diff --git a/product/default/navigationBar/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts b/product/default/navigationBar/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts new file mode 100644 index 00000000..1aba4bcc --- /dev/null +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ServiceExtension from '@ohos.application.ServiceExtensionAbility' +import Log from '../../../../../../../common/src/main/ets/default/Log' +import WindowManager, { WindowType } from '../../../../../../../common/src/main/ets/default/WindowManager' +import AbilityManager from '../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import NavBarConfiguration from './common/NavBarConfiguration' + +const TAG = "NavigationBar_ServiceExtAbility" + +class ServiceExtAbility extends ServiceExtension { + async onCreate(want) { + Log.showInfo(TAG, `api8New onCreate, want: ${JSON.stringify(want)}`); + AbilityManager.setContext(AbilityManager.ABILITY_NAME_NAVIGATION_BAR, this.context) + + let configInfo = await NavBarConfiguration.getConfiguration(); + if (configInfo.showNavHorizontal) { + if (configInfo.maxWidth > configInfo.maxHeight) { // Pad、PC Mode + configInfo.realHeight = 44 * configInfo.maxWidth / 1280 + } else { // Phone Mode + configInfo.realHeight = 36 * configInfo.maxWidth / 360 + } + configInfo.minHeight = configInfo.realHeight + if (configInfo.yCoordinate > 0) { + configInfo.yCoordinate = configInfo.maxHeight - configInfo.realHeight + } + } else { + if (configInfo.maxWidth > configInfo.maxHeight) { // Pad、PC Mode + configInfo.realWidth = 44 * configInfo.maxWidth / 1280 + } else { // Phone Mode + configInfo.realWidth = 36 * configInfo.maxWidth / 360 + } + configInfo.minHeight = configInfo.realWidth + if (configInfo.xCoordinate > 0) { + configInfo.xCoordinate = configInfo.maxWidth - configInfo.realWidth + } + } + AbilityManager.setAbilityData(AbilityManager.ABILITY_NAME_NAVIGATION_BAR, 'config', configInfo) + Log.showInfo(TAG, `api8New onCreate, configInfo: ${JSON.stringify(configInfo)}`) + + let navigationBarRect = { + left: configInfo.xCoordinate, + top: configInfo.yCoordinate, + width: configInfo.realWidth, + height: configInfo.realHeight + } + WindowManager.createWindow(this.context, WindowType.NAVIGATION_BAR, navigationBarRect, "pages/index") + .then(() => { + Log.showInfo(TAG, `api8New onCreate, createWindow success.`); + WindowManager.showWindow(WindowType.NAVIGATION_BAR); + }) + .catch((err) => Log.showError(TAG, `Can't create window, err:${err}`)); + } + + onDestroy() { + Log.showInfo(TAG, 'api8New onDestroy'); + } +} + +export default ServiceExtAbility \ No newline at end of file diff --git a/product/statusbar/src/main/ets/default/app.ets b/product/default/navigationBar/src/main/ets/ServiceExtAbility/app.ets similarity index 52% rename from product/statusbar/src/main/ets/default/app.ets rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/app.ets index 070c7f9a..72ec8953 100644 --- a/product/statusbar/src/main/ets/default/app.ets +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/app.ets @@ -12,19 +12,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import WindowManager from '../../../../../../common/src/main/ets/default/WindowManager.ets' -import StatusBarConfiguration from '../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/common/StatusBarConfiguration.ets'; + +import AbilityManager from '../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import configManager from '../../../../../../../features/navigationservice/src/main/ets/com/ohos/navigationservice/ConfigManager' + +let mConfigManager = configManager export default { async onCreate() { - console.info('SystemUI statusBar Application onCreate') - let val = await StatusBarConfiguration.getConfiguration(); - let mWindowManager = new WindowManager(); - await mWindowManager.initWindowManager(); - await mWindowManager.initWindowMin(val.realWidth, val.realHeight, val.xCoordinate, val.yCoordinate) - + console.info('SystemUI navigationBar Application onCreate') + let configInfo = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_NAVIGATION_BAR, 'config') + AppStorage.SetAndLink("showNavHorizontal", configInfo.showNavHorizontal) + mConfigManager.initConfig() }, onDestroy() { - console.info('SystemUI statusBar Application onDestroy') + console.info('SystemUI navigationBar Application onDestroy') }, -} +} \ No newline at end of file diff --git a/product/navigationBar/src/main/ets/default/common/NavBarConfiguration.ets b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/NavBarConfiguration.ts similarity index 88% rename from product/navigationBar/src/main/ets/default/common/NavBarConfiguration.ets rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/common/NavBarConfiguration.ts index 38e9bd2d..53cad273 100644 --- a/product/navigationBar/src/main/ets/default/common/NavBarConfiguration.ets +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/NavBarConfiguration.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,8 +14,8 @@ */ import display from '@ohos.display'; -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; -import ResourceUtil from '../../../../../../../common/src/main/ets/default/ResourceUtil.ets'; +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import ResourceUtil from '../../../../../../../../common/src/main/ets/default/ResourceUtil'; const TAG = 'NavBarConfiguration'; var directionNav; @@ -46,13 +46,14 @@ enum Position { class NavBarConfiguration { async initNavBarConfiguration() { Log.showInfo(TAG, 'initNavBarConfiguration'); - minHeight = AppStorage.SetAndLink("minNavHeight", 0); + minHeight = 0; await display.getDefaultDisplay() .then(dis => { + Log.showInfo(TAG, `initNavBarConfiguration dis ${JSON.stringify(dis)}`); maxWidth = dis.width; maxHeight = dis.height; - Log.showInfo(TAG, `initNavBarConfiguration maxWidth ${maxWidth} maxHeight ${maxHeight} minHeight ${minHeight.get()}`); + Log.showInfo(TAG, `initNavBarConfiguration maxWidth ${maxWidth} maxHeight ${maxHeight} minHeight ${minHeight}`); }) } @@ -94,9 +95,10 @@ class NavBarConfiguration { await this.getDirectionAndPosition(); + let showNavHorizontal = false; if (navbarPosition == Position.TOP_POSITION || navbarPosition == Position.BOTTOM_POSITION) { - AppStorage.Set("showNavHorizontal", true); - minHeight.set(parseInt(navShortSideLength)); + showNavHorizontal = true; + minHeight = parseInt(navShortSideLength); Log.showInfo(TAG, 'TOP_POSITION = ' + 2); if (statusbarPosition == Position.LEFT_POSITION || statusbarPosition == Position.RIGHT_POSITION) { realWidth = parseInt(maxWidth) - parseInt(statusShortSideLength); @@ -117,8 +119,8 @@ class NavBarConfiguration { Log.showInfo(TAG, 'BOTTOM_POSITION = ' + yCoordinate); } } else if (navbarPosition == Position.LEFT_POSITION || navbarPosition == Position.RIGHT_POSITION) { - AppStorage.Set("showNavHorizontal", false); - minHeight.set(parseInt(navShortSideLength)); + showNavHorizontal = false; + minHeight = parseInt(navShortSideLength); if (statusbarPosition == Position.TOP_POSITION || statusbarPosition == Position.BOTTOM_POSITION) { realHeight = parseInt(maxHeight) - parseInt(statusShortSideLength); } else { @@ -140,6 +142,10 @@ class NavBarConfiguration { Log.showInfo(TAG, `initWindowManager xCoordinate ${xCoordinate} yCoordinate ${yCoordinate}`); Log.showInfo(TAG, `initWindowManager realWidth ${realWidth} realHeight ${realHeight}`); var configuration = { + maxWidth: maxWidth, + maxHeight: maxHeight, + minHeight: minHeight, + showNavHorizontal: showNavHorizontal, realWidth: realWidth, realHeight: realHeight, xCoordinate: xCoordinate, diff --git a/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/StyleConfiguration.ts b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/StyleConfiguration.ts new file mode 100644 index 00000000..5156bc40 --- /dev/null +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/StyleConfiguration.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import StyleManager from '../../../../../../../../common/src/main/ets/default/StyleManager'; + +const TAG = 'NavigationBar-StyleConfiguration'; + +export default class StyleConfiguration { + static getKeyButtonStyle() { + const key: string = TAG + "-KeyButton"; + return StyleManager.getStyle(key, () => { + return { + buttonWidth: $r('app.float.navigation_bar_button_width'), + buttonHeight: $r('app.float.navigation_bar_button_height'), + buttonBorderRadius: $r('app.float.navigation_bar_button_radius'), + buttonIconWidth: $r('app.float.navigation_bar_button_icon_width'), + buttonIconHeight: $r('app.float.navigation_bar_button_icon_height'), + }; + }); + } +} \ No newline at end of file diff --git a/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/StyleManager.ts b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/StyleManager.ts new file mode 100644 index 00000000..4782e759 --- /dev/null +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/StyleManager.ts @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager'; +import StyleConfiguration from './StyleConfiguration' + +const TAG = 'StatusBar-StyleManager'; + +export default class StyleManager { + static PAD_STANDARD_DISPLAY_WIDTH: number = 1280; + static PAD_STANDARD_DISPLAY_HEIGHT: number = 800; + static PHONE_STANDARD_DISPLAY_WIDTH: number = 720; + static PHONE_STANDARD_DISPLAY_HEIGHT: number = 1280; + static maxWidth: number = StyleManager.PAD_STANDARD_DISPLAY_WIDTH; + static rumMode: string = 'pad'; + + static setPadStyle() { + Log.showInfo(TAG, `setPadStyle`) + + let config = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_NAVIGATION_BAR, 'config'); + StyleManager.maxWidth = config.maxWidth; + StyleManager.rumMode = 'pad' + + // keyButton + { + let style: any = StyleConfiguration.getKeyButtonStyle(); + style.buttonWidth = StyleManager.calcScaleSizePx(88); + style.buttonHeight = StyleManager.calcScaleSizePx(44); + style.buttonBorderRadius = StyleManager.calcScaleSizePx(22); + style.buttonIconWidth = StyleManager.calcScaleSizePx(15); + style.buttonIconHeight = StyleManager.calcScaleSizePx(15); + } + } + + static setPhoneStyle() { + Log.showInfo(TAG, `setPhoneStyle`) + + let config = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_NAVIGATION_BAR, 'config'); + StyleManager.maxWidth = config.maxWidth; + StyleManager.rumMode = 'phone' + + // keyButton + { + let style: any = StyleConfiguration.getKeyButtonStyle(); + style.buttonWidth = StyleManager.calcScaleSizePx(144); + style.buttonHeight = StyleManager.calcScaleSizePx(72); + style.buttonBorderRadius = StyleManager.calcScaleSizePx(36); + style.buttonIconWidth = StyleManager.calcScaleSizePx(24); + style.buttonIconHeight = StyleManager.calcScaleSizePx(24); + } + } + + static number2px(n: number): string { + return n.toString() + 'px'; + } + + static calcScaleSize(n: number): number { + return n * StyleManager.maxWidth / (StyleManager.rumMode == 'pad' ? StyleManager.PAD_STANDARD_DISPLAY_WIDTH : StyleManager.PHONE_STANDARD_DISPLAY_WIDTH); + } + + static calcScaleSizePx(n: number): string { + return StyleManager.number2px(StyleManager.calcScaleSize(n)); + } +} \ No newline at end of file diff --git a/product/navigationBar/src/main/ets/default/common/constants.ets b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/constants.ts similarity index 81% rename from product/navigationBar/src/main/ets/default/common/constants.ets rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/common/constants.ts index 8bb0f4e0..833cea42 100644 --- a/product/navigationBar/src/main/ets/default/common/constants.ets +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/constants.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,7 +24,10 @@ class Constants{ static THREE_TEMPLATE: string = '1fr 1fr 1fr'; static ONE_ICON_LAYOUT: number = 1; static THREE_ICON_LAYOUT: number = 3; - static IMAGE_WIDTH: number = 32; - static IMAGE_HEIGHT: number = 32; - static BUTTON_WIDTH: number = 100; -} \ No newline at end of file +} + +export class NavigationBarComponentData { + isEnable: boolean = true; + backgroundColor: string = "#00000000"; + contentColor: string = "#FFFFFFFF"; +} diff --git a/product/navigationBar/src/main/ets/default/common/utils/configReader.ets b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/utils/configReader.ts similarity index 89% rename from product/navigationBar/src/main/ets/default/common/utils/configReader.ets rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/common/utils/configReader.ts index 278d85df..c230742d 100644 --- a/product/navigationBar/src/main/ets/default/common/utils/configReader.ets +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/common/utils/configReader.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,10 +13,10 @@ * limitations under the License. */ import Fileio from '@ohos.fileio'; -import Log from '../../../../../../../../common/src/main/ets/default/Log.ets' +import Log from '../../../../../../../../../common/src/main/ets/default/Log' const DEFAULT_LAYOUT_INFO_FILE_PATH = "/data/accounts/account_0/applications/com.ohos.systemui/" + - "com.ohos.systemui.navigationbar/assets/navigationBar/resources/rawfile/navigationBarLayoutConfig.json"; + "com.ohos.systemui.navigationbar/assets/default_navigationBar/resources/rawfile/navigationBarLayoutConfig.json"; const READ_DATA_SIZE = 4096; const TAG = "ConfigReader"; diff --git a/product/navigationBar/src/main/ets/default/i18n/en-US.json b/product/default/navigationBar/src/main/ets/ServiceExtAbility/i18n/en-US.json similarity index 100% rename from product/navigationBar/src/main/ets/default/i18n/en-US.json rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/i18n/en-US.json diff --git a/product/navigationBar/src/main/ets/default/i18n/zh-CN.json b/product/default/navigationBar/src/main/ets/ServiceExtAbility/i18n/zh-CN.json similarity index 100% rename from product/navigationBar/src/main/ets/default/i18n/zh-CN.json rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/i18n/zh-CN.json diff --git a/product/navigationBar/src/main/ets/default/pages/index.ets b/product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/index.ets similarity index 50% rename from product/navigationBar/src/main/ets/default/pages/index.ets rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/index.ets index 0feb07bc..c53ccd38 100644 --- a/product/navigationBar/src/main/ets/default/pages/index.ets +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/index.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,13 +13,16 @@ * limitations under the License. */ -import Three from './threeLayout.ets' -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; -import HeightConfigUtils from '../../../../../../../common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ets'; +import Three from './threeLayout' +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import CommonStyleManager from '../../../../../../../../common/src/main/ets/default/StyleManager' +import NavigationBarViewModel from '../viewmodel/NavigationBarViewModel'; +import {NavigationBarComponentData} from '../common/constants' +import StyleManager from '../common/StyleManager' const STORAGE_NAVIGATION_TYPE = 'navigationType' -let mHeightConfigUtils; const TAG = 'NavigationBar-Index'; @Entry @@ -28,6 +31,7 @@ struct Index { @StorageLink('navigationLayoutConfig') mConfig: any = {} @StorageLink('minNavHeight') minNavHeight: number = 32 @StorageLink("showNavHorizontal") showNavHorizontal: boolean = true + @State mNavigationBarComponentData: NavigationBarComponentData = new NavigationBarComponentData() onBackPress(): boolean { @@ -36,12 +40,24 @@ struct Index { aboutToAppear() { Log.showInfo(TAG, `aboutToAppear Start`) - let NavCoefficient = AppStorage.SetAndLink("NavCoefficient", 1.0); - NavCoefficient.set(mHeightConfigUtils.getNavHCoefficient()); + + setAppBgColor('#00000000') + CommonStyleManager.setAbilityPageName(TAG) + let configInfo = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_NAVIGATION_BAR, 'config') + if (configInfo.maxWidth > configInfo.maxHeight) { // Pad、PC Mode + StyleManager.setPadStyle() + } else { // Phone Mode + StyleManager.setPhoneStyle() + } + + let navigationBarViewModelInstance = NavigationBarViewModel.getInstance(); + navigationBarViewModelInstance.install(); + this.mNavigationBarComponentData = navigationBarViewModelInstance.getNavigationBarComponentData(); } aboutToDisappear() { Log.showInfo(TAG, `aboutToDisAppear`) + NavigationBarViewModel.getInstance().uninstall() } build() { @@ -51,7 +67,7 @@ struct Index { .width('100%') .height('100%') .constraintSize({ minHeight: this.minNavHeight + 'px'}) - .backgroundColor($r('app.color.index_background')) + .backgroundColor(this.mNavigationBarComponentData.backgroundColor) .padding(this.showNavHorizontal ? { left: '18%', right: '18%' } : { top: '18%', bottom: '18%' }) } } diff --git a/product/navigationBar/src/main/ets/default/pages/keyButton.ets b/product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/keyButton.ets similarity index 61% rename from product/navigationBar/src/main/ets/default/pages/keyButton.ets rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/keyButton.ets index 5b221f2b..6629e4b0 100644 --- a/product/navigationBar/src/main/ets/default/pages/keyButton.ets +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/keyButton.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,10 +13,12 @@ * limitations under the License. */ -import keyCodeEvent from '../../../../../../../features/navigationservice/src/main/ets/com/ohos/navigationservice/KeyCodeEvent.ets'; -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; -import Constants from '../common/constants.ets' - +import keyCodeEvent from '../../../../../../../../features/navigationservice/src/main/ets/com/ohos/navigationservice/KeyCodeEvent'; +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import Constants from '../common/constants' +import StyleConfiguration from '../common/StyleConfiguration' +import NavigationBarViewModel from '../viewmodel/NavigationBarViewModel'; +import {NavigationBarComponentData} from '../common/constants' const TAG = 'NavigationBar-KeyButton'; @@ -26,8 +28,10 @@ export default struct keyButton { private uri: any; @Prop keyCode: number; @State backGroundColor: any = $r('app.color.button_default_background'); - @StorageLink('NavCoefficient') NavCoefficient:number = 1.0 @StorageLink("showNavHorizontal") showNavHorizontal: boolean = AppStorage.SetAndLink("showNavHorizontal", true).get(); + @State mNavigationBarComponentData: NavigationBarComponentData = NavigationBarViewModel.getInstance() + .getNavigationBarComponentData() + @State style: any = StyleConfiguration.getKeyButtonStyle() aboutToAppear() { Log.showInfo(TAG, `aboutToAppear Start`) @@ -40,17 +44,21 @@ export default struct keyButton { build() { Stack({ alignContent: Alignment.Center }) { Flex() {} - .borderRadius($r('app.float.button_radius')) + .borderRadius(this.style.buttonBorderRadius) .width('100%') .height('100%') .backgroundColor(this.backGroundColor) Image(this.uri) .objectFit(ImageFit.Contain) - .size({ width: Constants.IMAGE_WIDTH*this.NavCoefficient, height:Constants.IMAGE_HEIGHT*this.NavCoefficient }) + .size({ + width: this.style.buttonIconWidth, + height: this.style.buttonIconHeight + }) + .fillColor(this.mNavigationBarComponentData.contentColor) } .onTouch(this.onKeyTouch.bind(this)) - .width(this.showNavHorizontal ? Constants.BUTTON_WIDTH*this.NavCoefficient : '100%') - .height(this.showNavHorizontal ? '100%' : Constants.BUTTON_WIDTH*this.NavCoefficient ) + .width(this.showNavHorizontal ? this.style.buttonWidth : this.style.buttonHeight) + .height(this.showNavHorizontal ? this.style.buttonHeight : this.style.buttonWidth) } private onKeyTouch(event:TouchEvent) { diff --git a/product/navigationBar/src/main/ets/default/pages/oneLayout.ets b/product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/oneLayout.ets similarity index 83% rename from product/navigationBar/src/main/ets/default/pages/oneLayout.ets rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/oneLayout.ets index 20b0a02d..0909c6e9 100644 --- a/product/navigationBar/src/main/ets/default/pages/oneLayout.ets +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/oneLayout.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,14 +13,14 @@ * limitations under the License. */ -import keyButton from './keyButton.ets'; -import Constants from '../common/constants.ets' -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; +import keyButton from './keyButton'; +import Constants from '../common/constants' +import Log from '../../../../../../../../common/src/main/ets/default/Log'; const TAG = 'NavigationBar-OneLayout'; let KeyCodeArr: any[] = [ { - "uri": $r('app.media.ic_navigation_home'), + "uri": $r('app.media.ic_systemui_home'), "keyCode": Constants.KEYCODE_HOME }]; diff --git a/product/navigationBar/src/main/ets/default/pages/threeLayout.ets b/product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/threeLayout.ets similarity index 76% rename from product/navigationBar/src/main/ets/default/pages/threeLayout.ets rename to product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/threeLayout.ets index 9027e19f..4af6d62f 100644 --- a/product/navigationBar/src/main/ets/default/pages/threeLayout.ets +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/pages/threeLayout.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,22 +13,22 @@ * limitations under the License. */ -import keyButton from './keyButton.ets'; -import Constants from '../common/constants.ets' -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; +import keyButton from './keyButton'; +import Constants from '../common/constants' +import Log from '../../../../../../../../common/src/main/ets/default/Log'; const TAG = 'NavigationBar-ThreeLayout'; let KeyCodeArr: any[] = [ { - "uri": $r('app.media.ic_navigation_back'), + "uri": $r('app.media.ic_systemui_back'), "keyCode": Constants.KEYCODE_BACK }, { - "uri": $r('app.media.ic_navigation_home'), + "uri": $r('app.media.ic_systemui_home'), "keyCode": Constants.KEYCODE_HOME }, { - "uri": $r('app.media.ic_navigation_recent'), + "uri": $r('app.media.ic_systemui_recent'), "keyCode": Constants.KEYCODE_RECENT }]; @@ -50,7 +50,9 @@ struct threeLayout { Grid() { ForEach(KeyCodeArr, (item: any) => { GridItem() { - keyButton({ uri: item.uri, keyCode: item.keyCode }) + Row() { + keyButton({ uri: item.uri, keyCode: item.keyCode }) + }.height('100%') } .height('100%') .constraintSize({ minHeight: this.minNavHeight + 'px'}) @@ -64,7 +66,9 @@ struct threeLayout { Grid() { ForEach(KeyCodeArr, (item: any) => { GridItem() { - keyButton({ uri: item.uri, keyCode: item.keyCode }) + Column() { + keyButton({ uri: item.uri, keyCode: item.keyCode }) + }.width('100%') } .width('100%') .constraintSize({ minHeight: this.minNavHeight + 'px'}) diff --git a/product/default/navigationBar/src/main/ets/ServiceExtAbility/viewmodel/NavigationBarViewModel.ts b/product/default/navigationBar/src/main/ets/ServiceExtAbility/viewmodel/NavigationBarViewModel.ts new file mode 100644 index 00000000..6643e0c5 --- /dev/null +++ b/product/default/navigationBar/src/main/ets/ServiceExtAbility/viewmodel/NavigationBarViewModel.ts @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import WindowManager, { WindowType } from '../../../../../../../../common/src/main/ets/default/WindowManager'; +import getSingleInstance from '../../../../../../../../common/src/main/ets/default/SingleInstanceHelper'; +import TintStateManager, {TintState, TintStateListener +} from '../../../../../../../../common/src/main/ets/default/TintStateManager'; +import {NavigationBarComponentData} from '../common/constants'; +import featureAbility from '@ohos.ability.featureAbility'; +import settings from '@ohos.settings'; +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager'; +import CommonConstants from "../../../../../../../../common/src/main/ets/default/Constants"; + +const TAG = 'NavigationBarViewModel'; + +const NAVIGATION_BAE_VIEW_MODEL_KEY = 'AppStorage_NavigationBarViewModel'; + +const NavigationBarComponentDataKey = 'AppStorage_NavigationBarComponentData'; + +export default class NavigationBarViewModel { + private settingDataKey = 'settings.display.navigationbar_status'; + private urivar: string = null; + private helper: any = null; + private navigationBarStatusDefaultValue: string = '1'; + private isDisplay = true; + mNavigationBarComponentData?: NavigationBarComponentData = { + ...new NavigationBarComponentData() + }; + mUseCount?: number = 0; + + static getInstance(): NavigationBarViewModel { + return getSingleInstance(NavigationBarViewModel, NAVIGATION_BAE_VIEW_MODEL_KEY); + } + + constructor() { + this.mNavigationBarComponentData = + AppStorage.SetAndLink(NavigationBarComponentDataKey, this.mNavigationBarComponentData).get() + this.urivar = settings.getUriSync(this.settingDataKey); + this.helper = featureAbility.acquireDataAbilityHelper(AbilityManager.getContext(), CommonConstants.URI_VAR); + this.initNavigationBarStatus(); + } + + install?() { + Log.showInfo(TAG, `install, useCount: ${this.mUseCount}`); + if (!this.mUseCount) { + TintStateManager.getInstance().registerListener('navigation', this as TintStateListener); + } + this.mUseCount++; + } + + uninstall?() { + Log.showInfo(TAG, `uninstall, useCount: ${this.mUseCount}`); + this.mUseCount--; + if (this.mUseCount) { + TintStateManager.getInstance().unregisterListener('navigation'); + } + } + + getNavigationBarComponentData?(): NavigationBarComponentData { + Log.showInfo(TAG, `getNavigationBarComponentData`) + return this.mNavigationBarComponentData; + } + + onTintStateChange?(tintState: TintState) { + Log.showInfo(TAG, `onTintStateChange, tintState: ${JSON.stringify(tintState)}`) + if (typeof (tintState.isEnable) == 'boolean') { + this.setWindowEnable(tintState.isEnable); + } + if (tintState.backgroundColor) { + this.mNavigationBarComponentData.backgroundColor = tintState.backgroundColor; + } + if (tintState.contentColor) { + this.mNavigationBarComponentData.contentColor = tintState.contentColor; + } + Log.showInfo(TAG, `onTintStateChange, backgroundColor ${this.mNavigationBarComponentData.backgroundColor}`); + Log.showInfo(TAG, `onTintStateChange, contentColor ${this.mNavigationBarComponentData.contentColor}`); + } + + setWindowEnable?(isEnable: boolean) { + Log.showInfo(TAG, `setWindowEnable, isEnable ${isEnable}`); + if (this.mNavigationBarComponentData.isEnable == isEnable) { + return; + } + this.mNavigationBarComponentData.isEnable = isEnable; + if (isEnable && this.isDisplay) { + WindowManager.showWindow(WindowType.NAVIGATION_BAR); + } else { + WindowManager.hideWindow(WindowType.NAVIGATION_BAR); + } + } + + private setValue(value: string) { + settings.setValueSync(this.helper, this.settingDataKey, value); + } + + private getValue(defaultValue?: string) { + return settings.getValueSync( + this.helper, this.settingDataKey, defaultValue ? defaultValue : this.navigationBarStatusDefaultValue + ); + } + + private registerListenForDataChanges(callback) { + this.helper.on("dataChange", this.urivar, (data) => { + callback(data); + }) + } + + /** + * Initialize the NavigationBar status. + */ + public initNavigationBarStatus() { + try { + let initValue = this.getValue(); + Log.showInfo(TAG, `initNavigationBarStatus initValue ${initValue}`); + this.windowSwitches(initValue); + this.registerListenForDataChanges(this.dataChangesCallback.bind(this)); + } catch (e) { + Log.showInfo(TAG, `initNavigationBarStatus error: ${e.toString()}`); + } + } + + /** + * Get NavigationBar status data. + * @return + */ + public dataChangesCallback(data: any) { + if (data.code !== 0) { + Log.showInfo(TAG, `dataChangesCallback failed, because ${data.message}`); + return; + } else { + let getRetValue = this.getValue(); + Log.showInfo(TAG, `dataChangesCallback initValue ${getRetValue}`); + this.windowSwitches(getRetValue); + } + } + + private windowSwitches(navigationBarStatusValue) { + this.isDisplay = navigationBarStatusValue == '1' ? true : false; + if (!this.isDisplay) { + WindowManager.hideWindow(WindowType.NAVIGATION_BAR); + } else { + WindowManager.showWindow(WindowType.NAVIGATION_BAR); + } + } +} \ No newline at end of file diff --git a/product/navigationBar/src/main/resources/base/element/color.json b/product/default/navigationBar/src/main/resources/base/element/color.json similarity index 70% rename from product/navigationBar/src/main/resources/base/element/color.json rename to product/default/navigationBar/src/main/resources/base/element/color.json index bd971768..26637d9f 100644 --- a/product/navigationBar/src/main/resources/base/element/color.json +++ b/product/default/navigationBar/src/main/resources/base/element/color.json @@ -1,9 +1,5 @@ { "color": [ - { - "name": "index_background", - "value": "#66000000" - }, { "name": "button_default_background", "value": "#00000000" diff --git a/product/default/navigationBar/src/main/resources/base/element/float.json b/product/default/navigationBar/src/main/resources/base/element/float.json new file mode 100644 index 00000000..d9b34215 --- /dev/null +++ b/product/default/navigationBar/src/main/resources/base/element/float.json @@ -0,0 +1,24 @@ +{ + "float": [ + { + "name": "navigation_bar_button_width", + "value": "144vp" + }, + { + "name": "navigation_bar_button_height", + "value": "72vp" + }, + { + "name": "navigation_bar_button_radius", + "value": "36vp" + }, + { + "name": "navigation_bar_button_icon_width", + "value": "24vp" + }, + { + "name": "navigation_bar_button_icon_height", + "value": "24vp" + } + ] +} \ No newline at end of file diff --git a/product/navigationBar/src/main/resources/base/element/string.json b/product/default/navigationBar/src/main/resources/base/element/string.json similarity index 89% rename from product/navigationBar/src/main/resources/base/element/string.json rename to product/default/navigationBar/src/main/resources/base/element/string.json index abe15793..72d2bf3e 100644 --- a/product/navigationBar/src/main/resources/base/element/string.json +++ b/product/default/navigationBar/src/main/resources/base/element/string.json @@ -2,11 +2,11 @@ "string": [ { "name": "nav_bar_size_portrait", - "value": "102" + "value": "72" }, { "name": "nav_bar_size_landscape", - "value": "102" + "value": "72" }, { "name": "nav_bar_position_portrait", @@ -22,11 +22,11 @@ }, { "name": "status_bar_size_portrait", - "value": "102" + "value": "48" }, { "name": "status_bar_size_landscape", - "value": "102" + "value": "48" }, { "name": "status_bar_position_portrait", diff --git a/product/default/navigationBar/src/main/resources/base/media/ic_systemui_back.svg b/product/default/navigationBar/src/main/resources/base/media/ic_systemui_back.svg new file mode 100644 index 00000000..b9480f0a --- /dev/null +++ b/product/default/navigationBar/src/main/resources/base/media/ic_systemui_back.svg @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/product/default/navigationBar/src/main/resources/base/media/ic_systemui_home.svg b/product/default/navigationBar/src/main/resources/base/media/ic_systemui_home.svg new file mode 100644 index 00000000..fb070ea3 --- /dev/null +++ b/product/default/navigationBar/src/main/resources/base/media/ic_systemui_home.svg @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/product/default/navigationBar/src/main/resources/base/media/ic_systemui_recent.svg b/product/default/navigationBar/src/main/resources/base/media/ic_systemui_recent.svg new file mode 100644 index 00000000..306fc679 --- /dev/null +++ b/product/default/navigationBar/src/main/resources/base/media/ic_systemui_recent.svg @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/product/notificationmanagement/src/main/resources/base/media/icon.png b/product/default/navigationBar/src/main/resources/base/media/icon.png similarity index 100% rename from product/notificationmanagement/src/main/resources/base/media/icon.png rename to product/default/navigationBar/src/main/resources/base/media/icon.png diff --git a/product/navigationBar/src/main/resources/zh_CN/element/string.json b/product/default/navigationBar/src/main/resources/en_US/element/string.json similarity index 89% rename from product/navigationBar/src/main/resources/zh_CN/element/string.json rename to product/default/navigationBar/src/main/resources/en_US/element/string.json index 7cc208b4..2abf9254 100644 --- a/product/navigationBar/src/main/resources/zh_CN/element/string.json +++ b/product/default/navigationBar/src/main/resources/en_US/element/string.json @@ -2,11 +2,11 @@ "string": [ { "name": "nav_bar_size_portrait", - "value": "102" + "value": "72" }, { "name": "nav_bar_size_landscape", - "value": "102" + "value": "72" }, { "name": "nav_bar_position_portrait", @@ -22,11 +22,11 @@ }, { "name": "status_bar_size_portrait", - "value": "102" + "value": "48" }, { "name": "status_bar_size_landscape", - "value": "102" + "value": "48" }, { "name": "status_bar_position_portrait", diff --git a/product/navigationBar/src/main/resources/rawfile/navigationBarLayoutConfig.json b/product/default/navigationBar/src/main/resources/rawfile/navigationBarLayoutConfig.json similarity index 100% rename from product/navigationBar/src/main/resources/rawfile/navigationBarLayoutConfig.json rename to product/default/navigationBar/src/main/resources/rawfile/navigationBarLayoutConfig.json diff --git a/product/navigationBar/src/main/resources/en_US/element/string.json b/product/default/navigationBar/src/main/resources/zh_CN/element/string.json similarity index 89% rename from product/navigationBar/src/main/resources/en_US/element/string.json rename to product/default/navigationBar/src/main/resources/zh_CN/element/string.json index 7cc208b4..2abf9254 100644 --- a/product/navigationBar/src/main/resources/en_US/element/string.json +++ b/product/default/navigationBar/src/main/resources/zh_CN/element/string.json @@ -2,11 +2,11 @@ "string": [ { "name": "nav_bar_size_portrait", - "value": "102" + "value": "72" }, { "name": "nav_bar_size_landscape", - "value": "102" + "value": "72" }, { "name": "nav_bar_position_portrait", @@ -22,11 +22,11 @@ }, { "name": "status_bar_size_portrait", - "value": "102" + "value": "48" }, { "name": "status_bar_size_landscape", - "value": "102" + "value": "48" }, { "name": "status_bar_position_portrait", diff --git a/product/notificationmanagement/.gitignore b/product/default/notificationmanagement/.gitignore similarity index 100% rename from product/notificationmanagement/.gitignore rename to product/default/notificationmanagement/.gitignore diff --git a/product/notificationmanagement/build.gradle b/product/default/notificationmanagement/build.gradle similarity index 73% rename from product/notificationmanagement/build.gradle rename to product/default/notificationmanagement/build.gradle index c23569f0..d1dfd5a6 100644 --- a/product/notificationmanagement/build.gradle +++ b/product/default/notificationmanagement/build.gradle @@ -4,11 +4,12 @@ ohos { defaultConfig { compatibleSdkVersion rootProject.ext.version.compatibleSdk } - entryModules "entry" + entryModules "phone_entry,pc_entry" } dependencies { - entryImplementation project(':entry') + entryImplementation project(':phone_entry') + entryImplementation project(':pc_entry') implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testCompile 'junit:junit:4.12' implementation project(':features:managementcomponent') diff --git a/product/statusbar/package.json b/product/default/notificationmanagement/package.json similarity index 100% rename from product/statusbar/package.json rename to product/default/notificationmanagement/package.json diff --git a/product/notificationmanagement/src/main/config.json b/product/default/notificationmanagement/src/main/config.json similarity index 80% rename from product/notificationmanagement/src/main/config.json rename to product/default/notificationmanagement/src/main/config.json index 5e620ab2..40e2b12f 100644 --- a/product/notificationmanagement/src/main/config.json +++ b/product/default/notificationmanagement/src/main/config.json @@ -5,18 +5,19 @@ "version": { "code": 1, "name": "1.0" - } + }, + "singleton": true }, "deviceConfig": {}, "module": { "package": "com.ohos.systemui.notificationmanagement", "name": ".MyApplication", "deviceType": [ - "phone" + "phone", "tablet" ], "distro": { "deliveryWithInstall": true, - "moduleName": "notificationmanagement", + "moduleName": "default_notificationmanagement", "moduleType": "feature" }, "abilities": [ @@ -28,7 +29,7 @@ "label": "$string:app_name", "type": "page", "launchType": "singleton", - "srcPath": "default", + "srcPath": "MainAbility", "srcLanguage": "ets" } ], @@ -38,7 +39,7 @@ "syntax": "ets", "type": "pageAbility" }, - "name": "default", + "name": "MainAbility", "window": { "designWidth": 720, "autoDesignWidth": false @@ -47,10 +48,11 @@ "pages/notificationManagenment", "pages/batchSetEnable", "pages/noDisturb", - "pages/setEnable" + "pages/setEnable", + "pages/noDisturbPre", + "pages/slotSetting" ] } - ], - "srcPath": "default" + ] } } \ No newline at end of file diff --git a/product/default/notificationmanagement/src/main/ets/AbilityStage.ts b/product/default/notificationmanagement/src/main/ets/AbilityStage.ts new file mode 100644 index 00000000..affea733 --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/AbilityStage.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" +import Log from '../../../../../../common/src/main/ets/default/Log' + +const TAG = "NotificationManagement_AbilityStage" +export default class MainAbilityStage extends AbilityStage { + onCreate() { + Log.showInfo(TAG, "onCreate") + } +} \ No newline at end of file diff --git a/product/default/notificationmanagement/src/main/ets/MainAbility/MainAbility.ts b/product/default/notificationmanagement/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 00000000..5c236b8c --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Ability from '@ohos.application.Ability' +import Log from '../../../../../../../common/src/main/ets/default/Log' +import AbilityManager from '../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' + +const TAG = "NotificationManagement-MainAbility" + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + Log.showInfo(TAG, "MainAbility onCreate") + globalThis[AbilityManager.ABILITY_NAME_NOTIFICATION_MANAGEMENT + '_want'] = want; + } + + onDestroy() { + Log.showInfo(TAG, "MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + Log.showInfo(TAG, "MainAbility onWindowStageCreate") + AbilityManager.setContext(AbilityManager.ABILITY_NAME_NOTIFICATION_MANAGEMENT, this.context) + windowStage.setUIContent(this.context, "pages/notificationManagenment", null) + } + + onWindowStageDestroy() { + Log.showInfo(TAG, "MainAbility onWindowStageDestroy") + } + + onForeground() { + Log.showInfo(TAG, "MainAbility onForeground") + } + + onBackground() { + Log.showInfo(TAG, "MainAbility onBackground") + } +}; diff --git a/product/notificationmanagement/src/main/ets/default/app.ets b/product/default/notificationmanagement/src/main/ets/MainAbility/app.ets similarity index 100% rename from product/notificationmanagement/src/main/ets/default/app.ets rename to product/default/notificationmanagement/src/main/ets/MainAbility/app.ets diff --git a/product/notificationmanagement/src/main/ets/default/common/constants.ets b/product/default/notificationmanagement/src/main/ets/MainAbility/common/constants.ts similarity index 89% rename from product/notificationmanagement/src/main/ets/default/common/constants.ets rename to product/default/notificationmanagement/src/main/ets/MainAbility/common/constants.ts index 261c499a..04932856 100644 --- a/product/notificationmanagement/src/main/ets/default/common/constants.ets +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/common/constants.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,8 +16,7 @@ export default class Constants { static WH_50_100 = '50%'; static WH_70_100 = '70%'; + static WH_90_100 = '90%'; static WH_100_100 = '100%'; static TOPMOST_INDEX = 999 - - static NEXT_DAY_NAME = '次日' } \ No newline at end of file diff --git a/product/default/notificationmanagement/src/main/ets/MainAbility/pages/batchSetEnable.ets b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/batchSetEnable.ets new file mode 100644 index 00000000..cceb4fee --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/batchSetEnable.ets @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//import Window from '@ohos.window'; +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import HeadComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headComponent'; +import AppItemComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/appItemComponent'; +import ConfigData from '../common/constants'; +import Router from '@system.router' + +const TAG = 'NotificationManagement-BatchSetEnable'; + +@Entry +@Component +export default struct BatchSetEnable { + @StorageLink('appManagementList') appList: any[]= []; + @State headName:Resource = $r('app.string.notificationManagement') + + build() { + Column() { + GridContainer({columns:12, sizeType: SizeType.Auto, gutter: vp2px(1) === 2 ? '12vp' : '0vp', margin: vp2px(1) === 2 ? '12vp' : '0vp'}) { + Row() { + Column() { + HeadComponent({ headName: $headName, isActive: true }); + List() { + ForEach(this.appList, (item) => { + ListItem() { + AppItemComponent({ + appIcon: item.appIcon, + appTitle: item.appTitle, + appSummary: item.appSummary, + appValue: item.appValue, + appArrow: item.appArrow, + appArrowStyle: '', + appUri: '', + appBundleName:item.appBundleName, + appUid:item.appUid, + appSwitch:1, + isCanChange: !item.systemApp + }); + } + .height($r('app.float.appitem_item_height')); + }); + } + .divider({ + strokeWidth: 1, + color: $r('app.color.background_color'), + startMargin: $r('app.float.divider_margin_l_info'), + endMargin: $r('app.float.divider_margin_r') + }) + .width(ConfigData.WH_100_100) + .height($r('app.float.applist_hieght_bat')) + .padding({ left: $r('app.float.itemComp_padding_l'), right: $r('app.float.itemComp_padding_r') }) + .align(Alignment.Top) + .backgroundColor(Color.White) + .visibility(Visibility.Visible) + .zIndex(0) + .border({ width: $r('app.float.border_width'), color:Color.White, + radius:$r('app.float.border_radius') }) + .margin({ top: $r('app.float.itemComp_margin_b') }); + } + .padding({ left: $r('sys.float.ohos_id_default_padding_start'), right: $r('sys.float.ohos_id_default_padding_start') }) + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100) + .useSizeType({ + xs: { span: 12, offset: 0 }, sm: { span: 12, offset: 0 }, + md: { span: 12, offset: 0 }, lg: { span: 8, offset: 2 } + }); + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + } + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .align(Alignment.Center) + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + + aboutToAppear(): void{ + Log.showInfo(TAG, `aboutToAppear`) + } + + onBackPress() { + Log.showInfo(TAG, `onBackPress`) + Router.back(); + } + +} diff --git a/product/default/notificationmanagement/src/main/ets/MainAbility/pages/noDisturb.ets b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/noDisturb.ets new file mode 100644 index 00000000..e2f148e9 --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/noDisturb.ets @@ -0,0 +1,551 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import HeadComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headComponent'; +import ConfigData from '../common/constants'; +import Router from '@system.router' +import { concatTime } from '../../../../../../../../common/src/main/ets/default/TimeManager'; +import ItemComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/itemComponent'; +import {DoNotDisturbType} from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/common/constants'; +import NoDisturbingModel from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/noDisturbingModel'; +import ViewModel from '../vm/noDisturbViewModel' + +const TAG = 'NotificationManagement-NoDisturb'; +const GROUP_REPEAT_MODE = 'repeatMode' + +@Entry +@Component +export default struct NoDisturb { + @State mViewModel: ViewModel = new ViewModel() + @State headName:Resource = $r('app.string.noDisturb') + @State repeatTitle:Resource = $r('app.string.repeat') + @State startDateTitle:Resource = $r('app.string.startDate') + @State endDateTitle:Resource = $r('app.string.endDate') + @State startTitle:Resource = $r('app.string.startTime') + @State endTitle:Resource = $r('app.string.endTime') + @State arrow: string | PixelMap | Resource = $r('app.media.ic_settings_arrow') + @State mRefreshCnt: number = 0; + mPrevData: string = ''; + + startDateDialogController: CustomDialogController = new CustomDialogController({ + builder: DateDialog({ + action:(data)=> this.setStartDate(data), + title: $r('app.string.startDate'), + defaultDate: this.mViewModel.defaultStartTime + }), + cancel: ()=>this.mViewModel.onCancel(), + autoCancel: false + }); + startTimeDialogController: CustomDialogController = new CustomDialogController({ + builder: TimeDialog({ + action:(data)=> this.setStartTime(data), + title: $r('app.string.startTime'), + defaultDate: this.mViewModel.defaultStartTime + }), + cancel: ()=>this.mViewModel.onCancel(), + autoCancel: false + }); + endDateDialogController: CustomDialogController = new CustomDialogController({ + builder: DateDialog({ + action:(data)=> this.setEndDate(data), + title: $r('app.string.endDate'), + defaultDate: this.mViewModel.defaultEndTime + }), + cancel: ()=>this.mViewModel.onCancel(), + autoCancel: false + }); + endTimeDialogController: CustomDialogController = new CustomDialogController({ + builder: TimeDialog({ + action:(data)=> this.setEndTime(data), + title: $r('app.string.endTime'), + defaultDate: this.mViewModel.defaultEndTime + }), + cancel: ()=>this.mViewModel.onCancel(), + autoCancel: false + }); + repeatDialogController: CustomDialogController = new CustomDialogController({ + builder: RepeatModeDialog({ + action:(data)=> this.setRepeatMode(data), + title: $r('app.string.repeat'), + selectMode: this.mViewModel.repeatMode + }), + cancel: ()=>this.mViewModel.onCancel(), + autoCancel: false + }); + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { + Column() { + GridContainer({columns:12, sizeType: SizeType.Auto, gutter: vp2px(1) === 2 ? '12vp' : '0vp', margin: vp2px(1) === 2 ? '12vp' : '0vp'}) { + Row() { + Column() { + HeadComponent({ headName: $headName, isActive: true }) + if (this.mRefreshCnt > 0) { + Row() { + ItemComponent({ + title: $repeatTitle, + value: this.mViewModel.repeatName, + arrow: $arrow + }) + }.onClick(() => { + this.repeatDialogController.open() + }).margin({ bottom: $r('app.float.itemComp_margin_b') }) + + if (this.mViewModel.repeatMode == DoNotDisturbType.TYPE_CLEARLY) { + List() { + ListItem() { + Row() { + ItemComponent({ + title: $startDateTitle, + value: this.mViewModel.startDateClue, + arrow: $arrow + }) + }.onClick(() => { + this.startDateDialogController.open() + }) + } + ListItem() { + Row() { + ItemComponent({ + title: $startTitle, + value: this.mViewModel.startTimeClue, + arrow: $arrow + }) + }.onClick(() => { + this.startTimeDialogController.open() + }) + } + }.divider({ + strokeWidth: 1, + color: $r('app.color.divider_color'), + startMargin: $r('app.float.divider_margin_l'), + endMargin: $r('app.float.divider_margin_r') + }).width(ConfigData.WH_100_100) + .visibility(Visibility.Visible) + .zIndex(0) + .border({ width: $r('app.float.border_width'), color: Color.White, + radius: $r('app.float.border_radius') }) + .backgroundColor(Color.White) + .margin({ bottom: $r('app.float.itemComp_margin_b')}) + List() { + ListItem() { + Row() { + ItemComponent({ + title: $endDateTitle, + value: this.mViewModel.endDateClue, + arrow: $arrow + }) + }.onClick(() => { + this.endDateDialogController.open() + }) + } + ListItem() { + Row() { + ItemComponent({ + title: $endTitle, + value: this.mViewModel.endTimeClue, + arrow: $arrow + }) + }.onClick(() => { + this.endTimeDialogController.open() + }) + } + }.divider({ + strokeWidth: 1, + color: $r('app.color.divider_color'), + startMargin: $r('app.float.divider_margin_l'), + endMargin: $r('app.float.divider_margin_r') + }).width(ConfigData.WH_100_100) + .visibility(Visibility.Visible) + .zIndex(0) + .border({ width: $r('app.float.border_width'), color: Color.White, + radius: $r('app.float.border_radius') }) + .backgroundColor(Color.White) + .margin({ bottom: $r('app.float.itemComp_margin_b')}) + } else { + Row() { + ItemComponent({ + title: $startTitle, + value: this.mViewModel.startTimeClue, + arrow: $arrow + }) + }.onClick(() => { + this.mPrevData = this.mViewModel.startTime + this.startTimeDialogController.open() + }).margin({ bottom: $r('app.float.itemComp_margin_b')}) + Row() { + ItemComponent({ + title: $endTitle, + value: this.mViewModel.endTimeClue, + arrow: $arrow + }) + }.onClick(() => { + this.mPrevData = this.mViewModel.endTime + this.endTimeDialogController.open() + }).margin({ bottom: $r('app.float.itemComp_margin_b')}) + } + } + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100) + .padding({ + left: $r('sys.float.ohos_id_default_padding_start'), + right: $r('sys.float.ohos_id_default_padding_end') + }) + .useSizeType({ + xs: { span: 12, offset: 0 }, sm: { span: 12, offset: 0 }, + md: { span: 12, offset: 0 }, lg: { span: 8, offset: 2 } + }) + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100) + } + } + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + .width(ConfigData.WH_100_100) + } + + setRepeatMode(data: number) { + this.mViewModel.onRepeatModeAccect(data); + this.mRefreshCnt++; + } + setStartDate(data: string) { + let dataSource = this.mViewModel.setDateIntoDateTime(this.mViewModel.defaultStartTime, data); + this.mViewModel.onStartTimeAccept(dataSource); + this.mRefreshCnt++; + } + setStartTime(data: string) { + let dataSource = data; + if (this.mViewModel.repeatMode == DoNotDisturbType.TYPE_CLEARLY) { + dataSource = this.mViewModel.setTimeIntoDateTime(this.mViewModel.defaultStartTime, data); + } else if (this.mViewModel.repeatMode == DoNotDisturbType.TYPE_NONE){ + dataSource = this.mPrevData; + } + this.mViewModel.onStartTimeAccept(dataSource); + this.mRefreshCnt++; + } + setEndDate(data: string) { + let dataSource = this.mViewModel.setDateIntoDateTime(this.mViewModel.defaultEndTime, data); + this.mViewModel.onEndTimeAccept(dataSource); + this.mRefreshCnt++; + } + setEndTime(data: string) { + let dataSource = data; + if (this.mViewModel.repeatMode == DoNotDisturbType.TYPE_CLEARLY) { + dataSource = this.mViewModel.setTimeIntoDateTime(this.mViewModel.defaultEndTime, data); + } else if (this.mViewModel.repeatMode == DoNotDisturbType.TYPE_NONE){ + dataSource = this.mPrevData; + } + this.mViewModel.onEndTimeAccept(dataSource); + this.mRefreshCnt++; + } + + + aboutToAppear(): void{ + Log.showInfo(TAG, `aboutToAppear`) + this.mViewModel.ViewModelInit() + this.mRefreshCnt++; + + } + + onBackPress() { + Log.showInfo(TAG, `onBackPress`) + Router.back(); + } +} + +/** + * select date dialog + */ +@CustomDialog +struct DateDialog { + public controller: CustomDialogController + public action: (data) => void + private selectedDate: string = '' + private title: string = '' + private defaultDate: Date = new Date() + private minDate: Date = new Date('2008-01-01'); + private maxDate: Date = new Date('2037-12-31'); + + build() { + Column() { + Column() { + Text(this.title) + .height($r('app.float.dialog_title_height')) + .width(ConfigData.WH_100_100) + .textAlign(TextAlign.Center) + .fontSize($r('app.float.dialog_title_font')) + .fontWeight(FontWeight.Medium) + DatePicker({ start: this.minDate, end: this.maxDate, selected: this.defaultDate, type: DatePickerType.Date }) + .useMilitaryTime(false) + .onChange((date: DatePickerResult) => { + let dateSource = new Date(date.year, date.month, date.day); + this.selectedDate = NoDisturbingModel.formatDate(dateSource); + }) + .width(ConfigData.WH_100_100) + .height($r('app.float.timeDialog_datePicker_height')) + } + + Row() { + Column() { + Text($r('app.string.cancel')) + .fontSize($r('app.float.dialog_button_font')) + .fontColor(Color.Blue) + + }.onClick(() => { + this.controller.close(); + }) + .alignItems(HorizontalAlign.Center) + .width(ConfigData.WH_50_100); + Divider() + .vertical(true) + .color($r('app.color.divider_color')) + .strokeWidth(1) + .height($r('app.float.divider_height')) + Column() { + Text($r('app.string.confirm')) + .fontSize($r('app.float.dialog_button_font')) + .fontColor(Color.Blue) + + }.onClick(() => { + Log.showInfo(TAG, `confirm button of DateDialog on click`) + this.controller.close(); + if(this.selectedDate != '') { + this.action(this.selectedDate); + } + }) + .alignItems(HorizontalAlign.Center) + .width(ConfigData.WH_50_100) + } + .width(ConfigData.WH_100_100) + .margin({top: $r("app.float.noDisturb_margin_16"), bottom: $r("app.float.noDisturb_margin_16")}) + } + .height($r('app.float.timeDialog_height')) + .width(ConfigData.WH_100_100) + } +} + +/** + * select time dialog + */ +@CustomDialog +struct TimeDialog { + public controller: CustomDialogController + public action: (data) => void + private selectedTime: string = '' + private title: string = '' + private defaultDate: Date = new Date() + + build() { + Column() { + Column() { + Text(this.title) + .height($r('app.float.dialog_title_height')) + .width(ConfigData.WH_100_100) + .textAlign(TextAlign.Center) + .fontSize($r('app.float.dialog_title_font')) + .fontWeight(FontWeight.Medium) + DatePicker({ selected: this.defaultDate, type: DatePickerType.Time }) + .useMilitaryTime(false) + .onChange((date: DatePickerResult) => { + this.selectedTime = concatTime(date.hour, date.minute); + }) + .width(ConfigData.WH_100_100) + .height($r('app.float.timeDialog_datePicker_height')) + } + + Row() { + Column() { + Text($r('app.string.cancel')) + .fontSize($r('app.float.dialog_button_font')) + .fontColor(Color.Blue) + + }.onClick(() => { + this.controller.close(); + }) + .alignItems(HorizontalAlign.Center) + .width(ConfigData.WH_50_100); + Divider() + .vertical(true) + .color($r('app.color.divider_color')) + .strokeWidth(1) + .height($r('app.float.divider_height')) + Column() { + Text($r('app.string.confirm')) + .fontSize($r('app.float.dialog_button_font')) + .fontColor(Color.Blue) + + }.onClick(() => { + Log.showInfo(TAG, `confirm button of TimeDialog on click`) + this.controller.close(); + if(this.selectedTime != '') { + this.action(this.selectedTime); + } + }) + .alignItems(HorizontalAlign.Center) + .width(ConfigData.WH_50_100) + } + .width(ConfigData.WH_100_100) + .margin({top: $r("app.float.noDisturb_margin_16"), bottom: $r("app.float.noDisturb_margin_16")}) + } + .height($r('app.float.timeDialog_height')) + .width(ConfigData.WH_100_100) + } +} + +/** + * select repeat Mode dialog + */ +@CustomDialog +struct RepeatModeDialog { + public controller: CustomDialogController + public action: (data) => void + private title: string= '' + private prevModeSetCnt: number = 0 + @State selectMode: number = DoNotDisturbType.TYPE_NONE + itSelectedBefore: number = -1 + build() { + Column() { + Column() { + Text(this.title) + .height($r('app.float.dialog_title_height')) + .width(ConfigData.WH_100_100) + .textAlign(TextAlign.Center) + .fontSize($r('app.float.dialog_title_font')) + .fontWeight(FontWeight.Medium) + Row() { + Text($r('app.string.noDisturb_none')) + .fontSize($r('app.float.repeatDialog_cont_font')) + .fontColor(Color.Black) + .width(ConfigData.WH_70_100) + .textAlign(TextAlign.Start) + .align(Alignment.Start) + Radio({ value: '' + DoNotDisturbType.TYPE_NONE, group: GROUP_REPEAT_MODE }) + .checked(this.selectMode == DoNotDisturbType.TYPE_NONE) + .align(Alignment.End) + .width($r('app.float.toggle_check_width')) + .height($r('app.float.toggle_check_width')) + .onClick(() => { + if (this.prevModeSetCnt == 0) { + this.itSelectedBefore = this.selectMode; + } + this.prevModeSetCnt++ + this.selectMode = DoNotDisturbType.TYPE_NONE; + }) + } + Row() { + Text($r('app.string.noDisturb_once')) + .fontSize($r('app.float.repeatDialog_cont_font')) + .fontColor(Color.Black) + .width(ConfigData.WH_70_100) + .textAlign(TextAlign.Start) + .align(Alignment.Start) + Radio({ value: '' + DoNotDisturbType.TYPE_ONCE, group: GROUP_REPEAT_MODE }) + .checked(this.selectMode == DoNotDisturbType.TYPE_ONCE) + .align(Alignment.End) + .width($r('app.float.toggle_check_width')) + .height($r('app.float.toggle_check_width')) + .onClick(() => { + if (this.prevModeSetCnt == 0) { + this.itSelectedBefore = this.selectMode; + } + this.prevModeSetCnt++ + this.selectMode = DoNotDisturbType.TYPE_ONCE; + }) + } + Row() { + Text($r('app.string.noDisturb_daily')) + .fontSize($r('app.float.repeatDialog_cont_font')) + .fontColor(Color.Black) + .width(ConfigData.WH_70_100) + .textAlign(TextAlign.Start) + .align(Alignment.Start) + Radio({ value: '' + DoNotDisturbType.TYPE_DAILY, group: GROUP_REPEAT_MODE }) + .checked(this.selectMode == DoNotDisturbType.TYPE_DAILY) + .align(Alignment.End) + .width($r('app.float.toggle_check_width')) + .height($r('app.float.toggle_check_width')) + .onClick(() => { + if (this.prevModeSetCnt == 0) { + this.itSelectedBefore = this.selectMode; + } + this.prevModeSetCnt++ + this.selectMode = DoNotDisturbType.TYPE_DAILY; + }) + } + Row() { + Text($r('app.string.noDisturb_clearly')) + .fontSize($r('app.float.repeatDialog_cont_font')) + .fontColor(Color.Black) + .width(ConfigData.WH_70_100) + .textAlign(TextAlign.Start) + .align(Alignment.Start) + Radio({ value: '' + DoNotDisturbType.TYPE_CLEARLY, group: GROUP_REPEAT_MODE }) + .checked(this.selectMode == DoNotDisturbType.TYPE_CLEARLY) + .align(Alignment.End) + .width($r('app.float.toggle_check_width')) + .height($r('app.float.toggle_check_width')) + .onClick(() => { + if (this.prevModeSetCnt == 0) { + this.itSelectedBefore = this.selectMode; + } + this.prevModeSetCnt++ + this.selectMode = DoNotDisturbType.TYPE_CLEARLY; + }) + } + } + + Row() { + Column() { + Text($r('app.string.cancel')) + .fontSize($r('app.float.dialog_button_font')) + .fontColor($r("app.color.font_color_007DFF")) + + }.onClick(() => { + this.controller.close(); + }) + .alignItems(HorizontalAlign.Center) + .width(ConfigData.WH_50_100); + Divider() + .vertical(true) + .color($r('app.color.divider_color')) + .strokeWidth(1) + .height($r('app.float.divider_height')) + Column() { + Text($r('app.string.confirm')) + .fontSize($r('app.float.dialog_button_font')) + .fontColor($r("app.color.font_color_007DFF")) + + }.onClick(() => { + Log.showInfo(TAG, `confirm button of TimeDialog on click`) + this.controller.close(); + if (this.itSelectedBefore != -1 && this.itSelectedBefore != this.selectMode){ + this.action(this.selectMode); + } + }) + .alignItems(HorizontalAlign.Center) + .width(ConfigData.WH_50_100) + } + .width(ConfigData.WH_100_100) + .margin({top: $r("app.float.noDisturb_margin_16"), bottom: $r("app.float.noDisturb_margin_16")}) + } + .height($r('app.float.repeatDialog_height')) + .width(ConfigData.WH_100_100) + } +} diff --git a/product/default/notificationmanagement/src/main/ets/MainAbility/pages/noDisturbPre.ets b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/noDisturbPre.ets new file mode 100644 index 00000000..0ecea6bc --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/noDisturbPre.ets @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//import Window from '@ohos.window'; + +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import HeadComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headComponent'; +import NoDisturbComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/noDisturbComponent'; +import ItemComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/itemComponent'; +import ConfigData from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/common/constants'; +import Router from '@system.router'; + +const TAG = 'NotificationManagement-NoDisturbPre'; + +@Entry +@Component +export default struct notificationManagenment { + @State columnMargin: string = '24vp'; + @State headName: Resource = $r('app.string.notificationManagement') + @State refreshRequest: number= 0 + + build() { + Column() { + GridContainer({ + columns: 12, + sizeType: SizeType.Auto, + gutter: vp2px(1) === 2 ? '12vp' : '0vp', + margin: vp2px(1) === 2 ? '24vp' : '0vp' + }) { + Row() { + Column() { + HeadComponent({ headName: $headName, isActive: true }); + Row() { + Text($r('app.string.timing_on')) + .fontSize($r('app.float.page_phrases_font')) + .margin({top:$r('app.float.page_phrases_padding_t')}) + } + .width(ConfigData.WH_100_100) + .height($r('app.float.page_phrases_height')) + .padding({ left: $r('sys.float.ohos_id_default_padding_start') }) + + Row() { + NoDisturbComponent({ refreshRequest: this.refreshRequest }) + } + .align(Alignment.Start) + .onClick(() => { + Log.showInfo(TAG, `NoDisturbComponent on click`) + Router.push({ uri: 'pages/noDisturb' }); + }).width(ConfigData.WH_100_100) + .backgroundColor(Color.White) + .border({ width: $r('app.float.border_width'), color: Color.White, + radius: $r('app.float.border_radius') }) + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100) + .padding({ left: $r('sys.float.ohos_id_default_padding_start'), + right: $r('sys.float.ohos_id_default_padding_end') }) + .useSizeType({ + xs: { span: 12, offset: 0 }, sm: { span: 12, offset: 0 }, + md: { span: 12, offset: 0 }, lg: { span: 8, offset: 2 } + }); + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + + aboutToAppear(): void{ + Log.showInfo(TAG, `aboutToAppear`) + } + + aboutToDisappear(): void{ + Log.showInfo(TAG, `aboutToDisappear`) + } + + onPageShow(): void{ + Log.showInfo(TAG, `onPageShow`) + this.refreshRequest++; + } + + onBackPress() { + Log.showInfo(TAG, `onBackPress`) + } +} diff --git a/product/default/notificationmanagement/src/main/ets/MainAbility/pages/notificationManagenment.ets b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/notificationManagenment.ets new file mode 100644 index 00000000..5707292a --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/notificationManagenment.ets @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//import Window from '@ohos.window'; + +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import HeadComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headComponent'; +import NoDisturbComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/noDisturbComponent'; +import ItemComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/itemComponent'; +import ConfigData from '../common/constants'; +import AppLstComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/appLstComponent'; +import Router from '@system.router'; +import ViewModel from '../vm/notificationManagenmentViewModel' +import Notification from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/notificationListener'; +import SwitchComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/switchComponent'; + +const TAG = 'NotificationManagement-Main'; + +@Entry +@Component +export default struct notificationManagenment { + @State columnMargin: string = '12vp'; + @State mViewModel: ViewModel = new ViewModel(); + @State headName: Resource = $r('app.string.notification') + @State title: Resource = $r('app.string.batch_Management') + @State arrow: string | PixelMap | Resource= $r('app.media.ic_settings_arrow') + @State allowDistribut: Resource = $r('app.string.allowDistribut') + @State allowDistributDescribe: Resource = $r('app.string.allowDistributDescribe') + + build() { + Column() { + GridContainer({ + columns: 12, + sizeType: SizeType.Auto, + gutter: vp2px(1) === 2 ? '12vp' : '0vp', + margin: vp2px(1) === 2 ? '24vp' : '0vp' + }) { + Row() { + Column() { + HeadComponent({ headName: $headName, isActive: true }) + Column() { + Row() { + Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { + Row() { + Column() { + Text($r('app.string.noDisturb')) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('app.color.itemComp_title_color')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Bold) + .height($r('app.float.itemComp_height')) + .padding({ left: $r('sys.float.ohos_id_default_padding_start') }) + } + .alignItems(HorizontalAlign.Start) + } + .flexShrink(1) + .align(Alignment.Start) + .alignItems(VerticalAlign.Center) + + Row() { + if (this.mViewModel.isEffective) { + Text($r('app.string.noDisturb_opened')) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('app.color.itemComp_title_color')) + .align(Alignment.End) + } else { + Text($r('app.string.noDisturb_closed')) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('app.color.itemComp_title_color')) + .align(Alignment.End) + } + Image($r('app.media.ic_settings_arrow')) + .align(Alignment.End) + .width($r('app.float.itemComp_image_width')) + .height($r('app.float.itemComp_image_height')) + } + .padding({ right: $r('sys.float.ohos_id_default_padding_end') }) + .flexShrink(0) + .align(Alignment.End) + .alignItems(VerticalAlign.Center) + } + .width(ConfigData.WH_100_100) + .height($r('app.float.itemComp_height')) + .border({ width: $r('app.float.border_width'), color: Color.White, + radius: $r('app.float.border_radius') }) + .backgroundColor(Color.White) + } + .height($r('app.float.itemComp_height')) + .margin({ top: $r('app.float.noDisturb_margin_lf') }) + .align(Alignment.Start) + .onClick(() => { + Log.showInfo(TAG, `NoDisturbComponent on click`) + Router.push({ uri: 'pages/noDisturbPre' }); + }).width(ConfigData.WH_100_100) + .flexShrink(0) + Column() { + Divider().color($r('app.color.divider_color')).strokeWidth(1) + }.padding({ left: $r('sys.float.ohos_id_default_padding_start'),right:$r('sys.float.ohos_id_default_padding_end') }) + Row() { + Row() { + SwitchComponent({ + title: $allowDistribut, + describe: this.allowDistributDescribe, + initializationAction: () => this.switchComponentInit(), + settingAction: (params) => this.switchComponentSet(params), + isCanChange: true + }) + } + }.margin({ bottom: $r('app.float.noDisturb_margin_lf') }) + } + .backgroundColor(Color.White) + .border({ width: $r('app.float.border_width'), color: Color.White, + radius: $r('app.float.border_radius') }) + .margin({top:$r('app.float.page_notice_title_margin_t')}); + + Row() { + Text($r('app.string.notificationManagement')) + .fontColor($r('sys.color.ohos_id_color_text_secondary')) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .fontWeight(FontWeight.Bold) + .fontFamily('HarmonyHeiTi-Medium') + .margin({top:$r('app.float.page_phrases_padding_t')}) + }.align(Alignment.Start) + .width(ConfigData.WH_100_100) + .height($r('app.float.page_phrases_height')) + .padding({ left: $r('sys.float.ohos_id_default_padding_start')}) + + Row() { + ItemComponent({ title: $title, value: '', arrow: $arrow }) + }.onClick(() => { + Log.showInfo(TAG, `BatchManagement on click`) + Router.push({ uri: 'pages/batchSetEnable' }); + }).width(ConfigData.WH_100_100) + .flexShrink(0) + + Column() { + AppLstComponent() + }.width(ConfigData.WH_100_100) + .height($r('app.float.applist_hieght')) + .margin({top:$r('app.float.applist_margin_t')}); + + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100) + .padding({ + left: $r('sys.float.ohos_id_default_padding_start'), + right: $r('sys.float.ohos_id_default_padding_end') + }) + .useSizeType({ + xs: { span: 12, offset: 0 }, sm: { span: 12, offset: 0 }, + md: { span: 12, offset: 0 }, lg: { span: 8, offset: 2 } + }); + + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + + aboutToAppear(): void{ + Log.showInfo(TAG, `aboutToAppear`) + this.mViewModel.ViewModelInit(); + } + + aboutToDisappear(): void{ + Log.showInfo(TAG, `aboutToDisappear`) + } + + onPageShow(): void{ + Log.showInfo(TAG, `onPageShow`) + this.mViewModel.RefreshNoDisturbState(); + } + + onBackPress() { + Log.showInfo(TAG, `onBackPress`) + } + + switchComponentInit() { + Log.showInfo(TAG, `switchComponentInit`) + return Notification.isDistributedEnabled(); + } + + switchComponentSet(params) { + Log.showInfo(TAG, `switchComponentSet`) + Notification.enableDistributed(params); + } +} diff --git a/product/default/notificationmanagement/src/main/ets/MainAbility/pages/setEnable.ets b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/setEnable.ets new file mode 100644 index 00000000..e2340bd2 --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/setEnable.ets @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//import Window from '@ohos.window'; +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import HeadComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headComponent'; +import AppItemComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/appItemComponent'; +import SwitchComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/switchComponent'; +import SlotLstComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/slotLstComponent'; +import ConfigData from '../common/constants'; +import Router from '@system.router' +import Notification from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/notificationListener'; + +const TAG = 'NotificationManagement-SetEnable'; + +let appInfo; + +@Entry +@Component +export default struct SetEnable { + private listeners: any[] = [] + @State headName:Resource = $r('app.string.notificationManagement') + @State allowNotice:Resource = $r('app.string.allowNotification') + build() { + Flex({ justifyContent: FlexAlign.SpaceBetween }) { + Column() { + GridContainer({columns:12, sizeType: SizeType.Auto, gutter: vp2px(1) === 2 ? '12vp' : '0vp', margin: vp2px(1) === 2 ? '12vp' : '0vp'}) { + Row() { + Column() { + HeadComponent({ headName: $headName, isActive: true }); + Row() { + AppItemComponent({ + appIcon: appInfo.appIcon, + appTitle: appInfo.appTitle, + appSummary: appInfo.appSummary, + appValue: '', + appArrow: appInfo.appArrow, + appArrowStyle: '', + appUri: appInfo.appUri, + appBundleName: appInfo.appBundleName, + appUid: appInfo.appUid, + appSwitch: 2 + }); + } + .margin({ top: $r('app.float.page_notice_part_margin_t'), right: $r('app.float.page_margin_r') }) + .padding({ left: $r('sys.float.ohos_id_max_padding_start'), right: $r('sys.float.ohos_id_default_padding_end')}) + + + Row() { + SwitchComponent({ + title: $allowNotice, + initializationAction: () => this.switchComponentInit(), + settingAction: (params) => this.switchComponentSet(params), + register: (listener) => Notification.register({bundle:appInfo.appBundleName,onEnableChanged:listener}), + isCanChange: !appInfo.systemApp + }) + } + .margin({ top: $r('app.float.page_notice_title_margin_t')}) + .padding({ left: $r('sys.float.ohos_id_default_padding_start'), right: $r('sys.float.ohos_id_default_padding_end')}) + .height($r('app.float.notice_row_height')) + + Row() { + SlotLstComponent({ appInfo: appInfo }) + } + .align(Alignment.Start) + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100) + .useSizeType({ + xs: { span: 12, offset: 0 }, sm: { span: 12, offset: 0 }, + md: { span: 12, offset: 0 }, lg: { span: 8, offset: 2 } + }); + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + } + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100) + } + .width(ConfigData.WH_100_100) + } + + aboutToAppear(): void{ + Log.showInfo(TAG, `aboutToAppear`) + appInfo = Router.getParams(); + appInfo.slotSettingUrl = 'pages/slotSetting' + Notification.subscribeEnableChanged(); + Log.showInfo(TAG, `aboutToAppear end`) + } + + aboutToDisappear(): void{ + Log.showInfo(TAG, `aboutToDisappear`) + Notification.unsubscribeEnableChanged(); + } + + onBackPress() { + Log.showInfo(TAG, `onBackPress`) + Router.back(); + } + + switchComponentInit() { + Log.showInfo(TAG, `switchComponentInit`) + return Notification.isNotificationEnabled({ bundle: appInfo.appBundleName, uid: appInfo.appUid }) + } + + switchComponentSet(params) { + Log.showInfo(TAG, `switchComponentSet`) + Notification.enableNotification({ bundle: appInfo.appBundleName, uid: appInfo.appUid }, params); + } +} diff --git a/product/default/notificationmanagement/src/main/ets/MainAbility/pages/slotSetting.ets b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/slotSetting.ets new file mode 100644 index 00000000..bf6eee85 --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/pages/slotSetting.ets @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import HeadComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headComponent'; +import AppItemComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/appItemComponent'; +import SwitchComponent from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/switchComponent'; +import ConfigData from '../common/constants'; +import NotificationConfigData from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/common/constants'; +import Router from '@system.router' +import Notification from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/notificationListener'; +import {SlotLevel} from '@ohos.notification'; + +const TAG = 'NotificationManagement-SlotSetting'; +const DEFAULT_SOUND = 'file://system/etc/Light.ogg'; + +let params; + +@Entry +@Component +export default struct SlotSetting { + private appInfo: any = null; + private slotInfo: any = null; + @State headName: Resource = $r('app.string.notificationManagement') + @State allowNotice: Resource = $r('app.string.allowNotification') + @State noticeStyleBanner: Resource = $r('app.string.notificationStyle_banner') + @State noticeSound: Resource = $r('app.string.notificationSound') + + build() { + Flex({ justifyContent: FlexAlign.SpaceBetween }) { + Column() { + GridContainer({ + columns: 12, + sizeType: SizeType.Auto, + gutter: vp2px(1) === 2 ? '12vp' : '0vp', + margin: vp2px(1) === 2 ? '12vp' : '0vp' + }) { + Row() { + Column() { + HeadComponent({ headName: $headName, isActive: true }); + Row() { + AppItemComponent({ + appIcon: this.appInfo.appIcon, + appTitle: this.appInfo.appTitle, + appSummary: this.appInfo.appSummary, + appValue: this.slotInfo.type, + appArrow: this.appInfo.appArrow, + appArrowStyle: '', + appUri: this.appInfo.appUri, + appBundleName: this.appInfo.appBundleName, + appUid: this.appInfo.appUid, + appSwitch: 3, + isCanChange: !this.appInfo.systemApp + }); + } + .margin({ top: $r('app.float.page_notice_part_margin_t') }) + .padding({ + left: $r('sys.float.ohos_id_max_padding_start'), + right: $r('sys.float.ohos_id_default_padding_end') + }) + + Row() { + SwitchComponent({ + title: $allowNotice, + initializationAction: () => this.notificationEnableInit(), + settingAction: (params) => this.notificationEnableSet(params), + register: (listener) => Notification.register({ + bundle: this.appInfo.appBundleName, + onEnableChanged: listener + }), + isCanChange: false //TODO: There is no service, so it cannot be modified + }) + } + .margin({ top: $r('app.float.page_notice_title_margin_t') }) + .padding({ + left: $r('sys.float.ohos_id_card_margin_start'), + right: $r('sys.float.ohos_id_card_margin_end') + }) + .height($r('app.float.notice_row_height')) + + Row() { + Text($r('app.string.notificationStyle')) + .fontColor($r('sys.color.ohos_id_color_text_secondary')) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .fontWeight(FontWeight.Bold) + .width(NotificationConfigData.WH_100_100) + .maxLines(NotificationConfigData.MAX_LINES_1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + }.height($r('app.float.notice_title_height')) + .padding({ + left: $r('sys.float.ohos_id_max_padding_start'), + right: $r('sys.float.ohos_id_max_padding_end') + }) + .margin({ top: $r('app.float.page_notice_part_margin_t')}) + .align(Alignment.Start); + + Row() { + SwitchComponent({ + title: $noticeStyleBanner, + initializationAction: () => this.bannerEnableInit(), + settingAction: (params) => this.bannerEnableSet(params) + }) + } + .padding({ + left: $r('sys.float.ohos_id_card_margin_start'), + right: $r('sys.float.ohos_id_card_margin_end') + }) + .margin({ top: $r('app.float.page_notice_title_margin_t')}) + .height($r('app.float.notice_row_height')) + + Row() { + SwitchComponent({ + title: $noticeSound, + initializationAction: () => this.soundEnableInit(), + settingAction: (params) => this.soundEnableSet(params) + }) + } + .padding({ + left: $r('sys.float.ohos_id_card_margin_start'), + right: $r('sys.float.ohos_id_card_margin_end') + }) + .margin({ top: $r('app.float.page_notice_row_margin_t') }) + .height($r('app.float.notice_row_height')) + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100) + .useSizeType({ + xs: { span: 12, offset: 0 }, sm: { span: 12, offset: 0 }, + md: { span: 12, offset: 0 }, lg: { span: 8, offset: 2 } + }); + } + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100); + } + } + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) + .width(ConfigData.WH_100_100) + .height(ConfigData.WH_100_100) + } + .width(ConfigData.WH_100_100) + } + + aboutToAppear(): void{ + Log.showInfo(TAG, `aboutToAppear`) + params = Router.getParams(); + this.appInfo = params.appInfo; + this.slotInfo = params.slotInfo + } + + onBackPress() { + Log.showInfo(TAG, `onBackPress`) + Router.back(); + } + + notificationEnableInit() { + Log.showInfo(TAG, `notificationEnableInit`) + return Notification.isNotificationEnabled({ bundle: this.appInfo.appBundleName, uid: this.appInfo.appUid }) + } + + notificationEnableSet(data) { + Log.showInfo(TAG, `notificationEnableSet data:${JSON.stringify(data)}`) + Notification.enableNotification({ bundle: this.appInfo.appBundleName, uid: this.appInfo.appUid }, data); + } + + soundEnableInit() { + Log.showInfo(TAG, `soundEnableInit`) + return new Promise((resolve, reject) => { + let result: boolean = false; + if (!!this.slotInfo.sound) { + result = true; + } + resolve(result); + Log.showInfo(TAG, `soundEnableInit state:${result}`) + }); + } + + soundEnableSet(params) { + Log.showInfo(TAG, `soundEnableSet params:${JSON.stringify(params)}`) + if (params == 0) { + this.slotInfo.sound = ''; + this.slotInfo.level = SlotLevel.LEVEL_LOW + } else if (params == 1) { + this.slotInfo.sound = DEFAULT_SOUND; + if (this.slotInfo.level < SlotLevel.LEVEL_DEFAULT) { + this.slotInfo.level = SlotLevel.LEVEL_DEFAULT + } + } + this.notificationSlotSet(); + } + + bannerEnableInit() { + Log.showInfo(TAG, `bannerEnableInit`) + return new Promise((resolve, reject) => { + let result: boolean = false; + if (this.slotInfo.level == SlotLevel.LEVEL_HIGH) { + result = true; + } + Log.showInfo(TAG, `bannerEnableInit state:${result}`) + resolve(result); + }); + } + + bannerEnableSet(params) { + Log.showInfo(TAG, `bannerEnableSet params:${JSON.stringify(params)}`) + if (params == 0) { + if (this.slotInfo.sound) { + this.slotInfo.level = SlotLevel.LEVEL_DEFAULT; + } else { + this.slotInfo.level = SlotLevel.LEVEL_LOW; + } + } else if (params == 1) { + this.slotInfo.level = SlotLevel.LEVEL_HIGH; + } + this.notificationSlotSet(); + } + + notificationSlotSet() { + Log.showInfo(TAG, `notificationSlotSet slotInfo:${JSON.stringify(this.slotInfo)}`) + Notification.notificationSlotSet({ bundle: this.appInfo.appBundleName, uid: this.appInfo.appUid }, this.slotInfo); + } +} diff --git a/product/default/notificationmanagement/src/main/ets/MainAbility/vm/noDisturbViewModel.ts b/product/default/notificationmanagement/src/main/ets/MainAbility/vm/noDisturbViewModel.ts new file mode 100644 index 00000000..35858d00 --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/vm/noDisturbViewModel.ts @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ConfigData from '../common/constants'; +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import NoDisturbingModel from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/noDisturbingModel'; +import NoDisturbComponentViewModel from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/vm/noDisturbComponentViewModel'; +import FeaturesConfigData, {DoNotDisturbType} from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/common/constants'; + +const TAG = 'NotificationManagement-NoDisturbViewModel' +const CONST_DAY_LENGTH = 24*3600*1000 + +export default class NoDisturbViewModel extends NoDisturbComponentViewModel { + + startDateClue: string = '' + startTimeClue: string = '' + endDateClue: string = '' + endTimeClue: string = '' + + ViewModelInit(): void{ + Log.showInfo(TAG, 'ViewModelInit'); + this.getNextDayLabel(); + this.getNoDisturbingDate.bind(this)() + } + getNoDisturbingDate() { + Log.showInfo(TAG, 'getNoDisturbingDate'); + NoDisturbingModel.getNoDisturbingDate((data) => { + Log.showInfo(TAG, 'getNoDisturbingDate data:' + JSON.stringify(data)); + this.repeatMode = data.type + this.startTime = data.begin + this.endTime = data.end + Log.showInfo(TAG, `getNoDisturbingDate this.repeatMode : ${this.repeatMode}`) + Log.showInfo(TAG, `getNoDisturbingDate this.startTime : ${this.startTime}`) + Log.showInfo(TAG, `getNoDisturbingDate this.endTime : ${this.endTime}`) + this.setClues.bind(this)() + }) + } + + setClues() { + Log.showInfo(TAG, `setClues`) + if (this.repeatMode == DoNotDisturbType.TYPE_DAILY || + this.repeatMode == DoNotDisturbType.TYPE_ONCE || + this.repeatMode == DoNotDisturbType.TYPE_CLEARLY) { + this.isEffective = true; + } else { + this.isEffective = false; + } + let tmpStartDateTime = null; + let tmpEndDateTime = null; + if (this.repeatMode == DoNotDisturbType.TYPE_CLEARLY) { + tmpStartDateTime = this.getDateByDateTime(this.startTime); + tmpEndDateTime = this.getDateByDateTime(this.endTime); + this.startDateClue = this.getDateLabel(this.startTime); + this.startTimeClue = NoDisturbingModel.formatTime(tmpStartDateTime); + this.endDateClue = this.getDateLabel(this.endTime); + this.endTimeClue = NoDisturbingModel.formatTime(tmpEndDateTime); + } else { + tmpStartDateTime = this.getDateByHHMI(this.startTime); + tmpEndDateTime = this.getDateByHHMI(this.endTime); + this.startDateClue = ''; + this.startTimeClue = this.startTime; + this.endDateClue = ''; + if (tmpStartDateTime.getTime() >= tmpEndDateTime.getTime()) { + this.endTimeClue = this.nextDayLabel + this.endTime; + } else { + this.endTimeClue = this.endTime; + } + } + this.defaultStartTime = tmpStartDateTime; + this.defaultEndTime = tmpEndDateTime; + this.repeatName = this.refreshRepeatName(this.repeatMode); + } + + onStartTimeAccept(data) { + Log.showInfo(TAG, `onStartTimeAccept`) + this.startTime = data + if (this.repeatMode == DoNotDisturbType.TYPE_CLEARLY) { + let tmpDateTime = this.getDateByDateTime(this.startTime); + if (this.defaultEndTime.getTime() < tmpDateTime.getTime()) { + this.startTime = this.endTime + } + } + this.setClues(); + this.setNoDisturbingDate() + + } + + onEndTimeAccept(data) { + Log.showInfo(TAG, `onEndTimeAccept`) + this.endTime = data + if (this.repeatMode == DoNotDisturbType.TYPE_CLEARLY) { + let tmpDateTime = this.getDateByDateTime(this.endTime); + if (tmpDateTime.getTime() < this.defaultStartTime.getTime()) { + this.endTime = this.startTime + } + } + this.setClues(); + this.setNoDisturbingDate() + } + + onRepeatModeAccect(data) { + Log.showInfo(TAG, `onRepeatModeAccect`) + this.repeatMode = data; + if (this.repeatMode == DoNotDisturbType.TYPE_CLEARLY) { + let dateSource = new Date(); + this.startTime = NoDisturbingModel.formatDate(dateSource) + ' ' + FeaturesConfigData.TIME_EMPTY; + this.endTime = NoDisturbingModel.formatDate(new Date(dateSource.getTime() + CONST_DAY_LENGTH)) + ' ' + FeaturesConfigData.TIME_EMPTY; + } else { + this.startTime = FeaturesConfigData.TIME_EMPTY; + this.endTime = FeaturesConfigData.TIME_EMPTY; + } + this.setClues(); + this.setNoDisturbingDate(); + } + + setDateIntoDateTime(dateSource: Date, inputData:string): string { + let result = inputData + ' ' + NoDisturbingModel.formatTime(dateSource); + return result; + } + + setTimeIntoDateTime(dateSource: Date, inputData:string): string { + let result = NoDisturbingModel.formatDate(dateSource) + ' ' + inputData; + return result; + } + + onCancel() { + Log.showInfo(TAG, `onCancel`) + } +} \ No newline at end of file diff --git a/product/default/notificationmanagement/src/main/ets/MainAbility/vm/notificationManagenmentViewModel.ts b/product/default/notificationmanagement/src/main/ets/MainAbility/vm/notificationManagenmentViewModel.ts new file mode 100644 index 00000000..7428c96c --- /dev/null +++ b/product/default/notificationmanagement/src/main/ets/MainAbility/vm/notificationManagenmentViewModel.ts @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ConfigData from '../common/constants'; +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import BundleResourceModel from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/bundleResourceModel'; +import NoDisturbComponentViewModel from '../../../../../../../../features/managementcomponent/src/main/ets/com/ohos/vm/noDisturbComponentViewModel' +import Router from '@system.router'; + +const TAG = 'NotificationManagement-NotificationManagenmentViewModel' + +export default class NotificationManagenmentViewModel extends NoDisturbComponentViewModel { + + ViewModelInit(): void{ + Log.showInfo(TAG, 'ViewModelInit'); + super.ViewModelInit(); + this.MigrateTo(); + } + + RefreshNoDisturbState() { + super.ViewModelInit(); + } + + MigrateTo() { + Log.showInfo(TAG, 'MigrateTo'); + //get the want + let want = globalThis[AbilityManager.ABILITY_NAME_NOTIFICATION_MANAGEMENT + '_want']; + Log.showInfo(TAG, `aboutToAppear want:${JSON.stringify(want)}`) + if (!want || !want.parameters.migrateUri || !want.parameters.migrateBundle) { + return; + } + let migrateUri = want.parameters.migrateUri; + let bundleName = want.parameters.migrateBundle; + Log.showInfo(TAG, `aboutToAppear migrateUri:${migrateUri} migrateBundle:${JSON.stringify(bundleName)}`) + + let dataModel: BundleResourceModel = new BundleResourceModel() + dataModel.getBundleInfo(bundleName, (bundleInfo) => { + Log.showInfo(TAG, `MigrateTo bundleInfo:${JSON.stringify(bundleInfo)}`); + //to next page + Router.push({ + uri: migrateUri, params: bundleInfo + }); + }); + //clear want + globalThis[AbilityManager.ABILITY_NAME_NOTIFICATION_MANAGEMENT + '_want'] = null; + } +} + +} \ No newline at end of file diff --git a/product/default/notificationmanagement/src/main/resources/base/element/string.json b/product/default/notificationmanagement/src/main/resources/base/element/string.json new file mode 100644 index 00000000..a3b7823f --- /dev/null +++ b/product/default/notificationmanagement/src/main/resources/base/element/string.json @@ -0,0 +1,25 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NotificationManagement" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "timing_on", + "value": "定时开启" + }, + { + "name": "allowDistribut", + "value": "允许通知同步" + }, + { + "name": "allowDistributDescribe", + "value": "开启后,本设备通知可同步到其他设备" + } + + ] +} \ No newline at end of file diff --git a/product/notificationmanagement/src/main/resources/base/media/ic_back.svg b/product/default/notificationmanagement/src/main/resources/base/media/ic_back.svg similarity index 100% rename from product/notificationmanagement/src/main/resources/base/media/ic_back.svg rename to product/default/notificationmanagement/src/main/resources/base/media/ic_back.svg diff --git a/product/notificationmanagement/src/main/resources/base/media/ic_settings_arrow.svg b/product/default/notificationmanagement/src/main/resources/base/media/ic_settings_arrow.svg similarity index 100% rename from product/notificationmanagement/src/main/resources/base/media/ic_settings_arrow.svg rename to product/default/notificationmanagement/src/main/resources/base/media/ic_settings_arrow.svg diff --git a/product/statusbar/src/main/resources/base/media/icon.png b/product/default/notificationmanagement/src/main/resources/base/media/icon.png similarity index 100% rename from product/statusbar/src/main/resources/base/media/icon.png rename to product/default/notificationmanagement/src/main/resources/base/media/icon.png diff --git a/product/default/notificationmanagement/src/main/resources/en_US/element/string.json b/product/default/notificationmanagement/src/main/resources/en_US/element/string.json new file mode 100644 index 00000000..1c41489c --- /dev/null +++ b/product/default/notificationmanagement/src/main/resources/en_US/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NotificationManagement" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "timing_on", + "value": "Timing On" + }, + { + "name": "allowDistribut", + "value": "Allow Distribut Notification" + }, + { + "name": "allowDistributDescribe", + "value": "After this device is started, it can be synchronized to other devices" + } + ] +} \ No newline at end of file diff --git a/product/default/notificationmanagement/src/main/resources/zh_CN/element/string.json b/product/default/notificationmanagement/src/main/resources/zh_CN/element/string.json new file mode 100644 index 00000000..df357a1c --- /dev/null +++ b/product/default/notificationmanagement/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NotificationManagement" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "timing_on", + "value": "定时开启" + }, + { + "name": "allowDistribut", + "value": "允许通知同步" + }, + { + "name": "allowDistributDescribe", + "value": "开启后,本设备通知可同步到其他设备" + } + ] +} \ No newline at end of file diff --git a/product/default/volumepanel/.gitignore b/product/default/volumepanel/.gitignore new file mode 100644 index 00000000..378eac25 --- /dev/null +++ b/product/default/volumepanel/.gitignore @@ -0,0 +1 @@ +build diff --git a/product/default/volumepanel/build.gradle b/product/default/volumepanel/build.gradle new file mode 100644 index 00000000..f04efab4 --- /dev/null +++ b/product/default/volumepanel/build.gradle @@ -0,0 +1,16 @@ +apply plugin: 'com.huawei.ohos.hap' +ohos { + compileSdkVersion rootProject.ext.version.compileSdk + defaultConfig { + compatibleSdkVersion rootProject.ext.version.compatibleSdk + } + entryModules "phone_entry,pc_entry" +} + +dependencies { + entryImplementation project(':phone_entry') + entryImplementation project(':pc_entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testCompile 'junit:junit:4.12' + implementation project(':features:volumepanelcomponent') +} \ No newline at end of file diff --git a/product/default/volumepanel/package.json b/product/default/volumepanel/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/product/default/volumepanel/package.json @@ -0,0 +1 @@ +{} diff --git a/product/default/volumepanel/src/main/config.json b/product/default/volumepanel/src/main/config.json new file mode 100644 index 00000000..19a549b2 --- /dev/null +++ b/product/default/volumepanel/src/main/config.json @@ -0,0 +1,56 @@ +{ + "app": { + "bundleName": "com.ohos.systemui", + "vendor": "ohos", + "version": { + "code": 1, + "name": "1.0" + }, + "singleton": true + }, + "deviceConfig": { + "default": { + "keepAlive": true + } + }, + "module": { + "package": "com.ohos.systemui.volumepanel", + "name": ".MyApplication", + "deviceType": [ + "phone", "tablet" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "default_volumepanel", + "moduleType": "feature" + }, + "abilities": [ + { + "visible": true, + "name": "com.ohos.systemui.volumepanel.ServiceExtAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "service", + "launchType": "singleton", + "srcPath": "ServiceExtAbility", + "srcLanguage": "ets" + } + ], + "js": [ + {"mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": "ServiceExtAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/product/default/volumepanel/src/main/ets/AbilityStage.ts b/product/default/volumepanel/src/main/ets/AbilityStage.ts new file mode 100644 index 00000000..fcdeeba1 --- /dev/null +++ b/product/default/volumepanel/src/main/ets/AbilityStage.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" +import Log from '../../../../../../common/src/main/ets/default/Log' + +const TAG = "volume_AbilityStage" +export default class MainAbilityStage extends AbilityStage { + onCreate() { + Log.showInfo(TAG, "onCreate") + } +} \ No newline at end of file diff --git a/product/default/volumepanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts b/product/default/volumepanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts new file mode 100644 index 00000000..ac826951 --- /dev/null +++ b/product/default/volumepanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ServiceExtension from '@ohos.application.ServiceExtensionAbility' +import display from "@ohos.display"; +import Log from "../../../../../../../common/src/main/ets/default/Log"; +import WindowManager, { WindowType } from "../../../../../../../common/src/main/ets/default/WindowManager"; +import AbilityManager from "../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager"; +import VolumeWindowController from "../../../../../../../features/volumepanelcomponent/src/main/ets/com/ohos/common/VolumeWindowController"; + +const TAG = "VolumePanel_ServiceExtAbility"; + +class ServiceExtAbility extends ServiceExtension { + onCreate(want) { + Log.showInfo(TAG, "api8New onCreate, want:" + want.abilityName); + AbilityManager.setContext(AbilityManager.ABILITY_NAME_VOLUME_PANEL, this.context); + display.getDefaultDisplay().then((dis) => { + let volumeRect = { + left: 0, + top: 0, + width: dis.width, + height: dis.height, + }; + + AbilityManager.setAbilityData(AbilityManager.ABILITY_NAME_VOLUME_PANEL, "dis", { + width: dis.width, + height: dis.height, + }); + WindowManager.createWindow(this.context, WindowType.VOLUME_PANEL, volumeRect, "pages/index") + .then((win) => { + Log.showInfo(TAG, `api8New onCreate, createWindow callback`); + VolumeWindowController.getInstance().setWindowHandle(win); + }) + .catch((err) => Log.showError(TAG, `Can't create window, err:${err}`)); + }); + } + + onDestroy() { + Log.showInfo(TAG, "api8New onDestroy"); + } +} + +export default ServiceExtAbility; diff --git a/product/default/volumepanel/src/main/ets/ServiceExtAbility/app.ets b/product/default/volumepanel/src/main/ets/ServiceExtAbility/app.ets new file mode 100644 index 00000000..8a989da2 --- /dev/null +++ b/product/default/volumepanel/src/main/ets/ServiceExtAbility/app.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityManager from '../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import WindowManager, { WindowType } from '../../../../../../../common/src/main/ets/default/WindowManager' + +export default { + onCreate() { + console.info('SystemUI volumePanel Application onCreate') + let configInfo = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_VOLUME_PANEL, 'dis') + let volumeRect; + if (configInfo.width > configInfo.height) { // Pad、PC Mode + const realWidth = 48; + const realHeight = 284; + volumeRect = { + left: configInfo.width - vp2px(16) - vp2px(realWidth), + top: (configInfo.height - vp2px(realHeight) ) / 2, + width: vp2px(realWidth) , + height: vp2px(realHeight) + } + } else { // Phone Mode + const realWidth = 96; + const realHeight = 568; + volumeRect = { + left: configInfo.width - vp2px(32) - vp2px(realWidth), + top: configInfo.height * 0.1, + width: vp2px(realWidth) , + height: vp2px(realHeight) + } + } + AbilityManager.setAbilityData(AbilityManager.ABILITY_NAME_VOLUME_PANEL, 'rect', volumeRect) + WindowManager.resetSizeWindow(WindowType.VOLUME_PANEL, volumeRect); + }, + onDestroy() { + console.info('SystemUI volumePanel Application onDestroy') + }, +} diff --git a/product/default/volumepanel/src/main/ets/ServiceExtAbility/common/StyleConfiguration.ts b/product/default/volumepanel/src/main/ets/ServiceExtAbility/common/StyleConfiguration.ts new file mode 100644 index 00000000..b410ff8d --- /dev/null +++ b/product/default/volumepanel/src/main/ets/ServiceExtAbility/common/StyleConfiguration.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import StyleManager from '../../../../../../../../common/src/main/ets/default/StyleManager'; + +const TAG = 'VolumePanel-StyleConfiguration'; + +export default class StyleConfiguration { + static getIndexStyle() { + const key: string = TAG + "-Index"; + return StyleManager.getStyle(key, () => { + return {}; + }); + } +} \ No newline at end of file diff --git a/product/default/volumepanel/src/main/ets/ServiceExtAbility/common/StyleManager.ts b/product/default/volumepanel/src/main/ets/ServiceExtAbility/common/StyleManager.ts new file mode 100644 index 00000000..f074b6d1 --- /dev/null +++ b/product/default/volumepanel/src/main/ets/ServiceExtAbility/common/StyleManager.ts @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log'; +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager'; +import StyleConfiguration from '../../../../../../../../features/volumepanelcomponent/src/main/ets/com/ohos/common/StyleConfiguration' + +const TAG = 'VolumePanel-StyleManager'; + +export default class StyleManager { + static STANDARD_DISPLAY_WIDTH: number = 2560; + static STANDARD_DISPLAY_HEIGHT: number = 1600; + static maxWidth: number = StyleManager.STANDARD_DISPLAY_WIDTH; + + static setStyle() { + Log.showInfo(TAG, `setStyle`) + + let config = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_VOLUME_PANEL, 'dis'); + StyleManager.maxWidth = config.width; + + // Pad、PC Mode + { + let style: any = StyleConfiguration.getVolumePanelComponentStyle(); + style.volumePanelSliderMarginTop = StyleManager.calcScaleSizePx(40); + style.volumePanSliderWidth = px2vp(StyleManager.calcScaleSize(8)) + 'vp'; + style.volumePanSliderHeight = StyleManager.calcScaleSizePx(320); + style.volumePanelSliderMarginBottom = StyleManager.calcScaleSizePx(40); + style.volumePanelMutBtnIconSize = StyleManager.calcScaleSizePx(48); + style.volumePanelMutBtnIconMarginBottom = StyleManager.calcScaleSizePx(24); + style.volumePanelMuteBtnHeight = StyleManager.calcScaleSizePx(72); + style.volumePanelSettingIconSize = StyleManager.calcScaleSizePx(48); + style.volumePanelSettingButtonSize = StyleManager.calcScaleSizePx(96); + style.volumePanelBackground = '#99FFFFFF' + style.volumePanelSliderBlockColor = '#FFFFFFFF' + style.volumePanelDividerHeight = StyleManager.calcScaleSizePx(1); + style.volumePanelDefaultMin = StyleManager.calcScaleSizePx(0); + style.volumePanelBorderRadius = StyleManager.calcScaleSizePx(48); + style.volumeDividerWidth = StyleManager.calcScaleSizePx(60); + style.volumeSliderTrackColor = '#FFAEE6E6'; + style.volumeSelectedColor = '#FF007DFF'; + style.volumeButtonBackgroundColor = '#00000000'; + style.volumePanelRingModeColor = '#FF007DFF'; + style.volumePanelDividerColor = '#FF9BCECE' + style.volumePanelSettingColor = '#FF4D6666' + + } + + } + + static number2px(n: number): string { + return n.toString() + 'px'; + } + + static calcScaleSize(n: number): number { + return n * StyleManager.maxWidth / StyleManager.STANDARD_DISPLAY_WIDTH; + } + + static calcScaleSizePx(n: number): string { + return StyleManager.number2px(StyleManager.calcScaleSize(n)); + } +} \ No newline at end of file diff --git a/product/default/volumepanel/src/main/ets/ServiceExtAbility/common/constants.ts b/product/default/volumepanel/src/main/ets/ServiceExtAbility/common/constants.ts new file mode 100644 index 00000000..2e686de4 --- /dev/null +++ b/product/default/volumepanel/src/main/ets/ServiceExtAbility/common/constants.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class Constants { + +} \ No newline at end of file diff --git a/product/default/volumepanel/src/main/ets/ServiceExtAbility/pages/index.ets b/product/default/volumepanel/src/main/ets/ServiceExtAbility/pages/index.ets new file mode 100644 index 00000000..d5a0618e --- /dev/null +++ b/product/default/volumepanel/src/main/ets/ServiceExtAbility/pages/index.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Constants from '../common/constants' +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import CommonStyleManager from '../../../../../../../../common/src/main/ets/default/StyleManager' +import VolumePanelComponent from '../../../../../../../../features/volumepanelcomponent/src/main/ets/com/ohos/pages/VolumePanelComponent' +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import StyleManager from '../common/StyleManager' + +const TAG = 'VolumePanel-Index' + +@Entry +@Component +struct Index { + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear Start`) + setAppBgColor('#00000000') + CommonStyleManager.setAbilityPageName(TAG) + let configInfo = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_VOLUME_PANEL, 'dis') + Log.showInfo(TAG, `configInfo Start, configInfo ${JSON.stringify(configInfo)}`); + if (configInfo.width > configInfo.height) { // Pad、PC Mode + StyleManager.setStyle() + } + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisAppear`) + } + + build() { + Column() { + VolumePanelComponent() + } + .width('100%') + .height('100%') + } +} diff --git a/product/notificationmanagement/src/main/resources/en_US/element/string.json b/product/default/volumepanel/src/main/resources/base/element/string.json similarity index 80% rename from product/notificationmanagement/src/main/resources/en_US/element/string.json rename to product/default/volumepanel/src/main/resources/base/element/string.json index 2afcf614..4b8592f0 100644 --- a/product/notificationmanagement/src/main/resources/en_US/element/string.json +++ b/product/default/volumepanel/src/main/resources/base/element/string.json @@ -2,7 +2,7 @@ "string": [ { "name": "app_name", - "value": "NotificationManagement" + "value": "VolumePanel" }, { "name": "mainability_description", diff --git a/product/default/volumepanel/src/main/resources/base/media/icon.png b/product/default/volumepanel/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlm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yJ4G9^2Y!^8=lwvF; zL$*mc7Hb?#V9+vPd&GZ3A5}T6vSM2oI~~?#Vc07m=d#LW S!BL { - ListItem() { - AppItemComponent({ - appIcon: item.appIcon, - appTitle: item.appTitle, - appSummary: item.appSummary, - appValue: item.appValue, - appArrow: item.appArrow, - appArrowStyle: '', - appUri: '', - appBundleName:item.appBundleName, - appUid:item.appUid, - appSwitch:1 - }); - } - .height($r('app.float.appitem_item_height')); - }); - } - .divider({ - strokeWidth: 1, - color: $r('app.color.background_color'), - startMargin: $r('app.float.divider_margin_l'), - endMargin: $r('app.float.divider_margin_r') - }) - .width(ConfigData.WH_100_100) - .height(ConfigData.WH_100_100) - .margin({ bottom: '90' }) - .visibility(Visibility.Visible) - .zIndex(0); - } - .align(Alignment.Center) - .width(ConfigData.WH_100_100) - .height(ConfigData.WH_100_100) - .border({ width: $r('app.float.border_width'), color:Color.White, - radius:$r('app.float.border_radius') }) - } - - aboutToAppear(): void{ - Log.showInfo(TAG, `aboutToAppear`) - } - - onBackPress() { - Log.showInfo(TAG, `onBackPress`) - Router.back(); - } - -} diff --git a/product/notificationmanagement/src/main/ets/default/pages/noDisturb.ets b/product/notificationmanagement/src/main/ets/default/pages/noDisturb.ets deleted file mode 100644 index 8e6fa6da..00000000 --- a/product/notificationmanagement/src/main/ets/default/pages/noDisturb.ets +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; -import HeadComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headComponent.ets'; -import ConfigData from '../common/constants.ets'; -import Router from '@system.router' -import DateAndTime from '../../../../../../../common/src/main/ets/default/DateAndTimeUtil.ets'; -import ItemComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/itemComponent.ets'; -import ViewModel from '../vm/noDisturbViewModel.ets' - -const TAG = 'NotificationManagement-NoDisturb'; - -@Entry -@Component -export default struct NoDisturb { - @State mViewModel: ViewModel = new ViewModel() - startTimeDialogController: CustomDialogController = new CustomDialogController({ - builder: TimeDialog({ - action: this.mViewModel.onStartTimeAccept.bind(this.mViewModel), - title: $r('app.string.startTime'), - defaultDate: this.mViewModel.defaultStartTime - }), - cancel: this.mViewModel.onCancel.bind(this.mViewModel), - autoCancel: false, - offset: { dx: 0, dy: 200 } - }); - endTimeDialogController: CustomDialogController = new CustomDialogController({ - builder: TimeDialog({ - action: this.mViewModel.onEndTimeAccept.bind(this.mViewModel), - title: $r('app.string.endTime'), - defaultDate: this.mViewModel.defaultEndTime - }), - cancel: this.mViewModel.onCancel.bind(this.mViewModel), - autoCancel: false, - offset: { dx: 0, dy: 200 } - }); - repeatDialogController: CustomDialogController = new CustomDialogController({ - builder: RepeatModeDialog({ - action: this.mViewModel.onRepeatModeAccect.bind(this.mViewModel), - title: $r('app.string.repeat'), - selectMode: this.mViewModel.repeatMode - }), - cancel: this.mViewModel.onCancel.bind(this.mViewModel), - autoCancel: false, - offset: { dx: 0, dy: 200 } - }); - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { - HeadComponent({ headName: $r('app.string.noDisturb'), isActive: true }) - - Row() { - ItemComponent({ - title: $r('app.string.repeat'), - value: $r('app.string.daily'), - arrow: $r('app.media.ic_settings_arrow') - }) - }.onClick(() => { - this.repeatDialogController.open() - }).margin({ left: $r('app.float.page_margin_l'), right: $r('app.float.page_margin_r') }) - - - Row() { - ItemComponent({ - title: $r('app.string.startTime'), - value: this.mViewModel.startTime, - arrow: $r('app.media.ic_settings_arrow') - }) - }.onClick(() => { - this.startTimeDialogController.open() - }).margin({ left: $r('app.float.page_margin_l'), right: $r('app.float.page_margin_r') }) - - Row() { - ItemComponent({ - title: $r('app.string.endTime'), - value: this.mViewModel.endTimeClue, - arrow: $r('app.media.ic_settings_arrow') - }) - }.onClick(() => { - this.endTimeDialogController.open() - }).margin({ left: $r('app.float.page_margin_l'), right: $r('app.float.page_margin_r') }) - }.backgroundColor($r('app.color.background_color')) - } - - aboutToAppear(): void{ - Log.showInfo(TAG, `aboutToAppear`) - this.mViewModel.ViewModelInit() - - } - - onBackPress() { - Log.showInfo(TAG, `onBackPress`) - Router.back(); - } -} - -/** - * select time dialog - */ -@CustomDialog -struct TimeDialog { - public controller: CustomDialogController - public action: (data) => void - private selectedTime: string - private title: string= '' - private defaultDate: Date= new Date() - - build() { - Column() { - Column() { - Text(this.title) - .height($r('app.float.dialog_title_height')) - .margin({ left: $r('app.float.dialog_title_margin_l') }) - .width(ConfigData.WH_100_100) - .fontSize($r('app.float.dialog_title_font')) - .fontWeight(FontWeight.Bold) - DatePicker({ selected: this.defaultDate, type: DatePickerType.Time }) - .useMilitaryTime(true) - .onChange((date: DatePickerResult) => { - this.selectedTime = DateAndTime.concatTime(date.hour, date.minute); - }) - .width(ConfigData.WH_100_100) - .height($r('app.float.timeDialog_datePicker_height')) - } - - Row() { - Column() { - Text($r('app.string.cancel')) - .fontSize($r('app.float.dialog_button_font')) - .fontColor(Color.Blue) - - }.onClick(() => { - this.controller.close(); - }) - .alignItems(HorizontalAlign.Center) - .width(ConfigData.WH_50_100); - Divider() - .vertical(true) - .color($r('app.color.divider_color')) - .strokeWidth(1) - .height($r('app.float.divider_height')) - Column() { - Text($r('app.string.confirm')) - .fontSize($r('app.float.dialog_button_font')) - .fontColor(Color.Blue) - - }.onClick(() => { - Log.showInfo(TAG, `confirm button of TimeDialog on click`) - this.controller.close(); - this.action(this.selectedTime); - }) - .alignItems(HorizontalAlign.Center) - .width(ConfigData.WH_50_100) - } - .width(ConfigData.WH_100_100) - .height($r('app.float.dialog_button_height')) - } - .height($r('app.float.timeDialog_height')) - .width(ConfigData.WH_100_100) - } -} - -/** - * select repeat Mode dialog - */ -@CustomDialog -struct RepeatModeDialog { - public controller: CustomDialogController - public action: (data) => void - private title: string= '' - private selectMode: number= 2 //TODO - @State isNo: boolean = true - - build() { - Column({ space: 30 }) { - Column() { - Text(this.title) - .height($r('app.float.dialog_title_height')) - .margin({ left: $r('app.float.dialog_title_margin_l') }) - .width(ConfigData.WH_100_100) - .fontSize($r('app.float.dialog_title_font')) - .fontWeight(FontWeight.Bold) - Row() { - Text($r('app.string.daily')) - .fontSize($r('app.float.repeatDialog_cont_font')) - .fontColor(Color.Black) - .width(ConfigData.WH_70_100) - .textAlign(TextAlign.Start) - .align(Alignment.Start) - Toggle({ type: ToggleType.Checkbox, isOn: this.isNo }) - .align(Alignment.End) - .width($r('app.float.toggle_check_width')) - .height($r('app.float.toggle_check_width')) - .onChange((data) => { - //TODO - this.selectMode = 2 - this.isNo = true - }) - } - } - - Row() { - Column() { - Text($r('app.string.cancel')) - .fontSize($r('app.float.dialog_button_font')) - .fontColor(Color.Blue) - - }.onClick(() => { - this.controller.close(); - }) - .alignItems(HorizontalAlign.Center) - .width(ConfigData.WH_50_100); - Divider() - .vertical(true) - .color($r('app.color.divider_color')) - .strokeWidth(1) - .height($r('app.float.divider_height')) - Column() { - Text($r('app.string.confirm')) - .fontSize($r('app.float.dialog_button_font')) - .fontColor(Color.Blue) - - }.onClick(() => { - Log.showInfo(TAG, `confirm button of TimeDialog on click`) - this.controller.close(); - this.action(this.selectMode); - }) - .alignItems(HorizontalAlign.Center) - .width(ConfigData.WH_50_100) - } - .width(ConfigData.WH_100_100) - .height($r('app.float.dialog_button_height')) - } - .height($r('app.float.repeatDialog_height')) - .width(ConfigData.WH_100_100) - } -} diff --git a/product/notificationmanagement/src/main/ets/default/pages/notificationManagenment.ets b/product/notificationmanagement/src/main/ets/default/pages/notificationManagenment.ets deleted file mode 100644 index 38dacaec..00000000 --- a/product/notificationmanagement/src/main/ets/default/pages/notificationManagenment.ets +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//import Window from '@ohos.window'; - -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; -import HeadComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headComponent.ets'; -import NoDisturbComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/noDisturbComponent.ets'; -import ItemComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/itemComponent.ets'; -import ConfigData from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/common/constants.ets'; -import AppLstComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/appLstComponent.ets'; -import Router from '@system.router'; - -const TAG = 'NotificationManagement-Main'; - -@Entry -@Component -export default struct notificationManagenment { - build() { - Column() { - Row() { - HeadComponent({ headName: $r('app.string.notification'), isActive: true }); - }.flexShrink(0) - - Row() { - Text($r('app.string.noDisturb')) - .fontSize($r('app.float.page_phrases_font')) - .height($r('app.float.page_phrases_height')) - .margin({ left: $r('app.float.page_margin_l'), bottom: $r('app.float.page_margin_t') }) - }.align(Alignment.Start) - .width(ConfigData.WH_100_100) - .flexShrink(0) - - Row() { - NoDisturbComponent() - } - .align(Alignment.Start) - .onClick(() => { - Log.showInfo(TAG, `NoDisturbComponent on click`) - Router.push({ uri: 'pages/noDisturb'}); - }).width(ConfigData.WH_100_100) - .flexShrink(0) - - Row() { - Text($r('app.string.notificationManagement')) - .fontSize($r('app.float.page_phrases_font')) - .height($r('app.float.page_phrases_height')) - .margin({ left: $r('app.float.page_margin_l'), bottom: $r('app.float.page_margin_t') }) - }.align(Alignment.Start) - .width(ConfigData.WH_100_100) - .flexShrink(0) - - Row() { - ItemComponent({ title: $r('app.string.batch_Management'), value: '', arrow: $r('app.media.ic_settings_arrow') }) - }.onClick(() => { - Log.showInfo(TAG, `BatchManagement on click`) - Router.push({ uri: 'pages/batchSetEnable' }); - }).width(ConfigData.WH_100_100) - .flexShrink(0) - - Column() { - AppLstComponent() - }.flexShrink(1) - } - .backgroundColor($r('app.color.background_color')) - .width(ConfigData.WH_100_100) - .height(ConfigData.WH_100_100); - } - - aboutToAppear(): void{ - Log.showInfo(TAG, `aboutToAppear`) - } - - aboutToDisappear(): void{ - Log.showInfo(TAG, `aboutToDisappear`) - } - - onPageShow(): void{ - Log.showInfo(TAG, `onPageShow`) - } - - onBackPress() { - Log.showInfo(TAG, `onBackPress`) - } -} diff --git a/product/notificationmanagement/src/main/ets/default/pages/setEnable.ets b/product/notificationmanagement/src/main/ets/default/pages/setEnable.ets deleted file mode 100644 index 1481d29f..00000000 --- a/product/notificationmanagement/src/main/ets/default/pages/setEnable.ets +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//import Window from '@ohos.window'; -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; -import HeadComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headComponent.ets'; -import AppItemComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/appItemComponent.ets'; -import SwitchComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/switchComponent.ets'; -import SlotLstComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/slotLstComponent.ets'; -import ConfigData from '../common/constants.ets'; -import Router from '@system.router' - -const TAG = 'NotificationManagement-SetEnable'; - -let appInfo; - -@Entry -@Component -export default struct SetEnable { - build() { - Flex({ justifyContent: FlexAlign.SpaceBetween }) { - Column({ space: 30 }) { - HeadComponent({ headName: $r('app.string.notificationManagement'), isActive: true }); - Row() { - AppItemComponent({ - appIcon: appInfo.appIcon, - appTitle: appInfo.appTitle, - appSummary: appInfo.appSummary, - appValue: '', - appArrow: appInfo.appArrow, - appArrowStyle: '', - appUri: appInfo.appUri, - appBundleName: appInfo.appBundleName, - appUid: appInfo.appUid, - appSwitch: 0 - }); - } - .margin({ left: $r('app.float.page_margin_l'), right: $r('app.float.page_margin_r') }) - .align(Alignment.Start) - .backgroundColor($r('app.color.background_color')) - - - Row() { - SwitchComponent({ - title: $r('app.string.allowNotification'), - appBundleName: appInfo.appBundleName, - appUid: appInfo.appUid - }) - }.margin({ left: $r('app.float.page_margin_l'), - right: $r('app.float.page_margin_r') }) - .align(Alignment.Start) - - Row() { - SlotLstComponent({ appBundleName: appInfo.appBundleName, - appUid: appInfo.appUid }) - } - .align(Alignment.Start) - } - .alignItems(HorizontalAlign.Start) - .backgroundColor($r('app.color.background_color')) - .width(ConfigData.WH_100_100) - .height(ConfigData.WH_100_100) - } - .width(ConfigData.WH_100_100) - - } - - aboutToAppear(): void{ - Log.showInfo(TAG, `aboutToAppear`) - appInfo = Router.getParams(); - } - - onBackPress() { - Log.showInfo(TAG, `onBackPress`) - Router.back(); - } -} diff --git a/product/notificationmanagement/src/main/ets/default/vm/noDisturbViewModel.ets b/product/notificationmanagement/src/main/ets/default/vm/noDisturbViewModel.ets deleted file mode 100644 index 3d1d51fa..00000000 --- a/product/notificationmanagement/src/main/ets/default/vm/noDisturbViewModel.ets +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import ConfigData from '../common/constants.ets'; -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; -import NoDisturbingModel from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/noDisturbingModel.ets'; -import NoDisturbComponentViewModel from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/vm/noDisturbComponentViewModel.ets'; - -const TAG = 'NotificationManagement-NoDisturbViewModel' - -export default class NoDisturbViewModel extends NoDisturbComponentViewModel { - - endTimeClue: string = '' - - setClues() { - Log.showInfo(TAG, `setClues`) - if (this.startTime > this.endTime) { - this.endTimeClue = ConfigData.NEXT_DAY_NAME + this.endTime - } else { - this.endTimeClue = this.endTime - } - this.defaultStartTime = this.getDateByHHMI(this.startTime) - this.defaultEndTime = this.getDateByHHMI(this.endTime) - } - - setNoDisturbingDate() { - let noDisturbingTime = { - type: this.repeatMode, begin: this.defaultStartTime, end: this.defaultEndTime - } - NoDisturbingModel.setNoDisturbingDate(noDisturbingTime, () => { - Log.showInfo(TAG, 'setNoDisturbingDate is success') - }) - } - - onStartTimeAccept(data) { - Log.showInfo(TAG, `onStartTimeAccept`) - this.startTime = data - this.setClues() - this.setNoDisturbingDate() - - } - - onEndTimeAccept(data) { - Log.showInfo(TAG, `onEndTimeAccept`) - this.endTime = data - this.setClues() - this.setNoDisturbingDate() - } - - onRepeatModeAccect(data) { - Log.showInfo(TAG, `onRepeatModeAccect`) - this.setNoDisturbingDate() - } - - onCancel() { - Log.showInfo(TAG, `onCancel`) - } -} \ No newline at end of file diff --git a/product/notificationmanagement/src/main/resources/base/element/color.json b/product/notificationmanagement/src/main/resources/base/element/color.json deleted file mode 100644 index 9239d9af..00000000 --- a/product/notificationmanagement/src/main/resources/base/element/color.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "color": [ - { - "name": "color_333333_grey", - "value": "#333333" - }, - { - "name": "color_999999_grey", - "value": "#999999" - }, - { - "name": "color_D4D4D4_grey", - "value": "#d4d4d4" - }, - { - "name": "color_E3E3E3_grey", - "value": "#E3E3E3" - }, - { - "name": "color_00000000_transparent", - "value": "#00000000" - }, - { - "name": "color_FBFBFB_grey", - "value": "#FBFBFB" - }, - { - "name": "color_F2F2F2_grey", - "value": "#F2F2F2" - } - ] -} \ No newline at end of file diff --git a/product/notificationmanagement/src/main/resources/base/element/float.json b/product/notificationmanagement/src/main/resources/base/element/float.json deleted file mode 100644 index 4ec88ecc..00000000 --- a/product/notificationmanagement/src/main/resources/base/element/float.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "float": [ - { - "name": "wh_border_1", - "value": "1" - }, - { - "name": "radius_border_30", - "value": "30" - }, - { - "name": "wh_value_5", - "value": "5" - }, - { - "name": "wh_value_10", - "value": "10" - }, - { - "name": "wh_value_15", - "value": "15" - }, - { - "name": "wh_value_50", - "value": "50" - }, - { - "name": "wh_value_20", - "value": "20" - }, - { - "name": "wh_value_30", - "value": "30" - }, - { - "name": "wh_value_40", - "value": "40" - }, - { - "name": "wh_value_60", - "value": "60" - }, - { - "name": "wh_value_65", - "value": "65" - }, - { - "name": "wh_value_70", - "value": "70" - }, - { - "name": "wh_value_100", - "value": "100" - }, - { - "name": "wh_value_280", - "value": "280" - }, - { - "name": "wh_value_590", - "value": "590" - }, - { - "name": "font_16", - "value": "16" - }, - { - "name": "font_18", - "value": "18" - }, - { - "name": "font_20", - "value": "20" - }, - { - "name": "font_24", - "value": "24" - } - ] -} \ No newline at end of file diff --git a/product/statusbar/.gitignore b/product/pc/controlpanel/.gitignore similarity index 100% rename from product/statusbar/.gitignore rename to product/pc/controlpanel/.gitignore diff --git a/product/pc/controlpanel/build.gradle b/product/pc/controlpanel/build.gradle new file mode 100644 index 00000000..37139a6a --- /dev/null +++ b/product/pc/controlpanel/build.gradle @@ -0,0 +1,22 @@ +apply plugin: 'com.huawei.ohos.hap' +ohos { + compileSdkVersion rootProject.ext.version.compileSdk + defaultConfig { + compatibleSdkVersion rootProject.ext.version.compatibleSdk + } + entryModules "pc_entry" +} + +dependencies { + entryImplementation project(':pc_entry') + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testCompile 'junit:junit:4.12' + implementation project(':features:controlcentercomponent') + implementation project(':features:airplanecomponent') + implementation project(':features:autorotatecomponent') + implementation project(':features:bluetoothcomponent') + implementation project(':features:brightnesscomponent') + implementation project(':features:locationcomponent') + implementation project(':features:ringmodecomponent') + implementation project(':features:wificomponent') +} diff --git a/product/pc/controlpanel/package.json b/product/pc/controlpanel/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/product/pc/controlpanel/package.json @@ -0,0 +1 @@ +{} diff --git a/product/pc/controlpanel/src/main/config.json b/product/pc/controlpanel/src/main/config.json new file mode 100644 index 00000000..8b39a12d --- /dev/null +++ b/product/pc/controlpanel/src/main/config.json @@ -0,0 +1,67 @@ +{ + "app": { + "bundleName": "com.ohos.systemui", + "vendor": "ohos", + "version": { + "code": 1, + "name": "1.0" + }, + "singleton": true + }, + "deviceConfig": {}, + "module": { + "package": "com.ohos.systemui.controlpanel", + "name": ".MyApplication", + "deviceType": [ + "tablet" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "pc_controlpanel", + "moduleType": "feature" + }, + "abilities": [ + { + "visible": true, + "skills": [ + { + "actions": [ + "com.ohos.systemui.action.BAR_ICON" + ] + } + ], + "name": "com.ohos.systemui.controlpanel.ServiceExtAbility", + "icon": "$media:ic_controlcenter_oh", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "service", + "launchType": "singleton", + "srcPath": "ServiceExtAbility", + "srcLanguage": "ets", + "metaData": { + "customizeData" : [ + { + "name": "com.ohos.systemui.action.BAR_ICON", + "value": "", + "extra": "\"pluginType\":\"1\",\"clickAction\":\"local=showControlCenter\",\"selectedClickAction\":\"local=hideControlCenter\",\"relationWindowId\":\"SystemUi_ControlPanel\"" + } + ] + } + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "name": "ServiceExtAbility", + "window": { + "designWidth": 1280, + "autoDesignWidth": false + }, + "pages": ["pages/index"] + } + ] + } +} \ No newline at end of file diff --git a/product/pc/controlpanel/src/main/ets/AbilityStage.ts b/product/pc/controlpanel/src/main/ets/AbilityStage.ts new file mode 100644 index 00000000..858fe570 --- /dev/null +++ b/product/pc/controlpanel/src/main/ets/AbilityStage.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" +import Log from '../../../../../../common/src/main/ets/default/Log' + +const TAG = "ControlPanel_AbilityStage" +export default class MainAbilityStage extends AbilityStage { + onCreate() { + Log.showInfo(TAG, "onCreate") + } +} \ No newline at end of file diff --git a/product/pc/controlpanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts new file mode 100644 index 00000000..f018fc24 --- /dev/null +++ b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ServiceExtension from '@ohos.application.ServiceExtensionAbility' +import display from "@ohos.display"; +import Log from "../../../../../../../common/src/main/ets/default/Log"; +import WindowManager, { + WindowType +} from "../../../../../../../common/src/main/ets/default/WindowManager"; +import AbilityManager from "../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager"; + +const TAG = "ControlPanel_ServiceExtAbility"; + +class ServiceExtAbility extends ServiceExtension { + async onCreate(want) { + Log.showInfo(TAG, `api8New onCreate, want: ${JSON.stringify(want)}`); + AbilityManager.setContext(AbilityManager.ABILITY_NAME_CONTROL_PANEL, this.context); + + let dis = await display.getDefaultDisplay(); + Log.showInfo(TAG, `api8New onCreate, dis: ${JSON.stringify(dis)}`); + let rect = { + left: (872 * dis.width) / 1280, + top: (44 * dis.width) / 1280, + width: (402 * dis.width) / 1280, + height: (310 * dis.width) / 1280, + }; + + AbilityManager.setAbilityData(AbilityManager.ABILITY_NAME_CONTROL_PANEL, "rect", rect); + AbilityManager.setAbilityData(AbilityManager.ABILITY_NAME_CONTROL_PANEL, "dis", { + width: dis.width, + height: dis.height, + }); + WindowManager.createWindow(this.context, WindowType.CONTROL_PANEL, rect, "pages/index").then(() => { + Log.showInfo(TAG, `createWindow success.`); + }); + } + + onDestroy() { + Log.showInfo(TAG, "onDestroy"); + } +} + +export default ServiceExtAbility; diff --git a/product/pc/controlpanel/src/main/ets/ServiceExtAbility/app.ets b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/app.ets new file mode 100644 index 00000000..5d2d9ef2 --- /dev/null +++ b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/app.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('SystemUI ControlPanel Application onCreate') + }, + onDestroy() { + console.info('SystemUI ControlPanel Application onDestroy') + }, +} diff --git a/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/ControlCenterConfig.ts b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/ControlCenterConfig.ts new file mode 100644 index 00000000..44173d27 --- /dev/null +++ b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/ControlCenterConfig.ts @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {FASlotName} from '../../../../../../../../../common/src/main/ets/default/Constants'; + +type pluginIconData = { + id: string; + bundleName: string; + abilityName: string; +}; +type Config = { + ComplexToggleLayout: Array; + DefaultSimpleToggleLayout: Array; + LocalToggles: { + ComplexToggles: Array; + SimpleToggles: Array; + }; + MetaToggles: Array; +}; + +const ControlCenterConfig: Config = { + ComplexToggleLayout: [FASlotName.WIFI, FASlotName.BLUETOOTH], + DefaultSimpleToggleLayout: ["screenshot", FASlotName.RING_MODE, FASlotName.LOCATION], + LocalToggles: { + ComplexToggles: [FASlotName.AIR_PLANE, FASlotName.BLUETOOTH, FASlotName.WIFI], + SimpleToggles: [FASlotName.LOCATION, FASlotName.RING_MODE], + }, + MetaToggles: [ + { + id: "screenshot", + bundleName: "com.ohos.screenshot", + abilityName: "com.ohos.screenshot.ServiceExtAbility", + }, + ], +}; + +export default ControlCenterConfig; diff --git a/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts new file mode 100644 index 00000000..e54b8095 --- /dev/null +++ b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import StyleManager from '../../../../../../../../../common/src/main/ets/default/StyleManager'; + +const TAG = 'ControlPanel-StyleConfiguration'; + +export default class StyleConfiguration { + static getIndexStyle() { + const key: string = TAG + "-Index"; + return StyleManager.getStyle(key, () => { + return { + borderRadius: $r('app.float.default_border_radius') + }; + }); + } +} \ No newline at end of file diff --git a/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts new file mode 100644 index 00000000..ec385fe1 --- /dev/null +++ b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../../common/src/main/ets/default/Log'; +import AbilityManager from '../../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager'; +import CommonTemplateStyleConfiguration from '../../../../../../../../../common/src/main/ets/template/common/StyleConfiguration'; +import ControlCenterStyleConfiguration from '../../../../../../../../../features/controlcentercomponent/src/main/ets/com/ohos/common/StyleConfiguration' +import BrightnessStyleConfiguration from '../../../../../../../../../features/brightnesscomponent/src/main/ets/default/common/StyleConfiguration' +import RingModeStyleConfiguration from '../../../../../../../../../features/ringmodecomponent/src/main/ets/com/ohos/common/StyleConfiguration' +import IndexStyleConfiguration from './StyleConfiguration' + +const TAG = 'ControlPanel-StyleManager'; + +export default class StyleManager { + static STANDARD_DISPLAY_WIDTH: number = 1280; + static STANDARD_DISPLAY_HEIGHT: number = 800; + static maxWidth: number = StyleManager.STANDARD_DISPLAY_WIDTH; + + static setStyle() { + Log.showInfo(TAG, `setStyle`) + + let dis = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_CONTROL_PANEL, 'dis'); + StyleManager.maxWidth = dis.width; + + // Index + { + let style: any = IndexStyleConfiguration.getIndexStyle(); + style.borderRadius = StyleManager.calcScaleSizePx(24); + } + + // ControlCenter + { + let style: any = ControlCenterStyleConfiguration.getControlCenterComponentStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(20); + style.marginRight = StyleManager.calcScaleSizePx(20); + style.marginTop = StyleManager.calcScaleSizePx(0); + style.upTitleHeight = StyleManager.calcScaleSizePx(56); + style.titleMarginBottom = StyleManager.calcScaleSizePx(0); + style.toggleAreaGap = StyleManager.calcScaleSizePx(12); + style.simpleToggleLayoutMarginTop = StyleManager.calcScaleSizePx(23); + style.simpleToggleLayoutMarginBottom = StyleManager.calcScaleSizePx(0); + style.brightnessMarginBottom = StyleManager.calcScaleSizePx(12); + style.componentBorderRadius = StyleManager.calcScaleSizePx(24); + style.componentBackgroundColor = '#99FFFFFF'; + } + + // ControlCenter-Title + { + let style: any = ControlCenterStyleConfiguration.getControlCenterUpTitleStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(24); + style.marginRight = StyleManager.calcScaleSizePx(21); + style.fontSize = StyleManager.calcScaleSizePx(20); + style.fontColor = '#000000'; + style.imageWidth = StyleManager.calcScaleSizePx(24); + style.imageHeight = StyleManager.calcScaleSizePx(24); + style.imageHoverWidth = StyleManager.calcScaleSizePx(32); + style.imageHoverHeight = StyleManager.calcScaleSizePx(32); + style.imageHoverRadius = StyleManager.calcScaleSizePx(8); + style.imageHoverColor = 'rgba(0, 0, 0, 0.05)'; + style.imageTransparentColor = 'rgba(255, 255, 255, 0)'; + style.upTitleSpace = StyleManager.calcScaleSizePx(24); + style.titleImageColor = '#ff182431'; + } + + // ControlCenter-ComplexToggleLayout + { + let style: any = ControlCenterStyleConfiguration.getControlCenterComplexToggleLayoutStyle(); + style.columnGap = StyleManager.calcScaleSizePx(12); + style.rowGap = StyleManager.calcScaleSize(12); + style.rowHeight = StyleManager.calcScaleSize(66); + } + + // ControlCenter-SimpleToggleLayout + { + let style: any = ControlCenterStyleConfiguration.getControlCenterSimpleToggleLayoutStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(11); + style.marginRight = StyleManager.calcScaleSizePx(11); + style.columnGap = StyleManager.calcScaleSizePx(0); + style.rowGap = StyleManager.calcScaleSize(0); + style.rowHeight = StyleManager.calcScaleSize(81); + } + + // CommonTemplate-iconTitleBase + { + let style: any = CommonTemplateStyleConfiguration.getIconTitleBaseStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(8); + style.marginRight = StyleManager.calcScaleSizePx(4); + style.componentGap = StyleManager.calcScaleSizePx(8); + style.titleSize = StyleManager.calcScaleSizePx(12); + style.titleColor = $r("sys.color.ohos_id_color_text_secondary"), + style.borderRadius = StyleManager.calcScaleSizePx(24); + style.backgroundColor = '#99FFFFFF'; + style.textMargin = StyleManager.calcScaleSizePx(8); + style.textHoverHeight = StyleManager.calcScaleSizePx(26); + style.textHoverWidth = StyleManager.calcScaleSizePx(68); + style.textHoverRadius = StyleManager.calcScaleSizePx(4); + style.hoverColor = 'rgba(0, 0, 0, 0.05)'; + style.transparentColor = 'rgba(255, 255, 255, 0)'; + } + + // CommonTemplate-iconComponent + { + let style: any = CommonTemplateStyleConfiguration.getIconComponentStyle(); + style.circleWidth = StyleManager.calcScaleSizePx(48); + style.circleHeight = StyleManager.calcScaleSizePx(48); + style.iconWidth = StyleManager.calcScaleSizePx(24); + style.iconHeight = StyleManager.calcScaleSizePx(24); + style.iconOffBG = '#1A000000'; + style.iconOnBG = '#FF007DFF'; + style.iconOnColor = '#FFFFFFFF'; + style.iconOffColor = $r("sys.color.ohos_id_color_secondary"); + style.hoverColor = 'rgba(0, 0, 0, 0.05)'; + style.transparentColor = 'rgba(255, 255, 255, 0)'; + } + + // CommonTemplate-simpleToggleBase + { + let style: any = CommonTemplateStyleConfiguration.getSimpleToggleBaseStyle(); + style.circleWidth = StyleManager.calcScaleSizePx(48); + style.circleHeight = StyleManager.calcScaleSizePx(48); + style.iconWidth = StyleManager.calcScaleSizePx(24); + style.iconHeight = StyleManager.calcScaleSizePx(24); + style.dragCircleWidth = StyleManager.calcScaleSizePx(60); + style.dragCircleHeight = StyleManager.calcScaleSizePx(60); + style.dragIconWidth = StyleManager.calcScaleSizePx(36); + style.dragIconHeight = StyleManager.calcScaleSizePx(36); + style.iconOffBG = '#1A000000'; + style.iconOnBG = '#FF007DFF'; + style.iconOnColor = '#FFFFFFFF'; + style.iconOffColor = $r("sys.color.ohos_id_color_secondary"); + style.componentGap = StyleManager.calcScaleSizePx(4); + style.titleSize = StyleManager.calcScaleSizePx(12); + style.titleColor = $r("sys.color.ohos_id_color_text_secondary"); + style.textHoverWidth = StyleManager.calcScaleSizePx(68); + style.textHoverHeight = StyleManager.calcScaleSizePx(18); + style.textHoverRadius = StyleManager.calcScaleSizePx(4); + style.hoverColor = 'rgba(0, 0, 0, 0.05)'; + style.transparentColor = 'rgba(255, 255, 255, 0)'; + } + + // Brightness + { + let style: any = BrightnessStyleConfiguration.getBrightnessComponentStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(12.5); + style.marginRight = StyleManager.calcScaleSizePx(12.5); + style.componentGap = StyleManager.calcScaleSizePx(8.5); + style.brightnessIconColor = $r("sys.color.ohos_id_color_secondary"); + style.brightnessReduceWidth = StyleManager.calcScaleSizePx(22); + style.brightnessReduceHeight = StyleManager.calcScaleSizePx(22); + style.brightnessPlusWidth = StyleManager.calcScaleSizePx(22); + style.brightnessPlusHeight = StyleManager.calcScaleSizePx(22); + style.brightnessHeight = StyleManager.calcScaleSizePx(40); + style.sliderHeight = px2vp(StyleManager.calcScaleSize(20)) + 'vp'; + style.sliderBlockColor = '#FFFFFFFF'; + style.sliderTrackColor = '#0D000000'; + style.sliderSelectedColor = '#FF007DFF'; + } + + // RingMode + { + let style: any = RingModeStyleConfiguration.getControlCenterRingModeComponentStyle(); + style.brightnessIconColor = '#FFFF9800'; + } + + // SimpleToggleLayoutEdit + { + let style: any = ControlCenterStyleConfiguration.getSimpleToggleLayoutEditComponentStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(0); + style.marginRight = StyleManager.calcScaleSizePx(0); + style.marginTop = StyleManager.calcScaleSizePx(0); + style.titleHeight = StyleManager.calcScaleSizePx(56); + style.titleMarginBottom = StyleManager.calcScaleSizePx(0); + style.upGridMarginTop = StyleManager.calcScaleSizePx(4); + style.upGridMarginBottom = StyleManager.calcScaleSizePx(20); + style.gridMarginLeft = StyleManager.calcScaleSizePx(21); + style.gridMarginRight = StyleManager.calcScaleSizePx(21); + style.msgMarginTop = StyleManager.calcScaleSizePx(0); + style.msgMarginBottom = StyleManager.calcScaleSizePx(4); + style.btnMarginTop = StyleManager.calcScaleSizePx(4); + style.btnMarginBottom = StyleManager.calcScaleSizePx(16); + style.borderRadius = StyleManager.calcScaleSizePx(24); + style.upAreaBgColor = '#00FFFFFF'; + style.downAreaBgColor = '#4DFFFFFF'; + style.editBtnFontColor = '#FF007DFF'; + style.editBtnFontSize = $r("sys.float.ohos_id_text_size_button1"); + style.editBtnBgColor = '#0D000000'; + style.editBtnMarginLeft = StyleManager.calcScaleSizePx(16); + style.editBtnMarginRight = StyleManager.calcScaleSizePx(16); + style.editBtnHeight = StyleManager.calcScaleSizePx(40); + style.editBtnSpace = StyleManager.calcScaleSizePx(16); + } + + // SimpleToggleLayoutEdit-title + { + let style: any = ControlCenterStyleConfiguration.getSimpleToggleLayoutEditUpTitleStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(24); + style.imageWidth = StyleManager.calcScaleSizePx(20); + style.imageHeight = StyleManager.calcScaleSizePx(20); + style.fontColor = '#FF000000'; + style.editTitleSpace = StyleManager.calcScaleSizePx(18); + style.titleFontSize = StyleManager.calcScaleSizePx(20); + } + + // SimpleToggleLayoutEdit-msg + { + let style: any = ControlCenterStyleConfiguration.getSimpleToggleLayoutEditOptMsgStyle(); + style.fontSize = StyleManager.calcScaleSizePx(12); + style.fontColor = $r('sys.color.ohos_id_color_text_secondary'); + style.height = StyleManager.calcScaleSizePx(41); + style.marginLeftRight = StyleManager.calcScaleSizePx(30); + } + + // SimpleToggleLayoutEdit-grid + { + let style: any = ControlCenterStyleConfiguration.getSimpleToggleLayoutEditGridStyle(); + style.columnGap = StyleManager.calcScaleSizePx(0); + style.rowGap = StyleManager.calcScaleSize(0); + style.rowHeight = StyleManager.calcScaleSize(80); + style.dragBgSize = StyleManager.calcScaleSizePx(60); + } + + // EditDialog + { + let style: any = ControlCenterStyleConfiguration.getControlEditDialogStyle(); + style.editDialogHeight = StyleManager.calcScaleSizePx(121); + style.editDialogWidth = StyleManager.calcScaleSizePx(374); + style.editDialogFontSize = StyleManager.calcScaleSizePx(18); + style.editDialogBtnMarginLF = StyleManager.calcScaleSizePx(13); + style.editDialogFontHeight = StyleManager.calcScaleSizePx(20); + style.editDialogBtnMarginTop = StyleManager.calcScaleSizePx(20); + style.editDialogButtonSize = StyleManager.calcScaleSizePx(18); + style.editDialogDividerHeight = StyleManager.calcScaleSizePx(20); + style.editDialogButtonHeight = StyleManager.calcScaleSizePx(30); + style.editDialogRadius = StyleManager.calcScaleSizePx(20); + style.editDialogBtnWidth = StyleManager.calcScaleSizePx(173); + style.editDialogFontMarginTop = StyleManager.calcScaleSizePx(29); + style.editDialogColor = '#FFFFFFFF'; + style.editDialogBtnFontColor = '#FF0000FF'; + style.editDialogBtnBgColor = '#00FFFFFF'; + style.editDialogDividerColor = $r("sys.color.ohos_id_color_secondary"); + style.editDialogDividerWidth = StyleManager.calcScaleSizePx(1); + Log.showInfo(TAG, `getControlEditDialogStyle`) + } + + } + + static number2px(n: number): string { + return n.toString() + 'px'; + } + + static calcScaleSize(n: number): number { + return n * StyleManager.maxWidth / StyleManager.STANDARD_DISPLAY_WIDTH; + } + + static calcScaleSizePx(n: number): string { + return StyleManager.number2px(StyleManager.calcScaleSize(n)); + } +} \ No newline at end of file diff --git a/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts new file mode 100644 index 00000000..b3ed15d1 --- /dev/null +++ b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class Constants { + static DEFAULT_SIMPLE_TOGGLE_COLUMN_COUNT = 5; +} \ No newline at end of file diff --git a/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/control.ets b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/control.ets new file mode 100644 index 00000000..0ec03116 --- /dev/null +++ b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/control.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import ControlCenterComponent from '../../../../../../../../features/controlcentercomponent/src/main/ets/com/ohos/pages/ControlCenterComponent' +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import Constants from './common/constants' +import ControlCenterConfig from './common/ControlCenterConfig'; + +const TAG = 'ControlPanel-Control'; + +@Component +export default struct Control { + private modeChangeCallback: Function + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear Start`) + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisAppear`) + } + + build() { + Column() { + ControlCenterComponent({ + mControlCenterComponentConfig: ControlCenterConfig, + mSimpleToggleColumnCount: Constants.DEFAULT_SIMPLE_TOGGLE_COLUMN_COUNT, + modeChangeCallback: (isEdit) => this.modeChangeCallback(isEdit), + titleDisplayInside: true + }) + } + .width('100%') + } +} \ No newline at end of file diff --git a/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/index.ets b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/index.ets new file mode 100644 index 00000000..568bca21 --- /dev/null +++ b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/pages/index.ets @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import image from "@ohos.multimedia.image" +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import CommonStyleManager from '../../../../../../../../common/src/main/ets/default/StyleManager' +import HeightConfigUtils from '../../../../../../../../common/src/main/ets/default/heightcofigUtils/HeightConfigUtils' +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/AbilityManager' +import StyleConfiguration from './common/StyleConfiguration' +import StyleManager from './common/StyleManager' +import ControlCenterComponent from './control' +import WindowManager, { + WindowType, + WINDOW_SHOW_HIDE_EVENT, +} from "../../../../../../../../common/src/main/ets/default/WindowManager"; +import EventManager, {unsubscribe} from "../../../../../../../../common/src/main/ets/default/event/EventManager"; +import {START_ABILITY_EVENT} from "../../../../../../../../common/src/main/ets/default/event/EventUtil"; +import MultimodalInputManager, { + MultiKeyCode, +} from "../../../../../../../../common/src/main/ets/default/MultimodalInputManager"; + + +const TAG = 'ControlPanel-Index' +const SHOW_EVENT = "showControlCenter"; +const HIDE_EVENT = "hideControlCenter"; +const SHOW_ANIM_CONFIG = { + duration: 300, + tempo: 1.0, + curve: Curve.Friction, + delay: 0, + iterations: 1, + playMode: PlayMode.Normal +}; +const HIDE_ANIM_CONFIG = { + duration: 200, + tempo: 1.0, + curve: Curve.EaseOut, + delay: 0, + iterations: 1, + playMode: PlayMode.Normal, +} + +let mHeightConfigUtils + +@Entry +@Component +struct Index { + @StorageLink('StatusCoefficient') StatusCoefficient: number = 1.0 + @State style: any = {} + @State mBackground: PixelMap | undefined = undefined; + @State mBlur: number = 0; + @State mOpacity: number = 0.0; + @State mWidthSize: number = 0.2 + @State mHeightSize: number = 0.2 + @State mHeightPx: number = 0 + mClearCallbacks: Array = []; + mShowAnimReady: boolean = false; + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear, start`) + + setAppBgColor('#00000000') + CommonStyleManager.setAbilityPageName(TAG) + this.style = StyleConfiguration.getIndexStyle() + StyleManager.setStyle() + + let rect = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_CONTROL_PANEL, 'rect') + this.mHeightPx = rect.height + + mHeightConfigUtils = new HeightConfigUtils(); + let StatusCoefficient; + + StatusCoefficient = AppStorage.SetAndLink("StatusCoefficient", 1.0); + StatusCoefficient.set(mHeightConfigUtils.getStatusCoefficient()); + + this.initWindowPolicy(); + Log.showInfo(TAG, `aboutToAppear, end`) + } + + onPageShow() { + this.startShowAnim(); + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisappear`) + this.mClearCallbacks.forEach((unsubscribe) => unsubscribe()); + this.mClearCallbacks.length = 0; + } + + build() { + Stack({ alignContent: Alignment.Top }) { + Image(this.mBackground) + .width('100%') + .height('100%') + .objectFit(ImageFit.Fill) + Column() { + Scroll(new Scroller()) { + Column() { + ControlCenterComponent({ + modeChangeCallback: (isEdit) => this.onModeChange(isEdit) + }) + } + .width('100%') + .onAreaChange((e, e2) => { + Log.showInfo(TAG, `onAreaChange, e: ${JSON.stringify(e)} e2: ${JSON.stringify(e2)}`); + }) + } + .scrollBarColor(Color.Gray) + .scrollBarWidth(10) + .width('100%') + } + .backgroundColor($r('app.color.default_background')) + .width('100%') + .height('100%') + } + .scale({ + x: this.mWidthSize, + y: this.mHeightSize, + z: 1, + centerX: '100%', + centerY: '0%' + }) + .opacity(this.mOpacity) + .clip(true) + .borderRadius(this.style.borderRadius) + .width('100%') + .height(this.mHeightPx + 'px') + } + + initWindowPolicy() { + Log.showInfo(TAG, `init controlcenter panel window Policy`); + this.mClearCallbacks.push( + EventManager.subscribe(SHOW_EVENT, () => WindowManager.showWindow(WindowType.CONTROL_PANEL)), + EventManager.subscribe(HIDE_EVENT, () => this.hideWindow()), + EventManager.subscribe(START_ABILITY_EVENT, () => this.hideWindow()), + EventManager.subscribe(WINDOW_SHOW_HIDE_EVENT, (args) => { + let { windowName, isShow } = args; + Log.showInfo(TAG, `WINDOW_SHOW_HIDE_EVENT windowName: ${windowName}, isShow: ${isShow}`); + windowName == WindowType.NOTIFICATION_PANEL && isShow && this.hideWindow(); + windowName == WindowType.CONTROL_PANEL && isShow && (this.mShowAnimReady = true); + }), + MultimodalInputManager.subscribeCombinationKey([MultiKeyCode.WIN, MultiKeyCode.I], (data) => { + let windowInfo = WindowManager.getWindowInfo(WindowType.CONTROL_PANEL); + Log.showInfo(TAG, `on CombinationKeyEvent: data: ${data}, windowInfo: ${windowInfo?.visibility}`); + if (windowInfo) { + windowInfo.visibility + ? this.hideWindow() + : WindowManager.showWindow(WindowType.CONTROL_PANEL); + } + }) + ); + } + + _animateTo(config, callback) { + animateTo(config, callback) + setTimeout(config.onFinish, config.duration + config.delay) + } + + async startShowAnim() { + if (!this.mShowAnimReady) { + return; + } + this.mShowAnimReady = false; + this._animateTo({ ...SHOW_ANIM_CONFIG, onFinish: () => { + Log.showInfo(TAG, `show anim finish.`); + this.mBlur = 20; + } }, () => { + this.mBlur = 20 + this.mOpacity = 1.0 + this.mWidthSize = 1.0 + this.mHeightSize = 1.0 + }) + } + + hideWindow() { + Log.showInfo(TAG, `hide anim start: ${JSON.stringify(this)}`); + this._animateTo({ ...HIDE_ANIM_CONFIG, onFinish: () => { + Log.showInfo(TAG, `anim finish, hide Notification window.`); + this.mBlur = 0 + WindowManager.hideWindow(WindowType.CONTROL_PANEL); + } + }, () => { + this.mBlur = 0 + this.mOpacity = 0.0 + this.mWidthSize = 0.2 + this.mHeightSize = 0.2 + }) + } + + onModeChange(isEdit) { + Log.showInfo(TAG, `onModeChange, isEdit: ${isEdit}`) + let initRect = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_CONTROL_PANEL, 'rect') + let newRect = initRect + if (isEdit) { + let dis = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_CONTROL_PANEL, 'dis') + newRect = { ...initRect, height: StyleManager.calcScaleSize(346) } + } + Log.showInfo(TAG, `onModeChange, newRect: ${JSON.stringify(newRect)}`) + this._animateTo({ + duration: 300, + tempo: 1.0, + curve: Curve.Friction, + delay: 0, + iterations: 1, + playMode: PlayMode.Normal, + onFinish: () => { + Log.showInfo(TAG, `onModeChange, show anim finish.`) + if (newRect.height <= initRect.height) { + WindowManager.resetSizeWindow(WindowType.CONTROL_PANEL, newRect) + } + } + }, () => { + Log.showInfo(TAG, `onModeChange, animateTo`) + if (newRect.height > initRect.height) { + WindowManager.resetSizeWindow(WindowType.CONTROL_PANEL, newRect) + } + this.mHeightPx = newRect.height + }) + } +} diff --git a/product/statusbar/src/main/ets/default/workers/PluginDataSourceWorker.js b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js similarity index 59% rename from product/statusbar/src/main/ets/default/workers/PluginDataSourceWorker.js rename to product/pc/controlpanel/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js index 4b3d78f1..3135d74c 100644 --- a/product/statusbar/src/main/ets/default/workers/PluginDataSourceWorker.js +++ b/product/pc/controlpanel/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,17 +13,17 @@ * limitations under the License. */ -import worker from '@ohos.worker'; -import Log from '../../../../../../../common/src/main/ets/default/Log.ets'; +import worker from "@ohos.worker"; +import Log from "../../../../../../../../common/src/main/ets/default/Log"; import PluginDataSourceManager -from '../../../../../../../common/src/main/ets/plugindatasource/PluginDataSourceManager.ets'; -import Constants, {obtainMsg} from '../../../../../../../common/src/main/ets/plugindatasource/common/Constants.ets'; +from "../../../../../../../../common/src/main/ets/plugindatasource/PluginDataSourceManager"; +import Constants, { obtainMsg } from "../../../../../../../../common/src/main/ets/plugindatasource/common/Constants"; -const parentPort = worker.parentPort -const TAG = `${parentPort.name} Worker` -Log.showInfo(TAG, `Start.`) +const parentPort = worker.parentPort; +const TAG = `${parentPort.name} Worker`; +Log.showInfo(TAG, `Start.`); -var sManager +var sManager; parentPort.onmessage = (msg) => { Log.showInfo(TAG, `onMessage, msg = ${JSON.stringify(msg)}`); @@ -41,19 +41,21 @@ parentPort.onmessage = (msg) => { default: Log.showError(TAG, `onMessage, unknown action type.`); } -} +}; function initConfig(config) { Log.showInfo(TAG, `initConfig, config = ${JSON.stringify(config)}`); - sManager = new PluginDataSourceManager(); - sManager.onItemAdd = (itemData) => { - Log.showInfo(TAG, `sManager.onItemAdd, itemData = ${JSON.stringify(itemData)}`); - parentPort.postMessage(obtainMsg(Constants.ADD_ITEM, itemData)); - }; - sManager.onItemRemove = (itemData) => { - Log.showInfo(TAG, `sManager.onItemRemove, itemData = ${JSON.stringify(itemData)}`); - parentPort.postMessage(obtainMsg(Constants.REMOVE_ITEM, itemData)); - }; + sManager = new PluginDataSourceManager({ + onItemAdd: (itemData) => { + Log.showInfo(TAG, `sManager.onItemAdd, itemData = ${JSON.stringify(itemData)}`); + itemData.label && (itemData.label = encodeURIComponent(itemData.label)); + parentPort.postMessage(obtainMsg(Constants.ADD_ITEM, itemData)); + }, + onItemRemove: (itemData) => { + Log.showInfo(TAG, `sManager.onItemRemove, itemData = ${JSON.stringify(itemData)}`); + parentPort.postMessage(obtainMsg(Constants.REMOVE_ITEM, itemData)); + }, + }); sManager.initDataSource(config); parentPort.postMessage(obtainMsg(Constants.INIT_FINISH, {})); } @@ -70,13 +72,15 @@ function loadData(userId) { parentPort.onclose = function () { Log.showInfo(TAG, `onclose`); -} +}; parentPort.onmessageerror = function () { Log.showInfo(TAG, `onmessageerror`); -} +}; parentPort.onerror = function (data) { - Log.showInfo(TAG, - `onerror, lineno = ${data.lineno}, msg = ${data.message}, filename = ${data.filename}, col = ${data.colno}`); -} \ No newline at end of file + Log.showInfo( + TAG, + `onerror, lineno = ${data.lineno}, msg = ${data.message}, filename = ${data.filename}, col = ${data.colno}` + ); +}; \ No newline at end of file diff --git a/product/pc/controlpanel/src/main/resources/base/element/color.json b/product/pc/controlpanel/src/main/resources/base/element/color.json new file mode 100644 index 00000000..242e5372 --- /dev/null +++ b/product/pc/controlpanel/src/main/resources/base/element/color.json @@ -0,0 +1,12 @@ +{ + "color": [ + { + "name": "default_background", + "value": "#F2F1F3F5" + }, + { + "name": "default_font_color", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/product/pc/controlpanel/src/main/resources/base/element/float.json b/product/pc/controlpanel/src/main/resources/base/element/float.json new file mode 100644 index 00000000..8cda5658 --- /dev/null +++ b/product/pc/controlpanel/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "default_border_radius", + "value": "24vp" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/product/pc/controlpanel/src/main/resources/base/element/string.json similarity index 100% rename from entry/src/main/resources/base/element/string.json rename to product/pc/controlpanel/src/main/resources/base/element/string.json diff --git a/product/pc/controlpanel/src/main/resources/base/media/ic_controlcenter_oh.png b/product/pc/controlpanel/src/main/resources/base/media/ic_controlcenter_oh.png new file mode 100644 index 0000000000000000000000000000000000000000..1e83d4a277acb311d294a9679f046dc377e32286 GIT binary patch literal 1161 zcmV;41a|w0P)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91NT34%1ONa40RR91KmY&$0H8q)E&u=n^GQTORCodHT+M0~F%+Kqhq$p8 zy@;>Sg$ROOSfRLfW049zfru|q7kvf6g-PFJdv+%RW0;$@sJcTSsaPnx{|1fr9AW3ErvgZt>zre7zWH0dK>68iEy6tGm2W12^5o-Kg3}RR%EWF~D@j0njSgMynkzcDwj+v2i)p*lilW#UnFD{?eWu z*VrRIJmAq@+M~@E;Nuzi!J)7Ad%73u69%Xn6hHesMmxW&ic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P>4I&$}y { + Log.showInfo(TAG, `api8New onCreate, createWindow callback`); + }); + + AbilityManager.setContext(AbilityManager.ABILITY_NAME_BANNER_NOTICE, this.context); + let bannerRect = { + left: 872 * dis.width / 1280, + top: 44 * dis.width / 1280, + width: 402 * dis.width / 1280, + height: 100 * dis.width / 1280 + } + AbilityManager.setAbilityData(AbilityManager.ABILITY_NAME_BANNER_NOTICE, 'bannerRect', bannerRect); + WindowManager.createWindow(this.context, WindowType.BANNER_NOTICE, bannerRect, 'pages/bannerNotification') + .then((win) => { + Log.showInfo(TAG, `api8New onCreate, createWindow callback`); + }) + .catch((err) => Log.showError(TAG, `Can't create window, err:${err}`)); + } + + onDestroy() { + Log.showInfo(TAG, "api8New onDestroy"); + } +} + +export default ServiceExtAbility; diff --git a/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/app.ets b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/app.ets new file mode 100644 index 00000000..08c517ce --- /dev/null +++ b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/app.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('SystemUI NotificationPanel Application onCreate') + }, + onDestroy() { + console.info('SystemUI NotificationPanel Application onDestroy') + }, +} diff --git a/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/bannerNotification.ets b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/bannerNotification.ets new file mode 100644 index 00000000..db316176 --- /dev/null +++ b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/bannerNotification.ets @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import WindowManager, { WindowType } from '../../../../../../../../common/src/main/ets/default/WindowManager' +import EventManager, {unsubscribe} from "../../../../../../../../common/src/main/ets/default/event/EventManager" +import BannerNotification from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/view/item/bannerNotificationItem' +import ViewModel from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/viewmodel/ViewModel'; +import NotificationConstants, { ScreenLockStatus } from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/common/constants'; + +const TAG = 'NotificationPanel-BannerNotification' + + +@Entry +@Component +struct Index { + @State distributedDeviceName: string = ''; + @State mBannerNoticeCnt: number = 0; + @State mLastActionTime: number = 0; + @State needExpand: boolean = true + @State isExpand: boolean = false; + @State pageData: any = {}; + + mClearCallbacks: unsubscribe[] + mDefaultBannerRect: any; + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear Start`) + setAppBgColor('#00000000') + this.mClearCallbacks = [] + this.mClearCallbacks.push(EventManager.subscribe('onBannerNoticeShow', () => this.onBannerNoticeShow())) + this.mClearCallbacks.push(EventManager.subscribe('onBannerNoticeHide', () => this.onBannerNoticeHide())) + Log.showInfo(TAG, `aboutToAppear End`) + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisAppear`) + this.mClearCallbacks.forEach((mClearCallback: Function) => { + mClearCallback() + mClearCallback = undefined + }) + this.mClearCallbacks = undefined + } + + build() { + Column() { + Column() { + if (this.mBannerNoticeCnt > 0) { + BannerNotification({ + want: this.pageData, + distributedDeviceName: $distributedDeviceName, + mLastActionTime: $mLastActionTime, + mBannerNoticeCnt: $mBannerNoticeCnt, + needExpand: $needExpand, + isExpand: $isExpand, + onBannerNoticeHide: () => this.onBannerNoticeHide() + }) + } else { + Blank() + } + } + } + .width('100%') + .height('100%') + .clip(true) + } + + onBannerNoticeShow() { + Log.showInfo(TAG, `onBannerNoticeShow start`); + let winInfoNotice = WindowManager.getWindowInfo(WindowType.NOTIFICATION_PANEL); + let bannerDisabledFlg = false; + let screenLockStatusInfo = AppStorage.Link('lockStatus'); + let screenLockStatus = ScreenLockStatus.Unlock; + if (!!screenLockStatusInfo) { + screenLockStatus = screenLockStatusInfo.get(); + } + if (screenLockStatus == ScreenLockStatus.Locking) { + bannerDisabledFlg = true; + } else if (winInfoNotice) { + if (winInfoNotice.visibility) { + bannerDisabledFlg = true; + } + } + WindowManager.hideWindow(WindowType.BANNER_NOTICE); + if (bannerDisabledFlg) { + Log.showInfo(TAG, `onBannerNoticeShow end`); + return; + } + this.pageData = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_BANNER_NOTICE, 'itemData'); + ViewModel.getDistributedDeviceName(this.pageData).then((deviceName) => { + this.distributedDeviceName = deviceName; + }) + this.needExpand = this.checkItemNeedExpand() + this.isExpand = false; + this.mBannerNoticeCnt++; + this.mLastActionTime = (new Date()).getTime(); + Log.showInfo(TAG, `onBannerNoticeShow count:` + this.mBannerNoticeCnt); + Log.showInfo(TAG, `onBannerNoticeShow pageData:${JSON.stringify(this.pageData)}`); + + WindowManager.resetSizeWindow(WindowType.BANNER_NOTICE, this.mDefaultBannerRect); + WindowManager.showWindow(WindowType.BANNER_NOTICE); + Log.showInfo(TAG, `onBannerNoticeShow end`); + } + + onBannerNoticeHide() { + this.mBannerNoticeCnt = 0; + WindowManager.resetSizeWindow(WindowType.BANNER_NOTICE, this.mDefaultBannerRect); + WindowManager.hideWindow(WindowType.BANNER_NOTICE); + } + + checkItemNeedExpand() { + if (this.pageData.contentType === NotificationConstants.NOTIFICATION_TYPE_BASIC + && (!(this.pageData.actionButtons?.length > 0))) { + return false; + } else { + return true; + } + } + +} diff --git a/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts new file mode 100644 index 00000000..8368748a --- /dev/null +++ b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import StyleManager from '../../../../../../../../../common/src/main/ets/default/StyleManager'; + +const TAG = 'NotificationPanel-StyleConfiguration'; + +export default class StyleConfiguration { + static getIndexStyle() { + const key: string = TAG + "-Index"; + return StyleManager.getStyle(key, () => { + return { + borderRadius: $r('app.float.default_border_radius') + }; + }); + } +} \ No newline at end of file diff --git a/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts new file mode 100644 index 00000000..b581c3ad --- /dev/null +++ b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../../common/src/main/ets/default/Log'; +import AbilityManager from '../../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager'; +import IndexStyleConfiguration from './StyleConfiguration' + +const TAG = 'NotificationPanel-StyleManager'; + +export default class StyleManager { + static STANDARD_DISPLAY_WIDTH: number = 1280; + static STANDARD_DISPLAY_HEIGHT: number = 800; + static maxWidth: number = StyleManager.STANDARD_DISPLAY_WIDTH; + + static setStyle() { + Log.showInfo(TAG, `setStyle`) + + let dis = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_NOTIFICATION_PANEL, 'dis'); + StyleManager.maxWidth = dis.width; + + // Index + { + let style: any = IndexStyleConfiguration.getIndexStyle(); + style.borderRadius = StyleManager.calcScaleSizePx(24); + } + + } + + static number2px(n: number): string { + return n.toString() + 'px'; + } + + static calcScaleSize(n: number): number { + return n * StyleManager.maxWidth / StyleManager.STANDARD_DISPLAY_WIDTH; + } + + static calcScaleSizePx(n: number): string { + return StyleManager.number2px(StyleManager.calcScaleSize(n)); + } +} \ No newline at end of file diff --git a/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts new file mode 100644 index 00000000..80a45419 --- /dev/null +++ b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class Constants { + static DIGITS = 10; + static MARK_MONTH = 0; + static MARK_DAY = 1; + static QUICKLY_SETTING_H = 83; +} \ No newline at end of file diff --git a/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/index.ets b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/index.ets new file mode 100644 index 00000000..be9e5acd --- /dev/null +++ b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/index.ets @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import image from "@ohos.multimedia.image" +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import Notification from './notification' +import WindowManager, { + WindowType, + WINDOW_SHOW_HIDE_EVENT, +} from "../../../../../../../../common/src/main/ets/default/WindowManager"; +import EventManager, {unsubscribe} from "../../../../../../../../common/src/main/ets/default/event/EventManager"; +import {START_ABILITY_EVENT} from "../../../../../../../../common/src/main/ets/default/event/EventUtil"; +import MultimodalInputManager, { + MultiKeyCode, +} from "../../../../../../../../common/src/main/ets/default/MultimodalInputManager"; + +const TAG = 'NotificationPanel-Index' +const SHOW_EVENT = "showNotificationPanel"; +const HIDE_EVENT = "hideNotificationPanel"; +const SHOW_ANIM_CONFIG = { + duration: 300, + tempo: 1.0, + curve: Curve.Friction, + delay: 0, + iterations: 1, + playMode: PlayMode.Normal, +} +const HIDE_ANIM_CONFIG = { + duration: 200, + tempo: 1.0, + curve: Curve.EaseOut, + delay: 0, + iterations: 1, + playMode: PlayMode.Normal, +} + +@Entry +@Component +struct Index { + @State mBlur: number = 0; + @State mOpacity: number = 0.0; + @State mWidthSize: number = 0.2 + @State mHeightSize: number = 0.2 + @State mBackground: PixelMap | undefined = undefined; + mClearCallbacks: Array = []; + mShowAnimReady: boolean = false; + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear, start`) + setAppBgColor('#00000000') + this.initWindowPolicy(); + } + + onPageShow() { + Log.showInfo(TAG, `onPageShow`) + this.startShowAnim(); + } + + onPageHide() { + Log.showInfo(TAG, `onPageHide`) + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisappear`) + this.mClearCallbacks.forEach((unsubscribe) => unsubscribe()); + this.mClearCallbacks.length = 0; + } + + build() { + Stack() { + Image(this.mBackground) + .width('100%') + .height('100%') + .objectFit(ImageFit.Fill) + Column() { + Notification() + } + .backgroundColor($r('app.color.default_background')) + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + .clip(true) + .opacity(this.mOpacity) + .borderRadius($r('app.float.default_border_radius')) + .scale({ + x: this.mWidthSize, + y: this.mHeightSize, + z: 1, + centerX: '100%', + centerY: '0%' + }) + } + + initWindowPolicy() { + Log.showInfo(TAG, `init notification panel window Policy`); + this.mClearCallbacks.push( + EventManager.subscribe(SHOW_EVENT, () => WindowManager.showWindow(WindowType.NOTIFICATION_PANEL)), + EventManager.subscribe(HIDE_EVENT, () => this.hideWindow()), + EventManager.subscribe(START_ABILITY_EVENT, () => this.hideWindow()), + EventManager.subscribe(WINDOW_SHOW_HIDE_EVENT, (args) => { + let { windowName, isShow } = args; + Log.showInfo(TAG, `WINDOW_SHOW_HIDE_EVENT windowName: ${windowName}, isShow: ${isShow}`); + windowName == WindowType.CONTROL_PANEL && isShow && this.hideWindow(); + windowName == WindowType.NOTIFICATION_PANEL && isShow && (this.mShowAnimReady = true); + }), + MultimodalInputManager.subscribeCombinationKey([MultiKeyCode.WIN, MultiKeyCode.N], (data) => { + let windowInfo = WindowManager.getWindowInfo(WindowType.NOTIFICATION_PANEL); + Log.showInfo(TAG, `on CombinationKeyEvent: data: ${data}, windowInfo: ${windowInfo?.visibility}`); + if (windowInfo) { + windowInfo.visibility + ? this.hideWindow() + : WindowManager.showWindow(WindowType.NOTIFICATION_PANEL); + } + }) + ); + } + + _animateTo(config, callback) { + animateTo(config, callback) + setTimeout(config.onFinish, config.duration + config.delay) + } + + async startShowAnim() { + if (!this.mShowAnimReady) { + return; + } + this.mShowAnimReady = false; + this._animateTo({ ...SHOW_ANIM_CONFIG, onFinish: () => { + Log.showInfo(TAG, `show anim finish.`); + this.mBlur = 20; + } }, () => { + this.mBlur = 20 + this.mOpacity = 1.0 + this.mWidthSize = 1.0 + this.mHeightSize = 1.0 + }) + } + + hideWindow() { + Log.showInfo(TAG, `hide anim start`); + this._animateTo({ ...HIDE_ANIM_CONFIG, onFinish: () => { + Log.showInfo(TAG, `anim finish, hide Notification window, view: ${JSON.stringify(this)}`); + this.mBlur = 0 + WindowManager.hideWindow(WindowType.NOTIFICATION_PANEL); + } + }, () => { + Log.showInfo(TAG, `do hide anim.`); + this.mBlur = 0 + this.mOpacity = 0.0 + this.mWidthSize = 0.2 + this.mHeightSize = 0.2 + }) + } +} diff --git a/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/notification.ets b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/notification.ets new file mode 100644 index 00000000..e976dd11 --- /dev/null +++ b/product/pc/notificationpanel/src/main/ets/ServiceExtAbility/pages/notification.ets @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import EventManager from "../../../../../../../../common/src/main/ets/default/event/EventManager" +import {obtainStartAbility} from "../../../../../../../../common/src/main/ets/default/event/EventUtil" +import NotificationListComponent from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/view/NotificationListComponent' +import ViewModel from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/viewmodel/ViewModel' + +const TAG = 'NotificationPanel-notification' +const NO_NOTIFICATION_TOP_MARGIN = 40; +const NOTIFICATION_TEXT_SIZE = 20; +const NOTIFICATION_TOTAL_MARGIN = 20; +const NOTIFICATION_ITEM_MARGIN = 16; +const NOTIFICATION_ICON_SIZE = 24; +const NOTIFICATION_TITLE_HEIGHT = 58; +const NOTIFICATION_TITLE_MARGIN = 4; +const NOTIFICATION_TITLE_ICON_MARGIN = 24; + +@Component +export default struct Notification { + @StorageLink('notificationList') notificationList: any[] = [] + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear Start`) + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { + CenterTitle() + if (this.notificationList.length == 0) { + Text($r("app.string.no_notification")) + .fontColor($r("sys.color.ohos_id_color_text_primary")) + .fontSize($r("sys.float.ohos_id_text_size_sub_title2")) + .fontWeight(FontWeight.Medium) + .alignSelf(ItemAlign.Center) + .margin({ top: NO_NOTIFICATION_TOP_MARGIN }) + } else { + Column() { + NotificationListComponent({ config: { itemMargin: NOTIFICATION_ITEM_MARGIN } }) + } + .flexGrow(1) + } + }.padding({ left: NOTIFICATION_TOTAL_MARGIN, right: NOTIFICATION_TOTAL_MARGIN }) + .width('100%') + } +} + +@Component +struct CenterTitle { + aboutToAppear() { + Log.showInfo(TAG, `CenterTitle, aboutToAppear`) + } + + aboutToDisappear() { + Log.showInfo(TAG, `CenterTitle, aboutToDisappear`) + } + + build() { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { + Text($r("app.string.notification_center")) + .fontColor($r("sys.color.ohos_id_color_text_primary")) + .fontSize(NOTIFICATION_TEXT_SIZE) + .fontWeight(FontWeight.Medium) + .margin({ left: NOTIFICATION_TITLE_MARGIN }) + Blank() + Image($r('app.media.ic_public_settings')) + .objectFit(ImageFit.Contain) + .fillColor($r("app.color.notification_title_image_color")) + .width(NOTIFICATION_ICON_SIZE) + .height(NOTIFICATION_ICON_SIZE) + .margin({ right: NOTIFICATION_TITLE_ICON_MARGIN }) + .onClick(this.settingClick.bind(this)) + Image($r('app.media.ic_public_delete')) + .objectFit(ImageFit.Contain) + .fillColor($r("app.color.notification_title_image_color")) + .width(NOTIFICATION_ICON_SIZE) + .height(NOTIFICATION_ICON_SIZE) + .margin({ right: NOTIFICATION_TITLE_MARGIN }) + .onClick(() => { + ViewModel.removeAllNotifications(); + }) + } + .height(NOTIFICATION_TITLE_HEIGHT) + } + + settingClick() { + Log.showInfo(TAG, ` settingClick `) + EventManager.publish(obtainStartAbility('com.ohos.systemui', 'com.ohos.systemui.notificationmanagement.MainAbility')) + } +} \ No newline at end of file diff --git a/product/pc/notificationpanel/src/main/resources/base/element/color.json b/product/pc/notificationpanel/src/main/resources/base/element/color.json new file mode 100644 index 00000000..4f862bb8 --- /dev/null +++ b/product/pc/notificationpanel/src/main/resources/base/element/color.json @@ -0,0 +1,24 @@ +{ + "color": [ + { + "name": "default_background", + "value": "#F2F1F3F5" + }, + { + "name": "default_font_color", + "value": "#000000" + }, + { + "name": "quicklysetting_time_fontcolor", + "value": "#FF000000" + }, + { + "name": "quicklysetting_date_fontcolor", + "value": "#FF000000" + }, + { + "name": "notification_title_image_color", + "value": "#ff182431" + } + ] +} \ No newline at end of file diff --git a/product/pc/notificationpanel/src/main/resources/base/element/float.json b/product/pc/notificationpanel/src/main/resources/base/element/float.json new file mode 100644 index 00000000..b640ff0d --- /dev/null +++ b/product/pc/notificationpanel/src/main/resources/base/element/float.json @@ -0,0 +1,120 @@ + { + "float": [ + { + "name": "default_border_radius", + "value": "18vp" + }, + { + "name": "quicklysetting_time_fontsize", + "value": "30" + }, + { + "name": "quicklysetting_date_fontsize", + "value": "20" + }, + { + "name": "quicklysetting_textflex_marginleft", + "value": "10" + }, + { + "name": "quicklysetting_image_width", + "value": "50" + }, + { + "name": "quicklysetting_image_height", + "value": "50" + }, + { + "name": "quicklysetting_image_marginright", + "value": "10" + }, + { + "name": "quicklysetting_borderradius", + "value": "20" + }, + { + "name": "quicklysetting_marginleft", + "value": "10" + }, + { + "name": "quicklysetting_marginright", + "value": "10" + }, + { + "name": "deleteall_image_width", + "value": "50" + }, + { + "name": "deleteall_image_height", + "value": "50" + }, + { + "name": "deleteall_image_borderradius", + "value": "25" + }, + { + "name": "setting_title_fontsize", + "value": "20vp" + }, + { + "name": "title_font_height", + "value": "28vp" + }, + { + "name": "title_font_margin_t", + "value": "13vp" + }, + { + "name": "confirm_button_margin_t", + "value": "23vp" + }, + { + "name": "message_font_margin_t", + "value": "14vp" + }, + { + "name": "confirm_title_fontsize", + "value": "20vp" + }, + { + "name": "title_image_width", + "value": "28vp" + }, + { + "name": "title_image_height", + "value": "28vp" + }, + { + "name": "setting_cont_fontsize", + "value": "32" + }, + { + "name": "close_notification_margin_top", + "value": "15vp" + }, + { + "name": "notification_appname_margin_top", + "value": "11vp" + }, + { + "name": "notification_cancle_margin_top", + "value": "11vp" + }, + { + "name": "setting_dialog_dy", + "value": "110" + }, + { + "name": "confirm_dialog_dy", + "value": "140" + }, + { + "name": "notification_border_radius", + "value": "24vp" + }, + { + "name": "applist_hieght", + "value": "361vp" + } + ] +} \ No newline at end of file diff --git a/product/statusbar/src/main/resources/base/element/string.json b/product/pc/notificationpanel/src/main/resources/base/element/string.json similarity index 73% rename from product/statusbar/src/main/resources/base/element/string.json rename to product/pc/notificationpanel/src/main/resources/base/element/string.json index aef4538b..0192c24b 100644 --- a/product/statusbar/src/main/resources/base/element/string.json +++ b/product/pc/notificationpanel/src/main/resources/base/element/string.json @@ -1,21 +1,5 @@ { "string": [ - { - "name": "status_bar_size_portrait", - "value": "102" - }, - { - "name": "status_bar_size_landscape", - "value": "102" - }, - { - "name": "status_bar_position_portrait", - "value": "1" - }, - { - "name": "status_bar_position_landscape", - "value": "2" - }, { "name": "app_name", "value": "SystemUI" @@ -59,6 +43,14 @@ { "name": "month", "value": "月" + }, + { + "name": "no_notification", + "value": "没有通知" + }, + { + "name": "notification_center", + "value": "通知中心" } ] } \ No newline at end of file diff --git a/product/statusbar/src/main/resources/base/media/delete_all.png b/product/pc/notificationpanel/src/main/resources/base/media/delete_all.png similarity index 100% rename from product/statusbar/src/main/resources/base/media/delete_all.png rename to product/pc/notificationpanel/src/main/resources/base/media/delete_all.png diff --git a/product/pc/notificationpanel/src/main/resources/base/media/ic_message_filled.png b/product/pc/notificationpanel/src/main/resources/base/media/ic_message_filled.png new file mode 100644 index 0000000000000000000000000000000000000000..0709a1d309c7cda74183f19c440bbbf71851e1b5 GIT binary patch literal 1375 zcmV-l1)%zgP)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91NT34%1ONa40RR91L;wH)09C=O?f?J;$w@>(RCodHo5^bwK@`Sk#C_kQ zL{Knl(2F8*K@>H{9l-@u`~&4|`-@{mEL(0CL>WttO<(kVCaTp$sbtV&P4I<$* z5}pBz!X~cqcJ1_UE9=vXQvDoMssZ9Gp^XwIMI2EUmv)bv%7NCWKqS~n!#(;}xsezf4!T`Ng{43_hYZfBY;R)U;B zh@-umhvj5UU~D5IJ@TiR_Hvxr3gk5L1=?!Yxe^NGG|4i(^heT5;EUzd=~3VhhkA+9 z0-QKKqL@E(+UUnT)9cPH1?EYhM$6?2rUH!;sLu4bb4!6b2{guXxq_*{7zs4Y^tf|N zfngHpi{)|!Q-LoM=(Fi@=avGWB~Yj3as^X?P6_nD^tf|Nfd>-kj^%O%Q-M2r7Sn5; zH^ANQO=)`8=E;ND^U!;t3wE6=NfT+KDJIjmG|p@Va+>%%isPx%%d;VNo79%{h1wKG z(1+Xz(g}_esg}o&J&G!Ucd=5*xS;+N*aLQfwIKBW zKhSm{>^m2^1Wp1yd=}lp!*n9DKxT5p(x<~4fIb;n4W@&N!d+r{2BL?0i>6eQil3xprN0s2dsI?{h%^?QtD2m?aq}aXNw;B;L=|sRO!g7usDMQxh*h7=j3~6quW9rzuYg6Pv0wh%ytn hQIo3Qx+9y(`~?O=ZfQ6ZzEA)F002ovPDHLkV1o2cVTk|$ literal 0 HcmV?d00001 diff --git a/product/pc/notificationpanel/src/main/resources/base/media/ic_public_delete.svg b/product/pc/notificationpanel/src/main/resources/base/media/ic_public_delete.svg new file mode 100644 index 00000000..422ec497 --- /dev/null +++ b/product/pc/notificationpanel/src/main/resources/base/media/ic_public_delete.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_delete + + + + + + + + + + \ No newline at end of file diff --git a/product/pc/notificationpanel/src/main/resources/base/media/ic_public_settings.svg b/product/pc/notificationpanel/src/main/resources/base/media/ic_public_settings.svg new file mode 100644 index 00000000..98a78dac --- /dev/null +++ b/product/pc/notificationpanel/src/main/resources/base/media/ic_public_settings.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_settings + + + + + + + + + + \ No newline at end of file diff --git a/product/statusbar/src/main/resources/base/media/ic_settings.png b/product/pc/notificationpanel/src/main/resources/base/media/ic_settings.png similarity index 100% rename from product/statusbar/src/main/resources/base/media/ic_settings.png rename to product/pc/notificationpanel/src/main/resources/base/media/ic_settings.png diff --git a/product/pc/notificationpanel/src/main/resources/base/media/icon.png b/product/pc/notificationpanel/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYS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hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y 0) { + configInfo.yCoordinate = configInfo.maxHeight - configInfo.realHeight; + } + } else { + configInfo.realWidth = (configInfo.realWidth * configInfo.maxWidth) / 1280; + configInfo.minHeight = configInfo.realWidth; + if (configInfo.xCoordinate > 0) { + configInfo.xCoordinate = configInfo.maxWidth - configInfo.realWidth; + } + } + AbilityManager.setAbilityData(AbilityManager.ABILITY_NAME_STATUS_BAR, "config", configInfo); + Log.showInfo(TAG, `api8New onCreate, configInfo: ${JSON.stringify(configInfo)}`); + + let statusBarRect = { + left: configInfo.xCoordinate, + top: configInfo.yCoordinate, + width: configInfo.realWidth, + height: configInfo.realHeight, + }; + WindowManager.createWindow(this.context, WindowType.STATUS_BAR, statusBarRect, "pages/index").then(() => + WindowManager.showWindow(WindowType.STATUS_BAR) + ); + } + + onDestroy() { + Log.showInfo(TAG, "api8New onDestroy"); + } +} + +export default ServiceExtAbility; diff --git a/product/pc/statusbar/src/main/ets/ServiceExtAbility/app.ets b/product/pc/statusbar/src/main/ets/ServiceExtAbility/app.ets new file mode 100644 index 00000000..c4ae2372 --- /dev/null +++ b/product/pc/statusbar/src/main/ets/ServiceExtAbility/app.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityManager from '../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import StatusBarVM from '../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/viewmodel/StatusBarVM' +import {StatusBarData} from '../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/common/Constants' + +export default { + async onCreate() { + console.info('SystemUI statusBar Application onCreate') + let configInfo = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_STATUS_BAR, 'config') + let statusBarData: StatusBarData = new StatusBarData(); + statusBarData.displayWidth = configInfo.maxWidth; + statusBarData.displayHeight = configInfo.maxHeight; + statusBarData.showHorizontal = configInfo.showHorizontal; + statusBarData.ableToMaximize = configInfo.ableToMaximize; + statusBarData.realWidth = configInfo.realWidth; + statusBarData.realHeight = configInfo.realHeight; + statusBarData.left = configInfo.xCoordinate; + statusBarData.top = configInfo.yCoordinate; + StatusBarVM.updateStatusBarData(statusBarData); + }, + onDestroy() { + console.info('SystemUI statusBar Application onDestroy') + }, +} diff --git a/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StatusbarConfig.ts b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StatusbarConfig.ts new file mode 100644 index 00000000..2d8f0016 --- /dev/null +++ b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StatusbarConfig.ts @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {FASlotName} from '../../../../../../../../../common/src/main/ets/default/Constants'; + +type LayoutGroup = { + id: number; + Components: Array; +}; +type pluginIconData = { + id: string; + bundleName: string; + abilityName: string; +}; +type Config = { + LayoutGroups: Array; + LocalSlots: Array; + MetaSlots: Array; + emptyPosition: { x1: number; x2: number; y1: number; y2: number }; +}; + +const StatusbarConfig: Config = { + LayoutGroups: [ + { + id: 1, + Components: [ + FASlotName.SIGNAL, + FASlotName.WIFI, + FASlotName.CAPSULE, + FASlotName.NOTIFICATION, + ], + }, + { + id: 2, + Components: [], + }, + { + id: 3, + Components: [ + FASlotName.LOCATION, + FASlotName.BLUETOOTH, + FASlotName.RING_MODE, + FASlotName.BATTERY, + FASlotName.CLOCK, + "systemui_notificationpanel", + "systemui_controlpanel", + ], + }, + ], + LocalSlots: [ + FASlotName.BATTERY, + FASlotName.BLUETOOTH, + FASlotName.CAPSULE, + FASlotName.CLOCK, + FASlotName.LOCATION, + FASlotName.NOTIFICATION, + FASlotName.RING_MODE, + FASlotName.SIGNAL, + FASlotName.WIFI, + ], + MetaSlots: [ + { + id: "systemui_notificationpanel", + bundleName: "com.ohos.systemui", + abilityName: "com.ohos.systemui.notificationpanel.ServiceExtAbility", + }, + { + id: "systemui_controlpanel", + bundleName: "com.ohos.systemui", + abilityName: "com.ohos.systemui.controlpanel.ServiceExtAbility", + }, + ], + emptyPosition: { + x1: 0, + y1: 0, + x2: 0, + y2: 0, + }, +}; + +export default StatusbarConfig; \ No newline at end of file diff --git a/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts new file mode 100644 index 00000000..9c7d17d3 --- /dev/null +++ b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import StyleManager from '../../../../../../../../../common/src/main/ets/default/StyleManager'; + +const TAG = 'StatusBar-StyleConfiguration'; + +export default class StyleConfiguration { + static getIndexStyle() { + const key: string = TAG + "-Index"; + return StyleManager.getStyle(key, () => { + return {}; + }); + } +} \ No newline at end of file diff --git a/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts new file mode 100644 index 00000000..7205ead7 --- /dev/null +++ b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../../common/src/main/ets/default/Log'; +import AbilityManager from '../../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager'; +import CommonStyleConfiguration from '../../../../../../../../../common/src/main/ets/default/StyleConfiguration'; +import StatusBarStyleConfiguration from '../../../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/common/StyleConfiguration' +import BatteryStyleConfiguration from '../../../../../../../../../features/batterycomponent/src/main/ets/default/common/StyleConfiguration' +import ClockStyleConfiguration from '../../../../../../../../../features/clockcomponent/src/main/ets/default/common/StyleConfiguration' +import WifiStyleConfiguration from '../../../../../../../../../features/wificomponent/src/main/ets/default/common/StyleConfiguration' +import BluetoothStyleConfiguration from '../../../../../../../../../features/bluetoothcomponent/src/main/ets/com/ohos/common/StyleConfiguration' +import SignalStyleConfiguration from '../../../../../../../../../features/signalcomponent/src/main/ets/default/common/StyleConfiguration' +import CapsuleStyleConfiguration from '../../../../../../../../../features/capsulecomponent/src/main/ets/default/common/StyleConfiguration' +import LocationStyleConfiguration from '../../../../../../../../../features/locationcomponent/src/main/ets/com/ohos/common/StyleConfiguration' +import RingModeStyleConfiguration from '../../../../../../../../../features/ringmodecomponent/src/main/ets/com/ohos/common/StyleConfiguration' +import IndexStyleConfiguration from './StyleConfiguration' + +const TAG = 'StatusBar-StyleManager'; + +export default class StyleManager { + static STANDARD_DISPLAY_WIDTH: number = 1280; + static STANDARD_DISPLAY_HEIGHT: number = 800; + static maxWidth: number = StyleManager.STANDARD_DISPLAY_WIDTH; + + static setStyle() { + Log.showInfo(TAG, `setStyle`) + + let config = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_STATUS_BAR, 'config'); + StyleManager.maxWidth = config.maxWidth; + + // Common + { + let style: any = CommonStyleConfiguration.getCommonStyle(); + style.statusBarFontSize = StyleManager.calcScaleSizePx(14); + style.statusBarIconWidth = StyleManager.calcScaleSizePx(20); + style.statusBarIconHeight = StyleManager.calcScaleSizePx(20); + style.statusBarMarginLeftRight = StyleManager.calcScaleSizePx(10); + } + + // StatusBar-VerticalStatusBarItemLoadComponent + { + let style: any = StatusBarStyleConfiguration.getVerticalStatusBarItemLoadComponentStyle(); + style.statusBarVerticalComponentHeight = StyleManager.calcScaleSize(64); + } + + // StatusBar-NotificationIcon + { + let style: any = StatusBarStyleConfiguration.getStatusBarNotificationIconStyle(); + style.iconWidth = StyleManager.calcScaleSizePx(16); + style.iconHeight = StyleManager.calcScaleSizePx(16); + style.iconSpace = StyleManager.calcScaleSizePx(6); + } + + // StatusBar-IconComponent + { + let style: any = StatusBarStyleConfiguration.getIconItemComponentStyle(); + style.stackHeight = StyleManager.calcScaleSizePx(8 * 2 + 18); + style.stackPadding = StyleManager.calcScaleSizePx(8); + style.stackBorderRadius = StyleManager.calcScaleSizePx(8); + style.stackBgColorSelected = '#33000000'; + style.stackBgColorUnSelected = '#00000000'; + style.componentSpace = StyleManager.calcScaleSizePx(8); + style.iconWidth = StyleManager.calcScaleSizePx(18); + style.iconHeight = StyleManager.calcScaleSizePx(18); + style.marginLeft = StyleManager.calcScaleSizePx(4); + style.marginRight = StyleManager.calcScaleSizePx(4); + } + + // Clock + { + let style: any = ClockStyleConfiguration.getClockComponentStyle(); + style.statusBarClockMaxWidth = StyleManager.calcScaleSizePx(37); + } + + // Battery-Icon + { + let style: any = BatteryStyleConfiguration.getBatteryComponentStyle(); + style.componentGap = StyleManager.calcScaleSizePx(6); + } + + // Battery-Pic + { + let style: any = BatteryStyleConfiguration.getBatteryPicStyle(); + style.picGap = StyleManager.calcScaleSizePx(1); + style.picBodyWidth = StyleManager.calcScaleSizePx(18.75); + style.picBodyHeight = StyleManager.calcScaleSizePx(10.83); + style.picBodyPadding = StyleManager.calcScaleSizePx(1); + style.picBodyBorderWidth = StyleManager.calcScaleSizePx(1); + style.picBorderRadius = StyleManager.calcScaleSizePx(2); + style.picHeadBorderRadius = StyleManager.calcScaleSizePx(1); + style.picChargingColor = '#00ff21'; + style.picLevelLowColor = '#ff0000'; + style.picHeadWidth = StyleManager.calcScaleSizePx(1.5); + style.picHeadHeight = StyleManager.calcScaleSizePx(5); + } + + // Signal-Icon + { + let style: any = SignalStyleConfiguration.getSignalComponentStyle(); + style.cellularImageWidth = StyleManager.calcScaleSizePx(25); + style.cellularImageHeight = StyleManager.calcScaleSizePx(20); + style.statusBarSignalTypeFontSize = StyleManager.calcScaleSizePx(7); + style.statusBarSignalUnknownFontSize = StyleManager.calcScaleSizePx(12); + style.signalTextMaxWeight = StyleManager.calcScaleSizePx(100); + style.netSignalTextMaxWidth = StyleManager.calcScaleSizePx(18); + } + + // Bluetooth -Icon + { + let style: any = BluetoothStyleConfiguration.getStatusBarBluetoothComponentStyle(); + style.staticBarBluetoothWidth = StyleManager.calcScaleSizePx(18); + style.staticBarBluetoothHeight = StyleManager.calcScaleSizePx(20); + } + + // Location-Icon + { + let style: any = LocationStyleConfiguration.getStartsBarLocationComponentStyle(); + style.statusBarLocationWidth = StyleManager.calcScaleSizePx(18); + style.statusBarLocationHeight = StyleManager.calcScaleSizePx(20); + } + + // RingMode-Icon + { + let style: any = RingModeStyleConfiguration.getStatusRingModeComponentStyle(); + style.statusBarRingModeWidth = StyleManager.calcScaleSizePx(20); + style.statusBarRingModeHeight = StyleManager.calcScaleSizePx(20); + } + + // Wifi-Icon + { + let style: any = WifiStyleConfiguration.getStartsBarWifiComponentStyle(); + style.statusBarWifiWidth = StyleManager.calcScaleSizePx(20); + style.statusBarWifiHeight = StyleManager.calcScaleSizePx(20); + } + + // Capsule-Icon + { + let style: any = CapsuleStyleConfiguration.getCapsuleComponentStyle(); + style.greenCapsulePhoneWidth = StyleManager.calcScaleSizePx(15); + style.greenCapsulePhoneHeight = StyleManager.calcScaleSizePx(15); + style.greenCapsuleHeight = StyleManager.calcScaleSizePx(30); + style.greenCapsuleTextColor = '#CCFFFFFF'; + style.greenCapsuleTextMarginLeftRight = StyleManager.calcScaleSizePx(10); + style.greenCapsuleRadius = StyleManager.calcScaleSizePx(24); + style.greenCapsuleBackgroundColor = '#64BB5C'; + style.maxLines = 1; + } + + } + + static number2px(n: number): string { + return n.toString() + 'px'; + } + + static calcScaleSize(n: number): number { + return n * StyleManager.maxWidth / StyleManager.STANDARD_DISPLAY_WIDTH; + } + + static calcScaleSizePx(n: number): string { + return StyleManager.number2px(StyleManager.calcScaleSize(n)); + } +} \ No newline at end of file diff --git a/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/constants.ts b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/constants.ts new file mode 100644 index 00000000..6a98994c --- /dev/null +++ b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/common/constants.ts @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class Constants { +} \ No newline at end of file diff --git a/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/index.ets b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/index.ets new file mode 100644 index 00000000..b07025e3 --- /dev/null +++ b/product/pc/statusbar/src/main/ets/ServiceExtAbility/pages/index.ets @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import CommonStyleManager from '../../../../../../../../common/src/main/ets/default/StyleManager' +import HeightConfigUtils from '../../../../../../../../common/src/main/ets/default/heightcofigUtils/HeightConfigUtils' +import StatusBarComponent from '../../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/pages/StatusBarComponent' +import StyleManager from './common/StyleManager' +import StatusbarConfig from './common/StatusbarConfig' + +const TAG = 'StatusBar-Index' + +let mHeightConfigUtils; + +@Entry +@Component +struct Index { + @StorageLink('StatusMinH') StatusMinH: number = 24 + @StorageLink('StatusCoefficient') StatusCoefficient: number = 1.0 + + onBackPress(): boolean { + return true; + } + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear, start`); + + setAppBgColor('#00000000') + CommonStyleManager.setAbilityPageName(TAG) + StyleManager.setStyle() + + mHeightConfigUtils = new HeightConfigUtils(); + let StatusMinH; + let StatusCoefficient; + + StatusMinH = AppStorage.SetAndLink("StatusMinH", 24); + StatusCoefficient = AppStorage.SetAndLink("StatusCoefficient", 1.0); + StatusMinH.set(mHeightConfigUtils.getStatusMinH()); + StatusCoefficient.set(mHeightConfigUtils.getStatusCoefficient()); + + let signalObserved = AppStorage.SetAndLink("signalObserved", false); + signalObserved.set(false); + + Log.showInfo(TAG, `aboutToAppear, end`); + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisappear`); + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + StatusBarComponent({ + mStatusBarComponentConfig: StatusbarConfig + }) + } + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + .constraintSize({ minHeight: this.StatusMinH + 'px' }) + .onAreaChange((e, e2) => { + Log.showInfo(TAG, `onAreaChange, e: ${JSON.stringify(e)} e2: ${JSON.stringify(e2)}`); + }) + } +} diff --git a/product/pc/statusbar/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js b/product/pc/statusbar/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js new file mode 100644 index 00000000..3135d74c --- /dev/null +++ b/product/pc/statusbar/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from "@ohos.worker"; +import Log from "../../../../../../../../common/src/main/ets/default/Log"; +import PluginDataSourceManager +from "../../../../../../../../common/src/main/ets/plugindatasource/PluginDataSourceManager"; +import Constants, { obtainMsg } from "../../../../../../../../common/src/main/ets/plugindatasource/common/Constants"; + +const parentPort = worker.parentPort; +const TAG = `${parentPort.name} Worker`; +Log.showInfo(TAG, `Start.`); + +var sManager; + +parentPort.onmessage = (msg) => { + Log.showInfo(TAG, `onMessage, msg = ${JSON.stringify(msg)}`); + let data = msg.data; + switch (data.action) { + case Constants.INIT_CONFIG: + initConfig(data.data); + break; + case Constants.CLEAR_ALL: + clearAll(); + break; + case Constants.LOAD_DATA: + loadData(data.data); + break; + default: + Log.showError(TAG, `onMessage, unknown action type.`); + } +}; + +function initConfig(config) { + Log.showInfo(TAG, `initConfig, config = ${JSON.stringify(config)}`); + sManager = new PluginDataSourceManager({ + onItemAdd: (itemData) => { + Log.showInfo(TAG, `sManager.onItemAdd, itemData = ${JSON.stringify(itemData)}`); + itemData.label && (itemData.label = encodeURIComponent(itemData.label)); + parentPort.postMessage(obtainMsg(Constants.ADD_ITEM, itemData)); + }, + onItemRemove: (itemData) => { + Log.showInfo(TAG, `sManager.onItemRemove, itemData = ${JSON.stringify(itemData)}`); + parentPort.postMessage(obtainMsg(Constants.REMOVE_ITEM, itemData)); + }, + }); + sManager.initDataSource(config); + parentPort.postMessage(obtainMsg(Constants.INIT_FINISH, {})); +} + +function clearAll() { + Log.showInfo(TAG, `clearAll `); + sManager?.clearAll(); +} + +function loadData(userId) { + Log.showInfo(TAG, `loadData `); + sManager?.loadData(userId); +} + +parentPort.onclose = function () { + Log.showInfo(TAG, `onclose`); +}; + +parentPort.onmessageerror = function () { + Log.showInfo(TAG, `onmessageerror`); +}; + +parentPort.onerror = function (data) { + Log.showInfo( + TAG, + `onerror, lineno = ${data.lineno}, msg = ${data.message}, filename = ${data.filename}, col = ${data.colno}` + ); +}; \ No newline at end of file diff --git a/product/pc/statusbar/src/main/resources/base/element/color.json b/product/pc/statusbar/src/main/resources/base/element/color.json new file mode 100644 index 00000000..6b163c9d --- /dev/null +++ b/product/pc/statusbar/src/main/resources/base/element/color.json @@ -0,0 +1,12 @@ +{ + "color": [ + { + "name": "default_background", + "value": "#66000000" + }, + { + "name": "default_font_color", + "value": "#ffffffff" + } + ] +} \ No newline at end of file diff --git a/product/pc/statusbar/src/main/resources/base/element/string.json b/product/pc/statusbar/src/main/resources/base/element/string.json new file mode 100644 index 00000000..85243901 --- /dev/null +++ b/product/pc/statusbar/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "status_bar_size_portrait", + "value": "44" + }, + { + "name": "status_bar_size_landscape", + "value": "44" + }, + { + "name": "status_bar_position_portrait", + "value": "1" + }, + { + "name": "status_bar_position_landscape", + "value": "2" + }, + { + "name": "app_name", + "value": "SystemUI" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/product/pc/statusbar/src/main/resources/base/media/icon.png b/product/pc/statusbar/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)F9W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.setAbilityData(AbilityManager.ABILITY_NAME_DROPDOWN_PANEL, "rect", rect); + WindowManager.createWindow(this.context, WindowType.DROPDOWN_PANEL, rect, "pages/index").then(() => + Log.showInfo(TAG, `api8New onCreate, createWindow callback`) + ); + + AbilityManager.setContext(AbilityManager.ABILITY_NAME_BANNER_NOTICE, this.context); + let bannerRect = { + left: 0, + top: dis.height / 5, + width: dis.width, + height: dis.height / 20 + } + AbilityManager.setAbilityData(AbilityManager.ABILITY_NAME_BANNER_NOTICE, 'bannerRect', bannerRect); + WindowManager.createWindow(this.context, WindowType.BANNER_NOTICE, bannerRect, 'pages/bannerNotification') + .then((win) => { + Log.showInfo(TAG, `api8New onCreate, createWindow callback`); + }) + .catch((err) => Log.showError(TAG, `Can't create window, err:${err}`)); + }); + } + + onDestroy() { + Log.showInfo(TAG, "api8New onDestroy"); + } +} + +export default ServiceExtAbility; diff --git a/common/src/main/ets/plugindatasource/sourceloader/MetaSourceLoader.ets b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/app.ets similarity index 58% rename from common/src/main/ets/plugindatasource/sourceloader/MetaSourceLoader.ets rename to product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/app.ets index e897518c..ed566992 100644 --- a/common/src/main/ets/plugindatasource/sourceloader/MetaSourceLoader.ets +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/app.ets @@ -13,15 +13,11 @@ * limitations under the License. */ -import Log from '../../default/Log.ets'; -import BaseMetaSourceLoader from './BaseMetaSourceLoader.ets'; -import {PluginType} from '../common/Constants.ets'; - -const TAG = "MetaSourceLoader"; - -export default class MetaSourceLoader extends BaseMetaSourceLoader { - constructor(config, channel) { - super(config, channel, PluginType.SIMPLE); - Log.showInfo(TAG, `constructor, config: ${JSON.stringify(config)} channel: ${channel}`) - } -} \ No newline at end of file +export default { + async onCreate() { + console.info('SystemUI dropdownPanel Application onCreate') + }, + onDestroy() { + console.info('SystemUI dropdownPanel Application onDestroy') + }, +} diff --git a/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/bannerNotification.ets b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/bannerNotification.ets new file mode 100644 index 00000000..a6cf1d7f --- /dev/null +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/bannerNotification.ets @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import WindowManager, { WindowType } from '../../../../../../../../common/src/main/ets/default/WindowManager' +import EventManager, {unsubscribe} from "../../../../../../../../common/src/main/ets/default/event/EventManager" +import BannerNotification from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/view/item/bannerNotificationItem' +import ViewModel from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/viewmodel/ViewModel'; +import NotificationConstants, { ScreenLockStatus } from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/common/constants'; + +const TAG = 'DropdownPanel-BannerNotification' + + +@Entry +@Component +struct Index { + @State distributedDeviceName: string = ''; + @State mBannerNoticeCnt: number = 0; + @State mLastActionTime: number = 0; + @State needExpand: boolean = true + @State isExpand: boolean = false; + @State pageData: any = {}; + + mClearCallbacks: unsubscribe[] + mDefaultBannerRect: any; + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear Start`) + setAppBgColor('#00000000') + this.mClearCallbacks = [] + this.mClearCallbacks.push(EventManager.subscribe('onBannerNoticeShow', () => this.onBannerNoticeShow())) + this.mClearCallbacks.push(EventManager.subscribe('onBannerNoticeHide', () => this.onBannerNoticeHide())) + Log.showInfo(TAG, `aboutToAppear End`) + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisAppear`) + this.mClearCallbacks.forEach((mClearCallback: Function) => { + mClearCallback() + mClearCallback = undefined + }) + this.mClearCallbacks = undefined + } + + build() { + Column() { + Column() { + if (this.mBannerNoticeCnt > 0) { + BannerNotification({ + want: this.pageData, + distributedDeviceName: $distributedDeviceName, + mLastActionTime: $mLastActionTime, + mBannerNoticeCnt: $mBannerNoticeCnt, + needExpand: $needExpand, + isExpand: $isExpand, + onBannerNoticeHide: () => this.onBannerNoticeHide() + }) + } else { + Blank() + } + } + } + .width('100%') + .height('100%') + } + + onBannerNoticeShow() { + Log.showInfo(TAG, `onBannerNoticeShow start`); + let windowInfoDrop = WindowManager.getWindowInfo(WindowType.DROPDOWN_PANEL); + let bannerDisabledFlg = false; + let screenLockStatusInfo = AppStorage.Link('lockStatus'); + let screenLockStatus = ScreenLockStatus.Unlock; + if (!!screenLockStatusInfo) { + screenLockStatus = screenLockStatusInfo.get(); + } + if (screenLockStatus == ScreenLockStatus.Locking) { + bannerDisabledFlg = true; + } else if (windowInfoDrop) { + if (windowInfoDrop.visibility) { + bannerDisabledFlg = true; + } + } + WindowManager.hideWindow(WindowType.BANNER_NOTICE); + if (bannerDisabledFlg) { + Log.showInfo(TAG, `onBannerNoticeShow end`); + return; + } + this.pageData = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_BANNER_NOTICE, 'itemData'); + ViewModel.getDistributedDeviceName(this.pageData).then((deviceName) => { + this.distributedDeviceName = deviceName; + }) + this.needExpand = this.checkItemNeedExpand() + this.isExpand = false; + this.mBannerNoticeCnt++; + this.mLastActionTime = (new Date()).getTime(); + Log.showInfo(TAG, `onBannerNoticeShow count:` + this.mBannerNoticeCnt); + Log.showInfo(TAG, `onBannerNoticeShow pageData:${JSON.stringify(this.pageData)}`); + + WindowManager.resetSizeWindow(WindowType.BANNER_NOTICE, this.mDefaultBannerRect); + WindowManager.showWindow(WindowType.BANNER_NOTICE); + Log.showInfo(TAG, `onBannerNoticeShow end`); + } + + onBannerNoticeHide() { + this.mBannerNoticeCnt = 0; + WindowManager.resetSizeWindow(WindowType.BANNER_NOTICE, this.mDefaultBannerRect); + WindowManager.hideWindow(WindowType.BANNER_NOTICE); + } + + checkItemNeedExpand() { + if (this.pageData.contentType === NotificationConstants.NOTIFICATION_TYPE_BASIC + && (!(this.pageData.actionButtons?.length > 0))) { + return false; + } else { + return true; + } + } + +} diff --git a/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/ControlCenterConfig.ts b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/ControlCenterConfig.ts new file mode 100644 index 00000000..44173d27 --- /dev/null +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/ControlCenterConfig.ts @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {FASlotName} from '../../../../../../../../../common/src/main/ets/default/Constants'; + +type pluginIconData = { + id: string; + bundleName: string; + abilityName: string; +}; +type Config = { + ComplexToggleLayout: Array; + DefaultSimpleToggleLayout: Array; + LocalToggles: { + ComplexToggles: Array; + SimpleToggles: Array; + }; + MetaToggles: Array; +}; + +const ControlCenterConfig: Config = { + ComplexToggleLayout: [FASlotName.WIFI, FASlotName.BLUETOOTH], + DefaultSimpleToggleLayout: ["screenshot", FASlotName.RING_MODE, FASlotName.LOCATION], + LocalToggles: { + ComplexToggles: [FASlotName.AIR_PLANE, FASlotName.BLUETOOTH, FASlotName.WIFI], + SimpleToggles: [FASlotName.LOCATION, FASlotName.RING_MODE], + }, + MetaToggles: [ + { + id: "screenshot", + bundleName: "com.ohos.screenshot", + abilityName: "com.ohos.screenshot.ServiceExtAbility", + }, + ], +}; + +export default ControlCenterConfig; diff --git a/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts new file mode 100644 index 00000000..9ddd4f1f --- /dev/null +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import StyleManager from '../../../../../../../../../common/src/main/ets/default/StyleManager'; +import Constants from './Constants' + +const TAG = 'DropdownPanel-StyleConfiguration'; + +export default class StyleConfiguration { + static getControlStyle() { + const key: string = TAG + "-Control"; + return StyleManager.getStyle(key, () => { + return { + statusBarHeight: $r("app.float.status_bar_height") + }; + }); + } + + static getNotificationStyle() { + const key: string = TAG + "-Notification"; + return StyleManager.getStyle(key, () => { + return { + statusBarHeight: $r("app.float.status_bar_height"), + deleteAllImageWidth: $r("app.float.delete_all_image_width"), + deleteAllImageHeight: $r("app.float.delete_all_image_height"), + deleteAllImageBorderRadius: $r("app.float.delete_all_image_border_radius"), + deleteAllImageOpacity: $r("app.float.delete_all_image_opacity"), + }; + }); + } + + static getQuicklySettingStyle() { + const key: string = TAG + "-QuicklySetting"; + return StyleManager.getStyle(key, () => { + return { + quicklySetTimeFontSize: $r("app.float.quickly_setting_time_font_size"), + quicklySetTimeFontColor: $r('app.color.quickly_setting_time_font_color'), + quicklyDateFontColor: $r('app.color.quickly_setting_date_font_color'), + quicklyDateFontSize: $r("app.float.quickly_setting_date_font_size"), + quicklySetTextFlexMarginLeft: $r("app.float.quickly_setting_text_flex_margin_left"), + quicklySetImageWidth: $r("app.float.quickly_setting_image_width"), + quicklySttImageHeight: $r("app.float.quickly_setting_image_height"), + quicklySetImageMarginRight: $r("app.float.quickly_setting_image_margin_right"), + quickLySettingBorderRadius: $r("app.float.quickly_setting_border_radius"), + quickLySettingMarginLeft: $r("app.float.quickly_setting_margin_left"), + quickLySettingMarginRight: $r("app.float.quickly_setting_margin_right"), + quickSettingH: Constants.QUICKLY_SETTING_H, + }; + }); + } + + static getDateItemStyle() { + const key: string = TAG + "-DateItem"; + return StyleManager.getStyle(key, () => { + return { + quicklySetDateItemFontSize: $r("app.float.quickly_setting_date_font_size"), + quicklySetDateItemFontColor: $r('app.color.quickly_setting_date_font_color'), + }; + }); + } +} \ No newline at end of file diff --git a/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts new file mode 100644 index 00000000..e3611acc --- /dev/null +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../../common/src/main/ets/default/Log'; +import AbilityManager from '../../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager'; +import CommonTemplateStyleConfiguration from '../../../../../../../../../common/src/main/ets/template/common/StyleConfiguration'; +import ControlCenterStyleConfiguration from '../../../../../../../../../features/controlcentercomponent/src/main/ets/com/ohos/common/StyleConfiguration'; +import DropdownPanelStyleConfiguration from './StyleConfiguration' +import BrightnessStyleConfiguration from '../../../../../../../../../features/brightnessComponent/src/main/ets/default/common/StyleConfiguration'; +import ClockStyleConfiguration from '../../../../../../../../../features/clockComponent/src/main/ets/default/common/StyleConfiguration'; +import RingModeStyleConfiguration from '../../../../../../../../../features/ringmodecomponent/src/main/ets/com/ohos/common/StyleConfiguration' +import IndexStyleConfiguration from './StyleConfiguration' + +const TAG = 'DropdownPanel-StyleManager'; + +export default class StyleManager { + static STANDARD_DISPLAY_WIDTH: number = 720; + static STANDARD_DISPLAY_HEIGHT: number = 1280; + static maxWidth: number = StyleManager.STANDARD_DISPLAY_WIDTH; + + static setStyle() { + Log.showInfo(TAG, `setStyle`) + + let rect = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_DROPDOWN_PANEL, 'rect'); + StyleManager.maxWidth = rect.width; + + + // ControlCenter + { + let style: any = ControlCenterStyleConfiguration.getControlCenterComponentStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(48); + style.marginRight = StyleManager.calcScaleSizePx(48); + style.marginTop = StyleManager.calcScaleSizePx(33); + style.upTitleHeight = StyleManager.calcScaleSizePx(127); + style.titleMarginBottom = StyleManager.calcScaleSizePx(0); + style.toggleAreaGap = StyleManager.calcScaleSizePx(24); + style.simpleToggleLayoutMarginTop = StyleManager.calcScaleSizePx(48); + style.simpleToggleLayoutMarginBottom = StyleManager.calcScaleSizePx(20); + style.brightnessMarginBottom = StyleManager.calcScaleSizePx(44); + style.componentBorderRadius = StyleManager.calcScaleSizePx(48); + style.componentBackgroundColor = '#99FFFFFF'; + } + + // ControlCenter-Title + { + let style: any = ControlCenterStyleConfiguration.getControlCenterUpTitleStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(72); + style.marginRight = StyleManager.calcScaleSizePx(30); + style.fontSize = StyleManager.calcScaleSizePx(40); + style.fontColor = "#FFFFFFFF"; + style.imageWidth = StyleManager.calcScaleSizePx(48); + style.imageHeight = StyleManager.calcScaleSizePx(48); + style.imageHoverWidth = StyleManager.calcScaleSizePx(64); + style.imageHoverHeight = StyleManager.calcScaleSizePx(64); + style.imageHoverRadius = StyleManager.calcScaleSizePx(16); + style.imageHoverColor = 'rgba(0, 0, 0, 0.05)'; + style.imageTransparentColor = 'rgba(255, 255, 255, 0)'; + style.upTitleSpace = StyleManager.calcScaleSizePx(36); + style.titleImageColor = "#FFFFFFFF"; + } + + // ControlCenter-ComplexToggleLayout + { + let style: any = ControlCenterStyleConfiguration.getControlCenterComplexToggleLayoutStyle(); + style.columnGap = StyleManager.calcScaleSizePx(24); + style.rowGap = StyleManager.calcScaleSize(24); + style.rowHeight = StyleManager.calcScaleSize(132); + } + + // ControlCenter-SimpleToggleLayout + { + let style: any = ControlCenterStyleConfiguration.getControlCenterSimpleToggleLayoutStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(22); + style.marginRight = StyleManager.calcScaleSizePx(22); + style.columnGap = StyleManager.calcScaleSizePx(0); + style.rowGap = StyleManager.calcScaleSize(0); + style.rowHeight = StyleManager.calcScaleSize(162); + } + + // CommonTemplate-iconTitleBase + { + let style: any = CommonTemplateStyleConfiguration.getIconTitleBaseStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(24); + style.marginRight = StyleManager.calcScaleSizePx(16); + style.componentGap = StyleManager.calcScaleSizePx(8); + style.titleSize = StyleManager.calcScaleSizePx(24); + style.titleColor = $r("sys.color.ohos_id_color_text_secondary"); + style.borderRadius = StyleManager.calcScaleSizePx(48); + style.backgroundColor = '#99FFFFFF'; + style.textMargin = StyleManager.calcScaleSizePx(8); + style.textHoverHeight = StyleManager.calcScaleSizePx(36); + style.textHoverWidth = StyleManager.calcScaleSizePx(136); + style.textHoverRadius = StyleManager.calcScaleSizePx(8); + style.hoverColor = 'rgba(0, 0, 0, 0.05)'; + style.transparentColor = 'rgba(255, 255, 255, 0)'; + } + + // CommonTemplate-iconComponent + { + let style: any = CommonTemplateStyleConfiguration.getIconComponentStyle(); + style.circleWidth = StyleManager.calcScaleSizePx(96); + style.circleHeight = StyleManager.calcScaleSizePx(96); + style.iconWidth = StyleManager.calcScaleSizePx(48); + style.iconHeight = StyleManager.calcScaleSizePx(48); + style.iconOffBG = '#1A000000'; + style.iconOnBG = '#FF007DFF'; + style.iconOnColor = '#FFFFFFFF'; + style.iconOffColor = $r("sys.color.ohos_id_color_secondary"); + style.hoverColor = 'rgba(0, 0, 0, 0.05)'; + style.transparentColor = 'rgba(255, 255, 255, 0)'; + } + + // CommonTemplate-simpleToggleBase + { + let style: any = CommonTemplateStyleConfiguration.getSimpleToggleBaseStyle(); + style.circleWidth = StyleManager.calcScaleSizePx(96); + style.circleHeight = StyleManager.calcScaleSizePx(96); + style.iconWidth = StyleManager.calcScaleSizePx(48); + style.iconHeight = StyleManager.calcScaleSizePx(48); + style.dragCircleWidth = StyleManager.calcScaleSizePx(120); + style.dragCircleHeight = StyleManager.calcScaleSizePx(120); + style.dragIconWidth = StyleManager.calcScaleSizePx(72); + style.dragIconHeight = StyleManager.calcScaleSizePx(72); + style.iconOffBG = '#1A000000'; + style.iconOnBG = '#FF007DFF'; + style.iconOnColor = '#FFFFFFFF'; + style.iconOffColor = $r("sys.color.ohos_id_color_secondary"); + style.componentGap = StyleManager.calcScaleSizePx(10); + style.titleSize = StyleManager.calcScaleSizePx(24); + style.titleColor = $r("sys.color.ohos_id_color_text_secondary"); + style.textHoverWidth = StyleManager.calcScaleSizePx(136); + style.textHoverHeight = StyleManager.calcScaleSizePx(36); + style.textHoverRadius = StyleManager.calcScaleSizePx(8); + style.hoverColor = 'rgba(0, 0, 0, 0.05)'; + style.transparentColor = 'rgba(255, 255, 255, 0)'; + } + + // Brightness + { + let style: any = BrightnessStyleConfiguration.getBrightnessComponentStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(26); + style.marginRight = StyleManager.calcScaleSizePx(26); + style.componentGap = StyleManager.calcScaleSizePx(26); + style.brightnessIconColor = $r("sys.color.ohos_id_color_secondary"); + style.brightnessReduceWidth = StyleManager.calcScaleSizePx(44); + style.brightnessReduceHeight = StyleManager.calcScaleSizePx(44); + style.brightnessPlusWidth = StyleManager.calcScaleSizePx(44); + style.brightnessPlusHeight = StyleManager.calcScaleSizePx(44); + style.brightnessHeight = StyleManager.calcScaleSizePx(44); + style.sliderHeight = StyleManager.calcScaleSizePx(40); + style.sliderBlockColor = '#FFFFFFFF'; + style.sliderTrackColor = '#0D000000'; + style.selectedColor = '#FF007DFF'; + } + + // RingMode + { + let style: any = RingModeStyleConfiguration.getControlCenterRingModeComponentStyle(); + style.brightnessIconColor = '#FFFF9800'; + } + + // SimpleToggleLayoutEdit + { + let style: any = ControlCenterStyleConfiguration.getSimpleToggleLayoutEditComponentStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(48); + style.marginRight = StyleManager.calcScaleSizePx(48); + style.marginTop = StyleManager.calcScaleSizePx(33); + style.titleHeight = StyleManager.calcScaleSizePx(127); + style.titleMarginBottom = StyleManager.calcScaleSizePx(0); + style.upGridMarginTop = StyleManager.calcScaleSizePx(48); + style.upGridMarginBottom = StyleManager.calcScaleSizePx(24); + style.gridMarginLeft = StyleManager.calcScaleSizePx(18.24); + style.gridMarginRight = StyleManager.calcScaleSizePx(18.24); + style.msgMarginTop = StyleManager.calcScaleSizePx(0); + style.msgMarginBottom = StyleManager.calcScaleSizePx(0); + style.btnMarginTop = StyleManager.calcScaleSizePx(24); + style.btnMarginBottom = StyleManager.calcScaleSizePx(32); + style.borderRadius = StyleManager.calcScaleSizePx(48); + style.upAreaBgColor = '#99FFFFFF'; + style.downAreaBgColor = '#4DFFFFFF'; + style.editBtnFontColor = '#FF007DFF'; + style.editBtnFontSize = StyleManager.calcScaleSizePx(32); + style.editBtnBgColor = '#0D000000'; + style.editBtnMarginLeft = StyleManager.calcScaleSizePx(32); + style.editBtnMarginRight = StyleManager.calcScaleSizePx(32); + style.editBtnHeight = StyleManager.calcScaleSizePx(80); + style.editBtnSpace = StyleManager.calcScaleSizePx(32); + } + + // SimpleToggleLayoutEdit-title + { + let style: any = ControlCenterStyleConfiguration.getSimpleToggleLayoutEditUpTitleStyle(); + style.marginLeft = StyleManager.calcScaleSizePx(72); + style.imageWidth = StyleManager.calcScaleSizePx(40); + style.imageHeight = StyleManager.calcScaleSizePx(40); + style.fontColor = "#FFFFFFFF"; + style.editTitleSpace = StyleManager.calcScaleSizePx(36); + style.titleFontSize = StyleManager.calcScaleSizePx(40); + } + + // SimpleToggleLayoutEdit-msg + { + let style: any = ControlCenterStyleConfiguration.getSimpleToggleLayoutEditOptMsgStyle(); + style.fontSize = StyleManager.calcScaleSizePx(24); + style.fontColor = $r('sys.color.ohos_id_color_text_secondary'); + style.height = StyleManager.calcScaleSizePx(98); + style.marginLeftRight = StyleManager.calcScaleSizePx(44); + } + + // SimpleToggleLayoutEdit-grid + { + let style: any = ControlCenterStyleConfiguration.getSimpleToggleLayoutEditGridStyle(); + style.columnGap = StyleManager.calcScaleSizePx(0); + style.rowGap = StyleManager.calcScaleSize(0); + style.rowHeight = StyleManager.calcScaleSize(162); + style.dragBgSize = StyleManager.calcScaleSizePx(120); + } + + // EditDialog + { + let style: any = ControlCenterStyleConfiguration.getControlEditDialogStyle(); + style.editDialogHeight = StyleManager.calcScaleSizePx(217); + style.editDialogWidth = StyleManager.calcScaleSizePx(670); + style.editDialogFontSize = StyleManager.calcScaleSizePx(30); + style.editDialogBtnMarginLF = StyleManager.calcScaleSizePx(24); + style.editDialogFontHeight = StyleManager.calcScaleSizePx(36); + style.editDialogBtnMarginTop = StyleManager.calcScaleSizePx(36); + style.editDialogButtonSize = StyleManager.calcScaleSizePx(30); + style.editDialogDividerHeight = StyleManager.calcScaleSizePx(36); + style.editDialogButtonHeight = StyleManager.calcScaleSizePx(54); + style.editDialogRadius = StyleManager.calcScaleSizePx(36); + style.editDialogBtnWidth = StyleManager.calcScaleSizePx(311); + style.editDialogFontMarginTop = StyleManager.calcScaleSizePx(52); + style.editDialogColor = '#FFFFFFFF'; + style.editDialogBtnFontColor = '#FF0000FF'; + style.editDialogBtnBgColor = '#00FFFFFF'; + style.editDialogDividerColor = $r("sys.color.ohos_id_color_secondary"); + style.editDialogDividerWidth = StyleManager.calcScaleSizePx(1); + Log.showInfo(TAG, `getControlEditDialogStyle`) + } + + } + + static number2px(n: number): string { + return n.toString() + 'px'; + } + + static calcScaleSize(n: number): number { + return n * StyleManager.maxWidth / StyleManager.STANDARD_DISPLAY_WIDTH; + } + + static calcScaleSizePx(n: number): string { + return StyleManager.number2px(StyleManager.calcScaleSize(n)); + } +} \ No newline at end of file diff --git a/product/statusbar/src/main/ets/default/pages/common/constants.ets b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts similarity index 72% rename from product/statusbar/src/main/ets/default/pages/common/constants.ets rename to product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts index 8086bb4c..905eae19 100644 --- a/product/statusbar/src/main/ets/default/pages/common/constants.ets +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/constants.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -27,18 +27,7 @@ export default class Constants { $r('app.string.sunday') ] static DIGITS = 10; - static DEFAULT_MIDDLE_PART_WIDTH = 70; static MARK_MONTH = 0; static MARK_DAY = 1; - static EMPTY = 'empty' - static WIFI = 'wifi' - static SIGNAL = 'signal' - static CLOCK = 'clock' - static BATTERY = 'battery' - static CAPSULE = 'capsule' - static NOTIFICATION = 'notification' - static STATIC_BAR_ICON_WIDTH = 24; - static STATIC_BAR_ICON_MARGIN = 2; - static STATIC_BAR_ICON_HEIGHT = 24; static QUICKLY_SETTING_H = 83; } \ No newline at end of file diff --git a/product/statusbar/src/main/ets/default/pages/common/navigationEvent.ets b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/navigationEvent.ts similarity index 94% rename from product/statusbar/src/main/ets/default/pages/common/navigationEvent.ets rename to product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/navigationEvent.ts index b8a7c77d..ec3165f0 100644 --- a/product/statusbar/src/main/ets/default/pages/common/navigationEvent.ets +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/common/navigationEvent.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,7 +14,7 @@ */ import commonEvent from '@ohos.commonEvent'; -import Log from '../../../../../../../../common/src/main/ets/default/Log.ets' +import Log from '../../../../../../../../../common/src/main/ets/default/Log' const TAG = 'navigationEvent'; diff --git a/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/control.ets b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/control.ets new file mode 100644 index 00000000..3708e159 --- /dev/null +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/control.ets @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import ControlCenterComponent from '../../../../../../../../features/controlcentercomponent/src/main/ets/com/ohos/pages/ControlCenterComponent' +import BatteryIcon from '../../../../../../../../features/batterycomponent/src/main/ets/default/pages/batteryIcon' +import ClockIcon from '../../../../../../../../features/clockcomponent/src/main/ets/default/pages/clockIcon' +import WifiIcon from '../../../../../../../../features/wificomponent/src/main/ets/default/pages/wifiIcon' +import BluetoothIcon from '../../../../../../../../features/bluetoothcomponent/src/main/ets/com/ohos/pages/StatusBarIconItemBluetoothComponent' +import SignalIcon from '../../../../../../../../features/signalcomponent/src/main/ets/default/pages/signalIcon' +import LocationIcon from '../../../../../../../../features/locationcomponent/src/main/ets/com/ohos/pages/StatusBarIconItemLocationComponent' +import RingModeIcon from '../../../../../../../../features/ringmodecomponent/src/main/ets/com/ohos/pages/StatusBarIconItemRingModeComponent' +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import Constants from './common/constants' +import StyleConfiguration from './common/StyleConfiguration' +import ControlCenterConfig from './common/ControlCenterConfig'; + +const TAG = 'DropdownPanel-Control'; + +@Component +export default struct Control { + private touchMoveCallback: Function + startX: number = 0 + startY: number = 0 + @State moveX: number = 0 + @State moveY: number = 0 + @State style: any = StyleConfiguration.getControlStyle() + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear Start`) + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisAppear`) + } + + build() { + Column() { + Column() { + statusBar() + } + .width('100%') + .height(this.style.statusBarHeight) + .layoutWeight(0) + + Scroll(new Scroller()) { + Column() { + ControlCenterComponent({ + touchMoveCallback: (data)=>this.controlCenterTouchMoveCallback(data), + mControlCenterComponentConfig: ControlCenterConfig + }) + } + .width('100%') + } + .width('100%') + .scrollBarColor(Color.Gray).scrollBarWidth(10) + .layoutWeight(1) + } + .width('100%') + .height('100%') + .onTouch(this.controlTouch.bind(this)) + } + + controlTouch(event: TouchEvent) { + Log.showInfo(TAG, `controlTouch================ event: ${event}`) + if (event.type == Constants.TOUCHTYPE_DOWN) { + this.startX = event.touches[0].screenX + this.startY = event.touches[0].screenY + Log.showInfo(TAG, `controlTouch=======startX: ${this.startX}, startY: ${this.startY}`) + } else if (event.type == Constants.TOUCHTYPE_MOVE) { + this.moveX = event.touches[0].screenX - this.startX + this.moveY = event.touches[0].screenY - this.startY + } else if (event.type == Constants.TOUCHTYPE_UP) { + Log.showInfo(TAG, `controlTouch, moveX: ${this.moveX}, moveY: ${this.moveY}`) + if (this.moveY < -30) { + if (this.touchMoveCallback) { + this.touchMoveCallback({ 'direction': 'top', 'touchComponent': 'control' }) + } + } + } + } + + controlCenterTouchMoveCallback(data) { + Log.showInfo(TAG, `controlCenterTouchMoveCallback data: ${JSON.stringify(data)}`) + data['touchComponent'] = 'control' + if (this.touchMoveCallback) { + this.touchMoveCallback(data) + } + } +} + +@Component +struct statusBar { + @StorageLink('StatusCoefficient') StatusCoefficient: number = 1.0 + + build() { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { + SignalIcon() + WifiIcon() + } + + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.End }) { + LocationIcon() + BluetoothIcon() + RingModeIcon() + BatteryIcon() + ClockIcon() + } + } + .width('100%') + .height('100%') + } +} diff --git a/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/index.ets b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/index.ets new file mode 100644 index 00000000..50a7496c --- /dev/null +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/index.ets @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import screenshot from "@ohos.screenshot" +import image from "@ohos.multimedia.image" +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import WindowManager, +{WindowType, WINDOW_SHOW_HIDE_EVENT} from '../../../../../../../../common/src/main/ets/default/WindowManager' +import EventManager, {unsubscribe} from "../../../../../../../../common/src/main/ets/default/event/EventManager" +import {START_ABILITY_EVENT} from "../../../../../../../../common/src/main/ets/default/event/EventUtil" +import CommonStyleManager from '../../../../../../../../common/src/main/ets/default/StyleManager' +import MultimodalInputManager from '../../../../../../../../common/src/main/ets/default/MultimodalInputManager' +import AbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import HeightConfigUtils from '../../../../../../../../common/src/main/ets/default/heightcofigUtils/HeightConfigUtils' +import StatusBarVM from '../../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/viewmodel/StatusBarVM' +import NavigationEvent from './common/navigationEvent' +import Notification from './notification' +import ControlCenterComponent from './control' +import StyleManager from './common/StyleManager' +import featureAbility from '@ohos.ability.featureAbility'; +import settings from '@ohos.settings'; +import CommonConstants from "../../../../../../../../common/src/main/ets/default/Constants"; + +const TAG = 'DropdownPanel-Index' + +let mHeightConfigUtils + +const SHOW_ANIM_CONFIG = { + duration: 300, + tempo: 1.0, + curve: Curve.Friction, + delay: 0, + iterations: 1, + playMode: PlayMode.Normal +}; +const HIDE_ANIM_CONFIG = { + duration: 200, + tempo: 1.0, + curve: Curve.EaseOut, + delay: 0, + iterations: 1, + playMode: PlayMode.Normal, +} + +@Entry +@Component +struct Index { + @State showComponentName: string = undefined + @State componentOptAreaHeightPX: number = 0 + @StorageLink('StatusCoefficient') StatusCoefficient: number = 1.0 + @State controlCenterComponentConfig: any = {}; + @State mBackground: PixelMap | undefined = undefined; + mCallback: any; + mClearCallbacks: unsubscribe[] + settingDataKey = 'settings.display.navigationbar_status'; + urivar: string = null; + helper: any = null; + mNavigationBarStatusDefaultValue: string = '1'; + navigationBarWidth: number = 0; + mNeedUpdate: boolean = false; + mWidthPx: number = 0; + @State mNotificationInsert: any = {} + @State mNotificationDelete: any = {} + @State mControlCenterInsert: any = {} + @State mControlCenterDelete: any = {} + @State componentOptAreaTranslateY: string = '0px' + @State backgroundOpacity: number = 0 + + onBackPress(): boolean { + return true + } + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear, start`) + + setAppBgColor('#00000000') + CommonStyleManager.setAbilityPageName(TAG) + StyleManager.setStyle() + + let dropdownRect = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_DROPDOWN_PANEL, 'rect') + let navigationBarRect = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_NAVIGATION_BAR, 'config') + this.urivar = settings.getUriSync(this.settingDataKey); + this.helper = featureAbility.acquireDataAbilityHelper(AbilityManager.getContext(), CommonConstants.URI_VAR); + this.resizeDropdownPanelAndNavigationBar(dropdownRect, navigationBarRect); + Log.showInfo(TAG, `getValueSync componentOptAreaHeightPX: ${this.componentOptAreaHeightPX}`) + this.helper.on("dataChange", this.urivar, (data) => { + if (data.code !== 0) { + Log.showInfo(TAG, `dataChangesCallback failed, because ${data.message}`); + return; + } else { + this.resizeDropdownPanelAndNavigationBar(dropdownRect, navigationBarRect); + Log.showInfo(TAG, `NavigationBar status change, componentOptAreaHeightPX: ${this.componentOptAreaHeightPX}`) + } + }) + + this.componentOptAreaTranslateY = (-this.componentOptAreaHeightPX * 0.1) + 'px' + + this.mClearCallbacks = [] + this.mClearCallbacks.push( + EventManager.subscribe('DropdownEvent', (args) => this.onDropdownEvent(args)), + EventManager.subscribe(START_ABILITY_EVENT, (args) => this.onStartAbility(args)), + EventManager.subscribe('hideNotificationWindowEvent', (args) => this.onHideNotificationWindowEvent(args))) + + mHeightConfigUtils = new HeightConfigUtils(); + let StatusCoefficient; + + StatusCoefficient = AppStorage.SetAndLink("StatusCoefficient", 1.0); + StatusCoefficient.set(mHeightConfigUtils.getStatusCoefficient()); + + let signalObserved = AppStorage.SetAndLink("signalObserved", false); + signalObserved.set(false); + + this.mCallback = { + "onStateChange": (data) => this.onStateChange(data), + "onNotificationShowOrHide": (err, data) => this.onNotificationShowOrHide(err, data), + "onControlShowOrHide": (err, data) => this.onControlShowOrHide(err, data) + } + NavigationEvent.registerCallback(this.mCallback); + MultimodalInputManager.registerControlListener(this.mCallback); + MultimodalInputManager.registerNotificationListener(this.mCallback); + Log.showInfo(TAG, `aboutToAppear, end`) + } + + onPageShow() { + Log.showInfo(TAG, `onPageShow, start`) + if (!this.showComponentName) { + return + } + StatusBarVM.setUseInWindowName(WindowType.DROPDOWN_PANEL) + this._animateTo({ ...SHOW_ANIM_CONFIG, onFinish: () => { + Log.showInfo(TAG, `onPageShow, show anim finish.`); + } }, () => { + this.componentOptAreaTranslateY = '0px' + this.backgroundOpacity = 1 + }) + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisappear`) + this.mClearCallbacks.forEach((mClearCallback: Function) => { + mClearCallback() + mClearCallback = undefined + }) + this.mClearCallbacks = undefined + } + + resizeDropdownPanelAndNavigationBar(dropdownRect, navigationBarRect) { + Log.showInfo(TAG, `resizeDropdownPanelAndNavigationBar, dropdownRect: ${JSON.stringify(dropdownRect)} navigationBarRect: ${JSON.stringify(navigationBarRect)}`) + this.mNavigationBarStatusDefaultValue = settings.getValueSync(this.helper, this.settingDataKey, '1'); + this.componentOptAreaHeightPX = this.mNavigationBarStatusDefaultValue == '1' ? dropdownRect.height - navigationBarRect.realHeight : dropdownRect.height; + this.navigationBarWidth = this.mNavigationBarStatusDefaultValue == '1' ? navigationBarRect.height : 0; + WindowManager.resetSizeWindow(WindowType.NAVIGATION_BAR, { ...navigationBarRect, height: this.navigationBarWidth }) + WindowManager.resetSizeWindow(WindowType.DROPDOWN_PANEL, { ...dropdownRect, height: this.componentOptAreaHeightPX }) + } + + onNotificationShowOrHide(err, data) { + Log.showInfo(TAG, `mNotificationAsyncCallback preKeys: ${data.preKeys}, finalKey: ${data.finalKey}`); + Log.showInfo(TAG, `this.showComponentName: ${this.showComponentName}`); + if (this.showComponentName == 'Notification') { + this.hideSelf(); + } else { + this.showSelf('Notification'); + } + Log.showInfo(TAG, `mNotificationAsyncCallback end`); + } + + onControlShowOrHide(err, data) { + Log.showInfo(TAG, `mControlAsyncCallback preKeys: ${data.preKeys}, finalKey: ${data.finalKey}`); + Log.showInfo(TAG, `this.showComponentName: ${this.showComponentName}`); + if (this.showComponentName == 'ControlCenter') { + this.hideSelf(); + } else { + this.showSelf('ControlCenter'); + } + Log.showInfo(TAG, `mControlAsyncCallback end`); + } + + onStateChange(data) { + Log.showInfo(TAG, `onStateChange, data: ${JSON.stringify(data)}`) + Log.showInfo(TAG, `onStateChange, showComponentName: ${this.showComponentName}`) + if (this.showComponentName) { + this.hideSelf() + } + } + + onDropdownEvent(args) { + Log.showInfo(TAG, `onDropdownEvent, args: ${JSON.stringify(args)}`) + this.showSelf(args.dropdownArea == 'left' ? 'Notification' : 'ControlCenter') + } + + onStartAbility(args) { + Log.showInfo(TAG, `onStartAbility, args: ${args}`) + this.hideSelf() + } + + onHideNotificationWindowEvent(args) { + Log.showInfo(TAG, `onHideNotificationWindowEvent, args: ${args}`) + this.hideSelf() + } + + onTouchMove(data) { + Log.showInfo(TAG, `onTouchMove, data: ${JSON.stringify(data)}`) + if (data.direction == 'top') { + this.hideSelf() + } else if (data.direction == 'left' && data.touchComponent == 'notification') { + this.switchNotificationOrControlCenter('ControlCenter') + } else if (data.direction == 'right' && data.touchComponent == 'control') { + this.switchNotificationOrControlCenter('Notification') + } + } + + switchNotificationOrControlCenter(showComponentName) { + Log.showInfo(TAG, `switchNotificationOrControlCenter, showComponentName: ${showComponentName}`) + this.mNotificationInsert = { type: TransitionType.Insert, opacity: 0, translate: { x: (-this.mWidthPx) + 'px' } } + this.mControlCenterInsert = { type: TransitionType.Insert, opacity: 0, translate: { x: (this.mWidthPx) + 'px' } } + let transitionDelete = { + type: TransitionType.Delete, + opacity: 0, + scale: { x: 0.8, y: 0.8, centerX: '50%', centerY: '50%' } + } + this.mNotificationDelete = transitionDelete + this.mControlCenterDelete = transitionDelete + this._animateTo({ ...SHOW_ANIM_CONFIG, onFinish: () => { + Log.showInfo(TAG, `switchNotificationOrControlCenter, show anim finish.`); + } }, () => { + this.showComponentName = showComponentName + }) + } + + showSelf(showComponentName) { + Log.showInfo(TAG, `showSelf, showComponentName: ${showComponentName}`) + this.showComponentName = showComponentName + this.updateBackground() + WindowManager.showWindow(WindowType.DROPDOWN_PANEL) + } + + hideSelf() { + Log.showInfo(TAG, `hideSelf`) + this._animateTo({ ...SHOW_ANIM_CONFIG, onFinish: () => { + Log.showInfo(TAG, `hideSelf, hide anim finish.`); + this.showComponentName = undefined + this.mBackground && this.mBackground.release(); + this.mBackground = undefined; + WindowManager.hideWindow(WindowType.DROPDOWN_PANEL) + } }, () => { + this.componentOptAreaTranslateY = (-this.componentOptAreaHeightPX * 0.1) + 'px' + this.backgroundOpacity = 0 + }) + } + + updateBackground() { + let rect = WindowManager.getWindowInfo(WindowType.DROPDOWN_PANEL)?.rect; + Log.showInfo(TAG, `start get snapShot, rect: ${JSON.stringify(rect)}`) + screenshot.save({ screenRect: rect }) + .then((snapImage) => { + Log.showInfo(TAG, `get snap: ${JSON.stringify(snapImage)}`) + this.mBackground = snapImage + }) + } + + _animateTo(config, callback) { + Log.showInfo(TAG, `_animateTo, config: ${JSON.stringify(config)}`) + animateTo(config, callback) + setTimeout(config.onFinish, config.duration + config.delay) + } + + build() { + Stack({ alignContent: Alignment.Top }) { + if (this.mBackground) { + Image(this.mBackground) + .width('100%') + .height('100%') + .objectFit(ImageFit.Fill) + .blur(20) + .opacity(this.backgroundOpacity) + } + Column() { + if (this.showComponentName == 'Notification') { + Column() { + Notification({ touchMoveCallback: (data) => this.onTouchMove(data) }) + } + .width('100%') + .height('100%') + .transition(this.mNotificationInsert) + .transition(this.mNotificationDelete) + } else if (this.showComponentName == 'ControlCenter') { + Column() { + ControlCenterComponent({ + touchMoveCallback: (data) => this.onTouchMove(data) + }) + } + .width('100%') + .height('100%') + .transition(this.mControlCenterInsert) + .transition(this.mControlCenterDelete) + } + } + .width('100%') + .height(this.componentOptAreaHeightPX + 'px') + .translate({ y: this.componentOptAreaTranslateY }) + } + .width('100%') + .height('100%') + .backgroundColor($r("app.color.default_background")) + .opacity(this.backgroundOpacity) + .onAreaChange((e, e2) => { + Log.showInfo(TAG, `onAreaChange, e: ${JSON.stringify(e)} e2: ${JSON.stringify(e2)}`); + this.mWidthPx = vp2px(e2.width) + }) + } +} diff --git a/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/notification.ets b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/notification.ets new file mode 100644 index 00000000..ad0dee75 --- /dev/null +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/pages/notification.ets @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import EventManager, {unsubscribe} from "../../../../../../../../common/src/main/ets/default/event/EventManager" +import {obtainStartAbility} from "../../../../../../../../common/src/main/ets/default/event/EventUtil" +import Constants from './common/constants' +import BatteryIcon from '../../../../../../../../features/batterycomponent/src/main/ets/default/pages/batteryIcon' +import ClockIcon from '../../../../../../../../features/clockcomponent/src/main/ets/default/pages/clockIcon' +import WifiIcon from '../../../../../../../../features/wificomponent/src/main/ets/default/pages/wifiIcon' +import BluetoothIcon from '../../../../../../../../features/bluetoothcomponent/src/main/ets/com/ohos/pages/StatusBarIconItemBluetoothComponent' +import SignalIcon from '../../../../../../../../features/signalcomponent/src/main/ets/default/pages/signalIcon' +import LocationIcon from '../../../../../../../../features/locationcomponent/src/main/ets/com/ohos/pages/StatusBarIconItemLocationComponent' +import RingModeIcon from '../../../../../../../../features/ringmodecomponent/src/main/ets/com/ohos/pages/StatusBarIconItemRingModeComponent' +import NotificationListComponent from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/view/NotificationListComponent' +import ViewModel from '../../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/viewmodel/ViewModel' +import ResourceUtil from '../../../../../../../../common/src/main/ets/default/ResourceUtil' +import TimeManager, { TimeEventArgs, TIME_CHANGE_EVENT } from '../../../../../../../../common/src/main/ets/default/TimeManager' + +const TAG = 'DropdownPanel-notification' +const GRID_SIZE = 6; +const IMAGE_SIZE_L = 40; +const IMAGE_SIZE_S = 48; +const NO_NOTIFICATION_TOP_MARGIN = 40; +const TIME_TEXT_MARGIN = 8; +const TIME_BOTTOM_OFFSET = 7; +const SETTING_ICON_MARGIN = 12; + +@Component +export default struct Notification { + private touchMoveCallback: Function + startX: number = 0 + startY: number = 0 + @State moveX: number = 0 + @State moveY: number = 0 + @StorageLink('notificationList') notificationList: any[] = [] + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear Start`) + } + + build() { + Stack({ alignContent: Alignment.Bottom }) { + Column() { + Row() + .height(24) + .width('100%') + .backgroundColor($r("app.color.statusbar_background_color")) + }.height('100%') + + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { + statusBar() + CenterTitle({ + touchMoveCallback: (data) => this.CenterTitleTouchMoveCallback(data) + }) + if (this.notificationList.length == 0) { + Text($r("app.string.no_notification")) + .fontColor($r("sys.color.ohos_id_color_text_primary_contrary")) + .fontSize($r("sys.float.ohos_id_text_size_sub_title2")) + .fontWeight(FontWeight.Medium) + .alignSelf(ItemAlign.Center) + .margin({ top: NO_NOTIFICATION_TOP_MARGIN }) + } else { + NotificationListComponent() + } + }.padding({ + left: $r("sys.float.ohos_id_notification_margin_start"), + right: $r("sys.float.ohos_id_notification_margin_end") + }) + .height('100%') + } + + if (this.notificationList.length > 0) { + Image($r('app.media.delete_all')) + .width(IMAGE_SIZE_L) + .height(IMAGE_SIZE_L) + .margin({ bottom: 32 }) + .onClick(() => { + ViewModel.removeAllNotifications(); + }) + } + }.onTouch(this.touchEvent.bind(this)) + } + + touchEvent(event: TouchEvent) { + if (event.type == Constants.TOUCHTYPE_DOWN) { + this.startX = event.touches[0].screenX + this.startY = event.touches[0].screenY + Log.showInfo(TAG, `touchStart2=======startX: ${this.startX}, startY: ${this.startY}`) + } else if (event.type == Constants.TOUCHTYPE_MOVE) { + this.moveX = event.touches[0].screenX - this.startX + this.moveY = event.touches[0].screenY - this.startY + } else if (event.type == Constants.TOUCHTYPE_UP) { + Log.showInfo(TAG, `touchEnd2, moveX: ${this.moveX}, moveY: ${this.moveY}`) + if (this.moveY < -30) { + if (this.touchMoveCallback) { + this.touchMoveCallback({ 'direction': 'top', 'touchComponent': 'notification' }) + } + } + } + } + + CenterTitleTouchMoveCallback(data) { + Log.showInfo(TAG, `CenterTitleTouchMoveCallback, data: ${JSON.stringify(data)}`) + data['touchComponent'] = 'notification' + if (this.touchMoveCallback) { + this.touchMoveCallback(data) + } + } +} + +@Component +struct statusBar { + @StorageLink('StatusCoefficient') StatusCoefficient: number = 1.0 + + build() { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { + SignalIcon() + WifiIcon() + } + + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.End }) { + LocationIcon() + BluetoothIcon() + RingModeIcon() + BatteryIcon() + ClockIcon() + } + } + .height(24) + .width('100%') + } +} + +@Component +struct CenterTitle { + private touchMoveCallback: Function + startX: number = 0 + startY: number = 0 + @State moveX: number = 0 + @State moveY: number = 0 + @State mTimeString: string = ''; + @State mTime: string = '01:01' + unSubscriber?: unsubscribe; + + aboutToAppear() { + Log.showInfo(TAG, `CenterTitle, aboutToAppear`) + this.unSubscriber = EventManager.subscribe(TIME_CHANGE_EVENT, (args: TimeEventArgs) => { + this.updateTimeString(args.date) + }); + this.updateTimeString(new Date()) + } + + aboutToDisappear() { + Log.showInfo(TAG, 'CenterTitle aboutToDisappear'); + this.unSubscriber && this.unSubscriber(); + this.unSubscriber = undefined; + } + + build() { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.End, justifyContent: FlexAlign.Start }) { + Text(this.mTime) + .fontColor($r("sys.color.ohos_id_color_text_primary_contrary")) + .fontSize('36fp') + .fontWeight(FontWeight.Medium) + .margin({ left: TIME_TEXT_MARGIN }) + Text(this.mTimeString) + .fontColor($r("sys.color.ohos_id_color_text_primary_contrary")) + .fontSize($r("sys.float.ohos_id_text_size_sub_title3")) + .fontWeight(FontWeight.Medium) + .margin({ left: TIME_TEXT_MARGIN, bottom: TIME_BOTTOM_OFFSET }) + .flexGrow(1) + Image($r('app.media.ic_settings')) + .objectFit(ImageFit.Contain) + .width(IMAGE_SIZE_S) + .height(IMAGE_SIZE_S) + .margin({ right: SETTING_ICON_MARGIN, bottom: TIME_BOTTOM_OFFSET }) + .onClick(this.settingClick.bind(this)) + } + .margin({ top: TIME_TEXT_MARGIN, bottom: TIME_TEXT_MARGIN }) + .onTouch(this.touchEvent.bind(this)) + } + + async updateTimeString(date: Date) { + this.mTime = TimeManager.formatTime(date); + let timeString = (date.getMonth() + 1) + (await ResourceUtil.getString($r('app.string.month'))); + timeString += date.getDate() + (await ResourceUtil.getString($r('app.string.month'))); + timeString += await ResourceUtil.getString(Constants.WEEKDAY_LIST[date.getMonth()]); + this.mTimeString = timeString; + } + + settingClick() { + Log.showInfo(TAG, ` settingClick `) + EventManager.publish(obtainStartAbility('com.ohos.systemui', 'com.ohos.systemui.notificationmanagement.MainAbility')) + } + + touchEvent(event: TouchEvent) { + if (event.type == Constants.TOUCHTYPE_DOWN) { + this.startX = event.touches[0].screenX + this.startY = event.touches[0].screenY + Log.showInfo(TAG, `CenterTitle touchStart2=======startX: ${this.startX}, startY: ${this.startY}`) + } else if (event.type == Constants.TOUCHTYPE_MOVE) { + this.moveX = event.touches[0].screenX - this.startX + this.moveY = event.touches[0].screenY - this.startY + } else if (event.type == Constants.TOUCHTYPE_UP) { + Log.showInfo(TAG, `CenterTitle touchEnd2, moveX: ${this.moveX}, moveY: ${this.moveY}`) + if (this.moveX < -30) { + if (this.touchMoveCallback) { + this.touchMoveCallback({ 'direction': 'left' }) + } + } else if (this.moveX > 30) { + if (this.touchMoveCallback) { + this.touchMoveCallback({ 'direction': 'right' }) + } + } + } + } +} diff --git a/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js new file mode 100644 index 00000000..3135d74c --- /dev/null +++ b/product/phone/dropdownpanel/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from "@ohos.worker"; +import Log from "../../../../../../../../common/src/main/ets/default/Log"; +import PluginDataSourceManager +from "../../../../../../../../common/src/main/ets/plugindatasource/PluginDataSourceManager"; +import Constants, { obtainMsg } from "../../../../../../../../common/src/main/ets/plugindatasource/common/Constants"; + +const parentPort = worker.parentPort; +const TAG = `${parentPort.name} Worker`; +Log.showInfo(TAG, `Start.`); + +var sManager; + +parentPort.onmessage = (msg) => { + Log.showInfo(TAG, `onMessage, msg = ${JSON.stringify(msg)}`); + let data = msg.data; + switch (data.action) { + case Constants.INIT_CONFIG: + initConfig(data.data); + break; + case Constants.CLEAR_ALL: + clearAll(); + break; + case Constants.LOAD_DATA: + loadData(data.data); + break; + default: + Log.showError(TAG, `onMessage, unknown action type.`); + } +}; + +function initConfig(config) { + Log.showInfo(TAG, `initConfig, config = ${JSON.stringify(config)}`); + sManager = new PluginDataSourceManager({ + onItemAdd: (itemData) => { + Log.showInfo(TAG, `sManager.onItemAdd, itemData = ${JSON.stringify(itemData)}`); + itemData.label && (itemData.label = encodeURIComponent(itemData.label)); + parentPort.postMessage(obtainMsg(Constants.ADD_ITEM, itemData)); + }, + onItemRemove: (itemData) => { + Log.showInfo(TAG, `sManager.onItemRemove, itemData = ${JSON.stringify(itemData)}`); + parentPort.postMessage(obtainMsg(Constants.REMOVE_ITEM, itemData)); + }, + }); + sManager.initDataSource(config); + parentPort.postMessage(obtainMsg(Constants.INIT_FINISH, {})); +} + +function clearAll() { + Log.showInfo(TAG, `clearAll `); + sManager?.clearAll(); +} + +function loadData(userId) { + Log.showInfo(TAG, `loadData `); + sManager?.loadData(userId); +} + +parentPort.onclose = function () { + Log.showInfo(TAG, `onclose`); +}; + +parentPort.onmessageerror = function () { + Log.showInfo(TAG, `onmessageerror`); +}; + +parentPort.onerror = function (data) { + Log.showInfo( + TAG, + `onerror, lineno = ${data.lineno}, msg = ${data.message}, filename = ${data.filename}, col = ${data.colno}` + ); +}; \ No newline at end of file diff --git a/product/phone/dropdownpanel/src/main/resources/base/element/color.json b/product/phone/dropdownpanel/src/main/resources/base/element/color.json new file mode 100644 index 00000000..24157404 --- /dev/null +++ b/product/phone/dropdownpanel/src/main/resources/base/element/color.json @@ -0,0 +1,23 @@ +{ + "color": [ + { + "name": "default_background", + "value": "#4D999999" + }, + { + "name": "default_font_color", + "value": "#ffffffff" + }, + { + "name": "quickly_setting_time_font_color", + "value": "#ffffffff" + }, + { + "name": "quickly_setting_date_font_color", + "value": "#ffffffff" + },{ + "name": "statusbar_background_color", + "value": "#1a262626" + } + ] +} \ No newline at end of file diff --git a/product/phone/dropdownpanel/src/main/resources/base/element/float.json b/product/phone/dropdownpanel/src/main/resources/base/element/float.json new file mode 100644 index 00000000..76a0e294 --- /dev/null +++ b/product/phone/dropdownpanel/src/main/resources/base/element/float.json @@ -0,0 +1,60 @@ + { + "float": [ + { + "name": "status_bar_height", + "value": "48vp" + }, + { + "name": "quickly_setting_time_font_size", + "value": "30fp" + }, + { + "name": "quickly_setting_date_font_size", + "value": "20fp" + }, + { + "name": "quickly_setting_text_flex_margin_left", + "value": "10vp" + }, + { + "name": "quickly_setting_image_width", + "value": "50vp" + }, + { + "name": "quickly_setting_image_height", + "value": "50vp" + }, + { + "name": "quickly_setting_image_margin_right", + "value": "10vp" + }, + { + "name": "quickly_setting_border_radius", + "value": "20vp" + }, + { + "name": "quickly_setting_margin_left", + "value": "10vp" + }, + { + "name": "quickly_setting_margin_right", + "value": "10vp" + }, + { + "name": "delete_all_image_width", + "value": "50vp" + }, + { + "name": "delete_all_image_height", + "value": "50vp" + }, + { + "name": "delete_all_image_border_radius", + "value": "25vp" + }, + { + "name": "delete_all_image_opacity", + "value": "0.9" + } + ] +} \ No newline at end of file diff --git a/product/phone/dropdownpanel/src/main/resources/base/element/string.json b/product/phone/dropdownpanel/src/main/resources/base/element/string.json new file mode 100644 index 00000000..128a7ac0 --- /dev/null +++ b/product/phone/dropdownpanel/src/main/resources/base/element/string.json @@ -0,0 +1,52 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SystemUI" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "monday", + "value": "星期一" + }, + { + "name": "tuesday", + "value": "星期二" + }, + { + "name": "wednesday", + "value": "星期三" + }, + { + "name": "thursday", + "value": "星期四" + }, + { + "name": "friday", + "value": "星期五" + }, + { + "name": "saturday", + "value": "星期六" + }, + { + "name": "sunday", + "value": "星期日" + }, + { + "name": "day", + "value": "日" + }, + { + "name": "month", + "value": "月" + }, + { + "name": "no_notification", + "value": "没有通知" + } + ] +} \ No newline at end of file diff --git a/product/phone/dropdownpanel/src/main/resources/base/media/delete_all.png b/product/phone/dropdownpanel/src/main/resources/base/media/delete_all.png new file mode 100644 index 0000000000000000000000000000000000000000..143463751f103bbf00d204cbbd40982b9a5a6ec1 GIT binary patch literal 4061 zcmV<34Px^mq|oHRCodHT}x~g*BQ2r@f%F*LZBts5pqlFU~K%5P$C2i+C>&b-6oX^X%~?| zs=8r=iXyRLQ&j?qO(0p&Z3PQ9NhJ_UgoF(?CN4x4!sbyq20J$K0~^fk_ub5l?wmRE zyff#_wdY84XXZTq|2zLT|2b#QoS9o*wgSS)$Vm0`=g;3PFE4LFb(*>5a=D*lUx&Cl z9M|(08}|%z*yfQohqQU)cnbS5ZipLQzkdCr*4EZVoR@ScFGcjXZ{L3F)vH%Mz}}7R zZETyd#a)*iWR7FIi><%1va)a2u3ZmsTv8!!qa;%Kfq{Vy%gf9A)~s36{rdH565EuB zB7dQi6%`eIz|s#aS35g9r~QlQ&5>Gyhlhu&78e)yqPct@Cfb9oQm?5T+Fv2&I-2>* z)z#J4+S=Nd963@Dkvf702M62WAqQcb-(hP=fsKMdm_?>9;nkNqIy#1f6i}5XH3Z+f zb&LJ!VR&q>s>&y!2OfO`a?kJHy}LgN`C(;hC%CV#?_Kn39|L%MSnw&&KZNnZxt^Y$ zZ*=0+MleRg?_eZ+43+07cqNCs7=fR{2>e?el~hh}e}8`?JoYG>;tzCGSeH&T-524} zr@OnmXH;TPMlc91zj^cKK~(f8D%hy9k}1+P13R4V>gu`#JMca`@t}m@8#iujhS#1% zr8*L?Q3)sj$%F9bK$+tG&M zOS_kdjbP450pMAv$_7*J_V!C@qz!3Hzl=fCV<8y#x4%d8@()~vH9-|;`Q#R$4QWf- zRGuSTY|(u%uQr3+HQ`iexxFlaJ{d!q<-Zj>mt7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/phone/dropdownpanel/src/main/resources/base/media/ic_settings.png new file mode 100644 index 0000000000000000000000000000000000000000..b665b89cd206a3e476f5e9efbe31d482be7a0321 GIT binary patch literal 1060 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY3?!3`olAjKMSxF;E0F#_5a8H~Cu@LqYm@}} z1v9Kz!j?9FIuBE}!mNZcS4&e#flzNf(Mi1>^=i%1`N3NL4o1n*HdQBu_hvFMFdKWi zIEF+Vej9#s+ad#j78kRdfm2)=4?g|>zd()AfAYJE{uH_A*Cuyvob>9Qm;38_*Xl$w zg_;8Ad2?=RF*z@q+goV#=%cJtiHVZdQUAw>rJKGbt>ZbuVqg*wcDRBmm+e%Z!84E9 zGmVOK{~Sz9ZSWBYJuGgoCl@W7{erOF;$IcgfUmCs@iPs@$<)xc{e&^r`Hz$n5Fc68o!~6m_X;r-3M!*R-C#c`pk^s zJ>T*>EFJ6%T6QFUShJtKpQXsdIE67zW3s}|YH=6SU-PrlN>v`}xS4-du5QippJ`Rn zlFzT2*C&DGO4`=s8kF>v+H*|T5jcEU0pj}>p- z&R(2s@b;??RS90X*HG_Xm(`U0F=ADlvyYehs0yDJnOBw9C1X25<)^Op@q~BX8`ta1P@n&# zQlMZ?9?P2xVMZIL`p>!fQo?`Pha*Q8{uX#SRq~QV<$VUw{C@5NXD`4}D? zS~OS2;k@mRipJAhZ%#R$7J5D1Jw481L5+t=u#l-@Ot#dN<6lnQ?@xF%E6L7fSI?=G zKd;W-{qYPw7g)mGYe$1ILWg+-yu;l zp literal 0 HcmV?d00001 diff --git a/product/phone/dropdownpanel/src/main/resources/base/media/icon.png b/product/phone/dropdownpanel/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?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BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y + WindowManager.showWindow(WindowType.STATUS_BAR) + ); + } + + onDestroy() { + Log.showInfo(TAG, 'api8New onDestroy'); + } +} + +export default ServiceExtAbility \ No newline at end of file diff --git a/product/phone/statusbar/src/main/ets/ServiceExtAbility/app.ets b/product/phone/statusbar/src/main/ets/ServiceExtAbility/app.ets new file mode 100644 index 00000000..58395908 --- /dev/null +++ b/product/phone/statusbar/src/main/ets/ServiceExtAbility/app.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityManager from '../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager' +import StatusBarVM from '../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/viewmodel/StatusBarVM' +import {StatusBarData} from '../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/common/Constants' + +export default { + async onCreate() { + console.info('SystemUI statusBar Application onCreate') + let configInfo = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_STATUS_BAR, 'config') + let statusBarData: StatusBarData = new StatusBarData(); + statusBarData.displayWidth = configInfo.maxWidth; + statusBarData.displayHeight = configInfo.maxHeight; + statusBarData.showHorizontal = configInfo.showHorizontal; + statusBarData.ableToMaximize = configInfo.ableToMaximize; + statusBarData.realWidth = configInfo.realWidth; + statusBarData.realHeight = configInfo.realHeight; + statusBarData.left = configInfo.xCoordinate; + statusBarData.top = configInfo.yCoordinate; + StatusBarVM.updateStatusBarData(statusBarData); + }, + onDestroy() { + console.info('SystemUI statusBar Application onDestroy') + }, +} diff --git a/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StatusbarConfig.ts b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StatusbarConfig.ts new file mode 100644 index 00000000..0dc0910a --- /dev/null +++ b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StatusbarConfig.ts @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {FASlotName} from '../../../../../../../../../common/src/main/ets/default/Constants'; + +type LayoutGroup = { + id: number; + Components: Array; +}; +type pluginIconData = { + id: string; + bundleName: string; + abilityName: string; +}; +type DropdownRange = { + startPosition: number; + endPosition: number; +}; +type Config = { + LayoutGroups: Array; + LocalSlots: Array; + MetaSlots: Array; + emptyPosition: { + x1: number; + x2: number; + y1: number; + y2: number + }; + dropdownRanges: { + notification: DropdownRange; + control: DropdownRange + } +}; + +const StatusbarConfig: Config = { + LayoutGroups: [ + { + id: 1, + Components: [ + FASlotName.SIGNAL, + FASlotName.WIFI, + FASlotName.CAPSULE, + FASlotName.NOTIFICATION, + ], + }, + { + id: 2, + Components: [], + }, + { + id: 3, + Components: [ + "testid", + FASlotName.LOCATION, + FASlotName.BLUETOOTH, + FASlotName.RING_MODE, + FASlotName.BATTERY, + FASlotName.CLOCK, + ], + }, + ], + LocalSlots: [ + FASlotName.BATTERY, + FASlotName.BLUETOOTH, + FASlotName.CAPSULE, + FASlotName.CLOCK, + FASlotName.LOCATION, + FASlotName.NOTIFICATION, + FASlotName.RING_MODE, + FASlotName.SIGNAL, + FASlotName.WIFI, + ], + MetaSlots: [ + { + id: "testid", + bundleName: "com.example.test_app_id", + abilityName: "com.example.test_app_id.MainAbility", + }, + ], + emptyPosition: { + x1: 0, + y1: 0, + x2: 0, + y2: 0, + }, + dropdownRanges: { + notification: { + startPosition: 0, + endPosition: 0.5 + }, + control: { + startPosition: 0.5, + endPosition: 1 + }, + } +}; + +export default StatusbarConfig; \ No newline at end of file diff --git a/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts new file mode 100644 index 00000000..9c7d17d3 --- /dev/null +++ b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleConfiguration.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import StyleManager from '../../../../../../../../../common/src/main/ets/default/StyleManager'; + +const TAG = 'StatusBar-StyleConfiguration'; + +export default class StyleConfiguration { + static getIndexStyle() { + const key: string = TAG + "-Index"; + return StyleManager.getStyle(key, () => { + return {}; + }); + } +} \ No newline at end of file diff --git a/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts new file mode 100644 index 00000000..9059434e --- /dev/null +++ b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/StyleManager.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../../common/src/main/ets/default/Log'; +import AbilityManager from '../../../../../../../../../common/src/main/ets/default/abilitymanager/abilityManager'; +import IndexStyleConfiguration from './StyleConfiguration' + +const TAG = 'StatusBar-StyleManager'; + +export default class StyleManager { + static STANDARD_DISPLAY_WIDTH: number = 720; + static STANDARD_DISPLAY_HEIGHT: number = 1280; + static maxWidth: number = StyleManager.STANDARD_DISPLAY_WIDTH; + + static setStyle() { + Log.showInfo(TAG, `setStyle`) + + let config = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_STATUS_BAR, 'config'); + StyleManager.maxWidth = config.maxWidth; + + // xxx + { + + } + + } + + static number2px(n: number): string { + return n.toString() + 'px'; + } + + static calcScaleSize(n: number): number { + return n * StyleManager.maxWidth / StyleManager.STANDARD_DISPLAY_WIDTH; + } + + static calcScaleSizePx(n: number): string { + return StyleManager.number2px(StyleManager.calcScaleSize(n)); + } +} \ No newline at end of file diff --git a/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/constants.ts b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/constants.ts new file mode 100644 index 00000000..16e20ce9 --- /dev/null +++ b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/common/constants.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class Constants { + static TOUCHTYPE_DOWN = 0; + static TOUCHTYPE_UP = 1; + static TOUCHTYPE_MOVE = 2; +} \ No newline at end of file diff --git a/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/index.ets b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/index.ets new file mode 100644 index 00000000..a4d80d68 --- /dev/null +++ b/product/phone/statusbar/src/main/ets/ServiceExtAbility/pages/index.ets @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Log from '../../../../../../../../common/src/main/ets/default/Log' +import WindowManager, {WindowType, WINDOW_SHOW_HIDE_EVENT +} from '../../../../../../../../common/src/main/ets/default/WindowManager' +import EventManager, {unsubscribe} from "../../../../../../../../common/src/main/ets/default/event/EventManager" +import {obtainLocalEvent} from "../../../../../../../../common/src/main/ets/default/event/EventUtil" +import CommonStyleManager from '../../../../../../../../common/src/main/ets/default/StyleManager' +import HeightConfigUtils from '../../../../../../../../common/src/main/ets/default/heightcofigUtils/HeightConfigUtils' +import StatusBarComponent from '../../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/pages/StatusBarComponent' +import StatusBarVM from '../../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/viewmodel/StatusBarVM' +import {StatusBarData} from '../../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/common/Constants' +import Constants from './common/constants' +import StyleManager from './common/StyleManager' +import StatusbarConfig from './common/StatusbarConfig' + +const TAG = 'StatusBar-Index' +const SLIDING_STATUS_BAR_DISTANCE = 30 + +let mHeightConfigUtils; + +@Entry +@Component +struct Index { + startX: number = 0 + startY: number = 0 + @State moveX: number = 0 + @State moveY: number = 0 + @State mStatusBarData: StatusBarData = StatusBarVM.getStatusBarData() + @StorageLink('StatusMinH') StatusMinH: number = 24 + @StorageLink('StatusCoefficient') StatusCoefficient: number = 1.0 + mClearCallback: unsubscribe | undefined + + onBackPress(): boolean { + return true; + } + + aboutToAppear() { + Log.showInfo(TAG, `aboutToAppear, start`); + + setAppBgColor('#00000000') + CommonStyleManager.setAbilityPageName(TAG) + StyleManager.setStyle() + + this.mClearCallback = EventManager.subscribe(WINDOW_SHOW_HIDE_EVENT, (args) => this.onWindowShowHideEvent(args)) + + mHeightConfigUtils = new HeightConfigUtils(); + let StatusMinH; + let StatusCoefficient; + + StatusMinH = AppStorage.SetAndLink("StatusMinH", 24); + StatusCoefficient = AppStorage.SetAndLink("StatusCoefficient", 1.0); + StatusMinH.set(mHeightConfigUtils.getStatusMinH()); + StatusCoefficient.set(mHeightConfigUtils.getStatusCoefficient()); + + let signalObserved = AppStorage.SetAndLink("signalObserved", false); + signalObserved.set(false); + + Log.showInfo(TAG, `aboutToAppear, end`); + } + + aboutToDisappear() { + Log.showInfo(TAG, `aboutToDisappear`); + this.mClearCallback && this.mClearCallback() + this.mClearCallback = undefined + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + StatusBarComponent({ + mStatusBarComponentConfig: StatusbarConfig + }) + } + .width('100%') + .height('100%') + .onTouch(this.touchEvent.bind(this)) + } + .width('100%') + .height('100%') + .constraintSize({ minHeight: this.StatusMinH + 'px' }) + .onAreaChange((e, e2) => { + Log.showInfo(TAG, `onAreaChange, e: ${JSON.stringify(e)} e2: ${JSON.stringify(e2)}`); + }) + } + + touchEvent(event: TouchEvent) { + Log.showInfo(TAG, 'touchEvent================' + event.touches) + if (event.type == Constants.TOUCHTYPE_DOWN) { //down + this.startX = event.touches[0].screenX + this.startY = event.touches[0].screenY + Log.showInfo(TAG, `touchStart=======startX: ${this.startX}, startY: ${this.startY}`) + } else if (event.type == Constants.TOUCHTYPE_MOVE) { //move + this.moveX = event.touches[0].screenX - this.startX + this.moveY = event.touches[0].screenY - this.startY + } else if (event.type == Constants.TOUCHTYPE_UP) { //up + Log.showInfo(TAG, `touchEnd, moveX: ${this.moveX}, moveY: ${this.moveY}`) + if (this.moveY > SLIDING_STATUS_BAR_DISTANCE) { + this.onDropdown(); + this.moveY = 0; + } + } + } + + onDropdown() { + Log.showInfo(TAG, `onDropdown`) + if (!this.mStatusBarData.showHorizontal || !this.mStatusBarData.ableToMaximize) { + return + } + let dropdownArea: string = null + if (this.checkDropdownShowStatus(StatusbarConfig.dropdownRanges.notification)) { + dropdownArea = 'left' + } else if (this.checkDropdownShowStatus(StatusbarConfig.dropdownRanges.control)) { + dropdownArea = 'right' + } + if (dropdownArea) { + EventManager.publish(obtainLocalEvent('DropdownEvent', { + dropdownArea: dropdownArea + })) + } + } + + checkDropdownShowStatus(range) { + let rangeStartX = this.mStatusBarData.realWidth * range.startPosition + this.mStatusBarData.left + let rangeEndX = this.mStatusBarData.realWidth * range.endPosition + this.mStatusBarData.left + return (vp2px(this.startX) >= rangeStartX) && (vp2px(this.startX) <= rangeEndX) + } + + onWindowShowHideEvent(args) { + Log.showInfo(TAG, `onWindowShowHideEvent, args: ${JSON.stringify(args)}`) + if (args.windowName == WindowType.DROPDOWN_PANEL) { + if (args.isShow) { + WindowManager.hideWindow(WindowType.STATUS_BAR) + } else { + StatusBarVM.setUseInWindowName(WindowType.STATUS_BAR) + WindowManager.showWindow(WindowType.STATUS_BAR) + } + } + } +} diff --git a/product/phone/statusbar/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js b/product/phone/statusbar/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js new file mode 100644 index 00000000..3135d74c --- /dev/null +++ b/product/phone/statusbar/src/main/ets/ServiceExtAbility/workers/PluginDataSourceWorker.js @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from "@ohos.worker"; +import Log from "../../../../../../../../common/src/main/ets/default/Log"; +import PluginDataSourceManager +from "../../../../../../../../common/src/main/ets/plugindatasource/PluginDataSourceManager"; +import Constants, { obtainMsg } from "../../../../../../../../common/src/main/ets/plugindatasource/common/Constants"; + +const parentPort = worker.parentPort; +const TAG = `${parentPort.name} Worker`; +Log.showInfo(TAG, `Start.`); + +var sManager; + +parentPort.onmessage = (msg) => { + Log.showInfo(TAG, `onMessage, msg = ${JSON.stringify(msg)}`); + let data = msg.data; + switch (data.action) { + case Constants.INIT_CONFIG: + initConfig(data.data); + break; + case Constants.CLEAR_ALL: + clearAll(); + break; + case Constants.LOAD_DATA: + loadData(data.data); + break; + default: + Log.showError(TAG, `onMessage, unknown action type.`); + } +}; + +function initConfig(config) { + Log.showInfo(TAG, `initConfig, config = ${JSON.stringify(config)}`); + sManager = new PluginDataSourceManager({ + onItemAdd: (itemData) => { + Log.showInfo(TAG, `sManager.onItemAdd, itemData = ${JSON.stringify(itemData)}`); + itemData.label && (itemData.label = encodeURIComponent(itemData.label)); + parentPort.postMessage(obtainMsg(Constants.ADD_ITEM, itemData)); + }, + onItemRemove: (itemData) => { + Log.showInfo(TAG, `sManager.onItemRemove, itemData = ${JSON.stringify(itemData)}`); + parentPort.postMessage(obtainMsg(Constants.REMOVE_ITEM, itemData)); + }, + }); + sManager.initDataSource(config); + parentPort.postMessage(obtainMsg(Constants.INIT_FINISH, {})); +} + +function clearAll() { + Log.showInfo(TAG, `clearAll `); + sManager?.clearAll(); +} + +function loadData(userId) { + Log.showInfo(TAG, `loadData `); + sManager?.loadData(userId); +} + +parentPort.onclose = function () { + Log.showInfo(TAG, `onclose`); +}; + +parentPort.onmessageerror = function () { + Log.showInfo(TAG, `onmessageerror`); +}; + +parentPort.onerror = function (data) { + Log.showInfo( + TAG, + `onerror, lineno = ${data.lineno}, msg = ${data.message}, filename = ${data.filename}, col = ${data.colno}` + ); +}; \ No newline at end of file diff --git a/product/phone/statusbar/src/main/resources/base/element/color.json b/product/phone/statusbar/src/main/resources/base/element/color.json new file mode 100644 index 00000000..6b163c9d --- /dev/null +++ b/product/phone/statusbar/src/main/resources/base/element/color.json @@ -0,0 +1,12 @@ +{ + "color": [ + { + "name": "default_background", + "value": "#66000000" + }, + { + "name": "default_font_color", + "value": "#ffffffff" + } + ] +} \ No newline at end of file diff --git a/product/phone/statusbar/src/main/resources/base/element/string.json b/product/phone/statusbar/src/main/resources/base/element/string.json new file mode 100644 index 00000000..6857b5fe --- /dev/null +++ b/product/phone/statusbar/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "status_bar_size_portrait", + "value": "48" + }, + { + "name": "status_bar_size_landscape", + "value": "48" + }, + { + "name": "status_bar_position_portrait", + "value": "1" + }, + { + "name": "status_bar_position_landscape", + "value": "2" + }, + { + "name": "app_name", + "value": "SystemUI" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/product/phone/statusbar/src/main/resources/base/media/icon.png b/product/phone/statusbar/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R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n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y{}); - } - } - } -} - -@Component -struct statusBar { - private minHeight: number - @StorageLink('StatusCoefficient') StatusCoefficient:number = 1.0 - build() { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { - SignalIcon() - WifiIcon() - } - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.End }) { - LocationIcon() - BluetoothIcon() - RingModeIcon() - BatteryIcon() - ClockIcon() - } - } - .width('100%') - .height(this.minHeight + 'px') - } -} diff --git a/product/statusbar/src/main/ets/default/pages/index.ets b/product/statusbar/src/main/ets/default/pages/index.ets deleted file mode 100644 index 4ac78b95..00000000 --- a/product/statusbar/src/main/ets/default/pages/index.ets +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Log from '../../../../../../../common/src/main/ets/default/Log.ets' -import ReadConfigUtil from '../../../../../../../common/src/main/ets/default/ReadConfigUtil.ets' -import Notification from './notification.ets' -import ControlCenterComponent from './control.ets' -import Constants from './common/constants.ets' -import NavigationEvent from './common/navigationEvent.ets' -import mBrightnessManager from '../../../../../../../features/brightnesscomponent/src/main/ets/default/brightnessManager.ets'; -import HeightConfigUtils from '../../../../../../../common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ets'; -import StatusBarComponent from '../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/pages/StatusBarComponent.ets'; -import WindowManager from '../../../../../../../common/src/main/ets/default/WindowManager.ets'; -import Window from '@ohos.window'; - -const STATUS_BAR_COMPONENT_CONFIG_FILE_PATH = "/data/accounts/account_0/applications/com.ohos.systemui/" + -"com.ohos.systemui.statusbar/assets/statusbar/resources/rawfile/statusbarcomponentConfig.json"; - -const CONTROL_CENTER_COMPONENT_CONFIG_FILE_PATH = "/data/accounts/account_0/applications/com.ohos.systemui/" + -"com.ohos.systemui.statusbar/assets/statusbar/resources/rawfile/controlcentercomponentConfig.json"; - -const TAG = 'StatusBar-Index' - -let mWindowManager; -let mHeightConfigUtils; - -@Entry -@Component -struct Index { - startX: number = 0 - startY: number = 0 - @State moveX: number = 0 - @State moveY: number = 0 - @StorageLink("showStatusBar") showStatusBar: boolean = true - @StorageLink("showHorizontal") showHorizontal: boolean = true - @StorageLink("ableToMaximize") ableToMaximize: boolean = true - @StorageLink('minHeight') minHeight: number = 0 - @StorageLink('maxWidth') maxWidth: number = 0 - @StorageLink('StatusMinH') StatusMinH: number = 24 - @StorageLink('StatusCoefficient') StatusCoefficient: number = 1.0 - @State statusBarComponentConfig: any = {}; - @State controlCenterComponentConfig: any = {}; - mCallback: any; - - onBackPress(): boolean { - return true; - } - - aboutToAppear() { - Log.showInfo(TAG, `aboutToAppear, start showStatusBar: ${this.showStatusBar}`); - mHeightConfigUtils = new HeightConfigUtils(); - let StatusMinH; - let StatusCoefficient; - - StatusMinH = AppStorage.SetAndLink("StatusMinH", 24); - StatusCoefficient = AppStorage.SetAndLink("StatusCoefficient", 1.0); - StatusMinH.set(mHeightConfigUtils.getStatusMinH()); - StatusCoefficient.set(mHeightConfigUtils.getStatusCoefficient()); - - { - let configData = ReadConfigUtil.ReadConfigFile(STATUS_BAR_COMPONENT_CONFIG_FILE_PATH); - for (let key in configData) { - this.statusBarComponentConfig[key] = configData[key]; - } - } - { - let controlCenterConfigData = ReadConfigUtil.ReadConfigFile(CONTROL_CENTER_COMPONENT_CONFIG_FILE_PATH); - for (let key in controlCenterConfigData) { - this.controlCenterComponentConfig[key] = controlCenterConfigData[key]; - } - } - - let signalObserved = AppStorage.SetAndLink("signalObserved", false); - signalObserved.set(false); - - mWindowManager = new WindowManager(); - mWindowManager.initWindowManager(); - this.mCallback = { - "onStateChange": this.onStateChange.bind(this) - } - NavigationEvent.registerCallback(this.mCallback); - Log.showInfo(TAG, `aboutToAppear, end showStatusBar: ${this.showStatusBar}`); - } - - onStateChange(data) { - if (this.ableToMaximize && !this.showStatusBar) { - this.showStatusBar = true; - mWindowManager.setWindowMin((result) => { - }) - } - } - - aboutToDisappear() { - Log.showInfo(TAG, `aboutToDisappear, showStatusBar: ${this.showStatusBar}`); - } - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - if (this.showStatusBar) { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - StatusBarComponent({ - mStatusBarComponentConfig: this.statusBarComponentConfig, - mStatusBarColor: '#ffffffff' - }) - } - .width('100%') - .height('100%') - .backgroundColor($r("app.color.statusbar_background")) - .onTouch(this.touchEvent.bind(this)) - } else if (this.showHorizontal && this.ableToMaximize) { - if (vp2px(this.startX) <= parseInt((this.maxWidth / 2).toString())) { - Notification({ showStatusBar: $showStatusBar, minHeight: this.minHeight }) - } else { - ControlCenterComponent({ - showStatusBar: $showStatusBar, - minHeight: this.minHeight, - mControlCenterComponentConfig: this.controlCenterComponentConfig - }) - } - } - } - .width('100%') - .height('100%') - .constraintSize({ minHeight: this.StatusMinH + 'px'}) - } - - touchEvent(event: TouchEvent) { - Log.showInfo(TAG, 'touchEvent================' + event.touches) - if (!this.showHorizontal && !this.ableToMaximize) { - return; - } - if (event.type == Constants.TOUCHTYPE_DOWN) { //down - this.startX = event.touches[0].screenX - this.startY = event.touches[0].screenY - Log.showInfo(TAG, `touchStart=======startX: ${this.startX}, startY: ${this.startY}`) - } else if (event.type == Constants.TOUCHTYPE_MOVE) { //move - this.moveX = event.touches[0].screenX - this.startX - this.moveY = event.touches[0].screenY - this.startY - } else if (event.type == Constants.TOUCHTYPE_UP) { //up - Log.showInfo(TAG, `touchEnd, moveX: ${this.moveX}, moveY: ${this.moveY}`) - if (this.moveY > 10) { - this.showStatusBar = false; - mWindowManager.setWindowMax((result) => { - }); - } - } - } -} diff --git a/product/statusbar/src/main/ets/default/pages/notification.ets b/product/statusbar/src/main/ets/default/pages/notification.ets deleted file mode 100644 index adf5094b..00000000 --- a/product/statusbar/src/main/ets/default/pages/notification.ets +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Log from '../../../../../../../common/src/main/ets/default/Log.ets' -import Constants from './common/constants.ets' -import FeatureAbilityManager from '../../../../../../../common/src/main/ets/default/abilitymanager/featureAbilityManager.ets' -import BatteryIcon from '../../../../../../../features/batterycomponent/src/main/ets/default/pages/batteryIcon.ets' -import ClockIcon from '../../../../../../../features/clockcomponent/src/main/ets/default/pages/clockIcon.ets' -import WifiIcon from '../../../../../../../features/wificomponent/src/main/ets/default/pages/wifiIcon.ets' -import BluetoothIcon from '../../../../../../../features/bluetoothcomponent/src/main/ets/com/ohos/pages/StatusBarIconItemBluetoothComponent.ets' -import SignalIcon from '../../../../../../../features/signalcomponent/src/main/ets/default/pages/signalIcon.ets' -import LocationIcon from '../../../../../../../features/locationcomponent/src/main/ets/com/ohos/pages/StatusBarIconItemLocationComponent.ets' -import RingModeIcon from '../../../../../../../features/ringmodecomponent/src/main/ets/com/ohos/pages/StatusBarIconItemRingModeComponent.ets' -import NotificationListComponent from '../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/view/NotificationListComponent.ets' -import WindowManager from '../../../../../../../common/src/main/ets/default/WindowManager.ets' -import ViewModel from '../../../../../../../features/noticeitem/src/main/ets/com/ohos/noticeItem/viewmodel/ViewModel.ets' - -const TAG = 'StatusBar-notification' - -let mWindowManager; -let mFeatureAbilityManager; - -@Component -export default -struct Notification { - @Link showStatusBar: boolean - private minHeight: number - startX: number = 0 - startY: number = 0 - @State moveX: number = 0 - @State moveY: number = 0 - @StorageLink('notificationList') notificationList: any[] = [] - - - aboutToAppear() { - mWindowManager = new WindowManager(); - mFeatureAbilityManager = new FeatureAbilityManager(); - Log.showInfo(TAG, `aboutToAppear Start`) - } - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { - statusBar({minHeight:this.minHeight}) - quicklySetting({ showStatusBar: $showStatusBar}) - Stack({ alignContent: Alignment.TopStart }) { - NotificationListComponent() - if (this.notificationList.length > 0) { - Image($r('app.media.delete_all')) //icon: remove all notifications - .objectFit(ImageFit.Contain) - .width($r('app.float.deleteall_image_width')) - .height($r('app.float.deleteall_image_height')) - .borderRadius($r('app.float.deleteall_image_borderradius')) - .opacity($r('app.float.deleteall_image_opacity')) - .onClick(() => { - ViewModel.removeAllNotifications(); - }) - .position({ x: '44.5%', y: '85%' }) - } - } - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.default_background')) - .onTouch(this.touchEvent.bind(this)) - } - - touchEvent(event: TouchEvent) { - if (event.type == Constants.TOUCHTYPE_DOWN) { - this.startX = event.touches[0].screenX - this.startY = event.touches[0].screenY - Log.showInfo(TAG, `touchStart2=======startX: ${this.startX}, startY: ${this.startY}`) - } else if (event.type == Constants.TOUCHTYPE_MOVE) { - this.moveX = event.touches[0].screenX - this.startX - this.moveY = event.touches[0].screenY - this.startY - } else if (event.type == Constants.TOUCHTYPE_UP) { - Log.showInfo(TAG, `touchEnd2, moveX: ${this.moveX}, moveY: ${this.moveY}`) - if (this.moveY < -30) { - this.showStatusBar = true; - mWindowManager.setWindowMin((result)=>{ - - }) - } - } - } -} - -@Component -struct statusBar { - private minHeight: number - @StorageLink('StatusCoefficient') StatusCoefficient:number = 1.0 - - build() { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { - SignalIcon() - WifiIcon() - } - - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.End }) { - LocationIcon() - BluetoothIcon() - RingModeIcon() - BatteryIcon() - ClockIcon() - } - } - .width('100%') - .height(this.minHeight + 'px') - } -} - -@Component -struct quicklySetting { - @Link showStatusBar: boolean - @StorageLink('time') mTime: string = '01:01' - @StorageLink('month') mMonth: number = 1 - @StorageLink('day') mDay: number = 1 - @StorageLink('weekDay') mWeekDay: number = 1 - @State showDay: string = 'day' - @State showMonth: string = 'month' - @State showWeekDay: any = 'weekday' - - aboutToAppear() { - Log.showInfo(TAG, `quicklySetting, aboutToAppear`) - //show month - this.showMonth = this.alignmentNumber(this.mMonth); - //show day - this.showDay = this.alignmentNumber(this.mDay); - //show weekDay - this.showWeekDay = Constants.WEEKDAY_LIST[this.mWeekDay-1]; - } - - aboutToDisappear() { - Log.showInfo(TAG, `quicklySetting, aboutToDisappear, showStatusBar: ${this.showStatusBar}`) - } - - build() { - Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Start }) { - Text(this.mTime) - .fontColor($r('app.color.quicklysetting_time_fontcolor')) - .fontSize($r('app.float.quicklysetting_time_fontsize')) - Flex({direction: FlexDirection.Row, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center}){ - dateItem({number: this.showMonth, unit: Constants.MARK_MONTH}) - dateItem({number: this.showDay, unit: Constants.MARK_DAY}) - Text(this.showWeekDay) - .fontColor($r('app.color.quicklysetting_date_fontcolor')) - .fontSize($r('app.float.quicklysetting_date_fontsize')) - } - } - .width('50%') - .height('100%') - .margin({ left: $r('app.float.quicklysetting_textflex_marginleft') }) - - Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.End }) { - Image($r('app.media.ic_settings')) - .objectFit(ImageFit.Contain) - .onClick(this.settingClick.bind(this)) - } - .width($r('app.float.quicklysetting_image_width')) - .height($r('app.float.quicklysetting_image_height')) - .margin({ right: $r('app.float.quicklysetting_image_marginright') }) - - } - .width('100%') - .height(Constants.QUICKLY_SETTING_H) - .borderRadius($r('app.float.quicklysetting_borderradius')) - .margin({ left: $r('app.float.quicklysetting_marginleft'), right: $r('app.float.quicklysetting_marginright') }) - } - - settingClick() { - Log.showInfo(TAG,` settingClick `) - this.showStatusBar = true; - mWindowManager.setWindowMin((result)=>{ - mFeatureAbilityManager.openAbility(TAG, { - want: { - bundleName: 'com.ohos.settings', - abilityName: 'com.ohos.settings.MainAbility' - } - }); - }); - } - alignmentNumber(timeOrDate){ - if(timeOrDate < Constants.DIGITS){ - return '0' + timeOrDate - }else{ - return '' + timeOrDate - } - } -} - -@Component -struct dateItem { - - @Prop number: string - @Prop unit: number - - build() { - Row() { - Text(this.number) - .fontColor($r('app.color.quicklysetting_date_fontcolor')) - .fontSize($r('app.float.quicklysetting_date_fontsize')) - if (this.unit == Constants.MARK_MONTH) { - Text($r('app.string.month')) - .fontColor($r('app.color.quicklysetting_date_fontcolor')) - .fontSize($r('app.float.quicklysetting_date_fontsize')) - } - if (this.unit == Constants.MARK_DAY) { - Text($r('app.string.day')) - .fontColor($r('app.color.quicklysetting_date_fontcolor')) - .fontSize($r('app.float.quicklysetting_date_fontsize')) - } - } - } -} diff --git a/product/statusbar/src/main/resources/base/element/color.json b/product/statusbar/src/main/resources/base/element/color.json deleted file mode 100644 index c3036068..00000000 --- a/product/statusbar/src/main/resources/base/element/color.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "color": [ - { - "name": "default_background", - "value": "#66000000" - }, - { - "name": "default_font_color", - "value": "#ffffffff" - }, - { - "name": "index_background", - "value": "#66000000" - }, - { - "name": "statusbar_background", - "value": "#66000000" - }, - { - "name": "quicklysetting_time_fontcolor", - "value": "#ffffffff" - }, - { - "name": "quicklysetting_date_fontcolor", - "value": "#ffffffff" - }, - { - "name": "quicklysetting_background", - "value": "#292830" - }, - { - "name": "twogroup_layout_background", - "value": "#66000000" - } - ] -} \ No newline at end of file diff --git a/product/statusbar/src/main/resources/base/element/float.json b/product/statusbar/src/main/resources/base/element/float.json deleted file mode 100644 index 49f9e8db..00000000 --- a/product/statusbar/src/main/resources/base/element/float.json +++ /dev/null @@ -1,68 +0,0 @@ - { - "float": [ - { - "name": "statusbar_height", - "value": "67" - }, - { - "name": "quicklysetting_time_fontsize", - "value": "30" - }, - { - "name": "quicklysetting_date_fontsize", - "value": "20" - }, - { - "name": "quicklysetting_textflex_marginleft", - "value": "10" - }, - { - "name": "quicklysetting_image_width", - "value": "50" - }, - { - "name": "quicklysetting_image_height", - "value": "50" - }, - { - "name": "quicklysetting_image_marginright", - "value": "10" - }, - { - "name": "quicklysetting_height", - "value": "120" - }, - { - "name": "quicklysetting_borderradius", - "value": "20" - }, - { - "name": "quicklysetting_marginleft", - "value": "10" - }, - { - "name": "quicklysetting_marginright", - "value": "10" - }, - { - "name": "deleteall_image_width", - "value": "50" - }, - { - "name": "deleteall_image_height", - "value": "50" - }, - { - "name": "deleteall_image_borderradius", - "value": "25" - }, - { - "name": "default_left_width_small", - "value": "230" - }, - { - "name": "default_left_width_large", - "value": "300" - } - ] -} \ No newline at end of file diff --git a/product/statusbar/src/main/resources/base/media/airplane.svg b/product/statusbar/src/main/resources/base/media/airplane.svg deleted file mode 100644 index d648b9f9..00000000 --- a/product/statusbar/src/main/resources/base/media/airplane.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/product/statusbar/src/main/resources/base/media/airplane_d.svg b/product/statusbar/src/main/resources/base/media/airplane_d.svg deleted file mode 100644 index ad2180b1..00000000 --- a/product/statusbar/src/main/resources/base/media/airplane_d.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/product/statusbar/src/main/resources/base/media/wifi.svg b/product/statusbar/src/main/resources/base/media/wifi.svg deleted file mode 100644 index e22c8330..00000000 --- a/product/statusbar/src/main/resources/base/media/wifi.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - ic_notification_wlan - Created with Sketch. - - - - - - - - - - - - \ No newline at end of file diff --git a/product/statusbar/src/main/resources/base/media/wifi_d.svg b/product/statusbar/src/main/resources/base/media/wifi_d.svg deleted file mode 100644 index e851f5b3..00000000 --- a/product/statusbar/src/main/resources/base/media/wifi_d.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - ic_notification_wlan - Created with Sketch. - - - - - - - - - - - - \ No newline at end of file diff --git a/product/statusbar/src/main/resources/rawfile/controlcentercomponentConfig.json b/product/statusbar/src/main/resources/rawfile/controlcentercomponentConfig.json deleted file mode 100644 index bef77a0f..00000000 --- a/product/statusbar/src/main/resources/rawfile/controlcentercomponentConfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "ComplexToggleLayout": [ - "wifi", - "bluetooth" - ], - "TempDBSimpleToggleLayout": [ - "ring_mode", - "location", - "testid" - ], - "LocalToggles": [ - "wifi", - "bluetooth", - "air_plane", - "location", - "ring_mode" - ], - "MetaToggles": [ - { - "id": "testid", - "abilityName": "" - } - ] -} \ No newline at end of file diff --git a/product/statusbar/src/main/resources/rawfile/statusbarcomponentConfig.json b/product/statusbar/src/main/resources/rawfile/statusbarcomponentConfig.json deleted file mode 100644 index e76d8f80..00000000 --- a/product/statusbar/src/main/resources/rawfile/statusbarcomponentConfig.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "LayoutGroups": [ - { - "id": 1, - "Components": [ - "signal", - "wifi", - "capsule", - "notification" - ] - }, - { - "id": 2, - "Components": [] - }, - { - "id": 3, - "Components": [ - "location", - "bluetooth", - "ring_mode", - "battery", - "clock" - ] - } - ], - "metaIconKeys": [ - ], - "LocalSlots": [ - "clock", - "battery", - "signal", - "wifi", - "bluetooth", - "capsule", - "notification", - "location", - "ring_mode" - ], - "emptyPosition": { - "x1": 0, - "y1": 0, - "x2": 0, - "y2": 0 - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 57b50528..c7d80338 100755 --- a/settings.gradle +++ b/settings.gradle @@ -13,9 +13,22 @@ * limitations under the License. */ -include ':entry', ':product:navigationBar', ':common', ':product:statusbar', ':product:notificationmanagement', +include ':common', + ':phone_entry', ':phone_statusbar', ':phone_dropdownpanel', + ':pc_entry', ':pc_statusbar', ':pc_controlpanel', ':pc_notificationpanel', + ':default_navigationBar', ':default_notificationmanagement', ':default_volumepanel', ':features:capsulecomponent', ':features:batterycomponent', ':features:clockcomponent', ':features:signalcomponent', ':features:wificomponent', ':features:navigationservice', ':features:noticeitem', ':features:airplanecomponent', ':features:brightnesscomponent', ':features:volumecomponent', ':features:managementcomponent', ':features:statusbarcomponent', ':features:controlcentercomponent', ':features:bluetoothcomponent', ':features:locationcomponent', - ':features:ringmodecomponent' \ No newline at end of file + ':features:ringmodecomponent', ':features:volumepanelcomponent', ':features:autorotatecomponent' +project(':phone_entry').projectDir = new File('./entry/phone') +project(':phone_statusbar').projectDir = new File('./product/phone/statusbar') +project(':phone_dropdownpanel').projectDir = new File('./product/phone/dropdownpanel') +project(':pc_entry').projectDir = new File('./entry/pc') +project(':pc_statusbar').projectDir = new File('./product/pc/statusbar') +project(':pc_controlpanel').projectDir = new File('./product/pc/controlpanel') +project(':pc_notificationpanel').projectDir = new File('./product/pc/notificationpanel') +project(':default_navigationBar').projectDir = new File('./product/default/navigationBar') +project(':default_notificationmanagement').projectDir = new File('./product/default/notificationmanagement') +project(':default_volumepanel').projectDir = new File('./product/default/volumepanel') \ No newline at end of file diff --git a/signature/systemui.p7b b/signature/systemui.p7b index cf9fe423ed88490ddb7b204079128f4809a7ca6b..7a68d3ce4b72d244c2e68b8348286bb6f5fbf667 100644 GIT binary patch delta 426 zcmcaB^+u}RpouqwjZ>@5qwPB{BRkWACf-P(P$&~4qam*WHydX{n+IbmGYb==K@%${ zLLuXVCYE0;O)TH4mC90!iZk=`bd&Q_QkAR>b>ISdiMc=lB||*}Jp&~jrP9*O6d>2s zz{otw(lS-oGz~~hTqVh0Qds~}SCpEQnpm8wG%-ti;$cZeQ%e&IGgBi|3mv7r{1V;7 zw35^!pz&rFmL}%LK;hcSe2fa*{spOd9*IS{`FWL_tr9B8w+GtD`{^qwQpQoCjrCO)Dpy`0>Mli;V*qnCEO+ zn3-7I4P2QNN^AULDz_voDo^~oIAdLTc}-@5qwPB{BRkWACSEU~kQ);tqanWmFB@kVK9r4|)u=I80=CFZ6oSt%Ln8R!`(>A;1P^HYGrhB``#1qHe( znZ+eVnMtK3APpsz6ZeQs%+i~9Nz%y7(9+n%(#X(KM=3AAL^m<5B((^r3n*xA01~d% zQ7Wk{0GVHunvZdz($Nof&CZT{wm zES~JFP6kbkc9Zpa3i(jIGUdMx8B+j z`}_71W8ttwmv2vgO0k)(ec|5s&}ZxZ>3s%VY#hMQJ7>$n%*5hm;KHQ98Bo}-ZX4|p zu915+o@<@BOa82iWPby_^