From: SnickerSun Date: Sat, 6 Apr 2024 15:27:14 +0000 (+0800) Subject: 602SDK patch 2024-4-3 X-Git-Tag: release_V1.2.70_20241020_135402~1231 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=425aad9368d710784c347400165cfece5766ea19;p=mirrors%2FFD230.git 602SDK patch 2024-4-3 --- diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp index 2da2024b1..20e64c64b 100755 --- a/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp +++ b/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp @@ -20,7 +20,7 @@ namespace OHOS { void Ability::AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability::AddSliceProxy sliceId = %d", sliceId); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability::AddSliceProxy sliceId = %d", sliceId); if (sliceId <= gSliceInvalid || proxy == nullptr) { return; } @@ -35,7 +35,7 @@ void Ability::AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy) void Ability::StartSlice(const uint16_t sliceId, const uint16_t priority) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability::StartSlice sliceId = %d", sliceId); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability::StartSlice sliceId = %d", sliceId); if (sliceId <= gSliceInvalid) { return; } @@ -50,7 +50,7 @@ void Ability::StartSlice(const uint16_t sliceId, const uint16_t priority) return; } - WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability::StartSlice Size = %d", allSlices_.size()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability::StartSlice Size = %d", allSlices_.size()); // 记录最多gMaxHistorySlices个页面id if (allSlices_.size() == gMaxHistorySlices) { allSlices_.erase(allSlices_.begin()); @@ -65,8 +65,9 @@ void Ability::StartSlice(const uint16_t sliceId, const uint16_t priority) nextSlice->OnResume(); } -void Ability::ReleaseCurSlice() { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability::ReleaseCurSlice"); +void Ability::ReleaseCurSlice() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability::ReleaseCurSlice"); if (curSlice_.slice != nullptr) { curSlice_.sliceId = gSliceInvalid; delete curSlice_.slice; diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/SliceTransition.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/SliceTransition.cpp index ee2c3482c..540c39fe0 100755 --- a/code/sdk/application/wearable/nativeabilityfwk/src/SliceTransition.cpp +++ b/code/sdk/application/wearable/nativeabilityfwk/src/SliceTransition.cpp @@ -92,7 +92,7 @@ ImageInfo SliceTransition::RectifySnapshot(ImageInfo& srcInfo) if (Screen::GetInstance().GetScreenShape() == CIRCLE) { int16_t radius = Screen::GetInstance().GetWidth() / 2; // 2: half of width/height ImageInfo dstInfo = {{0}}; - dstInfo = ClipImg::ClipImgByCircle(srcInfo, nullptr, { radius, radius }, radius, ARGB8888); + dstInfo = ClipImg::ClipImgByCircle(srcInfo, { radius, radius }, radius, ARGB8888, true); if (dstInfo.data == nullptr) { return srcInfo; } else { diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index ad92a899a..15f8c8f22 100755 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -29,6 +29,10 @@ set(PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/temperature/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/offlinevoice/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/settings/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_desktop/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_dial/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/key/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/player/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/applist/include @@ -52,7 +56,6 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/innerkits - ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include/components ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/events ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits @@ -82,6 +85,8 @@ set(PRIVATE_HEADER ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audiomanager/interfaces/kits/audiocommon ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/player/interfaces/kits/ ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/utils/include + ${ROOT_DIR}/open_source/openharmony/utils/native/lite/include + ${ROOT_DIR}/open_source/openharmony/utils/native/lite/kv_store/innerkits ) set(SOURCES @@ -89,6 +94,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/src/slices/main/MainPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/src/slices/main/MainView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/MainViewSample.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/MainModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/MainPresenterSample.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/ModelListenerSample.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/PresenterTask.cpp @@ -203,6 +209,24 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/settings/src/SettingView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/settings/src/SettingModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/settings/src/SettingItemView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_desktop/src/SetDesktopModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_desktop/src/SetDesktopPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_desktop/src/SetDesktopView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardAdapter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardItem.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardNoCardView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardDeleteView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardAdapter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardItem.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_dial/src/SetDialModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_dial/src/SetDialPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_dial/src/SetDialView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/key/src/KeyInputListener.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassControlView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassCalibrationView.cpp @@ -241,6 +265,9 @@ set(SOURCES ${UI_SAMPLE_ROOT}/components/ui_test_cube_rotate/cube_rotate_view.cpp ${UI_SAMPLE_ROOT}/components/ui_test_cube_rotate/ui_test_cube_rotate.cpp ${UI_SAMPLE_ROOT}/components/ui_test_video_play/ui_test_video_play.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_hexagons_list/ui_test_hexagons_list.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_coverflow/ui_test_coverflow.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_kaleidoscope/ui_test_kaleidoscope.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialRotateImgView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialOptionImgView.cpp diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h index 79e8581cf..1c77878c0 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h @@ -1,4 +1,3 @@ - /* * Copyright (c) 2020-2021 CompanyNameMagicTag. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -49,6 +48,10 @@ typedef enum : uint16_t { #ifdef SUPPORT_ALIPAY_SEC VIEW_MAIN_ALIPAY, #endif + VIEW_SET_DESKTOP, + VIEW_SET_CARD, + VIEW_ADD_CARD, + VIEW_SET_DIAL, VIEW_MAX_INTER_APP, // 在此之前添加native应用ID. VIEW_EXTERN_APP = 0xFFFE, // 三方应用 VIEW_INVALIDE_APP = 0xFFFF, diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h index c34e4a907..cadd1ee31 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h @@ -1,4 +1,3 @@ - /* * Copyright (c) 2020-2021 CompanyNameMagicTag. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +16,6 @@ #ifndef NATIVE_LAUNCHER_H #define NATIVE_LAUNCHER_H #include "AppViewIDs.h" -#include "components/ui_label_ext.h" namespace OHOS { class NativeLauncher { @@ -45,6 +43,10 @@ public: void InitRebootSlice(void); void InitUISampleSlice(void); void InitMainAlipaySlice(void); + void InitSetDesktopSlice(void); + void InitSetCardSlice(void); + void InitAddCardSlice(void); + void InitSetDialSlice(void); private: void InitAllNativeSlices(void); diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h index 153407a5c..7f1935264 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h @@ -13,6 +13,21 @@ #include "graphic_config.h" namespace OHOS { + static const int CARD_SETTING_COUNT_MAX = 5; + typedef enum { + WATCH_FACE = 0, /* 主表盘枚举值不能修改 */ + HEART_RATE, + COMPASS, + ACTIVITY, + MUSIC_PLAYER, + MAX_CARD, + } CardId; + + typedef enum { + DIAL_CLOCK = 0, + DIAL_MAX, + } DialId; + #ifndef UNUSED #define UNUSED(x) ((void)(x)) #endif @@ -38,6 +53,7 @@ namespace OHOS { #define APP_RES_PATH "/user/res" #define APP_MUSIC_PATH "/user/music" #define APP_VIDEO_PATH "/user/video" + #define APP_DIAL_PATH "/user/dial" static constexpr const char *CARD_CONFIG_PATH = "/user/cardconfig.bin"; @@ -139,6 +155,10 @@ namespace OHOS { static constexpr const char *PNG_SHUTDOWN_BUTTON_IMAGE = APP_RES_PATH"/SHUTDOWN_BUTTON.bin"; static constexpr const char *PNG_SETTTING_REBOOT_IMAGE = APP_RES_PATH"/SETTTING_REBOOT.bin"; static constexpr const char *PNG_SETTTING_SHUTDOWN_IMAGE = APP_RES_PATH"/SETTTING_SHUTDOWN.bin"; + static constexpr const char *PNG_SETTTING_DESKTOP_IMAGE = APP_RES_PATH"/SETTTING_DESKTOP.bin"; + static constexpr const char *PNG_SET_DESKTOP_LIST_IMAGE = APP_RES_PATH"/SET_DESKTOP_LIST.bin"; + static constexpr const char *PNG_SET_DESKTOP_HEXAGONS_IMAGE = APP_RES_PATH"/SET_DESKTOP_HEXAGONS.bin"; + static constexpr const char *PNG_SET_DESKTOP_BG_IMAGE = APP_RES_PATH"/SET_DESKTOP_BG.bin"; static constexpr const char *PNG_CONNECT_PHONE_IMAGE = APP_RES_PATH"/CONNECT_PHONE.bin"; static constexpr const char *PNG_BLUETOOTH_STITLE = APP_RES_PATH"/BLUETOOTH_TITLE.bin"; @@ -300,7 +320,7 @@ namespace OHOS { static constexpr const char *PNG_APPLIST_SETTING_IMAGE = APP_RES_PATH"/APPLIST_SETTING.bin"; // 设置 static constexpr const char *PNG_APPLIST_TEMP_IMAGE = APP_RES_PATH"/TEMP_IMAGE.bin"; // 体温 - static constexpr const char *PNG_APPLIST_ALIPAY_IMAGE = APP_RES_PATH"/alipay/alipay_logo.bin"; // 支付宝 + static constexpr const char *PNG_APPLIST_ALIPAY_IMAGE = APP_RES_PATH"/alipay_logo.bin"; // 支付宝 static constexpr const char *PNG_ALIPAY_BIND_FAILURE = APP_RES_PATH"/ALIPAY_BIND_FAILURE.bin"; static constexpr const char *PNG_ALIPAY_BIND_SUCCESS = APP_RES_PATH"/ALIPAY_BIND_SUCCESS.bin"; static constexpr const char *PNG_ALIPAY_LIST_PAY = APP_RES_PATH"/ALIPAY_LIST_PAY.bin"; @@ -328,6 +348,15 @@ namespace OHOS { static constexpr const char *PNG_WALK_STEPS_IMAGE = APP_RES_PATH"/STEPS_IMAGE.bin"; static constexpr const char *PNG_APPLIST_UI_SAMPLE_IMAGE = APP_RES_PATH"/APPLIST_UI_SAMPLE.bin"; // Applist图标 + + static constexpr const char *PNG_SET_CARD_ADD = APP_RES_PATH"/CARD_ADD.bin"; + static constexpr const char *PNG_SET_CARD_DEL = APP_RES_PATH"/CARD_DEL.bin"; + static constexpr const char *PNG_SET_CARD_HEART = APP_RES_PATH"/CARD_HEART.bin"; + static constexpr const char *PNG_SET_CARD_COMPASS = APP_RES_PATH"/CARD_COMPASS.bin"; + static constexpr const char *PNG_SET_CARD_ACTIVITY = APP_RES_PATH"/CARD_ACTIVITY.bin"; + static constexpr const char *PNG_SET_CARD_PLAYER = APP_RES_PATH"/CARD_PLAYER.bin"; + + static constexpr const char *PNG_SET_DIAL_CLOCK = APP_RES_PATH"/DIAL_CLOCK.bin"; } #endif // UI_CONFIG_H diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp index 3637aee87..0d578dfe2 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -66,6 +66,17 @@ #include "AlipayMainView.h" #include "AlipayPresenter.h" #endif +#include "SetDesktopView.h" +#include "SetDesktopPresenter.h" +#include "SetCardView.h" +#include "SetCardPresenter.h" +#include "AddCardView.h" +#include "AddCardPresenter.h" +#include "SetDialView.h" +#include "SetDialPresenter.h" +#ifdef JS_ENABLE +#include "product_adapter.h" +#endif namespace OHOS { struct AppViewMapper @@ -102,6 +113,10 @@ static const AppViewMapper SLICE_MAPPER[] = { #ifdef SUPPORT_ALIPAY_SEC {VIEW_MAIN_ALIPAY, &NativeLauncher::InitMainAlipaySlice}, #endif + {VIEW_SET_DESKTOP, &NativeLauncher::InitSetDesktopSlice}, + {VIEW_SET_CARD, &NativeLauncher::InitSetCardSlice}, + {VIEW_ADD_CARD, &NativeLauncher::InitAddCardSlice}, + {VIEW_SET_DIAL, &NativeLauncher::InitSetDialSlice}, }; static const ViewIdToString VIEW_MAPPER[] = { @@ -126,6 +141,10 @@ static const ViewIdToString VIEW_MAPPER[] = { #ifdef SUPPORT_ALIPAY_SEC {VIEW_MAIN_ALIPAY, "mianAlipayView"}, #endif + {VIEW_SET_DESKTOP, "SetDesktop"}, + {VIEW_SET_CARD, "SetCard"}, + {VIEW_ADD_CARD, "AddCard"}, + {VIEW_SET_DIAL, "SetDial"}, }; NativeLauncher::NativeLauncher() {} @@ -137,7 +156,11 @@ NativeLauncher &NativeLauncher::GetInstance(void) return instance; } -void NativeLauncher::InitNativeLauncher() { +void NativeLauncher::InitNativeLauncher() +{ +#ifdef JS_ENABLE + ACELite::ProductAdapter::SetScreenSize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); +#endif GraphicStartUp::InitFontEngine(MEM_POOL_UI_FONT, MEM_POOL_UI_FONT_SIZE, OHOS::VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME); WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "NativeLauncher::InitNativeLauncher"); // 初始化所有预加载slice @@ -146,7 +169,7 @@ void NativeLauncher::InitNativeLauncher() { CallerLogModel::GetInstance()->InitPhoneService(); PlayersModel::GetInstance()->AudioInit(); ActivityModel::GetInstance()->Init(); - ScreenModels::GetInstance()->InitCardConfig(); + ScreenModels::GetInstance()->InitKvStorage(); VocassistModel::GetInstance()->Init(); HeartModel::GetInstance()->Init(); BluetoothModel::GetInstance()->Init(); @@ -375,4 +398,49 @@ void NativeLauncher::InitUISampleSlice(void) } NativeAbility::GetInstance().AddSliceProxy(VIEW_UISAMPLE, uisampleView); } + +void NativeLauncher::InitSetDesktopSlice(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSetDesktopSlice"); + SliceProxy *setDesktopView = new AbilitySliceProxy; + if (setDesktopView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "setDesktopView"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SET_DESKTOP, setDesktopView); +} + +void NativeLauncher::InitSetCardSlice(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSetCardSlice"); + SliceProxy *setCardView = new AbilitySliceProxy; + if (setCardView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "setCardView"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SET_CARD, setCardView); +} + +void NativeLauncher::InitAddCardSlice(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitAddCardSlice"); + SliceProxy *addCardView = new AbilitySliceProxy; + if (addCardView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addCardView"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_ADD_CARD, addCardView); +} + +void NativeLauncher::InitSetDialSlice(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSetDialSlice"); + SliceProxy *setDialView = new AbilitySliceProxy; + if (setDialView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "setCardView"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SET_DIAL, setDialView); +} + } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardAdapter.h new file mode 100644 index 000000000..34882c939 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardAdapter.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardAdapter.h + * Author: + * Create: 2021-09-18 + */ + +#ifndef ADD_CARD_ADAPTER_H +#define ADD_CARD_ADAPTER_H + +#include +#include +#include "components/ui_list.h" +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/abstract_adapter.h" +#include "UiConfig.h" +#include "wearable_log.h" +#include "AddCardItem.h" + +namespace OHOS { +class AddCardAdapter : public AbstractAdapter { +public: + explicit AddCardAdapter(); + virtual ~AddCardAdapter(); + + virtual uint16 GetCount(void) override; + + virtual UIView *GetView(UIView *inView, int16 index) override; + + virtual void AddListItem(const AddCardInfo &item); + + void SetItemClickListener(UIView::OnClickListener *itemClickListener) + { + itemClickListener_ = itemClickListener; + } + + void ClearItem(void); + +private: + std::list listData_; + UIView::OnClickListener *itemClickListener_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardItem.h b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardItem.h new file mode 100644 index 000000000..5ce44d585 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardItem.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardItem.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef ADD_CARD_ITEM_H +#define ADD_CARD_ITEM_H + +#include +#include +#include "components/ui_view.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" +#include "UiConfig.h" + +namespace OHOS { +typedef struct { + CardId id; + bool addFlag; + const char *cardImg; +} AddCardInfo; + +class AddCardItem :public UIViewGroup { +public: + AddCardItem(); + virtual ~AddCardItem(); + void SetItemInfo(const AddCardInfo &cardInfo); + void SetOnClickListener(OnClickListener *onClickListener); + void UpdateItemInfo(bool addFlag); +private: + void SetUpChild(); + UIImageView cardImg_; + UILabelButton cardLabel_; + AddCardInfo cardInfo_; +}; + +} + +#endif // ADD_CARD_ITEM_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardModel.h b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardModel.h new file mode 100644 index 000000000..ae17e1a0f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardModel.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef ADD_CARD_MODEL_H +#define ADD_CARD_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "AddCardPresenter.h" +#include "MainModel.h" + +namespace OHOS { + class AddCardModel { + public: + static AddCardModel &GetInstance(void); + void SetSelectedCardIndex(uint8_t cardIndex); + uint8_t GetSelectedCardIndex(void) const; + void AddCardSetting(void); + private: + AddCardModel(); + AddCardModel(const AddCardModel &); + AddCardModel &operator=(const AddCardModel &); + virtual ~AddCardModel(); + uint8_t selectedCardIndex{0}; + + }; +} + +#endif // ADD_CARD_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardPresenter.h new file mode 100644 index 000000000..f8e6f885b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardPresenter.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardPresenter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef ADD_CARD_PRESENTER_H +#define ADD_CARD_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_list.h" +#include "components/ui_view.h" +#include "KeyInputListener.h" + +namespace OHOS { +static const char *ADD_CARD_ADD = "addcardadd"; +class AddCardView; +class AddCardModel; +class AddCardPresenter : public Presenter, + public UIView::OnClickListener, public UIView::OnDragListener, + public ListScrollListener { +public: + AddCardPresenter(); + virtual ~AddCardPresenter(); + + virtual void OnStart() override; + virtual void OnResume() override; + virtual void OnStop() override; + + bool OnClick(UIView &view, const ClickEvent &event) override; + virtual void OnScrollStart(int16_t index, UIView *view) override; + virtual void OnScrollEnd(int16_t index, UIView *view) override; + virtual void OnItemSelected(int16_t index, UIView* view) override; + virtual bool OnDrag(UIView& view, const DragEvent& event) override; +private: + KeyInputListener *keyActListenr{nullptr}; + AddCardModel *model{nullptr}; + +}; +} + +#endif // ADD_CARD_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardView.h b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardView.h new file mode 100644 index 000000000..63d51bba5 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardView.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardView.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef ADD_CARD_VIEW_H +#define ADD_CARD_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +#include "window/window.h" +#include "BaseView.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "AddCardAdapter.h" +#include "AddCardModel.h" + +namespace OHOS { +class AddCardPresenter; + +class AddCardView : public View { +public: + AddCardView(); + virtual ~AddCardView(); + + static AddCardView *GetInstance() + { + static AddCardView instance; + return &instance; + } + + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + void RefreshCardList(void); +private: + void SetUpListInfo(void); + void SetUpListView(void); + UIList contentList_; + AddCardAdapter *addCardAdapter_{nullptr}; +}; +} +#endif // ADD_CARD_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardAdapter.cpp new file mode 100644 index 000000000..d92f38ddb --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardAdapter.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardAdapter.cpp + * Author: + * Create: 2021-09-18 + */ + +#include "AddCardAdapter.h" + +namespace OHOS { +AddCardAdapter::AddCardAdapter() {} + +AddCardAdapter::~AddCardAdapter() +{ + listData_.clear(); +} + +uint16 AddCardAdapter::GetCount(void) +{ + return listData_.size(); +} + +void AddCardAdapter::ClearItem(void) +{ + listData_.clear(); +} + +UIView *AddCardAdapter::GetView(UIView *inView, int16 index) +{ + if (index >= (int16)listData_.size() || index < 0) { + return nullptr; + } + + std::list::iterator it = listData_.begin(); + for (int i = 0; i < index; i++) { + it++; + } + + AddCardItem *item = nullptr; + if (inView == nullptr) { + item = new AddCardItem(); + if (item == nullptr) { + return nullptr; + } + } else { + item = static_cast(inView); + } + + item->SetItemInfo(*it); + item->SetViewIndex(index); + item->SetOnClickListener(itemClickListener_); + return item; +} + +void AddCardAdapter::AddListItem(const AddCardInfo &item) +{ + listData_.push_back(item); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardItem.cpp b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardItem.cpp new file mode 100644 index 000000000..67e287ec8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardItem.cpp @@ -0,0 +1,58 @@ +#include "AddCardItem.h" +#include "AddCardPresenter.h" +#include "wearable_log.h" + +namespace OHOS { + AddCardItem::AddCardItem() + { + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + SetUpChild(); + Add(&cardImg_); + Add(&cardLabel_); + } + + AddCardItem::~AddCardItem() + { + Remove(&cardImg_); + Remove(&cardLabel_); + } + + void AddCardItem::SetUpChild() + { + cardImg_.SetPosition(87, 60); + cardImg_.Resize(280, 280); + cardImg_.SetResizeMode(UIImageView::FILL); + cardImg_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + cardLabel_.SetPosition(175, 360); + cardLabel_.Resize(100, 50); + cardLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + } + + void AddCardItem::SetItemInfo(const AddCardInfo &cardInfo) + { + cardInfo_ = cardInfo; + cardImg_.SetSrc(cardInfo.cardImg); + if (cardInfo.addFlag) { + cardLabel_.SetText("已添加"); + } else { + cardLabel_.SetText("添加"); + } + } + + void AddCardItem::UpdateItemInfo(bool addFlag) + { + if (addFlag) { + cardLabel_.SetText("已添加"); + cardInfo_.addFlag = addFlag; + Invalidate(); + } + } + + void AddCardItem::SetOnClickListener(OnClickListener *onClickListener) + { + cardLabel_.SetOnClickListener(onClickListener); + } + +}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardModel.cpp new file mode 100644 index 000000000..fa052decb --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardModel.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "AddCardModel.h" +#include "kv_store.h" +#include "securec.h" + +namespace OHOS { + AddCardModel::AddCardModel() {} + + AddCardModel::~AddCardModel() {} + + AddCardModel &AddCardModel::GetInstance() + { + static AddCardModel instance; + return instance; + } + + void AddCardModel::SetSelectedCardIndex(uint8_t cardIndex) + { + selectedCardIndex = cardIndex; + } + + uint8_t AddCardModel::GetSelectedCardIndex(void) const + { + return selectedCardIndex; + } + + void AddCardModel::AddCardSetting(void) + { + MainModel::GetInstance().AddCardSetting(selectedCardIndex); + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp new file mode 100644 index 000000000..73044d546 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardPresenter.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "AddCardView.h" +#include "AddCardModel.h" +#include "AddCardPresenter.h" + +namespace OHOS { + AddCardPresenter::AddCardPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::AddCardPresenter"); + model = &AddCardModel::GetInstance(); + } + + AddCardPresenter::~AddCardPresenter() { + } + + void AddCardPresenter::OnStart() + { + Presenter::OnStart(); + } + + void AddCardPresenter::OnResume(void) + { + } + + void AddCardPresenter::OnStop(void) + { + } + + bool AddCardPresenter::OnDrag(UIView& view, const DragEvent& event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnDrag ChangeSlice"); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } + return false; + } + + bool AddCardPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnClick"); + model->AddCardSetting(); + view_->RefreshCardList(); + return true; + } + + void AddCardPresenter::OnScrollStart(int16_t index, UIView *view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnScrollStart index = %d", index); + return; + } + + void AddCardPresenter::OnScrollEnd(int16_t index, UIView *view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnScrollEnd index = %d", index); + if (view == nullptr) { + return; + } + model->SetSelectedCardIndex(index); + } + + void AddCardPresenter::OnItemSelected(int16_t index, UIView* view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnItemSelected index = %d", index); + if (view == nullptr) { + return; + } + } + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardView.cpp new file mode 100644 index 000000000..a696032d2 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardView.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardView.cpp + * Author: + * Create: 2021-11-23 + */ + +#include +#include "AddCardView.h" +#include "AddCardPresenter.h" + +namespace OHOS { +AddCardView::AddCardView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::AddCardView"); +} + +AddCardView::~AddCardView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::~AddCardView"); + if (addCardAdapter_ != nullptr) { + delete addCardAdapter_; + addCardAdapter_ = nullptr; + } +} + +void AddCardView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + addCardAdapter_ = new AddCardAdapter(); + addCardAdapter_->SetItemClickListener(presenter_); + SetUpListInfo(); + SetUpListView(); +} + +void AddCardView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::OnSetUpView"); + View::OnSetUpView(); +} + +void AddCardView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::OnTearDownView"); + View::OnTearDownView(); +} + +void AddCardView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::OnStop"); + View::OnStop(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } +} + +void AddCardView::SetUpListInfo(void) +{ + MainModel::GetInstance().InitCardSettings(); + uint8_t cardCount = MainModel::GetInstance().GetCardSettingCount(); + CardId *cardSettings = MainModel::GetInstance().GetCardSettings(); + addCardAdapter_->ClearItem(); + for (uint8_t i = WATCH_FACE + 1; i < MAX_CARD; i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "All:cardId = %d", i); + const CardInfo *info = MainModel::GetInstance().GetCardInfo((CardId)i); + if (info != nullptr) { + AddCardInfo addInfo; + addInfo.id = info->id; + addInfo.cardImg = info->cardImg; + addInfo.addFlag = false; + for (uint8_t j = 0; j < cardCount; j++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Settings:cardId = %d", cardSettings[j]); + if (cardSettings[j] == i) { + addInfo.addFlag = true; + break; + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListInfo::%d %s %d", + addInfo.id, addInfo.cardImg, addInfo.addFlag); + addCardAdapter_->AddListItem(addInfo); + } + } +} + +void AddCardView::SetUpListView(void) +{ + contentList_.SetPosition(0, 0); + contentList_.Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + contentList_.SetScrollBlankSize(VERTICAL_RESOLUTION / 2); + contentList_.SetSelectPosition(VERTICAL_RESOLUTION / 2); + contentList_.SetDraggable(true); + contentList_.SetThrowDrag(true); + contentList_.EnableAutoAlign(true); + contentList_.SetScrollStateListener(presenter_); + contentList_.SetOnDragListener(presenter_); + contentList_.SetMaxScrollDistance(1000); + contentList_.SetAdapter(addCardAdapter_); + contentList_.SetVisible(true); + container_->Add(&contentList_); +} + +void AddCardView::RefreshCardList(void) +{ + SetUpListInfo(); + contentList_.RefreshList(); +} + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayMainView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayMainView.cpp index 10bad7db9..9aca06afd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayMainView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayMainView.cpp @@ -753,6 +753,7 @@ static const int16 DestroyMapper[] = { ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_TRANS_VIEW, ALIPAY_TRANS_LIST_VIEW, + ALIPAY_SETTING_VIEW, }; void AlipayMainView::DestroyTempView(int16 hideView) @@ -780,6 +781,9 @@ void AlipayMainView::DestroyTempView(int16 hideView) } else if (hideView == ALIPAY_TRANS_LIST_VIEW) { delete alipayTransList; alipayTransList = nullptr; + } else if (hideView == ALIPAY_SETTING_VIEW) { + delete alipaySetting; + alipaySetting = nullptr; } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/AppItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/AppItemView.h index ffb9c803a..b6f9568f4 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/AppItemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/AppItemView.h @@ -33,6 +33,20 @@ private: UILabel label_; AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; }; + +class HexagonsItemView : public UIImageView { +public: + explicit HexagonsItemView(); + virtual ~HexagonsItemView(); + void SetItemInfo(const AppItem &itemInfo); + AppViewId GetViewId(); + const char *GetAppUid(); +private: + HexagonsItemView(const HexagonsItemView &); + HexagonsItemView &operator = (const HexagonsItemView &); + AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; +}; + } #endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistModel.h b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistModel.h index c0a5d913d..135071023 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistModel.h @@ -10,7 +10,6 @@ #include "bundle_info.h" #include "AppViewIDs.h" -#include "components/ui_label_ext.h" #include "ohos_types.h" #define APP_MAX_NUM 50 @@ -29,7 +28,7 @@ class ApplistModel { public: static ApplistModel &GetInstance(void); - void initApplist(); + void Init(); const AppItem *GetApplistItems() const; uint8 GetAppListNum() const; void ResolvingJSAppItems(void); @@ -39,7 +38,7 @@ public: int GetHeadItemY(void); void ApplistUpdate(void); void SetPresenter(ApplistPresenter *p); - + bool GetIsUseListStyle(void); private: ApplistModel(); ApplistModel(const ApplistModel &); @@ -54,6 +53,7 @@ private: uint16_t startIndex = 0; int headItemY = 0; + bool initFlag{false}; }; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistPresenter.h index fd604015b..c0d53a29d 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistPresenter.h @@ -17,7 +17,8 @@ #include "KeyInputListener.h" namespace OHOS { - class ApplistPresenter : public Presenter, public UIView::OnClickListener { + class ApplistPresenter : public Presenter, public UIView::OnClickListener, + public ListScrollListener { public: ApplistPresenter(); virtual ~ApplistPresenter(); @@ -28,14 +29,18 @@ namespace OHOS { virtual void OnStop() override; bool OnClick(UIView &view, const ClickEvent &event) override; + void OnItemSelected(int16 index, UIView *view) override; void SetStartIndex(uint16_t index); uint16_t GetStartIndex(void); void SetHeadItemY(int y); int GetHeadItemY(void); uint8_t GetListItemNum(void); ApplistView* GetAppListView(); + bool GetIsUseListStyle(void); private: + AppItemView *itemViewSele{nullptr}; + AppItemView *preItemViewSele{nullptr}; ApplistModel *model{nullptr}; KeyInputListener *keyActListenr{nullptr}; }; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistView.h b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistView.h index 88be5fe1d..6689efb18 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistView.h @@ -14,6 +14,7 @@ #include "components/ui_scroll_view.h" #include "components/ui_label.h" #include "components/ui_list.h" +#include "components/ui_custom_hexagons_list.h" #include "window/window.h" #include "ohos_types.h" #include "BaseView.h" @@ -66,7 +67,7 @@ private: }; class ApplistPresenter; -class ApplistView : public View, public ListScrollListener { +class ApplistView : public View { public: ApplistView(); virtual ~ApplistView(); @@ -78,15 +79,28 @@ public: void AddAppItemToList(const AppItem &item); void ClearAppItemToList(); - void OnItemSelected(int16 index, UIView *view) override; - UIList* GetAppUIList(void); - + void RefreshAppList(void); private: + void HexagonsStyleOnStart(); + void ListStyleOnStart(); + void HexagonsStyleOnSetUpView(); + void ListStyleOnSetUpView(); + void HexagonsStyleOnStop(); + void ListStyleOnStop(); + + /* for list style */ ApplistAdapter *listAdapter_{nullptr}; UIList *contentList_{nullptr}; UIView::OnDragListener *dragListener{nullptr}; - AppItemView *itemViewSele{nullptr}; - AppItemView *preItemViewSele{nullptr}; + + /* for hexagons style */ + UICustomHexagonsList* hexagonsList_{nullptr}; + std::list listHexagonsView_; + int16_t horMargin_ = 0; + int16_t verMargin_ = 0; + uint16_t imgSize_ = 0; + uint16_t imgDistance_ = 0; + }; } #endif // APPLIST_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/AppItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/AppItemView.cpp index 87ed2e4f5..cd35ebb0f 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/AppItemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/AppItemView.cpp @@ -82,4 +82,25 @@ namespace OHOS { icon_.ResetTransParameter(); } + HexagonsItemView::HexagonsItemView() + { + } + + HexagonsItemView::~HexagonsItemView() + { + } + void HexagonsItemView::SetItemInfo(const AppItem &itemInfo) + { + itemInfo_ = itemInfo; + } + + AppViewId HexagonsItemView::GetViewId() + { + return itemInfo_.id; + } + + const char *HexagonsItemView::GetAppUid() + { + return itemInfo_.uid; + } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp index d08582292..f6a21be8f 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp @@ -16,6 +16,7 @@ #include "UiConfig.h" #include "ApplistModel.h" #include "ApplistPresenter.h" +#include "SetDesktopModel.h" namespace OHOS { const AppItem g_nativeAppList[] = { @@ -50,9 +51,13 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistModel::~ApplistModel()"); } - void ApplistModel::initApplist() + + void ApplistModel::Init() { - ResolvingJSAppItems(); + if (!initFlag) { + ResolvingJSAppItems(); + initFlag = true; + } } void ApplistModel::ResolvingJSAppItems(void) @@ -107,6 +112,8 @@ namespace OHOS { appLen++; bundleInfos[len].abilityInfo = nullptr; } + } else { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems GetBundleInfos ret = %d \r", ret); } #endif } @@ -149,7 +156,7 @@ namespace OHOS { for (uint8 i = 0; i < GetAppListNum(); i++) { presenter->GetAppListView()->AddAppItemToList(itemInfo[i]); } - presenter->GetAppListView()->GetAppUIList()->RefreshList(); + presenter->GetAppListView()->RefreshAppList(); } } @@ -157,4 +164,9 @@ namespace OHOS { { presenter = p; } + + bool ApplistModel::GetIsUseListStyle(void) + { + return (SetDesktopModel::GetInstance().GetDesktopStyle() == APPLIST_STYLE); + } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistPresenter.cpp index 66763132c..49e02f84d 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistPresenter.cpp @@ -7,7 +7,6 @@ #include "ApplistPresenter.h" #include "ability_manager.h" - #include "securec.h" namespace OHOS { @@ -15,6 +14,7 @@ namespace OHOS { { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::ApplistPresenter()"); model = &ApplistModel::GetInstance(); + model->Init(); model->SetPresenter(this); } @@ -30,8 +30,6 @@ namespace OHOS { { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnStart()"); Presenter::OnStart(); - model->initApplist(); - if (keyActListenr == nullptr) { keyActListenr = new KeyInputListener(); if (keyActListenr != nullptr) { @@ -53,6 +51,7 @@ namespace OHOS { for (uint8 i = 0; i < model->GetAppListNum(); i++) { view_->AddAppItemToList(itemInfo[i]); } + view_->RefreshAppList(); } void ApplistPresenter::OnPause() @@ -63,28 +62,35 @@ namespace OHOS { void ApplistPresenter::OnStop(void) { Presenter::OnStop(); - RootView::GetInstance()->ClearOnKeyActListener(); } bool ApplistPresenter::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); - AppItemView *itemView = static_cast(&view); - AppViewId viewId = itemView->GetViewId(); - + AppViewId viewId = VIEW_INVALID; + char *uid = nullptr; + if (GetIsUseListStyle() == true) { + AppItemView *itemView = static_cast(&view); + viewId = itemView->GetViewId(); + uid = (char *)itemView->GetAppUid(); + } else { + HexagonsItemView *itemView = static_cast(&view); + viewId = itemView->GetViewId(); + uid = (char *)itemView->GetAppUid(); + } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d", viewId); if (viewId < VIEW_MAX_INTER_APP) { NativeAbility::GetInstance().ChangeSlice(viewId); return true; } else if (viewId == VIEW_EXTERN_APP) { #ifdef JS_ENABLE - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick bundleName = %s", itemView->GetAppUid()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick bundleName = %s", uid); Want *want = new Want(); memset_s(want, sizeof(Want), 0, sizeof(Want)); ElementName startElement = {}; startElement.abilityName = (char *)"default"; - startElement.bundleName = (char *)itemView->GetAppUid(); + startElement.bundleName = uid; startElement.deviceId = nullptr; SetWantElement(want, startElement); @@ -95,7 +101,19 @@ namespace OHOS { } return false; } + void ApplistPresenter::OnItemSelected(int16 index, UIView *view) + { + UNUSED(index); + if (view != nullptr) { + itemViewSele = static_cast(view); + itemViewSele->SelectedChange(); + if (preItemViewSele != nullptr && preItemViewSele != itemViewSele) { + preItemViewSele->Reset(); + } + preItemViewSele = itemViewSele; + } + } void ApplistPresenter::SetStartIndex(uint16_t index) { model->SetStartIndex(index); @@ -123,6 +141,11 @@ namespace OHOS { return model->GetAppListNum(); } + bool ApplistPresenter::GetIsUseListStyle(void) + { + return model->GetIsUseListStyle(); + } + ApplistView* ApplistPresenter::GetAppListView() { return view_; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistView.cpp index c0f0cf68b..07b7ef0e1 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistView.cpp @@ -22,19 +22,60 @@ ApplistView::ApplistView() ApplistView::~ApplistView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::~ApplistView "); - delete listAdapter_; - listAdapter_ = nullptr; - delete contentList_; - contentList_ = nullptr; - delete dragListener; - dragListener = nullptr; + if (listAdapter_ != nullptr) { + delete listAdapter_; + listAdapter_ = nullptr; + } + if (contentList_ != nullptr) { + delete contentList_; + contentList_ = nullptr; + } + if (dragListener != nullptr) { + delete dragListener; + dragListener = nullptr; + } + if (hexagonsList_ != nullptr) { + delete hexagonsList_; + hexagonsList_ = nullptr; + } } void ApplistView::OnStart() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStart "); View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + if (presenter_->GetIsUseListStyle() == true) { + ListStyleOnStart(); + } else { + HexagonsStyleOnStart(); + } +} +void ApplistView::HexagonsStyleOnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStart "); + if (hexagonsList_ == nullptr) { + hexagonsList_ = new UICustomHexagonsList(); + } + container_->Add(hexagonsList_); + hexagonsList_->SetPosition(0, 0, + container_->GetWidth() - 2 * (horMargin_ + 1), container_->GetHeight() - 2 * (verMargin_ + 1)); // 2, two + imgDistance_ = container_->GetWidth() * 0.25991; // 0.25991, empirical coefficient + imgSize_ = container_->GetWidth() * 0.23348; // 0.23348, empirical coefficient + hexagonsList_->SetImageDistance(imgDistance_); + hexagonsList_->SetImageSizeInCenter(imgSize_); + int16_t blankSize = hexagonsList_->GetRelativeRect().GetWidth() > hexagonsList_->GetRelativeRect().GetHeight() ? + hexagonsList_->GetRelativeRect().GetWidth() / 2 : hexagonsList_->GetRelativeRect().GetHeight() / 2; // 2, half + hexagonsList_->SetScrollBlankSize(blankSize); + hexagonsList_->SetReboundSize(blankSize); + hexagonsList_->SetThrowDrag(true); +} + +void ApplistView::ListStyleOnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStart"); listAdapter_ = new ApplistAdapter(); if (listAdapter_ == nullptr) { return; @@ -52,10 +93,10 @@ void ApplistView::OnStart() contentList_->SetDraggable(true); contentList_->SetThrowDrag(true); contentList_->EnableAutoAlign(true); - contentList_->SetScrollStateListener(this); + contentList_->SetScrollStateListener(presenter_); contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS); contentList_->SetYScrollBarVisible(true); - SetContainerView(contentList_); + container_->Add(contentList_); dragListener = new AppListOnDragListener(); if (dragListener == nullptr) { @@ -68,6 +109,21 @@ void ApplistView::OnSetUpView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnSetUpView"); View::OnSetUpView(); + if (presenter_->GetIsUseListStyle() == true) { + ListStyleOnSetUpView(); + } else { + HexagonsStyleOnSetUpView(); + } +} + +void ApplistView::HexagonsStyleOnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnSetUpView "); +} + +void ApplistView::ListStyleOnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnSetUpView"); if (contentList_ == nullptr || listAdapter_ == nullptr) { return; @@ -88,7 +144,6 @@ void ApplistView::OnSetUpView() contentList_->SetStartIndex(startIndex); contentList_->SetAdapter(listAdapter_); contentList_->ScrollBy(headY); - Draw(); return; } @@ -102,48 +157,79 @@ void ApplistView::OnTearDownView() void ApplistView::OnStop() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStop"); - int16_t listHeadY = contentList_->GetChildrenHead()->GetY(); - int16_t listHeadIndex = contentList_->GetChildrenHead()->GetViewIndex(); - - presenter_->SetHeadItemY(listHeadY); - presenter_->SetStartIndex(listHeadIndex); - + if (presenter_->GetIsUseListStyle() == true) { + ListStyleOnStop(); + } else { + HexagonsStyleOnStop(); + } + if (container_ != nullptr) { + container_->RemoveAll(); + } View::OnStop(); - container_ = nullptr; - RootView::GetInstance()->ClearOnKeyActListener(); - RootView::GetInstance()->RemoveAll(); return; } -void ApplistView::AddAppItemToList(const AppItem &item) +void ApplistView::HexagonsStyleOnStop() { - listAdapter_->AddListItem(item); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStop"); + if (hexagonsList_ != nullptr) { + hexagonsList_->RemoveAll(); + } + for (auto iter : listHexagonsView_) { + delete iter; + } + listHexagonsView_.clear(); } -void ApplistView::ClearAppItemToList() +void ApplistView::ListStyleOnStop() { - listAdapter_->ClearItem(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStop"); + int16_t listHeadY = contentList_->GetChildrenHead()->GetY(); + int16_t listHeadIndex = contentList_->GetChildrenHead()->GetViewIndex(); + presenter_->SetHeadItemY(listHeadY); + presenter_->SetStartIndex(listHeadIndex); } -void ApplistView::OnItemSelected(int16 index, UIView *view) +void ApplistView::AddAppItemToList(const AppItem &item) { - UNUSED(index); - if (view != nullptr) { - itemViewSele = static_cast(view); - itemViewSele->SelectedChange(); + if (presenter_->GetIsUseListStyle() == true) { + listAdapter_->AddListItem(item); + } else { + HexagonsItemView *itemView = new HexagonsItemView(); + itemView->SetItemInfo(item); + itemView->SetSrc(item.iconSmall); + itemView->SetTouchable(true); + itemView->SetOnClickListener(presenter_); + + hexagonsList_->Add(itemView); + listHexagonsView_.push_back(itemView); + } +} - if (preItemViewSele != nullptr && preItemViewSele != itemViewSele) { - preItemViewSele->Reset(); +void ApplistView::ClearAppItemToList() +{ + if (presenter_->GetIsUseListStyle() == true) { + listAdapter_->ClearItem(); + } else { + if (hexagonsList_ != nullptr) { + hexagonsList_->RemoveAll(); + } + for (auto iter : listHexagonsView_) { + delete iter; } - preItemViewSele = itemViewSele; + listHexagonsView_.clear(); } } -UIList* ApplistView::GetAppUIList(void) +void ApplistView::RefreshAppList(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::GetAppUIList"); - return contentList_; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::RefreshAppList"); + if (presenter_->GetIsUseListStyle() == true) { + contentList_->RefreshList(); + } else { + hexagonsList_->LayoutChildren(true); + } } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp index 4c8f4aa4a..c940ac853 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp @@ -12,6 +12,7 @@ #include "components/ui_label.h" #include "BloodBandoffView.h" #include "ChangeSliceListener.h" +#include "ui_service.h" namespace OHOS { static BloodOxygenPresenter *g_pMainView = nullptr; @@ -38,6 +39,7 @@ BloodOxygenPresenter* BloodOxygenPresenter::GetInstance() void BloodOxygenPresenter::OnStart() { Presenter::OnStart(); + SendMsgToUIService(UI_ADD_SLEEP_VETO, 0, NULL, 0); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::On Start "); } @@ -45,7 +47,9 @@ void BloodOxygenPresenter::OnPause(void) {} void BloodOxygenPresenter::OnResume(void) {} -void BloodOxygenPresenter::OnStop(void) {} +void BloodOxygenPresenter::OnStop(void) { + SendMsgToUIService(UI_RM_SLEEP_VETO, 0, NULL, 0); +} bool BloodOxygenPresenter::CheckPointersValue() { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothModel.h b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothModel.h index 25c7d4157..5cbb44093 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothModel.h @@ -29,18 +29,6 @@ typedef struct { int16_t temp; } BluetoothCaseInfo; -typedef struct { - void *stream_hdl; - uint8_t loc_volume; - uint8_t play_stat; - uint8_t dir_forward; - uint8_t avrcp_button_flag; - bd_addr_t bd_addr; - uint8_t reg_cap_auto; - uint8_t resrv; - profile_connect_state_t avrcp_srv_conn_stat; -} BtAvrcpTgInftrerface; - class BluetoothItemView; class BluetoothModel { public: diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp index 6b1d6e73b..94994ca27 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp @@ -33,6 +33,15 @@ static profile_connect_state_t BtAvrcpStat() return g_avrcpTgStat; } +void BtAvrcpVolumeChangedSyncMedia(uint8_t a2dp_volume) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "[BtAvrcpVolumeChangedSyncMedia]::a2dp_volume = 0x%x\r\n", a2dp_volume); + int32_t audio_volume = a2dp_volume * BT_A2DP_MEDIA_VOL_LEVEL / AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100; + AudioManager::GetInstance().SetVolume(AUDIO_STREAM_A2DP_MUSIC, audio_volume); /* 设置增益音量 */ + g_avrcp_tg_local_media_vol = a2dp_volume; + avrcp_tg_notify_volume_changed(a2dp_volume); +} + /* tg通知媒体状态 */ static void BtAvrcpTgNotifyMeidaStatus(bt_avrcp_tg_evt_status_param *notifyEventStatusParam) { @@ -74,9 +83,10 @@ static void BtAvrcpTgNotifyMeidaStatus(bt_avrcp_tg_evt_status_param *notifyEvent avrcp_tg_notify_uid_changed(*(td_u16 *)notifyEventStatusParam->event_status); break; case AVRCP_NOTIFY_EVENT_VOLUME_CHANGED: - avrcp_tg_notify_volume_changed(*(td_u8 *)notifyEventStatusParam->event_status); + BtAvrcpVolumeChangedSyncMedia(notifyEventStatusParam->event_status[0]); break; case AVRCP_NOTIFY_EVENT_RESERVED: + break; default: break; } @@ -84,7 +94,7 @@ static void BtAvrcpTgNotifyMeidaStatus(bt_avrcp_tg_evt_status_param *notifyEvent void PressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PressButtonStatusCallback]::keyValue = %x keyOperation = %x", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PressButtonStatusCallback]::keyValue = 0x%x keyOperation = 0x%x", keyValue, keyOperation); GraphicService::GetInstance()->PostGraphicEvent(std::bind(UsingPressButtonStatusCallback, keyOperation, keyValue)); } @@ -92,7 +102,7 @@ void PressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue) void BtAvrcpTgNotifyVolumeChangedProc(uint8_t a2dp_volume) { int32_t audio_volume = a2dp_volume * BT_A2DP_MEDIA_VOL_LEVEL / AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100; - AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, audio_volume); + AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, audio_volume); // 耳机连接手表场景调节手表音量 } void UsingPressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue) @@ -145,10 +155,15 @@ void UsingPressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue) uint8_t BtAvrcpTgGetLocMediaVolume(void) { - uint32_t audio_volume = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC); - uint8_t a2dp_volume = audio_volume * AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100 / BT_A2DP_MEDIA_VOL_LEVEL; - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get local media volume, a2dp_volume = 0x%x", a2dp_volume); - return a2dp_volume; + if (g_avrcp_tg_local_media_vol == AVRCP_ABSOLUTE_VOLUME_INVALID) { + int32_t audio_volume = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_A2DP_MUSIC); + uint8_t a2dp_volume = (uint8_t)(audio_volume * AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100 / BT_A2DP_MEDIA_VOL_LEVEL); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "audio_volume 0x%x, a2dp_volume 0x%x\n", audio_volume, a2dp_volume); + g_avrcp_tg_local_media_vol = a2dp_volume; + } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get local media volume, a2dp_volume = 0x%x", g_avrcp_tg_local_media_vol); + return g_avrcp_tg_local_media_vol; } void MediaStatusCallback(bt_avrcp_tg_evt_status_param *eventStatusParam) diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp index a89f5f38b..e58b3f6ea 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp @@ -23,9 +23,6 @@ #include "bts_gatt_server.h" #include "bts_le_gap.h" #include "bts_spp.h" - -// #include "bleService.h" - #include "osal_task.h" #ifdef SUPPORT_ALIPAY_SEC #include "alipay_feature.h" @@ -36,10 +33,6 @@ #include "bts_avrcp_target.h" namespace OHOS { -#define BLE_SERVICE_UUID 0x18E0 -#define BLE_RX_UUID 0x2ae3 -#define BLE_TX_UUID 0x2ae5 -#define BLE_BAE_UUID {0xfb,0x34,0x9b,0x5f,0x80,0x00,0x00,0x80,0x00,0x10,0x00,0x00,0xE3,0x2A,0x00,0x00} #define BT_SPP_TASK_STACK_SIZE 2048 #define BT_SPP_TASK_PRI 20 @@ -51,8 +44,6 @@ constexpr uint16_t BLUETOOTH_MAX_NUM = 20; osal_timer g_a2dp_stream_accept_timer = {NULL, NULL, 0, 0}; #define A2DP_STREAM_ACCEPT_TIMER_PERIOD 500 AudioFormatConfig g_audio_format_config = {AUDIO_DEFAULT, 0, 0}; -BtAvrcpTgInftrerface g_avrcp_srv_infterface; - void BluetoothModel::SetBluetoothCalleridStatus(int16_t value) { @@ -77,16 +68,16 @@ BluetoothModel *BluetoothModel::GetInstance(void) void BluetoothModel::Init() { - // bool ret = enable_bt_stack(); - // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt enable_bt_stack ret = %d", ret); + bool ret = enable_bt_stack(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt enable_bt_stack ret = %d", ret); BtInitCallBacks(); - - - // svr_bluetooth_init(); +#ifdef SUPPORT_ALIPAY_SEC + svr_alipay_bluetooth_init(); +#else BtInitCallBacksEx(); BtInitGatts(); - +#endif BtInitSpp(); SetUpListCase(); @@ -756,7 +747,6 @@ static void DisconnectBluetoothPause() static void DisconnectedHandle() { - DisconnectBluetoothPause(); BluetoothModel::GetInstance()->SetTagDisconnectView(false); BluetoothDeviceListView *bluetoothDeviceListView = BluetoothDeviceListView::GetInstance(); if (bluetoothDeviceListView == nullptr) { @@ -939,8 +929,8 @@ static void BtGattsServiceAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint16_ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsServiceAddCallback 0x%x 0x%x 0x%x", status, serverId, srvcHandle); - if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == BLE_SERVICE_UUID)) { - uint16_t id = BLE_RX_UUID; + if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0x1FF0)) { + uint16_t id = 0x1FF1; gatts_add_chara_info_t character; uint16_t value = 0; @@ -948,27 +938,12 @@ static void BtGattsServiceAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint16_ character.chara_uuid.uuid_len = sizeof(id); memcpy_s(character.chara_uuid.uuid, sizeof(character.chara_uuid.uuid), (char *)&id, sizeof(id)); character.permissions = GATT_ATTRIBUTE_PERMISSION_WRITE; - character.properties = GATT_CHARACTER_PROPERTY_BIT_WRITE | GATT_CHARACTER_PROPERTY_BIT_READ |GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP|GATT_CHARACTER_PROPERTY_BIT_NOTIFY; + character.properties = GATT_CHARACTER_PROPERTY_BIT_WRITE; character.value_len = (uint16_t)sizeof(value); character.value = (uint8_t *)(&value); ret = gatts_add_characteristic(serverId, srvcHandle, &character); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_add_characteristic ret 0x%x", ret); - - uint16_t tx_uuid[16] = BLE_BAE_UUID; - gatts_add_chara_info_t txcharacter; - uint16_t txvalue = 0; - - memset_s(&txcharacter, sizeof(gatts_add_chara_info_t), 0, sizeof(gatts_add_chara_info_t)); - txcharacter.chara_uuid.uuid_len = sizeof(tx_uuid); - memcpy_s(txcharacter.chara_uuid.uuid, sizeof(txcharacter.chara_uuid.uuid), (char *)&tx_uuid, sizeof(tx_uuid)); - txcharacter.permissions = GATT_ATTRIBUTE_PERMISSION_WRITE; - txcharacter.properties = GATT_CHARACTER_PROPERTY_BIT_WRITE | GATT_CHARACTER_PROPERTY_BIT_READ |GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP|GATT_CHARACTER_PROPERTY_BIT_NOTIFY; - txcharacter.value_len = (uint16_t)sizeof(txvalue); - txcharacter.value = (uint8_t *)(&txvalue); - - ret = gatts_add_characteristic(serverId, srvcHandle, &txcharacter); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_add_characteristic ret 0x%x", ret); } } @@ -1011,7 +986,7 @@ static void BtGattsRequestReadCallback(uint8_t serverId, uint16_t connId, gatts_ static void BtGattsRequestWriteCallback(uint8_t serverId, uint16_t connId, gatts_req_write_cb_t *writeCbPara, errcode_t status) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsRequestWriteCallback2 %s length:%d",writeCbPara->value,writeCbPara->length); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsRequestWriteCallback"); } static void BtA2dpSnkAcceptTimerStop(void) @@ -1086,8 +1061,8 @@ static int32_t BtA2dpSnkAudioDestroy() static void BtA2dpSnkConnectStateChangedCb(bd_addr_t *bd_addr, int conn_state) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr1111: ****%02x%02x%02x%02x%02x%02x conn_state: %x\n", - bd_addr->addr[5],bd_addr->addr[4],bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], conn_state); /* 3 2 1 0 idx */ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x conn_state: %x\n", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], conn_state); /* 3 2 1 0 idx */ } static void BtA2dpSnkStartStreamReqCb(bd_addr_t *bd_addr) @@ -1162,7 +1137,6 @@ static a2dp_snk_callbacks_t g_a2dp_snk_callbacks = { void BtInitCallBacks() { - return; g_btGapCallBacks.discovery_result_callback = BtGapDiscoveryResultCallback; g_btGapCallBacks.discovery_state_changed_callback = BtGapDiscoveryStateChangedCallback; g_btGapCallBacks.acl_state_changed_callbak = GapAclStateChangedCallback; @@ -1185,7 +1159,6 @@ void BtInitCallBacks() void BtInitCallBacksEx() { - return; g_gapBleCallbacks.conn_state_change_cb = BleConnStateChangeCallback; g_gapBleCallbacks.start_adv_cb = BleAdvStartCallback; g_gapBleCallbacks.stop_adv_cb = BleAdvStopCallback; @@ -1205,8 +1178,7 @@ void BtInitCallBacksEx() void BtInitGatts(void) { - return; - uint16_t id = BLE_SERVICE_UUID; + uint16_t id = 0x1FF0; uint16_t ser_id = 0x1FFF; uint8_t serverId = 0; bt_uuid_t uuid; @@ -1325,7 +1297,6 @@ void BtInitSpp(void) void BleAdvStart(void) { - return; int advId = 1; if (BluetoothModel::GetInstance()->GetAdvStartState()) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BleAdvStart already started"); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogModel.h b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogModel.h index 9786748f0..4bd290096 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogModel.h @@ -45,7 +45,6 @@ namespace OHOS { using namespace std; class CallerLogModel { - public: typedef enum { CallSourcePhone, @@ -81,7 +80,7 @@ public: bool GetNotifyFlag(void); void SetNotifyFlag(bool flag); - + bool IsMulitplePhoneStatus(void); CallSource GetCallSource(void) { return callsrc; @@ -90,8 +89,6 @@ public: { callsrc = source; } - - private: CallerLogModel(); CallerLogModel(const CallerLogModel &); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp index 62f699411..facd7fcfd 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp @@ -37,7 +37,8 @@ static int g_firstPriority = NO_NUMBER_STATUS; static int g_secondPriority = NO_NUMBER_STATUS; static int g_thirdPriority = NO_NUMBER_STATUS; static int g_fourthPriority = NO_NUMBER_STATUS; - +// 是否为手表接听状态 +static bool g_isWatchCallView = false; void g_callTimesclean() { g_callTimes=0; @@ -95,6 +96,8 @@ static void StatusReset() // If the call is handling in the notification, the slice is not switched if (CallerLogModel::GetInstance()->GetNotifyFlag() == false) { NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } else { + g_isWatchCallView = false; } return; } @@ -241,6 +244,9 @@ static void ExitMakePhoneSlice(void) } CallerLogModel::GetInstance()->SetCallStatus(false); DisableCallingTimer(); + if (CallerLogModel::GetInstance()->GetNotifyFlag() == true) { + g_isWatchCallView = false; + } } static void DialingHandle(void) @@ -273,6 +279,8 @@ static void WaitingOpreate() // If the call is handling in the notification, the slice is not switched if (CallerLogModel::GetInstance()->GetNotifyFlag() == false) { NativeAbility::GetInstance().ChangeSlice(VIEW_MAEKPHONE_SAMPLE, TRANSITION_INVALID, PRIORITY_ONE); + } else { + g_isWatchCallView = true; } } @@ -288,12 +296,15 @@ static void WatchActiveHandle(const PhoneCallInfo *phoneCall) InitCallingTimer(); CallerLogModel::GetInstance()->SetCallStatus(true); } + if (CallerLogModel::GetInstance()->GetNotifyFlag() == true) { + g_isWatchCallView = true; + } } static void PhoneActiveHandle(void) { if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAEKPHONE_SAMPLE || - CallerLogModel::GetInstance()->GetNotifyFlag() == true) { + g_isWatchCallView == true) { if (GetCurrCallNum() > 1) { g_phoneStatus = PHONE_MULTI_STATUS; if (GetScoConnectState() == HFP_SCO_STATE_DISCONNECTED) { @@ -304,6 +315,8 @@ static void PhoneActiveHandle(void) // If the call is handling in the notification, the slice is not switched if (CallerLogModel::GetInstance()->GetNotifyFlag() == false) { NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); // 退出通话界面,回到主表盘应用 + } else { + g_isWatchCallView = false; } CallModelPostGraphicEvent(CallModelResumePlayer); } @@ -314,7 +327,7 @@ static void PhoneActiveHandle(void) static void OppoActiveHandle(const PhoneCallInfo *phoneCall) { if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAEKPHONE_SAMPLE || - CallerLogModel::GetInstance()->GetNotifyFlag() == true) { + g_isWatchCallView == true) { if (GetCurrCallNum() > 1) { g_phoneStatus = PHONE_MULTI_STATUS; return; @@ -370,7 +383,11 @@ static bool MultiplePhonesViewDisplay() DisableCallingTimer(); CallerLogModel::GetInstance()->SetMulitplePhoneStatus(true); CallerLogModel::GetInstance()->SetCallStatus(true); - NativeAbility::GetInstance().ChangeSlice(VIEW_MAEKPHONE_SAMPLE, TRANSITION_INVALID, PRIORITY_ONE); + if (CallerLogModel::GetInstance()->GetNotifyFlag() == false) { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAEKPHONE_SAMPLE, TRANSITION_INVALID, PRIORITY_ONE); + } else { + g_isWatchCallView = true; + } return true; } if (MulitplePhoneTextReplaces() == false) { @@ -403,9 +420,13 @@ static void NonWatchFinishHandle(int laststatus) // If the call is handling in the notification, the slice is not switched if (CallerLogModel::GetInstance()->GetNotifyFlag() == false) { NativeAbility::GetInstance().ChangeSlice(VIEW_MAEKPHONE_SAMPLE, TRANSITION_INVALID, PRIORITY_ONE); + } else { + g_isWatchCallView = true; } } - CallerLogModel::GetInstance()->SetNotifyFlag(false); + if (GetCurrCallNum() == 0) { + CallerLogModel::GetInstance()->SetNotifyFlag(false); + } } if (GetCurrCallNum() == 0) { g_phoneStatus = PHONE_SINGLE_STATUS; @@ -418,13 +439,13 @@ static void WatchFinishHandle(void) CallerLogModel::GetInstance()->GetNotifyFlag() == true) { if (GetCurrCallNum() == 0) { StatusReset(); + CallerLogModel::GetInstance()->SetNotifyFlag(false); } else { StatusReset(); for (int i = GetCurrCallNum(); i > 0; i--) { FinishCall(); } } - CallerLogModel::GetInstance()->SetNotifyFlag(false); } g_phoneStatus = PHONE_SINGLE_STATUS; } @@ -577,6 +598,8 @@ static void ScoConnectHandle(void) // If the call is handling in the notification, the slice is not switched if (CallerLogModel::GetInstance()->GetNotifyFlag() == false) { NativeAbility::GetInstance().ChangeSlice(VIEW_MAEKPHONE_SAMPLE, TRANSITION_INVALID, PRIORITY_ONE); + } else { + g_isWatchCallView = true; } } @@ -725,6 +748,13 @@ bool CallerLogModel::GetNotifyFlag(void) return notifyFlag; } +// 电话是否为多路状态 +bool CallerLogModel::IsMulitplePhoneStatus(void) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "IsMulitplePhoneStatus phoneStatus:%d", g_phoneStatus); + return g_phoneStatus == PHONE_MULTI_STATUS; +} + /* 是否为多路通话界面 */ void CallerLogModel::SetMulitplePhoneStatus(bool status) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartModel.cpp index e8b771345..54098cc04 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartModel.cpp @@ -338,7 +338,7 @@ void HeartModel::RefreshHeartRateScreen(uint16_t perSec, uint16_t rest, uint16_t } if (MainViewSample::GetInstance() != nullptr && HeartRateView::GetInstance() != nullptr) { - if (MainViewSample::GetInstance()->GetHorCurrentPage() == HEART_RATE) { + if (MainViewSample::GetInstance()->GetHorCurrentCard() == HEART_RATE) { HeartRateView::GetInstance()->SetHeartRateData(rateData, sizeof(Point) * len); HeartRateView::GetInstance()->RefreshElectrocardiogram(); HeartRateView::GetInstance()->RefreshHeartRatePerSec(perSec); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkMotionView.h b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkMotionView.h index 4a4ebaa49..303045f66 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkMotionView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkMotionView.h @@ -50,7 +50,6 @@ private: bool pageStatus[MAX_MOTIONPAGE]{false}; UISwipeView::OnSwipeListener* motionclickListener{nullptr}; UIView::OnDragListener* motionDragListener{nullptr}; - AppGroupView *GreatePage(int32_t MotionPageId); }; } // namespace OHOS #endif // INDOORWALK_MOTION_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp index 866e42f86..a3350f28e 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp @@ -127,7 +127,7 @@ UIViewGroup *IndoorWalkMotionView::WalkMotionViewInit(void) walkMotionList->SetAnimatorTime(50); // 50:animator drag time(ms) for (uint16_t i = 0; i < maxPage; i++) { - recordCard[i] = GreatePage(i); + recordCard[i] = (this->*(g_pageMapper[i].func))(); if (recordCard[i] == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "IndoorWalkMotionView:: recordCard %d error", i); return nullptr; @@ -170,20 +170,4 @@ void IndoorWalkMotionView::InitialStep() IndoorWalkModel::GetInstance()->SetInitialStep(stepValue); } -AppGroupView *IndoorWalkMotionView::GreatePage(int32_t StreamId) -{ - uint16_t i; - AppGroupView *view = nullptr; - int32_t MotionPageId = ScreenModels::GetInstance()->GetCardPage(StreamId); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GreatePage MotionPageId:%d", MotionPageId); - for (i = 0; i < sizeof(g_pageMapper) / sizeof(g_pageMapper[0]); i++) { - if (g_pageMapper[i].id == MotionPageId) { - view = (this->*(g_pageMapper[i].func))(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GreatePage view:%p", view); - return view; - } - } - return nullptr; -} - } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/key/include/KeyInputListener.h b/code/sdk/application/wearable/nativeapp/nativeui/key/include/KeyInputListener.h index b9724f9dd..e7ca76f00 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/key/include/KeyInputListener.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/key/include/KeyInputListener.h @@ -25,8 +25,8 @@ private: void OnKeyPress(void); void OnKeyLongPress(const KeyEvent& event); void OnKeyRelease(const KeyEvent& event); - void CallVolumeDipSwitchControl(uint8_t status); - void PlayerVolumeDipSwitchControl(uint8_t model); + void CallVolumeDipSwitchControl(VolumeChangeStatus status); + void PlayerVolumeDipSwitchControl(VolumeChangeStatus status); private: int32 pressFlag{0}; int32 longPressFlag{0}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/key/src/KeyInputListener.cpp b/code/sdk/application/wearable/nativeapp/nativeui/key/src/KeyInputListener.cpp index d70e6337e..877ad1b38 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/key/src/KeyInputListener.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/key/src/KeyInputListener.cpp @@ -8,7 +8,6 @@ #include "KeyInputListener.h" #include "common/key_code.h" #include "AppViewIDs.h" -#include "components/ui_label_ext.h" #include "View.h" #include "MainViewSample.h" #include "wearable_log.h" @@ -75,7 +74,7 @@ void KeyInputListener::OnKeyLongPress(const KeyEvent& event) return; } -void KeyInputListener::CallVolumeDipSwitchControl(uint8_t model) +void KeyInputListener::CallVolumeDipSwitchControl(VolumeChangeStatus status) { if (MainCallingPresenter::GetInstance() != nullptr && CallerLogModel::GetInstance()->GetCallStatus()) { if (CallerLogModel::GetInstance()->GetVolumeScreenStatus() == true) { @@ -83,7 +82,7 @@ void KeyInputListener::CallVolumeDipSwitchControl(uint8_t model) if (volumeSliderEventListener == nullptr) { return; } - volumeSliderEventListener->ChangeVolume(model); + volumeSliderEventListener->ChangeVolume(status); } else { MainCallingPresenter::GetInstance()->HonrsViewChange(); CallerLogModel::GetInstance()->SetVolumeScreenStatus(true); @@ -95,7 +94,7 @@ void KeyInputListener::CallVolumeDipSwitchControl(uint8_t model) if (volumeSliderEventListener == nullptr) { return; } - volumeSliderEventListener->ChangeVolume(model); + volumeSliderEventListener->ChangeVolume(status); } else { HonrsViewChange(); NotificationManager::GetInstance()->SetVolumeScreenStatus(true); @@ -111,7 +110,7 @@ void KeyInputListener::OnKeyRelease(const KeyEvent& event) if (longPressFlag == 0 && pressFlag == 1) { // 短按电源键 if (currentViewId == VIEW_MAEKPHONE_SAMPLE || IsCallingNotify() == true) { // 音量卡片 // 音量+ - CallVolumeDipSwitchControl(1); + CallVolumeDipSwitchControl(VOLUMEUP); } else if (currentViewId != VIEW_MAIN_SAMPLE) { // 主表盘 PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面 NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TRANSITION_ZOOM); @@ -128,7 +127,7 @@ void KeyInputListener::OnKeyRelease(const KeyEvent& event) if (longPressFlag == 0 && pressFlag == 1) { // 短按功能键 if (currentViewId == VIEW_MAEKPHONE_SAMPLE || IsCallingNotify() == true) { // 音量卡片 // 音量- - CallVolumeDipSwitchControl(0); + CallVolumeDipSwitchControl(VOLUMEDOWN); } else { // 切换到用户配置的快捷卡片 } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParser.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParser.h new file mode 100644 index 000000000..dc737236f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParser.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 CompanyNameMagicTag. + * 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. + */ +#ifndef GRAPHIC_LITE_DIAL_BIN_PARSER_H +#define GRAPHIC_LITE_DIAL_BIN_PARSER_H +#include +#include +#include "graphic_types.h" +#include "DialViewGroup.h" +#include "DialBinTypes.h" +#include "components/ui_abstract_progress.h" + +namespace OHOS { +class DialBinParser { +public: + static DialBinParser* GetInstance(void); + bool UpdateDial(const std::string& file, FILE* fp, DialViewGroup* group); + bool GetDialPreviewInfo(FILE* fp, DialPreviewInfo* info); + +protected: + int32_t ParseDialHeader(FILE* file); + int32_t ParserDialStaticImg(FILE* fp); + int32_t ParserDialSequenceImg(FILE* fp); + int32_t ParserDialRotateImg(FILE* fp); + int32_t ParserDialOptionImg(FILE* fp); + int32_t ParserDialDigitalImg(FILE* fp); + int32_t ParserDialLabel(FILE* fp); + int32_t ParserDialArcLabel(FILE* fp); + int32_t ParserDialBoxProgress(FILE* fp); + int32_t ParserDialArcProgress(FILE* fp); + int32_t ParserDialVideo(FILE* fp); + int32_t ParserDialClick(FILE* fp); + int32_t ParserDialKaleidoscope(FILE* fp); + +private: + DialBinParser(); + virtual ~DialBinParser(); + void* MallocAndReadBuf(FILE* file, uint32_t readSize); + bool SetProgressType(FILE* fp, UIAbstractProgress* view, DialProgressType data); + + static constexpr uint8_t DIAL_BIN_PARSER_FUNC_NUM = 12; // 12: func max value + int32_t (DialBinParser::*funcArray_[DIAL_BIN_PARSER_FUNC_NUM])(FILE*); + + DialViewGroup* dialGroup_ = nullptr; + std::string file_; + uint32_t dirId_ = 0xfef << 20; // 20: offset + uint32_t imageOffset_ = 0; +}; +} +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinTypes.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinTypes.h new file mode 100644 index 000000000..1f8f49375 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinTypes.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2023 CompanyNameMagicTag. + * 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. + */ +#ifndef GRAPHIC_LITE_DIAL_BIN_TYPE_H +#define GRAPHIC_LITE_DIAL_BIN_TYPE_H +#include "color.h" +#include "graphic_types.h" +#include "components/ui_canvas_ext.h" + +namespace OHOS { +static constexpr uint8_t DIAL_NAME_MAX_LEN = 16; +static constexpr uint8_t DIAL_VERSION_MAX_LEN = 16; +static constexpr uint8_t DIAL_DESCRIPTION_MAX_LEN = 128; +static constexpr uint8_t DIAL_DIGITALIMG_IMG_MAX_NUM = 10; + +struct DialPreviewInfo { + char dialName[DIAL_NAME_MAX_LEN]; + char description[DIAL_DESCRIPTION_MAX_LEN]; + uint32_t imgId; + uint32_t offset; +}; + +struct DialRect { + int16_t x; + int16_t y; + int16_t w; + int16_t h; +}; + +struct DialHeader { + char dialName[DIAL_NAME_MAX_LEN]; + int16_t width; + int16_t height; + char version[DIAL_VERSION_MAX_LEN]; + uint16_t previewImgId; + char description[DIAL_DESCRIPTION_MAX_LEN]; + uint32_t imageOffset; + uint8_t freq; + uint8_t dialViewCount; +}; + +struct DialStaticImg { + Point pos; + Point center; + float rotate; + uint16_t imgId; +}; + +struct DialSequenceImg { + Point pos; + uint16_t interval; + bool repeat; + uint8_t imgNum; +}; + +struct DialRotateImg { + Point pos; + Point center; + int16_t rotateStart; + int16_t rotateEnd; + uint16_t imgId; + int16_t bindData; + bool isPeriod; +}; + +struct DialOptionImg { + Point pos; + int16_t bindData; + bool isPeriod; + uint8_t count; +}; + +struct DialDigitalImg { + uint8_t alignType : 4; + uint8_t integerLength : 4; + uint8_t decimalPrecision; + uint16_t imgIds[DIAL_DIGITALIMG_IMG_MAX_NUM]; + int16_t signImgId; + int16_t decimalPointImgId; + uint16_t space; + Point alignPosition; + int16_t bindData; + bool isPeriod; +}; + +struct DialLabel { + uint8_t breakMode; + uint8_t align; + uint8_t fontSize; + bool isPeriod; + DialRect rect; + uint32_t color; + char fontName[64]; + char text[64]; + int16_t bindData; +}; + +struct DialArcLabel { + uint8_t align; + uint8_t fontSize; + Point center; + int16_t radius; + int16_t rotateStart; + int16_t rotateEnd; + uint32_t color; + char fontName[64]; + char text[64]; + int16_t bindData; + bool isPeriod; +}; + +struct DialProgressType { + uint8_t type; // image | color | gradient_color + DialRect rect; + union { + uint8_t stopCount; + uint16_t imgId; + Color32 color; + }; +}; + +struct DialBoxProgress { + uint8_t cap; + uint8_t direction; + bool isPeriod; + int16_t bindData; + uint32_t bgColor; + DialProgressType typeData; +}; + +struct DialArcProgress { + uint8_t cap; + bool isPeriod; + uint16_t radius; + uint16_t startAngle; + uint16_t endAngle; + uint16_t lineWidth; + int16_t bindData; + uint32_t bgColor; + DialProgressType typeData; +}; + +struct DialVideo { + DialRect rect; + uint32_t offset; + Color32 colorKey; +}; + +struct DialClick { + uint8_t type; + DialRect rect; + union { + uint32_t sliceId; + char bundleName[64]; + }; +}; + +struct DialKaleidoscope { + uint16_t imgId; + float crownRotateStep; + float animatorRotateStep; +}; +} +#endif // GRAPHIC_LITE_DIAL_BIN_TYPE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainModel.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainModel.h new file mode 100644 index 000000000..6bc09a099 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainModel.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef MAIN_MODEL_H +#define MAIN_MODEL_H + +#include +#include "UiConfig.h" + +namespace OHOS { + typedef struct { + CardId id; + const char *cardImg; + } CardInfo; + + typedef struct { + DialId id; + const char *dialName; + const char *dialImg; + uint8_t freq; + } DialInfo; + + typedef struct { + uint8_t dialFlag; + uint8_t dialId; + std::string dialFullName; + } DialSetting; + + class MainModel { + public: + static MainModel &GetInstance(void); + void InitCardSettings(void); + uint8_t GetCardSettingCount(void); + CardId *GetCardSettings(void); + void DeleteCardSetting(uint8_t index); + void AddCardSetting(uint8_t index); + const CardInfo *GetCardInfo(CardId card) const; + const DialInfo *GetDialInfo(DialId dial) const; + void AddDialSetting(const DialSetting &setting); + void InitDialSettings(void); + DialSetting &GetDialSetting(); + private: + void InitDialSettingDefault(void); + MainModel(); + MainModel(const MainModel &); + MainModel &operator=(const MainModel &); + virtual ~MainModel(); + + CardId cardSettings[CARD_SETTING_COUNT_MAX] = { MAX_CARD }; + uint8_t cardSettingCount{0}; + DialSetting dialSetting; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h index 1feb8bcaa..08fc301b0 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h @@ -14,6 +14,7 @@ #include "KeyInputListener.h" #include "drag_event.h" #include "MainViewSample.h" +#include "MainModel.h" #include "components/ui_swipe_view.h" #include "components/ui_view.h" #include "CompassView.h" @@ -41,7 +42,7 @@ constexpr uint16_t HORIZONTAL_STATUS = 0; class MainViewSample; class MainPresenterSample : public Presenter, public ModelListenerSample, public UIView::OnClickListener, public UISwipeView::OnSwipeListener, - public UISwipeView, public CompassPresenter { + public UIView::OnLongPressListener, public UISwipeView, public CompassPresenter { public: MainPresenterSample(); virtual ~MainPresenterSample(); @@ -53,24 +54,20 @@ public: void OnStop() override; virtual void Notify() override; bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnLongPress(UIView& view, const LongPressEvent& event) override; virtual void OnSwipe(UISwipeView& view) override; void SetPage(int8_t id); - void SetTaskPeroid(int page); + void SetTaskPeroid(CardId cardId); void setCallback(ZoomEffect* callback) { callback_ = callback; } - void SetDialPath(std::string filePath) - { - filePath_ = filePath; - } - - std::string GetDialPath() - { - return filePath_; - } - + void InitCardSettings(void); + uint8_t GetCardSettingCount(void); + CardId *GetCardSettings(void); + void InitDialSettings(void); + DialSetting& GetDialSetting(); private: void ProcessDataNotify(void); void SetCircleProgress(void); @@ -82,7 +79,6 @@ private: int64_t playerMusicDuration_{0}; int64_t playerProgressValue_{0}; bool isCompassSensorOpened_{false}; - std::string filePath_; }; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h index 7c0e55d26..243a5db3a 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h @@ -21,17 +21,15 @@ #include "ScreenModels.h" #include "ActivityWeekView.h" #include "CompassControlView.h" -#if USE_OFFLINE_DIAL #include "DialViewGroup.h" -#else #include "MainClockView.h" -#endif #include "PlayersView.h" #include "MainPresenterSample.h" #include "HeartRateView.h" #include "components/ui_card_page.h" #include "PullUpDownView.h" #include "components/ui_cross_view.h" +#include "SetCardModel.h" namespace OHOS { class MainPresenterSample; @@ -51,11 +49,7 @@ public: UICardPage *InitMusicPlayerPage(void); void AnimatorStart(int pageIndex); void AnimatorStop(void); - uint16_t GetHorCurrentPage() const - { - return mainSwipeGroup->GetCurrentPageId(UISwipeView::HORIZONTAL); // 0: horizontal; 1: vertical - } - + CardId GetHorCurrentCard() const; UIView* GetMainViewGroup(void) const { return mainSwipeGroup; @@ -82,11 +76,7 @@ private: PullUpDownView *dropDownView{nullptr}; UICardPage *messageView{nullptr}; UILabel *messageLable{nullptr}; -#if USE_OFFLINE_DIAL - DialViewGroup *mainClockView{nullptr}; -#else - MainClockView *mainClockView{nullptr}; -#endif + UICardPage *mainClockView{nullptr}; ActivityWeekView *activityWeekView{nullptr}; PlayersView *playersView{nullptr}; CompassControlView *compassControlView{nullptr}; @@ -100,6 +90,8 @@ private: void VerticalViewInit(void); void VertViewLoad(void); void HorViewLoad(void); + UICardPage *InitWathOffDial(DialSetting &setting); + UICardPage *InitWathDial(DialSetting &setting); }; } // namespace OHOS #endif // MAIN_VIEW_SAMPLE_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingPresenter.h index 26cc09892..f18dac441 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingPresenter.h @@ -28,8 +28,8 @@ typedef enum : uint16_t { } VolumeFactor; typedef enum : uint8_t { - VOLUMELOWERS = 0, - VOLUMELEVATED = 1, + VOLUMEDOWN = 0, + VOLUMEUP = 1, VOLUMEDRAG = 2, } VolumeChangeStatus; @@ -42,8 +42,7 @@ public: static VolumeSliderEventListener *GetInstance(); void OnChange(int32_t progress) override; void OnRelease(int32_t progress) override; - void ChangeImage(void); - void ChangeVolume(uint8_t status); + void ChangeVolume(VolumeChangeStatus status); bool OnClick(UIView& view, const ClickEvent& event) override; bool OnDrag(UIView& view, const DragEvent& event) override; void SetPlayerCoefficients(int16_t value); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialKaleidoscopeView.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialKaleidoscopeView.h new file mode 100644 index 000000000..f73c2b817 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialKaleidoscopeView.h @@ -0,0 +1,11 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +#ifndef DIAL_KALEIDOSCOPE_VIEW_H +#define DIAL_KALEIDOSCOPE_VIEW_H +#include "components/ui_kaleidoscope_view.h" +namespace OHOS{ +using DialKaleidoscopeView = UIKaleidoscopeView; +} +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainModel.cpp new file mode 100644 index 000000000..53a0dd307 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainModel.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "unistd.h" +#include "MainModel.h" +#include "kv_store.h" +#include "securec.h" +#include "wearable_log.h" + +namespace OHOS { + static const int CARD_SETTING_VALUE_LEN = 32; + static const int DIAL_SETTING_VALUE_LEN = 64; + const CardInfo cardInfoMap[] = { + { HEART_RATE, PNG_SET_CARD_HEART }, + { COMPASS, PNG_SET_CARD_COMPASS }, + { ACTIVITY, PNG_SET_CARD_ACTIVITY }, + { MUSIC_PLAYER, PNG_SET_CARD_PLAYER }, + }; + + const DialInfo dialInfoMap[] = { + { DIAL_CLOCK, "扫秒表盘", PNG_SET_DIAL_CLOCK, DEFAULT_TASK_PERIOD }, + }; + + MainModel::MainModel() {} + + MainModel::~MainModel() {} + + MainModel &MainModel::GetInstance() + { + static MainModel instance; + return instance; + } + + const CardInfo *MainModel::GetCardInfo(CardId card) const + { + for (uint8_t i = 0; i < (sizeof(cardInfoMap) / sizeof(cardInfoMap[0])); i++) { + if (card == cardInfoMap[i].id) { + return &cardInfoMap[i]; + } + } + return nullptr; + } + + const DialInfo *MainModel::GetDialInfo(DialId dialId) const + { + for (uint8_t i = 0; i < (sizeof(dialInfoMap) / sizeof(dialInfoMap[0])); i++) { + if (dialId == dialInfoMap[i].id) { + return &dialInfoMap[i]; + } + } + return nullptr; + } + + void MainModel::InitCardSettings(void) + { + char temp[CARD_SETTING_VALUE_LEN] = { 0 }; + int len; + int index = 0; + + memset_s(cardSettings, CARD_SETTING_COUNT_MAX, 0, CARD_SETTING_COUNT_MAX); + len = UtilsGetValue("card_setting", temp, CARD_SETTING_VALUE_LEN); + if (len >= 0) { + /* 读取用户card配置 */ + char *setBuffer = nullptr; + char *setValue = strtok_s(temp, ",", &setBuffer); + while (setValue != nullptr) { + if (index >= CARD_SETTING_COUNT_MAX) { + break; + } + cardSettings[index++] = (CardId)atoi(setValue); + setValue = strtok_s(nullptr, ",", &setBuffer); + } + cardSettingCount = index; + } else { + /* 使用默认card配置 */ + cardSettings[index++] = WATCH_FACE; + cardSettings[index++] = HEART_RATE; + cardSettings[index++] = COMPASS; + cardSettings[index++] = ACTIVITY; + cardSettings[index++] = MUSIC_PLAYER; + cardSettingCount = index; + } + } + + void MainModel::DeleteCardSetting(uint8_t index) + { + char temp[CARD_SETTING_VALUE_LEN] = { 0 }; + for (uint8_t i = 0; i < cardSettingCount; i++) { + if (i == index + 1) { + uint8_t j = i; + for (; j < cardSettingCount - 1; j++) { + cardSettings[j] = cardSettings[j + 1]; + } + cardSettings[j] = MAX_CARD; + cardSettingCount--; + } + } + + for (uint8_t i = 0; i < cardSettingCount; i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardSettings[%d] = %d", i, cardSettings[i]); + (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[i]); + } + (void)UtilsSetValue("card_setting", temp); + } + + void MainModel::AddCardSetting(uint8_t index) + { + char temp[CARD_SETTING_VALUE_LEN] = { 0 }; + if (cardSettingCount >= CARD_SETTING_COUNT_MAX) { + return; + } + for (int i = 0; i < cardSettingCount; i++) { + if (cardSettings[i] == cardInfoMap[index].id) { + return; + } + } + cardSettings[cardSettingCount++] = cardInfoMap[index].id; + for (uint8_t i = 0; i < cardSettingCount; i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardSettings[%d] = %d", i, cardSettings[i]); + (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[i]); + } + (void)UtilsSetValue("card_setting", temp); + } + + uint8_t MainModel::GetCardSettingCount(void) + { + return cardSettingCount; + } + + CardId *MainModel::GetCardSettings(void) + { + return cardSettings; + } + + void MainModel::InitDialSettingDefault(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitDialSettingDefault"); + dialSetting.dialFlag = 0; + dialSetting.dialId = DIAL_CLOCK; + dialSetting.dialFullName = ""; + } + + void MainModel::AddDialSetting(const DialSetting &setting) + { + std::string tmp; + tmp += std::to_string(setting.dialFlag); + tmp += ","; + tmp += std::to_string(setting.dialId); + tmp += ","; + tmp += setting.dialFullName; + tmp += ","; + (void)UtilsSetValue("dial_setting", tmp.c_str()); + } + + void MainModel::InitDialSettings(void) + { + char temp[DIAL_SETTING_VALUE_LEN] = { 0 }; + int len; + len = UtilsGetValue("dial_setting", temp, DIAL_SETTING_VALUE_LEN); + if (len >= 0) { + char *setBuffer = nullptr; + char *setValue = strtok_s(temp, ",", &setBuffer); + if (setValue != nullptr) { + dialSetting.dialFlag = atoi(setValue); + } else { + InitDialSettingDefault(); + return; + } + + setValue = strtok_s(nullptr, ",", &setBuffer); + if (setValue != nullptr) { + dialSetting.dialId = atoi(setValue); + } else { + InitDialSettingDefault(); + return; + } + + setValue = strtok_s(nullptr, ",", &setBuffer); + if (setValue != nullptr) { + dialSetting.dialFullName = setValue; + if (!((dialSetting.dialFullName.length() > 0) && + (access(dialSetting.dialFullName.c_str(), F_OK) == 0))) { + InitDialSettingDefault(); + return; + } + } else { + InitDialSettingDefault(); + return; + } + } else { + InitDialSettingDefault(); + } + } + + DialSetting& MainModel::GetDialSetting() + { + return dialSetting; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp index e3ad3fdab..0cef9ed5e 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp @@ -23,9 +23,7 @@ #include "ModelDialDataFactory.h" #include "PresenterTask.h" #include "DialModelTime.h" -#if USE_OFFLINE_DIAL #include "DialViewGroup.h" -#endif #include "ui_service.h" namespace OHOS { @@ -133,6 +131,21 @@ bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event) return true; } +bool MainPresenterSample::OnLongPress(UIView& view, const LongPressEvent& event) +{ + UNUSED(event); + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress"); + uint8_t cardId = view_->GetHorCurrentCard(); + if (cardId != WATCH_FACE ) { + SetCardModel::GetInstance().SetSelectedCard(cardId); + NativeAbility::GetInstance().ChangeSlice(VIEW_SET_CARD); + } else { + NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL); + } + return true; +} + void MainPresenterSample::SetPage(int8_t id) { if (view_ != nullptr) { @@ -140,18 +153,20 @@ void MainPresenterSample::SetPage(int8_t id) } } -void MainPresenterSample::SetTaskPeroid(int page) +void MainPresenterSample::SetTaskPeroid(CardId cardId) { - if (page == COMPASS) { + if (cardId == COMPASS) { PresenterTask::GetInstance()->SetPeriod(DEFAULT_TASK_PERIOD); - } else if (page == WATCH_FACE) { -#if USE_OFFLINE_DIAL - uint32_t time = dynamic_cast(view_->GetViewById(WATCH_FACE))->GetPeriod(); -#else - uint32_t time = DEFAULT_TASK_PERIOD; -#endif + } else if (cardId == WATCH_FACE) { + uint32_t time; + DialSetting &setting = GetDialSetting(); + if (setting.dialFlag) { + time = dynamic_cast(view_->GetViewById(WATCH_FACE))->GetPeriod(); + } else { + time = DEFAULT_TASK_PERIOD; + } PresenterTask::GetInstance()->SetPeriod(time); - } else if (page == MUSIC_PLAYER) { + } else if (cardId == MUSIC_PLAYER) { PresenterTask::GetInstance()->SetPeriod(PLAYER_PERIOD); } else { PresenterTask::GetInstance()->SetPeriod(MAX_PERIOD); @@ -161,10 +176,10 @@ void MainPresenterSample::SetTaskPeroid(int page) void MainPresenterSample::OnSwipe(UISwipeView &view) { UNUSED(view); - int page = view_->GetHorCurrentPage(); + CardId cardId = view_->GetHorCurrentCard(); callback_->OnSwipe(view); - SetTaskPeroid(page); - if (page == COMPASS) { + SetTaskPeroid(cardId); + if (cardId == COMPASS) { if (!isCompassSensorOpened_) { CompassModel::GetInstance()->OpenCompassSensor(); isCompassSensorOpened_ = true; @@ -205,6 +220,12 @@ void MainPresenterSample::SetCircleProgress() } state_ = playersView->GetPlayerButtonState(); if (state_ == UICheckBox::UICheckBoxState::SELECTED) { + int32_t playerState; + PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); + if (playerState != PLAYER_STARTED) { + playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + return; + } PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_); PlayersModel::GetInstance()->GetDuration(playerMusicDuration_); if (playerMusicDuration_ != 0) { @@ -229,18 +250,44 @@ void MainPresenterSample::SetCompassRotate() void MainPresenterSample::Notify(void) { - if (view_->GetHorCurrentPage() == COMPASS) { + CardId cardId = view_->GetHorCurrentCard(); + if (cardId == COMPASS) { SetCompassRotate(); - } else if (view_->GetHorCurrentPage() == MUSIC_PLAYER) { + } else if (cardId == MUSIC_PLAYER) { SetCircleProgress(); - } else if (view_->GetHorCurrentPage() == WATCH_FACE) { -#if USE_OFFLINE_DIAL - DialModelTime::GetInstance()->UpdateTime(); - dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData(); -#else - dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateTime(); -#endif + } else if (cardId == WATCH_FACE) { + DialSetting &setting = GetDialSetting(); + if (setting.dialFlag) { + DialModelTime::GetInstance()->UpdateTime(); + dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData(); + } else { + dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateTime(); + } } } +void MainPresenterSample::InitCardSettings(void) +{ + MainModel::GetInstance().InitCardSettings(); +} + +uint8_t MainPresenterSample::GetCardSettingCount(void) +{ + return MainModel::GetInstance().GetCardSettingCount(); +} + +CardId *MainPresenterSample::GetCardSettings(void) +{ + return MainModel::GetInstance().GetCardSettings(); +} + +void MainPresenterSample::InitDialSettings(void) +{ + return MainModel::GetInstance().InitDialSettings(); +} +DialSetting& MainPresenterSample::GetDialSetting() +{ + return MainModel::GetInstance().GetDialSetting(); +} + } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp index 6be82a687..b540ca6e3 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp @@ -22,7 +22,7 @@ struct MainViewMapper { UICardPage *(MainViewSample::*func)(void); }; -static const MainViewMapper PageMapper[] = { +static const MainViewMapper CardMapper[] = { {WATCH_FACE, &MainViewSample::InitWatchFacePage}, {HEART_RATE, &MainViewSample::InitHeartRatePage}, {COMPASS, &MainViewSample::InitCompassPage}, @@ -92,6 +92,11 @@ MainViewSample::~MainViewSample() compassControlView = nullptr; } + if (callback != nullptr) { + delete callback; + callback = nullptr; + } + g_pMainView = nullptr; } @@ -138,31 +143,44 @@ void MainViewSample::OnStart() bool MainViewSample::HorizontalViewInit(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::HorizontalViewInit"); - UISwipeView::OnSwipeListener *listener = nullptr; - - for (int16_t i = 0; i < MAX_CARD; i++) { - recordCard[i] = (this->*(PageMapper[i].func))(); - if (recordCard[i] == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainViewSample:: recordCard %d error", i); - return false; + presenter_->InitDialSettings(); + presenter_->InitCardSettings(); + uint8_t cardSettingNum = presenter_->GetCardSettingCount(); + CardId *cardSettings = presenter_->GetCardSettings(); + uint8_t cardMapNumber = sizeof(CardMapper) / sizeof(CardMapper[0]); + for (int16_t i = 0; i < cardSettingNum; i++) { + for (uint8_t j = 0; j < cardMapNumber; j++) { + if (cardSettings[i] == CardMapper[j].id) { + recordCard[j] = (this->*(CardMapper[j].func))(); + if (recordCard[j] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MainViewSample:: recordCard %d error", j); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "MainViewSample:: recordCard[%d]:%p", j, recordCard[j]); + break; + } } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample:: recordCard[%d]:%p", i, recordCard[i]); - } - - listener = static_cast(MainPresenterSample::GetInstance()); - if (listener == nullptr) { - return false; } - MainPresenterSample::GetInstance()->setCallback(callback); - mainSwipeGroup->SetOnSwipeListener(listener); + presenter_->setCallback(callback); + mainSwipeGroup->SetOnSwipeListener(presenter_); + mainSwipeGroup->SetOnLongPressListener(presenter_); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitPage over"); return true; } void MainViewSample::HorViewLoad(void) { - for (int16_t i = 0; i < MAX_CARD; i++) { - mainSwipeGroup->HorAdd(recordCard[i]); + uint8_t cardSettingNum = presenter_->GetCardSettingCount(); + CardId *cardSettings = presenter_->GetCardSettings(); + for (int16_t i = 0; i < cardSettingNum; i++) { + CardId cardId = cardSettings[i]; + if (recordCard[cardId] != nullptr) { + mainSwipeGroup->HorAdd(recordCard[cardId]); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample:: HorViewLoad cardid = %d ViewIndex = %d", + cardId, recordCard[cardId]->GetViewIndex()); + } } } @@ -239,18 +257,31 @@ void MainViewSample::OnStop() return; } +UICardPage *MainViewSample::InitWathOffDial(DialSetting &setting) +{ + DialViewGroup *dial = new DialViewGroup(); + dial->SetDial(setting.dialFullName); + return dial; +} + +UICardPage *MainViewSample::InitWathDial(DialSetting &setting) +{ + switch (setting.dialId) { + case DIAL_CLOCK: + return new MainClockView(); + default: + return nullptr; + } +} + UICardPage *MainViewSample::InitWatchFacePage(void) { -#if USE_OFFLINE_DIAL - mainClockView = new DialViewGroup(); - std::string filePath = dynamic_cast(presenter_)->GetDialPath(); - if (filePath.size() == 0) { - filePath = RES_PATH"maomao.bin"; + DialSetting &setting = presenter_->GetDialSetting(); + if (setting.dialFlag) { + mainClockView = InitWathOffDial(setting); + } else { + mainClockView = InitWathDial(setting); } - mainClockView->SetDial(filePath); -#else - mainClockView = new MainClockView(); -#endif if (mainClockView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); @@ -299,7 +330,6 @@ UICardPage *MainViewSample::InitMusicPlayerPage(void) return playersView; } - void MainViewSample::SetPage(int16_t page) { if (mainSwipeGroup != nullptr) { @@ -307,17 +337,28 @@ void MainViewSample::SetPage(int16_t page) } if (presenter_ != nullptr) { - presenter_->SetTaskPeroid(page); + CardId *cardSettings = presenter_->GetCardSettings(); + /* page 与CardId 没有对应关系,需要一次转换 */ + presenter_->SetTaskPeroid(cardSettings[page]); } } bool MainViewSample::IsMainClockPage(void) { - if (mainSwipeGroup->GetCurrentPageId(0) == WATCH_FACE && + if (mainSwipeGroup->GetCurrentPageId(0) == mainClockView->GetViewIndex() && mainSwipeGroup->GetCurrentPageId(1) == 1) { // 0: horizontal; 1: vertical return true; } else { return false; } } + +CardId MainViewSample::GetHorCurrentCard() const +{ + CardId *cardSettings = presenter_->GetCardSettings(); + int pageId = mainSwipeGroup->GetCurrentPageId(UISwipeView::HORIZONTAL); // 0: horizontal; 1: vertical + /* pageId 与CardId 没有对应关系,需要一次转换 */ + return cardSettings[pageId]; +} + } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp index e35841c94..ca79d102f 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp @@ -16,8 +16,15 @@ #include "bts_avrcp_controller.h" #include "bts_avrcp_target.h" #include "notification_manager.h" +#include "BluetoothHeadsetEvent.h" +#include "bts_avrcp_controller.h" namespace OHOS { + +#ifdef __cplusplus +extern "C" { +#endif + static VolumeSliderEventListener *g_pVolumeSliderEventListener = nullptr; constexpr int16_t SOUND_CHANGE = 10; @@ -46,51 +53,18 @@ bool VolumeSliderEventListener::OnClick(UIView& view, const ClickEvent& event) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick OnClick"); if (strcmp(view.GetViewId(), INCREASE_BUTTON) == 0) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetIncreaseButton OnClick"); - ChangeVolume(VOLUMELEVATED); + ChangeVolume(VOLUMEUP); } else if (strcmp(view.GetViewId(), DECREASE_BUTTON) == 0) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetDecreaseButton OnClick"); - ChangeVolume(VOLUMELOWERS); + ChangeVolume(VOLUMEDOWN); } else if (strcmp(view.GetViewId(), VOLUME_PROGRESS) == 0) { - ChangeImage(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetDragButton OnClick"); ChangeVolume(VOLUMEDRAG); } return true; } -void VolumeSliderEventListener::ChangeImage() -{ - ImageInfo *image; - VolumeSettingView *volumeSettingView = VolumeSettingView::GetInstance(); - if (volumeSettingView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChangeImage:volumeSettingView new fail"); - return; - } - UISlider *progress = volumeSettingView->GetProgress(); - if (progress == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChangeImage:progress new fail"); - return; - } - UIButton *decrease = volumeSettingView->GetDecreaseButton(); - if (decrease == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChangeImage:decrease new fail"); - return; - } - - volumeSettingView->sounding = progress->GetValue(); - if (volumeSettingView->sounding == 0) { - image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUTE_BUTTON, PLAYER_IAMGES); - decrease->SetImageSrc(image, image); - // 刷新UI - decrease->Invalidate(); - } else { - image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_DECREASE_BUTTON, PLAYER_IAMGES); - decrease->SetImageSrc(image, image); - // 刷新UI - decrease->Invalidate(); - } -} - -void VolumeSliderEventListener::ChangeVolume(uint8_t status) +void VolumeSliderEventListener::ChangeVolume(VolumeChangeStatus status) { ImageInfo *image; VolumeSettingView *volumeSettingView = VolumeSettingView::GetInstance(); @@ -110,7 +84,7 @@ void VolumeSliderEventListener::ChangeVolume(uint8_t status) } preSound = volumeSettingView->sounding; - if (status == 1) { + if (status == VOLUMEUP) { volumeSettingView->sounding = progress->GetValue() + SOUND_CHANGE; if (volumeSettingView->sounding > VOLUME_MAX) { volumeSettingView->sounding = VOLUME_MAX; @@ -119,19 +93,45 @@ void VolumeSliderEventListener::ChangeVolume(uint8_t status) decrease->SetImageSrc(image, image); // 刷新UI decrease->Invalidate(); - } else if (status == 0) { + progress->SetValue(volumeSettingView->sounding); + } else if (status == VOLUMEDOWN) { volumeSettingView->sounding = progress->GetValue() - SOUND_CHANGE; if (volumeSettingView->sounding < VOLUME_MIN) { volumeSettingView->sounding = VOLUME_MIN; } + if (volumeSettingView->sounding == VOLUME_MIN && + (playerCoefficients == VOLUMEPHONE || playerCoefficients == VOLUMEPHONENOTIFY)) { + // 通话场景音量不能设置为0 + volumeSettingView->sounding = SOUND_CHANGE; + } if ((volumeSettingView->sounding == 0) && (preSound != 0)) { image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUTE_BUTTON, PLAYER_IAMGES); decrease->SetImageSrc(image, image); // 刷新UI decrease->Invalidate(); } + progress->SetValue(volumeSettingView->sounding); + } else if (status == VOLUMEDRAG) { + volumeSettingView->sounding = progress->GetValue(); + if (volumeSettingView->sounding == VOLUME_MIN && + (playerCoefficients == VOLUMEPHONE || playerCoefficients == VOLUMEPHONENOTIFY)) { + // 通话场景音量不能设置为0 + volumeSettingView->sounding = SOUND_CHANGE; + progress->SetValue(volumeSettingView->sounding); + } + if (volumeSettingView->sounding == 0) { + image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUTE_BUTTON, PLAYER_IAMGES); + decrease->SetImageSrc(image, image); + // 刷新UI + decrease->Invalidate(); + } else { + image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_DECREASE_BUTTON, PLAYER_IAMGES); + decrease->SetImageSrc(image, image); + // 刷新UI + decrease->Invalidate(); + } } - progress->SetValue(volumeSettingView->sounding); + if (playerCoefficients == VOLUMEPLAYERS) { BtAndLocalVolumeSet(volumeSettingView->sounding); } @@ -142,16 +142,22 @@ void VolumeSliderEventListener::ChangeVolume(uint8_t status) } } +extern BtAvrcpTgInf g_avrcp_srv_inf; void VolumeSliderEventListener::BtAndLocalVolumeSet(int16_t sounding) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtAndLocalVolumeSet %d", sounding); - AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 本地音量设置 + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtAndLocalVolumeSet %d", sounding); + if (g_avrcp_srv_inf.avrcp_srv_conn_stat == PROFILE_STATE_CONNECTED) { + uint8_t volume = sounding * AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100 / 100; // 100:本地音量最大值 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "volume 0x%x", volume); + (void)avrcp_ct_set_absolute_volume(&(g_avrcp_srv_inf.bd_addr), volume); // 手表音量设置同步远端BT音量 + } else { + AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 本地音量设置 + } } void VolumeSliderEventListener::OnRelease(int32_t value) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRelease %d", value); - ChangeImage(); ChangeVolume(VOLUMEDRAG); } @@ -163,7 +169,6 @@ void VolumeSliderEventListener::SetPlayerCoefficients(int16_t value) void VolumeSliderEventListener::OnChange(int32_t value) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnChange %d", value); - ChangeImage(); ChangeVolume(VOLUMEDRAG); } @@ -207,4 +212,7 @@ bool VolumeSliderEventListener::OnDrag(UIView& view, const DragEvent& event) } return true; } +#ifdef __cplusplus +} +#endif } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinParser.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinParser.cpp index 3316e9661..6e54b0a92 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinParser.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinParser.cpp @@ -29,6 +29,7 @@ #include "DialBoxProgressView.h" #include "DialArcProgressView.h" #include "DialArcLabelView.h" +#include "DialKaleidoscopeView.h" namespace OHOS { DialBinParser::DialBinParser() @@ -44,6 +45,7 @@ DialBinParser::DialBinParser() funcArray_[8] = &DialBinParser::ParserDialArcProgress; // 8: index funcArray_[9] = &DialBinParser::ParserDialVideo; // 9: index funcArray_[10] = &DialBinParser::ParserDialClick; // 10: index + funcArray_[11] = &DialBinParser::ParserDialKaleidoscope; // 11: index } DialBinParser::~DialBinParser() @@ -76,6 +78,39 @@ DialBinParser* DialBinParser::GetInstance(void) return &instance; } +bool DialBinParser::GetDialPreviewInfo(FILE* fp, DialPreviewInfo* info) +{ + if (fp == nullptr || info == nullptr) { + GRAPHIC_LOGE("Get dial preview fail, param error!\n"); + return false; + } + + DialHeader* dialHeader = static_cast(MallocAndReadBuf(fp, sizeof(DialHeader))); + if (dialHeader == nullptr) { + GRAPHIC_LOGE("[%s: %d]malloc or read fail!\n", __FUNCTION__, __LINE__); + return false; + } + + if (memcpy_s(info->dialName, DIAL_NAME_MAX_LEN, dialHeader->dialName, DIAL_NAME_MAX_LEN) != EOK) { + GRAPHIC_LOGE("[%s: %d]memcpy_s dial name fail!\n", __FUNCTION__, __LINE__); + free(dialHeader); + return false; + } + + if (memcpy_s(info->description, DIAL_DESCRIPTION_MAX_LEN, + dialHeader->description, DIAL_DESCRIPTION_MAX_LEN) != EOK) { + GRAPHIC_LOGE("[%s: %d]memcpy_s dial description fail!\n", __FUNCTION__, __LINE__); + free(dialHeader); + return false; + } + + info->imgId = dialHeader->previewImgId | dirId_; + info->offset = dialHeader->imageOffset; + + free(dialHeader); + return true; +} + bool DialBinParser::UpdateDial(const std::string& file, FILE* fp, DialViewGroup* group) { if (fp == nullptr) { @@ -340,8 +375,8 @@ int32_t DialBinParser::ParserDialDigitalImg(FILE* fp) fseek(fp, curReadPt, SEEK_SET); } - ImageInfo* numInfoArray[DIGITALIMG_IMG_MAX_NUM] = {}; - for (uint16_t i = 0; i < DIGITALIMG_IMG_MAX_NUM; i++) { + ImageInfo* numInfoArray[DIAL_DIGITALIMG_IMG_MAX_NUM] = {}; + for (uint16_t i = 0; i < DIAL_DIGITALIMG_IMG_MAX_NUM; i++) { resId = data->imgIds[i] | dirId_; curReadPt = ftell(fp); numInfoArray[i] = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, @@ -355,7 +390,7 @@ int32_t DialBinParser::ParserDialDigitalImg(FILE* fp) fseek(fp, curReadPt, SEEK_SET); } view->SetParent(dialGroup_); - view->SetNumRes(const_cast(numInfoArray), DIGITALIMG_IMG_MAX_NUM); + view->SetNumRes(const_cast(numInfoArray), DIAL_DIGITALIMG_IMG_MAX_NUM); dialGroup_->AddView(static_cast(data->bindData), view, data->isPeriod); UIFree(data); @@ -444,7 +479,11 @@ bool DialBinParser::SetProgressType(FILE* fp, UIAbstractProgress* view, DialProg fseek(fp, curReadPt, SEEK_SET); view->SetImage(foregroundInfo, nullptr); } else if (data.type == 1) { - view->SetForegroundStyle(STYLE_BACKGROUND_COLOR, data.color.full); + if (view->GetViewType() == UI_BOX_PROGRESS) { + view->SetForegroundStyle(STYLE_BACKGROUND_COLOR, data.color.full); + } else if (view->GetViewType() == UI_CIRCLE_PROGRESS) { + view->SetForegroundStyle(STYLE_LINE_COLOR, data.color.full); + } } else if (data.type == 2) { // 2: gradient ColorStop* stopArray = static_cast(MallocAndReadBuf(fp, (sizeof(ColorStop) * data.stopCount))); if (stopArray == nullptr) { @@ -567,4 +606,40 @@ int32_t DialBinParser::ParserDialClick(FILE* fp) return 0; } -} \ No newline at end of file + +int32_t DialBinParser::ParserDialKaleidoscope(FILE* fp) +{ + if (fp == nullptr) { + GRAPHIC_LOGE("Parser dial option image fail, file is nullptr!\n"); + return -1; + } + + DialKaleidoscope* data = static_cast(MallocAndReadBuf(fp, sizeof(DialKaleidoscope))); + if (data == nullptr) { + GRAPHIC_LOGE("[%s: %d]malloc or read fail!\n", __FUNCTION__, __LINE__); + return -1; + } + + DialKaleidoscopeView* view = new DialKaleidoscopeView(); + uint32_t resId = data->imgId | dirId_; + uint32_t curReadPt = ftell(fp); + ImageInfo* imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, + file_, fp, false, imageOffset_); + if (imgInfo == nullptr) { + GRAPHIC_LOGE("[%s: %d]load img fail! file: %s resId: %x\n", + __FUNCTION__, __LINE__, file_.c_str(), resId); + return false; + } + fseek(fp, curReadPt, SEEK_SET); + + view->SetSrc(imgInfo); + view->RequestFocus(); + view->SetRotateEventFactor(data->crownRotateStep); // 0.2: rotate event factor + view->SetRotateAnimatorValue(data->animatorRotateStep); // 0.1: rotate animator value + view->StartRotateAnimator(); + dialGroup_->AddView(view); + + UIFree(data); + return 0; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp index 07d41f3cf..a15639445 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp @@ -568,9 +568,6 @@ static void BtDisconnectedPro(void) PhoneServiceErrorCallback(ERROR_BT, PROFILE_STATE_DISCONNECTED); CallListInit(); - // 释放媒体资源 - PostGraphicEvent(AudioRelease); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtDisconnectedPro callState: %d", g_currCallState); if (g_currCallState == HFP_HF_CALL_STATE_INCOMING) { /* 处理呼入阶段,取消手表配对 */ @@ -732,7 +729,7 @@ static int GetCallLogFileSize(void) } // 添加通话进通话记录文件 -void AddToCallLog(CallLogInfo *info) +static void AddToCallLog(CallLogInfo *info) { FILE *fp = NULL; size_t ret; @@ -1245,7 +1242,7 @@ static void CallChangeActivePro(const hfp_hf_calls_info_t *call) if (phoneCall->operate == OPERATE_PHONE_ACTIVE) { // 发布电话接听事件,手表关闭来电通知 HfpIncomingEventPublish(TOPIC_EVENT_HFP_PHONE_ACTIVE, phoneCall->unitCalls); - } else if (phoneCall->operate == OPERATE_WATCH_ACTIVE) { + } else if (phoneCall->operate == OPERATE_WATCH_ACTIVE && g_scoFlag == HFP_SCO_STATE_CONNECTED) { // 发布手表接听事件,通知切换接听界面 HfpIncomingEventPublish(TOPIC_EVENT_HFP_WATCH_ACTIVE, phoneCall->unitCalls); } @@ -1453,37 +1450,34 @@ static void CallStateChanged(const bd_addr_t *bdAddr, const hfp_hf_calls_info_t } if (g_currCallNum == 0) { - PostGraphicEvent(AudioRelease); g_completeCallFlag = false; } } -static int g_hfpVolumeType; -static unsigned char g_hfpVolume; - -static void BtHfpVolumeChanged(void) +static void BtHfpVolumeChanged(int volumeType, unsigned char hfpVolume) { - int maxVolume, minVolume, tmp; + int maxVolume, minVolume, volume; bool ret; // mic - if (g_hfpVolumeType == HFP_VOLUME_MIC) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BtHfpVolumeChanged] g_hfpVolumeType = %d, g_hfpVolume = %d ", - g_hfpVolumeType, g_hfpVolume); + if (volumeType == HFP_VOLUME_MIC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VolumeChanged Type = %d, hfpVolume = %d", + volumeType, hfpVolume); } // speak - if (g_hfpVolumeType == HFP_VOLUME_SPEAKER) { + if (volumeType == HFP_VOLUME_SPEAKER) { minVolume = PhoneAudioGetMinVolume(); maxVolume = PhoneAudioGetMaxVolume(); - tmp = g_hfpVolume * (maxVolume - minVolume) / CALL_VOLUME_MAX; // 转换 - - ret = PhoneAudioSetVolume(tmp); + volume = hfpVolume * (maxVolume - minVolume) / CALL_VOLUME_MAX; // 转换 + volume = (volume == 0) ? ((maxVolume - minVolume) / CALL_VOLUME_MAX) : volume; + ret = PhoneAudioSetVolume(volume); if (ret != true) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BtHfpVolumeChanged] g_hfpVolumeType: %d, ret: %d", g_hfpVolumeType, ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VolumeChanged Type: %d, ret: %d", + volumeType, ret); } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BtHfpVolumeChanged] g_hfpVolumeType: %d, minVolume: %d, maxVolume: %d tmp: %d\ - ret: %d ", g_hfpVolumeType, minVolume, maxVolume, tmp, ret); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VolumeChanged Type: %d, min: %d, max: %d volume: %d ret: %d", + volumeType, minVolume, maxVolume, volume, ret); } } @@ -1491,10 +1485,8 @@ static void BtHfpVolumeChanged(void) static void VolumeChanged(const bd_addr_t *bdAddr, hfp_volume_type_t type, unsigned char volume) { UNUSED(bdAddr); - g_hfpVolumeType = type; - g_hfpVolume = volume; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[VolumeChanged] type = %d volume = %d", type, volume); - PostGraphicEvent(BtHfpVolumeChanged); // 解决SdkMsgThread爆栈问题 + GraphicService::GetInstance()->PostGraphicEvent(std::bind(BtHfpVolumeChanged, type, volume)); } // 拨号失败回调 @@ -1794,71 +1786,53 @@ int GetCallInfoInCallList(PhoneCallInfo callList[], int listNum, int *retNum) return OHOS_SUCCESS; } -static unsigned char g_changeSpkVolume; - -static void GetCallCurrVolumeEvent(void) +// 获取当前通话音量大小 (0 - 15) +// hfp音量范围 0-15, media 音量范围 0-100 +unsigned char GetCallCurrVolume(void) { int volume; int minVolume; int maxVolume; - unsigned char tmp; + unsigned char hfpVolume; volume = PhoneAudioGetVolume(); minVolume = PhoneAudioGetMinVolume(); maxVolume = PhoneAudioGetMaxVolume(); - tmp = (unsigned char)((volume * CALL_VOLUME_MAX) / (maxVolume - minVolume)); // 转换 + hfpVolume = (unsigned char)((volume * CALL_VOLUME_MAX) / (maxVolume - minVolume)); // 转换 - if (volume != 0 && tmp == 0) { - tmp = 1; + if (volume != 0 && hfpVolume == 0) { + hfpVolume = 1; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallCurrVolumeEvent] volume = %d, minVolume = %d, maxVolume = %d, tmp = %d", - volume, minVolume, maxVolume, tmp); - g_changeSpkVolume = tmp; -} - -// 获取当前通话音量大小 (0 - 15) -unsigned char GetCallCurrVolume(void) -{ - GetCallCurrVolumeEvent(); - return g_changeSpkVolume; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallCurrVolume] volume = %d, minVolume = %d, maxVolume = %d, hfpVolume = %d", + volume, minVolume, maxVolume, hfpVolume); + return hfpVolume; } -static void SetSpeakerVolumeEvent(void) +void SetSpeakerVolume(unsigned char hfpVolume) { - int ret, minVolume, maxVolume, tmp; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] start, hfpVolume = %d", hfpVolume); + int ret, minVolume, maxVolume, volume; minVolume = PhoneAudioGetMinVolume(); maxVolume = PhoneAudioGetMaxVolume(); - tmp = g_changeSpkVolume * (maxVolume - minVolume) / CALL_VOLUME_MAX; // 转换 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolumeEvent] minVolume = %d, maxVolume = %d, tmp = %d", - minVolume, maxVolume, tmp); + volume = hfpVolume * (maxVolume - minVolume) / CALL_VOLUME_MAX; // 转换 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] minVolume = %d, maxVolume = %d, volume = %d", + minVolume, maxVolume, volume); - ret = PhoneAudioSetVolume(tmp); + ret = PhoneAudioSetVolume(volume); if (ret != true) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolumeEvent] PhoneAudioSetVolume ret = %d", ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] PhoneAudioSetVolume ret = %d", ret); return; } - ret = hfp_hf_set_volume(&g_bdAddr, HFP_VOLUME_SPEAKER, g_changeSpkVolume); + ret = hfp_hf_set_volume(&g_bdAddr, HFP_VOLUME_SPEAKER, hfpVolume); if (ret != ERRCODE_BT_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolumeEvent] hfp_hf_set_volume fail ret = %d, g_changeSpkVolume = %d", - ret, g_changeSpkVolume); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] set_volume fail ret = %d, hfpVolume = %d", + ret, hfpVolume); return; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolumeEvent] success!"); -} - -// 设置手表通话Speaker音量:0 - 15 -void SetSpeakerVolume(unsigned char volume) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] start, volume = %d", volume); - if (volume > CALL_VOLUME_MAX) { - g_changeSpkVolume = CALL_VOLUME_MAX; - } else { - g_changeSpkVolume = volume; - } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] success!"); - SetSpeakerVolumeEvent(); return; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp index cdafd264c..3a22d8c53 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp @@ -847,8 +847,6 @@ void PlayerInterruptListener::ResumePlayer(void) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerInterruptListener::ResumePlayer] this is in calling"); return; // 通话界面,禁止音乐恢复播放 } - AudioRelease(); // 适配某些机型不触发SCO - PlayerPostGraphicEvent(Resume); } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h index 78bab7b61..ffa8c36d0 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h @@ -12,41 +12,16 @@ #include "ui_image_view.h" namespace OHOS { -typedef enum { - WATCH_FACE = 0, - HEART_RATE, - COMPASS, - ACTIVITY, - MUSIC_PLAYER, - MAX_CARD, -} CardId; - - -struct CardInfo { - int16_t cardId; -}; - class ScreenModels { public: ScreenModels(); ~ScreenModels(); static ScreenModels *GetInstance(void); - // card funtion - bool SetUpListCase(void); - bool SaveCardConfig(void); - bool InitCardConfig(void); - void SetCardConfigDefault(void); - int16_t GetCardPage(uint16_t page); - bool CardInsertFirst(int32_t card); - bool CardDelete(int32_t card); - int16_t GetMaxCard(void); - int16_t GetLastCardPage(void); bool LoadAppImages(std::string file, UIImageView *view, uint32_t resId); void PreLoadAppimages(void); + void InitKvStorage(void); private: void LoadAppMultiImages(std::string file, uint32_t startId, uint32_t lastId); - List *listMainView{nullptr}; // record main view pages - int16_t maxPage = MAX_CARD; }; } #endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp index 082bfc43d..5eebb9819 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp @@ -11,6 +11,8 @@ #include "stdio.h" #include #include +#include "kvstore_env.h" +#include "kv_store.h" #include "ScreenModels.h" #include "common/image_cache_manager.h" #include "UiConfig.h" @@ -32,115 +34,10 @@ ScreenModels *ScreenModels::GetInstance(void) return &screenModel; } -bool ScreenModels::SetUpListCase(void) +void ScreenModels::InitKvStorage(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListCase"); - listMainView = new List(); - if (listMainView == nullptr) { - return false; - } - listMainView->Clear(); - return true; -} - -bool ScreenModels::InitCardConfig(void) -{ - if (SetUpListCase() == false) { - return false; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig1"); - int32_t fd = open(CARD_CONFIG_PATH, O_RDWR, S_IRWXU); - ListNode *node; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig2"); - struct CardInfo cardInfoData; - if (fd < 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig open fail"); - fd = open(CARD_CONFIG_PATH, O_RDWR | O_CREAT, S_IRWXU); - if (fd < 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig open fail 2"); - return false; - } - SetCardConfigDefault(); - node = listMainView->Begin(); - for (int32_t i = 0; i < maxPage; i++) { - cardInfoData = node->data_; - node = node->next_; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Init write cardInfoData.i:%d ", cardInfoData.cardId); - if (write(fd, &cardInfoData, sizeof(CardInfo)) != sizeof(CardInfo)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Init SaveGlobalHealthToFile fail"); - } - } - close(fd); - return true; - } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig3"); - for (int32_t i = 0; i < maxPage; i++) { - if (read(fd, &cardInfoData, sizeof(CardInfo)) != sizeof(CardInfo)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Init Read GlobalHealthToFile fail"); - } - listMainView->PushBack(cardInfoData); - } - close(fd); - return true; - } - return false; -} - -bool ScreenModels::SaveCardConfig(void) -{ - int32_t fd = open(CARD_CONFIG_PATH, O_RDWR | O_CREAT, S_IRWXU); - if (fd < 0) { - close(fd); - return false; - } else { - if (write(fd, &listMainView, listMainView->Size()) != listMainView->Size()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SaveGlobalHealthToFile fail"); - } - close(fd); - return true; - } -} - -void ScreenModels::SetCardConfigDefault(void) -{ - int16_t i; - struct CardInfo cardInfoData; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardConfigDefault"); - for (i = 0; i < MAX_CARD; i++) { - cardInfoData.cardId = i; - listMainView->PushBack(cardInfoData); - } -} - -int16_t ScreenModels::GetCardPage(uint16_t page) -{ - ListNode *node = listMainView->Begin(); - for (uint8_t i = 0; i < page; i++) { - if (node->next_ != NULL) { - node = node->next_; - } else { - return -1; - } - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetCardPage cardId:%d", node->data_.cardId); - return node->data_.cardId; -} - -int16_t ScreenModels::GetLastCardPage(void) -{ - ListNode *node = listMainView->Begin(); - for (uint8_t i = 0; i < MAX_CARD; i++) { - if (node->next_ == NULL) { - node = node->next_; - } - } - return node->data_.cardId; -} - -int16_t ScreenModels::GetMaxCard(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetMaxCard maxPage:%d", maxPage); - return maxPage; + int ret = UtilsSetEnv("/user"); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "UtilsSetEnv /user ret = %d", ret); } void ScreenModels::LoadAppMultiImages(std::string file, uint32_t startId, uint32_t lastId) diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardAdapter.h new file mode 100644 index 000000000..417891c87 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardAdapter.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardAdapter.h + * Author: + * Create: 2021-09-18 + */ + +#ifndef SET_CARD_ADAPTER_H +#define SET_CARD_ADAPTER_H + +#include +#include +#include "components/ui_list.h" +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/abstract_adapter.h" +#include "UiConfig.h" +#include "wearable_log.h" +#include "SetCardItem.h" + +namespace OHOS { +class SetCardAdapter : public AbstractAdapter { +public: + explicit SetCardAdapter(); + virtual ~SetCardAdapter(); + + virtual uint16 GetCount(void) override; + + virtual UIView *GetView(UIView *inView, int16 index) override; + + virtual void AddListItem(const CardInfo &item); + + void ClearItem(void); + +private: + std::list listData_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardDeleteView.h b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardDeleteView.h new file mode 100644 index 000000000..99b0c8c2a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardDeleteView.h @@ -0,0 +1,26 @@ +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: + * Author: + * Create: + */ + +#ifndef SET_CARD_DELETE_VIEW_H +#define SET_CARD_DELETE_VIEW_H + +#include "components/ui_label_button.h" +#include "SetCardPresenter.h" + +namespace OHOS { +class SetCardDeleteView : public UIViewGroup { +public: + SetCardDeleteView(SetCardPresenter *presenter); + virtual ~SetCardDeleteView(); + bool InitView(); +private: + SetCardPresenter *presenter_; + UILabelButton confirmBtn; + UILabelButton cancelBtn; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardItem.h b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardItem.h new file mode 100644 index 000000000..646f24fbf --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardItem.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardItem.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_CARD_ITEM_H +#define SET_CARD_ITEM_H + +#include +#include +#include "components/ui_view.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "MainModel.h" +#include "UiConfig.h" + +namespace OHOS { + +class SetCardItem :public UIViewGroup { +public: + SetCardItem(); + virtual ~SetCardItem(); + void SetItemInfo(const CardInfo &cardInfo); +private: + void SetUpChild(); + UIImageView cardImg_; + CardInfo cardInfo_; +}; + +} + +#endif // SET_CARD_ITEM_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardModel.h b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardModel.h new file mode 100644 index 000000000..43ed70b26 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardModel.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_CARD_MODEL_H +#define SET_CARD_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "SetCardPresenter.h" +#include "SetCardItem.h" + +namespace OHOS { + class SetCardModel { + public: + static SetCardModel &GetInstance(void); + uint8_t *GetCardShowList(void); + uint8_t GetCardShowCount(void) const; + void InitCardShowList(void); + void SetSelectedCardIndex(uint8_t cardIndex); + uint8_t GetSelectedCardIndex(void) const; + void DeleteCardSetting(void); + void SetSelectedCard(uint8_t cardId); + uint8_t GetSelectedCard(void); + private: + SetCardModel(); + SetCardModel(const SetCardModel &); + SetCardModel &operator=(const SetCardModel &); + virtual ~SetCardModel(); + + uint8_t cardShowList[CARD_SETTING_COUNT_MAX] = { 0 }; + uint8_t cardShowCount{0}; + uint8_t selectedCardIndex{0}; + uint8_t selectedCardId{MAX_CARD}; + }; +} + +#endif // SET_CARD_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardNoCardView.h b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardNoCardView.h new file mode 100644 index 000000000..16264fac7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardNoCardView.h @@ -0,0 +1,27 @@ +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: + * Author: + * Create: + */ + +#ifndef SET_CARD_NO_CARD_VIEW_H +#define SET_CARD_NO_CARD_VIEW_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "SetCardPresenter.h" + +namespace OHOS { +class SetCardNoCardView : public UIViewGroup { +public: + SetCardNoCardView(SetCardPresenter *presenter); + virtual ~SetCardNoCardView(); + bool InitView(); +private: + SetCardPresenter *presenter_; + UILabelButton addBtn; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardPresenter.h new file mode 100644 index 000000000..5c9b4e016 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardPresenter.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardPresenter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_CARD_PRESENTER_H +#define SET_CARD_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_list.h" +#include "components/ui_view.h" +#include "KeyInputListener.h" + +namespace OHOS { + +static const char *SET_CARD_ADD = "setcardadd"; +static const char *SET_CARD_DEL = "setcarddel"; +static const char *SET_CARD_DEL_CONFIRM = "setcarddelconfirm"; +static const char *SET_CARD_DEL_CANCEL = "setcarddelcancel"; + +class SetCardView; +class SetCardModel; +class SetCardPresenter : public Presenter, + public UIView::OnClickListener, + public ListScrollListener { +public: + SetCardPresenter(); + virtual ~SetCardPresenter(); + + virtual void OnStart() override; + virtual void OnResume() override; + virtual void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + virtual void OnScrollStart(int16_t index, UIView *view) override; + virtual void OnScrollEnd(int16_t index, UIView *view) override; + virtual void OnItemSelected(int16_t index, UIView* view) override; + void InitCardShowList(void); + uint8_t *GetCardShowList(void); + uint8_t GetCardShowCount(void) const; + void SetSelectedCard(uint8_t cardId); + uint8_t GetSelectedCard(void); +private: + KeyInputListener *keyActListenr{nullptr}; + SetCardModel *model{nullptr}; + +}; +} + +#endif // SET_CARD_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardView.h b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardView.h new file mode 100644 index 000000000..9c18e0d09 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardView.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardView.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_CARD_VIEW_H +#define SET_CARD_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +#include "window/window.h" +#include "BaseView.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "SetCardAdapter.h" +#include "SetCardModel.h" +#include "SetCardDeleteView.h" +#include "SetCardNoCardView.h" + +namespace OHOS { +class SetCardPresenter; + +class SetCardView : public View { +public: + SetCardView(); + virtual ~SetCardView(); + + static SetCardView *GetInstance() + { + static SetCardView instance; + return &instance; + } + + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + void ShowDeleteView(bool show); + void ShowAddView(bool show); + void RefreshCardList(void); +private: + void SetUpListInfo(void); + void SetUpListView(void); + void SetUpDeleteView(void); + void SetUpAddView(void); + void ShowCardListView(bool show); + UIImageView addImg_; + UIList contentList_; + UIImageView delImg_; + + SetCardDeleteView *deleteView_{nullptr}; + SetCardNoCardView *noCardView_{nullptr}; + SetCardAdapter *setCardAdapter_{nullptr}; + uint32_t scrollIndex_{0}; +}; +} +#endif // SET_CARD_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardAdapter.cpp new file mode 100644 index 000000000..4bce9dbb0 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardAdapter.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardAdapter.cpp + * Author: + * Create: 2021-09-18 + */ + +#include "SetCardAdapter.h" + +namespace OHOS { +SetCardAdapter::SetCardAdapter() {} + +SetCardAdapter::~SetCardAdapter() +{ + listData_.clear(); +} + +uint16 SetCardAdapter::GetCount(void) +{ + return listData_.size(); +} + +void SetCardAdapter::ClearItem(void) +{ + listData_.clear(); +} + +UIView *SetCardAdapter::GetView(UIView *inView, int16 index) +{ + if (index >= (int16)listData_.size() || index < 0) { + return nullptr; + } + + std::list::iterator it = listData_.begin(); + for (int i = 0; i < index; i++) { + it++; + } + + SetCardItem *item = nullptr; + if (inView == nullptr) { + item = new SetCardItem(); + if (item == nullptr) { + return nullptr; + } + } else { + item = static_cast(inView); + } + + item->SetItemInfo(*it); + item->SetViewIndex(index); + return item; +} + +void SetCardAdapter::AddListItem(const CardInfo &item) +{ + listData_.push_back(item); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardDeleteView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardDeleteView.cpp new file mode 100644 index 000000000..d957515c8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardDeleteView.cpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description. + * Author: + * Create: + */ + +#include "UiConfig.h" +#include +#include "cmsis_os.h" +#include "SetCardDeleteView.h" + +namespace OHOS { + +SetCardDeleteView::SetCardDeleteView(SetCardPresenter *presenter) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardDeleteView::SetCardDeleteView"); + presenter_ = presenter; + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + InitView(); + Add(&confirmBtn); + Add(&cancelBtn); +} + +SetCardDeleteView::~SetCardDeleteView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardDeleteView::~SetCardDeleteView"); + Remove(&confirmBtn); + Remove(&cancelBtn); +} + +bool SetCardDeleteView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardDeleteView::InitView"); + confirmBtn.SetPosition(184, 118); + confirmBtn.Resize(86, 50); + confirmBtn.SetViewId(SET_CARD_DEL_CONFIRM); + confirmBtn.SetText("删除"); + confirmBtn.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + confirmBtn.SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + confirmBtn.SetOnClickListener(presenter_); + + cancelBtn.SetPosition(186, 231); + cancelBtn.Resize(82, 50); + cancelBtn.SetViewId(SET_CARD_DEL_CANCEL); + cancelBtn.SetText("取消"); + cancelBtn.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + cancelBtn.SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + cancelBtn.SetOnClickListener(presenter_); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardItem.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardItem.cpp new file mode 100644 index 000000000..61b9c4989 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardItem.cpp @@ -0,0 +1,32 @@ +#include "SetCardItem.h" +#include "SetCardPresenter.h" +#include "wearable_log.h" + +namespace OHOS { + SetCardItem::SetCardItem() + { + SetPosition(0, 0, 454, 280); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + SetUpChild(); + Add(&cardImg_); + } + + SetCardItem::~SetCardItem() + { + Remove(&cardImg_); + } + + void SetCardItem::SetUpChild() + { + cardImg_.SetPosition(87, 0); + cardImg_.Resize(280, 280); + cardImg_.SetResizeMode(UIImageView::FILL); + cardImg_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + } + + void SetCardItem::SetItemInfo(const CardInfo &cardInfo) + { + cardInfo_ = cardInfo; + cardImg_.SetSrc(cardInfo.cardImg); + } +}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardModel.cpp new file mode 100644 index 000000000..32ca2b547 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardModel.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetCardModel.h" +#include "MainModel.h" +#include "kv_store.h" +#include "securec.h" + +namespace OHOS { + SetCardModel::SetCardModel() {} + + SetCardModel::~SetCardModel() {} + + SetCardModel &SetCardModel::GetInstance() + { + static SetCardModel instance; + return instance; + } + + void SetCardModel::InitCardShowList(void) + { + MainModel::GetInstance().InitCardSettings(); + uint8_t cardCount = MainModel::GetInstance().GetCardSettingCount(); + CardId *cardSettings = MainModel::GetInstance().GetCardSettings(); + cardShowCount = 0; + for (uint8_t i = 0; i < cardCount; i++) { + if (cardSettings[i] == WATCH_FACE) { + continue; + } + cardShowList[cardShowCount++] = cardSettings[i]; + } + } + + uint8_t *SetCardModel::GetCardShowList(void) + { + return cardShowList; + } + + uint8_t SetCardModel::GetCardShowCount(void) const + { + return cardShowCount; + } + + void SetCardModel::SetSelectedCardIndex(uint8_t cardIndex) + { + selectedCardIndex = cardIndex; + } + + uint8_t SetCardModel::GetSelectedCardIndex(void) const + { + return selectedCardIndex; + } + + void SetCardModel::DeleteCardSetting(void) + { + MainModel::GetInstance().DeleteCardSetting(selectedCardIndex); + } + + void SetCardModel::SetSelectedCard(uint8_t cardId) + { + selectedCardId = cardId; + } + + uint8_t SetCardModel::GetSelectedCard(void) + { + return selectedCardId; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardNoCardView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardNoCardView.cpp new file mode 100644 index 000000000..15cb462b6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardNoCardView.cpp @@ -0,0 +1,43 @@ +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description. + * Author: + * Create: + */ + +#include "UiConfig.h" +#include +#include "cmsis_os.h" +#include "SetCardNoCardView.h" + +namespace OHOS { + +SetCardNoCardView::SetCardNoCardView(SetCardPresenter *presenter) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardNoCardView::SetCardNoCardView"); + presenter_ = presenter; + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + InitView(); + Add(&addBtn); +} + +SetCardNoCardView::~SetCardNoCardView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardNoCardView::~SetCardNoCardView"); + Remove(&addBtn); +} + +bool SetCardNoCardView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardNoCardView::InitView"); + addBtn.SetPosition(184, 118); + addBtn.Resize(86, 50); + addBtn.SetViewId(SET_CARD_ADD); + addBtn.SetText("添加"); + addBtn.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + addBtn.SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + addBtn.SetOnClickListener(presenter_); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardPresenter.cpp new file mode 100644 index 000000000..f32df85a9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardPresenter.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardPresenter.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetCardView.h" +#include "SetCardModel.h" +#include "SetCardPresenter.h" + +namespace OHOS { + SetCardPresenter::SetCardPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SetCardPresenter"); + model = &SetCardModel::GetInstance(); + } + + SetCardPresenter::~SetCardPresenter() { + if (keyActListenr != nullptr) { + delete keyActListenr; + keyActListenr = nullptr; + } + } + + void SetCardPresenter::OnStart() + { + Presenter::OnStart(); + if (keyActListenr == nullptr) { + keyActListenr = new KeyInputListener(); + if (keyActListenr != nullptr) { + RootView::GetInstance()->SetOnKeyActListener(keyActListenr); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnStart: new KeyInputListener fail"); + } + } + } + + void SetCardPresenter::OnResume(void) + { + } + + void SetCardPresenter::OnStop(void) + { + RootView::GetInstance()->ClearOnKeyActListener(); + } + + bool SetCardPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::OnClick"); + if (strcmp(view.GetViewId(), SET_CARD_ADD) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SET_CARD_ADD"); + NativeAbility::GetInstance().ChangeSlice(VIEW_ADD_CARD); + } else if (strcmp(view.GetViewId(), SET_CARD_DEL) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SET_CARD_DEL"); + view_->ShowDeleteView(true); + } else if (strcmp(view.GetViewId(), SET_CARD_DEL_CONFIRM) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SET_CARD_DEL_CONFIRM"); + model->DeleteCardSetting(); + view_->ShowDeleteView(false); + view_->RefreshCardList(); + } else if (strcmp(view.GetViewId(), SET_CARD_DEL_CANCEL) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SET_CARD_DEL_CANCEL"); + view_->ShowDeleteView(false); + } + return true; + } + + void SetCardPresenter::OnScrollStart(int16_t index, UIView *view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::OnScrollStart index = %d", index); + return; + } + + void SetCardPresenter::OnScrollEnd(int16_t index, UIView *view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::OnScrollEnd index = %d", index); + if (view == nullptr) { + return; + } + model->SetSelectedCardIndex(index); + } + + void SetCardPresenter::OnItemSelected(int16_t index, UIView* view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::OnItemSelected index = %d", index); + if (view == nullptr) { + return; + } + } + void SetCardPresenter::InitCardShowList(void) + { + model->InitCardShowList(); + } + + uint8_t *SetCardPresenter::GetCardShowList(void) + { + return model->GetCardShowList(); + } + + uint8_t SetCardPresenter::GetCardShowCount(void) const + { + return model->GetCardShowCount(); + } + + void SetCardPresenter::SetSelectedCard(uint8_t cardId) + { + model->SetSelectedCard(cardId); + } + + uint8_t SetCardPresenter::GetSelectedCard(void) + { + return model->GetSelectedCard(); + } + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardView.cpp new file mode 100644 index 000000000..f18a1c8e4 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardView.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardView.cpp + * Author: + * Create: 2021-11-23 + */ + +#include +#include "SetCardView.h" +#include "SetCardPresenter.h" + +namespace OHOS { +SetCardView::SetCardView():contentList_(UIList::HORIZONTAL) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::SetCardView"); +} + +SetCardView::~SetCardView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::~SetCardView"); + if (deleteView_ != nullptr) { + delete deleteView_; + deleteView_ = nullptr; + } + + if (noCardView_ != nullptr) { + delete noCardView_; + noCardView_ = nullptr; + } + + if (setCardAdapter_ != nullptr) { + delete setCardAdapter_; + setCardAdapter_ = nullptr; + } +} + +void SetCardView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + setCardAdapter_ = new SetCardAdapter(); + SetUpListInfo(); + SetUpListView(); + SetUpDeleteView(); + SetUpAddView(); +} + +void SetCardView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::OnSetUpView"); + View::OnSetUpView(); + ShowDeleteView(false); + if (setCardAdapter_->GetCount() == 0) { + ShowAddView(true); + } +} + +void SetCardView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::OnTearDownView"); + View::OnTearDownView(); +} + +void SetCardView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::OnStop"); + View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } +} + +void SetCardView::SetUpListInfo(void) +{ + presenter_->InitCardShowList(); + uint8_t num = presenter_->GetCardShowCount(); + uint8_t *cardSettings = presenter_->GetCardShowList(); + uint8_t selectCardId = presenter_->GetSelectedCard(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListInfo::selectCardId = %u", selectCardId); + setCardAdapter_->ClearItem(); + for (uint8_t i = 0; i < num; i++) { + const CardInfo *info = MainModel::GetInstance().GetCardInfo( + static_cast(cardSettings[i])); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListInfo::%d %s", info->id, info->cardImg); + if (selectCardId == info->id) { + scrollIndex_ = i; + presenter_->SetSelectedCard(MAX_CARD); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListInfo::scrollIndex_ = %u", scrollIndex_); + } + setCardAdapter_->AddListItem(*info); + } +} + +void SetCardView::SetUpListView(void) +{ + addImg_.SetPosition(187, 10); + addImg_.Resize(80, 80); + addImg_.SetResizeMode(UIImageView::FILL); + addImg_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + addImg_.SetSrc(PNG_SET_CARD_ADD); + addImg_.SetViewId(SET_CARD_ADD); + addImg_.SetVisible(false); + + contentList_.SetPosition(0, 92); + contentList_.Resize(HORIZONTAL_RESOLUTION, 280); + contentList_.SetScrollBlankSize(HORIZONTAL_RESOLUTION / 2); + contentList_.SetSelectPosition(HORIZONTAL_RESOLUTION / 2); + contentList_.SetDraggable(true); + contentList_.SetThrowDrag(true); + contentList_.EnableAutoAlign(true); + contentList_.SetScrollStateListener(presenter_); + contentList_.SetMaxScrollDistance(1000); + contentList_.SetAdapter(setCardAdapter_); + contentList_.SetVisible(false); + contentList_.ScrollTo(scrollIndex_); + + delImg_.SetPosition(187, 374); + delImg_.Resize(80, 80); + delImg_.SetResizeMode(UIImageView::FILL); + delImg_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + delImg_.SetSrc(PNG_SET_CARD_DEL); + delImg_.SetViewId(SET_CARD_DEL); + delImg_.SetVisible(false); + + addImg_.SetTouchable(true); + addImg_.SetOnClickListener(presenter_); + delImg_.SetTouchable(true); + delImg_.SetOnClickListener(presenter_); + + container_->Add(&addImg_); + container_->Add(&contentList_); + container_->Add(&delImg_); +} + +void SetCardView::SetUpDeleteView(void) +{ + deleteView_ = new SetCardDeleteView(presenter_); + if (deleteView_ == nullptr) { + return; + } + deleteView_->SetVisible(false); + container_->Add(deleteView_); +} + +void SetCardView::SetUpAddView(void) +{ + noCardView_ = new SetCardNoCardView(presenter_); + if (noCardView_ == nullptr) { + return; + } + noCardView_->SetVisible(false); + container_->Add(noCardView_); +} + +void SetCardView::ShowCardListView(bool show) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::ShowCardListView %u", show); + if (show) { + addImg_.SetVisible(true); + contentList_.SetVisible(true); + delImg_.SetVisible(true); + } else { + addImg_.SetVisible(false); + contentList_.SetVisible(false); + delImg_.SetVisible(false); + } +} + +void SetCardView::ShowDeleteView(bool show) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::ShowDeleteView %u", show); + if (show) { + ShowCardListView(false); + deleteView_->SetVisible(true); + } else { + ShowCardListView(true); + deleteView_->SetVisible(false); + } +} + +void SetCardView::ShowAddView(bool show) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::ShowAddView %u", show); + if (show) { + ShowCardListView(false); + noCardView_->SetVisible(true); + } else { + ShowCardListView(true); + noCardView_->SetVisible(false); + } +} + +void SetCardView::RefreshCardList(void) +{ + contentList_.RemoveAll(); + SetUpListInfo(); + contentList_.RefreshList(); + if (setCardAdapter_->GetCount() == 0) { + ShowAddView(true); + } +} + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopModel.h b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopModel.h new file mode 100644 index 000000000..5c5a9261e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopModel.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDesktopModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DESKTOP_MODEL_H +#define SET_DESKTOP_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "SetDesktopPresenter.h" + +typedef enum { + APPLIST_STYLE, + HEXAGONS_STYLE, +} DesktopStyle; + +namespace OHOS { + class SetDesktopModel { + public: + static SetDesktopModel &GetInstance(void); + DesktopStyle GetDesktopStyle(void); + void SetDesktopStyle(DesktopStyle style); + private: + SetDesktopModel(); + SetDesktopModel(const SetDesktopModel &); + SetDesktopModel &operator=(const SetDesktopModel &); + virtual ~SetDesktopModel(); + + }; +} + +#endif // SET_DESKTOP_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopPresenter.h new file mode 100644 index 000000000..1e8d0c19f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopPresenter.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDesktopPresenter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DESKTOP_PRESENTER_H +#define SET_DESKTOP_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" + +namespace OHOS { +static const char *SET_DESKTOP_LIST = "setdesktopList"; +static const char *SET_DESKTOP_HEXAGONS = "setdesktopHexagons"; + +class SetDesktopView; +class SetDesktopModel; +class SetDesktopPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SetDesktopPresenter(); + virtual ~SetDesktopPresenter(); + + virtual void OnStart() override; + virtual void OnResume() override; + virtual void OnStop() override; + + bool OnClick(UIView &view, const ClickEvent &event) override; + virtual bool OnDrag(UIView& view, const DragEvent& event) override; + bool GetHexagonsStyleState(void); +private: + +}; +} + +#endif // SET_DESKTOP_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopView.h b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopView.h new file mode 100644 index 000000000..4c992747f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopView.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDesktopView.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DESKTOP_VIEW_H +#define SET_DESKTOP_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +#include "window/window.h" +#include "BaseView.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" + +namespace OHOS { +class SetDesktopPresenter; + +class SetDesktopView : public View { +public: + SetDesktopView(); + virtual ~SetDesktopView(); + + static SetDesktopView *GetInstance() + { + static SetDesktopView instance; + return &instance; + } + + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + void UpdateSelectedStyle(bool hexagonsSelected); +private: + UILabel titleText; + UIToggleButton hexagonsBtn; + UIToggleButton listBtn; + UIImageView hexagonsImage; + UIImageView listImage; + UILabel listText; + UILabel hexagonsText; +}; +} +#endif // SET_DESKTOP_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopModel.cpp new file mode 100644 index 000000000..d5f64f315 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopModel.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SettingModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetDesktopModel.h" +#include "kv_store.h" +#include "securec.h" + +namespace OHOS { + static const int STYLE_VALUE_LEN = 32; + SetDesktopModel::SetDesktopModel() {} + + SetDesktopModel::~SetDesktopModel() {} + + SetDesktopModel &SetDesktopModel::GetInstance() + { + static SetDesktopModel instance; + return instance; + } + + DesktopStyle SetDesktopModel::GetDesktopStyle(void) + { + DesktopStyle style; + char temp[STYLE_VALUE_LEN] = { 0 }; + (void)UtilsGetValue("applist_style", temp, STYLE_VALUE_LEN); + if (strcmp(temp, "hexagons") == 0) { + style = HEXAGONS_STYLE; + } else { + style = APPLIST_STYLE; + } + return style; + } + + void SetDesktopModel::SetDesktopStyle(DesktopStyle style) + { + if (style == APPLIST_STYLE) { + (void)UtilsSetValue("applist_style", "list"); + } else if (style == HEXAGONS_STYLE) { + (void)UtilsSetValue("applist_style", "hexagons"); + } + } + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopPresenter.cpp new file mode 100644 index 000000000..0c361bcb1 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopPresenter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SettingPresenter.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetDesktopView.h" +#include "SetDesktopModel.h" +#include "SetDesktopPresenter.h" + +namespace OHOS { + SetDesktopPresenter::SetDesktopPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopPresenter::SetDesktopPresenter"); + } + + SetDesktopPresenter::~SetDesktopPresenter() {} + + void SetDesktopPresenter::OnStart() + { + Presenter::OnStart(); + } + + void SetDesktopPresenter::OnResume(void) + { + } + + void SetDesktopPresenter::OnStop(void) + { + } + + bool SetDesktopPresenter::OnDrag(UIView& view, const DragEvent& event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnDrag ChangeSlice"); + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return false; + } + + bool SetDesktopPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopPresenter::OnClick"); + if (strcmp(view.GetViewId(), SET_DESKTOP_HEXAGONS) == 0) { + SetDesktopModel::GetInstance().SetDesktopStyle(HEXAGONS_STYLE); + } else if (strcmp(view.GetViewId(), SET_DESKTOP_LIST) == 0) { + SetDesktopModel::GetInstance().SetDesktopStyle(APPLIST_STYLE); + } + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + return true; + } + bool SetDesktopPresenter::GetHexagonsStyleState(void) + { + return (SetDesktopModel::GetInstance().GetDesktopStyle() == HEXAGONS_STYLE); + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopView.cpp new file mode 100644 index 000000000..c5f2b49df --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopView.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDesktopView.cpp + * Author: + * Create: 2021-11-23 + */ + +#include +#include "SetDesktopView.h" +#include "SetDesktopPresenter.h" + +namespace OHOS { +SetDesktopView::SetDesktopView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::SetDesktopView"); +} + +SetDesktopView::~SetDesktopView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::~SetDesktopView"); +} + +void SetDesktopView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetDraggable(true); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetOnDragListener(presenter_); + container_->SetTouchable(true); +} + +void SetDesktopView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::OnSetUpView"); + View::OnSetUpView(); + + titleText.SetPosition(180, 45, 260, 110); + titleText.SetText("桌面"); + titleText.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + titleText.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + titleText.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + container_->Add(&titleText); + + listImage.SetPosition(25, 135, 190, 190); + listImage.SetSrc(PNG_SET_DESKTOP_BG_IMAGE); + container_->Add(&listImage); + + listBtn.SetPosition(47, 157, 148, 148); + listBtn.SetImages(PNG_SET_DESKTOP_LIST_IMAGE, PNG_SET_DESKTOP_LIST_IMAGE); + listBtn.SetViewId(SET_DESKTOP_LIST); + container_->Add(&listBtn); + + listText.SetPosition(96, 328, 200, 60); + listText.SetText("列表"); + listText.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + listText.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + listText.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + container_->Add(&listText); + + hexagonsImage.SetPosition(247, 135, 190, 190); + hexagonsImage.SetSrc(PNG_SET_DESKTOP_BG_IMAGE); + container_->Add(&hexagonsImage); + + hexagonsBtn.SetPosition(267, 157, 148, 148); + hexagonsBtn.SetImages(PNG_SET_DESKTOP_HEXAGONS_IMAGE, PNG_SET_DESKTOP_HEXAGONS_IMAGE); + hexagonsBtn.SetViewId(SET_DESKTOP_HEXAGONS); + container_->Add(&hexagonsBtn); + + hexagonsText.SetPosition(305, 328, 200, 60); + hexagonsText.SetText("蜂窝"); + hexagonsText.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + hexagonsText.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + hexagonsText.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + container_->Add(&hexagonsText); + + listBtn.SetOnClickListener(presenter_); + hexagonsBtn.SetOnClickListener(presenter_); + UpdateSelectedStyle(presenter_->GetHexagonsStyleState()); +} + +void SetDesktopView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::OnTearDownView"); + View::OnTearDownView(); +} + +void SetDesktopView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::OnStop"); + View::OnStop(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } +} + +void SetDesktopView::UpdateSelectedStyle(bool hexagonsSelected) +{ + listImage.SetVisible(!hexagonsSelected); + hexagonsImage.SetVisible(hexagonsSelected); + hexagonsBtn.SetState(hexagonsSelected); + listBtn.SetState(!hexagonsSelected); +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialInfo.h b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialInfo.h new file mode 100644 index 000000000..7ccb7984d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialInfo.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialInfo.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DIAL_INFO_H +#define SET_DIAL_INFO_H +#include +#include +#include +#include "common/image_cache_manager.h" +namespace OHOS { + typedef struct { + uint8_t dialFlag; /* 1:离线表盘 0:预制表盘 */ + uint8_t id; /* 仅预制表盘使用 */ + std::string dialFullName; /* 仅离线表盘使用 */ + std::string imageFullName; /* 仅预制表盘使用 */ + std::string dialName; + std::string description; /* 仅离线表盘使用 */ + uint8_t freq; + ImageInfo *preImageInfo; + } SetDialInfo; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialModel.h b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialModel.h new file mode 100644 index 000000000..695c5beea --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialModel.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DIAL_MODEL_H +#define SET_DIAL_MODEL_H +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "SetDialInfo.h" + +namespace OHOS { + class SetDialModel { + public: + static SetDialModel &GetInstance(void); + void LoadAllDial(void); + size_t GetDialCount(void); + std::vector& GetDialInfo(void); + void SaveDialSetting(uint8_t pageIndex); + uint8_t GetPageIndex(void); + private: + void LoadAllDialFromRam(void); + void LoadAllDialFromFs(void); + SetDialModel(); + SetDialModel(const SetDialModel &); + SetDialModel &operator=(const SetDialModel &); + virtual ~SetDialModel(); + int32_t ParseDialHeader(const std::string &dialFileName, SetDialInfo &dialInfo); + std::vector dialInfoList; + uint8_t pageIndex_{0}; + }; +} + +#endif // SET_DIAL_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialPresenter.h new file mode 100644 index 000000000..65b4a746d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialPresenter.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialPresenter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DIAL_PRESENTER_H +#define SET_DIAL_PRESENTER_H +#include "SetDialInfo.h" +#include "SetDialModel.h" +#include "Presenter.h" +#include "components/ui_view.h" +#include "KeyInputListener.h" + +namespace OHOS { + +class SetDialView; +class SetDialModel; +class SetDialPresenter : public Presenter, + public UIView::OnClickListener, + public UICoverflowView::OnCoverflowScrollListener { +public: + SetDialPresenter(); + virtual ~SetDialPresenter(); + size_t GetDialCount(void); + std::vector& GetDialInfo(void); + uint8_t GetPageIndex(void); + virtual void OnStart() override; + virtual void OnResume() override; + virtual void OnStop() override; + bool OnScroll() override; + bool OnClick(UIView &view, const ClickEvent &event) override; +private: + KeyInputListener *keyActListenr{nullptr}; + SetDialModel *model{nullptr}; +}; +} + +#endif // SET_DIAL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialView.h b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialView.h new file mode 100644 index 000000000..85ee938c9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialView.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialView.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DIAL_VIEW_H +#define SET_DIAL_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_coverflow_view.h" +#include "window/window.h" +#include "BaseView.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" + +namespace OHOS { +static constexpr uint8_t DIVISOR_TWO = 2; +class SetDialPresenter; + +class SetDialView : public View { +public: + SetDialView(); + virtual ~SetDialView(); + + static SetDialView *GetInstance() + { + static SetDialView instance; + return &instance; + } + + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + void CoverflowViewScroll(void); + uint8_t GetCoverflowPage(void); +private: + void SetUpCoverflowView(void); + UICoverflowView coverflow_; + UILabel label_; + uint8_t lastIndex_; +}; +} +#endif // SET_DIAL_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialModel.cpp new file mode 100644 index 000000000..122c0adb0 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialModel.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "MainModel.h" +#include "SetDialModel.h" +#include "kv_store.h" +#include "securec.h" +#include "dirent.h" +#include "DialBinTypes.h" +#include "wearable_log.h" + +namespace OHOS { + SetDialModel::SetDialModel() {} + + SetDialModel::~SetDialModel() {} + + SetDialModel &SetDialModel::GetInstance() + { + static SetDialModel instance; + return instance; + } + void SetDialModel::LoadAllDial() + { + dialInfoList.clear(); + LoadAllDialFromRam(); + LoadAllDialFromFs(); + } + + void SetDialModel::LoadAllDialFromRam() + { + for (uint8_t i = DIAL_CLOCK; i < DIAL_MAX; i++) { + const DialInfo *info = MainModel::GetInstance().GetDialInfo((DialId)i); + if (info != nullptr) { + SetDialInfo dialInfo; + dialInfo.dialFlag = 0; + dialInfo.id = i; + dialInfo.dialName = info->dialName; + dialInfo.imageFullName = info->dialImg; + dialInfo.freq = info->freq; + ImageInfo* imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(info->dialImg, false); + if (info == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", + info->dialImg); + continue; + } + dialInfo.preImageInfo = imageInfo; + dialInfoList.push_back(dialInfo); + } + } + } + + void SetDialModel::LoadAllDialFromFs() + { + int ret; + struct dirent *direntp; + + // 打开目录 + DIR *dirp = opendir(APP_DIAL_PATH); + // 遍历文件 + if (dirp != NULL) { + while ((direntp = readdir(dirp)) != NULL) { + SetDialInfo dialInfo; + int ret = ParseDialHeader(direntp->d_name, dialInfo); + if (ret == 0) { + dialInfoList.push_back(dialInfo); + } + } + } + // 关闭目录 + closedir(dirp); + return; + } + + int32_t SetDialModel::ParseDialHeader(const std::string &dialFileName, SetDialInfo &dialInfo) + { + DialHeader dialHeader{0}; + std::string dialFullName = APP_DIAL_PATH; + dialFullName += "/"; + dialFullName += dialFileName; + FILE *fp = fopen(dialFullName.c_str(), "rb"); + if (fp == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader cannot open file: %s", + dialFullName.c_str()); + return -1; + } + if (fread(&dialHeader, 1, sizeof(dialHeader), fp) != sizeof(dialHeader)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader fread %s fail", + dialFullName.c_str()); + return -1; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialFullName: %s", + dialFullName.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialName: %s", + dialHeader.dialName); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader description: %s", + dialHeader.description); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader freq: %u", + dialHeader.freq); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader previewImgId: %u", + dialHeader.previewImgId); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader imageOffset: %u", + dialHeader.imageOffset); + ImageInfo *info = ImageCacheManager::GetInstance().LoadOneInMultiRes( + dialHeader.previewImgId | (0xfef << 20), dialFullName, fp, false, dialHeader.imageOffset); + if (info == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader loadimage fail"); + return -1; + } + + dialInfo.dialFlag = 1; + dialInfo.id = 0; + dialInfo.dialFullName = dialFullName; + dialInfo.dialName = dialHeader.dialName; + dialInfo.description = dialHeader.description; + dialInfo.freq = dialHeader.freq; + dialInfo.preImageInfo = info; + + fclose(fp); + return 0; + } + + void SetDialModel::SaveDialSetting(uint8_t pageIndex) + { + if (pageIndex >= dialInfoList.size()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialModel SaveDialSetting [%u %u]", + pageIndex, dialInfoList.size()); + return; + } + DialSetting diagSetting; + SetDialInfo &info = dialInfoList[pageIndex]; + diagSetting.dialFlag = info.dialFlag; + diagSetting.dialId = info.id; + diagSetting.dialFullName = info.dialFullName; + MainModel::GetInstance().AddDialSetting(diagSetting); + pageIndex_ = pageIndex; + } + + size_t SetDialModel::GetDialCount(void) + { + return dialInfoList.size(); + } + + std::vector& SetDialModel::GetDialInfo(void) + { + return dialInfoList; + } + + uint8_t SetDialModel::GetPageIndex(void) + { + if (pageIndex_ >= dialInfoList.size()) { + return 0; + } else { + return pageIndex_; + } + } + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp new file mode 100644 index 000000000..5aa0bb29c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialPresenter.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetDialView.h" +#include "SetDialModel.h" +#include "SetDialPresenter.h" + +namespace OHOS { + SetDialPresenter::SetDialPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialPresenter::SetDialPresenter"); + model = &SetDialModel::GetInstance(); + model->LoadAllDial(); + } + + SetDialPresenter::~SetDialPresenter() + { + if (keyActListenr != nullptr) { + delete keyActListenr; + keyActListenr = nullptr; + } + } + + void SetDialPresenter::OnStart() + { + Presenter::OnStart(); + if (keyActListenr == nullptr) { + keyActListenr = new KeyInputListener(); + if (keyActListenr != nullptr) { + RootView::GetInstance()->SetOnKeyActListener(keyActListenr); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnStart: new KeyInputListener fail"); + } + } + } + + void SetDialPresenter::OnResume(void) + { + } + + void SetDialPresenter::OnStop(void) + { + } + + bool SetDialPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialPresenter::OnClick"); + uint8_t pageIndex = view_->GetCoverflowPage(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialPresenter select pageIndex = %u", pageIndex); + model->SaveDialSetting(pageIndex); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + return true; + } + + bool SetDialPresenter::OnScroll() + { + view_->CoverflowViewScroll(); + return true; + } + + size_t SetDialPresenter::GetDialCount(void) + { + return model->GetDialCount(); + } + + std::vector& SetDialPresenter::GetDialInfo(void) + { + return model->GetDialInfo(); + } + + uint8_t SetDialPresenter::GetPageIndex(void) + { + return model->GetPageIndex(); + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialView.cpp new file mode 100644 index 000000000..b683a860f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialView.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialView.cpp + * Author: + * Create: 2021-11-23 + */ + +#include +#include "SetDialView.h" +#include "SetDialPresenter.h" + +namespace OHOS { +SetDialView::SetDialView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetDialView"); +} + +SetDialView::~SetDialView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::~SetDialView"); +} + +void SetDialView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + SetUpCoverflowView(); +} + +void SetDialView::SetUpCoverflowView(void) +{ + coverflow_.SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + coverflow_.SetIntercept(true); + coverflow_.SetOnCoverflowListener(presenter_); + coverflow_.SetOnClickListener(presenter_); + std::vector &dialInfo = presenter_->GetDialInfo(); + for (auto iter : dialInfo) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetUpCoverflowView %s", + iter.dialName.c_str()); + coverflow_.Add(iter.dialName.c_str(), iter.preImageInfo); + } + lastIndex_ = presenter_->GetPageIndex(); + coverflow_.SetCurrentPage(lastIndex_); + + label_.SetPosition(127, 50, 200, 50); + label_.SetTextColor(Color::White()); + label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label_.SetText(dialInfo[lastIndex_].dialName.c_str()); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + container_->Add(&coverflow_); + container_->Add(&label_); +} + +void SetDialView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnSetUpView"); + View::OnSetUpView(); +} + +void SetDialView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnTearDownView"); + View::OnTearDownView(); +} + +void SetDialView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnStop"); + View::OnStop(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } +} + +void SetDialView::CoverflowViewScroll(void) +{ + int16_t contMidX = static_cast(Screen::GetInstance().GetWidth() / DIVISOR_TWO); + int16_t minOffset = contMidX; + uint8_t newCenterIndex = lastIndex_; + for (uint8_t i = 0; i < coverflow_.GetChildrenNumber(); i++) { + Rect rect = coverflow_.GetViewByIndex(i)->GetOrigRect(); + int16_t x = rect.GetLeft(); + int16_t x1 = rect.GetRight(); + int16_t xMid = static_cast(x + (x1 - x + 1) / DIVISOR_TWO); + int16_t distance = MATH_ABS(xMid - contMidX); + if (distance < minOffset) { + newCenterIndex = i; + minOffset = distance; + } + } + if (newCenterIndex != lastIndex_) { + lastIndex_ = newCenterIndex; + std::vector &dialInfo = presenter_->GetDialInfo(); + label_.SetText(dialInfo[lastIndex_].dialName.c_str()); + } + + Rect curViewRect = coverflow_.GetViewByIndex(lastIndex_)->GetOrigRect(); + int16_t centerMid = curViewRect.GetLeft() + curViewRect.GetWidth() / DIVISOR_TWO; + int16_t offset = MATH_ABS(contMidX - centerMid); + if (offset > curViewRect.GetWidth() / DIVISOR_TWO) { + label_.SetStyle(STYLE_TEXT_OPA, 0); + } else { + uint8_t alpha = (uint8_t)((1.0f - ((float)offset / (curViewRect.GetWidth() / DIVISOR_TWO))) * OPA_OPAQUE); + label_.SetStyle(STYLE_TEXT_OPA, alpha); + } +} + +uint8_t SetDialView::GetCoverflowPage(void) +{ + return lastIndex_; +} + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItem.h b/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItem.h index 448deb599..250105ce0 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItem.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItem.h @@ -11,19 +11,8 @@ #include namespace OHOS { -/* - * setting id. - */ -typedef enum : uint16_t { - // setting item index - SETTING_ITEM_ZERO = 0x0000, - SETTING_ITEM_ONE, - SETTING_ITEM_TWO, - SETTING_ITEM_THREE, -} SettingIndex; - typedef struct { - SettingIndex index; + AppViewId viewId; const char *icon; const char *label; bool hasSecondMenu; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItemView.h index 20de7163c..aa5de7ad1 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItemView.h @@ -22,15 +22,15 @@ public: virtual ~SettingItemView(); virtual void SetItemInfo(const SettingItem itemInfo); virtual void SetUpChild(); - SettingIndex GetSettingIndex(); - + AppViewId GetViewId(); + const char* GetIconId(); private: SettingItemView(const SettingItemView &); UIImageView sIcon; UILabel sLabel; UIImageView sNextImage; - SettingItem sItemInfo = { SETTING_ITEM_ZERO, nullptr, nullptr, false }; + SettingItem sItemInfo = { VIEW_INVALID, nullptr, nullptr, false }; }; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingModel.h b/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingModel.h index be1e4d5a3..6a50ebfc8 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingModel.h @@ -11,19 +11,18 @@ #include #include #include "AppViewIDs.h" -#include "components/ui_label_ext.h" #include "UiConfig.h" #include "SettingItem.h" #include "SettingPresenter.h" namespace OHOS { + static const uint16_t SETTING_ITEM_COUNT = 10; class SettingModel { public: static SettingModel &GetInstance(void); void InitSettingItem(); const SettingItem *GetSettinglistItems() const; uint8_t GetSettingListNum() const; - const std::map &GetSettingIdToViewId() const; bool GetBlueToothConnectStatus(void); void UpdateBlueToothConnectStatus(bool status); private: @@ -31,9 +30,8 @@ namespace OHOS { SettingModel(const SettingModel &); SettingModel &operator=(const SettingModel &); virtual ~SettingModel(); - static const uint16_t SETTING_ITEM_LEN = 4; - SettingItem settings[SETTING_ITEM_LEN] = { SETTING_ITEM_ZERO, nullptr, nullptr, false }; - std::map settingIdToViewId; + SettingItem settings[SETTING_ITEM_COUNT] = { VIEW_INVALID, nullptr, nullptr, false }; + int usedLen; bool btConnectStatus{false}; }; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingItemView.cpp index f9b7424e3..fed442ced 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingItemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingItemView.cpp @@ -67,8 +67,13 @@ namespace OHOS { sNextImage.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); } - SettingIndex SettingItemView::GetSettingIndex() + AppViewId SettingItemView::GetViewId() { - return sItemInfo.index; + return sItemInfo.viewId; + } + + const char* SettingItemView::GetIconId() + { + return sItemInfo.icon; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp index 016996c62..47c9c9164 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp @@ -21,14 +21,15 @@ namespace OHOS { void SettingModel::InitSettingItem() { - settings[0] = {SETTING_ITEM_ZERO, PNG_BLUETOOTH_STITLE, "蓝牙耳机", true}; - settings[1] = {SETTING_ITEM_ONE, PNG_CONNECT_PHONE_IMAGE, "连接手机", true}; - settings[2] = {SETTING_ITEM_TWO, PNG_SETTTING_REBOOT_IMAGE, "重启", true}; - settings[3] = {SETTING_ITEM_THREE, PNG_SETTTING_SHUTDOWN_IMAGE, "关机", true}; - settingIdToViewId.insert(std::pair(SETTING_ITEM_ZERO, VIEW_BLUETOOTH_EARPHONE)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_ONE, VIEW_CONNECT_PHONE)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_TWO, VIEW_REBOOT)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_THREE, VIEW_REBOOT)); + int index = 0; + settings[index++] = {VIEW_BLUETOOTH_EARPHONE, PNG_BLUETOOTH_STITLE, "蓝牙耳机", true}; + settings[index++] = {VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, "连接手机", true}; + settings[index++] = {VIEW_REBOOT, PNG_SETTTING_REBOOT_IMAGE, "重启", true}; + settings[index++] = {VIEW_REBOOT, PNG_SETTTING_SHUTDOWN_IMAGE, "关机", true}; + settings[index++] = {VIEW_SET_DESKTOP, PNG_SETTTING_DESKTOP_IMAGE, "桌面", true}; + settings[index++] = {VIEW_SET_DIAL, PNG_SETTTING_DESKTOP_IMAGE, "表盘", true}; + settings[index++] = {VIEW_SET_CARD, PNG_SETTTING_DESKTOP_IMAGE, "卡片", true}; + usedLen = index; } const SettingItem *SettingModel::GetSettinglistItems() const @@ -38,12 +39,7 @@ namespace OHOS { uint8_t SettingModel::GetSettingListNum() const { - return SETTING_ITEM_LEN; - } - - const std::map &SettingModel::GetSettingIdToViewId() const - { - return settingIdToViewId; + return usedLen; } bool SettingModel::GetBlueToothConnectStatus(void) diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingPresenter.cpp index 6f6fd5ae8..368d3675e 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingPresenter.cpp @@ -56,20 +56,17 @@ namespace OHOS { { UNUSED(event); SettingItemView *settingItemView = static_cast(&view); - SettingIndex index = settingItemView->GetSettingIndex(); - if (index >= SettingModel::GetInstance().GetSettingListNum()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnClick is no index"); - return false; - } else { - if (index == SETTING_ITEM_TWO) { + AppViewId viewId = settingItemView->GetViewId(); + if (viewId == VIEW_REBOOT) { + if (strstr(settingItemView->GetIconId(), "REBOOT") != nullptr){ RebootModel::GetInstance()->SetSelectViewId(REBOOTDEVICE); RebootModel::GetInstance()->SetExitsView(true); - } else if (index == SETTING_ITEM_THREE) { + } else { RebootModel::GetInstance()->SetSelectViewId(SHUTDOWNDEVICE); RebootModel::GetInstance()->SetExitsView(true); } - NativeAbility::GetInstance().ChangeSlice(SettingModel::GetInstance().GetSettingIdToViewId().at(index)); - return true; } + NativeAbility::GetInstance().ChangeSlice(viewId); + return true; } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingView.cpp index 9de644b8c..b38f9a696 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingView.cpp @@ -122,8 +122,6 @@ void SettingView::OnSetUpView() scrollView->Add(contentList); RootView::GetInstance()->Add(scrollView); contentList->SetAdapter(listAdapter); - - Draw(); return; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPresenter.cpp index 9826b504b..5f44a54f8 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPresenter.cpp @@ -9,15 +9,11 @@ #include "TempMainView.h" #include "ChangeSliceListener.h" #include "graphic_service.h" +#include "ui_service.h" #include "string" #include "iostream" #include "sstream" -#include "errcode.h" -#include "pm_definition.h" -extern "C" errcode_t uapi_pm_add_sleep_veto(pm_id_t veto_id); -extern "C" errcode_t uapi_pm_remove_sleep_veto(pm_id_t veto_id); - namespace OHOS { static TempPresenter *g_tempPresenter = nullptr; @@ -47,13 +43,16 @@ void TempPresenter::OnStart() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TempPresenter OnStart"); Presenter::OnStart(); + SendMsgToUIService(UI_ADD_SLEEP_VETO, 0, NULL, 0); } void TempPresenter::OnPause(void) {} void TempPresenter::OnResume(void) {} -void TempPresenter::OnStop(void) {} +void TempPresenter::OnStop(void) { + SendMsgToUIService(UI_RM_SLEEP_VETO, 0, NULL, 0); +} bool TempPresenter::OnDrag(UIView& view, const DragEvent& event) { @@ -75,9 +74,6 @@ void TempPresenter::ProgressNotify(void) if (TempMeaProcess::GetInstance()->GetCircleStatus() == true && TempMeaProcess::GetInstance()->GetCircleProgress() != nullptr) { if (countTemp > 0) { - if (countTemp == SET_HUNDRED) { - uapi_pm_add_sleep_veto(PM_ID_SCREEN); - } GraphicService::GetInstance()->PostGraphicEvent(std::bind(&TempPresenter::UpdateTempCount, this)); } else { TempMeaProcess::GetInstance()->SetCircleStatus(false); @@ -85,7 +81,6 @@ void TempPresenter::ProgressNotify(void) TempMainView::GetInstance()->ChangeView(MEASURE_ING, MEASURE_INIT); } SetTempCountMax(); - uapi_pm_remove_sleep_veto(PM_ID_SCREEN); } } return; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp index 221440102..59fe703c6 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp @@ -8,6 +8,7 @@ #include "UISampleView.h" #include "UISampleModel.h" #include "UISamplePresenter.h" +#include "ui_service.h" namespace OHOS { UISamplePresenter::UISamplePresenter() @@ -21,17 +22,16 @@ namespace OHOS { void UISamplePresenter::OnStart() { Presenter::OnStart(); + SendMsgToUIService(UI_ADD_SLEEP_VETO, 0, NULL, 0); } void UISamplePresenter::OnResume(void) { - if (view_ == nullptr) { - return; - } } void UISamplePresenter::OnStop(void) { + SendMsgToUIService(UI_RM_SLEEP_VETO, 0, NULL, 0); return; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uisample/uitest/framework/src/ui_test_group.cpp b/code/sdk/application/wearable/nativeapp/nativeui/uisample/uitest/framework/src/ui_test_group.cpp index db1ab83f3..a6307df44 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/uisample/uitest/framework/src/ui_test_group.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/uisample/uitest/framework/src/ui_test_group.cpp @@ -25,7 +25,10 @@ #include "ui_test_running_ball/ui_test_running_ball.h" #endif #include "ui_test_tiger/ui_test_tiger.h" +#include "ui_test_hexagons_list/ui_test_hexagons_list.h" #include "ui_test_video_play/ui_test_video_play.h" +#include "ui_test_coverflow/ui_test_coverflow.h" +#include "ui_test_kaleidoscope/ui_test_kaleidoscope.h" namespace OHOS { void UITestGroup::AddTestCase(TestCaseInfo testCaseInfo) @@ -44,11 +47,14 @@ void UITestGroup::SetUpTestCase() } testCaseList_->Clear(); testCaseList_->PushBack(TestCaseInfo{"老虎头", new UITestTiger()}); + testCaseList_->PushBack(TestCaseInfo{"蜂窝表盘", new UITestHexagonsList()}); testCaseList_->PushBack(TestCaseInfo{"滑动列表", new UITestListFPS()}); testCaseList_->PushBack(TestCaseInfo{"卡片切换", new UITestCardSwitch()}); testCaseList_->PushBack(TestCaseInfo{"立方体旋转", new UITestCubeRotate()}); testCaseList_->PushBack(TestCaseInfo{"消息", new UITestMessage()}); testCaseList_->PushBack(TestCaseInfo{"呼吸效果", new UITestBreath()}); + testCaseList_->PushBack(TestCaseInfo{"覆盖流", new UITestCoverflow()}); + testCaseList_->PushBack(TestCaseInfo{"万花筒", new UITestKaleidoscope()}); #if ENABLE_VGU_ENGINE && CAPABILITY_HWDRAW_PATH testCaseList_->PushBack(TestCaseInfo{"倒计时", new UITestCountdown()}); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uiservice/include/ui_service.h b/code/sdk/application/wearable/nativeapp/nativeui/uiservice/include/ui_service.h index 5e442e726..4792e4f2f 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/uiservice/include/ui_service.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/uiservice/include/ui_service.h @@ -47,6 +47,9 @@ typedef enum { SCREEN_TURN_ON_TO_UI, SCREEN_TURN_OFF_TO_UI, SCREEN_OFF_ENABLE_TO_UI, + UI_ADD_SLEEP_VETO, + UI_RM_SLEEP_VETO, + } UiServiceMsgId; #define BUNDLE_NAME_LEN 128 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/nativeapp/nativeui/uiservice/src/ui_service.cpp index b12fcf3a1..3ede65992 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -31,6 +31,11 @@ #include "ui_screennotify.h" #include "HealthModel.h" +#include "errcode.h" +#include "pm_definition.h" +extern "C" errcode_t uapi_pm_add_sleep_veto(pm_id_t veto_id); +extern "C" errcode_t uapi_pm_remove_sleep_veto(pm_id_t veto_id); + #ifdef __cplusplus extern "C" { #endif @@ -158,7 +163,12 @@ void ServiceMsgProcess(Request *request) case SCREEN_OFF_ENABLE_TO_UI: ScreenOffEnable(request); break; - + case UI_ADD_SLEEP_VETO: + uapi_pm_add_sleep_veto(PM_ID_SCREEN); + break; + case UI_RM_SLEEP_VETO: + uapi_pm_remove_sleep_veto(PM_ID_SCREEN); + break; } SAMGR_FreeRequestMsg(request); } diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_ACTIVITY.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_ACTIVITY.bin new file mode 100644 index 000000000..45a459dac Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_ACTIVITY.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_ADD.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_ADD.bin new file mode 100644 index 000000000..f308fc020 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_ADD.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_COMPASS.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_COMPASS.bin new file mode 100644 index 000000000..e253bbe46 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_COMPASS.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_DEL.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_DEL.bin new file mode 100644 index 000000000..0c0adcbd8 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_DEL.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_HEART.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_HEART.bin new file mode 100644 index 000000000..a19125d62 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_HEART.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_PLAYER.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_PLAYER.bin new file mode 100644 index 000000000..6b0985224 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/CARD_PLAYER.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/DIAL_CLOCK.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/DIAL_CLOCK.bin new file mode 100644 index 000000000..744141270 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/DIAL_CLOCK.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SETTTING_DESKTOP.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SETTTING_DESKTOP.bin new file mode 100644 index 000000000..332ebc054 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SETTTING_DESKTOP.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SET_DESKTOP_BG.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SET_DESKTOP_BG.bin new file mode 100644 index 000000000..fafbd1b50 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SET_DESKTOP_BG.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SET_DESKTOP_HEXAGONS.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SET_DESKTOP_HEXAGONS.bin new file mode 100644 index 000000000..6c9477666 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SET_DESKTOP_HEXAGONS.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SET_DESKTOP_LIST.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SET_DESKTOP_LIST.bin new file mode 100644 index 000000000..14547a23b Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/SET_DESKTOP_LIST.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/hexagons.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/hexagons.bin new file mode 100644 index 000000000..f3dc2e88b Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/hexagons.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/kaleidoscope.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/kaleidoscope.bin new file mode 100644 index 000000000..eac0b9066 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/kaleidoscope.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/planet.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/planet.bin new file mode 100644 index 000000000..9a6e5ba36 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/planet.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/rabbit454.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/rabbit454.bin new file mode 100644 index 000000000..f98a0c1bf Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/rabbit454.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/rainbow.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/rainbow.bin new file mode 100644 index 000000000..3419bad22 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/evb4/fs/user/res/rainbow.bin differ diff --git a/code/sdk/build/config/target_config/common_config.py b/code/sdk/build/config/target_config/common_config.py index f01bdee14..be29f0651 100755 --- a/code/sdk/build/config/target_config/common_config.py +++ b/code/sdk/build/config/target_config/common_config.py @@ -116,10 +116,11 @@ component_set = { 'efuse_v120': ['efuse', 'hal_efuse_v120', 'efuse_porting'], 'efuse_v100': ['efuse', 'hal_efuse_v100', 'efuse_porting'], 'efuse_v130': ['efuse', 'hal_efuse_v130', 'efuse_port'], - 'ohos_set' : ['bootstrap', 'samgr', 'ams', 'bms', 'ace', 'ace_adapt', 'permission', 'appverify', 'jerryscript','js_player', 'js_audio_captuer','i18n', 'resmgr', 'syspara'], + 'ohos_set' : ['bootstrap', 'samgr', 'ams', 'bms', 'ace', 'ace_adapt', 'permission', 'appverify', 'jerryscript','js_player', 'js_audio_captuer', 'i18n', + 'resmgr', 'syspara', 'utils_kv_store', 'native_file'], 'wearable_set' : ['nativeabilityfwk', 'ai_voice_service', 'ai_voice_engine_hal', 'ai_voice_audio_stream_wrapper', 'ohos_deps', 'broadcast', 'msg_center', 'msg_center_adapt', 'ohos_startup'], - 'xts_set' : ["syspara", "utils_kv_store", "native_file", "xts_adapt", "ohos_drv_v3.2", + 'xts_set' : ["xts_adapt", "ohos_drv_v3.2", "hiview_lite", "hievent_lite", "hilog_lite", "huks_sdk"], 'xts_test_set' : ["hctest", "ActsHuksHalFunctionTest", "huks_test_common", "ActsAbilityMgrTest", "ActsBundleMgrTest", "ActsKvStoreTest", "ActsUtilsFileTest", "ActsHieventLiteTest", "ActsDfxFuncTest", "ActsWifiIotTest", diff --git a/code/sdk/middleware/services/gui/hal/common/include/graphic_hardware_config.h b/code/sdk/middleware/services/gui/hal/common/include/graphic_hardware_config.h index 8867e30c3..43bcb9df4 100755 --- a/code/sdk/middleware/services/gui/hal/common/include/graphic_hardware_config.h +++ b/code/sdk/middleware/services/gui/hal/common/include/graphic_hardware_config.h @@ -139,7 +139,7 @@ /** * @brief Memory pool define. */ -#define ALIGN_UP(x, a) ((((x) + ((a)-1)) / (a)) * (a)) +#define ALIGN_UP(x, a) ((((x) + ((a) - 1)) / (a)) * (a)) #ifndef CONFIG_PSRAM_SUPPORT // equal to MEMORY_MINI #define MEM_POOL_UI_POOL_SIZE 0x13c000 // 1408 - 144 = 1264k diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-native-js/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-native-js/libdisplay_gfx.a index 5a1a1d1c1..f20d975dc 100755 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-native-js/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-native-js/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-target1/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-target1/libdisplay_gfx.a index 66994fb09..eb73ea809 100755 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-target1/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-target1/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-target3/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-target3/libdisplay_gfx.a index 42abaaf86..f5f1c39b7 100755 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-target3/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-target3/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-target5/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-target5/libdisplay_gfx.a index c8e9fcb7a..4a8ab1216 100755 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-target5/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-target5/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-xts/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-xts/libdisplay_gfx.a index f0ca757e2..d78c31608 100755 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-xts/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-xts/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/hal/display/src/display_gralloc.c b/code/sdk/middleware/services/gui/hal/display/src/display_gralloc.c index cf2f29084..6f64ebdc7 100755 --- a/code/sdk/middleware/services/gui/hal/display/src/display_gralloc.c +++ b/code/sdk/middleware/services/gui/hal/display/src/display_gralloc.c @@ -147,7 +147,7 @@ static int32_t InitBufferHandle(BufferHandle *buffer, const AllocInfo *info) } else { const FormatInfo *fmtInfo = GetFormatInfo(info->format); if (fmtInfo == NULL) { - DISP_LOGE("%s: can not get format information : %d\n", __func__, buffer->format); + DISP_LOGE("%s: can not get format information : %d\n", __func__, info->format); return DISPLAY_FAILURE; } diff --git a/code/sdk/middleware/services/gui/uikit/CMakeLists.txt b/code/sdk/middleware/services/gui/uikit/CMakeLists.txt index e3c1d6bc1..c2aa26288 100755 --- a/code/sdk/middleware/services/gui/uikit/CMakeLists.txt +++ b/code/sdk/middleware/services/gui/uikit/CMakeLists.txt @@ -206,9 +206,15 @@ set(COMPONENT_SRC ${PROP_UI_SRC}/components_ext/text_ext.cpp ${PROP_UI_SRC}/components_ext/ui_label_button_ext.cpp ${PROP_UI_SRC}/components_ext/image_cache_manager.cpp + ${PROP_UI_SRC}/components_ext/ui_hexagons_list.cpp ${PROP_UI_SRC}/components_ext/ui_canvas_ext.cpp ${PROP_UI_SRC}/components_ext/ui_card_container.cpp ${PROP_UI_SRC}/components_ext/ui_cross_view.cpp + ${PROP_UI_SRC}/components_ext/kaleidoscope_utils.cpp + ${PROP_UI_SRC}/components_ext/ui_kaleidoscope_view.cpp + ${PROP_UI_SRC}/components_ext/ui_map_view.cpp + ${PROP_UI_SRC}/components_ext/map_svg_parser.cpp + ${PROP_UI_SRC}/components_ext/ui_coverflow_view.cpp ) set(SOURCES @@ -261,4 +267,4 @@ set(MAIN_COMPONENT false ) -build_component() \ No newline at end of file +build_component() diff --git a/code/sdk/middleware/services/gui/uikit/brandy-native-js/libuikit_ext.a b/code/sdk/middleware/services/gui/uikit/brandy-native-js/libuikit_ext.a index 989d7e9b2..8161135c7 100755 Binary files a/code/sdk/middleware/services/gui/uikit/brandy-native-js/libuikit_ext.a and b/code/sdk/middleware/services/gui/uikit/brandy-native-js/libuikit_ext.a differ diff --git a/code/sdk/middleware/services/gui/uikit/brandy-target3/libuikit_ext.a b/code/sdk/middleware/services/gui/uikit/brandy-target3/libuikit_ext.a index efe481361..8161135c7 100755 Binary files a/code/sdk/middleware/services/gui/uikit/brandy-target3/libuikit_ext.a and b/code/sdk/middleware/services/gui/uikit/brandy-target3/libuikit_ext.a differ diff --git a/code/sdk/middleware/services/gui/uikit/brandy-xts/libuikit_ext.a b/code/sdk/middleware/services/gui/uikit/brandy-xts/libuikit_ext.a index 6a175b7fa..8161135c7 100755 Binary files a/code/sdk/middleware/services/gui/uikit/brandy-xts/libuikit_ext.a and b/code/sdk/middleware/services/gui/uikit/brandy-xts/libuikit_ext.a differ diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/kaleidoscope_utils.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/kaleidoscope_utils.h new file mode 100644 index 000000000..c126d1ba9 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/kaleidoscope_utils.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +/** + * @file kaleidoscope_utils.h + * + * @brief Declares a KaleidoscopeUtils. + */ + +#ifndef KALEIDOSCOPE_UTILS_H +#define KALEIDOSCOPE_UTILS_H + +#include "gfx_utils/heap_base.h" +#include "components/ui_canvas_ext.h" +#include "gfx_utils/image_info.h" + +namespace OHOS { + +typedef struct { + ImageInfo info; + uint32_t stride; +} ImageInfoExt; + +class KaleidoscopeUtils : public HeapBase { +public: + + KaleidoscopeUtils() {}; + + virtual ~KaleidoscopeUtils(); + + /** + * @brief Init KaleidoscopeUtils. + * @param [in] src Pointer to a ImageInfo struct, which is the source img for kaleidoscope img. + * @param [in] dst Pointer to a ImageInfoExt struct, which will be used to store kaleidoscope data. + If it is NULL, it will be created and managed internally. + * @return Return true if init successfully; and false otherwise. + */ + bool Init(const ImageInfo* src, const ImageInfoExt* dst); + + /** + * @brief Update the kaleidoscope img by a rotate value. + * @param [in] rotate Rotate value. + * @return Return true if update successfully; and false otherwise. + */ + bool Rotate(float rotate); + + /** + * @brief Update the address of kaleidoscope data, when init with an externally managed ImageInfoExt. + * @param [in] addr Address of kaleidoscope data. + * @return Return true if update successfully; and false otherwise. + */ + bool UpdateKaleidoscopeAddr(const uint8_t* addr); + + /** + * @brief Obtain kaleidoscope img. + * @return Return pointer to ImageInfoExt struct. + */ + ImageInfoExt* GetKaleidoscopeInfo(); + +private: + ImageInfo* imgInfo_ = nullptr; + ImageInfoExt* kaleidoscopeInfo_ = nullptr; + ImageInfoExt* partialInfo_ = nullptr; + Path sectorPath_ = {0}; + Path imgPath_ = {0}; + float thetaVal_ = 0.0f; + float radius_ = 0.0f; + Point point_ = {0, 0}; + Point startPoint_ = {0, 0}; + bool isInternalMem_ = false; + + void UpdatePoint(float rotate); + bool ConstructPartial(); + bool ConstructKaleidoscope(); + Rect GetBoundingArea(const ImageHeader& header); + bool InitKaleidoscopeInfo(const ImageInfo* src, const ImageInfoExt* dst); + bool InitInnerPath(); + bool InitPartialInfo(); + void DeinitKaleidoscopeInfo(); + void DeInitPartialInfo(); + void DeinitInnerPath(); + void DeinitImgInfo(); + bool ConstructFirstQuadrant(BufferInfo& bufferInfo); + bool ConstructRestQuadrant(BufferInfo& bufferInfo); +}; +} +#endif +/** + * @} + */ diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_barcode.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_barcode.h index 57cbacdf2..ac8342681 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_barcode.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_barcode.h @@ -51,7 +51,7 @@ public: * @since 3.0 * @version 5.0 */ - virtual ~UIBarcode(); + ~UIBarcode() override; /** * @brief Sets the bar code information. diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_card_page.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_card_page.h index a51a2bd12..d3b668c79 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_card_page.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_card_page.h @@ -49,7 +49,7 @@ public: * @since 1.0 * @version 1.0 */ - virtual ~UICardPage() {} + ~UICardPage() override {} /* * * @brief Preload resource callback function, it will be called at the end of swipe animator or the function @@ -132,6 +132,13 @@ public: return UI_CARD_PAGE; } + /* * + * @brief Clear the image cache of this page. + * @since 1.0 + * @version 1.0 + */ + void ClearCache(void); + private: bool isCoverable_ = false; }; diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_coverflow_view.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_coverflow_view.h new file mode 100644 index 000000000..e063a8af0 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_coverflow_view.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * 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. + */ + +#ifndef UI_COVERFLOW_VIEW_H +#define UI_COVERFLOW_VIEW_H +#include "components/ui_swipe_view.h" +#include +#include +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +class UICoverflowView : public UISwipeView { +public: + UICoverflowView(); + ~UICoverflowView() override; + + /** + * @brief Add a item to coverflow. + * + * @param id Indicates the pointer to the view ID. + * @param src point item show main image imageinfo. + */ + void Add(const char* id, const ImageInfo* src); + + /** + * @brief remove a item from coverflow. + * + * @param id Indicates the pointer to the view ID. + */ + void Remove(const char* id); + + /** + * @brief Set center item width in static display mode. + * + * @param width setting item width. + */ + void SetItemWidth(uint16_t width); + + /** + * @brief Set ratote angle between the left and right items in static display mode. + * + * @param angle setting ratote angle. + */ + void SetRotateAngle(float angle); + + /** + * @brief Set mirror image opacity. + * + * @param opa setting mirror opacity value. + */ + void SetMirrorOpacity(uint8_t opa); + + /** + * @brief Represents a listener for swipe of the coverflow view. + */ + class OnCoverflowScrollListener : public HeapBase { + public: + virtual bool OnScroll() = 0; + virtual ~OnCoverflowScrollListener() {} + }; + + /** + * @brief Sets the listener that contains a callback to be invoked upon a swipe event. + * + * @param onCoverflowListener Indicates the listener to set. + * @since 1.0 + * @version 1.0 + */ + void SetOnCoverflowListener(OnCoverflowScrollListener* onCoverflowListener) + { + coverflowListener_ = onCoverflowListener; + } + + void SetDirection(uint8_t direction) = delete; + uint8_t GetDirection() const = delete; +protected: + bool DragXInner(int16_t distance) override; + +private: + void UpdatePerspectiveMatrix(); + void ReMeasure(void) override; + void TransformImage(UIImageView* view); + void TransformPage(uint16_t index); + void DeleteGroup(UIViewGroup* group); + + using UISwipeView::Add; + using UISwipeView::Remove; + + OnCoverflowScrollListener* coverflowListener_; + uint16_t itemWidth_; + uint8_t mirrorOpa_; + float rotateAngle_; + std::map> map_; + Matrix4 perspectiveMatrix_; +}; +} // namespace OHOS +#endif // UI_COVERFLOW_VIEW_H diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_cross_view.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_cross_view.h index 0f05ee094..e0d4fefb4 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_cross_view.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_cross_view.h @@ -40,6 +40,9 @@ namespace OHOS { */ class UICrossView : public UIViewGroup, public UISwipeView::OnSwipeListener { public: + UICrossView(const UICrossView &) = delete; + UICrossView &operator=(const UICrossView &) = delete; + /* * * @brief Scale align mode. */ @@ -60,7 +63,7 @@ public: * @since 1.0 * @version 1.0 */ - virtual ~UICrossView() override; + ~UICrossView() override; /* * * @brief Get the static instance for UICrossView. @@ -89,7 +92,7 @@ public: void HorAdd(UICardPage* view); /* * - * @brief Insert view by horizontal direction. + * @brief Insert view by horizontal direction. set as first page if preview is nullptr * @since 1.0 * @version 1.0 */ @@ -203,18 +206,22 @@ public: } private: + void UpdateCardPageIndex(); + static constexpr uint16_t INVALID_VIEW_INDEX = 0xff; bool loop_ = false; bool enableScreenCap_ = false; bool GaussianBlurEnable_ = false; int swipeDirect_ = 0; int pullIndex_ = 0; - int16_t hDragStartIndex_ = 0xff; - int16_t vBlankIndex_ = 0xff; - UIView* Vertblank_ = nullptr; + int16_t hDragStartIndex_ = INVALID_VIEW_INDEX; + int16_t vBlankIndex_ = INVALID_VIEW_INDEX; + UIView* vBlankView_ = nullptr; UISwipeView vertical_; HorSwipeView horizontal_; + UIView* tailView_ = nullptr; UISwipeView::OnSwipeListener *swipeListener_ = nullptr; + void RemoveAllInner(UISwipeView& view); void ProcessRes(void); void VertSetGausBlur(uint16_t direct); void HorHandleCardEvent(int16_t index, uint16_t scrollStage); diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_custom_hexagons_list.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_custom_hexagons_list.h new file mode 100644 index 000000000..a17072cca --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_custom_hexagons_list.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +#ifndef UI_HEXAGONS_LIST_EXT_H +#define UI_HEXAGONS_LIST_EXT_H +#include "components/ui_hexagons_list.h" + +namespace OHOS { +class UICustomHexagonsList : public UIHexagonsList { +public: + UICustomHexagonsList() {} + ~UICustomHexagonsList() override; + UICustomHexagonsList(const UICustomHexagonsList &) = delete; + UICustomHexagonsList &operator=(const UICustomHexagonsList &) = delete; + +#if ENABLE_ROTATE_INPUT + bool OnRotateStartEvent(const RotateEvent& event) override; + + bool OnRotateEvent(const RotateEvent& event) override; + + bool OnRotateEndEvent(const RotateEvent& event) override; +#endif + void StartRotateAnimator(uint8_t center, int16_t xDistance, int16_t yDistance, float startScale, float endScale); + void StopRotateAnimator(); + float GetScaleInSmallState() + { + return scaleInSmallState_; + } + +protected: + class RotateAnimatorCallback : public ListAnimatorCallback { + public: + RotateAnimatorCallback(); + ~RotateAnimatorCallback() override {} + RotateAnimatorCallback(const RotateAnimatorCallback &) = delete; + RotateAnimatorCallback &operator=(const RotateAnimatorCallback &) = delete; + + void SetDuration(uint16_t times) + { + totalTime_ = times; + } + + void SetCenterIndex(uint8_t center) + { + centerIndex_ = center; + } + + void SetRotateRange(int16_t xDistance, int16_t yDistance, float startScale, float endScale) + { + xDistance_ = xDistance; + yDistance_ = yDistance; + startScale_ = startScale; + endScale_ = endScale; + } + + void ResetCallback() + { + curTime_ = 0; + totalTime_ = 0; + xDistance_ = 0; + prevX_ = 0; + yDistance_ = 0; + prevY_ = 0; + startScale_ = 0.0f; + endScale_ = 0.0f; + centerIndex_ = 0; + } + + void Callback(UIView* view) override; + + private: + uint16_t curTime_; + uint16_t totalTime_; + int16_t xDistance_; + int16_t yDistance_; + int16_t prevX_; + int16_t prevY_; + float startScale_; + float endScale_; + uint8_t centerIndex_; + }; +private: + RotateAnimatorCallback rotateCallback_; + Animator* rotateAnimator_ = nullptr; + float scaleInSmallState_ = 0.42f; + uint8_t rotateCenterIndexInNormal_ = 0; +}; +} +#endif // UI_HEXAGONS_LIST_EXT_H \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_hexagons_list.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_hexagons_list.h new file mode 100644 index 000000000..5a7e3d11d --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_hexagons_list.h @@ -0,0 +1,231 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +#ifndef UI_HEXAGONS_LIST_H +#define UI_HEXAGONS_LIST_H + +#include "components/ui_view.h" +#include "components/ui_abstract_scroll.h" +#include "components/ui_scroll_view.h" +#include "gfx_utils/list.h" +#include "gfx_utils/vector.h" + +namespace OHOS { +class UIHexagonsList : public UIScrollView { +public: + UIHexagonsList(); + + ~UIHexagonsList() override {} + + /** + * @brief Set origin image distance between the center of the two adjacent images + * imageDistance = oriImgDistance * globalScale + * globalScale: refer to function Scale + * LayoutChildren(true) must be invoked mannualy after invoking this method. + * + * @param distance Indicates image distance to set when the image in the center region + */ + void SetImageDistance(uint16_t distance) + { + oriImgDistance_ = distance; + } + + /** + * @brief Set image size + * LayoutChildren(true) must be invoked mannualy after invoking this method. + * + * @param size Indicates size to set, when the image in the center + */ + void SetImageSizeInCenter(uint16_t size) + { + imgSizeInCenter_ = size; + } + + /** + * @brief Set origin image scale factor, scale strategy will follow the below rules + * if globalScale >= 1 + * scaleFactor = oriScaleFactor + * elif globalScale > scaleThreshold + * scaleFactor = oriScaleFactor * (globalScale - scaleThreshold) / (1 - scaleThrethold) + * else + * scaleFactor = 0 + * img size is inversely proportional to distance * scaleFactor + * + * oriScaleFactor: refer to function SetScaleFactorByDistance + * scaleThreshold: refer to function SetScaleThesholdOfZeroFactor + * globalScale: refer to function Scale + * + * @param factor Indicates scale factor to set, which will decide scale value together with distance + */ + void SetScaleFactorByDistance(float factor) + { + oriScaleFactor_ = factor; + } + + float GetScaleFactorByDistance() + { + return oriScaleFactor_; + } + + /** + * @brief Set scale threshold, scale factor will decrese to 0 if global scale equal and less than scaleThreshold, + * default value is 0.6, more information can refer to method SetScaleFactorByDistance + * + * @param threshold Indicates factor to set, the scale factor when the image is not in the center + */ + void SetScaleThesholdOfZeroFactor(float threshold) + { + scaleThresholdOfZeroFactor_ = threshold; + } + + float GetScaleThesholdOfZeroFactor() + { + return scaleThresholdOfZeroFactor_; + } + + /** + * @brief Adds a child image view whose resize mode will set to be UIImageView::COVER. + * LayoutChildren(true) should be invoked mannualy after invoking this method. + * Note: View index was set for children innner in order of addition, so you can + * get its index by call method GetViewIndex() + * + * @param view Indicates the pointer to the child view to add. + */ + void Add(UIView* view) override; + + /** + * @brief Inserts a child image view whose resize mode will set to be UIImageView::COVER. + * LayoutChildren(true) should be invoked mannualy after invoking this method. + * Note: View index was set for children innner in order of addition, so you can + * get its index by call method GetViewIndex() + * + * @param prevView Indicates the pointer to the child image view, previous to the new child image view. + * @param view Indicates the pointer to the new child image view to insert. + */ + void Insert(UIView* prevView, UIView* insertView) override; + + bool OnDragEvent(const DragEvent& event) override; + + /** + * @brief Lays out all children views according to the hexagons shape, it must be invoked after method: + * 1. Add(UIView* view) + * 2. Insert(UIView* prevView, UIView* insertView) + * 3. void SetImageSizeInCenter(uint16_t size) + * 4. void SetImageDistance(uint16_t distance) + * + * @param needInvalidate Specifies whether to refresh the invalidated area after the layout is complete. + * Value true means to refresh the invalidated area after the layout is complete, + * and false means the opposite. + */ + void LayoutChildren(bool needInvalidate = false) override; + + /** + * @brief Moves all child views. + * + * @param x Indicates the offset distance by which this view group is moved on the x-axis. + * @param y Indicates the offset distance by which this view group is moved on the y-axis. + */ + void MoveChildByOffset(int16_t offsetX, int16_t offsetY) override; + + /** + * @brief Set global scale, and image with centerIndex will be focused + * + * @param scale Indicates global scale value both for x- and y- axes. + * @param pivot Indicates index of scaling center. + */ + void Scale(float scale, uint8_t centerIndex); + + float GetGlobalScale() + { + return globalScale_; + } + + /** + * @brief Get the Index Of View object in this view group + * + * @param view, Indicates the view to search + * @return Returns the index, -1 if not exsit + */ + UIView* GetViewByIndex(uint8_t index); + + enum class ReboundMode : uint8_t { + NEAREST_IMG_ON_SCR_CENTER, + CENTER_IMG_ON_SCR_CENTER, + NORMAL, // same with UIScrollView + }; + + void SetReboundMode(ReboundMode mode) + { + reboundMode = mode; + } + + /** + * @brief Get index of focused image, default 0, changed by scale and scroll + * When scroll animator end, the index of image in the center screen will set to be focus index + * When start Scale(scale, index), scale center index will set to be focus index + * @return Returns index of focused image, -1 if rebound mode is NORMAL + */ + int8_t GetFocusedImgIndex() + { + if (reboundMode == ReboundMode::NORMAL) { + return -1; + } else { + return focusImgIndex_; + } + } + + /** + * @brief Get center position of the special(index) image + * Note: the position is not actual position, it is position in regular hexagon without futher adjustment + * which include adjusting the img zoom and distance in order to improve display experience + * + * @return Returns postion in regular hexagon + */ + Vector2 GetCurrentPosition(uint8_t index); + +protected: + bool DragXInner(int16_t distance) override; + bool DragYInner(int16_t distance) override; + void ReMeasure() override; + /** + * @brief Get center position of the special(index) image when scale and center image index in screen is specified + * + * @return Returns position + */ + Vector2 GetPositionWithCondition(uint8_t index, uint8_t centerIndex, float scale); + + float globalScale_{1.0f}; + float scaleThresholdOfZeroFactor_{0.75f}; + +private: + void InitParametersAndImgIndex(); + bool IsCenterInPolygons(const Vector2& offset = {0, 0}); + Rect GetChildrenRegion(); + void CalculateAdjustDistanceForRectScreen(Vector2& position, float& imgScaleRatio); + void AdjustViewByDistance(UIView& view, const Vector2& position); + void CalculateReboundDistance(int16_t& dragDistanceX, int16_t& dragDistanceY) override; + void CalculateReboundDistanceForNormal(int16_t& dragDistanceX, int16_t& dragDistanceY); + void CalculateReboundDistanceForNearestOnCenter(int16_t& dragDistanceX, int16_t& dragDistanceY); + void CalculateNearestPointFromOutterPoint(const Vector2& outerPoint); + void UpdateNearestPointFromFixedPoint(const Vector2& fixedPoint, uint8_t index); + void CreatePolygons(uint16_t lap, int16_t angle); + Graphic::Vector> imgPoints_{64}; + uint16_t maxLap_ = 0; + uint16_t maxAngleInMaxLap_ = 0; + Graphic::Vector polygonPoints_{10}; + uint16_t imgDistance_{0}; + uint16_t oriImgDistance_{0}; + float oriScaleFactor_{0.23f}; + int16_t imgSizeInCenter_{0}; + uint32_t minDistancePow_{0xFFFFFFFF}; + uint8_t nearestIndex_{0}; + uint8_t focusImgIndex_{0}; + float oriImgRadius_{0.0f}; + float imgRadius_{0.0f}; + int16_t centerX_{0}; + int16_t centerY_{0}; + ReboundMode reboundMode{ReboundMode::NEAREST_IMG_ON_SCR_CENTER}; +}; +} +#endif // UI_HEXAGONS_LIST_H \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_kaleidoscope_view.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_kaleidoscope_view.h new file mode 100644 index 000000000..fcb00217f --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_kaleidoscope_view.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +/** + * @addtogroup UI_Components + * @{ + * + * @brief Defines UI components such as buttons, texts, images, lists, and progress bars. + */ + +/** + * @file ui_kaleidoscope_view.h + * + * @brief Declares a UIKaleidoscopeView. + */ + +#ifndef UI_KALEIDOSCOPE_VIEW_H +#define UI_KALEIDOSCOPE_VIEW_H + +#include "components/ui_view.h" +#include "gfx_utils/image_info.h" +#include "components/kaleidoscope_utils.h" +#include "hals/display_dev.h" + +namespace OHOS { +/** + * @brief It provide kaleidoscope view. + */ +class UIKaleidoscopeView : public UIView { +public: + UIKaleidoscopeView(const UIKaleidoscopeView &) = delete; + UIKaleidoscopeView &operator=(const UIKaleidoscopeView &) = delete; + + /** + * @brief A constructor used to create the UIKaleidoscopeView instance. + This view will directly modify the buffer, and it is the same size as the screen. + */ + UIKaleidoscopeView(); + + /** + * @brief A destructor used to delete the UIKaleidoscopeView instance. + */ + ~UIKaleidoscopeView() override; + + /** + * @brief Obtains the view type. + * @return Returns UI_KALEIDOSCOPE_VIEW, as defined in {@link UIViewType}. + */ + UIViewType GetViewType() const override + { + return UI_KALEIDOSCOPE_VIEW; + } + + /** + * @brief Set src img for kaleidoscope. + * @param [in] src Pointer to a ImageInfo struct, which is the source img for kaleidoscope img. + The size of img must match the size of screen. + * @return Return true if set successfully; and false otherwise. + */ + bool SetSrc(const ImageInfo* info); + + /** + * @brief Update the kaleidoscope by a rotate value. + * @param [in] rotate Rotate value. + */ + void Rotate(float rotate); + +#if ENABLE_ROTATE_INPUT + /** + * @brief Set rotate factor for rotate event. + */ + void SetRotateEventFactor(float factor); + + /** + * @brief Handle Rotate Event. Update the kaleidoscope by a rotate event. + * @param [in] event Rotate event. + */ + bool OnRotateEvent(const RotateEvent& event) override; +#endif + + /** + * @brief Set rotate value for rotate animator callback. + * @param [in] rotate Rotate value. + */ + void SetRotateAnimatorValue(float rotate); + + /** + * @brief Start rotate animator + */ + void StartRotateAnimator(); + + /** + * @brief Stop rotate animator + */ + void StopRotateAnimator(); + + void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; +private: + class RotateCallback : public AnimatorCallback { + public: + RotateCallback() {} + ~RotateCallback() override {} + void SetRotateValue(float rotate); + void Callback(UIView* view) override; + private: + float rotate_ = 0.0f; + }; + +#if ENABLE_ROTATE_INPUT + float factor_ = 1.0f; +#endif + float rotate_ = 0.0f; + KaleidoscopeUtils kaleidoscope_; + RotateCallback callback_; + Animator* animator_ = nullptr; +}; +} +#endif +/** + * @} + */ diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_map_view.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_map_view.h new file mode 100644 index 000000000..75a255743 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_map_view.h @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * 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. + */ + +/** + * @addtogroup UI_Components + * @{ + * + * @brief Defines UI components such as buttons, texts, images, lists, and progress bars. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file ui_map_view.h + * + * @brief Defines the class to extend canvas/paint ability. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef GRAPHIC_LITE_UI_MAP_VIEW_H +#define GRAPHIC_LITE_UI_MAP_VIEW_H +#include "components_ext/map_svg_parser.h" +#include "components/ui_view_group.h" + +namespace OHOS { +#if ENABLE_VGU_ENGINE && CAPABILITY_HWDRAW_PATH +struct POIInfo { + ImageDetail* img; + TextDetail* text[2]; + uint8_t tag; + uint16_t rank; + uint16_t id; + Rect rect; + Point orignPos; + bool visible; +}; + +struct RoadInfo { + TextDetail* text; + Rect rect; + Point orignPos; + bool visible; +}; + +class OnPOIClickListener : public HeapBase { +public: + /* * + * @brief Called when a POI is clicked. + * @since 1.0 + * @version 1.0 + */ + virtual bool OnClick(uint32_t index) + { + return false; + } + + /* * + * @brief A destructor used to delete the OnPOIClickListener instance. + * @since 1.0 + * @version 1.0 + */ + virtual ~OnPOIClickListener() {} +}; + +class UIMapView : public UIViewGroup, public UIView::OnClickListener { +public: + UIMapView(const UIMapView &) = delete; + UIMapView &operator=(const UIMapView &) = delete; + + /* * + * @brief A constructor used to create an UIMapView instance. + * + */ + UIMapView(); + + /* * + * @brief A destructor used to delete the UIMapView instance. + * + */ + ~UIMapView() override; + + /* * + * @brief Get current view type. + * + */ + UIViewType GetViewType() const override + { + return UI_MAP_VIEW; + } + + /* * + * @brief Set SVG src with file path. + * + */ + bool SetSVG(const char* path); + + /* * + * @brief Set SVG src with file buffer. + * + */ + bool SetSVG(uint8_t* data, uint32_t length); + + /* * + * @brief Set POI on cick listener. + * + */ + void SetOnPOIClickListener(OnPOIClickListener* listener); + + /* * + * @brief Enable cache. It will cache this tile immediately when enable is true, + * and free cache buffer immediately. We need to enable cache when setting svg, + * or after scale map finished, and disable cache before scale map. + * + */ + void EnableCache(bool enable); + + /* * + * @brief Used to scale map base the target point. + * + */ + void ScaleMap(float scale, const Vector2& pivot); + + /* * + * @brief Hide the POI by tag. + * + */ + void HidePOI(uint16_t tag, bool isHide = true); + void SetX(int16_t x) override; + void SetY(int16_t x) override; + +private: + POIInfo* POIs_ = nullptr; + RoadInfo* roads_ = nullptr; + OnPOIClickListener* POIlistener_ = nullptr; + bool cacheEnable_ = false; + bool needUpdate_ = false; + ImageInfo cacheInfo_ = {{0}}; + MapSVGParser parser_; + uint8_t* data_ = nullptr; + char* filePath_ = nullptr; + PathDetail* pathArray_ = nullptr; + uint8_t pathCount_ = 0; + RoadDetail* roadArray_ = nullptr; + uint8_t roadCount_ = 0; + POIDetail* POIArray_ = nullptr; + uint8_t POICount_ = 0; + char* fontName_ = DEFAULT_VECTOR_FONT_FILENAME; + uint8_t fontId_ = 0xff; + uint8_t fontSize_ = 0; + uint32_t POIMask_ = 0; + float scale_ = 1.0f; + + void DrawPath(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea); + void DrawText(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, TextDetail& info, Point offset = {0, 0}, + bool isPOIText = false); + Rect DrawImage(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, ImageInfo& info, MapRect& rect); + void DrawPOIs(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea); + void DrawRoads(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea); + bool RenderMapToCache(void); + void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + void HandlePOICollision(); + void HandleRoadCollision(); + bool InitPOIInfo(int num); + bool InitRoadInfo(int num); + void ClearSVG(); +}; +#endif +} +#endif +/** + * @} + */ diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_menu_item.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_menu_item.h index 5463c07fc..d2bea3e33 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_menu_item.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_menu_item.h @@ -48,6 +48,9 @@ namespace OHOS { */ class UIMenuItem : public UIButton { public: + UIMenuItem(const UIMenuItem &) = delete; + UIMenuItem &operator=(const UIMenuItem &) = delete; + /** * @brief Scale align mode. */ @@ -85,7 +88,7 @@ public: return UI_MENU_ITEM; } - /** + /** * @brief Sets the image path for menu image. * * @since 1.0 diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_custom_hexagons_list.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_custom_hexagons_list.cpp new file mode 100644 index 000000000..c6a48d506 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_custom_hexagons_list.cpp @@ -0,0 +1,187 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +#include "components/ui_custom_hexagons_list.h" +#include "animator/easing_equation.h" + +namespace OHOS { +static const float TRASPANRENT_SCALE = 2.5f; +static const float ROTATE_SCALE_FACTOR = 0.02f; +static const float SCALE_SMALLEST_VALUE = 0.1f; +static const float ROTATE_ANIMATION_DURATION = 10; + +UICustomHexagonsList::~UICustomHexagonsList() +{ + if (rotateAnimator_ != nullptr) { + delete rotateAnimator_; + rotateAnimator_ = nullptr; + } +} + +UICustomHexagonsList::RotateAnimatorCallback::RotateAnimatorCallback() + : curTime_(0), + totalTime_(0), + xDistance_(0), + yDistance_(0), + prevX_(0), + prevY_(0), + startScale_(0.0f), + endScale_(0.0f), + centerIndex_(0) +{} + +void UICustomHexagonsList::RotateAnimatorCallback::Callback(UIView* view) +{ + UICustomHexagonsList* hexView = dynamic_cast(view); + if (hexView == nullptr) { + return; + } + curTime_++; + if (curTime_ > totalTime_) { + hexView->StopRotateAnimator(); + return; + } + float timeRatio = curTime_ * 1.0f / totalTime_; + if (!FloatEqual(xDistance_, 0)) { + if (!FloatEqual(prevX_, xDistance_)) { + int16_t curX = static_cast(timeRatio * xDistance_); + hexView->DragXInner(curX - prevX_); + prevX_ = curX; + } + } + if (!FloatEqual(yDistance_, 0)) { + if (!FloatEqual(prevY_, yDistance_)) { + int16_t curY = static_cast(timeRatio * yDistance_); + hexView->DragYInner(curY - prevY_); + prevY_ = curY; + } + } + float curScale = timeRatio * (endScale_ - startScale_) + startScale_; + if (FloatMoreEqual(curScale, 1.0f)) { + uint8_t opa = static_cast((1 - (curScale - 1.0f) / (TRASPANRENT_SCALE - 1.0f)) * OPA_OPAQUE); + hexView->GetViewByIndex(centerIndex_)->SetOpaScale(opa); + } + if ((FloatMore(startScale_, endScale_) && (curScale >= endScale_)) || + (FloatLess(startScale_, endScale_) || (curScale <= endScale_))) { + hexView->Scale(curScale, centerIndex_); + } + if (FloatEqual(curScale, endScale_)) { + hexView->StopRotateAnimator(); + } +} + +void UICustomHexagonsList::StartRotateAnimator(uint8_t center, int16_t xDistance, int16_t yDistance, + float startScale, float endScale) +{ + if (rotateAnimator_ == nullptr) { + rotateAnimator_ = new Animator(&rotateCallback_, this, 0, true); + } + rotateCallback_.ResetCallback(); + rotateCallback_.SetCenterIndex(center); + rotateCallback_.SetDuration(ROTATE_ANIMATION_DURATION); + rotateCallback_.SetRotateRange(xDistance, yDistance, startScale, endScale); + rotateAnimator_->Start(); +} + +void UICustomHexagonsList::StopRotateAnimator() +{ + rotateAnimator_->Stop(); + rotateCallback_.ResetCallback(); +} + +#if ENABLE_ROTATE_INPUT +bool UICustomHexagonsList::OnRotateStartEvent(const RotateEvent& event) +{ + if (scrollAnimator_.GetState() != Animator::STOP) { + UIAbstractScroll::StopAnimator(); + } + if ((rotateAnimator_ != nullptr) && (rotateAnimator_->GetState() != Animator::STOP)) { + StopRotateAnimator(); + } + + // Record rotate center index when scale is large than 1.0f + if (FloatMoreEqual(GetGlobalScale(), 1.0f)) { + int8_t focusIndex = GetFocusedImgIndex(); + if (focusIndex < 0) { + GRAPHIC_LOGE("wrong focus index %d, force to be 0 !!", focusIndex); + rotateCenterIndexInNormal_ = 0; + } else { + rotateCenterIndexInNormal_ = static_cast(focusIndex); + } + } + return UIView::OnRotateStartEvent(event); +} + +bool UICustomHexagonsList::OnRotateEvent(const RotateEvent& event) +{ + float deltaScale = event.GetRotate() * ROTATE_SCALE_FACTOR; + float targetScale = globalScale_ + deltaScale; + Vector2 position = GetCurrentPosition(rotateCenterIndexInNormal_); + Vector2 deltaDistance; + // Current scale > Normal(1.0f), scale and change opaque + if (FloatMore(targetScale, 1.0f)) { + UIView* view = GetViewByIndex(rotateCenterIndexInNormal_); + uint8_t opa = static_cast((1 - (targetScale - 1.0f) / (TRASPANRENT_SCALE - 1.0f)) * OPA_OPAQUE); + if (view != nullptr) { + view->SetOpaScale(opa); + } + Scale(targetScale, rotateCenterIndexInNormal_); + // Current scale in [Equal-Threshold, Normal], only scale + } else if (FloatMoreEqual(targetScale, scaleThresholdOfZeroFactor_)) { + Scale(targetScale, rotateCenterIndexInNormal_); + // Current scale in [Small, Equal-Threshold), scale and scroll + } else if (FloatMore(targetScale, scaleInSmallState_)) { + if (deltaScale < 0) { + Vector2 targetPos = GetPositionWithCondition(rotateCenterIndexInNormal_, 0, scaleInSmallState_); + deltaDistance = targetPos - position; + float deltaScaleToSmallState = scaleInSmallState_ - globalScale_; + int16_t deltaX = static_cast(deltaDistance.x_ / deltaScaleToSmallState * deltaScale); + int16_t deltaY = static_cast(deltaDistance.y_ / deltaScaleToSmallState * deltaScale); + ScrollBy(deltaX, deltaY); + } else { + deltaDistance = Vector2(GetWidth() / 2, GetHeight() / 2) - position; // 2, center + float deltaScaleToSmallState = scaleThresholdOfZeroFactor_ - globalScale_; + int16_t deltaX = static_cast(deltaDistance.x_ / deltaScaleToSmallState * deltaScale); + int16_t deltaY = static_cast(deltaDistance.y_ / deltaScaleToSmallState * deltaScale); + ScrollBy(deltaX, deltaY); + } + Scale(targetScale, rotateCenterIndexInNormal_); + // Current scale in [Smallest, Small), only scale + } else if (FloatMore(targetScale, SCALE_SMALLEST_VALUE)) { + Vector2 centerImgPosition = GetCurrentPosition(0); + Vector2 targetPos(GetWidth() / 2, GetHeight() / 2); // 2, center + deltaDistance = targetPos - centerImgPosition; + ScrollBy(deltaDistance.x_, deltaDistance.y_); + Scale(targetScale, 0); + } + return UIView::OnRotateEvent(event); +} + +bool UICustomHexagonsList::OnRotateEndEvent(const RotateEvent& event) +{ + // Rotate end in (Normal, .), start animator to enter Normal State + if (FloatMore(globalScale_, 1.0f)) { + StartRotateAnimator(rotateCenterIndexInNormal_, 0, 0, globalScale_, 1.0f); + SetReboundMode(ReboundMode::NEAREST_IMG_ON_SCR_CENTER); + // Rotate end in (Equal-Threshold, Normal), start animator to enter Normal State + } else if (FloatMore(globalScale_, scaleThresholdOfZeroFactor_)) { + StartRotateAnimator(rotateCenterIndexInNormal_, 0, 0, globalScale_, 1.0f); + SetReboundMode(ReboundMode::NEAREST_IMG_ON_SCR_CENTER); + // Rotate end in (Small, Equal-Threshold), start animator to enter Small State + } else if (FloatMore(globalScale_, scaleInSmallState_)) { + Vector2 targetPos = GetPositionWithCondition(rotateCenterIndexInNormal_, 0, scaleInSmallState_); + Vector2 curPos = GetCurrentPosition(rotateCenterIndexInNormal_); + Vector2 delta = targetPos - curPos; + StartRotateAnimator(rotateCenterIndexInNormal_, delta.x_, delta.y_, globalScale_, scaleInSmallState_); + SetReboundMode(ReboundMode::CENTER_IMG_ON_SCR_CENTER); + // Rotate end in (., Small), start animator to enter Small State + } else { + StartRotateAnimator(0, 0, 0, globalScale_, scaleInSmallState_); + SetReboundMode(ReboundMode::CENTER_IMG_ON_SCR_CENTER); + } + + return UIView::OnRotateEndEvent(event); +} +#endif +} \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_list_ext.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_list_ext.cpp index 1eaaacbc2..628788d7d 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_list_ext.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_list_ext.cpp @@ -35,12 +35,12 @@ void UIListExt::ReMeasure() if (direction_ == VERTICAL) { int offset = (y + view->GetHeight() / 2 - midY); int temp = EasingEquation::SineEaseIn(0, scaleFactor_, abs(offset), scaleFactor_); - float scale = 1.0 - ((float)temp / scaleFactor_); + float scale = 1.0 - (static_cast(temp) / scaleFactor_); view->Scale(Vector2(scale, scale), view->GetScaleCenter()); } else { int offset = (x + view->GetWidth() / 2 - midX); int temp = EasingEquation::SineEaseIn(0, scaleFactor_, abs(offset), scaleFactor_); - float scale = 1.0 - ((float)temp / scaleFactor_); + float scale = 1.0 - (static_cast(temp) / scaleFactor_); view->Scale(Vector2(scale, scale), view->GetScaleCenter()); } view = static_cast(view->GetNextSibling()); diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_lite_surface_view.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_lite_surface_view.cpp index dc4ccb5f4..ca2585861 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_lite_surface_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_lite_surface_view.cpp @@ -214,8 +214,8 @@ bool UILiteSurfaceView::GetBitmap(ImageInfo& bitmap) UIView::GetBitmap(bitmap); } else { CscYuvBuf yuv = {0}; - yuv.yAddr = (uint8_t*)lastFlushedBuffer_->addr; - yuv.uvAddr = (uint8_t*)yuv.yAddr + ALIGN_BYTE(lastFlushedBuffer_->width, YUV_WIDTH_ALIGNMENT) * + yuv.yAddr = reinterpret_cast(lastFlushedBuffer_->addr); + yuv.uvAddr = static_cast(yuv.yAddr) + ALIGN_BYTE(lastFlushedBuffer_->width, YUV_WIDTH_ALIGNMENT) * lastFlushedBuffer_->height; yuv.width = lastFlushedBuffer_->width; yuv.height = lastFlushedBuffer_->height; @@ -236,7 +236,7 @@ bool UILiteSurfaceView::GetBitmap(ImageInfo& bitmap) rgb.addr = reinterpret_cast(ImageCacheMalloc(bitmap)); CscConvertYuvToRgb(&rgb, &yuv); } - return true; + return true; } void UILiteSurfaceView::BlitBitmapToFb(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, ImageInfo& bitmap) diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/hor_swipe_view.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/hor_swipe_view.h index 1900882a7..5a5fb8e8b 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/hor_swipe_view.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/hor_swipe_view.h @@ -25,7 +25,7 @@ public: * @since 1.0 * @version 1.0 */ - virtual ~HorSwipeView() {} + ~HorSwipeView() override {} bool DragXInner(int16_t distance) override; bool OnDragEvent(const DragEvent& event) override; diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/map_svg_parser.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/map_svg_parser.h new file mode 100644 index 000000000..d2efc3bfc --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/map_svg_parser.h @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * 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. + */ +#ifndef GRAPHIC_LITE_MAP_SVG_PARSER_H +#define GRAPHIC_LITE_MAP_SVG_PARSER_H +#include +#include "gfx_utils/color.h" + +namespace OHOS { +struct MapRect { + int16_t x; + int16_t y; + int16_t width; + int16_t height; +}; + +struct PathStyle { + uint8_t strokeCap : 4; + uint8_t strokeJoin : 4; + Color24 strokeColor; + Color24 fillColor; + float strokeWidth; +}; + +struct MapPathBase { + uint8_t type; + uint8_t pathStyleIndex; + uint16_t cmdNum; + uint16_t dataNum; +}; + +struct PathDetail { + MapPathBase base; + uint8_t* cmd; + float* data; +}; + +struct ImageBase { + uint8_t id; + MapRect rect; +}; + +struct ImageDetail { + ImageBase base; + ImageInfo* info; +}; + +struct MapTextBase { + uint8_t fontSize; + Color24 fontColor; + Color24 strokeColor; + float strokeWidth; + MapRect rect; + uint16_t charLen; +}; + +struct TextDetail { + MapTextBase base; + char* text; + Point* offset; +}; + +struct POIDetail { + int8_t imgIndex; + int8_t textIndex[2]; + uint8_t tag; + uint16_t rank; + uint16_t id; +}; + +struct RoadDetail { + int8_t textIndex; +}; + +class MapSVGParser { +public: + MapSVGParser(void); + virtual ~MapSVGParser(void); + + bool SetSVG(uint8_t* data, uint32_t length); + Color24 GetBackGroundColor(void); + uint32_t GetImageOffset(void); + void GetSize(int16_t& width, int16_t& height); + + uint8_t GetPaths(PathDetail*& pathList); + uint8_t GetPOIs(POIDetail*& poiList); + uint8_t GetRoads(RoadDetail*& roadList); + + PathStyle* GetPathStyleByIndex(uint8_t index); + TextDetail* GetTextByIndex(uint8_t index); + ImageDetail* GetImageByIndex(uint8_t index); + void ClearSVG(uint8_t* data); + +private: + struct MapHeader { + Color24 bgColor; + uint8_t nodeNum; + uint8_t pathStyleNum; + int16_t width; + int16_t height; + uint32_t imgDataOffset; + }; + + struct MapNode { + uint8_t type; + uint8_t count; + uint32_t offset; + }; + + static constexpr uint8_t PARSER_TYPE_NUM = 5; + typedef uint32_t (MapSVGParser::*MapTypeParserInit)(uint8_t* data, uint32_t length, uint32_t offset, uint8_t count); + typedef void (MapSVGParser::*MapTypeParserDeinit)(uint8_t count); + + uint32_t ReadMapNode(uint8_t* data, uint32_t length, uint32_t offset); + uint32_t ReadPathStyle(uint8_t* data, uint32_t length, uint32_t offset); + uint32_t ReadMapPath(uint8_t* data, uint32_t length, uint32_t offset, uint8_t count); + uint32_t ReadMapText(uint8_t* data, uint32_t length, uint32_t offset, uint8_t count); + uint32_t ReadMapImg(uint8_t* data, uint32_t length, uint32_t offset, uint8_t count); + uint32_t ReadMapRoad(uint8_t* data, uint32_t length, uint32_t offset, uint8_t count); + uint32_t ReadMapPOI(uint8_t* data, uint32_t length, uint32_t offset, uint8_t count); + uint32_t ReadImage(uint8_t* data, uint32_t length, uint32_t offset); + + void ReleaseMapPath(uint8_t count); + void ReleaseMapText(uint8_t count); + void ReleaseMapImg(uint8_t count); + void ReleaseMapRoad(uint8_t count); + void ReleaseMapPOI(uint8_t count); + void ReleaseResource(void); + bool AllocPath(PathDetail& path, uint32_t cmdNum, uint32_t dataNum); + + MapTypeParserInit parserInitFunc[PARSER_TYPE_NUM] = { &MapSVGParser::ReadMapPath, &MapSVGParser::ReadMapText, + &MapSVGParser::ReadMapImg, &MapSVGParser::ReadMapRoad, + &MapSVGParser::ReadMapPOI }; + MapTypeParserDeinit parserDeinitFunc[PARSER_TYPE_NUM] = { + &MapSVGParser::ReleaseMapPath, &MapSVGParser::ReleaseMapText, &MapSVGParser::ReleaseMapImg, + &MapSVGParser::ReleaseMapRoad, &MapSVGParser::ReleaseMapPOI + }; + + MapHeader mapHeader_; + MapNode* nodeArray_ = nullptr; + PathStyle* pathStyleArray_ = nullptr; + PathDetail* pathArray_ = nullptr; + uint8_t pathCount_ = 0; + TextDetail* textArray_ = nullptr; + uint8_t textCount_ = 0; + ImageDetail* imageArray_ = nullptr; + uint8_t imageCount_ = 0; + RoadDetail* roadArray_ = nullptr; + uint8_t roadCount_ = 0; + POIDetail* poiArray_ = nullptr; + uint8_t poiCount_ = 0; +}; +} +#endif // GRAPHIC_LITE_MAP_SVG_PARSER_H diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/ui_card_container.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/ui_card_container.h index 0ada8aa61..c009fcd7d 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/ui_card_container.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/ui_card_container.h @@ -15,13 +15,16 @@ namespace OHOS { class UICardContainer : public UIViewGroup { public: UICardContainer(); - virtual ~UICardContainer() override; + ~UICardContainer() override; + UICardContainer(const UICardContainer &) = delete; + UICardContainer &operator=(const UICardContainer &) = delete; void SwitchCardToBitmap(bool bitMapFromFB = false); void SwitchBitmapToCard(void); void SetCardPage(UICardPage* page) { cardPage_ = page; + Add(cardPage_); Resize(page->GetWidth(), page->GetHeight()); } @@ -51,6 +54,14 @@ private: bool OnDragStartEvent(const DragEvent& event) override; bool OnDragEvent(const DragEvent& event) override; bool OnDragEndEvent(const DragEvent& event) override; + bool OnLongPressEvent(const LongPressEvent& event) override; + bool OnClickEvent(const ClickEvent& event) override; + bool OnPressEvent(const PressEvent& event) override; + bool OnReleaseEvent(const ReleaseEvent& event) override; + bool OnCancelEvent(const CancelEvent& event) override; +#if ENABLE_ROTATE_INPUT + bool OnRotateEvent(const RotateEvent& event) override; +#endif bool IsVideoContained(UIView* view); }; } diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/clip_img.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/clip_img.cpp index 960e76139..ca7d64cc4 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/clip_img.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/clip_img.cpp @@ -44,11 +44,10 @@ void ClipImg::ClipImgByPath(ImageInfo& dstInfo, ImageInfo& srcInfo, const Path* uintptr_t handle = LiteMGfxEngine::GetInstance()->InitPath(true); LiteMGfxEngine::GetInstance()->SetPathData(handle, path->cmdNum, path->cmds, path->dataNum, path->data); LiteMGfxEngine::GetInstance()->ClipImgByPath(dstInfo, srcInfo, handle, srcImgArea, pathMatrix, imgMatrix); - LiteMGfxEngine::GetInstance()->SyncHwDraw(); } -ImageInfo ClipImg::ClipImgByCircle(ImageInfo& srcInfo, Rect* srcImgArea, Point center, int16_t radius, - ColorMode mode) +ImageInfo ClipImg::ClipImgByCircle(ImageInfo& srcInfo, Point center, int16_t radius, + ColorMode mode, bool immediatelySync) { ImageInfo dstInfo = {{0}}; Path path = {0}; @@ -63,6 +62,9 @@ ImageInfo ClipImg::ClipImgByCircle(ImageInfo& srcInfo, Rect* srcImgArea, Point c } ClipImgByPath(dstInfo, srcInfo, &path, nullptr, nullptr, nullptr); + if (immediatelySync) { + LiteMGfxEngine::GetInstance()->SyncHwDraw(); + } ClearPath(&path); return dstInfo; } diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/clip_img.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/clip_img.h index 222a00ab9..f16b708b2 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/clip_img.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/clip_img.h @@ -20,8 +20,8 @@ class ClipImg : public HeapBase { public: static void ClipImgByPath(ImageInfo& dstInfo, ImageInfo& srcInfo, const Path* path, Rect* srcImgArea, const Matrix4* pathMatrix, const Matrix4* imgMatrix); - static ImageInfo ClipImgByCircle(ImageInfo& srcInfo, Rect* srcImgArea, Point center, int16_t radius, - ColorMode mode = RGB888); + static ImageInfo ClipImgByCircle(ImageInfo& srcInfo, Point center, int16_t radius, + ColorMode mode = RGB888, bool immediatelySync = false); static ImageInfo ClipImgByRect(ImageInfo& srcInfo, Rect* srcImgArea, Rect clipArea, ColorMode mode = RGB888); }; } // namespace OHOS diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/hw_draw_utils.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/hw_draw_utils.cpp index 3d848f687..72db48c0b 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/hw_draw_utils.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/hw_draw_utils.cpp @@ -98,6 +98,37 @@ int8_t HWDrawUtils::GetArcData(float* arcData, const Point& center, return bezierSegmentCount; } +void HWDrawUtils::Obtain30DegSectorPath(const ArcInfo& arc, uint8_t* cmd, float* data) +{ + float startAngle = arc.startAngle; + float endAngle = arc.endAngle; + float angleExtend = endAngle - startAngle; + float neg = (startAngle < endAngle) ? 1 : -1; + + ConvertCircularDegree(startAngle); + float startAngleRad = startAngle / RADIAN_TO_ANGLE; + float extendRad = static_cast(angleExtend) / RADIAN_TO_ANGLE; + float endAngleRad = startAngleRad + extendRad; + + cmd[0] = CMD_MOVE_TO; + cmd[1] = CMD_LINE_TO; + cmd[2] = CMD_CUBIC_TO; // 2: index + cmd[3] = CMD_CLOSE; // 3: index + + float a = startAngleRad + neg * RAD_90_DEG; + a = RAD_90_DEG - (a - endAngleRad) * neg; + + data[0] = arc.center.x; + data[1] = arc.center.y; + data[2] = arc.center.x + arc.radius * cos(startAngleRad); // 2: index + data[3] = arc.center.y + arc.radius * sin(startAngleRad); // 3: index + data[8] = arc.center.x + arc.radius * cos(endAngleRad); // 8: index + data[9] = arc.center.y + arc.radius * sin(endAngleRad); // 9: index + + float magicNum = 4.0f / 3.0f * (1 - cos(a / 2)) / sin(a / 2); // 2: divisor + GetArcControlPoint(&data[2], arc.center, magicNum, neg); // 2: index +} + bool HWDrawUtils::ObtainArcPath(const ArcInfo& arc, uint32_t& cmdNum, uint8_t*& cmds, uint32_t& dataNum, float*& data) { float startAngle = arc.startAngle; diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/hw_draw_utils.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/hw_draw_utils.h index 2136aab96..1284abfd7 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/hw_draw_utils.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/draw/hw_draw_utils.h @@ -31,6 +31,7 @@ public: bool ObtainArcPath(const ArcInfo& arc, uint32_t& cmdNum, uint8_t*& cmds, uint32_t& dataNum, float*& data); bool ObtainCirclePath(const ArcInfo& arc, uint32_t& cmdNum, uint8_t*& cmds, uint32_t& dataNum, float*& data); bool AllocBufferForData(uint16_t dataNum, float*& addr); + void Obtain30DegSectorPath(const ArcInfo& arc, uint8_t* cmd, float* data); private: HWDrawUtils() {} diff --git a/code/sdk/middleware/services/gui/uikit/res/hexagons.bin b/code/sdk/middleware/services/gui/uikit/res/hexagons.bin new file mode 100644 index 000000000..f3dc2e88b Binary files /dev/null and b/code/sdk/middleware/services/gui/uikit/res/hexagons.bin differ diff --git a/code/sdk/middleware/services/gui/uikit/res/kaleidoscope_dial.bin b/code/sdk/middleware/services/gui/uikit/res/kaleidoscope_dial.bin new file mode 100644 index 000000000..4c1cfd090 Binary files /dev/null and b/code/sdk/middleware/services/gui/uikit/res/kaleidoscope_dial.bin differ diff --git a/code/sdk/middleware/services/gui/uikit/res/map.bin b/code/sdk/middleware/services/gui/uikit/res/map.bin new file mode 100644 index 000000000..1aa3a3ad2 Binary files /dev/null and b/code/sdk/middleware/services/gui/uikit/res/map.bin differ diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow.cpp new file mode 100644 index 000000000..fd3e57978 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow.cpp @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * 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. + */ + +#include "ui_test_coverflow.h" +#include "common/screen.h" +#include "font/ui_font.h" +#include "gfx_utils/graphic_math.h" +#include "gfx_utils/rect.h" +#include "common/image_cache_manager.h" + +namespace OHOS { +namespace { +struct FaceInfo { + const char* name; + const char* path; +} ; + +static constexpr uint8_t COVERFLOW_MAX_PAGE_NUM = 6; +static FaceInfo g_faceInfo[COVERFLOW_MAX_PAGE_NUM] = { + {"1 rainbow", RES_PATH"/rainbow.bin"}, + {"2 kaleidoscope", RES_PATH"/kaleidoscope.bin"}, + {"3 planet", RES_PATH"/planet.bin"}, + {"4 rainbow", RES_PATH"/rainbow.bin"}, + {"5 kaleidoscope", RES_PATH"/kaleidoscope.bin"}, + {"6 planet", RES_PATH"/planet.bin"} +}; + +static constexpr uint8_t COVERFLOW_PRELOAD_PAGE_NUM = 3; +static constexpr int16_t LABEL_FONT_SIZE = 30; +static constexpr uint8_t DEFAULT_STEP = 10; +static constexpr uint16_t BUTTON_WIDTH = 60; +static constexpr uint16_t BUTTON_HEIGHT = 40; +static constexpr uint16_t BUTTON_GROUP_WIDTH = 300; +static constexpr uint16_t BUTTON_GROUP_HEIGHT = 80; +static constexpr uint8_t DIVISOR_TWO = 2; +} // namespace + +void UITestCoverflow::SetUp() +{ + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetThrowDrag(true); + container_->SetHorizontalScrollState(false); + container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + } +} + +void UITestCoverflow::TearDown() +{ + container_->Remove(coverflow_); + DeleteChildren(container_); + if (container_ != nullptr) { + container_ = nullptr; + } + delete coverflow_; + coverflow_ = nullptr; + showBtn_ = nullptr; + btnGrp_ = nullptr; + label_ = nullptr; + addBtn_ = nullptr; + removeBtn_ = nullptr; + mirrorOpaAddBtn_ = nullptr; + mirrorOpaSubBtn_ = nullptr; + pageWidthAddBtn_ = nullptr; + pageWidthSubBtn_ = nullptr; + maxAngleAddBtn_ = nullptr; + maxAngleSubBtn_ = nullptr; + loopBtn_ = nullptr; +} + +const UIView* UITestCoverflow::GetTestView() +{ + UITestCoverflowView001(); + return container_; +} + + +void UITestCoverflow::CreateLabelButton(UILabelButton** btn, const char* tile, int16_t x, int16_t y) +{ + UILabelButton* tempBtn = nullptr; + if (tempBtn == nullptr) { + tempBtn = new UILabelButton(); + } + tempBtn->SetPosition(x, y, BUTTON_WIDTH, BUTTON_HEIGHT); + tempBtn->SetText(tile); + tempBtn->SetOnClickListener(this); + btnGrp_->Add(tempBtn); + *btn = tempBtn; +} + +void UITestCoverflow::InitButtonGroup() +{ + if (showBtn_ == nullptr) { + showBtn_ = new UIButton(); + showBtn_->SetPosition(202, 10, BUTTON_WIDTH, BUTTON_HEIGHT); // 202: x position 10: y position + showBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::ButtonState::RELEASED); + showBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::ButtonState::PRESSED); + showBtn_->SetOnClickListener(this); + container_->Add(showBtn_); + } + if (btnGrp_ == nullptr) { + btnGrp_ = new UIViewGroup(); + btnGrp_->SetPosition(77, 40, BUTTON_GROUP_WIDTH, BUTTON_GROUP_HEIGHT); // 77: x position 40: y position + btnGrp_->SetStyle(STYLE_BACKGROUND_OPA, 0); + btnGrp_->SetVisible(false); + container_->Add(btnGrp_); + } + CreateLabelButton(&mirrorOpaAddBtn_, "opa+", 0, 0); + CreateLabelButton(&mirrorOpaSubBtn_, "opa-", 60, 0); // 60: x position + CreateLabelButton(&pageWidthAddBtn_, "wid+", 120, 0); // 120: x position + CreateLabelButton(&pageWidthSubBtn_, "wid-", 180, 0); // 180: x position + CreateLabelButton(&maxAngleAddBtn_, "ang+", 0, 40); // 40: y position + CreateLabelButton(&maxAngleSubBtn_, "ang-", 60, 40); // 60: x position 40: y position + CreateLabelButton(&addBtn_, "add", 120, 40); // 120: x position 40: y position + CreateLabelButton(&removeBtn_, "sub", 180, 40); // 180: x position 40: y position + CreateLabelButton(&loopBtn_, "loop", 240, 40); // 240: x position 40: y position +} + +void UITestCoverflow::UITestCoverflowView001() +{ + if (container_ != nullptr) { + if (coverflow_ == nullptr) { + coverflow_ = new UICoverflowView(); + } + coverflow_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + coverflow_->SetIntercept(true); + for (uint8_t i = 0; i < COVERFLOW_PRELOAD_PAGE_NUM; i++) { + ImageInfo* src = ImageCacheManager::GetInstance().LoadSingleRes(std::string(g_faceInfo[i].path)); + if (src == nullptr) { + continue; + } + coverflow_->Add(g_faceInfo[i].name, src); + loadNum_++; + } + + if (label_ == nullptr) { + label_ = new UILabel(); + } + label_->SetPosition(127, 50, 200, 50); // 127 50 200 50: label position + label_->SetTextColor(Color::White()); + label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + lastIndex_ = coverflow_->GetCurrentPage(); + label_->SetText(g_faceInfo[lastIndex_].name); + label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT_SIZE); + + coverflow_->SetOnCoverflowListener(this); + container_->Add(coverflow_); + container_->Add(label_); + InitButtonGroup(); + } +} + +bool UITestCoverflow::OnScroll() +{ + int16_t contMidX = static_cast(Screen::GetInstance().GetWidth() / DIVISOR_TWO); + int16_t minOffset = contMidX; + uint8_t newCenterIndex = lastIndex_; + for (uint8_t i = 0; i < coverflow_->GetChildrenNumber(); i++) { + Rect rect = coverflow_->GetViewByIndex(i)->GetOrigRect(); + int16_t x = rect.GetLeft(); + int16_t x1 = rect.GetRight(); + int16_t xMid = static_cast(x + (x1 - x + 1) / DIVISOR_TWO); + int16_t distance = MATH_ABS(xMid - contMidX); + if (distance < minOffset) { + newCenterIndex = i; + minOffset = distance; + } + } + if (newCenterIndex != lastIndex_) { + lastIndex_ = newCenterIndex; + label_->SetText(g_faceInfo[lastIndex_].name); + } + + Rect curViewRect = coverflow_->GetViewByIndex(lastIndex_)->GetOrigRect(); + int16_t centerMid = curViewRect.GetLeft() + curViewRect.GetWidth() / DIVISOR_TWO; + int16_t offset = MATH_ABS(contMidX - centerMid); + if (offset > curViewRect.GetWidth() / DIVISOR_TWO) { + label_->SetStyle(STYLE_TEXT_OPA, 0); + } else { + uint8_t alpha = (uint8_t)((1.0f - ((float)offset / (curViewRect.GetWidth() / DIVISOR_TWO))) * OPA_OPAQUE); + label_->SetStyle(STYLE_TEXT_OPA, alpha); + } + return true; +} + +bool UITestCoverflow::OnClick(UIView& view, const ClickEvent& event) +{ + if (&view == mirrorOpaAddBtn_) { + mirrorOpa_ += DEFAULT_STEP; + coverflow_->SetMirrorOpacity(mirrorOpa_); + } else if (&view == mirrorOpaSubBtn_) { + mirrorOpa_ -= DEFAULT_STEP; + coverflow_->SetMirrorOpacity(mirrorOpa_); + } else if (&view == showBtn_) { + btnGrp_->SetVisible(!btnGrp_->IsVisible()); + } else if (&view == loopBtn_) { + isLoop_ = !isLoop_; + coverflow_->SetLoopState(isLoop_); + if (isLoop_) { + loopBtn_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + } else { + loopBtn_->SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x00, 0x7d, 0xff).full); + } + } else if (&view == pageWidthAddBtn_) { + itemWidth_ += DEFAULT_STEP; + coverflow_->SetItemWidth(itemWidth_); + } else if (&view == pageWidthSubBtn_) { + itemWidth_ -= DEFAULT_STEP; + coverflow_->SetItemWidth(itemWidth_); + } else if (&view == addBtn_) { + if (loadNum_ >= COVERFLOW_MAX_PAGE_NUM) { + return true; + } + ImageInfo* src = ImageCacheManager::GetInstance().LoadSingleRes(std::string(g_faceInfo[loadNum_].path)); + coverflow_->Add(g_faceInfo[loadNum_++].name, src); + } else if (&view == removeBtn_) { + if (loadNum_ > 0) { + coverflow_->Remove(g_faceInfo[--loadNum_].name); + } + } else if (&view == maxAngleAddBtn_) { + rotateAngle_ += 2.0; // 2.0 variables per click + coverflow_->SetRotateAngle(rotateAngle_); + } else if (&view == maxAngleSubBtn_) { + rotateAngle_ -= 2.0; // 2.0 variables per click + coverflow_->SetRotateAngle(rotateAngle_); + } + coverflow_->Invalidate(); + return true; +} +} // namespace OHOS diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow.h new file mode 100644 index 000000000..b67c47e49 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * 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. + */ + +#ifndef UI_TEST_COVERFLOW_VIEW_H +#define UI_TEST_COVERFLOW_VIEW_H + +#include "components/ui_coverflow_view.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_button.h" +#include "animator/animator.h" +#include "ui_test.h" + +namespace OHOS { +class UITestCoverflow : public UITest, + public UICoverflowView::OnCoverflowScrollListener, public UIView::OnClickListener { +public: + UITestCoverflow() {} + ~UITestCoverflow() override {} + void SetUp() override; + void TearDown() override; + const UIView* GetTestView() override; + /** + * @brief Test display UICoverflow + */ + void UITestCoverflowView001(); + + bool OnScroll(); + + bool OnClick(UIView& view, const ClickEvent& event); +private: + void InitButtonGroup(); + void CreateLabelButton(UILabelButton** btn, const char* tile, int16_t x, int16_t y); + + UIScrollView* container_ = nullptr; + UICoverflowView* coverflow_ = nullptr; + UILabel* label_ = nullptr; + uint16_t lastIndex_ = 0; + UIButton* showBtn_ = nullptr; + bool isShowBtnGrp_ = false; + UIViewGroup* btnGrp_ = nullptr; + uint8_t loadNum_ = 0; + UILabelButton* addBtn_ = nullptr; + UILabelButton* removeBtn_ = nullptr; + UILabelButton* mirrorOpaAddBtn_ = nullptr; + UILabelButton* mirrorOpaSubBtn_ = nullptr; + UILabelButton* pageWidthAddBtn_ = nullptr; + UILabelButton* pageWidthSubBtn_ = nullptr; + UILabelButton* maxAngleAddBtn_ = nullptr; + UILabelButton* maxAngleSubBtn_ = nullptr; + UILabelButton* loopBtn_ = nullptr; + uint16_t itemWidth_ = 250; // 250: default value + uint8_t mirrorOpa_ = 30; // 30: default value + float rotateAngle_ = 70.0f; // 70: default value + bool isLoop_ = false; +}; +} // namespace OHOS +#endif // UI_TEST_QRCODE_H \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_cross/ui_test_cross.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_cross/ui_test_cross.h index 9423f7515..5890f17be 100755 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_cross/ui_test_cross.h +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_cross/ui_test_cross.h @@ -36,8 +36,10 @@ public: #ifndef _WIN32 class VideoPage : public UICardPage { public: + VideoPage(const VideoPage &) = delete; + VideoPage &operator=(const VideoPage &) = delete; VideoPage(void) {} - ~VideoPage(); + ~VideoPage() override; void ScrollBegin(bool isActive) override; void ScrollEnd(bool isActive) override; void CoverBegin(bool isCovered) override; diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_cube_rotate/cube_rotate_view.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_cube_rotate/cube_rotate_view.cpp index 5edb65335..7d54432cc 100755 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_cube_rotate/cube_rotate_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_cube_rotate/cube_rotate_view.cpp @@ -261,7 +261,7 @@ bool CubeRotateView::OnDragEvent(const DragEvent& event) int y = (point.y - startPoint_.y); float len = Sqrt(x * x + y * y); float angle = RADIAN_TO_ANGLE * len / IMG_WIDTH; - const Vector3 center = {CENTER_X, CENTER_Y, -IMG_SIZE/2.0f}; + const Vector3 center = {CENTER_X, CENTER_Y, -IMG_SIZE / 2.0f}; RotatePlanes(angle, center, {center.x_ + normal.x_, center.y_ + normal.y_, center.z_ + normal.z_}); return true; } diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_hexagons_list/ui_test_hexagons_list.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_hexagons_list/ui_test_hexagons_list.cpp new file mode 100644 index 000000000..5cb89642e --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_hexagons_list/ui_test_hexagons_list.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +#include "ui_test_hexagons_list/ui_test_hexagons_list.h" +#include "components/root_view.h" +#include "components/ui_image_view.h" +#include "common/image_cache_manager.h" +#include "common/screen.h" +#include "ui_test_list_fps/ui_list_fps_res.h" +#include "dock/focus_manager.h" + +namespace OHOS { +const uint8_t IMG_COUNT = 45; +const uint8_t IMG_DISTANCE_DELTA = 1; +const uint8_t IMG_SIZE_DELTA = 1; +const int16_t BUTTON_SIZE = 60; +const float IMG_SCALE_FACTOR_DELTA = 0.01f; +const int16_t MARGIN_DELTA = 1; +const int16_t BORDER_RADIUS_DELTA = 1; +const float GLOBAL_SCALE = 1.0f; +const float GLOBAL_SCALE_DELTA = 0.02f; +const float CLICK_SCALE_TARGET_IN_NORMAL = 2.0f; + +void UITestHexagonsList::ConfigButtonAttr(UIView& view, int16_t x, int16_t y, int16_t width, int16_t height) +{ + view.SetOpaScale(OPA_TRANSPARENT); + view.SetOnClickListener(this); + view.SetOnLongPressListener(this); + view.SetPosition(x, y, width, height); + container_->Add(&view); +} + +void UITestHexagonsList::SetUpButtons(int16_t xEnd, int16_t yEnd, int16_t xMiddle, int16_t yMiddle) +{ + if (modifyImgSizeButton_ == nullptr) { + modifyImgSizeButton_ = new UIButton(); + ConfigButtonAttr(*modifyImgSizeButton_, xMiddle - BUTTON_SIZE, 0, BUTTON_SIZE, BUTTON_SIZE); + } + if (modifyImgDistanceButton_ == nullptr) { + modifyImgDistanceButton_ = new UIButton(); + ConfigButtonAttr(*modifyImgDistanceButton_, xMiddle, 0, BUTTON_SIZE, BUTTON_SIZE); + } + if (modifyScaleFatorButton_ == nullptr) { + modifyScaleFatorButton_ = new UIButton(); + ConfigButtonAttr(*modifyScaleFatorButton_, xEnd - BUTTON_SIZE, yMiddle - BUTTON_SIZE, BUTTON_SIZE, BUTTON_SIZE); + } + if (modifyGlobalScaleButton_ == nullptr) { + modifyGlobalScaleButton_ = new UIButton(); + ConfigButtonAttr(*modifyGlobalScaleButton_, xEnd - BUTTON_SIZE, yMiddle, BUTTON_SIZE, BUTTON_SIZE); + } + if (modifyHorMarginButton_ == nullptr) { + modifyHorMarginButton_ = new UIButton(); + ConfigButtonAttr(*modifyHorMarginButton_, xMiddle - BUTTON_SIZE, yEnd - BUTTON_SIZE, BUTTON_SIZE, BUTTON_SIZE); + } + if (modifyVerMarginButton_ == nullptr) { + modifyVerMarginButton_ = new UIButton(); + ConfigButtonAttr(*modifyVerMarginButton_, xMiddle, yEnd - BUTTON_SIZE, BUTTON_SIZE, BUTTON_SIZE); + } + if (modifyBorderRadiusButton_ == nullptr) { + modifyBorderRadiusButton_ = new UIButton(); + ConfigButtonAttr(*modifyBorderRadiusButton_, xMiddle - BUTTON_SIZE, yMiddle, BUTTON_SIZE, BUTTON_SIZE); + } +} + +void UITestHexagonsList::SetUp() +{ + if (container_ == nullptr) { + container_ = new UIViewGroup(); + } + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + if (hexagonsList_ == nullptr) { + hexagonsList_ = new UICustomHexagonsList(); + } + container_->Add(hexagonsList_); + + if (Screen::GetInstance().GetScreenShape() == RECTANGLE) { + borderRadius_ = Screen::GetInstance().GetWidth() * 0.336; // 0.336, empirical coefficient + hexagonsList_->SetStyle(STYLE_BORDER_RADIUS, borderRadius_); + // STYLE_BORDER_WIDTH was used to debug, it should be removed in the actual running content + hexagonsList_->SetStyle(STYLE_BORDER_WIDTH, 1); + hexagonsList_->SetStyle(STYLE_MARGIN_LEFT, horMargin_); + hexagonsList_->SetStyle(STYLE_MARGIN_RIGHT, horMargin_); + hexagonsList_->SetStyle(STYLE_MARGIN_TOP, verMargin_); + hexagonsList_->SetStyle(STYLE_MARGIN_BOTTOM, verMargin_); + hexagonsList_->SetStyle(STYLE_BORDER_COLOR, Color::Red().full); + imgDistance_ = container_->GetWidth() * 0.31; // 0.31, empirical coefficient + imgSize_ = container_->GetWidth() * 0.27; // 0.27, empirical coefficient + } else { + imgDistance_ = container_->GetWidth() * 0.25991; // 0.25991, empirical coefficient + imgSize_ = container_->GetWidth() * 0.23348; // 0.23348, empirical coefficient + } + hexagonsList_->SetPosition(0, 0, + container_->GetWidth() - 2 * (horMargin_ + 1), container_->GetHeight() - 2 * (verMargin_ + 1)); // 2, two + + ImageInfo* info = ImageCacheManager::GetInstance().LoadSingleRes(RES_PATH"hexagons.bin"); + for (int16_t i = 0; i < IMG_COUNT; i++) { + UIImageView* img = new UIImageView(); + img->SetSrc(info); + img->SetTouchable(true); + img->SetOnClickListener(this); + hexagonsList_->Add(img); + } + imgScaleFactor_ = hexagonsList_->GetScaleFactorByDistance(); + globalScale_ = hexagonsList_->GetGlobalScale(); + hexagonsList_->SetImageDistance(imgDistance_); + hexagonsList_->SetImageSizeInCenter(imgSize_); + int16_t blankSize = hexagonsList_->GetRelativeRect().GetWidth() > hexagonsList_->GetRelativeRect().GetHeight() ? + hexagonsList_->GetRelativeRect().GetWidth() / 2 : hexagonsList_->GetRelativeRect().GetHeight() / 2; // 2, half + hexagonsList_->SetScrollBlankSize(blankSize); + hexagonsList_->SetReboundSize(blankSize); + hexagonsList_->SetThrowDrag(true); + hexagonsList_->LayoutChildren(true); + SetUpButtons(container_->GetWidth() - 1, container_->GetHeight() - 1, + container_->GetWidth() / 2, container_->GetHeight() / 2); // 2, half size + FocusManager::GetInstance()->RequestFocus(hexagonsList_); +} + +void UITestHexagonsList::TearDown() +{ + FocusManager::GetInstance()->ClearFocus(); + DeleteChildren(container_); + container_ = nullptr; + hexagonsList_ = nullptr; + modifyImgSizeButton_ = nullptr; + modifyImgDistanceButton_ = nullptr; + modifyScaleFatorButton_ = nullptr; + modifyGlobalScaleButton_ = nullptr; + modifyHorMarginButton_ = nullptr; + modifyVerMarginButton_ = nullptr; + modifyBorderRadiusButton_ = nullptr; +} + +void UITestHexagonsList::HandleClickEventForRectScreen(const UIView& view) +{ + if (modifyHorMarginButton_ == &view) { + horMargin_ += isIncreaseHorMargin_ ? MARGIN_DELTA : -MARGIN_DELTA; + horMargin_ = horMargin_ < 0 ? 0 : horMargin_; + hexagonsList_->SetPosition(horMargin_, verMargin_, + container_->GetWidth() - 2 * (horMargin_ + 1), container_->GetHeight() - 2 * (verMargin_ + 1)); // 2, two + hexagonsList_->LayoutChildren(true); + } else if (modifyVerMarginButton_ == &view) { + verMargin_ += isIncreaseVerMargin_ ? MARGIN_DELTA : -MARGIN_DELTA; + verMargin_ = verMargin_ < 0 ? 0 : verMargin_; + hexagonsList_->SetPosition(horMargin_, verMargin_, + container_->GetWidth() - 2 * (horMargin_ + 1), container_->GetHeight() - 2 * (verMargin_ + 1)); // 2, two + hexagonsList_->LayoutChildren(true); + } else if (modifyBorderRadiusButton_ == &view) { + borderRadius_ += isIncreaseBorderRadius_ ? BORDER_RADIUS_DELTA : -BORDER_RADIUS_DELTA; + borderRadius_ = borderRadius_ < 0 ? 0 : borderRadius_; + int8_t index = hexagonsList_->GetFocusedImgIndex(); + hexagonsList_->SetStyle(STYLE_BORDER_RADIUS, borderRadius_); + } + container_->Invalidate(); +} + +bool UITestHexagonsList::OnClick(UIView& view, const ClickEvent& event) +{ + // Handle content click for image view + if (view.GetViewType() == UI_IMAGE_VIEW) { + uint8_t index = static_cast(view.GetViewIndex()); + float scaleInSmall = hexagonsList_->GetScaleInSmallState(); + Vector2 center(hexagonsList_->GetWidth() / 2, hexagonsList_->GetHeight() / 2); // 2, center + Vector2 delta = center - hexagonsList_->GetCurrentPosition(index); + if (FloatEqual(hexagonsList_->GetGlobalScale(), scaleInSmall)) { + hexagonsList_->StartRotateAnimator(index, delta.x_, delta.y_, scaleInSmall, 1.0f); + } else if (FloatEqual(hexagonsList_->GetGlobalScale(), 1.0f)) { + hexagonsList_->StartRotateAnimator(index, delta.x_, delta.y_, 1.0f, CLICK_SCALE_TARGET_IN_NORMAL); + } else if (FloatEqual(hexagonsList_->GetGlobalScale(), CLICK_SCALE_TARGET_IN_NORMAL)) { + hexagonsList_->StartRotateAnimator(index, delta.x_, delta.y_, CLICK_SCALE_TARGET_IN_NORMAL, 1.0f); + } + } + + if (modifyImgSizeButton_ == &view) { + imgSize_ += isIncreaseImgSize_ ? IMG_SIZE_DELTA : -IMG_SIZE_DELTA; + hexagonsList_->SetImageSizeInCenter(imgSize_); + hexagonsList_->LayoutChildren(true); + } else if (modifyImgDistanceButton_ == &view) { + imgDistance_ += isIncreaseImgDistance_ ? IMG_DISTANCE_DELTA : -IMG_DISTANCE_DELTA; + hexagonsList_->SetImageDistance(imgDistance_); + hexagonsList_->LayoutChildren(true); + } else if (modifyScaleFatorButton_ == &view) { + imgScaleFactor_ += isIncreaseScaleFactor_ ? IMG_SCALE_FACTOR_DELTA : -IMG_SCALE_FACTOR_DELTA; + hexagonsList_->SetScaleFactorByDistance(imgScaleFactor_); + hexagonsList_->LayoutChildren(true); + } else if (modifyGlobalScaleButton_ == &view) { + globalScale_ += isIncreaseGlobalScale_ ? GLOBAL_SCALE_DELTA : -GLOBAL_SCALE_DELTA; + int8_t index = hexagonsList_->GetFocusedImgIndex(); + if (index >= 0) { + hexagonsList_->Scale(globalScale_, static_cast(index)); + } + } + if (FloatLess(globalScale_, hexagonsList_->GetScaleThesholdOfZeroFactor())) { + hexagonsList_->SetReboundMode(UIHexagonsList::ReboundMode::CENTER_IMG_ON_SCR_CENTER); + } else { + hexagonsList_->SetReboundMode(UIHexagonsList::ReboundMode::NEAREST_IMG_ON_SCR_CENTER); + } + + if (Screen::GetInstance().GetScreenShape() == RECTANGLE) { + HandleClickEventForRectScreen(view); + } + + GRAPHIC_LOGE("%d-%d imgDist_=%d imgSize=%d imgScaleFactor=%f globalScale=%f horPad=%d verPad=%d boderRadius=%d", + view.GetViewType(), view.GetViewIndex(), imgDistance_, imgSize_, imgScaleFactor_, globalScale_, + horMargin_, verMargin_, borderRadius_); + return true; +} + +bool UITestHexagonsList::OnLongPress(UIView& view, const LongPressEvent& event) +{ + if (modifyImgSizeButton_ == &view) { + isIncreaseImgSize_ = !isIncreaseImgSize_; + } else if (modifyImgDistanceButton_ == &view) { + isIncreaseImgDistance_ = !isIncreaseImgDistance_; + } else if (modifyScaleFatorButton_ == &view) { + isIncreaseScaleFactor_ = !isIncreaseScaleFactor_; + } else if (modifyGlobalScaleButton_ == &view) { + isIncreaseGlobalScale_ = !isIncreaseGlobalScale_; + } else if (modifyHorMarginButton_ == &view) { + isIncreaseHorMargin_ = !isIncreaseHorMargin_; + } else if (modifyVerMarginButton_ == &view) { + isIncreaseVerMargin_ = !isIncreaseVerMargin_; + } else if (modifyBorderRadiusButton_ == &view) { + isIncreaseBorderRadius_ = !isIncreaseBorderRadius_; + } + GRAPHIC_LOGE("incSize=%d incDist=%d incFactor=%d incGloScale=%d incHPadding=%d incVPadding=%d incBRadius=%d", + isIncreaseImgSize_, isIncreaseImgDistance_, isIncreaseScaleFactor_, isIncreaseGlobalScale_, + isIncreaseHorMargin_, isIncreaseVerMargin_, isIncreaseBorderRadius_); + return true; +} + +const UIView* UITestHexagonsList::GetTestView() +{ + return container_; +} +} \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_hexagons_list/ui_test_hexagons_list.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_hexagons_list/ui_test_hexagons_list.h new file mode 100644 index 000000000..999b41b83 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_hexagons_list/ui_test_hexagons_list.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +#ifndef UI_TEST_HEXAGONS_LIST_H +#define UI_TEST_HEXAGONS_LIST_H + +#include "ui_test.h" +#include "gfx_utils/list.h" +#include "components/ui_custom_hexagons_list.h" +#include "components/ui_button.h" + +namespace OHOS { +class UITestHexagonsList : public UITest, public UIView::OnClickListener, public UIView::OnLongPressListener { +public: + UITestHexagonsList() {} + ~UITestHexagonsList() override {} + void SetUp() override; + void TearDown() override; + const UIView *GetTestView() override; + bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnLongPress(UIView& view, const LongPressEvent& event) override; + +private: + void HandleClickEventForRectScreen(const UIView& view); + void ConfigButtonAttr(UIView& view, int16_t x, int16_t y, int16_t width, int16_t height); + void SetUpButtons(int16_t xEnd, int16_t yEnd, int16_t xMiddle, int16_t yMiddle); + UICustomHexagonsList* hexagonsList_ = nullptr; + int16_t horMargin_ = 0; + int16_t verMargin_ = 0; + int16_t borderRadius_ = 0; + UIViewGroup* container_ = nullptr; + uint16_t imgSize_ = 0; + uint16_t imgDistance_ = 0; + float imgScaleFactor_ = 0; + float globalScale_ = 0; + bool isIncreaseImgSize_ = true; + UIButton* modifyImgSizeButton_ = nullptr; + bool isIncreaseImgDistance_ = true; + UIButton* modifyImgDistanceButton_ = nullptr; + bool isIncreaseScaleFactor_ = true; + UIButton* modifyScaleFatorButton_ = nullptr; + bool isIncreaseGlobalScale_ = true; + UIButton* modifyGlobalScaleButton_ = nullptr; + bool isIncreaseHorMargin_ = true; + UIButton* modifyHorMarginButton_ = nullptr; + bool isIncreaseVerMargin_ = true; + UIButton* modifyVerMarginButton_ = nullptr; + bool isIncreaseBorderRadius_ = true; + UIButton* modifyBorderRadiusButton_ = nullptr; +}; +} +#endif // UI_TEST_HEXAGONS_LIST_H \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_kaleidoscope/ui_test_kaleidoscope.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_kaleidoscope/ui_test_kaleidoscope.cpp new file mode 100644 index 000000000..3f528d96a --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_kaleidoscope/ui_test_kaleidoscope.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +#include "ui_test_kaleidoscope.h" +#include "common/image_cache_manager.h" + +namespace OHOS { + +void UITestKaleidoscope::KaleidoscopeAnimator::Callback(UIView* view) +{ + if (view == nullptr) { + return; + } + + kaleidoscopeUtils_->Rotate(0.1f); // 0.1: rotate by 0.1 + view->Invalidate(); +} + +void UITestKaleidoscope::SetUp() +{ + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + + imgInfo_ = ImageCacheManager::GetInstance().LoadSingleRes(RES_PATH"rabbit454.bin"); + + if ((Screen::GetInstance().GetWidth() == imgInfo_->header.width) && + (Screen::GetInstance().GetHeight() == imgInfo_->header.height)) { + kaleidoscope_ = new UIKaleidoscopeView(); + if (kaleidoscope_->SetSrc(imgInfo_) == false) { + return; + } + + container_->Add(kaleidoscope_); + kaleidoscope_->RequestFocus(); + kaleidoscope_->SetRotateEventFactor(0.2f); // 0.2: rotate event factor + kaleidoscope_->SetRotateAnimatorValue(0.1f); // 0.1: rotate animator value + kaleidoscope_->StartRotateAnimator(); + return; + } + + kaleidoscopeUtils_ = new KaleidoscopeUtils(); + kaleidoscopeUtils_->Init(imgInfo_, nullptr); + ImageInfoExt* infoExt = kaleidoscopeUtils_->GetKaleidoscopeInfo(); + + img_ = new UIImageView(); + img_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + img_->SetAutoEnable(false); + img_->SetResizeMode(UIImageView::ImageResizeMode::FILL); + img_->SetSrc(&infoExt->info); + container_->Add(img_); + + if (utilsAnimator_ == nullptr) { + utilsAnimator_ = new KaleidoscopeAnimator(kaleidoscopeUtils_, img_); + utilsAnimator_->Start(); + } +} + +void UITestKaleidoscope::TearDown() +{ + if (utilsAnimator_ != nullptr) { + utilsAnimator_->Stop(); + delete utilsAnimator_; + utilsAnimator_ = nullptr; + } + + if (kaleidoscope_ != nullptr) { + kaleidoscope_->StopRotateAnimator(); + kaleidoscope_->ClearFocus(); + kaleidoscope_ = nullptr; + } + + DeleteChildren(container_); + container_ = nullptr; + imgInfo_ = nullptr; + img_ = nullptr; + + if (kaleidoscopeUtils_ != nullptr) { + delete kaleidoscopeUtils_; + kaleidoscopeUtils_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(RES_PATH"rabbit454.bin"); +} + +const UIView* UITestKaleidoscope::GetTestView() +{ + return container_; +} +} diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_kaleidoscope/ui_test_kaleidoscope.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_kaleidoscope/ui_test_kaleidoscope.h new file mode 100644 index 000000000..15c3d933b --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_kaleidoscope/ui_test_kaleidoscope.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +#ifndef UI_TEST_KALEIDOSCOPE_H +#define UI_TEST_KALEIDOSCOPE_H + +#include "ui_test.h" +#include "components/ui_kaleidoscope_view.h" +#include "components/kaleidoscope_utils.h" +#include "animator/animator.h" +#include "components/ui_image_view.h" + +namespace OHOS { +class UITestKaleidoscope : public UITest { +public: + UITestKaleidoscope() {} + ~UITestKaleidoscope() override {} + void SetUp() override; + void TearDown() override; + const UIView* GetTestView() override; + +private: + class KaleidoscopeAnimator : public Animator, public AnimatorCallback { + public: + KaleidoscopeAnimator(KaleidoscopeUtils* kaleidoscopeUtils, UIImageView* img) + : Animator(this, img, 0, true), kaleidoscopeUtils_(kaleidoscopeUtils) {} + virtual ~KaleidoscopeAnimator() {} + void Callback(UIView* view) override; + + private: + KaleidoscopeUtils* kaleidoscopeUtils_; + }; + + UIViewGroup* container_ = nullptr; + ImageInfo* imgInfo_ = nullptr; + + UIKaleidoscopeView* kaleidoscope_ = nullptr; + + UIImageView* img_ = nullptr; + KaleidoscopeUtils* kaleidoscopeUtils_ = nullptr; + KaleidoscopeAnimator* utilsAnimator_ = nullptr; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_map/ui_test_map.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_map/ui_test_map.cpp new file mode 100644 index 000000000..53cee9582 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_map/ui_test_map.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * 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. + */ + +#include "ui_test_map.h" +#include "common/screen.h" +#include "components/root_view.h" + +namespace OHOS { +static float g_scale = 1.0; +static const float SCALE_LIMIT = 0.5; +static const float SCALE_STEP = 0.1; +static const Vector2 SCALE_CENTER = {228, 178}; // 228, 178: scale center + +void UITestMap::SetUp() +{ + container_ = new UIScrollView(); + container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetScrollBlankSize(200); // 200: blank size + + map_ = new UIMapView(); + map_->SetPosition(100, 50, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); // 100, 50: x, y + map_->SetSVG(RES_PATH"map.bin"); + container_->Add(map_); + + scale_ = new UILabelButton(); + scale_->SetPosition(57, 340, 100, 50); // 57: x, 340: y, 100: width, 50: height + scale_->SetText("scale"); + scale_->SetOnClickListener(this); + container_->Add(scale_); + + cache_ = new UILabelButton(); + cache_->SetPosition(177, 340, 100, 50); // 177: x, 340: y, 100: width, 50: height + cache_->SetText("cache"); + cache_->SetOnClickListener(this); + container_->Add(cache_); + + reset_ = new UILabelButton(); + reset_->SetPosition(297, 340, 100, 50); // 297: x, 340: y, 100: width, 50: height + reset_->SetText("reset"); + reset_->SetOnClickListener(this); + container_->Add(reset_); +} + +void UITestMap::TearDown() +{ + DeleteChildren(container_); + container_ = nullptr; + scale_ = nullptr; + cache_ = nullptr; + reset_ = nullptr; + map_ = nullptr; +} + +const UIView* UITestMap::GetTestView() +{ + return container_; +} + +bool UITestMap::OnClick(UIView& view, const ClickEvent& event) +{ + if (&view == scale_) { + g_scale -= SCALE_STEP; + if (g_scale < SCALE_LIMIT) { + g_scale = SCALE_LIMIT; + } + map_->EnableCache(false); + map_->ScaleMap(g_scale, SCALE_CENTER); + } else if (&view == cache_) { + if (!cached_) { + cache_->SetText("clear cache"); + map_->EnableCache(true); + cached_ = true; + } else { + cache_->SetText("cache"); + map_->EnableCache(false); + cached_ = false; + } + } else if (&view == reset_) { + g_scale = 1.0; + map_->EnableCache(false); + map_->ScaleMap(g_scale, SCALE_CENTER); + } + RootView::GetInstance()->Invalidate(); + return true; +} +} diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_map/ui_test_map.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_map/ui_test_map.h new file mode 100644 index 000000000..927a09840 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_map/ui_test_map.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * 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. + */ + +#ifndef UI_TEST_MAP_H +#define UI_TEST_MAP_H + +#include "ui_test.h" +#include "components/ui_label_button.h" +#include "components/ui_map_view.h" +#include "components/ui_scroll_view.h" + +namespace OHOS { +class UITestMap : public UITest, public UIView::OnClickListener { +public: + UITestMap() {} + ~UITestMap() override {} + void SetUp() override; + void TearDown() override; + const UIView* GetTestView() override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + UIScrollView* container_ = nullptr; + UILabelButton* scale_ = nullptr; + UILabelButton* cache_ = nullptr; + UILabelButton* reset_ = nullptr; + UIMapView* map_ = nullptr; + bool cached_ = false; +}; +} +#endif diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/test_case_list_adapter.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/test_case_list_adapter.cpp index b3ec25124..ce6b1e7cd 100755 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/test_case_list_adapter.cpp +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/test_case_list_adapter.cpp @@ -26,6 +26,7 @@ namespace OHOS { namespace { const uint16_t TESTCASE_BUTTON_HEIGHT = 100; const uint16_t STYLE_BORDER_WIDTH_VALUE = 4; +const uint16_t BACK_BUTTON_SIZE = 50; } // namespace uint16_t TestCaseListAdapter::GetCount() @@ -82,7 +83,8 @@ public: rootView->Add(tempView); if (backBtn_ == nullptr) { backBtn_ = new TransparentBackButton(); - backBtn_->SetPosition(0, 202, 50, 50); // 0: x position, 202: y position, 50: width and height + backBtn_->SetPosition(0, (Screen::GetInstance().GetHeight() - BACK_BUTTON_SIZE) / 2, // 2, half size + BACK_BUTTON_SIZE, BACK_BUTTON_SIZE); } backBtn_->SetViewId(view.GetViewId()); rootView->Add(backBtn_); diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/ui_test_group.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/ui_test_group.cpp index 5379804cf..7109cafed 100755 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/ui_test_group.cpp +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/ui_test_group.cpp @@ -68,12 +68,16 @@ #include "ui_test_sweepclock/ui_test_sweepclock.h" #include "ui_test_text_fps/ui_test_text_fps.h" #include "ui_test_tiger/ui_test_tiger.h" +#include "ui_test_hexagons_list/ui_test_hexagons_list.h" #include "ui_test_list_fps/ui_test_list_fps.h" #include "ui_test_card_switch/ui_test_card_switch.h" #include "ui_test_message/ui_test_message.h" #include "ui_test_breath/ui_test_breath.h" #include "ui_test_cube_rotate/ui_test_cube_rotate.h" #include "ui_test_cross/ui_test_cross.h" +#include "ui_test_map/ui_test_map.h" +#include "ui_test_coverflow/ui_test_coverflow.h" +#include "ui_test_kaleidoscope/ui_test_kaleidoscope.h" namespace OHOS { void UITestGroup::AddTestCase(TestCaseInfo testCaseInfo) @@ -92,6 +96,7 @@ void UITestGroup::SetUpTestCase() } testCaseList_->Clear(); testCaseList_->PushBack(TestCaseInfo{"老虎头", new UITestTiger()}); + testCaseList_->PushBack(TestCaseInfo{"蜂窝表盘", new UITestHexagonsList()}); testCaseList_->PushBack(TestCaseInfo{"滑动列表", new UITestListFPS()}); testCaseList_->PushBack(TestCaseInfo{"扫秒", new UITestSweepClock()}); testCaseList_->PushBack(TestCaseInfo{"指南针", new UITestCompass()}); @@ -101,12 +106,18 @@ void UITestGroup::SetUpTestCase() testCaseList_->PushBack(TestCaseInfo{"卡片切换", new UITestCardSwitch()}); testCaseList_->PushBack(TestCaseInfo{"消息", new UITestMessage()}); testCaseList_->PushBack(TestCaseInfo{"呼吸效果", new UITestBreath()}); + testCaseList_->PushBack(TestCaseInfo{"地图", new UITestMap()}); #if !defined(_WIN32) && !defined(QSPI_DISPLAY) testCaseList_->PushBack(TestCaseInfo{"视频播放", new UITestVideoPlay()}); #endif #if !defined(QSPI_DISPLAY) testCaseList_->PushBack(TestCaseInfo{"翻转动效", new UITestCross()}); #endif +#if !defined(_WIN32) + testCaseList_->PushBack(TestCaseInfo{"万花筒", new UITestKaleidoscope()}); +#endif + testCaseList_->PushBack(TestCaseInfo{"覆盖流", new UITestCoverflow()}); + #if ENABLE_VGU_ENGINE && CAPABILITY_HWDRAW_PATH testCaseList_->PushBack(TestCaseInfo{"倒计时", new UITestCountdown()}); testCaseList_->PushBack(TestCaseInfo{"动画曲线", new UITestRunningBall()}); diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/root_view.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/root_view.cpp index cf86bbf6c..d87f0f51a 100755 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/root_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/root_view.cpp @@ -802,7 +802,7 @@ void RootView::DrawTop(UIView* view, const Rect& rect) #if ENABLE_MAP_BUFFER if ((curView->GetViewType() != UI_IMAGE_VIEW) && (curView->GetViewType() != UI_TEXTURE_MAPPER) && (curView->GetViewType() != UI_CANVAS_EXT) && (curView->GetViewType() != UI_MENU_ITEM) && - !curView->IsTransInvalid() && !enableAnimator) { + (curView->GetViewType() != UI_MAP_VIEW) && !curView->IsTransInvalid() && !enableAnimator) { origRect = curView->GetOrigRect(); relativeRect = curView->GetRelativeRect(); curView->GetTransformMap().SetInvalid(true); diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp index cfd695a8f..efc6b5141 100755 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp @@ -792,6 +792,7 @@ void UIList::RefreshList() void UIList::RemoveAll() { + UIViewGroup::RemoveAll(); recycle_.ClearScrapView(); } diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view.cpp index 360a751b1..74a13ec57 100755 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view.cpp @@ -272,7 +272,7 @@ void UIView::Rotate(int16_t angle, const Vector2& pivot) { #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT)) { + if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW)) { GRAPHIC_LOGE("Rotate is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -291,7 +291,7 @@ void UIView::Rotate(int16_t angle, const Vector3& pivotStart, const Vecto { #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT)) { + if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW)) { GRAPHIC_LOGE("Rotate is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -306,10 +306,10 @@ void UIView::Rotate(int16_t angle, const Vector3& pivotStart, const Vecto transMap_->Rotate(angle, pivotStart, pivotEnd); if (firstTrans) { joinRect = transMap_->GetBoxRect(); + joinRect.Join(joinRect, GetOrigRect()); } else { joinRect.Join(joinRect, transMap_->GetBoxRect()); } - joinRect.Join(joinRect, GetOrigRect()); InvalidateRect(joinRect); } @@ -317,7 +317,7 @@ void UIView::Scale(const Vector2& scale, const Vector2& pivot) { #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT)) { + if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW)) { GRAPHIC_LOGE("Scale is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -331,7 +331,7 @@ void UIView::Scale(const Vector3& scale, const Vector3& pivot) { #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT)) { + if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW)) { GRAPHIC_LOGE("Scale is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -354,10 +354,10 @@ void UIView::Scale(const Vector3& scale, const Vector3& pivot) transMap_->Scale(scale, pivot); if (firstTrans) { joinRect = transMap_->GetBoxRect(); + joinRect.Join(joinRect, GetOrigRect()); } else { joinRect.Join(joinRect, transMap_->GetBoxRect()); } - joinRect.Join(joinRect, GetOrigRect()); InvalidateRect(joinRect); } @@ -365,7 +365,7 @@ void UIView::Shear(const Vector2& shearX, const Vector2& shearY, c { #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT)) { + if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW)) { GRAPHIC_LOGE("Shear is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -380,10 +380,10 @@ void UIView::Shear(const Vector2& shearX, const Vector2& shearY, c transMap_->Shear(shearX, shearY, shearZ); if (firstTrans) { joinRect = transMap_->GetBoxRect(); + joinRect.Join(joinRect, GetOrigRect()); } else { joinRect.Join(joinRect, transMap_->GetBoxRect()); } - joinRect.Join(joinRect, GetOrigRect()); InvalidateRect(joinRect); } @@ -391,7 +391,7 @@ void UIView::Translate(const Vector2& trans) { #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT)) { + if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW)) { GRAPHIC_LOGE("Translate is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -404,7 +404,7 @@ void UIView::Translate(const Vector3& trans) { #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT)) { + if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW)) { GRAPHIC_LOGE("Translate is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -419,10 +419,10 @@ void UIView::Translate(const Vector3& trans) transMap_->Translate(trans); if (firstTrans) { joinRect = transMap_->GetBoxRect(); + joinRect.Join(joinRect, GetOrigRect()); } else { joinRect.Join(joinRect, transMap_->GetBoxRect()); } - joinRect.Join(joinRect, GetOrigRect()); InvalidateRect(joinRect); } @@ -799,7 +799,7 @@ void UIView::SetTransformMap(const TransformMap& transMap) { #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT)) { + if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW)) { GRAPHIC_LOGE("SetTransformMap is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } diff --git a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_scroll_view.h b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_scroll_view.h index 3ad3579fa..c5039a795 100755 --- a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_scroll_view.h +++ b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_scroll_view.h @@ -241,10 +241,10 @@ protected: bool DragXInner(int16_t distance) override; bool DragYInner(int16_t distance) override; bool MoveOffset(int16_t offsetX, int16_t offsetY); + void CalculateReboundDistance(int16_t& dragDistanceX, int16_t& dragDistanceY) override; private: void Drag(const DragEvent& event); - void CalculateReboundDistance(int16_t& dragDistanceX, int16_t& dragDistanceY) override; void RefreshScrollBar(); OnScrollListener* scrollListener_; #if ENABLE_VIBRATOR diff --git a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_view.h b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_view.h index f3c3c76d7..3c9227f09 100755 --- a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_view.h +++ b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_view.h @@ -113,6 +113,8 @@ enum UIViewType : uint8_t { UI_CARD_PAGE, UI_CROSS_VIEW, UI_BARCODE, + UI_MAP_VIEW, + UI_KALEIDOSCOPE_VIEW, UI_NUMBER_MAX }; diff --git a/code/sdk/middleware/services/gui/uikit/utils/frameworks/geometry2d.cpp b/code/sdk/middleware/services/gui/uikit/utils/frameworks/geometry2d.cpp index df8f05d49..2444ccc02 100755 --- a/code/sdk/middleware/services/gui/uikit/utils/frameworks/geometry2d.cpp +++ b/code/sdk/middleware/services/gui/uikit/utils/frameworks/geometry2d.cpp @@ -82,6 +82,9 @@ uint32_t Rect::GetSize() const bool Rect::Intersect(const Rect& rect1, const Rect& rect2) { + if (!rect1.IsValid() || !rect2.IsValid()) { + return false; + } /* Get the smaller area from 'rect1' and 'rect2' */ left_ = MATH_MAX(rect1.left_, rect2.left_); top_ = MATH_MAX(rect1.top_, rect2.top_); diff --git a/code/sdk/middleware/services/gui/uikit/utils/frameworks/graphic_math.cpp b/code/sdk/middleware/services/gui/uikit/utils/frameworks/graphic_math.cpp index e7941cd7f..d544bf73f 100755 --- a/code/sdk/middleware/services/gui/uikit/utils/frameworks/graphic_math.cpp +++ b/code/sdk/middleware/services/gui/uikit/utils/frameworks/graphic_math.cpp @@ -57,6 +57,27 @@ float Sin(float angle) #endif } +float Acos(float value) +{ +#if defined(ENABLE_CMATH) && ENABLE_CMATH + return acos(value); +#else + float result, l, r; + l = 0; + r = UI_PI; + result = (l + r) / 2; + while (MATH_ABS(Sin(QUARTER_IN_DEGREE - result * RADIAN_TO_ANGLE) - value) > UI_FLT_EPSILON) { + if (Sin(QUARTER_IN_DEGREE - result * RADIAN_TO_ANGLE) - value > UI_FLT_EPSILON) { + l = result; + } else { + r = result; + } + result = (l + r) / 2; + } + return result; +#endif +} + /* arctan(x) = x - p3 * x^3 + p5 * x^5 - p7 * x^7 */ uint16_t FastAtan2(int16_t x, int16_t y) { diff --git a/code/sdk/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils/graphic_math.h b/code/sdk/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils/graphic_math.h index b0d571ba0..7780787b1 100755 --- a/code/sdk/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils/graphic_math.h +++ b/code/sdk/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils/graphic_math.h @@ -84,6 +84,7 @@ static constexpr float UI_FLT_EPSILON = 1E-5; static constexpr int16_t ORDER_MATRIX_4 = 4; float Sin(float angle); +float Acos(float value); uint16_t FastAtan2(int16_t x, int16_t y); float Sqrt(float x); @@ -956,7 +957,27 @@ inline int64_t FloatToInt64(float f) inline bool FloatEqual(float lhs, float rhs, float precision = 0.00001f) { - return (MATH_ABS(lhs - rhs) < precision) ? true : false; + return MATH_ABS(lhs - rhs) < precision; +} + +inline bool FloatMore(float lhs, float rhs, float precision = 0.00001f) +{ + return lhs - rhs > precision; +} + +inline bool FloatLess(float lhs, float rhs, float precision = 0.00001f) +{ + return lhs - rhs < -precision; +} + +inline bool FloatMoreEqual(float lhs, float rhs, float precision = 0.00001f) +{ + return lhs - rhs > -precision; +} + +inline bool FloatLessEqual(float lhs, float rhs, float precision = 0.00001f) +{ + return lhs - rhs < precision; } bool IsIdentity(Matrix3& matrix);