From: luozheng <1732036298@qq.com> Date: Thu, 24 Jul 2025 06:30:26 +0000 (+0800) Subject: application文件夹下wearable文件夹合并提交 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~216 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.js?a=commitdiff_plain;h=a00a5ff876efe7d2299dbc913688b26daf9ff3a7;p=mirrors%2FFD230.git application文件夹下wearable文件夹合并提交 --- diff --git a/code/sdk/application/wearable/alipay/service/alipay_bluetooth.c b/code/sdk/application/wearable/alipay/service/alipay_bluetooth.c index 65aafbd99..c394f7ccf 100644 --- a/code/sdk/application/wearable/alipay/service/alipay_bluetooth.c +++ b/code/sdk/application/wearable/alipay/service/alipay_bluetooth.c @@ -17,7 +17,7 @@ #include "securec.h" #include "cmsis_os2.h" #ifdef SUPPORT_OHOSFWK -#include "BluetoothWrapper.h" +#include "bluetooth/BluetoothWrapper.h" #endif /* Gatt service UUID */ diff --git a/code/sdk/application/wearable/nativeabilityfwk/CMakeLists.txt b/code/sdk/application/wearable/nativeabilityfwk/CMakeLists.txt index e98bcf649..63e56e84a 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeabilityfwk/CMakeLists.txt @@ -19,12 +19,12 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/surface/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits ${ROOT_DIR}/middleware/services/gui/uikit/ui/frameworks - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/applist/include/ ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ) set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/Ability.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/AbilitySlice.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/NativeAbility.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/StartNative.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/transition/ZoomTransition.cpp diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h index 9606728be..f6a6877ef 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h @@ -16,26 +16,101 @@ #ifndef NATIVEABILITYFWK_ABILITY_H #define NATIVEABILITYFWK_ABILITY_H #include -#include "SliceProxy.h" -#include "Slice.h" #include "wearable_log.h" #include "TransitionType.h" #include "soc_osal.h" #include "gfx_utils/vector.h" #include "graphic_mutex.h" +#include "Slice.h" +#include "SliceProxy.h" +#include "SlicePageManager.h" namespace OHOS { const static uint16_t gSliceInvalid = 0; +const static uint16_t gPageInvalid = 0; const static uint16_t gSliceDefaultPriority = 4; // 页面默认是最低优先级 + class Ability { public: - void AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy); - void ChangeSlice(const uint16_t targetSliceId, TransitionType type = TransitionType::TRANSITION_INVALID, - const uint16_t priority = gSliceDefaultPriority, bool enableSlideBack = false); - void SetDefaultSliceId(const uint16_t defaultSliceId) { - defaultSliceId_ = defaultSliceId; + void AddSliceProxy(uint16_t sliceId, SliceProxy* proxy); + + /** + * @brief Switch to specified page in the current slice, matched page will be created, and current slice will not be + * recreated. if slices or pages is being switched, this operation will be canceled + * @param pageId Indicates the specified id of the page in the current slice, it should not be zero + * @param data Indicates the data which will be transfered to next page, default value is nullptr + * @param type Indicates Transition animation type, which is declared in TransitionType.h. The matched + * Transitioncallback should have params: enableCurrentSnapshot_ = false enableTargetSnapshot_ = false + * @param canBack Indicates whether current page should be cached and can be back from target page + * @return Returns true if the pages is switched successfully, returns false otherwise. + */ + bool SwitchPageInSlice(uint16_t pageId, void* data = nullptr, + TransitionType type = TransitionType::TRANSITION_INVALID, bool canBack = false); + + /** + * @brief Switch to specified slice. matched slice will be created. + * 1. If pageId is valid or default page is exist, matched page will also be created + * 2. If slices is being switched, this operation will be cached and run later. + * @param sliceId Indicates the specified id of the slice + * @param pageId Indicates the specified id of the slice, if pageId is invalid, default page will be used. + * @param type Indicates Transition animation type, which is declared in TransitionType.h + * @param enableSliceBack Indicates whether can return to current slice from target slice by sliding + */ + void SwitchSlice(uint16_t sliceId, uint16_t pageId = gPageInvalid, + TransitionType type = TransitionType::TRANSITION_INVALID, bool enableSlideBack = false); + + /** + * @brief Switch to specified slice. matched slice will be created. + * 1. If default page is exist, default page will also be created + * 2. If slices is being switched, this operation will be cached and run later. + * Note: Method SwitchSlice is recommended, this method is reserved for compatibility. + * @param sliceId Indicates the specified id of the slice + * @param type Indicates Transition animation type, which is declared in TransitionType.h + * @param priority Indicates the priority of slice, default value is used currently. if needed, config it in + * XXXPresenter::OnResume using method SetCurSlicePriority + * @param enableSliceBack Indicates whether can return to current slice from target slice by sliding + */ + void ChangeSlice(uint16_t sliceId, TransitionType type = TransitionType::TRANSITION_INVALID, + uint16_t priority = gSliceDefaultPriority, bool enableSlideBack = false); + + /** + * @brief Get SlicePageManager of currrent slice. you can Use SlicePageManager to get page info in the slice. + * @return Returns nullptr if slices is being switched, or js ability is running + */ + SlicePageManager* GetCurSlicePageManager(); + + void SetDefaultSliceId(uint16_t defaultSliceId, uint16_t pageId = gPageInvalid) + { + defaultTargetId_ = defaultSliceId | (static_cast(pageId) << PAGE_OFFSET); } - uint16_t GetCurSliceId(void) { + + /** + * @brief Get current slice id + * @return Returns 0 if js ability is running, detail refer to comments of variable allSlices_ + */ + uint16_t GetCurSliceId(void) + { + if (allSlices_.IsEmpty()) { + return gSliceInvalid; + } + return static_cast(allSlices_[allSlices_.Size() - 1] & SLICE_MASK); + } + + /** + * @brief Get prevoius slice id in the slice vector, detail refer to comments of variable allSlices_ + */ + uint16_t GetPreSliceId(void) + { + if (allSlices_.Size() < 2) { + return gSliceInvalid; + } + return static_cast(allSlices_[allSlices_.Size() - 2] & SLICE_MASK); + } + + void UpdateCurSlicePageId(uint16_t pageId); + + uint32_t GetCurTargetId(void) + { if (allSlices_.IsEmpty()) { return gSliceInvalid; } @@ -43,30 +118,35 @@ public: return allSlices_[allSlices_.Size() - 1]; } - uint16_t GetPreSliceId(void) { - if (allSlices_.Size() < 2) { + uint32_t GetPreTargetId(void) + { + if (allSlices_.Size() < 2) { // 2, minimum count if contains previous target return gSliceInvalid; } - return allSlices_[allSlices_.Size() - 2]; + + return allSlices_[allSlices_.Size() - 2]; // 2, index offset } - void SetCurSlicePriority(const uint16_t priority) { + void SetCurSlicePriority(uint16_t priority) + { curSlicePriority_ = priority; } - uint16_t GetCurSlicePriority(void) { + uint16_t GetCurSlicePriority(void) + { return curSlicePriority_; } - void StartSlice(const uint16_t sliceId, const uint16_t priority); - void ResumeSliceWithoutJS(); + void ResumeSlice(); void PauseSlice(); - void StopSlice(); - void StopPrevSlice(); void StopSliceTransition(); void BackToPreSlice(); protected: + // targetId consists of slice id and page id + void StartSlice(uint32_t targetId); + void ResumeSliceWithoutJS(); + void StopSlice(); Ability() = default; virtual ~Ability() = default; struct ProxyStruct { @@ -82,17 +162,20 @@ protected: // 预加载的所有slices Graphic::Vector allSlicesProxy_{16}; - // 历史记录的所有slices, 当前只使用了id - // TODO:: 整页面的能力恢复功能待考虑扩展 - Graphic::Vector allSlices_; + /** Processing rule of allSlices_, its item value consists of slice and page. slice | page << 16. + * 1. When switch slice A to main slice, clear slice vector, and then push back main slice into slice vector + * 2. When switch slice A to slice B (not main), push back slice B into slice vector + * 3. When switch js to slice A, clear slice vector, and then push back slice A into slice vector + * 4. When switch slice A to js, push back 0 into slice vector. You Can get slice A by method GetPreSliceId() + */ + Graphic::Vector allSlices_; SliceStruct curSlice_; - SliceStruct prevSlice_; - uint16_t targetSliceIdFromJS_ = 0; - uint16_t defaultSliceId_ = gSliceInvalid; + SliceStruct nextSlice_; + uint32_t targetIdFromJS_ = 0; + uint32_t defaultTargetId_ = gSliceInvalid; uint16_t curSlicePriority_ = gSliceDefaultPriority; - void PostChangeSlice(const uint16_t targetSliceId, TransitionType type, - const uint16_t priority, bool enableSlideBack); + void PostChangeSlice(uint32_t targetId, TransitionType type); Ability::ProxyStruct* Find(const uint16_t sliceId); }; } diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/AbilitySlice.h b/code/sdk/application/wearable/nativeabilityfwk/include/AbilitySlice.h index a4acb09d7..09a8c81e4 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/AbilitySlice.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/AbilitySlice.h @@ -17,7 +17,9 @@ #define NATIVEABILITYFWK_ABILITY_SLICE_H #include #include "Slice.h" -#include "wearable_log.h" +#include "Presenter.h" +#include "View.h" +#include "SlicePageManager.h" namespace OHOS { enum class SliceState : uint8_t { @@ -27,93 +29,33 @@ enum class SliceState : uint8_t { PAUSE, STOP }; -template class AbilitySlice : public Slice { public: - AbilitySlice() - :view_(nullptr), presenter_(nullptr), state_(SliceState::UNINITIALIZED) {} - ~AbilitySlice() {} + AbilitySlice(ViewBase* viewBase, PresenterBase* presenterBase, uint32_t targetId) + : sliceId_(targetId & SLICE_MASK), view_(viewBase), presenter_(presenterBase), + slicePageMgr_(targetId), state_(SliceState::UNINITIALIZED) {} - void OnStart() override - { - if ((presenter_ != nullptr) || (view_ != nullptr)) { - return; - } + void OnStart() override; - presenter_ = new P(); - view_ = new V(); + void OnResume() override; - presenter_->Attach(view_); - view_->Attach(presenter_); + void OnPause() override; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Slice %s OnStart", typeid(view_).name()); - view_->SetupView(); - view_->OnStart(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Slice %s OnStart", typeid(presenter_).name()); - presenter_->OnStart(); - state_ = SliceState::START; - } + void OnStop() override; - void OnResume() override - { - if ((state_ != SliceState::START) && (state_ != SliceState::PAUSE)) { // avoid repeated resume - return; - } - if (presenter_ != nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Slice %s OnResume", typeid(presenter_).name()); - presenter_->OnResume(); - } - if (view_ != nullptr) { - view_->Draw(); - } - state_ = SliceState::RESUME; - } + UIViewGroup* GetSliceContainer() override; - void OnPause() override - { - if (state_ != SliceState::RESUME) { // avoid repeated pause - return; - } - if (presenter_ != nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Slice %s OnPause", typeid(presenter_).name()); - presenter_->OnPause(); - } - state_ = SliceState::PAUSE; - } + bool ChangeSlicePage(uint16_t pageId, void* data, TransitionType type, bool canBack); - void OnStop() override + SlicePageManager* GetSlicePageManger() { - if (view_ != nullptr) { - view_->TearDownView(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Slice %s OnStop", typeid(view_).name()); - view_->OnStop(); - delete view_; - view_ = nullptr; - } - if (presenter_ != nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Slice %s OnStop", typeid(presenter_).name()); - presenter_->OnStop(); - delete presenter_; - presenter_ = nullptr; - } - state_ = SliceState::STOP; + return &slicePageMgr_; } - - UIViewGroup* GetSliceContainer() override - { - if (view_ != nullptr) { - return view_->GetRootContainer(); - } else { - return nullptr; - } - } - private: - AbilitySlice(const AbilitySlice &); - AbilitySlice &operator=(const AbilitySlice &); - - V* view_; - P* presenter_; + uint16_t sliceId_; + ViewBase* view_; + PresenterBase* presenter_; + SlicePageManager slicePageMgr_; SliceState state_; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/AbilitySliceProxy.h b/code/sdk/application/wearable/nativeabilityfwk/include/AbilitySliceProxy.h index d942f0c62..1cb8f8943 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/AbilitySliceProxy.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/AbilitySliceProxy.h @@ -17,25 +17,26 @@ #define NATIVEABILITYFWK_ABILITY_SLICE_PROXY_H #include "AbilitySlice.h" - #include "wearable_log.h" +#include "Presenter.h" namespace OHOS { template - class AbilitySliceProxy : public SliceProxy { public: - AbilitySliceProxy() {} - ~AbilitySliceProxy() {} - - Slice* CreateSlice() override + Slice* CreateSlice(uint32_t targetId) override { - return new AbilitySlice(); + V* v = new V(); + if (v == nullptr) { + return nullptr; + } + P* p = new P(); + if (p == nullptr) { + delete v; + return nullptr; + } + return new AbilitySlice(v, p, targetId); } - -private: - AbilitySliceProxy(const AbilitySliceProxy &); - AbilitySliceProxy &operator=(const AbilitySliceProxy &); }; } // namespace OHOS #endif // NATIVEABILITYFWK_ABILITY_SLICE_PROXY_H diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/BackDragListener.h b/code/sdk/application/wearable/nativeabilityfwk/include/BackDragListener.h index a851b5523..4cca1dfbe 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/BackDragListener.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/BackDragListener.h @@ -9,16 +9,21 @@ #define BACK_DRAG_LISTENER_H #include #include "animator/animator.h" -#include "components/ui_view.h" +#include "components/ui_view_group.h" namespace OHOS { class BackDragListener : public UIView::OnDragListener { public: - static BackDragListener* GetInstance(); + BackDragListener() = default; + ~BackDragListener() override; bool OnDragStart(UIView& view, const DragEvent& event) override; bool OnDrag(UIView& view, const DragEvent& event) override; bool OnDragEnd(UIView& view, const DragEvent& event) override; - void ClearStatus(); + void ClearDragState(); + void SetParentView(UIViewGroup* view) + { + parentView_ = view; + } void SetCurrentAndTargetView(UIView *cur, UIView *tar) { curView_ = cur; @@ -39,74 +44,46 @@ public: { time_ = time; } + BackDragListener(const BackDragListener &) = delete; + BackDragListener &operator=(const BackDragListener &) = delete; + BackDragListener(BackDragListener &&) = delete; + BackDragListener &operator=(BackDragListener &&) = delete; private: - BackDragListener() {}; - ~BackDragListener() {}; class BackAnimatorCallback : public AnimatorCallback { public: + BackAnimatorCallback(BackDragListener* listener, uint16_t duration) + : dragListener_(listener), curtTime_(0), duration_(duration) {} void Callback(UIView* view) override; - void OnStop(UIView& view) override; - void SetDragParam(int16_t startX, int16_t endX, uint16_t dragTimes) - { - startValueX_ = startX; - endValueX_ = endX; - dragTimes_ = dragTimes; - } - - void SetAnimator(Animator *ani) - { - ani_ = ani; - } - - void SetGoToTarget(bool goToTarget) - { - goToTarget_ = goToTarget; - } - - void SetStopAction(const std::function &action) - { - stopAct_ = action; - } - - void SetTargetView(UIView *target) - { - targetView_ = target; - } - - void ResetStatus() + void OnStop(UIView& view) override { curtTime_ = 0; - dragTimes_ = 0; - startValueX_ = 0; - endValueX_ = 0; - ani_ = nullptr; - stopAct_ = nullptr; - targetView_ = nullptr; - goToTarget_ = false; } - private: - Animator *ani_ = nullptr; - UIView *targetView_ = nullptr; - uint16_t curtTime_ = 0; - uint16_t dragTimes_ = 0; - int16_t startValueX_ = 0; - int16_t endValueX_ = 0; - bool goToTarget_ = false; - std::function stopAct_; + private: + BackDragListener* dragListener_; + uint16_t curtTime_; + uint16_t duration_; }; + bool StartAnimator(); + void StopDragging(); Animator *backAnimator_ = nullptr; - BackAnimatorCallback backCallback_; + BackAnimatorCallback* backCallback_ = nullptr; UIView *targetView_ = nullptr; UIView *curView_ = nullptr; + UIViewGroup* parentView_ = nullptr; int16_t left_ = 0; int16_t right_ = 0; std::function targetAction_; std::function curAction_; const static uint16_t DEFAULT_TIME = 200; uint16_t time_ = DEFAULT_TIME; + bool goToTarget_ = false; + int16_t animStartX_ = 0; + int16_t animEndX_ = 0; + bool isDragging_ = false; + bool isTargetViewAdded_ = false; }; // BackDragListener } // namespace OHOS diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/NativeAbility.h b/code/sdk/application/wearable/nativeabilityfwk/include/NativeAbility.h index 2b1a26890..5ccd53d0f 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/NativeAbility.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/NativeAbility.h @@ -41,14 +41,9 @@ class NativeAbility : public Ability { public: static NativeAbility &GetInstance(void); - #ifdef JS_ENABLE void InstallAbility(void); #endif - void ResumeAbility(uint16_t targetSliceId, uint16_t priority); - void PauseAbility(); - void StopAbility(); - // SliteAbility, AMS控制的应用生命周期 void OnStart(const Want &want) OVERRIDE; void OnActive(const Want &want) OVERRIDE; @@ -57,7 +52,12 @@ public: void OnStop() OVERRIDE; int GetNativeAbilityState() const; + private: + // targetId consists of slice id and page id + void ResumeAbility(uint32_t targetId); + void PauseAbility(); + void StopAbility(); NativeAbility() {} void ResumeSliceWithJS(); ~NativeAbility() override {} diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/PageTransitionMgr.h b/code/sdk/application/wearable/nativeabilityfwk/include/PageTransitionMgr.h index 39e695435..5b58fecc8 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/PageTransitionMgr.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/PageTransitionMgr.h @@ -14,6 +14,7 @@ #include "graphic_mutex.h" #include "TransitionCallback.h" #include "TransitionType.h" +#include "gfx_utils/image_info.h" namespace OHOS { using TransitionAnimatorStopCallback = std::function; @@ -75,6 +76,15 @@ public: // this function is called by application when slice is on pause phase if it need to custom its slideback snapshot void SaveSlideBackSnapShotIfNecessary(UIView* view); UIImageView* GetTopSlideBackImage(); + /** + * @brief Check whether slide back is enabled currently, equivalent to: + * View::GetBackDragListener() + * Note: Don't use canSlideBack_ because it will be reset after transition + */ + bool CanSlideBack() + { + return (GetTopSlideBackImage() != nullptr); + } // remove top slice back image from rootview and delete it void ClearTopSlideBackImage(); void SaveCurrentSourceIfNecessary(UIView* view); @@ -105,6 +115,16 @@ public: return transitionCaller_ == TransitionCaller::BACK_TRANSITION; } + /** + * @brief Set current app's recent img source. Should be invoked in OnResume method. + */ + void SetRecentAppImg(uint32_t resId, std::string file); + + /** + * @brief Set min lasting period of an app so that it could be added to recent manager. + */ + void SetRecentMinPeriod(uint32_t minPeriod); + private: PageTransitionMgr() {}; ~PageTransitionMgr() {}; @@ -112,11 +132,17 @@ private: void SaveSlideBackSnapShotInner(UIView* view, bool custom); void SaveCurrentSnapShotInner(UIView* view); void ClearSlideBackHistory(); + bool SnapshotRecentSource(UIView* view); + void AddRecentAppIfNecessary(); + bool FillRecentSnapshot(bool& needToFreeSnapshot); Animator* animator_ = nullptr; PageTransAnimCallback* animatorCallback_ = nullptr; std::shared_ptr currentSlideBackSnapshot_ = nullptr; std::shared_ptr currentSnapshot_ = nullptr; std::shared_ptr targetSnapshot_ = nullptr; + ImageInfo recentSnapshot_ = {0}; + uint32_t recentAppResId_ = 0; + std::string recentAppFile_ = ""; std::shared_ptr slideBackHistroy_[MAX_SLIDE_BACK_NUM] = {nullptr}; uint8_t curSlideBackNum_ = 0; UIViewGroup* currentView_ = nullptr; @@ -137,6 +163,12 @@ private: GraphicMutex operationLock_; void ClearTransitionResource(); ImageInfo RectifySnapshot(ImageInfo& dstInfo); + uint32_t lastTransitionTime_ = 0; + uint32_t recentMinPeriod_ = 0; + bool recentMinPeriodSatisfied_ = true; + bool isSnapshotRecent_ = false; + uint16_t recentSliceId_ = 0; // invalid slice + uint32_t recentTargetId_ = 0; // invalid slice }; } // namespace OHOS -#endif // PAGE_TRANSITION_MGR_H +#endif // PAGE_TRANSITION_MGR_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/Presenter.h b/code/sdk/application/wearable/nativeabilityfwk/include/Presenter.h index 76276cc2e..b8cbc7a4c 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/Presenter.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/Presenter.h @@ -16,20 +16,13 @@ #ifndef APPFWK_PRESENTER_H #define APPFWK_PRESENTER_H -#include "components/root_view.h" -#include "KeyInputListener.h" -#include "dock/focus_manager.h" -#include "PageTransitionMgr.h" -#include "NativeAbility.h" -#include "BackDragListener.h" +#include "View.h" namespace OHOS { -template - -class Presenter { +class PresenterBase { public: - Presenter() : view_(nullptr), model_(nullptr) {} - virtual ~Presenter() {} + PresenterBase() : viewBase_(nullptr) {} + virtual ~PresenterBase() = default; /** * @brief Scheduled by slice when it is started and before transition animator starts if exsit @@ -42,39 +35,15 @@ public: * @brief Scheduled by slice when it will be visiable and after transition animator ends if exsit * * You can set custom input event listener, request focus, and start its own animator here. - * Please call Presenter::OnResume in your implemention */ - virtual void OnResume() - { - // make sure root container was added because it maybe removed during transition when current snap is false - if (view_->GetRootContainer()->GetParent() == nullptr) { - RootView::GetInstance()->Add(view_->GetRootContainer()); - } - // Reset the default key listener - RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance()); - UIView* backView = PageTransitionMgr::GetInstance().GetTopSlideBackImage(); - if (backView == nullptr) { - return; - } - BackDragListener::GetInstance()->ClearStatus(); - BackDragListener::GetInstance()->SetCurrentAndTargetView(view_->GetRootContainer(), backView); - BackDragListener::GetInstance()->SetDragToTargetAction([]() { NativeAbility::GetInstance().BackToPreSlice(); }); - view_->GetRootContainer()->SetOnDragListener(BackDragListener::GetInstance()); - } + virtual void OnResume() {} /** * @brief Scheduled by slice when another slice will be started and before slice transition animator starts if exsit * * You can clear input event listener, clear focus, and stop animator here. - * Please call Presenter::OnPause in your implemention if default key listener need to be cleared. */ - virtual void OnPause() - { - // Ensure that key listener is disabled during transition if exist - RootView::GetInstance()->ClearOnKeyActListener(); - view_->GetRootContainer()->SetOnDragListener(nullptr); - FocusManager::GetInstance()->ClearFocus(); - } + virtual void OnPause() {} /** * @brief Presenter lifecycle scheduled by slice when it will be invisible and another slice will be visible @@ -82,14 +51,39 @@ public: * You can destroy non-ui resources here */ virtual void OnStop() {} + + /** + * @brief This function will attach view to this presenter + * + * @param view view pointer defined by developer + */ + virtual void Attach(ViewBase* view) + { + viewBase_ = view; + } + + PresenterBase(const PresenterBase&) = delete; + PresenterBase& operator=(const PresenterBase&) = delete; + PresenterBase(PresenterBase&&) = delete; + PresenterBase& operator=(PresenterBase&&) = delete; +protected: + ViewBase* viewBase_; +}; + +template +class Presenter : public PresenterBase { +public: + Presenter() : model_(nullptr) {} + /** * @brief This function will attach view to this presenter * * @param view view pointer defined by developer */ - void Attach(V* view) + void Attach(ViewBase* view) override { - view_ = view; + PresenterBase::Attach(view); + view_ = dynamic_cast(viewBase_); } /** @@ -105,13 +99,6 @@ public: protected: V* view_; M* model_; - BackDragListener* backDragListener_ = nullptr; - -private: - Presenter(const Presenter&) = delete; - Presenter& operator=(const Presenter&) = delete; - Presenter(Presenter&&) = delete; - Presenter& operator=(Presenter&&) = delete; }; } #endif diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/RecentManager.h b/code/sdk/application/wearable/nativeabilityfwk/include/RecentManager.h new file mode 100644 index 000000000..76e9598db --- /dev/null +++ b/code/sdk/application/wearable/nativeabilityfwk/include/RecentManager.h @@ -0,0 +1,192 @@ +/* + * Copyright (c) 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 RECENT_MANAGER_H +#define RECENT_MANAGER_H + +#include +#include +#include "gfx_utils/image_info.h" +#include "gfx_utils/list.h" +#include "graphic_mutex.h" + +namespace OHOS { +#define RECENT_APP_BUNDLE_NAME_MAX_LEN 127 + +typedef struct { + bool isNativeSlice; // true: native; false: js + union { + uint32_t targetId; + char bundleName[RECENT_APP_BUNDLE_NAME_MAX_LEN]; + }; + ImageInfo* snapshot; +} RecentAppInfo; + +class RecentManager { +public: + + /** + * @brief Get RecentManager* instance. + */ + static RecentManager* GetInstance(); + + /** + * @brief Set max recent app size. Once current size > max, the oldest will be removed. + * Default value is 0, and it will not record any recent app. + */ + void SetMaxSize(uint32_t max); + + /** + * @brief Get max recent app size. + */ + uint32_t GetMaxSize(); + + /** + * @brief Get current recent app size. + */ + uint32_t GetCurrentSize(); + + /** + * @brief Add a native app to recent manager with its snapshot to be cached. + */ + void AddRecentApp(uint32_t targetId, const ImageInfo* snapshot); + + /** + * @brief Add a js app to recent manager with its snapshot to be cached. + */ + void AddRecentApp(const char* bundleName, const ImageInfo* snapshot); + + /** + * @brief Remove a native app with given targetId. + */ + bool RemoveRecentApp(uint32_t targetId, bool deleteFile = true); + + /** + * @brief Remove a js app with given bundleName. + */ + bool RemoveRecentApp(const char* bundleName, bool deleteFile = true); + + /** + * @brief Remove all recent apps. + */ + void RemoveAllRecentApps(); + + /** + * @brief Get a list of RecentAppInfo. + */ + const List& GetRecentApps(); + + /** + * @brief Set scale ratio. When an app is added, its snapshot could be scaled and cached. Default value is 0.5f. + */ + void SetScaleRatio(float ratio); + + /** + * @brief Get scale ratio. + */ + float GetScaleRatio(); + + /** + * @brief Add a sliceId to black list so that it will not be saved as a recent app. + */ + void AddToBlackList(uint32_t sliceId); + + /** + * @brief Remove a sliceId from black list so that it can be saved as a recent app. + */ + void RemoveFromBlackList(uint32_t sliceId); + + /** + * @brief Clear black list. + */ + void ClearBlackList(); + + /** + * @brief Return whether the sliceId is on black list. + */ + bool IsOnBlackList(uint32_t sliceId); + + /** + * @brief Return whether it is updated. + */ + bool IsUpdateCompleted(); + + /** + * @brief Set dir path to save recent snapshots. + */ + void SetDirPath(std::string path); + + /** + * @brief Return dir path to save recent snapshots. + */ + std::string GetDirPath(); + + /** + * @brief Return whether it is enabled. It is enabled when max size is a valid value and dir path is set. + */ + bool IsEnabled(); + + /** + * @brief Used internally. + */ + void PushRecentApp(RecentAppInfo* info); + + /** + * @brief Used internally. + */ + void RemoveOldest(); + + /** + * @brief Used internally. + */ + void DecLoadingCnt(); + + /** + * @brief Used internally. + */ + uint32_t GetLoadingCnt(); + +private: + RecentManager(); + virtual ~RecentManager(); + + void AddRecentAppWithSourceInfo(RecentAppInfo* appInfo, const ImageInfo* snapshot); + void AddRecentAppInner(RecentAppInfo* appInfo, const ImageInfo* snapshot); + void RemoveRecentAppNode(ListNode* node, bool deleteFile); + bool ScaleSnapshot(const ImageInfo* src, ImageInfo* dst); + ListNode* FindRecentAppInfo(List& list, + bool isNativeSlice, uint32_t sliceId, const char* bundleName); + void AddPersistingTask(RecentAppInfo* info); + static void AsyncPersisterRunnable(void* args); + static void FreeRecentAppInfo(void* data); + void AsyncFreeRecentAppInfo(RecentAppInfo* info); + void ProcessPersistingTasks(); + void ProcessTask(RecentAppInfo* info); + static void LoadRecentApp(void* data); + List recentApps_; + List persistingTasks_; + List blackList_; + static GraphicMutex recentAppsMutex_; + static GraphicMutex persistingTaskMutex_; + static GraphicCond newPersistingTaskCond_; + static GraphicCond persistingTaskDoneCond_; + uint32_t maxSize_ = 0; + float scaleRatio_ = 0.5f; + std::string dirPath_; + uint32_t loadingCnt_ = 0; +}; +} // namespace OHOS + +#endif // RECENT_MANAGER_H diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/Slice.h b/code/sdk/application/wearable/nativeabilityfwk/include/Slice.h index 9e87062a6..047cc6085 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/Slice.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/Slice.h @@ -18,10 +18,12 @@ #include "components/ui_view_group.h" namespace OHOS { +extern const uint16_t SLICE_MASK; +extern const uint32_t PAGE_OFFSET; class Slice { public: - Slice() {} - virtual ~Slice() {} + Slice() = default; + virtual ~Slice() = default; /** * @brief Called when the Slice is started and before transition animator starts if exits. * @@ -54,9 +56,10 @@ public: virtual void OnStop() = 0; virtual UIViewGroup* GetSliceContainer() = 0; -private: - Slice(const Slice &); - Slice &operator=(const Slice &); + Slice(const Slice &) = delete; + Slice &operator=(const Slice &) = delete; + Slice(Slice &&) = delete; + Slice &operator=(Slice &&) = delete; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/SlicePage.h b/code/sdk/application/wearable/nativeabilityfwk/include/SlicePage.h new file mode 100644 index 000000000..127f32941 --- /dev/null +++ b/code/sdk/application/wearable/nativeabilityfwk/include/SlicePage.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: Slice Page + * Author: Hisi Graphic Team + * Create: 2025-4 + */ +#ifndef SLICE_PAGE_H +#define SLICE_PAGE_H +#include "components/ui_view_group.h" +#include "Presenter.h" + +namespace OHOS { +class SlicePageBase { +public: + SlicePageBase() : pageContainer_(nullptr), backDragListener_(nullptr) {} + + virtual ~SlicePageBase() = default; + + virtual void OnStart(void* data) = 0; + + virtual void OnResume() {} + + virtual void OnPause() {} + + virtual void OnStop() {} + + UIViewGroup* GetSlicePageContainer() + { + return pageContainer_; + } + + BackDragListener* GetBackDragListener() + { + return backDragListener_; + } + + void AddViewToPageContainer(UIView* view); + + virtual void AttachPresenter(PresenterBase* p) = 0; + + SlicePageBase(const SlicePageBase&) = delete; + SlicePageBase& operator=(const SlicePageBase&) = delete; + SlicePageBase(SlicePageBase&&) = delete; + SlicePageBase& operator=(SlicePageBase&&) = delete; + uint16_t pageId_; + +private: + friend class SlicePageManager; + void SetupView(bool canBack); + void TearDownView(); + UIViewGroup* pageContainer_; + BackDragListener* backDragListener_; +}; + +template +class SlicePage : public SlicePageBase { +public: + void AttachPresenter(PresenterBase* p) override + { + presenter_ = dynamic_cast(p); + } +protected: + P* presenter_ = nullptr; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/SlicePageFactory.h b/code/sdk/application/wearable/nativeabilityfwk/include/SlicePageFactory.h new file mode 100644 index 000000000..49dd1c7b0 --- /dev/null +++ b/code/sdk/application/wearable/nativeabilityfwk/include/SlicePageFactory.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: SlicePageFactory + * Author: Hisi Graphic Team + * Create: 2025-4 + */ +#ifndef SLICE_PAGE_FACTORY_H +#define SLICE_PAGE_FACTORY_H +#include +#include "SlicePage.h" + +namespace OHOS { +class SlicePageProxyInterface; +class SlicePageFactory : public HeapBase { +public: + static SlicePageFactory& GetInstance() + { + static SlicePageFactory instance; + return instance; + } + + bool IsSlicePageExist(uint16_t sliceId, uint16_t pageId); + + SlicePageBase* CreateSlicePage(uint16_t sliceId, uint16_t pageId); + + SlicePageBase* GetDefaultSlicePage(uint16_t sliceId, uint16_t& defaultPageId); + + void RegisterPage(uint16_t sliceId, uint16_t pageId, SlicePageProxyInterface* proxy, bool isMainPage); + +private: + SlicePageFactory() {}; + ~SlicePageFactory() {}; + SlicePageFactory(const SlicePageFactory &) = delete; + SlicePageFactory &operator=(const SlicePageFactory &) = delete; + std::unordered_map pageProxyMap_; + std::unordered_map mainPageMap_; + std::unordered_map mainPageIdMap_; +}; + +class SlicePageProxyInterface : public HeapBase { +public: + virtual SlicePageBase* CreateSlicePage(uint16_t pageId) = 0; +}; + +class SlicePageRegister : public HeapBase { +public: + SlicePageRegister(uint16_t sliceId, uint16_t pageId, SlicePageProxyInterface* proxy, bool isMainPage); +}; + +template +class SlicePageProxy : public SlicePageProxyInterface { +public: + SlicePageBase* CreateSlicePage(uint16_t pageId) override + { + V* v = new V(); + SlicePageBase* page = dynamic_cast(v); + if (page == nullptr) { + delete v; + } else { + page->pageId_ = pageId; + } + return page; + } +}; +} + +#define REGIST_SLICE_PAGE(sliceId, pageId, V, isMainPage) \ + const static OHOS::SlicePageRegister (STATIC_VAR)(sliceId, pageId, new OHOS::SlicePageProxy(), isMainPage) +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/SlicePageManager.h b/code/sdk/application/wearable/nativeabilityfwk/include/SlicePageManager.h new file mode 100644 index 000000000..c69ef48f4 --- /dev/null +++ b/code/sdk/application/wearable/nativeabilityfwk/include/SlicePageManager.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: SlicePageManager + * Author: Hisi Graphic Team + * Create: 2025-4 + */ +#ifndef SLICE_PAGE_MANAGER_H +#define SLICE_PAGE_MANAGER_H +#include "animator/animator.h" +#include "Presenter.h" +#include "Slice.h" +#include "SlicePage.h" +#include "gfx_utils/vector.h" +#include "TransitionType.h" +#include "TransitionCallback.h" + +namespace OHOS { +class SlicePageManager; +class SlicePageSwitchCallback : public AnimatorCallback { +public: + SlicePageSwitchCallback(SlicePageManager* transMgr) + : isStarted_(false), startTime_(0), pageTransMgr_(transMgr) {} + void Callback(UIView* view) override; + void OnStop(UIView& view) override; + +private: + bool isStarted_; + uint32_t startTime_; + SlicePageManager* pageTransMgr_; +}; + +class SlicePageManager : public HeapBase { +public: + SlicePageManager(uint32_t targetId) + : isPageBeingSwitched_(false), sliceId_(static_cast(targetId & SLICE_MASK)), + targetPageId_(static_cast(targetId >> PAGE_OFFSET)), + curPage_(nullptr), nextPage_(nullptr), pagesInBackQueue_(4), // 4, default queue size + presenter_(nullptr), view_{nullptr}, transitionCallback_(nullptr), canBack_(false) {} + + ~SlicePageManager(); + + // Get current page which is display on the screen + SlicePageBase* GetCurSlicePage() + { + return curPage_; + } + + // Get specified page in the back queue + SlicePageBase* GetSlicePageInBackQueue(uint16_t sliceId); + + // Get previous page before current page in the back queue + SlicePageBase* GetLastPageInBackQueue() + { + return pagesInBackQueue_.Back(); + } + + void ClearBackQueue(); + + bool ChangeSlicePage(uint16_t pageId, void* data, TransitionType type, bool canBack); + + bool IsAnimatorRunning() + { + return ((animator_ != nullptr) && (animator_->GetState() != Animator::STOP)); + } + + void BackToPrevSlicePage(); + + SlicePageManager(const SlicePageManager&) = delete; + SlicePageManager& operator=(const SlicePageManager&) = delete; + SlicePageManager(SlicePageManager&&) = delete; + SlicePageManager& operator=(SlicePageManager&&) = delete; + +private: + friend class AbilitySlice; + friend class SlicePageSwitchCallback; + void AttachVP(PresenterBase* p, ViewBase* v) + { + presenter_ = p; + view_ = v; + } + void StartSlicePage(void* data = nullptr); + void ResumeSlicePage(); + void PauseSlicePage(); + void StopSlicePage(bool clearBackQueue = true); + void StartSwitchAnimator(); + void StopSwitchAnimator(); + + Animator* animator_ = nullptr; + SlicePageSwitchCallback* switchCallback_ = nullptr; + bool isPageBeingSwitched_; + uint16_t sliceId_; + uint16_t targetPageId_; + SlicePageBase* curPage_; + SlicePageBase* nextPage_; + Graphic::Vector pagesInBackQueue_; + PresenterBase* presenter_; + ViewBase* view_; + TransitionCallback* transitionCallback_; + bool canBack_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/SliceProxy.h b/code/sdk/application/wearable/nativeabilityfwk/include/SliceProxy.h index 7d1cc3b32..ccbf2be7e 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/SliceProxy.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/SliceProxy.h @@ -20,13 +20,13 @@ namespace OHOS { class SliceProxy { public: - SliceProxy() {} - ~SliceProxy() {} - virtual Slice* CreateSlice() = 0; - -private: - SliceProxy(const SliceProxy &); - SliceProxy &operator=(const SliceProxy &); + virtual Slice* CreateSlice(uint32_t targetId) = 0; + SliceProxy() = default; + virtual ~SliceProxy() = default; + SliceProxy(const SliceProxy&) = delete; + SliceProxy& operator=(const SliceProxy&) = delete; + SliceProxy(SliceProxy&&) = delete; + SliceProxy& operator=(SliceProxy&&) = delete; }; } // namespace OHOS #endif // SLICE_PROXY_H diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/View.h b/code/sdk/application/wearable/nativeabilityfwk/include/View.h index 1243e46b1..207926648 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/View.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/View.h @@ -17,26 +17,35 @@ #define APPFWK_VIEW_H #include "components/ui_view_group.h" -#include "components/root_view.h" -#include "common/screen.h" +#include "BackDragListener.h" namespace OHOS { -template -class View { +class PresenterBase; +class ViewBase { public: - View() : presenter_(nullptr), rootContainer_(nullptr) {} - virtual ~View() {} + ViewBase() : rootContainer_(nullptr), backDragListener_(nullptr) {} + virtual ~ViewBase() = default; /** - * @brief get container view - * - * @returns container + * @brief Get container view + * @returns rootContainer_ */ - UIViewGroup* GetRootContainer() const + UIViewGroup* GetRootContainer() { return rootContainer_; } + /** + * @brief Get back drag listener + * This method can be used in AbilitySlice.cpp, and also can be used in XXXView.cpp + * If used in XXXView.cpp, you can use it to check whether default OnDragListener is configured. + * @returns backDragListener_ + */ + BackDragListener* GetBackDragListener() + { + return backDragListener_; + } + /** * @brief Scheduled by slice after funtion SetupView and before transition animator starts if exits. * @@ -65,76 +74,50 @@ public: virtual void OnStop() {} /** - * @brief Scheduled by slice to create root container add it to root view + * @brief draw container * - * This method is called by system class AbilitySlice, you should not override it. */ - void SetupView() - { - if (rootContainer_ != nullptr) { - printf("OnStart Error: rootContainer_ already exist"); - } else { - rootContainer_ = new UIViewGroup(); - } - rootContainer_->SetPosition(0, 0, RootView::GetInstance()->GetWidth(), RootView::GetInstance()->GetHeight()); - RootView::GetInstance()->Add(rootContainer_); - } + void Draw(); /** - * @brief Scheduled by slice to remove and delete root container from root view + * @brief This function will attach presenter to this view * - * This method is called by by system class AbilitySlice, you should not override it. + * @param presenter presenter pointer defined by developer */ - void TearDownView() - { - // Todo: Only remove root container, and application should remove other children in its own implemention - RootView::GetInstance()->Remove(rootContainer_); - if (rootContainer_ != nullptr) { - rootContainer_->RemoveAll(); - delete rootContainer_; - rootContainer_ = nullptr; - } else { - printf("TearDownView Error: rootContainer_ was not initialized !!!"); - } - } + virtual void Attach(PresenterBase* presenter) = 0; - /** - * @brief draw container - * - */ - void Draw() - { - RootView::GetInstance()->Invalidate(); - } + void AddViewToRootContainer(UIView* view); + + ViewBase(const ViewBase&) = delete; + ViewBase& operator=(const ViewBase&) = delete; + ViewBase(ViewBase&&) = delete; + ViewBase& operator=(ViewBase&&) = delete; + +private: + friend class AbilitySlice; + void SetupView(); + void TearDownView(); + UIViewGroup* rootContainer_; + BackDragListener* backDragListener_; +}; + +template +class View : public ViewBase { +public: + View() : presenter_(nullptr) {} /** * @brief This function will attach presenter to this view * * @param presenter presenter pointer defined by developer */ - void Attach(P* presenter) - { - presenter_ = presenter; - } - - void AddViewToRootContainer(UIView* view) + void Attach(PresenterBase* presenter) override { - if (rootContainer_ == nullptr) { - printf("AddViewToContainer Error: rootContainer_ is nullptr"); - return; - } - rootContainer_->Add(view); + presenter_ = dynamic_cast(presenter); } protected: P* presenter_; - -private: - UIViewGroup* rootContainer_ = nullptr; - View(const View&) = delete; - View& operator=(const View&) = delete; - View(View&&) = delete; - View& operator=(View&&) = delete; }; } #endif diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp index 8be4e9709..82e0d033d 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp +++ b/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp @@ -24,14 +24,9 @@ #include "common/graphic_utils.h" #include "PageTransitionMgr.h" #include "gfx_utils/list.h" +#include "AbilitySlice.h" namespace OHOS { -const uint8_t MAX_SLICE_ID_LENGTH = 16; -struct SliceOperation { - uint16_t targetSliceId; - TransitionType type; -}; - void Ability::AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability AddSliceProxy sliceId = %d", sliceId); @@ -47,49 +42,39 @@ void Ability::AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy) allSlicesProxy_.PushBack(proxyPair); } -void Ability::StartSlice(const uint16_t sliceId, const uint16_t priority) +void Ability::StartSlice(uint32_t targetId) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability StartSlice %d", sliceId); - if (sliceId <= gSliceInvalid) { + if (targetId <= gSliceInvalid) { return; } - + uint16_t sliceId = static_cast(targetId & SLICE_MASK); Ability::ProxyStruct* proxyStruct = Find(sliceId); if (proxyStruct == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "no slice %d was found", sliceId); return; } InputDeviceManager::GetInstance()->ClearInputDeviceState(); - Slice* nextSlice = proxyStruct->proxy->CreateSlice(); - if (nextSlice == nullptr) { + + Slice* newSlice = proxyStruct->proxy->CreateSlice(targetId); + if (newSlice == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "create slice %u failed", sliceId); return; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability::StartSlice Size = %d", allSlices_.Size()); - // 记录最多gMaxHistorySlices个页面id - if (PageTransitionMgr::GetInstance().IsBackTransitionRunning()) { - PageTransitionMgr::GetInstance().ClearTopSlideBackImage(); - } - if (sliceId == defaultSliceId_) { - allSlices_.Clear(); // clear slice history when return to home - allSlices_.PushBack(defaultSliceId_); + if (sliceId == defaultTargetId_) { + allSlices_.Clear(); // clear slice history when return to main slice + allSlices_.PushBack(defaultTargetId_); } else if (PageTransitionMgr::GetInstance().IsBackTransitionRunning()) { allSlices_.PopBack(); } else { - allSlices_.PushBack(sliceId); - } - if (curSlice_.slice != nullptr) { - prevSlice_.sliceId = curSlice_.sliceId; - prevSlice_.slice = curSlice_.slice; - } else { - prevSlice_.sliceId = gSliceInvalid; - prevSlice_.slice = nullptr; + allSlices_.PushBack(targetId); } - curSlice_.sliceId = sliceId; - curSlice_.slice = nextSlice; - curSlicePriority_ = priority; - - nextSlice->OnStart(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability StartSlice %d page %d size:%d", sliceId, + targetId >> PAGE_OFFSET, allSlices_.Size()); + nextSlice_.sliceId = sliceId; + nextSlice_.slice = newSlice; + newSlice->OnStart(); } Ability::ProxyStruct* Ability::Find(const uint16_t sliceId) @@ -110,46 +95,102 @@ Ability::ProxyStruct* Ability::Find(const uint16_t sliceId) return nullptr; } -void Ability::ChangeSlice(const uint16_t targetSliceId, TransitionType type, - const uint16_t priority, bool enableSlideBack) +SlicePageManager* Ability::GetCurSlicePageManager() +{ + if (PageTransitionMgr::GetInstance().IsTransitionRunning()) + { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "No valid SlicePageManager during slice switching"); + return nullptr; + } + AbilitySlice* slice = dynamic_cast(curSlice_.slice); + if (slice == nullptr) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "No valid SlicePageManager when js is running"); + return nullptr; + } + return slice->GetSlicePageManger(); +} + +void Ability::UpdateCurSlicePageId(uint16_t pageId) +{ + if (allSlices_.IsEmpty()) { + return; + } + uint32_t sliceId = allSlices_[allSlices_.Size() - 1] & SLICE_MASK; + allSlices_[allSlices_.Size() - 1] = sliceId | (static_cast(pageId) << PAGE_OFFSET); +} + +bool Ability::SwitchPageInSlice(uint16_t pageId, void* data, TransitionType type, bool canBack) +{ + if (pageId == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page id should be valid but no zero"); + return false; + } + if (PageTransitionMgr::GetInstance().IsTransitionRunning()) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page can't be switched during transition"); + return false; + } + AbilitySlice* slice = dynamic_cast(curSlice_.slice); + if (slice == nullptr) { + WEARABLE_LOGW(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "page can't be switched because current slice is nullptr"); + return false; + } + return slice->ChangeSlicePage(pageId, data, type, canBack); +} + +void Ability::SwitchSlice(uint16_t sliceId, uint16_t pageId, TransitionType type, bool enableSlideBack) { + if (Find(sliceId) == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "slice %d is not registered", sliceId); + return; + } #ifdef JS_ENABLE ElementName *elementName = OHOS::AbilityMsClient::GetInstance().GetTopAbility(); if (elementName != nullptr && strcmp(elementName->bundleName, "com.huawei.launcher") != 0) { OHOS::AbilityMsClient::GetInstance().ForceStop(elementName->bundleName, type); - targetSliceIdFromJS_ = targetSliceId; + targetIdFromJS_ = sliceId | (static_cast(pageId) << PAGE_OFFSET); FreeElement(elementName); return; } FreeElement(elementName); #endif TransitionTarget target; - target.sliceInfo = targetSliceId | (priority << 16); + target.sliceInfo = sliceId | (static_cast(pageId) << PAGE_OFFSET); bool runImmed = PageTransitionMgr::GetInstance().BeginTransition(TransitionCaller::CHANGE_SLICE, target, type, enableSlideBack); if (!runImmed) { - printf("pending change slice id:%d type:%d enableSlideBack:%d\n", targetSliceId, type, enableSlideBack); + printf("pending change slice id:%d type:%d enableSlideBack:%d\n", target.sliceInfo, type, enableSlideBack); return; } - GraphicService::GetInstance()->PostGraphicEvent(std::bind(&Ability::PostChangeSlice, this, targetSliceId, - type, priority, enableSlideBack)); + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&Ability::PostChangeSlice, this, target.sliceInfo, type)); } -void Ability::PostChangeSlice(const uint16_t targetSliceId, TransitionType type, +void Ability::ChangeSlice(uint16_t sliceId, TransitionType type, const uint16_t priority, bool enableSlideBack) +{ + (void)(priority); + SwitchSlice(sliceId, gPageInvalid, type, enableSlideBack); +} + +void Ability::PostChangeSlice(uint32_t targetId, TransitionType type) { PauseSlice(); + if (allSlices_.Size() > 0 && allSlices_[allSlices_.Size() - 1] == VIEW_AOD) { + allSlices_.PopBack(); + if (allSlices_.Size() > 0 && (allSlices_[allSlices_.Size() - 1] & SLICE_MASK) == (targetId & SLICE_MASK)) { + allSlices_.PopBack(); + } + } PageTransitionMgr::GetInstance().SaveCurrentSourceIfNecessary(curSlice_.slice->GetSliceContainer()); if (!PageTransitionMgr::GetInstance().IsTransAnimNeeded() || PageTransitionMgr::GetInstance().IsCurrentSnapshotEnabled()) { StopSlice(); } - StartSlice(targetSliceId, priority); + StartSlice(targetId); if (!PageTransitionMgr::GetInstance().IsTransAnimNeeded()) { ResumeSliceWithoutJS(); } else { - PageTransitionMgr::GetInstance().SaveTargetSource(curSlice_.slice->GetSliceContainer()); + PageTransitionMgr::GetInstance().SaveTargetSource(nextSlice_.slice->GetSliceContainer()); PageTransitionMgr::GetInstance().StartTransAnim(std::bind(&Ability::ResumeSliceWithoutJS, this)); } } @@ -158,7 +199,7 @@ void Ability::ResumeSliceWithoutJS() { if (PageTransitionMgr::GetInstance().IsTransAnimNeeded() && !PageTransitionMgr::GetInstance().IsCurrentSnapshotEnabled()) { - StopPrevSlice(); + StopSlice(); } ResumeSlice(); PageTransitionMgr::GetInstance().EndTransition(true); @@ -166,6 +207,17 @@ void Ability::ResumeSliceWithoutJS() void Ability::ResumeSlice() { + // if new slice was created, set is as current slice and resume it + if (nextSlice_.slice != nullptr) { + if (curSlice_.slice != nullptr) { + GRAPHIC_LOGE("Both slice %d and %d is valid during resume", curSlice_.sliceId, nextSlice_.sliceId); + } + curSlice_.sliceId = nextSlice_.sliceId; + curSlice_.slice = nextSlice_.slice; + nextSlice_.sliceId = gSliceInvalid; + nextSlice_.slice = nullptr; + } + if (curSlice_.slice != nullptr) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability ResumeSlice %d", curSlice_.sliceId); curSlice_.slice->OnResume(); @@ -177,8 +229,8 @@ void Ability::ResumeSlice() void Ability::PauseSlice() { if (curSlice_.slice != nullptr) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability PauseSlice %d", curSlice_.sliceId); InputDeviceManager::GetInstance()->ClearInputDeviceState(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability PauseSlice %d", curSlice_.sliceId); curSlice_.slice->OnPause(); } else { GRAPHIC_LOGE("No valid slice to pause"); @@ -199,21 +251,6 @@ void Ability::StopSlice() } } -void Ability::StopPrevSlice() -{ - if (prevSlice_.slice != nullptr) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability StopPrevSlice %d", prevSlice_.sliceId); - prevSlice_.slice->OnStop(); - if (prevSlice_.slice != nullptr) { - prevSlice_.sliceId = gSliceInvalid; - delete prevSlice_.slice; - prevSlice_.slice = nullptr; - } - } else { - GRAPHIC_LOGE("No valid prev slice to stop"); - } -} - void Ability::StopSliceTransition() { PageTransitionMgr::GetInstance().SyncStopAnimator(); @@ -221,15 +258,17 @@ void Ability::StopSliceTransition() void Ability::BackToPreSlice() { - uint16_t targetSliceId = GetPreSliceId(); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability BackToPreSlice %d", targetSliceId); - if (targetSliceId == gSliceInvalid) { + uint32_t targetId = GetPreTargetId(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Ability BackToPreSlice %d", targetId); + if (targetId == gSliceInvalid) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "previous slice is invalid"); return; } TransitionTarget target; - target.sliceInfo = targetSliceId | (gSliceDefaultPriority << 16); + target.sliceInfo = targetId; + uint16_t sliceId = static_cast(targetId & SLICE_MASK); + uint16_t pageId = static_cast(targetId >> PAGE_OFFSET); PageTransitionMgr::GetInstance().BeginBackTransition(TransitionCaller::CHANGE_SLICE, target); - ChangeSlice(targetSliceId); + SwitchSlice(sliceId, pageId); } } // namespace OHOS diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/AbilitySlice.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/AbilitySlice.cpp new file mode 100644 index 000000000..37810c795 --- /dev/null +++ b/code/sdk/application/wearable/nativeabilityfwk/src/AbilitySlice.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: AbilitySlice + * Author: Hisi Graphic Team + * Create: 2025-4 + */ + +#include "AbilitySlice.h" +#include "components/root_view.h" +#include "dock/focus_manager.h" +#include "wearable_log.h" +#include "PageTransitionMgr.h" +#include "NativeAbility.h" +#include "View.h" +#include "Presenter.h" +#include "key/KeyInputListener.h" + +namespace OHOS { +const uint16_t SLICE_MASK = 0xFFFF; +const uint32_t PAGE_OFFSET = 16; + +void AbilitySlice::OnStart() +{ + if ((presenter_ == nullptr) || (view_ == nullptr)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "Presenter or View was nullptr for slice %s", sliceId_); + return; + } + + // if back to current slice, delete slide back ImageView of current slice firstly + if (PageTransitionMgr::GetInstance().IsBackTransitionRunning()) { + PageTransitionMgr::GetInstance().ClearTopSlideBackImage(); + } + presenter_->Attach(view_); + view_->Attach(presenter_); + slicePageMgr_.AttachVP(presenter_, view_); + + view_->SetupView(); + view_->OnStart(); + slicePageMgr_.StartSlicePage(); + presenter_->OnStart(); + state_ = SliceState::START; +} + +void AbilitySlice::OnResume() +{ + if ((state_ != SliceState::START) && (state_ != SliceState::PAUSE)) { // avoid repeated resume + return; + } + if ((presenter_ == nullptr) || (view_ == nullptr)) { + return; + } + + if (view_->GetRootContainer()->GetParent() == nullptr) { + RootView::GetInstance()->Add(view_->GetRootContainer()); + } + // Reset the default key listener + RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance()); + NativeAbility::GetInstance().SetCurSlicePriority(gSliceDefaultPriority); + + UIView* backView = PageTransitionMgr::GetInstance().GetTopSlideBackImage(); + BackDragListener* backDragListener = view_->GetBackDragListener(); + if ((backView != nullptr) && ((backDragListener != nullptr))) { + backDragListener->SetCurrentAndTargetView(view_->GetRootContainer(), backView); + backDragListener->SetParentView(RootView::GetInstance()); + backDragListener->SetDragToTargetAction([]() { NativeAbility::GetInstance().BackToPreSlice(); }); + view_->GetRootContainer()->SetTouchable(true); + view_->GetRootContainer()->SetDraggable(true); + view_->GetRootContainer()->SetOnDragListener(backDragListener); + } + + slicePageMgr_.ResumeSlicePage(); + presenter_->OnResume(); + view_->Draw(); + state_ = SliceState::RESUME; +} + +void AbilitySlice::OnPause() +{ + if (state_ != SliceState::RESUME) { // avoid repeated pause + return; + } + if ((presenter_ == nullptr) || (view_ == nullptr)) { + return; + } + + if (slicePageMgr_.IsAnimatorRunning()) { + slicePageMgr_.StopSwitchAnimator(); + } + slicePageMgr_.PauseSlicePage(); + RootView::GetInstance()->ClearOnKeyActListener(); + BackDragListener* backDragListener = view_->GetBackDragListener(); + if (backDragListener != nullptr) { + backDragListener->ClearDragState(); + } + view_->GetRootContainer()->SetOnDragListener(nullptr); + + FocusManager::GetInstance()->ClearFocus(); + presenter_->OnPause(); + state_ = SliceState::PAUSE; +} + +void AbilitySlice::OnStop() +{ + if ((presenter_ == nullptr) || (view_ == nullptr)) { + return; + } + + slicePageMgr_.StopSlicePage(); + view_->TearDownView(); + view_->OnStop(); + delete view_; + view_ = nullptr; + + presenter_->OnStop(); + delete presenter_; + presenter_ = nullptr; + + state_ = SliceState::STOP; +} + +UIViewGroup* AbilitySlice::GetSliceContainer() +{ + if (view_ != nullptr) { + return view_->GetRootContainer(); + } else { + return nullptr; + } +} + +bool AbilitySlice::ChangeSlicePage(uint16_t pageId, void* data, TransitionType type, bool canBack) +{ + return slicePageMgr_.ChangeSlicePage(pageId, data, type, canBack); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp index 12a9cb143..1b5ae820c 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp +++ b/code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp @@ -78,37 +78,40 @@ void NativeAbility::ResumeSliceWithJS() #endif } -void NativeAbility::ResumeAbility(uint16_t targetSliceId, uint16_t priority) +void NativeAbility::ResumeAbility(uint32_t targetId) { GraphicService::GetInstance()->SetNativeUIRunning(true); NotificationManager::GetInstance()->SetNativeUIRunning(true); - if (curSlice_.slice == nullptr) { + if ((targetId & SLICE_MASK) != VIEW_AOD) { allSlices_.Clear(); // clear slice history when jump from js to native - StartSlice(targetSliceId, priority); } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "NativeAbility ResumeAbility with slice %d", curSlice_.sliceId); + allSlices_.PopBack(); // clear invalid slice id + } + StartSlice(targetId); + if (nextSlice_.slice == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "NativeAbility ResumeAbility %d failed", targetId); + return; } - if (!PageTransitionMgr::GetInstance().IsTransAnimNeeded()) { ResumeSliceWithJS(); } else { - PageTransitionMgr::GetInstance().SaveTargetSource(curSlice_.slice->GetSliceContainer()); + PageTransitionMgr::GetInstance().SaveTargetSource(nextSlice_.slice->GetSliceContainer()); PageTransitionMgr::GetInstance().StartTransAnim(std::bind(&NativeAbility::ResumeSliceWithJS, this)); } } void NativeAbility::OnActive(const Want &want) { - uint16_t targetSliceId = gSliceInvalid; - if (targetSliceIdFromJS_ != gSliceInvalid) { - targetSliceId = targetSliceIdFromJS_; - targetSliceIdFromJS_ = gSliceInvalid; - } else if (GetPreSliceId() != gSliceInvalid) { - targetSliceId = GetPreSliceId(); - } else if (GetCurSliceId() != gSliceInvalid) { - targetSliceId = GetCurSliceId(); + uint32_t targetId = gSliceInvalid; + if (targetIdFromJS_ != gSliceInvalid) { + targetId = targetIdFromJS_; + targetIdFromJS_ = gSliceInvalid; + } else if (GetPreTargetId() != gSliceInvalid) { + targetId = GetPreTargetId(); // for forcestop or ternimate js + } else if (GetCurTargetId() != gSliceInvalid) { + targetId = GetCurTargetId(); } - targetSliceId = (targetSliceId == gSliceInvalid) ? defaultSliceId_ : targetSliceId; + targetId = (targetId == gSliceInvalid) ? defaultTargetId_ : targetId; #ifdef JS_ENABLE if ((GetState() == STATE_ACTIVE)) { @@ -117,7 +120,7 @@ void NativeAbility::OnActive(const Want &want) #endif WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "NativeAbility OnActive"); GraphicService::GetInstance()->PostGraphicEvent(std::bind(&NativeAbility::ResumeAbility, this, - targetSliceId, gSliceDefaultPriority)); + targetId)); } void NativeAbility::PauseAbility() @@ -153,6 +156,9 @@ void NativeAbility::StopAbility() !PageTransitionMgr::GetInstance().IsCurrentSnapshotEnabled()) { StopSlice(); } + if (allSlices_.Size() > 0 && allSlices_[allSlices_.Size() - 1] == VIEW_AOD) { + allSlices_.PopBack(); + } allSlices_.PushBack(gSliceInvalid); nativeAbilityState_ = STATE_UNINITIALIZED; #ifdef JS_ENABLE diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/transition/BackToHexagonsTransition.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/transition/BackToHexagonsTransition.cpp index afe3c799a..da9c42185 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/src/transition/BackToHexagonsTransition.cpp +++ b/code/sdk/application/wearable/nativeabilityfwk/src/transition/BackToHexagonsTransition.cpp @@ -9,7 +9,7 @@ #include "TransitionManager.h" #include "NativeAbility.h" #include "components/root_view.h" -#include "AppItemView.h" +#include "applist/AppItemView.h" #include "hal_tick.h" #include "wearable_log.h" #ifdef JS_ENABLE diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/transition/BackToWaterfallTransition.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/transition/BackToWaterfallTransition.cpp index 18331afd7..a5bb73077 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/src/transition/BackToWaterfallTransition.cpp +++ b/code/sdk/application/wearable/nativeabilityfwk/src/transition/BackToWaterfallTransition.cpp @@ -9,7 +9,7 @@ #include "TransitionManager.h" #include "NativeAbility.h" #include "components/root_view.h" -#include "AppItemView.h" +#include "applist/AppItemView.h" #include "hal_tick.h" #include "wearable_log.h" #ifdef JS_ENABLE @@ -47,6 +47,12 @@ void BackToWaterfallTransition::OnTransitionStart(UIImageView* current, UIViewGr focusView_ = itemView; break; } +#else + if (itemView->GetViewId() == sliceId) { + focusIndex_ = itemView->GetViewIndex(); + focusView_ = itemView; + break; + } #endif childView = childView->GetNextSibling(); } diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index 852d5a3c7..779b0cc29 100644 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -7,54 +7,12 @@ set(UI_SAMPLE_ROOT ${ROOT_DIR}/middleware/services/gui/uikit/sample/uitest) set(PUBLIC_HEADER ${NativeApp}/nativelauncher/include - ${NativeApp}/nativeui/screennotify/include - ${NativeApp}/nativeui/bluetooth/include + ${NativeApp}/nativeui/include ) set(PRIVATE_HEADER ${NativeApp}/nativeui/ - ${NativeApp}/nativeui/main/include - ${NativeApp}/nativeui/clock/include - ${NativeApp}/nativeui/bloodoxygen/include - ${NativeApp}/nativeui/bluetooth/include - ${NativeApp}/nativeui/indoorwalk/include - ${NativeApp}/nativeui/rebootdevice/include - ${NativeApp}/nativeui/activity/include - ${NativeApp}/nativeui/heartrate/include - ${NativeApp}/nativeui/callerlog/include - ${NativeApp}/nativeui/makephone/include - ${NativeApp}/nativeui/rtcservice/include - ${NativeApp}/nativeui/compass/include - ${NativeApp}/nativeui/connectnewphone/include - ${NativeApp}/nativeui/alarmclockmanage/include - ${NativeApp}/nativeui/alarmclocktimerconfig/include - ${NativeApp}/nativeui/alarm/include - ${NativeApp}/nativeui/temperature/include - ${NativeApp}/nativeui/offlinevoice/include - ${NativeApp}/nativeui/settings/include - ${NativeApp}/nativeui/set_desktop/include - ${NativeApp}/nativeui/set_card/include - ${NativeApp}/nativeui/add_card/include - ${NativeApp}/nativeui/set_dial/include - ${NativeApp}/nativeui/set_dial_style/include - ${NativeApp}/nativeui/key/include - ${NativeApp}/nativeui/player/include - ${NativeApp}/nativeui/applist/include - ${NativeApp}/nativeui/phoneservice/include - ${NativeApp}/nativeui/screensetting/include - ${NativeApp}/nativeui/uiservice/include - ${NativeApp}/nativeui/uisample/include ${NativeApp}/nativeui/uisample/uitest/framework/include - ${NativeApp}/nativeui/aod_view/include - - ${NativeApp}/nativeui/alipay/include - ${NativeApp}/nativeui/alipay/include/AlipayList - - ${NativeApp}/nativeui/alipay/include/AlipayTrans - ${NativeApp}/nativeui/restoredefaults/include - - ${NativeApp}/nativeui/videocard/include - ${UI_SAMPLE_ROOT}/components ${NativeApp}/../service/smart_voice/smart_voice_service/interfaces/innerkits/native_c/include ${NativeApp}/../service/smart_voice/voice_engine_hal/interfaces/innerkits/native_c/include @@ -79,14 +37,15 @@ set(PRIVATE_HEADER ${ROOT_DIR}/include/middleware/services/bts/common ${ROOT_DIR}/include/middleware/services/bts/ble ${ROOT_DIR}/include/middleware/services/bts/br + ${ROOT_DIR}/middleware/chips/brandy/nv/ ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ${ROOT_DIR}/open_source/openharmony/foundation/distributedschedule/samgr_lite/interfaces/kits/samgr - ${NativeApp}/nativeui/main/include/dial ${ROOT_DIR}/middleware/services/media/foundation/sample/wrapper ${ROOT_DIR}/application/wearable/service/msg_center/include ${ROOT_DIR}/application/wearable/nativeabilityfwk/include + ${ROOT_DIR}/application/wearable/service/device_msg ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audio_player/interfaces/kits ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audiomanager/interfaces/kits/audiomanager ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audiomanager/interfaces/kits/audiocommon @@ -98,6 +57,12 @@ set(PRIVATE_HEADER ${UIKIT_ROOT_DIR}/proprietary/src/ui/innerkits ${ROOT_DIR}/application/wearable/service/dial_market ${ROOT_DIR}/open_source/openharmony/third_party/cJSON + ${ROOT_DIR}/middleware/utils/dfx/diag/ + ${ROOT_DIR}/middleware/utils/dfx/diag/diag_cmd_router/include + ${ROOT_DIR}/open_source/openharmony/hiviewdfx/hilog/lite/interfaces/native/kits/hilog_lite + ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/animator + ${ROOTDIR}/open_source/flatbuffers/include + ${ROOT_DIR}/open_source/openharmony/third_party/lwip/lwip_adapter/lwip_driver_adapter ) file(GLOB_RECURSE SOURCES "${NativeApp}/nativeui/*.cpp") @@ -105,6 +70,8 @@ set(SOURCES ${SOURCES} ${NativeApp}/nativelauncher/src/NativeLauncher.cpp ${NativeApp}/nativelauncher/src/NativeRegisterManager.cpp + ${NativeApp}/nativelauncher/src/UICardPageFactory.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_lottie/ui_test_lottie.cpp ${UI_SAMPLE_ROOT}/components/ui_test_tiger/tiger_view.cpp ${UI_SAMPLE_ROOT}/components/ui_test_tiger/ui_test_tiger.cpp ${UI_SAMPLE_ROOT}/components/ui_test_running_ball/ui_test_running_ball.cpp @@ -215,9 +182,14 @@ set(COMPONENT_NAME "uikit_fwk") set(UIKIT_NATIVE_FWK ${ROOT_DIR}/application/wearable/nativeabilityfwk) set(UIKIT_NATIVE_DIAL ${NativeApp}/nativeui/main) set(COMPONENT_SRC + ${UIKIT_NATIVE_FWK}/src/View.cpp + ${UIKIT_NATIVE_FWK}/src/SlicePage.cpp ${UIKIT_NATIVE_FWK}/src/BackDragListener.cpp ${UIKIT_NATIVE_FWK}/src/PageTransitionMgr.cpp ${UIKIT_NATIVE_FWK}/src/TransitionManager.cpp + ${UIKIT_NATIVE_FWK}/src/RecentManager.cpp + ${UIKIT_NATIVE_FWK}/src/SlicePageManager.cpp + ${UIKIT_NATIVE_FWK}/src/SlicePageFactory.cpp ${UIKIT_NATIVE_FWK}/src/TransitionRecord.cpp ${UIKIT_NATIVE_DIAL}/src/dial/parser/DialBinParser.cpp ${UIKIT_NATIVE_DIAL}/src/dial/parser/DialBinParserManager.cpp @@ -244,13 +216,13 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/surface/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits ${ROOT_DIR}/middleware/services/gui/uikit/ui/frameworks - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/applist/include/ ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/format/interfaces/include ${UIKIT_NATIVE_DIAL}/include/dial ${ROOT_DIR}/middleware/services/media/foundation/sample/wrapper ${ROOT_DIR}/middleware/services/media/foundation/player/interfaces/kits ${UIKIT_ROOT_DIR}/proprietary/src/ui/innerkits + ${ROOT_DIR}/open_source/openharmony/base/security/appverify/include ) set(PRIVATE_DEFINES diff --git a/code/sdk/application/wearable/nativeapp/brandy-auto-ota-cli/libuikit_fwk.a b/code/sdk/application/wearable/nativeapp/brandy-auto-ota-cli/libuikit_fwk.a index f8834ae85..eede3b370 100644 Binary files a/code/sdk/application/wearable/nativeapp/brandy-auto-ota-cli/libuikit_fwk.a and b/code/sdk/application/wearable/nativeapp/brandy-auto-ota-cli/libuikit_fwk.a differ diff --git a/code/sdk/application/wearable/nativeapp/brandy-auto-ota-ser/libuikit_fwk.a b/code/sdk/application/wearable/nativeapp/brandy-auto-ota-ser/libuikit_fwk.a index 9c513d8e2..40a9458c8 100644 Binary files a/code/sdk/application/wearable/nativeapp/brandy-auto-ota-ser/libuikit_fwk.a and b/code/sdk/application/wearable/nativeapp/brandy-auto-ota-ser/libuikit_fwk.a differ diff --git a/code/sdk/application/wearable/nativeapp/brandy-native-js/libuikit_fwk.a b/code/sdk/application/wearable/nativeapp/brandy-native-js/libuikit_fwk.a index b1ab9d2d0..e3ce469ad 100644 Binary files a/code/sdk/application/wearable/nativeapp/brandy-native-js/libuikit_fwk.a and b/code/sdk/application/wearable/nativeapp/brandy-native-js/libuikit_fwk.a differ diff --git a/code/sdk/application/wearable/nativeapp/brandy-xts/libuikit_fwk.a b/code/sdk/application/wearable/nativeapp/brandy-xts/libuikit_fwk.a index 7864f090a..337b034d5 100644 Binary files a/code/sdk/application/wearable/nativeapp/brandy-xts/libuikit_fwk.a and b/code/sdk/application/wearable/nativeapp/brandy-xts/libuikit_fwk.a differ diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h index 9774ce9e5..6c6b38fcb 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h @@ -45,16 +45,32 @@ typedef enum : uint16_t { VIEW_INDOORWALK, VIEW_REBOOT, VIEW_UISAMPLE, + VIEW_MAIN_BREATHEASE, + VIEW_FLASHLIGHT, // 手电筒; + VIEW_STOPWATCH, // 秒表; + VIEW_WEATHER, // 天气 + VIEW_TIMER, // 计时器 + VIEW_BLOOD, // 血氧 + VIEW_CAMERA, // 相机 + VIEW_FIND_PHONE, // 寻找手机 + VIEW_DATE, // 日期 + VIEW_QRCODE_CONN, // 二维码连接; + VIEW_SPORTS, + VIEW_SLEEPING, + VIEW_TRAINING, + VIEW_EMPTY, #ifdef SUPPORT_ALIPAY_SEC VIEW_MAIN_ALIPAY, #endif VIEW_SET_DESKTOP, + VIEW_SET_OTA, VIEW_SET_CARD, VIEW_ADD_CARD, VIEW_SET_DIAL, VIEW_SET_DIAL_STYLE, VIEW_AOD, VIEW_RESTORE_DEFAULTS, + VIEW_RECENT_APP, VIEW_MAX_INTER_ARRY_APP = 0x7FFF, // 在此之前添加内部数组native应用ID. VIEW_MAX_INTER_APP = 0xFFFD, // 在此之前添加内部静态注册native应用ID,æ­¤ID在NativeRegisterType.h里单独管理 VIEW_EXTERN_APP = 0xFFFE, // 三方应用 diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h index 1fc741df7..cfcecf0de 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h @@ -23,8 +23,6 @@ public: static NativeLauncher &GetInstance(void); void InitNativeLauncher(void); private: - void InitAllNativeSlices(void); - NativeLauncher(); NativeLauncher(const NativeLauncher &); NativeLauncher &operator=(const NativeLauncher &); diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeRegisterManager.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeRegisterManager.h index b8d7f198d..2079112a1 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeRegisterManager.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeRegisterManager.h @@ -13,7 +13,7 @@ #include "NativeRegisterType.h" #include "SliceProxy.h" #include "AbilitySliceProxy.h" -#include "ApplistModel.h" +#include "applist/ApplistModel.h" #include "NativeAbility.h" #include "wearable_log.h" #include "UiConfig.h" @@ -27,11 +27,6 @@ public: virtual void InitSlice() {}; }; -struct NativeMap { - NativeRegisterType type; - NativeRegisterCallback* native; -}; - struct SliceMap { uint16_t id; SliceProxy* slice; @@ -45,31 +40,21 @@ public: return instance; } void InitAllNativesSlices(); - Graphic::Vector& GetNatives(); List& GetNativeAppLists(); - void RegisterNative(const AppItem &nativeAppList, NativeRegisterCallback* native); void RegisterSlice(const uint16_t id, SliceProxy* slice); void RegisterMenu(const uint16_t id, const char *icon, const char *iconHexagon, const char *label); + void RegisterMenu(const AppItem &item); bool IsSliceIdExist(AppViewId id); private: NativeRegisterManager() {}; - ~NativeRegisterManager(); + ~NativeRegisterManager() {}; NativeRegisterManager(const NativeRegisterManager&) = delete; NativeRegisterManager &operator=(const NativeRegisterManager&) = delete; - Graphic::Vector natives_; Graphic::Vector slices_; List nativeAppLists_; }; -class NativeRegister { -public: - NativeRegister(const AppItem &nativeAppList, NativeRegisterCallback* native) - { - NativeRegisterManager::GetInstance().RegisterNative(nativeAppList, native); - } -}; - class SliceRegister { public: SliceRegister(const uint16_t id, SliceProxy* sliceProxy) @@ -82,14 +67,26 @@ public: NativeRegisterManager::GetInstance().RegisterSlice(id, sliceProxy); NativeRegisterManager::GetInstance().RegisterMenu(id, icon, iconHexagon, label); } + SliceRegister(const AppItem &item, SliceProxy* sliceProxy) + { + NativeRegisterManager::GetInstance().RegisterSlice(item.id, sliceProxy); + NativeRegisterManager::GetInstance().RegisterMenu(item); + } }; } // namespace OHOS -#define REGIST_NATIVE(nativeAppList, func) \ - const static OHOS::NativeRegister (STATIC_VAR)(nativeAppList, new func()) #define REGIST_SLICE(id, V, P) \ const static OHOS::SliceRegister (STATIC_VAR)(static_cast(id), new AbilitySliceProxy()) #define REGIST_MENU(id, V, P, icon, iconHexagon, label) \ const static OHOS::SliceRegister (STATIC_VAR)(static_cast(id), new AbilitySliceProxy(), \ icon, iconHexagon, label) +/* + * 目前支持两种模式的注册,如果需要扩展,请自行扩展AppItem的构造方法 + * 支持多语言注册以及多图标打包功能的注册示例:REGIST_MENU_EXT((AppItem{VIEW_OFFLINEVOICE, VOICE_RES_ID, + * VOICE_HEXAGON_ID, RES_PATH, HEXAGON_PATH, VOICE_LANGUAGE_ID, nullptr}), MainVocassistView, VocassistPresenter); + * 不支持多语言,一个图标使用一个文件的注册示例:REGIST_MENU_EXT((AppItem{VIEW_OFFLINEVOICE, PNG_APPLIST_VOCASSIST_IMAGE, + * PNG_APPLIST_DEFAULT_IMG, "语音助手", nullptr}), MainVocassistView, VocassistPresenter); + */ +#define REGIST_MENU_EXT(item, V, P) \ + const static OHOS::SliceRegister (STATIC_VAR)(item, new AbilitySliceProxy()) #endif // NATIVE_MANAGER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/UICardPageFactory.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UICardPageFactory.h new file mode 100644 index 000000000..761e137c7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UICardPageFactory.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: UICardPageFactory + * Author: + * Create: 2025-06 + */ + +#ifndef UI_CARD_PAGE_FACTORY_H +#define UI_CARD_PAGE_FACTORY_H + +#include +#include "components/ui_card_page.h" +#include "UiConfig.h" + +namespace OHOS { +class UICardPageProxyInterface; +class UICardPageFactory { +public: + static UICardPageFactory& GetInstance() + { + static UICardPageFactory instance; + return instance; + } + void RegisterWatchDial(const uint16_t mode, const uint16_t id, UICardPageProxyInterface* uiCardPage); + UICardPage* CreateWatchDial(uint16_t mode, uint16_t id); + +private: + UICardPageFactory() {}; + ~UICardPageFactory() {}; + UICardPageFactory(const UICardPageFactory&) = delete; + UICardPageFactory &operator=(const UICardPageFactory&) = delete; + std::unordered_map watchDials_[static_cast(DIAL_DISPLAY_MODE_MAX)]; +}; + +class WatchDialRegister { +public: + WatchDialRegister(const uint16_t mode, const uint16_t id, UICardPageProxyInterface* uiCardPage) + { + UICardPageFactory::GetInstance().RegisterWatchDial(mode, id, uiCardPage); + } +}; + +class UICardPageProxyInterface { +public: + virtual UICardPage* CreateUICardPage() = 0; + UICardPageProxyInterface() = default; + virtual ~UICardPageProxyInterface() = default; + UICardPageProxyInterface(const UICardPageProxyInterface&) = delete; + UICardPageProxyInterface& operator=(const UICardPageProxyInterface&) = delete; + UICardPageProxyInterface(UICardPageProxyInterface&&) = delete; + UICardPageProxyInterface& operator=(UICardPageProxyInterface&&) = delete; +}; + +template +class WatchDialProxy : public UICardPageProxyInterface { +public: + UICardPage* CreateUICardPage() override + { + U* u = new U(); + UICardPage* page = dynamic_cast(u); + if (page == nullptr) { + delete u; + } + return page; + } +}; +} // namespace OHOS + +#define REGIST_WATCH_DIAL(mode, id, U) \ + const static OHOS::WatchDialRegister (STATIC_VAR)(static_cast(mode), static_cast(id), \ + new WatchDialProxy()) + +#endif // UI_CARD_PAGE_FACTORY_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h index ffecde66d..b04a143ac 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h @@ -31,6 +31,12 @@ namespace OHOS { DIAL_MAX, } DialId; + typedef enum { + DIAL_DISPLAY_MODE_MAIN = 0, + DIAL_DISPLAY_MODE_AOD, + DIAL_DISPLAY_MODE_MAX, + } DialDispayMode; + #ifndef UNUSED #define UNUSED(x) ((void)(x)) #endif @@ -379,6 +385,25 @@ namespace OHOS { static constexpr const char *PNG_PREVIEW_CARD_VIDEO = APP_RES_PATH"/noaudio_05.bin"; static constexpr const char *PNG_SET_DIAL_CLOCK = APP_RES_PATH"/DIAL_CLOCK.bin"; + + static constexpr const char *PNG_APPLIST_STOPWATCH_LOGO = APP_RES_PATH"/STOPWATCH_LOGO.bin"; + static constexpr const char *PNG_APPLIST_STOPWATCH_IMAGE = APP_RES_PATH"/STOPWATCH.bin"; + static constexpr const char *WEATHER_IMAGE = APP_RES_PATH"/WEATHER.bin"; + static constexpr const char *WEATHER_MAIN_ICON = APP_RES_PATH"/WEATHER_LOGO.bin"; + static constexpr const char *TIMER_IMAGE = APP_RES_PATH"/TIMER.bin"; + static constexpr const char *TIMER_MAIN_ICON = APP_RES_PATH"/TIMER_ICON.bin"; + static constexpr const char *DATE_IMAGE = APP_RES_PATH"/DATE.bin"; + static constexpr const char *DATE_MAIN_ICON = APP_RES_PATH"/DATE_LOGO.bin"; + static constexpr const char *FLASHLIGHT_IMAGE = APP_RES_PATH"/FLASHLIGHT.bin"; + static constexpr const char *FLASHLIGHT_MAIN_ICON = APP_RES_PATH"/FLASHLIGHT_LOGO.bin"; + static constexpr const char *SLEEP_IMAGE = APP_RES_PATH"/SLEEP.bin"; + static constexpr const char *SLEEP_ICON = APP_RES_PATH"/SLEEP_ICON.bin"; + static constexpr const char *BREATH_IMAGE = APP_RES_PATH"/BREATH.bin"; + static constexpr const char *BREATH_MAIN_ICON = APP_RES_PATH"/BREATH_ICON.bin"; + static constexpr const char *FINDPHONE_IMAGE = APP_RES_PATH"/FINDPHONE.bin"; + static constexpr const char *FINDPHONE_MAIN_ICON = APP_RES_PATH"/FINDPHONE_LOGO.bin"; + static constexpr const char *CAMERA_IMAGE = APP_RES_PATH"/CAMERA.bin"; + static constexpr const char *CAMERA_MAIN_ICON = APP_RES_PATH"/CAMERA_ICON.bin"; } #endif // UI_CONFIG_H diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_breath.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_breath.h new file mode 100644 index 000000000..ca668341c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_breath.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIBreathResource + * Create: 2025-06-05 + */ +#ifndef UI_RESOURCE_BREATH_IMAGE_H +#define UI_RESOURCE_BREATH_IMAGE_H +#include +namespace OHOS { + static const int IMAGE_CONVERTER_TOOL_BREATH001 = 0x100001; + static const int IMAGE_CONVERTER_TOOL_BREATH002 = 0x100002; + static const int IMAGE_CONVERTER_TOOL_BREATH003 = 0x100003; + static const int IMAGE_CONVERTER_TOOL_BREATH004 = 0x100004; + static const int IMAGE_CONVERTER_TOOL_BREATH005 = 0x100005; + static const int IMAGE_CONVERTER_TOOL_BREATH006 = 0x100006; + static const int IMAGE_CONVERTER_TOOL_BREATH007 = 0x100007; + static const int IMAGE_CONVERTER_TOOL_BREATH008 = 0x100008; + static const int IMAGE_CONVERTER_TOOL_BREATH009 = 0x100009; + static const int IMAGE_CONVERTER_TOOL_BREATH010 = 0x10000a; + static const int IMAGE_CONVERTER_TOOL_BREATH011 = 0x10000b; + static const int IMAGE_CONVERTER_TOOL_BREATH012 = 0x10000c; + static const int IMAGE_CONVERTER_TOOL_BREATH013 = 0x10000d; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE001 = 0x10000e; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE002 = 0x10000f; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE003 = 0x100010; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE004 = 0x100011; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE005 = 0x100012; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE006 = 0x100013; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE007 = 0x100014; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE008 = 0x100015; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE009 = 0x100016; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE010 = 0x100017; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE011 = 0x100018; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE012 = 0x100019; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE013 = 0x10001a; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE014 = 0x10001b; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE015 = 0x10001c; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE016 = 0x10001d; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE017 = 0x10001e; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE018 = 0x10001f; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE019 = 0x100020; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE020 = 0x100021; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE021 = 0x100022; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE022 = 0x100023; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE023 = 0x100024; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE024 = 0x100025; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE025 = 0x100026; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE026 = 0x100027; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE027 = 0x100028; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE028 = 0x100029; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE029 = 0x10002a; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE030 = 0x10002b; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE031 = 0x10002c; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE032 = 0x10002d; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE033 = 0x10002e; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE034 = 0x10002f; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE035 = 0x100030; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE036 = 0x100031; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE037 = 0x100032; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE038 = 0x100033; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE039 = 0x100034; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE040 = 0x100035; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE041 = 0x100036; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE042 = 0x100037; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE043 = 0x100038; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE044 = 0x100039; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE045 = 0x10003a; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE046 = 0x10003b; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE047 = 0x10003c; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE048 = 0x10003d; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE049 = 0x10003e; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE050 = 0x10003f; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE051 = 0x100040; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE052 = 0x100041; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE053 = 0x100042; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE054 = 0x100043; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE055 = 0x100044; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE056 = 0x100045; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE057 = 0x100046; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE058 = 0x100047; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE059 = 0x100048; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE060 = 0x100049; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE061 = 0x10004a; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE062 = 0x10004b; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE063 = 0x10004c; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE064 = 0x10004d; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE065 = 0x10004e; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE066 = 0x10004f; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE067 = 0x100050; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE068 = 0x100051; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE069 = 0x100052; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE070 = 0x100053; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE071 = 0x100054; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE072 = 0x100055; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE073 = 0x100056; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE074 = 0x100057; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE075 = 0x100058; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE076 = 0x100059; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE077 = 0x10005a; + static const int IMAGE_CONVERTER_TOOL_INOREX_HALE078 = 0x10005b; +} // OHOS +#endif // UI_RESOURCE_BREATH_IMAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_camera.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_camera.h new file mode 100644 index 000000000..022ddfca0 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_camera.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UICameraResource + * Create: 2025-06-05 + */ +#ifndef UI_RESOURCE_CAMERA_H +#define UI_RESOURCE_CAMERA_H +#include +namespace OHOS { + static const int IMAGE_CONVERTER_TOOL_CAMERA_1 = 0x100001; + static const int IMAGE_CONVERTER_TOOL_CAMERA_2 = 0x100002; + static const int IMAGE_CONVERTER_TOOL_CAMERA_3 = 0x100003; + static const int IMAGE_CONVERTER_TOOL_CAMERA_4 = 0x100004; + static const int IMAGE_CONVERTER_TOOL_CAMERA_5 = 0x100005; + +} // OHOS +#endif // UI_RESOURCE_CAMERA_H diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_date.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_date.h new file mode 100644 index 000000000..0bccb8b0e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_date.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIWeatherResource + * Create: 2025-06-10 + */ +#ifndef UI_RESOURCE_DATE_H +#define UI_RESOURCE_DATE_H +#include +namespace OHOS { + static const int DIR_MASK = 0xfff00000; + static const int PNG_MASK = 0x000fffff; + static const int IMAGE_CONVERTER_TOOL_DATE1 = 0x100001; + static const int IMAGE_CONVERTER_TOOL_DATE2 = 0x100002; + static const int IMAGE_CONVERTER_TOOL_DATE3 = 0x100003; + static const int IMAGE_CONVERTER_TOOL_DATE4 = 0x100004; + static const int IMAGE_CONVERTER_TOOL_DATE5 = 0x100005; + static const int IMAGE_CONVERTER_TOOL_DATE6 = 0x100006; + static const int IMAGE_CONVERTER_TOOL_DATE7 = 0x100007; + static const int IMAGE_CONVERTER_TOOL_DATE8 = 0x100008; +} // OHOS +#endif // UI_RESOURCE_DATE_H diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_findPhone.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_findPhone.h new file mode 100644 index 000000000..9a51cdf10 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_findPhone.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIFindPhoneResource + * Create: 2025-2-13 + */ +#ifndef UI_RESOURCE_FINDPHONE_H +#define UI_RESOURCE_FINDPHONE_H +#include +namespace OHOS { + static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_1 = 0x100001; + static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_2 = 0x100002; + static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_3 = 0x100003; + static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4 = 0x100004; + static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5 = 0x100005; + static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_6 = 0x100006; + static const int IMAGE_CONVERTER_TOOL_CONNECT_PHONE_7 = 0x100007; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE001 = 0x100008; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE002 = 0x100009; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE003 = 0x10000a; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE004 = 0x10000b; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE005 = 0x10000c; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE006 = 0x10000d; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE007 = 0x10000e; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE008 = 0x10000f; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE009 = 0x100010; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE010 = 0x100011; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE011 = 0x100012; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE012 = 0x100013; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE013 = 0x100014; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE014 = 0x100015; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE015 = 0x100016; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE016 = 0x100017; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE017 = 0x100018; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE018 = 0x100019; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE019 = 0x10001a; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE020 = 0x10001b; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE021 = 0x10001c; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE022 = 0x10001d; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE023 = 0x10001e; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE024 = 0x10001f; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE025 = 0x100020; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE026 = 0x100021; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE027 = 0x100022; + static const int IMAGE_CONVERTER_TOOL_FINDPHONE028 = 0x100023; +} // OHOS +#endif // UI_RESOURCE_FINDPHONE_H diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_sleep.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_sleep.h new file mode 100644 index 000000000..c5d369d71 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_sleep.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UISleepResource + * Create: 2025-06-05 + */ +#ifndef UI_RESOURCE_SLEEP_H +#define UI_RESOURCE_SLEEP_H +#include +namespace OHOS { + static const int IMAGE_CONVERTER_TOOL_BACKGROUND = 0x100001; + static const int IMAGE_CONVERTER_TOOL_BLACK_BG = 0x100002; + static const int IMAGE_CONVERTER_TOOL_BLUE_CIR = 0x100003; + static const int IMAGE_CONVERTER_TOOL_GREEN_CIR = 0x100004; + static const int IMAGE_CONVERTER_TOOL_NORECORD_SLEEP = 0x100005; + static const int IMAGE_CONVERTER_TOOL_ORANGE_CIR = 0x100006; + static const int IMAGE_CONVERTER_TOOL_RECORD_BG = 0x100007; + static const int IMAGE_CONVERTER_TOOL_RECORD_SLEEP = 0x100008; + static const int IMAGE_CONVERTER_TOOL_RED_CIR = 0x100009; + static const int IMAGE_CONVERTER_TOOL_SELECTEDTIME = 0x10000a; + static const int IMAGE_CONVERTER_TOOL_SELECTTIME = 0x10000b; + static const int IMAGE_CONVERTER_TOOL_SETTIMEBTN = 0x10000c; + static const int IMAGE_CONVERTER_TOOL_SETTING = 0x10000d; + static const int IMAGE_CONVERTER_TOOL_START_GRAY = 0x10000e; + static const int IMAGE_CONVERTER_TOOL_STAR_GRAY = 0x10000f; + static const int IMAGE_CONVERTER_TOOL_STAR_YELLOW = 0x100010; + static const int IMAGE_CONVERTER_TOOL_TIPS = 0x100011; +} // OHOS +#endif // UI_RESOURCE_SLEEP_H diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_string.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_string.h new file mode 100644 index 000000000..d7ca185f6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_string.h @@ -0,0 +1,23 @@ +/* +* Copyright (c) xxxxxxxx Technologies Co., Ltd. 2021-2021. All rights reserved. +* Description: language +* Author: Graphic develop team +* Create: 2021-07-06 +*/ + +#ifndef UI_RESOURCE_STRING_H +#define UI_RESOURCE_STRING_H +#include +namespace OHOS { +enum UIResourceTextId : uint16_t { + STR_LANGUAGE = 0, + STR_MAX_ID = 1, +}; // UIResourceTextId + +enum FontLanguageId : uint8_t { + LANGUAGE_ID_ZH, + LANGUAGE_ID_EN, + LANGUAGE_ID_MAX +}; // UITextLanguageTextId +} +#endif /* UI_RESOURCE_STRING_H */ diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_timer.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_timer.h new file mode 100644 index 000000000..b9a462900 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_timer.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UITimerResource + * Create: 2025-06-05 + */ +#ifndef UI_RESOURCE_TIMER_H +#define UI_RESOURCE_TIMER_H +#include +namespace OHOS { + static const int IMAGE_CONVERTER_TOOL_BG_CIR = 0x100001; + static const int IMAGE_CONVERTER_TOOL_TIMER_1 = 0x100002; + static const int IMAGE_CONVERTER_TOOL_TIMER_15 = 0x100003; + static const int IMAGE_CONVERTER_TOOL_TIMER_3 = 0x100004; + static const int IMAGE_CONVERTER_TOOL_TIMER_30 = 0x100005; + static const int IMAGE_CONVERTER_TOOL_TIMER_BEGIN_GRAY = 0x100006; + static const int IMAGE_CONVERTER_TOOL_TIMER_BEGIN_ORANGE = 0x100007; + static const int IMAGE_CONVERTER_TOOL_TIMER_BG = 0x100008; + static const int IMAGE_CONVERTER_TOOL_TIMER_EXIT = 0x100009; + static const int IMAGE_CONVERTER_TOOL_TIMER_PAUSE = 0x10000a; + static const int IMAGE_CONVERTER_TOOL_TIMER_PAUSE_ORANGE = 0x10000b; + static const int IMAGE_CONVERTER_TOOL_TIMER_PBG = 0x10000c; + static const int IMAGE_CONVERTER_TOOL_TIMER_PLAY = 0x10000d; + static const int IMAGE_CONVERTER_TOOL_TIMER_POINTER = 0x10000e; + static const int IMAGE_CONVERTER_TOOL_TIMER_RESTART = 0x10000f; + static const int IMAGE_CONVERTER_TOOL_TIMER_USER = 0x100010; +} // OHOS +#endif // UI_RESOURCE_TIMER_H diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_weather.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_weather.h new file mode 100644 index 000000000..874ba3f93 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_weather.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: UIWeatherResource + * Create: 2025-06-05 + */ +#ifndef UI_RESOURCE_WEATHER_IMAGE_H +#define UI_RESOURCE_WEATHER_IMAGE_H +#include +namespace OHOS { +static const int IMAGE_CONVERTER_TOOL_WEATHER00 = 0x100001; +static const int IMAGE_CONVERTER_TOOL_WEATHER01 = 0x100002; +static const int IMAGE_CONVERTER_TOOL_WEATHER02 = 0x100003; +static const int IMAGE_CONVERTER_TOOL_WEATHER03 = 0x100004; +static const int IMAGE_CONVERTER_TOOL_WEATHER04 = 0x100005; +static const int IMAGE_CONVERTER_TOOL_WEATHER05 = 0x100006; +static const int IMAGE_CONVERTER_TOOL_WEATHER06 = 0x100007; +static const int IMAGE_CONVERTER_TOOL_WEATHER07 = 0x100008; +static const int IMAGE_CONVERTER_TOOL_WEATHER08 = 0x100009; +static const int IMAGE_CONVERTER_TOOL_WEATHER09 = 0x10000a; +static const int IMAGE_CONVERTER_TOOL_WEATHER10 = 0x10000b; +static const int IMAGE_CONVERTER_TOOL_WEATHER11 = 0x10000c; +static const int IMAGE_CONVERTER_TOOL_WEATHER12 = 0x10000d; +static const int IMAGE_CONVERTER_TOOL_WEATHER13 = 0x10000e; +static const int IMAGE_CONVERTER_TOOL_WEATHER14 = 0x10000f; +static const int IMAGE_CONVERTER_TOOL_WEATHER15 = 0x100010; +static const int IMAGE_CONVERTER_TOOL_WEATHER16 = 0x100011; +static const int IMAGE_CONVERTER_TOOL_WEATHER17 = 0x100012; +static const int IMAGE_CONVERTER_TOOL_WEATHER18 = 0x100013; +static const int IMAGE_CONVERTER_TOOL_WEATHER19 = 0x100014; +static const int IMAGE_CONVERTER_TOOL_WEATHER20 = 0x100015; +static const int IMAGE_CONVERTER_TOOL_WEATHER21 = 0x100016; +static const int IMAGE_CONVERTER_TOOL_WEATHER22 = 0x100017; +static const int IMAGE_CONVERTER_TOOL_WEATHER23 = 0x100018; +static const int IMAGE_CONVERTER_TOOL_WEATHER24 = 0x100019; +static const int IMAGE_CONVERTER_TOOL_WEATHER25 = 0x10001a; +static const int IMAGE_CONVERTER_TOOL_WEATHER26 = 0x10001b; +static const int IMAGE_CONVERTER_TOOL_WEATHER27 = 0x10001c; +static const int IMAGE_CONVERTER_TOOL_WEATHER28 = 0x10001d; +static const int IMAGE_CONVERTER_TOOL_WEATHER29 = 0x10001e; +static const int IMAGE_CONVERTER_TOOL_WEATHER30 = 0x10001f; +static const int IMAGE_CONVERTER_TOOL_WEATHER31 = 0x100020; +static const int IMAGE_CONVERTER_TOOL_WEATHER32 = 0x100021; +static const int IMAGE_CONVERTER_TOOL_WEATHER33 = 0x100022; +static const int IMAGE_CONVERTER_TOOL_WEATHER34 = 0x100023; +static const int IMAGE_CONVERTER_TOOL_WEATHER35 = 0x100024; +static const int IMAGE_CONVERTER_TOOL_WEATHER36 = 0x100025; +static const int IMAGE_CONVERTER_TOOL_WEATHER37 = 0x100026; +static const int IMAGE_CONVERTER_TOOL_WEATHER38 = 0x100027; +static const int IMAGE_CONVERTER_TOOL_WEATHER39 = 0x100028; +static const int IMAGE_CONVERTER_TOOL_WEATHER40 = 0x100029; +static const int IMAGE_CONVERTER_TOOL_WEATHER41 = 0x10002a; +static const int IMAGE_CONVERTER_TOOL_WEATHER42 = 0x10002b; +static const int IMAGE_CONVERTER_TOOL_WEATHER43 = 0x10002c; +static const int IMAGE_CONVERTER_TOOL_WEATHER44 = 0x10002d; +static const int IMAGE_CONVERTER_TOOL_WEATHER45 = 0x10002e; +static const int IMAGE_CONVERTER_TOOL_WEATHER46 = 0x10002f; +static const int IMAGE_CONVERTER_TOOL_WEATHER47 = 0x100030; +static const int IMAGE_CONVERTER_TOOL_WEATHER48 = 0x100031; +static const int IMAGE_CONVERTER_TOOL_WEATHER49 = 0x100032; +static const int IMAGE_CONVERTER_TOOL_WEATHER50 = 0x100033; +static const int IMAGE_CONVERTER_TOOL_WEATHER51 = 0x100034; +static const int IMAGE_CONVERTER_TOOL_WEATHER52 = 0x100035; +static const int IMAGE_CONVERTER_TOOL_WEATHER53 = 0x100036; +static const int IMAGE_CONVERTER_TOOL_WEATHER54 = 0x100037; +static const int IMAGE_CONVERTER_TOOL_WEATHER55 = 0x100038; +static const int IMAGE_CONVERTER_TOOL_WEATHER56 = 0x100039; +static const int IMAGE_CONVERTER_TOOL_WEATHER57 = 0x10003a; +static const int IMAGE_CONVERTER_TOOL_WEATHER58 = 0x10003b; +static const int IMAGE_CONVERTER_TOOL_WEATHER59 = 0x10003c; +static const int IMAGE_CONVERTER_TOOL_WEATHER60 = 0x10003d; +static const int IMAGE_CONVERTER_TOOL_WEATHER61 = 0x10003e; +static const int IMAGE_CONVERTER_TOOL_WEATHER62 = 0x10003f; +static const int IMAGE_CONVERTER_TOOL_WEATHER63 = 0x100040; +static const int IMAGE_CONVERTER_TOOL_WEATHER64 = 0x100041; +static const int IMAGE_CONVERTER_TOOL_WEATHER65 = 0x100042; +static const int IMAGE_CONVERTER_TOOL_WEATHER66 = 0x100043; +static const int IMAGE_CONVERTER_TOOL_WEATHER67 = 0x100044; +static const int IMAGE_CONVERTER_TOOL_WEATHER68 = 0x100045; +static const int IMAGE_CONVERTER_TOOL_WEATHER69 = 0x100046; +static const int IMAGE_CONVERTER_TOOL_WEATHER70 = 0x100047; +static const int IMAGE_CONVERTER_TOOL_WEATHER71 = 0x100048; +static const int IMAGE_CONVERTER_TOOL_WEATHER72 = 0x100049; +static const int IMAGE_CONVERTER_TOOL_WEATHER73 = 0x10004a; +static const int IMAGE_CONVERTER_TOOL_WEATHER74 = 0x10004b; +static const int IMAGE_CONVERTER_TOOL_WEATHER75 = 0x10004c; +static const int IMAGE_CONVERTER_TOOL_WEATHER76 = 0x10004d; +static const int IMAGE_CONVERTER_TOOL_WEATHER77 = 0x10004e; +} // OHOS +#endif // UI_RESOURCE_IMAGE_H diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_stopwatch_resource.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_stopwatch_resource.h new file mode 100644 index 000000000..56019f1cd --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_stopwatch_resource.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: UIStopWatchResource + * Create: 2025-06-05 + */ + +#ifndef UI_STOPWATCH_RESOURCE_H +#define UI_STOPWATCH_RESOURCE_H + +#include + +namespace OHOS { +static const int IMAGE_STOPWATCH_STOPWATCH01 = 0x100001; +static const int IMAGE_STOPWATCH_STOPWATCH02 = 0x100002; +static const int IMAGE_STOPWATCH_STOPWATCH04 = 0x100003; +static const int IMAGE_STOPWATCH_STOPWATCH06 = 0x100004; +static const int IMAGE_STOPWATCH_STOPWATCH08 = 0x100005; +static const int IMAGE_STOPWATCH_STOPWATCH10 = 0x100006; +static const int IMAGE_STOPWATCH_STOPWATCH12 = 0x100007; +static const int IMAGE_STOPWATCH_STOPWATCH14 = 0x100008; +static const int IMAGE_STOPWATCH_STOPWATCH16 = 0x100009; +static const int IMAGE_STOPWATCH_STOPWATCH19 = 0x10000a; +static const int IMAGE_STOPWATCH_STOPWATCH20 = 0x10000b; +} // OHOS +#endif // UI_STOPWATCH_RESOURCE_H diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp index 4f3804675..be0ab5890 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -18,20 +18,23 @@ #include "SliceProxy.h" #include "AbilitySliceProxy.h" #include "wearable_log.h" -#include "CallerLogModel.h" -#include "ActivityModel.h" -#include "HeartModel.h" -#include "PlayersModel.h" -#include "HealthModel.h" -#include "VocassistModel.h" -#include "ScreenModels.h" -#include "BluetoothHeadsetEvent.h" +#include "callerlog/CallerLogModel.h" +#include "activity/ActivityModel.h" +#include "heartrate/HeartModel.h" +#include "player/PlayersModel.h" +#include "main/HealthModel.h" +#include "sports/SportsModel.h" +#include "offlinevoice/VocassistModel.h" +#include "screensetting/ScreenModels.h" +#include "bluetooth/BluetoothHeadsetEvent.h" #include "graphic_hardware_config.h" #include "graphic_service.h" #include "common/graphic_startup.h" #ifdef JS_ENABLE #include "product_adapter.h" #endif +#include "RecentManager.h" +#include "PageTransitionMgr.h" namespace OHOS { @@ -48,13 +51,15 @@ void NativeLauncher::InitNativeLauncher() { #ifdef JS_ENABLE ACELite::ProductAdapter::SetScreenSize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + ACELite::ProductAdapter::SetDefaultFontStyle( + DEFAULT_VECTOR_FONT_FILENAME, ACELite::ProductAdapter::GetDefaultFontSize()); #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 InitBtHeadsetEvent(); // 蓝牙ct和tg适配初始化 - InitAllNativeSlices(); + NativeRegisterManager::GetInstance().InitAllNativesSlices(); CallerLogModel::GetInstance()->InitPhoneService(); PlayersModel::GetInstance()->AudioInit(); ActivityModel::GetInstance()->Init(); @@ -62,22 +67,18 @@ void NativeLauncher::InitNativeLauncher() VocassistModel::GetInstance()->Init(); HeartModel::GetInstance()->Init(); BluetoothModel::GetInstance()->Init(); + SportsModel::GetInstance()->Init(); // 初始化默认首页 ScreenModels::GetInstance()->PreLoadAppimages(); NativeAbility::GetInstance().SetDefaultSliceId(VIEW_MAIN_SAMPLE); -} -void NativeLauncher::InitAllNativeSlices(void) -{ - Graphic::Vector& natives = NativeRegisterManager::GetInstance().GetNatives(); - for(uint16_t index =0; index < natives.Size(); index++) { - if (static_cast(natives[index].type) >= VIEW_MAX_INTER_APP) { - continue; - } - natives[index].native->InitSlice(); - } - NativeRegisterManager::GetInstance().InitAllNativesSlices(); - return; + RecentManager::GetInstance()->SetDirPath("system/recent/"); + RecentManager::GetInstance()->AddToBlackList(VIEW_AOD); + RecentManager::GetInstance()->AddToBlackList(VIEW_RECENT_APP); + RecentManager::GetInstance()->AddToBlackList(VIEW_APPLIST); + RecentManager::GetInstance()->AddToBlackList(VIEW_MAIN_SAMPLE); + RecentManager::GetInstance()->SetMaxSize(5); // 5: max number of recent apps. + PageTransitionMgr::GetInstance().SetRecentMinPeriod(1000); // 1000: min period } } diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeRegisterManager.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeRegisterManager.cpp index 6ea82ddfb..bfd2119e0 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeRegisterManager.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeRegisterManager.cpp @@ -8,15 +8,6 @@ #include "NativeRegisterManager.h" namespace OHOS { -NativeRegisterManager::~NativeRegisterManager() -{ - for(uint16_t i =0; i < natives_.Size(); i++) { - if (natives_[i].native != nullptr) { - delete natives_[i].native; - natives_[i].native = nullptr; - } - } -} void NativeRegisterManager::InitAllNativesSlices() { @@ -26,34 +17,11 @@ void NativeRegisterManager::InitAllNativesSlices() } } -Graphic::Vector& NativeRegisterManager::GetNatives() -{ - return natives_; -} - List& NativeRegisterManager::GetNativeAppLists() { return nativeAppLists_; } -void NativeRegisterManager::RegisterNative(const AppItem &nativeAppList, NativeRegisterCallback* native) -{ - if (native == nullptr) { - GRAPHIC_LOGE("native can't be nullptr"); - return; - } - for(uint16_t i = 0; i < natives_.Size(); i++) { - if (natives_[i].type == (NativeRegisterType)nativeAppList.id) { - GRAPHIC_LOGE("RegisterNative failed because type %d already registered", nativeAppList.id); - return; - } - } - GRAPHIC_LOGI("register native %d", nativeAppList.id); - NativeMap map = {(NativeRegisterType)nativeAppList.id, native}; - natives_.PushBack(map); - nativeAppLists_.PushBack(nativeAppList); -} - void NativeRegisterManager::RegisterSlice(const uint16_t id, SliceProxy* sliceProxy) { if (sliceProxy == nullptr) { @@ -72,7 +40,7 @@ void NativeRegisterManager::RegisterSlice(const uint16_t id, SliceProxy* slicePr void NativeRegisterManager::RegisterMenu(const uint16_t id, const char *icon, const char *iconHexagon, const char *label) { - AppItem item = {id, icon, icon, iconHexagon, label, nullptr}; + AppItem item = {id, icon, iconHexagon, label, nullptr}; ListNode* appNode = nativeAppLists_.Head(); while (appNode != nativeAppLists_.End()) { if (id == appNode->data_.id) { @@ -88,6 +56,23 @@ void NativeRegisterManager::RegisterMenu(const uint16_t id, const char *icon, co nativeAppLists_.PushBack(item); } +void NativeRegisterManager::RegisterMenu(const AppItem &item) +{ + ListNode* appNode = nativeAppLists_.Head(); + while (appNode != nativeAppLists_.End()) { + if (item.id == appNode->data_.id) { + GRAPHIC_LOGE("Register menu failed because id %d already registered.", item.id); + return; + } + if (item.id < appNode->data_.id) { + nativeAppLists_.Insert(appNode, item); + return; + } + appNode = appNode->next_; + } + nativeAppLists_.PushBack(item); +} + bool NativeRegisterManager::IsSliceIdExist(AppViewId id) { for (uint16_t index = 0; index < slices_.Size(); index++) { diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/UICardPageFactory.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/UICardPageFactory.cpp new file mode 100644 index 000000000..649aa2f3c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/UICardPageFactory.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: UICardPageFactory + * Author: + * Create: 2025-06 + */ + +#include "UICardPageFactory.h" +#include "wearable_log.h" + +namespace OHOS { + +void UICardPageFactory::RegisterWatchDial(const uint16_t mode, const uint16_t id, UICardPageProxyInterface* uiCardPage) +{ + if (mode >= DIAL_DISPLAY_MODE_MAX || uiCardPage == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Can't register watch dial using invalid mode or proxy %d-%p", + mode, uiCardPage); + return; + } + if (watchDials_[mode].find(id) != watchDials_[mode].end()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Watch dial mode %d id:%d has already been registered", mode, id); + return; + } else { + watchDials_[mode].insert({id, uiCardPage}); + } +} + +UICardPage* UICardPageFactory::CreateWatchDial(uint16_t mode, uint16_t id) +{ + if (mode >= DIAL_DISPLAY_MODE_MAX ) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Can't create watch dial using invalid mode %d", mode); + return nullptr; + } + + auto it = watchDials_[mode].find(id); + if (it != watchDials_[mode].end()) { + return it->second->CreateUICardPage(); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Watch dial mode %d id:%d was not registered", mode, id); + return nullptr; + } +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityModel.cpp index a47bb9a77..a68a6c7e5 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityModel.cpp @@ -5,7 +5,7 @@ * Create: 2022-03-02 */ -#include "ActivityModel.h" +#include "activity/ActivityModel.h" #include #include "iostream" #include @@ -17,9 +17,9 @@ #include "graphic_timer.h" #include "securec.h" #include "broadcast_service.h" -#include "MainClockView.h" -#include "IndoorWalkPresenter.h" -#include "ActivityWeekView.h" +#include "clock/MainClockView.h" +#include "indoorwalk/IndoorWalkPresenter.h" +#include "activity/ActivityWeekView.h" #include "graphic_service.h" #ifdef __cplusplus @@ -76,32 +76,50 @@ static void RefreshStepControls(const uint32_t &value, const uint16 &msgId) { MainClockView *mainClockView = OHOS::MainClockView::GetInstance(); if (mainClockView != nullptr) { - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&MainClockView::RefreshStep, mainClockView, value)); + GraphicService::GetInstance()->PostGraphicEvent([value]() { + if (OHOS::MainClockView::GetInstance() != nullptr) { + OHOS::MainClockView::GetInstance()->RefreshStep(value); + } + }); } IndoorWalkPresenter *indoorWalkPresenter = OHOS::IndoorWalkPresenter::GetInstance(); if (indoorWalkPresenter != nullptr) { - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&IndoorWalkPresenter::ModifiesSteps, indoorWalkPresenter, value)); + GraphicService::GetInstance()->PostGraphicEvent([value]() { + if (OHOS::IndoorWalkPresenter::GetInstance() != nullptr) { + OHOS::IndoorWalkPresenter::GetInstance()->ModifiesSteps(value); + } + }); } ActivityWeekView *activityWeekView = OHOS::ActivityWeekView::GetInstance(); if (activityWeekView == nullptr) { return; } - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&ActivityWeekView::RefreshSteps, activityWeekView, value)); + GraphicService::GetInstance()->PostGraphicEvent([value]() { + if (OHOS::ActivityWeekView::GetInstance() != nullptr) { + OHOS::ActivityWeekView::GetInstance()->RefreshSteps(value); + } + }); if (msgId == TOPIC_EVENT_STEPDATA_UPDATE) { - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&ActivityWeekView::RefreshTodayView, activityWeekView, value)); + GraphicService::GetInstance()->PostGraphicEvent([value]() { + if (OHOS::ActivityWeekView::GetInstance() != nullptr) { + OHOS::ActivityWeekView::GetInstance()->RefreshTodayView(value); + } + }); } else if (msgId == TOPIC_EVENT_NEXTDAY_UPDATE) { - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&ActivityWeekView::InitAvgStep, activityWeekView)); + GraphicService::GetInstance()->PostGraphicEvent([]() { + if (OHOS::ActivityWeekView::GetInstance() != nullptr) { + OHOS::ActivityWeekView::GetInstance()->InitAvgStep(); + } + }); if (OHOS::ActivityModel::GetInstance()->GetWeekToday() == MONDAY_STEP_COUNTER) { - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&ActivityWeekView::InitWeekView, activityWeekView)); + GraphicService::GetInstance()->PostGraphicEvent([]() { + if (OHOS::ActivityWeekView::GetInstance() != nullptr) { + OHOS::ActivityWeekView::GetInstance()->InitWeekView(); + } + }); } } } @@ -123,8 +141,11 @@ static void Notify(void *args, const Topic topic, Request* request) counter += *(uint32_t *)request->data; OHOS::ActivityModel::GetInstance()->ReviseStepCounter(counter); - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&ActivityModel::SetStepData, ActivityModel::GetInstance(), counter)); + GraphicService::GetInstance()->PostGraphicEvent([counter]() { + if (ActivityModel::GetInstance() != nullptr) { + ActivityModel::GetInstance()->SetStepData(counter); + } + }); RefreshStepControls(counter, TOPIC_EVENT_STEPDATA_UPDATE); } @@ -216,7 +237,7 @@ void SaveEveryMinCallback(void* data) GraphicService::GetInstance()->PostGraphicEvent(std::bind(SaveEveryMinCallbackProc, data)); } -void ActivityModel::SetStepData(uint32_t &value) +void ActivityModel::SetStepData(const uint32_t &value) { g_stepData1.weekSteps[weekToday] = value; // 第一次上报数据后打开定时器 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityPresenter.cpp index c381e72e9..4603a46c0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityPresenter.cpp @@ -9,13 +9,13 @@ #include "gfx_utils/graphic_types.h" #include "components/ui_checkbox.h" #include "UiConfig.h" -#include "ActivityPresenter.h" +#include "activity/ActivityPresenter.h" #include "NativeRegisterManager.h" namespace OHOS { REGIST_SLICE(VIEW_MAIN_ACTIVITY, MainActivityView, ActivityPresenter); - + static ActivityPresenter *g_pActivityPresenter = nullptr; ActivityPresenter::ActivityPresenter() { @@ -36,7 +36,7 @@ ActivityPresenter *ActivityPresenter::GetInstance() bool ActivityPresenter::OnDrag(UIView& view, const DragEvent& event) { - WEARABLE_LOGD("WEARABLE_LOG_MODULE_APP", "ActivityPresenter::OnDrag"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ActivityPresenter::OnDrag"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { if (strcmp(view.GetViewId(), ACTIVITY_WEEK_VIEW) == 0) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ActivityPresenter::OnDrag on ACTIVITY_WEEK_VIEW"); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityWeekView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityWeekView.cpp index 3e880d409..dfafe79ba 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityWeekView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/activity/src/ActivityWeekView.cpp @@ -5,8 +5,8 @@ * Create: 2021-10-18 */ -#include "ActivityWeekView.h" -#include "ActivityPresenter.h" +#include "activity/ActivityWeekView.h" +#include "activity/ActivityPresenter.h" #include "common/image_cache_manager.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/activity/src/MainActivityView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/activity/src/MainActivityView.cpp index d9f307527..a119b20ec 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/activity/src/MainActivityView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/activity/src/MainActivityView.cpp @@ -6,7 +6,7 @@ */ #include "components/ui_label.h" -#include "MainActivityView.h" +#include "activity/MainActivityView.h" namespace OHOS { 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 index d92f38ddb..b62235fec 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardAdapter.cpp @@ -5,7 +5,7 @@ * Create: 2021-09-18 */ -#include "AddCardAdapter.h" +#include "add_card/AddCardAdapter.h" namespace OHOS { AddCardAdapter::AddCardAdapter() {} 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 index 67e287ec8..c6453a442 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardItem.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardItem.cpp @@ -1,5 +1,5 @@ -#include "AddCardItem.h" -#include "AddCardPresenter.h" +#include "add_card/AddCardItem.h" +#include "add_card/AddCardPresenter.h" #include "wearable_log.h" namespace OHOS { 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 index fa052decb..52a621627 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardModel.cpp @@ -5,7 +5,7 @@ * Create: 2021-11-23 */ -#include "AddCardModel.h" +#include "add_card/AddCardModel.h" #include "kv_store.h" #include "securec.h" 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 index b72e0dcfc..59474f5d9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp @@ -5,9 +5,9 @@ * Create: 2021-11-23 */ -#include "AddCardView.h" -#include "AddCardModel.h" -#include "AddCardPresenter.h" +#include "add_card/AddCardView.h" +#include "add_card/AddCardModel.h" +#include "add_card/AddCardPresenter.h" #include "hal_tick.h" #include "NativeRegisterManager.h" 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 index abb1a6376..4828ac3fe 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/add_card/src/AddCardView.cpp @@ -6,8 +6,8 @@ */ #include -#include "AddCardView.h" -#include "AddCardPresenter.h" +#include "add_card/AddCardView.h" +#include "add_card/AddCardPresenter.h" namespace OHOS { AddCardView::AddCardView() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmClockModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmClockModel.cpp index 4edb2149a..e2863a5a4 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmClockModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmClockModel.cpp @@ -12,12 +12,12 @@ #include "samgr_lite.h" #include "graphic_mutex.h" #include "UiConfig.h" -#include "AlarmClockModel.h" -#include "AlarmPopUpPresenter.h" +#include "alarm/AlarmClockModel.h" +#include "alarm/AlarmPopUpPresenter.h" #include "graphic_service.h" -#include "PlayersModel.h" -#include "PhoneService.h" -#include "ui_service.h" +#include "player/PlayersModel.h" +#include "phoneservice/PhoneService.h" +#include "uiservice/ui_service.h" #ifdef __cplusplus extern "C" { @@ -456,8 +456,7 @@ void AlarmClockModel::SetDelayAlarm(uint8_t alarm) } currentAlarm[clockListener]->delayNum++; clockQueueMsg->eventType = EVENT_ALARM_RING_DELAY; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmClockModel::ButtonStatusRing clockQueueMsg->eventType is %u", - clockQueueMsg->eventType); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmClockModel::SetDelayAlarm %u %u", clockQueueMsg->eventType, alarm); (clockQueueMsg->data).value = alarm; AlmmgrAlarmClockEventProcess(clockQueueMsg); return; @@ -471,8 +470,7 @@ void AlarmClockModel::SetCancelAlarm(uint8_t alarm) return; } clockQueueMsg->eventType = EVENT_ALARM_RING_CANCEL; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmClockModel::ButtonStatusRing clockQueueMsg->eventType is %u", - clockQueueMsg->eventType); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmClockModel::SetCancelAlarm %u %u", clockQueueMsg->eventType, alarm); (clockQueueMsg->data).value = alarm; AlmmgrAlarmClockEventProcess(clockQueueMsg); return; @@ -805,8 +803,9 @@ int AlarmClockModel::AlarmPlayerStart(void) void AlarmPlayerCallbackImpl::OnPlaybackComplete() { - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::AlarmClockModel::DeactAudioInter, OHOS::AlarmClockModel::GetInstance())); + /* msg center已处理,此处注释 */ + // GraphicService::GetInstance()->PostGraphicEvent( + // std::bind(&OHOS::AlarmClockModel::DeactAudioInter, OHOS::AlarmClockModel::GetInstance())); } uint16_t AlarmClockModel::JudgePreSlice(void) diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmCloseRingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmCloseRingView.cpp index e69e8b6ef..c10fa4875 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmCloseRingView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmCloseRingView.cpp @@ -5,7 +5,7 @@ * Create: 2021-09-11 */ -#include "AlarmCloseRingView.h" +#include "alarm/AlarmCloseRingView.h" #include "common/screen.h" #include "components/ui_label.h" #include "components/ui_label_button.h" @@ -13,8 +13,8 @@ #include "ohos_timer.h" #include "graphic_timer.h" -#include "AlarmPopUpPresenter.h" -#include "PhoneService.h" +#include "alarm/AlarmPopUpPresenter.h" +#include "phoneservice/PhoneService.h" namespace OHOS { #define CLOSE "关闭" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmConfigView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmConfigView.cpp index 171caef71..97141e68b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmConfigView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmConfigView.cpp @@ -5,10 +5,10 @@ * Create: 2021-09-11 */ -#include "AlarmConfigView.h" +#include "alarm/AlarmConfigView.h" #include "UiConfig.h" #include -#include "AlarmPresenter.h" +#include "alarm/AlarmPresenter.h" #include #include "color.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmJudgeView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmJudgeView.cpp index 9e6c2ea72..3ec474d30 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmJudgeView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmJudgeView.cpp @@ -5,10 +5,10 @@ * Create: 2021-09-11 */ -#include "AlarmJudgeView.h" +#include "alarm/AlarmJudgeView.h" #include "UiConfig.h" #include -#include "AlarmPresenter.h" +#include "alarm/AlarmPresenter.h" namespace OHOS { #define DELETE_INETERFACES "是否删除此闹钟?" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmMaxClock.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmMaxClock.cpp index ed0e5aef6..5bc2c3949 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmMaxClock.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmMaxClock.cpp @@ -5,14 +5,14 @@ * Create: 2021-09-11 */ -#include "AlarmMaxClock.h" +#include "alarm/AlarmMaxClock.h" #include "UiConfig.h" #include #include "ohos_timer.h" #include "graphic_timer.h" -#include "AlarmPresenter.h" -#include "MainAlarmView.h" +#include "alarm/AlarmPresenter.h" +#include "alarm/MainAlarmView.h" namespace OHOS { #define MAX_INETERFACES "当前闹钟个数已达上限" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmNewTimeView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmNewTimeView.cpp index 93a205b55..d13509d96 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmNewTimeView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmNewTimeView.cpp @@ -5,7 +5,7 @@ * Create: 2021-09-11 */ -#include "AlarmNewTimeView.h" +#include "alarm/AlarmNewTimeView.h" #include "common/screen.h" #include "components/ui_label.h" #include "components/ui_label_button.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPopUpPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPopUpPresenter.cpp index 2ae51d223..972cc0e3e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPopUpPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPopUpPresenter.cpp @@ -6,11 +6,11 @@ */ -#include "AlarmPopUpPresenter.h" -#include "MainAlarmView.h" +#include "alarm/AlarmPopUpPresenter.h" +#include "alarm/MainAlarmView.h" #include "ChangeSliceListener.h" -#include "PhoneService.h" -#include "PlayersModel.h" +#include "phoneservice/PhoneService.h" +#include "player/PlayersModel.h" #include "NativeRegisterManager.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPopUpView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPopUpView.cpp index 29ad7f6fb..3d54a5ce9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPopUpView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPopUpView.cpp @@ -5,8 +5,8 @@ * Create: 2021-09-11 */ -#include "AlarmPopUpView.h" -#include "AlarmPopUpPresenter.h" +#include "alarm/AlarmPopUpView.h" +#include "alarm/AlarmPopUpPresenter.h" #include "common/screen.h" #include "components/ui_label.h" #include "components/ui_label_button.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPresenter.cpp index 29b88dd08..c0e1985b1 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmPresenter.cpp @@ -6,8 +6,8 @@ */ -#include "AlarmPresenter.h" -#include "MainAlarmView.h" +#include "alarm/AlarmPresenter.h" +#include "alarm/MainAlarmView.h" #include "NativeRegisterManager.h" #include "ChangeSliceListener.h" #include "string" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmRingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmRingView.cpp index bb449321c..26c94cdb4 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmRingView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmRingView.cpp @@ -5,15 +5,15 @@ * Create: 2021-09-11 */ -#include "AlarmRingView.h" +#include "alarm/AlarmRingView.h" #include "common/screen.h" #include "components/ui_label.h" #include "components/ui_label_button.h" #include -#include "AlarmPopUpPresenter.h" +#include "alarm/AlarmPopUpPresenter.h" #include "ohos_timer.h" #include "graphic_timer.h" -#include "PhoneService.h" +#include "phoneservice/PhoneService.h" namespace OHOS { #define RING_AGAIN "响铃将在十分钟后再次响起" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmSetTimeView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmSetTimeView.cpp index 6d04e328f..bf5f07d11 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmSetTimeView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmSetTimeView.cpp @@ -5,7 +5,7 @@ * Create: 2021-09-11 */ -#include "AlarmSetTimeView.h" +#include "alarm/AlarmSetTimeView.h" #include "common/screen.h" #include "components/ui_label.h" #include "components/ui_label_button.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmSetWeekView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmSetWeekView.cpp index 397430b78..673317760 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmSetWeekView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/AlarmSetWeekView.cpp @@ -5,7 +5,7 @@ * Create: 2021-09-11 */ -#include "AlarmSetWeekView.h" +#include "alarm/AlarmSetWeekView.h" #include "common/screen.h" #include "components/ui_digital_clock.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/MainAlarmView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/MainAlarmView.cpp index 430334b14..1f56be330 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/MainAlarmView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarm/src/MainAlarmView.cpp @@ -5,10 +5,10 @@ * Create: 2021-09-11 */ -#include "MainAlarmView.h" +#include "alarm/MainAlarmView.h" #include "UiConfig.h" #include "ui_label_button.h" -#include "PhoneService.h" +#include "phoneservice/PhoneService.h" namespace OHOS { static MainAlarmView *g_MainAlarmView = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/src/AlarmClockManage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/src/AlarmClockManage.cpp index 5ce9f8636..a87b03af3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/src/AlarmClockManage.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/src/AlarmClockManage.cpp @@ -19,9 +19,9 @@ #include "broadcast_service.h" #include "samgr_lite.h" -#include "RtcService.h" -#include "AlarmClockTimerConfig.h" -#include "AlarmClockManage.h" +#include "rtcservice/RtcService.h" +#include "alarmclocktimerconfig/AlarmClockTimerConfig.h" +#include "alarmclockmanage/AlarmClockManage.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp index 135ebd78d..c5c02282e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp @@ -16,7 +16,7 @@ #include "thread_adapter.h" #include "graphic_service.h" -#include "AlarmClockTimerConfig.h" +#include "alarmclocktimerconfig/AlarmClockTimerConfig.h" #ifdef __cplusplus extern "C" { @@ -102,8 +102,9 @@ void AlarmScan(void *arg) if ((g_alarmCtrA.callback != nullptr) && (g_alarmCtrA.info.hour == curTime.tm_hour) && (g_alarmCtrA.info.minute == curTime.tm_min)) { - g_alarmCtrA.callback(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmA Called %d %d", curTime.tm_hour, curTime.tm_min); g_alarmCtrA.state = ALARM_STATUS_CREATED; + g_alarmCtrA.callback(); } } @@ -112,8 +113,9 @@ void AlarmScan(void *arg) (g_alarmCtrB.info.week == curTime.tm_wday) && (g_alarmCtrB.info.hour == curTime.tm_hour) && (g_alarmCtrB.info.minute == curTime.tm_min)) { - g_alarmCtrB.callback(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmB Called %d %d", curTime.tm_hour, curTime.tm_min); g_alarmCtrB.state = ALARM_STATUS_CREATED; + g_alarmCtrB.callback(); } } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBarCode.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBarCode.cpp index 5e8723d58..8ecfc16e3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBarCode.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBarCode.cpp @@ -8,8 +8,8 @@ #include "UiConfig.h" #include #include "cmsis_os.h" -#include "AlipayBarCode.h" -#include "AlipayModel.h" +#include "alipay/AlipayBarCode.h" +#include "alipay/AlipayModel.h" namespace OHOS { #define ALIPAY_BARCODE_SPACE 32 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBind.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBind.cpp index 780949585..ec5e44753 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBind.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBind.cpp @@ -6,8 +6,8 @@ */ #include "UiConfig.h" #include -#include "AlipayBind.h" -#include "AlipayModel.h" +#include "alipay/AlipayBind.h" +#include "alipay/AlipayModel.h" namespace OHOS { static const char *BIND_TITLE = (char *)"使用支付宝扫码绑定"; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBindAni.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBindAni.cpp index 4574cb9f5..3a1b70ff1 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBindAni.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBindAni.cpp @@ -9,7 +9,7 @@ #include "layout/grid_layout.h" #include "font/ui_font.h" #include -#include "AlipayBindAni.h" +#include "alipay/AlipayBindAni.h" #include "common/image_cache_manager.h" #include "graphic_service.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBindRes.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBindRes.cpp index 0a331982b..04d775882 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBindRes.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayBindRes.cpp @@ -10,8 +10,8 @@ #include "font/ui_font.h" #include #include "cmsis_os.h" -#include "AlipayBindRes.h" -#include "AlipayModel.h" +#include "alipay/AlipayBindRes.h" +#include "alipay/AlipayModel.h" namespace OHOS { static const int16 EXIT_LABEL_X_FIRST = 151; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayExitBind.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayExitBind.cpp index edf88e323..3d86a9393 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayExitBind.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayExitBind.cpp @@ -9,7 +9,7 @@ #include "layout/grid_layout.h" #include "font/ui_font.h" #include -#include "AlipayExitBind.h" +#include "alipay/AlipayExitBind.h" namespace OHOS { static const int16 EXIT_LABEL_X_FIRST = 132; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayHelp.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayHelp.cpp index a772a5c10..6e1ff1652 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayHelp.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayHelp.cpp @@ -8,8 +8,8 @@ #include "UiConfig.h" #include #include "cmsis_os.h" -#include "AlipayHelp.h" -#include "AlipayModel.h" +#include "alipay/AlipayHelp.h" +#include "alipay/AlipayModel.h" namespace OHOS { static const char *HELP_TITLE = (char*)"使用支付宝扫码求助"; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListAdapter.cpp index 75b2d2da8..3ac28ada0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListAdapter.cpp @@ -5,8 +5,8 @@ * Create: */ -#include "AlipayListAdapter.h" -#include "AlipayListItemView.h" +#include "alipay/AlipayList/AlipayListAdapter.h" +#include "alipay/AlipayList/AlipayListItemView.h" namespace OHOS { AlipayListAdapter::AlipayListAdapter() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListItemView.cpp index 4cd238d8a..b91ee5cd1 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListItemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListItemView.cpp @@ -6,7 +6,7 @@ */ #include "wearable_log.h" -#include "AlipayListItemView.h" +#include "alipay/AlipayList/AlipayListItemView.h" namespace OHOS { static constexpr int16 ALIPAY_LIST_ICON_X = 20; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListView.cpp index e96e47030..292c48bba 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayList/AlipayListView.cpp @@ -6,8 +6,8 @@ */ #include -#include "AlipayListView.h" -#include "AlipayListItem.h" +#include "alipay/AlipayList/AlipayListView.h" +#include "alipay/AlipayList/AlipayListItem.h" #include "cmsis_os2.h" namespace OHOS { 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 76c9385ff..d45093f13 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayMainView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayMainView.cpp @@ -5,7 +5,7 @@ * Create: */ -#include "AlipayMainView.h" +#include "alipay/AlipayMainView.h" #include "UiConfig.h" #include "alipay_feature.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayModel.cpp index 0414fd48b..cc906cbee 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayModel.cpp @@ -7,8 +7,8 @@ #include "UiConfig.h" #include "alipay_feature.h" -#include "AlipayModel.h" -#include "AlipayMainView.h" +#include "alipay/AlipayModel.h" +#include "alipay/AlipayMainView.h" #include "graphic_service.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayPayCode.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayPayCode.cpp index 79e738f0f..0fea31b45 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayPayCode.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayPayCode.cpp @@ -8,8 +8,8 @@ #include "UiConfig.h" #include #include "cmsis_os.h" -#include "AlipayPayCode.h" -#include "AlipayModel.h" +#include "alipay/AlipayPayCode.h" +#include "alipay/AlipayModel.h" namespace OHOS { static AlipayPayCode *g_alipayPayCode = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp index a58470e2d..4909bd08d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp @@ -5,8 +5,8 @@ * Create: */ -#include "AlipayPresenter.h" -#include "AlipayMainView.h" +#include "alipay/AlipayPresenter.h" +#include "alipay/AlipayMainView.h" #include "ChangeSliceListener.h" #include "graphic_service.h" #include "string" @@ -14,10 +14,10 @@ #include "sstream" #include "errcode.h" #include "pm_definition.h" -#include "AlipayListView.h" -#include "AlipayListItemView.h" -#include "AlipayTransListItemView.h" -#include "AlipayTransListView.h" +#include "alipay/AlipayList/AlipayListView.h" +#include "alipay/AlipayList/AlipayListItemView.h" +#include "alipay/AlipayTrans/AlipayTransListItemView.h" +#include "alipay/AlipayTrans/AlipayTransListView.h" #include "NativeRegisterManager.h" namespace OHOS { @@ -61,7 +61,6 @@ void AlipayPresenter::OnStart() void AlipayPresenter::OnResume(void) { - Presenter::OnResume(); svr_alipay_create_task(); } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipaySetting.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipaySetting.cpp index c889eff58..8c977405b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipaySetting.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipaySetting.cpp @@ -8,8 +8,8 @@ #include "UiConfig.h" #include #include "cmsis_os.h" -#include "AlipaySetting.h" -#include "AlipayModel.h" +#include "alipay/AlipaySetting.h" +#include "alipay/AlipayModel.h" namespace OHOS { static const char *SETTING_TITLE = (char *)"设置"; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayGetTransList.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayGetTransList.cpp index 0bdadd009..b17032a7c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayGetTransList.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayGetTransList.cpp @@ -10,7 +10,7 @@ #include "font/ui_font.h" #include #include "cmsis_os.h" -#include "AlipayGetTransList.h" +#include "alipay/AlipayTrans/AlipayGetTransList.h" namespace OHOS { static const int16 EXIT_LABEL_X_FIRST = 60; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransAni.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransAni.cpp index 37adb66e5..1ef552af3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransAni.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransAni.cpp @@ -10,7 +10,7 @@ #include "font/ui_font.h" #include #include "cmsis_os.h" -#include "AlipayTransAni.h" +#include "alipay/AlipayTrans/AlipayTransAni.h" #include "common/image_cache_manager.h" #include "graphic_service.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransCode.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransCode.cpp index 2f0459546..072b53b57 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransCode.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransCode.cpp @@ -8,8 +8,8 @@ #include "UiConfig.h" #include #include "cmsis_os.h" -#include "AlipayTransCode.h" -#include "AlipayModel.h" +#include "alipay/AlipayTrans/AlipayTransCode.h" +#include "alipay/AlipayModel.h" namespace OHOS { static const char *TRANSCODE_BUTTON = (char *)"切换交通卡"; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransEnable.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransEnable.cpp index 8b42995ba..917843773 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransEnable.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransEnable.cpp @@ -8,8 +8,8 @@ #include "UiConfig.h" #include #include "cmsis_os.h" -#include "AlipayTransEnable.h" -#include "AlipayModel.h" +#include "alipay/AlipayTrans/AlipayTransEnable.h" +#include "alipay/AlipayModel.h" namespace OHOS { static const char *TRANSCODE_TITLE = (char *)"乘车码未开通"; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListAdapter.cpp index 703c4b275..54ddc916f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListAdapter.cpp @@ -5,8 +5,8 @@ * Create: */ -#include "AlipayTransListAdapter.h" -#include "AlipayTransListItemView.h" +#include "alipay/AlipayTrans/AlipayTransListAdapter.h" +#include "alipay/AlipayTrans/AlipayTransListItemView.h" namespace OHOS { AlipayTransListAdapter::AlipayTransListAdapter() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListItemView.cpp index aa4b0f0c7..ad049da17 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListItemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListItemView.cpp @@ -6,7 +6,7 @@ */ #include "wearable_log.h" -#include "AlipayTransListItemView.h" +#include "alipay/AlipayTrans/AlipayTransListItemView.h" namespace OHOS { static constexpr int16_t ALIPAY_TRANS_LIST_ITEM_BUTTON_HEIGHT = 95; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListView.cpp index b77752179..d811a1ee9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransListView.cpp @@ -6,9 +6,9 @@ */ #include -#include "AlipayTransListView.h" -#include "AlipayTransListItem.h" -#include "AlipayModel.h" +#include "alipay/AlipayTrans/AlipayTransListView.h" +#include "alipay/AlipayTrans/AlipayTransListItem.h" +#include "alipay/AlipayModel.h" #include "cmsis_os2.h" #include "common_def.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransRes.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransRes.cpp index c7b5558b2..573415e63 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransRes.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransRes.cpp @@ -10,8 +10,8 @@ #include "font/ui_font.h" #include #include "cmsis_os.h" -#include "AlipayTransRes.h" -#include "AlipayModel.h" +#include "alipay/AlipayTrans/AlipayTransRes.h" +#include "alipay/AlipayModel.h" namespace OHOS { static const int16 EXIT_LABEL_X_FIRST = 38; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransTips.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransTips.cpp index 11706660a..a59f99f14 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransTips.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayTrans/AlipayTransTips.cpp @@ -10,8 +10,8 @@ #include "font/ui_font.h" #include #include "cmsis_os.h" -#include "AlipayTransTips.h" -#include "AlipayModel.h" +#include "alipay/AlipayTrans/AlipayTransTips.h" +#include "alipay/AlipayModel.h" namespace OHOS { static const int16 TIPS_LABEL_X_FIRST = 38; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayUnbind.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayUnbind.cpp index 2c081cae3..a716545b0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayUnbind.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayUnbind.cpp @@ -10,7 +10,7 @@ #include "font/ui_font.h" #include #include "cmsis_os.h" -#include "AlipayUnbind.h" +#include "alipay/AlipayUnbind.h" namespace OHOS { static const int16 EXIT_LABEL_X_FIRST = 132; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayUnbindFinish.cpp b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayUnbindFinish.cpp index 817d90bf3..bd259f23e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayUnbindFinish.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/alipay/src/AlipayUnbindFinish.cpp @@ -8,7 +8,7 @@ #include "UiConfig.h" #include #include "cmsis_os.h" -#include "AlipayUnbindFinish.h" +#include "alipay/AlipayUnbindFinish.h" namespace OHOS { static AlipayUnbindFinish *g_alipayUnbindFinish = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodModel.cpp index e06b38c0e..a32c98430 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodModel.cpp @@ -5,7 +5,9 @@ * Create: 2024-10-30 */ -#include "AodModel.h" +#include "aod_view/AodModel.h" +#include +#include "securec.h" #include "kv_store.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodPresenter.cpp index c08a7472b..9d47082d9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodPresenter.cpp @@ -5,7 +5,7 @@ * Create: 2024-10-30 */ -#include "AodPresenter.h" +#include "aod_view/AodPresenter.h" #include "NativeRegisterManager.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodView.cpp index 90405196d..6bb9f8cec 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/aod_view/src/AodView.cpp @@ -5,14 +5,15 @@ * Create: 2024-10-30 */ -#include "AodView.h" -#include "AodPresenter.h" -#include "AodModel.h" +#include "aod_view/AodView.h" +#include "aod_view/AodPresenter.h" +#include "aod_view/AodModel.h" #include "common/graphic_utils.h" -#include "DialBinParser.h" -#include "DialViewGroup.h" -#include "AmbientClockView.h" -#include "DialModelTime.h" +#include "UICardPageFactory.h" +#include "main/DialBinParser.h" +#include "main/dial/DialViewGroup.h" +#include "clock/AmbientClockView.h" +#include "main/dial/DialModelTime.h" namespace OHOS { AodView::~AodView() @@ -67,13 +68,7 @@ void AodView::OnStop() UIViewGroup *AodView::InitAodDial(DialSetting &setting) { - switch (setting.dialId) { - case DIAL_CLOCK: - return new AmbientClockView; - default: - return nullptr; - } - return nullptr; + return UICardPageFactory::GetInstance().CreateWatchDial(DIAL_DISPLAY_MODE_AOD, setting.dialId); } UIViewGroup *AodView::InitAodOffDial(DialSetting &setting) @@ -84,7 +79,7 @@ UIViewGroup *AodView::InitAodOffDial(DialSetting &setting) if (fp == nullptr) { return nullptr; } - bool ret = DialBinParserManager::GetInstance()->GetDialPreviewInfo(fp, &preview); + bool ret = DialBinParserManager::GetInstance()->GetDialPreviewInfo(setting.dialFullName, fp, &preview); fclose(fp); if (!ret) { return nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistModel.h b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistModel.h deleted file mode 100644 index fdf1a34f2..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistModel.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: ApplistModel.h - * Author: - * Create: 2021-09-18 - */ - -#ifndef APPLIST_MODEL_H -#define APPLIST_MODEL_H - -#include "bundle_info.h" -#include "AppViewIDs.h" -#include "ohos_types.h" - -#define APP_MAX_NUM 50 - -namespace OHOS { -typedef struct { - uint16_t id; - const char *iconLarge; - const char *iconSmall; - const char *iconHexagon; - const char *label; - const char *uid; -} AppItem; - -enum AppListStyle { - APPLIST_STYLE, - HEXAGONS_STYLE, - FOOTBALL_STYLE, - WATERFALL_STYLE -}; - -class ApplistPresenter; -class ApplistModel { -public: - static ApplistModel &GetInstance(void); - - void Init(); - const AppItem *GetApplistItems() const; - uint8 GetAppListNum() const; - void ResolvingJSAppItems(void); - void SetStartIndex(uint16_t index); - uint16_t GetStartIndex(void); - void SetHeadItemY(int index); - int GetHeadItemY(void); - void ApplistUpdate(void); - void SetPresenter(ApplistPresenter *p); - AppListStyle GetCurrentStyle(void); - void SetInitFlag(bool flag); - -private: - ApplistModel(); - ApplistModel(const ApplistModel &); - ApplistModel &operator=(const ApplistModel &); - virtual ~ApplistModel(); - ApplistPresenter *presenter{nullptr}; - - AppItem applist[APP_MAX_NUM] = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr, nullptr }; - BundleInfo *bundleInfos = nullptr; - int32 bundleLen = 0; - uint8 appLen = 0; - - uint16_t startIndex = 0; - int headItemY = 0; - bool initFlag{false}; -}; -} - -#endif 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 e4193a9a5..f5dca80fd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/AppItemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/AppItemView.cpp @@ -5,7 +5,8 @@ * Create: 2021-09-18 */ -#include "AppItemView.h" +#include "applist/AppItemView.h" +#include "common/image_cache_manager.h" #include "wearable_log.h" namespace OHOS { @@ -33,6 +34,9 @@ namespace OHOS { { Remove(&icon_); Remove(&label_); + if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); + } } void AppItemView::SetUpChild() @@ -56,8 +60,25 @@ namespace OHOS { void AppItemView::SetItemInfo(const AppItem &itemInfo) { itemInfo_ = itemInfo; - icon_.SetSrc(itemInfo.iconSmall); - label_.SetText(itemInfo.label); + if (itemInfo.label == nullptr) { + if (itemInfo.labelId != STR_MAX_ID) { + label_.SetTextId(itemInfo.labelId); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AppItemView::SetItemInfo label is null and labelId equal STR_MAX_ID!"); + } + } else { + label_.SetText(itemInfo.label); + } + if (itemInfo.iconSmall == nullptr && itemInfo_.resPath != nullptr) { + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(itemInfo.resId, itemInfo.resPath); + if (image != nullptr) { + icon_.SetSrc(image); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AppItemView::SetItemInfo image get failed!"); + } + } else { + icon_.SetSrc(itemInfo.iconSmall); + } } AppViewId AppItemView::GetViewId() @@ -88,6 +109,9 @@ namespace OHOS { HexagonsItemView::~HexagonsItemView() { + if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); + } } void HexagonsItemView::SetItemInfo(const AppItem &itemInfo) @@ -105,6 +129,13 @@ namespace OHOS { return itemInfo_.uid; } + FootballItemView::~FootballItemView() + { + if (itemInfo_.iconHexagon == nullptr && itemInfo_.hexagonPath != nullptr) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.hexagonId, itemInfo_.hexagonPath); + } + } + void FootballItemView::SetItemInfo(const AppItem &itemInfo) { itemInfo_ = itemInfo; @@ -119,6 +150,13 @@ namespace OHOS { { return itemInfo_.uid; } + + WaterfallItemView::~WaterfallItemView() + { + if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); + } + } void WaterfallItemView::SetItemInfo(const AppItem &itemInfo) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistAdapter.cpp index 8e26721c8..2808ba27a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistAdapter.cpp @@ -5,7 +5,7 @@ * Create: 2021-09-18 */ -#include "ApplistAdapter.h" +#include "applist/ApplistAdapter.h" namespace OHOS { ApplistAdapter::ApplistAdapter() {} 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 c5a7339bf..b3eabbb23 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp @@ -12,11 +12,11 @@ #include "utils.h" #include "bundlems_slite_client.h" #include "wearable_log.h" - #include "UiConfig.h" -#include "ApplistModel.h" -#include "ApplistPresenter.h" -#include "SetDesktopView.h" +#include "applist/ApplistModel.h" +#include "applist/ApplistPresenter.h" +#include "font/font_global_manager.h" +#include "settings/SetDesktopModel.h" #include "NativeRegisterManager.h" namespace OHOS { @@ -96,7 +96,6 @@ namespace OHOS { applist[appLen] = { VIEW_EXTERN_APP, bundleInfos[len].smallIconPath, - bundleInfos[len].smallIconPath, bundleInfos[len].bigIconPath, bundleInfos[len].label, bundleInfos[len].bundleName @@ -163,15 +162,6 @@ namespace OHOS { AppListStyle ApplistModel::GetCurrentStyle(void) { - uint8_t currenStyle = SetDesktopView::GetInstance()->GetCurrentSelectedStyle(); - if (currenStyle == 1) { // 1: hexagons desktop style - return HEXAGONS_STYLE; - } else if (currenStyle == 2) { // 2: football desktop style - return FOOTBALL_STYLE; - } else if (currenStyle == 3) { // 3: waterfall desktop style - return WATERFALL_STYLE; - } else { - return APPLIST_STYLE; - } + return static_cast(SetDesktopModel::GetInstance().GetDesktopStyle()); } } 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 3442b147c..382786a39 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistPresenter.cpp @@ -5,7 +5,7 @@ * Create: 2021-09-18 */ -#include "ApplistPresenter.h" +#include "applist/ApplistPresenter.h" #include "ability_manager.h" #include "securec.h" #include "components/ui_hexagons_list.h" @@ -44,7 +44,6 @@ REGIST_SLICE(VIEW_APPLIST, ApplistView, ApplistPresenter); void ApplistPresenter::OnResume() { - Presenter::OnResume(); if (GetCurrentStyle() == AppListStyle::FOOTBALL_STYLE) { view_->StartFootBallAnimator(); } else if (GetCurrentStyle() == AppListStyle::WATERFALL_STYLE) { 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 11876d275..fbb18801e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistView.cpp @@ -6,10 +6,11 @@ */ #include "components/ui_view_group.h" -#include "ApplistView.h" -#include "ApplistPresenter.h" -#include "AppItemView.h" +#include "applist/ApplistView.h" +#include "applist/ApplistPresenter.h" +#include "applist/AppItemView.h" #include "common/image_cache_manager.h" +#include "common/screen.h" #include "hal_tick.h" namespace OHOS { @@ -264,13 +265,27 @@ void ApplistView::ListStyleOnStop() presenter_->SetStartIndex(listHeadIndex); } +void ApplistView::LoadAppIconImage(UIImageView *view, const uint32_t id, const char *path) +{ + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(id, path); + if (image == nullptr) { + GRAPHIC_LOGE("Load App Icon path %s Image %x fail\n", path, id); + return; + } + view->SetSrc(image); +} + void ApplistView::AddAppItemToList(const AppItem &item) { AppListStyle style = presenter_->GetCurrentStyle(); if (style == AppListStyle::FOOTBALL_STYLE) { FootballItemView *itemView = new FootballItemView(); itemView->SetItemInfo(item); - itemView->SetSrc(item.iconHexagon); + if (item.iconHexagon == nullptr && item.hexagonPath != nullptr) { + LoadAppIconImage(itemView, item.hexagonId, item.hexagonPath); + } else { + itemView->SetSrc(item.iconHexagon); + } itemView->SetTouchable(true); itemView->SetOnClickListener(presenter_); footballList_->Add(itemView); @@ -278,7 +293,11 @@ void ApplistView::AddAppItemToList(const AppItem &item) } else if (style == AppListStyle::HEXAGONS_STYLE) { HexagonsItemView *itemView = new HexagonsItemView(); itemView->SetItemInfo(item); - itemView->SetSrc(item.iconSmall); + if (item.iconSmall == nullptr && item.resPath != nullptr) { + LoadAppIconImage(itemView, item.resId, item.resPath); + } else { + itemView->SetSrc(item.iconSmall); + } itemView->SetTouchable(true); itemView->SetOnClickListener(presenter_); hexagonsList_->Add(itemView); @@ -286,7 +305,11 @@ void ApplistView::AddAppItemToList(const AppItem &item) } else if (style == AppListStyle::WATERFALL_STYLE) { WaterfallItemView *itemView = new WaterfallItemView(); itemView->SetItemInfo(item); - itemView->SetSrc(item.iconSmall); + if (item.iconSmall == nullptr && item.resPath != nullptr) { + LoadAppIconImage(itemView, item.resId, item.resPath); + } else { + itemView->SetSrc(item.iconSmall); + } itemView->SetTouchable(true); itemView->SetOnClickListener(presenter_); waterfallList_->Add(itemView); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodModel.cpp new file mode 100644 index 000000000..692d2d93d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodModel.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SettingModel.cpp + * Author: + * Create: 2025-03-23 + */ + +#include +#include "blood/BloodModel.h" +#include "blood/BloodView.h" +#include "ohos_timer.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr uint64_t CENTI_SECOND_UNIT = 100; +static constexpr uint64_t MS_ONE_SECONDS = 1000; +static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t NUM_TIME_MIN = 60; +static constexpr uint16_t NUM_TIME_HOUR = 3600; +static constexpr int32_t NUM_TIME_DAY = 86400; + +static constexpr int16_t MIN_TO_HOUR = 60; +static constexpr int16_t HOURLY_SYSTEM = 24; +BloodModel::BloodModel() +{ + InitCurrentTimeTimer(); +} + +BloodModel::~BloodModel() +{ + DisableCurrentTimeTimer(); +} + +BloodModel &BloodModel::GetInstance() +{ + static BloodModel instance; + return instance; +} +void BloodModel::SetbuttonStatus(bool status) +{ + buttonStatus = status; +} + +bool BloodModel::GetbuttonStatus() +{ + return buttonStatus; +} + +/* 定时器回调函数 */ +static void CurrentTimeTimerCallback(void *data) +{ + (void)data; + BloodView *view = BloodView::GetInstance(); + if (view != nullptr && view->IsCurrentTimeLabelValid()) { + std::string currTime = BloodModel::GetInstance().GetCurrentTimeString(); + view->UpdateCurrentTimeLabel(currTime.c_str()); + } +} + +std::string BloodModel::GetCurrentTimeString() +{ + std::string strHours; + std::string strMinute; + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t second = tv.tv_sec; + uint64_t uSecond = tv.tv_usec; + uint64_t minute = second / MIN_TO_HOUR; + uint64_t hour = minute / MIN_TO_HOUR; + uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); + uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); + + if (realHour >= 0 && realHour < NUM_TEN) { + strHours = "0" + std::to_string(realHour); + } else { + strHours = std::to_string(realHour); + } + if (realMinute >= 0 && realMinute < NUM_TEN) { + strMinute = "0" + std::to_string(realMinute); + } else { + strMinute = std::to_string(realMinute); + } + return strHours + ":" + strMinute; +} + +void BloodModel::InitCurrentTimeTimer() +{ + if (pCurrentTimeTimer_ != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchModel::InitCurrentTimeTimer GraphicTimer already exists!!"); + return; + } + uint32_t tick = GetOSTick(MS_ONE_SECONDS); + pCurrentTimeTimer_ = new GraphicTimer(tick, CurrentTimeTimerCallback, nullptr, true); + if (pCurrentTimeTimer_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchModel::InitCurrentTimeTimer new GraphicTimer failed!!"); + return; + } +} + +void BloodModel::DisableCurrentTimeTimer() +{ + if (pCurrentTimeTimer_ != nullptr) { + pCurrentTimeTimer_->Stop(); + delete pCurrentTimeTimer_; + pCurrentTimeTimer_ = nullptr; + } +} + +void BloodModel::StartCurrentTimeTimer() +{ + if (pCurrentTimeTimer_ != nullptr) { + bool retTimer = pCurrentTimeTimer_->Start(); + if (!retTimer) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartStopwatchTimer GraphicTimer Start failed!!"); + if (pCurrentTimeTimer_ != nullptr) { + delete pCurrentTimeTimer_; + pCurrentTimeTimer_ = nullptr; + } + return; + } + } +} + +void BloodModel::PauseCurrentTimeTimer() +{ + if (pCurrentTimeTimer_ != nullptr) { + pCurrentTimeTimer_->Stop(); + } +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodPresenter.cpp new file mode 100644 index 000000000..5e98671cc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodPresenter.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingPresenter.cpp + * Author: + * Create: 2025-03-23 + */ + +#include "blood/BloodPresenter.h" +#include "blood/BloodView.h" +#include "blood/BloodModel.h" +#include "uiservice/ui_service.h" +#include "NativeRegisterManager.h" +namespace OHOS { + +REGIST_MENU(VIEW_BLOOD, BloodView, BloodPresenter, PNG_APPLIST_TEMP_IMAGE, PNG_APPLIST_TEMP_IMAGE, "血氧"); + +static BloodPresenter *g_pBloodPresenter = nullptr; + +BloodPresenter::BloodPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodPresenter::BloodPresenter"); + findPhoneModel = &BloodModel::GetInstance(); + g_pBloodPresenter = this; +} + +BloodPresenter::~BloodPresenter() +{ + g_pBloodPresenter = nullptr; +} + +void BloodPresenter::OnResume(void) +{ + Presenter::OnResume(); + SendMsgToUIService(UI_ADD_SLEEP_VETO, 0, nullptr, 0); + BloodModel::GetInstance().StartCurrentTimeTimer(); +} + +void BloodPresenter::OnPause(void) +{ + Presenter::OnPause(); + SendMsgToUIService(UI_RM_SLEEP_VETO, 0, nullptr, 0); + BloodModel::GetInstance().PauseCurrentTimeTimer(); + return; +} + +BloodPresenter *BloodPresenter::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodPresenter GetInstance"); + return g_pBloodPresenter; +} + +bool BloodPresenter::ClickFuncId(const char *buttonName) +{ + if (buttonName == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempPresenter::ClickFuncId buttonName nullptr error!"); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TempPresenter::ClickFuncId buttonName = %s", buttonName); + if (strcmp(buttonName, "button1") == 0) { + } else if (strcmp(buttonName, "button2") == 0) { + } + return false; +} + +bool BloodPresenter::OnClick(UIView &view, const ClickEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TempPresenter::OnClick "); + UNUSED(event); + BloodView::GetInstance()->DropView(view, 1); + return true; +} + +bool BloodPresenter::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherOnDragListener::OnDrag"); + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag %s", view.GetViewId()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag %s", event.GetDragDirection()); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag ChangeSlice(VIEW_APPLIST)"); + BloodView::GetInstance()->DropView(view, 0); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag DIRECTION_RIGHT_TO_LEFT"); + BloodView::GetInstance()->DropView(view, 1); + } + return false; +} + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodView.cpp new file mode 100644 index 000000000..05a7801dc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodView.cpp @@ -0,0 +1,603 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingView.cpp + * Author: + * Create: 2025-03-23 + */ + +#include + +#include "blood/BloodView.h" +#include "blood/BloodPresenter.h" +#include "ui_test_group.h" + +namespace OHOS { +static BloodView *g_pBloodView = nullptr; +static const char *BLOOD_LABEL_TWO = (char *)"本功能用于18岁以上健康人群测量运动过程,及之后腕部皮肤温度和体温的变化," + "请加入研究,以便及时观察运动前后身体的变化。"; +static const char *BLOOD_LABEL_THREE = (char *)"测量需佩戴10分钟以上,且容易受到环境因素影响。目前达不到水银体温计的精" + "度,测量结果仅供参考,不作为医疗诊断依据。"; +static constexpr uint16_t BLOOD_FIRST_LABEL_FONT = 35; +static constexpr uint16_t BLOOD_LABEL_FIRST_X = 45; +static constexpr uint16_t BLOOD_LABEL_FIRST_Y = 120; +static constexpr uint16_t BLOOD_LABEL_SECOND_Y = 350; +static constexpr uint16_t BLOOD_LABEL_THIRD_Y = 650; +static constexpr uint16_t BLOOD_LABEL_FIRST_WIDTH = 350; +static constexpr uint16_t BLOOD_LABEL_FIRST_HEIGHT = 400; +static constexpr uint16_t BLOOD_IMAGE_POSITION_X = 92; +static constexpr uint16_t BLOOD_IMAGE_POSITION_y = 127; +static constexpr uint16_t BLOOD_IMAGE_WIDTH = 276; +static constexpr uint16_t BLOOD_IMAGE_HEIGHT = 125; +static const char *BLOOD_LABEL_ONE = + (char *)"本功能通过内置温度传感器测量腕部皮肤温度,主要研究腕部皮肤温度和体温的关系。"; +static constexpr uint16_t WATCH_TIME_LABEL_CURTIME_XPOS = 188; +static constexpr uint16_t WATCH_TIME_LABEL_CURTIME_YPOS = 12; +static constexpr uint16_t WATCH_TIME_LABEL_CURTIME_WIDTH = 361; +static constexpr uint16_t WATCH_TIME_LABEL_CURTIME_HEIGHT = 80; +static constexpr uint16_t WATCH_TIME_LABEL_CURTIME_FONT_SIZE = 40; +static constexpr uint16_t BLOOD_LAYOUT_POSITION_X = 370; +static constexpr uint16_t BLOOD_LAYOUT_WIDTH = 320; +static constexpr uint16_t BLOOD_BUTTON_POSITION_X = 188; +static constexpr uint16_t BLOOD_BUTTON_POSITION_Y = 320; +static constexpr uint16_t BLOOD_BUTTON_WIDTH = 180; +static constexpr uint16_t BLOOD_BUTTON_HEIGHT = 80; +static constexpr uint16_t BLOOD_BUTTON_TWO_POSITION_Y = 330; +static constexpr uint16_t BLOOD_BUTTON_TWO_WIDTH = 120; +static constexpr uint16_t BLOOD_LABEL_FRONT = 25; +static constexpr uint16_t BLOOD_LABEL1_POSITION_X = 150; +static constexpr uint16_t BLOOD_LABEL1_POSITION_Y = 161; +static constexpr uint16_t BLOOD_LABEL1_WIDTH = 200; +static constexpr uint16_t BLOOD_LABEL1_HEIGHT = 60; +static constexpr uint16_t BLOOD_LABEL_FRONT1 = 60; +static constexpr uint16_t BLOOD_LABEL2_POSITION_X = 150; +static constexpr uint16_t BLOOD_LABEL2_POSITION_Y = 132; +static constexpr uint16_t BLOOD_LABEL2_WIDTH = 200; +static constexpr uint16_t BLOOD_LABEL2_HEIGHT = 60; +static constexpr uint16_t BLOOD_IMAGEANIMATOR_POSITION_X = 84; +static constexpr uint16_t BLOOD_IMAGEANIMATOR_POSITION_Y = 108; +static constexpr uint16_t BLOOD_IMAGEANIMATOR_WIDTH = 100; +static constexpr uint16_t BLOOD_IMAGEANIMATOR_HEIGHT = 100; + +static ImageAnimatorInfo g_imageAnimatorInfo[4] = { + {PNG_SETTTING_BUTTON_IMAGE, {84, 108}, 116, 116, IMG_SRC_FILE_PATH}, + {PNG_NEW_DEVICE, {84, 108}, 116, 116, IMG_SRC_FILE_PATH}, + {PNG_BT_LIST, {84, 108}, 116, 116, IMG_SRC_FILE_PATH}, + {PNG_GANTAN, {84, 108}, 116, 116, IMG_SRC_FILE_PATH}, +}; + +BloodView::BloodView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodView::BloodView"); + g_pBloodView = this; + findPhoneModel = &BloodModel::GetInstance(); +} + +BloodView::~BloodView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodView::~BloodView"); + g_pBloodView = nullptr; + if (currentTime_ != nullptr) { + delete currentTime_; + currentTime_ = nullptr; + } + if (button != nullptr) { + delete button; + button = nullptr; + } + if (buttonMore != nullptr) { + delete buttonMore; + buttonMore = nullptr; + } + if (label1_ != nullptr) { + delete label1_; + label1_ = nullptr; + } + if (label2_ != nullptr) { + delete label2_; + label2_ = nullptr; + } + if (layout_ != nullptr) { + delete layout_; + layout_ = nullptr; + } + if (currentTime_ != nullptr) { + delete currentTime_; + currentTime_ = nullptr; + } + if (group != nullptr) { + delete group; + group = nullptr; + } + if (groupTest != nullptr) { + delete groupTest; + groupTest = nullptr; + } + if (scrollGroup != nullptr) { + delete scrollGroup; + scrollGroup = nullptr; + } + for (int16_t numGroup = SET_ZERO; numGroup <= MAX_BLOOD_PAGE; numGroup++) { + if (container[numGroup] != nullptr) { + container[numGroup] = nullptr; + } + } +} + +BloodView *BloodView::GetInstance() +{ + return g_pBloodView; +} + +void BloodView::OnStart() +{ + SetupCurrentTime(); + InitStart(); +} + +void BloodView::OnStop() +{ + if (dragListener_ != nullptr) { + delete dragListener_; + dragListener_ = nullptr; + } + return; +} + +void BloodView::SetupCurrentTime() +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::SetupCurrentTime new Label"); + currentTime_ = new UILabel(); + if (currentTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::SetupCurrentTime new Label currentTime_ fail"); + return; + } + currentTime_->SetPosition(WATCH_TIME_LABEL_CURTIME_XPOS, WATCH_TIME_LABEL_CURTIME_YPOS); + currentTime_->Resize(WATCH_TIME_LABEL_CURTIME_WIDTH, WATCH_TIME_LABEL_CURTIME_HEIGHT); + std::string curtime = BloodModel::GetInstance().GetCurrentTimeString(); + currentTime_->SetText(curtime.c_str()); + currentTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WATCH_TIME_LABEL_CURTIME_FONT_SIZE); + currentTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + currentTime_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + currentTime_->SetRollSpeed(0); + currentTime_->SetVisible(true); +} + +void BloodView::SetUpImageAnimator() +{ + imageAnimator_ = new UIImageAnimatorView(); + if (imageAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::UIImageAnimatorView new Label currentTime_ fail"); + return; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::SetUpImageAnimator "); + imageAnimator_ = new UIImageAnimatorView(); + imageAnimator_->SetPosition(BLOOD_IMAGE_POSITION_X, BLOOD_IMAGE_POSITION_y, BLOOD_IMAGE_WIDTH, + BLOOD_IMAGE_HEIGHT); // 50 : offset 50 : offset 200 : offset 200: offset + int imageNumber = 4; + int ImageUpdate = 300; + imageAnimator_->SetImageAnimatorSrc(g_imageAnimatorInfo, imageNumber, + ImageUpdate); // 4: the number of images, 100: updating time + imageAnimator_->Stop(); + imageAnimator_->LayoutCenterOfParent(); + imageAnimator_->SetDraggable(true); + UIView::OnDragListener *listener = static_cast(BloodPresenter::GetInstance()); + imageAnimator_->SetOnDragListener(listener); + container[BLOOD_START]->Add(imageAnimator_); + if (layout_ == nullptr) { + layout_ = new GridLayout(); + uint16_t height = Screen::GetInstance().GetHeight(); + + int heightOffset = 50; + layout_->SetPosition(BLOOD_LAYOUT_POSITION_X, 0, BLOOD_LAYOUT_WIDTH, + height - heightOffset); // 370: x , 320: width, 50: offset + container[BLOOD_START]->Add(layout_); + layout_->SetLayoutDirection(LAYOUT_VER); + layout_->SetRows(SET_NINE); // 9 : rows + layout_->SetCols(SET_TWO); // 2 : columns + } + InitImageInfo(); +} + +void BloodView::InitStart() +{ + if (group == nullptr) { + group = new UIViewGroup(); + } + group->SetPosition(0, 0); + group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + UIView::OnDragListener *dragListener = static_cast(BloodPresenter::GetInstance()); + if (dragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "start dragListener = nullptr"); + } + group->SetOnDragListener(dragListener); + group->SetViewId("startPage"); + group->SetDraggable(true); + group->SetTouchable(true); + + if (button == nullptr) { + button = new UILabelButton(); + } + button->SetPosition(BLOOD_BUTTON_POSITION_X, + BLOOD_BUTTON_TWO_POSITION_Y); // widget's left position and top position + button->Resize(BLOOD_BUTTON_TWO_WIDTH, BLOOD_BUTTON_HEIGHT); // widget's width and height + button->SetViewId("button1"); // Set style + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)(BloodPresenter::GetInstance()); + button->SetOnClickListener(clickListener); + button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + button->SetVisible(true); + button->SetText("开始"); + + group->Add(currentTime_); + group->Add(button); + container[BLOOD_START] = group; + + AddViewToRootContainer(container[BLOOD_START]); + GetRootContainer()->Invalidate(); +} + +void BloodView::InitTest() +{ + if (groupTest == nullptr) { + groupTest = new UIViewGroup(); + } + groupTest->SetPosition(0, 0); + groupTest->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + + UIView::OnDragListener *dragListener = static_cast(BloodPresenter::GetInstance()); + if (dragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init test dragListener = nullptr"); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init test dragListener successful"); + + groupTest->SetOnDragListener(dragListener); + groupTest->SetViewId("testPage"); + groupTest->SetDraggable(true); + groupTest->SetTouchable(true); + + if (label1_ == nullptr) { + label1_ = new UILabel(); + } + + label1_->SetPosition(BLOOD_LABEL1_POSITION_X, BLOOD_LABEL1_POSITION_Y); // widget's left position and top position + label1_->Resize(BLOOD_LABEL1_WIDTH, BLOOD_LABEL1_HEIGHT); // widget's width and height + label1_->SetViewId("label1"); // Set style + label1_->SetStyle(STYLE_TEXT_FONT, BLOOD_LABEL_FRONT1); + + // Set additional property + label1_->SetText("99%"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABEL_FRONT1); + + // Add to rootView + label1_->SetVisible(true); + + // Add Label to App + if (label2_ == nullptr) { + label2_ = new UILabel(); + } + + label2_->SetPosition(BLOOD_LABEL2_POSITION_X, BLOOD_LABEL2_POSITION_Y); // widget's left position and top position + label2_->Resize(BLOOD_LABEL2_WIDTH, BLOOD_LABEL2_HEIGHT); // widget's width and height + label2_->SetViewId("label1"); // Set style + label2_->SetStyle(STYLE_TEXT_FONT, BLOOD_LABEL_FRONT); + + // Set additional property + label2_->SetText("血氧"); + label2_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label2_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label2_->SetRollSpeed(0); + label2_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_LABEL_FRONT); + label2_->SetVisible(true); + + // Add to rootView + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init test label successful"); + + if (buttonMore == nullptr) { + buttonMore = new UILabelButton(); + } + + buttonMore->SetPosition(BLOOD_BUTTON_POSITION_X, + BLOOD_BUTTON_POSITION_Y); // widget's left position and top position + buttonMore->Resize(BLOOD_BUTTON_WIDTH, BLOOD_BUTTON_HEIGHT); // widget's width and height + buttonMore->SetViewId("button2"); // Set style + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)(BloodPresenter::GetInstance()); + buttonMore->SetOnClickListener(clickListener); + buttonMore->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + buttonMore->SetVisible(true); + buttonMore->SetText("了解更多"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init test button successful"); + + groupTest->Add(label1_); + groupTest->Add(label2_); + groupTest->Add(currentTime_); + groupTest->Add(buttonMore); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init test add button successful"); +} + +void BloodView::InitMore() +{ + if (scrollGroup == nullptr) { + scrollGroup = new UIScrollView(); + } + scrollGroup->Add(currentTime_); + + scrollGroup->SetViewId("moreGroup"); + scrollGroup->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scrollGroup->SetThrowDrag(true); + scrollGroup->SetScrollBlankSize(50); // 50:font size + UIView::OnDragListener *listener = static_cast(BloodPresenter::GetInstance()); + scrollGroup->SetOnDragListener(listener); + scrollGroup->SetDraggable(true); + scrollGroup->SetTouchable(true); + if (!InitSimilarLabel(SET_ZERO, BLOOD_LABEL_FIRST_Y, BLOOD_LABEL_ONE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempJoinStudy::TempInitLabel new tempLabel[SET_ZERO] error"); + } + if (!InitSimilarLabel(SET_ONE, BLOOD_LABEL_SECOND_Y, BLOOD_LABEL_TWO)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempJoinStudy::TempInitLabel new tempLabel[SET_ONE] error"); + } + if (!InitSimilarLabel(SET_TWO, BLOOD_LABEL_THIRD_Y, BLOOD_LABEL_THREE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempJoinStudy::TempInitLabel new tempLabel[SET_ONE] error"); + } +} + +bool BloodView::InitSimilarLabel(int16 num, int16 labelY, const char *labelText) +{ + tempLabel[num] = new UILabel(); + if (tempLabel[num] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempJoinStudy::TempInitLabel new tempLabel[%d] error", num); + return false; + } + tempLabel[num]->SetPosition(BLOOD_LABEL_FIRST_X, labelY, BLOOD_LABEL_FIRST_WIDTH, BLOOD_LABEL_FIRST_HEIGHT); + tempLabel[num]->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + tempLabel[num]->SetText(labelText); + tempLabel[num]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLOOD_FIRST_LABEL_FONT); + scrollGroup->Add(tempLabel[num]); + + return true; +} + +bool BloodView::TempInitLabel(void) +{ + scrollGroup->Add(currentTime_); + UIView::OnDragListener *dragListener = static_cast(BloodPresenter::GetInstance()); + if (dragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init more dragListener = nullptr"); + } + if (!InitSimilarLabel(SET_ZERO, BLOOD_LABEL_FIRST_Y, BLOOD_LABEL_ONE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempJoinStudy::TempInitLabel new tempLabel[SET_ZERO] error"); + return false; + } + if (!InitSimilarLabel(SET_ONE, BLOOD_LABEL_SECOND_Y, BLOOD_LABEL_TWO)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempJoinStudy::TempInitLabel new tempLabel[SET_ONE] error"); + return false; + } + if (!InitSimilarLabel(SET_TWO, BLOOD_LABEL_THIRD_Y, BLOOD_LABEL_THREE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempJoinStudy::TempInitLabel new tempLabel[SET_ONE] error"); + return false; + } + return true; +} + +void BloodView::InitImageInfo() +{ + const uint16_t pixelByteSize = 4; // 4: bytes per pixel + const uint16_t width = 100; // 100: image's width + const uint16_t height = 100; // 100: image's height + uint32_t dataSize = width * height * pixelByteSize; + uint8_t *srcData1 = static_cast(UIMalloc(dataSize)); + if (srcData1 == nullptr) { + return; + } + + for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { + srcData1[i] = SET_INT_MAX; // 255: pixel value + srcData1[i + 1] = 0; // 1: set green channel + srcData1[i + 2] = 0; // 2: set red channel + srcData1[i + 3] = OPA_OPAQUE; // 3: set alpha channel + } + imageInfo1_ = static_cast(UIMalloc(sizeof(ImageInfo))); + if (imageInfo1_ == nullptr) { + UIFree(srcData1); + return; + } + + imageInfo1_->header.width = width; + imageInfo1_->header.height = height; + imageInfo1_->header.colorMode = ColorMode::ARGB8888; + imageInfo1_->dataSize = dataSize; + imageInfo1_->data = srcData1; + + uint8_t *srcData2 = static_cast(UIMalloc(dataSize)); + if (srcData2 == nullptr) { + UIFree(imageInfo1_); + UIFree(srcData1); + return; + } + for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { + srcData2[i] = 0; // set blue channel + srcData2[i + 1] = SET_INT_MAX; // 1: set green channel 255: pixel value + srcData2[i + 2] = 0; // 2: set red channel + srcData2[i + 3] = OPA_OPAQUE; // 3: set alpha channel + } + + imageInfo2_ = static_cast(UIMalloc(sizeof(ImageInfo))); + if (imageInfo2_ == nullptr) { + UIFree(srcData2); + UIFree(imageInfo1_); + UIFree(srcData1); + return; + } + imageInfo2_->header.width = width; + imageInfo2_->header.height = height; + imageInfo2_->header.colorMode = ARGB8888; + imageInfo2_->dataSize = dataSize; + imageInfo2_->data = srcData2; + + uint8_t *srcData3 = static_cast(UIMalloc(dataSize)); + if (srcData3 == nullptr) { + UIFree(imageInfo2_); + UIFree(srcData2); + UIFree(imageInfo1_); + UIFree(srcData1); + return; + } + for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { + srcData3[i] = 0; // set blue channel + srcData3[i + 1] = 0; // 1: set green channel + srcData3[i + 2] = SET_INT_MAX; // 2: set red channel 255: pixel value + srcData3[i + 3] = OPA_OPAQUE; // 3: set alpha channel + } + + imageInfo3_ = static_cast(UIMalloc(sizeof(ImageInfo))); + if (imageInfo3_ == nullptr) { + UIFree(srcData3); + UIFree(imageInfo2_); + UIFree(srcData2); + UIFree(imageInfo1_); + UIFree(srcData1); + return; + } + imageInfo3_->header.width = width; + imageInfo3_->header.height = height; + imageInfo3_->header.colorMode = ARGB8888; + imageInfo3_->dataSize = dataSize; + imageInfo3_->data = srcData3; + + imageAnimatorImageInfo_[0].imageInfo = imageInfo1_; + imageAnimatorImageInfo_[0].pos = {BLOOD_IMAGEANIMATOR_POSITION_X, BLOOD_IMAGEANIMATOR_POSITION_Y}; + imageAnimatorImageInfo_[0].width = BLOOD_IMAGEANIMATOR_WIDTH; // 100: width value + imageAnimatorImageInfo_[0].height = BLOOD_IMAGEANIMATOR_HEIGHT; // 100: height value + imageAnimatorImageInfo_[0].imageType = IMG_SRC_IMAGE_INFO; + + imageAnimatorImageInfo_[1].imageInfo = imageInfo2_; + imageAnimatorImageInfo_[1].pos = {BLOOD_IMAGEANIMATOR_POSITION_X, BLOOD_IMAGEANIMATOR_POSITION_Y}; + imageAnimatorImageInfo_[1].width = BLOOD_IMAGEANIMATOR_WIDTH; // 100: width value + imageAnimatorImageInfo_[1].height = BLOOD_IMAGEANIMATOR_HEIGHT; // 100: height value + imageAnimatorImageInfo_[1].imageType = IMG_SRC_IMAGE_INFO; + + imageAnimatorImageInfo_[2].imageInfo = imageInfo3_; // 2: image index + imageAnimatorImageInfo_[2].pos = {BLOOD_IMAGEANIMATOR_POSITION_X, BLOOD_IMAGEANIMATOR_POSITION_Y}; // 2: image index + imageAnimatorImageInfo_[2].width = BLOOD_IMAGEANIMATOR_WIDTH; // 2: image index, 100: width value + imageAnimatorImageInfo_[2].height = BLOOD_IMAGEANIMATOR_HEIGHT; // 2: image index, 100: height value + imageAnimatorImageInfo_[2].imageType = IMG_SRC_IMAGE_INFO; // 2: image index +} + +void BloodView::UpdateCurrentTimeLabel(const char *currentTime) +{ + currentTime_->SetText(currentTime); + currentTime_->Invalidate(); +} + +bool BloodView::IsCurrentTimeLabelValid() +{ + return currentTime_ != nullptr ? true : false; +} + +void BloodView::DropView(UIView &view, int type) +{ + if (type == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::DropView::container[WEATHER_ondrop]-0"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::DropView::container[WEATHER_ondrop] view name :%s", + view.GetViewId()); + if (&view == container[BLOOD_START]) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::DropView::container[CHANGE_INTERFACE_CONFIG]-0"); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } else if (&view == container[BLOOD_TEST]) { + ChangeView(BLOOD_TEST, BLOOD_START); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::DropView::container[BLOOD_START]-0"); + } else if (&view == container[BLOOD_MORE]) { + ChangeView(BLOOD_MORE, BLOOD_TEST); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::DropView::container[WEATHER_SCROLL]-0"); + } + } else if (type == 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::DropView::container[WEATHER_ondrop] view name :%s", + view.GetViewId()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::DropView::container[WEATHER_ondrop]-1"); + if (&view == button || view.GetViewId() == "button1") { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::DropView::container[WEATHER_SWIPE]-1"); + ChangeView(BLOOD_START, BLOOD_TEST); + } else if (&view == buttonMore || view.GetViewId() == "button1") { + ChangeView(BLOOD_TEST, BLOOD_MORE); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::DropView::container[WEATHER_SCROLL]-1"); + } else if (&view == container[BLOOD_MORE]) { + } + } +} + +bool BloodView::ChangeBloodStart(int16_t thisView) +{ + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodView::WeatherGroupView"); + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool BloodView::ChangeBloodTest(int16_t thisView) +{ + if (container[thisView] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::ChangeBloodTest"); + InitTest(); + container[thisView] = groupTest; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool BloodView::ChangeBloodMore(int16_t thisView) +{ + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodView::WeatherScrollView"); + InitMore(); + container[thisView] = scrollGroup; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +struct BloodViewMapper { + uint16_t viewId; + bool (BloodView::*func)(int16 thisView); +}; + +static const BloodViewMapper ViewMapper[] = { + {BLOOD_START, &BloodView::ChangeBloodStart}, + {BLOOD_TEST, &BloodView::ChangeBloodTest}, + {BLOOD_MORE, &BloodView::ChangeBloodMore}, +}; + +bool BloodView::ClickFunc(int16 interf) +{ + int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); + for (int i = 0; i < funcSize; i++) { + if (interf == ViewMapper[i].viewId) { + bool jug = (this->*(ViewMapper[i].func))(interf); + if (!jug) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView:: ChangeInterFace[%d] false", interf); + return false; + } + return true; + } + } + return false; +} + +void BloodView::ChangeView(int16 hideView, int16 showView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodView::ChangeView hideView = %d, showView = %d", hideView, showView); + if (hideView > MAX_BLOOD_PAGE) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::ChangeView Overstep ones bounds"); + return; + } + if (!ClickFunc(showView)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::ChangeView ClickFunc ercror"); + return; + } + container[hideView]->SetVisible(false); + container[showView]->SetVisible(true); + Draw(); + return; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodBandoffView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodBandoffView.cpp index 656cf1bf1..894ffd66c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodBandoffView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodBandoffView.cpp @@ -6,8 +6,8 @@ */ #include "UiConfig.h" #include "wearable_log.h" -#include "BloodBandoffView.h" -#include "BloodOxygenModel.h" +#include "bloodoxygen/BloodBandoffView.h" +#include "bloodoxygen/BloodOxygenModel.h" namespace OHOS { // 动态显示图片设置 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp index c6f083a43..edad7933b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp @@ -5,7 +5,7 @@ * Create: 2021-08-01 */ -#include "BloodOxygenModel.h" +#include "bloodoxygen/BloodOxygenModel.h" namespace OHOS { BloodOxygenModel::BloodOxygenModel() 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 c7bcfe376..84d8e0897 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp @@ -5,14 +5,14 @@ * Create: 2021-08-01 */ -#include "BloodOxygenPresenter.h" +#include "bloodoxygen/BloodOxygenPresenter.h" #include "common/task_manager.h" -#include "BloodOxygenView.h" -#include "BloodOxygenModel.h" +#include "bloodoxygen/BloodOxygenView.h" +#include "bloodoxygen/BloodOxygenModel.h" #include "components/ui_label.h" -#include "BloodBandoffView.h" +#include "bloodoxygen/BloodBandoffView.h" #include "ChangeSliceListener.h" -#include "ui_service.h" +#include "uiservice/ui_service.h" #include "NativeRegisterManager.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenView.cpp index d6ee39ad4..5b2ade831 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/src/BloodOxygenView.cpp @@ -5,8 +5,8 @@ * Create: 2021-08-01 */ -#include "BloodOxygenView.h" -#include "BloodOxygenModel.h" +#include "bloodoxygen/BloodOxygenView.h" +#include "bloodoxygen/BloodOxygenModel.h" namespace OHOS { // 按钮设置 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothCaseListAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothCaseListAdapter.cpp index 763f631ce..06dc76ba1 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothCaseListAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothCaseListAdapter.cpp @@ -5,13 +5,13 @@ * Create: 2021-07-26 */ #include -#include "BluetoothCaseListAdapter.h" -#include "BluetoothEarPhoneView.h" +#include "bluetooth/BluetoothCaseListAdapter.h" +#include "bluetooth/BluetoothEarPhoneView.h" #include "gfx_utils/list.h" -#include "PlayersPresenter.h" +#include "player/PlayersPresenter.h" #include "wearable_log.h" #include "UiConfig.h" -#include "BluetoothModel.h" +#include "bluetooth/BluetoothModel.h" namespace OHOS { BluetoothCaseListAdapter::~BluetoothCaseListAdapter() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp index f2950ec01..ed234cca2 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp @@ -5,13 +5,13 @@ * Create: 2021-07-26 */ #include -#include "BluetoothDeviceCaseListAdapter.h" -#include "BluetoothOptionsView.h" +#include "bluetooth/BluetoothDeviceCaseListAdapter.h" +#include "bluetooth/BluetoothOptionsView.h" #include "gfx_utils/list.h" -#include "BluetoothModel.h" +#include "bluetooth/BluetoothModel.h" #include "wearable_log.h" #include "UiConfig.h" -#include "BluetoothPresenter.h" +#include "bluetooth/BluetoothPresenter.h" namespace OHOS { BluetoothDeviceCaseListAdapter::~BluetoothDeviceCaseListAdapter() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothDeviceListView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothDeviceListView.cpp index 94ef720d7..abcad4678 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothDeviceListView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothDeviceListView.cpp @@ -4,12 +4,12 @@ * Author: * Create: 2021-10-13 */ -#include "BluetoothDeviceListView.h" +#include "bluetooth/BluetoothDeviceListView.h" #include "wearable_log.h" #include "UiConfig.h" -#include "PlayersPresenter.h" -#include "BluetoothPresenter.h" -#include "BluetoothModel.h" +#include "player/PlayersPresenter.h" +#include "bluetooth/BluetoothPresenter.h" +#include "bluetooth/BluetoothModel.h" namespace OHOS { static BluetoothDeviceListView *g_pBluetoothDeviceListView{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothEarListView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothEarListView.cpp index daf4cf89d..190747bde 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothEarListView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothEarListView.cpp @@ -4,13 +4,13 @@ * Author: * Create: 2021-10-13 */ -#include "BluetoothModel.h" -#include "BluetoothEarListView.h" +#include "bluetooth/BluetoothModel.h" +#include "bluetooth/BluetoothEarListView.h" #include "wearable_log.h" #include "UiConfig.h" -#include "PlayersPresenter.h" -#include "BluetoothPresenter.h" -#include "SettingModel.h" +#include "player/PlayersPresenter.h" +#include "bluetooth/BluetoothPresenter.h" +#include "settings/SettingModel.h" namespace OHOS { static BluetoothEarListView *g_pBluetoothEarListView{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp index 7253ed754..5c85b6d00 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp @@ -5,13 +5,13 @@ * Create: 2021-10-13 */ #include -#include "BluetoothEarPhoneView.h" +#include "bluetooth/BluetoothEarPhoneView.h" #include "wearable_log.h" #include "UiConfig.h" -#include "BluetoothPresenter.h" -#include "PlayersPresenter.h" -#include "BluetoothItemView.h" -#include "SettingModel.h" +#include "bluetooth/BluetoothPresenter.h" +#include "player/PlayersPresenter.h" +#include "bluetooth/BluetoothItemView.h" +#include "settings/SettingModel.h" #include "common/image_cache_manager.h" #include "graphic_service.h" 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 6ac112db8..a036e7628 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp @@ -5,10 +5,10 @@ * Create: 2022-3-22 */ -#include "BluetoothHeadsetEvent.h" +#include "bluetooth/BluetoothHeadsetEvent.h" #include "bts_avrcp_target.h" #include "bts_avrcp_controller.h" -#include "PlayersModel.h" +#include "player/PlayersModel.h" #include "graphic_service.h" using namespace OHOS; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothItemView.cpp index 676c0183e..a05ca8591 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothItemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothItemView.cpp @@ -5,7 +5,7 @@ * Create: 2021-10-13 */ -#include "BluetoothItemView.h" +#include "bluetooth/BluetoothItemView.h" #include "wearable_log.h" #include "UiConfig.h" #include "common/image_cache_manager.h" 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 abea09a37..cf54e84df 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp @@ -5,14 +5,14 @@ * Create: 2021-10-13 */ #include -#include "BluetoothModel.h" -#include "BluetoothWrapper.h" -#include "BluetoothPresenter.h" -#include "ConnectPhonePresenter.h" -#include "BluetoothView.h" -#include "BluetoothItemView.h" -#include "PlayersModel.h" -#include "PhoneAudio.h" +#include "bluetooth/BluetoothModel.h" +#include "bluetooth/BluetoothWrapper.h" +#include "bluetooth/BluetoothPresenter.h" +#include "connectnewphone/ConnectPhonePresenter.h" +#include "player/BluetoothView.h" +#include "bluetooth/BluetoothItemView.h" +#include "player/PlayersModel.h" +#include "phoneservice/PhoneAudio.h" #include "graphic_service.h" #include "msg_center.h" #include "bts_def.h" @@ -35,8 +35,11 @@ #include "msg_center_protocol.h" #include "dfx_channel.h" #include "tcxo.h" -#include "ui_service.h" +#include "uiservice/ui_service.h" #include "network/network_listener.h" +#if defined(SUPPORT_LWIP) && defined(SUPPORT_BREDR) +#include "lwip_driver_adapter.h" +#endif namespace OHOS { #define BT_SPP_TASK_STACK_SIZE 2048 @@ -849,6 +852,36 @@ void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned } } +void ChangeBleConnectToMax() +{ + if (msg_center_get_trans_channel() == DIAG_FRAME_FID_BT) { + gap_conn_param_update_t conn_param = { 0 }; + conn_param.conn_handle = BLUETOOTH_CONN_HANDLE; + conn_param.interval_min = BLUETOOTH_INTERVAL_TOMAX_MIN; + conn_param.interval_max = BLUETOOTH_INTERVAL_TOMAX_MAX; + conn_param.slave_latency = BLUETOOTH_LATENCY; + conn_param.timeout_multiplier = BLUETOOTH_TIMEOUT_MUTIPLIER; + errcode_t ret = gap_ble_connect_param_update(&conn_param); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BleConnectCallback change to max interval ret:%d : latency-min:%u latency-max:%u\n", + ret, conn_param.interval_min, conn_param.interval_max); + } +} + +void ChangeBleConnectToDefault() +{ + if (msg_center_get_trans_channel() == DIAG_FRAME_FID_BT) { + gap_conn_param_update_t conn_param = { 0 }; + conn_param.conn_handle = BLUETOOTH_CONN_HANDLE; + conn_param.interval_min = BLUETOOTH_INTERVAL_TODEFAULT_MIN; + conn_param.interval_max = BLUETOOTH_INTERVAL_TODEFAULT_MAX; + conn_param.slave_latency = BLUETOOTH_LATENCY; + conn_param.timeout_multiplier = BLUETOOTH_TIMEOUT_MUTIPLIER; + errcode_t ret = gap_ble_connect_param_update(&conn_param); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BleConnectCallback change to default interval ret:%d : latency-min:%u latency-max:%u\n", + ret, conn_param.interval_min, conn_param.interval_max); + } +} + // 回调:ACL连接状态上报 void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason) { @@ -872,6 +905,9 @@ void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, SendMsgToUIService(BT_CONNECTED_TO_UI, 0, nullptr, 0); // send to ace network // SetAclConnected(true); +#if defined(SUPPORT_LWIP) && defined(SUPPORT_BREDR) + bt_pan_open(); +#endif net_connect_status_change(NETWORK_TYPE_BLUETOOTH, CONNECTION_STATUS_CONNECTED); } return; @@ -1299,6 +1335,11 @@ static a2dp_snk_callbacks_t g_a2dp_snk_callbacks = { BtA2dpSnkConfigChangedCb }; +static void BleConnectCallback(uint16_t conn_id, errcode_t status, const gap_ble_conn_param_update_t *param) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BleConnectCallback conn_id:%u, interval-1:%u latency:%u timeout:%u\n",conn_id, param->interval, param->latency, param->timeout); +} + void BtInitCallBacks() { g_btGapCallBacks.discovery_result_callback = BtGapDiscoveryResultCallback; @@ -1327,6 +1368,7 @@ void BtInitCallBacksEx() g_gapBleCallbacks.start_adv_cb = BleAdvStartCallback; g_gapBleCallbacks.stop_adv_cb = BleAdvStopCallback; g_gapBleCallbacks.terminate_adv_cb = BleAdvTerminateCallback; + g_gapBleCallbacks.conn_param_update_cb = BleConnectCallback; wrapper_gap_ble_register_callbacks(&g_gapBleCallbacks); g_btGattsCallbacks.add_service_cb = BtGattsServiceAddCallback; @@ -1411,10 +1453,6 @@ void BtSppServerCreate(const char *spp_uuid, const char *name, uint8_t name_len) param.socket_type = SPP_SOCKET_RFCOMM; param.is_encrypt = true; - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "uuid: %s uuid_len: %u\n", spp_uuid, param.uuid.uuid_len); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "socket_type: %x is_encrypt: %d name: %s nameLen: %u\n", param.socket_type, - param.is_encrypt, name, name_len); - int ret = spp_server_create(¶m, name, name_len); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "spp_server_create ret: %x\n", ret); } @@ -1422,12 +1460,9 @@ void BtSppServerCreate(const char *spp_uuid, const char *name, uint8_t name_len) static int BtSppServerAcceptTaskBody(void *data) { int server_id = (int)(intptr_t)data; - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "server_id: %x\n", server_id); - int ret = spp_server_accept(server_id); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "spp_server_accept ret: %x\n", ret); - + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "spp_server_accept ret: %x, server_id: %d\r\n", ret, server_id); return OSAL_SUCCESS; } @@ -1445,8 +1480,6 @@ void BtSppServerAccept(uint8_t server_id) if (ret != OSAL_SUCCESS) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "set pri error: %08x\n", ret); } - - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "create task success.\n"); } void BtInitSpp(void) diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothOptionsView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothOptionsView.cpp index a2c367198..ae254eaa6 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothOptionsView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothOptionsView.cpp @@ -4,12 +4,12 @@ * Author: * Create: 2021-10-13 */ -#include "BluetoothOptionsView.h" -#include "BluetoothModel.h" +#include "bluetooth/BluetoothOptionsView.h" +#include "bluetooth/BluetoothModel.h" #include "wearable_log.h" #include "UiConfig.h" -#include "PlayersPresenter.h" -#include "BluetoothPresenter.h" +#include "player/PlayersPresenter.h" +#include "bluetooth/BluetoothPresenter.h" namespace OHOS { static BluetoothOptionsView *g_pBluetoothOptionsView{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp index bcb1aa3bb..e3e472450 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp @@ -7,9 +7,9 @@ #include "wearable_log.h" #include "UiConfig.h" -#include "BluetoothPresenter.h" -#include "BluetoothReconnectView.h" -#include "MainBluetoothView.h" +#include "bluetooth/BluetoothPresenter.h" +#include "bluetooth/BluetoothReconnectView.h" +#include "bluetooth/MainBluetoothView.h" #include "NativeRegisterManager.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothReconnectView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothReconnectView.cpp index ad2334248..c1bea7573 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothReconnectView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothReconnectView.cpp @@ -4,12 +4,12 @@ * Create: 2021-10-13 */ -#include "BluetoothReconnectView.h" -#include "BluetoothModel.h" +#include "bluetooth/BluetoothReconnectView.h" +#include "bluetooth/BluetoothModel.h" #include "wearable_log.h" #include "UiConfig.h" -#include "PlayersPresenter.h" -#include "BluetoothPresenter.h" +#include "player/PlayersPresenter.h" +#include "bluetooth/BluetoothPresenter.h" #include "common/image_cache_manager.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp index 22e85a984..0e074c908 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp @@ -6,7 +6,7 @@ */ #include -#include "BluetoothWrapper.h" +#include "bluetooth/BluetoothWrapper.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp index 5e1ca8918..a7a242543 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp @@ -4,8 +4,8 @@ * Author: * Create: 2021-10-13 */ -#include "MainBluetoothView.h" -#include "BluetoothModel.h" +#include "bluetooth/MainBluetoothView.h" +#include "bluetooth/BluetoothModel.h" #include "wearable_log.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsConnFailMessageView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsConnFailMessageView.cpp index 552f968aa..21fb3c440 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsConnFailMessageView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsConnFailMessageView.cpp @@ -4,12 +4,12 @@ * Author: * Create: 2021-10-13 */ -#include "TipsConnFailMessageView.h" -#include "BluetoothModel.h" +#include "bluetooth/TipsConnFailMessageView.h" +#include "bluetooth/BluetoothModel.h" #include "wearable_log.h" #include "UiConfig.h" -#include "PlayersPresenter.h" -#include "BluetoothPresenter.h" +#include "player/PlayersPresenter.h" +#include "bluetooth/BluetoothPresenter.h" namespace OHOS { static TipsConnFailMessageView *g_pConnFailMessageView{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsFailMessageView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsFailMessageView.cpp index 4d732b85d..ad592dc90 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsFailMessageView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsFailMessageView.cpp @@ -4,12 +4,12 @@ * Author: * Create: 2021-10-13 */ -#include "TipsFailMessageView.h" -#include "BluetoothModel.h" +#include "bluetooth/TipsFailMessageView.h" +#include "bluetooth/BluetoothModel.h" #include "wearable_log.h" #include "UiConfig.h" -#include "PlayersPresenter.h" -#include "BluetoothPresenter.h" +#include "player/PlayersPresenter.h" +#include "bluetooth/BluetoothPresenter.h" namespace OHOS { static TipsFailMessageView *g_pFailMessageView{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsSuccMessageView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsSuccMessageView.cpp index 9bab50fa8..99b0a7f73 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsSuccMessageView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/TipsSuccMessageView.cpp @@ -4,12 +4,12 @@ * Author: * Create: 2021-10-13 */ -#include "TipsSuccMessageView.h" -#include "BluetoothModel.h" +#include "bluetooth/TipsSuccMessageView.h" +#include "bluetooth/BluetoothModel.h" #include "wearable_log.h" #include "UiConfig.h" -#include "PlayersPresenter.h" -#include "BluetoothPresenter.h" +#include "player/PlayersPresenter.h" +#include "bluetooth/BluetoothPresenter.h" namespace OHOS { static TipsSuccMessageView *g_pSuccMessageView{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathDurPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathDurPage.cpp new file mode 100644 index 000000000..fd888e58a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathDurPage.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathDurPage + * Create: 2025-5-13 + */ +#include "components/root_view.h" +#include "gfx_utils/graphic_math.h" +#include "UiConfig.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "alarm/MainAlarmView.h" +#include "TransitionType.h" +#include "SlicePageFactory.h" +#include "ui_resource_breath.h" +#include "main/LoadImg.h" +#include "breath/BreathView.h" +#include "breath/BreathDurPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_MAIN_BREATHEASE, BrearhView::BREATH_DUR_VIEW, BreathDurPage, false); + +#define WND_BTHDUR_BTN_OK_ID "BTH_DUR_OK" +#define WND_BTHDUR_TITLE_X 100 +#define WND_BTHDUR_TITLE_Y 38 +#define WND_BTHDUR_TITLE_W 253 +#define WND_BTHDUR_TITLE_H 53 +#define WND_BTHDUR_TITLE_FONT_SIZE 38 +#define WND_BTHDUR_PICKER_X 64 +#define WND_BTHDUR_PICKER_Y 109 +#define WND_BTHDUR_PICKER_W 321 +#define WND_BTHDUR_PICKER_H 218 +#define WND_BTHDUR_PICKER_B_FONT_SIZE 44 +#define WND_BTHDUR_PICKER_H_FONT_SIZE 44 +#define WND_BTHDUR_PICKER_ITEM_H 80 +#define WND_BTHDUR_OK_X 61 +#define WND_BTHDUR_OK_Y 362 +#define WND_BTHDUR_OK_W 331 +#define WND_BTHDUR_OK_H 98 +#define BREATH_GROUP_SIZE 466 + +BreathDurPage::BreathDurPage() {} + +BreathDurPage::~BreathDurPage() +{ + group->RemoveAll(); + if (lableTitle != nullptr) { + delete lableTitle; + lableTitle = nullptr; + } + if (pickerTime != nullptr) { + delete pickerTime; + pickerTime = nullptr; + } + if (buttonOk != nullptr) { + delete buttonOk; + buttonOk = nullptr; + } + if (group != nullptr) { + delete group; + group = nullptr; + } + if (center != nullptr) { + delete center; + center = nullptr; + } +} + +void BreathDurPage::OnStart(void *data) +{ + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathDurPage::OnStart new Group ERROR"); + group = new UIViewGroup(); + } + group->SetPosition(0, 0); + group->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + + if (lableTitle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathDurPage::OnStart new lableTitle ERROR"); + lableTitle = new UILabel(); + } + lableTitle->SetPosition(WND_BTHDUR_TITLE_X, WND_BTHDUR_TITLE_Y); + lableTitle->Resize(WND_BTHDUR_TITLE_W, WND_BTHDUR_TITLE_H); + lableTitle->SetText("时间设置"); + lableTitle->SetTextColor(Color::White()); + lableTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHDUR_TITLE_FONT_SIZE); + lableTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(lableTitle); + + if (pickerTime == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathDurPage::OnStart new pickerTime ERROR"); + pickerTime = new UIPicker(); + } + pickerTime->SetPosition(WND_BTHDUR_PICKER_X, WND_BTHDUR_PICKER_Y); + pickerTime->Resize(WND_BTHDUR_PICKER_W, WND_BTHDUR_PICKER_H); + pickerTime->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + pickerTime->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHDUR_PICKER_B_FONT_SIZE); + pickerTime->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHDUR_PICKER_H_FONT_SIZE); + pickerTime->SetItemHeight(WND_BTHDUR_PICKER_ITEM_H); + pickerTime->SetTextColor(Color::GetColorFromRGBA(0xfa, 0xf3, 0xf3, 0xff), + Color::GetColorFromRGBA(0xfa, 0xf3, 0xf3, 0xff)); + uint8_t selectTime = BreathModel::GetInstance().GetSelectTime(); + pickerTime->SetSelected(selectTime); + pickerTime->SetOnDragListener(this); + pickerTime->SetLoopState(false); + group->Add(pickerTime); + + if (center == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathDurPage::OnStart new center ERROR"); + center = new UIImageView(); + } + center->SetPosition(WND_BTHDUR_PICKER_X, WND_BTHDUR_PICKER_Y); + center->Resize(WND_BTHDUR_PICKER_W, WND_BTHDUR_PICKER_H); + LOADIMG::LoadImageViewImg(center, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH013); + group->Add(center); + + if (buttonOk == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathDurPage::OnStart new buttonOk ERROR"); + buttonOk = new UIButton(); + } + buttonOk->SetPosition(WND_BTHDUR_OK_X, WND_BTHDUR_OK_Y); + buttonOk->Resize(WND_BTHDUR_OK_W, WND_BTHDUR_OK_H); + buttonOk->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + buttonOk->SetViewId(WND_BTHDUR_BTN_OK_ID); + LOADIMG::LoadBtnImage(buttonOk, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH005, IMAGE_CONVERTER_TOOL_BREATH005); + buttonOk->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonOk->SetOnClickListener(this); + group->Add(buttonOk); + + AddViewToPageContainer(group); +} + +void BreathDurPage::OnStop() {} + +void BreathDurPage::OnResume() +{ + pickerTime->SetValues(BreathModel::GetInstance().GetDurListData(), BreathModel::GetInstance().GetDurListSize()); + GetSlicePageContainer()->SetIntercept(true); + GetSlicePageContainer()->SetOnDragListener(nullptr); +} + +void BreathDurPage::OnPause() {} + +bool BreathDurPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), WND_BTHDUR_BTN_OK_ID) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathDurPage OnClick...ChangeTo DUR"); + BreathModel::GetInstance().SetTimeDuration(pickerTime->GetSelected()); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_MAIN_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathDurPage OnClick...ChangeTo unknow"); + return false; + } + return true; +} + +bool BreathDurPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathDurPage::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, "BreathDurPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_MAIN_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + } + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathExerPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathExerPage.cpp new file mode 100644 index 000000000..92c689bb3 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathExerPage.cpp @@ -0,0 +1,323 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathExerPage + * Create: 2025-5-13 + */ +#include +#include +#include "gfx_utils/graphic_math.h" +#include "common/image_cache_manager.h" +#include "components/ui_image_animator.h" +#include "components/root_view.h" +#include "UiConfig.h" +#include "ohos_timer.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "ui_resource_breath.h" +#include "main/LoadImg.h" +#include "breath/BreathView.h" +#include "breath/BreathExerPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_MAIN_BREATHEASE, BrearhView::BREATH_EXER_VIEW, BreathExerPage, false); + +#define BREATH_GROUP_SIZE 454 +#define BREATH_ZERO 0 +#define BREATH_ONE 1 +#define BREATH_TWO 2 +#define BREATH_THREE 3 +static constexpr uint16_t BREATH_PHONE_IMAGE_POSITION_X = 0; +static constexpr uint16_t BREATH_PHONE_IMAGE_POSITION_y = 0; +static constexpr uint16_t BREATH_PHONE_IMAGE_WIDTH = 400; +static constexpr uint16_t BREATH_PHONE_IMAGE_HEIGHT = 400; +static constexpr uint16_t BREATH_PHONE_IMAGEANIMATOR_POSITION_X = 170; +static constexpr uint16_t BREATH_PHONE_IMAGEANIMATOR_POSITION_Y = 170; +static constexpr uint16_t BREATH_PHONE_IMAGEANIMATOR_WIDTH = 100; +static constexpr uint16_t BREATH_PHONE_IMAGEANIMATOR_HEIGHT = 100; +static constexpr uint16_t IMAGE_SIZE = 454; +static constexpr uint16_t IMAGEANIMATOERVIEW_SIZE = 80; +static constexpr uint16_t FIND_PHONE_IMAGE_X = 1; +static constexpr uint16_t FIND_PHONE_IMAGE_y = 1; +static constexpr uint16_t FIND_PHONE_PIXELBYTE_SIZE = 4; +static constexpr uint16_t FIND_PHONE_PIXELBYTEH = 100; +static constexpr uint16_t END_TIME = 20; + +const int g_imageAnimatorInfo[IMAGEANIMATOERVIEW_SIZE] = { + IMAGE_CONVERTER_TOOL_INOREX_HALE001, IMAGE_CONVERTER_TOOL_INOREX_HALE002, IMAGE_CONVERTER_TOOL_INOREX_HALE003, + IMAGE_CONVERTER_TOOL_INOREX_HALE004, IMAGE_CONVERTER_TOOL_INOREX_HALE005, IMAGE_CONVERTER_TOOL_INOREX_HALE006, + IMAGE_CONVERTER_TOOL_INOREX_HALE007, IMAGE_CONVERTER_TOOL_INOREX_HALE008, IMAGE_CONVERTER_TOOL_INOREX_HALE009, + IMAGE_CONVERTER_TOOL_INOREX_HALE010, IMAGE_CONVERTER_TOOL_INOREX_HALE011, IMAGE_CONVERTER_TOOL_INOREX_HALE012, + IMAGE_CONVERTER_TOOL_INOREX_HALE013, IMAGE_CONVERTER_TOOL_INOREX_HALE014, IMAGE_CONVERTER_TOOL_INOREX_HALE015, + IMAGE_CONVERTER_TOOL_INOREX_HALE016, IMAGE_CONVERTER_TOOL_INOREX_HALE017, IMAGE_CONVERTER_TOOL_INOREX_HALE018, + IMAGE_CONVERTER_TOOL_INOREX_HALE019, IMAGE_CONVERTER_TOOL_INOREX_HALE020, IMAGE_CONVERTER_TOOL_INOREX_HALE021, + IMAGE_CONVERTER_TOOL_INOREX_HALE022, IMAGE_CONVERTER_TOOL_INOREX_HALE023, IMAGE_CONVERTER_TOOL_INOREX_HALE024, + IMAGE_CONVERTER_TOOL_INOREX_HALE025, IMAGE_CONVERTER_TOOL_INOREX_HALE026, IMAGE_CONVERTER_TOOL_INOREX_HALE027, + IMAGE_CONVERTER_TOOL_INOREX_HALE028, IMAGE_CONVERTER_TOOL_INOREX_HALE029, IMAGE_CONVERTER_TOOL_INOREX_HALE030, + IMAGE_CONVERTER_TOOL_INOREX_HALE031, IMAGE_CONVERTER_TOOL_INOREX_HALE032, IMAGE_CONVERTER_TOOL_INOREX_HALE033, + IMAGE_CONVERTER_TOOL_INOREX_HALE034, IMAGE_CONVERTER_TOOL_INOREX_HALE035, IMAGE_CONVERTER_TOOL_INOREX_HALE036, + IMAGE_CONVERTER_TOOL_INOREX_HALE037, IMAGE_CONVERTER_TOOL_INOREX_HALE038, IMAGE_CONVERTER_TOOL_INOREX_HALE039, + IMAGE_CONVERTER_TOOL_INOREX_HALE040, IMAGE_CONVERTER_TOOL_INOREX_HALE041, IMAGE_CONVERTER_TOOL_INOREX_HALE042, + IMAGE_CONVERTER_TOOL_INOREX_HALE043, IMAGE_CONVERTER_TOOL_INOREX_HALE044, IMAGE_CONVERTER_TOOL_INOREX_HALE045, + IMAGE_CONVERTER_TOOL_INOREX_HALE046, IMAGE_CONVERTER_TOOL_INOREX_HALE047, IMAGE_CONVERTER_TOOL_INOREX_HALE048, + IMAGE_CONVERTER_TOOL_INOREX_HALE049, IMAGE_CONVERTER_TOOL_INOREX_HALE050, IMAGE_CONVERTER_TOOL_INOREX_HALE051, + IMAGE_CONVERTER_TOOL_INOREX_HALE052, IMAGE_CONVERTER_TOOL_INOREX_HALE053, IMAGE_CONVERTER_TOOL_INOREX_HALE054, + IMAGE_CONVERTER_TOOL_INOREX_HALE055, IMAGE_CONVERTER_TOOL_INOREX_HALE056, IMAGE_CONVERTER_TOOL_INOREX_HALE057, + IMAGE_CONVERTER_TOOL_INOREX_HALE058, IMAGE_CONVERTER_TOOL_INOREX_HALE059, IMAGE_CONVERTER_TOOL_INOREX_HALE060, + IMAGE_CONVERTER_TOOL_INOREX_HALE061, IMAGE_CONVERTER_TOOL_INOREX_HALE062, IMAGE_CONVERTER_TOOL_INOREX_HALE063, + IMAGE_CONVERTER_TOOL_INOREX_HALE064, IMAGE_CONVERTER_TOOL_INOREX_HALE065, IMAGE_CONVERTER_TOOL_INOREX_HALE066, + IMAGE_CONVERTER_TOOL_INOREX_HALE067, IMAGE_CONVERTER_TOOL_INOREX_HALE068, IMAGE_CONVERTER_TOOL_INOREX_HALE068, + IMAGE_CONVERTER_TOOL_INOREX_HALE069, IMAGE_CONVERTER_TOOL_INOREX_HALE070, IMAGE_CONVERTER_TOOL_INOREX_HALE071, + IMAGE_CONVERTER_TOOL_INOREX_HALE072, IMAGE_CONVERTER_TOOL_INOREX_HALE073, IMAGE_CONVERTER_TOOL_INOREX_HALE074, + IMAGE_CONVERTER_TOOL_INOREX_HALE075, IMAGE_CONVERTER_TOOL_INOREX_HALE076, IMAGE_CONVERTER_TOOL_INOREX_HALE077, + IMAGE_CONVERTER_TOOL_INOREX_HALE078, IMAGE_CONVERTER_TOOL_INOREX_HALE078, +}; + +BreathExerPage::BreathExerPage() {} + +BreathExerPage::~BreathExerPage() +{ + group->RemoveAll(); + if (group != nullptr) { + delete group; + group = nullptr; + } + if (imageAnimator_ != nullptr) { + delete imageAnimator_; + imageAnimator_ = nullptr; + } + if (animatorCallBack != nullptr) { + delete animatorCallBack; + animatorCallBack = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(BREATH_IMAGE); +} + +void BreathExerPage::OnStart(void *data) +{ + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::OnStart new group ERROR"); + group = new UIViewGroup(); + } + group->SetPosition(0, 0); + group->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group->SetTouchable(true); + group->SetDraggable(true); + group->SetOnDragListener(this); + + palyNumber = BreathModel::GetInstance().GetTheNumberOfPlays(); + SetUpImageAnimator(); + + imageAnimator_->Start(); + imageAnimator_->SetVisible(true); + animatorCallBack = new BreathExerPageCallback(this); + if (animatorCallBack == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::OnStart new animatorCallBack ERROR"); + return; + } + animation = new Animator(animatorCallBack, nullptr, 0, true); + if (animation == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::OnStart new animation ERROR"); + return; + } + animation->Start(); + + AddViewToPageContainer(group); +} +void BreathExerPage::OnStop() {} + +void BreathExerPage::SetUpImageAnimator() +{ + imageAnimator_ = new UIImageAnimatorView(); + if (imageAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::UIImageAnimatorView new Label SetUpImageAnimator fail"); + return; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathExerPage::SetUpImageAnimator "); + imageAnimator_ = new UIImageAnimatorView(); + for (uint32_t DATA = 0; DATA < IMAGEANIMATOERVIEW_SIZE; DATA++) { + searchImageInfo[DATA].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(g_imageAnimatorInfo[DATA], BREATH_IMAGE); + searchImageInfo[DATA].imageType = IMG_SRC_IMAGE_INFO; + searchImageInfo[DATA].pos.x = FIND_PHONE_IMAGE_X; + searchImageInfo[DATA].pos.y = FIND_PHONE_IMAGE_y; + searchImageInfo[DATA].width = IMAGE_SIZE; + searchImageInfo[DATA].height = IMAGE_SIZE; + } + imageAnimator_->SetPosition(BREATH_PHONE_IMAGE_POSITION_X, BREATH_PHONE_IMAGE_POSITION_y, BREATH_PHONE_IMAGE_WIDTH, + BREATH_PHONE_IMAGE_HEIGHT); + int imageNumber = IMAGEANIMATOERVIEW_SIZE; + int ImageUpdate = BreathModel::GetInstance().GetStatusRespiratory(); + imageAnimator_->SetImageAnimatorSrc(searchImageInfo, imageNumber, ImageUpdate); + imageAnimator_->LayoutCenterOfParent(); + imageAnimator_->SetDraggable(true); + imageAnimator_->SetRepeat(false); + imageAnimator_->SetRepeatTimes(palyNumber); + imageAnimator_->SetOnDragListener(this); + group->Add(imageAnimator_); + InitImageInfo(); +} + +void BreathExerPage::BreathExerPageCallback::Callback(UIView *view) +{ + UNUSED(view); + static int count = 0; + struct timeval currentTime; + uint32_t breathingTime; + + breathingTime = BreathModel::GetInstance().GetTimeBreathing(); + gettimeofday(¤tTime, nullptr); + int32_t StartTime = BreathModel::GetInstance().GetBeginsTime(); + int32_t remTime = breathingTime - (currentTime.tv_sec - StartTime); + if (remTime <= END_TIME) { + if (BreathExerPage->imageAnimator_->GetState() == false) { + BreathExerPage->animation->Stop(); + BreathExerPage->imageAnimator_->Stop(); + BreathExerPage->imageAnimator_->SetVisible(false); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_RESULT_VIEW, nullptr, + TransitionType::TRANSITION_INVALID, true); + } + } +} + +void BreathExerPage::OnPause() +{ + animation->Stop(); + imageAnimator_->Stop(); + imageAnimator_->SetVisible(false); +} + +bool BreathExerPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathExerPage::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, "BreathExerPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + animation->Stop(); + imageAnimator_->Stop(); + imageAnimator_->SetVisible(false); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_MAIN_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + } + return true; +} +void BreathExerPage::OnTimer() {} + +void BreathExerPage::InitImageInfo() +{ + const uint16_t pixelByteSize = FIND_PHONE_PIXELBYTE_SIZE; + const uint16_t width = FIND_PHONE_PIXELBYTEH; + const uint16_t height = FIND_PHONE_PIXELBYTEH; + uint32_t dataSize = width * height * pixelByteSize; + uint8_t *srcData1 = static_cast(UIMalloc(dataSize)); + if (srcData1 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::InitImageInfo new srcData1 ERROR"); + return; + } + + for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { + srcData1[i] = SET_INT_MAX_; + srcData1[i + BREATH_ONE] = 0; + srcData1[i + BREATH_TWO] = 0; + srcData1[i + BREATH_THREE] = OPA_OPAQUE; + } + imageInfoOen = static_cast(UIMalloc(sizeof(ImageInfo))); + if (imageInfoOen == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::InitImageInfo new imageInfoOen ERROR"); + UIFree(srcData1); + return; + } + + imageInfoOen->header.width = width; + imageInfoOen->header.height = height; + imageInfoOen->header.colorMode = ColorMode::ARGB8888; + imageInfoOen->dataSize = dataSize; + imageInfoOen->data = srcData1; + + uint8_t *srcData2 = static_cast(UIMalloc(dataSize)); + if (srcData2 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::InitImageInfo new srcData2 ERROR"); + UIFree(imageInfoOen); + UIFree(srcData1); + return; + } + for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { + srcData2[i] = 0; + srcData2[i + BREATH_ONE] = SET_INT_MAX_; + srcData2[i + BREATH_TWO] = 0; + srcData2[i + BREATH_THREE] = OPA_OPAQUE; + } + + imageInfoTwo = static_cast(UIMalloc(sizeof(ImageInfo))); + if (imageInfoTwo == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::InitImageInfo new imageInfoTwo ERROR"); + UIFree(srcData2); + UIFree(imageInfoOen); + UIFree(srcData1); + return; + } + imageInfoTwo->header.width = width; + imageInfoTwo->header.height = height; + imageInfoTwo->header.colorMode = ARGB8888; + imageInfoTwo->dataSize = dataSize; + imageInfoTwo->data = srcData2; + + uint8_t *srcData3 = static_cast(UIMalloc(dataSize)); + if (srcData3 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::InitImageInfo new srcData3 ERROR"); + UIFree(imageInfoTwo); + UIFree(srcData2); + UIFree(imageInfoOen); + UIFree(srcData1); + return; + } + for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { + srcData3[i] = 0; + srcData3[i + BREATH_ONE] = 0; + srcData3[i + BREATH_TWO] = SET_INT_MAX_; + srcData3[i + BREATH_THREE] = OPA_OPAQUE; + } + + imageInfoThree = static_cast(UIMalloc(sizeof(ImageInfo))); + if (imageInfoThree == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathExerPage::InitImageInfo new imageInfoThree ERROR"); + UIFree(srcData3); + UIFree(imageInfoTwo); + UIFree(srcData2); + UIFree(imageInfoOen); + UIFree(srcData1); + return; + } + imageInfoThree->header.width = width; + imageInfoThree->header.height = height; + imageInfoThree->header.colorMode = ARGB8888; + imageInfoThree->dataSize = dataSize; + imageInfoThree->data = srcData3; + + imageAnimatorImageInfo[BREATH_ZERO].imageInfo = imageInfoOen; + imageAnimatorImageInfo[BREATH_ZERO].pos = {BREATH_PHONE_IMAGEANIMATOR_POSITION_X, + BREATH_PHONE_IMAGEANIMATOR_POSITION_Y}; + imageAnimatorImageInfo[BREATH_ZERO].width = BREATH_PHONE_IMAGEANIMATOR_WIDTH; + imageAnimatorImageInfo[BREATH_ZERO].height = BREATH_PHONE_IMAGEANIMATOR_HEIGHT; + imageAnimatorImageInfo[BREATH_ZERO].imageType = IMG_SRC_IMAGE_INFO; + + imageAnimatorImageInfo[BREATH_ONE].imageInfo = imageInfoTwo; + imageAnimatorImageInfo[BREATH_ONE].pos = {BREATH_PHONE_IMAGEANIMATOR_POSITION_X, + BREATH_PHONE_IMAGEANIMATOR_POSITION_Y}; + imageAnimatorImageInfo[BREATH_ONE].width = BREATH_PHONE_IMAGEANIMATOR_WIDTH; + imageAnimatorImageInfo[BREATH_ONE].height = BREATH_PHONE_IMAGEANIMATOR_HEIGHT; + imageAnimatorImageInfo[BREATH_ONE].imageType = IMG_SRC_IMAGE_INFO; + + imageAnimatorImageInfo[BREATH_TWO].imageInfo = imageInfoThree; + imageAnimatorImageInfo[BREATH_TWO].pos = {BREATH_PHONE_IMAGEANIMATOR_POSITION_X, + BREATH_PHONE_IMAGEANIMATOR_POSITION_Y}; + imageAnimatorImageInfo[BREATH_TWO].width = BREATH_PHONE_IMAGEANIMATOR_WIDTH; + imageAnimatorImageInfo[BREATH_TWO].height = BREATH_PHONE_IMAGEANIMATOR_HEIGHT; + imageAnimatorImageInfo[BREATH_TWO].imageType = IMG_SRC_IMAGE_INFO; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathMainPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathMainPage.cpp new file mode 100644 index 000000000..3b12ef70f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathMainPage.cpp @@ -0,0 +1,253 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathMainPage + * Create: 2025-5-13 + */ +#include "gfx_utils/graphic_math.h" +#include "UiConfig.h" +#include "AppViewIDs.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "alarm/MainAlarmView.h" +#include "NativeAbility.h" +#include "TransitionType.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "ui_resource_breath.h" +#include "main/LoadImg.h" +#include "breath/BreathModel.h" +#include "breath/BreathMainPage.h" + +namespace OHOS { + +#define WND_BTHMAIN_BTN_DUR_ID "BTH_MAIN_DUR" +#define WND_BTHMAIN_BTN_RHY_ID "BTH_MAIN_RHY" +#define WND_BTHMAIN_BTN_START_ID "BTH_MAIN_START" +#define WND_BTHMAIN_TITLE_X 97 +#define WND_BTHMAIN_TITLE_Y 34 +#define WND_BTHMAIN_TITLE_W 260 +#define WND_BTHMAIN_TITLE_H 53 +#define WND_BTHMAIN_TITLE_FONT_SIZE 38 +#define WND_BTHMAIN_DURBTN_X 16 +#define WND_BTHMAIN_DURBTN_Y 190 +#define WND_BTHMAIN_DURBTN_W 74 +#define WND_BTHMAIN_DURBTN_H 74 +#define WND_BTHMAIN_RHYBTN_X 364 +#define WND_BTHMAIN_RHYBTN_Y 190 +#define WND_BTHMAIN_RHYBTN_W 74 +#define WND_BTHMAIN_RHYBTN_H 74 +#define WND_BTHMAIN_STARTBTN_X 60 +#define WND_BTHMAIN_STARTBTN_Y 358 +#define WND_BTHMAIN_STARTBTN_W 333 +#define WND_BTHMAIN_STARTBTN_H 96 +#define WND_BTHMAIN_DURLAB_X 20 +#define WND_BTHMAIN_DURLAB_Y 275 +#define WND_BTHMAIN_DURLAB_W 65 +#define WND_BTHMAIN_DURLAB_H 30 +#define WND_BTHMAIN_RHYLAB_X 376 +#define WND_BTHMAIN_RHYLAB_Y 275 +#define WND_BTHMAIN_RHYLAB_W 50 +#define WND_BTHMAIN_RHYLAB_H 30 +#define WND_BTHMAIN_CENTER_XY 127 +#define WND_BTHMAIN_CENTER_WH 200 +#define WND_BTHMAIN_lableSetting_FONT_SIZE 24 +#define WND_BTHMAIN_lableTime_FONT_SIZE 20 +#define BREATH_GROUP_SIZE 466 + +REGIST_SLICE_PAGE(VIEW_MAIN_BREATHEASE, BrearhView::BREATH_MAIN_VIEW, BreathMainPage, true); + +BreathMainPage::~BreathMainPage() +{ + group->RemoveAll(); + if (lableSetting != nullptr) { + delete lableSetting; + lableSetting = nullptr; + } + if (buttonStart != nullptr) { + delete buttonStart; + buttonStart = nullptr; + } + if (buttonSetting != nullptr) { + delete buttonSetting; + buttonSetting = nullptr; + } + if (buttonTime != nullptr) { + delete buttonTime; + buttonTime = nullptr; + } + if (lableBreathing != nullptr) { + delete lableBreathing; + lableBreathing = nullptr; + } + if (lableTime != nullptr) { + delete lableTime; + lableTime = nullptr; + } + if (group != nullptr) { + delete group; + group = nullptr; + } + if (background != nullptr) { + delete background; + background = nullptr; + } + if (center != nullptr) { + delete center; + center = nullptr; + } +} + +void BreathMainPage::OnStart(void *data) +{ + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::OnStart new group ERROR"); + group = new UIViewGroup(); + } + group->SetPosition(0, 0); + group->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group->SetTouchable(true); + group->SetDraggable(true); + group->SetOnDragListener(this); + + if (background == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::OnStart new Background ERROR"); + background = new UIImageView(); + } + background->SetPosition(0, 0); + background->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + LOADIMG::LoadImageViewImg(background, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH001); + group->Add(background); + + if (center == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::OnStart new Center ERROR"); + center = new UIImageView(); + } + center->SetPosition(WND_BTHMAIN_CENTER_XY, WND_BTHMAIN_CENTER_XY); + center->Resize(WND_BTHMAIN_CENTER_WH, WND_BTHMAIN_CENTER_WH); + LOADIMG::LoadImageViewImg(center, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH012); + group->Add(center); + + if (lableBreathing == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::OnStart new lableBreathing ERROR"); + lableBreathing = new UILabel(); + } + lableBreathing->SetPosition(WND_BTHMAIN_TITLE_X, WND_BTHMAIN_TITLE_Y); + lableBreathing->Resize(WND_BTHMAIN_TITLE_W, WND_BTHMAIN_TITLE_H); + lableBreathing->SetText("呼吸"); + lableBreathing->SetTextColor(Color::White()); + lableBreathing->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + lableBreathing->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_TITLE_FONT_SIZE); + group->Add(lableBreathing); + + if (buttonTime == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::OnStart new buttonTime ERROR"); + buttonTime = new UIButton(); + } + buttonTime->SetPosition(WND_BTHMAIN_DURBTN_X, WND_BTHMAIN_DURBTN_Y); + buttonTime->Resize(WND_BTHMAIN_DURBTN_W, WND_BTHMAIN_DURBTN_H); + buttonTime->SetViewId(WND_BTHMAIN_BTN_DUR_ID); + buttonTime->SetOnClickListener(this); + LOADIMG::LoadBtnImage(buttonTime, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH002, IMAGE_CONVERTER_TOOL_BREATH002); + buttonTime->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonTime->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group->Add(buttonTime); + + if (buttonSetting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::OnStart new buttonSetting ERROR"); + buttonSetting = new UIButton(); + } + buttonSetting->SetPosition(WND_BTHMAIN_RHYBTN_X, WND_BTHMAIN_RHYBTN_Y); + buttonSetting->Resize(WND_BTHMAIN_RHYBTN_W, WND_BTHMAIN_RHYBTN_H); + buttonSetting->SetViewId(WND_BTHMAIN_BTN_RHY_ID); + buttonSetting->SetOnClickListener(this); + LOADIMG::LoadBtnImage(buttonSetting, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH004, IMAGE_CONVERTER_TOOL_BREATH004); + buttonSetting->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonSetting->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group->Add(buttonSetting); + + if (buttonStart == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::OnStart new buttonStart ERROR"); + buttonStart = new UIButton(); + } + buttonStart->SetPosition(WND_BTHMAIN_STARTBTN_X, WND_BTHMAIN_STARTBTN_Y); + buttonStart->Resize(WND_BTHMAIN_STARTBTN_W, WND_BTHMAIN_STARTBTN_H); + buttonStart->SetViewId(WND_BTHMAIN_BTN_START_ID); + buttonStart->SetOnClickListener(this); + LOADIMG::LoadBtnImage(buttonStart, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH006, IMAGE_CONVERTER_TOOL_BREATH006); + buttonStart->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonStart->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group->Add(buttonStart); + + if (lableSetting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::OnStart new lableSetting ERROR"); + lableSetting = new UILabel(); + } + lableSetting->SetPosition(WND_BTHMAIN_RHYLAB_X, WND_BTHMAIN_RHYLAB_Y); + lableSetting->Resize(WND_BTHMAIN_RHYLAB_W, WND_BTHMAIN_RHYLAB_H); + lableSetting->SetText("设置"); + lableSetting->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + lableSetting->SetTextColor(Color::White()); + lableSetting->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + lableSetting->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_lableSetting_FONT_SIZE); + group->Add(lableSetting); + + if (lableTime == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::OnStart new lableTime ERROR"); + lableTime = new UILabel(); + } + lableTime->SetPosition(WND_BTHMAIN_DURLAB_X, WND_BTHMAIN_DURLAB_Y); + lableTime->Resize(WND_BTHMAIN_DURLAB_W, WND_BTHMAIN_DURLAB_H); + lableTime->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + lableTime->SetTextColor(Color::White()); + lableTime->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + lableTime->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_lableTime_FONT_SIZE); + group->Add(lableTime); + + AddViewToPageContainer(group); +} + +void BreathMainPage::OnStop(void) {} + +void BreathMainPage::OnResume(void) +{ + lableTime->SetText(BreathModel::GetInstance().GetTimeDuration()); +} + +bool BreathMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), WND_BTHMAIN_BTN_DUR_ID) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathMainPage OnClick...ChangeTo DUR"); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_DUR_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + } else if (strcmp(view.GetViewId(), WND_BTHMAIN_BTN_RHY_ID) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathMainPage OnClick...ChangeTo RHY"); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_RHY_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + } else if (strcmp(view.GetViewId(), WND_BTHMAIN_BTN_START_ID) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathMainPage OnClick...ChangeTo START"); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_START_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + uint32_t remTime = current_time.tv_sec; + BreathModel::GetInstance().SetSaveTime(remTime); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage OnClick...ChangeTo unknow"); + return false; + } + return true; +} + +bool BreathMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathMainPage::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, "BreathMainPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathModel.cpp new file mode 100644 index 000000000..ef067f2c9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathModel.cpp @@ -0,0 +1,259 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathModel + * Create: 2025-5-13 + */ +#include "uiservice/ui_service.h" +#include "main/HealthModel.h" +#include "breath/BreathDurPage.h" +#include "breath/BreathModel.h" + +namespace OHOS { +#define MINUTE_IDX_1 0 +#define MINUTE_IDX_2 1 +#define MINUTE_IDX_3 2 +#define SPEED_IDX_1 0 +#define SPEED_IDX_2 1 +#define SPEED_IDX_3 2 +#define MINUTE_1 "1 分钟" +#define MINUTE_2 "2 分钟" +#define MINUTE_3 "3 分钟" +#define SPEED_FAST_8 "稍快 8次/分" +#define SPEED_SLOW_7 "舒缓 7次/分" +#define SPEED_SLOW_6 "缓慢 6次/分" +#define TIME_1 "1" +#define TIME_2 "2" +#define TIME_3 "3" +#define SPEED_FASTER_LITTLE "稍快" +#define SPEED_SOOTHING "舒缓" +#define SPEED_SLOWING "缓慢" +#define MINUTE_0_DATA 0 +#define MINUTE_1_DATA 1 +#define MINUTE_2_DATA 2 +#define MINUTE_3_DATA 3 +#define NUMBLE_PLAY_8_DATA 8 +#define NUMBLE_PLAY_7_DATA 7 +#define NUMBLE_PLAY_6_DATA 6 +#define NUMBLE_PLAY_16_DATA 16 +#define NUMBLE_PLAY_14_DATA 14 +#define NUMBLE_PLAY_12_DATA 12 +#define NUMBLE_PLAY_24_DATA 24 +#define NUMBLE_PLAY_21_DATA 21 +#define NUMBLE_PLAY_18_DATA 18 +#define Frequency_Score_LOWER 60 +#define Frequency_Score_RANGE 40 +#define Heart_Rate_LOWER 90 +#define Heart_Rate_RANGE 10 +#define ONE_MINUTE 60 +#define TWO_MINUTES 120 +#define THREE_MINUTES 180 +#define SIX_POINTS_FOR_ONE 125 +#define SEVEN_POINTS_FOR_ONE 106 +#define EIGHT_POINTS_FOR_ONE 98 +uint8_t g_frequencyScore; +uint8_t g_heartRate; + +BreathModel::BreathModel() +{ + DefaultData(); +} + +BreathModel::~BreathModel() {} + +void BreathModel::DefaultData() +{ + durList[MINUTE_IDX_1] = MINUTE_1; + durList[MINUTE_IDX_2] = MINUTE_2; + durList[MINUTE_IDX_3] = MINUTE_3; + rhyList[SPEED_IDX_1] = SPEED_FAST_8; + rhyList[SPEED_IDX_2] = SPEED_SLOW_7; + rhyList[SPEED_IDX_3] = SPEED_SLOW_6; + durListVal[MINUTE_IDX_1] = MINUTE_1_DATA; + durListVal[MINUTE_IDX_2] = MINUTE_2_DATA; + durListVal[MINUTE_IDX_3] = MINUTE_3_DATA; +} + +BreathModel &BreathModel::GetInstance() +{ + static BreathModel instance; + return instance; +} + +const char **BreathModel::GetDurListData() +{ + return durList; +} + +const char **BreathModel::GetRhyListData() +{ + return rhyList; +} + +uint8_t BreathModel::GetDurListSize() +{ + return sizeof(durList) / sizeof(durList[0]); +} + +uint8_t BreathModel::GetRhyListSize() +{ + return sizeof(rhyList) / sizeof(rhyList[0]); +} + +void BreathModel::SetTimeDuration(uint16_t idx) +{ + data = idx; +} + +void BreathModel::SetTimeRhyation(uint16_t idx) +{ + date = idx; +} + +uint8_t BreathModel::GetSelectTime() +{ + if (data == MINUTE_0_DATA) { + return MINUTE_IDX_1; + } else if (data == MINUTE_1_DATA) { + return MINUTE_IDX_2; + } else if (data == MINUTE_2_DATA) { + return MINUTE_IDX_3; + } + return 0; +} + +uint8_t BreathModel::GetSelectTempo() +{ + if (date == MINUTE_0_DATA) { + return SPEED_IDX_1; + } else if (date == MINUTE_1_DATA) { + return SPEED_IDX_2; + } else if (date == MINUTE_2_DATA) { + return SPEED_IDX_3; + } + return 0; +} + +char *BreathModel::GetTimeDuration() +{ + if (data == MINUTE_0_DATA) { + return MINUTE_1; + } else if (data == MINUTE_1_DATA) { + return MINUTE_2; + } else if (data == MINUTE_2_DATA) { + return MINUTE_3; + } + return nullptr; +} + +char *BreathModel::GetDuration() +{ + if (data == MINUTE_0_DATA) { + return TIME_1; + } else if (data == MINUTE_1_DATA) { + return TIME_2; + } else if (data == MINUTE_2_DATA) { + return TIME_3; + } + return nullptr; +} + +char *BreathModel::GetRhythm() +{ + if (date == MINUTE_0_DATA) { + return SPEED_FASTER_LITTLE; + } else if (date == MINUTE_1_DATA) { + return SPEED_SOOTHING; + } else if (date == MINUTE_2_DATA) { + return SPEED_SLOWING; + } + return nullptr; +} + +void BreathModel::SetSaveTime(int32_t idx) +{ + saveTime = idx; +} + +int32_t BreathModel::GetSaveTime() +{ + return saveTime; +} + +void BreathModel::SetBeginsTime(int32_t idx) +{ + beginsTime = idx; +} + +int32_t BreathModel::GetBeginsTime() +{ + return beginsTime; +} + +uint32_t BreathModel::GetTimeBreathing() +{ + if (data == MINUTE_0_DATA) { + return ONE_MINUTE; + } else if (data == MINUTE_1_DATA) { + return TWO_MINUTES; + } else if (data == MINUTE_2_DATA) { + return THREE_MINUTES; + } + return 0; +} + +uint32_t BreathModel::GetStatusRespiratory() +{ + if (date == MINUTE_0_DATA) { + return EIGHT_POINTS_FOR_ONE; + } else if (date == MINUTE_1_DATA) { + return SEVEN_POINTS_FOR_ONE; + } else if (date == MINUTE_2_DATA) { + return SIX_POINTS_FOR_ONE; + } + return 0; +} + +void BreathModel::SetFrequencyScore() +{ + g_frequencyScore = Frequency_Score_LOWER + rand() % Frequency_Score_RANGE; +} + +uint8_t BreathModel::GetFrequencyScore() +{ + return g_frequencyScore; +} + +void BreathModel::SetHeartRate() +{ + g_heartRate = Heart_Rate_LOWER + rand() % Heart_Rate_RANGE; +} + +uint8_t BreathModel::GetHeartRate() +{ + return g_heartRate; +} + +uint32_t BreathModel::GetTheNumberOfPlays() +{ + if (date == MINUTE_0_DATA && data == MINUTE_0_DATA) { + return NUMBLE_PLAY_8_DATA; + } else if (date == MINUTE_1_DATA && data == MINUTE_0_DATA) { + return NUMBLE_PLAY_7_DATA; + } else if (date == MINUTE_2_DATA && data == MINUTE_0_DATA) { + return NUMBLE_PLAY_6_DATA; + } else if (date == MINUTE_0_DATA && data == MINUTE_1_DATA) { + return NUMBLE_PLAY_16_DATA; + } else if (date == MINUTE_1_DATA && data == MINUTE_1_DATA) { + return NUMBLE_PLAY_14_DATA; + } else if (date == MINUTE_2_DATA && data == MINUTE_1_DATA) { + return NUMBLE_PLAY_12_DATA; + } else if (date == MINUTE_0_DATA && data == MINUTE_2_DATA) { + return NUMBLE_PLAY_24_DATA; + } else if (date == MINUTE_1_DATA && data == MINUTE_2_DATA) { + return NUMBLE_PLAY_21_DATA; + } else if (date == MINUTE_2_DATA && data == MINUTE_2_DATA) { + return NUMBLE_PLAY_18_DATA; + } + return 0; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathPresenter.cpp new file mode 100644 index 000000000..61c31fb7d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathPresenter.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathPresenter + * Create: 2025-5-13 + */ +#include "AppViewIDs.h" +#include "NativeRegisterManager.h" +#include "breath/BreathView.h" +#include "breath/BreathPresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_MAIN_BREATHEASE, BreathView, BreathPresenter, BREATH_MAIN_ICON, BREATH_MAIN_ICON, "呼吸训练"); +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathResultPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathResultPage.cpp new file mode 100644 index 000000000..1f4796678 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathResultPage.cpp @@ -0,0 +1,353 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathReult + * Create: 2025-5-13 + */ +#include +#include "gfx_utils/graphic_math.h" +#include "components/root_view.h" +#include "UiConfig.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "TransitionType.h" +#include "SlicePageFactory.h" +#include "main/LoadImg.h" +#include "ui_resource_breath.h" +#include "breath/BreathView.h" +#include "breath/BreathResultPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_MAIN_BREATHEASE, BrearhView::BREATH_RESULT_VIEW, BreathResultPage, false); +#define WND_BTHMAIN_RESULTS_X 97 +#define WND_BTHMAIN_RESULTS_Y 34 +#define WND_BTHMAIN_RESULTS_W 260 +#define WND_BTHMAIN_RESULTS_H 53 +#define WND_BTHMAIN_MAX_FONT_SIZE 38 +#define WND_BTHMAIN_FREQUENCIES_X 140 +#define WND_BTHMAIN_FREQUENCIES_Y 133 +#define WND_BTHMAIN_FREQUENCIES_W 164 +#define WND_BTHMAIN_FREQUENCIES_H 30 +#define WND_BTHMAIN_MIN_FONT_SIZE 24 +#define WND_BTHMAIN_HEARTRATE_X 149 +#define WND_BTHMAIN_HEARTRATE_Y 233 +#define WND_BTHMAIN_HEARTRATE_W 120 +#define WND_BTHMAIN_HEARTRATE_H 30 +#define WND_BTHMAIN_FREQUEBCY_TIMES_X 204 +#define WND_BTHMAIN_FREQUEBCY_TIMES_Y 179 +#define WND_BTHMAIN_FREQUEBCY_TIMES_W 29 +#define WND_BTHMAIN_FREQUEBCY_TIMES_H 29 +#define WND_BTHMAIN_HEARTRATE_TIMES_X 204 +#define WND_BTHMAIN_HEARTRATE_TIMES_Y 279 +#define WND_BTHMAIN_HEARTRATE_TIMES_W 58 +#define WND_BTHMAIN_HEARTRATE_TIMES_H 29 +#define WND_BTHMAIN_DURATION_X 149 +#define WND_BTHMAIN_DURATION_Y 333 +#define WND_BTHMAIN_DURATION_W 96 +#define WND_BTHMAIN_DURATION_H 30 +#define WND_BTHMAIN_FREQUENCIES_SCOUT_X 149 +#define WND_BTHMAIN_FREQUENCIES_SCOUT_Y 165 +#define WND_BTHMAIN_FREQUENCIES_SCOUT_W 49 +#define WND_BTHMAIN_FREQUENCIES_SCOUT_H 49 +#define WND_BTHMAIN_SCOUT_FONT_SIZE 40 +#define WND_BTHMAIN_HEARTRATE_SCOUT_X 149 +#define WND_BTHMAIN_HEARTRATE_SCOUT_Y 265 +#define WND_BTHMAIN_HEARTRATE_SCOUT_W 49 +#define WND_BTHMAIN_HEARTRATE_SCOUT_H 49 +#define WND_BTHMAIN_RHYTHM_X 161 +#define WND_BTHMAIN_RHYTHM_Y 83 +#define WND_BTHMAIN_RHYTHM_W 132 +#define WND_BTHMAIN_RHYTHM_H 30 +#define WND_BTHMAIN_TIME_X 149 +#define WND_BTHMAIN_TIME_Y 365 +#define WND_BTHMAIN_TIME_W 25 +#define WND_BTHMAIN_TIME_H 48 +#define WND_BTHMAIN_TIME_UNIT_X 180 +#define WND_BTHMAIN_TIME_UNIT_Y 379 +#define WND_BTHMAIN_TIME_UNIT_W 58 +#define WND_BTHMAIN_TIME_UNIT_H 29 +#define WND_BTHMAIN_SCORES_X 241 +#define WND_BTHMAIN_SCORES_Y 177 +#define WND_BTHMAIN_SCORES_W 72 +#define WND_BTHMAIN_SCORES_H 32 +#define BREATH_GROUP_SIZE 466 +#define BREATH_GUINEAS_SIZE 100 +#define BREATH_NINETY_SIZE 90 +#define BREATH_EIGHTY_NINE_SIZE 89 +#define BREATH_EIGHTY_SIZE 80 +#define BREATH_SEVENTY_NINE_SIZE 79 +#define BREATH_SEVENTY_SIZE 70 +#define BREATH_SIXTY_NINE_SIZE 69 +#define BREATH_SIXTY_SIZE 60 +#define TEXT_OPACITY 147 +#define TEXT_SIZE 5 + +BreathResultPage::BreathResultPage() {} + +BreathResultPage::~BreathResultPage() +{ + group->RemoveAll(); + if (trainingResults != nullptr) { + delete trainingResults; + trainingResults = nullptr; + } + if (trainingFrequencies != nullptr) { + delete trainingFrequencies; + trainingFrequencies = nullptr; + } + if (trainingHeartRate != nullptr) { + delete trainingHeartRate; + trainingHeartRate = nullptr; + } + if (trainingDuration != nullptr) { + delete trainingDuration; + trainingDuration = nullptr; + } + if (frequenciesScout != nullptr) { + delete frequenciesScout; + frequenciesScout = nullptr; + } + if (heartRateScout != nullptr) { + delete heartRateScout; + heartRateScout = nullptr; + } + if (descriptionBreathing != nullptr) { + delete descriptionBreathing; + descriptionBreathing = nullptr; + } + if (time != nullptr) { + delete time; + time = nullptr; + } + if (timeUnit != nullptr) { + delete timeUnit; + timeUnit = nullptr; + } + if (heartRateTimes != nullptr) { + delete heartRateTimes; + heartRateTimes = nullptr; + } + if (frequencyTimes != nullptr) { + delete frequencyTimes; + frequencyTimes = nullptr; + } + if (group != nullptr) { + delete group; + group = nullptr; + } + if (scores != nullptr) { + delete scores; + scores = nullptr; + } +} + +void BreathResultPage::OnStart(void *data) +{ + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new group ERROR"); + group = new UIViewGroup(); + } + group->SetPosition(0, 0); + group->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group->SetTouchable(true); + group->SetDraggable(true); + group->SetOnDragListener(this); + + if (trainingResults == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new trainingResults ERROR"); + trainingResults = new UILabel(); + } + trainingResults->SetPosition(WND_BTHMAIN_RESULTS_X, WND_BTHMAIN_RESULTS_Y); + trainingResults->Resize(WND_BTHMAIN_RESULTS_W, WND_BTHMAIN_RESULTS_H); + trainingResults->SetText("训练结果"); + trainingResults->SetTextColor(Color::White()); + trainingResults->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_MAX_FONT_SIZE); + trainingResults->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(trainingResults); + + if (trainingFrequencies == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new trainingFrequencies ERROR"); + trainingFrequencies = new UILabel(); + } + trainingFrequencies->SetPosition(WND_BTHMAIN_FREQUENCIES_X, WND_BTHMAIN_FREQUENCIES_Y); + trainingFrequencies->Resize(WND_BTHMAIN_FREQUENCIES_W, WND_BTHMAIN_FREQUENCIES_H); + trainingFrequencies->SetText("呼吸频率得分"); + trainingFrequencies->SetTextColor(Color::White()); + trainingFrequencies->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_MIN_FONT_SIZE); + trainingFrequencies->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + trainingFrequencies->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group->Add(trainingFrequencies); + + if (trainingHeartRate == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new trainingHeartRate ERROR"); + trainingHeartRate = new UILabel(); + } + trainingHeartRate->SetPosition(WND_BTHMAIN_HEARTRATE_X, WND_BTHMAIN_HEARTRATE_Y); + trainingHeartRate->Resize(WND_BTHMAIN_HEARTRATE_W, WND_BTHMAIN_HEARTRATE_H); + trainingHeartRate->SetText("呼吸前心率"); + trainingHeartRate->SetTextColor(Color::White()); + trainingHeartRate->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_MIN_FONT_SIZE); + trainingHeartRate->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + trainingHeartRate->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group->Add(trainingHeartRate); + + if (frequencyTimes == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new frequencyTimes ERROR"); + frequencyTimes = new UILabel(); + } + frequencyTimes->SetPosition(WND_BTHMAIN_FREQUEBCY_TIMES_X, WND_BTHMAIN_FREQUEBCY_TIMES_Y); + frequencyTimes->Resize(WND_BTHMAIN_FREQUEBCY_TIMES_W, WND_BTHMAIN_FREQUEBCY_TIMES_H); + frequencyTimes->SetText("分"); + frequencyTimes->SetTextColor(Color::White()); + frequencyTimes->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_MIN_FONT_SIZE); + frequencyTimes->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + frequencyTimes->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group->Add(frequencyTimes); + + if (heartRateTimes == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new HeartRate_Times ERROR"); + heartRateTimes = new UILabel(); + } + heartRateTimes->SetPosition(WND_BTHMAIN_HEARTRATE_TIMES_X, WND_BTHMAIN_HEARTRATE_TIMES_Y); + heartRateTimes->Resize(WND_BTHMAIN_HEARTRATE_TIMES_W, WND_BTHMAIN_HEARTRATE_TIMES_H); + heartRateTimes->SetText("次/分"); + heartRateTimes->SetTextColor(Color::White()); + heartRateTimes->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_MIN_FONT_SIZE); + heartRateTimes->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + heartRateTimes->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group->Add(heartRateTimes); + + if (trainingDuration == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new trainingDuration ERROR"); + trainingDuration = new UILabel(); + } + trainingDuration->SetPosition(WND_BTHMAIN_DURATION_X, WND_BTHMAIN_DURATION_Y); + trainingDuration->Resize(WND_BTHMAIN_DURATION_W, WND_BTHMAIN_DURATION_H); + trainingDuration->SetText("训练时长"); + trainingDuration->SetTextColor(Color::White()); + trainingDuration->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_MIN_FONT_SIZE); + trainingDuration->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + trainingDuration->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group->Add(trainingDuration); + + if (frequenciesScout == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new Frequencies_scout ERROR"); + frequenciesScout = new UILabel(); + } + frequenciesScout->SetPosition(WND_BTHMAIN_FREQUENCIES_SCOUT_X, WND_BTHMAIN_FREQUENCIES_SCOUT_Y); + frequenciesScout->Resize(WND_BTHMAIN_FREQUENCIES_SCOUT_W, WND_BTHMAIN_FREQUENCIES_SCOUT_H); + frequenciesScout->SetTextColor(Color::White()); + frequenciesScout->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_SCOUT_FONT_SIZE); + frequenciesScout->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(frequenciesScout); + + if (heartRateScout == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new HeartRate_scout ERROR"); + heartRateScout = new UILabel(); + } + heartRateScout->SetPosition(WND_BTHMAIN_HEARTRATE_SCOUT_X, WND_BTHMAIN_HEARTRATE_SCOUT_Y); + heartRateScout->Resize(WND_BTHMAIN_HEARTRATE_SCOUT_W, WND_BTHMAIN_HEARTRATE_SCOUT_H); + heartRateScout->SetTextColor(Color::White()); + heartRateScout->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_SCOUT_FONT_SIZE); + heartRateScout->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(heartRateScout); + + if (descriptionBreathing == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new Rhythm ERROR"); + descriptionBreathing = new UILabel(); + } + descriptionBreathing->SetPosition(WND_BTHMAIN_RHYTHM_X, WND_BTHMAIN_RHYTHM_Y); + descriptionBreathing->Resize(WND_BTHMAIN_RHYTHM_W, WND_BTHMAIN_RHYTHM_H); + descriptionBreathing->SetTextColor(Color::Green()); + descriptionBreathing->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_MIN_FONT_SIZE); + descriptionBreathing->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(descriptionBreathing); + + if (time == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new Time ERROR"); + time = new UILabel(); + } + time->SetPosition(WND_BTHMAIN_TIME_X, WND_BTHMAIN_TIME_Y); + time->Resize(WND_BTHMAIN_TIME_W, WND_BTHMAIN_TIME_H); + time->SetTextColor(Color::White()); + time->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_SCOUT_FONT_SIZE); + time->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(time); + + if (timeUnit == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new Time_Unit ERROR"); + timeUnit = new UILabel(); + } + timeUnit->SetPosition(WND_BTHMAIN_TIME_UNIT_X, WND_BTHMAIN_TIME_UNIT_Y); + timeUnit->Resize(WND_BTHMAIN_TIME_UNIT_W, WND_BTHMAIN_TIME_UNIT_H); + timeUnit->SetText("分钟"); + timeUnit->SetTextColor(Color::White()); + timeUnit->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHMAIN_MIN_FONT_SIZE); + timeUnit->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timeUnit->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group->Add(timeUnit); + + if (scores == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::OnStart new Scores ERROR"); + scores = new UIImageView(); + } + scores->SetPosition(WND_BTHMAIN_SCORES_X, WND_BTHMAIN_SCORES_Y); + scores->Resize(WND_BTHMAIN_SCORES_W, WND_BTHMAIN_SCORES_H); + group->Add(scores); + + AddViewToPageContainer(group); +} +void BreathResultPage::OnStop() {} +void BreathResultPage::OnResume(void) +{ + std::ostringstream oss; + oss << BreathModel::GetInstance().GetTimeDuration() << " | " << BreathModel::GetInstance().GetRhythm(); + std::string weatherHumidity = oss.str(); + descriptionBreathing->SetText(weatherHumidity.c_str()); + time->SetText(BreathModel::GetInstance().GetDuration()); + + BreathModel::GetInstance().SetFrequencyScore(); + BreathModel::GetInstance().SetHeartRate(); + + frequencyScore = BreathModel::GetInstance().GetFrequencyScore(); + char szFrequencyScore[TEXT_SIZE] = ""; + sprintf_s(szFrequencyScore, sizeof(szFrequencyScore), "%d", frequencyScore); + frequenciesScout->SetText(szFrequencyScore); + + if (frequencyScore >= BREATH_NINETY_SIZE && frequencyScore <= BREATH_GUINEAS_SIZE) { + LOADIMG::LoadImageViewImg(scores, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH008); + } else if (frequencyScore >= BREATH_EIGHTY_SIZE && frequencyScore <= BREATH_EIGHTY_NINE_SIZE) { + LOADIMG::LoadImageViewImg(scores, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH007); + } else if (frequencyScore >= BREATH_SEVENTY_SIZE && frequencyScore <= BREATH_SEVENTY_NINE_SIZE) { + LOADIMG::LoadImageViewImg(scores, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH011); + } else if (frequencyScore >= BREATH_SIXTY_SIZE && frequencyScore <= BREATH_SIXTY_NINE_SIZE) { + LOADIMG::LoadImageViewImg(scores, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH009); + } else { + LOADIMG::LoadImageViewImg(scores, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH010); + } + + heartRate = BreathModel::GetInstance().GetHeartRate(); + char szHeartRate[TEXT_SIZE] = ""; + sprintf_s(szHeartRate, sizeof(szHeartRate), "%d", heartRate); + heartRateScout->SetText(szHeartRate); +} + +bool BreathResultPage::OnClick(UIView &view, const ClickEvent &event) +{ + return true; +} + +bool BreathResultPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathResultPage::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, "BreathResultPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_MAIN_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + } + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathRhyPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathRhyPage.cpp new file mode 100644 index 000000000..1265c9912 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathRhyPage.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathRhyPage + * Create: 2025-5-13 + */ +#include "gfx_utils/graphic_math.h" +#include "UiConfig.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "alarm/MainAlarmView.h" +#include "SlicePageFactory.h" +#include "ui_resource_breath.h" +#include "main/LoadImg.h" +#include "breath/BreathView.h" +#include "breath/BreathModel.h" +#include "breath/BreathRhyPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_MAIN_BREATHEASE, BrearhView::BREATH_RHY_VIEW, BreathRhyPage, false); +#define WND_BTHRHY_BTN_OK_ID "BTH_RHY_OK" +#define WND_BTHRHY_TITLE_X 100 +#define WND_BTHRHY_TITLE_Y 38 +#define WND_BTHRHY_TITLE_W 253 +#define WND_BTHRHY_TITLE_H 53 +#define WND_BTHRHY_TITLE_FONT_SIZE 38 +#define WND_BTHRHY_PICKER_X 64 +#define WND_BTHRHY_PICKER_Y 109 +#define WND_BTHRHY_PICKER_W 321 +#define WND_BTHRHY_PICKER_H 218 +#define WND_BTHRHY_PICKER_B_FONT_SIZE 44 +#define WND_BTHRHY_PICKER_H_FONT_SIZE 44 +#define WND_BTHRHY_PICKER_ITEM_H 80 +#define WND_BTHRHY_OK_X 61 +#define WND_BTHRHY_OK_Y 362 +#define WND_BTHRHY_OK_W 331 +#define WND_BTHRHY_OK_H 98 +#define BREATH_GROUP_SIZE 466 + +BreathRhyPage::BreathRhyPage() {} + +BreathRhyPage::~BreathRhyPage() +{ + group->RemoveAll(); + if (lableRhythm != nullptr) { + delete lableRhythm; + lableRhythm = nullptr; + } + if (pickerRhythm != nullptr) { + delete pickerRhythm; + pickerRhythm = nullptr; + } + if (buttonOk != nullptr) { + delete buttonOk; + buttonOk = nullptr; + } + if (group != nullptr) { + delete group; + group = nullptr; + } + if (center != nullptr) { + delete center; + center = nullptr; + } +} + +void BreathRhyPage::OnStart(void *data) +{ + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathRhyPage::OnStart new group ERROR"); + group = new UIViewGroup(); + } + group->SetPosition(0, 0); + group->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group->SetTouchable(false); + group->SetDraggable(false); + + if (lableRhythm == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathRhyPage::OnStart new lableRhythm ERROR"); + lableRhythm = new UILabel(); + } + lableRhythm->SetPosition(WND_BTHRHY_TITLE_X, WND_BTHRHY_TITLE_Y); + lableRhythm->Resize(WND_BTHRHY_TITLE_W, WND_BTHRHY_TITLE_H); + lableRhythm->SetText("节奏设置"); + lableRhythm->SetTextColor(Color::White()); + lableRhythm->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + lableRhythm->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHRHY_TITLE_FONT_SIZE); + group->Add(lableRhythm); + + if (pickerRhythm == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathRhyPage::OnStart new pickerRhythm ERROR"); + pickerRhythm = new UIPicker(); + } + pickerRhythm->SetPosition(WND_BTHRHY_PICKER_X, WND_BTHRHY_PICKER_Y); + pickerRhythm->Resize(WND_BTHRHY_PICKER_W, WND_BTHRHY_PICKER_H); + pickerRhythm->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHRHY_PICKER_B_FONT_SIZE); + pickerRhythm->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHRHY_PICKER_H_FONT_SIZE); + pickerRhythm->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + pickerRhythm->SetItemHeight(WND_BTHRHY_PICKER_ITEM_H); + pickerRhythm->SetTextColor(Color::GetColorFromRGBA(0xfa, 0xf3, 0xf3, 0xff), + Color::GetColorFromRGBA(0xfa, 0xf3, 0xf3, 0xff)); + uint8_t selectTempo = BreathModel::GetInstance().GetSelectTempo(); + pickerRhythm->SetSelected(selectTempo); + pickerRhythm->RegisterSelectedListener(this); + pickerRhythm->SetVisible(true); + pickerRhythm->SetOnDragListener(this); + pickerRhythm->SetLoopState(false); + group->Add(pickerRhythm); + + if (center == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathRhyPage::OnStart new Center ERROR"); + center = new UIImageView(); + } + center->SetPosition(WND_BTHRHY_PICKER_X, WND_BTHRHY_PICKER_Y); + center->Resize(WND_BTHRHY_PICKER_W, WND_BTHRHY_PICKER_H); + LOADIMG::LoadImageViewImg(center, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH013); + group->Add(center); + + if (buttonOk == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathRhyPage::OnStart new buttonOk ERROR"); + buttonOk = new UIButton(); + } + buttonOk->SetPosition(WND_BTHRHY_OK_X, WND_BTHRHY_OK_Y); + buttonOk->Resize(WND_BTHRHY_OK_W, WND_BTHRHY_OK_H); + buttonOk->SetViewId(WND_BTHRHY_BTN_OK_ID); + buttonOk->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + LOADIMG::LoadBtnImage(buttonOk, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH005, IMAGE_CONVERTER_TOOL_BREATH005); + buttonOk->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + buttonOk->SetOnClickListener(this); + group->Add(buttonOk); + + AddViewToPageContainer(group); +} +void BreathRhyPage::OnResume() +{ + pickerRhythm->SetValues(BreathModel::GetInstance().GetRhyListData(), BreathModel::GetInstance().GetRhyListSize()); + GetSlicePageContainer()->SetIntercept(true); + GetSlicePageContainer()->SetOnDragListener(nullptr); +} + +void BreathRhyPage::OnPause() {} + +void BreathRhyPage::OnStop() {} + +bool BreathRhyPage::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), WND_BTHRHY_BTN_OK_ID) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathRhyPage OnClick...ChangeTo DUR"); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_MAIN_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + BreathModel::GetInstance().SetTimeRhyation(pickerRhythm->GetSelected()); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathRhyPage OnClick...ChangeTo unknow"); + return false; + } + return true; +} + +bool BreathRhyPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathRhyPage::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, "BreathRhyPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_MAIN_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + } + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathStartPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathStartPage.cpp new file mode 100644 index 000000000..6545ac442 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/breath/src/BreathStartPage.cpp @@ -0,0 +1,197 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathStartPage + * Create: 2025-5-13 + */ +#include +#include +#include +#include "gfx_utils/graphic_math.h" +#include "components/root_view.h" +#include "UiConfig.h" +#include "ohos_timer.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "TransitionType.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "ui_resource_breath.h" +#include "main/LoadImg.h" +#include "breath/BreathView.h" +#include "breath/BreathModel.h" +#include "breath/BreathStartPage.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_MAIN_BREATHEASE, BrearhView::BREATH_START_VIEW, BreathStartPage, false); + +#define WND_BTHSTART_TITLE_X 97 +#define WND_BTHSTART_TITLE_Y 40 +#define WND_BTHSTART_TITLE_W 260 +#define WND_BTHSTART_TITLE_H 53 +#define WND_BTHSTART_TITLE_FONT_SIZE 36 +#define WND_BTHSTART_CENTERIMG_X 88 +#define WND_BTHSTART_CENTERIMG_Y 88 +#define WND_BTHSTART_CENTERIMG_W 279 +#define WND_BTHSTART_CENTERIMG_H 280 +#define WND_BTHSTART_GUIDE_X 126 +#define WND_BTHSTART_GUIDE_Y 354 +#define WND_BTHSTART_GUIDE_W 202 +#define WND_BTHSTART_GUIDE_H 68 +#define WND_BTHSTART_GUIDE_FONT_SIZE 24 +#define BREATH_GROUP_SIZE 466 +#define TEXT_OPACITY 147 +#define countDown 5 +#define SIZE 64 + +BreathStartPage::BreathStartPage() {} + +BreathStartPage::~BreathStartPage() +{ + group->RemoveAll(); + if (titleLable != nullptr) { + delete titleLable; + titleLable = nullptr; + } + if (guideLable != nullptr) { + delete guideLable; + guideLable = nullptr; + } + if (centerImge != nullptr) { + delete centerImge; + centerImge = nullptr; + } + if (group != nullptr) { + delete group; + group = nullptr; + } + if (background != nullptr) { + delete background; + background = nullptr; + } + if (animation != nullptr) { + delete animation; + animation = nullptr; + } + if (animatorCallBack != nullptr) { + delete animatorCallBack; + animatorCallBack = nullptr; + } +} + +void BreathStartPage::OnStart(void *data) +{ + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathStartPage::OnStart new group ERROR"); + group = new UIViewGroup(); + } + group->SetPosition(0, 0); + group->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group->SetTouchable(true); + group->SetDraggable(true); + group->SetOnDragListener(this); + + if (background == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathStartPage::OnStart new background ERROR"); + background = new UIImageView(); + } + background->SetPosition(0, 0); + background->Resize(BREATH_GROUP_SIZE, BREATH_GROUP_SIZE); + LOADIMG::LoadImageViewImg(background, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH001); + group->Add(background); + + if (titleLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathStartPage::OnStart new titleLable ERROR"); + titleLable = new UILabel(); + } + titleLable->SetPosition(WND_BTHSTART_TITLE_X, WND_BTHSTART_TITLE_Y); + titleLable->Resize(WND_BTHSTART_TITLE_W, WND_BTHSTART_TITLE_H); + titleLable->SetText("请保持静止"); + titleLable->SetTextColor(Color::White()); + titleLable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHSTART_TITLE_FONT_SIZE); + group->Add(titleLable); + + if (centerImge == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathStartPage::OnStart new centerImg ERROR"); + centerImge = new UIImageView(); + } + centerImge->SetPosition(WND_BTHSTART_CENTERIMG_X, WND_BTHSTART_CENTERIMG_Y); + centerImge->Resize(WND_BTHSTART_CENTERIMG_W, WND_BTHSTART_CENTERIMG_H); + LOADIMG::LoadImageViewImg(centerImge, BREATH_IMAGE, IMAGE_CONVERTER_TOOL_BREATH003); + group->Add(centerImge); + + if (guideLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathStartPage::OnStart new guideLable ERROR"); + guideLable = new UILabel(); + } + guideLable->SetPosition(WND_BTHSTART_GUIDE_X, WND_BTHSTART_GUIDE_Y); + guideLable->Resize(WND_BTHSTART_GUIDE_W, WND_BTHSTART_GUIDE_H); + guideLable->SetTextColor(Color::White()); + guideLable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + guideLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WND_BTHSTART_GUIDE_FONT_SIZE); + guideLable->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + guideLable->SetStyle(STYLE_TEXT_OPA, TEXT_OPACITY); + group->Add(guideLable); + + animatorCallBack = new BreathStartCallback(this); + if (animatorCallBack == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathStartPage::OnStart new animatorCallBack ERROR"); + return; + } + animation = new Animator(animatorCallBack, nullptr, 0, true); + if (animation == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BreathStartPage::OnStart new animation ERROR"); + return; + } + animation->Start(); + AddViewToPageContainer(group); +} + +void BreathStartPage::OnStop() {} + +void BreathStartPage::BreathStartCallback::Callback(UIView *view) +{ + UNUSED(view); + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + int32_t overTime = countDown; + int32_t start_time = BreathModel::GetInstance().GetSaveTime(); + int32_t remTime = overTime - (current_time.tv_sec - start_time); + + char szText[SIZE] = ""; + sprintf_s(szText, sizeof(szText), "%d秒后跟随训练指引开始吸气和呼气", remTime); + BreathStartPage->guideLable->SetText(szText); + if (remTime <= 0) { + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_EXER_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + BreathStartPage->animation->Stop(); + struct timeval start_breathing_time; + gettimeofday(&start_breathing_time, nullptr); + uint32_t breathing_time = start_breathing_time.tv_sec; + BreathModel::GetInstance().SetBeginsTime(breathing_time); + } +} + +void BreathStartPage::OnPause() +{ + animation->Stop(); +} + +bool BreathStartPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BreathStartPage::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, "BreathStartPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + NativeAbility::GetInstance().SwitchPageInSlice(BREATH_MAIN_VIEW, nullptr, TransitionType::TRANSITION_INVALID, + true); + } + return true; +} + +void BreathStartPage::OnTimer() {} + +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerItemView.cpp index c63f1851c..70b62303c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerItemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerItemView.cpp @@ -5,9 +5,12 @@ * Create: 2021-10-12 */ -#include "CallerItemView.h" -#include "CallerLogPresenter.h" +#include "callerlog/CallerItemView.h" +#include "sys/time.h" #include "wearable_log.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif namespace OHOS { static constexpr int16 ICON_X = 100; 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 5e9e96d73..11d24831b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp @@ -4,15 +4,15 @@ * Author: * Create: 2021-10-12 */ -#include "CallerLogModel.h" -#include "CallerLogView.h" -#include "DialingScreenView.h" -#include "CallingView.h" +#include "callerlog/CallerLogModel.h" +#include "callerlog/CallerLogView.h" +#include "makephone/DialingScreenView.h" +#include "makephone/CallingView.h" #include "ohos_timer.h" #include "graphic_timer.h" #include "samgr_lite.h" -#include "MainCallingPresenter.h" -#include "PlayersModel.h" +#include "makephone/MainCallingPresenter.h" +#include "player/PlayersModel.h" #include "graphic_service.h" #ifdef __cplusplus diff --git a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogPresenter.cpp index 6c87b1fa7..398f25152 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogPresenter.cpp @@ -5,11 +5,11 @@ * Create: 2021-10-12 */ -#include "CallerLogPresenter.h" -#include "CallerLogView.h" +#include "callerlog/CallerLogPresenter.h" +#include "callerlog/CallerLogView.h" #include "common/task_manager.h" #include "wearable_log.h" -#include "PhoneService.h" +#include "phoneservice/PhoneService.h" #include "NativeRegisterManager.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogView.cpp index 5edabaa18..a9d012a1c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/callerlog/src/CallerLogView.cpp @@ -5,9 +5,9 @@ * Create: 2021-10-12 */ -#include "CallerLogView.h" -#include "CallerLogPresenter.h" -#include "CallerLogModel.h" +#include "callerlog/CallerLogView.h" +#include "callerlog/CallerLogPresenter.h" +#include "callerlog/CallerLogModel.h" #include "wearable_log.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/camera/src/CameraMainPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/camera/src/CameraMainPage.cpp new file mode 100644 index 000000000..6aca1160c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/camera/src/CameraMainPage.cpp @@ -0,0 +1,376 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: CameraMainPage + * Created: 2025-06-05 + */ + +#include +#include "ui_test_group.h" +#include "phoneservice/PhoneService.h" +#include "uiservice/ui_service.h" +#include "common/image_cache_manager.h" +#include "main/LoadImg.h" +#include "msg_center_device.h" +#include "bts_spp.h" +#include "ui_resource_camera.h" +#include "camera/CameraView.h" +#include "camera/CameraMainPage.h" +#include "camera/CameraPresenter.h" + +namespace OHOS { +static CameraMainPage *g_pCameraMainPage = nullptr; + +static constexpr uint16_t BLUETOOTH_XPOS = 158; +static constexpr uint16_t BLUETOOTH_XPOY = 154; +static constexpr uint16_t TITLE_XPOS = 15; +static constexpr uint16_t TITLE_XPOY = 329; +static constexpr uint16_t TITLE_WIDTH = 424; +static constexpr uint16_t TITLE_HIGHT = 50; +static constexpr uint16_t TITLE_FONT_SIZE = 36; +static constexpr uint16_t CAMERATITLE_FONT_SIZE = 38; +static constexpr uint16_t CAMERATITLE_XPOS = 97; +static constexpr uint16_t CAMERATITLE_XPOY = 37; +static constexpr uint16_t CAMERATITLE_WIDTH = 260; +static constexpr uint16_t CAMERATITLE_HIGHT = 53; +static constexpr uint16_t CAMERAFIND_XPOS = 123; +static constexpr uint16_t CAMERAFIND_XPOY = 200; +static constexpr uint16_t CAMERAFIND_WIDTH = 250; +static constexpr uint16_t CAMERAFIND_HIGHT = 42; +static constexpr uint16_t CAMERATIME_XPOS = 200; +static constexpr uint16_t BUTTON_WIDTH = 171; +static constexpr uint16_t BUTTON_HIGHT = 171; +static constexpr uint16_t COUNTDOWN_TIME = 5; +static constexpr uint16_t CAMERA_SIZE = 466; +static constexpr uint16_t CAMERA_BUTTON_POSITION_X = 144; +static constexpr uint16_t CAMERA_BUTTON_POSITION_Y = 154; +static constexpr uint16_t TIME_FONT_SIZE = 50; +static constexpr uint16_t CAMERATIME_HIGHT = 55; +static constexpr uint16_t ERROR_NUM = 2; + +REGIST_SLICE_PAGE(VIEW_CAMERA, CAMERA_PAGES::CAMERA_MAIN_PAGE, CameraMainPage, true); + +CameraMainPage::CameraMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraMainPage::CameraMainPage"); + ImageCacheManager::GetInstance().LoadAllInMultiRes(CAMERA_IMAGE); + g_pCameraMainPage = this; +} + +CameraMainPage::~CameraMainPage() +{ + g_pCameraMainPage = nullptr; + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + + if (title != nullptr) { + delete title; + title = nullptr; + } + + if (bluetoothDisconnected != nullptr) { + delete bluetoothDisconnected; + bluetoothDisconnected = nullptr; + } + + if (cameraFind != nullptr) { + delete cameraFind; + cameraFind = nullptr; + } + + if (cameraTitle != nullptr) { + delete cameraTitle; + cameraTitle = nullptr; + } + + if (cameraTime != nullptr) { + delete cameraTime; + cameraTime = nullptr; + } + + if (button != nullptr) { + delete button; + button = nullptr; + } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + + if (callBack_ != nullptr) { + delete callBack_; + callBack_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(CAMERA_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraMainPage::~CameraMainPage"); +} + +CameraMainPage *CameraMainPage::GetInstance() +{ + return g_pCameraMainPage; +} + +void CameraMainPage::OnStart(void *data) +{ + if (container_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CameraMainPage::new container fail"); + container_ = new UIScrollView(); + container_->SetPosition(0, 0, CAMERA_SIZE, CAMERA_SIZE); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + container_->SetTouchable(true); + container_->SetDraggable(true); + container_->SetOnDragListener(this); + + bluetoothDisconnected = new UIImageView(); + if (bluetoothDisconnected == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothDisconnected is nullptr"); + return; + } + LOADIMG::LoadImageViewImg(bluetoothDisconnected, CAMERA_IMAGE, IMAGE_CONVERTER_TOOL_CAMERA_2); + bluetoothDisconnected->SetPosition(BLUETOOTH_XPOS, BLUETOOTH_XPOY); + bluetoothDisconnected->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + bluetoothDisconnected->SetVisible(false); + container_->Add(bluetoothDisconnected); + + title = new UILabel(); + if (title == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title is nullptr"); + return; + } + title->SetText("蓝牙已断开"); + title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT_SIZE); + title->SetPosition(TITLE_XPOS, TITLE_XPOY, TITLE_WIDTH, TITLE_HIGHT); + title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title->SetVisible(false); + container_->Add(title); + + cameraTitle = new UILabel(); + if (cameraTitle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cameraTitle is nullptr"); + return; + } + cameraTitle->SetText("相机"); + cameraTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, CAMERATITLE_FONT_SIZE); + cameraTitle->SetPosition(CAMERATITLE_XPOS, CAMERATITLE_XPOY, CAMERATITLE_WIDTH, CAMERATITLE_HIGHT); + cameraTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + cameraTitle->SetVisible(false); + container_->Add(cameraTitle); + + cameraFind = new UILabel(); + if (cameraFind == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cameraFind is nullptr"); + return; + } + cameraFind->SetText("正在连接手机..."); + cameraFind->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT_SIZE); + cameraFind->SetPosition(CAMERAFIND_XPOS, CAMERAFIND_XPOY, CAMERAFIND_WIDTH, CAMERAFIND_HIGHT); + cameraFind->SetVisible(false); + container_->Add(cameraFind); + + cameraTime = new UILabel(); + if (cameraTime == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cameraTime is nullptr"); + return; + } + cameraTime->SetText("5s"); + cameraTime->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIME_FONT_SIZE); + cameraTime->SetPosition(CAMERATIME_XPOS, CAMERAFIND_XPOY, CAMERAFIND_WIDTH, CAMERATIME_HIGHT); + cameraTime->SetVisible(false); + container_->Add(cameraTime); + SetUpButton(); + callBack_ = new CameraAnimatorCallback(this); + animator_ = new Animator(callBack_, nullptr, 0, true); + + AddViewToPageContainer(container_); + InitCameraView(); +} + +uint8_t CameraMainPage::GetConnectStatus() +{ + uint8_t conn_status = 0; + +#ifdef _WIN32 + conn_status = 1; +#else + if (msg_center_get_trans_channel() == DIAG_FRAME_FID_PHONE) { + conn_status = is_spp_connected(0) == true ? 1 : 0; + } else if (msg_center_get_trans_channel() == DIAG_FRAME_FID_BT) { + conn_status = msg_center_get_ble_conn_state(); + } +#endif + return conn_status; +} + +void CameraMainPage::InitCameraView() +{ + if (GetConnectStatus() == 1) { + cameraTitle->SetVisible(true); + cameraFind->SetVisible(true); + title->SetVisible(false); + bluetoothDisconnected->SetVisible(false); + cameraTime->SetVisible(false); + button->SetVisible(false); + button->SetTouchable(false); + container_->Invalidate(); + uint8_t value = 1; + errcode_t ret; +#ifdef _WIN32 + ret = 0; +#else + ret = msg_center_send_data(MSGCENTER_CMD_DEVICE, + MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE, &value, sizeof(value)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE ret = %d", ret); +#endif + } else { + title->SetVisible(true); + bluetoothDisconnected->SetVisible(true); + cameraTitle->SetVisible(false); + cameraFind->SetVisible(false); + cameraTime->SetVisible(false); + button->SetVisible(false); + button->SetTouchable(false); + container_->Invalidate(); + } +} + +void CameraMainPage::Refresh_page() +{ + cameraTitle->SetVisible(true); + button->SetVisible(true); + button->SetTouchable(true); + cameraFind->SetVisible(false); + title->SetVisible(false); + bluetoothDisconnected->SetVisible(false); + cameraTime->SetVisible(false); + container_->Invalidate(); +} + +void CameraMainPage::SetUpButton() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraMainPage::SetupButton new Label"); + if (button == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "button is nullptr"); + button = new UILabelButton(); + } + + button->SetPosition(CAMERA_BUTTON_POSITION_X, CAMERA_BUTTON_POSITION_Y); + button->Resize(BUTTON_WIDTH, BUTTON_HIGHT); + button->SetViewId("button1"); + button->SetOnClickListener(this); + button->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::RELEASED); + button->SetVisible(false); + button->SetTouchable(false); + LOADIMG::LoadBtnImage(button, CAMERA_IMAGE, IMAGE_CONVERTER_TOOL_CAMERA_1, IMAGE_CONVERTER_TOOL_CAMERA_1); + container_->Add(button); +} + +void CameraMainPage::OnPause() +{ + animator_->Stop(); +} + +bool CameraMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (view.GetViewId() == "button1") { + if (GetConnectStatus() == 1) { + button->SetVisible(false); + cameraTime->SetVisible(true); + SetFirstFlag(true); + animator_->Start(); + } else { + title->SetVisible(true); + bluetoothDisconnected->SetVisible(true); + cameraTitle->SetVisible(false); + cameraFind->SetVisible(false); + cameraTime->SetVisible(false); + button->SetVisible(false); + button->SetTouchable(false); + container_->Invalidate(); + } + } + return true; +} + +bool CameraMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraPresenter::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, "CameraOnDragListener::OnDrag ChangeSlice(VIEW_APPLIST)"); + uint8_t value = 1; + errcode_t ret; +#ifdef _WIN32 + ret = 0; +#else + ret = msg_center_send_data(MSGCENTER_CMD_DEVICE, + MSGCENTER_TYPE_ID_CAMERA_PHONE_EXIT, &value, sizeof(value)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MSGCENTER_TYPE_ID_CAMERA_PHONE_EXIT ret = %d", ret); +#endif + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + return true; +} + +void CameraMainPage::CameraAnimatorCallback::Callback(UIView *view) +{ + (void)view; + static int count = 0; + static struct timeval start_time; + struct timeval current_time; + if (page_->GetFirstFlag()) { + gettimeofday(&start_time, nullptr); + page_->SetFirstFlag(false); + } + gettimeofday(¤t_time, nullptr); + int time = current_time.tv_sec - start_time.tv_sec; + std::string strTime1 = std::to_string(COUNTDOWN_TIME - time) + "s"; + page_->SetCameraTime(time); + if (time == COUNTDOWN_TIME) { + page_->StopAnimator(); + } +} + +void CameraMainPage::StopAnimator() +{ + animator_->Stop(); + button->SetVisible(true); + cameraTime->SetVisible(false); + cameraTime->SetText("5s"); + SetFirstFlag(false); + uint8_t value = 1; + errcode_t ret; +#ifdef _WIN32 + ret = 0; +#else + ret = msg_center_send_data(MSGCENTER_CMD_DEVICE, + MSGCENTER_TYPE_ID_ON_CAMERA, &value, sizeof(value)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MSGCENTER_TYPE_ID_ON_CAMERA ret = %d", ret); +#endif +} + +void CameraMainPage::SetCameraTime(int time) +{ + int progressTime = COUNTDOWN_TIME - time; + int progressValue = 0; + std::string strTime = std::to_string(COUNTDOWN_TIME - time) + "s"; + cameraTime->SetText(strTime.c_str()); +} + +bool CameraMainPage::GetFirstFlag() +{ + return isFirst; +} + +void CameraMainPage::SetFirstFlag(bool value) +{ + isFirst = value; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/camera/src/CameraModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/camera/src/CameraModel.cpp new file mode 100644 index 000000000..669c55b3d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/camera/src/CameraModel.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: CameraModel + * Created: 2025-06-05 + */ + +#include +#include "ohos_timer.h" +#include "wearable_log.h" +#include "camera/CameraModel.h" +#include "camera/CameraView.h" + +namespace OHOS { + +CameraModel::CameraModel() {} + +CameraModel::~CameraModel() {} + +CameraModel &CameraModel::GetInstance() +{ + static CameraModel instance; + return instance; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/camera/src/CameraPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/camera/src/CameraPresenter.cpp new file mode 100644 index 000000000..4d94013c8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/camera/src/CameraPresenter.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: CameraPresenter + * Created: 2025-06-05 + */ + +#include "uiservice/ui_service.h" +#include "NativeRegisterManager.h" +#include "camera/CameraView.h" +#include "camera/CameraModel.h" +#include "camera/CameraPresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_CAMERA, CameraView, CameraPresenter, CAMERA_MAIN_ICON, PNG_APPLIST_SETTING_IMAGE, "相机"); +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/AmbientClockView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/AmbientClockView.cpp index 7bc705a74..c0e50762d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/AmbientClockView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/AmbientClockView.cpp @@ -5,14 +5,18 @@ * Create: 2024-10-30 */ -#include "AmbientClockView.h" -#include "MainPresenterSample.h" +#include "clock/AmbientClockView.h" +#include "main/MainPresenterSample.h" #include "components/ui_label.h" #include "wearable_log.h" #include "ui_resource_image.h" #include "common/image_cache_manager.h" +#include "UICardPageFactory.h" namespace OHOS { + +REGIST_WATCH_DIAL(DIAL_DISPLAY_MODE_AOD, DIAL_CLOCK, AmbientClockView); + static constexpr uint16_t POINT_POSITION_X = 202; static constexpr uint16_t POINT_POSITION_Y = 16; static constexpr uint16_t SECOND_POINT_POSITION_Y = 16; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp index 9beeb512f..1fdfcf4da 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -5,15 +5,19 @@ * Create: 2021-08-14 */ -#include "MainClockView.h" -#include "MainPresenterSample.h" +#include "clock/MainClockView.h" +#include "main/MainPresenterSample.h" #include "components/ui_label.h" #include "wearable_log.h" #include "ui_resource_image.h" #include "common/image_cache_manager.h" +#include "UICardPageFactory.h" #include namespace OHOS { + +REGIST_WATCH_DIAL(DIAL_DISPLAY_MODE_MAIN, DIAL_CLOCK, MainClockView); + static MainClockView *g_pMainClockView = nullptr; static constexpr uint16_t FONT_DEFAULT_SIZE = 25; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassCalibrationView.h b/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassCalibrationView.h deleted file mode 100644 index 704e60d96..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassCalibrationView.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. - * Description: CompassCalibrationView.h - * Author: - * Create: 2022-04-02 - */ - -#ifndef COMPASS_CALIBRATION_VIEW_H -#define COMPASS_CALIBRATION_VIEW_H - -#include "components/ui_label.h" -#include "View.h" -#include "ohos_types.h" -#include "AppGroupView.h" -#include "components/ui_image_view.h" - -namespace OHOS { -class CompassCalibrationView : public AppGroupView { -public: - CompassCalibrationView(); - ~CompassCalibrationView() override; - - bool CreateUIViewGroup(void); - static CompassCalibrationView *GetInstance(void); - bool InitView(void *caller) override; -private: - UILabel *labelOne{nullptr}; - UILabel *labelTwo{nullptr}; - UIImageView *imageView{nullptr}; - - void ClearAll(void); -}; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassControlView.h b/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassControlView.h deleted file mode 100644 index 3dc43f20f..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassControlView.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. - * Description: CompassControlView.h - * Author: - * Create: 2022-04-02 - */ - -#ifndef COMPASS_CONTROL_VIEW_H -#define COMPASS_CONTROL_VIEW_H - -#include "components/root_view.h" -#include "UiConfig.h" -#include "components/ui_card_page.h" -#include "CompassCalibrationView.h" -#include "CompassView.h" - -namespace OHOS { - -class CompassControlView : public UICardPage { -public: - CompassControlView(); - ~CompassControlView() override; - bool InitView(void); - void PreLoad(void) override; - void UnLoad(void) override; - void SetCalibrationView(bool flag); -private: - CompassCalibrationView *compassCalibrationView{nullptr}; - CompassView *compassView{nullptr}; - bool viewiInitStatus{false}; - bool isCalibration{false}; - - void ClearAll(void); -}; -} -#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassModel.h b/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassModel.h deleted file mode 100644 index 80cfd2f6a..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassModel.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. - * Description: CompassModel.h - * Author: - * Create: 2022-04-02 - */ - -#ifndef COMPASS_MODEL_H -#define COMPASS_MODEL_H - -#include - -namespace OHOS { -class CompassModel { -public: - static CompassModel *GetInstance(void); - bool OpenCompassSensor(void); - bool CloseCompassSensor(void); - void SetCalibrationStatus(uint8_t status); - uint8_t GetCalibrationStatus(void); - void SetDisplayAngle(uint16_t angle); - uint16_t GetDisplayAngle(void); -#if defined(_WIN32) -#undef GetCurrentTime -#endif - time_t GetCurrentTime(void); - void SetLastTime(time_t value); - time_t GetLastTime(void); - -private: - uint8_t calibrationStatus{1}; - uint16_t displayAngle{0}; - time_t lastTime{0}; -}; -} - -#endif - diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassPresenter.h deleted file mode 100644 index 68d6877d8..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassPresenter.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: CompassPresenter.h - * Author: - * Create: 2021-12-21 - */ -#ifndef COMPASS_PRESENTER_H -#define COMPASS_PRESENTER_H - -#include "Presenter.h" -#include "components/ui_view.h" -#include "components/ui_image_view.h" -#include "ohos_types.h" -#include "UiConfig.h" -#include "AppViewIDs.h" -#include "CompassView.h" - -namespace OHOS { -typedef struct { - uint16_t beginAngle; - uint16_t endAngle; - const char *dir; -} CompassItem; - -class CompassView; -class CompassPresenter { -public: - CompassPresenter(); - virtual ~CompassPresenter(); - - static CompassPresenter *GetInstance(void); - void DisplayAngleDir(uint16_t angle); - void DetermineToRotate(void); - void InScopeRotate(void); - void TimeCreateRandomNum(void); - void DisplayAngleRight(uint16_t angle); - -private: - int16_t lastRotateAngle{0}; - int16_t currentRotateAngle{0}; - int16_t angleDiff{0}; - bool getAngleStatus{false}; - bool initDisplayStatus{true}; -}; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassView.h b/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassView.h deleted file mode 100644 index 97cd957d1..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassView.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: CompassView.h - * Author: - * Create: 2021-12-21 - */ - -#ifndef COMPASS_VIEW_H -#define COMPASS_VIEW_H - -#include "View.h" -#include "components/root_view.h" -#include "components/ui_label.h" -#include "components/ui_image_view.h" -#include "ChangeSliceListener.h" -#include "UiConfig.h" -#include "AppGroupView.h" -#include "CompassCalibrationView.h" - -namespace OHOS { -static constexpr float VIEW_CENTERS = 227; - -class CompassView : public AppGroupView { -public: - CompassView(); - ~CompassView() override; - - void DirectionSetText(const char *text, const char *angle); - static CompassView *GetInstance(void); - void CompassStartRotate(int16_t numb); - bool InitPage(void); - bool InitView(void *caller) override; - bool GetInitViewState(void); - bool InitCompassImage(void); - -private: - bool LoadCompassImage(UIImageView *view, uint32_t resId); - void ClearAll(void); - UILabel *directionLabel{nullptr}; - UILabel *angledLabel{nullptr}; - UIImageView *backGround{nullptr}; - UIImageView *rotateShaft{nullptr}; - UIImageView *triangulation{nullptr}; - const Vector2 VIEW_CENTER = {VIEW_CENTERS, VIEW_CENTERS}; -}; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/MainCompassPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/compass/include/MainCompassPresenter.h deleted file mode 100644 index cd025a41b..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/MainCompassPresenter.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainCompassPresenter.h - * Author: - * Create: 2021-12-21 - */ -#ifndef COMPASS_MAINPRESENTER_H -#define COMPASS_MAINPRESENTER_H - -#include "Presenter.h" -#include "ModelListenerSample.h" -#include "ohos_types.h" -#include "UiConfig.h" -#include "AppViewIDs.h" -#include "MainCompassView.h" -#include "CompassPresenter.h" -#include "CompassModel.h" -#include "CompassCalibrationView.h" - -namespace OHOS { -class MainCompassPresenter : public Presenter, public CompassPresenter, - public ModelListenerSample, public UIView::OnDragListener { -public: - MainCompassPresenter(); - ~MainCompassPresenter() override; - - static MainCompassPresenter *GetInstance(void); - bool OnDrag(UIView& view, const DragEvent& event) override; - void Notify() override; -}; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/MainCompassView.h b/code/sdk/application/wearable/nativeapp/nativeui/compass/include/MainCompassView.h deleted file mode 100644 index 306496a5a..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/include/MainCompassView.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainCompassView - * Author: - * Create: 2021-12-23 - */ - -#ifndef MAIN_COMPASS_VIEW_H -#define MAIN_COMPASS_VIEW_H - -#include -#include "View.h" -#include "components/ui_label.h" -#include "components/root_view.h" -#include "components/ui_view_group.h" -#include "components/ui_image_view.h" -#include "components/ui_label_button.h" -#include "ChangeSliceListener.h" -#include "graphic_config.h" -#include "CompassView.h" -#include "CompassModel.h" -#include "CompassCalibrationView.h" - -namespace OHOS { -class MainCompassPresenter; -class CompassView; -class MainCompassView : public View { -public: - MainCompassView(); - ~MainCompassView() override; - - void OnStart() override; - void OnStop() override; - - static MainCompassView *GetInstance(void); - void SetDisplayTure(void); - void SetDisplayFalse(void); - -private: - CompassView *compassView{nullptr}; - CompassCalibrationView *compassCalibrationView{nullptr}; -}; -} // namespace OHOS -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassCalibrationView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassCalibrationView.cpp deleted file mode 100644 index 390c0ae82..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassCalibrationView.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. - * Description: CompassCalibrationView.cpp - * Author: - * Create: 2022-04-02 - */ -#include "UiConfig.h" -#include "wearable_log.h" -#include "CompassCalibrationView.h" -#include "CompassModel.h" - -namespace OHOS { -// 标签设置 -static constexpr uint16_t LABEL_POSITION_X = 118; -static constexpr uint16_t LABEL_POSITION_Y = 80; -static constexpr uint16_t LABEL_POSITION_WIDTH = 200; -static constexpr uint16_t LABEL_POSITION_HEIGHT = 50; - -static constexpr uint16_t LABEL_POSITION_X1 = 28; -static constexpr uint16_t LABEL_POSITION_Y1 = 130; -static constexpr uint16_t LABEL_POSITION_WIDTH1 = 400; -static constexpr uint16_t LABEL_POSITION_HEIGHT1 = 50; -static constexpr uint16_t FONT_DEFAULT_SIZE = 35; - -static CompassCalibrationView *g_pMainView = nullptr; -CompassCalibrationView::CompassCalibrationView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::CompassCalibrationView"); - SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - g_pMainView = this; -} - -CompassCalibrationView::~CompassCalibrationView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::~CompassCalibrationView"); - ClearAll(); - g_pMainView = nullptr; -} - -void CompassCalibrationView::ClearAll(void) -{ - RemoveAll(); - if (labelOne != nullptr) { - delete labelOne; - labelOne = nullptr; - } - if (imageView != nullptr) { - delete imageView; - imageView = nullptr; - } - if (labelTwo != nullptr) { - delete labelTwo; - labelTwo = nullptr; - } -} - -CompassCalibrationView *CompassCalibrationView::GetInstance(void) -{ - return g_pMainView; -} - -bool CompassCalibrationView::CreateUIViewGroup(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::CreateUIViewGroup"); - imageView = new UIImageView(); - if (imageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new UIImageView fail"); - return false; - } - imageView->SetPosition(0, 0); - imageView->SetSrc(COMPASS_CALIBRATE_IMAGE); - - labelOne = new UILabel(); - if (labelOne == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new labelOne fail"); - ClearAll(); - return false; - } - - labelOne->SetPosition(LABEL_POSITION_X, LABEL_POSITION_Y, LABEL_POSITION_WIDTH, LABEL_POSITION_HEIGHT); - labelOne->SetText("请按图示"); - labelOne->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - labelOne->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - labelOne->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - labelOne->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - labelOne->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - - labelTwo = new UILabel(); - if (labelTwo == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new labelTwo fail"); - ClearAll(); - return false; - } - - labelTwo->SetPosition(LABEL_POSITION_X1, LABEL_POSITION_Y1, LABEL_POSITION_WIDTH1, LABEL_POSITION_HEIGHT1); - labelTwo->SetText("旋转手表进行校准"); - labelTwo->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - labelTwo->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - labelTwo->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - labelTwo->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - labelTwo->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - - Add(imageView); - Add(labelOne); - Add(labelTwo); - SetDraggable(false); - SetTouchable(false); - initViewStatus = true; - return true; -} - -bool CompassCalibrationView::InitView(void *caller) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView InitView %p", caller); - bool ret = CreateUIViewGroup(); - if (!ret) { - return false; - } - SetDraggable(true); - SetTouchable(true); - return true; -} - -} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassControlView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassControlView.cpp index 546dd33f8..d4139a5b9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassControlView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassControlView.cpp @@ -4,95 +4,64 @@ * Author: * Create: 2022-04-02 */ -#include "CompassControlView.h" -#include "CompassModel.h" +#include "compass/CompassControlView.h" +#include "wearable_log.h" namespace OHOS { CompassControlView::CompassControlView() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassControlView::CompassControlView()"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); } -CompassControlView::~CompassControlView() +void CompassControlView::PreLoad(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassControlView::~CompassControlView()"); - if (viewiInitStatus) { - ClearAll(); + if (compassFragment_ == nullptr) { + compassFragment_ = new CompassFragment(); + if (compassFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassView::new compassFragment_ fail"); + return; + } } + + compassFragment_->CreateView(); + Add(compassFragment_->GetFragmentView()); } -void CompassControlView::ClearAll(void) +void CompassControlView::UnLoad(void) { - RemoveAll(); - if (compassCalibrationView != nullptr) { - delete compassCalibrationView; - compassCalibrationView = nullptr; - } - if (compassView != nullptr) { - delete compassView; - compassView = nullptr; + if (compassFragment_ != nullptr) { + compassFragment_->DestroyView(); + Remove(compassFragment_->GetFragmentView()); + delete compassFragment_; + compassFragment_ = nullptr; } } -bool CompassControlView::InitView(void) +void CompassControlView::OnPause(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassControlView InitView"); - compassCalibrationView = new CompassCalibrationView(); - if (compassCalibrationView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new compassCalibrationView fail"); - return false; - } - if (!compassCalibrationView->CreateUIViewGroup()) { - return false; - } - - compassView = new CompassView(); - if (compassView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassView::new compassView fail"); - return false; + if (compassFragment_ != nullptr) { + compassFragment_->PauseView(); } - if (!compassView->InitPage()) { - return false; - } - Add(compassView); - Add(compassCalibrationView); - uint8_t status = CompassModel::GetInstance()->GetCalibrationStatus(); - if (status == 1) { - compassView->SetVisible(false); - compassCalibrationView->SetVisible(true); - } else { - compassView->SetVisible(true); - compassCalibrationView->SetVisible(false); - } - return true; } -void CompassControlView::SetCalibrationView(bool flag) +void CompassControlView::OnActive(void) { - if (flag == isCalibration) { - return; - } - - if (flag) { - compassCalibrationView->SetVisible(true); - compassView->SetVisible(false); - } else { - compassCalibrationView->SetVisible(false); - compassView->SetVisible(true); + if (compassFragment_ != nullptr) { + compassFragment_->ResumeView(); } } -void CompassControlView::PreLoad(void) +void CompassControlView::ScrollBegin(bool isActive) { - if (!viewiInitStatus) { - InitView(); - viewiInitStatus = true; + if (isActive && (compassFragment_ != nullptr)) { + compassFragment_->PauseView(); } } -void CompassControlView::UnLoad(void) +void CompassControlView::ScrollEnd(bool isActive) { - // Compass's usage scenes is complicated, so we do not release it's resources inner slice. + if (isActive && (compassFragment_ != nullptr)) { + compassFragment_->ResumeView(); + } } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassFragment.cpp b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassFragment.cpp new file mode 100644 index 000000000..cca744b26 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassFragment.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CompassFragment.cpp + * Author: + * Create: 2021-12-21 + */ +#include "compass/CompassFragment.h" + +#include +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_resource_image.h" +#include "compass/CompassModel.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr float VIEW_CENTERS = 227; +static constexpr int16_t POINT_CENTER_IMAGE_X = 150; +static constexpr int16_t POINT_CENTER_IMAGE_Y = 150; +static constexpr int16_t trianImg__X = 210; +static constexpr int16_t trianImg__Y = 0; +static constexpr int16_t directionLabel__X = 160; +static constexpr int16_t directionLabel__Y = 215; +static constexpr int16_t FONT_TEXT_SIZE = 25; +static constexpr int16_t angleLabel__X = 215; +static constexpr int16_t angleLabel__Y = 215; +static constexpr int16_t TEXT_WIDTH = 90; +static constexpr int16_t TEXT_HEIGHT = 35; +static constexpr int16_t RANDOM_NUMBER_720 = 720; +static constexpr int16_t RANDOM_NUMBER_360 = 360; +static constexpr int16_t DELAYING_NUMS = 2000; +static constexpr int16_t RIGHT_NORTH_DOWN_23 = 23; +static constexpr int16_t RIGHT_EASTNORTH_UP_68 = 68; +static constexpr int16_t RIGHT_WESTNORTH_UP_338 = 338; +static constexpr int16_t RIGHT_SOUTH_UP_203 = 203; +static constexpr int16_t RIGHT_EASTSOUTH_UP_158 = 158; +static constexpr int16_t RIGHT_WESTSOUTH_UP_248 = 248; +static constexpr int16_t RIGHT_WEST_UP_293 = 293; +static constexpr int16_t RIGHT_EAST_UP_113 = 113; +static constexpr int16_t DIRECTION_COUNT = 7; + +typedef struct { + uint16_t beginAngle; + uint16_t endAngle; + const char *dir; +} CompassItem; + +const CompassItem g_compassList[] = { + {RIGHT_NORTH_DOWN_23, RIGHT_EASTNORTH_UP_68, "东北"}, + {RIGHT_EASTNORTH_UP_68, RIGHT_EAST_UP_113, "东"}, + {RIGHT_EAST_UP_113, RIGHT_EASTSOUTH_UP_158, "东南"}, + {RIGHT_EASTSOUTH_UP_158, RIGHT_SOUTH_UP_203, "南"}, + {RIGHT_SOUTH_UP_203, RIGHT_WESTSOUTH_UP_248, "西南"}, + {RIGHT_WESTSOUTH_UP_248, RIGHT_WEST_UP_293, "西"}, + {RIGHT_WEST_UP_293, RIGHT_WESTNORTH_UP_338, "西北"} +}; + +void CompassFragment::Callback(void) +{ + if (!initialized_) { + return; + } + int16_t angle = CompassModel::GetInstance()->GetAngle(); + bgImg_->Rotate(-angle, Vector2(VIEW_CENTERS, VIEW_CENTERS)); + if ((angle >= RIGHT_WESTNORTH_UP_338) || (angle >= 0 && angle < RIGHT_NORTH_DOWN_23)) { + directionLabel_->SetText("北"); + angleLabel_->SetText((std::to_string(angle) + "°").c_str()); + } + for (int i = 0; i < DIRECTION_COUNT; i++) { + if ((angle >= g_compassList[i].beginAngle) && (angle < g_compassList[i].endAngle)) { + directionLabel_->SetText(g_compassList[i].dir); + angleLabel_->SetText((std::to_string(angle) + "°").c_str()); + } + } + CompassModel::GetInstance()->UpdateAngle(); +} + +bool CompassFragment::LoadCompassImage(UIImageView *view, uint32_t resId) +{ + std::string file = COMPASS_IAMGES; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassFragment LoadCompassImage: %s, resID=0x%x", COMPASS_IAMGES, resId); + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassFragment::LoadCompassImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; +} + +bool CompassFragment::InitCompassImage(void) +{ + bgImg_ = new UIImageView(); + if (bgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], bgImg_ new fail", __LINE__); + return false; + } + bgImg_->SetPosition(0, 0); + + if (!LoadCompassImage(bgImg_, COMPASS_COMPASS)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], trianImg_ load fail", __LINE__); + return false; + } + + fgImg_ = new UIImageView(); + if (fgImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], fgImg_ new fail", __LINE__); + return false; + } + fgImg_->SetPosition(POINT_CENTER_IMAGE_X, POINT_CENTER_IMAGE_Y); + if (!LoadCompassImage(fgImg_, COMPASS_ROTATE_CENTER_IMAGE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], fgImg_ load fail", __LINE__); + return false; + } + + trianImg_ = new UIImageView(); + if (trianImg_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], trianImg_ new fail", __LINE__); + return false; + } + trianImg_->SetPosition(trianImg__X, trianImg__Y); + if (!LoadCompassImage(trianImg_, COMPASS_CORRESPONDENCE_DEGREE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "trianImg_ load fail"); + return false; + } + return true; +} + +void CompassFragment::OnCreateView(void* data) +{ + fragmentView_.SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassFragment InitView"); + if (!InitCompassImage()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitCompassImage fail"); + initialized_ = false; + return; + } + + directionLabel_ = new UILabel(); + if (directionLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "directionLabel_ new fail"); + initialized_ = false; + return; + } + directionLabel_->SetPosition(directionLabel__X, directionLabel__Y); + directionLabel_->Resize(TEXT_WIDTH, TEXT_HEIGHT); + directionLabel_->SetText("北"); + directionLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); + directionLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + directionLabel_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + directionLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + directionLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + + angleLabel_ = new UILabel(); + if (angleLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "angleLabel_ new fail"); + initialized_ = false; + return; + } + angleLabel_->SetPosition(angleLabel__X, angleLabel__Y); + angleLabel_->Resize(TEXT_WIDTH, TEXT_HEIGHT); + angleLabel_->SetText("0°"); + angleLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); + angleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + angleLabel_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + angleLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + angleLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + + fragmentView_.Add(bgImg_); + fragmentView_.Add(fgImg_); + fragmentView_.Add(trianImg_); + fragmentView_.Add(directionLabel_); + fragmentView_.Add(angleLabel_); + CompassModel::GetInstance()->ResetAngle(); + initialized_ = true; +} + +void CompassFragment::OnPauseView() +{ + Deinit(); +} + +void CompassFragment::OnResumeView() +{ + Init(); +} + +void CompassFragment::OnDestroyView() +{ + Deinit(); + fragmentView_.RemoveAll(); + if (directionLabel_ != nullptr) { + delete directionLabel_; + directionLabel_= nullptr; + } + if (angleLabel_ != nullptr) { + delete angleLabel_; + angleLabel_ = nullptr; + } + if (bgImg_ != nullptr) { + delete bgImg_; + bgImg_ = nullptr; + } + if (fgImg_ != nullptr) { + delete fgImg_; + fgImg_ = nullptr; + } + if (trianImg_ != nullptr) { + delete trianImg_; + trianImg_ = nullptr; + } +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassModel.cpp index e9ff3f5c8..80774e6a6 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassModel.cpp @@ -5,9 +5,8 @@ * Create: 2022-04-02 */ -#include -#include "CompassModel.h" -#include +#include "compass/CompassModel.h" +#include "gfx_utils/graphic_math.h" #ifdef __cplusplus extern "C" { @@ -20,59 +19,50 @@ using namespace OHOS; #endif namespace OHOS { +static constexpr int16_t DELTA_ANGLE = 1; + CompassModel *CompassModel::GetInstance(void) { static CompassModel instance; return &instance; } -void CompassModel::SetCalibrationStatus(uint8_t status) -{ - calibrationStatus = status; -} - -uint8_t CompassModel::GetCalibrationStatus(void) +void CompassModel::UpdateAngle() { - return 0; -} - -void CompassModel::SetDisplayAngle(uint16_t angle) -{ - displayAngle += angle; - if (displayAngle > 359) { - displayAngle = 0; + if (clockwise_) { + angle_ += DELTA_ANGLE; + } else { + angle_ -= DELTA_ANGLE; + } + if (angle_ >= CIRCLE_IN_DEGREE) { + angle_ = 360; + clockwise_ = false; + } + if (angle_ <= 0) { + angle_ = 0; + clockwise_ = true; } } -uint16_t CompassModel::GetDisplayAngle(void) -{ - return displayAngle; -} - -void CompassModel::SetLastTime(time_t value) -{ - lastTime = value; -} - -time_t CompassModel::GetLastTime(void) +int16_t CompassModel::GetAngle(void) { - return lastTime; + return angle_; } -time_t CompassModel::GetCurrentTime(void) +void CompassModel::ResetAngle(void) { - struct timeval tv; - gettimeofday(&tv, nullptr); - return tv.tv_sec; + angle_ = 0; } bool CompassModel::OpenCompassSensor(void) { + // Add implemetion later return true; } bool CompassModel::CloseCompassSensor(void) { + // Add implemetion later return true; } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassPresenter.cpp deleted file mode 100644 index 4a48b5458..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassPresenter.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: CompassPresenter.cpp - * Author: - * Create: 2021-12-21 - */ -#include "CompassView.h" -#include "CompassPresenter.h" -#include "CompassModel.h" -#include "graphic_service.h" - -namespace OHOS { -static constexpr int16_t RIGHT_NORTH_DOWN_23 = 23; -static constexpr int16_t RIGHT_EASTNORTH_UP_68 = 68; -static constexpr int16_t RIGHT_WESTNORTH_UP_338 = 338; -static constexpr int16_t RIGHT_SOUTH_UP_203 = 203; -static constexpr int16_t RIGHT_EASTSOUTH_UP_158 = 158; -static constexpr int16_t RIGHT_WESTSOUTH_UP_248 = 248; -static constexpr int16_t RIGHT_WEST_UP_293 = 293; -static constexpr int16_t RIGHT_EAST_UP_113 = 113; -static constexpr int16_t RIGHT_MAX_ANGLE_360 = 360; -static constexpr int16_t RIGHT_HALF_ANGLE_180 = 180; -static constexpr int16_t RIGHT_ROTATION_INTERVAL = 2; -static constexpr int16_t DIRECTION_COUNT = 7; -static constexpr int16_t LEFT_NORTH_DOWN_23 = -23; -static constexpr int16_t LEFT_EASTNORTH_DOWN_337 = -337; -static constexpr int16_t LEFT_WESTNORTH_DOWN_68 = -68; -static constexpr int16_t LEFT_SOUTH_DOWN_202 = -202; -static constexpr int16_t LEFT_EASTSOUTH_DOWN_247 = -247; -static constexpr int16_t LEFT_WESTSOUTH_DOWN_157 = -157; -static constexpr int16_t LEFT_WEST_DOWN_113 = -113; -static constexpr int16_t LEFT_EAST_DOWN_292 = -292; -static constexpr int16_t RIGHT_MIN_ANGLE_360 = -360; -static constexpr int16_t LEFT_HALF_ANGLE_180 = -180; -static constexpr int16_t LEFT_ROTATION_INTERVAL = -2; - -static constexpr const char *NORTH_DIRECTION = (char *)"北"; -static constexpr const char *SOUTH_DIRECTION = (char *)"南"; -static constexpr const char *WEST_DIRECTION = (char *)"西"; -static constexpr const char *EAST_DIRECTION = (char *)"东"; -static constexpr const char *WESTNORTH_DIRECTION = (char *)"西北"; -static constexpr const char *WESTSOUTH_DIRECTION = (char *)"西南"; -static constexpr const char *EASTSOUTH_DIRECTION = (char *)"东南"; -static constexpr const char *EASTNORTH_DIRECTION = (char *)"东北"; - -const CompassItem g_compassList[] = { - {RIGHT_NORTH_DOWN_23, RIGHT_EASTNORTH_UP_68, EASTNORTH_DIRECTION}, - {RIGHT_EASTNORTH_UP_68, RIGHT_EAST_UP_113, EAST_DIRECTION}, - {RIGHT_EAST_UP_113, RIGHT_EASTSOUTH_UP_158, EASTSOUTH_DIRECTION}, - {RIGHT_EASTSOUTH_UP_158, RIGHT_SOUTH_UP_203, SOUTH_DIRECTION}, - {RIGHT_SOUTH_UP_203, RIGHT_WESTSOUTH_UP_248, WESTSOUTH_DIRECTION}, - {RIGHT_WESTSOUTH_UP_248, RIGHT_WEST_UP_293, WEST_DIRECTION}, - {RIGHT_WEST_UP_293, RIGHT_WESTNORTH_UP_338, WESTNORTH_DIRECTION} -}; - -static CompassPresenter *g_pMainView = nullptr; - -CompassPresenter::CompassPresenter() -{ - g_pMainView = this; -} - -CompassPresenter::~CompassPresenter() -{ - g_pMainView = nullptr; -} - -CompassPresenter* CompassPresenter::GetInstance(void) -{ - return g_pMainView; -} - -void CompassPresenter::DisplayAngleRight(uint16_t angle) -{ - if ((angle >= RIGHT_WESTNORTH_UP_338) || (angle >= 0 && angle < RIGHT_NORTH_DOWN_23)) { - CompassView::GetInstance()->DirectionSetText(NORTH_DIRECTION, (std::to_string(angle) + "°").c_str()); - } - for (int i = 0; i < DIRECTION_COUNT; i++) { - if ((angle >= g_compassList[i].beginAngle) && (angle < g_compassList[i].endAngle)) { - CompassView::GetInstance()->DirectionSetText(g_compassList[i].dir, (std::to_string(angle) + "°").c_str()); - } - } -} - -void CompassPresenter::DisplayAngleDir(uint16_t angle) -{ - if (CompassView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DisplayAngleDir]CompassView::GetInstance() is nullptr"); - return; - } - if (angle >= 0 && angle <= RIGHT_MAX_ANGLE_360) { - DisplayAngleRight(angle); - } -} - - -void CompassPresenter::InScopeRotate(void) -{ - angleDiff = lastRotateAngle - currentRotateAngle; - if (angleDiff > LEFT_HALF_ANGLE_180 && angleDiff < RIGHT_HALF_ANGLE_180) { - if (lastRotateAngle < currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - if (angleDiff <= LEFT_ROTATION_INTERVAL) { - lastRotateAngle+=RIGHT_ROTATION_INTERVAL; - } else { - lastRotateAngle++; - } - } else if (lastRotateAngle != currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - if (angleDiff >= RIGHT_ROTATION_INTERVAL) { - lastRotateAngle-=RIGHT_ROTATION_INTERVAL; - } else { - lastRotateAngle--; - } - } - } else { - if (lastRotateAngle < currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - if (angleDiff <= LEFT_ROTATION_INTERVAL) { - lastRotateAngle-=RIGHT_ROTATION_INTERVAL; - } else { - lastRotateAngle--; - } - if (lastRotateAngle <= 0) { - lastRotateAngle = RIGHT_MAX_ANGLE_360; - } - } else if (lastRotateAngle != currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - if (angleDiff >= RIGHT_ROTATION_INTERVAL) { - lastRotateAngle+=RIGHT_ROTATION_INTERVAL; - } else { - lastRotateAngle++; - } - if (lastRotateAngle >= RIGHT_MAX_ANGLE_360) { - lastRotateAngle = 0; - } - } - } -} - -void CompassPresenter::DetermineToRotate(void) -{ - if (CompassView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DetermineToRotate]CompassView::GetInstance() is nullptr"); - return; - } - bool initState = CompassView::GetInstance()->GetInitViewState(); - if (initState) { - if (initDisplayStatus) { - currentRotateAngle = CompassModel::GetInstance()->GetDisplayAngle(); - lastRotateAngle = currentRotateAngle; - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - DisplayAngleDir(currentRotateAngle); - initDisplayStatus = false; - } else { - if (!getAngleStatus) { - currentRotateAngle = CompassModel::GetInstance()->GetDisplayAngle(); - } - InScopeRotate(); - getAngleStatus = true; - if (lastRotateAngle == currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - DisplayAngleDir(currentRotateAngle); - getAngleStatus = false; - } - } - } - CompassModel::GetInstance()->SetDisplayAngle(1); -} - -} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassView.cpp deleted file mode 100644 index 5b3bbc27d..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassView.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: CompassView.cpp - * Author: - * Create: 2021-12-21 - */ -#include -#include "common/image_cache_manager.h" -#include "ui_resource_image.h" -#include "CompassView.h" -#include "MainCompassView.h" - -namespace OHOS { -static constexpr int16_t POINT_CENTER_IMAGE_X = 150; -static constexpr int16_t POINT_CENTER_IMAGE_Y = 150; -static constexpr int16_t TRIANGULATION_X = 210; -static constexpr int16_t TRIANGULATION_Y = 0; -static constexpr int16_t DIRECTIONLABEL_X = 160; -static constexpr int16_t DIRECTIONLABEL_Y = 215; -static constexpr int16_t FONT_TEXT_SIZE = 25; -static constexpr int16_t ANGLEDLABEL_X = 215; -static constexpr int16_t ANGLEDLABEL_Y = 215; -static constexpr int16_t TEXT_WIDTH = 90; -static constexpr int16_t TEXT_HEIGHT = 35; -static constexpr int16_t RANDOM_NUMBER_720 = 720; -static constexpr int16_t RANDOM_NUMBER_360 = 360; -static constexpr int16_t DELAYING_NUMS = 2000; - -static CompassView *g_pCompassView = nullptr; - -CompassView::CompassView() -{ - SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - g_pCompassView = this; -} - -CompassView::~CompassView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassView::~CompassView()"); - ClearAll(); - g_pCompassView = nullptr; -} - -void CompassView::ClearAll(void) -{ - RemoveAll(); - if (directionLabel != nullptr) { - delete directionLabel; - directionLabel= nullptr; - } - if (angledLabel != nullptr) { - delete angledLabel; - angledLabel = nullptr; - } - if (backGround != nullptr) { - delete backGround; - backGround = nullptr; - } - if (rotateShaft != nullptr) { - delete rotateShaft; - rotateShaft = nullptr; - } - if (triangulation != nullptr) { - delete triangulation; - triangulation = nullptr; - } -} - -void CompassView::DirectionSetText(const char *text, const char *angle) -{ - directionLabel->SetText(text); - angledLabel->SetText(angle); -} - -bool CompassView::LoadCompassImage(UIImageView *view, uint32_t resId) -{ - std::string file = COMPASS_IAMGES; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassView LoadCompassImage: %s, resID=0x%x", COMPASS_IAMGES, resId); - ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); - if (image == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassView::LoadCompassImage %x fail", resId); - return false; - } - view->SetSrc(image); - return true; -} - -bool CompassView::InitCompassImage(void) -{ - backGround = new UIImageView(); - if (backGround == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], backGround new fail", __LINE__); - return false; - } - backGround->SetPosition(0, 0); - - if (!LoadCompassImage(backGround, COMPASS_COMPASS)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], triangulation load fail", __LINE__); - return false; - } - - rotateShaft = new UIImageView(); - if (rotateShaft == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], rotateShaft new fail", __LINE__); - return false; - } - rotateShaft->SetPosition(POINT_CENTER_IMAGE_X, POINT_CENTER_IMAGE_Y); - if (!LoadCompassImage(rotateShaft, COMPASS_ROTATE_CENTER_IMAGE)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], rotateShaft load fail", __LINE__); - return false; - } - - triangulation = new UIImageView(); - if (triangulation == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], triangulation new fail", __LINE__); - return false; - } - triangulation->SetPosition(TRIANGULATION_X, TRIANGULATION_Y); - if (!LoadCompassImage(triangulation, COMPASS_CORRESPONDENCE_DEGREE)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "triangulation load fail"); - return false; - } - return true; -} - -bool CompassView::InitPage(void) -{ - if (!InitCompassImage()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitCompassImage fail"); - ClearAll(); - return false; - } - - directionLabel = new UILabel(); - if (directionLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "directionLabel new fail"); - ClearAll(); - return false; - } - directionLabel->SetPosition(DIRECTIONLABEL_X, DIRECTIONLABEL_Y); - directionLabel->Resize(TEXT_WIDTH, TEXT_HEIGHT); - directionLabel->SetText("北"); - directionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); - directionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - directionLabel->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - directionLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - directionLabel->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - - angledLabel = new UILabel(); - if (angledLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "angledLabel new fail"); - ClearAll(); - return false; - } - angledLabel->SetPosition(ANGLEDLABEL_X, ANGLEDLABEL_Y); - angledLabel->Resize(TEXT_WIDTH, TEXT_HEIGHT); - angledLabel->SetText("0°"); - angledLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); - angledLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - angledLabel->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - angledLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - angledLabel->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - - Add(backGround); - Add(rotateShaft); - Add(triangulation); - Add(directionLabel); - Add(angledLabel); - SetDraggable(false); - SetTouchable(false); - initViewStatus = true; - return true; -} - - -bool CompassView::InitView(void *caller) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassView InitView %p", caller); - if (!InitPage()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitPage fail"); - return false; - } - SetDraggable(true); - SetTouchable(true); - return true; -} - -bool CompassView::GetInitViewState(void) -{ - return initViewStatus; -} - -CompassView *CompassView::GetInstance(void) -{ - return g_pCompassView; -} - -void CompassView::CompassStartRotate(int16_t numb) -{ - if (backGround == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGround is nullptr"); - return; - } - backGround->Rotate(-numb, VIEW_CENTER); -} -} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp index 72dc3b726..11a3b45cd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp @@ -4,54 +4,36 @@ * Author: * Create: 2021-12-21 */ -#include "CompassView.h" -#include "MainCompassPresenter.h" -#include "MainCompassView.h" +#include "compass/MainCompassPresenter.h" +#include "compass/MainCompassView.h" #include "NativeRegisterManager.h" namespace OHOS { -REGIST_MENU(VIEW_COMPASS, MainCompassView, MainCompassPresenter, PNG_APPLIST_COMPASS_IMAGE, PNG_APPLIST_DEFAULT_IMG, "指南针"); - -static MainCompassPresenter *g_pMainView = nullptr; - -MainCompassPresenter::MainCompassPresenter() -{ - g_pMainView = this; -} - -MainCompassPresenter::~MainCompassPresenter() -{ - g_pMainView = nullptr; -} - - -MainCompassPresenter* MainCompassPresenter::GetInstance() -{ - return g_pMainView; -} +REGIST_MENU(VIEW_COMPASS, MainCompassView, MainCompassPresenter, PNG_APPLIST_COMPASS_IMAGE, + PNG_APPLIST_DEFAULT_IMG, "指南针"); bool MainCompassPresenter::OnDrag(UIView& view, const DragEvent& event) { UNUSED(view); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); } return true; } -void MainCompassPresenter::Notify() +void MainCompassPresenter::OnResume() { - if (MainCompassView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[Notify]MainCompassView::GetInstance() == nullptr"); - return; + if ((view_ != nullptr) && (view_->compassFragment_ != nullptr)) { + view_->compassFragment_->ResumeView(); } - uint8_t status = CompassModel::GetInstance()->GetCalibrationStatus(); - if (status == 1) { - MainCompassView::GetInstance()->SetDisplayTure(); - } else { - MainCompassView::GetInstance()->SetDisplayFalse(); - DetermineToRotate(); +} + +void MainCompassPresenter::OnPause() +{ + if ((view_ != nullptr) && (view_->compassFragment_ != nullptr)) { + view_->compassFragment_->PauseView(); } } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassView.cpp index b5311d462..9f7ecb0fa 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassView.cpp @@ -5,107 +5,36 @@ * Create: 2021-12-23 */ -#include "MainCompassView.h" -#include "MainCompassPresenter.h" +#include "compass/MainCompassView.h" +#include "compass/MainCompassPresenter.h" +#include "compass/CompassModel.h" +#include "wearable_log.h" namespace OHOS { static constexpr int16_t TWO_HOUR_SECOND = 7200; -static MainCompassView *g_pMainCompassView = nullptr; - -MainCompassView::MainCompassView() -{ - g_pMainCompassView = this; -} - -MainCompassView::~MainCompassView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCompassView::~MainCompassView"); - delete compassView; - compassView = nullptr; - delete compassCalibrationView; - compassCalibrationView = nullptr; - g_pMainCompassView = nullptr; -} - -MainCompassView *MainCompassView::GetInstance() -{ - return g_pMainCompassView; -} - -void MainCompassView::SetDisplayTure() -{ - if (compassView == nullptr || compassCalibrationView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCompassView::SetDisplayTure null"); - return; - } - compassView->SetVisible(false); - compassCalibrationView->SetVisible(true); -} - -void MainCompassView::SetDisplayFalse() -{ - if (compassView == nullptr || compassCalibrationView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCompassView::SetDisplayFalse null"); - return; - } - compassView->SetVisible(true); - compassCalibrationView->SetVisible(false); -} void MainCompassView::OnStart() { - - compassCalibrationView = new CompassCalibrationView(); - if (compassCalibrationView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCompassView:: OnStart compassCalibrationView null"); - return; - } - - compassView = new CompassView(); - if (compassView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCompassView:: OnStart compassView null"); + compassFragment_ = new CompassFragment(); + if (compassFragment_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCompassView:: OnStart compassFragment_ null"); return; } - - UIView::OnDragListener *compassCalibrationDragListener = (UIView::OnDragListener *) - OHOS::MainCompassPresenter::GetInstance(); - if (compassCalibrationDragListener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "compassCalibrationDragListener new fail"); - return; - } - - UIView::OnDragListener *compassDragListener = (UIView::OnDragListener *)OHOS::MainCompassPresenter::GetInstance(); - if (compassDragListener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "compassDragListener new fail"); - return; - } - compassView->SetOnDragListener(compassDragListener); - compassView->InitView(this); - - compassCalibrationView->SetOnDragListener(compassCalibrationDragListener); - compassCalibrationView->InitView(this); - AddViewToRootContainer(compassView); - AddViewToRootContainer(compassCalibrationView); - - time_t currTime = CompassModel::GetInstance()->GetCurrentTime(); - time_t lastTime = CompassModel::GetInstance()->GetLastTime(); - if (currTime >= TWO_HOUR_SECOND + lastTime) { - CompassModel::GetInstance()->SetCalibrationStatus(1); - } - - uint8_t status = CompassModel::GetInstance()->GetCalibrationStatus(); - if (status == 1) { - compassView->SetVisible(false); - compassCalibrationView->SetVisible(true); - } else { - compassView->SetVisible(true); - compassCalibrationView->SetVisible(false); - } + compassFragment_->CreateView(); + compassFragment_->GetFragmentView()->SetTouchable(true); + compassFragment_->GetFragmentView()->SetDraggable(true); + compassFragment_->GetFragmentView()->SetOnDragListener(presenter_); + AddViewToRootContainer(compassFragment_->GetFragmentView()); CompassModel::GetInstance()->OpenCompassSensor(); } void MainCompassView::OnStop() { + if (compassFragment_ != nullptr) { + compassFragment_->DestroyView(); + delete compassFragment_; + compassFragment_ = nullptr; + } CompassModel::GetInstance()->CloseCompassSensor(); return; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectOpenView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectOpenView.cpp index ac8fee5af..2b5a5f419 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectOpenView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectOpenView.cpp @@ -3,11 +3,12 @@ * Description: ConnectOpen View * Create: 2022-03-22 */ -#include "ConnectOpenView.h" +#include "connectnewphone/ConnectOpenView.h" +#include "PageTransitionMgr.h" #include "wearable_log.h" #include "UiConfig.h" -#include "ConnectPhonePresenter.h" -#include "BluetoothModel.h" +#include "connectnewphone/ConnectPhonePresenter.h" +#include "bluetooth/BluetoothModel.h" namespace OHOS { static ConnectOpenView *g_pConnectOpenView{nullptr}; @@ -120,7 +121,7 @@ UIViewGroup *ConnectOpenView::InitShowUpView(void) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsDragListener GetInstance fail"); return nullptr; } - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly + if (!PageTransitionMgr::GetInstance().CanSlideBack()) { // support default slide back firstly group->SetOnDragListener(tipsDragListener); } group->SetViewId(CONNECT_OPEN_VIEW); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectPhonePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectPhonePresenter.cpp index 4994756ca..a9a89852c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectPhonePresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectPhonePresenter.cpp @@ -4,13 +4,13 @@ * Create: 2022-01-19 */ -#include "ConnectPhonePresenter.h" -#include "ConnectPhoneView.h" +#include "connectnewphone/ConnectPhonePresenter.h" +#include "connectnewphone/ConnectPhoneView.h" #include "drag_event.h" #include "cmsis_os.h" #include "UiConfig.h" #include "wearable_log.h" -#include "ui_service.h" +#include "uiservice/ui_service.h" #include "NativeRegisterManager.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectPhoneView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectPhoneView.cpp index 5e9c6b58c..1e5b1c109 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectPhoneView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectPhoneView.cpp @@ -4,7 +4,7 @@ * Create: 2022-01-19 */ -#include "ConnectPhoneView.h" +#include "connectnewphone/ConnectPhoneView.h" #include "components/ui_label.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectSelectView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectSelectView.cpp index 3a4196111..4465006bc 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectSelectView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/src/ConnectSelectView.cpp @@ -3,10 +3,11 @@ * Description: ConnectSelect View * Create: 2022-03-22 */ -#include "ConnectSelectView.h" +#include "connectnewphone/ConnectSelectView.h" +#include "PageTransitionMgr.h" #include "wearable_log.h" #include "UiConfig.h" -#include "ConnectPhonePresenter.h" +#include "connectnewphone/ConnectPhonePresenter.h" namespace OHOS { static ConnectSelectView *g_pConnectSelectView{nullptr}; @@ -109,7 +110,7 @@ UIViewGroup *ConnectSelectView::InitShowUpView() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "connectDragListener GetInstance fail"); return nullptr; } - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly + if (!PageTransitionMgr::GetInstance().CanSlideBack()) { // support default slide back firstly group->SetOnDragListener(connectDragListener); } group->SetViewId(CONNECT_SELECT_VIEW); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateAdapter.cpp new file mode 100644 index 000000000..944e5b6fc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateAdapter.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateAdapter + * Create: 2025-03-23 + */ + +#include "date/DateAdapter.h" + +namespace OHOS { +DateAdapter::DateAdapter() {} + +DateAdapter::~DateAdapter() +{ + listData.clear(); +} + +uint16_t DateAdapter::GetCount(void) +{ + return listData.size(); +} + +void DateAdapter::SetData(std::list &data) +{ + if (!listData.empty()) { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) { + listData.push_back(*it); + } +} + +UIView *DateAdapter::GetView(UIView *inView, int16_t index) +{ + if (listData.empty()) { + return nullptr; + } + if (index < 0) { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData.size()) { + return nullptr; + } + + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) { + it++; + } + DateItem itemData = *it; + DateItemView *item = nullptr; + if (inView == nullptr) { + item = new DateItemView(); + } else { + item = static_cast(inView); + } + + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + return item; +} + +void DateAdapter::AddListItem(const DateItem &item) +{ + listData.push_back(item); +} + +void DateAdapter::ClearListItem() +{ + listData.clear(); +} + +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateButtonAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateButtonAdapter.cpp new file mode 100644 index 000000000..c187d094c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateButtonAdapter.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateButtonAdapter + * Create: 2025-03-23 + */ + +#include "date/DateButtonAdapter.h" + +namespace OHOS { +DateButtonAdapter::DateButtonAdapter() {} + +DateButtonAdapter::~DateButtonAdapter() +{ + listData.clear(); +} + +uint16_t DateButtonAdapter::GetCount(void) +{ + return listData.size(); +} + +void DateButtonAdapter::SetData(std::list &data) +{ + if (!listData.empty()) { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) { + listData.push_back(*it); + } +} + +UIView *DateButtonAdapter::GetView(UIView *inView, int16_t index) +{ + if (listData.empty()) { + return nullptr; + } + if (index < 0) { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData.size()) { + return nullptr; + } + + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) { + it++; + } + DateButtonItem itemData = *it; + DateButtonItemView *item = nullptr; + if (inView == nullptr) { + item = new DateButtonItemView(); + } else { + item = static_cast(inView); + } + + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + return item; +} + +void DateButtonAdapter::AddListItem(const DateButtonItem &item) +{ + listData.push_back(item); +} + +void DateButtonAdapter::ClearListItem() +{ + listData.clear(); +} + +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateButtonItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateButtonItemView.cpp new file mode 100644 index 000000000..210f188bc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateButtonItemView.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateButtonItemView + * Create: 2025-03-23 + */ + +#include "date/DateButtonItemView.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_resource_date.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr int16_t DATE_ITEM_BUTTON_POSITION_X = 0; +static constexpr int16_t DATE_ITEM_BUTTON_POSITION_Y = 20; +static constexpr int16_t DATE_ITEM_BUTTON_WIDTH = 80; +static constexpr int16_t DATE_ITEM_BUTTON_HEIGHT = 55; +static constexpr int16 DATE_ITEM_FONT_SIZE = 36; +static constexpr int16_t DATE_ITEM_WIDTH = 95; +static constexpr int16_t DATE_ITEM_HEIGHT = 60; + +DateButtonItemView::DateButtonItemView() +{ + SetPosition(0, 0, DATE_ITEM_WIDTH, DATE_ITEM_HEIGHT); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + SetTouchable(true); + SetUpChild(); + + Add(&sLabelButton); +} + +DateButtonItemView::~DateButtonItemView() +{ + Remove(&sLabelButton); +} + +void DateButtonItemView::SetItemInfo(const DateButtonItem itemInfo) +{ + sItemInfo = itemInfo; + sLabelButton.SetText(sItemInfo.button_day); + ImageInfo *image1; + ImageInfo *image2; + if (sItemInfo.isFirst) { + if (sItemInfo.isSelect) { + image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE6, DATE_IMAGE); + sLabelButton.SetTextColor(Color::White()); + } else { + sLabelButton.SetTextColor(Color::GetColorFromRGBA(0xe0, 0x2d, 0x2f, 0xff)); + image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE3, DATE_IMAGE); + } + if (image1 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId1 fail"); + return; + } + image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE6, DATE_IMAGE); + if (image2 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId2 fail"); + return; + } + } else { + if (sItemInfo.isSelect) { + image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE4, DATE_IMAGE); + } else { + image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE2, DATE_IMAGE); + } + if (image1 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId1 fail"); + return; + } + image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE4, DATE_IMAGE); + if (image2 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId2 fail"); + return; + } + sLabelButton.SetTextColor(Color::White()); + } + sLabelButton.SetImageSrc(image1, image2); +} + +void DateButtonItemView::SetUpChild() +{ + sLabelButton.SetPosition(DATE_ITEM_BUTTON_POSITION_X, 0); + sLabelButton.Resize(DATE_ITEM_BUTTON_WIDTH, DATE_ITEM_BUTTON_HEIGHT); + sLabelButton.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT_SIZE); + sLabelButton.SetAlign(TEXT_ALIGNMENT_CENTER); + sLabelButton.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabelButton.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + sLabelButton.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); +} + +DateButtonItem DateButtonItemView ::GetItem() +{ + return sItemInfo; +} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateItemView.cpp new file mode 100644 index 000000000..a20141236 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateItemView.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateItemView + * Create: 2025-03-23 + */ + +#include "date/DateItemView.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_resource_date.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr int16_t DATE_ITEM_BUTTON_HEIGHT = 65; +static constexpr int16_t DATE_ITEM_LABEL_POSITION_X = 43; +static constexpr int16_t DATE_ITEM_LABEL_POSITION_Y = 22; +static constexpr int16_t DATE_ITEM_LABEL_TWO_POSITION_X = 23; +static constexpr int16_t DATE_ITEM_LABEL_TWO_POSITION_Y = 60; +static constexpr int16_t DATE_ITEM_LABEL_WIDTH = 135; +static constexpr int16_t DATE_ITEM_LABEL_HEIGHT = 40; +static constexpr int16_t DATE_ITEM_LABEL2_HEIGHT = 96; +static constexpr int16_t DATE_ITEM_LABEL_TWO_WIDTH = 314; +static constexpr int16 DATE_ITEM_FONT_SIZE = 24; +static constexpr int16 DATE_ITEM_FONT2_SIZE = 32; +static constexpr int16_t DATE_ITEM_WIDTH = 376; +static constexpr int16_t DATE_ITEM_HEIGHT = 190; + +DateItemView::DateItemView() +{ + SetPosition(0, 0, DATE_ITEM_WIDTH, DATE_ITEM_HEIGHT); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + SetTouchable(true); + SetUpChild(); + + Add(&sLabel_1); + Add(&sLabel_2); + Add(&Signs); + Add(&BackGround); +} + +DateItemView::~DateItemView() +{ + Remove(&sLabel_1); + Remove(&sLabel_2); + Remove(&Signs); + Remove(&BackGround); +} + +void DateItemView::SetItemInfo(const DateItem itemInfo) +{ + sItemInfo = itemInfo; + sLabel_1.SetText(itemInfo.label_1); + sLabel_2.SetText(itemInfo.label_2); + BackGround.SetPosition(0, 0); + if (itemInfo.visiable) { + int offsetX1 = 100; + int offsetY1 = 10; + int offsetX2 = 30; + int offsetY2 = 40; + sLabel_1.SetPosition(DATE_ITEM_LABEL_POSITION_X + offsetX1, DATE_ITEM_LABEL_POSITION_Y + offsetY1); + sLabel_2.SetPosition(DATE_ITEM_LABEL_TWO_POSITION_X + offsetX2, DATE_ITEM_LABEL_TWO_POSITION_Y + offsetY2); + sLabel_1.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel_2.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + sLabel_1.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT2_SIZE); + sLabel_2.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT_SIZE); + Signs.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + } else { + sLabel_1.SetPosition(DATE_ITEM_LABEL_POSITION_X, DATE_ITEM_LABEL_POSITION_Y); + sLabel_2.SetPosition(DATE_ITEM_LABEL_TWO_POSITION_X, DATE_ITEM_LABEL_TWO_POSITION_Y); + sLabel_1.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + sLabel_2.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel_1.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT_SIZE); + sLabel_2.SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_ITEM_FONT2_SIZE); + Signs.SetPosition(DATE_ITEM_LABEL_TWO_POSITION_X, DATE_ITEM_FONT_SIZE); + } + Signs.SetVisible(!itemInfo.visiable); +} + +void DateItemView::SetUpChild() +{ + sLabel_1.Resize(DATE_ITEM_LABEL_WIDTH, DATE_ITEM_LABEL_HEIGHT); + sLabel_1.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + sLabel_1.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel_1.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + sLabel_1.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + sLabel_2.Resize(DATE_ITEM_LABEL_TWO_WIDTH, DATE_ITEM_LABEL2_HEIGHT); + sLabel_2.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + sLabel_2.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel_2.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + sLabel_2.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE5, DATE_IMAGE); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "DateMessagePage::OnStart LoadStopwatchImage IMAGE_CONVERTER_TOOL_DATE5 fail"); + return; + } + Signs.SetSrc(image); + image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE1, DATE_IMAGE); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "DateMessagePage::OnStart LoadStopwatchImage IMAGE_CONVERTER_TOOL_DATE1 fail"); + return; + } + BackGround.SetSrc(image); +} + +const char *DateItemView ::GetViewId() +{ + return sItemInfo.index; +} +bool DateItemView::GetVisiable() +{ + return sItemInfo.visiable; +} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateMainPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateMainPage.cpp new file mode 100644 index 000000000..5072468de --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateMainPage.cpp @@ -0,0 +1,303 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateMainPage + * Created: 2025-4 + */ + +#include "date/DateMainPage.h" +#include "date/DateModel.h" +#include "date/DatePresenter.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "components/ui_button.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_resource_date.h" + +static constexpr int16_t DOWNSELECTPOSITION = 100; +static constexpr int16_t DOWNCONTENTLIST_POSITION_X = 39; +static constexpr int16_t DOWNCONTENTLIST_POSITION_Y = 171; +static constexpr int16_t DOWNCONTENTLIST_WIDTH = 376; +static constexpr int16_t DOWNCONTENTLIST_HEIGHT = 260; +static constexpr int16_t BUTTONCONTENTLIST_POSITION_X = 36; +static constexpr int16_t BUTTONCONTENTLIST_POSITION_Y = 97; +static constexpr int16_t BUTTONCONTENTLIST_WIDTH = 410; +static constexpr int16_t BUTTONCONTENTLIST_HEIGHT = 55; +static constexpr int16_t BUTTONCONTENTLIST_SELECT_POSITON = 90; +static constexpr uint16_t DATE_MONTH_FONT = 25; +static constexpr uint16_t DATE_MONTH_POS_X = 129; +static constexpr uint16_t DATE_MONTH_POS_Y = 31; +static constexpr uint16_t DATE_MONTH_WIDTH = 196; +static constexpr uint16_t LIST_POSITION_Y = 155; +static constexpr uint16_t DATE_MONTH_HEIGHT = 50; +static constexpr uint8_t FONT_FORTY_SIZE = 36; + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_DATE, DATE_PAGES::DATE_MAIN_PAGE, DateMainPage, true); + +DateMainPage::DateMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateMainPage::DateMainPage"); +} + +DateMainPage::~DateMainPage() +{ + if (uiScrollView != nullptr) { + uiScrollView->RemoveAll(); + delete uiScrollView; + uiScrollView = nullptr; + } + + if (listAdapter != nullptr) { + delete listAdapter; + listAdapter = nullptr; + } + + if (buttonAdapter != nullptr) { + delete buttonAdapter; + buttonAdapter = nullptr; + } + + if (buttonContentList != nullptr) { + delete buttonContentList; + buttonContentList = nullptr; + } + + if (downContentList != nullptr) { + delete downContentList; + downContentList = nullptr; + } + + if (title != nullptr) { + delete title; + title = nullptr; + } + + if (image1 != nullptr) { + delete image1; + image1 = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateMainPage::~DateMainPage"); +} + +void DateMainPage::OnStart(void *data) +{ + uiScrollView = new UIScrollView(); + if (uiScrollView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::scrollView is nullptr"); + return; + } + uiScrollView->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + uiScrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + uiScrollView->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + uiScrollView->SetThrowDrag(true); + uiScrollView->SetOnDragListener(this); + uiScrollView->SetThrowDrag(true); + image1 = new UIImageView(); + if (image1 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::image1 is nullptr"); + return; + } + image1->SetPosition(0, 0); + image1->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + ImageInfo *imgSrc = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE7, DATE_IMAGE); + if (imgSrc == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "DateMainPage::OnStart LoadOneInMultiRes IMAGE_CONVERTER_TOOL_DATE8 fail"); + return; + } + image1->SetSrc(imgSrc); + uiScrollView->Add(image1); + + DateModel::GetInstance().InitDate(); + title = new UILabel(); + if (title == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::title is nullptr"); + return; + } + title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MONTH_FONT); + std::stringstream ss; + title->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT, UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT); + title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); + title->SetPosition(DATE_MONTH_POS_X, DATE_MONTH_POS_Y, DATE_MONTH_WIDTH, DATE_MONTH_HEIGHT); + uiScrollView->Add(title); + InitDownList(); + AddViewToPageContainer(uiScrollView); +} + +void DateMainPage::InitDownList() +{ + if (buttonContentList == nullptr) { + buttonContentList = new UIList(0); + } + buttonAdapter = new DateButtonAdapter(); + if (buttonAdapter == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::listAdapter is nullptr"); + return; + } + buttonAdapter->SetItemClickListener(this); + buttonContentList->SetViewId("buttonList"); + buttonContentList->SetPosition(BUTTONCONTENTLIST_POSITION_X, BUTTONCONTENTLIST_POSITION_Y, BUTTONCONTENTLIST_WIDTH, + BUTTONCONTENTLIST_HEIGHT); + buttonContentList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + buttonContentList->SetSelectPosition(BUTTONCONTENTLIST_SELECT_POSITON); + buttonContentList->SetDraggable(true); + buttonContentList->SetThrowDrag(true); + buttonContentList->EnableAutoAlign(true); + buttonContentList->ScrollTo(0); + buttonContentList->SetAdapter(buttonAdapter); + buttonContentList->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); + InitDateTop(); + RefreshButtonListDate(0); + if (downContentList == nullptr) { + downContentList = new UIList(); + } + + listAdapter = new DateAdapter(); + if (listAdapter == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateView::OnStart::listAdapter is nullptr"); + return; + } + listAdapter->SetItemClickListener(this); + SetDownListAdapter(); + downContentList->SetViewId("downList"); + downContentList->SetPosition(DOWNCONTENTLIST_POSITION_X, DOWNCONTENTLIST_POSITION_Y); + downContentList->Resize(DOWNCONTENTLIST_WIDTH, DOWNCONTENTLIST_HEIGHT); // 364: height + downContentList->SetSelectPosition(DOWNSELECTPOSITION); + downContentList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + downContentList->SetDraggable(true); + downContentList->SetThrowDrag(true); + downContentList->EnableAutoAlign(true); + downContentList->SetElastic(true); + downContentList->ScrollTo(0); + downContentList->SetAdapter(listAdapter); + UpdateMsg(listTop.front().button_viewId); + uiScrollView->Add(downContentList); + uiScrollView->Add(buttonContentList); +} + +int calculateWeekday(int year, int month, int day) +{ + if (month < SET_THREE) { + month += SET_TWELVE; + year--; + } + int K = year % SET_HUNDRED; + int J = year / SET_HUNDRED; + int h = (day + SET_THIRTEEN * (month + SET_ONE) / SET_FIVE + K + K / SET_FOUR + J / SET_FOUR + SET_FIVE * J) % + SET_SEVEN; + return h; +} + +// 刷新List数据 +void DateMainPage::UpdateMsg(std::string dateMsg) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateView::UpdateMsg:%s", dateMsg.c_str()); + listAdapter->ClearListItem(); // 清空list数据 + DateModel::GetInstance().InitDateVec(dateMsg); + SetDownListAdapter(); // 将设置的数据写入list + int year; + int month; + int day; + int ret = sscanf_s(dateMsg.c_str(), "%d-%d-%d", &year, &month, &day); + if (ret != SET_THREE) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DateMainPage::OnStart strDate"); + return; + } + std::string weekDay[] = {"星期六", "星期日", "星期一", "星期二", "星期三", "星期四", "星期五"}; + int today = calculateWeekday(year, month, day); + std::string titleDay; + if (dateMsg == listTop.front().button_viewId) { + titleDay = "今天 "; + } else { + titleDay = std::to_string(month) + "月 "; + } + titleDay += weekDay[today]; + DateModel::GetInstance().titleName = titleDay; + title->SetText(titleDay.c_str()); + downContentList->ScrollTo(SET_ZERO); + downContentList->RefreshList(); +} + +void DateMainPage::SetDownListAdapter() +{ + for (const auto &item : DateModel::GetInstance().listDate) { + listAdapter->AddListItem(item); + } +} + +void DateMainPage::RefreshButtonListDate(int value) +{ + buttonAdapter->ClearListItem(); + for (auto &item : listTop) { + if (item.index == value) { + item.isSelect = true; + } else { + item.isSelect = false; + } + buttonAdapter->AddListItem(item); + } + buttonContentList->RefreshList(); +} + +bool DateMainPage::InitDateTop() +{ + listTop.clear(); + for (int i = 0; i < SET_SEVEN; ++i) { + strDate[i] = GetFutureDate(i); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateMainPage::OnStart strDate[%d]:%s", i, strDate[i].c_str()); + strDay[i] = strDate[i].substr(strDate[i].length() - SET_TWO); + if (i == 0) { + listTop.push_back({strDate[i].c_str(), strDay[i].c_str(), i, true, true}); + } else { + listTop.push_back({strDate[i].c_str(), strDay[i].c_str(), i, false, false}); + } + } + return true; +} + +std::string DateMainPage::GetFutureDate(int days_ahead) +{ + time_t now = time(nullptr); + time_t future_time = now + (days_ahead * HOUR_COUNT * NUM_TIME_MIN * NUM_TIME_MIN); + tm *tm = localtime(&future_time); + char buffer[80]; // 存储格式化后的日期字符串 + strftime(buffer, sizeof(buffer), "%Y-%m-%d", tm); + return std::string(buffer); +} + +bool DateMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + return true; +} + +bool DateMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + int posY = event.GetCurrentPos().y; + if (posY > LIST_POSITION_Y) { + DateItemView *dateItemView = static_cast(&view); + std::string view_id = dateItemView->GetViewId(); + bool visiable = dateItemView->GetVisiable(); + if (visiable) { + return false; + } + DateModel::GetInstance().messageIndex = view_id; + NativeAbility::GetInstance().SwitchPageInSlice(DATE_PAGES::DATE_MESSAGE_PAGE, nullptr, + TransitionType::TRANSITION_INVALID, true); + } else { + DateButtonItemView *dateButtonItemView = static_cast(&view); + DateButtonItem item = dateButtonItemView->GetItem(); + RefreshButtonListDate(item.index); + UpdateMsg(item.button_viewId); + } + UNUSED(event); + return true; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateMessagePage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateMessagePage.cpp new file mode 100644 index 000000000..277e65596 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateMessagePage.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateMessagePage + * Create: 2025-03-15 + */ + +#include "date/DateMessagePage.h" +#include "date/DateModel.h" +#include "date/DatePresenter.h" +#include "date/DateView.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "ui_resource_date.h" + +namespace OHOS { +static constexpr uint16_t DATE_MONTH_WIDTH = 221; +static constexpr uint16_t DATE_MESSAGE_WIDTH = 180; +static constexpr uint16_t DATE_MESSAGE_HEIGHT = 50; +static constexpr uint16_t DATE_MESSAGE_POSITON_X = 117; +static constexpr uint16_t DATE_MESSAGE_POSITON_Y = 20; +static constexpr uint16_t DATE_MESSAGE_POSITON_X1 = 137; +static constexpr uint16_t DATE_MESSAGE_FRONT_SIZE_ONE = 36; +static constexpr uint16_t DATE_MESSAGE_FRONT_SIZE_TWO = 32; +static constexpr uint16_t DATE_MESSAGE_TWO_POSITION_X = 31; +static constexpr uint16_t DATE_MESSAGE_TWO_POSITION_Y = 100; +static constexpr uint16_t DATE_MESSAGE_TWO_WIDTH = 392; +static constexpr uint16_t DATE_MESSAGE_TWO_HEIGHT = 120; +static constexpr uint16_t DATE_MESSAGE_MAX_LINE_HEIGHT = 140; + +REGIST_SLICE_PAGE(VIEW_DATE, DATE_PAGES::DATE_MESSAGE_PAGE, DateMessagePage, false); + +DateMessagePage::DateMessagePage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateMessagePage::DateMessagePage"); +} + +DateMessagePage::~DateMessagePage() +{ + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (image1 != nullptr) { + delete image1; + image1 = nullptr; + } + + if (labelTitle != nullptr) { + delete labelTitle; + labelTitle = nullptr; + } + + if (labelMessage != nullptr) { + delete labelMessage; + labelMessage = nullptr; + } + + if (labelTime != nullptr) { + delete labelTime; + labelTime = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DateMessagePage::~DateMessagePage"); +} + +void DateMessagePage::OnStart(void *data) +{ + group = new UIViewGroup(); + group->SetPosition(0, 0); + group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + image1 = new UIImageView; + if (image1 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::title is nullptr"); + return; + } + image1->SetPosition(0, 0); + image1->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + ImageInfo *imgSrc = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_DATE8, DATE_IMAGE); + if (imgSrc == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::LoadOneInMultiRes fail"); + } + image1->SetSrc(imgSrc); + group->Add(image1); + + labelTitle = new UILabel(); + if (labelTitle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::title is nullptr"); + return; + } + labelTitle->SetPosition(DATE_MESSAGE_POSITON_X, DATE_MESSAGE_POSITON_Y, DATE_MONTH_WIDTH, DATE_MESSAGE_HEIGHT); + labelTitle->SetStyle(STYLE_TEXT_COLOR, Color::Purple().full); + labelTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_ONE); + labelTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTitle->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTitle->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group->Add(labelTitle); + + labelMessage = new UILabel(); + if (labelMessage == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::title is nullptr"); + return; + } + labelMessage->SetPosition(DATE_MESSAGE_TWO_POSITION_X, DATE_MESSAGE_TWO_POSITION_Y, DATE_MESSAGE_TWO_WIDTH, + DATE_MESSAGE_TWO_HEIGHT); + labelMessage->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelMessage->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelMessage->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelMessage->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelMessage->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_ONE); + labelMessage->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + labelMessage->SetRollSpeed(0); + group->Add(labelMessage); + + labelTime = new UILabel(); + if (labelTime == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::title is nullptr"); + return; + } + labelTime->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + labelTime->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + labelTime->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + labelTime->SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + labelTime->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DATE_MESSAGE_FRONT_SIZE_TWO); + group->Add(labelTime); + + std::string strTitle = DateModel::GetInstance().titleName; + labelTitle->SetText(strTitle.c_str()); + for (const auto &item : DateModel::GetInstance().listDate) { + std::string strIndex = DateModel::GetInstance().messageIndex; + if (strIndex == item.index) { + labelTime->SetText(item.label_1); + labelMessage->SetText(item.label_2); + } + } + int posTextHeight = labelMessage->GetTextHeight(); + int posHeight = DATE_MESSAGE_TWO_POSITION_Y; + int pos = 0; + if (posTextHeight < DATE_MESSAGE_MAX_LINE_HEIGHT) { + int offsetY = 50; + pos = DATE_MESSAGE_TWO_POSITION_Y + posTextHeight + offsetY; + labelMessage->SetY(DATE_MESSAGE_TWO_POSITION_Y + offsetY); + } else { + pos = DATE_MESSAGE_TWO_POSITION_Y + posTextHeight; + labelMessage->SetY(DATE_MESSAGE_TWO_POSITION_Y); + } + labelMessage->SetHeight(posTextHeight); + labelTime->SetPosition(DATE_MESSAGE_POSITON_X1, pos, DATE_MESSAGE_WIDTH, DATE_MESSAGE_HEIGHT); + group->SetOnDragListener(this); + group->SetDraggable(true); + AddViewToPageContainer(group); +} + +bool DateMessagePage::OnDrag(UIView &view, const DragEvent &event) +{ + 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, "DatePresenter::OnDrag ChangeSlice(VIEW_APPLIST)"); + } + return true; +} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateModel.cpp new file mode 100644 index 000000000..4792289fa --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DateModel.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateModel + * Create: 2025-03-23 + */ + +#include "date/DateModel.h" +#include "date/DatePresenter.h" +#include "phoneservice/PhoneService.h" +#include "ohos_timer.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr int16 DATE_COUNT = 24; +static constexpr int16 DATE_HOUR = 12; + +DateModel::DateModel() {} + +DateModel::~DateModel() {} + +DateModel &DateModel::GetInstance() +{ + static DateModel instance; + return instance; +} + +bool DateModel::InitDateVec(std::string dateStr) +{ + int index = 0; + listDate.clear(); + if (GetBtConnectStatus() != PROFILE_STATE_CONNECTED) { + listDate.push_back({"无日程", "请连接手机,同步日程信息", "0", true}); + } else { + for (const auto &msg : keyValues) { + for (const auto &item : msg.second) { + if (msg.first == dateStr) { + index++; + strIndex = std::to_string(index); + listDate.push_back({item.hour.c_str(), item.eventTitle.c_str(), strIndex.c_str(), false}); + } + } + } + if (listDate.size() == 0) { + listDate.push_back({"无日程", "请前往手机日历创建日程", "0", true}); + } + } + return true; +} + +bool DateModel::InitDate() +{ + keyValues.clear(); + std::ifstream file("/user/app/user/ace/data/com.vendor.Weather/calendar.json"); + if (!file.is_open()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cannot open file"); + return false; + } + std::stringstream buffer; + buffer << file.rdbuf(); + std::string content = buffer.str(); + int intsize = sizeof(content); + cJSON *root = nullptr; + if (intsize != 0) { + root = cJSON_Parse(content.c_str()); + } + if (root == NULL) { + const char *error_ptr; + return false; + } + cJSON *dateSum = cJSON_GetObjectItemCaseSensitive(root, "dateSum"); + if (!cJSON_IsObject(dateSum)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error observe:"); + cJSON_Delete(root); + return false; + } + int sum = std::atoi(cJSON_GetObjectItemCaseSensitive(dateSum, "count")->valuestring); + for (int i = 0; i < sum; i++) { + cJSON *date = cJSON_GetObjectItemCaseSensitive(dateSum, std::to_string(i).c_str()); + if (!cJSON_IsObject(date)) { + cJSON_Delete(root); + continue; + } + std::string hour = cJSON_GetObjectItemCaseSensitive(date, "hour")->valuestring; + std::string eventTitle = cJSON_GetObjectItemCaseSensitive(date, "eventTitle")->valuestring; + std::string startTime = cJSON_GetObjectItemCaseSensitive(date, "startTime")->valuestring; + std::string time = cJSON_GetObjectItemCaseSensitive(date, "time")->valuestring; + std::string week = cJSON_GetObjectItemCaseSensitive(date, "week")->valuestring; + DateMsg item = {hour, eventTitle, startTime, week}; + keyValues[time].push_back(item); + } + return true; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/date/src/DatePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DatePresenter.cpp new file mode 100644 index 000000000..64ba20fee --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/date/src/DatePresenter.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DatePresenter + * Create: 2025-03-23 + */ + +#include "date/DatePresenter.h" +#include "date/DateModel.h" +#include "date/DateView.h" +#include "NativeRegisterManager.h" +#include "uiservice/ui_service.h" +#include "wearable_log.h" + +namespace OHOS { +REGIST_MENU(VIEW_DATE, DateView, DatePresenter, DATE_MAIN_ICON, DATE_MAIN_ICON, "日程"); +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/emptypage/src/EmptyPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/emptypage/src/EmptyPage.cpp new file mode 100644 index 000000000..6860eaec8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/emptypage/src/EmptyPage.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: EmptyPage + * Create: 2025-04-24 + */ + +#include "emptypage/EmptyPage.h" +#include "emptypage/EmptyPresenter.h" +#include "SlicePageFactory.h" +#include "flashlight/FlashLightView.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" + +namespace OHOS { +static const uint16_t MEM_LABEL_FONT_SIZE = 40; +static uint32_t EMPTY_PAGE = 1; +REGIST_SLICE_PAGE(VIEW_EMPTY, EMPTY_PAGE, EmptyPage, true); +void EmptyPage::OnStart(void *data) +{ + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + // 设置界面组件回调函数 + container_->SetOnDragListener(this); + container_->SetOnClickListener(this); + } +#if !defined(_WIN32) + test_get_mem_info(1, &used_, &free_); +#endif + // Add Label to App + if (memLabel_ == nullptr) { + memLabel_ = new UILabel(); + } + memLabel_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + std::string memInfo = "Used : " + std::to_string(used_) + "\n" + "Free : " + std::to_string(free_); + memLabel_->SetText(memInfo.c_str()); + memLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + memLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MEM_LABEL_FONT_SIZE); + container_->Add(memLabel_); + AddViewToPageContainer(container_); +} + +EmptyPage::~EmptyPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmptyPage::~EmptyPage"); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (memLabel_ != nullptr) { + delete memLabel_; + memLabel_ = nullptr; + } +} + +bool EmptyPage::OnDrag(UIView &view, const DragEvent &event) +{ + return false; +} + +bool EmptyPage::OnClick(UIView &view, const ClickEvent &event) +{ + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/emptypage/src/EmptyPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/emptypage/src/EmptyPresenter.cpp new file mode 100644 index 000000000..1a429dfa6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/emptypage/src/EmptyPresenter.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: EmptyPresenter + * Create: 2025-04-24 + */ + +#include "emptypage/EmptyView.h" +#include "emptypage/EmptyPresenter.h" +#include "NativeRegisterManager.h" + +namespace OHOS { +REGIST_MENU(VIEW_EMPTY, EmptyView, EmptyPresenter, FLASHLIGHT_MAIN_ICON, PNG_APPLIST_DEFAULT_IMG, "空页面"); +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/findphone/src/FindPhoneMainPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/findphone/src/FindPhoneMainPage.cpp new file mode 100644 index 000000000..54396d287 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/findphone/src/FindPhoneMainPage.cpp @@ -0,0 +1,623 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FindPhoneMainPage + * Create: 2025-03-23 + */ + +#include "phoneservice/PhoneService.h" +#include "UiConfig.h" +#include "bts_spp.h" +#include "common/image_cache_manager.h" +#include "main/LoadImg.h" +#include "ui_resource_findPhone.h" +#include "uiservice/ui_service.h" +#include "ui_test_group.h" +#include "wearable_onlinelog.h" +#include "msg_center_protocol.h" +#include "msg_center_device.h" +#include "findphone/FindPhoneMainPage.h" +#include "findphone/FindPhonePresenter.h" +#include "findphone/FindPhoneView.h" + +static uint8_t data = 0; +namespace OHOS { + +static FindPhoneMainPage *g_pFindPhoneMainPage = nullptr; +static constexpr uint16_t FIND_PHONE_IMAGE_WIDTH = 500; +static constexpr uint16_t FIND_PHONE_IMAGE_HEIGHT = 500; +static constexpr uint16_t FIND_PHONE_BUTTON_POSITION_X = 154; +static constexpr uint16_t FIND_PHONE_BUTTON_POSITION_Y = 154; +static constexpr uint16_t FIND_PHONE_BUTTON_WIDTH = 146; +static constexpr uint16_t FIND_PHONE_BUTTON_HEIGHT = 146; +static constexpr uint16_t FIND_PHONE_RTYBUTTON_POSITION_X = 179; +static constexpr uint16_t FIND_PHONE_RTYBUTTON_POSITION_Y = 289; +static constexpr uint16_t FIND_PHONE_RTYBUTTON = 96; +static constexpr uint16_t FIND_PHONE_SIZE = 466; +static constexpr uint16_t FIND_PHONE_IMAGEANIMATOR_POSITION_X = 170; +static constexpr uint16_t FIND_PHONE_IMAGEANIMATOR_POSITION_Y = 170; +static constexpr uint16_t FIND_PHONE_IMAGEANIMATOR_WIDTH = 100; +static constexpr uint16_t FIND_PHONE_IMAGEANIMATOR_HEIGHT = 100; +static constexpr uint16_t FONT_DEFAULT_SIZE_1 = 36; +static constexpr uint16_t FONT_DEFAULT_SIZE_2 = 38; +static constexpr uint16_t FIND_PHONE_INITIAL = 0; +static constexpr uint16_t FIND_PHONE_TITLDE_X = 140; +static constexpr uint16_t FIND_PHONE_TITLDE_Y = 345; +static constexpr uint16_t FIND_PHONE_TITLDE_WIDTH = 314; +static constexpr uint16_t FIND_PHONE_FINDTITLE_X = 150; +static constexpr uint16_t FIND_PHONE_FINDTITLE_Y = 31; +static constexpr uint16_t FIND_PHONE_FINDTITLE_WIDTH = 253; +static constexpr uint16_t FIND_PHONE_FINDTITLE_HEIGHT = 53; +static constexpr uint16_t FIND_PHONE_RINGING_X = 200; +static constexpr uint16_t FIND_PHONE_RINGING2_X = 156; +static constexpr uint16_t FIND_PHONE_RINGING_Y = 353; +static constexpr uint16_t FIND_PHONE_RINGING_WIDTH = 93; +static constexpr uint16_t FIND_PHONE_RINGING2_WIDTH = 144; +static constexpr uint16_t FIND_PHONE_RINGING_HEIGHT = 42; +static constexpr uint16_t FIND_PHONE_SEARCHTIMEOUT_X = 50; +static constexpr uint16_t FIND_PHONE_SEARCHTIMEOUT_Y = 185; +static constexpr uint16_t FIND_PHONE_SEARCHTIMEOUT_WIDTH = 424; +static constexpr uint16_t FIND_PHONE_SEARCHTIMEOUT_HEIGHT = 50; +static constexpr uint16_t FIND_PHONE_DURATION_TIME = 60; +static constexpr uint16_t IMAGE_SIZE = 500; +static constexpr uint16_t IMAGEANIMATOERVIEW_SIZE = 28; +static constexpr uint16_t IMAGEANIMATOERVIEW_TIME = 60; +static constexpr uint16_t FIND_PHONE_IMAGE_X = 5; +static constexpr uint16_t FIND_PHONE_IMAGE_y = 1; +static constexpr uint16_t FIND_PHONE_PIXELBYTE_SIZE = 4; +static constexpr uint16_t FIND_PHONE_PIXELBYTEH = 100; + +REGIST_SLICE_PAGE(VIEW_FIND_PHONE, FIND_PHONE_PAGES::FIND_PHONE_MAIN_PAGE, FindPhoneMainPage, true); + +const int g_imageAnimatorInfo[IMAGEANIMATOERVIEW_SIZE] = { + IMAGE_CONVERTER_TOOL_FINDPHONE001, IMAGE_CONVERTER_TOOL_FINDPHONE002, IMAGE_CONVERTER_TOOL_FINDPHONE003, + IMAGE_CONVERTER_TOOL_FINDPHONE004, IMAGE_CONVERTER_TOOL_FINDPHONE005, IMAGE_CONVERTER_TOOL_FINDPHONE006, + IMAGE_CONVERTER_TOOL_FINDPHONE007, IMAGE_CONVERTER_TOOL_FINDPHONE008, IMAGE_CONVERTER_TOOL_FINDPHONE009, + IMAGE_CONVERTER_TOOL_FINDPHONE010, IMAGE_CONVERTER_TOOL_FINDPHONE011, IMAGE_CONVERTER_TOOL_FINDPHONE012, + IMAGE_CONVERTER_TOOL_FINDPHONE013, IMAGE_CONVERTER_TOOL_FINDPHONE014, IMAGE_CONVERTER_TOOL_FINDPHONE015, + IMAGE_CONVERTER_TOOL_FINDPHONE016, IMAGE_CONVERTER_TOOL_FINDPHONE017, IMAGE_CONVERTER_TOOL_FINDPHONE018, + IMAGE_CONVERTER_TOOL_FINDPHONE019, IMAGE_CONVERTER_TOOL_FINDPHONE020, IMAGE_CONVERTER_TOOL_FINDPHONE021, + IMAGE_CONVERTER_TOOL_FINDPHONE022, IMAGE_CONVERTER_TOOL_FINDPHONE023, IMAGE_CONVERTER_TOOL_FINDPHONE024, + IMAGE_CONVERTER_TOOL_FINDPHONE025, IMAGE_CONVERTER_TOOL_FINDPHONE026, IMAGE_CONVERTER_TOOL_FINDPHONE027, + IMAGE_CONVERTER_TOOL_FINDPHONE028, +}; + +FindPhoneMainPage::FindPhoneMainPage() +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::FindPhoneMainPage"); + g_pFindPhoneMainPage = this; +} + +FindPhoneMainPage::~FindPhoneMainPage() +{ + g_pFindPhoneMainPage = nullptr; + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + + if (buttonFind != nullptr) { + delete buttonFind; + buttonFind = nullptr; + } + + if (mainImage != nullptr) { + delete mainImage; + mainImage = nullptr; + } + + if (labelUnder != nullptr) { + delete labelUnder; + labelUnder = nullptr; + } + + if (labelFindTitle != nullptr) { + delete labelFindTitle; + labelFindTitle = nullptr; + } + + if (labelRing != nullptr) { + delete labelRing; + labelRing = nullptr; + } + + if (buttonRty != nullptr) { + delete buttonRty; + buttonRty = nullptr; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::~FindPhoneMainPage"); +} + +FindPhoneMainPage *FindPhoneMainPage::GetInstance() +{ + return g_pFindPhoneMainPage; +} + +void FindPhoneMainPage::OnStop() +{ + if (imageAnimator_->GetState() == true) { + DisableFindPhoneTimer(); +#ifndef _WIN32 + errcode_t result = + uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_OFF_FIND_PHONE, nullptr, 0); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnStop::uapi_diag_service_send_log OFF result:%d ", result); +#endif + ImageCacheManager::GetInstance().UnloadAllInMultiRes(FINDPHONE_IMAGE); + } + data = 0; +} + +void FindPhoneMainPage::OnStart(void *data) +{ + if (container_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new container_ fail"); + container_ = new UIViewGroup(); + container_->SetPosition(FIND_PHONE_INITIAL, FIND_PHONE_INITIAL, FIND_PHONE_SIZE, FIND_PHONE_SIZE); + container_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + } + container_->SetTouchable(true); + container_->SetDraggable(true); + container_->SetOnDragListener(this); + + if (mainImage == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new mainImage fail"); + mainImage = new UIImageView(); + } + mainImage->SetPosition(FIND_PHONE_INITIAL, FIND_PHONE_INITIAL); + LOADIMG::LoadImageViewImg(mainImage, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_2); + container_->Add(mainImage); + + SetUpImageAnimator(); + SetupButton(); + + labelUnder = new UILabel(); + if (labelUnder == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new labelUnder fail"); + return; + } + labelUnder->SetText("蓝牙已断开"); + labelUnder->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_1); + labelUnder->SetPosition(FIND_PHONE_TITLDE_X, FIND_PHONE_TITLDE_Y, FIND_PHONE_TITLDE_WIDTH, + FIND_PHONE_IMAGEANIMATOR_HEIGHT); + container_->Add(labelUnder); + labelFindTitle = new UILabel(); + if (labelFindTitle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new labelFindTitle fail"); + return; + } + labelFindTitle->SetText("查找手机"); + labelFindTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_2); + labelFindTitle->SetPosition(FIND_PHONE_FINDTITLE_X, FIND_PHONE_FINDTITLE_Y, FIND_PHONE_FINDTITLE_WIDTH, + FIND_PHONE_FINDTITLE_HEIGHT); + container_->Add(labelFindTitle); + + labelRing = new UILabel(); + if (labelRing == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new labelRing fail"); + return; + } + labelRing->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_1); + container_->Add(labelRing); + if (GetConnectStatus() == 1) { + labelRing->SetVisible(true); + labelUnder->SetVisible(false); + LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5, + IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5); + buttonFind->Enable(); + } else { + LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4, + IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4); + buttonFind->Disable(); + labelUnder->SetVisible(true); + labelRing->SetVisible(false); + } + imageAnimator_->Stop(); + imageAnimator_->SetVisible(false); + AddViewToPageContainer(container_); +} + +void FindPhoneMainPage::SetUpImageAnimator() +{ + imageAnimator_ = new UIImageAnimatorView(); + if (imageAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "FindPhoneMainPage::UIImageAnimatorView new Label SetUpImageAnimator fail"); + return; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::SetUpImageAnimator "); + imageAnimator_ = new UIImageAnimatorView(); + for (data; data < IMAGEANIMATOERVIEW_SIZE; data++) { + searchImageInfo[data].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(g_imageAnimatorInfo[data], FINDPHONE_IMAGE); + ; + searchImageInfo[data].imageType = IMG_SRC_IMAGE_INFO; + searchImageInfo[data].pos.x = FIND_PHONE_IMAGE_X; + searchImageInfo[data].pos.y = FIND_PHONE_IMAGE_y; + searchImageInfo[data].width = IMAGE_SIZE; + searchImageInfo[data].height = IMAGE_SIZE; + } + imageAnimator_->SetPosition(FIND_PHONE_IMAGE_X, FIND_PHONE_IMAGE_y, FIND_PHONE_IMAGE_WIDTH, + FIND_PHONE_IMAGE_HEIGHT); // 50 : offset 50 : offset 200 : offset 200: offset + int imageNumber = IMAGEANIMATOERVIEW_SIZE; + int ImageUpdate = IMAGEANIMATOERVIEW_TIME; + imageAnimator_->SetImageAnimatorSrc(searchImageInfo, imageNumber, + ImageUpdate); // 4: the number of images, 100: updating time + imageAnimator_->Stop(); + imageAnimator_->LayoutCenterOfParent(); + imageAnimator_->SetDraggable(true); + imageAnimator_->SetOnDragListener(this); + container_->Add(imageAnimator_); + InitImageInfo(); +} + +void FindPhoneMainPage::SetupButton() +{ + // Add Button to App + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::SetupButton new Label"); + if (buttonFind == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new buttonFind fail"); + buttonFind = new UIButton(); + } + buttonFind->SetPosition(FIND_PHONE_BUTTON_POSITION_X, FIND_PHONE_BUTTON_POSITION_Y); + buttonFind->Resize(FIND_PHONE_BUTTON_WIDTH, FIND_PHONE_BUTTON_HEIGHT); + buttonFind->SetViewId("button1"); + buttonFind->SetOnClickListener(this); + buttonFind->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); + buttonFind->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + buttonFind->SetVisible(true); + LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5, + IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5); + if (buttonRty == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new buttonRty fail"); + buttonRty = new UIButton(); + } + buttonRty->SetPosition(FIND_PHONE_RTYBUTTON_POSITION_X, FIND_PHONE_RTYBUTTON_POSITION_Y); + buttonRty->Resize(FIND_PHONE_RTYBUTTON, FIND_PHONE_RTYBUTTON); + buttonRty->SetViewId("buttonRty"); + buttonRty->SetOnClickListener(this); + buttonRty->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); + buttonRty->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadBtnImage(buttonRty, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_7, + IMAGE_CONVERTER_TOOL_CONNECT_PHONE_7); + buttonRty->SetVisible(false); + // Add to rootView + container_->Add(buttonRty); + container_->Add(buttonFind); +} + +bool FindPhoneMainPage::ClickButtonChange() +{ +#ifndef _WIN32 + errcode_t result; + if (imageAnimator_->GetState() == true) { + // 关闭定时器 + result = + uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_OFF_FIND_PHONE, nullptr, 0); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_diag_service_send_log OFF result:%d ", result); + if (result == 0) { + DisableFindPhoneTimer(); + LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5, + IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5); + imageAnimator_->Stop(); + imageAnimator_->SetVisible(false); + buttonFind->SetOpaScale(OPA_OPAQUE); + mainImage->SetVisible(true); + labelRing->SetText("响铃"); + labelRing->SetPosition(FIND_PHONE_RINGING_X, FIND_PHONE_RINGING_Y, FIND_PHONE_RINGING_WIDTH, + FIND_PHONE_RINGING_HEIGHT); + return true; + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OFF send to phone fail:%d ", result); + return false; + } + } else { + // 开启定时器 + result = + uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_ON_FIND_PHONE, nullptr, 0); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_diag_service_send_log ON result:%d ", result); + if (result == 0) { + InitFindPhoneTimer(); + g_startCount->Start(); + imageAnimator_->Start(); + imageAnimator_->SetVisible(true); + buttonFind->SetOpaScale(OPA_TRANSPARENT); + mainImage->SetVisible(false); + labelRing->SetText("停止响铃"); + labelRing->SetPosition(FIND_PHONE_RINGING2_X, FIND_PHONE_RINGING_Y, FIND_PHONE_RINGING2_WIDTH, + FIND_PHONE_RINGING_HEIGHT); + return true; + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ON send to phone fail:%d ", result); + return false; + } + } +#endif + return true; +} + +void FindPhoneMainPage::ShowReset() +{ + // rtybutton、title显示,findTitle、button隐藏,imageAnimator停止 + labelUnder->SetText("查找手机超时,请重试"); + labelUnder->SetPosition(FIND_PHONE_SEARCHTIMEOUT_X, FIND_PHONE_SEARCHTIMEOUT_Y, FIND_PHONE_SEARCHTIMEOUT_WIDTH, + FIND_PHONE_SEARCHTIMEOUT_HEIGHT); + labelUnder->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE_1); + labelUnder->SetVisible(true); + buttonRty->SetVisible(true); + labelFindTitle->SetVisible(false); + labelRing->SetVisible(false); + buttonFind->SetVisible(false); + mainImage->SetVisible(false); + imageAnimator_->Stop(); + imageAnimator_->SetVisible(false); + DisableFindPhoneTimer(); +} + +bool FindPhoneMainPage::StopFindPhone() +{ +#ifndef _WIN32 + errcode_t result; + if (imageAnimator_->GetState() == true) { + // 关闭定时器 + result = + uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_OFF_FIND_PHONE, nullptr, 0); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_diag_service_send_log OFF result:%d ", result); + if (result == 0) { + DisableFindPhoneTimer(); + LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5, + IMAGE_CONVERTER_TOOL_CONNECT_PHONE_5); + imageAnimator_->Stop(); + imageAnimator_->SetVisible(false); + buttonFind->SetOpaScale(OPA_OPAQUE); + mainImage->SetVisible(true); + labelRing->SetText("响铃"); + labelRing->SetPosition(FIND_PHONE_RINGING_X, FIND_PHONE_RINGING_Y, FIND_PHONE_RINGING_WIDTH, + FIND_PHONE_RINGING_HEIGHT); + return true; + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OFF send to phone fail:%d ", result); + return false; + } + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::imageAnimator is stop"); + } +#endif + return true; +} + +bool FindPhoneMainPage::OnClick(UIView &view, const ClickEvent &event) +{ +#ifndef _WIN32 + UNUSED(event); + if (view.GetViewId() == "buttonRty") { + // rtybutton、title隐藏,findTitle、button显示,imageAnimator播放 + InitFindPhoneTimer(); + static uint8_t buffer[1024] = {16}; + errcode_t result = + uapi_diag_service_send_log(msg_center_get_trans_channel(), MSGCENTER_TYPE_ID_ON_FIND_PHONE, buffer, 16); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_diag_service_send_log ON result:%d ", result); + if (result == 0) { + buttonRty->SetVisible(false); + labelUnder->SetVisible(false); + mainImage->SetVisible(false); + buttonFind->SetVisible(true); + labelFindTitle->SetVisible(true); + imageAnimator_->Start(); + imageAnimator_->SetVisible(true); + buttonFind->SetOpaScale(OPA_TRANSPARENT); + labelRing->SetVisible(true); + labelRing->SetText("停止响铃"); + labelRing->SetPosition(FIND_PHONE_RINGING2_X, FIND_PHONE_RINGING_Y, FIND_PHONE_RINGING2_WIDTH, + FIND_PHONE_RINGING_HEIGHT); + return true; + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "try send to phone fail:%d ", result); + return false; + } + } else { + ClickButtonChange(); + } +#endif + return true; +} + +bool FindPhoneMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::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, "FindPhoneOnDragListener::OnDrag ChangeSlice(VIEW_APPLIST)"); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + return false; +} + +uint8_t FindPhoneMainPage::GetConnectStatus() +{ + uint8_t conn_status = 0; +#ifndef _WIN32 + if (msg_center_get_trans_channel() == DIAG_FRAME_FID_PHONE) { + conn_status = is_spp_connected(0) == true ? 1 : 0; + } else if (msg_center_get_trans_channel() == DIAG_FRAME_FID_BT) { + conn_status = msg_center_get_ble_conn_state(); + } +#endif + return conn_status; +} + +void FindPhoneMainPage::ChangeToDisConnect() +{ + LOADIMG::LoadBtnImage(buttonFind, FINDPHONE_IMAGE, IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4, + IMAGE_CONVERTER_TOOL_CONNECT_PHONE_4); + imageAnimator_->Stop(); + imageAnimator_->SetVisible(false); + buttonFind->SetOpaScale(OPA_OPAQUE); + buttonFind->Disable(); + labelFindTitle->SetVisible(false); + labelUnder->SetVisible(true); + labelRing->SetVisible(false); +} + +/* 定时器回调函数 */ +void FindPhoneTimerCallback(void *data) +{ + (void)data; + timeCount++; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::timeCount:%d", timeCount); + if (timeCount == FIND_PHONE_DURATION_TIME) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Searching for phone timed out!!"); + FindPhoneMainPage::GetInstance()->ShowReset(); + timeCount = 0; + } + if (FindPhoneMainPage::GetInstance()->GetConnectStatus() != 1) { + FindPhoneMainPage::GetInstance()->ChangeToDisConnect(); + } +} + +/* 开启定时器 */ +void FindPhoneMainPage::InitFindPhoneTimer() +{ + if (g_startCount != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage already exists!!"); + return; + } + uint32 tick = GetOSTick(MS_ONE_SECONDS); + g_startCount = new GraphicTimer(tick, FindPhoneTimerCallback, nullptr, true); + if (g_startCount == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage new GraphicTimer failed!!"); + return; + } + bool retTimer = g_startCount->Start(); + if (!retTimer) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage osTimerStart failed!!"); + if (g_startCount != nullptr) { + delete g_startCount; + g_startCount = nullptr; + } + return; + } +} + +/* 关闭定时器 */ +void FindPhoneMainPage::DisableFindPhoneTimer() +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "CameraModel::DisableFindPhoneTimer!!"); + if (g_startCount != nullptr) { + g_startCount->Stop(); + delete g_startCount; + g_startCount = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CameraModel::DisableFindPhoneTimer delete g_startCount!!"); + } + timeCount = 0; +} + +void FindPhoneMainPage::InitImageInfo() +{ + const uint16_t pixelByteSize = FIND_PHONE_PIXELBYTE_SIZE; // 4: bytes per pixel + const uint16_t width = FIND_PHONE_PIXELBYTEH; // 100: image's width + const uint16_t height = FIND_PHONE_PIXELBYTEH; // 100: image's height + uint32_t dataSize = width * height * pixelByteSize; + uint8_t *srcData1 = static_cast(UIMalloc(dataSize)); + if (srcData1 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::srcData1 fail"); + return; + } + for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { + srcData1[i] = SET_INT_MAX; // 255: pixel value + srcData1[i + 1] = 0; // 1: set green channel + srcData1[i + SET_TWO] = 0; // 2: set red channel + srcData1[i + SET_THREE] = OPA_OPAQUE; // 3: set alpha channel + } + imageInfo1_ = static_cast(UIMalloc(sizeof(ImageInfo))); + if (imageInfo1_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new imageInfo1_ fail"); + UIFree(srcData1); + return; + } + + imageInfo1_->header.width = width; + imageInfo1_->header.height = height; + imageInfo1_->header.colorMode = ColorMode::ARGB8888; + imageInfo1_->dataSize = dataSize; + imageInfo1_->data = srcData1; + + uint8_t *srcData2 = static_cast(UIMalloc(dataSize)); + if (srcData2 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::srcData2 fail"); + UIFree(imageInfo1_); + UIFree(srcData1); + return; + } + for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { + srcData2[i] = 0; // set blue channel + srcData2[i + 1] = SET_INT_MAX; // 1: set green channel 255: pixel value + srcData2[i + SET_TWO] = 0; // 2: set red channel + srcData2[i + SET_THREE] = OPA_OPAQUE; // 3: set alpha channel + } + + imageInfo2_ = static_cast(UIMalloc(sizeof(ImageInfo))); + if (imageInfo2_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new imageInfo2_ fail"); + UIFree(srcData2); + UIFree(imageInfo1_); + UIFree(srcData1); + return; + } + imageInfo2_->header.width = width; + imageInfo2_->header.height = height; + imageInfo2_->header.colorMode = ARGB8888; + imageInfo2_->dataSize = dataSize; + imageInfo2_->data = srcData2; + + uint8_t *srcData3 = static_cast(UIMalloc(dataSize)); + if (srcData3 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::srcData3 fail"); + UIFree(imageInfo2_); + UIFree(srcData2); + UIFree(imageInfo1_); + UIFree(srcData1); + return; + } + for (uint32_t i = 0; i < dataSize; i += pixelByteSize) { + srcData3[i] = 0; // set blue channel + srcData3[i + 1] = 0; // 1: set green channel + srcData3[i + SET_TWO] = SET_INT_MAX; // 2: set red channel 255: pixel value + srcData3[i + SET_THREE] = OPA_OPAQUE; // 3: set alpha channel + } + + imageInfo3_ = static_cast(UIMalloc(sizeof(ImageInfo))); + if (imageInfo3_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneMainPage::new imageInfo3_ fail"); + UIFree(srcData3); + UIFree(imageInfo2_); + UIFree(srcData2); + UIFree(imageInfo1_); + UIFree(srcData1); + return; + } + imageInfo3_->header.width = width; + imageInfo3_->header.height = height; + imageInfo3_->header.colorMode = ARGB8888; + imageInfo3_->dataSize = dataSize; + imageInfo3_->data = srcData3; + + imageAnimatorImageInfo_[0].imageInfo = imageInfo1_; + imageAnimatorImageInfo_[0].pos = {FIND_PHONE_IMAGEANIMATOR_POSITION_X, FIND_PHONE_IMAGEANIMATOR_POSITION_Y}; + imageAnimatorImageInfo_[0].width = FIND_PHONE_IMAGEANIMATOR_WIDTH; // 100: width value + imageAnimatorImageInfo_[0].height = FIND_PHONE_IMAGEANIMATOR_HEIGHT; // 100: height value + imageAnimatorImageInfo_[0].imageType = IMG_SRC_IMAGE_INFO; + + imageAnimatorImageInfo_[1].imageInfo = imageInfo2_; + imageAnimatorImageInfo_[1].pos = {FIND_PHONE_IMAGEANIMATOR_POSITION_X, FIND_PHONE_IMAGEANIMATOR_POSITION_Y}; + imageAnimatorImageInfo_[1].width = FIND_PHONE_IMAGEANIMATOR_WIDTH; // 100: width value + imageAnimatorImageInfo_[1].height = FIND_PHONE_IMAGEANIMATOR_HEIGHT; // 100: height value + imageAnimatorImageInfo_[1].imageType = IMG_SRC_IMAGE_INFO; + + imageAnimatorImageInfo_[SET_TWO].imageInfo = imageInfo3_; // 2: image index + imageAnimatorImageInfo_[SET_TWO].pos = {FIND_PHONE_IMAGEANIMATOR_POSITION_X, FIND_PHONE_IMAGEANIMATOR_POSITION_Y}; + imageAnimatorImageInfo_[SET_TWO].width = FIND_PHONE_IMAGEANIMATOR_WIDTH; // 2: image index, 100: width value + imageAnimatorImageInfo_[SET_TWO].height = FIND_PHONE_IMAGEANIMATOR_HEIGHT; // 2: image index, 100: height value + imageAnimatorImageInfo_[SET_TWO].imageType = IMG_SRC_IMAGE_INFO; // 2: image index +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/findphone/src/FindPhoneModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/findphone/src/FindPhoneModel.cpp new file mode 100644 index 000000000..c4784a692 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/findphone/src/FindPhoneModel.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FindPhoneModel + * Create: 2025-03-23 + */ + +#include "ohos_timer.h" +#include "wearable_log.h" +#include "findphone/FindPhoneModel.h" +#include "findphone/FindPhoneView.h" + +namespace OHOS { +static constexpr uint64_t CENTI_SECOND_UNIT = 100; +static constexpr uint64_t MS_ONE_SECONDS = 1000; +static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t NUM_TIME_MIN = 60; +static constexpr uint16_t NUM_TIME_HOUR = 3600; +static constexpr int32_t NUM_TIME_DAY = 86400; +static constexpr int16_t MIN_TO_HOUR = 60; +static constexpr int16_t HOURLY_SYSTEM = 24; +FindPhoneModel::FindPhoneModel() {} + +FindPhoneModel::~FindPhoneModel() {} + +FindPhoneModel &FindPhoneModel::GetInstance() +{ + static FindPhoneModel instance; + return instance; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp new file mode 100644 index 000000000..96f909c52 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FindPhonePresenter + * Create: 2025-03-23 + */ + +#include "NativeRegisterManager.h" +#include "uiservice/ui_service.h" +#include "findphone/FindPhonePresenter.h" +#include "findphone/FindPhoneModel.h" +#include "findphone/FindPhoneView.h" + +namespace OHOS { +REGIST_MENU(VIEW_FIND_PHONE, FindPhoneView, FindPhonePresenter, FINDPHONE_MAIN_ICON, FINDPHONE_MAIN_ICON, "查找手机"); +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightBlinkPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightBlinkPage.cpp new file mode 100644 index 000000000..521673522 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightBlinkPage.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightBlinkPage + * Create: 2025-04-24 + */ + +#include "flashlight/FlashLightBlinkPage.h" +#include "flashlight/FlashLightPresenter.h" +#include "SlicePageFactory.h" +#include "flashlight/FlashLightView.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "flashlight/FlashLightModel.h" +#include "main/LoadImg.h" +#include "flashlight/FlashlightUiResourceImage.h" +namespace OHOS { +static const uint16_t BLINK_PICKER_POS_X = 106; +static const uint16_t BLINK_PICKER_POS_Y = 113; +static const uint16_t BLINK_PICKER_WIDTH = 254; +static const uint16_t BLINK_PICKER_HEIGHT = 218; +static const uint16_t BLINK_PICKER_BACKGROUND_FONT_SIZE = 38; +static const uint16_t BLINK_PICKER_HIGHLIGHT_FONT_SIZE = 44; +static const uint16_t BLINK_PICKER_ITEM_HEIGHT = 73; +static const uint16_t BLINK_PICKER_NUM = 3; +static const uint16_t BLINK_BUTTON_POS_X = 59; +static const uint16_t BLINK_BUTTON_POS_Y = 358; +static const uint16_t BLINK_BUTTON_WIDTH = 337; +static const uint16_t BLINK_BUTTON_HEIGHT = 96; +static const uint16_t BLINK_TEXT_POS_X = 100; +static const uint16_t BLINK_TEXT_POS_Y = 38; +static const uint16_t BLINK_TEXT_WIDTH = 253; +static const uint16_t BLINK_TEXT_HEIGHT = 53; +static const uint16_t BLINK_TEXT_FONT_SIZE = 38; +static const std::string START_BLINK_BUTTON_ID = "startBlink"; + +REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_BLINK_VIEW, FlashLightBlinkPage, false); +void FlashLightBlinkPage::OnStart(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::OnStart"); + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + if (blinkLabel_ == nullptr) { + blinkLabel_ = new UILabel(); + } + blinkLabel_->SetPosition(BLINK_TEXT_POS_X, BLINK_TEXT_POS_Y, BLINK_TEXT_WIDTH, BLINK_TEXT_HEIGHT); + blinkLabel_->SetText("闪烁频率"); + blinkLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + blinkLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + blinkLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BLINK_TEXT_FONT_SIZE); + container_->Add(blinkLabel_); + blinkLabel_->SetVisible(true); + + // Add Picker to App + if (blinkPicker_ == nullptr) { + blinkPicker_ = new UIPicker(); + } + blinkPicker_->SetPosition(BLINK_PICKER_POS_X, BLINK_PICKER_POS_Y, BLINK_PICKER_WIDTH, BLINK_PICKER_HEIGHT); + blinkPicker_->SetViewId("uiPicker1"); + blinkPicker_->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BLINK_PICKER_BACKGROUND_FONT_SIZE); + blinkPicker_->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, BLINK_PICKER_HIGHLIGHT_FONT_SIZE); + const char *uiPicker1Data[] = {"慢", "å¿«", "不闪烁"}; + blinkPicker_->SetValues(uiPicker1Data, BLINK_PICKER_NUM); + uint16_t selectBlink = FlashLightModel::GetInstance().GetBlinkFrequency(); + blinkPicker_->SetSelected(selectBlink); + blinkPicker_->SetTextColor(Color::Gray(), Color::White()); + blinkPicker_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + blinkPicker_->SetItemHeight(BLINK_PICKER_ITEM_HEIGHT); + container_->Add(blinkPicker_); + blinkPicker_->SetVisible(true); + + // Add LabelButtonExt to App + if (blinkButton_ == nullptr) { + blinkButton_ = new UILabelButtonExt(); + } + blinkButton_->SetPosition(BLINK_BUTTON_POS_X, BLINK_BUTTON_POS_Y, BLINK_BUTTON_WIDTH, BLINK_BUTTON_HEIGHT); + blinkButton_->SetViewId(START_BLINK_BUTTON_ID.c_str()); + LOADIMG::LoadBtnImage(blinkButton_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_BLINKBUTTON, + IMAGE_CONVERTER_TOOL_BLINKBUTTON); + blinkButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + blinkButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + container_->Add(blinkButton_); + blinkButton_->SetVisible(true); + + blinkButton_->SetOnClickListener(this); + container_->SetOnDragListener(this); + AddViewToPageContainer(container_); +} + +FlashLightBlinkPage::~FlashLightBlinkPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::~FlashLightBlinkPage"); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (blinkLabel_ != nullptr) { + delete blinkLabel_; + blinkLabel_ = nullptr; + } + if (blinkPicker_ != nullptr) { + delete blinkPicker_; + blinkPicker_ = nullptr; + } + if (blinkButton_ != nullptr) { + delete blinkButton_; + blinkButton_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); +} + +bool FlashLightBlinkPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::OnDrag"); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW); + } + return false; +} + +bool FlashLightBlinkPage::OnClick(UIView &view, const ClickEvent &event) +{ + std::string viewId = view.GetViewId(); + uint16_t itemIndex = blinkPicker_->GetSelected(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::OnClick [%s], itemIndex : [%d] ", viewId.c_str(), + itemIndex); + if (viewId == START_BLINK_BUTTON_ID) { + FlashLightModel::GetInstance().SetBlinkFrequency((FlashLightBlinkFrequency)itemIndex); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightBlinkPage::OnClick [Invalid]"); + } + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightColorPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightColorPage.cpp new file mode 100644 index 000000000..20ae1c068 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightColorPage.cpp @@ -0,0 +1,330 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightColorPage + * Create: 2025-04-24 + */ + +#include "flashlight/FlashLightColorPage.h" +#include "flashlight/FlashLightPresenter.h" +#include "SlicePageFactory.h" +#include "flashlight/FlashLightView.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "flashlight/FlashLightModel.h" +#include "main/LoadImg.h" +#include "flashlight/FlashlightUiResourceImage.h" +namespace OHOS { +static const uint16_t COLOR_LABEL_POS_X = 100; +static const uint16_t COLOR_LABEL_POS_Y = 38; +static const uint16_t COLOR_LABEL_WIDTH = 253; +static const uint16_t COLOR_LABEL_HEIGHT = 53; +static const uint16_t COLOR_LABEL_FONT_SIZE = 38; +static const uint16_t CONTAINER_BLANK_SIZE = 100; +// 行坐标 +const uint16_t FIRST_ROW_COLOR_BUTTON_POS_Y = 104; +const uint16_t SECOND_ROW_COLOR_BUTTON_POS_Y = 225; +const uint16_t THIRD_ROW_COLOR_BUTTON_POS_Y = 346; +// 列坐标 +const uint16_t FIRST_COLUMN_COLOR_BUTTON_POS_X = 46; +const uint16_t SECOND_COLUMN_COLOR_BUTTON_POS_X = 169; +const uint16_t THIRD_COLUMN_COLOR_BUTTON_POS_X = 290; +// 按钮大小 +const uint16_t COLOR_BUTTON_WIDTH = 117; +const uint16_t COLOR_BUTTON_HEIGHT = 117; +static const uint32_t SELECT_COLOR_BUTTON_RES[10] = { + 0, + IMAGE_CONVERTER_TOOL_COLOR1PRESSBUTTON, + IMAGE_CONVERTER_TOOL_COLOR2PRESSBUTTON, + IMAGE_CONVERTER_TOOL_COLOR3PRESSBUTTON, + IMAGE_CONVERTER_TOOL_COLOR4PRESSBUTTON, + IMAGE_CONVERTER_TOOL_COLOR5PRESSBUTTON, + IMAGE_CONVERTER_TOOL_COLOR6PRESSBUTTON, + IMAGE_CONVERTER_TOOL_COLOR7PRESSBUTTON, + IMAGE_CONVERTER_TOOL_COLOR8PRESSBUTTON, + IMAGE_CONVERTER_TOOL_COLOR9PRESSBUTTON, +}; +static const std::string COLOR1_BUTTON_ID = "color1Button"; +static const std::string COLOR2_BUTTON_ID = "color2Button"; +static const std::string COLOR3_BUTTON_ID = "color3Button"; +static const std::string COLOR4_BUTTON_ID = "color4Button"; +static const std::string COLOR5_BUTTON_ID = "color5Button"; +static const std::string COLOR6_BUTTON_ID = "color6Button"; +static const std::string COLOR7_BUTTON_ID = "color7Button"; +static const std::string COLOR8_BUTTON_ID = "color8Button"; +static const std::string COLOR9_BUTTON_ID = "color9Button"; +REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_COLOR_VIEW, FlashLightColorPage, false); +void FlashLightColorPage::OnStart(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnStart"); + uint32_t COLOR_BUTTON_RES[10] = { + 0, + IMAGE_CONVERTER_TOOL_COLOR1BUTTON, + IMAGE_CONVERTER_TOOL_COLOR2BUTTON, + IMAGE_CONVERTER_TOOL_COLOR3BUTTON, + IMAGE_CONVERTER_TOOL_COLOR4BUTTON, + IMAGE_CONVERTER_TOOL_COLOR5BUTTON, + IMAGE_CONVERTER_TOOL_COLOR6BUTTON, + IMAGE_CONVERTER_TOOL_COLOR7BUTTON, + IMAGE_CONVERTER_TOOL_COLOR8BUTTON, + IMAGE_CONVERTER_TOOL_COLOR9BUTTON, + }; + uint16_t selectColor = (uint16_t)FlashLightModel::GetInstance().GetViewColor(); + COLOR_BUTTON_RES[selectColor] = SELECT_COLOR_BUTTON_RES[selectColor]; + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + container_->SetScrollBlankSize(CONTAINER_BLANK_SIZE, UIAbstractScroll::Direction::TOP); + container_->SetScrollBlankSize(CONTAINER_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + } + + if (colorLabel_ == nullptr) { + colorLabel_ = new UILabel(); + } + colorLabel_->SetPosition(COLOR_LABEL_POS_X, COLOR_LABEL_POS_Y, COLOR_LABEL_WIDTH, COLOR_LABEL_HEIGHT); + colorLabel_->SetText("灯光颜色"); + colorLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + colorLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + colorLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, COLOR_LABEL_FONT_SIZE); + container_->Add(colorLabel_); + colorLabel_->SetVisible(true); + // 第一行颜色按钮 + if (color1Button_ == nullptr) { + color1Button_ = new UILabelButtonExt(); + } + color1Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + color1Button_->SetViewId(COLOR1_BUTTON_ID.c_str()); + color1Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + color1Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + color1Button_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(color1Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[WHITE_COLOR], COLOR_BUTTON_RES[WHITE_COLOR]); + container_->Add(color1Button_); + color1Button_->SetVisible(true); + + if (color2Button_ == nullptr) { + color2Button_ = new UILabelButtonExt(); + } + color2Button_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + color2Button_->SetViewId(COLOR2_BUTTON_ID.c_str()); + color2Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + color2Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + color2Button_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(color2Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[RED_COLOR], COLOR_BUTTON_RES[RED_COLOR]); + container_->Add(color2Button_); + color2Button_->SetVisible(true); + + if (color3Button_ == nullptr) { + color3Button_ = new UILabelButtonExt(); + } + color3Button_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, FIRST_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + color3Button_->SetViewId(COLOR3_BUTTON_ID.c_str()); + color3Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + color3Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + color3Button_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(color3Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[ORANGE_COLOR], + COLOR_BUTTON_RES[ORANGE_COLOR]); + container_->Add(color3Button_); + color3Button_->SetVisible(true); + + // 第二行颜色按钮 + if (color4Button_ == nullptr) { + color4Button_ = new UILabelButtonExt(); + } + color4Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + color4Button_->SetViewId(COLOR4_BUTTON_ID.c_str()); + color4Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + color4Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + color4Button_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(color4Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[YELLOW_COLOR], + COLOR_BUTTON_RES[YELLOW_COLOR]); + container_->Add(color4Button_); + color4Button_->SetVisible(true); + + if (color5Button_ == nullptr) { + color5Button_ = new UILabelButtonExt(); + } + color5Button_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + color5Button_->SetViewId(COLOR5_BUTTON_ID.c_str()); + color5Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + color5Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + color5Button_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(color5Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[GREEN_COLOR], COLOR_BUTTON_RES[GREEN_COLOR]); + container_->Add(color5Button_); + color5Button_->SetVisible(true); + + if (color6Button_ == nullptr) { + color6Button_ = new UILabelButtonExt(); + } + color6Button_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, SECOND_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + color6Button_->SetViewId(COLOR6_BUTTON_ID.c_str()); + color6Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + color6Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + color6Button_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(color6Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[LIGHT_BLUE_COLOR], + COLOR_BUTTON_RES[LIGHT_BLUE_COLOR]); + + container_->Add(color6Button_); + color6Button_->SetVisible(true); + + // 第三行颜色按钮 + if (color7Button_ == nullptr) { + color7Button_ = new UILabelButtonExt(); + } + color7Button_->SetPosition(FIRST_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + color7Button_->SetViewId(COLOR7_BUTTON_ID.c_str()); + color7Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + color7Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + color7Button_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(color7Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[DARK_BLUE_COLOR], + COLOR_BUTTON_RES[DARK_BLUE_COLOR]); + container_->Add(color7Button_); + color7Button_->SetVisible(true); + + if (color8Button_ == nullptr) { + color8Button_ = new UILabelButtonExt(); + } + color8Button_->SetPosition(SECOND_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + color8Button_->SetViewId(COLOR8_BUTTON_ID.c_str()); + color8Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + color8Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + color8Button_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(color8Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[PURPLE_COLOR], + COLOR_BUTTON_RES[PURPLE_COLOR]); + container_->Add(color8Button_); + color8Button_->SetVisible(true); + + if (color9Button_ == nullptr) { + color9Button_ = new UILabelButtonExt(); + } + color9Button_->SetPosition(THIRD_COLUMN_COLOR_BUTTON_POS_X, THIRD_ROW_COLOR_BUTTON_POS_Y, COLOR_BUTTON_WIDTH, + COLOR_BUTTON_HEIGHT); + color9Button_->SetViewId(COLOR9_BUTTON_ID.c_str()); + color9Button_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + color9Button_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + color9Button_->SetAlign(TEXT_ALIGNMENT_CENTER); + LOADIMG::LoadBtnImage(color9Button_, FLASHLIGHT_IMAGE, COLOR_BUTTON_RES[MULTI_COLOR], COLOR_BUTTON_RES[MULTI_COLOR]); + container_->Add(color9Button_); + color9Button_->SetVisible(true); + + // 设置界面组件回调函数 + container_->SetOnDragListener(this); + // 设置手电筒多个颜色按钮回调函数 + color3Button_->SetOnClickListener(this); + color1Button_->SetOnClickListener(this); + color2Button_->SetOnClickListener(this); + color6Button_->SetOnClickListener(this); + color5Button_->SetOnClickListener(this); + color4Button_->SetOnClickListener(this); + color9Button_->SetOnClickListener(this); + color8Button_->SetOnClickListener(this); + color7Button_->SetOnClickListener(this); + AddViewToPageContainer(container_); +} + +FlashLightColorPage::~FlashLightColorPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::~FlashLightColorPage"); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (colorLabel_ != nullptr) { + delete colorLabel_; + colorLabel_ = nullptr; + } + if (color1Button_ != nullptr) { + delete color1Button_; + color1Button_ = nullptr; + } + if (color2Button_ != nullptr) { + delete color2Button_; + color2Button_ = nullptr; + } + if (color3Button_ != nullptr) { + delete color3Button_; + color3Button_ = nullptr; + } + if (color4Button_ != nullptr) { + delete color4Button_; + color4Button_ = nullptr; + } + if (color5Button_ != nullptr) { + delete color5Button_; + color5Button_ = nullptr; + } + if (color6Button_ != nullptr) { + delete color6Button_; + color6Button_ = nullptr; + } + if (color7Button_ != nullptr) { + delete color7Button_; + color7Button_ = nullptr; + } + if (color8Button_ != nullptr) { + delete color8Button_; + color8Button_ = nullptr; + } + if (color9Button_ != nullptr) { + delete color9Button_; + color9Button_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); +} + +bool FlashLightColorPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnDrag"); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW); + } + return false; +} + +bool FlashLightColorPage::OnClick(UIView &view, const ClickEvent &event) +{ + std::string viewId = view.GetViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnClick [%s]", viewId.c_str()); + if (viewId == COLOR1_BUTTON_ID) { + FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::WHITE_COLOR); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else if (viewId == COLOR2_BUTTON_ID) { + FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::RED_COLOR); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else if (viewId == COLOR3_BUTTON_ID) { + FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::ORANGE_COLOR); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else if (viewId == COLOR4_BUTTON_ID) { + FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::YELLOW_COLOR); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else if (viewId == COLOR5_BUTTON_ID) { + FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::GREEN_COLOR); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else if (viewId == COLOR6_BUTTON_ID) { + FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::LIGHT_BLUE_COLOR); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else if (viewId == COLOR7_BUTTON_ID) { + FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::DARK_BLUE_COLOR); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else if (viewId == COLOR8_BUTTON_ID) { + FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::PURPLE_COLOR); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else if (viewId == COLOR9_BUTTON_ID) { + FlashLightModel::GetInstance().SetViewColor(FlashLightColorAttribute::MULTI_COLOR); + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnClick [Invalid]"); + } + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightDefaultPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightDefaultPage.cpp new file mode 100644 index 000000000..7b6582c39 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightDefaultPage.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightDefaultPage + * Create: 2025-04-24 + */ +#include "flashlight/FlashLightDefaultPage.h" +#include "flashlight/FlashLightPresenter.h" +#include "SlicePageFactory.h" +#include "flashlight/FlashLightView.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "flashlight/FlashLightModel.h" +#include "main/LoadImg.h" +#include "flashlight/FlashlightUiResourceImage.h" +namespace OHOS { +static const uint16_t RECOVER_LABEL_POS_X = 15; +static const uint16_t RECOVER_LABEL_POS_Y = 185; +static const uint16_t RECOVER_LABEL_WIDTH = 424; +static const uint16_t RECOVER_LABEL_HEIGHT = 50; +static const uint16_t RECOVER_LABEL_FONT_SIZE = 36; +static const uint16_t CANCLE_BUTTON_POS_X = 115; +static const uint16_t CANCLE_BUTTON_POS_Y = 300; +static const uint16_t CONFIRM_BUTTON_POS_X = 255; +static const uint16_t CONFIRM_BUTTON_POS_Y = 300; +static const uint16_t CANCLE_BUTTON_WIDTH = 85; +static const uint16_t CANCLE_BUTTON_HEIGHT = 85; +static const std::string CANCLE_BUTTON_ID = "cancle"; +static const std::string CONFIRM_BUTTON_ID = "confirm"; + +REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_DEFAULT_VIEW, FlashLightDefaultPage, false); +void FlashLightDefaultPage::OnStart(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightDefaultPage::OnStart"); + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + if (recoverLabel_ == nullptr) { + recoverLabel_ = new UILabel(); + } + recoverLabel_->SetPosition(RECOVER_LABEL_POS_X, RECOVER_LABEL_POS_Y, RECOVER_LABEL_WIDTH, RECOVER_LABEL_HEIGHT); + recoverLabel_->SetText("是否恢复默认设置"); + recoverLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + recoverLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + recoverLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, RECOVER_LABEL_FONT_SIZE); + // Add to rootView + container_->Add(recoverLabel_); + recoverLabel_->SetVisible(true); + + if (cancelButton_ == nullptr) { + cancelButton_ = new UILabelButtonExt(); + } + cancelButton_->SetPosition(CANCLE_BUTTON_POS_X, CANCLE_BUTTON_POS_Y, CANCLE_BUTTON_WIDTH, CANCLE_BUTTON_HEIGHT); + cancelButton_->SetViewId(CANCLE_BUTTON_ID.c_str()); + LOADIMG::LoadBtnImage(cancelButton_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_RECOVERCANCLE, + IMAGE_CONVERTER_TOOL_RECOVERCANCLE); + cancelButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + cancelButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + container_->Add(cancelButton_); + cancelButton_->SetVisible(true); + + if (confirmButton_ == nullptr) { + confirmButton_ = new UILabelButtonExt(); + } + confirmButton_->SetPosition(CONFIRM_BUTTON_POS_X, CONFIRM_BUTTON_POS_Y, CANCLE_BUTTON_WIDTH, CANCLE_BUTTON_HEIGHT); + confirmButton_->SetViewId(CONFIRM_BUTTON_ID.c_str()); + LOADIMG::LoadBtnImage(confirmButton_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_RECOVERCONFIRM, + IMAGE_CONVERTER_TOOL_RECOVERCONFIRM); + confirmButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + confirmButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + container_->Add(confirmButton_); + confirmButton_->SetVisible(true); + + // 设置界面组件回调函数 + container_->SetOnDragListener(this); + cancelButton_->SetOnClickListener(this); + confirmButton_->SetOnClickListener(this); + AddViewToPageContainer(container_); +} + +FlashLightDefaultPage::~FlashLightDefaultPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightDefaultPage::~FlashLightDefaultPage"); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (recoverLabel_ != nullptr) { + delete recoverLabel_; + recoverLabel_ = nullptr; + } + if (cancelButton_ != nullptr) { + delete cancelButton_; + cancelButton_ = nullptr; + } + if (confirmButton_ != nullptr) { + delete confirmButton_; + confirmButton_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); +} + +bool FlashLightDefaultPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnDrag"); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW); + } + return false; +} + +bool FlashLightDefaultPage::OnClick(UIView &view, const ClickEvent &event) +{ + std::string viewId = view.GetViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightDefaultPage::OnClick [%s]", viewId.c_str()); + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + if (viewId == CONFIRM_BUTTON_ID) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGTH_VIEW); + FlashLightModel::GetInstance().SetDefault(); + } else if (viewId == CANCLE_BUTTON_ID) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW); + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightDefaultPage::OnClick [Invalid]"); + } + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightModel.cpp new file mode 100644 index 000000000..273a4641a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightModel.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightModel + * Create: 2025-04-24 + */ +#include "flashlight/FlashLightModel.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif + +namespace OHOS { +static const uint32_t TIME_DISPLAY_NUM = 10; +FlashLightModel::FlashLightModel(FlashLightColorAttribute color, FlashLightBlinkFrequency blinkFrequency) +{ + color_ = color; + blinkFrequency_ = blinkFrequency; +} + +FlashLightModel::~FlashLightModel() {} + +FlashLightModel &FlashLightModel::GetInstance() +{ + static FlashLightModel instance; + return instance; +} + +FlashLightColorAttribute FlashLightModel::GetViewColor() +{ + return color_; +} + +void FlashLightModel::SetViewColor(FlashLightColorAttribute color) +{ + color_ = color; +} + +FlashLightBlinkFrequency FlashLightModel::GetBlinkFrequency() +{ + return blinkFrequency_; +} + +void FlashLightModel::SetBlinkFrequency(FlashLightBlinkFrequency blinkFrequency) +{ + blinkFrequency_ = blinkFrequency; +} + +void FlashLightModel::SetDefault() +{ + blinkFrequency_ = FlashLightBlinkFrequency::NOT_BLINK; // 不闪烁; + color_ = FlashLightColorAttribute::WHITE_COLOR; // 白色; +} + +uint32_t FlashLightModel::GetSysCurrentTime(std::string ¤tTime) +{ +#ifdef _WIN32 + struct tm localTime; + time_t timep; + gettimeofday(&sysTime_, NULL); + timep = (time_t)sysTime_.tv_sec; + localtime_r(&timep, &localTime); +#else + struct tm localTime; + time64_t timep; + gettimeofday64(&sysTime_, NULL); + timep = (time64_t)sysTime_.tv_sec; + localtime64_r(&sysTime_.tv_sec, &localTime); +#endif + if (localTime.tm_hour < TIME_DISPLAY_NUM) { + currentTime += "0"; + } + currentTime += std::to_string(localTime.tm_hour) + ":"; + if (localTime.tm_min < TIME_DISPLAY_NUM) { + currentTime += "0"; + } + currentTime += std::to_string(localTime.tm_min); + return 0; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightPage.cpp new file mode 100644 index 000000000..ba91d99ce --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightPage.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightPage + * Create: 2025-04-24 + */ +#include +#include "flashlight/FlashLightPage.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashLightModel.h" +#include "SlicePageFactory.h" +#include "flashlight/FlashLightView.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "main/LoadImg.h" +#include "flashlight/FlashlightUiResourceImage.h" + +namespace OHOS { +static const uint16_t SWITCH_BUTTON_POS_X = 168; +static const uint16_t SWITCH_BUTTON_POS_Y = 168; +static const uint16_t SWITCH_BUTTON_WIDTH = 119; +static const uint16_t SWITCH_BUTTON_HEIGHT = 119; +static const uint16_t SWITCH_LABEL_POS_X = 168; +static const uint16_t SWITCH_LABEL_POS_Y = 308; +static const uint16_t SWITCH_LABEL_WIDTH = 128; +static const uint16_t SWITCH_LABEL_HEIGHT = 46; +static const uint16_t SWITCH_LABEL_FONT_SIZE = 32; +static const uint16_t TIME_LABEL_FONT_SIZE = 38; +static const uint16_t IMAGE_VIEW_POS_X = 213; +static const uint16_t IMAGE_VIEW_POS_Y = 414; +static const uint16_t TIME_TEXT_POS_X = 151; +static const uint16_t TIME_TEXT_POS_Y = 31; +static const uint16_t TIME_TEXT_WIDTH = 153; +static const uint16_t TIME_TEXT_HEIGHT = 53; +static const uint16_t Y_OFFSET = 300; +static const std::string SWITCH_BUTTON_ID = "switch"; + +REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGTH_VIEW, FlashLightPage, true); +void FlashLightPage::OnStart(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::OnStart"); + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + } + + if (OnLabel_ == nullptr) { + OnLabel_ = new UILabel(); + } + OnLabel_->SetPosition(SWITCH_LABEL_POS_X, SWITCH_LABEL_POS_Y, SWITCH_LABEL_WIDTH, SWITCH_LABEL_HEIGHT); + OnLabel_->SetText("点击照明"); + OnLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + OnLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SWITCH_LABEL_FONT_SIZE); + OnLabel_->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + OnLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + OnLabel_->SetVisible(true); + container_->Add(OnLabel_); + + if (flashLightOn_ == nullptr) { + flashLightOn_ = new UILabelButton(); + } + flashLightOn_->SetPosition(SWITCH_BUTTON_POS_X, SWITCH_BUTTON_POS_Y, SWITCH_BUTTON_WIDTH, SWITCH_BUTTON_HEIGHT); + flashLightOn_->SetViewId(SWITCH_BUTTON_ID.c_str()); + flashLightOn_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + flashLightOn_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + LOADIMG::LoadBtnImage(flashLightOn_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_FLASHLIGHTON, + IMAGE_CONVERTER_TOOL_FLASHLIGHTON); + flashLightOn_->SetVisible(true); + container_->Add(flashLightOn_); + + // 创建时间显示组件 + if (systemTime_ == nullptr) { + systemTime_ = new UILabel(); + } + systemTime_->SetPosition(TIME_TEXT_POS_X, TIME_TEXT_POS_Y, TIME_TEXT_WIDTH, TIME_TEXT_HEIGHT); + systemTime_->SetText("12:00"); + systemTime_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + systemTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIME_LABEL_FONT_SIZE); + systemTime_->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + systemTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + systemTime_->SetVisible(true); + container_->Add(systemTime_); + if (timeCallback_ == nullptr) { + timeCallback_ = new TimeAnimatorCallback(); + } + if (timeAnimator_ == nullptr) { + timeAnimator_ = new Animator(timeCallback_, systemTime_, 0, true); + } + timeAnimator_->Start(); + + // Add ImageView to App + if (imageArrow_ == nullptr) { + imageArrow_ = new UIImageView(); + } + imageArrow_->SetPosition(IMAGE_VIEW_POS_X, IMAGE_VIEW_POS_Y); + container_->Add(imageArrow_); + imageArrow_->SetVisible(true); + LOADIMG::LoadImageViewImg(imageArrow_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_DOWNARROW); + + flashLightOn_->SetOnClickListener(this); + container_->SetOnDragListener(this); + AddViewToPageContainer(container_); +} + +FlashLightPage::~FlashLightPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::~FlashLightPage"); + if (timeAnimator_ != nullptr) { + timeAnimator_->Stop(); + } + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (flashLightOn_ != nullptr) { + delete flashLightOn_; + flashLightOn_ = nullptr; + } + if (systemTime_ != nullptr) { + delete systemTime_; + systemTime_ = nullptr; + } + if (imageArrow_ != nullptr) { + delete imageArrow_; + imageArrow_ = nullptr; + } + if (timeAnimator_ != nullptr) { + delete timeAnimator_; + timeAnimator_ = nullptr; + } + if (timeCallback_ != nullptr) { + delete timeCallback_; + timeCallback_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); +} + +bool FlashLightPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnDrag"); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } else if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && + (event.GetStartPoint().y > Y_OFFSET)) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW); + } + return false; +} + +bool FlashLightPage::OnClick(UIView &view, const ClickEvent &event) +{ + std::string viewId = view.GetViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::OnClick [%s]", viewId.c_str()); + if (viewId == SWITCH_BUTTON_ID) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW); + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPage::OnClick [Invalid]"); + } + return false; +} + +void FlashLightPage::TimeAnimatorCallback::Callback(UIView *view) +{ + UILabel *timeLabel = dynamic_cast(view); + if (timeLabel == nullptr) { + return; + } + std::string currTime; + FlashLightModel::GetInstance().GetSysCurrentTime(currTime); + timeLabel->SetText(currTime.c_str()); + timeLabel->Invalidate(); +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightPlayPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightPlayPage.cpp new file mode 100644 index 000000000..fdf35dccc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightPlayPage.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightPlayPage + * Create: 2025-04-24 + */ + +#include "flashlight/FlashLightPlayPage.h" +#include "flashlight/FlashLightPresenter.h" +#include "SlicePageFactory.h" +#include "flashlight/FlashLightView.h" +#include "wearable_log.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "main/LoadImg.h" + +namespace OHOS { +static const uint32_t FLASHLIGHT_PAGE_RES[10] = { + IMAGE_CONVERTER_TOOL_PLAYBLACKPAGE, IMAGE_CONVERTER_TOOL_PLAY1PAGE, IMAGE_CONVERTER_TOOL_PLAY2PAGE, + IMAGE_CONVERTER_TOOL_PLAY3PAGE, IMAGE_CONVERTER_TOOL_PLAY4PAGE, IMAGE_CONVERTER_TOOL_PLAY5PAGE, + IMAGE_CONVERTER_TOOL_PLAY6PAGE, IMAGE_CONVERTER_TOOL_PLAY7PAGE, IMAGE_CONVERTER_TOOL_PLAY8PAGE, + IMAGE_CONVERTER_TOOL_PLAY9PAGE, +}; +static const uint32_t FLASHLIGHT_BLINK_FREQ[3] = {500, 100, 0}; +static const uint32_t IMAGE_NUM = 2; +static const std::string PLAY_VIEW_ID = "flashLightPlayPage"; + +REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_PLAY_VIEW, FlashLightPlayPage, false); +void FlashLightPlayPage::OnStart(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPlayPage::OnStart"); + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetViewId(PLAY_VIEW_ID.c_str()); + } + uint16_t colorIndex = (uint16_t)FlashLightModel::GetInstance().GetViewColor(); + uint16_t blinkIndex = (uint16_t)FlashLightModel::GetInstance().GetBlinkFrequency(); + if (playImageAnimal == nullptr) { + playImageAnimal = new UIImageAnimatorView(); + } + playImageInfo[0].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(FLASHLIGHT_PAGE_RES[colorIndex], FLASHLIGHT_IMAGE); + playImageInfo[0].imageType = IMG_SRC_IMAGE_INFO; + playImageInfo[0].pos.x = 0; + playImageInfo[0].pos.y = 0; + playImageInfo[0].width = HORIZONTAL_RESOLUTION; + playImageInfo[0].height = VERTICAL_RESOLUTION; + playImageInfo[1].imageInfo = + ImageCacheManager::GetInstance().LoadOneInMultiRes(FLASHLIGHT_PAGE_RES[0], FLASHLIGHT_IMAGE); + playImageInfo[1].imageType = IMG_SRC_IMAGE_INFO; + playImageInfo[1].pos.x = 0; + playImageInfo[1].pos.y = 0; + playImageInfo[1].width = HORIZONTAL_RESOLUTION; + playImageInfo[1].height = VERTICAL_RESOLUTION; + playImageAnimal->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + playImageAnimal->SetImageAnimatorSrc(playImageInfo, IMAGE_NUM, FLASHLIGHT_BLINK_FREQ[blinkIndex]); + playImageAnimal->SetRepeat(true); + playImageAnimal->SetAutoEnable(false); + playImageAnimal->SetResizeMode(UIImageView::FILL); + container_->Add(playImageAnimal); + + playImageAnimal->Start(); + container_->SetOnDragListener(this); + container_->SetOnClickListener(this); + AddViewToPageContainer(container_); +} + +FlashLightPlayPage::~FlashLightPlayPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPlayPage::~FlashLightPlayPage"); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (playImageAnimal != nullptr) { + playImageAnimal->Stop(); + delete playImageAnimal; + playImageAnimal = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); +} + +bool FlashLightPlayPage::OnDrag(UIView &view, const DragEvent &event) +{ + std::string id = view.GetViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnDrag [%s]", id.c_str()); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + return false; +} + +bool FlashLightPlayPage::OnClick(UIView &view, const ClickEvent &event) +{ + std::string viewId = view.GetViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightPlayPage::OnClick [%s]", viewId.c_str()); + if (viewId == PLAY_VIEW_ID) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGTH_VIEW); + } + return false; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightPresenter.cpp new file mode 100644 index 000000000..57bb513b2 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightPresenter.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightPresenter + * Create: 2025-04-24 + */ + +#include "flashlight/FlashLightView.h" +#include "flashlight/FlashLightPresenter.h" +#include "NativeRegisterManager.h" + +namespace OHOS { +REGIST_MENU(VIEW_FLASHLIGHT, FlashLightView, FlashLightPresenter, FLASHLIGHT_MAIN_ICON, PNG_APPLIST_DEFAULT_IMG, + "手电筒"); +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightSetItemAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightSetItemAdapter.cpp new file mode 100644 index 000000000..2adbf459e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightSetItemAdapter.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightSetItemAdapter.cpp + * Create: 2025-11-23 + */ +#include "flashlight/FlashLightSetItemAdapter.h" +#include "flashlight/FlashLightSetItemView.h" + +namespace OHOS { +FlashLightSetItemAdapter::FlashLightSetItemAdapter() {} + +FlashLightSetItemAdapter::~FlashLightSetItemAdapter() +{ + itemDatas_.Clear(); +} + +uint16_t FlashLightSetItemAdapter::GetCount(void) +{ + return itemDatas_.Size(); +} + +void FlashLightSetItemAdapter::SetData(const Graphic::Vector &data) +{ + if (!itemDatas_.IsEmpty()) { + itemDatas_.Clear(); + } + itemDatas_ = data; +} + +UIView *FlashLightSetItemAdapter::GetView(UIView *inView, int16_t index) +{ + if (itemDatas_.IsEmpty()) { + return nullptr; + } + + if (index >= itemDatas_.Size() || index < 0) { + return nullptr; + } + + FlashLightSetItem itemData = itemDatas_[index]; + FlashLightSetItemView *item = nullptr; + if (inView == nullptr) { + item = new FlashLightSetItemView(); + } else { + item = static_cast(inView); + } + item->SetItemInfo(itemData); + item->SetViewId(itemData.label.c_str()); + item->SetOnClickListener(itemClickListener); + return item; +} + +void FlashLightSetItemAdapter::AddListItem(const FlashLightSetItem &item) +{ + itemDatas_.PushBack(item); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightSetItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightSetItemView.cpp new file mode 100644 index 000000000..32f330bf3 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightSetItemView.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightSetItemView + * Create: 2025-02-15 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "flashlight/FlashLightSetItemView.h" +#include "screensetting/ScreenModels.h" +#include "main/LoadImg.h" +#include "flashlight/FlashLightModel.h" + +namespace OHOS { +static constexpr uint16_t ITEM_X = 0; +static constexpr uint16_t ITEM_Y = 0; +static constexpr uint16_t ITEM_W = 340; +static constexpr uint16_t ITEM_H = 122; +static constexpr uint16_t ICON_X = 0; +static constexpr uint16_t ICON_Y = 10; +static constexpr uint16_t LABEL_X = 109; +static constexpr uint16_t LABEL_Y = 0; +static constexpr uint16_t LABEL_W = 172; +static constexpr uint16_t LABEL_H = 53; +static constexpr uint16_t LABEL_FONT = 38; +static constexpr uint16_t IMAGE_X = 315; +static constexpr uint16_t IMAGE_Y = 33; +static constexpr uint16_t ITEM_LABEL_X = 109; +static constexpr uint16_t ITEM_LABEL_Y = 52; +static constexpr uint16_t ITEM_LABEL_W = 172; +static constexpr uint16_t ITEM_LABEL_H = 46; +static constexpr uint16_t ITEM_LABEL_FONT = 32; + +FlashLightSetItemView::FlashLightSetItemView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightSetItemView"); + SetPosition(ITEM_X, ITEM_Y, ITEM_W, ITEM_H); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetTouchable(true); + + sIcon.SetPosition(ICON_X, ICON_Y); + sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + sLabel.SetPosition(LABEL_X, LABEL_Y); + sLabel.Resize(LABEL_W, LABEL_H); + sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + sLabel.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + sLabel.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + itemLabel.SetPosition(ITEM_LABEL_X, ITEM_LABEL_Y); + itemLabel.Resize(ITEM_LABEL_W, ITEM_LABEL_H); + itemLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, ITEM_LABEL_FONT); + itemLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + itemLabel.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + itemLabel.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); + itemLabel.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + itemLabel.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + sNextImage.SetPosition(IMAGE_X, IMAGE_Y); + sNextImage.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + LOADIMG::LoadImageViewImg(&sNextImage, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_RIGHTARROW); + + Add(&sIcon); + Add(&sLabel); + Add(&itemLabel); + Add(&sNextImage); +} + +FlashLightSetItemView::~FlashLightSetItemView() +{ + Remove(&sIcon); + Remove(&sLabel); + Remove(&itemLabel); + Remove(&sNextImage); + ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); +} + +void FlashLightSetItemView::SetItemInfo(const FlashLightSetItem itemInfo) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightSetItemView::SetItemInfo %[s]", itemInfo.viewId.c_str()); + sItemInfo = itemInfo; + sLabel.SetText(itemInfo.label.c_str()); + itemLabel.SetText(itemInfo.itemLabel.c_str()); + LOADIMG::LoadImageViewImg(&sIcon, FLASHLIGHT_IMAGE, itemInfo.resId); +} + +const char *FlashLightSetItemView::GetViewId() const +{ + return sItemInfo.viewId.c_str(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightSetPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightSetPage.cpp new file mode 100644 index 000000000..7a2361a61 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/flashlight/src/FlashLightSetPage.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightSetPage + * Create: 2025-04-24 + */ + +#include "flashlight/FlashLightSetPage.h" +#include "flashlight/FlashLightPresenter.h" +#include "SlicePageFactory.h" +#include "flashlight/FlashLightView.h" +#include "flashlight/FlashLightModel.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include +#include "main/LoadImg.h" + +namespace OHOS { + +static const uint16_t SET_LABEL_POS_X = 117; +static const uint16_t SET_LABEL_POS_Y = 31; +static const uint16_t SET_LABEL_WIDTH = 220; +static const uint16_t SET_LABEL_HEIGHT = 53; +static const uint16_t SET_LABEL_FONT_SIZE = 38; +static const uint16_t SET_LIST_POS_X = 59; +static const uint16_t SET_LIST_POS_Y = 127; +static const uint16_t SET_LIST_WIDTH = 340; +static const uint16_t SET_LIST_HEIGHT = 244; +static const uint16_t RECOVER_BUTTON_POS_X = 120; +static const uint16_t RECOVER_BUTTON_POS_Y = 408; +static const uint16_t RECOVER_BUTTON_WIDTH = 220; +static const uint16_t RECOVER_BUTTON_HEIGHT = 80; +static const uint16_t RECOVER_BUTTON_FONT_SIZE = 36; +static const uint16_t CONTAINER_BLANK_SIZE = 100; +static const std::string COLOR__BUTTON_ID = "setColorItem"; +static const std::string BLINK_BUTTON_ID = "setBlinkItem"; +static const std::string RECOVER_BUTTON_ID = "recoverDefault"; +static std::string BLINK_ITEM_CONTENT[3] = {"慢", "å¿«", "不闪烁"}; +static std::string COLOR_ITEM_CONTENT[10] = {"黑色", "白色", "红色", "橙色", "黄色", + "绿色", "浅蓝色", "深蓝色", "紫色", "彩色"}; + +REGIST_SLICE_PAGE(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_SET_VIEW, FlashLightSetPage, false); +void FlashLightSetPage::OnStart(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightSetPage::OnStart"); + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + container_->SetScrollBlankSize(CONTAINER_BLANK_SIZE, UIAbstractScroll::Direction::TOP); + container_->SetScrollBlankSize(CONTAINER_BLANK_SIZE, UIAbstractScroll::Direction::BOTTOM); + } + + if (setLabel_ == nullptr) { + setLabel_ = new UILabel(); + } + setLabel_->SetPosition(SET_LABEL_POS_X, SET_LABEL_POS_Y, SET_LABEL_WIDTH, SET_LABEL_HEIGHT); + setLabel_->SetText("手电筒设置"); + setLabel_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + setLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + setLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SET_LABEL_FONT_SIZE); + container_->Add(setLabel_); + setLabel_->SetVisible(true); + + if (setItemList_ == nullptr) { + setItemList_ = new UIList(); + } + setItemList_->SetPosition(SET_LIST_POS_X, SET_LIST_POS_Y, SET_LIST_WIDTH, SET_LIST_HEIGHT); + setItemList_->SetLoopState(false); + setItemList_->EnableAutoAlign(true); + if (setItemAdapter_ == nullptr) { + setItemAdapter_ = new FlashLightSetItemAdapter(); + } + uint16_t colorIndex = (uint16_t)FlashLightModel::GetInstance().GetViewColor(); + uint16_t blinkIndex = (uint16_t)FlashLightModel::GetInstance().GetBlinkFrequency(); + colorItem_.itemLabel = COLOR_ITEM_CONTENT[colorIndex]; + colorItem_.viewId = COLOR__BUTTON_ID; + blinkItem_.itemLabel = BLINK_ITEM_CONTENT[blinkIndex]; + blinkItem_.viewId = BLINK_BUTTON_ID; + setItemAdapter_->AddListItem(colorItem_); + setItemAdapter_->AddListItem(blinkItem_); + setItemAdapter_->SetItemClickListener(this); + setItemList_->SetAdapter(setItemAdapter_); + container_->Add(setItemList_); + setItemList_->SetVisible(true); + + if (recoverButton_ == nullptr) { + recoverButton_ = new UILabelButtonExt(); + } + recoverButton_->SetPosition(RECOVER_BUTTON_POS_X, RECOVER_BUTTON_POS_Y, RECOVER_BUTTON_WIDTH, + RECOVER_BUTTON_HEIGHT); + recoverButton_->SetViewId(RECOVER_BUTTON_ID.c_str()); + recoverButton_->SetText("恢复默认\n"); + recoverButton_->SetTextColor(Color::Red()); + recoverButton_->SetAlign(TEXT_ALIGNMENT_CENTER); + recoverButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, RECOVER_BUTTON_FONT_SIZE); + LOADIMG::LoadBtnImage(recoverButton_, FLASHLIGHT_IMAGE, IMAGE_CONVERTER_TOOL_RECOVERBUTTON, + IMAGE_CONVERTER_TOOL_RECOVERBUTTON); + recoverButton_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + recoverButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + container_->Add(recoverButton_); + recoverButton_->SetVisible(true); + + // 设置界面组件回调函数 + container_->SetOnDragListener(this); + recoverButton_->SetOnClickListener(this); + AddViewToPageContainer(container_); +} + +FlashLightSetPage::~FlashLightSetPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightSetPage::~FlashLightSetPage"); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (setLabel_ != nullptr) { + delete setLabel_; + setLabel_ = nullptr; + } + if (recoverButton_ != nullptr) { + delete recoverButton_; + recoverButton_ = nullptr; + } + if (setItemList_ != nullptr) { + delete setItemList_; + setItemList_ = nullptr; + } + if (setItemAdapter_ != nullptr) { + delete setItemAdapter_; + setItemAdapter_ = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(FLASHLIGHT_IMAGE); +} + +bool FlashLightSetPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashLightColorPage::OnDrag"); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGTH_VIEW); + } + return false; +} + +bool FlashLightSetPage::OnClick(UIView &view, const ClickEvent &event) +{ + uint8_t viewType = view.GetViewType(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashLightSetPage::OnClick [%d]", viewType); + if (viewType == UIViewType::UI_VIEW_GROUP) { + FlashLightSetItemView *itemView = static_cast(&view); + std::string viewId = itemView->GetViewId(); + if (viewId == COLOR__BUTTON_ID) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_COLOR_VIEW); + } else if (viewId == BLINK_BUTTON_ID) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_BLINK_VIEW); + } + } else if (viewType == UIViewType::UI_LABEL_BUTTON_EXT && view.GetViewId() == RECOVER_BUTTON_ID) { + NativeAbility::GetInstance().SwitchSlice(VIEW_FLASHLIGHT, FlashLightAllView::FLASH_LIGHT_DEFAULT_VIEW); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashLightSetPage::OnClick [Invalid]"); + } + return false; +} +} \ No newline at end of file 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 852053b9b..43e318f77 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartModel.cpp @@ -1,10 +1,10 @@ -#include "HeartModel.h" +#include "heartrate/HeartModel.h" #include "wearable_log.h" #include "graphic_service.h" -#include "IndoorWalkPreparedView.h" -#include "IndoorWalkPresenter.h" -#include "MainViewSample.h" -#include "HeartRateView.h" +#include "indoorwalk/IndoorWalkPreparedView.h" +#include "indoorwalk/IndoorWalkPresenter.h" +#include "main/MainViewSample.h" +#include "heartrate/HeartRateView.h" #ifdef __cplusplus extern "C" { @@ -73,7 +73,7 @@ static void Notify(void *args, const Topic topic, Request* request) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[Notify] malloc fail"); } - int rets = memcpy_s(heartInfo, sizeof(HeartDatas), (HeartInfo*)request->data, request->len); + int rets = memcpy_s(heartInfo, sizeof(HeartDatas), (HeartDatas*)request->data, request->len); if (rets != EOK) { free(heartInfo); heartInfo = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartRateView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartRateView.cpp index 8c9643544..2c9b2c42e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartRateView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/heartrate/src/HeartRateView.cpp @@ -6,10 +6,10 @@ */ #include -#include "HeartRateView.h" +#include "heartrate/HeartRateView.h" #include "common/screen.h" #include "UiConfig.h" -#include "ScreenModels.h" +#include "screensetting/ScreenModels.h" #include "ui_resource_image.h" #include "common/image_cache_manager.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/activity/include/ActivityModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/activity/ActivityModel.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/activity/include/ActivityModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/activity/ActivityModel.h index 7c694f9f8..388fe95fd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/activity/include/ActivityModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/activity/ActivityModel.h @@ -13,7 +13,7 @@ #include #include #include "ohos_types.h" -#include "RtcService.h" +#include "rtcservice/RtcService.h" #include "samgr_lite.h" namespace OHOS { @@ -39,7 +39,7 @@ public: uint32 GetStepCounter(void); void ReviseStepCounter(uint32 &counter); void GetStepData(const StepDataDistribute &type, uint32_t *value); - void SetStepData(uint32_t &value); + void SetStepData(const uint32_t &value); void SaveStepToFile(struct tm *tm_data); int GetWeekToday(void); uint32 GetLastSavedValue(void); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/activity/include/ActivityPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/activity/ActivityPresenter.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/activity/include/ActivityPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/activity/ActivityPresenter.h index 7ff632eec..073146568 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/activity/include/ActivityPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/activity/ActivityPresenter.h @@ -10,7 +10,7 @@ #include #include "Presenter.h" -#include "MainActivityView.h" +#include "activity/MainActivityView.h" namespace OHOS { static constexpr const char *ACTIVITY_WEEK_VIEW = "activityweekview"; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/activity/include/ActivityWeekView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/activity/ActivityWeekView.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/activity/include/ActivityWeekView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/activity/ActivityWeekView.h index 06a8c755b..fa9da0b46 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/activity/include/ActivityWeekView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/activity/ActivityWeekView.h @@ -17,7 +17,7 @@ #include "UiConfig.h" #include "wearable_log.h" #include "components/ui_card_page.h" -#include "ActivityModel.h" +#include "activity/ActivityModel.h" namespace OHOS { #define DAYS 7 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/activity/include/MainActivityView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/activity/MainActivityView.h similarity index 81% rename from code/sdk/application/wearable/nativeapp/nativeui/activity/include/MainActivityView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/activity/MainActivityView.h index ff024061d..2d0a6877d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/activity/include/MainActivityView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/activity/MainActivityView.h @@ -19,10 +19,10 @@ #include "font/ui_font_bitmap.h" #include "font/ui_font.h" #include "graphic_config.h" -#include "ModelListenerSample.h" -#include "ActivityModel.h" -#include "ActivityPresenter.h" -#include "ActivityWeekView.h" +#include "main/ModelListenerSample.h" +#include "activity/ActivityModel.h" +#include "activity/ActivityPresenter.h" +#include "activity/ActivityWeekView.h" namespace OHOS { class ActivityPresenter; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardAdapter.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardAdapter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardAdapter.h index 8f18d42be..a819ed10c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardAdapter.h @@ -17,7 +17,7 @@ #include "components/abstract_adapter.h" #include "UiConfig.h" #include "wearable_log.h" -#include "AddCardItem.h" +#include "add_card/AddCardItem.h" namespace OHOS { class AddCardAdapter : public AbstractAdapter { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardItem.h b/code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardItem.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardItem.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardItem.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardModel.h similarity index 88% rename from code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardModel.h index 9bdf0e41d..0ef22336e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardModel.h @@ -12,8 +12,8 @@ #include #include "AppViewIDs.h" #include "UiConfig.h" -#include "AddCardPresenter.h" -#include "MainModel.h" +#include "add_card/AddCardPresenter.h" +#include "main/MainModel.h" namespace OHOS { class AddCardModel { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardPresenter.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardPresenter.h index f1fd42b33..c0ea8536f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardPresenter.h @@ -11,7 +11,7 @@ #include "Presenter.h" #include "components/ui_list.h" #include "components/ui_view.h" -#include "ModelListenerSample.h" +#include "main/ModelListenerSample.h" #define TOAST_KEEP_TIME 1000 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardView.h similarity index 93% rename from code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardView.h index 12cca7012..952590d8f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/add_card/include/AddCardView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/add_card/AddCardView.h @@ -15,8 +15,8 @@ #include "components/ui_toggle_button.h" #include "ChangeSliceListener.h" #include "UiConfig.h" -#include "AddCardAdapter.h" -#include "AddCardModel.h" +#include "add_card/AddCardAdapter.h" +#include "add_card/AddCardModel.h" namespace OHOS { class AddCardPresenter; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmClockModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmClockModel.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmClockModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmClockModel.h index 074df441b..9a742feb5 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmClockModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmClockModel.h @@ -9,7 +9,7 @@ #include "ohos_types.h" #include "list.h" -#include "AlmmgrAlarmClockManage.h" +#include "alarmclockmanage/AlmmgrAlarmClockManage.h" #include "player.h" #include "source.h" #include "broadcast_feature.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmCloseRingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmCloseRingView.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmCloseRingView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmCloseRingView.h index f995da7ee..8cd9634b2 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmCloseRingView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmCloseRingView.h @@ -14,7 +14,7 @@ #include "components/ui_button.h" #include "components/ui_label_button.h" #include "UiConfig.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmClockModel.h" #include "ChangeSliceListener.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmConfigView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmConfigView.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmConfigView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmConfigView.h index 48c844ca4..77797f368 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmConfigView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmConfigView.h @@ -18,7 +18,7 @@ #include "font/ui_font.h" #include "common/screen.h" #include "gfx_utils/graphic_log.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmClockModel.h" namespace OHOS { class AlarmConfigView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmJudgeView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmJudgeView.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmJudgeView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmJudgeView.h index c5a7cd1ba..89c8b0d1b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmJudgeView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmJudgeView.h @@ -20,8 +20,8 @@ #include "layout/grid_layout.h" #include "font/ui_font.h" #include "common/screen.h" -#include "AlarmPresenter.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmPresenter.h" +#include "alarm/AlarmClockModel.h" namespace OHOS { class AlarmJudgeView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmMaxClock.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmMaxClock.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmMaxClock.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmMaxClock.h index f5798f421..e17c63481 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmMaxClock.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmMaxClock.h @@ -20,8 +20,8 @@ #include "layout/grid_layout.h" #include "font/ui_font.h" #include "common/screen.h" -#include "AlarmPresenter.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmPresenter.h" +#include "alarm/AlarmClockModel.h" namespace OHOS { void CancelScanHandle(void); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmNewTimeView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmNewTimeView.h similarity index 86% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmNewTimeView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmNewTimeView.h index ec6286a05..c163548ec 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmNewTimeView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmNewTimeView.h @@ -13,8 +13,8 @@ #include "components/ui_scroll_view.h" #include "components/ui_time_picker.h" #include "View.h" -#include "AlarmPresenter.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmPresenter.h" +#include "alarm/AlarmClockModel.h" namespace OHOS { class AlarmNewTimeView : public UITimePicker::SelectedListener { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmPopUpPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmPopUpPresenter.h similarity index 86% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmPopUpPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmPopUpPresenter.h index 632c010cc..073294924 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmPopUpPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmPopUpPresenter.h @@ -13,7 +13,7 @@ #include "Presenter.h" #include "ChangeSliceListener.h" #include "UiConfig.h" -#include "AlarmPopUpView.h" +#include "alarm/AlarmPopUpView.h" #include "components/ui_label.h" #include "common/screen.h" #include "components/ui_label.h" @@ -26,11 +26,11 @@ #include "components/ui_label_button.h" #include "components/ui_digital_clock.h" #include "gfx_utils/graphic_log.h" -#include "ModelListenerSample.h" -#include "AlarmCloseRingView.h" -#include "AlarmRingView.h" -#include "AlarmPopUpView.h" -#include "AlarmClockModel.h" +#include "main/ModelListenerSample.h" +#include "alarm/AlarmCloseRingView.h" +#include "alarm/AlarmRingView.h" +#include "alarm/AlarmPopUpView.h" +#include "alarm/AlarmClockModel.h" #include "wearable_log.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmPopUpView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmPopUpView.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmPopUpView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmPopUpView.h index 107c4a6e4..988dacfff 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmPopUpView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmPopUpView.h @@ -16,10 +16,10 @@ #include "components/ui_label_button.h" #include "ChangeSliceListener.h" #include "components/ui_digital_clock.h" -#include "AlarmSetTimeView.h" -#include "AlarmCloseRingView.h" -#include "AlarmRingView.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmSetTimeView.h" +#include "alarm/AlarmCloseRingView.h" +#include "alarm/AlarmRingView.h" +#include "alarm/AlarmClockModel.h" #include "UiConfig.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmPresenter.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmPresenter.h index 11ba16cae..c8d98ea2d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmPresenter.h @@ -24,7 +24,7 @@ #include "components/ui_time_picker.h" #include "components/ui_digital_clock.h" #include "gfx_utils/graphic_log.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmClockModel.h" #include "wearable_log.h" #include "color.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmRingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmRingView.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmRingView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmRingView.h index b79eb123b..f6b7ea02d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmRingView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmRingView.h @@ -17,7 +17,7 @@ #include "ChangeSliceListener.h" #include "components/ui_digital_clock.h" #include "UiConfig.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmClockModel.h" #include "ChangeSliceListener.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmSetTimeView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmSetTimeView.h similarity index 86% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmSetTimeView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmSetTimeView.h index 5c7486ba8..f781fb390 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmSetTimeView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmSetTimeView.h @@ -13,8 +13,8 @@ #include "components/ui_scroll_view.h" #include "components/ui_time_picker.h" #include "View.h" -#include "AlarmPresenter.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmPresenter.h" +#include "alarm/AlarmClockModel.h" #include "wearable_log.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmSetWeekView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmSetWeekView.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmSetWeekView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmSetWeekView.h index 3f4b8848c..6496a80d0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/AlarmSetWeekView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/AlarmSetWeekView.h @@ -17,8 +17,8 @@ #include "layout/grid_layout.h" #include "components/root_view.h" #include "components/ui_time_picker.h" -#include "AlarmPresenter.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmPresenter.h" +#include "alarm/AlarmClockModel.h" namespace OHOS { class AlarmSetWeekView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/MainAlarmView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/MainAlarmView.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/alarm/include/MainAlarmView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarm/MainAlarmView.h index 0982563a6..2969cde9c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarm/include/MainAlarmView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarm/MainAlarmView.h @@ -19,14 +19,14 @@ #include "ChangeSliceListener.h" #include "components/ui_digital_clock.h" #include "components/ui_toggle_button.h" -#include "AlarmPresenter.h" -#include "AlarmSetTimeView.h" -#include "AlarmSetWeekView.h" -#include "AlarmJudgeView.h" -#include "AlarmConfigView.h" -#include "AlarmNewTimeView.h" -#include "AlarmMaxClock.h" -#include "AlarmClockModel.h" +#include "alarm/AlarmPresenter.h" +#include "alarm/AlarmSetTimeView.h" +#include "alarm/AlarmSetWeekView.h" +#include "alarm/AlarmJudgeView.h" +#include "alarm/AlarmConfigView.h" +#include "alarm/AlarmNewTimeView.h" +#include "alarm/AlarmMaxClock.h" +#include "alarm/AlarmClockModel.h" namespace OHOS { constexpr int16_t D_CLOCK_Y = 210; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/include/AlarmClockManage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarmclockmanage/AlarmClockManage.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/include/AlarmClockManage.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarmclockmanage/AlarmClockManage.h index 869857e5e..360a78e74 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/include/AlarmClockManage.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarmclockmanage/AlarmClockManage.h @@ -13,7 +13,7 @@ #include #include "ohos_types.h" -#include "AlarmClockTimerConfig.h" +#include "alarmclocktimerconfig/AlarmClockTimerConfig.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/include/AlmmgrAlarmClockManage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarmclockmanage/AlmmgrAlarmClockManage.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/include/AlmmgrAlarmClockManage.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarmclockmanage/AlmmgrAlarmClockManage.h index 96fc7dd67..a10d45c91 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alarmclockmanage/include/AlmmgrAlarmClockManage.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alarmclockmanage/AlmmgrAlarmClockManage.h @@ -8,7 +8,7 @@ #define ALMMGR_ALARM_CLOCK_MANAGE_H #include "ohos_types.h" -#include "AlarmClockManage.h" +#include "alarmclockmanage/AlarmClockManage.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alarmclocktimerconfig/include/AlarmClockTimerConfig.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alarmclocktimerconfig/AlarmClockTimerConfig.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/alarmclocktimerconfig/include/AlarmClockTimerConfig.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alarmclocktimerconfig/AlarmClockTimerConfig.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBarCode.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBarCode.h similarity index 93% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBarCode.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBarCode.h index 12426d62e..d8dfe8fa0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBarCode.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBarCode.h @@ -12,7 +12,7 @@ #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_barcode.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayBarCode : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBind.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBind.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBind.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBind.h index bfe2153e8..80fe2172f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBind.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBind.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" #include "components/ui_qrcode.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBindAni.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBindAni.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBindAni.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBindAni.h index ea2cc5820..28b883d18 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBindAni.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBindAni.h @@ -12,7 +12,7 @@ #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_image_animator.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" #define ALIPAY_BIND_SEARCH_IMAGE_NUM 8 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBindRes.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBindRes.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBindRes.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBindRes.h index 5b7f9a6a0..5edfbb339 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayBindRes.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayBindRes.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayBindRes : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayExitBind.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayExitBind.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayExitBind.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayExitBind.h index 4b9321a60..6f28cc489 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayExitBind.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayExitBind.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayExitBind : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayHelp.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayHelp.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayHelp.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayHelp.h index 350da2143..acce7877b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayHelp.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayHelp.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" #include "components/ui_qrcode.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListAdapter.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListAdapter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListAdapter.h index c28ddc4be..4f05b9922 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListAdapter.h @@ -17,7 +17,7 @@ #include "components/abstract_adapter.h" #include "wearable_log.h" #include "UiConfig.h" -#include "AlipayListItem.h" +#include "alipay/AlipayList/AlipayListItem.h" namespace OHOS { class AlipayListAdapter : public AbstractAdapter { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListItem.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListItem.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListItem.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListItem.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListItemView.h similarity index 88% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListItemView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListItemView.h index 74262222f..43f7a273d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListItemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListItemView.h @@ -13,8 +13,8 @@ #include "components/ui_image_view.h" #include "UiConfig.h" -#include "AlipayListItem.h" -#include "AlipayListView.h" +#include "alipay/AlipayList/AlipayListItem.h" +#include "alipay/AlipayList/AlipayListView.h" namespace OHOS { class AlipayListItemView : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListView.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListView.h index ef9dd02bf..328632c93 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayList/AlipayListView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayList/AlipayListView.h @@ -16,11 +16,11 @@ #include "components/ui_scroll_view.h" #include "components/ui_list.h" #include "components/icon_adapter.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" #include "AppViewIDs.h" #include "UiConfig.h" -#include "AlipayListAdapter.h" -#include "AlipayListItem.h" +#include "alipay/AlipayList/AlipayListAdapter.h" +#include "alipay/AlipayList/AlipayListItem.h" namespace OHOS { class AlipayListAdapter; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayMainView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayMainView.h similarity index 76% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayMainView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayMainView.h index 325c47047..6e07939dd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayMainView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayMainView.h @@ -13,27 +13,27 @@ #include "components/ui_view_group.h" #include "ChangeSliceListener.h" #include "components/ui_swipe_view.h" -#include "AlipayPresenter.h" -#include "AlipayModel.h" -#include "AlipayBind.h" -#include "AlipayExitBind.h" -#include "AlipayBindRes.h" -#include "AlipayBindAni.h" -#include "AlipayListView.h" -#include "AlipayBarCode.h" -#include "AlipayPayCode.h" -#include "AlipaySetting.h" -#include "AlipayHelp.h" -#include "AlipayUnbindFinish.h" -#include "AlipayUnbind.h" +#include "alipay/AlipayPresenter.h" +#include "alipay/AlipayModel.h" +#include "alipay/AlipayBind.h" +#include "alipay/AlipayExitBind.h" +#include "alipay/AlipayBindRes.h" +#include "alipay/AlipayBindAni.h" +#include "alipay/AlipayList/AlipayListView.h" +#include "alipay/AlipayBarCode.h" +#include "alipay/AlipayPayCode.h" +#include "alipay/AlipaySetting.h" +#include "alipay/AlipayHelp.h" +#include "alipay/AlipayUnbindFinish.h" +#include "alipay/AlipayUnbind.h" -#include "AlipayGetTransList.h" -#include "AlipayTransTips.h" -#include "AlipayTransCode.h" -#include "AlipayTransEnable.h" -#include "AlipayTransRes.h" -#include "AlipayTransListView.h" -#include "AlipayTransAni.h" +#include "alipay/AlipayTrans/AlipayGetTransList.h" +#include "alipay/AlipayTrans/AlipayTransTips.h" +#include "alipay/AlipayTrans/AlipayTransCode.h" +#include "alipay/AlipayTrans/AlipayTransEnable.h" +#include "alipay/AlipayTrans/AlipayTransRes.h" +#include "alipay/AlipayTrans/AlipayTransListView.h" +#include "alipay/AlipayTrans/AlipayTransAni.h" namespace OHOS { class AlipayMainView; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayModel.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayModel.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayPayCode.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayPayCode.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayPayCode.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayPayCode.h index 6ef24cb3a..997ff5f32 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayPayCode.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayPayCode.h @@ -12,7 +12,7 @@ #include "components/ui_label_button.h" #include "components/ui_button.h" #include "components/ui_qrcode.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayPayCode : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayPresenter.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayPresenter.h index 092ee45eb..f8f96a57d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayPresenter.h @@ -12,7 +12,7 @@ #include "UiConfig.h" #include "wearable_log.h" #include "color.h" -#include "AlipayModel.h" +#include "alipay/AlipayModel.h" namespace OHOS { constexpr char *ALIPAY_LIST_PAY_BUTTON = (char *)"alipaylistpay"; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayRefreshBindCode.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayRefreshBindCode.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayRefreshBindCode.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayRefreshBindCode.h index fe03e3035..cc3d25f00 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayRefreshBindCode.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayRefreshBindCode.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" #include "components/ui_qrcode.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipaySetting.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipaySetting.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipaySetting.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipaySetting.h index deb5a2da5..356bd1014 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipaySetting.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipaySetting.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" #include "components/ui_qrcode.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayGetTransList.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayGetTransList.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayGetTransList.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayGetTransList.h index a5c671432..4eae2a652 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayGetTransList.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayGetTransList.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayGetTransList : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransAni.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransAni.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransAni.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransAni.h index fc577b8b8..8f383eddd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransAni.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransAni.h @@ -12,7 +12,7 @@ #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_image_animator.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" #define ALIPAY_TRANS_SEARCH_IMAGE_NUM 8 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransCode.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransCode.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransCode.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransCode.h index d4ba75077..d614e800a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransCode.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransCode.h @@ -12,7 +12,7 @@ #include "components/ui_label_button.h" #include "components/ui_button.h" #include "components/ui_qrcode.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayTransCode : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransEnable.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransEnable.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransEnable.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransEnable.h index e2af18b71..8461574ea 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransEnable.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransEnable.h @@ -12,7 +12,7 @@ #include "components/ui_label_button.h" #include "components/ui_button.h" #include "components/ui_qrcode.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayTransEnable : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListAdapter.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListAdapter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListAdapter.h index 233193063..9dbdb4e28 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListAdapter.h @@ -17,7 +17,7 @@ #include "components/abstract_adapter.h" #include "wearable_log.h" #include "UiConfig.h" -#include "AlipayTransListItem.h" +#include "alipay/AlipayTrans/AlipayTransListItem.h" namespace OHOS { class AlipayTransListAdapter : public AbstractAdapter { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListItem.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListItem.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListItem.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListItem.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListItemView.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListItemView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListItemView.h index 6a12a6a42..6cf9a780a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListItemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListItemView.h @@ -13,8 +13,8 @@ #include "components/ui_image_view.h" #include "UiConfig.h" -#include "AlipayTransListItem.h" -#include "AlipayTransListView.h" +#include "alipay/AlipayTrans/AlipayTransListItem.h" +#include "alipay/AlipayTrans/AlipayTransListView.h" namespace OHOS { class AlipayTransListItemView : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListView.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListView.h index 23cb4fe94..443cfa4cd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransListView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransListView.h @@ -17,11 +17,11 @@ #include "components/ui_list.h" #include "components/ui_button.h" #include "components/icon_adapter.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" #include "AppViewIDs.h" #include "UiConfig.h" -#include "AlipayTransListAdapter.h" -#include "AlipayTransListItem.h" +#include "alipay/AlipayTrans/AlipayTransListAdapter.h" +#include "alipay/AlipayTrans/AlipayTransListItem.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransRes.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransRes.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransRes.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransRes.h index 57a93a147..805df6db2 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransRes.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransRes.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayTransRes : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransTips.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransTips.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransTips.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransTips.h index 0254ab881..c1fb83438 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayTrans/AlipayTransTips.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayTrans/AlipayTransTips.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayTransTips : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayUnbind.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayUnbind.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayUnbind.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayUnbind.h index 183b8066e..27a192655 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayUnbind.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayUnbind.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" namespace OHOS { class AlipayUnbind : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayUnbindFinish.h b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayUnbindFinish.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayUnbindFinish.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayUnbindFinish.h index 9221d783f..4d2e0dfe6 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/alipay/include/AlipayUnbindFinish.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/alipay/AlipayUnbindFinish.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AlipayPresenter.h" +#include "alipay/AlipayPresenter.h" #include "components/ui_qrcode.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/include/AodModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/aod_view/AodModel.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/aod_view/include/AodModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/aod_view/AodModel.h index 69586855d..f55ad1726 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/include/AodModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/aod_view/AodModel.h @@ -7,8 +7,7 @@ #ifndef AODMODEL_H #define AODMODEL_H -#include "AodView.h" -#include "components/ui_view.h" +#include "main/MainModel.h" namespace OHOS { class AodModel { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/include/AodPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/aod_view/AodPresenter.h similarity index 82% rename from code/sdk/application/wearable/nativeapp/nativeui/aod_view/include/AodPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/aod_view/AodPresenter.h index 969fc9c1d..0216f983f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/include/AodPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/aod_view/AodPresenter.h @@ -8,10 +8,10 @@ #ifndef AODPRESENTER_H #define AODPRESENTER_H #include "Presenter.h" -#include "AodView.h" +#include "aod_view/AodView.h" #include "components/ui_view.h" -#include "KeyInputListener.h" -#include "ModelListenerSample.h" +#include "key/KeyInputListener.h" +#include "main/ModelListenerSample.h" namespace OHOS { class AodView; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/include/AodView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/aod_view/AodView.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/aod_view/include/AodView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/aod_view/AodView.h index 0bcf7afba..e012a460a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/aod_view/include/AodView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/aod_view/AodView.h @@ -8,9 +8,9 @@ #ifndef AODVIEW_H #define AODVIEW_H #include "View.h" -#include "MainModel.h" -#include "SetDialInfo.h" -#include "DialBinTypesV2.h" +#include "main/MainModel.h" +#include "set_dial/SetDialInfo.h" +#include "main/DialBinTypesV2.h" #include "components/ui_view.h" #include "components/ui_card_page.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/AppItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/AppItemView.h similarity index 79% rename from code/sdk/application/wearable/nativeapp/nativeui/applist/include/AppItemView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/applist/AppItemView.h index 077e4c12f..51eb58cfa 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/AppItemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/AppItemView.h @@ -8,10 +8,10 @@ #ifndef APP_ITEM_VIEW_H #define APP_ITEM_VIEW_H -#include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_view_group.h" #include "components/ui_image_view.h" -#include "ApplistModel.h" +#include "applist/ApplistModel.h" #include "UiConfig.h" namespace OHOS { @@ -30,8 +30,8 @@ private: AppItemView &operator = (const AppItemView &); UIImageView icon_; - UILabel label_; - AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; + UILabelExt label_; + AppItem itemInfo_; }; class HexagonsItemView : public UIImageView { @@ -44,34 +44,34 @@ public: private: HexagonsItemView(const HexagonsItemView &); HexagonsItemView &operator = (const HexagonsItemView &); - AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; + AppItem itemInfo_; }; class FootballItemView : public UIImageView { public: explicit FootballItemView() {} - ~FootballItemView() {} + ~FootballItemView(); void SetItemInfo(const AppItem &itemInfo); AppViewId GetViewId(); const char *GetAppUid(); private: FootballItemView(const FootballItemView &); FootballItemView &operator = (const FootballItemView &); - AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; + AppItem itemInfo_; }; class WaterfallItemView : public UIImageView { public: explicit WaterfallItemView() {} - ~WaterfallItemView() {} + ~WaterfallItemView(); void SetItemInfo(const AppItem &itemInfo); AppViewId GetViewId(); const char *GetAppUid(); private: WaterfallItemView(const WaterfallItemView &); WaterfallItemView &operator = (const WaterfallItemView &); - AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; + AppItem itemInfo_; }; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistAdapter.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistAdapter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistAdapter.h index 5302fbc5e..811d2b296 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistAdapter.h @@ -17,8 +17,8 @@ #include "components/abstract_adapter.h" #include "UiConfig.h" #include "wearable_log.h" -#include "AppItemView.h" -#include "ApplistModel.h" +#include "applist/AppItemView.h" +#include "applist/ApplistModel.h" namespace OHOS { class ApplistAdapter : public AbstractAdapter { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistModel.h new file mode 100644 index 000000000..1cd7bd0df --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistModel.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: ApplistModel.h + * Author: + * Create: 2021-09-18 + */ + +#ifndef APPLIST_MODEL_H +#define APPLIST_MODEL_H + +#include "bundle_info.h" +#include "AppViewIDs.h" +#include "ohos_types.h" + +#define APP_MAX_NUM 50 + +namespace OHOS { +static const int INVALID_MASK = 0x0; + +enum UIResourceTextId : uint16_t { + STR_MAX_ID = 0, +}; + +struct AppItem { + uint16_t id = VIEW_INVALID; + const char *iconSmall = nullptr; // 小图标资源路径 + const char *iconHexagon = nullptr; // 六边形图标资源路径 + const char *label = nullptr; // 应用名 + uint32_t resId = INVALID_MASK; // 小图标压缩资源对应的id + uint32_t hexagonId = INVALID_MASK; // 六边形图标压缩资源对应的id + const char *resPath = nullptr; // 小图标压缩资源路径 + const char *hexagonPath = nullptr; // 六边形图标压缩资源路径 + uint16_t labelId = STR_MAX_ID; // 多语言环境下对应的字符id + const char *uid = nullptr; + // resId、resPath和iconSmall互斥, hexagonId、hexagonPath和iconHexagon互斥, labelId和label互斥 + + AppItem() = default; + + // 使用该构造方法初始化,支持多语言注册以及多图标打包功能 + AppItem(uint16_t id, uint32_t resId, uint32_t hexagonId, const char *resPath, + const char *hexagonPath, uint16_t labelId, const char *uid) : + id(id), + resId(resId), + hexagonId(hexagonId), + resPath(resPath), + hexagonPath(hexagonPath), + labelId(labelId), + uid(uid) {} + + // 使用该构造方法初始化,不支持多语言,一个图标使用一个文件 + AppItem(uint16_t id, const char *iconSmall, const char *iconHexagon, + const char *label, const char *uid) : + id(id), + iconSmall(iconSmall), + iconHexagon(iconHexagon), + label(label), + uid(uid) {} +}; + +enum AppListStyle { + APPLIST_STYLE, + HEXAGONS_STYLE, + FOOTBALL_STYLE, + WATERFALL_STYLE +}; + +class ApplistPresenter; +class ApplistModel { +public: + static ApplistModel &GetInstance(void); + + void Init(); + const AppItem *GetApplistItems() const; + uint8 GetAppListNum() const; + void ResolvingJSAppItems(void); + void SetStartIndex(uint16_t index); + uint16_t GetStartIndex(void); + void SetHeadItemY(int index); + int GetHeadItemY(void); + void ApplistUpdate(void); + void SetPresenter(ApplistPresenter *p); + AppListStyle GetCurrentStyle(void); + void SetInitFlag(bool flag); + +private: + ApplistModel(); + ApplistModel(const ApplistModel &); + ApplistModel &operator=(const ApplistModel &); + virtual ~ApplistModel(); + ApplistPresenter *presenter{nullptr}; + + AppItem applist[APP_MAX_NUM]; + BundleInfo *bundleInfos = nullptr; + int32 bundleLen = 0; + uint8 appLen = 0; + + uint16_t startIndex = 0; + int headItemY = 0; + bool initFlag{false}; +}; +} + +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistPresenter.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistPresenter.h index 5849d2d63..1275b0a5d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistPresenter.h @@ -10,9 +10,9 @@ #include "Presenter.h" #include "ohos_types.h" -#include "AppItemView.h" -#include "ApplistView.h" -#include "ApplistModel.h" +#include "applist/AppItemView.h" +#include "applist/ApplistView.h" +#include "applist/ApplistModel.h" #include "components/root_view.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistView.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistView.h index aedb6381d..ab2ce4adb 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/applist/ApplistView.h @@ -20,7 +20,7 @@ #include "components/ui_icosahedron_view.h" #include "gfx_utils/list.h" #include "ohos_types.h" -#include "ApplistAdapter.h" +#include "applist/ApplistAdapter.h" #include "ChangeSliceListener.h" #include "drag_event.h" #include "UiConfig.h" @@ -113,6 +113,7 @@ public: void OnStart() override; void OnStop() override; + void LoadAppIconImage(UIImageView *view, const uint32_t id, const char *path); void AddAppItemToList(const AppItem &item); void ClearAppItemToList(); void RefreshAppList(void); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/blood/BloodModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/blood/BloodModel.h new file mode 100644 index 000000000..47a2cae25 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/blood/BloodModel.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingModel.h + * Author: + * Create: 2025-03-23 + */ + +#ifndef BLOOD_MODEL_H +#define BLOOD_MODEL_H + +#include +#include +#include "graphic_timer.h" + +namespace OHOS { + class BloodModel { + public: + static BloodModel &GetInstance(void); + bool GetbuttonStatus(); + void SetbuttonStatus(bool status); + std::string GetCurrentTimeString(); + void StartCurrentTimeTimer(); + void PauseCurrentTimeTimer(); + private: + virtual ~BloodModel(); + BloodModel(); + BloodModel(const BloodModel &); + void InitCurrentTimeTimer(); + void DisableCurrentTimeTimer(); + BloodModel &operator=(const BloodModel &); + bool buttonStatus = 0; + GraphicTimer *pCurrentTimeTimer_ = nullptr; + }; +} +#endif // BLOOD_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/blood/BloodPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/blood/BloodPresenter.h new file mode 100644 index 000000000..893d57789 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/blood/BloodPresenter.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingPresenter.h + * Author: + * Create: 2025-03-23 + */ + +#ifndef BLOOD_PRESENTER_H +#define BLOOD_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" + +namespace OHOS { +typedef enum { + BLOOD_START, + BLOOD_TEST, + BLOOD_MORE, + MAX_BLOOD_PAGE, +} PageId; +constexpr short SET_ZERO = 0; +constexpr short SET_ONE = 1; +constexpr short SET_TWO = 2; +constexpr short SET_THREE = 3; +constexpr short SET_FOUR = 4; +constexpr short SET_FIVE = 5; +constexpr short TEMP_SET_SIX = 6; +constexpr short SET_SEVEN = 7; +constexpr short SET_EIGHT = 8; +constexpr short SET_NINE = 9; +constexpr short SET_HUNDRED = 100; +constexpr short SET_INT_MAX = 255; +class BloodView; +class BloodModel; +class BloodPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BloodPresenter(); + ~BloodPresenter() override; + static BloodPresenter *GetInstance(); + + void OnResume() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void OnPause() override; + bool ClickFuncId(const char *buttonName); + +private: + BloodModel *findPhoneModel; +}; +} + +#endif // BLOOD_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/blood/BloodView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/blood/BloodView.h new file mode 100644 index 000000000..f28958afa --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/blood/BloodView.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingView.h + * Author: + * Create: 2025-03-23 + */ + +#ifndef BLOOD_VIEW_H +#define BLOOD_VIEW_H + +#include "View.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_image_animator.h" +#include "ChangeSliceListener.h" +#include "test_case_list_adapter.h" +#include "UiConfig.h" +#include "blood/BloodModel.h" +#include "blood/BloodPresenter.h" +#include "layout/grid_layout.h" +#include "ui_test.h" +namespace OHOS { +class BloodPresenter; + +class BloodModel; +class BloodView : public View { +public: + BloodView(); + ~BloodView() override; + + static BloodView *GetInstance(); + + void OnStart() override; + void OnStop() override; + bool ClickButtonChange(bool status); + void SetupCurrentTime(); + void SetupImageAnimator(); + void UpdateCurrentTimeLabel(const char *currentTime); + bool IsCurrentTimeLabelValid(); + void SetUpImageAnimator(); + void SetupButton(); + void InitImageInfo(); + + void InitStart(); + void InitTest(); + void InitMore(); + bool TempInitLabel(void); + bool InitSimilarLabel(int16 num, int16 labelY, const char *labelText); + void ChangeView(int16 hideView, int16 showView); + + void DropView(UIView& view, int type); + bool ClickFunc(int16 interf); + bool ChangeBloodStart(int16_t thisView); + bool ChangeBloodTest(int16_t thisView); + bool ChangeBloodMore(int16_t thisView); +private: + UIView::OnDragListener *dragListener_ = nullptr; + TestCaseListAdapter* adapter_ = nullptr; + BloodModel *findPhoneModel; + UILabel *currentTime_{nullptr}; + GridLayout* layout_ = nullptr; + + UIViewGroup* container[MAX_BLOOD_PAGE] = {nullptr}; + UIViewGroup *group = nullptr; + UIViewGroup *groupTest = nullptr; + UIScrollView *scrollGroup = nullptr; + UILabelButton* button = nullptr; + UILabelButton* buttonMore = nullptr; + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + + ImageInfo* imageInfo1_ = nullptr; + ImageInfo* imageInfo2_ = nullptr; + ImageInfo* imageInfo3_ = nullptr; + ImageAnimatorInfo imageAnimatorImageInfo_[3] = { 0 }; + UIImageAnimatorView* imageAnimator_ = nullptr; + + UILabel *tempTitle{nullptr}; + UILabel *tempLabel[SET_THREE]{nullptr}; +}; +} +#endif // BLOOD_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodBandoffView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodBandoffView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodBandoffView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodBandoffView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodOxygenModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodOxygenModel.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodOxygenModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodOxygenModel.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodOxygenPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodOxygenPresenter.h similarity index 93% rename from code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodOxygenPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodOxygenPresenter.h index e36393704..70ca55d57 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodOxygenPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodOxygenPresenter.h @@ -9,7 +9,7 @@ #define BLOOD_OXYGEN_PRESENTER_H #include "Presenter.h" -#include "ModelListenerSample.h" +#include "main/ModelListenerSample.h" #include "components/ui_circle_progress.h" #include "ohos_types.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodOxygenView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodOxygenView.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodOxygenView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodOxygenView.h index 6ea38268d..059e1d517 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bloodoxygen/include/BloodOxygenView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bloodoxygen/BloodOxygenView.h @@ -17,8 +17,8 @@ #include "components/ui_image_animator.h" #include "components/ui_circle_progress.h" #include "components/ui_view_group.h" -#include "BloodOxygenPresenter.h" -#include "BloodBandoffView.h" +#include "bloodoxygen/BloodOxygenPresenter.h" +#include "bloodoxygen/BloodBandoffView.h" namespace OHOS { class BloodOxygenView : public View { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothCaseListAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothCaseListAdapter.h similarity index 88% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothCaseListAdapter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothCaseListAdapter.h index 49a590a5b..7cdad65ab 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothCaseListAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothCaseListAdapter.h @@ -11,8 +11,8 @@ #include "components/abstract_adapter.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "PlayersPresenter.h" -#include "BluetoothItemView.h" +#include "player/PlayersPresenter.h" +#include "bluetooth/BluetoothItemView.h" namespace OHOS { class BluetoothCaseListAdapter : public AbstractAdapter { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothChangeBle.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothChangeBle.h new file mode 100644 index 000000000..fb6b0435b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothChangeBle.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2023. All rights reserved. + * Description: transmit header file + * This file should be changed only infrequently and with great care. + */ +#ifndef BLUETOOTH_CHANGE_BLE_H +#define BLUETOOTH_CHANGE_BLE_H + +#ifdef __cplusplus +extern "C" { +#endif +void ChangeBleConnectToMax(void); +void ChangeBleConnectToDefault(void); +#ifdef __cplusplus +} +#endif +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothDeviceCaseListAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothDeviceCaseListAdapter.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothDeviceCaseListAdapter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothDeviceCaseListAdapter.h index a2b0e2371..bb641b0ec 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothDeviceCaseListAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothDeviceCaseListAdapter.h @@ -11,7 +11,7 @@ #include "components/abstract_adapter.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "BluetoothItemView.h" +#include "bluetooth/BluetoothItemView.h" namespace OHOS { class BluetoothDeviceCaseListAdapter : public AbstractAdapter { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothDeviceListView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothDeviceListView.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothDeviceListView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothDeviceListView.h index 72b9b9871..29b302459 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothDeviceListView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothDeviceListView.h @@ -11,7 +11,7 @@ #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_list.h" -#include "BluetoothDeviceCaseListAdapter.h" +#include "bluetooth/BluetoothDeviceCaseListAdapter.h" namespace OHOS { class BluetoothDeviceCaseListAdapter; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothEarListView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothEarListView.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothEarListView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothEarListView.h index 8a0dd9839..298f4d90d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothEarListView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothEarListView.h @@ -12,7 +12,7 @@ #include "components/ui_label_button.h" #include "components/ui_image_animator.h" #include "components/ui_list.h" -#include "BluetoothCaseListAdapter.h" +#include "bluetooth/BluetoothCaseListAdapter.h" namespace OHOS { class BluetoothCaseListAdapter; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothEarPhoneView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothEarPhoneView.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothEarPhoneView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothEarPhoneView.h index 3636a1af1..e7f40ecd7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothEarPhoneView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothEarPhoneView.h @@ -14,7 +14,7 @@ #include "components/ui_image_animator.h" #include "ohos_timer.h" #include "graphic_timer.h" -#include "BluetoothModel.h" +#include "bluetooth/BluetoothModel.h" #define BLUETOOTH_SEARCH_IMAGE_NUM 8 namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothHeadsetEvent.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothHeadsetEvent.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothHeadsetEvent.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothHeadsetEvent.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothItemView.h similarity index 93% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothItemView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothItemView.h index 563fe825d..ed4847891 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothItemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothItemView.h @@ -14,7 +14,7 @@ #include "components/ui_label_button.h" #include "components/ui_image_animator.h" -#include "BluetoothModel.h" +#include "bluetooth/BluetoothModel.h" #include "UiConfig.h" #define BLUETOOTH_CONNECT_IMAGE_NUM 8 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothModel.h similarity index 88% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothModel.h index 3aef02c0e..632af7b7c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothModel.h @@ -16,6 +16,14 @@ #include "bts_br_gap.h" namespace OHOS { +constexpr uint16_t BLUETOOTH_CONN_HANDLE = 64; +constexpr uint16_t BLUETOOTH_INTERVAL_TOMAX_MIN = 12; +constexpr uint16_t BLUETOOTH_INTERVAL_TOMAX_MAX = 12; +constexpr uint16_t BLUETOOTH_INTERVAL_TODEFAULT_MIN = 24; +constexpr uint16_t BLUETOOTH_INTERVAL_TODEFAULT_MAX = 48; +constexpr uint16_t BLUETOOTH_LATENCY = 0; +constexpr uint16_t BLUETOOTH_TIMEOUT_MUTIPLIER = 500; + typedef enum : uint16_t { CALLERSETTING, CALLERPLAYERS, @@ -81,7 +89,9 @@ public: int ConnectRemoteDevice(const bd_addr_t *addr); bool ConnectRemoteCheck(const bd_addr_t *addr); char* getWatchName(void); - + void ChangeBleConnectToMax(); + void ChangeBleConnectToDefault(); + private: BluetoothModel(); int16_t callerid{0}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothOptionsView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothOptionsView.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothOptionsView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothOptionsView.h index 836df4bcb..0573986f5 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothOptionsView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothOptionsView.h @@ -11,7 +11,7 @@ #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_image_animator.h" -#include "BluetoothCaseListAdapter.h" +#include "bluetooth/BluetoothCaseListAdapter.h" namespace OHOS { class BluetoothOptionsView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothPresenter.h similarity index 88% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothPresenter.h index fa72f28f9..3a70f4dc3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothPresenter.h @@ -8,14 +8,14 @@ #define BLUETOOTH_PRESENTER_H #include "Presenter.h" -#include "BluetoothModel.h" -#include "MainBluetoothView.h" +#include "bluetooth/BluetoothModel.h" +#include "bluetooth/MainBluetoothView.h" #include "components/ui_view.h" #include "components/ui_image_view.h" #include "components/ui_label_button.h" #include "components/ui_view_group.h" -#include "VolumeSettingView.h" -#include "UiViewId.h" +#include "main/VolumeSettingView.h" +#include "main/UiViewId.h" namespace OHOS { enum BluetoothPresenterNum : uint8_t { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothReconnectView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothReconnectView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothReconnectView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothReconnectView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothWrapper.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothWrapper.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothWrapper.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/BluetoothWrapper.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/MainBluetoothView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/MainBluetoothView.h similarity index 81% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/MainBluetoothView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/MainBluetoothView.h index e564e2ced..3f04896cb 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/MainBluetoothView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/MainBluetoothView.h @@ -10,17 +10,17 @@ #include "View.h" #include "UiConfig.h" #include "ChangeSliceListener.h" -#include "BluetoothPresenter.h" -#include "BluetoothCaseListAdapter.h" -#include "BluetoothEarListView.h" -#include "BluetoothEarPhoneView.h" -#include "BluetoothOptionsView.h" -#include "BluetoothReconnectView.h" -#include "TipsConnFailMessageView.h" -#include "TipsSuccMessageView.h" -#include "TipsFailMessageView.h" -#include "BluetoothDeviceListView.h" -#include "BluetoothItemView.h" +#include "bluetooth/BluetoothPresenter.h" +#include "bluetooth/BluetoothCaseListAdapter.h" +#include "bluetooth/BluetoothEarListView.h" +#include "bluetooth/BluetoothEarPhoneView.h" +#include "bluetooth/BluetoothOptionsView.h" +#include "bluetooth/BluetoothReconnectView.h" +#include "bluetooth/TipsConnFailMessageView.h" +#include "bluetooth/TipsSuccMessageView.h" +#include "bluetooth/TipsFailMessageView.h" +#include "bluetooth/BluetoothDeviceListView.h" +#include "bluetooth/BluetoothItemView.h" namespace OHOS { constexpr int16_t NUM_CONTAINER = 9; // NUM_CONTAINER :蓝牙耳机连接的9个界面容器 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/TipsConnFailMessageView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/TipsConnFailMessageView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/TipsConnFailMessageView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/TipsConnFailMessageView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/TipsFailMessageView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/TipsFailMessageView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/TipsFailMessageView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/TipsFailMessageView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/TipsSuccMessageView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/TipsSuccMessageView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/bluetooth/include/TipsSuccMessageView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/bluetooth/TipsSuccMessageView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathDurPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathDurPage.h new file mode 100644 index 000000000..0376dbed5 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathDurPage.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathDurPage + * Create: 2025-5-13 + */ +#ifndef BREATH_DUR_PAGE_H +#define BREATH_DUR_PAGE_H + +#include +#include "components/ui_label.h" +#include "components/ui_picker.h" +#include "components/ui_image_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_button.h" +#include "components/ui_toggle_button.h" +#include "View.h" +#include "UiConfig.h" +#include "SlicePage.h" +#include "SlicePageFactory.h" +#include "breath/BreathModel.h" +#include "breath/BreathPresenter.h" + +namespace OHOS { + +class BreathDurPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathDurPage(); + ~BreathDurPage() override; + void OnStart(void* data) override; + void OnStop() override; + void OnResume() override; + void OnPause() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; +private: + UILabel *lableTitle = nullptr; + UIPicker *pickerTime = nullptr; + UIButton *buttonOk = nullptr; + UIViewGroup *group = nullptr; + UIImageView *center = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathExerPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathExerPage.h new file mode 100644 index 000000000..3f3513bfa --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathExerPage.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathExerPage + * Create: 2025-5-13 + */ +#ifndef BREATH_EXER_PAGE_H +#define BREATH_EXER_PAGE_H + +#include "layout/grid_layout.h" +#include "components/ui_label.h" +#include "components/ui_digital_clock.h" +#include "components/ui_image_animator.h" +#include "View.h" +#include "SlicePage.h" +#include "graphic_timer.h" +#include "SlicePageFactory.h" +#include "power_display_service.h" +#include "breath/BreathModel.h" +#include "breath/BreathPresenter.h" + +#define ALIPAY_BIND_SEARCH_IMAGE_NUM 80 +#define SPEED_IDX_3 3 + +namespace OHOS { +class BreathExerPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathExerPage(); + ~BreathExerPage() override; + void OnStart(void* data) override; + void OnStop() override; + void OnPause() override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void OnTimer(); + void SetUpImageAnimator(); + void InitImageInfo(); + +private: + UIViewGroup *group = nullptr; + UIImageAnimatorView* imageAnimator_ = nullptr; + ImageInfo* imageInfoOen = nullptr; + ImageInfo* imageInfoTwo = nullptr; + ImageInfo* imageInfoThree = nullptr; + uint32_t palyNumber; + ImageAnimatorInfo imageAnimatorImageInfo[SPEED_IDX_3] = { 0 }; + ImageAnimatorInfo searchImageInfo[ALIPAY_BIND_SEARCH_IMAGE_NUM]; + + class BreathExerPageCallback : public AnimatorCallback { + public: + BreathExerPageCallback(BreathExerPage* page) : BreathExerPage(page) {} + virtual ~BreathExerPageCallback() override {} + void Callback(UIView* view) override; + private: + BreathExerPage* BreathExerPage{nullptr}; + }; + BreathExerPageCallback* animatorCallBack{nullptr}; + Animator *animation = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathMainPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathMainPage.h new file mode 100644 index 000000000..bd06de488 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathMainPage.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathMainPage + * Create: 2025-5-13 + */ +#ifndef BREATH_MAIN_PAGE_H +#define BREATH_MAIN_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_digital_clock.h" +#include "components/ui_image_animator.h" +#include "View.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "breath/BreathView.h" +#include "breath/BreathModel.h" +#include "breath/BreathPresenter.h" + +namespace OHOS { + +class BreathMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathMainPage() = default; + ~BreathMainPage() override; + void OnStart(void* data) override; + void OnStop() override; + void OnResume() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + +private: + UILabel *lableBreathing = nullptr; + UIButton *buttonTime = nullptr; + UIButton *buttonSetting = nullptr; + UIButton *buttonStart = nullptr; + UILabel *lableSetting = nullptr; + UILabel *lableTime = nullptr; + UIViewGroup *group = nullptr; + UIImageView *background = nullptr; + UIImageView *center = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathModel.h new file mode 100644 index 000000000..701040381 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathModel.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathModel + * Create: 2025-5-13 + */ +#ifndef BREATH_MODEL_H +#define BREATH_MODEL_H + +#include "gfx_utils/graphic_math.h" +namespace OHOS { +#define SPEED_IDX_3 3 +class BreathModel { +public: + static BreathModel &GetInstance(); + virtual ~BreathModel(); + const char **GetDurListData(); + const char **GetRhyListData(); + uint8_t GetDurListSize(); + uint8_t GetRhyListSize(); + char *GetTimeDuration(); + void SetTimeDuration(uint16_t idx); + void SetTimeRhyation(uint16_t idx); + uint8_t GetSelectTime(); + uint8_t GetSelectTempo(); + char *GetDuration(); + char *GetRhythm(); + void SetSaveTime(int32_t idx); + int32_t GetSaveTime(); + uint32_t GetTimeBreathing(); + uint32_t GetStatusRespiratory(); + void SetBeginsTime(int32_t idx); + int32_t GetBeginsTime(); + void SetFrequencyScore(); + uint8_t GetFrequencyScore(); + void SetHeartRate(); + uint8_t GetHeartRate(); + uint32_t GetTheNumberOfPlays(); + +protected: + void DefaultData(); + +private: + BreathModel(); + BreathModel(const BreathModel &); + BreathModel &operator=(const BreathModel &); + const char *durList[SPEED_IDX_3]; + const char *rhyList[SPEED_IDX_3]; + uint32_t durListVal[SPEED_IDX_3]; + uint32_t rhyListVal[SPEED_IDX_3]; + uint16_t data; + uint16_t date; + int32_t saveTime; + int32_t beginsTime; +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathPresenter.h new file mode 100644 index 000000000..1b1f6c091 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathPresenter.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathPresenter + * Create: 2025-5-23 + */ + +#ifndef Breath_PRESENTER_H +#define Breath_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +constexpr int16_t SET_INT_MAX_ = 255; + +class BreathView; +class BreathPresenter : public Presenter {}; +} + +#endif // Breath_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathResultPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathResultPage.h new file mode 100644 index 000000000..0f2b1a471 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathResultPage.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathResult + * Create: 2025-5-13 + */ +#ifndef BREATH_RESULT_PAGE_H +#define BREATH_RESULT_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_picker.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_button.h" +#include "components/ui_toggle_button.h" +#include "View.h" +#include "UiConfig.h" +#include "SlicePage.h" +#include "SlicePageFactory.h" +#include "breath/BreathModel.h" +#include "breath/BreathPresenter.h" + +namespace OHOS { + +class BreathResultPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathResultPage(); + ~BreathResultPage() override; + void OnStart(void* data) override; + void OnStop() override; + void OnResume() override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + +private: + UILabel *trainingResults = nullptr; + UILabel *trainingFrequencies = nullptr; + UILabel *trainingHeartRate = nullptr; + UILabel *trainingDuration = nullptr; + UILabel *heartRateScout = nullptr; + UILabel *frequenciesScout = nullptr; + UIImageView *scores = nullptr; + UILabel *descriptionBreathing = nullptr; + UILabel *time = nullptr; + UILabel *timeUnit = nullptr; + UILabel *frequencyTimes = nullptr; + UILabel *heartRateTimes = nullptr; + UIViewGroup *group = nullptr; + uint8_t frequencyScore; + uint8_t heartRate; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathRhyPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathRhyPage.h new file mode 100644 index 000000000..2c9780d5d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathRhyPage.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathRhyPage + * Create: 2025-5-13 + */ +#ifndef BREATH_RHY_PAGE_H +#define BREATH_RHY_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_picker.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" +#include "View.h" +#include "SlicePage.h" +#include "SlicePageFactory.h" +#include "breath/BreathModel.h" +#include "breath/BreathPresenter.h" + +namespace OHOS { + +class BreathRhyPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UIPicker::SelectedListener { +public: + BreathRhyPage(); + ~BreathRhyPage() override; + void OnStart(void* data) override; + void OnResume() override; + void OnPause() override; + void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + +private: + UILabel *lableRhythm = nullptr; + UIPicker *pickerRhythm = nullptr; + UIButton *buttonOk = nullptr; + UIViewGroup *group = nullptr; + UIImageView *center = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathStartPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathStartPage.h new file mode 100644 index 000000000..86b1a9f4b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathStartPage.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathStartPage + * Create: 2025-5-13 + */ +#ifndef BREATH_START_PAGE_H +#define BREATH_START_PAGE_H + +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "View.h" +#include "SlicePage.h" +#include "graphic_timer.h" +#include "SlicePageFactory.h" +#include "breath/BreathModel.h" +#include "breath/BreathPresenter.h" + +namespace OHOS { + +class BreathStartPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + BreathStartPage(); + ~BreathStartPage() override; + void OnStart(void* data) override; + void OnStop() override; + void OnTimer(); + bool OnDrag(UIView &view, const DragEvent &event) override; + void OnPause() override; +private: + UILabel *titleLable = nullptr; + UILabel *guideLable = nullptr; + UIImageView *centerImge = nullptr; + UIViewGroup *group = nullptr; + UIImageView *background = nullptr; + + class BreathStartCallback : public AnimatorCallback { + public: + BreathStartCallback(BreathStartPage* page) : BreathStartPage(page) {} + virtual ~BreathStartCallback() override {} + void Callback(UIView* view) override; + private: + BreathStartPage* BreathStartPage{nullptr}; + }; + BreathStartCallback* animatorCallBack{nullptr}; + Animator *animation = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathView.h new file mode 100644 index 000000000..0cfa80156 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/breath/BreathView.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: BreathView + * Create: 2025-5-14 + */ + +#ifndef BREATH_VIEW_H +#define BREATH_VIEW_H + +#include "View.h" +namespace OHOS { +enum BrearhView { + BREATH_MAIN_VIEW = 1, + BREATH_DUR_VIEW = 2, + BREATH_EXER_VIEW = 3, + BREATH_RHY_VIEW = 4, + BREATH_START_VIEW = 5, + BREATH_RESULT_VIEW = 6, +}; + +class BreathPresenter; +class BreathView : public View {}; +} +#endif // BREATH_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerItemView.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerItemView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerItemView.h index 50f2c345d..907f47d78 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerItemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerItemView.h @@ -13,9 +13,9 @@ #include "components/ui_image_view.h" #include "components/ui_label_button.h" -#include "CallerLogModel.h" +#include "callerlog/CallerLogModel.h" #include "UiConfig.h" -#include "PhoneService.h" +#include "phoneservice/PhoneService.h" namespace OHOS { class CallerItemView : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerLogModel.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerLogModel.h index 22e6b403a..d4d51a414 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerLogModel.h @@ -8,7 +8,7 @@ #define CALLER_LOG_MODEL_H #include "string" -#include "PhoneService.h" +#include "phoneservice/PhoneService.h" #include "AppViewIDs.h" #include "message.h" #include "msg_center.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerLogPresenter.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerLogPresenter.h index d5cde172c..e90602125 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerLogPresenter.h @@ -10,7 +10,7 @@ #include "Presenter.h" #include "ohos_types.h" -#include "CallerLogModel.h" +#include "callerlog/CallerLogModel.h" #include "graphic_timer.h" #include "sys/time.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerLogView.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerLogView.h index 0fbe3a4ce..a9594f02c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/callerlog/include/CallerLogView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/callerlog/CallerLogView.h @@ -9,8 +9,8 @@ #define CALLER_LOG_VIEW_H #include "View.h" -#include "CallerLogPresenter.h" -#include "CallerItemView.h" +#include "callerlog/CallerLogPresenter.h" +#include "callerlog/CallerItemView.h" #include "components/ui_view_group.h" #include "components/ui_image_animator.h" #include "components/ui_scroll_view.h" @@ -18,7 +18,7 @@ #include "components/ui_label_button.h" #include "components/ui_list.h" #include "components/abstract_adapter.h" -#include "PhoneService.h" +#include "phoneservice/PhoneService.h" #include "vector.h" #include "ChangeSliceListener.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraMainPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraMainPage.h new file mode 100644 index 000000000..01aa7b8de --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraMainPage.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: CameraMainPage + * Created: 2025-06-05 + */ + +#ifndef CAMERA_MAIN_PAGE_H +#define CAMERA_MAIN_PAGE_H + +#include +#include "View.h" +#include "components/root_view.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_image_animator.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "layout/grid_layout.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "diag_service.h" +#include "ohos_timer.h" +#include "components/ui_chart.h" +#include "camera/CameraModel.h" +#include "camera/CameraPresenter.h" + +namespace OHOS { + +class CameraPresenter; + +class CameraModel; +class CameraMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + CameraMainPage(); + ~CameraMainPage() override; + + static CameraMainPage *GetInstance(); + + void OnStart(void* data) override; + uint8_t GetConnectStatus(); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void OnPause() override; + + bool GetFirstFlag(); + void SetFirstFlag(bool value); + void SetUpButton(); + void InitCameraTimer(); + void InitCameraView(); + void DisableCameraTimer(); + void SetCameraTime(int time); + void StopAnimator(); + void PhotoTaken(); + void Refresh_page(); +private: + UILabel *title = nullptr; + UILabel *cameraFind = nullptr; + UILabel *cameraTitle = nullptr; + UILabel *cameraTime = nullptr; + UIButton *button = nullptr; + bool isFirst; + UIScrollView* container_ = nullptr; + UIImageView *bluetoothDisconnected = nullptr; + +class CameraAnimatorCallback : public AnimatorCallback { +public: + explicit CameraAnimatorCallback(CameraMainPage* page) : page_(page) {} + ~CameraAnimatorCallback() override {} + void Callback(UIView *view) override; + +private: + CameraMainPage* page_{nullptr}; +}; + Animator *animator_ = nullptr; + CameraAnimatorCallback *callBack_ = nullptr; +}; +} +#endif // CAMERA_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraModel.h new file mode 100644 index 000000000..61a9c5ed5 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraModel.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: CameraModel + * Created: 2025-06-05 + */ + +#ifndef CAMERA_MODEL_H +#define CAMERA_MODEL_H + +#include +#include +#include "graphic_timer.h" + +namespace OHOS { +class CameraModel { +public: + static CameraModel &GetInstance(void); +private: + CameraModel(); + CameraModel(const CameraModel &); + CameraModel &operator=(const CameraModel &); + virtual ~CameraModel(); + bool buttonStatus = 0; +}; +} + +#endif // CAMERA_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraPresenter.h new file mode 100644 index 000000000..dced5767c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraPresenter.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: CameraPresenter + * Created: 2025-06-05 + */ + +#ifndef CAMERA_PRESENTER_H +#define CAMERA_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" + +namespace OHOS { + +class CameraView; +class CameraPresenter : public Presenter { +}; +} + +#endif // CAMERA_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraView.h new file mode 100644 index 000000000..d939d9d5e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/camera/CameraView.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: CameraView + * Created: 2025-06-05 + */ + +#ifndef CAMERA_VIEW_H +#define CAMERA_VIEW_H + +#include "View.h" +namespace OHOS { +enum CAMERA_PAGES { + CAMERA_MAIN_PAGE = 1, // 0 is invalid +}; + +class CameraPresenter; +class CameraView : public View { +}; +} +#endif // CAMERA_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/AmbientClockView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/clock/AmbientClockView.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/clock/include/AmbientClockView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/clock/AmbientClockView.h index 2d02ca41e..bb20b9c1c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/AmbientClockView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/clock/AmbientClockView.h @@ -21,8 +21,8 @@ #include "font/ui_font_bitmap.h" #include "font/ui_font.h" #include "graphic_config.h" -#include "HealthModel.h" -#include "ActivityModel.h" +#include "main/HealthModel.h" +#include "activity/ActivityModel.h" #include "UiConfig.h" #include "components/ui_card_page.h" #include "animator/animator_manager.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/clock/MainClockView.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/clock/MainClockView.h index 4e4fb8894..c643693d5 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/clock/MainClockView.h @@ -21,8 +21,8 @@ #include "font/ui_font_bitmap.h" #include "font/ui_font.h" #include "graphic_config.h" -#include "HealthModel.h" -#include "ActivityModel.h" +#include "main/HealthModel.h" +#include "activity/ActivityModel.h" #include "UiConfig.h" #include "components/ui_card_page.h" #include "animator/animator_manager.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/compass/CompassControlView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/CompassControlView.h new file mode 100644 index 000000000..e2242e1c8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/CompassControlView.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: CompassControlView.h + * Author: + * Create: 2022-04-02 + */ + +#ifndef COMPASS_CONTROL_VIEW_H +#define COMPASS_CONTROL_VIEW_H + +#include "components/ui_card_page.h" +#include "compass/CompassFragment.h" + +namespace OHOS { + +class CompassControlView : public UICardPage { +public: + CompassControlView(); + void PreLoad(void) override; + void UnLoad(void) override; + void OnPause(void) override; + void OnActive(void) override; + void ScrollBegin(bool isActive) override; + void ScrollEnd(bool isActive) override; +private: + CompassFragment *compassFragment_{nullptr}; +}; +} +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/compass/CompassFragment.h b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/CompassFragment.h new file mode 100644 index 000000000..64c6ee054 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/CompassFragment.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CompassView.h + * Author: + * Create: 2021-12-21 + */ + +#ifndef COMPASS_VIEW_H +#define COMPASS_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_fragment.h" +#include "common/task.h" + +namespace OHOS { +class CompassFragment : public UIFragment, public Task { +public: + void OnCreateView(void* data) override; + void OnResumeView() override; + void OnPauseView() override; + void OnDestroyView() override; + void Callback() override; + +private: + bool InitCompassImage(void); + bool LoadCompassImage(UIImageView *view, uint32_t resId); + UILabel *directionLabel_{nullptr}; + UILabel *angleLabel_{nullptr}; + UIImageView *bgImg_{nullptr}; + UIImageView *fgImg_{nullptr}; + UIImageView *trianImg_{nullptr}; + bool initialized_{false}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/compass/CompassModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/CompassModel.h new file mode 100644 index 000000000..880617419 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/CompassModel.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: CompassModel.h + * Author: + * Create: 2022-04-02 + */ + +#ifndef COMPASS_MODEL_H +#define COMPASS_MODEL_H + +#include + +namespace OHOS { +class CompassModel { +public: + static CompassModel *GetInstance(void); + bool OpenCompassSensor(void); + bool CloseCompassSensor(void); + void UpdateAngle(void); + void ResetAngle(void); + int16_t GetAngle(void); + +private: + int16_t angle_{0}; + bool clockwise_{true}; +}; +} + +#endif + diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/compass/MainCompassPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/MainCompassPresenter.h new file mode 100644 index 000000000..2588f0a43 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/MainCompassPresenter.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainCompassPresenter.h + * Author: + * Create: 2021-12-21 + */ +#ifndef COMPASS_MAINPRESENTER_H +#define COMPASS_MAINPRESENTER_H + +#include "Presenter.h" +#include "compass/MainCompassView.h" +#include "compass/CompassModel.h" + +namespace OHOS { +class MainCompassView; +class MainCompassPresenter : public Presenter, public UIView::OnDragListener { +public: + bool OnDrag(UIView& view, const DragEvent& event) override; + + void OnResume() override; + + void OnPause() override; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/compass/MainCompassView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/MainCompassView.h new file mode 100644 index 000000000..4694861fd --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/compass/MainCompassView.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainCompassView + * Author: + * Create: 2021-12-23 + */ + +#ifndef MAIN_COMPASS_VIEW_H +#define MAIN_COMPASS_VIEW_H + +#include "View.h" +#include "compass/CompassFragment.h" + +namespace OHOS { +class MainCompassPresenter; +class MainCompassView : public View { +public: + MainCompassView() : compassFragment_(nullptr) {} + void OnStart() override; + void OnStop() override; + +private: + friend class MainCompassPresenter; + CompassFragment *compassFragment_; +}; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectOpenView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectOpenView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectOpenView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectOpenView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectPhonePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectPhonePresenter.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectPhonePresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectPhonePresenter.h index 2bb8fe69c..d55eab049 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectPhonePresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectPhonePresenter.h @@ -8,7 +8,7 @@ #define CONNECT_PHONE_PRESENTER_H #include "Presenter.h" -#include "ConnectOpenView.h" +#include "connectnewphone/ConnectOpenView.h" #include "NativeLauncher.h" #include "NativeAbility.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectPhoneView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectPhoneView.h similarity index 85% rename from code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectPhoneView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectPhoneView.h index d74226c55..1a248987a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectPhoneView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectPhoneView.h @@ -8,9 +8,9 @@ #define CONNECT_PHONE_VIEW_H #include "View.h" -#include "ConnectPhonePresenter.h" -#include "ConnectSelectView.h" -#include "AppGroupView.h" +#include "connectnewphone/ConnectPhonePresenter.h" +#include "connectnewphone/ConnectSelectView.h" +#include "main/AppGroupView.h" namespace OHOS { constexpr int16_t NUM_CONNECT_PHONE_CONTAINER = 2; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectSelectView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectSelectView.h similarity index 86% rename from code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectSelectView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectSelectView.h index 48d9695b5..f73d4faf5 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/connectnewphone/include/ConnectSelectView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/connectnewphone/ConnectSelectView.h @@ -8,7 +8,7 @@ #define CONNECT_SELECT_VIEW_H #include "View.h" -#include "ConnectPhonePresenter.h" +#include "connectnewphone/ConnectPhonePresenter.h" #include "components/ui_label.h" #include "components/ui_button.h" #include "components/ui_view_group.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateAdapter.h new file mode 100644 index 000000000..676b8007d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateAdapter.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateAdapter + * Create: 2025-03-23 + */ + +#ifndef DATE_ADAPTER_H +#define DATE_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 "wearable_log.h" +#include "UiConfig.h" +#include "date/DateModel.h" +#include "date/DateItemView.h" + +namespace OHOS { +class DateAdapter : public AbstractAdapter { +public: + explicit DateAdapter(); + ~DateAdapter() override; + void SetData(std::list &data); + uint16_t GetCount(void) override; + UIView *GetView(UIView *inView, int16_t index) override; + void AddListItem(const DateItem &item); + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } + void ClearListItem(); + +private: + std::list listData; + UIView::OnClickListener *itemClickListener{nullptr}; +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateButtonAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateButtonAdapter.h new file mode 100644 index 000000000..da4c0136a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateButtonAdapter.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateButtonAdapter + * Create: 2025-03-23 + */ + +#ifndef DATE_BUTTON_ADAPTER_H +#define DATE_BUTTON_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 "wearable_log.h" +#include "UiConfig.h" +#include "date/DateModel.h" +#include "date/DateButtonItemView.h" + +namespace OHOS { +class DateButtonAdapter : public AbstractAdapter { +public: + explicit DateButtonAdapter(); + ~DateButtonAdapter() override; + + void SetData(std::list &data); + uint16_t GetCount(void) override; + UIView *GetView(UIView *inView, int16_t index) override; + void AddListItem(const DateButtonItem &item); + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } + void ClearListItem(); + +private: + std::list listData; + UIView::OnClickListener *itemClickListener{nullptr}; +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateButtonItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateButtonItemView.h new file mode 100644 index 000000000..c03c4b284 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateButtonItemView.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateButtonItemView + * Create: 2025-03-23 + */ + +#ifndef DATE_BUTTON_ITEM_VIEW_H +#define DATE_BUTTON_ITEM_VIEW_H + +#include "date/DateModel.h" +#include "UiConfig.h" +#include "components/ui_canvas.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" +#include "main/LoadImg.h" + +namespace OHOS { +class DateButtonItemView : public UIViewGroup { +public: + explicit DateButtonItemView(); + ~DateButtonItemView() override; + virtual void SetItemInfo(const DateButtonItem itemInfo); + virtual void SetUpChild(); + DateButtonItem GetItem(); + +private: + static bool flag; + UILabelButton sLabelButton; + DateButtonItem sItemInfo = {nullptr, 0, false, false}; +}; +} + +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateItemView.h new file mode 100644 index 000000000..9f7d97676 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateItemView.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateItemView + * Create: 2025-03-23 + */ + +#ifndef DATE_ITEM_VIEW_H +#define DATE_ITEM_VIEW_H + +#include "date/DateModel.h" +#include "UiConfig.h" +#include "components/ui_canvas.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_view_group.h" + +namespace OHOS { +class DateItemView : public UIViewGroup { +public: + explicit DateItemView(); + ~DateItemView() override; + virtual void SetItemInfo(const DateItem itemInfo); + virtual void SetUpChild(); + const char *GetViewId(); + bool GetVisiable(); + +private: + UILabel sLabel_1; + UIImageView sIcon; + UILabel sLabel_2; + UIImageView sNextImage; + UIImageView Schedule; + UIImageView Signs; + UIImageView BackGround; + DateItem sItemInfo = {nullptr, nullptr, nullptr, false}; +}; +} + +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateMainPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateMainPage.h new file mode 100644 index 000000000..9bb45843e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateMainPage.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateMainPage + * Create: 2025-03-23 + */ + +#ifndef DATE_MAIN_PAGE_H +#define DATE_MAIN_PAGE_H + +#include +#include +#include +#include +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "date/DateAdapter.h" +#include "date/DateButtonAdapter.h" +#include "date/DatePresenter.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "date/DateView.h" +#include "components/ui_button.h" + +namespace OHOS { +#define LABEL_COUNT 4 +static constexpr int16_t START_YEAR = 1900; + +class DatePresenter; +class DateMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + DateMainPage(); + ~DateMainPage() override; + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void InitDownList(); + void UpdateMsg(std::string dateMsg); + void SetDownListAdapter(); + bool InitDateTop(); + std::string GetFutureDate(int days_ahead); + void RefreshButtonListDate(int value); +private: + UIScrollView *uiScrollView = nullptr; + DateAdapter *listAdapter{nullptr}; + UIList *downContentList{nullptr}; + UIImageView *image1{nullptr}; + DateButtonAdapter *buttonAdapter{nullptr}; + UIList *buttonContentList{nullptr}; + UILabel *title{nullptr}; + std::list listTop; + std::string strDate[SET_SEVEN]; + std::string strDay[SET_SEVEN]; +}; +} +#endif // SETTING_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateMessagePage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateMessagePage.h new file mode 100644 index 000000000..8a5e59ca6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateMessagePage.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateMessagePage + * Create: 2025-03-15 + */ + +#ifndef DATE_MESSAGE_H +#define DATE_MESSAGE_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_swipe_view.h" +#include "ui_swipe_view.h" +#include "date/DatePresenter.h" +#include "date/DateModel.h" +#include "date/DateView.h" +#include "SlicePage.h" +#include "UiConfig.h" + +namespace OHOS { +#define LABEL_COUNT 8 +class DatePresenter; +class DateMessagePage : public SlicePage, + public UIView::OnDragListener { +public: + DateMessagePage(); + ~DateMessagePage() override; + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + +private: + UIViewGroup *group; + UIImageView *image1; + UILabel *labelTitle{nullptr}; + UILabel *labelMessage{nullptr}; + UILabel *labelTime{nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateModel.h new file mode 100644 index 000000000..b86e3e2e6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateModel.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateModel + * Create: 2025-03-23 + */ + +#ifndef DATE_MODEL_H +#define DATE_MODEL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hal_tick.h" +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "cJSON.h" + +namespace OHOS { +static constexpr int16 HOUR_COUNT = 24; +static constexpr uint64_t CENTI_SECOND_UNIT = 100; +static constexpr uint64_t MS_ONE_SECONDS = 1000; +static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t NUM_TIME_MIN = 60; +static constexpr uint16_t NUM_TIME_HOUR = 3600; +static constexpr int32_t NUM_TIME_DAY = 86400; +static constexpr int16_t MIN_TO_HOUR = 60; +static constexpr int16_t HOURLY_SYSTEM = 24; +typedef struct { + std::string hour; + std::string eventTitle; + std::string startTime; + std::string week; +} DateMsg; + +typedef struct { + const char *label_1; + const char *label_2; + const char *index; + bool visiable; +} DateItem; + +typedef struct { + const char *button_viewId; + const char *button_day; + int index; + bool isFirst; + bool isSelect; +} DateButtonItem; + +static const uint16_t DATE_ITEM_COUNT = 10; +class DateModel { +public: + static DateModel &GetInstance(void); + virtual ~DateModel(); + bool InitDateVec(std::string dateStr); + bool InitDate(); + + const char *GetViewId(); + std::unordered_map> keyValues; + std::list listDate; + std::string now; + std::string titleName; + std::string messageIndex; + std::string strIndex; + +private: + DateModel(); + DateModel(const DateModel &); + DateModel &operator=(const DateModel &); +}; +} + +#endif // DATE_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/date/DatePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DatePresenter.h new file mode 100644 index 000000000..813c5ba44 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DatePresenter.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DatePresenter + * Create: 2025-03-23 + */ + +#ifndef DATE_PRESENTER_H +#define DATE_PRESENTER_H + +#include "date/DateModel.h" +#include "Presenter.h" +#include "components/ui_view.h" +namespace OHOS { +constexpr int16 BACKGROUND_IMAGE_WIDTH = 190; +constexpr int16 SET_ZERO = 0; +constexpr int16 SET_ONE = 1; +constexpr int16 SET_TWO = 2; +constexpr int16 SET_THREE = 3; +constexpr int16 SET_FOUR = 4; +constexpr int16 SET_FIVE = 5; +constexpr int16 SET_SIX = 6; +constexpr int16 SET_SEVEN = 7; +constexpr int16 SET_EIGHT = 8; +constexpr int16 SET_NINE = 9; +constexpr int16 SET_TEN = 10; +constexpr int16 SET_TWELVE = 12; +constexpr int16 SET_THIRTEEN = 13; +constexpr int16 SET_FOURTEEN = 14; +constexpr int16 SET_HUNDRED = 100; +constexpr int16 SET_TWO_HUNDRED = 200; + +class DateView; +class DatePresenter : public Presenter {}; +} + +#endif // DATE_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateView.h new file mode 100644 index 000000000..8271b29e0 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/date/DateView.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: DateView + * Create: 2025-03-23 + */ + +#ifndef DATE_VIEW_H +#define DATE_VIEW_H + +#include "View.h" +namespace OHOS { +enum DATE_PAGES { + DATE_MAIN_PAGE = 1, // 0 is invalid + DATE_MESSAGE_PAGE = 2, +}; + +class DatePresenter; +class DateView : public View {}; +} +#endif // Date_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/emptypage/EmptyPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/emptypage/EmptyPage.h new file mode 100644 index 000000000..0b497c751 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/emptypage/EmptyPage.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: EmptyPage + * Create: 2025-04-24 + */ +#ifndef EMPTY_PAGE_H +#define EMPTY_PAGE_H +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "SlicePage.h" +#include "emptypage/EmptyPresenter.h" + +namespace OHOS { + +class EmptyPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + EmptyPage(){}; + ~EmptyPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + EmptyPage(const EmptyPage &) = delete; + EmptyPage &operator=(const EmptyPage &) = delete; + EmptyPage(EmptyPage &&) = delete; + EmptyPage &operator=(EmptyPage &&) = delete; + + UIScrollView *container_ = nullptr; + UILabel *memLabel_ = nullptr; + uint32_t used_ = 0; + uint32_t free_ = 0; +}; + +#ifdef __cplusplus +extern "C" { +#endif +#if !defined(_WIN32) +uint32_t test_get_mem_info(uint8_t memType, uint32_t *used, uint32_t *free); +#endif +#ifdef __cplusplus +} +#endif +} // namespace OHOS +#endif /* EMPTY_PAGE_H */ diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/emptypage/EmptyPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/emptypage/EmptyPresenter.h new file mode 100644 index 000000000..ca245c8d2 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/emptypage/EmptyPresenter.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: EmptyPresenter + * Create: 2025-04-24 + */ + +#ifndef EMPTY_PRESENTER_H +#define EMPTY_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class EmptyView; +class EmptyPresenter : public Presenter {}; +} + +#endif // EMPTY_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/emptypage/EmptyView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/emptypage/EmptyView.h new file mode 100644 index 000000000..b17ea9e70 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/emptypage/EmptyView.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: EmptyView + * Create: 2025-04-24 + */ + +#ifndef EMPTY_VIEW_H +#define EMPTY_VIEW_H +#include "View.h" +namespace OHOS { +class EmptyPresenter; +class EmptyView : public View {}; +} +#endif // EMPTY_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhoneMainPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhoneMainPage.h new file mode 100644 index 000000000..39e3b9222 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhoneMainPage.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FindPhoneMainPage + * Create: 2025-03-23 + */ + +#ifndef FINDPHONE_MAIN_PAGE_H +#define FINDPHONE_MAIN_PAGE_H + +#include +#include "View.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_list.h" +#include "components/ui_image_animator.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "layout/grid_layout.h" +#include "SlicePageFactory.h" +#include "SlicePage.h" +#include "diag_service.h" +#include "ohos_timer.h" +#include "findphone/FindPhoneModel.h" +#include "findphone/FindPhonePresenter.h" + +#define ALIPAY_BIND_SEARCH_IMAGE_NUM 28 +namespace OHOS { +static int timeCount = 0; +static constexpr uint64_t MS_ONE_SECONDS = 1000; +class FindPhonePresenter; +class FindPhoneModel; +class FindPhoneMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + FindPhoneMainPage(); + ~FindPhoneMainPage() override; + static FindPhoneMainPage *GetInstance(); + void OnStart(void* data) override; + void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool ClickButtonChange(); + void SetUpImageAnimator(); + void SetupButton(); + void InitImageInfo(); + void ShowReset(); + void DisableFindPhoneTimer(); + void InitFindPhoneTimer(); + bool StopFindPhone(); + uint8_t GetConnectStatus(); + void ChangeToDisConnect(); +private: + UIViewGroup* container_ = nullptr; + UILabel* labelUnder = nullptr; + UILabel* labelFindTitle = nullptr; + UIButton* buttonFind = nullptr; + UIButton* buttonRty = nullptr; + UILabel *labelRing = nullptr; + UIImageView *mainImage = nullptr; + ImageInfo* imageInfo1_ = nullptr; + ImageInfo* imageInfo2_ = nullptr; + ImageInfo* imageInfo3_ = nullptr; + ImageAnimatorInfo imageAnimatorImageInfo_[SET_THREE] = { 0 }; + UIImageAnimatorView* imageAnimator_ = nullptr; + GraphicTimer *g_startCount = nullptr; + ImageAnimatorInfo searchImageInfo[ALIPAY_BIND_SEARCH_IMAGE_NUM]; +}; +} +#endif // FINDPHONE_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhoneModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhoneModel.h new file mode 100644 index 000000000..494c171be --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhoneModel.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FindPhoneModel + * Create: 2025-03-23 + */ + +#ifndef FINDPHONE_MODEL_H +#define FINDPHONE_MODEL_H + +#include +#include +#include +#include "graphic_timer.h" + +namespace OHOS { +constexpr int16_t SET_ZERO = 0; +constexpr int16_t SET_ONE = 1; +constexpr int16_t SET_TWO = 2; +constexpr int16_t SET_THREE = 3; +constexpr int16_t SET_FOUR = 4; +constexpr int16_t SET_FIVE = 5; +constexpr int16_t SET_SIX = 6; +constexpr int16_t SET_SEVEN = 7; +constexpr int16_t SET_EIGHT = 8; +constexpr int16_t SET_NINE = 9; +constexpr int16_t SET_TEN = 10; +constexpr int16_t SET_INT_MAX = 255; + +class FindPhoneModel { +public: + static FindPhoneModel &GetInstance(void); + +private: + FindPhoneModel(); + FindPhoneModel(const FindPhoneModel &); + FindPhoneModel &operator=(const FindPhoneModel &); + virtual ~FindPhoneModel(); + bool buttonStatus = 0; +}; +} + +#endif // FINDPHONE_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhonePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhonePresenter.h new file mode 100644 index 000000000..6c74c4669 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhonePresenter.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FindPhonePresenter + * Create: 2025-03-23 + */ + +#ifndef FINDPHONE_PRESENTER_H +#define FINDPHONE_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" + +namespace OHOS { +class FindPhoneView; +class FindPhonePresenter : public Presenter {}; +} + +#endif // FINDPHONE_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhoneView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhoneView.h new file mode 100644 index 000000000..6cb7de185 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/findphone/FindPhoneView.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FindPhoneView + * Create: 2025-03-23 + */ + +#ifndef FINDPHONE_VIEW_H +#define FINDPHONE_VIEW_H + +#include "View.h" +namespace OHOS { +enum FIND_PHONE_PAGES { + FIND_PHONE_MAIN_PAGE = 1, // 0 is invalid + FIND_PHONE_MESSAGE_PAGE = 2, +}; + +class FindPhonePresenter; +class FindPhoneView : public View {}; +} +#endif // FINDPHONE_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightBlinkPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightBlinkPage.h new file mode 100644 index 000000000..46f4ef937 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightBlinkPage.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightBlinkPage + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_BLINK_PAGE_H +#define FLASHLIGHT_BLINK_PAGE_H +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "flashlight/FlashLightPresenter.h" +#include "components/ui_picker.h" + +namespace OHOS { +class FlashLightBlinkPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + FlashLightBlinkPage(){}; + ~FlashLightBlinkPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + FlashLightBlinkPage(const FlashLightBlinkPage &) = delete; + FlashLightBlinkPage &operator=(const FlashLightBlinkPage &) = delete; + FlashLightBlinkPage(FlashLightBlinkPage &&) = delete; + FlashLightBlinkPage &operator=(FlashLightBlinkPage &&) = delete; + + UIScrollView *container_ = nullptr; + UILabel *blinkLabel_ = nullptr; + UIPicker* blinkPicker_ = nullptr; + UILabelButtonExt* blinkButton_ = nullptr; +}; +} // namespace OHOS +#endif /* FLASHLIGHT_BLINK_PAGE_H */ diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightColorPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightColorPage.h new file mode 100644 index 000000000..acbe25c21 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightColorPage.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightColorPage + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_COLOR_PAGE_H +#define FLASHLIGHT_COLOR_PAGE_H +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "flashlight/FlashLightPresenter.h" + +namespace OHOS { +class FlashLightColorPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + FlashLightColorPage(){}; + ~FlashLightColorPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + FlashLightColorPage(const FlashLightColorPage &) = delete; + FlashLightColorPage &operator=(const FlashLightColorPage &) = delete; + FlashLightColorPage(FlashLightColorPage &&) = delete; + FlashLightColorPage &operator=(FlashLightColorPage &&) = delete; + + UIScrollView *container_ = nullptr; + UILabel *colorLabel_ = nullptr; + UILabelButtonExt *color1Button_ = nullptr; + UILabelButtonExt *color2Button_ = nullptr; + UILabelButtonExt *color3Button_ = nullptr; + UILabelButtonExt *color4Button_ = nullptr; + UILabelButtonExt *color5Button_ = nullptr; + UILabelButtonExt *color6Button_ = nullptr; + UILabelButtonExt *color7Button_ = nullptr; + UILabelButtonExt *color8Button_ = nullptr; + UILabelButtonExt *color9Button_ = nullptr; +}; +} // namespace OHOS +#endif /* FLASHLIGHT_COLOR_PAGE_H */ diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightDefaultPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightDefaultPage.h new file mode 100644 index 000000000..0314434b6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightDefaultPage.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightDefaultPage + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_DEFAULT_PAGE_H +#define FLASHLIGHT_DEFAULT_PAGE_H +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "flashlight/FlashLightPresenter.h" + +namespace OHOS { +class FlashLightDefaultPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + FlashLightDefaultPage(){}; + ~FlashLightDefaultPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + FlashLightDefaultPage(const FlashLightDefaultPage &) = delete; + FlashLightDefaultPage &operator=(const FlashLightDefaultPage &) = delete; + FlashLightDefaultPage(FlashLightDefaultPage &&) = delete; + FlashLightDefaultPage &operator=(FlashLightDefaultPage &&) = delete; + + UIScrollView *container_ = nullptr; + UILabel *recoverLabel_ = nullptr; + UILabelButtonExt *cancelButton_ = nullptr; + UILabelButtonExt *confirmButton_ = nullptr; +}; +} // namespace OHOS +#endif /* FLASHLIGHT_DEFAULT_PAGE_H */ diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightModel.h new file mode 100644 index 000000000..adf42ce13 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightModel.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightModel + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_MODEL_H +#define FLASHLIGHT_MODEL_H + +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashlightUiResourceImage.h" +#ifndef _WIN32 +#include "time64.h" +#endif +namespace OHOS { +enum FlashLightBlinkFrequency { SLOW_BLINK = 0, FAST_BLINK, NOT_BLINK }; + +enum FlashLightColorAttribute { + BLACK_COLOR = 0, + WHITE_COLOR = 1, + RED_COLOR = 2, + ORANGE_COLOR = 3, + YELLOW_COLOR = 4, + GREEN_COLOR = 5, + LIGHT_BLUE_COLOR = 6, + DARK_BLUE_COLOR = 7, + PURPLE_COLOR = 8, + MULTI_COLOR = 9, +}; + +class FlashLightModel { +public: + static FlashLightModel &GetInstance(void); + // 设置手电筒颜色; + FlashLightColorAttribute GetViewColor(); + void SetViewColor(FlashLightColorAttribute color); + // 设置手电筒闪烁频率; + FlashLightBlinkFrequency GetBlinkFrequency(); + void SetBlinkFrequency(FlashLightBlinkFrequency blinkFrequency); + // 恢复默认参数; + void SetDefault(); + // 获取当前时间; + uint32_t GetSysCurrentTime(std::string ¤tTime); + +private: + FlashLightModel(FlashLightColorAttribute color = FlashLightColorAttribute::WHITE_COLOR, + FlashLightBlinkFrequency blinkFrequency = FlashLightBlinkFrequency::NOT_BLINK); + FlashLightModel(const FlashLightModel &); + FlashLightModel &operator=(const FlashLightModel &); + virtual ~FlashLightModel(); + +private: +#ifdef _WIN32 + struct timeval sysTime_ { + 0 + }; +#else + struct timeval64 sysTime_ { + 0 + }; +#endif + FlashLightColorAttribute color_; + FlashLightBlinkFrequency blinkFrequency_; +}; +} + +#endif // FLASHLIGHT_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightPage.h new file mode 100644 index 000000000..629a2e871 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightPage.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightPage + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_PAGE_H +#define FLASHLIGHT_PAGE_H + +#include +#include "View.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_view.h" +#include "components/ui_image_view.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "SlicePage.h" +#include "flashlight/FlashLightPresenter.h" +#include "animator.h" + +namespace OHOS { +class FlashLightPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + FlashLightPage(){}; + ~FlashLightPage(); + + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + class TimeAnimatorCallback : public AnimatorCallback { + public: + TimeAnimatorCallback() {} + virtual ~TimeAnimatorCallback() override {} + void Callback(UIView* view) override; + }; + TimeAnimatorCallback* timeCallback_ = nullptr; + Animator* timeAnimator_ = nullptr; + UILabelButton* flashLightOn_ = nullptr; + UILabel* systemTime_ = nullptr; + UILabel* OnLabel_ = nullptr; + UIImageView* imageArrow_ = nullptr; + UIScrollView *container_ = nullptr; +}; +} +#endif // FLASHLIGHT_PAGE_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightPlayPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightPlayPage.h new file mode 100644 index 000000000..b7fc36541 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightPlayPage.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightPlayPage + * Create: 2025-04-24 + */ +#ifndef FLASHLIGHT_PLAY_PAGE_H +#define FLASHLIGHT_PLAY_PAGE_H +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include "SlicePage.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashLightModel.h" + +namespace OHOS { +class FlashLightPlayPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + FlashLightPlayPage(){}; + ~FlashLightPlayPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + FlashLightPlayPage(const FlashLightPlayPage &) = delete; + FlashLightPlayPage &operator=(const FlashLightPlayPage &) = delete; + FlashLightPlayPage(FlashLightPlayPage &&) = delete; + FlashLightPlayPage &operator=(FlashLightPlayPage &&) = delete; + + UIScrollView *container_ = nullptr; + UIImageAnimatorView *playImageAnimal = nullptr; + ImageAnimatorInfo playImageInfo[2]; +}; +} // namespace OHOS +#endif /* FLASHLIGHT_PLAY_PAGE_H */ diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightPresenter.h new file mode 100644 index 000000000..3f356de27 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightPresenter.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightPresenter + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_PRESENTER_H +#define FLASHLIGHT_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { + +class FlashLightView; +class FlashLightPresenter : public Presenter {}; +} + +#endif // FLASHLIGHT_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightSetItemAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightSetItemAdapter.h new file mode 100644 index 000000000..9aeb158ed --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightSetItemAdapter.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightSetItemAdapter + * Create: 2025-11-23 + */ + +#ifndef FLASHLIGHTSET_ITEM_ADAPTER_H +#define FLASHLIGHTSET_ITEM_ADAPTER_H + +#include "flashlight/FlashLightSetItemAdapter.h" +#include "flashlight/FlashLightSetItemView.h" +#include "components/abstract_adapter.h" +#include "gfx_utils/vector.h" + +namespace OHOS { + +class FlashLightSetItemAdapter : public AbstractAdapter { +public: + explicit FlashLightSetItemAdapter(); + ~FlashLightSetItemAdapter() override; + + /* * + * @brief Sets the UIView adapter data, which is a SettingItem linked list. + * + * @param data Indicates the SettingItem linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(const Graphic::Vector &data); + + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + uint16_t GetCount(void) override; + + UIView *GetView(UIView *inView, int16_t index) override; + + void AddListItem(const FlashLightSetItem &item); + + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } +private: + Graphic::Vector itemDatas_; + UIView::OnClickListener *itemClickListener{nullptr}; +}; +} + +#endif // FLASHLIGHTSET_ITEM_ADAPTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightSetItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightSetItemView.h new file mode 100644 index 000000000..1704f88ab --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightSetItemView.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightSetItemView + * Create: 2025-05-18 + */ + +#ifndef FLASHLIGHTSET_ITEM_VIEW_H +#define FLASHLIGHTSET_ITEM_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t item; + uint32_t resId; + std::string label; + std::string itemLabel; + std::string viewId; +} FlashLightSetItem; + +class FlashLightSetItemView : public UIViewGroup { +public: + FlashLightSetItemView(); + ~FlashLightSetItemView() override; + virtual void SetItemInfo(const FlashLightSetItem itemInfo); + const char *GetViewId() const; + +private: + UIImageView sIcon; + UILabel sLabel; + UILabel itemLabel; + UIImageView sNextImage; + FlashLightSetItem sItemInfo = {0, 0, "", "", ""}; +}; +} +#endif // FLASHLIGHTSET_ITEM_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightSetPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightSetPage.h new file mode 100644 index 000000000..d1f1b068b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightSetPage.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightSetPage + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_SET_PAGE_H +#define FLASHLIGHT_SET_PAGE_H +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_scroll_view.h" +#include "components/ui_list.h" +#include "SlicePage.h" +#include "flashlight/FlashLightPresenter.h" +#include "flashlight/FlashLightSetItemAdapter.h" +#include "flashlight/FlashLightSetItemView.h" +#include "UiConfig.h" +#include "main/LoadImg.h" +#include "flashlight/FlashlightUiResourceImage.h" + +namespace OHOS { +class FlashLightSetPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + FlashLightSetPage(){}; + ~FlashLightSetPage(); + void OnStart(void* data) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + FlashLightSetPage(const FlashLightSetPage &) = delete; + FlashLightSetPage &operator=(const FlashLightSetPage &) = delete; + FlashLightSetPage(FlashLightSetPage &&) = delete; + FlashLightSetPage &operator=(FlashLightSetPage &&) = delete; + + UIScrollView *container_ = nullptr; + UILabel *setLabel_ = nullptr; + UILabelButtonExt *recoverButton_ = nullptr; + + UIList* setItemList_ = nullptr; + FlashLightSetItemAdapter *setItemAdapter_ = nullptr; + FlashLightSetItem colorItem_ = {1, IMAGE_CONVERTER_TOOL_COLORITEM, "灯光颜色"}; + FlashLightSetItem blinkItem_ = {2, IMAGE_CONVERTER_TOOL_BLINKITEM, "闪烁频率"}; +}; +} // namespace OHOS +#endif /* FLASHLIGHT_SET_PAGE_H */ diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightView.h new file mode 100644 index 000000000..463a94e1c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashLightView.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashLightView + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_VIEW_H +#define FLASHLIGHT_VIEW_H +#include "View.h" +namespace OHOS { + +enum FlashLightAllView { + FLASH_LIGTH_VIEW = 1, // 手电筒主界面 + FLASH_LIGHT_PLAY_VIEW, // 手电筒显示播放 + FLASH_LIGHT_SET_VIEW, // 手电筒设置 + FLASH_LIGHT_COLOR_VIEW, // 手电筒颜色 + FLASH_LIGHT_BLINK_VIEW, // 手电筒闪烁 + FLASH_LIGHT_DEFAULT_VIEW, // 手电筒默认 + FLASH_LIGHT_ALL_VIEW, +}; + +class FlashLightPresenter; +class FlashLightView : public View {}; +} +#endif // FLASHLIGHT_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashlightUiResourceImage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashlightUiResourceImage.h new file mode 100644 index 000000000..50238d30b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/flashlight/FlashlightUiResourceImage.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: FlashlightUiResourceImage + * Create: 2025-04-24 + */ + +#ifndef FLASHLIGHT_UI_RESOURCE_IMAGE_H +#define FLASHLIGHT_UI_RESOURCE_IMAGE_H +#include +namespace OHOS { +static const int IMAGE_CONVERTER_TOOL_BLINKBUTTON = 0x100001; +static const int IMAGE_CONVERTER_TOOL_BLINKITEM = 0x100002; +static const int IMAGE_CONVERTER_TOOL_COLOR1BUTTON = 0x100003; +static const int IMAGE_CONVERTER_TOOL_COLOR1PRESSBUTTON = 0x100004; +static const int IMAGE_CONVERTER_TOOL_COLOR2BUTTON = 0x100005; +static const int IMAGE_CONVERTER_TOOL_COLOR2PRESSBUTTON = 0x100006; +static const int IMAGE_CONVERTER_TOOL_COLOR3BUTTON = 0x100007; +static const int IMAGE_CONVERTER_TOOL_COLOR3PRESSBUTTON = 0x100008; +static const int IMAGE_CONVERTER_TOOL_COLOR4BUTTON = 0x100009; +static const int IMAGE_CONVERTER_TOOL_COLOR4PRESSBUTTON = 0x10000a; +static const int IMAGE_CONVERTER_TOOL_COLOR5BUTTON = 0x10000b; +static const int IMAGE_CONVERTER_TOOL_COLOR5PRESSBUTTON = 0x10000c; +static const int IMAGE_CONVERTER_TOOL_COLOR6BUTTON = 0x10000d; +static const int IMAGE_CONVERTER_TOOL_COLOR6PRESSBUTTON = 0x10000e; +static const int IMAGE_CONVERTER_TOOL_COLOR7BUTTON = 0x10000f; +static const int IMAGE_CONVERTER_TOOL_COLOR7PRESSBUTTON = 0x100010; +static const int IMAGE_CONVERTER_TOOL_COLOR8BUTTON = 0x100011; +static const int IMAGE_CONVERTER_TOOL_COLOR8PRESSBUTTON = 0x100012; +static const int IMAGE_CONVERTER_TOOL_COLOR9BUTTON = 0x100013; +static const int IMAGE_CONVERTER_TOOL_COLOR9PRESSBUTTON = 0x100014; +static const int IMAGE_CONVERTER_TOOL_COLORITEM = 0x100015; +static const int IMAGE_CONVERTER_TOOL_DOWNARROW = 0x100016; +static const int IMAGE_CONVERTER_TOOL_FLASHLIGHTON = 0x100017; +static const int IMAGE_CONVERTER_TOOL_PLAY1PAGE = 0x100018; +static const int IMAGE_CONVERTER_TOOL_PLAY2PAGE = 0x100019; +static const int IMAGE_CONVERTER_TOOL_PLAY3PAGE = 0x10001a; +static const int IMAGE_CONVERTER_TOOL_PLAY4PAGE = 0x10001b; +static const int IMAGE_CONVERTER_TOOL_PLAY5PAGE = 0x10001c; +static const int IMAGE_CONVERTER_TOOL_PLAY6PAGE = 0x10001d; +static const int IMAGE_CONVERTER_TOOL_PLAY7PAGE = 0x10001e; +static const int IMAGE_CONVERTER_TOOL_PLAY8PAGE = 0x10001f; +static const int IMAGE_CONVERTER_TOOL_PLAY9PAGE = 0x100020; +static const int IMAGE_CONVERTER_TOOL_PLAYBLACKPAGE = 0x100021; +static const int IMAGE_CONVERTER_TOOL_RECOVERBUTTON = 0x100022; +static const int IMAGE_CONVERTER_TOOL_RECOVERCANCLE = 0x100023; +static const int IMAGE_CONVERTER_TOOL_RECOVERCONFIRM = 0x100024; +static const int IMAGE_CONVERTER_TOOL_RIGHTARROW = 0x100025; +} // OHOS +#endif // FLASHLIGHT_UI_RESOURCE_IMAGE_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/heartrate/include/HeartModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/heartrate/HeartModel.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/heartrate/include/HeartModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/heartrate/HeartModel.h index 3891ec79a..20336ca0b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/heartrate/include/HeartModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/heartrate/HeartModel.h @@ -5,7 +5,7 @@ #include "broadcast_feature.h" #include "broadcast_service.h" #include "samgr_lite.h" -#include "MainClockView.h" +#include "clock/MainClockView.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/heartrate/include/HeartRateView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/heartrate/HeartRateView.h similarity index 95% rename from code/sdk/application/wearable/nativeapp/nativeui/heartrate/include/HeartRateView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/heartrate/HeartRateView.h index 1d94d89e5..152b81259 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/heartrate/include/HeartRateView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/heartrate/HeartRateView.h @@ -14,7 +14,7 @@ #include "wearable_log.h" #include "ohos_types.h" #include "components/ui_card_page.h" -#include "HeartModel.h" +#include "heartrate/HeartModel.h" namespace OHOS { #define HEART_AVE_NUM 360 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/CustomizationView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/CustomizationView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/CustomizationView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/CustomizationView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkEndView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkEndView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkEndView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkEndView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkModel.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkModel.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkMotionView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkMotionView.h similarity index 82% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkMotionView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkMotionView.h index 40e0e4502..6619e7093 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkMotionView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkMotionView.h @@ -8,11 +8,11 @@ #define INDOORWALK_MOTION_VIEW_H #include "View.h" -#include "MotionPageFirst.h" -#include "MotionPageSecond.h" -#include "MotionPageThird.h" -#include "MotionPageFourth.h" -#include "MotionPageFifth.h" +#include "indoorwalk/MotionPageFirst.h" +#include "indoorwalk/MotionPageSecond.h" +#include "indoorwalk/MotionPageThird.h" +#include "indoorwalk/MotionPageFourth.h" +#include "indoorwalk/MotionPageFifth.h" #include "components/ui_swipe_view.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkPreparedView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkPreparedView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkPreparedView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkPreparedView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkPresenter.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkPresenter.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkView.h similarity index 82% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkView.h index c89592aa1..c39891ce8 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/IndoorWalkView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/IndoorWalkView.h @@ -7,12 +7,12 @@ #ifndef INDOORWALK_VIEW_H #define INDOORWALK_VIEW_H -#include "IndoorWalkEndView.h" +#include "indoorwalk/IndoorWalkEndView.h" #include "View.h" -#include "IndoorWalkPresenter.h" -#include "IndoorWalkPreparedView.h" -#include "CustomizationView.h" -#include "IndoorWalkMotionView.h" +#include "indoorwalk/IndoorWalkPresenter.h" +#include "indoorwalk/IndoorWalkPreparedView.h" +#include "indoorwalk/CustomizationView.h" +#include "indoorwalk/IndoorWalkMotionView.h" #include "components/ui_view_group.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageFifth.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageFifth.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageFifth.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageFifth.h index 6acdbbd5c..5d1b8fba7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageFifth.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageFifth.h @@ -12,7 +12,7 @@ #include "ohos_types.h" #include "components/ui_label.h" #include "components/ui_image_view.h" -#include "AppGroupView.h" +#include "main/AppGroupView.h" namespace OHOS { class MotionPageFifth : public AppGroupView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageFirst.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageFirst.h similarity index 95% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageFirst.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageFirst.h index 109325e4a..fb4f42456 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageFirst.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageFirst.h @@ -12,7 +12,7 @@ #include "ohos_types.h" #include "components/ui_label.h" #include "components/ui_image_view.h" -#include "AppGroupView.h" +#include "main/AppGroupView.h" namespace OHOS { class MotionPageFirst : public AppGroupView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageFourth.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageFourth.h similarity index 93% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageFourth.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageFourth.h index eeb81c939..b3237f0ab 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageFourth.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageFourth.h @@ -12,7 +12,7 @@ #include "ohos_types.h" #include "components/ui_label.h" #include "components/ui_image_view.h" -#include "AppGroupView.h" +#include "main/AppGroupView.h" namespace OHOS { class MotionPageFourth : public AppGroupView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageSecond.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageSecond.h similarity index 95% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageSecond.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageSecond.h index 13665cc55..fc44d1825 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageSecond.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageSecond.h @@ -12,7 +12,7 @@ #include "ohos_types.h" #include "components/ui_label.h" #include "components/ui_image_view.h" -#include "AppGroupView.h" +#include "main/AppGroupView.h" namespace OHOS { class MotionPageSecond : public AppGroupView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageThird.h b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageThird.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageThird.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageThird.h index 8dc7072f5..0416dcb3a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/include/MotionPageThird.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/indoorwalk/MotionPageThird.h @@ -12,7 +12,7 @@ #include "ohos_types.h" #include "components/ui_label.h" #include "components/ui_image_view.h" -#include "AppGroupView.h" +#include "main/AppGroupView.h" namespace OHOS { class MotionPageThird : public AppGroupView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/key/include/KeyInputListener.h b/code/sdk/application/wearable/nativeapp/nativeui/include/key/KeyInputListener.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/key/include/KeyInputListener.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/key/KeyInputListener.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/AppGroupView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/AppGroupView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/AppGroupView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/AppGroupView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParser.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinParser.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParser.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinParser.h index 362c93050..ac020abe9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParser.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinParser.h @@ -14,15 +14,15 @@ */ #ifndef GRAPHIC_LITE_DIAL_BIN_PARSER_H #define GRAPHIC_LITE_DIAL_BIN_PARSER_H -#include "DialBinParserManager.h" -#include "DialBinTypesV2.h" +#include "main/DialBinParserManager.h" +#include "main/DialBinTypesV2.h" #include "components/ui_abstract_progress.h" namespace OHOS { class DialBinParser : public DialBinParserInterface { public: bool UpdateDial(const std::string& file, FILE* fp, DialViewGroup* group, DisplayState state) override; - bool GetDialPreviewInfo(FILE* fp, DialPreviewInfo* info) override; + bool GetDialPreviewInfo(const std::string& file, FILE* fp, DialPreviewInfo* info) override; DialBinParser(); ~DialBinParser() override; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParserManager.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinParserManager.h similarity index 81% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParserManager.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinParserManager.h index 50a9e4a6f..ae969a32d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParserManager.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinParserManager.h @@ -10,14 +10,15 @@ #include #include #include "graphic_types.h" -#include "DialViewGroup.h" -#include "DialBinTypes.h" +#include "main/dial/DialViewGroup.h" +#include "main/DialBinTypes.h" namespace OHOS { class DialBinParserInterface { public: virtual bool UpdateDial(const std::string& file, FILE* fp, DialViewGroup* group, DisplayState state) = 0; - virtual bool GetDialPreviewInfo(FILE* fp, DialPreviewInfo* info) = 0; + virtual bool GetDialPreviewInfo(const std::string& file, FILE* fp, DialPreviewInfo* info) = 0; + virtual void SetEncryptData(uint8_t *data, uint32_t len) {} virtual ~DialBinParserInterface() {} }; // class DialBinParserInterface @@ -25,7 +26,7 @@ class DialBinParserManager { public: static DialBinParserManager *GetInstance(void); bool UpdateDial(const std::string &file, FILE *fp, DialViewGroup *group, DisplayState state); - bool GetDialPreviewInfo(FILE *fp, DialPreviewInfo *info); + bool GetDialPreviewInfo(const std::string& file, FILE *fp, DialPreviewInfo *info, bool isNeedVerify = false); bool RegisterParser(const std::string &version, DialBinParserInterface *parser); uint8_t GetSupportVersionCnt() const @@ -46,6 +47,7 @@ private: DialBinParserManager(); virtual ~DialBinParserManager(); DialBinParserInterface *GetParser(FILE* fp) const; + DialBinParserInterface *GetParser(const std::string &fileName, FILE *fp, bool isNeedVerify = false) const; static constexpr uint8_t PARSER_MAX_NUM = 8; struct Pair { std::string version; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParserV3.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinParserV3.h similarity index 82% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParserV3.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinParserV3.h index 99d530e89..7e7427a83 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinParserV3.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinParserV3.h @@ -7,12 +7,12 @@ #ifndef GRAPHIC_LITE_DIAL_BIN_PARSER_V3_H #define GRAPHIC_LITE_DIAL_BIN_PARSER_V3_H -#include "DialBinParserManager.h" -#include "DialModelTime.h" +#include "main/DialBinParserManager.h" +#include "main/dial/DialModelTime.h" #include "components/ui_abstract_progress.h" -#include "DialViewContainer.h" -#include "DialDataType.h" -#include "DialOHSliceId.h" +#include "main/dial/DialViewContainer.h" +#include "main/dial/DialDataType.h" +#include "main/dial/DialOHSliceId.h" namespace OHOS { class DialBinParserV3 : public DialBinParserInterface { @@ -20,7 +20,8 @@ public: DialBinParserV3(); ~DialBinParserV3() override; bool UpdateDial(const std::string& file, FILE* fp, DialViewGroup* group, DisplayState state) override; - bool GetDialPreviewInfo(FILE* fp, DialPreviewInfo* info) override; + bool GetDialPreviewInfo(const std::string& file, FILE* fp, DialPreviewInfo* info) override; + void SetEncryptData(uint8_t *data, uint32_t len) override final; protected: bool ParseDialHeader(FILE* file); @@ -58,12 +59,16 @@ private: bool ParseViewType(uint8_t *viewType, uint8_t dialViewCount, FILE *file); bool ParseContainerSubviews(DialViewContainer *container, uint8_t num); bool ParseOptionsSubviews(ContainerInterface &parent); + DialHeader *GetHeader(FILE *fp); + uint8_t *GetVeiwType(FILE *fp, DialHeader *dialHeader); DialViewGroup* dialGroup_ = nullptr; std::string file_; const uint32_t dirId_ = 0xfef << 20; // 20: offset uint32_t imageOffset_ = 0; DisplayState state_ = DisplayState::NORMAL; + uint8_t *encryptedData_ = nullptr; + uint32_t encrpytedLen_ = 0; }; // class DialBinParserV3 } // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinTypes.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinTypes.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinTypes.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinTypes.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinTypesV2.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinTypesV2.h similarity index 99% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinTypesV2.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinTypesV2.h index 837a0a685..d49b354c7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/DialBinTypesV2.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/DialBinTypesV2.h @@ -7,7 +7,7 @@ #ifndef GRAPHIC_LITE_DIAL_BIN_TYPE_V2_H #define GRAPHIC_LITE_DIAL_BIN_TYPE_V2_H -#include "DialBinTypes.h" +#include "main/DialBinTypes.h" namespace OHOS { enum class DisplayState { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/HealthModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/HealthModel.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/HealthModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/HealthModel.h index 9b087ae7e..9b6015779 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/HealthModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/HealthModel.h @@ -18,7 +18,7 @@ #include #include "gfx_utils/list.h" -#include "UiServersMsg.h" +#include "main/UiServersMsg.h" namespace OHOS { #define NUM_1 1 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/main/LoadImg.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/LoadImg.h new file mode 100644 index 000000000..b92e242a7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/LoadImg.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: LoadImg + * Create: 2025-06-05 + */ +#ifndef LOAD_IMG_H +#define LOAD_IMG_H + +#include +#include "wearable_log.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "common/image_cache_manager.h" + +namespace OHOS { +namespace LOADIMG { +// 加载图片资源 +void LoadBtnImage(UIButton *btn, std::string file, uint32_t resId1, uint32_t resId2); + +void LoadImageViewImg(UIImageView *view, std::string file, uint32_t resId); +} +} +#endif // LOAD_IMG_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/include/main/MainModel.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/MainModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/MainModel.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MainPresenterSample.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/MainPresenterSample.h index aa2f4658e..444436189 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MainPresenterSample.h @@ -9,17 +9,17 @@ #define MAIN_PRESENTER_SAMPLE_H #include "Presenter.h" -#include "ModelListenerSample.h" +#include "main/ModelListenerSample.h" #include "components/root_view.h" #include "drag_event.h" -#include "MainViewSample.h" -#include "MainModel.h" +#include "main/MainViewSample.h" +#include "main/MainModel.h" #include "components/ui_swipe_view.h" #include "components/ui_view.h" -#include "MainCompassView.h" -#include "MainCompassPresenter.h" -#include "PlayersView.h" -#include "HeartRateView.h" +#include "compass/MainCompassView.h" +#include "compass/MainCompassPresenter.h" +#include "player/PlayersView.h" +#include "heartrate/HeartRateView.h" #include "swipe_effect/zoom_effect.h" namespace OHOS { @@ -45,7 +45,7 @@ enum class MainPresenterState { class MainViewSample; class MainPresenterSample : public Presenter, public ModelListenerSample, public UIView::OnClickListener, public UISwipeView::OnSwipeListener, - public UIView::OnLongPressListener, public UISwipeView, public CompassPresenter { + public UIView::OnLongPressListener, public UISwipeView { public: MainPresenterSample(); ~MainPresenterSample() override; @@ -75,7 +75,6 @@ public: private: void ProcessDataNotify(void); void SetCircleProgress(void); - void SetCompassRotate(void); uint8_t state_ = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; int64_t playerCurrentTime_{0}; int64_t playerMusicDuration_{0}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MainViewSample.h similarity index 86% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/MainViewSample.h index 05a667c14..b1be728de 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MainViewSample.h @@ -15,20 +15,20 @@ #include "ChangeSliceListener.h" #include "font/ui_font.h" #include "graphic_config.h" -#include "ModelListenerSample.h" -#include "ScreenModels.h" -#include "ActivityWeekView.h" -#include "CompassControlView.h" -#include "DialViewGroup.h" -#include "MainClockView.h" -#include "PlayersView.h" -#include "MainPresenterSample.h" -#include "HeartRateView.h" +#include "main/ModelListenerSample.h" +#include "screensetting/ScreenModels.h" +#include "activity/ActivityWeekView.h" +#include "compass/CompassControlView.h" +#include "main/dial/DialViewGroup.h" +#include "clock/MainClockView.h" +#include "player/PlayersView.h" +#include "main/MainPresenterSample.h" +#include "heartrate/HeartRateView.h" #include "components/ui_card_page.h" -#include "PullUpDownView.h" +#include "main/PullUpDownView.h" #include "components/ui_cross_view.h" -#include "SetCardModel.h" -#include "VideoCard.h" +#include "set_card/SetCardModel.h" +#include "videocard/VideoCard.h" namespace OHOS { class MainPresenterSample; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageAdapter.h new file mode 100644 index 000000000..a3e52fe35 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageAdapter.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MessageAdapter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef MESSAGE_ADAPTER_H +#define MESSAGE_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 "wearable_log.h" +#include "UiConfig.h" +#include "main/MainModel.h" +#include "main/MessageItemView.h" + +namespace OHOS { +class MessageAdapter : public AbstractAdapter { +public: + explicit MessageAdapter(); + ~MessageAdapter() override; + + /* * + * @brief Sets the UIView adapter data, which is a WeatherItem linked list. + * + * @param data Indicates the MessageItem linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(std::list &data); + + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + uint16_t GetCount(void) override; + + UIView *GetView(UIView *inView, int16_t index) override; + + void AddListItem(const MessageItem &item); + + void ClearListItem(); + + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } +private: + std::list listData; + UIView::OnClickListener *itemClickListener{nullptr}; +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageItemView.h new file mode 100644 index 000000000..73ec20a55 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageItemView.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: weather/WeatherItemView.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef MESSAGE_ITEM_VIEW_H +#define MESSAGE_ITEM_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_canvas.h" + +#include "UiConfig.h" +#include "main/MessageModel.h" + +namespace OHOS { +class MessageItemView : public UIViewGroup { +public: + explicit MessageItemView(); + ~MessageItemView() override; + virtual void SetItemInfo(const MessageItem itemInfo); + virtual void SetUpChild(); +private: + UILabel sLabel_1; + UIImageView sIcon; + UILabel sLabel_2; + UILabel sLabel_3; + UIImageView sNextImage; + UILabel sback; + MessageItem sItemInfo = { nullptr, nullptr, nullptr, nullptr}; +}; +} + +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageMainView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageMainView.h new file mode 100644 index 000000000..79b049adf --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageMainView.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: WeekStep + * Author: + * Create: 2021-09-11 + */ + +#ifndef MESSAGE_MAIN_VIEW_H +#define MESSAGE_MAIN_VIEW_H + +#include "graphic_types.h" +#include "wearable_log.h" +#include "components/ui_card_page.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "main/MessageModel.h" +#include "main/MessageAdapter.h" + +namespace OHOS { +class MessageMainView : public UICardPage { +public: + MessageMainView(); + ~MessageMainView() override; + static MessageMainView *GetInstance(void); + bool InitView(); + void PreLoad(void) override; + void VerticalViewInits(void); + void ConfirmDeletion(void); + void CancelDeletion(void); + void ShowMessageList(void); + void DeletionView(void); + void NoNotify(void); + void NewNotify(void); + void RefreshMessageList(std::vector item); + bool InitScrollData(); + MessageAdapter *listAdapter{nullptr}; + UIList *contentList{nullptr}; // 列表 +private: + UILabel *messageLables{nullptr}; // 无消息 + UILabel *messageLable{nullptr}; // 通知 + UILabel *deletereminder{nullptr}; // 是否删除通知? + UILabelButton *confirm{nullptr}; // 确认 + UILabelButton *cancel{nullptr}; // 取消 + UIImageView *notice{nullptr}; // 删除图标 + UIView::OnClickListener *clickListener{nullptr}; + UIView::OnClickListener *confirmListener{nullptr}; + UIView::OnClickListener *cancelListener{nullptr}; + UIView::OnClickListener *notifyListener{nullptr}; + UIView::OnClickListener *newNotifyListener{nullptr}; +}; +} +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageModel.h new file mode 100644 index 000000000..fd24ca33d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/MessageModel.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef MESSAGE_MODEL_H +#define MESSAGE_MODEL_H + +#include +#include +#include "UiConfig.h" + +namespace OHOS { +typedef struct { + std::string label_1; + std::string icon; + std::string label_2; + std::string label_3; +} MessageItem; + + // static const uint16_t WEATHER_ITEM_COUNT = 10; + class MessageModel { + public: + static MessageModel &GetInstance(void); + void InitMessageItem(); + const std::vector GetMessagelistItems() const; + void ClearListItem(); + void GetMessageInfo(std::string app, std::string contact, std::string information); + void SetViewStatus(bool viewStatus); + bool GetViewStatus(void); + private: + MessageModel(); + MessageModel(const MessageModel &); + MessageModel &operator=(const MessageModel &); + virtual ~MessageModel(); + std::vector vecMsg; + MessageItem mes; + bool viewInitStatus{false}; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/ModelListenerSample.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/ModelListenerSample.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/ModelListenerSample.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/ModelListenerSample.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/PullUpDownView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/PullUpDownView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/PullUpDownView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/PullUpDownView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/UiServersMsg.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/UiServersMsg.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/UiServersMsg.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/UiServersMsg.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/UiViewId.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/UiViewId.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/UiViewId.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/UiViewId.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/VolumeSettingPresenter.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/VolumeSettingPresenter.h index a303b9052..2e0017072 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/VolumeSettingPresenter.h @@ -11,8 +11,8 @@ #include "components/ui_label_button.h" #include "components/ui_view_group.h" #include "components/ui_slider.h" -#include "VolumeSettingView.h" -#include "PlayersView.h" +#include "main/VolumeSettingView.h" +#include "player/PlayersView.h" namespace OHOS { #define INCREASE_BUTTON "increaseButton" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/VolumeSettingView.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/VolumeSettingView.h index ac3db835b..b4ccd2239 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/VolumeSettingView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/VolumeSettingView.h @@ -11,9 +11,9 @@ #include "components/ui_button.h" #include "components/ui_view_group.h" #include "components/ui_slider.h" -#include "PlayersView.h" +#include "player/PlayersView.h" #include "wearable_log.h" -#include "VolumeSettingPresenter.h" +#include "main/VolumeSettingPresenter.h" namespace OHOS { #define VOLUME_MIN 0 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialArcLabelView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialArcLabelView.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialArcLabelView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialArcLabelView.h index 43d0dd217..899d1de81 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialArcLabelView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialArcLabelView.h @@ -6,7 +6,7 @@ #define DIAL_ARC_LABEL_VIEW_H #include -#include "DialView.h" +#include "main/dial/DialView.h" #include "components/ui_arc_label.h" #include "font/font_global_manager.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialArcProgressView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialArcProgressView.h similarity index 78% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialArcProgressView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialArcProgressView.h index 29675223f..4e4763956 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialArcProgressView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialArcProgressView.h @@ -5,7 +5,7 @@ #ifndef DIAL_ARC_PROGRESS_VIEW_H #define DIAL_ARC_PROGRESS_VIEW_H -#include "DialView.h" +#include "main/dial/DialView.h" #include "components/ui_circle_progress.h" namespace OHOS { @@ -14,6 +14,7 @@ public: DialArcProgressView(); ~DialArcProgressView() override; void HandleFloatData(float data) override; + void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; private: int32_t value_ = -1; }; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialBaseModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialBaseModel.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialBaseModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialBaseModel.h index ef71b9bb1..d9e6bd0e2 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialBaseModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialBaseModel.h @@ -10,7 +10,7 @@ #include #include "heap_base.h" -#include "OnDialDataUpdateListener.h" +#include "main/dial/OnDialDataUpdateListener.h" namespace OHOS { class DialBaseModel : public HeapBase { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialBoxProgressView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialBoxProgressView.h similarity index 78% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialBoxProgressView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialBoxProgressView.h index cc45b4d91..4c8d5e67c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialBoxProgressView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialBoxProgressView.h @@ -5,7 +5,7 @@ #ifndef DIAL_BOX_PROGRESS_VIEW_H #define DIAL_BOX_PROGRESS_VIEW_H -#include "DialView.h" +#include "main/dial/DialView.h" #include "components/ui_box_progress.h" namespace OHOS { @@ -14,6 +14,7 @@ public: DialBoxProgressView(); ~DialBoxProgressView() override; void HandleFloatData(float data) override; + void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; private: int32_t value_ = -1; }; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialDataBase.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialDataBase.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialDataBase.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialDataBase.h index e6d52b7ec..5a0a9bd6e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialDataBase.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialDataBase.h @@ -7,7 +7,7 @@ #ifndef DIAL_DATA_BASE_H #define DIAL_DATA_BASE_H -#include "DialDataType.h" +#include "main/dial/DialDataType.h" enum class DialOldDataType { DATA_TYPE_FLOAT_BASE = 0, diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialDataType.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialDataType.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialDataType.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialDataType.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialDigitalImgView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialDigitalImgView.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialDigitalImgView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialDigitalImgView.h index 540c491b5..a058c6ff8 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialDigitalImgView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialDigitalImgView.h @@ -6,8 +6,8 @@ #define DIAL_DIGITAL_IMG_VIEW_H #include -#include "DialView.h" -#include "DialModelTime.h" +#include "main/dial/DialView.h" +#include "main/dial/DialModelTime.h" #include "components/ui_image_view.h" #include "gfx_utils/graphic_math.h" #include "components/ui_view_group.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialKaleidoscopeView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialKaleidoscopeView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialKaleidoscopeView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialKaleidoscopeView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialLabelView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialLabelView.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialLabelView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialLabelView.h index 6e9f2a830..fb32df0b3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialLabelView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialLabelView.h @@ -6,7 +6,7 @@ #define DIAL_LABEL_VIEW_H #include -#include "DialView.h" +#include "main/dial/DialView.h" #include "components/ui_label.h" #include "font/font_global_manager.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelHeartRate.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelHeartRate.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelHeartRate.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelHeartRate.h index 481f39459..54573de9c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelHeartRate.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelHeartRate.h @@ -8,7 +8,7 @@ #ifndef DIAL_MODEL_HEART_RATE_H #define DIAL_MODEL_HEART_RATE_H -#include "DialBaseModel.h" +#include "main/dial/DialBaseModel.h" namespace OHOS { class DialModelHeartRate : public DialBaseModel { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelPower.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelPower.h similarity index 93% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelPower.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelPower.h index cb6a97ce5..a6fc0e084 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelPower.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelPower.h @@ -8,7 +8,7 @@ #ifndef DIAL_MODEL_POWER_H #define DIAL_MODEL_POWER_H -#include "DialBaseModel.h" +#include "main/dial/DialBaseModel.h" namespace OHOS { class DialModelPower : public DialBaseModel { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelSteps.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelSteps.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelSteps.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelSteps.h index e1e9930dd..af23abd9b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelSteps.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelSteps.h @@ -8,7 +8,7 @@ #ifndef DIAL_MODEL_STEPS_H #define DIAL_MODEL_STEPS_H -#include "DialBaseModel.h" +#include "main/dial/DialBaseModel.h" namespace OHOS { class DialModelSteps : public DialBaseModel { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelTime.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelTime.h similarity index 97% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelTime.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelTime.h index d71982f5f..2a95eb18b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialModelTime.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialModelTime.h @@ -8,7 +8,7 @@ #ifndef DIAL_MODEL_TIME_H #define DIAL_MODEL_TIME_H -#include "DialBaseModel.h" +#include "main/dial/DialBaseModel.h" #include "gfx_utils/list.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialOHSliceId.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialOHSliceId.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialOHSliceId.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialOHSliceId.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialOptionImgView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialOptionImgView.h similarity index 93% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialOptionImgView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialOptionImgView.h index 52e4298c2..8feab2815 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialOptionImgView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialOptionImgView.h @@ -6,8 +6,8 @@ #define DIAL_OPTION_IMG_VIEW_H #include -#include "DialView.h" -#include "DialModelTime.h" +#include "main/dial/DialView.h" +#include "main/dial/DialModelTime.h" #include "components/ui_image_view.h" #include "font/font_global_manager.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialRotateImgView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialRotateImgView.h similarity index 95% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialRotateImgView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialRotateImgView.h index e1fff0ed8..ef46414fa 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialRotateImgView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialRotateImgView.h @@ -6,7 +6,7 @@ #define DIAL_ROTATE_IMG_VIEW_H #include -#include "DialView.h" +#include "main/dial/DialView.h" #include "components/ui_image_view.h" #include "gfx_utils/graphic_math.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialSequenceImgView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialSequenceImgView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialSequenceImgView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialSequenceImgView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialStaticImgView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialStaticImgView.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialStaticImgView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialStaticImgView.h index df8f2810c..922517a64 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialStaticImgView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialStaticImgView.h @@ -7,7 +7,7 @@ #include "components/ui_image_view.h" #include "font/font_global_manager.h" -#include "DialModelTime.h" +#include "main/dial/DialModelTime.h" namespace OHOS { class DialStaticImgView : public UIImageView, diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialVideoView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialVideoView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialVideoView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialVideoView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialView.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialView.h index 3155d760a..ceab904ed 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialView.h @@ -7,7 +7,7 @@ #include #include -#include "DialDataType.h" +#include "main/dial/DialDataType.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialViewContainer.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialViewContainer.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialViewContainer.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialViewContainer.h index 0dd421c44..15974b2b6 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialViewContainer.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialViewContainer.h @@ -9,8 +9,8 @@ #define DIAL_VIEW_CONTAINER_H #include "components/ui_view_group.h" #include "gfx_utils/list.h" -#include "dial/DialView.h" -#include "dial/DialDataBase.h" +#include "main/dial/DialView.h" +#include "main/dial/DialDataBase.h" namespace OHOS { class ContainerInterface { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialViewGroup.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialViewGroup.h similarity index 95% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialViewGroup.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialViewGroup.h index a3072703f..347b8ad37 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/DialViewGroup.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/DialViewGroup.h @@ -7,19 +7,19 @@ #include #include -#include "DialDataBase.h" +#include "main/dial/DialDataBase.h" #include "components/ui_view_group.h" #include "components/ui_image_animator.h" #include "components/ui_label.h" -#include "OnDialDataUpdateListener.h" +#include "main/dial/OnDialDataUpdateListener.h" #include "components/ui_card_page.h" #include "components/ui_kaleidoscope_view.h" #include "gfx_utils/list.h" #include "gfx_utils/vector.h" -#include "DialView.h" -#include "DialVideoView.h" -#include "DialBinTypesV2.h" -#include "DialViewContainer.h" +#include "main/dial/DialView.h" +#include "main/dial/DialVideoView.h" +#include "main/DialBinTypesV2.h" +#include "main/dial/DialViewContainer.h" namespace OHOS { class DialViewGroup : public UICardPage, public OnDialDataUpdateListener, public ContainerInterface { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/ModelDialDataFactory.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/ModelDialDataFactory.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/ModelDialDataFactory.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/ModelDialDataFactory.h index 33bedbe49..23c5255fd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/ModelDialDataFactory.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/ModelDialDataFactory.h @@ -9,9 +9,9 @@ #define MODE_DIAL_DATA_FACTORY #include -#include "DialBaseModel.h" -#include "DialDataBase.h" -#include "ModelDialDataFactory.h" +#include "main/dial/DialBaseModel.h" +#include "main/dial/DialDataBase.h" +#include "main/dial/ModelDialDataFactory.h" namespace OHOS { class ModelDialDataFactory : public HeapBase { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/OnDialDataUpdateListener.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/OnDialDataUpdateListener.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/OnDialDataUpdateListener.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/OnDialDataUpdateListener.h index c2af34466..a14c09e44 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/OnDialDataUpdateListener.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/OnDialDataUpdateListener.h @@ -8,7 +8,7 @@ #ifndef ON_DIAL_DATA_UPDATE_LISTENER_H #define ON_DIAL_DATA_UPDATE_LISTENER_H -#include "DialDataBase.h" +#include "main/dial/DialDataBase.h" namespace OHOS { class OnDialDataUpdateListener : public HeapBase { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/RegisterDialModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/RegisterDialModel.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/RegisterDialModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/RegisterDialModel.h index f648a5d37..c0b4cbdde 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/RegisterDialModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/RegisterDialModel.h @@ -8,8 +8,8 @@ #ifndef REGISTER_DIAL_MODEL_H #define REGISTER_DIAL_MODEL_H -#include "DialDataBase.h" -#include "ModelDialDataFactory.h" +#include "main/dial/DialDataBase.h" +#include "main/dial/ModelDialDataFactory.h" namespace OHOS { class RegisterDialModel { public: diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/WatchInterface.h b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/WatchInterface.h similarity index 59% rename from code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/WatchInterface.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/WatchInterface.h index 2938ed4a0..f628bded6 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/dial/WatchInterface.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/main/dial/WatchInterface.h @@ -16,12 +16,22 @@ extern "C" { /** * @brief Get all watch face information - * @param[out] info Pointer to store the watch face information - * @param[out] num Pointer to store the number of watch faces - * @param[in] maxCnt Maximum number of watch faces to retrieve - * @return bool Returns true if successful, false otherwise + * @param [out] watch_dial_info **info + * A pointer to a pointer where the retrieved watch face information will be stored. + * @param [out] uint8_t *num + * A pointer to the number of watch face information entries retrieved. + * @return bool + * - true: Successfully retrieved watch face information. + * The pointer pointed to by `info` needs to be released + * externally. + * - false: Failed to retrieve watch face information. + * @remarks + * - If the function returns true, + * the memory pointed to by `info` must be freed by the caller to prevent + * memory leaks. + * - If the function returns false, the values of `info` and `num` remain unchanged. */ -bool GetAllWatchFaceInfo(watch_dial_info *info, uint8_t *num, uint8_t maxCnt); +bool GetAllWatchFaceInfo(watch_dial_info **info, uint8_t *num); /** * @brief Get information of a specific watch face by UUID @@ -68,15 +78,20 @@ bool SetCurrentWatchFace(uint32_t uuid); bool UninstallWatch(uint32_t uuid); /** - * @brief Install a watch face from a specified path - * @param[in] path Path to the watch face file - * @param[out] uuid Pointer to store the unique identifier of the installed watch face - * @return bool Returns true if successful, false otherwise - * @note If a watch face with the same UUID already exists, it will be replaced + * @brief Retrieves the unique identifier (UUID) associated with a specified path. + * + * @param[in] path The path to look up. + * @param[out] uuid A pointer to a variable where the UUID will be stored if found. + * + * @return bool + * - true if the UUID is successfully retrieved. + * - false if the path is invalid or the UUID cannot be obtained. + * + * @remarks The caller is responsible for ensuring that the 'uuid' pointer is valid and properly aligned. */ -bool InstallWatch(const char *path, uint32_t *uuid); +bool GetUuidByPath(const char *path, uint32_t *uuid); #ifdef __cplusplus } #endif -#endif // WATCH_INTERFACE_H \ No newline at end of file +#endif // WATCH_INTERFACE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/include/CallerDisplayView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/makephone/CallerDisplayView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/makephone/include/CallerDisplayView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/makephone/CallerDisplayView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/include/CallingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/makephone/CallingView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/makephone/include/CallingView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/makephone/CallingView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/include/DialingScreenView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/makephone/DialingScreenView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/makephone/include/DialingScreenView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/makephone/DialingScreenView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/include/MainCallingPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/makephone/MainCallingPresenter.h similarity index 84% rename from code/sdk/application/wearable/nativeapp/nativeui/makephone/include/MainCallingPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/makephone/MainCallingPresenter.h index a9b800fce..56b231da4 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/makephone/include/MainCallingPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/makephone/MainCallingPresenter.h @@ -9,9 +9,9 @@ #include "Presenter.h" #include "ohos_types.h" -#include "CallerLogModel.h" -#include "VolumeSettingView.h" -#include "VolumeSettingPresenter.h" +#include "callerlog/CallerLogModel.h" +#include "main/VolumeSettingView.h" +#include "main/VolumeSettingPresenter.h" namespace OHOS { class MainCallingView; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/include/MainCallingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/makephone/MainCallingView.h similarity index 83% rename from code/sdk/application/wearable/nativeapp/nativeui/makephone/include/MainCallingView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/makephone/MainCallingView.h index e4bf8dd9d..0c7483a94 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/makephone/include/MainCallingView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/makephone/MainCallingView.h @@ -10,10 +10,10 @@ #include "View.h" #include "components/ui_view_group.h" #include "ohos_types.h" -#include "CallerDisplayView.h" -#include "CallingView.h" -#include "DialingScreenView.h" -#include "WaitingHintsView.h" +#include "makephone/CallerDisplayView.h" +#include "makephone/CallingView.h" +#include "makephone/DialingScreenView.h" +#include "makephone/WaitingHintsView.h" namespace OHOS { class MainCallingPresenter; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/include/WaitingHintsView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/makephone/WaitingHintsView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/makephone/include/WaitingHintsView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/makephone/WaitingHintsView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/MainVocassistView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/MainVocassistView.h similarity index 85% rename from code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/MainVocassistView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/MainVocassistView.h index c039e7981..0ec4a21f3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/MainVocassistView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/MainVocassistView.h @@ -8,8 +8,8 @@ #define MAIN_VOCASSIST_VIEW_H #include "View.h" -#include "VocassistModel.h" -#include "VocassistView.h" +#include "offlinevoice/VocassistModel.h" +#include "offlinevoice/VocassistView.h" namespace OHOS { class VocassistPresenter; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/VocassistModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/VocassistModel.h similarity index 95% rename from code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/VocassistModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/VocassistModel.h index e17d153fb..8c9e494ac 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/VocassistModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/VocassistModel.h @@ -9,7 +9,7 @@ #define VOCASSIST_MODEL_H #include "smart_voice_service.h" -#include "VocassistView.h" +#include "offlinevoice/VocassistView.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/VocassistPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/VocassistPresenter.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/VocassistPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/VocassistPresenter.h index 5c3abe4f6..bdb49b9e4 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/VocassistPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/VocassistPresenter.h @@ -10,8 +10,8 @@ #include "Presenter.h" #include "NativeAbility.h" -#include "VocassistView.h" -#include "MainVocassistView.h" +#include "offlinevoice/VocassistView.h" +#include "offlinevoice/MainVocassistView.h" namespace OHOS { class MainVocassistView; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/VocassistView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/VocassistView.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/VocassistView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/VocassistView.h index 541578ad4..3370008cf 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/include/VocassistView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/offlinevoice/VocassistView.h @@ -15,7 +15,7 @@ #include "UiConfig.h" #include "dfx/event_injector.h" #include "wearable_log.h" -#include "AppGroupView.h" +#include "main/AppGroupView.h" static constexpr const char VOCPHOTO_ID[] = "VOCPIC"; static constexpr const char VOC_ID[] = "VOC"; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneAudio.h b/code/sdk/application/wearable/nativeapp/nativeui/include/phoneservice/PhoneAudio.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneAudio.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/phoneservice/PhoneAudio.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneService.h b/code/sdk/application/wearable/nativeapp/nativeui/include/phoneservice/PhoneService.h similarity index 99% rename from code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneService.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/phoneservice/PhoneService.h index 7e7dd371a..ebc275911 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneService.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/phoneservice/PhoneService.h @@ -10,7 +10,7 @@ #include "bts_br_gap.h" #include "bts_hfp_hf.h" #include "ohos_types.h" -#include "PhoneAudio.h" +#include "phoneservice/PhoneAudio.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/player/BluetoothView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/player/BluetoothView.h new file mode 100644 index 000000000..a5465e563 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/player/BluetoothView.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: Bluetooth view 设置页面 + * Create: 2021-09-5 + */ + +#ifndef BLUETOOTH_VIEW_H +#define BLUETOOTH_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_radio_button.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" + +namespace OHOS { +class PlayerOnDragListener; +class BluetoothView { +public: + BluetoothView(); + virtual ~BluetoothView(); + UIViewGroup *LoadBluetoothView(void); + static BluetoothView *GetInstance(void); + UIViewGroup *group{nullptr}; + UIRadioButton *GetPhoneButton(void); + UIRadioButton *GetWatchButton(void); + UIButton *GetSettingButton(void); + UILabelButton *GetDeleteButton(void); +private: + UILabel *watchLabel{nullptr}; + UILabel *phoneLabel{nullptr}; + UILabel *bluetoothLabel{nullptr}; + UIImageView *watchImage{nullptr}; + UIImageView *phoneImage{nullptr}; + UIImageView *bluetoothImage{nullptr}; + UIRadioButton *watchButton{nullptr}; + UIRadioButton *phoneButton{nullptr}; + UIButton *settingButton{nullptr}; + UILabelButton *deleteButton{nullptr}; + int LoadRadioButton(); + int LoadButtonView(); + int LoadLabelButton(); + int LoadLabel(); + int LoadImage(); + + void SetUpButton(UILabelButton *btn, const Point& point, int16_t width, int16_t height, + UIView::OnClickListener *listener); +}; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersCaseListAdapter.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersCaseListAdapter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersCaseListAdapter.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersModel.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersModel.h index 61e90947c..f24dfceb7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersModel.h @@ -10,12 +10,12 @@ #include #include "gfx_utils/list.h" -#include "UiServersMsg.h" +#include "main/UiServersMsg.h" #include "player.h" #include "source.h" #include "audio_manager.h" #include "audio_base_type.h" -#include "PlayersPresenter.h" +#include "player/PlayersPresenter.h" #include "bts_avrcp_controller.h" namespace OHOS { @@ -88,13 +88,14 @@ public: int DecreaseVolume(void); int32_t GetPlayerstatus(); void SetBTMusicPlay(avrcp_key_operation_t notification); - void ConnectBtAndLocalPlay(int32_t connCtState, int32_t connTgState, int32_t playerState); // 蓝牙连接和本地播放 - void ConnectBtAndLocalPause(int32_t connCtState, int32_t connTgState); + int32_t ConnectBtAndLocalPlay(int32_t connCtState, int32_t connTgState, int32_t playerState); // 蓝牙连接和本地播放 + int32_t ConnectBtAndLocalPause(int32_t connCtState, int32_t connTgState); void ConncetBtResetButton(); void ClearActivateAudioInterrupt(void); void GetDuration(int64_t &duration); private: int64_t duration_{0}; + bool isInterruptedPause_{false}; bool audioInitStatus{false}; char *sliceId{nullptr}; List listPlayers; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersPresenter.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersPresenter.h index f955b7142..07d019467 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersPresenter.h @@ -13,19 +13,19 @@ #include "player.h" #include "audio_manager.h" #include "audio_base_type.h" -#include "BluetoothView.h" -#include "VolumeSettingView.h" -#include "VolumeSettingPresenter.h" -#include "BluetoothModel.h" -#include "BluetoothEarPhoneView.h" -#include "BluetoothEarListView.h" -#include "BluetoothOptionsView.h" -#include "BluetoothReconnectView.h" -#include "TipsSuccMessageView.h" -#include "TipsConnFailMessageView.h" -#include "TipsFailMessageView.h" -#include "BluetoothDeviceListView.h" -#include "BluetoothItemView.h" +#include "player/BluetoothView.h" +#include "main/VolumeSettingView.h" +#include "main/VolumeSettingPresenter.h" +#include "bluetooth/BluetoothModel.h" +#include "bluetooth/BluetoothEarPhoneView.h" +#include "bluetooth/BluetoothEarListView.h" +#include "bluetooth/BluetoothOptionsView.h" +#include "bluetooth/BluetoothReconnectView.h" +#include "bluetooth/TipsSuccMessageView.h" +#include "bluetooth/TipsConnFailMessageView.h" +#include "bluetooth/TipsFailMessageView.h" +#include "bluetooth/BluetoothDeviceListView.h" +#include "bluetooth/BluetoothItemView.h" namespace OHOS { using OHOS::Media::Player; @@ -138,6 +138,7 @@ public: bool IsResumed(); bool IsBeginStopped(); bool IsEndStopped(); + bool IsInterruptedPaused(); void OnInterrupt(int32_t type, int32_t hint) override; void PausePlayer(void); void ResumePlayer(void); @@ -151,6 +152,7 @@ private: bool isResumed_{false}; bool isBeginStopped_{false}; bool isEndStopped_{false}; + bool isInterruptedPause_{false}; }; // 滑动手势 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersView.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersView.h index 0dfcd5883..757fff50f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/include/PlayersView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/player/PlayersView.h @@ -23,7 +23,7 @@ #include "font/ui_font.h" #include "graphic_config.h" #include "components/ui_card_page.h" -#include "PlayersPresenter.h" +#include "player/PlayersPresenter.h" namespace OHOS { #define PLAY_PROGRESS_MIN 0 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/qrcode_conn/QrcodeConnModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/qrcode_conn/QrcodeConnModel.h new file mode 100644 index 000000000..9bfab4573 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/qrcode_conn/QrcodeConnModel.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: QrcodeConnModel.h + * Author: + * Create: 2025-04-24 + */ + +#ifndef QRCODE_CONN_MODEL_H +#define QRCODE_CONN_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" + +namespace OHOS { +class QrcodeConnModel { +public: + static QrcodeConnModel &GetInstance(void); + +private: + QrcodeConnModel(); + QrcodeConnModel(const QrcodeConnModel &); + QrcodeConnModel &operator=(const QrcodeConnModel &); + virtual ~QrcodeConnModel(); + +private: +}; +} + +#endif // QRCODE_CONN_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/qrcode_conn/QrcodeConnPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/qrcode_conn/QrcodeConnPresenter.h new file mode 100644 index 000000000..8914dc9d6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/qrcode_conn/QrcodeConnPresenter.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: QrcodeConnPresenter.h + * Author: + * Create: 2025-04-24 + */ + +#ifndef QRCODE_CONN_PRESENTER_H +#define QRCODE_CONN_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" +#include "qrcode_conn/QrcodeConnView.h" +#include "qrcode_conn/QrcodeConnModel.h" + +namespace OHOS { + +class QrcodeConnView; +class QrcodeConnModel; +class QrcodeConnPresenter : public Presenter, + public UIView::OnDragListener { +public: + QrcodeConnPresenter(); + ~QrcodeConnPresenter() override; + static QrcodeConnPresenter *GetInstance(); + bool OnDrag(UIView& view, const DragEvent& event) override; +private: +}; +} + +#endif // QRCODE_CONN_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/qrcode_conn/QrcodeConnView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/qrcode_conn/QrcodeConnView.h new file mode 100644 index 000000000..24aaae618 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/qrcode_conn/QrcodeConnView.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: QrcodeConnView.h + * Author: + * Create: 2025-04-24 + */ + +#ifndef QRCODE_CONN_VIEW_H +#define QRCODE_CONN_VIEW_H + +#include +#include "View.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "UiConfig.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_view.h" +#include "components/ui_qrcode.h" + +namespace OHOS { + +class QrcodeConnPresenter; +class QrcodeConnView : public View { +public: + QrcodeConnView(); + ~QrcodeConnView() override; + + static QrcodeConnView *GetInstance(); + + void OnStart() override; + void OnStop() override; + void InitView(); + void DeInit(); + +private: + UIScrollView *group_ = nullptr; + UIQrcode *qrcode_ = nullptr; +}; +} +#endif // QRCODE_CONN_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/RebootDeviceView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/RebootDeviceView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/RebootDeviceView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/RebootDeviceView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/RebootModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/RebootModel.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/RebootModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/RebootModel.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/RebootPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/RebootPresenter.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/RebootPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/RebootPresenter.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/RebootView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/RebootView.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/RebootView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/RebootView.h index 8627b6232..7ea1ed32f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/RebootView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/RebootView.h @@ -7,8 +7,8 @@ #define REBOOT_VIEW_H #include "View.h" -#include "ShutdownDeviceView.h" -#include "RebootDeviceView.h" +#include "rebootdevice/ShutdownDeviceView.h" +#include "rebootdevice/RebootDeviceView.h" #include "components/ui_view_group.h" #include "components/ui_label.h" #include "components/ui_button.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/ShutdownDeviceView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/ShutdownDeviceView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/include/ShutdownDeviceView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/rebootdevice/ShutdownDeviceView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/recent_app/RecentAppPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/recent_app/RecentAppPresenter.h new file mode 100644 index 000000000..ccc47e1be --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/recent_app/RecentAppPresenter.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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 RECENT_APP_PRESENTER_H +#define RECENT_APP_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" + +namespace OHOS { +class RecentAppView; +class RecentAppPresenter : public Presenter, public UIView::OnClickListener { +public: + RecentAppPresenter(); + ~RecentAppPresenter() override; + void OnResume() override; + bool OnClick(UIView &view, const ClickEvent &event) override; +}; +} + +#endif // RECENT_APP_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/recent_app/RecentAppView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/recent_app/RecentAppView.h new file mode 100644 index 000000000..02dc69422 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/recent_app/RecentAppView.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 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 RECENT_APP_VIEW_H +#define RECENT_APP_VIEW_H + +#include +#include "recent_app/RecentAppPresenter.h" +#include "View.h" +#include "animator/animator.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_roller_view.h" + +namespace OHOS { +static constexpr const char* RECENT_APP_DELETE_BTN_ID = "RecentAppDeleteBtn"; +static std::string RECENT_ITEM_NATIVE_PREFIX = "NA_"; +static std::string RECENT_ITEM_JS_PREFIX = "JS_"; +static constexpr const uint8_t RECENT_ITEM_PREFIX_LEN = 3; +class RecentAppView : public View { +public: + RecentAppView(); + ~RecentAppView() override; + void OnStart() override; + void LoadContent(); + UIRollerView* GetRollerView() + { + return roller_; + } +private: + class LoadingAnimCb : public AnimatorCallback { + public: + LoadingAnimCb() {} + ~LoadingAnimCb() override {} + void Callback(UIView* view) override; + void SetRecentAppView(RecentAppView* recentAppView) + { + recentAppView_ = recentAppView; + } + private: + RecentAppView* recentAppView_; + }; + + void AddRecentAppToRoller(); + void LoadRecentAppContent(); + void InitRecentApps(); + UIRollerView* roller_ = nullptr; + Animator* loadingAnim_ = nullptr; + UILabel* loadingLabel_ = nullptr; + UILabel* noRecentAppLabel_ = nullptr; + UILabelButton* delBtn_ = nullptr; + LoadingAnimCb loadingAnimCb_; + bool viewiInitStatus_ = false; +}; +} // namespace OHOS +#endif // RECENT_APP_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/include/RestoreDefaultsPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/restoredefaults/RestoreDefaultsPresenter.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/include/RestoreDefaultsPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/restoredefaults/RestoreDefaultsPresenter.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/include/RestoreDefaultsView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/restoredefaults/RestoreDefaultsView.h similarity index 84% rename from code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/include/RestoreDefaultsView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/restoredefaults/RestoreDefaultsView.h index 18ac59105..bdfd4e1c3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/include/RestoreDefaultsView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/restoredefaults/RestoreDefaultsView.h @@ -8,9 +8,9 @@ #define RESTORE_DEFAULTS_VIEW_H #include "View.h" -#include "RestoreDefaultsPresenter.h" -#include "RestoreSelectView.h" -#include "AppGroupView.h" +#include "restoredefaults/RestoreDefaultsPresenter.h" +#include "restoredefaults/RestoreSelectView.h" +#include "main/AppGroupView.h" namespace OHOS { constexpr int16_t NUM_RESTORE_DEFAULTS_CONTAINER = 1; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/include/RestoreSelectView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/restoredefaults/RestoreSelectView.h similarity index 86% rename from code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/include/RestoreSelectView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/restoredefaults/RestoreSelectView.h index 85861750a..4eb08e437 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/include/RestoreSelectView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/restoredefaults/RestoreSelectView.h @@ -8,7 +8,7 @@ #define RESTORE_SELECT_VIEW_H #include "View.h" -#include "RestoreDefaultsPresenter.h" +#include "restoredefaults/RestoreDefaultsPresenter.h" #include "components/ui_label.h" #include "components/ui_button.h" #include "components/ui_view_group.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rtcservice/include/RtcService.h b/code/sdk/application/wearable/nativeapp/nativeui/include/rtcservice/RtcService.h similarity index 86% rename from code/sdk/application/wearable/nativeapp/nativeui/rtcservice/include/RtcService.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/rtcservice/RtcService.h index bbda60eb4..3ebf69730 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/rtcservice/include/RtcService.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/rtcservice/RtcService.h @@ -10,7 +10,7 @@ #include "service.h" #include "iunknown.h" #include "broadcast_feature.h" -#include "AlarmClockManage.h" +#include "alarmclockmanage/AlarmClockManage.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/screennotify/include/ui_screennotify.h b/code/sdk/application/wearable/nativeapp/nativeui/include/screennotify/ui_screennotify.h similarity index 67% rename from code/sdk/application/wearable/nativeapp/nativeui/screennotify/include/ui_screennotify.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/screennotify/ui_screennotify.h index 39399a4f4..d06c8d7c0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/screennotify/include/ui_screennotify.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/screennotify/ui_screennotify.h @@ -41,6 +41,20 @@ void set_back_to_home_interval(uint32_t time_sec); */ uint32_t get_back_to_home_interval(void); +/** + * @brief 设置进入AOD后返回上一个应用的可返回时间间隔,需要在slice对应的Presentor的OnStart方法中调用 + * 默认可返回时间间隔是5秒,进入AOD超过5秒后再次亮屏会跳回主界面 + * @param time_sec 设置的可返回时间间隔 + */ +void set_back_to_pre_slice_interval(uint32_t time_sec); + +/** + * @brief 获取进入AOD后返回上一个应用的可返回时间间隔,需要在slice对应的Presentor的OnStart方法中调用 + * 默认可返回时间间隔是5秒,进入AOD超过5秒后再次亮屏会跳回主界面 + * @param time_sec 获取的可返回时间间隔 + */ +uint32_t get_back_to_pre_slice_interval(void); + #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h b/code/sdk/application/wearable/nativeapp/nativeui/include/screensetting/ScreenModels.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/screensetting/ScreenModels.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardAdapter.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardAdapter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardAdapter.h index 75b9ba8d0..50ca27d1e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardAdapter.h @@ -17,7 +17,7 @@ #include "components/abstract_adapter.h" #include "UiConfig.h" #include "wearable_log.h" -#include "SetCardItem.h" +#include "set_card/SetCardItem.h" namespace OHOS { class SetCardAdapter : public AbstractAdapter { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardDeleteView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardDeleteView.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardDeleteView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardDeleteView.h index 6abfe4ee1..14fd9e307 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardDeleteView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardDeleteView.h @@ -9,7 +9,7 @@ #define SET_CARD_DELETE_VIEW_H #include "components/ui_label_button.h" -#include "SetCardPresenter.h" +#include "set_card/SetCardPresenter.h" namespace OHOS { class SetCardDeleteView : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardItem.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardItem.h similarity index 88% rename from code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardItem.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardItem.h index 3926d9357..1d545c1bb 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardItem.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardItem.h @@ -13,7 +13,7 @@ #include "components/ui_view.h" #include "components/ui_view_group.h" #include "components/ui_image_view.h" -#include "MainModel.h" +#include "main/MainModel.h" #include "UiConfig.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardModel.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardModel.h index 43ed70b26..74ca5bd2d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardModel.h @@ -12,8 +12,8 @@ #include #include "AppViewIDs.h" #include "UiConfig.h" -#include "SetCardPresenter.h" -#include "SetCardItem.h" +#include "set_card/SetCardPresenter.h" +#include "set_card/SetCardItem.h" namespace OHOS { class SetCardModel { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardNoCardView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardNoCardView.h similarity index 88% rename from code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardNoCardView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardNoCardView.h index dc8ee1226..711648810 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardNoCardView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardNoCardView.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "SetCardPresenter.h" +#include "set_card/SetCardPresenter.h" namespace OHOS { class SetCardNoCardView : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardPresenter.h similarity index 95% rename from code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardPresenter.h index fb73852ce..8af598cdd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardPresenter.h @@ -11,7 +11,7 @@ #include "Presenter.h" #include "components/ui_list.h" #include "components/ui_view.h" -#include "ModelListenerSample.h" +#include "main/ModelListenerSample.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardView.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardView.h index 22e95d899..fb5c224ee 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/include/SetCardView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_card/SetCardView.h @@ -15,10 +15,10 @@ #include "components/ui_toggle_button.h" #include "ChangeSliceListener.h" #include "UiConfig.h" -#include "SetCardAdapter.h" -#include "SetCardModel.h" -#include "SetCardDeleteView.h" -#include "SetCardNoCardView.h" +#include "set_card/SetCardAdapter.h" +#include "set_card/SetCardModel.h" +#include "set_card/SetCardDeleteView.h" +#include "set_card/SetCardNoCardView.h" namespace OHOS { class SetCardPresenter; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialInfo.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialInfo.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialInfo.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialInfo.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialModel.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialModel.h index ff3787b17..546e89d86 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialModel.h @@ -9,7 +9,7 @@ #define SET_DIAL_MODEL_H #include "AppViewIDs.h" #include "UiConfig.h" -#include "SetDialInfo.h" +#include "set_dial/SetDialInfo.h" namespace OHOS { class SetDialModel { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialPresenter.h similarity index 75% rename from code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialPresenter.h index 80fc743b0..a50ffdada 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialPresenter.h @@ -7,13 +7,15 @@ #ifndef SET_DIAL_PRESENTER_H #define SET_DIAL_PRESENTER_H -#include "SetDialInfo.h" -#include "SetDialModel.h" +#include "set_dial/SetDialInfo.h" +#include "set_dial/SetDialModel.h" #include "Presenter.h" #include "components/ui_view.h" #include "components/ui_roller_view.h" -#include "KeyInputListener.h" -#include "ModelListenerSample.h" +#include "key/KeyInputListener.h" +#include "main/ModelListenerSample.h" +#include "components/ui_coverflow_view.h" +#include "main/MainModel.h" namespace OHOS { @@ -28,6 +30,8 @@ class SetDialPresenter : public Presenter, public: SetDialPresenter(); ~SetDialPresenter() override; + static SetDialPresenter *GetCurrentInstance(); + void SpecifyDialSetting(const DialSetting &setting); size_t GetDialCount(void); std::vector& GetDialInfo(void); uint8_t GetPageIndex(void); @@ -42,6 +46,8 @@ private: void OnClickAction(void); SetDialModel *model{nullptr}; uint64_t startTime{0}; + bool isSpecific = false; + DialSetting specificSetting; }; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/set_dial/include/SetDialView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_dial/SetDialView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/include/SetDialStyleModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial_style/SetDialStyleModel.h similarity index 96% rename from code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/include/SetDialStyleModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_dial_style/SetDialStyleModel.h index c27e3007a..7ed274df2 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/include/SetDialStyleModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial_style/SetDialStyleModel.h @@ -7,7 +7,7 @@ #ifndef SET_DIAL_STYLE_MODEL_H #define SET_DIAL_STYLE_MODEL_H -#include "SetDialView.h" +#include "set_dial/SetDialView.h" #include "components/ui_view.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/include/SetDialStylePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial_style/SetDialStylePresenter.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/include/SetDialStylePresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/set_dial_style/SetDialStylePresenter.h index fda918ece..d867280af 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/include/SetDialStylePresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_dial_style/SetDialStylePresenter.h @@ -7,7 +7,7 @@ #ifndef SET_DIAL_STYLE_PRESENTER_H #define SET_DIAL_STYLE_PRESENTER_H -#include "SetDialView.h" +#include "set_dial/SetDialView.h" #include "components/ui_view.h" #include "Presenter.h" @@ -19,7 +19,7 @@ class SetDialStylePresenter : public Presenter +namespace OHOS { + +enum class TaskType { UpdateInfo, LocalUpdate, Unknown }; + +struct LocalUpdateData { + uint32_t fileSize; +}; + +class OTAPresenter; +class OTAModel : public Model { +public: + OTAModel(); + ~OTAModel(); + +public: + bool ModelRunTask(TaskType type, void *data); + +protected: + void SwitchTask(); + void UpdateInfo(void *data); + void LocalUpdate(void *data); + +protected: + void DelayRebootFor5S(); + void UpdatePercentCallback(uint32_t percent); + +protected: + static int OSALKthreadCallback(void *data); + static int WaitCondition(const void *data); + +protected: + static void OtaUpdatePercentCallback(uint32_t percent); + +private: + osal_task *task = nullptr; + osal_wait wait; + std::atomic_bool isIdel; + TaskType type = TaskType::Unknown; + void *data = nullptr; +}; + +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/set_ota/OTAPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_ota/OTAPresenter.h new file mode 100644 index 000000000..8c37384eb --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_ota/OTAPresenter.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: ota local update + * Author: wangle + * Create: 2025-5-6 + */ +#ifndef OTA_PRESENTER_H +#define OTA_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" +#include "set_ota/OTAModel.h" + +namespace OHOS { + +class OTAView; +class OTAPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + void OnStart() override; + void OnStop() override; + +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; +public: + // Model调用 + void SetPackageInfo(const char* filePath, uint32_t fileSize); + void SetUpdateProgress(const char* message, uint8_t progress); + void SetErrorMessage(const char* message); + void SetMessage(const char* message); +protected: + void SaveSystemScreen(); + void BackSystemScreen(); +private: + bool updateEnable = true; + const char* updateFilePath = nullptr; + uint32_t updateFileSize = 0; + uint32_t briScrStatus = 0; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/set_ota/OTAView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/set_ota/OTAView.h new file mode 100644 index 000000000..1beee87c4 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/set_ota/OTAView.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: ota local update + * Author: wangle + * Create: 2025-5-6 + */ +#ifndef OTA_VIEW_H +#define OTA_VIEW_H + +#include "View.h" +#include "Presenter.h" +#include "components/ui_label.h" +#include "components/ui_box_progress.h" +#include "components/ui_label_button.h" + +namespace OHOS { +class OTAPresenter; +class OTAView : public View { +public: + OTAView(){}; + ~OTAView(){}; + void OnStart() override; + void OnStop() override; + void InitMessageCtrl(); + void InitProgressCtrl(); + void InitUpdateCtrl(); + void AddCtrlToView(); + void DeInitMessageCtrl(); + void DeInitProgressCtrl(); + void DeInitUpdateCtrl(); + +public: + void SetUpdateEnable(); + void SetUpdateDisable(); + void SetMessage(const char *msg); + void SetProgress(uint8_t progress); + +private: + UILabel *message = nullptr; + UIBoxProgress *progress = nullptr; + UILabelButton *update = nullptr; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SetDesktopModel.h similarity index 58% rename from code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/settings/SetDesktopModel.h index 723a0c30d..2866da667 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SetDesktopModel.h @@ -1,8 +1,8 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SetDesktopModel.h - * Author: - * Create: 2021-11-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SetDesktopModel + * Author: Hisi Graphic Team + * Created: 2025-4 */ #ifndef SET_DESKTOP_MODEL_H @@ -27,10 +27,8 @@ namespace OHOS { DesktopStyle GetDesktopStyle(void); void SetDesktopStyle(DesktopStyle style); private: - SetDesktopModel(); - SetDesktopModel(const SetDesktopModel &); - SetDesktopModel &operator=(const SetDesktopModel &); - virtual ~SetDesktopModel(); + SetDesktopModel() = default; + virtual ~SetDesktopModel() = default; }; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingAdapter.h similarity index 94% rename from code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingAdapter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingAdapter.h index d89fe3ee0..a3c5f69ca 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingAdapter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingAdapter.h @@ -17,8 +17,8 @@ #include "components/abstract_adapter.h" #include "wearable_log.h" #include "UiConfig.h" -#include "SettingModel.h" -#include "SettingItemView.h" +#include "settings/SettingModel.h" +#include "settings/SettingItemView.h" namespace OHOS { class SettingAdapter : public AbstractAdapter { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingDesktopPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingDesktopPage.h new file mode 100644 index 000000000..8e8dd1e6d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingDesktopPage.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopPage + * Author: Hisi Graphic Team + * Created: 2025-4 + */ + +#ifndef SETTING_DESKTOP_PAGE_H +#define SETTING_DESKTOP_PAGE_H + +#include "View.h" +#include "components/ui_scroll_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 "SlicePage.h" +#include "UiConfig.h" +#include "settings/SetDesktopModel.h" +#include "settings/SettingPresenter.h" + +namespace OHOS { +class SettingDesktopPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SettingDesktopPage(); + ~SettingDesktopPage() override; + void OnStart(void* data) override; + void UpdateSelectedStyle(DesktopStyle selectedStyle); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + +private: + void InitFootballItem(); + void InitWaterfallItem(); + UIScrollView *scrollview{nullptr}; + UILabel titleText; + UIToggleButton hexagonsBtn; + UIToggleButton listBtn; + UIToggleButton footballBtn_; + UIToggleButton waterfallBtn_; + UIImageView hexagonsImage; + UIImageView listImage; + UIImageView footballImage_; + UIImageView waterfallImage_; + UILabel listText; + UILabel hexagonsText; + UILabel footballText_; + UILabel waterfallText_; +}; +} +#endif // SETTING_DESKTOP_PAGE_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItem.h b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingItem.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItem.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingItem.h index 0031350f1..c45c20469 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItem.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingItem.h @@ -12,7 +12,7 @@ namespace OHOS { typedef struct { - AppViewId viewId; + uint32_t targetId; 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/include/settings/SettingItemView.h similarity index 93% rename from code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItemView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingItemView.h index f045d1cbe..11ba9444e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingItemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingItemView.h @@ -13,7 +13,7 @@ #include "components/ui_image_view.h" #include "UiConfig.h" -#include "SettingModel.h" +#include "settings/SettingModel.h" namespace OHOS { class SettingItemView : public UIViewGroup { @@ -26,7 +26,7 @@ public: { return sItemInfo.enableSlideBack; } - AppViewId GetViewId(); + uint32_t GetTargetId(); const char* GetIconId(); private: UIImageView sIcon; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingMainPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingMainPage.h new file mode 100644 index 000000000..5d3a8c47d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingMainPage.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingMainPage + * Author: Hisi Graphic Team + * Created: 2025-4 + */ + +#ifndef SETTING_MAIN_PAGE_H +#define SETTING_MAIN_PAGE_H + +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "SlicePage.h" +#include "settings/SettingAdapter.h" +#include "settings/SettingPresenter.h" + +namespace OHOS { +class SettingPresenter; +class SettingMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SettingMainPage() = default; + ~SettingMainPage() override; + + void OnStart(void* data) override; + void RefreshSettingsList(const SettingItem* item, uint8_t count); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; +private: + SettingAdapter *listAdapter{nullptr}; + UIScrollView *scrollView{nullptr}; + UIList *contentList{nullptr}; + UILabel *title{nullptr}; +}; +} +#endif // SETTING_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingModel.h similarity index 93% rename from code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingModel.h index 6a50ebfc8..191a64913 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingModel.h @@ -12,8 +12,8 @@ #include #include "AppViewIDs.h" #include "UiConfig.h" -#include "SettingItem.h" -#include "SettingPresenter.h" +#include "settings/SettingItem.h" +#include "settings/SettingPresenter.h" namespace OHOS { static const uint16_t SETTING_ITEM_COUNT = 10; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingPresenter.h new file mode 100644 index 000000000..16595d225 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingPresenter.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SettingPresenter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SETTING_PRESENTER_H +#define SETTING_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class SettingView; +class SettingPresenter : public Presenter { +}; +} + +#endif // SETTING_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingView.h new file mode 100644 index 000000000..2f79acf50 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/settings/SettingView.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025. All rights reserved. + * Description: SettingPage.h + * Author: + * Create: 2025-04-14 + */ + +#ifndef SETTING_VIEW_H +#define SETTING_VIEW_H + +#include "View.h" +namespace OHOS { +enum SETTING_PAGES { + SETTING_MAIN_PAGE = 1, // 0 is invalid + SETTING_DESKTOP_PAGE = 2, +}; + +class SettingPresenter; +class SettingView : public View { +}; +} +#endif // SETTING_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingDetailsPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingDetailsPage.h new file mode 100644 index 000000000..34cb969fd --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingDetailsPage.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepingDetailsPage + * Created: 2025-06-05 + */ +#ifndef SLEEPING_DETAILS_PAGE_H +#define SLEEPING_DETAILS_PAGE_H + +#include "View.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "SlicePage.h" +#include "main/LoadImg.h" +#include "ui_resource_sleep.h" +#include "sleep/SleepingPresenter.h" +#include "sleep/SleepingView.h" +#include "sleep/SleepingModel.h" + +namespace OHOS { +class SleepingPresenter; +class SleepingDetailsPage : public SlicePage, + public UIView::OnDragListener { +public: + SleepingDetailsPage(); + ~SleepingDetailsPage() override; + + void OnStart(void* data) override; + void InitPage(); + void InitNoDeatilPage(); + void InitDetailPage(); + + void InitSoberingTime(); + void InitRapidEyeMovement(); + void InitLightSleepTime(); + void InitDeepSleepTime(); + bool OnDrag(UIView &view, const DragEvent &event) override; + bool GetRecord(); + std::string SetTimeText(std::tuple timeTuple); + void InitActualSleepTime(std::tuple timeTuple); + void IoadDeatilActualSleepTime(); +private: + + UIScrollView *group{nullptr}; + UIImageView *detailsSleepView{nullptr}; + UILabel *sleep{nullptr}; + UILabel *actualSleepTime{nullptr}; + UILabel *actualSleepTimeHours{nullptr}; + UILabel *actualSleepTimeHoursText{nullptr}; + UILabel *actualSleepTimeMinutes{nullptr}; + UILabel *actualSleepTimeMinutesText{nullptr}; + UIImageView *grayBg{nullptr}; + + UIImageView *image1{nullptr}; + UILabel *soberingTime_{nullptr}; + UILabel *soberingTimeText{nullptr}; + UIImageView *image2{nullptr}; + UILabel *rapidEyeMovement_ {nullptr}; + UILabel *rapidEyeMovementText{nullptr}; + UIImageView *image3{nullptr}; + UILabel *lightSleepTime_{nullptr}; + UILabel *lightSleepTimeText{nullptr}; + UIImageView *image4{nullptr}; + UILabel *deepSleepTime_{nullptr}; + UILabel *deepSleepTimeText{nullptr}; +}; +} + +#endif // SLEEPING_DETAILS_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingMainPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingMainPage.h new file mode 100644 index 000000000..72492303e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingMainPage.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepingMainPage + * Created: 2025-06-05 + */ +#ifndef SLEEPING_MAIN_PAGE_H +#define SLEEPING_MAIN_PAGE_H + +#include "View.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" +#include "components/ui_view_group.h" +#include "components/ui_circle_progress.h" +#include "components/ui_scroll_view.h" +#include "ui_resource_sleep.h" +#include "main/LoadImg.h" +#include "sleep/TargetSleepTime.h" +#include "sleep/SleepingPresenter.h" +#include "sleep/SleepingView.h" +#include "sleep/SleepingModel.h" + + +namespace OHOS { +class SleepingPresenter; +class SleepingMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SleepingMainPage(); + ~SleepingMainPage() override; + + void OnStart(void* data) override; + void InitNoRecordPage(); + void InitRecordPage(); + void IoadActualSleepTime(std::tuple timeTuple); + void IoadTargetTimeButton(std::tuple timeTuple); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void CircleProgress(); + void TargetTimeButton(); + uint32_t GetSleepingScores(); + void InitSleepTimeLabel(); + void ScoreDisplay(); + bool GetRecord(); + void InitScoreDisplayPicture(); +private: + + UIImageView *imageViewMain{nullptr}; + UILabel *sleep{nullptr}; + UIImageView *moonNoRecord{nullptr}; + UIImageView *moon{nullptr}; + UILabel *noRecord{nullptr}; + UILabel *tips{nullptr}; + + UILabel *sleepScores_{nullptr}; + UILabel *scoreText{nullptr}; + UILabel *sleepScore{nullptr}; + + UIImageView *scoreDisplayPicture1{nullptr}; + UIImageView *scoreDisplayPicture2{nullptr}; + UIImageView *scoreDisplayPicture3{nullptr}; + UIImageView *scoreDisplayPicture4{nullptr}; + UIImageView *scoreDisplayPicture5{nullptr}; + UIImageView *setting{nullptr}; + UILabel *actualSleepTimeHours{nullptr}; + UILabel *actualSleepTimeHoursText{nullptr}; + UILabel *actualSleepTimeMinutes{nullptr}; + UILabel *actualSleepTimeMinutesText{nullptr}; + + UILabelButton *targetTimeButton{nullptr}; + UILabel *targetTimeText{nullptr}; + UICircleProgress* circleProgress{nullptr}; + + UIScrollView *group{nullptr}; +}; +} + +#endif // SLEEPING_MAIN_PAGE_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingModel.h new file mode 100644 index 000000000..08965502e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingModel.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepingModel + * Created: 2025-06-05 + */ +#ifndef SLEEPING_MODEL_H +#define SLEEPING_MODEL_H + +#include +#include +#include +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "graphic_timer.h" +#include "ohos_timer.h" +#include "wearable_log.h" +#include "diag_service.h" +#include "msg_center_device.h" +#include "diag_common.h" +#include "sleep/SleepingPresenter.h" + +namespace OHOS { + static const uint16_t SLEEP_DATA_DATE_RANGE = 20; + static const uint16_t SLEEP_DATA_START_DATA_RANGE = 24; + + #pragma pack(1) + typedef struct { + bool isSend; + char date[SLEEP_DATA_DATE_RANGE]; + uint8_t type; // 睡眠类别 深睡 浅睡 快速动眼 清醒 + char start[SLEEP_DATA_START_DATA_RANGE]; + char end[SLEEP_DATA_START_DATA_RANGE]; + char sleepStart[SLEEP_DATA_START_DATA_RANGE]; + char sleepEnd[SLEEP_DATA_START_DATA_RANGE]; + } SleepData; + #pragma pack() + + + class SleepingModel { + public: + static SleepingModel &GetInstance(void); + void SendData(); + uint8_t* SerializeSleepData(const SleepData* sleepData, size_t* outSize); + void SetSleepData(); + void SetTime(uint32_t minute); + std::tuple GetTime(); + void SetData(); + std::tuple GetSoberingTime(); + std::tuple GetRapidEyeMovementTime(); + std::tuple GetLightSleepTime(); + std::tuple GetDeepSleepTime(); + std::tuple GetSleepTime(); + void SetSoberingTime(); + void SetRapidEyeMovementTime(); + void SetLightSleepTime(); + void SetDeepSleepTime(); + bool GetRecord(); + uint32_t GetSleepTimeHours(); + uint32_t GetSleepTimeMinutes(); + std::tuple MinutesToHours(uint32_t minutes); + uint32_t TimeDiffInMinutes(const std::string& timeStr1, const std::string& timeStr2); + uint32_t GetDetailData(int type); + uint32_t GetTotalSleepTime(); + + private: + SleepingModel(); + void PrintSleepData(const SleepData *data); + virtual ~SleepingModel(); + uint32_t sleepTarget = 0; + std::vector sleepDataVector; + uint32_t soberingTime; + uint32_t eyeMoveTime; + uint32_t lightTime; + uint32_t deepTime; + }; +} + +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingPresenter.h new file mode 100644 index 000000000..2e0fdfa4d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingPresenter.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepingPresenter + * Created: 2025-06-05 + */ + +#ifndef SETTING_PRESENTER_H +#define SETTING_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class SleepingView; +class SleepingPresenter : public Presenter { +}; +} + +#endif // SETTING_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingView.h new file mode 100644 index 000000000..67325adf9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/SleepingView.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepingView + * Created: 2025-06-05 + */ + +#ifndef SLEEPING_VIEW_H +#define SLEEPING_VIEW_H + +#include "View.h" +namespace OHOS { +enum SLEEPING_PAGES { + SLEEPING_MAIN_PAGE = 1, // 0 is invalid + SLEEPING_DEATIL_PAGE = 2, + SLEEPING_TARGET_PAGE = 3, +}; + +class SleepingPresenter; +class SleepingView : public View { +}; +} +#endif // SLEEPING_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/TargetSleepTime.h b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/TargetSleepTime.h new file mode 100644 index 000000000..2aa0f8be1 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/sleep/TargetSleepTime.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TargetSleepTime + * Created: 2025-06-05 + */ + +#ifndef TARGET_SLEEP_TIME_H +#define TARGET_SLEEP_TIME_H + +#include "View.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" +#include "components/ui_view_group.h" +#include "components/ui_picker.h" +#include "components/ui_scroll_view.h" +#include "main/LoadImg.h" +#include "sleep/SleepingPresenter.h" +#include "sleep/SleepingView.h" +namespace OHOS { +class TargetSleepTime : public SlicePage, + public UIPicker::SelectedListener, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + TargetSleepTime() = default; + ~TargetSleepTime() override; + + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void OnPickerStoped(UIPicker& picker) override; + void TargetTimeButton(); + void CreatePicker(); + void CreateLabel(); + void SetPickerTime(); +private: + UILabel* setTraget{nullptr}; + UILabel* timerLabel{nullptr}; + UILabelButton *startButton{nullptr}; + UIImageView *backgroundImage{nullptr}; + UIScrollView *group{nullptr}; + UIPicker* timerPicker[2]{nullptr}; +}; +} +#endif // TARGET_SLEEP_TIME_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/sports/SportsModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/sports/SportsModel.h new file mode 100644 index 000000000..8b7b56a1f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/sports/SportsModel.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Sports Model + * Create: 2025-04-28 + */ + +#ifndef SPORTS_MODEL_H +#define SPORTS_MODEL_H +#include "graphic_timer.h" + +namespace OHOS { + +typedef struct sport_data { + uint32_t step; + uint32_t distance; + int32_t lat; + int32_t lng; + uint32_t speed; + uint16_t heartrate; +} sport_data_t; + +class SportsModel { +public: + ~SportsModel(); + static SportsModel *GetInstance(void); + void Init(); + bool StartSportsTimer(); + void StopSportsTimer(bool isDelete); + void IncrSportsTime(); + std::string CountingSportsTime(); + bool IsActive(); + sport_data_t *GetSportsData(); + void ResetSportsData(); + uint32_t CalculateSpeed(uint32_t distance); + +private: + SportsModel(); + void InitSportsTimer(); + uint32_t uiSportTime_ = 0; + bool isActive_{false}; + GraphicTimer *pGraphicTimer_{nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/sports/SportsPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/sports/SportsPresenter.h new file mode 100644 index 000000000..6ff4a6985 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/sports/SportsPresenter.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: sports Presenter + * Create: 2025-04-28 + */ + +#ifndef SPORTS_PRESENTER_H +#define SPORTS_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { + +class SportsView; +class SportsPresenter : public Presenter, + public UIView::OnDragListener { +public: + SportsPresenter(); + ~SportsPresenter(); + static SportsPresenter *GetInstance(); + bool OnDrag(UIView& view, const DragEvent& event) override; +private: +}; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/sports/SportsView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/sports/SportsView.h new file mode 100644 index 000000000..aeca78761 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/sports/SportsView.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: sports View + * Create: 2025-04-28 + */ +#ifndef SPORTS_VIEW_H +#define SPORTS_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" + +namespace OHOS { + +enum SportDataType { + SPORT_TIME = 0, + SPORT_SETP, + SPORT_DISTANCE, + SPORT_HEARTRATE, + SPORT_SPEED, + SPORT_MAX, +}; + +class SportsPresenter; +class SportsView : public View { +public: + SportsView(); + ~SportsView() override; + static SportsView *GetInstance(); + void OnStart() override; + void SetStep(uint32_t step); + void SetHeartRate(uint16_t heartrate); + void SetDistance(uint32_t distance); + void SetTime(const char *time); + void SetSpeed(uint32_t speed); + +private: + bool InitView(); + bool InitLableView(int index, const char *text, uint16_t x, uint16_t y1, uint16_t w, uint16_t y2); + void InitSportDataLabel(); + UILabel TitleLabel[SPORT_MAX]; + UILabel ContentLabel[SPORT_MAX]; + UIViewGroup *group{nullptr}; + UIImageView *backGround{nullptr}; +}; +} // namespace OHOS +#endif // SPORTS_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchAdapter.h new file mode 100644 index 000000000..bd160d86e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchAdapter.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchAdapter + * Create: 2025-06-06 + */ + +#ifndef STOPWATCH_ADAPTER_H +#define STOPWATCH_ADAPTER_H + +#include "gfx_utils/list.h" +#include "components/abstract_adapter.h" +#include "stopwatch/StopwatchItemView.h" + +namespace OHOS { + +class StopwatchAdapter : public AbstractAdapter { +public: + explicit StopwatchAdapter(); + ~StopwatchAdapter() override; + + void SetData(const List &data); + + uint16_t GetCount(void) override; + UIView *GetView(UIView *inView, int16_t index) override; + +private: + List listData_; +}; +} + +#endif // STOPWATCH_ADAPTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchItemView.h new file mode 100644 index 000000000..b4a48db38 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchItemView.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchItemView + * Create: 2025-06-06 + */ + +#ifndef STOPWATCH_ITEM_VIEW_H +#define STOPWATCH_ITEM_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" + +namespace OHOS { +typedef struct { + std::string record; + bool isLatest; +} StopwatchItem; + +class StopwatchItemView : public UIViewGroup { +public: + explicit StopwatchItemView(); + virtual ~StopwatchItemView() override; + void SetItemInfo(int16_t index, const StopwatchItem &itemInfo); + +private: + UILabel nameLabel_; + UILabel recordLabel_; + UILabelButton itemBg_; +}; +} + +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchModel.h new file mode 100644 index 000000000..41c75f093 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchModel.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchModel + * Create: 2025-06-06 + */ + +#ifndef STOPWATCH_MODEL_H +#define STOPWATCH_MODEL_H + +#include "stopwatch/StopwatchItemView.h" +#include "gfx_utils/list.h" +#ifndef _WIN32 +#include "time64.h" +#endif + +namespace OHOS { +class StopwatchModel { +public: + ~StopwatchModel(); + static StopwatchModel &GetInstance(void); + + void SetStartTime(); + void SaveElapsedTime(); + uint64_t GetElapsedTime(); + uint64_t UpdateElapsedTime(); + void ResetCounter(); + bool GetActiveState(); + void SetActiveState(); + void SetInactiveState(); + List &GetRecordsList(); + void AddRecordToList(const StopwatchItem &record); + void ClearData(); + bool IsInRecordView(); + void SetRecordViewState(bool state); + bool GetOverflowState() + { + return isOverflow_; + } + void SetOverflowState(bool state) + { + isOverflow_ = state; + } + +private: + StopwatchModel(); + StopwatchModel(const StopwatchModel &); + StopwatchModel &operator=(const StopwatchModel &); +#ifdef _WIN32 + struct timeval startTime_ {0}; +#else + struct timeval64 startTime_ {0}; +#endif + bool isOverflow_{false}; + uint64_t uiElapsedTime_{0}; + uint64_t uiSavedElapsedTime_{0}; + bool bIsActive_{false}; + bool bIsRecordView_{false}; + List records_; +}; +} + +#endif // STOPWATCH_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchPage.h new file mode 100644 index 000000000..9568a306c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchPage.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchPage + * Create: 2025-06-06 + */ + +#ifndef STOPWATCH_PAGE_H +#define STOPWATCH_PAGE_H + +#include "UiConfig.h" +#include "SlicePage.h" +#include "stopwatch/StopwatchPresenter.h" +#include "stopwatch/StopwatchAdapter.h" +#include "NativeRegisterManager.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_label_button.h" +#include "components/ui_image_view.h" +#include "components/ui_sweep_clock.h" +#include "animator/animator.h" + +namespace OHOS { + +#define STOPWATCH_APP_NAME "秒表" + +class StopwatchPresenter; +class StopwatchPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + StopwatchPage(); + ~StopwatchPage() override; + + void OnStart(void* data) override; + void OnStop() override; + void OnPause() override; + void OnResume() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void Overflowing(void); + UISweepClock* GetSweepClock(){return sweepClock_;} + UILabel* GetElapsedTimeLabel(){return elapsedTime_;} +private: + void DrawButtonStatusView(bool isActive); + void DrawContainRecordListView(bool isContainRecordList); + void RefreshRecordsList(void); + class StopwatchAnimatorCallback : public AnimatorCallback { + public: + StopwatchAnimatorCallback(StopwatchPage* page) : stopwatchPage(page) {} + virtual ~StopwatchAnimatorCallback() override {} + void Callback(UIView* view) override; + private: + StopwatchPage* stopwatchPage{nullptr}; + }; + class TimeAnimatorCallback : public AnimatorCallback { + public: + TimeAnimatorCallback() {} + virtual ~TimeAnimatorCallback() override {} + void Callback(UIView* view) override; + }; + Animator* animator_{nullptr}; + StopwatchAnimatorCallback* animatorCallback_{nullptr}; + TimeAnimatorCallback* timeCallback_{nullptr}; + Animator* timeAnimator_{nullptr}; + UISweepClock *sweepClock_{nullptr}; + Image *secondHand_{nullptr}; + UILabel *currentTime_{nullptr}; + UILabel *appName_{nullptr}; + UILabel *elapsedTime_{nullptr}; + UIList *recordsList_{nullptr}; + StopwatchAdapter *listAdapter_{nullptr}; + UILabelButton *startButton_{nullptr}; + UILabelButton *resetButton_{nullptr}; + UIImageView *backGround_{nullptr}; + UIImageView *imgScale_{nullptr}; +}; +} +#endif // STOPWATCH_PAGE_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchPresenter.h new file mode 100644 index 000000000..76492cac2 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchPresenter.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchPresenter + * Create: 2025-06-06 + */ + +#ifndef STOPWATCH_PRESENTER_H +#define STOPWATCH_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class StopwatchView; +class StopwatchPresenter : public Presenter {}; +} + +#endif // STOPWATCH_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchView.h new file mode 100644 index 000000000..c35a5709c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/stopwatch/StopwatchView.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchView + * Create: 2025-06-06 + */ + +#ifndef STOPWATCH_VIEW_H +#define STOPWATCH_VIEW_H + +#include "View.h" +namespace OHOS { +enum STOPWATCH_PAGES { + STOPWATCH_MAIN_PAGE = 1, // 0 is invalid +}; + +class StopwatchPresenter; +class StopwatchView : public View {}; +} +#endif // STOPWATCH_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempClickMea.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempClickMea.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempClickMea.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempClickMea.h index 7756ff74e..06485e007 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempClickMea.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempClickMea.h @@ -11,7 +11,7 @@ #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_scroll_view.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempClickMea : public UIScrollView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempContinueWarn.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempContinueWarn.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempContinueWarn.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempContinueWarn.h index c6aca9ea1..0d0ac1a38 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempContinueWarn.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempContinueWarn.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_view_group.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempContinueWarn : public UIViewGroup { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempExitInter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempExitInter.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempExitInter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempExitInter.h index 81df8141b..3b8e93eee 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempExitInter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempExitInter.h @@ -10,8 +10,8 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" -#include "AppGroupView.h" -#include "TempPresenter.h" +#include "main/AppGroupView.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempExitInter : public AppGroupView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempExitPrompt.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempExitPrompt.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempExitPrompt.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempExitPrompt.h index 63543772d..f0395f07f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempExitPrompt.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempExitPrompt.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_scroll_view.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempExitPrompt : public UIScrollView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempInitInter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempInitInter.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempInitInter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempInitInter.h index 6de798213..41bb91f1a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempInitInter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempInitInter.h @@ -11,8 +11,8 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AppGroupView.h" -#include "TempPresenter.h" +#include "main/AppGroupView.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempInitInter : public AppGroupView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempJoinStudy.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempJoinStudy.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempJoinStudy.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempJoinStudy.h index 6aec60c0b..6d66ddd42 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempJoinStudy.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempJoinStudy.h @@ -11,7 +11,7 @@ #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_scroll_view.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempJoinStudy : public UIScrollView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempLittleTip.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempLittleTip.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempLittleTip.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempLittleTip.h index 49320fcff..344e6331d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempLittleTip.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempLittleTip.h @@ -10,7 +10,7 @@ #include "components/ui_label.h" #include "components/ui_scroll_view.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempLittleTip : public UIScrollView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempMainView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempMainView.h similarity index 76% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempMainView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempMainView.h index 2b3448138..6ae132c00 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempMainView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempMainView.h @@ -13,22 +13,22 @@ #include "components/ui_view_group.h" #include "ChangeSliceListener.h" #include "components/ui_swipe_view.h" -#include "TempPresenter.h" -#include "TempJoinStudy.h" -#include "TempMeasure.h" -#include "TempExitInter.h" -#include "TempPromptWear.h" -#include "TempClickMea.h" -#include "TempRemindWear.h" -#include "TempMeaProcess.h" -#include "TempInitInter.h" -#include "TempWarn.h" -#include "TempLittleTip.h" -#include "TempModel.h" -#include "TempStudyAbout.h" -#include "TempExitPrompt.h" -#include "TempContinueWarn.h" -#include "TempReport.h" +#include "temperature/TempPresenter.h" +#include "temperature/TempJoinStudy.h" +#include "temperature/TempMeasure.h" +#include "temperature/TempExitInter.h" +#include "temperature/TempPromptWear.h" +#include "temperature/TempClickMea.h" +#include "temperature/TempRemindWear.h" +#include "temperature/TempMeaProcess.h" +#include "temperature/TempInitInter.h" +#include "temperature/TempWarn.h" +#include "temperature/TempLittleTip.h" +#include "temperature/TempModel.h" +#include "temperature/TempStudyAbout.h" +#include "temperature/TempExitPrompt.h" +#include "temperature/TempContinueWarn.h" +#include "temperature/TempReport.h" namespace OHOS { class TempMainView; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempMeaProcess.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempMeaProcess.h similarity index 92% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempMeaProcess.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempMeaProcess.h index ebd0ee48a..3264e72cd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempMeaProcess.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempMeaProcess.h @@ -12,7 +12,7 @@ #include "components/ui_label.h" #include "components/ui_scroll_view.h" #include "components/ui_circle_progress.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempMeaProcess : public UIScrollView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempMeasure.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempMeasure.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempMeasure.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempMeasure.h index de6aa31c0..972e64e10 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempMeasure.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempMeasure.h @@ -11,8 +11,8 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AppGroupView.h" -#include "TempPresenter.h" +#include "main/AppGroupView.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempMeasure : public AppGroupView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempModel.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempModel.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempPresenter.h similarity index 95% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempPresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempPresenter.h index f9b3520e1..2b1321c89 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempPresenter.h @@ -14,7 +14,7 @@ #include "components/ui_swipe_view.h" #include "wearable_log.h" #include "color.h" -#include "ModelListenerSample.h" +#include "main/ModelListenerSample.h" namespace OHOS { constexpr char* TEMP_JOIN_STUDY = (char*)"tempjoinstudy"; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempPromptWear.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempPromptWear.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempPromptWear.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempPromptWear.h index 5f590e00f..2b3793cfa 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempPromptWear.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempPromptWear.h @@ -12,7 +12,7 @@ #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_scroll_view.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempPromptWear : public UIScrollView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempRemindWear.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempRemindWear.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempRemindWear.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempRemindWear.h index 24f10ed90..9375bf154 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempRemindWear.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempRemindWear.h @@ -11,7 +11,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_scroll_view.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempRemindWear : public UIScrollView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempReport.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempReport.h similarity index 87% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempReport.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempReport.h index 3faadd519..649afb5cf 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempReport.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempReport.h @@ -10,8 +10,8 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" -#include "AppGroupView.h" -#include "TempPresenter.h" +#include "main/AppGroupView.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempReport : public AppGroupView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempStudyAbout.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempStudyAbout.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempStudyAbout.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempStudyAbout.h index 3d0deee4a..754c3912d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempStudyAbout.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempStudyAbout.h @@ -10,7 +10,7 @@ #include "components/ui_label.h" #include "components/ui_scroll_view.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempStudyAbout : public UIScrollView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempWarn.h b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempWarn.h similarity index 90% rename from code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempWarn.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempWarn.h index 821b4a4bb..1fbc6ebf3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/include/TempWarn.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/temperature/TempWarn.h @@ -12,7 +12,7 @@ #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_scroll_view.h" -#include "TempPresenter.h" +#include "temperature/TempPresenter.h" namespace OHOS { class TempWarn : public UIScrollView { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerMainPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerMainPage.h new file mode 100644 index 000000000..417b92b68 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerMainPage.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerMainPage + * Create: 2025-06-09 + */ + +#ifndef TIMER_MAIN_PAGE_H +#define TIMER_MAIN_PAGE_H + +#include +#include "View.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "UiConfig.h" +#include "ChangeSliceListener.h" +#include "components/ui_image_view.h" +#include "timers/TimerPresenter.h" +#include "timers/TimerModel.h" +#include "SlicePage.h" +#include "common/image_cache_manager.h" +#include "ui_resource_timer.h" + +namespace OHOS { + class TimerMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { + public: + TimerMainPage() = default; + ~TimerMainPage() override; + + void OnStart(void *data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void LabelTitle(); + void CreateButton(); + void InitView(); + + private: + UIScrollView *group{nullptr}; + UIImageView *selectMin[4]{nullptr}; // 分钟计时 + UIImageView *addButton{nullptr}; // 自定义按钮 + UILabel *title{nullptr}; // 计时器 + UIImageView *backround{nullptr}; + }; +} +#endif // TIMER_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerModel.h new file mode 100644 index 000000000..fee8cd676 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerModel.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerModel + * Create: 2025-06-09 + */ + +#ifndef TIMER_MODEL_H +#define TIMER_MODEL_H + +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "timers/TimerPresenter.h" +#include "graphic_timer.h" +#include "ohos_timer.h" + +namespace OHOS { + class TimerModel { + public: + static TimerModel &GetInstance(void); + + void SetDurationTime(uint32_t time); // 设置计时器的总时间 + uint32_t GetDurationTime(); // 获取计时器的总时间 + bool GetIsTiming() { return isTiming; } + void SetIsTiming(bool value) { isTiming = value; } + bool GetIsPause() { return isPause; } + void SetIsPause(bool value) { isPause = value; } + uint32_t GetStartTime() { return start_time; }; + void SetStartTime(uint32_t value) { start_time = value; }; + uint32_t GetSaveTime(); + void SetSaveTime(bool falg, uint32_t value); + + void InitTimer(); + void DisableTimer(); + bool GetExistTimer() { return haveTimer; }; + void SetExistTimer(bool value) { haveTimer = value; }; + + private: + TimerModel(); + virtual ~TimerModel(); + TimerModel(const TimerModel &) = delete; + TimerModel &operator=(const TimerModel &) = delete; + uint32_t start_time; + uint32_t save_time; + uint32_t durationTime = 0; + GraphicTimer *g_startCounting = nullptr; // 定时器 + bool haveTimer = false; + bool isTiming = false; + bool isPause = false; + }; +} + +#endif // TIMER_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerPresenter.h new file mode 100644 index 000000000..e2d42aef7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerPresenter.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerPresenter + * Create: 2025-06-09 + */ + +#ifndef TIMER_PRESENTER_H +#define TIMER_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" + +namespace OHOS { + +#define SETTING_TIMER "setting_timer" +#define STOPWATCH_RESET "stopwatch_reset" +#define ONE_MIN "onemine" +#define THREE_MIN "threemine" +#define FIFTY_MIN "fiftymine" +#define THIRTY_MIN "thirtymine" +#define BACK_TIMER "backtimer" +#define RESET "reset" +#define START_PAUSE "start_pause" +#define START_TIMING "start_timing" + + class TimerView; + class TimerPresenter : public Presenter { + }; +} + +#endif // TIMER_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerSettingPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerSettingPage.h new file mode 100644 index 000000000..1ede0c7ea --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerSettingPage.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerSettingPage + * Create: 2025-06-09 + */ + +#ifndef TIMER_SETTING_PAGE_H +#define TIMER_SETTING_PAGE_H + +#include "View.h" +#include "components/ui_button.h" +#include "components/ui_label.h" +#include "components/ui_time_picker.h" +#include "components/ui_label_button.h" +#include "components/ui_scroll_view.h" +#include "UiConfig.h" +#include "timers/TimerPresenter.h" +#include "timers/TimerModel.h" +#include "SlicePage.h" +#include "ChangeSliceListener.h" +#include "ui_resource_timer.h" + +namespace OHOS { + class TimerSettingPage : public UIPicker::SelectedListener, + public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { + public: + TimerSettingPage() = default; + ~TimerSettingPage() override; + + void OnStart(void *data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + + void CreateLabel(void); + void CreateStartButton(void); + void CreatePicker(); + UIScrollView *InitTimerSetView(); + void OnPickerStoped(UIPicker& picker) override; + + private: + UIScrollView *group{nullptr}; + UIButton *back{nullptr}; + UILabel *title{nullptr}; + UIImageView *start{nullptr}; + + UILabel *timerLabel{nullptr}; + UIPicker *timerPicker[3]{nullptr}; + ImageInfo *image1 = nullptr; + ImageInfo *image2 = nullptr; + }; +} +#endif // TIMER_SETTING_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerTimingPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerTimingPage.h new file mode 100644 index 000000000..a64450a42 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerTimingPage.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerTimingPage + * Create: 2025-06-09 + */ + +#ifndef TIMER_TIMING_PAGE_H +#define TIMER_TIMING_PAGE_H + +#include +#include "View.h" +#include "components/ui_button.h" +#include "components/ui_label.h" +#include "components/ui_scroll_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_image_view.h" +#include "components/ui_circle_progress.h" +#include "UiConfig.h" +#include "timers/TimerModel.h" +#include "timers/TimerPresenter.h" +#include "SlicePage.h" +#include "ChangeSliceListener.h" +#include "components/ui_sweep_clock.h" +#include "ui_resource_timer.h" + +namespace OHOS { + class TimerTimingPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { + public: + TimerTimingPage() = default; + ~TimerTimingPage() override; + void OnStart(void *data) override; + void OnResume() override; + void OnPause() override; + + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void CreateButton(); + void CreateTimerTime(); + void CircleProgress(); + void SetTimerTime(uint32_t durationTime); + void SetupAnimator(); + void SetAnimatorStatus(bool status); + + private: + class TimeAnimatorCallback : public AnimatorCallback { + public: + TimeAnimatorCallback() {} + virtual ~TimeAnimatorCallback() override {} + void Callback(UIView *view) override; + }; + + class TimerTimingCallback : public AnimatorCallback { + public: + explicit TimerTimingCallback(TimerTimingPage *page) : page_(page) {} + ~TimerTimingCallback() override {} + void Callback(UIView *view) override; + + private: + TimerTimingPage *page_{nullptr}; + }; + + UIScrollView *group{nullptr}; + UISweepClock *sweepClock_{nullptr}; + UIDigitalClock *dClock{nullptr}; + UILabel *title{nullptr}; + UIDigitalClock *timerTime{nullptr}; + UIImageView *reset{nullptr}; + UIImageView *start{nullptr}; + UICircleProgress *circleProgress{nullptr}; + UILabel *currentTime_{nullptr}; + TimeAnimatorCallback *timeCallback_{nullptr}; + Animator *timeAnimator_{nullptr}; + TimerTimingCallback *callBack_ = nullptr; + Animator *animator_ = nullptr; + Image *secondHand_{nullptr}; + UIImageView *backround{nullptr}; + }; +} +#endif // TIMER_TIMING_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerView.h new file mode 100644 index 000000000..2849c441e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/timers/TimerView.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerView + * Create: 2025-06-09 + */ + +#ifndef TIMER_VIEW_H +#define TIMER_VIEW_H + +#include "View.h" + +namespace OHOS { + enum TIMER_PAGES { + TIMER_MAIN_PAGE = 1, // 主页面 + TIMER_SETTING_PAGE, // 自定义页面 + TIMER_TIMING_PAGE, // 显示计时页面 + TIMER_ALL_VIEW, + }; + + class TimerPresenter; + class TimerView : public View { + }; +} +#endif // TIMER_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/DataView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/DataView.h new file mode 100644 index 000000000..d22cc5576 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/DataView.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Data View + * Create: 2025-03-22 + */ + +#ifndef TRAINING_DATA_VIEW_H +#define TRAINING_DATA_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_canvas.h" +#include "components/ui_image_view.h" +#include "components/ui_view_group.h" + +namespace OHOS { +class DataView { +public: + DataView(); + ~DataView(); + static DataView *GetInstance(); + UIViewGroup *InitShowUpView(void); + void UpdateDataViewByType(); + +private: + void ShowupBackgroup(); + void ShowupTopView(); + void ShowupLeftView(); + void ShowupRightView(); + void ShowupBottomView(); + void ShowupSepLine(); + UIImageView *backGround{nullptr}; + UIImageView *heartrate{nullptr}; + UICanvas *sepLine{nullptr}; + UILabel *topValueLabel{nullptr}; + UILabel *topUnitLabel{nullptr}; + UILabel *leftValueLabel{nullptr}; + UILabel *leftUnitLabel{nullptr}; + UILabel *rightValueLabel{nullptr}; + UILabel *rightUnitLabel{nullptr}; + UILabel *bottomValueLabel{nullptr}; + UILabel *bottomUnitLabel{nullptr}; + UIViewGroup *group{nullptr}; +}; +} // namespace OHOS +#endif // TRAINING_DATA_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/MenuView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/MenuView.h new file mode 100644 index 000000000..02bd72eb0 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/MenuView.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Menu View + * Create: 2025-03-22 + */ + +#ifndef TRAINING_MENU_VIEW_H +#define TRAINING_MENU_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_view_group.h" +#include "training/TrainingItemView.h" +#include "training/TrainingAdapter.h" +#include "UiConfig.h" +namespace OHOS { +enum TrainingTypes : uint8_t { + TRAINING_TYPE_OUTDOOR_RUNNING = 0, + TRAINING_TYPE_INDOOR_RUNNING, + TRAINING_TYPE_CYCLING, + TRAINING_TYPE_CLIMBING, + TRAINING_TYPE_INDOOR_SWIMMING, + TRAINING_TYPE_OUTDOOR_SWIMMING, + TRAINING_TYPE_MAX, +}; + +#define TRAINING_ITEM_OUTDOOR_RUNNING "trainingItemOutdoorRunning" +#define TRAINING_ITEM_INDOOR_RUNNING "trainingItemIndoorRunning" +#define TRAINING_ITEM_CYCLING "trainingItemCycling" +#define TRAINING_ITEM_CLIMBING "trainingItemClimbing" +#define TRAINING_ITEM_INDOOR_SWIMMING "trainingItemIndoorSwimming" +#define TRAINING_ITEM_OUTDOOR_SWIMMING "trainingItemOutdoorSwimming" + +class MenuView { +public: + MenuView(); + ~MenuView(); + static MenuView *GetInstance(); + UIViewGroup *InitShowUpView(void); + +private: + void CreateUILabel(void); + void CreateUIList(void); + UILabel *titleLabel{nullptr}; + UIList *trainingList{nullptr}; + TrainingAdapter *listAdapter_{nullptr}; + UIViewGroup *group{nullptr}; + TrainingItem trainings[TRAINING_TYPE_MAX] = { + {TRAINING_TYPE_OUTDOOR_RUNNING, PNG_APPLIST_WALK_IMAGE, "户外跑步", TRAINING_ITEM_OUTDOOR_RUNNING}, + {TRAINING_TYPE_INDOOR_RUNNING, PNG_APPLIST_WALK_IMAGE, "室内跑步", TRAINING_ITEM_INDOOR_RUNNING}, + {TRAINING_TYPE_CYCLING, PNG_APPLIST_WALK_IMAGE, "骑行", TRAINING_ITEM_CYCLING}, + {TRAINING_TYPE_CLIMBING, PNG_APPLIST_WALK_IMAGE, "登山", TRAINING_ITEM_CLIMBING}, + {TRAINING_TYPE_INDOOR_SWIMMING, PNG_APPLIST_WALK_IMAGE, "室内游泳", TRAINING_ITEM_INDOOR_SWIMMING}, + {TRAINING_TYPE_OUTDOOR_SWIMMING, PNG_APPLIST_WALK_IMAGE, "户外游泳", TRAINING_ITEM_OUTDOOR_SWIMMING}}; +}; +} // namespace OHOS +#endif // TRAINING_MENU_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/PauseView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/PauseView.h new file mode 100644 index 000000000..cde8714b7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/PauseView.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Pause View + * Create: 2025-03-22 + */ + +#ifndef TRAINING_PAUSE_VIEW_H +#define TRAINING_PAUSE_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" + +namespace OHOS { +#define TRAINING_PAUSE_CONTINUE_BUTTON "trainingPauseContinueButton" +#define TRAINING_PAUSE_FINISH_BUTTON "trainingPauseFinishButton" + +class PauseView { +public: + PauseView(); + ~PauseView(); + static PauseView *GetInstance(); + UIViewGroup *InitShowUpView(void); + +private: + void CreateUILabel(void); + void CreateUIButton(void); + UILabel *timeLabel{nullptr}; + UILabel *textLabel{nullptr}; + UILabelButton *continueButton{nullptr}; + UILabelButton *finishButton{nullptr}; + UIViewGroup *group{nullptr}; +}; +} // namespace OHOS +#endif // TRAINING_PAUSE_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/PrepareView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/PrepareView.h new file mode 100644 index 000000000..1805406ac --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/PrepareView.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Prepare View + * Create: 2025-03-22 + */ + +#ifndef TRAINING_PREPARE_VIEW_H +#define TRAINING_PREPARE_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" + +namespace OHOS { +#define TRAINING_PREPARE_START_BUTTON "trainingPrepareStartButton" +class PrepareView { +public: + PrepareView(); + ~PrepareView(); + static PrepareView *GetInstance(); + UIViewGroup *InitShowUpView(void); + void UpdateViewByTrainingType(uint8_t trainingType); + +private: + bool InitBatteryView(); + bool InitHeartbeatView(); + bool InitTimeLableVIew(); + bool InitLocatingLableVIew(); + bool InitCenterView(); + bool InitGPSView(); + bool InitHeartrateView(); + bool InitStartButtonView(); + UILabel *timeLabel{nullptr}; + UIImageView *battery{nullptr}; + UILabel *batteryLabel{nullptr}; + UIImageView *gpsImageView{nullptr}; + UILabel *gpsLabel{nullptr}; + UIImageView *heartRateImageView{nullptr}; + UILabel *heartRateLabel{nullptr}; + UILabel *locatingLabel{nullptr}; + UILabelButton *startButton{nullptr}; + UIButton *iconImageView{nullptr}; + UIViewGroup *group{nullptr}; +}; +} // namespace OHOS +#endif // TRAINING_PREPARE_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/PromptView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/PromptView.h new file mode 100644 index 000000000..7a1d38f0f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/PromptView.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Prompt View + * Create: 2025-03-22 + */ + +#ifndef PROMPT_VIEW_H +#define PROMPT_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_view_group.h" + +namespace OHOS { +#define TRAINING_PROMPT_CANCEL_BUTTON "trainingPromptCancelButton" +#define TRAINING_PROMPT_CONFIRM_BUTTON "trainingPromptConfirmButton" + +class PromptView { +public: + PromptView(); + ~PromptView(); + static PromptView *GetInstance(); + UIViewGroup *InitShowUpView(void); + +private: + void CreateUILabel(void); + void CreateUIButton(void); + UILabel *titleLabel{nullptr}; + UIButton *cancelButton{nullptr}; + UIButton *confirmButton{nullptr}; + UIViewGroup *group{nullptr}; +}; +} // namespace OHOS +#endif // PROMPT_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetAdapter.h new file mode 100644 index 000000000..74045cd7f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetAdapter.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TargetAdapter.h + * Author: + * Create: 2025-11-23 + */ + +#ifndef TARGET_ADAPTER_H +#define TARGET_ADAPTER_H + +#include +#include "training/TargetItemView.h" +#include "components/abstract_adapter.h" + +namespace OHOS { + +class TargetAdapter : public AbstractAdapter { +public: + explicit TargetAdapter(); + ~TargetAdapter() override; + + /* * + * @brief Sets the UIView adapter data, which is a SettingItem linked list. + * + * @param data Indicates the SettingItem linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(const std::list &data); + + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + uint16_t GetCount(void) override; + + UIView *GetView(UIView *inView, int16_t index) override; + + void AddListItem(const TargetItem &item); + + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } +private: + std::list listData_; + UIView::OnClickListener *itemClickListener{nullptr}; +}; +} + +#endif // TARGET_ADAPTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetItemView.h new file mode 100644 index 000000000..13c211fbe --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetItemView.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TargetItemView + * Author: + * Create: 2025-02-15 + */ + +#ifndef TARGET_ITEM_H +#define TARGET_ITEM_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t type; + const char *icon; + const char *label; + const char *viewId; +} TargetItem; + +class TargetItemView : public UIViewGroup { +public: + TargetItemView(); + ~TargetItemView() override; + + virtual void SetItemInfo(const TargetItem itemInfo); + +private: + bool InitView(); + UIImageView sIcon; + UILabel sLabel; + UIImageView sNextImage; + TargetItem sItemInfo = {0, nullptr, nullptr, nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetSettingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetSettingView.h new file mode 100644 index 000000000..69ed6f1e4 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetSettingView.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TargetSetting View + * Create: 2025-03-22 + */ + +#ifndef TRAINING_TARGET_SETTING_VIEW_H +#define TRAINING_TARGET_SETTING_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" +#include "components/ui_picker.h" + +namespace OHOS { +#define TARGET_SETTING_CONFIRM_BUTTON "targetSettingConfirmButton" + +class TargetSettingView { +public: + TargetSettingView(); + ~TargetSettingView(); + static TargetSettingView *GetInstance(); + UIViewGroup *InitShowUpView(void); + void UpdateViewByTargetType(uint8_t targetType); + +private: + void CreateUILabel(void); + void CreateUIPicker(void); + void CreateUIButton(void); + UILabel *titleLabel{nullptr}; + UIPicker *picker{nullptr}; + UILabelButton *confirmButton{nullptr}; + UIViewGroup *group{nullptr}; +}; +} // namespace OHOS +#endif // TRAINING_TARGET_SETTING_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetView.h new file mode 100644 index 000000000..14e71ed63 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TargetView.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Target View + * Create: 2025-03-22 + */ + +#ifndef TRAINING_TARGET_VIEW_H +#define TRAINING_TARGET_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_view_group.h" +#include "training/TargetItemView.h" +#include "training/TargetAdapter.h" +#include "UiConfig.h" +namespace OHOS { +enum TrainingTargets : uint8_t { + TRAINING_TARGET_DISTANCE = 0, + TRAINING_TARGET_TIME, + TRAINING_TARGET_CALORIE, + TRAINING_TARGET_MAX, +}; + +#define TRAINING_TARGET_ITEM_DISTANCE "trainingTargetItemDistance" +#define TRAINING_TARGET_ITEM_TIME "trainingTargetItemTime" +#define TRAINING_TARGET_ITEM_CALORIE "trainingTargetItemCalorie" + +class TargetView { +public: + TargetView(); + ~TargetView(); + static TargetView *GetInstance(); + UIViewGroup *InitShowUpView(void); + +private: + void CreateUILabel(void); + void CreateUIList(void); + UILabel *titleLabel{nullptr}; + UIList *targetList{nullptr}; + TargetAdapter *listAdapter_{nullptr}; + UIViewGroup *group{nullptr}; + TargetItem targets[TRAINING_TARGET_MAX] = { + {TRAINING_TARGET_DISTANCE, PNG_PHONE_IMAGE, "距离", TRAINING_TARGET_ITEM_DISTANCE}, + {TRAINING_TARGET_TIME, PNG_WATCH_IMAGE, "时间", TRAINING_TARGET_ITEM_TIME}, + {TRAINING_TARGET_CALORIE, PNG_BLUETOOTH_IMAGE, "热量", TRAINING_TARGET_ITEM_CALORIE}}; +}; +} // namespace OHOS +#endif // TRAINING_TARGET_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingAdapter.h new file mode 100644 index 000000000..19b747c49 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingAdapter.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingAdapter.h + * Author: + * Create: 2025-11-23 + */ + +#ifndef TRAINING_ADAPTER_H +#define TRAINING_ADAPTER_H + +#include +#include "training/TrainingItemView.h" +#include "components/abstract_adapter.h" + +namespace OHOS { + +class TrainingAdapter : public AbstractAdapter { +public: + explicit TrainingAdapter(); + ~TrainingAdapter() override; + + /* * + * @brief Sets the UIView adapter data, which is a SettingItem linked list. + * + * @param data Indicates the SettingItem linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(const std::list &data); + + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + uint16_t GetCount(void) override; + + UIView *GetView(UIView *inView, int16_t index) override; + + void AddListItem(const TrainingItem &item); + + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } +private: + std::list listData_; + UIView::OnClickListener *itemClickListener{nullptr}; +}; +} + +#endif // TRAINING_ADAPTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingItemView.h new file mode 100644 index 000000000..7b863f997 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingItemView.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingItemView + * Author: + * Create: 2025-02-15 + */ + +#ifndef TRAINING_ITEM_H +#define TRAINING_ITEM_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t type; + const char *icon; + const char *label; + const char *viewId; +} TrainingItem; + +class TrainingItemView : public UIViewGroup { +public: + TrainingItemView(); + ~TrainingItemView() override; + + virtual void SetItemInfo(const TrainingItem itemInfo); + +private: + bool InitView(); + UIImageView sIcon; + UILabel sLabel; + UIImageView sSettingImage; + TrainingItem sItemInfo = {0, nullptr, nullptr, nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingModel.h new file mode 100644 index 000000000..32b122ce3 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingModel.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingModel.h + * Author: + * Create: 2025-11-23 + */ + +#ifndef TRAINING_MODEL_H +#define TRAINING_MODEL_H + +#include +namespace OHOS { +class TrainingModel { +public: + static TrainingModel &GetInstance(void); + void SetCurView(int16_t viewNum); + int16_t GetCurView(void); + void SetCurTrainingType(int8_t trainingType); + int8_t GetCurTrainingType(void); + +private: + TrainingModel(); + TrainingModel(const TrainingModel &); + TrainingModel &operator=(const TrainingModel &); + virtual ~TrainingModel(); + int16_t curView_{0}; + uint8_t trainingType_{0}; +}; +} + +#endif // TRAINING_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingPresenter.h new file mode 100644 index 000000000..b23bfcb35 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingPresenter.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingPresenter.h + * Author: + * Create: 2025-11-23 + */ + +#ifndef TRAINING_PRESENTER_H +#define TRAINING_PRESENTER_H + +#include "Presenter.h" +#include "training/TrainingView.h" +#include "training/TrainingModel.h" +#include "components/ui_view.h" + +namespace OHOS { +class TrainingView; +class TrainingPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + TrainingPresenter(); + ~TrainingPresenter() override; + static TrainingPresenter *GetInstance(); + + void OnResume() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void OnPause() override; +private: + void ClickStartButton(void); + void ClickCountineButton(void); + void ClickFinishButton(void); + void ClickCancelButton(void); + void ClickConfirmButton(void); + void TrainingSetting(uint8_t trainingType); + void StartTraining(uint8_t trainingType); + void SettingTarget(uint8_t targetType); + void EnterTarget(void); + void ConfirmTargetSetting(void); + TrainingModel *trainingModel_{nullptr}; +}; +} + +#endif // TRAINING_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingSettingAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingSettingAdapter.h new file mode 100644 index 000000000..b0c1d823f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingSettingAdapter.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingSettingAdapter.h + * Author: + * Create: 2025-11-23 + */ + +#ifndef TRAINING_SETTING_ADAPTER_H +#define TRAINING_SETTING_ADAPTER_H + +#include +#include "training/TrainingSettingItemView.h" +#include "components/abstract_adapter.h" + +namespace OHOS { + +class TrainingSettingAdapter : public AbstractAdapter { +public: + explicit TrainingSettingAdapter(); + ~TrainingSettingAdapter() override; + + /* * + * @brief Sets the UIView adapter data, which is a SettingItem linked list. + * + * @param data Indicates the SettingItem linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(const std::list &data); + + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + uint16_t GetCount(void) override; + + UIView *GetView(UIView *inView, int16_t index) override; + + void AddListItem(const TrainingSettingItem &item); + + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } +private: + std::list listData_; + UIView::OnClickListener *itemClickListener{nullptr}; +}; +} + +#endif // TRAINING_SETTING_ADAPTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingSettingItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingSettingItemView.h new file mode 100644 index 000000000..26a644259 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingSettingItemView.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingSettingItemView.h + * Author: + * Create: 2025-11-23 + */ + +#ifndef TRAINING_SETTING_ITEM_H +#define TRAINING_SETTING_ITEM_H + +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" + +namespace OHOS { +typedef struct { + uint8_t type; + const char *icon; + const char *label; + const char *viewId; +} TrainingSettingItem; + +class TrainingSettingItemView : public UIViewGroup { +public: + TrainingSettingItemView(); + ~TrainingSettingItemView() override; + + virtual void SetItemInfo(const TrainingSettingItem itemInfo); + +private: + bool InitView(); + UIImageView sIcon; + UILabel sLabel; + UIImageView sNextImage; + TrainingSettingItem sItemInfo = {0, nullptr, nullptr, nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingSettingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingSettingView.h new file mode 100644 index 000000000..deba904f9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingSettingView.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingSetting View + * Create: 2025-03-22 + */ + +#ifndef TRAINING_SETTING_VIEW_H +#define TRAINING_SETTING_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/ui_view_group.h" +#include "training/TrainingSettingItemView.h" +#include "training/TrainingSettingAdapter.h" +#include "UiConfig.h" + +namespace OHOS { +enum TrainingSettings : uint8_t { + TRAINING_SETTING_TARGET = 0, + TRAINING_SETTING_REMIND, + TRAINING_SETTING_MISTOUCH, + TRAINING_SETTING_DATA_DISPLAY, + TRAINING_SETTING_METRONOME, + TRAINING_SETTING_REMOVE, + TRAINING_SETTING_MAX, +}; + +#define TRAINING_SETTING_ITEM_TARGET "trainingSettingItemTarget" +#define TRAINING_SETTING_ITEM_REMIND "trainingSettingItemTargetRemind" +#define TRAINING_SETTING_ITEM_MISTOUCH "trainingSettingItemTargetMistouch" +#define TRAINING_SETTING_ITEM_DATA_DISPLAY "trainingSettingItemTargetDataDisplay" +#define TRAINING_SETTING_ITEM_METRONOME "trainingSettingItemTargetMetronome" +#define TRAINING_SETTING_ITEM_REMOVE "trainingSettingItemTargetRemove" + +class TrainingSettingView { +public: + TrainingSettingView(); + ~TrainingSettingView(); + static TrainingSettingView *GetInstance(); + UIViewGroup *InitShowUpView(void); + +private: + void CreateUILabel(void); + void CreateUIList(void); + UILabel *titleLabel{nullptr}; + UIList *settingList{nullptr}; + TrainingSettingAdapter *listAdapter_{nullptr}; + UIViewGroup *group{nullptr}; + TrainingSettingItem settings[TRAINING_SETTING_MAX] = { + {TRAINING_SETTING_TARGET, PNG_BLUETOOTH_IMAGE, "目标", TRAINING_SETTING_ITEM_TARGET}, + {TRAINING_SETTING_REMIND, PNG_WATCH_IMAGE, "提醒", TRAINING_SETTING_ITEM_REMIND}, + {TRAINING_SETTING_MISTOUCH, PNG_PHONE_IMAGE, "防误触", TRAINING_SETTING_ITEM_MISTOUCH}, + {TRAINING_SETTING_DATA_DISPLAY, PNG_BLUETOOTH_IMAGE, "数据显示", TRAINING_SETTING_ITEM_DATA_DISPLAY}, + {TRAINING_SETTING_METRONOME, PNG_WATCH_IMAGE, "节拍器", TRAINING_SETTING_ITEM_METRONOME}, + {TRAINING_SETTING_REMOVE, PNG_PHONE_IMAGE, "移除此运动", TRAINING_SETTING_ITEM_REMOVE}}; +}; +} // namespace OHOS +#endif // SETTING_SETTING_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingView.h new file mode 100644 index 000000000..8c1bbd9ba --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/training/TrainingView.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingViews View + * Create: 2025-03-22 + */ + +#ifndef TRAINING_VIEW_H +#define TRAINING_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "training/MenuView.h" +#include "training/PrepareView.h" +#include "training/DataView.h" +#include "training/PauseView.h" +#include "training/PromptView.h" +#include "training/TrainingSettingView.h" +#include "training/TargetView.h" +#include "training/TargetSettingView.h" + +namespace OHOS { +enum TrainingViews : uint8_t { + TRAINING_VIEW_MENU, + TRAINING_VIEW_PREPARE, + TRAINING_VIEW_DATA, + TRAINING_VIEW_PAUSE, + TRAINING_VIEW_PROMPT, + TRAINING_VIEW_SETTING, + TRAINING_VIEW_TARGET, + TRAINING_VIEW_TARGET_SETTING, + TRAINING_VIEW_MAX, +}; + +constexpr const char *MENU_VIEW_ID = "MenuViewID"; +constexpr const char *PREPARE_VIEW_ID = "PrepareViewID"; +constexpr const char *DATA_VIEW_ID = "DataViewID"; +constexpr const char *PAUSE_VIEW_ID = "PauseViewID"; +constexpr const char *PROMPT_VIEW_ID = "PromptViewID"; +constexpr const char *SETTING_VIEW_ID = "SettingViewID"; +constexpr const char *TARGET_VIEW_ID = "TargetViewID"; +constexpr const char *TARGET_SETTING_VIEW_ID = "TargetSettingViewID"; + +class TrainingPresenter; +class TrainingView : public View { +public: + TrainingView(); + ~TrainingView() override; + static TrainingView *GetInstance(); + + void OnStart() override; + void OnStop() override; + void ChangeView(int16_t hideView, int16_t showView); + +private: + UIViewGroup *container[TRAINING_VIEW_MAX]{nullptr}; + typedef bool (TrainingView::*PreprosssChangeView)(int16_t hideView, int16_t thisView); + PreprosssChangeView preProcessView[TRAINING_VIEW_MAX]; + bool CheckViewParam(int16_t hideView, int16_t showView); + MenuView *menuView{nullptr}; + PrepareView *prepareView{nullptr}; + DataView *dataView{nullptr}; + PauseView *pauseView{nullptr}; + PromptView *promptView{nullptr}; + TrainingSettingView *settingView{nullptr}; + TargetView *targetView{nullptr}; + TargetSettingView *targetSettingView{nullptr}; + bool ChangeMenuView(int16_t hideView, int16_t thisView); + bool ChangePrepareView(int16_t hideView, int16_t thisView); + bool ChangeDataView(int16_t hideView, int16_t thisView); + bool ChangePauseView(int16_t hideView, int16_t thisView); + bool ChangePromptView(int16_t hideView, int16_t thisView); + bool ChangeSettingView(int16_t hideView, int16_t thisView); + bool ChangeTargetView(int16_t hideView, int16_t thisView); + bool ChangeTargetSettingView(int16_t hideView, int16_t thisView); +}; +} +#endif // TRAINING_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uisample/include/UISampleModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/uisample/UISampleModel.h similarity index 89% rename from code/sdk/application/wearable/nativeapp/nativeui/uisample/include/UISampleModel.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/uisample/UISampleModel.h index 45028caf6..ea285b540 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/uisample/include/UISampleModel.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/uisample/UISampleModel.h @@ -12,7 +12,7 @@ #include #include "AppViewIDs.h" #include "UiConfig.h" -#include "UISamplePresenter.h" +#include "uisample/UISamplePresenter.h" namespace OHOS { class UISampleModel { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uisample/include/UISamplePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/uisample/UISamplePresenter.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/uisample/include/UISamplePresenter.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/uisample/UISamplePresenter.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uisample/include/UISampleView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/uisample/UISampleView.h similarity index 100% rename from code/sdk/application/wearable/nativeapp/nativeui/uisample/include/UISampleView.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/uisample/UISampleView.h diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/uiservice/ui_language.h b/code/sdk/application/wearable/nativeapp/nativeui/include/uiservice/ui_language.h new file mode 100644 index 000000000..4595d1013 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/uiservice/ui_language.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: Breath Ease + * Author: wangle + * Create: 2025-4-23 + */ +#ifndef UI_MANAGER_H +#define UI_MANAGER_H +#include +#include "main/AppGroupView.h" + +namespace OHOS { +class UILanguage { +public: + static const char* GetText(uint16_t textId); + static void SetLanguage(uint8_t id); + static void UpdateLanguage(); +private: + static bool RegisterGlobalManager(); +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uiservice/include/ui_service.h b/code/sdk/application/wearable/nativeapp/nativeui/include/uiservice/ui_service.h similarity index 97% rename from code/sdk/application/wearable/nativeapp/nativeui/uiservice/include/ui_service.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/uiservice/ui_service.h index a36e63d60..c4a0410d8 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/uiservice/include/ui_service.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/uiservice/ui_service.h @@ -46,7 +46,9 @@ typedef enum { BT_DISCONNECTED_TO_UI, UI_ADD_SLEEP_VETO, UI_RM_SLEEP_VETO, + UI_UPDATE_LANGUAGE, CONNECT_NEW_PHONE, + UI_OTA_UPDATE, } UiServiceMsgId; #define BUNDLE_NAME_LEN 128 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/videocard/include/VideoCard.h b/code/sdk/application/wearable/nativeapp/nativeui/include/videocard/VideoCard.h similarity index 91% rename from code/sdk/application/wearable/nativeapp/nativeui/videocard/include/VideoCard.h rename to code/sdk/application/wearable/nativeapp/nativeui/include/videocard/VideoCard.h index f717fc502..a119391a9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/videocard/include/VideoCard.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/videocard/VideoCard.h @@ -6,13 +6,13 @@ #define VIDEO_CARD_H #include -#include "DialDataBase.h" +#include "main/dial/DialDataBase.h" #include "components/ui_view_group.h" -#include "OnDialDataUpdateListener.h" +#include "main/dial/OnDialDataUpdateListener.h" #include "components/ui_card_page.h" #include "components/ui_lite_surface_view.h" #include "video_play_wrapper.h" -#include "DialView.h" +#include "main/dial/DialView.h" namespace OHOS { class VideoCard : public UICardPage { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherAdapter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherAdapter.h new file mode 100644 index 000000000..c94553bfa --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherAdapter.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: weather/WeatherAdapter.h + * Create: 2025-03-23 + */ + +#ifndef WEATHER_ADAPTER_H +#define WEATHER_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 "wearable_log.h" +#include "UiConfig.h" +#include "weather/WeatherModel.h" +#include "weather/WeatherItemView.h" + +namespace OHOS { +class WeatherAdapter : public AbstractAdapter { +public: + explicit WeatherAdapter(); + ~WeatherAdapter() override; + + /* * + * @brief Sets the UIView adapter data, which is a WeatherItem linked list. + * + * @param data Indicates the WeatherItem linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(std::list &data); + + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + uint16_t GetCount(void) override; + + UIView *GetView(UIView *inView, int16_t index) override; + + void AddListItem(const WeatherItem &item); + + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } +private: + std::list listData; + UIView::OnClickListener *itemClickListener{nullptr}; +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherItemView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherItemView.h new file mode 100644 index 000000000..13c19fa16 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherItemView.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherItemView + * Create: 2025-03-23 + */ + +#ifndef WEATHER_ITEM_VIEW_H +#define WEATHER_ITEM_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_canvas.h" + +#include "UiConfig.h" +#include "weather/WeatherModel.h" + +namespace OHOS { +class WeatherItemView : public UIViewGroup { +public: + explicit WeatherItemView(); + ~WeatherItemView() override; + virtual void SetItemInfo(const WeatherItem itemInfo); + virtual void SetUpChild(); + +private: + UILabel sLabel_1; + UIImageView sIcon; + UILabel sLabel_2; + UICanvas chartLine; + UIImageView sNextImage; + WeatherItem sItemInfo = {nullptr, nullptr, nullptr, false}; +}; +} + +#endif diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherMainPage.h b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherMainPage.h new file mode 100644 index 000000000..31a9ea0a5 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherMainPage.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherMainPage + * Created: 2025-4 + */ + +#ifndef WEATHER_MAIN_PAGE_H +#define WEATHER_MAIN_PAGE_H + +#include +#include "components/ui_label_button.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "weather/WeatherAdapter.h" +#include "weather/WeatherPresenter.h" +#include "SlicePage.h" +#include "UiConfig.h" +#include "weather/WeatherView.h" +namespace OHOS { +static constexpr int16_t LABEL_COUNT = 6; +class WeatherPresenter; +class WeatherMainPage : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + WeatherMainPage(); + ~WeatherMainPage() override; + + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + std::string FormatTime(bool falg, const std::string& inputStr); + void InitLabel(); + void InitImage(); + void InitWeatherImage(); +private: + bool flag = false; + int curWeather_code = 0; + CurWeather cur{nullptr}; + UIViewGroup *group = nullptr; + WeatherModel *weatherModel = nullptr; + UILabel *title[LABEL_COUNT]{nullptr}; + UILabel *labelTitle{nullptr}; + UIImageView *mainImg{nullptr}; + UIImageView *addressImg{nullptr}; + UIImageView *aroundImg = nullptr; + UIImageView *weatherImg{nullptr}; + UIImageView *ImageAir{nullptr}; + UIImageView *ImageHumidity{nullptr}; + UIImageView *ImagePageKey{nullptr}; +}; +} +#endif // SETTING_MAIN_PAGE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherModel.h b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherModel.h new file mode 100644 index 000000000..55d135a42 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherModel.h @@ -0,0 +1,185 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherModel + * Create: 2025-03-23 + */ + +#ifndef WEATHER_MODEL_H +#define WEATHER_MODEL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "cJSON.h" +#include "components/ui_image_view.h" +#include "common/image_cache_manager.h" +#include "main/LoadImg.h" +#include "ui_resource_weather.h" +#ifndef _WIN32 +#include "time64.h" +#endif +namespace OHOS { +static constexpr int16_t MIN_TO_HOUR = 60; +static constexpr int16_t HOURLY_SYSTEM = 24; +static constexpr int16_t WEATHER_COUNT = 24; +static constexpr int16_t WEATHER_HOUR = 12; +static constexpr int16_t SET_ZERO = 0; +static constexpr int16_t SET_ONE = 1; +static constexpr int16_t SET_TWO = 2; +static constexpr int16_t SET_THREE = 3; +static constexpr int16_t SET_FOUR = 4; +static constexpr int16_t SET_FIVE = 5; +static constexpr int16_t SET_SIX = 6; +static constexpr int16_t SET_SEVEN = 7; +static constexpr int16_t SET_EIGHT = 8; +static constexpr int16_t SET_NINE = 9; +static constexpr int16_t SET_TEN = 10; +static constexpr int16_t SET_TWELVE = 12; +static constexpr int16_t SET_FOURTEEN = 14; +static constexpr int16_t SET_HUNDRED = 100; +static constexpr int16_t START_YEAR = 1900; +static constexpr int16_t ARRAY_SIZE = 31; +static const uint16_t WEATHER_ITEM_COUNT = 10; + +const int bigWeatherImage[ARRAY_SIZE] = { + IMAGE_CONVERTER_TOOL_WEATHER00, // 0 + IMAGE_CONVERTER_TOOL_WEATHER01, // 1 + IMAGE_CONVERTER_TOOL_WEATHER02, // 2 + IMAGE_CONVERTER_TOOL_WEATHER03, // 3 + IMAGE_CONVERTER_TOOL_WEATHER04, // 4 + IMAGE_CONVERTER_TOOL_WEATHER05, // 5 + IMAGE_CONVERTER_TOOL_WEATHER06, // 6 + IMAGE_CONVERTER_TOOL_WEATHER07, // 7 + IMAGE_CONVERTER_TOOL_WEATHER08, // 8 + IMAGE_CONVERTER_TOOL_WEATHER09, // 9 + IMAGE_CONVERTER_TOOL_WEATHER10, // 10 + IMAGE_CONVERTER_TOOL_WEATHER11, // 11 + IMAGE_CONVERTER_TOOL_WEATHER12, // 12 + IMAGE_CONVERTER_TOOL_WEATHER13, // 13 + IMAGE_CONVERTER_TOOL_WEATHER14, // 14 + IMAGE_CONVERTER_TOOL_WEATHER15, // 15 + IMAGE_CONVERTER_TOOL_WEATHER16, // 16 + IMAGE_CONVERTER_TOOL_WEATHER17, // 17 + IMAGE_CONVERTER_TOOL_WEATHER18, // 18 + IMAGE_CONVERTER_TOOL_WEATHER19, // 19 + IMAGE_CONVERTER_TOOL_WEATHER20, // 20 + IMAGE_CONVERTER_TOOL_WEATHER21, // 21 + IMAGE_CONVERTER_TOOL_WEATHER22, // 22 + IMAGE_CONVERTER_TOOL_WEATHER23, // 23 + IMAGE_CONVERTER_TOOL_WEATHER24, // 24 + IMAGE_CONVERTER_TOOL_WEATHER25, // 25 + IMAGE_CONVERTER_TOOL_WEATHER26, // 26 + IMAGE_CONVERTER_TOOL_WEATHER27, // 27 + IMAGE_CONVERTER_TOOL_WEATHER28, // 28 + IMAGE_CONVERTER_TOOL_WEATHER29, // 29 + IMAGE_CONVERTER_TOOL_WEATHER31 // 30 +}; + +const int smallWeatherImage[ARRAY_SIZE] = { + IMAGE_CONVERTER_TOOL_WEATHER32, // 32 + IMAGE_CONVERTER_TOOL_WEATHER33, // 33 + IMAGE_CONVERTER_TOOL_WEATHER34, // 34 + IMAGE_CONVERTER_TOOL_WEATHER35, // 35 + IMAGE_CONVERTER_TOOL_WEATHER36, // 36 + IMAGE_CONVERTER_TOOL_WEATHER37, // 37 + IMAGE_CONVERTER_TOOL_WEATHER38, // 38 + IMAGE_CONVERTER_TOOL_WEATHER39, // 39 + IMAGE_CONVERTER_TOOL_WEATHER40, // 40 + IMAGE_CONVERTER_TOOL_WEATHER41, // 41 + IMAGE_CONVERTER_TOOL_WEATHER42, // 42 + IMAGE_CONVERTER_TOOL_WEATHER43, // 43 + IMAGE_CONVERTER_TOOL_WEATHER44, // 44 + IMAGE_CONVERTER_TOOL_WEATHER45, // 45 + IMAGE_CONVERTER_TOOL_WEATHER46, // 46 + IMAGE_CONVERTER_TOOL_WEATHER47, // 47 + IMAGE_CONVERTER_TOOL_WEATHER48, // 48 + IMAGE_CONVERTER_TOOL_WEATHER49, // 49 + IMAGE_CONVERTER_TOOL_WEATHER50, // 50 + IMAGE_CONVERTER_TOOL_WEATHER51, // 51 + IMAGE_CONVERTER_TOOL_WEATHER52, // 52 + IMAGE_CONVERTER_TOOL_WEATHER53, // 53 + IMAGE_CONVERTER_TOOL_WEATHER54, // 54 + IMAGE_CONVERTER_TOOL_WEATHER55, // 55 + IMAGE_CONVERTER_TOOL_WEATHER56, // 56 + IMAGE_CONVERTER_TOOL_WEATHER57, // 57 + IMAGE_CONVERTER_TOOL_WEATHER58, // 58 + IMAGE_CONVERTER_TOOL_WEATHER59, // 59 + IMAGE_CONVERTER_TOOL_WEATHER60, // 60 + IMAGE_CONVERTER_TOOL_WEATHER61, // 61 + IMAGE_CONVERTER_TOOL_WEATHER62 // 62 +}; + +typedef struct { + const char *label_1; + const ImageInfo *icon; + const char *label_2; + bool hasSecondMenu; +} WeatherItem; + +typedef struct { + const char *min_degree; + const char *max_degree; + const char *address; + const char *weather_code; + const char *degree; + const char *updateTime; + const char *humidity; + std::string sunSet; + std::string sunRise; +} CurWeather; + +typedef struct { + const char *hour; + const char *degree; + const char *weather; +} HourWeather; +class WeatherModel { +public: + static WeatherModel &GetInstance(void); + bool InitWeatherItem(); + WeatherItem *GetWeatherlistItems(); + uint8_t GetWeatherListNum(); + CurWeather GetCurWeather(); + std::vector GetHourWeather(); + void InitFirstPageData(); + void InitSecondPageData(); + void InitThirdPageData(); + void UpdateTemp(); + bool InitVecForecast(cJSON *root); + bool InitVecObserve(cJSON *root); + bool InitVecRise(cJSON *root); + bool InitVecWeek(cJSON *root); + bool InitVecAddress(cJSON *root); + virtual ~WeatherModel(); + void SetDayStatus(const std::string &timeRise, const std::string &timeSet); + bool GetDayStatus(); + +private: + WeatherModel(); + WeatherModel(const WeatherModel &); + WeatherModel &operator=(const WeatherModel &); + int usedLen{0}; + int tempMinArray[WEATHER_ITEM_COUNT] = {0}; + int tempMaxArray[WEATHER_ITEM_COUNT] = {0}; + bool isDay; + CurWeather curWeather{nullptr}; + std::vector houWeather; + WeatherItem weather[WEATHER_ITEM_COUNT] = {nullptr, nullptr, nullptr, false}; + std::vector> vec_forecast_1h; + std::vector> vec_forecast_24h; + std::vector> vec_rise; + std::map map_observe; + std::map map_address; +}; +} + +#endif // Weather_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherPageSecond.h b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherPageSecond.h new file mode 100644 index 000000000..85638351d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherPageSecond.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageSecond + * Create: 2025-03-15 + */ + +#ifndef WEATHER_PAGESECOND_H +#define WEATHER_PAGESECOND_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_swipe_view.h" +#include "ui_swipe_view.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherView.h" +#include "SlicePage.h" +#include "UiConfig.h" +namespace OHOS { +class WeatherPresenter; +class WeatherPageSecond : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UISwipeView::OnSwipeListener { +public: + WeatherPageSecond(); + ~WeatherPageSecond() override; + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void OnSwipe(UISwipeView &view) override; + void WeatherInit(UIViewGroup *group); + void InitLabel(UIViewGroup *group, int count); + void InitImage(UIViewGroup *group, int count); + bool SetSwipeInter(); + void InitVecWeather(); +private: + WeatherModel *weatherModel = nullptr; + std::vector houWeather; + UISwipeView *weatherSwipeGroup = nullptr; + UIViewGroup *swipeGroup[SET_THREE]{nullptr}; + UIImageView *imgBack[SET_EIGHT]{nullptr}; + UILabel *labelTime[SET_EIGHT]{nullptr}; + UILabel *labelTemp[SET_EIGHT]{nullptr}; + UIImageView *imgWeather[SET_EIGHT]{nullptr}; + UIImageView *mainImg{nullptr}; + UIImageView *ImagePageKey{nullptr}; + int index = 0; // 记录当前是第几个swipe +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherPageThird.h b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherPageThird.h new file mode 100644 index 000000000..a7f72f9e7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherPageThird.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageThird + * Create: 2025-03-15 + */ + +#ifndef WEATHER_PAGETHIRD_H +#define WEATHER_PAGETHIRD_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "components/ui_swipe_view.h" +#include "main/AppGroupView.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherAdapter.h" +#include "SlicePage.h" +#include "UiConfig.h" +namespace OHOS { +class WeatherPageThird : public SlicePage, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UISwipeView::OnSwipeListener { +public: + WeatherPageThird(); + ~WeatherPageThird() override; + void OnStart(void* data) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + void OnSwipe(UISwipeView &view) override; + void InitScrollView(); + bool InitScrollData(); + void RefreshWeathersList(const WeatherItem *item, uint8_t count); +private: + WeatherModel *weatherModel = nullptr; + UIViewGroup *group = nullptr; + UIList *contentList{nullptr}; + UILabel *title{nullptr}; + WeatherAdapter *listAdapter{nullptr}; + UIImageView *mainImg{nullptr}; + UIImageView *ImagePageKey{nullptr}; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherPresenter.h new file mode 100644 index 000000000..6cb6bf1ad --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherPresenter.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPresenter + * Create: 2025-11-23 + */ + +#ifndef WEATHER_PRESENTER_H +#define WEATHER_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" +#include "weather/WeatherModel.h" +namespace OHOS { +class WeatherView; +class WeatherPresenter : public Presenter {}; +} + +#endif // Weather_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherView.h b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherView.h new file mode 100644 index 000000000..4c2e46906 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/include/weather/WeatherView.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherView + * Create: 2025-11-23 + */ + +#ifndef WEATHER_VIEW_H +#define WEATHER_VIEW_H + +#include "View.h" +namespace OHOS { +enum WEATHER_PAGES { + WEATHER_MAIN_PAGE = 1, // 0 is invalid + WEATHER_SECOND_PAGE = 2, + WEATHER_THIRD_PAGE = 3, +}; + +class WeatherPresenter; +class WeatherView : public View {}; +} +#endif // Weather_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/CustomizationView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/CustomizationView.cpp index 4e3e637ea..0546bb8c0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/CustomizationView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/CustomizationView.cpp @@ -4,8 +4,8 @@ * Create: 2022-03-02 */ -#include "CustomizationView.h" -#include "IndoorWalkPresenter.h" +#include "indoorwalk/CustomizationView.h" +#include "indoorwalk/IndoorWalkPresenter.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkEndView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkEndView.cpp index bcaa1e761..cbb22c343 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkEndView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkEndView.cpp @@ -4,8 +4,8 @@ * Create: 2022-03-02 */ -#include "IndoorWalkEndView.h" -#include "IndoorWalkPresenter.h" +#include "indoorwalk/IndoorWalkEndView.h" +#include "indoorwalk/IndoorWalkPresenter.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkModel.cpp index 4afd157fd..42786d830 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkModel.cpp @@ -4,8 +4,8 @@ * Create: 2022-03-02 */ -#include "IndoorWalkModel.h" -#include "IndoorWalkPresenter.h" +#include "indoorwalk/IndoorWalkModel.h" +#include "indoorwalk/IndoorWalkPresenter.h" #include "ohos_timer.h" #include "graphic_timer.h" @@ -293,7 +293,7 @@ void InitIndoorWalkTimer() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "IndoorWalkModel::IndoorWalkTimer already exists!!"); return; } - uint32 tick = GetOSTick(MS_ONE_SECONDS); + uint32_t tick = GetOSTick(MS_ONE_SECONDS); g_startCounting = new GraphicTimer(tick, IndoorWalkTimerCallback, nullptr, true); if (g_startCounting == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "IndoorWalkModel::IndoorWalkTimer new GraphicTimer failed!!"); 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 a3350f28e..4e88d67e0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp @@ -4,13 +4,13 @@ * Create: 2022-03-02 */ -#include "IndoorWalkMotionView.h" -#include "IndoorWalkPresenter.h" +#include "indoorwalk/IndoorWalkMotionView.h" +#include "indoorwalk/IndoorWalkPresenter.h" #include "wearable_log.h" #include "UiConfig.h" -#include "ScreenModels.h" -#include "ActivityModel.h" -#include "IndoorWalkModel.h" +#include "screensetting/ScreenModels.h" +#include "activity/ActivityModel.h" +#include "indoorwalk/IndoorWalkModel.h" #include namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkPreparedView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkPreparedView.cpp index 6f3efcd2b..709ab2845 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkPreparedView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkPreparedView.cpp @@ -4,9 +4,9 @@ * Create: 2022-03-02 */ -#include "IndoorWalkPreparedView.h" -#include "IndoorWalkPresenter.h" -#include "ScreenModels.h" +#include "indoorwalk/IndoorWalkPreparedView.h" +#include "indoorwalk/IndoorWalkPresenter.h" +#include "screensetting/ScreenModels.h" #include "ui_resource_image.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp index 9ea8f6055..fcffcc433 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp @@ -4,14 +4,14 @@ * Create: 2022-03-02 */ -#include "IndoorWalkPresenter.h" -#include "IndoorWalkView.h" -#include "IndoorWalkModel.h" +#include "indoorwalk/IndoorWalkPresenter.h" +#include "indoorwalk/IndoorWalkView.h" +#include "indoorwalk/IndoorWalkModel.h" #include "drag_event.h" #include "UiConfig.h" #include "wearable_log.h" #include -#include "ActivityModel.h" +#include "activity/ActivityModel.h" #include "NativeRegisterManager.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkView.cpp index 0308e9864..4cbdb8eb5 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/IndoorWalkView.cpp @@ -4,8 +4,8 @@ * Create: 2022-03-02 */ -#include "IndoorWalkView.h" -#include "IndoorWalkModel.h" +#include "indoorwalk/IndoorWalkView.h" +#include "indoorwalk/IndoorWalkModel.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFifth.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFifth.cpp index a3da2bbde..7c41f0fa2 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFifth.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFifth.cpp @@ -3,7 +3,7 @@ * Description: Motion PageFifth View * Create: 2022-03-02 */ -#include "MotionPageFifth.h" +#include "indoorwalk/MotionPageFifth.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFirst.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFirst.cpp index c16b941d5..0975cbedb 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFirst.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFirst.cpp @@ -4,9 +4,9 @@ * Create: 2022-03-02 */ -#include "MotionPageFirst.h" -#include "IndoorWalkPresenter.h" -#include "IndoorWalkModel.h" +#include "indoorwalk/MotionPageFirst.h" +#include "indoorwalk/IndoorWalkPresenter.h" +#include "indoorwalk/IndoorWalkModel.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFourth.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFourth.cpp index a43ab8ff6..8ea8febb0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFourth.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageFourth.cpp @@ -3,9 +3,9 @@ * Description: Motion PageFourth View * Create: 2022-03-02 */ -#include "MotionPageFourth.h" -#include "IndoorWalkPresenter.h" -#include "IndoorWalkModel.h" +#include "indoorwalk/MotionPageFourth.h" +#include "indoorwalk/IndoorWalkPresenter.h" +#include "indoorwalk/IndoorWalkModel.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageSecond.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageSecond.cpp index 34e136df5..33fc94f8c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageSecond.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageSecond.cpp @@ -3,9 +3,9 @@ * Description: Motion PageSecond View * Create: 2022-03-02 */ -#include "MotionPageSecond.h" -#include "IndoorWalkPresenter.h" -#include "IndoorWalkModel.h" +#include "indoorwalk/MotionPageSecond.h" +#include "indoorwalk/IndoorWalkPresenter.h" +#include "indoorwalk/IndoorWalkModel.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageThird.cpp b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageThird.cpp index 668d78cd4..d6730e95b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageThird.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/indoorwalk/src/MotionPageThird.cpp @@ -3,9 +3,9 @@ * Description: Motion PageThird View * Create: 2022-03-02 */ -#include "MotionPageThird.h" -#include "IndoorWalkPresenter.h" -#include "IndoorWalkModel.h" +#include "indoorwalk/MotionPageThird.h" +#include "indoorwalk/IndoorWalkPresenter.h" +#include "indoorwalk/IndoorWalkModel.h" #include "wearable_log.h" #include "UiConfig.h" 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 871138f01..9f8ecd313 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/key/src/KeyInputListener.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/key/src/KeyInputListener.cpp @@ -5,19 +5,19 @@ * Create: 2021-09-18 */ -#include "KeyInputListener.h" +#include "key/KeyInputListener.h" #include "common/key_code.h" #include "AppViewIDs.h" #include "View.h" -#include "MainViewSample.h" +#include "main/MainViewSample.h" #include "wearable_log.h" #include "UiConfig.h" #include "dock/input_device.h" #include "notification_manager.h" -#include "AlarmPopUpPresenter.h" -#include "CallerLogModel.h" -#include "MainCallingPresenter.h" -#include "ApplistModel.h" +#include "alarm/AlarmPopUpPresenter.h" +#include "callerlog/CallerLogModel.h" +#include "makephone/MainCallingPresenter.h" +#include "applist/ApplistModel.h" namespace OHOS { static bool IsNotifyCallStatus() @@ -137,8 +137,8 @@ void KeyInputListener::OnKeyRelease(const KeyEvent& event) NotificationManager::GetInstance()->GetWatchCallStatus()) { // 音量卡片 // 音量- CallVolumeDipSwitchControl(VOLUMEDOWN); - } else { - // 切换到用户配置的快捷卡片 + } else if (currentViewId != VIEW_RECENT_APP) { + NativeAbility::GetInstance().ChangeSlice(VIEW_RECENT_APP); } } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/HealthModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/HealthModel.cpp index d61182de7..5f0b22d3a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/HealthModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/HealthModel.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "HealthModel.h" +#include "main/HealthModel.h" #include #include #include diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/LoadImg.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/LoadImg.cpp new file mode 100644 index 000000000..5586182b5 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/LoadImg.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: LoadImg + * Author: + * Create: 2025-06-05 + */ + +#include "main/LoadImg.h" + +namespace OHOS { +namespace LOADIMG { + +// 加载图片资源 +void LoadBtnImage(UIButton *btn, std::string file, uint32_t resId1, uint32_t resId2) +{ + ImageInfo *image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId1, file); + if (image1 == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId1 fail"); + return; + } + ImageInfo *image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId2, file); + if (image2 == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadBtnImage resId2 fail"); + return; + } + btn->SetImageSrc(image1, image2); +} + +void LoadImageViewImg(UIImageView *view, std::string file, uint32_t resId) +{ + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadImageViewImg %x fail", resId); + return; + } + view->SetSrc(image); + return; +} +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainModel.cpp index dc5b9e350..a84d1d7d5 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainModel.cpp @@ -6,11 +6,11 @@ */ #include "unistd.h" -#include "MainModel.h" +#include "main/MainModel.h" #include "kv_store.h" #include "securec.h" #include "wearable_log.h" -#include "DialBinTypesV2.h" +#include "main/DialBinTypesV2.h" #include "power_display_service.h" namespace OHOS { @@ -198,6 +198,9 @@ namespace OHOS { return; } + if (dialSetting.dialFlag == 0) { + return; + } setValue = strtok_s(nullptr, ",", &setBuffer); if (setValue != nullptr) { dialSetting.dialFullName = setValue; 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 ca40fa472..434c85e11 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp @@ -5,15 +5,13 @@ * Create: 2021-10-18 */ -#include "MainPresenterSample.h" +#include "main/MainPresenterSample.h" #include "common/task_manager.h" -#include "HeartRateView.h" -#include "PlayersModel.h" -#include "PlayersPresenter.h" -#include "MainCompassPresenter.h" +#include "heartrate/HeartRateView.h" +#include "player/PlayersModel.h" +#include "player/PlayersPresenter.h" #include "NativeRegisterManager.h" -#include "CompassModel.h" -#include "CompassCalibrationView.h" +#include "compass/CompassModel.h" #include "drag_event.h" #include "graphic_service.h" #include "wearable_log.h" @@ -21,10 +19,10 @@ #include "ui_resource_image.h" #include #include -#include "ModelDialDataFactory.h" -#include "DialModelTime.h" -#include "DialViewGroup.h" -#include "ui_service.h" +#include "main/dial/ModelDialDataFactory.h" +#include "main/dial/DialModelTime.h" +#include "main/dial/DialViewGroup.h" +#include "uiservice/ui_service.h" #include "PageTransitionMgr.h" namespace OHOS { @@ -73,7 +71,6 @@ void MainPresenterSample::OnStart() void MainPresenterSample::OnPause() { - Presenter::OnPause(); // Save watchface content for slide back UIView* watchFace = view_->GetViewById(WATCH_FACE)->GetParent(); uint8_t opaScale = watchFace->GetOpaScale(); @@ -91,7 +88,6 @@ void MainPresenterSample::OnPause() void MainPresenterSample::OnResume(void) { - Presenter::OnResume(); mainPresenterState_ = MainPresenterState::RESUME; // Set current page again to invoke OnActive method. uint8_t curCardId = view_->GetHorCurrentCard(); @@ -263,21 +259,10 @@ void MainPresenterSample::SetCircleProgress() } } -void MainPresenterSample::SetCompassRotate() -{ - bool status = CompassModel::GetInstance()->GetCalibrationStatus(); - dynamic_cast(view_->GetViewById(COMPASS))->SetCalibrationView(status); - if (!status) { - DetermineToRotate(); - } -} - void MainPresenterSample::Notify(void) { CardId cardId = view_->GetHorCurrentCard(); - if (cardId == COMPASS) { - SetCompassRotate(); - } else if (cardId == MUSIC_PLAYER) { + if (cardId == MUSIC_PLAYER) { SetCircleProgress(); } else if (cardId == WATCH_FACE) { DialSetting &setting = 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 b6c882643..0133239e3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp @@ -5,9 +5,10 @@ * Create: 2021-10-18 */ #include "wearable_log.h" -#include "MainViewSample.h" +#include "main/MainViewSample.h" #include "graphic_service.h" #include "common/image_cache_manager.h" +#include "UICardPageFactory.h" namespace OHOS { static MainViewSample *g_pMainView = nullptr; @@ -271,12 +272,7 @@ UICardPage *MainViewSample::InitWatchOffDial(DialSetting &setting) UICardPage *MainViewSample::InitWatchDial(DialSetting &setting) { - switch (setting.dialId) { - case DIAL_CLOCK: - return new MainClockView(); - default: - return nullptr; - } + return UICardPageFactory::GetInstance().CreateWatchDial(DIAL_DISPLAY_MODE_MAIN, setting.dialId); } UICardPage *MainViewSample::InitWatchFacePage(void) diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageAdapter.cpp new file mode 100644 index 000000000..8d5748cec --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageAdapter.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MessageAdapter.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "main/MessageAdapter.h" + +namespace OHOS { +MessageAdapter::MessageAdapter() {} + +MessageAdapter::~MessageAdapter() +{ + listData.clear(); +} + +uint16_t MessageAdapter::GetCount(void) +{ + return listData.size(); +} + +void MessageAdapter::SetData(std::list &data) +{ + if (!listData.empty()) { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) { + listData.push_back(*it); + } +} + +UIView *MessageAdapter::GetView(UIView *inView, int16_t index) +{ + if (listData.empty()) { + return nullptr; + } + if (index < 0) { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData.size()) { + return nullptr; + } + + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) { + it++; + } + MessageItem itemData = *it; + MessageItemView *item = nullptr; + if (inView == nullptr) { + item = new MessageItemView(); + } else { + item = static_cast(inView); + } + + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + return item; +} + +void MessageAdapter::AddListItem(const MessageItem &item) +{ + listData.push_back(item); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "listData == %d-------zsy", listData.size()); + for (const auto& item : listData) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageItem.App == %s-------zsy", item.label_1.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageItem.Content == %s-------zsy", item.label_2.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageItem.Info == %s-------zsy", item.label_3.c_str()); + } +} + +void MessageAdapter::ClearListItem() +{ + listData.clear(); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageItemView.cpp new file mode 100644 index 000000000..db7e81e5d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageItemView.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MessageItemView.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "wearable_log.h" +#include "main/MessageItemView.h" + +namespace OHOS { + static constexpr int16 SETTING_ICON_X = 20; + static constexpr int16 NUM_22 = 22; + static constexpr int16_t SETTING_ITEM_BUTTON_HEIGHT = 80; + static constexpr int16_t SETTING_ITEM_LABEL_WIDTH = 155; + static constexpr int16_t SETTING_ITEM_LABEL_HEIGHT = 100; + static constexpr int16 SETTING_ITEM_FONT_SIZE = 35; + static constexpr int16_t SETTINGS_RESIZE_SIZE = 100; + static constexpr int16_t SETTING_SICON_Y = 15; + static constexpr int16 NUMS_2 = 2; + static constexpr int16 NUMS_50 = 50; + + MessageItemView::MessageItemView() + { + SetPosition(0, 0, HORIZONTAL_RESOLUTION, 200); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetTouchable(true); + SetUpChild(); + + Add(&sback); + Add(&sLabel_1); + Add(&sIcon); + Add(&sLabel_2); + Add(&sLabel_3); + } + + MessageItemView::~MessageItemView() + { + Remove(&sIcon); + Remove(&sLabel_1); + Remove(&sLabel_2); + Remove(&sLabel_3); + Remove(&sback); + } + + void MessageItemView::SetItemInfo(const MessageItem itemInfo) + { + sItemInfo = itemInfo; + sLabel_1.SetText(itemInfo.label_1.c_str()); + sIcon.SetSrc(itemInfo.icon.c_str()); + sLabel_2.SetText(itemInfo.label_2.c_str()); + sLabel_3.SetText(itemInfo.label_3.c_str()); + } + + void MessageItemView::SetUpChild() + { + sLabel_1.SetPosition(50, 10); + sLabel_1.Resize(SETTING_ITEM_LABEL_WIDTH, 50); + sLabel_1.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ITEM_FONT_SIZE); + sLabel_1.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sLabel_1.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel_1.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel_1.SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + sLabel_1.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + sIcon.SetPosition(15, SETTING_SICON_Y); + sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + sLabel_2.SetPosition(15, 78); + sLabel_2.Resize(100, 50); + sLabel_2.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ITEM_FONT_SIZE); + sLabel_2.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sLabel_2.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel_2.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel_2.SetStyle(STYLE_BACKGROUND_COLOR, Color::Orange().full); + sLabel_2.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + sLabel_3.SetPosition(150, 78, 100, 50); + sLabel_3.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ITEM_FONT_SIZE); + sLabel_3.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sLabel_3.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel_3.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel_3.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + sLabel_3.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + sback.SetPosition(0, 0, 450, 180); + sback.SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); + sback.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageMainView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageMainView.cpp new file mode 100644 index 000000000..ed1000dd2 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageMainView.cpp @@ -0,0 +1,374 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: WeekStep + * Author: + * Create: 2021-09-11 + */ + +#include "main/MessageMainView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "common/screen.h" +#include "main/MainPresenterSample.h" +#include "screensetting/ScreenModels.h" +#include "settings/SettingModel.h" +#include "ui_resource_image.h" + +namespace OHOS { + +static MessageMainView *g_pMessageMainView = nullptr; + +constexpr int16_t DISTURB_IMG_X = 117; +constexpr int16_t DISTURB_IMG_Y = 50; +constexpr int16_t SCREEN_IMG_X = 251; +constexpr int16_t SCREEN_IMG_Y = 50; +constexpr int16_t PHONE_IMG_X = 49; +constexpr int16_t PHONE_IMG_Y = 184; +constexpr int16_t ALARM_IMG_X = 184; +constexpr int16_t ALARM_IMG_Y = 184; +constexpr int16_t SETTING_IMG_X = 319; +constexpr int16_t SETTING_IMG_Y = 184; + +constexpr int16_t BLUETOOTH_IMG_X = 145; +constexpr int16_t BLUETOOTH_IMG_Y = 335; +constexpr int16_t BATTERY_IMG_X = 195; +constexpr int16_t BATTERY_IMG_Y = 340; + +constexpr int16_t DISTURB_LABEL_X = 136; +constexpr int16_t DISTURB_LABEL_Y = 145; +constexpr int16_t SCREEN_LABEL_X = 270; +constexpr int16_t SCREEN_LABEL_Y = 145; +constexpr int16_t PHONE_LABEL_X = 68; +constexpr int16_t PHONE_LABEL_Y = 279; +constexpr int16_t ALARM_LABEL_X = 203; +constexpr int16_t ALARM_LABEL_Y = 279; +constexpr int16_t SETTING_LABEL_X = 338; +constexpr int16_t SETTING_LABEL_Y = 279; + +constexpr int16_t BATTERY_LABEL_X = 247; +constexpr int16_t BATTERY_LABEL_Y = 335; +constexpr int16_t DATE_LABEL_X = 173; +constexpr int16_t DATE_LABEL_Y = 374; + +constexpr int16_t FONT_DEFAULT_SIZE = 24; +constexpr int16_t TEXT_WIDTH = 86; +constexpr int16_t TEXT_HEIGHT = 30; + +constexpr int16_t NONOTICE_LABLE_X = 141; +constexpr int16_t NONOTICE_LABLE_Y = 212; + +MessageMainView::MessageMainView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainView::MessageMainView"); + g_pMessageMainView = this; +} + +MessageMainView::~MessageMainView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainView::~MessageMainView"); + RemoveAll(); + delete messageLables; + messageLables = nullptr; + delete messageLable; + messageLable = nullptr; + delete deletereminder; + deletereminder = nullptr; + delete confirm; + confirm = nullptr; + delete cancel; + cancel = nullptr; + delete notice; + notice = nullptr; + delete contentList; + contentList = nullptr; + if (listAdapter != nullptr) { + delete listAdapter; + listAdapter = nullptr; + } + g_pMessageMainView = nullptr; + MessageModel::GetInstance().SetViewStatus(false); +} + +MessageMainView *MessageMainView::GetInstance(void) +{ + return g_pMessageMainView; +} + +bool MessageMainView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainView::InitView"); + messageLable = new UILabel(); + if (messageLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLable new fail"); + return false; + } + messageLable->SetPosition(175, 20, 100, 30); + messageLable->SetText("通知"); + messageLable->SetAlign(TEXT_ALIGNMENT_CENTER); + messageLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); + messageLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + messageLable->SetViewId("Notify"); + messageLable->SetTouchable(true); + notifyListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + messageLable->SetOnClickListener(notifyListener); + // 删除图标 + notice = new UIImageView(); + if (notice == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerTimingView:: new startButton fail"); + return false; + } + notice->SetPosition(175, 330); + notice->Resize(100, 100); + notice->SetSrc(ALARM_TRUE_ADD_PATH); + notice->SetViewId("Delete"); + notice->SetTouchable(true); + clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + notice->SetOnClickListener(clickListener); + ShowMessageList(); + InitScrollData(); + Add(messageLable); + Add(notice); + return true; +} + +void MessageMainView::PreLoad(void) +{ + if (! MessageModel::GetInstance().GetViewStatus()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageMainView::PreLoad,viewiInitStatus == false"); + InitView(); + DeletionView(); + NoNotify(); + const std::vector itemInfo = MessageModel::GetInstance().GetMessagelistItems(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageMainView::PreLoad,itemInfo == %d", itemInfo.size()); + if (itemInfo.size() == 0) { + messageLable->SetVisible(false); + notice->SetVisible(false); + contentList->SetVisible(false); + deletereminder->SetVisible(false); + confirm->SetVisible(false); + cancel->SetVisible(false); + messageLables->SetVisible(true); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageMainView::PreLoad,itemInfo.size() == 0"); + } else { + messageLable->SetVisible(true); + notice->SetVisible(true); + contentList->SetVisible(true); + deletereminder->SetVisible(false); + confirm->SetVisible(false); + cancel->SetVisible(false); + messageLables->SetVisible(false); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageMainView::PreLoad,itemInfo.size() != 0"); + } + MessageModel::GetInstance().SetViewStatus(true); + } +} + +void MessageMainView::ShowMessageList(void) +{ + contentList = new UIList(); + if (contentList == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainView::ShowMessageList contentList is nullptr"); + return; + } + contentList->SetPosition(32, 70); + contentList->Resize(HORIZONTAL_RESOLUTION, 318); // 364: height + contentList->SetSelectPosition(120); // middle position + contentList->SetDraggable(true); + contentList->SetThrowDrag(true); + contentList->EnableAutoAlign(true); + contentList->SetElastic(true); + Add(contentList); +} + +void MessageMainView::ConfirmDeletion(void) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageMainView::ConfirmDeletion"); + if (notice->IsVisible()) { + notice->SetVisible(false); + } + if (messageLable->IsVisible()) { + messageLable->SetVisible(false); + } + if (contentList->IsVisible()) { + contentList->SetVisible(false); + } + if (! deletereminder->IsVisible()) { + deletereminder->SetVisible(true); + } + if (! confirm->IsVisible()) { + confirm->SetVisible(true); + } + if (! cancel->IsVisible()) { + cancel->SetVisible(true); + } +} + +void MessageMainView::NewNotify(void) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageMainView::NewNotify"); + if (messageLables->IsVisible()) { + messageLables->SetVisible(false); + } + if (! notice->IsVisible()) { + notice->SetVisible(true); + } + if (! messageLable->IsVisible()) { + messageLable->SetVisible(true); + } + if (! contentList->IsVisible()) { + contentList->SetVisible(true); + } +} + +void MessageMainView::DeletionView(void) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageMainView::DeletionView"); + // 标题 + deletereminder = new UILabel(); + if (deletereminder == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deletereminder new fail"); + return; + } + deletereminder->SetPosition(177, 145); // widget's left position and top position + deletereminder->Resize(260, 204); // widget's width and height + deletereminder->SetViewId("deletereminder");// Set style + + // Set additional property + deletereminder->SetText("是否删除通知?"); + deletereminder->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + deletereminder->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + deletereminder->SetRollSpeed(0); + + // 确认按钮 + confirm = new UILabelButton(); + if (confirm == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "confirm new fail"); + return; + } + confirm->SetPosition(88, 255); // widget's left position and top position + confirm->Resize(70, 50); // widget's width and height + confirm->SetViewId("Confirm");// Set style + + // Set additional property + confirm->SetText("确认"); + confirm->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 16); + confirm->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + confirmListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + confirm->SetOnClickListener(confirmListener); + + // 取消按钮 + cancel = new UILabelButton(); + if (cancel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cancel new fail"); + return; + // cancel = new UILabelButton(); + } + cancel->SetPosition(301, 251); // widget's left position and top position + cancel->Resize(70, 50); // widget's width and height + cancel->SetViewId("Cancel");// Set style + + // Set additional property + cancel->SetText("取消"); + cancel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 16); + cancel->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + cancelListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + cancel->SetOnClickListener(cancelListener); + Add(deletereminder); + Add(confirm); + Add(cancel); +} + +void MessageMainView::VerticalViewInits(void) +{ + if (deletereminder->IsVisible()) { + deletereminder->SetVisible(false); + } + if (confirm->IsVisible()) { + confirm->SetVisible(false); + } + if (cancel->IsVisible()) { + cancel->SetVisible(false); + } + if (! messageLables->IsVisible()) { + messageLables->SetVisible(true); + } +} + +void MessageMainView::NoNotify(void) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageMainView::NoNotify"); + messageLables = new UILabel(); + if (messageLables == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLable new fail"); + return; + } + messageLables->SetPosition(177, 212, 100, 30); + messageLables->SetText("无消息"); + messageLables->SetAlign(TEXT_ALIGNMENT_CENTER); + messageLables->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); + messageLables->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + messageLables->SetViewId("NoNotify"); + messageLables->SetTouchable(true); + newNotifyListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + messageLables->SetOnClickListener(newNotifyListener); + Add(messageLables); +} + +void MessageMainView::CancelDeletion(void) +{ + if (deletereminder->IsVisible()) { + deletereminder->SetVisible(false); + } + if (confirm->IsVisible()) { + confirm->SetVisible(false); + } + if (cancel->IsVisible()) { + cancel->SetVisible(false); + } + if (! messageLable->IsVisible()) { + messageLable->SetVisible(true); + } + if (! notice->IsVisible()) { + notice->SetVisible(true); + } + if (! contentList->IsVisible()) { + contentList->SetVisible(true); + } +} + +void MessageMainView::RefreshMessageList(std::vector item) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainView::RefreshMessageList"); + if (listAdapter == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainView::RefreshMessageList listAdapter is nullptr"); + listAdapter = new MessageAdapter(); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainView::RefreshMessageList"); + if (item.size() == 0) { + return; + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainView::RefreshMessageList %d", item.size()); + listAdapter->ClearListItem(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "listAdapter->ClearListItem"); + for (size_t i = 0; i < item.size(); ++i) { + listAdapter->AddListItem(item[i]); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "listAdapter->AddListItem"); + } + } + if (contentList == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageMainView::contentList fail"); + return; + } + contentList->ScrollTo(0); + contentList->SetAdapter(listAdapter); + contentList->RefreshList(); +} + +bool MessageMainView::InitScrollData() +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageMainView::InitScrollData"); + const std::vector itemInfo = MessageModel::GetInstance().GetMessagelistItems(); + RefreshMessageList(itemInfo); + return true; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageModel.cpp new file mode 100644 index 000000000..8bbdf47f9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MessageModel.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "unistd.h" +#include "main/MessageModel.h" +#include "main/MessageMainView.h" +#include "kv_store.h" +#include "securec.h" +#include "wearable_log.h" +#include "main/DialBinTypesV2.h" +#include "power_display_service.h" +#include +#include +#include +namespace OHOS { + MessageModel::MessageModel() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::MessageModel"); + } + + MessageModel::~MessageModel() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::~MessageModel"); + } + + MessageModel &MessageModel::GetInstance() + { + static MessageModel instance; + return instance; + } + + void MessageModel::GetMessageInfo(std::string app, std::string contact, std::string information) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::GetMessageInfo"); + //保存数据 + mes.label_1 = app; // 应用 + mes.label_2 = contact; // 联系人 + mes.label_3 = information; // 内容 + mes.icon = "默认"; + // if (app == 微信) { + // mes1.icon = 微信图标; + // } + // if (app == 信息) { + // mes1.icon = 信息图标; + // } + InitMessageItem(); + if (GetViewStatus()) { + if (! MessageMainView::GetInstance()->contentList->IsVisible()) { + MessageMainView::GetInstance()->NewNotify(); + } + MessageMainView::GetInstance()->InitScrollData(); + } + } + + void MessageModel::InitMessageItem() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem"); + if (vecMsg.size() != 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,vecMsg.size() != 0"); + size_t i = 0; + for (i; i < vecMsg.size(); ++i) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,for()"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,vecMsg[i].label_1 = %s", vecMsg[i].label_1.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,vecMsg[i].label_2 = %s", vecMsg[i].label_2.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,vecMsg[i].label_3 = %s", vecMsg[i].label_3.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,mes.label_1 = %s", mes.label_1.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,mes.label_2 = %s", mes.label_2.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,mes.label_3 = %s", mes.label_3.c_str()); + if (vecMsg[i].label_1 == mes.label_1 && vecMsg[i].label_2 == mes.label_2) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,if()"); + vecMsg[i].label_3 = mes.label_3; + break; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,else(break)"); + continue; + } + if (i == vecMsg.size()) { + vecMsg.push_back(mes); + } + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageModel::InitMessageItem,else()"); + vecMsg.push_back(mes); + } + } + + const std::vector MessageModel::GetMessagelistItems() const + { + return vecMsg; + } + + void MessageModel::ClearListItem() + { + vecMsg.clear(); + } + + void MessageModel::SetViewStatus(bool viewStatus) + { + viewInitStatus = viewStatus; + } + + bool MessageModel::GetViewStatus(void) + { + return viewInitStatus; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/ModelListenerSample.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/ModelListenerSample.cpp index 26c67fb1f..5971ec477 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/ModelListenerSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/ModelListenerSample.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "ModelListenerSample.h" +#include "main/ModelListenerSample.h" #include "wearable_log.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp index 34eb21de7..810d3ab07 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp @@ -5,13 +5,13 @@ * Create: 2021-09-11 */ -#include "PullUpDownView.h" +#include "main/PullUpDownView.h" #include "wearable_log.h" #include "UiConfig.h" #include "common/screen.h" -#include "MainPresenterSample.h" -#include "ScreenModels.h" -#include "SettingModel.h" +#include "main/MainPresenterSample.h" +#include "screensetting/ScreenModels.h" +#include "settings/SettingModel.h" #include "ui_resource_image.h" namespace OHOS { 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 7ca2d4c07..1c86925b3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingPresenter.cpp @@ -3,20 +3,20 @@ * Description: VolumeSettingView view * Create: 2021-09-5 */ -#include "VolumeSettingView.h" -#include "VolumeSettingPresenter.h" -#include "PlayersModel.h" +#include "main/VolumeSettingView.h" +#include "main/VolumeSettingPresenter.h" +#include "player/PlayersModel.h" #include "common/image_cache_manager.h" #include "UiConfig.h" #include "ui_resource_image.h" #include "drag_event.h" -#include "MainCallingView.h" -#include "PhoneService.h" -#include "CallerLogModel.h" +#include "makephone/MainCallingView.h" +#include "phoneservice/PhoneService.h" +#include "callerlog/CallerLogModel.h" #include "bts_avrcp_controller.h" #include "bts_avrcp_target.h" #include "notification_manager.h" -#include "BluetoothHeadsetEvent.h" +#include "bluetooth/BluetoothHeadsetEvent.h" #include "bts_avrcp_controller.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingView.cpp index e8eeb4df7..ae6426962 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/VolumeSettingView.cpp @@ -3,8 +3,8 @@ * Description: VolumeSettingView view * Create: 2021-09-5 */ -#include "VolumeSettingView.h" -#include "PlayersView.h" +#include "main/VolumeSettingView.h" +#include "player/PlayersView.h" #include "common/image_cache_manager.h" #include "UiConfig.h" #include "ui_resource_image.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialArcLabelView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialArcLabelView.cpp index 02ce99c31..fa4a34771 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialArcLabelView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialArcLabelView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialArcLabelView.h" +#include "main/dial/DialArcLabelView.h" #include "securec.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialArcProgressView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialArcProgressView.cpp index 67dadd4c7..d045de8e7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialArcProgressView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialArcProgressView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialArcProgressView.h" +#include "main/dial/DialArcProgressView.h" namespace OHOS { DialArcProgressView::DialArcProgressView(void) @@ -28,4 +28,16 @@ void DialArcProgressView::HandleFloatData(float data) value_ = value; SetValue(value_); } + +void DialArcProgressView::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) +{ + if (foregroundStopCount_ != 0) { + Rect rect = GetOrigRect(); + foregroundGradient_.startX = rect.GetX(); + foregroundGradient_.startY = rect.GetY(); + foregroundGradient_.endX = rect.GetRight(); + foregroundGradient_.endY = rect.GetBottom(); + } + UICircleProgress::OnDraw(gfxDstBuffer, invalidatedArea); +} } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialBoxProgressView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialBoxProgressView.cpp index 8084dfb75..b3ce7908c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialBoxProgressView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialBoxProgressView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialBoxProgressView.h" +#include "main/dial/DialBoxProgressView.h" namespace OHOS { DialBoxProgressView::DialBoxProgressView(void) @@ -28,4 +28,16 @@ void DialBoxProgressView::HandleFloatData(float data) value_ = value; SetValue(value_); } + +void DialBoxProgressView::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) +{ + if (foregroundStopCount_ != 0) { + Rect rect = GetOrigRect(); + foregroundGradient_.startX = rect.GetX(); + foregroundGradient_.startY = rect.GetY(); + foregroundGradient_.endX = rect.GetRight(); + foregroundGradient_.endY = rect.GetBottom(); + } + UIBoxProgress::OnDraw(gfxDstBuffer, invalidatedArea); +} } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialDataBase.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialDataBase.cpp index bda2cf912..3052d247d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialDataBase.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialDataBase.cpp @@ -6,7 +6,7 @@ */ #include -#include "dial/DialDataBase.h" +#include "main/dial/DialDataBase.h" namespace { struct DataTypeHash { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialDigitalImgView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialDigitalImgView.cpp index 4f316171e..50e7b59df 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialDigitalImgView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialDigitalImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialDigitalImgView.h" +#include "main/dial/DialDigitalImgView.h" #include #include "securec.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialLabelView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialLabelView.cpp index 40fd07671..38a544fd6 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialLabelView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialLabelView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialLabelView.h" +#include "main/dial/DialLabelView.h" #include "securec.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelHeartRate.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelHeartRate.cpp index ff827325e..d6b6d91b7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelHeartRate.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelHeartRate.cpp @@ -5,8 +5,8 @@ * Create: 2023-12 */ -#include "RegisterDialModel.h" -#include "DialModelHeartRate.h" +#include "main/dial/RegisterDialModel.h" +#include "main/dial/DialModelHeartRate.h" REGIST_DIAL_MODULE(OHOS::DialDataType::HEART_RATE, OHOS::DialModelHeartRate::GetInstance()); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp index b6a2c5a86..dcb3e0d67 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp @@ -5,16 +5,32 @@ * Create: 2023-12 */ -#include "RegisterDialModel.h" -#include "DialModelPower.h" +#include "main/dial/RegisterDialModel.h" +#include "main/dial/DialModelPower.h" REGIST_DIAL_MODULE(OHOS::DialDataType::BATTERY, OHOS::DialModelPower::GetInstance()); namespace OHOS { +static RegisterDialModel REGIST_BATTERY_LEVEL(DialDataType::BATTERY_LEVEL, DialModelPower::GetInstance()); +static RegisterDialModel REGIST_BATTERY_ENUM(DialDataType::BATTERY_ENUM, DialModelPower::GetInstance()); bool DialModelPower::GetDialFloatData(DialDataType& type, float& out) { - (void)type; - out = power_; + switch (type) { + case DialDataType::BATTERY: { + out = power_; + break; + } + case DialDataType::BATTERY_LEVEL: { + out = static_cast(power_) / 100.0; // 100.0: full power + break; + } + case DialDataType::BATTERY_ENUM: { + out = static_cast(power_ / 10); // 10: num + break; + } + default: + (void)type; + } return true; } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelSteps.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelSteps.cpp index a1ad2edf9..15fd7393c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelSteps.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelSteps.cpp @@ -5,8 +5,8 @@ * Create: 2023-12 */ -#include "RegisterDialModel.h" -#include "DialModelSteps.h" +#include "main/dial/RegisterDialModel.h" +#include "main/dial/DialModelSteps.h" REGIST_DIAL_MODULE(OHOS::DialDataType::STEP_COUNT, OHOS::DialModelSteps::GetInstance()); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelTime.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelTime.cpp index b626e0233..4422425e9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelTime.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelTime.cpp @@ -7,8 +7,8 @@ #include #include "sys/time.h" -#include "RegisterDialModel.h" -#include "DialModelTime.h" +#include "main/dial/RegisterDialModel.h" +#include "main/dial/DialModelTime.h" #include "components/root_view.h" #define REGIST_DIAL_MODULE_ANGLE_H(type, func) static OHOS::RegisterDialModel(REGIST_ANGLE_H)(type, func) @@ -41,6 +41,8 @@ REGIST_DIAL_MODULE_YEAR(OHOS::DialDataType::SOLAR_YEAR, OHOS::DialModelTime::Get REGIST_DIAL_MODULE_GEAR_POSITIVE(OHOS::DialDataType::SWIVEL_GEAR_POSITIVE, OHOS::DialModelTime::GetInstance()); REGIST_DIAL_MODULE_GEAR_NEGATIVE(OHOS::DialDataType::SWIVEL_GEAR_NEGATIVE, OHOS::DialModelTime::GetInstance()); +static OHOS::RegisterDialModel REGIST_MOUNTH_80(OHOS::DialDataType::MONTH_DATA, OHOS::DialModelTime::GetInstance()); + namespace OHOS { static constexpr int16_t S_MS_US_TRANS = 1000; // 1000: seconds, milliseconds, microsecond transform value static constexpr uint8_t ONE_MINUTE_IN_SECOND = 60; // 60: 60 seconds per minute @@ -186,6 +188,10 @@ bool DialModelTime::GetDialFloatData(DialDataType& type, float& out) out = static_cast(accleratedAngle * -1.0 + CIRCLE_IN_DEGREE); break; } + case DialDataType::MONTH_DATA: { + out = static_cast(tblock_->tm_mon) + 1.0; + break; + } default: return false; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialOptionImgView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialOptionImgView.cpp index 980d438cd..4175937c2 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialOptionImgView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialOptionImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialOptionImgView.h" +#include "main/dial/DialOptionImgView.h" #include "securec.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialRotateImgView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialRotateImgView.cpp index bec17ca81..171aeea7e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialRotateImgView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialRotateImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialRotateImgView.h" +#include "main/dial/DialRotateImgView.h" namespace OHOS { DialRotateImgView::DialRotateImgView(void) diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialSequenceImgView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialSequenceImgView.cpp index c7d1c24e7..8741d4c9a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialSequenceImgView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialSequenceImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialSequenceImgView.h" +#include "main/dial/DialSequenceImgView.h" #include "securec.h" #include "common/graphic_utils.h" #include "common/image_cache_manager.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialStaticImgView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialStaticImgView.cpp index ffc87a701..bfa5182ea 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialStaticImgView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialStaticImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialStaticImgView.h" +#include "main/dial/DialStaticImgView.h" namespace OHOS { DialStaticImgView::DialStaticImgView() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialVideoView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialVideoView.cpp index f18e9ea9d..9ac7b75d1 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialVideoView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialVideoView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialVideoView.h" +#include "main/dial/DialVideoView.h" namespace OHOS { static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewContainer.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewContainer.cpp index 8ed4cf710..198c0679b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewContainer.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewContainer.cpp @@ -5,9 +5,9 @@ * Create: 2025-02-06 */ -#include "DialViewContainer.h" -#include "DialDigitalImgView.h" -#include "ModelDialDataFactory.h" +#include "main/dial/DialViewContainer.h" +#include "main/dial/DialDigitalImgView.h" +#include "main/dial/ModelDialDataFactory.h" namespace OHOS { DialViewContainer::~DialViewContainer() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp index 54d197579..3c52dd760 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp @@ -1,20 +1,20 @@ -#include "DialViewGroup.h" +#include "main/dial/DialViewGroup.h" #include #include #include "NativeAbility.h" #include "msg_center.h" #include "securec.h" -#include "DialBinParser.h" -#include "ModelDialDataFactory.h" +#include "main/DialBinParser.h" +#include "main/dial/ModelDialDataFactory.h" #include "common/low_power_manager.h" #include "common/image_cache_manager.h" #ifdef SUPPORT_OHOSFWK -#include "ui_screennotify.h" +#include "screennotify/ui_screennotify.h" #endif -#include "MainPresenterSample.h" -#include "DialDigitalImgView.h" +#include "main/MainPresenterSample.h" +#include "main/dial/DialDigitalImgView.h" #include "common/input_device_manager.h" -#include "DialSequenceImgView.h" +#include "main/dial/DialSequenceImgView.h" #include "engines/gfx/lite_m_gfx_engine.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/ModelDialDataFactory.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/ModelDialDataFactory.cpp index d17de5b31..71ea7a19f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/ModelDialDataFactory.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/ModelDialDataFactory.cpp @@ -5,7 +5,7 @@ * Create: 2023-12 */ -#include "ModelDialDataFactory.h" +#include "main/dial/ModelDialDataFactory.h" namespace OHOS { bool ModelDialDataFactory::GetDialTextData(DialDataType& type, std::string*& out, int16_t& strNum) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/WatchInterface.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/WatchInterface.cpp index c4f9fd1c2..11f98448d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/WatchInterface.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/WatchInterface.cpp @@ -6,24 +6,35 @@ */ #include +#include #include "dirent.h" -#include "DialBinParser.h" +#include "main/DialBinParser.h" #include "UiConfig.h" -#include "WatchInterface.h" +#include "main/dial/WatchInterface.h" #include "gfx_utils/vector.h" #include "common/screen.h" -#include "MainModel.h" -#include "MainViewSample.h" -#include "SetDialModel.h" +#include "main/MainModel.h" +#include "main/MainViewSample.h" +#include "set_dial/SetDialModel.h" #include "graphic_service.h" #include "NativeAbility.h" +#include "graphic_mutex.h" +#include "set_dial/SetDialModel.h" +#include "set_dial/SetDialPresenter.h" +#include "power_display_service.h" using namespace OHOS; namespace { -struct { - Graphic::Vector fileNames; // only for 3.0 - Graphic::Vector watchInfo; // only for 3.0 -} g_info; +struct WatchInfoInner { + std::string fileName; + watch_dial_info watchInfo; +}; + +Graphic::Vector g_info; +GraphicMutex g_mutex; +GraphicCond g_cond; +bool g_eventFinished = true; +const uint16_t INVALID_INFO_INDEX = 0xFFFF; bool GetActiveWatchPath(std::string &path) { @@ -34,7 +45,7 @@ bool GetActiveWatchPath(std::string &path) return false; } -bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview) +bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview, bool isNeedVerify = false) { const std::string type(".bin"); if (!(fileName.length() > type.length() && @@ -45,7 +56,7 @@ bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview) FILE *file = fopen(fileName.c_str(), "rb"); bool isSuccess = false; if (file != nullptr) { - isSuccess = DialBinParserManager::GetInstance()->GetDialPreviewInfo(file, &preview); + isSuccess = DialBinParserManager::GetInstance()->GetDialPreviewInfo(fileName, file, &preview, isNeedVerify); fclose(file); } return isSuccess; @@ -70,16 +81,14 @@ bool ConvertPreview2WatchDialInfo(const DialPreviewInfo &preview, watch_dial_inf return true; } -bool GetAllWatchInfo() +void RefreshAllWatchInfo() { - g_info.fileNames.Clear(); - g_info.watchInfo.Clear(); + g_info.Clear(); struct dirent *direntp = nullptr; - // ´ò¿ªÄ¿Â¼ + // 打开目录 DIR *dirp = opendir(APP_DIAL_PATH); - bool isSuccess = true; - // ±éÀúÎļþ + // 遍历文件 DialPreviewInfo info; watch_dial_info watchInfo; std::string activePath; @@ -87,56 +96,133 @@ bool GetAllWatchInfo() if (dirp != nullptr) { while ((direntp = readdir(dirp)) != nullptr) { std::string fileName = std::string(APP_DIAL_PATH) + std::string("/") + std::string(direntp->d_name); - isSuccess = GetPreviewInfo(fileName, info); - if (!isSuccess) { + if (!GetPreviewInfo(fileName, info)) { continue; } const std::string lowestVersion("3.0"); std::string curVersion(info.protocolVersion); if (curVersion >= lowestVersion) { - isSuccess = ConvertPreview2WatchDialInfo(info, watchInfo); - if (!isSuccess) { + if (!ConvertPreview2WatchDialInfo(info, watchInfo)) { break; } watchInfo.install_state = true; watchInfo.is_current_watch = isActiveExist ? (activePath == fileName) : false; - g_info.fileNames.PushBack(fileName); - g_info.watchInfo.PushBack(watchInfo); + g_info.PushBack({fileName, watchInfo}); } } } - // ¹Ø±ÕĿ¼ + // 关闭目录 closedir(dirp); - return isSuccess; } -} // namespace -bool GetAllWatchFaceInfo(watch_dial_info *info, uint8_t *num, uint8_t maxCnt) +inline bool IsFileExists(const std::string &file) +{ + return access(file.c_str(), F_OK) == 0; +} + +uint16_t FindMaxVersionIndex(uint16_t indexArray[], uint16_t num) +{ + if (num == 0) { + return INVALID_INFO_INDEX; + } + + if (num == 0) { + return indexArray[0]; + } + std::string version = reinterpret_cast(g_info[indexArray[0]].watchInfo.watch_version); + uint16_t index = 0; + for (uint16_t i = 1; i < num; ++i) { + std::string curVerion = std::string(reinterpret_cast(g_info[indexArray[i]].watchInfo.watch_version)); + if (curVerion > version) { + version = curVerion; + index = i; + } + } + if (num > 1) { + GRAPHIC_LOGE("There are watches with the same uuid. %u", g_info[indexArray[index]].watchInfo.uuid); + } + index = indexArray[index]; + return index; +} + +void GetWatchInfo(uint32_t uuid, uint16_t &index) +{ + index = INVALID_INFO_INDEX; + if (g_info.IsEmpty()) { + RefreshAllWatchInfo(); + } + const uint16_t MAX_INFO_NUM = 128; + static uint16_t indexArray[MAX_INFO_NUM]; + uint16_t num = 0; + std::string activePath; + bool isActive = GetActiveWatchPath(activePath); + bool isNeedRequery = false; + for (uint16_t i = 0; i < g_info.Size(); ++i) { + if (uuid == g_info[i].watchInfo.uuid && num < MAX_INFO_NUM) { + if (IsFileExists(g_info[i].fileName)) { + g_info[i].watchInfo.is_current_watch = isActive ? (g_info[i].fileName == activePath) : false; + indexArray[num++] = i; + } else { + RefreshAllWatchInfo(); + isNeedRequery = true; + break; + } + } + } + + if (!isNeedRequery) { + index = FindMaxVersionIndex(indexArray, num); + return; + } + num = 0; + for (uint16_t i = 0; i < g_info.Size(); ++i) { + if (uuid == g_info[i].watchInfo.uuid && num < MAX_INFO_NUM) { + indexArray[num++] = i; + } + } + index = FindMaxVersionIndex(indexArray, num); +} + +void TryToTurnOnScreen() +{ + const power_display_svr_api_t *ctx = power_display_svr_get_api(); + if (ctx == nullptr) { + return; + } + if (ctx->get_screen_state != nullptr && ctx->get_screen_state() != SCREEN_ON) { + if (ctx->turn_on_screen != nullptr) { + ctx->turn_on_screen(); + } + } +} +} // anonymous namespace + +bool GetAllWatchFaceInfo(watch_dial_info **info, uint8_t *num) { if (info == nullptr || num == nullptr) { GRAPHIC_LOGE("para error!"); return false; } - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watch info."); - return false; + GraphicLockGuard guard(g_mutex); + while (!g_eventFinished) { + g_cond.Wait(g_mutex); } - if (g_info.watchInfo.Size() > maxCnt) { - GRAPHIC_LOGE("mem is not enough."); - return false; - } - *num = g_info.watchInfo.Size(); + RefreshAllWatchInfo(); + *num = g_info.Size(); if (*num == 0) { - return false; + *info = nullptr; + return true; } - if (memcpy_s(info, - g_info.watchInfo.Size() * sizeof(watch_dial_info), - &g_info.watchInfo[0], - g_info.watchInfo.Size() * sizeof(watch_dial_info)) != 0) { - GRAPHIC_LOGE("copy info error!"); + watch_dial_info *mem = static_cast(malloc(*num * sizeof(watch_dial_info))); + if (mem == nullptr) { + GRAPHIC_LOGE("failed to malloc"); return false; } + for (uint16_t i = 0; i < g_info.Size(); ++i) { + memcpy_s(&mem[i], sizeof(watch_dial_info), &g_info[i].watchInfo, sizeof(watch_dial_info)); + } + *info = mem; return true; } @@ -146,17 +232,19 @@ bool GetWatchFaceInfo(uint32_t uuid, watch_dial_info *watch) GRAPHIC_LOGE("para error!"); return false; } - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watch info."); + + uint16_t index = INVALID_INFO_INDEX; + GraphicLockGuard guard(g_mutex); + while (!g_eventFinished) { + g_cond.Wait(g_mutex); + } + GetWatchInfo(uuid, index); + if (index == INVALID_INFO_INDEX) { + GRAPHIC_LOGE("uuid %u does not exist", uuid); return false; } - for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) { - if (g_info.watchInfo[i].uuid == uuid) { - *watch = g_info.watchInfo[i]; - return true; - } - } - return false; + memcpy_s(watch, sizeof(watch_dial_info), &g_info[index].watchInfo, sizeof(watch_dial_info)); + return true; } bool GetWatchCapability(watch_dev_cap_info *capability) @@ -235,90 +323,118 @@ bool GetCurrentWatchFaceInfo(watch_dial_info *watch) bool SetCurrentWatchFace(uint32_t uuid) { - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watch info."); + uint16_t index = INVALID_INFO_INDEX; + GraphicLockGuard guard(g_mutex); + while (!g_eventFinished) { + g_cond.Wait(g_mutex); + } + GetWatchInfo(uuid, index); + if (index == INVALID_INFO_INDEX) { + GRAPHIC_LOGE("uuid %u does not exist", uuid); return false; } - watch_dial_info info; - uint16_t index = 0; - bool isExists = false; - for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) { - if (uuid == g_info.watchInfo[i].uuid) { - isExists = true; - info = g_info.watchInfo[i]; - index = i; - break; - } - } - if (!isExists) { - GRAPHIC_LOGE("uuid does not exist!"); - return false; + DialSetting setting = MainModel::GetInstance().GetDialSetting(); + setting.dialFlag = 1; + setting.dialFullName = g_info[index].fileName; + if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) { + GraphicService::GetInstance()->PostGraphicEvent([setting]() { + if (SetDialPresenter::GetCurrentInstance() != nullptr) { + SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting); + } + }); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + return true; } - if (info.is_current_watch) { + if (g_info[index].watchInfo.is_current_watch) { return true; } - - DialSetting setting = MainModel::GetInstance().GetDialSetting(); - setting.dialFlag = 1; - setting.dialFullName = g_info.fileNames[index]; + g_eventFinished = false; GraphicService::GetInstance()->PostGraphicEvent([setting]() { + GraphicLockGuard guardGraphic(g_mutex); MainModel::GetInstance().GetDialSetting() = setting; MainModel::GetInstance().AddDialSetting(setting); if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) { MainViewSample::GetInstance()->ReloadWatchFace(); } + g_eventFinished = true; + g_cond.Signal(); }); + TryToTurnOnScreen(); return true; } bool UninstallWatch(uint32_t uuid) { - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watch info."); - return false; - } - watch_dial_info info; - uint16_t index = 0; - bool isExists = false; - for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) { - if (uuid == g_info.watchInfo[i].uuid) { - isExists = true; - info = g_info.watchInfo[i]; - index = i; - break; - } - } - if (!isExists) { - GRAPHIC_LOGE("uuid does not exist!"); + uint16_t index = INVALID_INFO_INDEX; + GraphicLockGuard guard(g_mutex); + while (!g_eventFinished) { + g_cond.Wait(g_mutex); + } + GetWatchInfo(uuid, index); + if (index == INVALID_INFO_INDEX) { + GRAPHIC_LOGE("uuid %u does not exist", uuid); return false; } - if (info.is_current_watch) { - DialSetting setting = MainModel::GetInstance().GetDialSetting(); + DialSetting setting = MainModel::GetInstance().GetDialSetting(); + if (g_info[index].watchInfo.is_current_watch) { setting.dialFlag = 0; setting.dialId = 0; - std::string fileName = g_info.fileNames[index]; - GraphicService::GetInstance()->PostGraphicEvent([setting, fileName]() { - MainModel::GetInstance().GetDialSetting() = setting; - MainModel::GetInstance().AddDialSetting(setting); - if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) { - MainViewSample::GetInstance()->ReloadWatchFace(); - } - if (remove(fileName.c_str()) != 0) { - GRAPHIC_LOGE("failed to remove file %s", fileName.c_str()); + } + if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) { + if (g_info[index].watchInfo.is_current_watch) { + // If it is the current watch face, set it as the default watch face. Otherwise, the configuration remains + // unchanged. + GraphicService::GetInstance()->PostGraphicEvent([setting]() { + if (SetDialPresenter::GetCurrentInstance() != nullptr) { + SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting); + } + }); + } + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + g_eventFinished = false; + GraphicService::GetInstance()->PostGraphicEvent([index]() { + GraphicLockGuard guardGraphic(g_mutex); + ImageCacheManager::GetInstance().UnloadAllInMultiRes(g_info[index].fileName); + if (remove(g_info[index].fileName.c_str()) != 0) { + GRAPHIC_LOGE("failed to remove file %s", g_info[index].fileName.c_str()); + g_eventFinished = true; + g_cond.Signal(); + return; } + g_info.Erase(index); + g_eventFinished = true; + g_cond.Signal(); }); - } else { - if (remove(g_info.fileNames[index].c_str()) != 0) { - GRAPHIC_LOGE("failed to remove file %s", g_info.fileNames[index].c_str()); - return false; - } + return true; } + + g_eventFinished = false; + GraphicService::GetInstance()->PostGraphicEvent([index, setting]() { + GraphicLockGuard guardGraphic(g_mutex); + if (g_info[index].watchInfo.is_current_watch && + NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) { + MainModel::GetInstance().GetDialSetting() = setting; + MainModel::GetInstance().AddDialSetting(setting); + MainViewSample::GetInstance()->ReloadWatchFace(); + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(g_info[index].fileName); + if (remove(g_info[index].fileName.c_str()) != 0) { + GRAPHIC_LOGE("failed to remove file %s", g_info[index].fileName.c_str()); + g_eventFinished = true; + g_cond.Signal(); + return; + } + g_info.Erase(index); + g_eventFinished = true; + g_cond.Signal(); + }); + TryToTurnOnScreen(); return true; } -bool InstallWatch(const char *path, uint32_t *uuid) +bool GetUuidByPath(const char *path, uint32_t *uuid) { if (path == nullptr || uuid == nullptr) { GRAPHIC_LOGE("para error!"); @@ -326,45 +442,31 @@ bool InstallWatch(const char *path, uint32_t *uuid) } DialPreviewInfo preview; - if (!GetPreviewInfo(std::string(path), preview)) { + if (!GetPreviewInfo(std::string(path), preview, true)) { return false; } if (std::string(preview.protocolVersion) < std::string("3.0")) { return false; } - *uuid = preview.uuid; - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watchinfo!"); - return false; - } - for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) { - const std::string &fileName = g_info.fileNames[i]; - const watch_dial_info &info = g_info.watchInfo[i]; - if (!(info.uuid == *uuid && std::string(path) != fileName)) { - continue; - } - - if (info.is_current_watch) { - DialSetting setting = MainModel::GetInstance().GetDialSetting(); - setting.dialFlag = 1; - setting.dialFullName = std::string(path); - GraphicService::GetInstance()->PostGraphicEvent([setting, fileName]() { - MainModel::GetInstance().GetDialSetting() = setting; - MainModel::GetInstance().AddDialSetting(setting); - if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) { - MainViewSample::GetInstance()->ReloadWatchFace(); - } - if (remove(fileName.c_str()) != 0) { - GRAPHIC_LOGE("failed to remove file %s", fileName.c_str()); - } - }); - } else { - if (remove(fileName.c_str()) != 0) { - return false; + watch_dial_info watchInfo; + if (ConvertPreview2WatchDialInfo(preview, watchInfo)) { + std::string activePath; + std::string appendPath(path); + bool isActiveExist = GetActiveWatchPath(activePath); + watchInfo.install_state = true; + watchInfo.is_current_watch = isActiveExist ? (activePath == appendPath) : false; + bool isExist = false; + for (uint16_t i = 0; i < g_info.Size(); ++i) { + if (g_info[i].fileName == appendPath) { + isExist = true; + break; } } + if (!isExist) { + g_info.PushBack({appendPath, watchInfo}); + } } - + *uuid = preview.uuid; return true; } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/CallerDisplayView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/CallerDisplayView.cpp index 2426ea21e..5617586d1 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/CallerDisplayView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/CallerDisplayView.cpp @@ -4,8 +4,8 @@ * Author: * Create: 2021-10-12 */ -#include "CallerDisplayView.h" -#include "MainCallingPresenter.h" +#include "makephone/CallerDisplayView.h" +#include "makephone/MainCallingPresenter.h" #include "UiConfig.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/CallingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/CallingView.cpp index 2c19d7599..953900e8b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/CallingView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/CallingView.cpp @@ -4,8 +4,8 @@ * Author: * Create: 2021-10-12 */ -#include "CallingView.h" -#include "MainCallingPresenter.h" +#include "makephone/CallingView.h" +#include "makephone/MainCallingPresenter.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/DialingScreenView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/DialingScreenView.cpp index 99808b2e9..e18ae2a72 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/DialingScreenView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/DialingScreenView.cpp @@ -6,8 +6,8 @@ */ #include "wearable_log.h" #include "UiConfig.h" -#include "DialingScreenView.h" -#include "MainCallingPresenter.h" +#include "makephone/DialingScreenView.h" +#include "makephone/MainCallingPresenter.h" namespace OHOS { static constexpr uint16 MATH_ZERO = 0; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/MainCallingPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/MainCallingPresenter.cpp index db8a0b9fc..07b4d2cec 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/MainCallingPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/MainCallingPresenter.cpp @@ -9,14 +9,14 @@ #include "common/image_cache_manager.h" #include "UiConfig.h" #include "ui_resource_image.h" -#include "MainCallingPresenter.h" -#include "CallingView.h" -#include "CallerDisplayView.h" -#include "DialingScreenView.h" -#include "MainCallingView.h" +#include "makephone/MainCallingPresenter.h" +#include "makephone/CallingView.h" +#include "makephone/CallerDisplayView.h" +#include "makephone/DialingScreenView.h" +#include "makephone/MainCallingView.h" #include "NativeRegisterManager.h" -#include "PhoneService.h" -#include "WaitingHintsView.h" +#include "phoneservice/PhoneService.h" +#include "makephone/WaitingHintsView.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/MainCallingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/MainCallingView.cpp index c4e6af6ac..d079a9676 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/MainCallingView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/MainCallingView.cpp @@ -6,9 +6,9 @@ */ #include "wearable_log.h" #include "UiConfig.h" -#include "MainCallingView.h" -#include "MainCallingPresenter.h" -#include "CallerLogModel.h" +#include "makephone/MainCallingView.h" +#include "makephone/MainCallingPresenter.h" +#include "callerlog/CallerLogModel.h" namespace OHOS { static MainCallingView *g_pMainView = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/WaitingHintsView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/WaitingHintsView.cpp index e27e55dbc..549e699f3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/WaitingHintsView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/makephone/src/WaitingHintsView.cpp @@ -4,10 +4,10 @@ * Author: * Create: 2022-03-14 */ -#include "WaitingHintsView.h" +#include "makephone/WaitingHintsView.h" #include "UiConfig.h" -#include "CallerLogModel.h" -#include "MainCallingPresenter.h" +#include "callerlog/CallerLogModel.h" +#include "makephone/MainCallingPresenter.h" namespace OHOS { static constexpr uint16 MATH_ZERO = 0; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/MainVocassistView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/MainVocassistView.cpp index 2b1eb6b10..aa90443bc 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/MainVocassistView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/MainVocassistView.cpp @@ -5,8 +5,8 @@ * Create: 2022-01-18 */ -#include "MainVocassistView.h" -#include "VocassistPresenter.h" +#include "offlinevoice/MainVocassistView.h" +#include "offlinevoice/VocassistPresenter.h" namespace OHOS { static MainVocassistView *g_pMainVocassistView = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistModel.cpp index adae52d69..12b59a00f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistModel.cpp @@ -4,10 +4,10 @@ * Author: CompanyName * Create: 2022-01-18 */ -#include "PhoneService.h" -#include "MainViewSample.h" -#include "VocassistView.h" -#include "VocassistModel.h" +#include "phoneservice/PhoneService.h" +#include "main/MainViewSample.h" +#include "offlinevoice/VocassistView.h" +#include "offlinevoice/VocassistModel.h" #include "AppViewIDs.h" #include "NativeAbility.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistPresenter.cpp index 3a38a9e01..49596a48b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistPresenter.cpp @@ -5,9 +5,9 @@ * Create: 2022-01-18 */ #include "AppViewIDs.h" -#include "VocassistPresenter.h" -#include "PlayersModel.h" -#include "ui_service.h" +#include "offlinevoice/VocassistPresenter.h" +#include "player/PlayersModel.h" +#include "uiservice/ui_service.h" #include "NativeRegisterManager.h" namespace OHOS { @@ -122,7 +122,6 @@ bool VocassistPresenter::OnDrag(UIView& view, const DragEvent& event) void VocassistPresenter::OnResume(void) { - Presenter::OnResume(); ScreenTurnOn(-1); } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistView.cpp index 70f80a813..e0c2c71d6 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/offlinevoice/src/VocassistView.cpp @@ -9,11 +9,11 @@ #include "ohos_timer.h" #include "graphic_timer.h" #include "AppViewIDs.h" -#include "PlayersModel.h" -#include "CallerLogModel.h" -#include "VocassistModel.h" -#include "VocassistView.h" -#include "VocassistPresenter.h" +#include "player/PlayersModel.h" +#include "callerlog/CallerLogModel.h" +#include "offlinevoice/VocassistModel.h" +#include "offlinevoice/VocassistView.h" +#include "offlinevoice/VocassistPresenter.h" static constexpr uint16_t SWITCH_MAP_NUM = 16; static constexpr uint16_t ANI_X = 84; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneAudio.cpp b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneAudio.cpp index 8b695c89a..665d1462f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneAudio.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneAudio.cpp @@ -4,8 +4,8 @@ * Create: 2021-09-22 */ -#include "PhoneAudio.h" -#include "PhoneService.h" +#include "phoneservice/PhoneAudio.h" +#include "phoneservice/PhoneService.h" #include #include #include "audio_manager.h" 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 adaf6ce57..66b889773 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp @@ -4,8 +4,8 @@ * Create: 2021-09-22 */ -#include "PhoneService.h" -#include "PhoneAudio.h" +#include "phoneservice/PhoneService.h" +#include "phoneservice/PhoneAudio.h" #include "securec.h" #include #include @@ -24,7 +24,7 @@ #include "service_id_define.h" #include "graphic_mutex.h" #include "samgr_lite.h" -#include "ui_service.h" +#include "uiservice/ui_service.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/BluetoothView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/BluetoothView.cpp index dfae52888..b05219ea4 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/BluetoothView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/BluetoothView.cpp @@ -3,11 +3,11 @@ * Description: bluetooth view 设置页面 * Create: 2021-09-5 */ -#include "BluetoothView.h" -#include "PlayersView.h" +#include "player/BluetoothView.h" +#include "player/PlayersView.h" #include "UiConfig.h" -#include "BluetoothEarPhoneView.h" -#include "PlayersPresenter.h" +#include "bluetooth/BluetoothEarPhoneView.h" +#include "player/PlayersPresenter.h" namespace OHOS { static BluetoothView *g_bluetoothView{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp index b9e550257..06775205a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersCaseListAdapter.cpp @@ -5,12 +5,12 @@ * Create: 2021-07-26 */ #include -#include "PlayersCaseListAdapter.h" +#include "player/PlayersCaseListAdapter.h" #include "gfx_utils/list.h" -#include "PlayersView.h" -#include "PlayersPresenter.h" +#include "player/PlayersView.h" +#include "player/PlayersPresenter.h" #include "wearable_log.h" -#include "PlayersModel.h" +#include "player/PlayersModel.h" namespace OHOS { constexpr uint16_t TESTCASE_BUTTON_HEIGHT = 64; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersModel.cpp index e454449be..410d07351 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersModel.cpp @@ -5,13 +5,13 @@ * Create: 2021-07-26 */ -#include "PlayersModel.h" +#include "player/PlayersModel.h" #include "thread_adapter.h" #include "UiConfig.h" #include "bts_avrcp_controller.h" #include "bts_avrcp_target.h" #include "bts_a2dp_source.h" -#include "BluetoothModel.h" +#include "bluetooth/BluetoothModel.h" namespace OHOS { @@ -107,7 +107,7 @@ int PlayersModel::PlayerStat() interrupt = {AUDIO_STREAM_MUSIC, sessionId, playerInterruptListener}; // 激活音频中断 5s超时 if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ActivateAudioInterrupt faild"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ActivateAudioInterrupt faild"); return OHOS_FAILURE; } isActivateAudioInterrupt = true; @@ -667,19 +667,22 @@ void PlayersModel::SetBTMusicPlay(avrcp_key_operation_t notification) } } // 蓝牙连接和本地的音乐播放 -void PlayersModel::ConnectBtAndLocalPlay(int32_t connCtState, int32_t connTgState, int32_t playerState) +int32_t PlayersModel::ConnectBtAndLocalPlay(int32_t connCtState, int32_t connTgState, int32_t playerState) { int ret; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel] ConnectBtAndLocalPlay connCtState = %d connTgState = %d", connCtState, connTgState); avrcp_key_operation_t playNotification = AVRCP_KEY_PLAY; if (PlayersModel::GetInstance()->GetPlayerCtr() == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayersModel::ConnectBtAndLocalPlay] BT GetPlayerCtr is nullptr "); - return; + return -1; } if (connCtState == HFP_SCO_STATE_CONNECTED || connTgState == HFP_SCO_STATE_CONNECTED) { if (playerState == PlayerStates::PLAYER_PAUSED) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BTPLAYER_PAUSED play, 122."); - PlayersModel::GetInstance()->GetPlayerCtr()->Play(); // 暂停后的播放 + if (playerInterruptListener->IsInterruptedPaused()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Paused by interrupt, dont resume"); + return -1; + } + ret = PlayersModel::GetInstance()->GetPlayerCtr()->Play(); // 暂停后的播放 PlayersModel::GetInstance()->SetBTMusicPlay(playNotification); } else { ret = PlayersModel::GetInstance()->PlayerStat(); // 蓝牙连接播放 @@ -691,7 +694,11 @@ void PlayersModel::ConnectBtAndLocalPlay(int32_t connCtState, int32_t connTgStat } else { if (playerState == PlayerStates::PLAYER_PAUSED) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PLAYER_PAUSED play, 122."); - PlayersModel::GetInstance()->GetPlayerCtr()->Play(); + if (playerInterruptListener->IsInterruptedPaused()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Paused by interrupt, dont resume"); + return -1; + } + ret = PlayersModel::GetInstance()->GetPlayerCtr()->Play(); } else { ret = PlayersModel::GetInstance()->PlayerStat(); // 本地播放 if (ret != 0) { @@ -699,19 +706,20 @@ void PlayersModel::ConnectBtAndLocalPlay(int32_t connCtState, int32_t connTgStat } } } + return ret; } // 蓝牙连接和本地音乐的暂停 -void PlayersModel::ConnectBtAndLocalPause(int32_t connCtState, int32_t connTgState) +int32_t PlayersModel::ConnectBtAndLocalPause(int32_t connCtState, int32_t connTgState) { - int ret; + int32_t ret = 0; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayerModel] ConnectBtAndLocalPause"); avrcp_key_operation_t playNotification = AVRCP_KEY_PAUSE; if (connCtState == HFP_SCO_STATE_CONNECTED || connTgState == HFP_SCO_STATE_CONNECTED) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state == BTUNSELECTED, 105."); if (PlayersModel::GetInstance()->GetPlayerCtr() == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayersModel::ConnectBtAndLocalPause] BT GetPlayerCtr is nullptr"); - return; + return -1; } ret = PlayersModel::GetInstance()->GetPlayerCtr()->Pause(); // 蓝牙连接暂停 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BT Music Pause, ret:%d", ret); @@ -721,6 +729,7 @@ void PlayersModel::ConnectBtAndLocalPause(int32_t connCtState, int32_t connTgSta ret = PlayersModel::GetInstance()->GetPlayerCtr()->Pause(); // 本地暂停 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Pause, ret:%d", ret); } + return ret; } void PlayersModel::ClearActivateAudioInterrupt() 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 e595ee337..8571cc9d3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersPresenter.cpp @@ -9,17 +9,17 @@ #include #include #include -#include "PlayersPresenter.h" +#include "player/PlayersPresenter.h" #include "wearable_log.h" #include "common/image_cache_manager.h" #include "UiConfig.h" #include "ui_resource_image.h" -#include "PlayersView.h" -#include "PlayersModel.h" -#include "BluetoothPresenter.h" +#include "player/PlayersView.h" +#include "player/PlayersModel.h" +#include "bluetooth/BluetoothPresenter.h" #include "graphic_service.h" -#include "PhoneService.h" -#include "MainViewSample.h" +#include "phoneservice/PhoneService.h" +#include "main/MainViewSample.h" #include "bts_avrcp_controller.h" #include "bts_avrcp_target.h" @@ -733,6 +733,11 @@ bool PlayerInterruptListener::IsPaused() return isPaused_; } +bool PlayerInterruptListener::IsInterruptedPaused() +{ + return isInterruptedPause_; +} + bool PlayerInterruptListener::IsDelayed() { return isDelayed_; @@ -864,10 +869,12 @@ void PlayerInterruptListener::OnInterrupt(int32_t type, int32_t hint) WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "[PlayerInterruptListener::] OnInterrupt go in, type %d, hint %d.", type, hint); if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_PAUSE) { + isInterruptedPause_ = true; PausePlayer(); } if (type == INTERRUPT_TYPE_END && hint == INTERRUPT_HINT_RESUME) { + isInterruptedPause_ = false; ResumePlayer(); } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp index e318718aa..3c10323bf 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/player/src/PlayersView.cpp @@ -8,11 +8,11 @@ #include #include "common/image_cache_manager.h" #include "ui_resource_image.h" -#include "PlayersView.h" +#include "player/PlayersView.h" #include "UiConfig.h" -#include "PlayersModel.h" -#include "PlayersCaseListAdapter.h" -#include "MainViewSample.h" +#include "player/PlayersModel.h" +#include "player/PlayersCaseListAdapter.h" +#include "main/MainViewSample.h" namespace OHOS { static PlayersView* g_pPlayersView = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/qrcode_conn/src/QrcodeConnModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/qrcode_conn/src/QrcodeConnModel.cpp new file mode 100644 index 000000000..2a78dc648 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/qrcode_conn/src/QrcodeConnModel.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: QrcodeConnModel.cpp + * Author: + * Create: 2025-04-24 + */ + +#include "qrcode_conn/QrcodeConnModel.h" + +namespace OHOS { +QrcodeConnModel::QrcodeConnModel() {} + +QrcodeConnModel::~QrcodeConnModel() {} + +QrcodeConnModel &QrcodeConnModel::GetInstance() +{ + static QrcodeConnModel instance; + return instance; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/qrcode_conn/src/QrcodeConnPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/qrcode_conn/src/QrcodeConnPresenter.cpp new file mode 100644 index 000000000..cf94db4d2 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/qrcode_conn/src/QrcodeConnPresenter.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: QrcodeConnPresenter.cpp + * Author: + * Create: 2025-04-24 + */ +#include "qrcode_conn/QrcodeConnPresenter.h" +#include "uiservice/ui_service.h" +#include "NativeRegisterManager.h" + +namespace OHOS { + +REGIST_MENU(VIEW_QRCODE_CONN, QrcodeConnView, QrcodeConnPresenter, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_DEFAULT_IMG, + "二维码连接"); + +static QrcodeConnPresenter *g_QrcodeConnPresenter = nullptr; + +QrcodeConnPresenter::QrcodeConnPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "QrcodeConnPresenter::QrcodeConnPresenter"); + g_QrcodeConnPresenter = this; +} + +QrcodeConnPresenter::~QrcodeConnPresenter() {} + +QrcodeConnPresenter *QrcodeConnPresenter::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "QrcodeConnPresenter GetInstance"); + return g_QrcodeConnPresenter; +} + +bool QrcodeConnPresenter::OnDrag(UIView &view, const DragEvent &event) +{ + std::string id = view.GetViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "QrcodeConnPresenter::OnDrag [%s]", id.c_str()); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + return false; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/qrcode_conn/src/QrcodeConnView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/qrcode_conn/src/QrcodeConnView.cpp new file mode 100644 index 000000000..02efc59b7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/qrcode_conn/src/QrcodeConnView.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: QrcodeConnView.cpp + * Author: + * Create: 2025-04-24 + */ + +#include "qrcode_conn/QrcodeConnView.h" +#include "qrcode_conn/QrcodeConnPresenter.h" +#include "qrcode_conn/QrcodeConnModel.h" +#include "bluetooth/BluetoothModel.h" +#include "wearable_log.h" + +namespace OHOS { +static const uint32_t QRCODE_POS_X = 76; +static const uint32_t QRCODE_POS_Y = 76; +static const uint32_t QRCODE_WIDTH = 282; +static const uint32_t QRCODE_HEIGHT = 282; +static const uint32_t PAD_SIZE = 10; + +static QrcodeConnView *g_pQrcodeConnView = nullptr; + +QrcodeConnView::QrcodeConnView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "QrcodeConnView::QrcodeConnView"); + g_pQrcodeConnView = this; +} + +QrcodeConnView::~QrcodeConnView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "QrcodeConnView::~QrcodeConnView"); + g_pQrcodeConnView = nullptr; +} + +QrcodeConnView *QrcodeConnView::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "QrcodeConnView::GetInstance"); + return g_pQrcodeConnView; +} + +void QrcodeConnView::InitView() +{ + if (group_ == nullptr) { + group_ = new UIScrollView(); + group_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + if (qrcode_ == nullptr) { + qrcode_ = new UIQrcode(); + } + qrcode_->SetPosition(QRCODE_POS_X, QRCODE_POS_Y, QRCODE_WIDTH, QRCODE_HEIGHT); + qrcode_->SetQrcodeInfo(BluetoothModel::GetInstance()->getWatchName()); + qrcode_->SetStyle(STYLE_PADDING_LEFT, PAD_SIZE); + qrcode_->SetStyle(STYLE_PADDING_RIGHT, PAD_SIZE); + qrcode_->SetStyle(STYLE_PADDING_TOP, PAD_SIZE); + qrcode_->SetStyle(STYLE_PADDING_BOTTOM, PAD_SIZE); + group_->Add(qrcode_); + UIView::OnDragListener *dragListener = (UIView::OnDragListener *)OHOS::QrcodeConnPresenter::GetInstance(); + group_->SetOnDragListener(dragListener); + // 更新 + group_->SetVisible(true); + AddViewToRootContainer(group_); + GetRootContainer()->Invalidate(); +} + +void QrcodeConnView::DeInit() +{ + if (group_ != nullptr) { + group_->RemoveAll(); + delete group_; + group_ = nullptr; + } + if (qrcode_ != nullptr) { + delete qrcode_; + qrcode_ = nullptr; + } +} + +void QrcodeConnView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "QrcodeConnView::OnStart"); + InitView(); +} + +void QrcodeConnView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "QrcodeConnView::OnStop"); + DeInit(); + return; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootDeviceView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootDeviceView.cpp index d2777a947..60dad05ba 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootDeviceView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootDeviceView.cpp @@ -4,10 +4,11 @@ * Create: 2022-04-28 */ -#include "RebootDeviceView.h" +#include "rebootdevice/RebootDeviceView.h" +#include "PageTransitionMgr.h" #include "wearable_log.h" #include "UiConfig.h" -#include "RebootPresenter.h" +#include "rebootdevice/RebootPresenter.h" namespace OHOS { static RebootDeviceView *g_pRebootDeviceView{nullptr}; @@ -98,7 +99,7 @@ UIViewGroup *RebootDeviceView::InitShowUpView(void) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rebootDeviceDragListener GetInstance fail"); return nullptr; } - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly + if (!PageTransitionMgr::GetInstance().CanSlideBack()) { // support default slide back firstly group->SetOnDragListener(rebootDeviceDragListener); } group->SetViewId(REBOOTDEVICE_VIEW); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootModel.cpp index d974582fd..889715b37 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootModel.cpp @@ -4,7 +4,7 @@ * Create: 2022-04-28 */ -#include "RebootModel.h" +#include "rebootdevice/RebootModel.h" #include "dfx_reboot.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp index c248e7ea7..223e102dd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp @@ -4,9 +4,9 @@ * Create: 2022-04-28 */ -#include "RebootPresenter.h" -#include "RebootView.h" -#include "RebootModel.h" +#include "rebootdevice/RebootPresenter.h" +#include "rebootdevice/RebootView.h" +#include "rebootdevice/RebootModel.h" #include "drag_event.h" #include "wearable_log.h" #include "NativeRegisterManager.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootView.cpp index 5d8d43736..5c7956474 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootView.cpp @@ -4,11 +4,12 @@ * Create: 2022-04-28 */ -#include "RebootView.h" -#include "RebootModel.h" +#include "rebootdevice/RebootView.h" +#include "PageTransitionMgr.h" +#include "rebootdevice/RebootModel.h" #include "wearable_log.h" #include "UiConfig.h" -#include "RebootPresenter.h" +#include "rebootdevice/RebootPresenter.h" namespace OHOS { static RebootView *g_pRebootView{nullptr}; @@ -47,6 +48,7 @@ RebootView *RebootView::GetInstance() void RebootView::OnStart() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootView::~OnStart"); if (RebootModel::GetInstance()->GetSelectView() == REBOOT) { ChangeView(REBOOT_MAX, REBOOTVIEW); } else if (RebootModel::GetInstance()->GetSelectView() == REBOOTDEVICE) { @@ -161,7 +163,7 @@ UIViewGroup *RebootView::InitShowUpView(void) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rebootDragListener GetInstance fail"); return nullptr; } - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly + if (!PageTransitionMgr::GetInstance().CanSlideBack()) { // support default slide back firstly group->SetOnDragListener(rebootDragListener); } group->SetViewId(REBOOT_VIEW); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/ShutdownDeviceView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/ShutdownDeviceView.cpp index 24ef4ef1f..f2acf7ea8 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/ShutdownDeviceView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/ShutdownDeviceView.cpp @@ -4,10 +4,11 @@ * Create: 2022-04-28 */ -#include "ShutdownDeviceView.h" +#include "rebootdevice/ShutdownDeviceView.h" +#include "PageTransitionMgr.h" #include "wearable_log.h" #include "UiConfig.h" -#include "RebootPresenter.h" +#include "rebootdevice/RebootPresenter.h" namespace OHOS { static ShutdownDeviceView *g_pShutdownDeviceView{nullptr}; @@ -98,7 +99,7 @@ UIViewGroup *ShutdownDeviceView::InitShowUpView(void) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rebootDragListener GetInstance fail"); return nullptr; } - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly + if (!PageTransitionMgr::GetInstance().CanSlideBack()) { // support default slide back firstly group->SetOnDragListener(rebootDragListener); } group->SetViewId(SHUTDOWNDEVICE_VIEW); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/recent_app/src/RecentAppPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/recent_app/src/RecentAppPresenter.cpp new file mode 100644 index 000000000..63b9a668f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/recent_app/src/RecentAppPresenter.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2025 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 "recent_app/RecentAppPresenter.h" +#include "recent_app/RecentAppView.h" +#include "RecentManager.h" +#include "NativeRegisterManager.h" +#include "msg_center_customer.h" + +namespace OHOS { + +REGIST_SLICE(VIEW_RECENT_APP, RecentAppView, RecentAppPresenter); + + RecentAppPresenter::RecentAppPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecentAppPresenter::RecentAppPresenter()"); + } + + RecentAppPresenter::~RecentAppPresenter() {} + + void RecentAppPresenter::OnResume() + { + if (view_ != nullptr) { + view_->LoadContent(); + } + } + + bool RecentAppPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UIRollerView* roller = view_->GetRollerView(); + if (roller == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "roller is nullptr!"); + return false; + } + + UIViewGroup* currentItemGroup = roller->GetCurrentItem(); + if (currentItemGroup == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentItemGroup is nullptr!"); + return false; + } + + std::string itemName = roller->GetCurrentItemName(); + std::string prefix(itemName.begin(), itemName.begin() + RECENT_ITEM_PREFIX_LEN); + std::string name(itemName.begin() + RECENT_ITEM_PREFIX_LEN, itemName.end()); + + uint32_t sliceId = 0; + bool isNativeSlice = true; + if (prefix == RECENT_ITEM_NATIVE_PREFIX) { + sliceId = static_cast(std::stoul(name)); + } else { + isNativeSlice = false; + } + + const char* viewId = view.GetViewId(); + if (viewId != nullptr && strcmp(viewId, RECENT_APP_DELETE_BTN_ID) == 0) { + if (isNativeSlice) { + RecentManager::GetInstance()->RemoveRecentApp(sliceId); + } else { + RecentManager::GetInstance()->RemoveRecentApp(name.c_str()); + } + roller->RemoveItem(itemName); + return true; + } + + Point clickPoint = event.GetCurrentPos(); + Rect rect = currentItemGroup->GetChildrenHead()->GetRect(); + if (rect.IsContains(clickPoint)) { + if (isNativeSlice) { + NativeAbility::GetInstance().ChangeSlice(sliceId); + } else { +#ifdef JS_ENABLE + StartJsApp(const_cast(name.c_str())); +#endif + } + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/recent_app/src/RecentAppView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/recent_app/src/RecentAppView.cpp new file mode 100644 index 000000000..792432059 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/recent_app/src/RecentAppView.cpp @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2025 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 "recent_app/RecentAppView.h" +#include "wearable_log.h" +#include "common/image_cache_manager.h" +#include "common/screen.h" +#include "Slice.h" +#include "RecentManager.h" + +namespace OHOS { +static constexpr uint8_t DEFAULT_TEXT_SIZE = 30; +RecentAppView::RecentAppView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecentAppView::RecentAppView"); + loadingAnimCb_.SetRecentAppView(this); +} + +RecentAppView::~RecentAppView() +{ + if (roller_ != nullptr) { + delete roller_; + } + if (loadingAnim_ != nullptr) { + if (loadingAnim_->GetState() != Animator::STOP) { + loadingAnim_->Stop(); + } + delete loadingAnim_; + } + if (loadingLabel_ != nullptr) { + delete loadingLabel_; + } + if (noRecentAppLabel_ != nullptr) { + delete noRecentAppLabel_; + } + if (delBtn_ != nullptr) { + delete delBtn_; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecentAppView::~RecentAppView"); +} + +void RecentAppView::OnStart(void) +{ + UIViewGroup* container = GetRootContainer(); + + loadingLabel_ = new UILabel(); + if (loadingLabel_ == nullptr) { + return; + } + container->Add(loadingLabel_); + loadingLabel_->SetText("Loading..."); + loadingLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DEFAULT_TEXT_SIZE); + loadingLabel_->Resize(300, 100); // 300, 100: size + loadingLabel_->LayoutCenterOfParent(); + loadingLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); +} + +void RecentAppView::LoadContent() +{ + if (viewiInitStatus_) { + return; + } + + UIViewGroup* rootContainer = GetRootContainer(); + if (!RecentManager::GetInstance()->IsUpdateCompleted()) { + loadingAnim_ = new Animator(&loadingAnimCb_, roller_, 0, true); + if (loadingAnim_ == nullptr) { + return; + } + loadingAnim_->Start(); + } else { + LoadRecentAppContent(); + } + viewiInitStatus_ = true; +} + +void RecentAppView::LoadingAnimCb::Callback(UIView* view) +{ + if (RecentManager::GetInstance()->IsUpdateCompleted()) { + recentAppView_->LoadRecentAppContent(); + } +} + +void RecentAppView::AddRecentAppToRoller() +{ + const List& recent = RecentManager::GetInstance()->GetRecentApps(); + ListNode* node = recent.Begin(); + std::string alignItemName = ""; + while (node != recent.End()) { + RecentAppInfo* appInfo = node->data_; + ImageInfo* imgInfo = appInfo->snapshot; + std::string name; + if (appInfo->isNativeSlice) { + name = RECENT_ITEM_NATIVE_PREFIX + std::to_string(appInfo->targetId & SLICE_MASK); + } else { + name = RECENT_ITEM_JS_PREFIX + appInfo->bundleName; + } + if (imgInfo->data != nullptr) { + roller_->AddItem(name, imgInfo); + } else { + std::string path(appInfo->snapshot->file, appInfo->snapshot->fileLen); + if (appInfo->snapshot->resId == 0) { + imgInfo = ImageCacheManager::GetInstance().LoadSingleRes(path); + } else { + imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(appInfo->snapshot->resId, path); + } + + if (imgInfo == nullptr) { + GRAPHIC_LOGE("Load res failed: %s", path.c_str()); + node = node->next_; + continue; + } + roller_->AddItem(name, imgInfo); + } + node = node->next_; + if (alignItemName == "") { + alignItemName = name; + } + } + roller_->SetCurrentItem(alignItemName); +} + +void RecentAppView::InitRecentApps() +{ + if (delBtn_ == nullptr) { + delBtn_ = new UILabelButton(); + } + if (delBtn_ == nullptr) { + GRAPHIC_LOGE("new delBtn_ failed!"); + return; + } + + if (roller_ == nullptr) { + roller_ = new UIRollerView(false); + } + if (roller_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UIRollerView fail"); + return; + } + + UIView::OnClickListener* onClickListener = dynamic_cast(presenter_); + + GetRootContainer()->Add(roller_); + roller_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + roller_->SetItemSize(250, 250); // 250: item size + roller_->SetThrowDrag(true); + roller_->SetItemPadding(80); // 80: item padding + roller_->SetCamDistance(380); // 380: Camera distance + roller_->SetCamY(48); // 48: camY + roller_->SetOnClickListener(onClickListener); + + GetRootContainer()->Add(delBtn_); + delBtn_->Resize(120, 50); // 120,50: width and height + delBtn_->LayoutCenterOfParent(0, 180); // 180: y offset + delBtn_->SetText("delete"); + delBtn_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DEFAULT_TEXT_SIZE); + delBtn_->SetViewId(RECENT_APP_DELETE_BTN_ID); + delBtn_->SetOnClickListener(onClickListener); + + AddRecentAppToRoller(); +} + +void RecentAppView::LoadRecentAppContent() +{ + if (loadingAnim_ != nullptr) { + loadingAnim_->Stop(); + } + + if (loadingLabel_ != nullptr) { + loadingLabel_->SetVisible(false); + } + + uint32_t size = RecentManager::GetInstance()->GetCurrentSize(); + if (size == 0) { + if (noRecentAppLabel_ == nullptr) { + noRecentAppLabel_ = new UILabel(); + } + if (noRecentAppLabel_ != nullptr) { + GetRootContainer()->Add(noRecentAppLabel_); + noRecentAppLabel_->SetText("No Recent App."); + noRecentAppLabel_->Resize(300, 100); // 300, 100: size + noRecentAppLabel_->LayoutCenterOfParent(); + noRecentAppLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + } + return; + } + + InitRecentApps(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestoreDefaultsView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestoreDefaultsView.cpp index 707c2b7b7..90e10c7b9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestoreDefaultsView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestoreDefaultsView.cpp @@ -4,7 +4,7 @@ * Create: 2024-08-12 */ -#include "RestoreDefaultsView.h" +#include "restoredefaults/RestoreDefaultsView.h" #include "components/ui_label.h" #include "wearable_log.h" #include "UiConfig.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestorePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestorePresenter.cpp index 8fb3a7676..47a30ab48 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestorePresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestorePresenter.cpp @@ -4,9 +4,9 @@ * Create: 2024-08-12 */ -#include "RestoreDefaultsPresenter.h" -#include "RestoreDefaultsView.h" -#include "BluetoothModel.h" +#include "restoredefaults/RestoreDefaultsPresenter.h" +#include "restoredefaults/RestoreDefaultsView.h" +#include "bluetooth/BluetoothModel.h" #include "bts_br_gap.h" #include "drag_event.h" #include "cmsis_os.h" @@ -17,6 +17,10 @@ #ifdef SUPPORT_ALIPAY_SEC #include "alipay_feature.h" #endif +#include "adapter.h" +#include "bundlems_slite_client.h" +#include "abilityms_slite_client.h" +#include "stopwatch/StopwatchModel.h" namespace OHOS { @@ -56,6 +60,11 @@ bool RestoreDefaultsPresenter::OnClick(UIView &view, const ClickEvent &event) return true; } +static void UninstallCallbackFunc(const uint8_t resultCode, const void *resultMessage) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UninstallCallbackFunc."); +} + void RestoreDefaultsPresenter::ConfirmOnClick() { bool res = bluetooth_factory_reset(); @@ -64,6 +73,53 @@ void RestoreDefaultsPresenter::ConfirmOnClick() (void)uapi_alipay_svr_reset(); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_alipay_svr_reset process."); #endif + + BundleInfo *bundleInfos = nullptr; + int32_t count = 0; + int32_t ret = ERRCODE_FAIL; + + ret = OHOS::BundleMsClient::GetInstance().GetBundleInfos(0, &bundleInfos, &count); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetBundleInfos count = %d bundleRet = 0x%x", count, ret); + if (ret != 0) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Get bundleInfos Failed\n"); + }else { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "\n" + "----------------- AppList Start --------------------\n"); + for (int32_t i = 0; i < count; i++) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, + "App:%d-----------------\n" + "label: %s\n" + "bundleName: %s\n", + i+1, + bundleInfos[i].label, + bundleInfos[i].bundleName + ); + ElementName* topAbility = OHOS::AbilityMsClient::GetInstance().GetTopAbility(); + + if ((topAbility != nullptr) && (strcmp(topAbility->bundleName, bundleInfos[i].bundleName) == 0)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "js app is active, first need terminate"); + int token = 0; + OHOS::AbilityMsClient::GetInstance().TerminateAbility(token); + } + + InstallParam installParam = { .installLocation = 1, .keepData = false }; + OHOS::BundleMsClient::GetInstance().Uninstall(bundleInfos[i].bundleName, &installParam, UninstallCallbackFunc); + FreeElement(topAbility); + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "\n" + "----------------- AppList End -----------------------\n"); + } + if (bundleInfos != nullptr) { + for (uint8_t i = 0; i < count; i++) { + ClearBundleInfo(bundleInfos + i); + } + + if (bundleInfos != nullptr) { + AdapterFree(bundleInfos); + bundleInfos = nullptr; + } + } + StopwatchModel::GetInstance().ClearData(); uapi_system_reboot(SYSTEM_SOFT_REBOOT); return; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestoreSelectView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestoreSelectView.cpp index 9c04748d0..d51d35f10 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestoreSelectView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/restoredefaults/src/RestoreSelectView.cpp @@ -3,10 +3,11 @@ * Description: RestoreSelect View * Create: 2024-08-12 */ -#include "RestoreSelectView.h" +#include "restoredefaults/RestoreSelectView.h" +#include "PageTransitionMgr.h" #include "wearable_log.h" #include "UiConfig.h" -#include "RestoreDefaultsPresenter.h" +#include "restoredefaults/RestoreDefaultsPresenter.h" namespace OHOS { static RestoreSelectView *g_pRestoreSelectView { nullptr }; @@ -110,7 +111,7 @@ UIViewGroup *RestoreSelectView::InitShowUpView() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "connectDragListener GetInstance fail"); return nullptr; } - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly + if (!PageTransitionMgr::GetInstance().CanSlideBack()) { // support default slide back firstly group->SetOnDragListener(connectDragListener); } group->SetViewId(RESTORE_SELECT_VIEW); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/rtcservice/src/RtcService.cpp b/code/sdk/application/wearable/nativeapp/nativeui/rtcservice/src/RtcService.cpp index bd99bcdb1..5814fee69 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/rtcservice/src/RtcService.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/rtcservice/src/RtcService.cpp @@ -14,8 +14,8 @@ #include "securec.h" #include "broadcast_service.h" -#include "AlmmgrAlarmClockManage.h" -#include "RtcService.h" +#include "alarmclockmanage/AlmmgrAlarmClockManage.h" +#include "rtcservice/RtcService.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/screennotify/src/ui_screennotify.cpp b/code/sdk/application/wearable/nativeapp/nativeui/screennotify/src/ui_screennotify.cpp index 89cef0ac3..991ee5938 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/screennotify/src/ui_screennotify.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/screennotify/src/ui_screennotify.cpp @@ -9,16 +9,22 @@ #include "power_display_service.h" #include "NativeAbility.h" #include "AppViewIDs.h" -#include "MainViewSample.h" -#include "ui_screennotify.h" +#include "main/MainViewSample.h" +#include "screennotify/ui_screennotify.h" #include "components/root_view.h" #include "notification_manager.h" -#include "DialBinTypesV2.h" +#include "main/DialBinTypesV2.h" +#include "hal_tick.h" +#include "abilityms_slite_client.h" #ifdef __cplusplus extern "C" { #endif static uint32_t g_back_to_home_interval = 5; +static uint32_t g_back_to_pre_slice = 5; +static uint32_t g_last_aod_on_stamp = 0; +static std::string g_pre_bundle_name = "com.huawei.launcher"; +static bool g_is_native = true; // 需要屏蔽掉的slice,ignore_slice_ids数组中的slice灭屏超时后不会调转到默认界面 uint16_t ignore_slice_ids[] = { @@ -59,25 +65,53 @@ static void ChangeToHomeView(void) } } -static void GuiEnterAod(bool entry) +static void EnterAod() { using namespace OHOS; - DisplayState newState = entry ? DisplayState::AOD : DisplayState::NORMAL; - - uint16_t current_slice_id = NativeAbility::GetInstance().GetCurSliceId(); - for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) { - if (ignore_slice_ids[i] == current_slice_id) { - return; + g_last_aod_on_stamp = HALTick::GetInstance().GetTime(); + if (NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) { + g_is_native = true; + } else { + ElementName *elementName = AbilityMsClient::GetInstance().GetTopAbility(); + if (elementName != nullptr) { + g_pre_bundle_name = elementName->bundleName; } + g_is_native = false; } - if (NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) { - if (newState == DisplayState::AOD) { - NativeAbility::GetInstance().ChangeSlice(VIEW_AOD); - } else { - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + NativeAbility::GetInstance().ChangeSlice(VIEW_AOD); +} + +static void ExitAod() +{ + using namespace OHOS; + uint32_t aodDur = HALTick::GetInstance().GetElapseTime(g_last_aod_on_stamp) / 1000; // 1000: 1s = 1000ms + if (aodDur > g_back_to_pre_slice) { + uint16_t sliceId = NativeAbility::GetInstance().GetPreTargetId() & SLICE_MASK; + for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) { + if (ignore_slice_ids[i] == sliceId) { + NativeAbility::GetInstance().ChangeSlice(sliceId); + return; + } } + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } else { + if (!g_is_native) { + Want *want = new Want(); + memset_s(want, sizeof(Want), 0, sizeof(Want)); + ElementName startElement = {}; + startElement.abilityName = "default"; + startElement.bundleName = const_cast(g_pre_bundle_name.c_str()); + startElement.deviceId = nullptr; + SetWantElement(want, startElement); + StartAbility(want); + ClearWant(want); + delete want; + return; + } + uint32_t preId = NativeAbility::GetInstance().GetPreTargetId(); + NativeAbility::GetInstance().SwitchSlice(preId & SLICE_MASK, preId >> PAGE_OFFSET); } -}; +} void notify_screen_on_event(void) { @@ -103,12 +137,12 @@ void notify_screen_off_event(void) void notify_screen_aod_on_event(void) { - GuiEnterAod(true); + EnterAod(); } void notify_screen_aod_off_event(void) { - GuiEnterAod(false); + ExitAod(); } void set_back_to_home_interval(uint32_t time_sec) @@ -121,6 +155,16 @@ uint32_t get_back_to_home_interval(void) return g_back_to_home_interval; } +void set_back_to_pre_slice_interval(uint32_t time_sec) +{ + g_back_to_pre_slice = time_sec; +} + +uint32_t get_back_to_pre_slice_interval(void) +{ + return g_back_to_pre_slice; +} + void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback) { if (callback != nullptr) { 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 5720b8336..6be2328bd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp @@ -13,7 +13,7 @@ #include #include "kvstore_env.h" #include "kv_store.h" -#include "ScreenModels.h" +#include "screensetting/ScreenModels.h" #include "common/image_cache_manager.h" #include "UiConfig.h" #include "ui_resource_image.h" @@ -38,7 +38,7 @@ void ScreenModels::InitKvStorage(void) { #if !defined(_WIN32) #ifndef XTS_SUPPORT - int ret = UtilsSetEnv("/user/system"); + int ret = UtilsSetEnv("/user"); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "UtilsSetEnv /user ret = %d", ret); #endif #else 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 index badbc10dc..5d15eb63e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardAdapter.cpp @@ -5,7 +5,7 @@ * Create: 2021-09-18 */ -#include "SetCardAdapter.h" +#include "set_card/SetCardAdapter.h" namespace OHOS { SetCardAdapter::SetCardAdapter() {} 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 index c916f4c7f..f37a50d36 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardDeleteView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardDeleteView.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "SetCardDeleteView.h" +#include "set_card/SetCardDeleteView.h" #include "wearable_log.h" namespace OHOS { 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 index 4bdd7ba98..7d08205d9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardItem.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardItem.cpp @@ -1,5 +1,5 @@ -#include "SetCardItem.h" -#include "SetCardPresenter.h" +#include "set_card/SetCardItem.h" +#include "set_card/SetCardPresenter.h" #include "wearable_log.h" namespace OHOS { 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 index 32ca2b547..df4d971e3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardModel.cpp @@ -5,8 +5,8 @@ * Create: 2021-11-23 */ -#include "SetCardModel.h" -#include "MainModel.h" +#include "set_card/SetCardModel.h" +#include "main/MainModel.h" #include "kv_store.h" #include "securec.h" 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 index eadcec935..f09315818 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardNoCardView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardNoCardView.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "SetCardNoCardView.h" +#include "set_card/SetCardNoCardView.h" #include "wearable_log.h" namespace OHOS { 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 index 1012057c9..0a93f42d8 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardPresenter.cpp @@ -5,9 +5,9 @@ * Create: 2021-11-23 */ -#include "SetCardView.h" -#include "SetCardModel.h" -#include "SetCardPresenter.h" +#include "set_card/SetCardView.h" +#include "set_card/SetCardModel.h" +#include "set_card/SetCardPresenter.h" #include "hal_tick.h" #include "NativeRegisterManager.h" 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 index c375c864c..b9d31c386 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_card/src/SetCardView.cpp @@ -6,8 +6,8 @@ */ #include -#include "SetCardView.h" -#include "SetCardPresenter.h" +#include "set_card/SetCardView.h" +#include "set_card/SetCardPresenter.h" namespace OHOS { SetCardView::SetCardView():contentList_(UIList::HORIZONTAL) 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 deleted file mode 100644 index 93c05876e..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopPresenter.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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"; -static const char *SET_DESKTOP_FOOTBALL = "setdesktopFootball"; -static const char *SET_DESKTOP_WATERFALL = "setdesktopWaterfall"; - -class SetDesktopView; -class SetDesktopModel; -class SetDesktopPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener { -public: - SetDesktopPresenter(); - ~SetDesktopPresenter() override; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView& view, const DragEvent& event) override; - uint8_t GetCurrentStyle(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 deleted file mode 100644 index 8de637987..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/include/SetDesktopView.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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_scroll_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 "ChangeSliceListener.h" -#include "UiConfig.h" - -namespace OHOS { -class SetDesktopPresenter; - -class SetDesktopView : public View { -public: - SetDesktopView(); - ~SetDesktopView() override; - - static SetDesktopView *GetInstance() - { - static SetDesktopView instance; - return &instance; - } - - void OnStart() override; - void UpdateSelectedStyle(uint8_t selectedStyle); - uint8_t GetCurrentSelectedStyle(void); - -private: - void InitFootballItem(); - void InitWaterfallItem(); - UIScrollView *scrollview{nullptr}; - UILabel titleText; - UIToggleButton hexagonsBtn; - UIToggleButton listBtn; - UIToggleButton footballBtn_; - UIToggleButton waterfallBtn_; - UIImageView hexagonsImage; - UIImageView listImage; - UIImageView footballImage_; - UIImageView waterfallImage_; - UILabel listText; - UILabel hexagonsText; - UILabel footballText_; - UILabel waterfallText_; -}; -} -#endif // SET_DESKTOP_VIEW_H 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 deleted file mode 100644 index 68b000b03..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopPresenter.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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" -#include "NativeRegisterManager.h" - -namespace OHOS { - -REGIST_SLICE(VIEW_SET_DESKTOP, SetDesktopView, SetDesktopPresenter); - - SetDesktopPresenter::SetDesktopPresenter() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopPresenter::SetDesktopPresenter"); - } - - SetDesktopPresenter::~SetDesktopPresenter() {} - - 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(DesktopStyle::HEXAGONS_STYLE); - } else if (strcmp(view.GetViewId(), SET_DESKTOP_LIST) == 0) { - SetDesktopModel::GetInstance().SetDesktopStyle(DesktopStyle::APPLIST_STYLE); - } else if (strcmp(view.GetViewId(), SET_DESKTOP_FOOTBALL) == 0) { - SetDesktopModel::GetInstance().SetDesktopStyle(DesktopStyle::FOOTBALL_STYLE); - } else if (strcmp(view.GetViewId(), SET_DESKTOP_WATERFALL) == 0) { - SetDesktopModel::GetInstance().SetDesktopStyle(DesktopStyle::WATERFALL_STYLE); - } - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(preSlice); - return true; - } - - uint8_t SetDesktopPresenter::GetCurrentStyle(void) - { - DesktopStyle style = SetDesktopModel::GetInstance().GetDesktopStyle(); - if (style == HEXAGONS_STYLE) { - return 1; // 1: hexagons style enum index - } else if (style == FOOTBALL_STYLE) { - return 2; // 2: football style enum index - } else if (style == WATERFALL_STYLE) { - return 3; // 3: waterfall style enum index - } - return 0; - } -} 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 index 974954c3a..8f15cfcd0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialModel.cpp @@ -5,12 +5,12 @@ * Create: 2021-11-23 */ #include -#include "MainModel.h" -#include "SetDialModel.h" +#include "main/MainModel.h" +#include "set_dial/SetDialModel.h" #include "kv_store.h" #include "securec.h" #include "dirent.h" -#include "DialBinParser.h" +#include "main/DialBinParser.h" #include "wearable_log.h" namespace OHOS { @@ -108,7 +108,7 @@ namespace OHOS { return -1; } DialPreviewInfo preInfo{0}; - bool ret = DialBinParserManager::GetInstance()->GetDialPreviewInfo(fp, &preInfo); + bool ret = DialBinParserManager::GetInstance()->GetDialPreviewInfo(dialFullName, fp, &preInfo); if (!ret) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetDialPreviewInfo %s fail", dialFullName.c_str()); 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 index f769b0f9d..e33267320 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp @@ -5,14 +5,17 @@ * Create: 2021-11-23 */ -#include "SetDialView.h" -#include "SetDialModel.h" -#include "SetDialPresenter.h" +#include "set_dial/SetDialView.h" +#include "set_dial/SetDialModel.h" +#include "set_dial/SetDialPresenter.h" #include "hal_tick.h" #include "NativeRegisterManager.h" namespace OHOS { +namespace { +SetDialPresenter *g_presenter = nullptr; +} // anonymous namespace REGIST_SLICE(VIEW_SET_DIAL, SetDialView, SetDialPresenter); @@ -22,10 +25,25 @@ REGIST_SLICE(VIEW_SET_DIAL, SetDialView, SetDialPresenter); model = &SetDialModel::GetInstance(); model->LoadAllDial(); ResetTickTimer(); + g_presenter = this; + specificSetting.dialFlag = 0; + specificSetting.dialId = 0; } SetDialPresenter::~SetDialPresenter() { + g_presenter = nullptr; + } + + SetDialPresenter *SetDialPresenter::GetCurrentInstance() + { + return g_presenter; + } + + void SetDialPresenter::SpecifyDialSetting(const DialSetting &setting) + { + isSpecific = true; + specificSetting = setting; } void SetDialPresenter::OnClickAction(void) @@ -79,6 +97,10 @@ REGIST_SLICE(VIEW_SET_DIAL, SetDialView, SetDialPresenter); void SetDialPresenter::OnStop() { model->ClearDialInfo(); + if (isSpecific) { + MainModel::GetInstance().GetDialSetting() = specificSetting; + MainModel::GetInstance().AddDialSetting(specificSetting); + } } void SetDialPresenter::ResetTickTimer(void) 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 index 15bba5fd5..a932d18be 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial/src/SetDialView.cpp @@ -6,9 +6,9 @@ */ #include -#include "SetDialView.h" -#include "SetDialPresenter.h" -#include "SetDialStyleModel.h" +#include "set_dial/SetDialView.h" +#include "set_dial/SetDialPresenter.h" +#include "set_dial_style/SetDialStyleModel.h" namespace OHOS { SetDialView::SetDialView() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStyleModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStyleModel.cpp index 81d833aef..3126804b3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStyleModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStyleModel.cpp @@ -5,7 +5,7 @@ * Create: 2024-06-06 */ -#include "SetDialStyleModel.h" +#include "set_dial_style/SetDialStyleModel.h" #include "kv_store.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStylePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStylePresenter.cpp index 6980d5f48..8c85a6a34 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStylePresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStylePresenter.cpp @@ -5,9 +5,9 @@ * Create: 2024-06-06 */ -#include "SetDialStyleView.h" -#include "SetDialStyleModel.h" -#include "SetDialStylePresenter.h" +#include "set_dial_style/SetDialStyleView.h" +#include "set_dial_style/SetDialStyleModel.h" +#include "set_dial_style/SetDialStylePresenter.h" #include "NativeRegisterManager.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStyleView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStyleView.cpp index 7d786aab4..85d72a819 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStyleView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_dial_style/src/SetDialStyleView.cpp @@ -5,10 +5,11 @@ * Create: 2024-06-06 */ -#include "SetDialStyleView.h" -#include "SetDialStyleModel.h" -#include "SetDialStylePresenter.h" -#include "MainModel.h" +#include "set_dial_style/SetDialStyleView.h" +#include "PageTransitionMgr.h" +#include "set_dial_style/SetDialStyleModel.h" +#include "set_dial_style/SetDialStylePresenter.h" +#include "main/MainModel.h" namespace OHOS { SetDialStyleView::SetDialStyleView() @@ -23,7 +24,7 @@ void SetDialStyleView::OnStart() { GetRootContainer()->SetDraggable(true); GetRootContainer()->SetTouchable(true); - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly + if (!PageTransitionMgr::GetInstance().CanSlideBack()) { // support default slide back firstly GetRootContainer()->SetOnDragListener(presenter_); } const int16_t BTN_HEIGHT = 55; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_ota/src/OTAModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_ota/src/OTAModel.cpp new file mode 100644 index 000000000..60715c5f4 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_ota/src/OTAModel.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: ota local update + * Author: wangle + * Create: 2025-5-6 + */ +#include "set_ota/OTACommon.h" +#include "set_ota/OTAModel.h" +#include "set_ota/OTAPresenter.h" +#include "tcxo.h" +#include "upg.h" +#include "upg_porting.h" +#include "upg_definitions.h" +#include "upg_common_porting.h" +#include "wearable_log.h" + + +namespace OHOS { +OTAModel::OTAModel() +{ + isIdel = true; + wait.wait = nullptr; + if (osal_wait_init(&wait) != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ota osal_wait_init error"); + return; + } + task = osal_kthread_create(&OTAModel::OSALKthreadCallback, this, "ota_model", MODLE_THREAD_STACK_SIZE); + if (task == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ota osal_wait_init error"); + osal_wait_destroy(&wait); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "model init succ"); +} +OTAModel::~OTAModel() +{ + if (task != nullptr) { + osal_kthread_destroy(task, 0); + } + if (wait.wait != nullptr) { + osal_wait_destroy(&wait); + } +} + +int OTAModel::WaitCondition(const void *data) +{ + OTAModel *model = (OTAModel *)data; + return model->isIdel ? 0 : 1; // 不空闲说明有任务 +} + +int OTAModel::OSALKthreadCallback(void *data) +{ + OTAModel *model = (OTAModel *)data; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "model thread... callback"); + while (true) { // osal_kthread_destroy规定 线程销毁前必须一直存在 + osal_wait_interruptible(&model->wait, &OTAModel::WaitCondition, data); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "model thread... wait done"); + model->SwitchTask(); + } + return 0; +} +bool OTAModel::ModelRunTask(TaskType tasktype, void *taskdata) +{ + if (!isIdel) + return false; + type = tasktype; + data = taskdata; + isIdel = false; + osal_wait_wakeup(&wait); + return true; +} +void OTAModel::SwitchTask() +{ + switch (type) { + case TaskType::UpdateInfo: + UpdateInfo(data); + isIdel = true; + break; + case TaskType::LocalUpdate: + LocalUpdate(data); + isIdel = true; + break; + default: + break; // 不处理 + } +} + +void OTAModel::UpdateInfo(void *data) +{ + uint32_t total_size = 0; + do { + FILE *fp = fopen(upg_get_pkg_file_path(), "rb"); + if (fp == nullptr) { + break; + } + fseek(fp, 0L, SEEK_END); + total_size = ftell(fp); + fclose(fp); + } while (false); + presenter_->SetPackageInfo(upg_get_pkg_file_path(), total_size); +} +void OTAModel::LocalUpdate(void *data) +{ + upg_prepare_info_t info{((LocalUpdateData *)data)->fileSize}; + + // update 准备工作 + presenter_->SetUpdateProgress("upg_prepare", LOCAL_UPDATE_PROGRESS_5); + errcode_t ret = uapi_upg_prepare(&info); + if (ret != ERRCODE_SUCC) { + presenter_->SetErrorMessage("uapi_upg_prepare error"); + return; + } + + // update 申请升级 + presenter_->SetUpdateProgress("upg_request_upgrade", LOCAL_UPDATE_PROGRESS_25); + ret = uapi_upg_request_upgrade(false); + if (ret != ERRCODE_SUCC) { + presenter_->SetErrorMessage("uapi_upg_request_upgrade error"); + return; + } + // 备份 + presenter_->SetUpdateProgress("upg_image_backups", LOCAL_UPDATE_PROGRESS_40); + ret = upg_image_backups_update(); + if (ret != ERRCODE_SUCC) { + presenter_->SetErrorMessage("upg_image_backups_update error"); + return; + } + + // update 开始升级 + presenter_->SetUpdateProgress("upg_start", LOCAL_UPDATE_PROGRESS_50); + ret = uapi_upg_start(); + if (ret != ERRCODE_SUCC) { + presenter_->SetErrorMessage("uapi_upg_start error"); + return; + } + presenter_->SetUpdateProgress("reboot", LOCAL_UPDATE_PROGRESS_100); + DelayRebootFor5S(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "update"); +} +void OTAModel::DelayRebootFor5S() +{ + char temp[60] = ""; + for (int i = 5; i > 0; i--) { + sprintf_s(temp, sizeof(temp), "%ds后系统将进行重启\r\n完成后续升级操作", i); + presenter_->SetMessage(temp); + osal_msleep(SLEEP_TIME_S); + } + upg_reboot(); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_ota/src/OTAPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_ota/src/OTAPresenter.cpp new file mode 100644 index 000000000..a77f53fc4 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_ota/src/OTAPresenter.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: ota local update + * Author: wangle + * Create: 2025-5-6 + */ +#include "AppViewIDs.h" +#include "NativeRegisterManager.h" +#include "gfx_utils/graphic_math.h" +#include "set_ota/OTACommon.h" +#include "set_ota/OTAView.h" +#include "set_ota/OTAPresenter.h" +#include "set_ota/OTAModel.h" +#include "main/HealthModel.h" +#include "uiservice/ui_service.h" + +namespace OHOS { + +REGIST_SLICE(VIEW_SET_OTA, OTAView, OTAPresenter); + +void OTAPresenter::OnStart() +{ + if (model_ == nullptr) { + Attach(new OTAModel); + } + if (model_ != nullptr) { + model_->Attach(this); + } + view_->SetUpdateDisable(); + view_->SetMessage("正在获取升级文件信息..."); + view_->SetProgress(0); + model_->ModelRunTask(TaskType::UpdateInfo, nullptr); +} +void OTAPresenter::OnStop() +{ + if (model_ != nullptr) { + delete model_; + model_ = nullptr; + } +} +bool OTAPresenter::OnClick(UIView &view, const ClickEvent &event) +{ + if (strcmp(view.GetViewId(), "update") == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTA OnClick... update"); + // 调用model升级方法 + model_->ModelRunTask(TaskType::LocalUpdate, nullptr); + view_->SetMessage("正在升级..."); + view_->SetProgress(0); + view_->SetUpdateDisable(); + updateEnable = true; // 升级中, 禁止右滑退出 + SaveSystemScreen(); // 升级中, 设置屏幕常亮 + } + return true; +} +bool OTAPresenter::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTA OnDrag..."); + if (updateEnable && event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + int16_t deltaX = event.GetDeltaX(); + int16_t deltaY = event.GetDeltaY(); + if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > SLIDING_LENGTH) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM); + } + } + return true; +} + +void OTAPresenter::SetPackageInfo(const char *filePath, uint32_t fileSize) +{ + char tempBuffer[60] = ""; + updateFilePath = filePath; + updateFileSize = fileSize; + updateEnable = true; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTA SetPackageInfo"); + if (fileSize != 0) { + double tempSizeMB = 1.0 * updateFileSize / 1024 / 1024; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "calc"); + sprintf_s(tempBuffer, sizeof(tempBuffer), "升级文件:%s\r\n大小:%.2lfMB", filePath, tempSizeMB); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "sprintf"); + view_->SetUpdateEnable(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "View setEnable"); + view_->SetMessage(tempBuffer); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "view SetMessage"); + } else { + sprintf_s(tempBuffer, sizeof(tempBuffer), "升级文件:%s\r\n不存在或已损坏", filePath); + view_->SetUpdateDisable(); + view_->SetMessage(tempBuffer); + } +} + +void OTAPresenter::SetUpdateProgress(const char *message, uint8_t progress) +{ + char tempBuffer[60] = ""; + sprintf_s(tempBuffer, sizeof(tempBuffer), "正在升级...%u%%...\r\n%s", progress, message); + view_->SetMessage(tempBuffer); + view_->SetProgress(progress); +} +void OTAPresenter::SetErrorMessage(const char *message) +{ + char tempBuffer[60] = ""; + sprintf_s(tempBuffer, sizeof(tempBuffer), "升级失败...\r\n%s", message); + view_->SetMessage(tempBuffer); + view_->SetUpdateEnable(); // 升级失败后, 允许重新升级 + updateEnable = false; // 升级失败后, 允许右滑退出 + BackSystemScreen(); // 升级失败后, 回滚屏幕亮屏设置 +} +void OTAPresenter::SetMessage(const char *message) +{ + view_->SetMessage(message); +} +void OTAPresenter::SaveSystemScreen() +{ + briScrStatus = HealthModel::GetInstance()->GetBriScrStatus(); + if (briScrStatus == 0) { // 若系统常亮未打开则打开系统常亮 + ScreenOffEnable(0); + HealthModel::GetInstance()->UpdateBriScrStatus(1); + } +} +void OTAPresenter::BackSystemScreen() +{ + if (briScrStatus == 0) { // 若系统原本未处于常亮则恢复 + ScreenOffEnable(1); + HealthModel::GetInstance()->UpdateBriScrStatus(0); + } +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_ota/src/OTAView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/set_ota/src/OTAView.cpp new file mode 100644 index 000000000..1161894fa --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/set_ota/src/OTAView.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: ota local update + * Author: wangle + * Create: 2025-5-6 + */ +#include "UiConfig.h" +#include "set_ota/OTACommon.h" +#include "set_ota/OTAView.h" +#include "set_ota/OTAPresenter.h" +#include "wearable_log.h" + +namespace OHOS { +void OTAView::OnStart() +{ + InitMessageCtrl(); + InitProgressCtrl(); + InitUpdateCtrl(); + AddCtrlToView(); +} +void OTAView::InitMessageCtrl() +{ + if (message == nullptr) { + message = new UILabel(); + } + message->SetPosition(VIEW_MESSAGE_X, VIEW_MESSAGE_Y); + message->Resize(VIEW_MESSAGE_W, VIEW_MESSAGE_H); + message->SetViewId("message"); + message->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + message->SetStyle(STYLE_TEXT_FONT, VIEW_MESSAGE_FONT); + message->SetStyle(STYLE_LINE_SPACE, 0); + + message->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + message->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + message->SetRollSpeed(0); + message->SetFont(DEFAULT_VECTOR_FONT_FILENAME, VIEW_MESSAGE_FONT); +} +void OTAView::InitProgressCtrl() +{ + if (progress == nullptr) { + progress = new UIBoxProgress(); + } + progress->SetViewId("progress"); + progress->SetDirection(UIBoxProgress::Direction::DIR_LEFT_TO_RIGHT); + progress->SetPosition(VIEW_PROGRESS_X, VIEW_PROGRESS_Y, VIEW_PROGRESS_W, VIEW_PROGRESS_H); + progress->SetValue(0); + progress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); + progress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); + progress->SetStyle(STYLE_BORDER_COLOR, Color::Yellow().full); + progress->SetStep(1); + progress->EnableBackground(true); +} +void OTAView::InitUpdateCtrl() +{ + if (update == nullptr) { + update = new UILabelButton(); + } + update->SetPosition(VIEW_UPDATE_X, VIEW_UPDATE_Y); + update->Resize(VIEW_UPDATE_W, VIEW_UPDATE_H); + update->SetViewId("update"); + update->SetText("升级"); + update->SetFont(DEFAULT_VECTOR_FONT_FILENAME, VIEW_UPDATE_FONT); + update->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + update->SetOnClickListener(presenter_); +} +void OTAView::AddCtrlToView() +{ + if (GetRootContainer() == nullptr) + return; + message->SetVisible(true); + progress->SetVisible(true); + update->SetVisible(true); + GetRootContainer()->Add(message); + GetRootContainer()->Add(progress); + GetRootContainer()->Add(update); + GetRootContainer()->SetTouchable(true); // 添加滑动响应 + GetRootContainer()->SetDraggable(true); + GetRootContainer()->SetOnDragListener(presenter_); +} +void OTAView::OnStop() +{ + DeInitMessageCtrl(); + DeInitProgressCtrl(); + DeInitUpdateCtrl(); +} +void OTAView::DeInitMessageCtrl() +{ + if (message != nullptr) { + delete message; + message = nullptr; + } +} +void OTAView::DeInitProgressCtrl() +{ + if (progress != nullptr) { + delete progress; + progress = nullptr; + } +} +void OTAView::DeInitUpdateCtrl() +{ + if (update != nullptr) { + delete update; + update = nullptr; + } +} +void OTAView::SetUpdateEnable() +{ + if (update == nullptr) + return; + update->Enable(); +} +void OTAView::SetUpdateDisable() +{ + if (update == nullptr) + return; + update->Disable(); +} + +void OTAView::SetMessage(const char *msg) +{ + if (message == nullptr) + return; + message->SetText(msg); +} +void OTAView::SetProgress(uint8_t progressNum) +{ + if (progress == nullptr) + return; + progress->SetValue(progressNum); +} + +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingPresenter.h deleted file mode 100644 index 6edba6ab1..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingPresenter.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingPresenter.h - * Author: - * Create: 2021-11-23 - */ - -#ifndef SETTING_PRESENTER_H -#define SETTING_PRESENTER_H - -#include "Presenter.h" -#include "components/ui_view.h" -#include "SettingAdapter.h" - -namespace OHOS { -class SettingView; -class SettingModel; -class SettingAdapter; -class SettingPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener { -public: - SettingPresenter(); - ~SettingPresenter() override; - - void OnStart() override; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView& view, const DragEvent& event) override; -private: - SettingModel *settingModel; -}; -} - -#endif // SETTING_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingView.h b/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingView.h deleted file mode 100644 index f8936c6db..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/include/SettingView.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingView.h - * Author: - * Create: 2021-11-23 - */ - -#ifndef SETTING_VIEW_H -#define SETTING_VIEW_H - -#include "View.h" -#include "components/root_view.h" -#include "components/ui_view_group.h" -#include "components/ui_scroll_view.h" -#include "components/ui_label.h" -#include "components/ui_list.h" -#include "SettingAdapter.h" -#include "ChangeSliceListener.h" -namespace OHOS { -class SettingPresenter; -class SettingView : public View { -public: - SettingView(); - ~SettingView() override; - - void OnStart() override; - void RefreshSettingsList(const SettingItem* item, uint8_t count); -private: - SettingAdapter *listAdapter{nullptr}; - UIScrollView *scrollView{nullptr}; - UIList *contentList{nullptr}; - UILabel *title{nullptr}; -}; -} -#endif // SETTING_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SetDesktopModel.cpp similarity index 83% rename from code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopModel.cpp rename to code/sdk/application/wearable/nativeapp/nativeui/settings/src/SetDesktopModel.cpp index 25c23a40e..f18610db0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SetDesktopModel.cpp @@ -1,19 +1,16 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingModel.cpp - * Author: - * Create: 2021-11-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SetDesktopModel + * Author: Hisi Graphic Team + * Created: 2025-4 */ -#include "SetDesktopModel.h" +#include "settings/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() { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingAdapter.cpp index 3ffb62c85..535c672ce 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingAdapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingAdapter.cpp @@ -5,7 +5,7 @@ * Create: 2021-11-23 */ -#include "SettingAdapter.h" +#include "settings/SettingAdapter.h" namespace OHOS { SettingAdapter::SettingAdapter() {} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingDesktopPage.cpp similarity index 55% rename from code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopView.cpp rename to code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingDesktopPage.cpp index 2a661577c..0c1c2cd3d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/set_desktop/src/SetDesktopView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingDesktopPage.cpp @@ -1,24 +1,35 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SetDesktopView.cpp - * Author: - * Create: 2021-11-23 + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingDesktopPage + * Author: Hisi Graphic Team + * Created: 2025-4 */ +#include "settings/SettingDesktopPage.h" #include -#include "SetDesktopView.h" -#include "SetDesktopPresenter.h" #include "components/ui_scroll_view_nested.h" +#include "common/screen.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "PageTransitionMgr.h" +#include "SlicePageFactory.h" +#include "settings/SettingView.h" namespace OHOS { -SetDesktopView::SetDesktopView() +static const char *SET_DESKTOP_LIST = "setdesktopList"; +static const char *SET_DESKTOP_HEXAGONS = "setdesktopHexagons"; +static const char *SET_DESKTOP_FOOTBALL = "setdesktopFootball"; +static const char *SET_DESKTOP_WATERFALL = "setdesktopWaterfall"; + +REGIST_SLICE_PAGE(VIEW_SETTING, SETTING_PAGES::SETTING_DESKTOP_PAGE, SettingDesktopPage, false); +SettingDesktopPage::SettingDesktopPage() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::SetDesktopView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingDesktopPage::SettingDesktopPage"); } -SetDesktopView::~SetDesktopView() +SettingDesktopPage::~SettingDesktopPage() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::~SetDesktopView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingDesktopPage::~SettingDesktopPage"); if (scrollview != nullptr) { scrollview->RemoveAll(); delete scrollview; @@ -26,13 +37,11 @@ SetDesktopView::~SetDesktopView() } } -void SetDesktopView::OnStart() +void SettingDesktopPage::OnStart(void *data) { - GetRootContainer()->SetDraggable(true); - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly - GetRootContainer()->SetOnDragListener(presenter_); + if (GetBackDragListener() == nullptr) { // support default slide back firstly + GetSlicePageContainer()->SetOnDragListener(this); } - GetRootContainer()->SetTouchable(true); scrollview = new UIScrollViewNested(UIAbstractScroll::HORIZONTAL); UIScrollViewNested *nested = dynamic_cast(scrollview); @@ -40,14 +49,14 @@ void SetDesktopView::OnStart() nested->SetBoundaryIntercept(DragEvent::DIRECTION_LEFT_TO_RIGHT, false); } scrollview->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - AddViewToRootContainer(scrollview); + AddViewToPageContainer(scrollview); 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); - AddViewToRootContainer(&titleText); + AddViewToPageContainer(&titleText); listImage.SetPosition(0, 135, 190, 190); listImage.SetSrc(PNG_SET_DESKTOP_BG_IMAGE); @@ -83,14 +92,14 @@ void SetDesktopView::OnStart() InitFootballItem(); InitWaterfallItem(); - listBtn.SetOnClickListener(presenter_); - hexagonsBtn.SetOnClickListener(presenter_); - footballBtn_.SetOnClickListener(presenter_); - waterfallBtn_.SetOnClickListener(presenter_); - UpdateSelectedStyle(presenter_->GetCurrentStyle()); + listBtn.SetOnClickListener(this); + hexagonsBtn.SetOnClickListener(this); + footballBtn_.SetOnClickListener(this); + waterfallBtn_.SetOnClickListener(this); + UpdateSelectedStyle(SetDesktopModel::GetInstance().GetDesktopStyle()); } -void SetDesktopView::UpdateSelectedStyle(uint8_t selectedStyle) +void SettingDesktopPage::UpdateSelectedStyle(DesktopStyle selectedStyle) { hexagonsImage.SetVisible(false); hexagonsBtn.SetState(false); @@ -101,13 +110,13 @@ void SetDesktopView::UpdateSelectedStyle(uint8_t selectedStyle) waterfallImage_.SetVisible(false); waterfallBtn_.SetState(false); - if (selectedStyle == 1) { // 1: select hexagons style + if (selectedStyle == HEXAGONS_STYLE) { // 1: select hexagons style hexagonsImage.SetVisible(true); hexagonsBtn.SetState(true); - } else if (selectedStyle == 2) { // 2: select football style + } else if (selectedStyle == FOOTBALL_STYLE) { // 2: select football style footballImage_.SetVisible(true); footballBtn_.SetState(true); - } else if (selectedStyle == 3) { // 3: select waterfall style + } else if (selectedStyle == WATERFALL_STYLE) { // 3: select waterfall style waterfallImage_.SetVisible(true); waterfallBtn_.SetState(true); } else { @@ -116,7 +125,7 @@ void SetDesktopView::UpdateSelectedStyle(uint8_t selectedStyle) } } -void SetDesktopView::InitFootballItem() +void SettingDesktopPage::InitFootballItem() { footballImage_.SetPosition(300, 135, 190, 190); footballImage_.SetSrc(PNG_SET_DESKTOP_BG_IMAGE); @@ -135,7 +144,7 @@ void SetDesktopView::InitFootballItem() scrollview->Add(&footballText_); } -void SetDesktopView::InitWaterfallItem() +void SettingDesktopPage::InitWaterfallItem() { waterfallImage_.SetPosition(450, 135, 190, 190); waterfallImage_.SetSrc(PNG_SET_DESKTOP_BG_IMAGE); @@ -153,8 +162,34 @@ void SetDesktopView::InitWaterfallItem() waterfallText_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); scrollview->Add(&waterfallText_); } -uint8_t SetDesktopView::GetCurrentSelectedStyle() + +bool SettingDesktopPage::OnDrag(UIView& view, const DragEvent& event) { - return presenter_->GetCurrentStyle(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingDesktopPage::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 SettingDesktopPage::OnClick(UIView &view, const ClickEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingDesktopPage::OnClick"); + if (strcmp(view.GetViewId(), SET_DESKTOP_HEXAGONS) == 0) { + SetDesktopModel::GetInstance().SetDesktopStyle(DesktopStyle::HEXAGONS_STYLE); + } else if (strcmp(view.GetViewId(), SET_DESKTOP_LIST) == 0) { + SetDesktopModel::GetInstance().SetDesktopStyle(DesktopStyle::APPLIST_STYLE); + } else if (strcmp(view.GetViewId(), SET_DESKTOP_FOOTBALL) == 0) { + SetDesktopModel::GetInstance().SetDesktopStyle(DesktopStyle::FOOTBALL_STYLE); + } else if (strcmp(view.GetViewId(), SET_DESKTOP_WATERFALL) == 0) { + SetDesktopModel::GetInstance().SetDesktopStyle(DesktopStyle::WATERFALL_STYLE); + } + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + return true; } } 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 19129a3ea..9e88a4e28 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingItemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingItemView.cpp @@ -6,7 +6,7 @@ */ #include "wearable_log.h" -#include "SettingItemView.h" +#include "settings/SettingItemView.h" namespace OHOS { static constexpr int16 SETTING_ICON_X = 20; @@ -43,7 +43,6 @@ namespace OHOS { void SettingItemView::SetItemInfo(const SettingItem itemInfo) { sItemInfo = itemInfo; - WEARABLE_LOGE("SettingItemView::SetItemInfo: %s", sItemInfo.label); sIcon.SetSrc(itemInfo.icon); sLabel.SetText(itemInfo.label); sNextImage.SetVisible(itemInfo.hasSecondMenu); @@ -68,9 +67,9 @@ namespace OHOS { sNextImage.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); } - AppViewId SettingItemView::GetViewId() + uint32_t SettingItemView::GetTargetId() { - return sItemInfo.viewId; + return sItemInfo.targetId; } const char* SettingItemView::GetIconId() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingMainPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingMainPage.cpp new file mode 100644 index 000000000..207eef016 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingMainPage.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingMainPage + * Author: Hisi Graphic Team + * Created: 2025-4 + */ + +#include + +#include "settings/SettingMainPage.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "settings/SettingItem.h" +#include "settings/SettingPresenter.h" +#include "settings/SettingView.h" +#include "PageTransitionMgr.h" +#include "settings/SetDesktopModel.h" +#include "rebootdevice/RebootModel.h" +#include "settings/SettingModel.h" + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_SETTING, SETTING_PAGES::SETTING_MAIN_PAGE, SettingMainPage, true); + +static constexpr uint8_t SETTINGS_ITEM_FONT_SIZE = 40; +static constexpr int16_t SETTINGS_RESIZE_SIZE_WIDTH = 100; +static constexpr int16_t SETTINGS_RESIZE_SIZE_HEIGHT = 60; +static constexpr int16_t SETTING_TITLE_POSITION_X = 187; +static constexpr int16_t SETTING_LIST_POSITION_X = 32; +static constexpr int16_t SETTING_LIST_POSITION_Y = 90; +static constexpr int16_t SETTING_SCROLLBLANKSIZE = 50; +static constexpr int16 MAX_SCR_DIS = 1000; +static constexpr int16 LIST_POS = 20; +static constexpr int16 SNUM_2 = 2; + +SettingMainPage::~SettingMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingMainPage::~SettingMainPage"); + if (scrollView != nullptr) { + scrollView->RemoveAll(); + delete scrollView; + scrollView = nullptr; + } + + if (title != nullptr) { + delete title; + title = nullptr; + } + + if (listAdapter != nullptr) { + delete listAdapter; + listAdapter = nullptr; + } + + if (contentList != nullptr) { + delete contentList; + contentList = nullptr; + } +} + +void SettingMainPage::OnStart(void* data) +{ + title = new UILabel(); + if (title == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingMainPage::OnStart::title is nullptr"); + return; + } + title->SetPosition(SETTING_TITLE_POSITION_X, 0); + title->SetText("设置"); + title->Resize(SETTINGS_RESIZE_SIZE_WIDTH, SETTINGS_RESIZE_SIZE_HEIGHT); + title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTINGS_ITEM_FONT_SIZE); + title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + title->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + contentList = new UIListNested(); + if (contentList == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingMainPage::OnStart::contentList is nullptr"); + return; + } + contentList->SetPosition(SETTING_LIST_POSITION_X, SETTING_LIST_POSITION_Y); + contentList->Resize(HORIZONTAL_RESOLUTION, 364); // 364: height + contentList->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE); + contentList->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); // middle position + contentList->SetDraggable(true); + contentList->SetThrowDrag(true); + contentList->EnableAutoAlign(true); + contentList->SetMaxScrollDistance(MAX_SCR_DIS); + + scrollView = new UIScrollViewNested(); + if (scrollView == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingMainPage::OnStart::scrollView is nullptr"); + return; + } + scrollView->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + scrollView->SetThrowDrag(true); + + if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly + scrollView->SetOnDragListener(this); + } + scrollView->Add(title); + scrollView->Add(contentList); + SettingModel::GetInstance().InitSettingItem(); + AddViewToPageContainer(scrollView); + RefreshSettingsList(SettingModel::GetInstance().GetSettinglistItems(), + SettingModel::GetInstance().GetSettingListNum()); +} + +void SettingMainPage::RefreshSettingsList(const SettingItem* item, uint8_t count) +{ + listAdapter = new SettingAdapter(); + if (listAdapter == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingMainPage::OnStart::listAdapter is nullptr"); + return; + } + listAdapter->SetItemClickListener(this); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingMainPage::RefreshSettingsList"); + for (int i = 0; i < count; i++) { + listAdapter->AddListItem(item[i]); + } + contentList->SetAdapter(listAdapter); +} + +bool SettingMainPage::OnDrag(UIView& view, const DragEvent& event) +{ + 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(VIEW_APPLIST)"); + if (SetDesktopModel::GetInstance().GetDesktopStyle() == HEXAGONS_STYLE) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } else if (SetDesktopModel::GetInstance().GetDesktopStyle() == WATERFALL_STYLE) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_WATERFALL); + } else { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + } + return false; +} + +bool SettingMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + SettingItemView *settingItemView = static_cast(&view); + uint32_t targetId = settingItemView->GetTargetId(); + uint16_t sliceId = static_cast(targetId & SLICE_MASK); + uint16_t pageId = static_cast(targetId >> PAGE_OFFSET); + if (sliceId == VIEW_REBOOT) { + if (strstr(settingItemView->GetIconId(), "REBOOT") != nullptr) { + RebootModel::GetInstance()->SetSelectViewId(REBOOTDEVICE); + RebootModel::GetInstance()->SetExitsView(true); + } else { + RebootModel::GetInstance()->SetSelectViewId(SHUTDOWNDEVICE); + RebootModel::GetInstance()->SetExitsView(true); + } + } + if (sliceId != VIEW_SETTING) { + if (settingItemView->SlideBackEnabled()) { + NativeAbility::GetInstance().ChangeSlice(sliceId, TransitionType::TRANSITION_INVALID, + gSliceDefaultPriority, true); + } else { + NativeAbility::GetInstance().ChangeSlice(sliceId); + } + } else { + NativeAbility::GetInstance().SwitchPageInSlice(pageId, nullptr, TransitionType::TRANSITION_INVALID, true); + } + return true; +} +} 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 3345274df..d732125d7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp @@ -5,8 +5,10 @@ * Create: 2021-11-23 */ -#include "SettingModel.h" -#include "PullUpDownView.h" +#include "settings/SettingModel.h" +#include "Slice.h" +#include "main/PullUpDownView.h" +#include "settings/SettingView.h" namespace OHOS { SettingModel::SettingModel() {} @@ -22,15 +24,20 @@ namespace OHOS { void SettingModel::InitSettingItem() { int index = 0; - settings[index++] = {VIEW_BLUETOOTH_EARPHONE, PNG_BLUETOOTH_STITLE, "蓝牙耳机", true, false}; - settings[index++] = {VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, "连接手机", true, true}; - settings[index++] = {VIEW_REBOOT, PNG_SETTTING_REBOOT_IMAGE, "重启", true, true}; - settings[index++] = {VIEW_REBOOT, PNG_SETTTING_SHUTDOWN_IMAGE, "关机", true, true}; - settings[index++] = {VIEW_SET_DESKTOP, PNG_SETTTING_DESKTOP_IMAGE, "桌面", true, true}; - settings[index++] = {VIEW_SET_DIAL, PNG_SETTTING_DESKTOP_IMAGE, "表盘", true, false}; - settings[index++] = {VIEW_SET_CARD, PNG_SETTTING_DESKTOP_IMAGE, "卡片", true, false}; - settings[index++] = {VIEW_SET_DIAL_STYLE, PNG_SETTTING_DESKTOP_IMAGE, "表盘风格", true, true}; - settings[index++] = {VIEW_RESTORE_DEFAULTS, PNG_SETTTING_DESKTOP_IMAGE, "恢复出厂", true, true}; + settings[index++] = {static_cast(VIEW_BLUETOOTH_EARPHONE), PNG_BLUETOOTH_STITLE, + "蓝牙耳机", true, false}; + settings[index++] = {static_cast(VIEW_CONNECT_PHONE), PNG_CONNECT_PHONE_IMAGE, "连接手机", true, true}; + settings[index++] = {static_cast(VIEW_REBOOT), PNG_SETTTING_REBOOT_IMAGE, "重启", true, true}; + settings[index++] = {static_cast(VIEW_REBOOT), PNG_SETTTING_SHUTDOWN_IMAGE, "关机", true, true}; + settings[index++] = {static_cast(VIEW_SET_DIAL), PNG_SETTTING_DESKTOP_IMAGE, "表盘", true, false}; + settings[index++] = {static_cast(VIEW_SETTING) | (SETTING_DESKTOP_PAGE << PAGE_OFFSET), + PNG_SETTTING_DESKTOP_IMAGE, "桌面", true, true}; + settings[index++] = {static_cast(VIEW_SET_CARD), PNG_SETTTING_DESKTOP_IMAGE, "卡片", true, false}; + settings[index++] = {static_cast(VIEW_SET_DIAL_STYLE), PNG_SETTTING_DESKTOP_IMAGE, + "表盘风格", true, true}; + settings[index++] = {static_cast(VIEW_RESTORE_DEFAULTS), PNG_SETTTING_DESKTOP_IMAGE, + "恢复出厂", true, true}; + settings[index++] = {static_cast(VIEW_SET_OTA), PNG_SETTTING_DESKTOP_IMAGE, "OTA升级", true, true}; usedLen = index; } 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 16499b9f7..fbf508ee9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingPresenter.cpp @@ -5,74 +5,10 @@ * Create: 2021-11-23 */ -#include "SettingView.h" -#include "SettingModel.h" -#include "SettingPresenter.h" -#include "RebootModel.h" -#include "SetDesktopModel.h" +#include "settings/SettingView.h" +#include "settings/SettingPresenter.h" #include "NativeRegisterManager.h" namespace OHOS { - REGIST_MENU(VIEW_SETTING, SettingView, SettingPresenter, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_DEFAULT_IMG, "设置"); - - SettingPresenter::SettingPresenter() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::SettingPresenter()"); - settingModel = &SettingModel::GetInstance(); - } - - SettingPresenter::~SettingPresenter() {} - - void SettingPresenter::OnStart() - { - settingModel->InitSettingItem(); - if (view_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view_ is nullptr!!"); - return; - } - const SettingItem *itemInfo = settingModel->GetSettinglistItems(); - view_->RefreshSettingsList(itemInfo, settingModel->GetSettingListNum()); - } - - bool SettingPresenter::OnDrag(UIView& view, const DragEvent& event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::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(VIEW_APPLIST)"); - if (SetDesktopModel::GetInstance().GetDesktopStyle() == HEXAGONS_STYLE) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_HEXAGONS); - } else if (SetDesktopModel::GetInstance().GetDesktopStyle() == WATERFALL_STYLE) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_WATERFALL); - } else { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - } - } - return false; - } - - bool SettingPresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - SettingItemView *settingItemView = static_cast(&view); - AppViewId viewId = settingItemView->GetViewId(); - if (viewId == VIEW_REBOOT) { - if (strstr(settingItemView->GetIconId(), "REBOOT") != nullptr) { - RebootModel::GetInstance()->SetSelectViewId(REBOOTDEVICE); - RebootModel::GetInstance()->SetExitsView(true); - } else { - RebootModel::GetInstance()->SetSelectViewId(SHUTDOWNDEVICE); - RebootModel::GetInstance()->SetExitsView(true); - } - } - if (settingItemView->SlideBackEnabled()) { - NativeAbility::GetInstance().ChangeSlice(viewId, TransitionType::TRANSITION_INVALID, - gSliceDefaultPriority, true); - } else { - 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 deleted file mode 100644 index 2b03b50ce..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingView.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingView.cpp - * Author: - * Create: 2021-11-23 - */ - -#include - -#include "SettingView.h" -#include "SettingItem.h" -#include "SettingPresenter.h" -#include "components/ui_list_nested.h" -#include "components/ui_scroll_view_nested.h" - -namespace OHOS { -static constexpr uint8_t SETTINGS_ITEM_FONT_SIZE = 40; -static constexpr int16_t SETTINGS_RESIZE_SIZE_WIDTH = 100; -static constexpr int16_t SETTINGS_RESIZE_SIZE_HEIGHT = 60; -static constexpr int16_t SETTING_TITLE_POSITION_X = 187; -static constexpr int16_t SETTING_LIST_POSITION_X = 32; -static constexpr int16_t SETTING_LIST_POSITION_Y = 90; -static constexpr int16_t SETTING_SCROLLBLANKSIZE = 50; -static constexpr int16 MAX_SCR_DIS = 1000; -static constexpr int16 LIST_POS = 20; -static constexpr int16 SNUM_2 = 2; - -SettingView::SettingView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::SettingView"); -} - -SettingView::~SettingView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::~SettingView"); - if (scrollView != nullptr) { - scrollView->RemoveAll(); - delete scrollView; - scrollView = nullptr; - } - - if (title != nullptr) { - delete title; - title = nullptr; - } - - if (listAdapter != nullptr) { - delete listAdapter; - listAdapter = nullptr; - } - - if (contentList != nullptr) { - delete contentList; - contentList = nullptr; - } -} - -void SettingView::OnStart() -{ - title = new UILabel(); - if (title == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::title is nullptr"); - return; - } - title->SetPosition(SETTING_TITLE_POSITION_X, 0); - title->SetText("设置"); - title->Resize(SETTINGS_RESIZE_SIZE_WIDTH, SETTINGS_RESIZE_SIZE_HEIGHT); - title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTINGS_ITEM_FONT_SIZE); - title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - title->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - title->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - title->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - title->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - - contentList = new UIListNested(); - if (contentList == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::contentList is nullptr"); - return; - } - contentList->SetPosition(SETTING_LIST_POSITION_X, SETTING_LIST_POSITION_Y); - contentList->Resize(HORIZONTAL_RESOLUTION, 364); // 364: height - contentList->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE); - contentList->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); // middle position - contentList->SetDraggable(true); - contentList->SetThrowDrag(true); - contentList->EnableAutoAlign(true); - contentList->SetMaxScrollDistance(MAX_SCR_DIS); - - scrollView = new UIScrollViewNested(); - if (scrollView == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::scrollView is nullptr"); - return; - } - scrollView->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - scrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - scrollView->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); - scrollView->SetThrowDrag(true); - - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly - scrollView->SetOnDragListener(presenter_); - } - scrollView->Add(title); - scrollView->Add(contentList); - AddViewToRootContainer(scrollView); -} - -void SettingView::RefreshSettingsList(const SettingItem* item, uint8_t count) -{ - listAdapter = new SettingAdapter(); - if (listAdapter == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::listAdapter is nullptr"); - return; - } - listAdapter->SetItemClickListener(presenter_); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::RefreshSettingsList"); - for (int i = 0; i < count; i++) { - listAdapter->AddListItem(item[i]); - } - contentList->SetAdapter(listAdapter); -} -} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingDetailsPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingDetailsPage.cpp new file mode 100644 index 000000000..1341d7b1b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingDetailsPage.cpp @@ -0,0 +1,635 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepingDetailsPage + * Created: 2025-06-05 + */ +#include +#include +#include "ohos_timer.h" +#include "wearable_log.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "sleep/SleepingView.h" +#include "sleep/SleepingModel.h" +#include "sleep/SleepingDetailsPage.h" + +namespace OHOS { + +static constexpr int16_t SLEEPDETAIL_SLEEP_X = 97; +static constexpr int16_t SLEEPDETAIL_SLEEP_Y = 31; +static constexpr int16_t SLEEPDETAIL_SLEEP_WIDTH = 260; +static constexpr int16_t SLEEPDETAIL_SLEEP_HEIGHT = 53; +static constexpr int16_t SLEEPDETAIL_SLEEP_FONT_SIZE = 38; +static constexpr int16_t SLEEPDETAIL_IMAGE1_X = 77; +static constexpr int16_t SLEEPDETAIL_IMAGE1_Y = 215; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_X = 103; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_Y = 205; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_WIDTH = 48; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_HEIGHT = 29; +static constexpr int16_t SLEEPDETAIL_SOBERINGTIME_FONT_SIZE = 24; +static constexpr int16_t SLEEPDETAIL_IMAGE2_Y = 254; +static constexpr int16_t SLEEPDETAIL_IMAGE3_Y = 291; +static constexpr int16_t SLEEPDETAIL_IMAGE4_Y = 330; +static constexpr int16_t SLEEPDETAIL_RAPID_Y = 244; +static constexpr int16_t SLEEPDETAIL_RAPID_WIDTH = 100; +static constexpr int16_t SLEEPDETAIL_RAPID_HEIGHT = 38; +static constexpr int16_t SLEEPDETAIL_LIGHT_Y = 283; +static constexpr int16_t SLEEPDETAIL_DEEP_Y = 322; +static constexpr int16_t SLEEPDETAIL_GRAYBG_X = 62; +static constexpr int16_t SLEEPDETAIL_GRAYBG_Y = 185; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_X = 180; +static constexpr int16_t SLEEPDETAIL_ACTUAL_NORECODE_X = 96; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_Y = 100; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_WIDTH = 200; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_HEIGHT = 35; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_FONT_SIZE = 32; +static constexpr int16_t SLEEPDETAIL_LABEL_WIDTH = 160; +static constexpr int16_t SLEEPDETAIL_PADDING_RIGHT = 30; +static constexpr int16_t SLEEPDETAIL_SOBERINGTEXT_X = 220; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_NORECORD_X = 179; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEP_NORECORD_Y = 110; +static constexpr int16_t SLEEPDETAIL_SOBERTIMETEXT_X = 300; +static constexpr int16_t SLEEPDETAIL_SOBERTIMETEXT_Y = 190; +static constexpr int16_t SLEEPDETAIL_RAPIDTIMETEXT_Y = 230; +static constexpr int16_t SLEEPDETAIL_LIGHTIMETEXT_Y = 270; +static constexpr int16_t SLEEPDETAIL_DEEPIMETEXT_Y = 310; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEPTIMEHOURS_FONT_SIZE = 40; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT = 50; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEPTIMINUTES_FONT_SIZE = 40; +static constexpr int16_t SLEEPDETAIL_ACTUALMINUTE_X = 230; +static constexpr int16_t SLEEPDETAIL_ACTUALMINUTE_Y = 116; +static constexpr int16_t SLEEPDETAIL_ACTUALHOUR_X = 135; +static constexpr int16_t SLEEPDETAIL_ACTUALHOUR_Y = 100; +static constexpr int16_t SLEEPDETAIL_ACTUALHOURTEXT_X = 170; +static constexpr int16_t SLEEPDETAIL_ACTUALMINUTETEXT_X = 280; +static constexpr int16_t ACTUALHOURS_X = 140; +static constexpr int16_t ACTUALHOURSTEXT_X = 180; +static constexpr int16_t ACTUALMINUTESTEXT_X = 270; + +REGIST_SLICE_PAGE(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_DEATIL_PAGE, SleepingDetailsPage, false); + +SleepingDetailsPage::SleepingDetailsPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepingDetailsPage::SleepingDetailsPage"); +} + +SleepingDetailsPage::~SleepingDetailsPage() +{ + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (detailsSleepView != nullptr) { + delete detailsSleepView; + detailsSleepView = nullptr; + } + + if (sleep != nullptr) { + delete sleep; + sleep = nullptr; + } + + if (actualSleepTime != nullptr) { + delete actualSleepTime; + actualSleepTime = nullptr; + } + + if (actualSleepTimeHours != nullptr) { + delete actualSleepTimeHours; + actualSleepTimeHours = nullptr; + } + + if (actualSleepTimeHoursText != nullptr) { + delete actualSleepTimeHoursText; + actualSleepTimeHoursText = nullptr; + } + + if (actualSleepTimeMinutes != nullptr) { + delete actualSleepTimeMinutes; + actualSleepTimeMinutes = nullptr; + } + + if (actualSleepTimeMinutesText != nullptr) { + delete actualSleepTimeMinutesText; + actualSleepTimeMinutesText = nullptr; + } + + if (grayBg != nullptr) { + delete grayBg; + grayBg = nullptr; + } + + if (image1 != nullptr) { + delete image1; + image1 = nullptr; + } + + if (soberingTime_ != nullptr) { + delete soberingTime_; + soberingTime_ = nullptr; + } + + if (soberingTimeText != nullptr) { + delete soberingTimeText; + soberingTimeText = nullptr; + } + + if (image2 != nullptr) { + delete image2; + image2 = nullptr; + } + + if (rapidEyeMovement_ != nullptr) { + delete rapidEyeMovement_; + rapidEyeMovement_ = nullptr; + } + + if (rapidEyeMovementText != nullptr) { + delete rapidEyeMovementText; + rapidEyeMovementText = nullptr; + } + + if (image3 != nullptr) { + delete image3; + image3 = nullptr; + } + + if (lightSleepTime_ != nullptr) { + delete lightSleepTime_; + lightSleepTime_ = nullptr; + } + + if (lightSleepTimeText != nullptr) { + delete lightSleepTimeText; + lightSleepTimeText = nullptr; + } + + if (image4 != nullptr) { + delete image4; + image4 = nullptr; + } + + if (deepSleepTime_ != nullptr) { + delete deepSleepTime_; + deepSleepTime_ = nullptr; + } + + if (deepSleepTimeText != nullptr) { + delete deepSleepTimeText; + deepSleepTimeText = nullptr; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepingDetailsPage::~SleepingDetailsPage"); +} + +void SleepingDetailsPage::OnStart(void* data) +{ + group = new UIScrollView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group is nullptr"); + return; + } + group->SetPosition(0, 0); + group->Resize(RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + group->SetViewId("sleepDetails"); + + detailsSleepView = new UIImageView(); + if (detailsSleepView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "detailsSleepView is nullptr"); + return; + } + LOADIMG::LoadImageViewImg(detailsSleepView, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_BACKGROUND); + detailsSleepView->SetPosition(0, 0, RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + group->Add(detailsSleepView); + + sleep = new UILabel(); + if (sleep == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep is nullptr"); + return; + } + sleep->SetPosition(SLEEPDETAIL_SLEEP_X, SLEEPDETAIL_SLEEP_Y); + sleep->Resize(SLEEPDETAIL_SLEEP_WIDTH, SLEEPDETAIL_SLEEP_HEIGHT); + sleep->SetText("睡眠"); + sleep->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sleep->SetTextColor(Color::White()); + sleep->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SLEEP_FONT_SIZE); + sleep->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(sleep); + + InitPage(); + + if (GetRecord() == true) { + InitDetailPage(); + } else { + InitNoDeatilPage(); + }; + group->SetOnDragListener(this); + group->SetDraggable(true); + group->SetTouchable(true); + AddViewToPageContainer(group); +} + +void SleepingDetailsPage::InitSoberingTime() +{ + image1 = new UIImageView(); + if (image1 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "image1 is nullptr"); + return; + } + image1->SetPosition(SLEEPDETAIL_IMAGE1_X, SLEEPDETAIL_IMAGE1_Y); + LOADIMG::LoadImageViewImg(image1, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_RED_CIR); + group->Add(image1); + soberingTime_ = new UILabel(); + if (soberingTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "soberingTime_ is nullptr"); + return; + } + soberingTime_->SetPosition(SLEEPDETAIL_SOBERINGTIME_X, SLEEPDETAIL_SOBERINGTIME_Y); + soberingTime_->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + soberingTime_->SetText("清醒"); + soberingTime_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + soberingTime_->SetTextColor(Color::White()); + soberingTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + soberingTime_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group->Add(soberingTime_); +} + +void SleepingDetailsPage::InitRapidEyeMovement() +{ + image2 = new UIImageView(); + if (image2 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "image2 is nullptr"); + return; + } + image2->SetPosition(SLEEPDETAIL_IMAGE1_X, SLEEPDETAIL_IMAGE2_Y); + LOADIMG::LoadImageViewImg(image2, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_ORANGE_CIR); + group->Add(image2); + + rapidEyeMovement_ = new UILabel(); + if (rapidEyeMovement_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rapidEyeMovement_ is nullptr"); + return; + } + rapidEyeMovement_->SetPosition(SLEEPDETAIL_SOBERINGTIME_X, SLEEPDETAIL_RAPID_Y); + rapidEyeMovement_->Resize(SLEEPDETAIL_RAPID_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + rapidEyeMovement_->SetText("快速动眼"); + rapidEyeMovement_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + rapidEyeMovement_->SetTextColor(Color::White()); + rapidEyeMovement_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + rapidEyeMovement_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group->Add(rapidEyeMovement_); +} + +void SleepingDetailsPage::InitLightSleepTime() +{ + image3 = new UIImageView(); + if (image3 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "image3 is nullptr"); + return; + } + image3->SetPosition(SLEEPDETAIL_IMAGE1_X, SLEEPDETAIL_IMAGE3_Y); + LOADIMG::LoadImageViewImg(image3, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_GREEN_CIR); + group->Add(image3); + + lightSleepTime_ = new UILabel(); + if (lightSleepTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lightSleepTime_ is nullptr"); + return; + } + lightSleepTime_->SetPosition(SLEEPDETAIL_SOBERINGTIME_X, SLEEPDETAIL_LIGHT_Y); + lightSleepTime_->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + lightSleepTime_->SetText("浅睡"); + lightSleepTime_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + lightSleepTime_->SetTextColor(Color::White()); + lightSleepTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + lightSleepTime_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group->Add(lightSleepTime_); +} + +void SleepingDetailsPage::InitDeepSleepTime() +{ + image4 = new UIImageView(); + if (image4 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "image4 is nullptr"); + return; + } + image4->SetPosition(SLEEPDETAIL_IMAGE1_X, SLEEPDETAIL_IMAGE4_Y); + LOADIMG::LoadImageViewImg(image4, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_BLUE_CIR); + group->Add(image4); + + deepSleepTime_ = new UILabel(); + if (deepSleepTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deepSleepTime_ is nullptr"); + return; + } + deepSleepTime_->SetPosition(SLEEPDETAIL_SOBERINGTIME_X, SLEEPDETAIL_DEEP_Y); + deepSleepTime_->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + deepSleepTime_->SetText("深睡"); + deepSleepTime_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + deepSleepTime_->SetTextColor(Color::White()); + deepSleepTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + deepSleepTime_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group->Add(deepSleepTime_); +} + +void SleepingDetailsPage::InitPage() +{ + grayBg = new UIImageView(); + if (grayBg == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "grayBg is nullptr"); + return; + } + grayBg->SetPosition(SLEEPDETAIL_GRAYBG_X, SLEEPDETAIL_GRAYBG_Y); + LOADIMG::LoadImageViewImg(grayBg, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_RECORD_BG); + group->Add(grayBg); + + // 加载详情四项 + InitSoberingTime(); + InitRapidEyeMovement(); + InitLightSleepTime(); + InitDeepSleepTime(); +} + +void SleepingDetailsPage::IoadDeatilActualSleepTime() +{ + actualSleepTimeHours = new UILabel(); + if (actualSleepTimeHours == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeHours is nullptr"); + return; + } + + actualSleepTimeHours->SetTextColor(Color::White()); + actualSleepTimeHours->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_ACTUALSLEEPTIMEHOURS_FONT_SIZE); + actualSleepTimeHours->SetVisible(false); + + actualSleepTimeHoursText = new UILabel(); + if (actualSleepTimeHoursText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeHoursText is nullptr"); + return; + } + actualSleepTimeHoursText->SetText("小时"); + actualSleepTimeHoursText->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + actualSleepTimeHoursText->SetTextColor(Color::White()); + actualSleepTimeHoursText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + actualSleepTimeHoursText->SetVisible(false); + + actualSleepTimeMinutes = new UILabel(); + if (actualSleepTimeMinutes == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeMinutes is nullptr"); + return; + } + + actualSleepTimeMinutes->Resize(SLEEPDETAIL_RAPID_WIDTH, SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT); + actualSleepTimeMinutes->SetTextColor(Color::White()); + actualSleepTimeMinutes->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_ACTUALSLEEPTIMINUTES_FONT_SIZE); + actualSleepTimeMinutes->SetVisible(false); + + actualSleepTimeMinutesText = new UILabel(); + if (actualSleepTimeMinutesText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeHours is nullptr"); + return; + } + + actualSleepTimeMinutesText->SetText("分钟"); + actualSleepTimeMinutesText->Resize(SLEEPDETAIL_SOBERINGTIME_WIDTH, SLEEPDETAIL_SOBERINGTIME_HEIGHT); + actualSleepTimeMinutesText->SetTextColor(Color::White()); + actualSleepTimeMinutesText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + actualSleepTimeMinutesText->SetVisible(false); +} + +void SleepingDetailsPage::InitActualSleepTime(std::tuple timeTuple) +{ + IoadDeatilActualSleepTime(); + uint32_t hours = std::get<0>(timeTuple); + uint32_t minutes = std::get<1>(timeTuple); + + if ((hours == 0) && (minutes != 0)) { + actualSleepTimeMinutes->SetPosition(SLEEPDETAIL_ACTUALSLEEP_X, SLEEPDETAIL_ACTUALSLEEP_Y); + actualSleepTimeMinutes->SetVisible(true); + actualSleepTimeMinutes->SetText(std::to_string(minutes).c_str()); + group->Add(actualSleepTimeMinutes); + + actualSleepTimeMinutesText->SetPosition(SLEEPDETAIL_ACTUALMINUTE_X, SLEEPDETAIL_ACTUALMINUTE_Y); + actualSleepTimeMinutesText->SetVisible(true); + group->Add(actualSleepTimeMinutesText); + } else if ((hours != 0) && (minutes == 0)) { + actualSleepTimeHours->SetPosition(SLEEPDETAIL_ACTUALSLEEP_X, SLEEPDETAIL_ACTUALSLEEP_Y); + actualSleepTimeHours->Resize(SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT, SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT); + actualSleepTimeHours->SetVisible(true); + actualSleepTimeHours->SetText(std::to_string(hours).c_str()); + group->Add(actualSleepTimeHours); + + actualSleepTimeHoursText->SetPosition(SLEEPDETAIL_ACTUALMINUTE_X, SLEEPDETAIL_ACTUALMINUTE_Y); + actualSleepTimeHoursText->SetVisible(true); + group->Add(actualSleepTimeHoursText); + } else if ((hours != 0) && (minutes != 0)) { + actualSleepTimeHours->SetPosition(SLEEPDETAIL_ACTUALHOUR_X, SLEEPDETAIL_ACTUALHOUR_Y); + actualSleepTimeHours->Resize(SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT, SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT); + + actualSleepTimeHours->SetVisible(true); + actualSleepTimeHours->SetText(std::to_string(hours).c_str()); + group->Add(actualSleepTimeHours); + + actualSleepTimeHoursText->SetPosition(SLEEPDETAIL_ACTUALHOURTEXT_X, SLEEPDETAIL_ACTUALMINUTE_Y); + actualSleepTimeHoursText->SetVisible(true); + group->Add(actualSleepTimeHoursText); + + actualSleepTimeMinutes->SetPosition(SLEEPDETAIL_ACTUALMINUTE_X, SLEEPDETAIL_ACTUALHOUR_Y); + actualSleepTimeMinutes->SetVisible(true); + actualSleepTimeMinutes->SetText(std::to_string(minutes).c_str()); + group->Add(actualSleepTimeMinutes); + + actualSleepTimeMinutesText->SetPosition(SLEEPDETAIL_ACTUALMINUTETEXT_X, SLEEPDETAIL_ACTUALMINUTE_Y); + actualSleepTimeMinutesText->SetVisible(true); + group->Add(actualSleepTimeMinutesText); + } else if ((hours == 0) && (minutes == 0)) { + actualSleepTimeHours->SetPosition(ACTUALHOURS_X, SLEEPDETAIL_ACTUALHOUR_Y); + actualSleepTimeHours->Resize(SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT, SLEEPDETAIL_ACTUALSLEEPTIMINUTES_HEIGHT); + actualSleepTimeHours->SetVisible(true); + actualSleepTimeHours->SetText("--"); + group->Add(actualSleepTimeHours); + + actualSleepTimeHoursText->SetPosition(ACTUALHOURSTEXT_X, SLEEPDETAIL_ACTUALMINUTE_Y); + actualSleepTimeHoursText->SetVisible(true); + group->Add(actualSleepTimeHoursText); + + actualSleepTimeMinutes->SetPosition(SLEEPDETAIL_ACTUALMINUTE_X, SLEEPDETAIL_ACTUALHOUR_Y); + actualSleepTimeMinutes->SetVisible(true); + actualSleepTimeMinutes->SetText("--"); + group->Add(actualSleepTimeMinutes); + + actualSleepTimeMinutesText->SetPosition(ACTUALMINUTESTEXT_X, SLEEPDETAIL_ACTUALMINUTE_Y); + actualSleepTimeMinutesText->SetVisible(true); + group->Add(actualSleepTimeMinutesText); + } +} + +void SleepingDetailsPage::InitDetailPage() +{ + InitActualSleepTime(SleepingModel::GetInstance().GetSleepTime()); + + soberingTimeText = new UILabel(); + if (soberingTimeText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "soberingTimeText is nullptr"); + return; + } + soberingTimeText->SetText((SetTimeText(SleepingModel::GetInstance().GetSoberingTime())).c_str()); + soberingTimeText->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_SOBERINGTIME_Y); + + soberingTimeText->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + soberingTimeText->SetTextColor(Color::White()); + soberingTimeText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + soberingTimeText->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + soberingTimeText->SetStyle(STYLE_PADDING_RIGHT, SLEEPDETAIL_PADDING_RIGHT); + group->Add(soberingTimeText); + + rapidEyeMovementText = new UILabel(); + if (rapidEyeMovementText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rapidEyeMovementText is nullptr"); + return; + } + rapidEyeMovementText->SetText((SetTimeText(SleepingModel::GetInstance().GetRapidEyeMovementTime())).c_str()); + rapidEyeMovementText->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_RAPID_Y); + + rapidEyeMovementText->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + rapidEyeMovementText->SetTextColor(Color::White()); + rapidEyeMovementText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + rapidEyeMovementText->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + rapidEyeMovementText->SetStyle(STYLE_PADDING_RIGHT, SLEEPDETAIL_PADDING_RIGHT); + group->Add(rapidEyeMovementText); + + lightSleepTimeText = new UILabel(); + if (lightSleepTimeText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lightSleepTimeText is nullptr"); + return; + } + lightSleepTimeText->SetText((SetTimeText(SleepingModel::GetInstance().GetLightSleepTime())).c_str()); + lightSleepTimeText->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_LIGHT_Y); + lightSleepTimeText->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + lightSleepTimeText->SetTextColor(Color::White()); + lightSleepTimeText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + lightSleepTimeText->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + lightSleepTimeText->SetStyle(STYLE_PADDING_RIGHT, SLEEPDETAIL_PADDING_RIGHT); + group->Add(lightSleepTimeText); + + deepSleepTimeText = new UILabel(); + if (deepSleepTimeText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deepSleepTimeText is nullptr"); + return; + } + deepSleepTimeText->SetText((SetTimeText(SleepingModel::GetInstance().GetDeepSleepTime())).c_str()); + deepSleepTimeText->SetPosition(SLEEPDETAIL_SOBERINGTEXT_X, SLEEPDETAIL_DEEP_Y); + deepSleepTimeText->Resize(SLEEPDETAIL_LABEL_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + deepSleepTimeText->SetTextColor(Color::White()); + deepSleepTimeText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + deepSleepTimeText->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + deepSleepTimeText->SetStyle(STYLE_PADDING_RIGHT, SLEEPDETAIL_PADDING_RIGHT); + group->Add(deepSleepTimeText); +} + +void SleepingDetailsPage::InitNoDeatilPage() +{ + actualSleepTime = new UILabel(); + if (actualSleepTime == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTime is nullptr"); + return; + } + actualSleepTime->SetText("无记录"); + actualSleepTime->SetPosition(SLEEPDETAIL_ACTUALSLEEP_NORECORD_X, SLEEPDETAIL_ACTUALSLEEP_NORECORD_Y); + actualSleepTime->Resize(SLEEPDETAIL_ACTUAL_NORECODE_X, SLEEPDETAIL_SOBERINGTIME_WIDTH); + actualSleepTime->SetTextColor(Color::White()); + actualSleepTime->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_ACTUALSLEEP_FONT_SIZE); + group->Add(actualSleepTime); + + soberingTimeText = new UILabel(); + if (soberingTimeText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "soberingTimeText is nullptr"); + return; + } + soberingTimeText->SetText("--"); + soberingTimeText->SetPosition(SLEEPDETAIL_SOBERTIMETEXT_X, SLEEPDETAIL_SOBERTIMETEXT_Y); + soberingTimeText->Resize(SLEEPDETAIL_RAPID_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + soberingTimeText->SetTextColor(Color::White()); + soberingTimeText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + soberingTimeText->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group->Add(soberingTimeText); + + rapidEyeMovementText = new UILabel(); + if (rapidEyeMovementText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rapidEyeMovementText is nullptr"); + return; + } + rapidEyeMovementText->SetText("--"); + rapidEyeMovementText->SetPosition(SLEEPDETAIL_SOBERTIMETEXT_X, SLEEPDETAIL_RAPIDTIMETEXT_Y); + rapidEyeMovementText->Resize(SLEEPDETAIL_RAPID_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + rapidEyeMovementText->SetTextColor(Color::White()); + rapidEyeMovementText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + rapidEyeMovementText->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group->Add(rapidEyeMovementText); + + lightSleepTimeText = new UILabel(); + if (lightSleepTimeText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lightSleepTimeText is nullptr"); + return; + } + lightSleepTimeText->SetText("--"); + lightSleepTimeText->SetPosition(SLEEPDETAIL_SOBERTIMETEXT_X, SLEEPDETAIL_LIGHTIMETEXT_Y); + lightSleepTimeText->Resize(SLEEPDETAIL_RAPID_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + lightSleepTimeText->SetTextColor(Color::White()); + lightSleepTimeText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + lightSleepTimeText->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group->Add(lightSleepTimeText); + + deepSleepTimeText = new UILabel(); + if (deepSleepTimeText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deepSleepTimeText is nullptr"); + return; + } + deepSleepTimeText->SetText("--"); + deepSleepTimeText->SetPosition(SLEEPDETAIL_SOBERTIMETEXT_X, SLEEPDETAIL_DEEPIMETEXT_Y); + deepSleepTimeText->Resize(SLEEPDETAIL_RAPID_WIDTH, SLEEPDETAIL_RAPID_HEIGHT); + deepSleepTimeText->SetTextColor(Color::White()); + deepSleepTimeText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_SOBERINGTIME_FONT_SIZE); + deepSleepTimeText->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group->Add(deepSleepTimeText); +} + +std::string SleepingDetailsPage::SetTimeText(std::tuple timeTuple) +{ + uint32_t hours = std::get<0>(timeTuple); + uint32_t minutes = std::get<1>(timeTuple); + + std::string str = ""; + if ((hours == 0) && (minutes != 0)) { + str = std::to_string(minutes) + "分钟"; + } else if ((hours != 0) && (minutes == 0)) { + str = std::to_string(hours) + "小时"; + } else if ((hours != 0) && (minutes != 0)) { + str = std::to_string(hours) + "小时" + std::to_string(minutes) + "分钟"; + } else if ((hours == 0) && (minutes == 0)) { + str = "---"; + } + return str; +} + +bool SleepingDetailsPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) { + NativeAbility::GetInstance().SwitchSlice(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_MAIN_PAGE); + } + return true; +} + +bool SleepingDetailsPage::GetRecord() +{ + if (SleepingModel::GetInstance().GetRecord()) { + return true; + } + return false; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingMainPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingMainPage.cpp new file mode 100644 index 000000000..d88a582cc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingMainPage.cpp @@ -0,0 +1,705 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepingMainPage + * Created: 2025-06-05 + */ + +#include +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "settings/SetDesktopModel.h" +#include "rebootdevice/RebootModel.h" +#include "common/image_cache_manager.h" +#include "diag_service.h" +#include "msg_center_device.h" +#include "diag_common.h" +#include "sleep/TargetSleepTime.h" +#include "sleep/SleepingMainPage.h" +#include "sleep/SleepingPresenter.h" +#include "sleep/SleepingView.h" + +namespace OHOS { + +REGIST_SLICE_PAGE(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_MAIN_PAGE, SleepingMainPage, true); + +static constexpr int16_t SLEEPMAIN_SLEEP_X = 190; +static constexpr int16_t SLEEPMAIN_SLEEP_Y = 50; +static constexpr int16_t SLEEPMAIN_SLEEP_WIDTH = 64; +static constexpr int16_t SLEEPMAIN_SLEEP_HEIGHT = 38; +static constexpr int16_t SLEEPMAIN_SLEEP_FONT_SIZE = 38; +static constexpr int16_t SLEEPMAIN_NORECORD_X = 179; +static constexpr int16_t SLEEPMAIN_NORECORD_Y = 179; +static constexpr int16_t SLEEPMAIN_NORECORD_WIDTH = 96; +static constexpr int16_t SLEEPMAIN_NORECORD_HEIGHT = 48; +static constexpr int16_t SLEEPMAIN_NORECORD_FONT_SIZE = 38; +static constexpr int16_t SLEEPMAIN_TIPS_X = 93; +static constexpr int16_t SLEEPMAIN_TIPS_Y = 321; +static constexpr int16_t SLEEPMAIN_TIPS_WIDTH = 188; +static constexpr int16_t SLEEPMAIN_TIPS_HEIGHT = 87; +static constexpr int16_t SLEEPMAIN_TIPS_FONT_SIZE = 24; +static constexpr int16_t SLEEPMAIN_SCORE_X = 164; +static constexpr int16_t SLEEPMAIN_SCORE_Y = 129; +static constexpr int16_t SLEEPMAIN_SCORE_WIDTH = 95; +static constexpr int16_t SLEEPMAIN_SCORE_HEIGHT = 65; +static constexpr int16_t SLEEPMAIN_SCORE_FONT_SIZE = 56; +static constexpr int16_t SLEEPMAIN_MOONNORECORD_X = 154; +static constexpr int16_t SLEEPMAIN_MOONNORECORD_Y = 154; +static constexpr int16_t SLEEPMAIN_SCORETEXT_FONT_SIZE = 21; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_1 = 20; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_2 = 40; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_3 = 60; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_4 = 80; +static constexpr int16_t SLEEP_SCORE_THRESHOLD_5 = 100; +static constexpr int16_t SLEEP_FONT_SIZE_LARGE = 40; +static constexpr int16_t SLEEPMAIN_SCORETEXT_X = 265; +static constexpr int16_t SLEEPMAIN_SCORETEXT_Y = 161; +static constexpr int16_t SLEEP_LABEL_WIDTH = 48; +static constexpr int16_t SLEEP_LABEL_HEIGHT = 29; +static constexpr int16_t SLEEP_TIME_LABEL_WIDTH = 100; +static constexpr int16_t SLEEP_TIME_LABEL_HEIGHT = 50; +static constexpr int16_t SLEEPMAIN_SETTING_X = 280; +static constexpr int16_t SLEEPMAIN_SETTING_Y = 374; +static constexpr int16_t SLEEPMAIN_ACTUALMINUTE_X = 230; +static constexpr int16_t SLEEPMAIN_ACTUALMINUTE_Y = 319; +static constexpr int16_t SLEEPMAIN_ACTUALHOUR_X = 135; +static constexpr int16_t ACTUALHOURS_X = 140; +static constexpr int16_t ACTUALMINUTES_X = 180; +static constexpr int16_t ACTUALMINUTES_Y = 303; +static constexpr int16_t SLEEPMAIN_ACTUALHOURTEXT_X = 170; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEPTIMEHOURS_FONT_SIZE = 32; +static constexpr int16_t SLEEPMAIN_HEIGHT = 50; +static constexpr int16_t SLEEPDETAIL_ACTUALSLEEPTIMINUTES_FONT_SIZE = 40; +static constexpr int16_t SLEEPMAIN_ACTUALMINUTETEXT_X = 280; +static constexpr int16_t SLEEPMAIN_ACTUALH_X = 170; +static constexpr int16_t SLEEPMAIN_ACTUALMINUTETEXT2_X = 270; +static constexpr int16_t SLEEPMAIN_CIR_HIGHT = 444; +static constexpr int16_t SLEEPMAIN_CIR_X = 228; +static constexpr int16_t SLEEPMAIN_CIR_Y = 228; +static constexpr int16_t SLEEPMAIN_CIR_RADIUS = 215; +static constexpr int16_t SLEEPMAIN_CIR_ANGLE = 360; +static constexpr int16_t SLEEPMAIN_CIR_RANGE = 100; +static constexpr int16_t SLEEPMAIN_CIR_LINE_WIDTH = 10; +static constexpr int16_t SLEEPMAIN_SCORE = 100; +static constexpr int16_t SLEEPMAIN_RATE = 100; +static constexpr float MINUTE_HOUR = 60.0f; +static constexpr int16_t TARGETTIMETEXT_Y = 363; +static constexpr int16_t TARGETTIMEBUTTON_X = 137; +static constexpr int16_t TARGETTIMETEXT_WIDTH = 184; +static constexpr int16_t TARGETTIMETEXT_HIGHT = 46; +static constexpr int16_t MAIN_SLEEP_COLOR_R = 181; +static constexpr int16_t MAIN_SLEEP_COLOR_G = 402; +static constexpr int16_t MAIN_SLEEP_COLOR_B = 255; +static constexpr int16_t MAIN_SLEEP_OPT = 110; +static constexpr int16_t MAIN_SLEEP_RANGE = 10; +static constexpr int16_t MAIN_SLEEP_POSX_2 = 2; +static constexpr int16_t MAIN_SLEEP_POSX_3 = 3; +static constexpr int16_t MAIN_SLEEP_POSX_4 = 4; +static constexpr int16_t MAIN_SLEEP_MOON_POSX = 198; +static constexpr int16_t MAIN_SLEEP_SCORE_HEIGHT = 192; +static constexpr int16_t MAIN_SLEEP_SCORE_X = 131; +static constexpr int16_t MAIN_SLEEP_SCORE_Y = 200; +static constexpr int16_t MAIN_SLEEP_STAR1_X = 145; +static constexpr int16_t MAIN_SLEEP_STAR2_X = 180; +static constexpr int16_t MAIN_SLEEP_STAR3_X = 215; +static constexpr int16_t MAIN_SLEEP_STAR4_X = 250; +static constexpr int16_t MAIN_SLEEP_STAR5_X = 285; +static constexpr int16_t MAIN_SLEEP_STAR_Y = 255; +static constexpr int16_t MAIN_SLEEP_SCORE_TEXT_FONT_SIZE = 55; +static constexpr int16_t MAIN_SLEEP_STAR_NUM = 5; + +int posX[MAIN_SLEEP_STAR_NUM] = {MAIN_SLEEP_STAR1_X, MAIN_SLEEP_STAR2_X, MAIN_SLEEP_STAR3_X, MAIN_SLEEP_STAR4_X, MAIN_SLEEP_STAR5_X}; +int posY = MAIN_SLEEP_STAR_Y; + +SleepingMainPage::SleepingMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepingMainPage::SleepingMainPage"); +} + +SleepingMainPage::~SleepingMainPage() +{ + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (imageViewMain != nullptr) { + delete imageViewMain; + imageViewMain = nullptr; + } + + if (sleep != nullptr) { + delete sleep; + sleep = nullptr; + } + + if (moonNoRecord != nullptr) { + delete moonNoRecord; + moonNoRecord = nullptr; + } + + if (moon != nullptr) { + delete moon; + moon = nullptr; + } + + if (noRecord != nullptr) { + delete noRecord; + noRecord = nullptr; + } + + if (tips != nullptr) { + delete tips; + tips = nullptr; + } + + if (sleepScores_ != nullptr) { + delete sleepScores_; + sleepScores_ = nullptr; + } + + if (scoreText != nullptr) { + delete scoreText; + scoreText = nullptr; + } + + if (sleepScore != nullptr) { + delete sleepScore; + sleepScore = nullptr; + } + + if (scoreDisplayPicture1 != nullptr) { + delete scoreDisplayPicture1; + scoreDisplayPicture1 = nullptr; + } + + if (scoreDisplayPicture2 != nullptr) { + delete scoreDisplayPicture2; + scoreDisplayPicture2 = nullptr; + } + + if (scoreDisplayPicture3 != nullptr) { + delete scoreDisplayPicture3; + scoreDisplayPicture3 = nullptr; + } + if (scoreDisplayPicture4 != nullptr) { + delete scoreDisplayPicture4; + scoreDisplayPicture4 = nullptr; + } + + if (scoreDisplayPicture5 != nullptr) { + delete scoreDisplayPicture5; + scoreDisplayPicture5 = nullptr; + } + + if (setting != nullptr) { + delete setting; + setting = nullptr; + } + + if (targetTimeText != nullptr) { + delete targetTimeText; + targetTimeText = nullptr; + } + + if (actualSleepTimeHours != nullptr) { + delete actualSleepTimeHours; + actualSleepTimeHours = nullptr; + } + + if (actualSleepTimeHoursText != nullptr) { + delete actualSleepTimeHoursText; + actualSleepTimeHoursText = nullptr; + } + + if (actualSleepTimeMinutes != nullptr) { + delete actualSleepTimeMinutes; + actualSleepTimeMinutes = nullptr; + } + + if (actualSleepTimeMinutesText != nullptr) { + delete actualSleepTimeMinutesText; + actualSleepTimeMinutesText = nullptr; + } + + if (targetTimeButton != nullptr) { + delete targetTimeButton; + targetTimeButton = nullptr; + } + + if (circleProgress != nullptr) { + delete circleProgress; + circleProgress = nullptr; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepingMainPage::~SleepingMainPage"); +} + +void SleepingMainPage::OnStart(void* data) +{ + group = new UIScrollView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group is nullptr"); + return; + } + group->SetPosition(0, 0); + group->Resize(RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + group->SetViewId("sleepMain"); + + imageViewMain = new UIImageView(); + if (imageViewMain == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "imageViewMain is nullptr"); + return; + } + LOADIMG::LoadImageViewImg(imageViewMain, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_BACKGROUND); + imageViewMain->SetPosition(0, 0, RESOLUTION_WIDTH, RESOLUTION_HEIGHT); + group->Add(imageViewMain); + + if (GetRecord() == false) { + InitNoRecordPage(); + } else { + InitRecordPage(); + } + + group->SetOnDragListener(this); + group->SetDraggable(true); + group->SetTouchable(true); + AddViewToPageContainer(group); +} + +void SleepingMainPage::InitNoRecordPage() +{ + sleep = new UILabel(); + if (sleep == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep is nullptr"); + return; + } + sleep->SetPosition(SLEEPMAIN_SLEEP_X, SLEEPMAIN_SLEEP_Y); + sleep->Resize(SLEEPMAIN_SLEEP_WIDTH, SLEEPMAIN_SLEEP_HEIGHT); + sleep->SetText("睡眠"); + sleep->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sleep->SetTextColor(Color::White()); + sleep->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_SLEEP_FONT_SIZE); + sleep->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(sleep); + + moonNoRecord = new UIImageView(); + if (moonNoRecord == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "moonNoRecord is nullptr"); + return; + } + LOADIMG::LoadImageViewImg(moonNoRecord, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_NORECORD_SLEEP); + moonNoRecord->SetPosition(SLEEPMAIN_MOONNORECORD_X, SLEEPMAIN_MOONNORECORD_Y); + group->Add(moonNoRecord); + + noRecord = new UILabel(); + if (noRecord == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "noRecord is nullptr"); + return; + } + noRecord->SetPosition(SLEEPMAIN_NORECORD_X, SLEEPMAIN_NORECORD_Y); + noRecord->Resize(SLEEPMAIN_NORECORD_WIDTH, SLEEPMAIN_NORECORD_HEIGHT); + noRecord->SetText("无记录"); + noRecord->SetTextColor(Color::White()); + noRecord->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_NORECORD_FONT_SIZE); + noRecord->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(noRecord); + + tips = new UILabel(); + if (tips == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tips is nullptr"); + return; + } + tips->SetPosition(SLEEPMAIN_TIPS_X, SLEEPMAIN_TIPS_Y); + tips->Resize(SLEEPMAIN_TIPS_WIDTH, SLEEPMAIN_TIPS_HEIGHT); + tips->SetText("睡眠时间过短或睡眠中动作幅度大,手表可能检测不到睡眠"); + tips->SetTextColor(Color::White()); + tips->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE); + tips->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(tips); +} + +void SleepingMainPage::InitRecordPage() +{ + SleepingModel::GetInstance().SendData(); + CircleProgress(); + moon = new UIImageView(); + if (moon == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "moon is nullptr"); + return; + } + + moon->SetPosition(MAIN_SLEEP_MOON_POSX, TARGETTIMETEXT_HIGHT); + LOADIMG::LoadImageViewImg(moon, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_RECORD_SLEEP); + group->Add(moon); + + sleepScores_ = new UILabel(); + if (sleepScores_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepScores_ is nullptr"); + return; + } + + sleepScores_->SetText(std::to_string(GetSleepingScores()).c_str()); + sleepScores_->SetPosition(SLEEPMAIN_SCORE_X, SLEEPMAIN_SCORE_Y); + sleepScores_->Resize(SLEEPMAIN_SCORE_WIDTH, SLEEPMAIN_SCORE_HEIGHT); + sleepScores_->SetTextColor(Color::White()); + sleepScores_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sleepScores_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_SCORE_FONT_SIZE); + sleepScores_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + group->Add(sleepScores_); + + scoreText = new UILabel(); + if (scoreText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scoreText is nullptr"); + return; + } + scoreText->SetText("分"); + scoreText->SetPosition(SLEEPMAIN_SCORETEXT_X, SLEEPMAIN_SCORETEXT_Y); + scoreText->Resize(MAIN_SLEEP_SCORE_TEXT_FONT_SIZE, SLEEPMAIN_TIPS_FONT_SIZE); + scoreText->SetTextColor(Color::White()); + scoreText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_SCORETEXT_FONT_SIZE); + group->Add(scoreText); + ScoreDisplay(); + sleepScore = new UILabel(); + if (sleepScore == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepScore is nullptr"); + return; + } + sleepScore->SetText("夜间睡眠得分"); + sleepScore->Resize(MAIN_SLEEP_SCORE_HEIGHT, SLEEPMAIN_NORECORD_HEIGHT); + sleepScore->SetPosition(MAIN_SLEEP_SCORE_X, MAIN_SLEEP_SCORE_Y); + sleepScore->SetTextColor(Color::White()); + sleepScore->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPDETAIL_ACTUALSLEEPTIMEHOURS_FONT_SIZE); + group->Add(sleepScore); + + // 显示具体睡觉时间 + IoadActualSleepTime(SleepingModel::GetInstance().GetSleepTime()); + + // 加载目标按钮 + IoadTargetTimeButton(SleepingModel::GetInstance().GetTime()); +} +void SleepingMainPage::InitScoreDisplayPicture() +{ + if (scoreDisplayPicture1 == nullptr) { + scoreDisplayPicture1 = new UIImageView(); + } + scoreDisplayPicture1->SetPosition(posX[0], posY); + group->Add(scoreDisplayPicture1); + + if (scoreDisplayPicture2 == nullptr) { + scoreDisplayPicture2 = new UIImageView(); + } + scoreDisplayPicture2->SetPosition(posX[1], posY); + group->Add(scoreDisplayPicture2); + + if (scoreDisplayPicture3 == nullptr) { + scoreDisplayPicture3 = new UIImageView(); + } + scoreDisplayPicture3->SetPosition(posX[MAIN_SLEEP_POSX_2], posY); + group->Add(scoreDisplayPicture3); + + if (scoreDisplayPicture4 == nullptr) { + scoreDisplayPicture4 = new UIImageView(); + } + scoreDisplayPicture4->SetPosition(posX[MAIN_SLEEP_POSX_3], posY); + group->Add(scoreDisplayPicture4); + + if (scoreDisplayPicture5 == nullptr) { + scoreDisplayPicture5 = new UIImageView(); + } + + scoreDisplayPicture5->SetPosition(posX[MAIN_SLEEP_POSX_4], posY); + group->Add(scoreDisplayPicture5); +} + +void SleepingMainPage::ScoreDisplay() +{ + InitScoreDisplayPicture(); + if (GetSleepingScores() < SLEEP_SCORE_THRESHOLD_1) { + LOADIMG::LoadImageViewImg(scoreDisplayPicture1, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture2, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture3, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture4, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture5, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + } else if (GetSleepingScores() >= SLEEP_SCORE_THRESHOLD_1 && GetSleepingScores() < SLEEP_SCORE_THRESHOLD_2) { + LOADIMG::LoadImageViewImg(scoreDisplayPicture1, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture2, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture3, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture4, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture5, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + } else if (GetSleepingScores() >= SLEEP_SCORE_THRESHOLD_2 && GetSleepingScores() < SLEEP_SCORE_THRESHOLD_3) { + LOADIMG::LoadImageViewImg(scoreDisplayPicture1, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture2, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture3, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture4, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture5, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + } else if (GetSleepingScores() >= SLEEP_SCORE_THRESHOLD_3 && GetSleepingScores() < SLEEP_SCORE_THRESHOLD_4) { + LOADIMG::LoadImageViewImg(scoreDisplayPicture1, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture2, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture3, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture4, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + LOADIMG::LoadImageViewImg(scoreDisplayPicture5, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + } else if (GetSleepingScores() >= SLEEP_SCORE_THRESHOLD_4 && GetSleepingScores() < SLEEP_SCORE_THRESHOLD_5) { + LOADIMG::LoadImageViewImg(scoreDisplayPicture1, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture2, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture3, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture4, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture5, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_GRAY); + } else if (GetSleepingScores() == SLEEP_SCORE_THRESHOLD_5) { + LOADIMG::LoadImageViewImg(scoreDisplayPicture1, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture2, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture3, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture4, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + LOADIMG::LoadImageViewImg(scoreDisplayPicture5, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_STAR_YELLOW); + } +} + +void SleepingMainPage::InitSleepTimeLabel() +{ + actualSleepTimeHours = new UILabel(); + if (actualSleepTimeHours == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeHours is nullptr"); + return; + } + + actualSleepTimeHours->SetTextColor(Color::White()); + actualSleepTimeHours->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEP_FONT_SIZE_LARGE); + actualSleepTimeHours->SetVisible(false); + + actualSleepTimeHoursText = new UILabel(); + if (actualSleepTimeHoursText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeHoursText is nullptr"); + return; + } + actualSleepTimeHoursText->SetText("小时"); + actualSleepTimeHoursText->Resize(SLEEP_LABEL_WIDTH, SLEEP_LABEL_HEIGHT); + actualSleepTimeHoursText->SetTextColor(Color::White()); + actualSleepTimeHoursText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE); + actualSleepTimeHoursText->SetVisible(false); + + actualSleepTimeMinutes = new UILabel(); + if (actualSleepTimeMinutes == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeMinutes is nullptr"); + return; + } + + actualSleepTimeMinutes->Resize(SLEEP_TIME_LABEL_WIDTH, SLEEP_TIME_LABEL_HEIGHT); + actualSleepTimeMinutes->SetTextColor(Color::White()); + actualSleepTimeMinutes->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEP_FONT_SIZE_LARGE); + actualSleepTimeMinutes->SetVisible(false); + + actualSleepTimeMinutesText = new UILabel(); + if (actualSleepTimeMinutesText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "actualSleepTimeMinutesText is nullptr"); + return; + } + + actualSleepTimeMinutesText->SetText("分钟"); + actualSleepTimeMinutesText->Resize(SLEEP_LABEL_WIDTH, SLEEP_LABEL_HEIGHT); + actualSleepTimeMinutesText->SetTextColor(Color::White()); + actualSleepTimeMinutesText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE); + actualSleepTimeMinutesText->SetVisible(false); +} + +void SleepingMainPage::IoadTargetTimeButton(std::tuple timeTuple) +{ + uint32_t hours = std::get<0>(timeTuple); + uint32_t minutes = std::get<1>(timeTuple); + + std::string str = ""; + if ((hours == 0) && (minutes != 0)) { + str = std::to_string(minutes) + "分钟"; + } else if ((hours != 0) && (minutes == 0)) { + str = std::to_string(hours) + "小时"; + } else if ((hours != 0) && (minutes != 0)) { + if (minutes < MAIN_SLEEP_RANGE && hours >= MAIN_SLEEP_RANGE) { + str = " " + std::to_string(hours) + ":0" + std::to_string(minutes); + } else if (hours < MAIN_SLEEP_RANGE && minutes >= MAIN_SLEEP_RANGE) { + str = " 0"+ std::to_string(hours) + ":" + std::to_string(minutes); + } else if (minutes < MAIN_SLEEP_RANGE && hours < MAIN_SLEEP_RANGE) { + str = " 0" + std::to_string(hours) + ":0" + std::to_string(minutes); + } else if (minutes >= MAIN_SLEEP_RANGE && hours >= MAIN_SLEEP_RANGE) { + str = " " + std::to_string(hours) + ":" + std::to_string(minutes); + } + } + targetTimeButton = new UILabelButton(); + if (targetTimeButton == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetTimeButton is nullptr"); + return; + } + targetTimeButton->SetPosition(TARGETTIMEBUTTON_X, TARGETTIMETEXT_Y); + targetTimeButton->SetViewId("targetTime"); + targetTimeButton->SetOnClickListener(this); + targetTimeButton->SetStyle(STYLE_BACKGROUND_COLOR, + Color::GetColorFromRGBA(MAIN_SLEEP_COLOR_R, MAIN_SLEEP_COLOR_G, + MAIN_SLEEP_COLOR_B, MAIN_SLEEP_OPT).full); + targetTimeButton->SetStyleForState ( + STYLE_BACKGROUND_COLOR, Color::GetColorFromRGBA( + MAIN_SLEEP_COLOR_R, MAIN_SLEEP_COLOR_G, MAIN_SLEEP_COLOR_B, MAIN_SLEEP_OPT).full, UIButton::PRESSED); + targetTimeButton->Resize(TARGETTIMETEXT_WIDTH, TARGETTIMETEXT_HIGHT); + targetTimeButton->SetTextColor(Color::White()); + targetTimeButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE); + group->Add(targetTimeButton); + + targetTimeText = new UILabel(); + if (targetTimeText == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "targetTimeText is nullptr"); + return; + } + std::string targetText = "目标" + str; + targetTimeText->SetText(targetText.c_str()); + targetTimeText->SetPosition(SLEEPMAIN_MOONNORECORD_X, TARGETTIMETEXT_Y); + targetTimeText->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + targetTimeText->Resize(TARGETTIMETEXT_WIDTH, TARGETTIMETEXT_HIGHT); + targetTimeText->SetTextColor(Color::White()); + targetTimeText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SLEEPMAIN_TIPS_FONT_SIZE); + targetTimeText->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + group->Add(targetTimeText); + + if (setting == nullptr) { + setting = new UIImageView(); + } + setting->SetPosition(SLEEPMAIN_SETTING_X, SLEEPMAIN_SETTING_Y); + LOADIMG::LoadImageViewImg(setting, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_SETTING); + group->Add(setting); +} + +void SleepingMainPage::IoadActualSleepTime(std::tuple timeTuple) +{ + InitSleepTimeLabel(); + uint32_t hours = std::get<0>(timeTuple); + uint32_t minutes = std::get<1>(timeTuple); + + if ((hours == 0) && (minutes != 0)) { + actualSleepTimeMinutes->SetPosition(ACTUALMINUTES_X, ACTUALMINUTES_Y); + actualSleepTimeMinutes->SetVisible(true); + actualSleepTimeMinutes->SetText(std::to_string(minutes).c_str()); + group->Add(actualSleepTimeMinutes); + + actualSleepTimeMinutesText->SetPosition(SLEEPMAIN_ACTUALMINUTE_X, SLEEPMAIN_ACTUALMINUTE_Y); + actualSleepTimeMinutesText->SetVisible(true); + group->Add(actualSleepTimeMinutesText); + } else if ((hours != 0) && (minutes == 0)) { + actualSleepTimeHours->SetPosition(ACTUALMINUTES_X, ACTUALMINUTES_Y); + actualSleepTimeHours->Resize(SLEEPMAIN_HEIGHT, SLEEPMAIN_HEIGHT); + + actualSleepTimeHours->SetVisible(true); + actualSleepTimeHours->SetText(std::to_string(hours).c_str()); + group->Add(actualSleepTimeHours); + + actualSleepTimeHoursText->SetPosition(SLEEPMAIN_ACTUALMINUTE_X, SLEEPMAIN_ACTUALMINUTE_Y); + actualSleepTimeHoursText->SetVisible(true); + group->Add(actualSleepTimeHoursText); + } else if ((hours != 0) && (minutes != 0)) { + actualSleepTimeHours->SetPosition(SLEEPMAIN_ACTUALHOUR_X, ACTUALMINUTES_Y); + actualSleepTimeHours->Resize(SLEEPMAIN_HEIGHT, SLEEPMAIN_HEIGHT); + + actualSleepTimeHours->SetVisible(true); + actualSleepTimeHours->SetText(std::to_string(hours).c_str()); + group->Add(actualSleepTimeHours); + + actualSleepTimeHoursText->SetPosition(SLEEPMAIN_ACTUALHOURTEXT_X, SLEEPMAIN_ACTUALMINUTE_Y); + actualSleepTimeHoursText->SetVisible(true); + group->Add(actualSleepTimeHoursText); + + actualSleepTimeMinutes->SetPosition(SLEEPMAIN_ACTUALMINUTE_X, ACTUALMINUTES_Y); + actualSleepTimeMinutes->SetVisible(true); + actualSleepTimeMinutes->SetText(std::to_string(minutes).c_str()); + group->Add(actualSleepTimeMinutes); + + actualSleepTimeMinutesText->SetPosition(SLEEPMAIN_ACTUALMINUTETEXT_X, SLEEPMAIN_ACTUALMINUTE_Y); + actualSleepTimeMinutesText->SetVisible(true); + group->Add(actualSleepTimeMinutesText); + } else if ((hours == 0) && (minutes == 0)) { + actualSleepTimeHours->SetPosition(ACTUALHOURS_X, ACTUALMINUTES_Y); + actualSleepTimeHours->Resize(SLEEPMAIN_HEIGHT, SLEEPMAIN_HEIGHT); + actualSleepTimeHours->SetVisible(true); + actualSleepTimeHours->SetText("--"); + group->Add(actualSleepTimeHours); + + actualSleepTimeHoursText->SetPosition(ACTUALMINUTES_X, SLEEPMAIN_ACTUALMINUTE_Y); + actualSleepTimeHoursText->SetVisible(true); + group->Add(actualSleepTimeHoursText); + + actualSleepTimeMinutes->SetPosition(SLEEPMAIN_ACTUALMINUTE_X, ACTUALMINUTES_Y); + actualSleepTimeMinutes->SetVisible(true); + actualSleepTimeMinutes->SetText("--"); + group->Add(actualSleepTimeMinutes); + + actualSleepTimeMinutesText->SetPosition(SLEEPMAIN_ACTUALMINUTETEXT2_X, SLEEPMAIN_ACTUALMINUTE_Y); + actualSleepTimeMinutesText->SetVisible(true); + group->Add(actualSleepTimeMinutesText); + } +} + +void SleepingMainPage::CircleProgress() +{ + if (circleProgress == nullptr) { + circleProgress = new UICircleProgress(); + } + circleProgress->SetPosition(0, 0); + circleProgress->Resize(SLEEPMAIN_CIR_HIGHT, SLEEPMAIN_CIR_HIGHT); + + circleProgress->SetCenterPosition(SLEEPMAIN_CIR_X, SLEEPMAIN_CIR_Y); + circleProgress->SetRadius(SLEEPMAIN_CIR_RADIUS); + circleProgress->SetStartAngle(0); + circleProgress->SetEndAngle(SLEEPMAIN_CIR_ANGLE); + circleProgress->SetRange(0, SLEEPMAIN_CIR_RANGE); + circleProgress->SetBackgroundStyle(STYLE_LINE_COLOR, 0xFF6f29a0); + circleProgress->SetForegroundStyle(STYLE_LINE_COLOR, 0xFFB566FF); + circleProgress->SetBackgroundStyle(STYLE_LINE_WIDTH, SLEEPMAIN_CIR_LINE_WIDTH); + circleProgress->SetForegroundStyle(STYLE_LINE_WIDTH, SLEEPMAIN_CIR_LINE_WIDTH); + + group->Add(circleProgress); + circleProgress->SetValue(GetSleepingScores()); + circleProgress->Invalidate(); +} + +uint32_t SleepingMainPage::GetSleepingScores() +{ + uint32_t hours = SleepingModel::GetInstance().GetSleepTimeHours(); + uint32_t minutes = SleepingModel::GetInstance().GetSleepTimeMinutes(); + std::tuple timeTuple = SleepingModel::GetInstance().GetTime(); + uint32_t timeHours = std::get<0>(timeTuple); + uint32_t timeMinutes = std::get<1>(timeTuple); + if (((hours * MINUTE_HOUR) + minutes) > ((timeHours * MINUTE_HOUR) + timeMinutes)) { + return SLEEPMAIN_SCORE; + } else { + float score = ((hours * MINUTE_HOUR) + minutes) / ((timeHours * MINUTE_HOUR) + timeMinutes); + return uint32_t(score * SLEEPMAIN_RATE); + } +} + +bool SleepingMainPage::GetRecord() +{ + if (SleepingModel::GetInstance().GetRecord()) { + return true; + } + return false; +} + +bool SleepingMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(view); + if (strcmp(view.GetViewId(), "targetTime") == 0) { + NativeAbility::GetInstance().SwitchSlice(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_TARGET_PAGE); + } + return true; +} + +bool SleepingMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepingMainPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { + NativeAbility::GetInstance().SwitchSlice(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_DEATIL_PAGE); + } + return true; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingModel.cpp new file mode 100644 index 000000000..fc254503d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingModel.cpp @@ -0,0 +1,283 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepingModel + * Created: 2025-06-05 + */ + +#include +#include +#include +#include +#include "main/HealthModel.h" +#include "uiservice/ui_service.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "ui_test_group.h" +#include "graphic_timer.h" +#include "ohos_timer.h" +#include "wearable_onlinelog.h" +#include "sleep/SleepingModel.h" + +namespace OHOS { +static constexpr uint64_t SLEEPMODEL_MINUTE_HOUR = 60; +static constexpr uint64_t SLEEPMODEL_HOUR = 23; +static constexpr uint64_t SLEEPMODEL_MINUTE = 59; +static constexpr uint64_t SLEEPMODEL_ERROR = 100; +static constexpr uint64_t SLEEPMODEL_DEEP = 4; +static constexpr uint64_t SLEEPMODEL_LIGHT = 3; +static constexpr uint64_t SLEEPMODEL_EYEMOVE = 2; +static constexpr uint64_t SLEEPMODEL_EIGHT_HOUR = 480; + +SleepingModel::SleepingModel() +{ + SetSleepData(); + SetSoberingTime(); + SetRapidEyeMovementTime(); + SetLightSleepTime(); + SetDeepSleepTime(); + SetTime(SLEEPMODEL_EIGHT_HOUR); +} + +SleepingModel::~SleepingModel() +{ +} + +bool SleepingModel::GetRecord() +{ + if (sleepDataVector.empty() == true) { + return false; + } + return true; +} + +uint8_t* SleepingModel::SerializeSleepData(const SleepData* sleepData, size_t* outSize) +{ + if (sleepData == nullptr) { + return nullptr; + } + size_t dataSize = sizeof(SleepData); + *outSize = dataSize; + uint8_t* buffer = new uint8_t[dataSize]; + uint8_t isSendValue = sleepData->isSend ? 1 : 0; + memcpy_s(buffer, sizeof(isSendValue), &isSendValue, sizeof(isSendValue)); + memcpy_s(buffer + offsetof(SleepData, date), sizeof(sleepData->date), + sleepData->date, sizeof(sleepData->date)); + memcpy_s(buffer + offsetof(SleepData, type), sizeof(sleepData->type), + &sleepData->type, sizeof(sleepData->type)); + memcpy_s(buffer + offsetof(SleepData, start), sizeof(sleepData->start), + sleepData->start, sizeof(sleepData->start)); + memcpy_s(buffer + offsetof(SleepData, end), sizeof(sleepData->end), + sleepData->end, sizeof(sleepData->end)); + memcpy_s(buffer + offsetof(SleepData, sleepStart), sizeof(sleepData->sleepStart), + sleepData->sleepStart, sizeof(sleepData->sleepStart)); + memcpy_s(buffer + offsetof(SleepData, sleepEnd), sizeof(sleepData->sleepEnd), + sleepData->sleepEnd, sizeof(sleepData->sleepEnd)); + return buffer; +} + +void SleepingModel::SendData() +{ +#ifndef _WIN32 + // 发送数据 + size_t dataSize; + for (int i = 0; i < sleepDataVector.size(); i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "send Date number: %d\n", i+1); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "send front isSend: %s\n\n", + sleepDataVector[i].isSend ? "true" : "false"); + if (sleepDataVector[i].isSend == true) { + continue; + } + PrintSleepData(&sleepDataVector[i]); + uint8_t* serializedData = SerializeSleepData(&sleepDataVector[i], &dataSize); + errcode_t ret = uapi_diag_service_send_log(msg_center_get_trans_channel(), + MSGCENTER_TYPE_ID_SLEEP_DATA, serializedData, dataSize); + delete[] serializedData; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MSGCENTER_TYPE_ID_SLEEP_DATA ret = %d", ret); + if (ret == 0) { + sleepDataVector[i].isSend = true; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "isSend after: %s\n\n", sleepDataVector[i].isSend ? "true" : "false"); + } +#endif +} + +void SleepingModel::SetSleepData() +{ +#ifndef _WIN32 + sleepDataVector.push_back({ + false, "2025-06-03", 4, "2025-06-03 00:00:00", "2025-06-03 00:30:00", + "2025-06-03 00:00:00", "2025-06-03 07:50:00" + }); + sleepDataVector.push_back({ + false, "2025-06-03", 2, "2025-06-03 00:30:00", "2025-06-03 03:00:00", + "2025-06-03 00:00:00", "2025-06-03 07:50:00" + }); + sleepDataVector.push_back({ + false, "2025-06-03", 3, "2025-06-03 03:00:00", "2025-06-03 03:30:00", + "2025-06-03 00:00:00", "2025-06-03 07:50:00" + }); + sleepDataVector.push_back({ + false, "2025-06-03", 1, "2025-06-03 03:30:00", "2025-06-03 05:30:00", + "2025-06-03 00:00:00", "2025-06-03 07:50:00" + }); + sleepDataVector.push_back({ + false, "2025-06-03", 3, "2025-06-03 05:30:00", "2025-06-03 06:00:00", + "2025-06-03 00:00:00", "2025-06-03 07:50:00" + }); + sleepDataVector.push_back({ + false, "2025-06-03", 2, "2025-06-03 06:00:00", "2025-06-03 07:30:00", + "2025-06-03 00:00:00", "2025-06-03 07:50:00" + }); + sleepDataVector.push_back({ + false, "2025-06-03", 4, "2025-06-03 07:30:00", "2025-06-03 07:50:00", + "2025-06-03 00:00:00", "2025-06-03 07:50:00" + }); +#endif +} + +void SleepingModel::PrintSleepData(const SleepData *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "isSend: %s\n\n", data->isSend ? "true" : "false"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PrintSleepData Date: %s\n", data->date); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Sleep type: %u\n", data->type); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Start: %s\n", data->start); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "End: %s\n", data->end); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Sleep Start: %s\n", data->sleepStart); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Sleep End: %s\n", data->sleepEnd); +} + +SleepingModel &SleepingModel::GetInstance() +{ + static SleepingModel instance; + return instance; +} + +std::tuple SleepingModel::GetSoberingTime() +{ + return MinutesToHours(soberingTime); +} + +std::tuple SleepingModel::GetRapidEyeMovementTime() +{ + return MinutesToHours(eyeMoveTime); +} + +std::tuple SleepingModel::GetLightSleepTime() +{ + return MinutesToHours(lightTime); +} + +std::tuple SleepingModel::GetDeepSleepTime() +{ + return MinutesToHours(deepTime); +} + +std::tuple SleepingModel::GetSleepTime() +{ + return MinutesToHours(GetTotalSleepTime()); +} + +std::tuple SleepingModel::MinutesToHours(uint32_t minutes) +{ + if (minutes == 0) { + return std::make_tuple(0, 0); + } + int hours = minutes / SLEEPMODEL_MINUTE_HOUR; + int remainingMinutes = minutes % SLEEPMODEL_MINUTE_HOUR; + + if (hours > SLEEPMODEL_HOUR || remainingMinutes > SLEEPMODEL_MINUTE) { + return std::make_tuple(SLEEPMODEL_ERROR, 0); + } + + return std::make_tuple(hours, remainingMinutes); +} + +uint32_t SleepingModel::GetSleepTimeHours() +{ + std::tuple timeTuple = GetSleepTime(); + return std::get<0>(timeTuple); +} + +uint32_t SleepingModel::GetSleepTimeMinutes() +{ + std::tuple timeTuple = GetSleepTime(); + return std::get<1>(timeTuple); +} + +void SleepingModel::SetTime(uint32_t minute) +{ + sleepTarget = minute; +} + +std::tuple SleepingModel::GetTime() +{ + return MinutesToHours(sleepTarget); +} + +uint32_t SleepingModel::TimeDiffInMinutes(const std::string& timeStr1, const std::string& timeStr2) +{ + std::tm tm1 = {}; + std::tm tm2 = {}; + + std::istringstream iss1(timeStr1); + std::istringstream iss2(timeStr2); + + iss1 >> std::get_time(&tm1, "%Y-%m-%d %H:%M:%S"); + if (iss1.fail()) { + return -1; + } + + iss2 >> std::get_time(&tm2, "%Y-%m-%d %H:%M:%S"); + if (iss2.fail()) { + return -1; + } + + std::time_t t1 = std::mktime(&tm1); + std::time_t t2 = std::mktime(&tm2); + if (t1 == -1 || t2 == -1) { + return -1; + } + + double diff_seconds = std::difftime(t2, t1); + return static_cast(diff_seconds / SLEEPMODEL_MINUTE_HOUR); +} + +// 遍历vector中的结构体 获取对应类型的时间差 +uint32_t SleepingModel::GetDetailData(int type) +{ + uint32_t min = 0; + for (size_t i = 0; i < sleepDataVector.size(); ++i) { + if (sleepDataVector[i].type == type) { + min += TimeDiffInMinutes(sleepDataVector[i].start, sleepDataVector[i].end); + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetDetailData type: %d\n", type); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetDetailData min: %d\n", min); + return min; +} + +// 获取总睡觉时间的时间差 +uint32_t SleepingModel::GetTotalSleepTime() +{ + uint32_t time = TimeDiffInMinutes(sleepDataVector[0].sleepStart, sleepDataVector[0].sleepEnd); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetTotalSleepTime time: %d\n", time); + return time; +} + +void SleepingModel::SetSoberingTime() +{ + soberingTime = GetDetailData(SLEEPMODEL_DEEP); +} +void SleepingModel::SetRapidEyeMovementTime() +{ + eyeMoveTime=GetDetailData(SLEEPMODEL_LIGHT); +} +void SleepingModel::SetLightSleepTime() +{ + lightTime = GetDetailData(SLEEPMODEL_EYEMOVE); +} +void SleepingModel::SetDeepSleepTime() +{ + deepTime = GetDetailData(1); +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingPresenter.cpp new file mode 100644 index 000000000..e1b9bf839 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/SleepingPresenter.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SleepingPresenter + * Created: 2025-06-05 + */ + +#include "NativeRegisterManager.h" +#include "sleep/SleepingView.h" +#include "sleep/SleepingPresenter.h" + +namespace OHOS { +REGIST_MENU(VIEW_SLEEPING, SleepingView, SleepingPresenter, SLEEP_ICON, PNG_APPLIST_DEFAULT_IMG, "睡眠"); +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/TargetSleepTime.cpp b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/TargetSleepTime.cpp new file mode 100644 index 000000000..4eab1f32f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/sleep/src/TargetSleepTime.cpp @@ -0,0 +1,335 @@ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TargetSleepTime + * Created: 2025-06-05 + */ +#include +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "PageTransitionMgr.h" +#include "settings/SetDesktopModel.h" +#include "rebootdevice/RebootModel.h" +#include "common/image_cache_manager.h" +#include "sleep/TargetSleepTime.h" +#include "sleep/SleepingMainPage.h" +#include "sleep/SleepingPresenter.h" +#include "sleep/SleepingView.h" + +namespace OHOS { +constexpr uint8_t BACKGROUND_FONT = 40; +constexpr uint8_t HIGHTLIGHT_FONT = 50; +static constexpr int16_t TARGET_SLEEP_SETTARGET_X = 120; +static constexpr int16_t TARGET_SLEEP_SETTARGET_Y = 40; +static constexpr int16_t TARGET_SLEEP_SETTARGET_WIDTH = 200; +static constexpr int16_t TARGET_SLEEP_SETTARGET_HIGHT = 38; +static constexpr int16_t TARGET_SLEEP_SETTARGET_FONT_SIZE = 32; +static constexpr int16_t TARGET_SLEEP_START_X = 112; +static constexpr int16_t TARGET_SLEEP_START_Y = 347; +static constexpr int16_t TARGET_SLEEP_START_WIDTH = 232; +static constexpr int16_t TARGET_SLEEP_START_HIGHT = 76; +static constexpr int16_t TARGET_SLEEP_PICKER2_X = 270; +static constexpr int16_t TARGET_SLEEP_PICKER_Y = 132; +static constexpr int16_t TARGET_SLEEP_PICKER_WIDTH = 80; +static constexpr int16_t TARGET_SLEEP_PICKER_HIGHT = 188; +static constexpr int16_t TARGET_SLEEP_PICKER_BORDER = 3; +static constexpr int16_t TARGET_SLEEP_PICKER_RADIUS = 11; +static constexpr int16_t TARGET_SLEEP_PICKER_ITEM = 63; +static constexpr int16_t TARGET_SLEEP_PICKER_HOUR = 24; +static constexpr int16_t TARGET_SLEEP_PICKER_MINUTE = 60; +static constexpr int16_t TARGET_SLEEP_PICKER_HOUR_RANGE = 23; +static constexpr int16_t TARGET_SLEEP_PICKER_MINUTE_RANGE = 59; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL_X = 131; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL2_X = 273; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL_Y = 99; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL2_Y = 90; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL_WIDTH = 55; +static constexpr int16_t TARGET_SLEEP_TIMERLABEL_HEIGHT = 30; +static constexpr uint8_t TIMERLABEL_FONT = 24; +static constexpr int16_t TARGET_SLEEP_COLOR_R = 181; +static constexpr int16_t TARGET_SLEEP_COLOR_G = 402; +static constexpr int16_t TARGET_SLEEP_COLOR_B = 255; +static constexpr int16_t NUM_PICKER = 2; +static constexpr int16_t TARGET_SLEEP_PICKER1_X = 115; +static constexpr int16_t TARGET_SLEEP_PICKER2_Y = 255; + +// 时间选择器分钟列 +const char *uiPickerMinute[] = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", + "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", + "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", + "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", + "51", "52", "53", "54", "55", "56", "57", "58", "59"}; + +// 时间选择器小时列 +const char *uiPickerHour[] = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", + "15", "16", "17", "18", "19", "20", "21", "22", "23"}; + +REGIST_SLICE_PAGE(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_TARGET_PAGE, TargetSleepTime, false); + +TargetSleepTime::~TargetSleepTime() +{ + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (setTraget != nullptr) { + delete setTraget; + setTraget = nullptr; + } + + if (timerLabel != nullptr) { + delete timerLabel; + timerLabel = nullptr; + } + + if (startButton != nullptr) { + delete startButton; + startButton = nullptr; + } + + if (backgroundImage != nullptr) { + delete backgroundImage; + backgroundImage = nullptr; + } + + for (int i = 0; i < NUM_PICKER; i++) { + if (timerPicker[i] != nullptr) { + delete timerPicker[i]; + timerPicker[i] = nullptr; + } + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TargetSleepTime::~TargetSleepTime"); +} + +void TargetSleepTime::OnStart(void* data) +{ + group = new UIScrollView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group is nullptr"); + return; + } + group->SetPosition(0, 0); + group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + + backgroundImage = new UIImageView(); + if (backgroundImage == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backgroundImage is nullptr"); + return; + } + backgroundImage->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(backgroundImage, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_BLACK_BG); + group->Add(backgroundImage); + + setTraget = new UILabel(); + if (setTraget == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "setTraget is nullptr"); + return; + } + setTraget->SetPosition(TARGET_SLEEP_SETTARGET_X, TARGET_SLEEP_SETTARGET_Y); + setTraget->Resize(TARGET_SLEEP_SETTARGET_WIDTH, TARGET_SLEEP_SETTARGET_HIGHT); + setTraget->SetText("设置目标"); + setTraget->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + setTraget->SetTextColor(Color::White()); + setTraget->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TARGET_SLEEP_SETTARGET_FONT_SIZE); + setTraget->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(setTraget); + + TargetTimeButton(); + CreateLabel(); + CreatePicker(); + + group->SetOnDragListener(this); + group->SetDraggable(true); + group->SetTouchable(true); + AddViewToPageContainer(group); +} + +void TargetSleepTime::TargetTimeButton() +{ + startButton = new UILabelButton(); + if (startButton == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startButton is nullptr"); + return; + } + startButton->SetPosition(TARGET_SLEEP_START_X, TARGET_SLEEP_START_Y); + startButton->Resize(TARGET_SLEEP_START_WIDTH, TARGET_SLEEP_START_HIGHT); + startButton->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + startButton->SetAlign(TEXT_ALIGNMENT_CENTER); + startButton->SetViewId("start"); + + startButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TARGET_SLEEP_SETTARGET_FONT_SIZE); + startButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Purple().full); + startButton->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::White().full, UIButton::PRESSED); + startButton->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::White().full, UIButton::RELEASED); + startButton->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::INACTIVE); + LOADIMG::LoadBtnImage(startButton, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_SETTIMEBTN, IMAGE_CONVERTER_TOOL_SETTIMEBTN); + startButton->SetText("开始"); + startButton->SetTextColor(Color::White()); + startButton->Enable(); + startButton->SetOnClickListener(this); + group->Add(startButton); +} + +void TargetSleepTime::SetPickerTime() +{ + std::tuple time = SleepingModel::GetInstance().GetTime(); + uint32_t timeHours = std::get<0>(time); + uint32_t timeMinutes = std::get<1>(time); + timerPicker[0] -> SetSelected(timeHours); + timerPicker[1] -> SetSelected(timeMinutes); +} + +void TargetSleepTime::CreatePicker() +{ + int posX[NUM_PICKER] = {TARGET_SLEEP_PICKER1_X, TARGET_SLEEP_PICKER2_Y}; + int posY = TARGET_SLEEP_PICKER_Y; + for (int i = 0; i < NUM_PICKER; i++) { + if (timerPicker[i] == nullptr) { + timerPicker[i] = new UIPicker(); + } + timerPicker[i]->SetPosition(posX[i], posY); + timerPicker[i]->Resize(TARGET_SLEEP_PICKER_WIDTH, TARGET_SLEEP_PICKER_HIGHT); + timerPicker[i]->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + timerPicker[i]->SetStyle(STYLE_BORDER_WIDTH, TARGET_SLEEP_PICKER_BORDER); + timerPicker[i]->SetStyle(STYLE_BORDER_RADIUS, TARGET_SLEEP_PICKER_RADIUS); + timerPicker[i]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[i]->SetItemHeight(TARGET_SLEEP_PICKER_ITEM); + timerPicker[i]->SetLoopState(true); + timerPicker[i]->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); + timerPicker[i]->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); + timerPicker[i]->SetTextColor(Color::Gray(), Color::White()); + if (i == 0) { + timerPicker[i]->SetValues(uiPickerHour, TARGET_SLEEP_PICKER_HOUR); + timerPicker[i]->SetSelected(TARGET_SLEEP_PICKER_HOUR_RANGE); + } else { + timerPicker[i]->SetValues(uiPickerMinute, TARGET_SLEEP_PICKER_MINUTE); + timerPicker[i]->SetSelected(TARGET_SLEEP_PICKER_MINUTE_RANGE); + } + timerPicker[i]->SetOnClickListener(this); + timerPicker[i]->SetOnDragListener(this); + timerPicker[i]->RegisterSelectedListener(this); + timerPicker[i]->SetDraggable(true); + group->Add(timerPicker[i]); + } + + timerPicker[0]->SetViewId("hourPicker"); + timerPicker[1]->SetViewId("minPicker"); + SetPickerTime(); +} + +bool TargetSleepTime::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + std::string viewId = view.GetViewId(); + if (viewId == "start") { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerMainPage::OnClick viewId == ONE_MIN"); + int hour = std::stoi(uiPickerHour[timerPicker[0]->GetSelected()]); + uint8_t minute = std::stoi(uiPickerMinute[timerPicker[1]->GetSelected()]); + SleepingModel::GetInstance().SetTime((hour * TARGET_SLEEP_PICKER_MINUTE) + minute); + NativeAbility::GetInstance().SwitchSlice(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_MAIN_PAGE); + } + return false; +} + +void TargetSleepTime::CreateLabel() +{ + if (timerLabel == nullptr) { + timerLabel = new UILabel(); + } + timerLabel->SetPosition(TARGET_SLEEP_TIMERLABEL_X, TARGET_SLEEP_TIMERLABEL_Y); + timerLabel->Resize(TARGET_SLEEP_TIMERLABEL_WIDTH, TARGET_SLEEP_TIMERLABEL_HEIGHT); + timerLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + timerLabel->SetText("小时"); + timerLabel->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFB566FF); + timerLabel->SetTextColor(Color::Black()); + timerLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timerLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIMERLABEL_FONT); + timerLabel->SetVisible(false); + + group->Add(timerLabel); +} + +bool TargetSleepTime::OnDrag(UIView& view, const DragEvent& event) +{ + 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, "TargetSleepTime::OnDrag ChangeSlice(VIEW_APPLIST)"); + NativeAbility::GetInstance().SwitchSlice(VIEW_SLEEPING, SLEEPING_PAGES::SLEEPING_MAIN_PAGE); + } + if (view.GetViewId() == "hourPicker") { + timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, + Color::GetColorFromRGB(TARGET_SLEEP_COLOR_R, TARGET_SLEEP_COLOR_G, TARGET_SLEEP_COLOR_B).full); + timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[0]->Invalidate(); + timerPicker[1]->Invalidate(); + timerLabel->SetVisible(true); + timerLabel->SetPosition(TARGET_SLEEP_TIMERLABEL_X, TARGET_SLEEP_TIMERLABEL2_Y); + timerLabel->SetText("小时"); + timerLabel->Invalidate(); + } else if (view.GetViewId() == "minPicker") { + timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, + Color::GetColorFromRGB(TARGET_SLEEP_COLOR_R, TARGET_SLEEP_COLOR_G, TARGET_SLEEP_COLOR_B).full); + timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[0]->Invalidate(); + timerPicker[1]->Invalidate(); + timerLabel->SetVisible(true); + timerLabel->SetPosition(TARGET_SLEEP_TIMERLABEL2_X, TARGET_SLEEP_TIMERLABEL2_Y); + timerLabel->SetText("分钟"); + timerLabel->Invalidate(); + } + return true; +} + +void TargetSleepTime::OnPickerStoped(UIPicker& picker) +{ + if (picker.GetViewId() == "hourPicker") { + uint16_t hour = picker.GetSelected(); + picker.SetStyle(STYLE_BORDER_COLOR, + Color::GetColorFromRGB(TARGET_SLEEP_COLOR_R, TARGET_SLEEP_COLOR_G, TARGET_SLEEP_COLOR_B).full); + picker.Invalidate(); + if ((hour == 0) && (timerPicker[1]->GetSelected() == 0)) { + startButton->SetText(""); + startButton->Disable(); + LOADIMG::LoadBtnImage(startButton, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_START_GRAY, + IMAGE_CONVERTER_TOOL_START_GRAY); + } else { + startButton->SetText("开始"); + startButton->SetTextColor(Color::White()); + startButton->Enable(); + LOADIMG::LoadBtnImage(startButton, SLEEP_IMAGE, + IMAGE_CONVERTER_TOOL_SETTIMEBTN, IMAGE_CONVERTER_TOOL_SETTIMEBTN); + } + timerLabel->SetVisible(true); + timerLabel->SetPosition(TARGET_SLEEP_TIMERLABEL_X, TARGET_SLEEP_TIMERLABEL2_Y); + timerLabel->SetText("小时"); + timerLabel->Invalidate(); + } else { + uint16_t minute = picker.GetSelected(); + picker.SetStyle(STYLE_BORDER_COLOR, + Color::GetColorFromRGB(TARGET_SLEEP_COLOR_R, TARGET_SLEEP_COLOR_G, TARGET_SLEEP_COLOR_B).full); + picker.Invalidate(); + if ((minute == 0) && (timerPicker[0]->GetSelected() == 0)) { + startButton->SetText(""); + startButton->Disable(); + LOADIMG::LoadBtnImage(startButton, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_START_GRAY, + IMAGE_CONVERTER_TOOL_START_GRAY); + } else { + startButton->SetText("开始"); + startButton->SetTextColor(Color::White()); + startButton->Enable(); + LOADIMG::LoadBtnImage(startButton, SLEEP_IMAGE, IMAGE_CONVERTER_TOOL_SETTIMEBTN, + IMAGE_CONVERTER_TOOL_SETTIMEBTN); + } + timerLabel->SetVisible(true); + timerLabel->SetPosition(TARGET_SLEEP_TIMERLABEL2_X, TARGET_SLEEP_TIMERLABEL2_Y); + timerLabel->SetText("分钟"); + timerLabel->Invalidate(); + } +} +} + diff --git a/code/sdk/application/wearable/nativeapp/nativeui/sports/src/SportsModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/sports/src/SportsModel.cpp new file mode 100644 index 000000000..4854d19a9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/sports/src/SportsModel.cpp @@ -0,0 +1,266 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Sports Model + * Create: 2025-04-28 + */ + +#include "sports/SportsView.h" +#include "sports/SportsModel.h" +#include "samgr_lite.h" +#include "broadcast_feature.h" +#include "broadcast_service.h" +#include "wearable_log.h" +#include "heartrate/HeartModel.h" +#include "device_location.h" + +#ifdef __cplusplus +extern "C" { +#endif + +using namespace OHOS; +static sport_data_t g_sportData = {0}; +static void Notify(void *args, const Topic topic, Request *request); + +Subscriber sportsSubscirber = { + .identity = nullptr, + .args = nullptr, + .Notify = Notify, +}; + +void SportsSubscribeTopic(Topic topic) +{ +#if !defined(_WIN32) + BroadcastApi *broadcastApi = nullptr; + IUnknown *api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME); + if (api == nullptr) { + return; + } + int result = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi); + if (result != 0 || broadcastApi == nullptr) { + return; + } + int ret = broadcastApi->SubscribeTopic((IUnknown *)broadcastApi, topic, &sportsSubscirber); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportsSubscribeTopic ret = %d, topic = %u", ret, topic); + broadcastApi->Release((IUnknown *)broadcastApi); +#endif +} + +void SportsUnsubscribeTopic(Topic topic) +{ +#if !defined(_WIN32) + BroadcastApi *broadcastApi = nullptr; + IUnknown *api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME); + if (api == nullptr) { + return; + } + int result = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi); + if (result != 0 || broadcastApi == nullptr) { + return; + } + broadcastApi->UnsubscribeTopic((IUnknown *)broadcastApi, topic, &sportsSubscirber); + broadcastApi->Release((IUnknown *)broadcastApi); +#endif +} + +static void Notify(void *args, const Topic topic, Request *request) +{ + UNUSED(args); + UNUSED(topic); + if (request == nullptr) { + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "topic=[%d,%d]\n", topic, request->msgId); + SportsView *sportView = SportsView::GetInstance(); + bool active = OHOS::SportsModel::GetInstance()->IsActive(); + if (sportView != nullptr && active) { + if (request->msgId == TOPIC_EVENT_HEARTRATE_UPDATA) { + HeartDatas *sportsInfo = (HeartDatas *)request->data; + g_sportData.heartrate = sportsInfo->perSec; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "heartrate=[%d]\n", g_sportData.heartrate); + sportView->SetHeartRate(g_sportData.heartrate); + } + if (request->msgId == TOPIC_EVENT_STEPDATA_UPDATE) { + g_sportData.step += *(uint32_t *)request->data; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "step=[%d]\n", g_sportData.step); + sportView->SetStep(g_sportData.step); + } + if (request->msgId == TOPIC_EVENT_SPORT_DISTANCE) { + g_sportData.distance += *(uint32_t *)request->data; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "distance=[%d]\n", g_sportData.distance); + sportView->SetDistance(g_sportData.distance); + uint32_t speed = OHOS::SportsModel::GetInstance()->CalculateSpeed(g_sportData.distance); + g_sportData.speed = speed; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "speed=[%d]\n", g_sportData.speed); + sportView->SetSpeed(speed); + } + if (request->msgId == TOPIC_EVENT_LOCATION) { + LocationInfo_t *locationData = (LocationInfo_t *)request->data; + g_sportData.lat = locationData->latitude_; + g_sportData.lng = locationData->longitude_; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "location=[%d,%d]\n", g_sportData.lat, g_sportData.lng); + } + } +} + +#ifdef __cplusplus +} +#endif + +namespace OHOS { + +static constexpr uint16_t MS_ONE_SECONDS = 1000; +static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t NUM_TIME_MIN = 60; +static constexpr uint16_t NUM_TIME_HOUR = 3600; +static constexpr uint32_t NUM_TIME_DAY = 86400; + +SportsModel::SportsModel() +{ + InitSportsTimer(); +} + +SportsModel::~SportsModel() +{ + StopSportsTimer(true); + SportsUnsubscribeTopic(TOPIC_EVENT_HEARTRATE_UPDATA); + SportsUnsubscribeTopic(TOPIC_EVENT_STEPDATA_UPDATE); + SportsUnsubscribeTopic(TOPIC_EVENT_SPORT_DISTANCE); + SportsUnsubscribeTopic(TOPIC_EVENT_LOCATION); +} + +SportsModel *SportsModel::GetInstance(void) +{ + static SportsModel instance; + return &instance; +} + +void SportsModel::Init() +{ + SportsSubscribeTopic(TOPIC_EVENT_HEARTRATE_UPDATA); + SportsSubscribeTopic(TOPIC_EVENT_STEPDATA_UPDATE); + SportsSubscribeTopic(TOPIC_EVENT_SPORT_DISTANCE); + SportsSubscribeTopic(TOPIC_EVENT_LOCATION); +} + +std::string SportsModel::CountingSportsTime() +{ + std::string strSportTime; + std::string hours; + std::string minute; + std::string seconds; + if (uiSportTime_ >= NUM_TIME_DAY) { + uiSportTime_ = 0; + } + int hour = uiSportTime_ / NUM_TIME_HOUR; + int min = (uiSportTime_ % NUM_TIME_HOUR) / NUM_TIME_MIN; + int sec = (uiSportTime_ % NUM_TIME_HOUR) % NUM_TIME_MIN; + if (hour >= 0 && hour < NUM_TEN) { + hours = "0" + std::to_string(hour); + } else { + hours = std::to_string(hour); + } + if (min >= 0 && min < NUM_TEN) { + minute = "0" + std::to_string(min); + } else { + minute = std::to_string(min); + } + if (sec >= 0 && sec < NUM_TEN) { + seconds = "0" + std::to_string(sec); + } else { + seconds = std::to_string(sec); + } + + strSportTime = hours + ":" + minute + ":" + seconds; + return strSportTime; +} + +void SportsModel::IncrSportsTime() +{ + uiSportTime_++; +} + +/* 定时器回调函数 */ +static void SportsTimerCallback(void *data) +{ + (void)data; + SportsModel::GetInstance()->IncrSportsTime(); + SportsView *view = SportsView::GetInstance(); + if (view != nullptr) { + std::string sportTime = SportsModel::GetInstance()->CountingSportsTime(); + view->SetTime(sportTime.c_str()); + } +} + +/* 创建定时器 */ +void SportsModel::InitSportsTimer() +{ + if (pGraphicTimer_ != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportsModel::InitSportsTimer GraphicTimer already exists!!"); + return; + } + uint32_t tick = GetOSTick(MS_ONE_SECONDS); + pGraphicTimer_ = new GraphicTimer(tick, SportsTimerCallback, nullptr, true); + if (pGraphicTimer_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportsModel::InitSportsTimer new GraphicTimer failed!!"); + return; + } +} + +/* 开启定时器 */ +bool SportsModel::StartSportsTimer() +{ + if (pGraphicTimer_ != nullptr) { + bool retTimer = pGraphicTimer_->Start(); + if (!retTimer) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartSportsTimer GraphicTimer Start failed!!"); + if (pGraphicTimer_ != nullptr) { + delete pGraphicTimer_; + pGraphicTimer_ = nullptr; + } + return false; + } + isActive_ = true; + return true; + } + return false; +} + +/* 关闭定时器 */ +void SportsModel::StopSportsTimer(bool isDelete) +{ + if (pGraphicTimer_ != nullptr) { + pGraphicTimer_->Stop(); + isActive_ = false; + if (isDelete) { + delete pGraphicTimer_; + pGraphicTimer_ = nullptr; + uiSportTime_ = 0; + } + } +} + +bool SportsModel::IsActive() +{ + return isActive_; +} + +sport_data_t *SportsModel::GetSportsData() +{ + return &g_sportData; +} + +void SportsModel::ResetSportsData() +{ + uiSportTime_ = 0; + memset_s(&g_sportData, sizeof(sport_data_t), 0, sizeof(sport_data_t)); +} + +uint32_t SportsModel::CalculateSpeed(uint32_t distance) +{ + uint32_t speed_multiply100 = 0; + if (uiSportTime_ != 0) { + speed_multiply100 = (distance * NUM_TIME_HOUR) / (uiSportTime_ * NUM_TEN); + } + return speed_multiply100; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/sports/src/SportsPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/sports/src/SportsPresenter.cpp new file mode 100644 index 000000000..363bf930f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/sports/src/SportsPresenter.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SPorts Presenter + * Create: 2025-04-28 + */ + +#include "sports/SportsPresenter.h" +#include "sports/SportsView.h" +#include "sports/SportsModel.h" +#include "wearable_log.h" +#include "NativeRegisterManager.h" + +namespace OHOS { + +REGIST_SLICE(VIEW_SPORTS, SportsView, SportsPresenter); + +static SportsPresenter *g_pSportsPresenter = nullptr; + +SportsPresenter::SportsPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportsPresenter::SportsPresenter"); + g_pSportsPresenter = this; +} + +SportsPresenter::~SportsPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportsPresenter::~SportsPresenter"); + g_pSportsPresenter = nullptr; +} + +SportsPresenter *SportsPresenter::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportsPresenter GetInstance"); + return g_pSportsPresenter; +} + +bool SportsPresenter::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportsPresenter::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, "SportsPresenter::OnDrag ChangeSlice"); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } + return true; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/sports/src/SportsView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/sports/src/SportsView.cpp new file mode 100644 index 000000000..2b3b50bff --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/sports/src/SportsView.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Sports View + * Create: 2025-04-28 + */ + +#include "sports/SportsView.h" +#include "sports/SportsModel.h" +#include "sports/SportsPresenter.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "uiservice/ui_service.h" + +namespace OHOS { +static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t NUM_HUNDRED = 100; +static constexpr uint16_t NUM_THOUSAND = 1000; +static constexpr uint16_t LEFT1_X = 47; +static constexpr uint16_t LEFT1_Y = 100; +static constexpr uint16_t LEFT1_W = 180; +static constexpr uint16_t RIGHT1_X = 227; +static constexpr uint16_t RIGHT1_Y = 100; +static constexpr uint16_t RIGHT1_W = 180; +static constexpr uint16_t LEFT2_X = 47; +static constexpr uint16_t LEFT2_Y = 210; +static constexpr uint16_t LEFT2_W = 180; +static constexpr uint16_t RIGHT2_X = 227; +static constexpr uint16_t RIGHT2_Y = 210; +static constexpr uint16_t RIGHT2_W = 180; +static constexpr uint16_t BOTTOM_X = 92; +static constexpr uint16_t BOTTOM_Y = 320; +static constexpr uint16_t BOTTOM_W = 270; +static constexpr uint16_t LABLE_H = 70; +static constexpr uint16_t UNIT_LEFT1_Y = 150; +static constexpr uint16_t UNIT_RIGHT1_Y = 150; +static constexpr uint16_t UNIT_LEFT2_Y = 260; +static constexpr uint16_t UNIT_RIGHT2_Y = 260; +static constexpr uint16_t UNIT_BOTTOM_Y = 370; +static constexpr uint16_t UNIT_H = 50; +static constexpr uint16_t CONTENT_FONT = 40; +static constexpr uint16_t TITLE_FONT = 30; + +static SportsView *g_pSportsView{nullptr}; +SportsView::SportsView() +{ + ScreenTurnOn(-1); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportsView::SportsView"); + g_pSportsView = this; +} + +SportsView::~SportsView() +{ + ScreenTurnOff(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SportsView::~SportsView"); + if (group != nullptr) { + group->RemoveAll(); + } + if (backGround != nullptr) { + delete backGround; + backGround = nullptr; + } + delete group; + group = nullptr; + g_pSportsView = nullptr; +} + +SportsView *SportsView::GetInstance() +{ + return g_pSportsView; +} + +bool SportsView::InitLableView(int index, const char *text, uint16_t x, uint16_t y1, uint16_t w, uint16_t y2) +{ + if (index < SPORT_TIME || index >= SPORT_MAX) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportsView::InitLableView index param error"); + return false; + } + + ContentLabel[index].SetPosition(x, y1, w, LABLE_H); + ContentLabel[index].SetFont(DEFAULT_VECTOR_FONT_FILENAME, CONTENT_FONT); + ContentLabel[index].SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + ContentLabel[index].SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + group->Add(&ContentLabel[index]); + + TitleLabel[index].SetPosition(x, y2, w, UNIT_H); + TitleLabel[index].SetText(text); + TitleLabel[index].SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT); + TitleLabel[index].SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + TitleLabel[index].SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + group->Add(&TitleLabel[index]); + return true; +} + +void SportsView::InitSportDataLabel() +{ + ContentLabel[SPORT_TIME].SetText("00:00:00"); + ContentLabel[SPORT_SETP].SetText("0"); + ContentLabel[SPORT_DISTANCE].SetText("0.00"); + ContentLabel[SPORT_HEARTRATE].SetText("0"); + ContentLabel[SPORT_SPEED].SetText("0.00"); +} + +bool SportsView::InitView() +{ + bool ret = false; + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return false; + } + group->SetPosition(0, 0); // 0:x; 0:y + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + group->SetStyle(STYLE_BACKGROUND_OPA, 0); + group->SetDraggable(true); + group->SetTouchable(true); + + backGround = new UIImageView(); + if (backGround == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGroundFirst new fail"); + return false; + } + backGround->SetPosition(0, 0); // 0 : X; 0 : Y + backGround->SetSrc(PNG_WALK_BACK_GROUND); + group->Add(backGround); + + InitSportDataLabel(); + ret = InitLableView(SPORT_SETP, "步数", LEFT1_X, LEFT1_Y, LEFT1_W, UNIT_LEFT1_Y); + if (!ret) { + return false; + } + ret = InitLableView(SPORT_DISTANCE, "距离(km)", RIGHT1_X, RIGHT1_Y, RIGHT1_W, UNIT_RIGHT1_Y); + if (!ret) { + return false; + } + ret = InitLableView(SPORT_HEARTRATE, "心率(bpm)", LEFT2_X, LEFT2_Y, LEFT2_W, UNIT_LEFT2_Y); + if (!ret) { + return false; + } + ret = InitLableView(SPORT_SPEED, "速度(km/h)", RIGHT2_X, RIGHT2_Y, RIGHT2_W, UNIT_RIGHT2_Y); + if (!ret) { + return false; + } + ret = InitLableView(SPORT_TIME, "时间", BOTTOM_X, BOTTOM_Y, BOTTOM_W, UNIT_BOTTOM_Y); + if (!ret) { + return false; + } + UIView::OnDragListener *dragListener = static_cast(SportsPresenter::GetInstance()); + group->SetOnDragListener(dragListener); + + AddViewToRootContainer(group); + return true; +} + +void SportsView::OnStart() +{ + if (!InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SportsView::OnStart InitView fail"); + } + return; +} + +void SportsView::SetStep(uint32_t step) +{ + ContentLabel[SPORT_SETP].SetText(std::to_string(step).c_str()); + ContentLabel[SPORT_SETP].Invalidate(); +} + +void SportsView::SetHeartRate(uint16_t heartrate) +{ + ContentLabel[SPORT_HEARTRATE].SetText(std::to_string(heartrate).c_str()); + ContentLabel[SPORT_HEARTRATE].Invalidate(); +} + +void SportsView::SetDistance(uint32_t distance) +{ + std::string distance_str; + uint32_t distance_int_part = distance / NUM_THOUSAND; + uint32_t distance_fractional_part = (distance % NUM_THOUSAND) / NUM_TEN; + if (distance_fractional_part < NUM_TEN) { + distance_str = std::to_string(distance_int_part) + ".0" + std::to_string(distance_fractional_part); + } else { + distance_str = std::to_string(distance_int_part) + "." + std::to_string(distance_fractional_part); + } + ContentLabel[SPORT_DISTANCE].SetText(distance_str.c_str()); + ContentLabel[SPORT_DISTANCE].Invalidate(); +} + +void SportsView::SetSpeed(uint32_t speed) +{ + std::string speed_str; + uint32_t speed_int_part = speed / NUM_HUNDRED; + uint32_t speed_fractional_part = speed % NUM_HUNDRED; + + if (speed_fractional_part < NUM_TEN) { + speed_str = std::to_string(speed_int_part) + ".0" + std::to_string(speed_fractional_part); + } else { + speed_str = std::to_string(speed_int_part) + "." + std::to_string(speed_fractional_part); + } + + ContentLabel[SPORT_SPEED].SetText(speed_str.c_str()); + ContentLabel[SPORT_SPEED].Invalidate(); +} + +void SportsView::SetTime(const char *time) +{ + ContentLabel[SPORT_TIME].SetText(time); + ContentLabel[SPORT_TIME].Invalidate(); +} + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchAdapter.cpp new file mode 100644 index 000000000..41959502d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchAdapter.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchAdapter + * Create: 2025-06-06 + */ +#include "stopwatch/StopwatchAdapter.h" +#include "stopwatch/StopwatchItemView.h" + +namespace OHOS { +StopwatchAdapter::StopwatchAdapter() {} + +StopwatchAdapter::~StopwatchAdapter() +{ + listData_.Clear(); +} + +uint16_t StopwatchAdapter::GetCount(void) +{ + return listData_.Size(); +} + +void StopwatchAdapter::SetData(const List &data) +{ + if (!listData_.IsEmpty()) { + listData_.Clear(); + } + ListNode *node = data.Head(); + while (node != data.End()) { + listData_.PushBack(node->data_); + node = node->next_; + } +} + +UIView *StopwatchAdapter::GetView(UIView *inView, int16_t index) +{ + if (listData_.IsEmpty()) { + return nullptr; + } + if (index < 0) { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData_.Size()) { + return nullptr; + } + + ListNode *node = listData_.Head(); + for (int i = 0; i < index; i++) { + node = node->next_; + } + StopwatchItem itemData = node->data_; + StopwatchItemView *item = nullptr; + if (inView == nullptr) { + item = new StopwatchItemView(); + } else { + item = static_cast(inView); + } + size_t rindex = listData_.Size() - index; + item->SetItemInfo(rindex, itemData); + return item; +} + +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchItemView.cpp new file mode 100644 index 000000000..80c4cfe9f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchItemView.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchItemView + * Create: 2025-06-06 + */ + +#include "UiConfig.h" +#include "stopwatch/StopwatchItemView.h" +#include "common/image_cache_manager.h" +#include "ui_stopwatch_resource.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr uint16_t STOPWATCH_ITEM_WIDTH = 312; +static constexpr uint16_t STOPWATCH_ITEM_HEIGHT = 60; +static constexpr uint16_t STOPWATCH_ITEM_BG_XPOS = 6; +static constexpr uint16_t STOPWATCH_ITEM_BG_YPOS = 8; +static constexpr uint16_t STOPWATCH_ITEM_BG_WIDTH = 300; +static constexpr uint16_t STOPWATCH_ITEM_BG_HEIGHT = 44; +static constexpr uint16_t STOPWATCH_ITEM_BG_OPA = 100; +static constexpr uint16_t STOPWATCH_ITEM_NAME_LABEL_XPOS = 33; +static constexpr uint16_t STOPWATCH_ITEM_RECORD_LABEL_XPOS = 154; +static constexpr uint16_t STOPWATCH_ITEM_LABEL_YPOS = 12; +static constexpr uint16_t STOPWATCH_ITEM_NAME_LABEL_WIDTH = 100; +static constexpr uint16_t STOPWATCH_ITEM_RECORD_LABEL_WIDTH = 126; +static constexpr uint16_t STOPWATCH_ITEM_LABEL_HEIGHT = 36; +static constexpr uint16_t STOPWATCH_ITEM_FONT_SIZE = 32; +static constexpr uint32_t STOPWATCH_ITEM_FONT_COLOR = 0xffff8530; + +StopwatchItemView::StopwatchItemView() +{ + SetPosition(0, 0, STOPWATCH_ITEM_WIDTH, STOPWATCH_ITEM_HEIGHT); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + SetTouchable(true); + + itemBg_.SetPosition(STOPWATCH_ITEM_BG_XPOS, STOPWATCH_ITEM_BG_YPOS); + itemBg_.Resize(STOPWATCH_ITEM_BG_WIDTH, STOPWATCH_ITEM_BG_HEIGHT); + itemBg_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + itemBg_.SetStyle(STYLE_BACKGROUND_OPA, STOPWATCH_ITEM_BG_OPA); + itemBg_.SetTouchable(false); + + nameLabel_.SetPosition(STOPWATCH_ITEM_NAME_LABEL_XPOS, STOPWATCH_ITEM_LABEL_YPOS); + nameLabel_.Resize(STOPWATCH_ITEM_NAME_LABEL_WIDTH, STOPWATCH_ITEM_LABEL_HEIGHT); + nameLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, STOPWATCH_ITEM_FONT_SIZE); + nameLabel_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + nameLabel_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + nameLabel_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + recordLabel_.SetPosition(STOPWATCH_ITEM_RECORD_LABEL_XPOS, STOPWATCH_ITEM_LABEL_YPOS); + recordLabel_.Resize(STOPWATCH_ITEM_RECORD_LABEL_WIDTH, STOPWATCH_ITEM_LABEL_HEIGHT); + recordLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, STOPWATCH_ITEM_FONT_SIZE); + recordLabel_.SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + recordLabel_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + recordLabel_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + Add(&itemBg_); + Add(&nameLabel_); + Add(&recordLabel_); +} + +StopwatchItemView::~StopwatchItemView() +{ + Remove(&nameLabel_); + Remove(&recordLabel_); + Remove(&itemBg_); +} + +void StopwatchItemView::SetItemInfo(int16_t index, const StopwatchItem &itemInfo) +{ + nameLabel_.SetText(("分段" + std::to_string(index)).c_str()); + recordLabel_.SetText(itemInfo.record.c_str()); + if (itemInfo.isLatest) { + nameLabel_.SetStyle(STYLE_TEXT_COLOR, STOPWATCH_ITEM_FONT_COLOR); + recordLabel_.SetStyle(STYLE_TEXT_COLOR, STOPWATCH_ITEM_FONT_COLOR); + } else { + nameLabel_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + recordLabel_.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchModel.cpp new file mode 100644 index 000000000..d73b785bc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchModel.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchModel + * Create: 2025-06-06 + */ +#include +#include "stopwatch/StopwatchModel.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr uint16_t UNIT_SEC_TO_MSEC = 1000; +StopwatchModel::StopwatchModel() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchModel::StopwatchModel"); +} + +StopwatchModel::~StopwatchModel() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchModel::~StopwatchModel"); +} + +StopwatchModel &StopwatchModel::GetInstance() +{ + static StopwatchModel instance; + return instance; +} + +void StopwatchModel::SetStartTime() +{ +#ifdef _WIN32 + gettimeofday(&startTime_, NULL); +#else + gettimeofday64(&startTime_, NULL); +#endif +} + +void StopwatchModel::SaveElapsedTime() +{ + uiSavedElapsedTime_ += uiElapsedTime_; + uiElapsedTime_ = 0; +} + +uint64_t StopwatchModel::GetElapsedTime() +{ + return uiSavedElapsedTime_ + uiElapsedTime_; +} + +uint64_t StopwatchModel::UpdateElapsedTime() +{ +#ifdef _WIN32 + struct timeval currTime = {0}; + gettimeofday(&currTime, NULL); +#else + struct timeval64 currTime = {0}; + gettimeofday64(&currTime, NULL); +#endif + uiElapsedTime_ = (currTime.tv_sec * UNIT_SEC_TO_MSEC + currTime.tv_usec / UNIT_SEC_TO_MSEC) - + (startTime_.tv_sec * UNIT_SEC_TO_MSEC + startTime_.tv_usec / UNIT_SEC_TO_MSEC); + return uiSavedElapsedTime_ + uiElapsedTime_; +} + +void StopwatchModel::ResetCounter() +{ + uiElapsedTime_ = 0; + uiSavedElapsedTime_ = 0; + records_.Clear(); +} + +bool StopwatchModel::GetActiveState() +{ + return bIsActive_; +} + +void StopwatchModel::SetActiveState() +{ + bIsActive_ = true; +} + +void StopwatchModel::SetInactiveState() +{ + bIsActive_ = false; +} + +List &StopwatchModel::GetRecordsList() +{ + return records_; +} + +void StopwatchModel::AddRecordToList(const StopwatchItem &record) +{ + ListNode *node = records_.Head(); + while (node != records_.End()) { + StopwatchItem &itemData = node->data_; + itemData.isLatest = false; + node = node->next_; + } + records_.PushFront(record); +} + +bool StopwatchModel::IsInRecordView() +{ + return bIsRecordView_; +} + +void StopwatchModel::SetRecordViewState(bool state) +{ + bIsRecordView_ = state; +} + +void StopwatchModel::ClearData() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchModel::ClearData start"); + uiElapsedTime_ = 0; + uiSavedElapsedTime_ = 0; + bIsActive_ = false; + bIsRecordView_ = false; + startTime_ = {0}; + records_.Clear(); +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchPage.cpp new file mode 100644 index 000000000..0652df389 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchPage.cpp @@ -0,0 +1,588 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchPage + * Create: 2025-06-06 + */ + +#include +#include +#include "stopwatch/StopwatchPage.h" +#include "stopwatch/StopwatchView.h" +#include "stopwatch/StopwatchPresenter.h" +#include "stopwatch/StopwatchModel.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "NativeRegisterManager.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "ui_stopwatch_resource.h" +#include "main/LoadImg.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif + +namespace OHOS { +static constexpr char *STOPWATCH_START = "stopwatch_start"; +static constexpr char *STOPWATCH_RESET = "stopwatch_reset"; +static constexpr uint16_t OFFSET = 4; +static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t UNIT_SEC_TO_MSEC = 1000; +static constexpr uint16_t UNIT_SECS_PER_MIN = 60; +static constexpr uint16_t UNIT_SECS_PER_HOUR = 3600; +static constexpr uint16_t MAX_RECORD_SIZE = 20; +static constexpr uint16_t STOPWATCH_CONTAINER_XPOS = 0; +static constexpr uint16_t STOPWATCH_CONTAINER_YPOS = 0; +static constexpr uint16_t STOPWATCH_HAND_POSITION_XPOS = 224; +static constexpr uint16_t STOPWATCH_HAND_POSITION_YPOS = 4; +static constexpr uint16_t STOPWATCH_HAND_CENTER_XPOS = 3; +static constexpr uint16_t STOPWATCH_HAND_CENTER_YPOS = 223; +static constexpr uint16_t STOPWATCH_HAND_WIDTH = 2; +static constexpr uint16_t STOPWATCH_HAND_HEIGHT = 5; +static constexpr uint16_t STOPWATCH_LABEL_CURTIME_XPOS = 199; +static constexpr uint16_t STOPWATCH_LABEL_CURTIME_YPOS = 54; +static constexpr uint16_t STOPWATCH_LABEL_CURTIME_WIDTH = 67; +static constexpr uint16_t STOPWATCH_LABEL_CURTIME_HEIGHT = 24; +static constexpr uint16_t STOPWATCH_LABEL_CURTIME_FONT_SIZE = 24; +static constexpr uint16_t STOPWATCH_LABEL_APPNAME_XPOS = 197; +static constexpr uint16_t STOPWATCH_LABEL_APPNAME_YPOS = 82; +static constexpr uint16_t STOPWATCH_LABEL_APPNAME_WIDTH = 64; +static constexpr uint16_t STOPWATCH_LABEL_APPNAME_HEIGHT = 38; +static constexpr uint16_t STOPWATCH_LABEL_APPNAME_FONT_SIZE = 32; +static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_XPOS = 87; +static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_YPOS1 = 176; +static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_YPOS2 = 82; +static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_WIDTH = 302; +static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_HEIGHT = 90; +static constexpr uint16_t STOPWATCH_LABEL_ELSTIME_FONT_SIZE = 72; +static constexpr uint16_t STOPWATCH_BUTTON_SRART_XPOS = 250; +static constexpr uint16_t STOPWATCH_BUTTON_SRART_YPOS = 302; +static constexpr uint16_t STOPWATCH_BUTTON_PAUSE_XPOS = 110; +static constexpr uint16_t STOPWATCH_BUTTON_PAUSE_YPOS = 302; +static constexpr uint16_t STOPWATCH_BUTTON_WIDTH = 96; +static constexpr uint16_t STOPWATCH_BUTTON_HEIGHT = 96; +static constexpr uint16_t STOPWATCH_LIST_RECORD_XPOS = 73; +static constexpr uint16_t STOPWATCH_LIST_RECORD_YPOS = 170; +static constexpr uint16_t STOPWATCH_LIST_RECORD_WIDTH = 312; +static constexpr uint16_t STOPWATCH_LIST_RECORD_HEIGHT = 122; +static constexpr uint16_t STOPWATCH_LABEL_REBOUND_SIZE = 60; + +REGIST_SLICE_PAGE(VIEW_STOPWATCH, STOPWATCH_PAGES::STOPWATCH_MAIN_PAGE, StopwatchPage, true); + +static std::string GetCurrentTimeStr() +{ + struct tm localTime; + time_t seconds = time(nullptr); + localtime_r(&seconds, &localTime); + std::string currTime; + if (localTime.tm_hour < NUM_TEN) { + currTime += "0"; + } + currTime += std::to_string(localTime.tm_hour) + ":"; + if (localTime.tm_min < NUM_TEN) { + currTime += "0"; + } + currTime += std::to_string(localTime.tm_min); + return currTime; +} + +static uint64_t GetMilliSeconds(uint64_t uiElapsedTime) +{ + return (uiElapsedTime % (UNIT_SECS_PER_HOUR * UNIT_SEC_TO_MSEC)) % (UNIT_SECS_PER_MIN * UNIT_SEC_TO_MSEC); +} + +static std::string FormatElapsedTime(uint64_t uiElapsedTime) +{ + std::string strElapsedTime; + std::string hours; + std::string minute; + std::string seconds; + std::string centisecs; + uint64_t hour = uiElapsedTime / (UNIT_SECS_PER_HOUR * UNIT_SEC_TO_MSEC); + uiElapsedTime %= (UNIT_SECS_PER_HOUR * UNIT_SEC_TO_MSEC); + uint64_t min = uiElapsedTime / (UNIT_SECS_PER_MIN * UNIT_SEC_TO_MSEC); + uiElapsedTime %= (UNIT_SECS_PER_MIN * UNIT_SEC_TO_MSEC); + uint64_t sec = uiElapsedTime / UNIT_SEC_TO_MSEC; + uiElapsedTime %= UNIT_SEC_TO_MSEC; + uint64_t csec = uiElapsedTime / NUM_TEN; + if (hour >= 0 && hour < NUM_TEN) { + hours = "0" + std::to_string(hour); + } else { + hours = std::to_string(hour); + } + if (min >= 0 && min < NUM_TEN) { + minute = "0" + std::to_string(min); + } else { + minute = std::to_string(min); + } + if (sec >= 0 && sec < NUM_TEN) { + seconds = "0" + std::to_string(sec); + } else { + seconds = std::to_string(sec); + } + if (csec >= 0 && csec < NUM_TEN) { + centisecs = "0" + std::to_string(csec); + } else { + centisecs = std::to_string(csec); + } + strElapsedTime = minute + ":" + seconds + "." + centisecs; + return strElapsedTime; +} + +void StopwatchPage::StopwatchAnimatorCallback::Callback(UIView *view) +{ + UNUSED(view); + uint64_t uiElapsedTime = StopwatchModel::GetInstance().UpdateElapsedTime(); + uint64_t millisecs = GetMilliSeconds(uiElapsedTime); + stopwatchPage->GetSweepClock()->SetSweepTime24Hour(0, 0, millisecs); + stopwatchPage->GetSweepClock()->Invalidate(); + std::string strElapsedTime = FormatElapsedTime(uiElapsedTime); + stopwatchPage->GetElapsedTimeLabel()->SetText(strElapsedTime.c_str()); + if (uiElapsedTime >= UNIT_SECS_PER_HOUR * UNIT_SEC_TO_MSEC) { + stopwatchPage->Overflowing(); + } +} + +void StopwatchPage::TimeAnimatorCallback::Callback(UIView *view) +{ + UILabel *timeLabel = dynamic_cast(view); + if (timeLabel == nullptr) { + return; + } + std::string currTime = GetCurrentTimeStr(); + timeLabel->SetText(currTime.c_str()); + timeLabel->Invalidate(); +} + +StopwatchPage::StopwatchPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPage::StopwatchPage"); +} + +StopwatchPage::~StopwatchPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPage::~StopwatchPage"); + bool ret = ImageCacheManager::GetInstance().UnloadAllInMultiRes(PNG_APPLIST_STOPWATCH_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnloadStopwatchImage fail"); + } + if (sweepClock_ != nullptr) { + sweepClock_->RemoveAll(); + delete sweepClock_; + sweepClock_ = nullptr; + } + if (currentTime_ != nullptr) { + delete currentTime_; + currentTime_ = nullptr; + } + if (appName_ != nullptr) { + delete appName_; + appName_ = nullptr; + } + if (elapsedTime_ != nullptr) { + delete elapsedTime_; + elapsedTime_ = nullptr; + } + if (startButton_ != nullptr) { + delete startButton_; + startButton_ = nullptr; + } + if (resetButton_ != nullptr) { + delete resetButton_; + resetButton_ = nullptr; + } + if (recordsList_ != nullptr) { + delete recordsList_; + recordsList_ = nullptr; + } + if (listAdapter_ != nullptr) { + delete listAdapter_; + listAdapter_ = nullptr; + } + if (backGround_ != nullptr) { + delete backGround_; + backGround_ = nullptr; + } + if (imgScale_ != nullptr) { + delete imgScale_; + imgScale_ = nullptr; + } + if (secondHand_ != nullptr) { + delete secondHand_; + secondHand_ = nullptr; + } + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + if (animatorCallback_ != nullptr) { + delete animatorCallback_; + animatorCallback_ = nullptr; + } + if (timeAnimator_ != nullptr) { + delete timeAnimator_; + timeAnimator_ = nullptr; + } + if (timeCallback_ != nullptr) { + delete timeCallback_; + timeCallback_ = nullptr; + } +} + +void StopwatchPage::OnStart(void *data) +{ + bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(PNG_APPLIST_STOPWATCH_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadStopwatchImage fail"); + return; + } + + sweepClock_ = new UISweepClock(); + if (sweepClock_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UISweepClock new fail"); + return; + } + sweepClock_->SetPosition(STOPWATCH_CONTAINER_XPOS, STOPWATCH_CONTAINER_YPOS); + sweepClock_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + sweepClock_->SetDraggable(true); + sweepClock_->SetTouchable(true); + + secondHand_ = new Image(); + if (secondHand_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "secondHand new fail"); + return; + } + ImageInfo *second = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_STOPWATCH_STOPWATCH02, PNG_APPLIST_STOPWATCH_IMAGE); + + if (second == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::OnStart source fail"); + return; + } + secondHand_->SetSrc(second); + sweepClock_->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand_, + {STOPWATCH_HAND_POSITION_XPOS, STOPWATCH_HAND_POSITION_YPOS}, + {STOPWATCH_HAND_CENTER_XPOS, STOPWATCH_HAND_CENTER_YPOS}); + sweepClock_->SetHandLine(UISweepClock::HandType::HOUR_HAND, + {STOPWATCH_HAND_POSITION_XPOS, STOPWATCH_HAND_POSITION_YPOS}, + {STOPWATCH_HAND_CENTER_XPOS, STOPWATCH_HAND_CENTER_YPOS}, Color::White(), + STOPWATCH_HAND_WIDTH, STOPWATCH_HAND_HEIGHT, OPA_TRANSPARENT); + sweepClock_->SetHandLine(UISweepClock::HandType::MINUTE_HAND, + {STOPWATCH_HAND_POSITION_XPOS, STOPWATCH_HAND_POSITION_YPOS}, + {STOPWATCH_HAND_CENTER_XPOS, STOPWATCH_HAND_CENTER_YPOS}, Color::White(), + STOPWATCH_HAND_WIDTH, STOPWATCH_HAND_HEIGHT, OPA_TRANSPARENT); + + sweepClock_->SetWorkMode(UISweepClock::WorkMode::NORMAL); + uint64_t uiElapsedTime = StopwatchModel::GetInstance().GetElapsedTime(); + uint64_t millisecs = GetMilliSeconds(uiElapsedTime); + sweepClock_->SetSweepTime24Hour(0, 0, millisecs); + + backGround_ = new UIImageView(); + if (backGround_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGroundFirst new fail"); + return; + } + backGround_->SetPosition(0, 0); + LOADIMG::LoadImageViewImg(backGround_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH06); + sweepClock_->Add(backGround_); + + imgScale_ = new UIImageView(); + if (imgScale_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGroundFirst new fail"); + return; + } + imgScale_->SetPosition(OFFSET, OFFSET); + LOADIMG::LoadImageViewImg(imgScale_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH04); + sweepClock_->Add(imgScale_); + + currentTime_ = new UILabel(); + if (currentTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupCurrentTime new Label currentTime_ fail"); + return; + } + currentTime_->SetPosition(STOPWATCH_LABEL_CURTIME_XPOS, STOPWATCH_LABEL_CURTIME_YPOS); + currentTime_->Resize(STOPWATCH_LABEL_CURTIME_WIDTH, STOPWATCH_LABEL_CURTIME_HEIGHT); + currentTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, STOPWATCH_LABEL_CURTIME_FONT_SIZE); + currentTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + currentTime_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + currentTime_->SetVisible(true); + sweepClock_->Add(currentTime_); + + appName_ = new UILabel(); + if (appName_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupAppName new Label appName_ fail"); + return; + } + appName_->SetPosition(STOPWATCH_LABEL_APPNAME_XPOS, STOPWATCH_LABEL_APPNAME_YPOS); + appName_->Resize(STOPWATCH_LABEL_APPNAME_WIDTH, STOPWATCH_LABEL_APPNAME_HEIGHT); + appName_->SetText(STOPWATCH_APP_NAME); + appName_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + appName_->SetTextColor(Color::White()); + appName_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, STOPWATCH_LABEL_APPNAME_FONT_SIZE); + appName_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + appName_->SetVisible(true); + sweepClock_->Add(appName_); + + elapsedTime_ = new UILabel(); + if (elapsedTime_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupElapsedTime new Label elapsedTime_ fail"); + return; + } + elapsedTime_->SetPosition(STOPWATCH_LABEL_ELSTIME_XPOS, STOPWATCH_LABEL_ELSTIME_YPOS1); + elapsedTime_->Resize(STOPWATCH_LABEL_ELSTIME_WIDTH, STOPWATCH_LABEL_ELSTIME_HEIGHT); + elapsedTime_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + elapsedTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, STOPWATCH_LABEL_ELSTIME_FONT_SIZE); + elapsedTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + elapsedTime_->SetVisible(true); + std::string strElapsedTime = FormatElapsedTime(uiElapsedTime); + elapsedTime_->SetText(strElapsedTime.c_str()); + sweepClock_->Add(elapsedTime_); + + startButton_ = new UILabelButton(); + if (startButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupButton new UILabelButton startButton_ fail"); + return; + } + startButton_->SetPosition(STOPWATCH_BUTTON_SRART_XPOS, STOPWATCH_BUTTON_SRART_YPOS); + startButton_->Resize(STOPWATCH_BUTTON_WIDTH, STOPWATCH_BUTTON_HEIGHT); + startButton_->SetViewId(STOPWATCH_START); + startButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + startButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + startButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + startButton_->SetOnClickListener(this); + sweepClock_->Add(startButton_); + + resetButton_ = new UILabelButton(); + if (resetButton_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupButton new UILabelButton resetButton_ fail"); + return; + } + resetButton_->SetPosition(STOPWATCH_BUTTON_PAUSE_XPOS, STOPWATCH_BUTTON_PAUSE_YPOS); + resetButton_->Resize(STOPWATCH_BUTTON_WIDTH, STOPWATCH_BUTTON_HEIGHT); + resetButton_->SetViewId(STOPWATCH_RESET); + resetButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + resetButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + resetButton_->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + resetButton_->SetOnClickListener(this); + sweepClock_->Add(resetButton_); + + listAdapter_ = new StopwatchAdapter(); + if (listAdapter_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "StopwatchPage::SetupRecordsList new StopwatchAdapter listAdapter_ fail"); + return; + } + recordsList_ = new UIList(); + if (recordsList_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::SetupRecordsList new UIList recordsList_ fail"); + return; + } + recordsList_->SetPosition(STOPWATCH_LIST_RECORD_XPOS, STOPWATCH_LIST_RECORD_YPOS); + recordsList_->Resize(STOPWATCH_LIST_RECORD_WIDTH, STOPWATCH_LIST_RECORD_HEIGHT); + recordsList_->SetThrowDrag(true); + recordsList_->SetDraggable(true); + recordsList_->SetReboundSize(STOPWATCH_LABEL_REBOUND_SIZE); + recordsList_->EnableAutoAlign(true); + recordsList_->SetElastic(true); + recordsList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + recordsList_->SetAdapter(listAdapter_); + recordsList_->SetVisible(false); + sweepClock_->Add(recordsList_); + + animatorCallback_ = new StopwatchAnimatorCallback(this); + if (animatorCallback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack new fail\n"); + return; + } + + animator_ = new Animator(animatorCallback_, nullptr, 0, true); + if (animator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::InitView new Animator animator_ fail"); + return; + } + + timeCallback_ = new TimeAnimatorCallback(); + if (timeCallback_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack new fail\n"); + return; + } + + timeAnimator_ = new Animator(timeCallback_, currentTime_, 0, true); + if (timeAnimator_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopwatchPage::InitView new Animator timeAnimator_ fail"); + return; + } + timeAnimator_->Start(); + + sweepClock_->SetOnDragListener(this); + AddViewToPageContainer(sweepClock_); + + bool isActive = StopwatchModel::GetInstance().GetActiveState(); + DrawButtonStatusView(isActive); + bool state = StopwatchModel::GetInstance().IsInRecordView(); + if (StopwatchModel::GetInstance().GetOverflowState()) { + state = false; + } + DrawContainRecordListView(state); +} + +void StopwatchPage::OnStop() {} + +void StopwatchPage::OnPause() +{ + if (animator_ != nullptr) { + if (animator_->GetState() != Animator::STOP) { + animator_->Stop(); + } + } + if (timeAnimator_ != nullptr) { + if (timeAnimator_->GetState() != Animator::STOP) { + timeAnimator_->Stop(); + } + } +} + +void StopwatchPage::OnResume() +{ + if (animator_ != nullptr) { + bool isActive = StopwatchModel::GetInstance().GetActiveState(); + if (isActive && animator_->GetState() == Animator::STOP) { + animator_->Start(); + } + } + if (timeAnimator_ != nullptr) { + if (timeAnimator_->GetState() == Animator::STOP) { + timeAnimator_->Start(); + } + } +} + +void StopwatchPage::DrawButtonStatusView(bool isActive) +{ + if (isActive) { + LOADIMG::LoadBtnImage(startButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH08, + IMAGE_STOPWATCH_STOPWATCH08); + startButton_->Invalidate(); + + resetButton_->Enable(); + LOADIMG::LoadBtnImage(resetButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH14, + IMAGE_STOPWATCH_STOPWATCH14); + auto &recordList = StopwatchModel::GetInstance().GetRecordsList(); + if (recordList.Size() >= MAX_RECORD_SIZE) { + resetButton_->Disable(); + LOADIMG::LoadBtnImage(resetButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH20, + IMAGE_STOPWATCH_STOPWATCH20); + } + resetButton_->Invalidate(); + } else { + LOADIMG::LoadBtnImage(startButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH12, + IMAGE_STOPWATCH_STOPWATCH12); + startButton_->Invalidate(); + + resetButton_->Enable(); + // 复位 + LOADIMG::LoadBtnImage(resetButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH19, + IMAGE_STOPWATCH_STOPWATCH19); + uint64_t elapsedTime = StopwatchModel::GetInstance().GetElapsedTime(); + if (elapsedTime == 0) { + resetButton_->Disable(); + LOADIMG::LoadBtnImage(resetButton_, PNG_APPLIST_STOPWATCH_IMAGE, IMAGE_STOPWATCH_STOPWATCH10, + IMAGE_STOPWATCH_STOPWATCH10); + } + resetButton_->Invalidate(); + } +} + +void StopwatchPage::DrawContainRecordListView(bool isContainRecordList) +{ + if (isContainRecordList) { + appName_->SetVisible(false); + recordsList_->SetVisible(true); + elapsedTime_->SetPosition(STOPWATCH_LABEL_ELSTIME_XPOS, STOPWATCH_LABEL_ELSTIME_YPOS2); + } else { + appName_->SetVisible(true); + recordsList_->SetVisible(false); + elapsedTime_->SetPosition(STOPWATCH_LABEL_ELSTIME_XPOS, STOPWATCH_LABEL_ELSTIME_YPOS1); + } + RefreshRecordsList(); +} + +void StopwatchPage::RefreshRecordsList() +{ + auto &records = StopwatchModel::GetInstance().GetRecordsList(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPage::RefreshRecordsList"); + listAdapter_->SetData(records); + recordsList_->RefreshList(); +} + +bool StopwatchPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + bool isActive = StopwatchModel::GetInstance().GetActiveState(); + if (strcmp(view.GetViewId(), STOPWATCH_START) == 0) { + if (isActive) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPresenter::OnClick activeState = %d, pause counting click", + isActive); + StopwatchModel::GetInstance().SetInactiveState(); + DrawButtonStatusView(false); + animator_->Stop(); + StopwatchModel::GetInstance().SaveElapsedTime(); + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPresenter::OnClick activeState = %d, start counting click", + isActive); + StopwatchModel::GetInstance().SetActiveState(); + if (StopwatchModel::GetInstance().GetOverflowState()) { + DrawContainRecordListView(false); + StopwatchModel::GetInstance().SetOverflowState(false); + } + DrawButtonStatusView(true); + StopwatchModel::GetInstance().SetStartTime(); + animator_->Start(); + } + } else if (strcmp(view.GetViewId(), STOPWATCH_RESET) == 0) { + if (isActive) { + StopwatchModel::GetInstance().SetRecordViewState(true); + uint64_t uiElapsedTime = StopwatchModel::GetInstance().GetElapsedTime(); + std::string strElapsedTime = FormatElapsedTime(uiElapsedTime); + StopwatchItem item = {strElapsedTime, true}; + StopwatchModel::GetInstance().AddRecordToList(item); + DrawContainRecordListView(true); + DrawButtonStatusView(true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPresenter::OnClick save a record"); + } else { + StopwatchModel::GetInstance().SetRecordViewState(false); + StopwatchModel::GetInstance().ResetCounter(); + elapsedTime_->SetText("00:00.00"); + sweepClock_->SetInitTime24Hour(0, 0, 0); + sweepClock_->Invalidate(); + DrawContainRecordListView(false); + DrawButtonStatusView(false); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchPresenter::OnClick reset a record"); + } + } + return true; +} + +bool StopwatchPage::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopwatchOnDragListener::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, "StopwatchOnDragListener::OnDrag ChangeSlice(VIEW_APPLIST)"); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + return true; +} + +void StopwatchPage::Overflowing() +{ + animator_->Stop(); + elapsedTime_->SetText("59:59.99"); + sweepClock_->SetSweepTime24Hour(0, 0, 0); + sweepClock_->Invalidate(); + StopwatchModel::GetInstance().SetInactiveState(); + DrawButtonStatusView(false); + StopwatchModel::GetInstance().ResetCounter(); + StopwatchModel::GetInstance().SetOverflowState(true); +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchPresenter.cpp new file mode 100644 index 000000000..90fcfe210 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopwatchPresenter.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: StopwatchPresenter + * Create: 2025-06-06 + */ +#include "stopwatch/StopwatchView.h" +#include "stopwatch/StopwatchPresenter.h" +#include "NativeRegisterManager.h" + +namespace OHOS { + +REGIST_MENU(VIEW_STOPWATCH, StopwatchView, StopwatchPresenter, PNG_APPLIST_STOPWATCH_LOGO, PNG_APPLIST_DEFAULT_IMG, + "秒表"); +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempClickMea.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempClickMea.cpp index f56dc3a88..45982b555 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempClickMea.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempClickMea.cpp @@ -8,7 +8,7 @@ #include "UiConfig.h" #include #include "font/ui_font.h" -#include "TempClickMea.h" +#include "temperature/TempClickMea.h" namespace OHOS { static TempClickMea *g_tempClickMea = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempContinueWarn.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempContinueWarn.cpp index 25acea9cd..e8f599deb 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempContinueWarn.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempContinueWarn.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "TempContinueWarn.h" +#include "temperature/TempContinueWarn.h" namespace OHOS { static TempContinueWarn *g_tempContinueWarn = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempExitInter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempExitInter.cpp index b2538b033..215e46833 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempExitInter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempExitInter.cpp @@ -9,7 +9,7 @@ #include "layout/grid_layout.h" #include "font/ui_font.h" #include -#include "TempExitInter.h" +#include "temperature/TempExitInter.h" namespace OHOS { static TempExitInter *g_tempExitInter = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempExitPrompt.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempExitPrompt.cpp index 34359aa4c..d4155fcb3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempExitPrompt.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempExitPrompt.cpp @@ -8,7 +8,7 @@ #include "UiConfig.h" #include "layout/grid_layout.h" #include -#include "TempExitPrompt.h" +#include "temperature/TempExitPrompt.h" namespace OHOS { static TempExitPrompt *g_tempExitPrompt = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempInitInter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempInitInter.cpp index dc00359c4..da8a03ad0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempInitInter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempInitInter.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "TempInitInter.h" +#include "temperature/TempInitInter.h" namespace OHOS { static TempInitInter *g_tempInitInter = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempJoinStudy.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempJoinStudy.cpp index bf089b5a1..22153997b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempJoinStudy.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempJoinStudy.cpp @@ -8,7 +8,7 @@ #include "UiConfig.h" #include "layout/grid_layout.h" #include -#include "TempJoinStudy.h" +#include "temperature/TempJoinStudy.h" namespace OHOS { static TempJoinStudy *g_tempJoinStudy = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempLittleTip.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempLittleTip.cpp index 8c6c01873..5f4d4fa94 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempLittleTip.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempLittleTip.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "TempLittleTip.h" +#include "temperature/TempLittleTip.h" namespace OHOS { static TempLittleTip *g_tempJoinStudy = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMainView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMainView.cpp index 5c533c7d2..10cbbae6f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMainView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMainView.cpp @@ -5,10 +5,10 @@ * Create: 2022-02-15 */ -#include "TempMainView.h" +#include "temperature/TempMainView.h" #include "UiConfig.h" -#include "TempMeaProcess.h" -#include "TempWarn.h" +#include "temperature/TempMeaProcess.h" +#include "temperature/TempWarn.h" namespace OHOS { static TempMainView *g_tempMainView = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMeaProcess.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMeaProcess.cpp index 76918d105..7a8fa1d8c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMeaProcess.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMeaProcess.cpp @@ -7,8 +7,8 @@ #include "UiConfig.h" #include -#include "TempMeaProcess.h" -#include "TempMainView.h" +#include "temperature/TempMeaProcess.h" +#include "temperature/TempMainView.h" namespace OHOS { static TempMeaProcess *g_tempMeaProcess = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMeasure.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMeasure.cpp index a3c01d99d..2ea184b71 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMeasure.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempMeasure.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "TempMeasure.h" +#include "temperature/TempMeasure.h" namespace OHOS { static TempMeasure *g_tempMeasure = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempModel.cpp index b52c38cfd..2078ffda7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempModel.cpp @@ -5,9 +5,9 @@ * Create: 2022-02-15 */ -#include "TempModel.h" +#include "temperature/TempModel.h" #include "UiConfig.h" -#include "TempModel.h" +#include "temperature/TempModel.h" namespace OHOS { TempModel::TempModel() 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 b1b9fc6dd..9b9a81898 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPresenter.cpp @@ -5,11 +5,11 @@ * Create: 2022-02-15 */ -#include "TempPresenter.h" -#include "TempMainView.h" +#include "temperature/TempPresenter.h" +#include "temperature/TempMainView.h" #include "ChangeSliceListener.h" #include "graphic_service.h" -#include "ui_service.h" +#include "uiservice/ui_service.h" #include "string" #include "iostream" #include "sstream" @@ -45,7 +45,6 @@ TempPresenter *TempPresenter::GetInstance() void TempPresenter::OnResume(void) { - Presenter::OnResume(); SendMsgToUIService(UI_ADD_SLEEP_VETO, 0, nullptr, 0); } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPromptWear.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPromptWear.cpp index 47ec2b05c..856e77275 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPromptWear.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempPromptWear.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "TempPromptWear.h" +#include "temperature/TempPromptWear.h" namespace OHOS { static TempPromptWear *g_tempPromptWear = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempRemindWear.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempRemindWear.cpp index a6ffbf5c9..b44a8289c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempRemindWear.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempRemindWear.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "TempRemindWear.h" +#include "temperature/TempRemindWear.h" namespace OHOS { static TempRemindWear *g_tempRemindWear = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempReport.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempReport.cpp index 46cf911c3..2f7166d3c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempReport.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempReport.cpp @@ -9,7 +9,7 @@ #include "layout/grid_layout.h" #include "font/ui_font.h" #include -#include "TempReport.h" +#include "temperature/TempReport.h" namespace OHOS { static TempReport *g_tempReport = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempStudyAbout.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempStudyAbout.cpp index 8db30bd09..b1fe71b1a 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempStudyAbout.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempStudyAbout.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "TempStudyAbout.h" +#include "temperature/TempStudyAbout.h" namespace OHOS { static TempStudyAbout *g_tempStudyAbout = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempWarn.cpp b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempWarn.cpp index 8df8eb975..879fd41c3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempWarn.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/temperature/src/TempWarn.cpp @@ -7,7 +7,7 @@ #include "UiConfig.h" #include -#include "TempWarn.h" +#include "temperature/TempWarn.h" namespace OHOS { static TempWarn *g_tempWarn = nullptr; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerMainPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerMainPage.cpp new file mode 100644 index 000000000..35f8c4b99 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerMainPage.cpp @@ -0,0 +1,199 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerMainPage + * Create: 2025-06-09 + */ + +#include +#include "timers/TimerMainPage.h" +#include "timers/TimerSettingPage.h" +#include "timers/TimerTimingPage.h" +#include "timers/TimerPresenter.h" +#include "SlicePageFactory.h" +#include "timers/TimerView.h" +#include "components/ui_scroll_view_nested.h" +#include "components/ui_arc_label.h" +#include "graphic_timer.h" +#include "ohos_timer.h" +#include "wearable_log.h" +#include "main/LoadImg.h" + +namespace OHOS { +static constexpr int16_t ADDBUTTON_MAX = 4; +static constexpr uint8_t MAIN_TITLE_FONT_SIZE = 40; +static constexpr int16_t MAIN_TITLE_SIZE_WIDTH = 160; +static constexpr int16_t MAIN_TITLE_SIZE_HEIGHT = 50; +static constexpr int16_t MAIN_TITLE_POSITION_X = 150; +static constexpr int16_t MAIN_TITLE_POSITION_Y = 20; +static constexpr int16_t MAIN_ADDBUTTON_POSITION_X = 111; +static constexpr int16_t MAIN_ADDBUTTON_POSITION_Y = 347; +static constexpr int16_t MAIN_ADDBUTTON_SIZE_WIDTH = 232; +static constexpr int16_t MAIN_ADDBUTTON_SIZE_HEIGHT = 76; +static constexpr int16_t SELECTMIN_POX = 86; +static constexpr int16_t SELECTMIN_POXS = 252; +static constexpr int16_t SELECTMIN_POY = 89; +static constexpr int16_t SELECTMIN_POYS = 220; +static constexpr int16_t SELECTMIN_SIZE = 100; +static constexpr int16_t MAX_SCR_DIS = 1000; +static constexpr uint8_t MIN = 60; + +REGIST_SLICE_PAGE(VIEW_TIMER, TIMER_PAGES::TIMER_MAIN_PAGE, TimerMainPage, true); + +TimerMainPage::~TimerMainPage() +{ + bool ret = ImageCacheManager::GetInstance().UnloadAllInMultiRes(TIMER_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnloadTimerImage fail"); + } + + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (title != nullptr) { + delete title; + title = nullptr; + } + + if (addButton != nullptr) { + delete addButton; + addButton = nullptr; + } + + for (int i = 0; i < ADDBUTTON_MAX; i++) { + if (selectMin[i] != nullptr) { + delete selectMin[i]; + selectMin[i] = nullptr; + } + } + + if (backround != nullptr) { + delete backround; + backround = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::~TimerMainPage()"); +} + +void TimerMainPage::OnStart(void* data) +{ + bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(TIMER_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadTimerImage fail"); + return; + } + // 主界面 + if (group == nullptr) { + group = new UIScrollView(); + group->SetPosition(0, 0, VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + group->SetViewId("mainview"); + } + if (backround == nullptr) { + backround = new UIImageView(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::OnStart new backround"); + } + LOADIMG::LoadImageViewImg(backround, TIMER_IMAGE, IMAGE_CONVERTER_TOOL_TIMER_BG); + backround->SetPosition(0, 0, RESOLUTION_WIDTH, RESOLUTION_WIDTH); + group->Add(backround); + InitView(); + LabelTitle(); + group->SetOnDragListener(this); + group->SetVisible(false); + AddViewToPageContainer(group); + if (TimerModel::GetInstance().GetExistTimer()) { + // 定时器存在,进入计时页面 + NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_TIMING_PAGE); + } else { + group->SetVisible(true); + } +} + +void TimerMainPage::LabelTitle() +{ + // 标题 + if (title == nullptr) { + title = new UILabel(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::LabelTitle new title"); + } + title->SetPosition(MAIN_TITLE_POSITION_X, MAIN_TITLE_POSITION_Y); + title->SetText("计时器"); + title->Resize(MAIN_TITLE_SIZE_WIDTH, MAIN_TITLE_SIZE_HEIGHT); + title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MAIN_TITLE_FONT_SIZE); + title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + title->SetVisible(true); + group->Add(title); +} + +void TimerMainPage::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::InitView() Start!"); + if (addButton == nullptr) { + addButton = new UIImageView(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::InitView new addButton"); + } + LOADIMG::LoadImageViewImg(addButton, TIMER_IMAGE, IMAGE_CONVERTER_TOOL_TIMER_USER); + addButton->SetPosition(MAIN_ADDBUTTON_POSITION_X, MAIN_ADDBUTTON_POSITION_Y); + addButton->Resize(MAIN_ADDBUTTON_SIZE_WIDTH, MAIN_ADDBUTTON_SIZE_HEIGHT); + addButton->SetViewId(SETTING_TIMER); + addButton->SetTouchable(true); + addButton->SetOnClickListener(this); + group->Add(addButton); + + int posX[ADDBUTTON_MAX] = {SELECTMIN_POX, SELECTMIN_POXS, SELECTMIN_POX, SELECTMIN_POXS}; + int posY[ADDBUTTON_MAX] = {SELECTMIN_POY, SELECTMIN_POY, SELECTMIN_POYS, SELECTMIN_POYS}; + const char* buttonViewId[ADDBUTTON_MAX] = {"1", "3", "15", "30"}; + ImageInfo *image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_1, TIMER_IMAGE); + ImageInfo *image3 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_3, TIMER_IMAGE); + ImageInfo *image15 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_15, TIMER_IMAGE); + ImageInfo *image30 = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_30, TIMER_IMAGE); + ImageInfo* buttonSrc[ADDBUTTON_MAX] = {image1, image3, image15, image30}; + // 一分钟按钮 + for (int i = 0;i < ADDBUTTON_MAX;i++) { + if (selectMin[i] == nullptr) { + selectMin[i] = new UIImageView(); + } + selectMin[i]->SetPosition(posX[i], posY[i]); + selectMin[i]->Resize(SELECTMIN_SIZE, SELECTMIN_SIZE); + selectMin[i]->SetTouchable(true); + selectMin[i]->SetOnClickListener(this); + selectMin[i]->SetViewId(buttonViewId[i]); + selectMin[i]->SetSrc(buttonSrc[i]); + group->Add(selectMin[i]); + } +} + +bool TimerMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + std::string viewId = view.GetViewId(); + if (viewId == SETTING_TIMER) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::OnClick viewId == SETTING_TIMER"); + NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_SETTING_PAGE); + } else if (viewId == "1"|| viewId == "3" || viewId == "15" || viewId == "30") { + int num = std::stoi(viewId); + struct timeval start_time; + gettimeofday(&start_time, nullptr); + uint32_t s_time = start_time.tv_sec * MAX_SCR_DIS + start_time.tv_usec / MAX_SCR_DIS; // 转换成ms + TimerModel::GetInstance().SetStartTime(s_time); + TimerModel::GetInstance().SetSaveTime(true, 0); + TimerModel::GetInstance().SetDurationTime(num * MIN); + NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_TIMING_PAGE); + } + return true; +} + +bool TimerMainPage::OnDrag(UIView& view, const DragEvent& event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerMainPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + } + return true; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerModel.cpp new file mode 100644 index 000000000..83c3b843c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerModel.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerModel + * Create: 2025-06-09 + */ + +#include "timers/TimerModel.h" +#include "main/HealthModel.h" +#include "uiservice/ui_service.h" +#include "wearable_log.h" + +namespace OHOS { +static int g_motionTimes{0}; +static constexpr uint64_t MS_ONE_SECONDS = 1000; +TimerModel::TimerModel() +{ +} + +TimerModel::~TimerModel() +{ +} + +TimerModel &TimerModel::GetInstance() +{ + static TimerModel instance; + return instance; +} + +uint32_t TimerModel::GetSaveTime() +{ + return save_time; +} + +void TimerModel::SetSaveTime(bool falg, uint32_t value) +{ + if (falg) { + save_time = 0; + } else { + save_time += value; + } +} + +void TimerModel::SetDurationTime(uint32_t time) +{ + durationTime = time; +} + +uint32_t TimerModel::GetDurationTime() +{ + return durationTime; +} + +/* 定时器回调函数 */ +void TimerTimerCallback(void *data) +{ + (void)data; + uint32_t dura_time = TimerModel::GetInstance().GetDurationTime(); + uint32_t start_time = TimerModel::GetInstance().GetStartTime(); + uint32_t save_time = TimerModel::GetInstance().GetSaveTime(); + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + uint32_t remTime = dura_time * 1000 - (current_time.tv_usec - start_time) - save_time; + if (remTime == 0) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "TimerTimerCallback: end :%d", time); + TimerModel::GetInstance().SetExistTimer(false); + TimerModel::GetInstance().DisableTimer(); + } +} + +/* 开启定时器 */ +void TimerModel::InitTimer() +{ + if (g_startCounting != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerModel::InitTimer g_startCounting != nullptr!!"); + return; + } + uint32_t tick = GetOSTick(MS_ONE_SECONDS); + g_startCounting = new GraphicTimer(tick, TimerTimerCallback, nullptr, true); + if (g_startCounting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerModel::InitTimer new GraphicTimer failed!!"); + return; + } + bool retTimer = g_startCounting->Start(); + if (!retTimer) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerModel::InitTimer Start failed!!"); + if (g_startCounting != nullptr) { + delete g_startCounting; + g_startCounting = nullptr; + } + return; + } +} + +/* 关闭定时器 */ +void TimerModel::DisableTimer() +{ + if (g_startCounting != nullptr) { + delete g_startCounting; + g_startCounting = nullptr; + g_motionTimes = 0; + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerPresenter.cpp new file mode 100644 index 000000000..b7390642f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerPresenter.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerPresenter + * Create: 2025-06-09 + */ + +#include "timers/TimerView.h" +#include "timers/TimerModel.h" +#include "timers/TimerPresenter.h" +#include "NativeRegisterManager.h" +#include "ohos_timer.h" + +namespace OHOS { + REGIST_MENU(VIEW_TIMER, TimerView, TimerPresenter, TIMER_MAIN_ICON, PNG_APPLIST_DEFAULT_IMG, "计时器"); +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerSettingPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerSettingPage.cpp new file mode 100644 index 000000000..0f01e9354 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerSettingPage.cpp @@ -0,0 +1,386 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerSettingPage + * Create: 2025-06-09 + */ + +#include +#include +#include "timers/TimerSettingPage.h" +#include "timers/TimerPresenter.h" +#include "components/ui_arc_label.h" +#include "wearable_log.h" +#include "timers/TimerView.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" + +namespace OHOS { +static constexpr uint8_t BACKGROUND_FONT = 40; +static constexpr uint8_t HIGHTLIGHT_FONT = 50; +static constexpr uint8_t TIMERPICKER_MAX = 3; +static constexpr uint16_t PADDING = 3; +static constexpr uint16_t BORDER_RADIUS = 5; +static constexpr uint16_t TEXT_FONT = 24; +static constexpr uint16_t SETTING_TITLE_POSITION_X = 100; +static constexpr uint16_t SETTING_TITLE_POSITION_Y = 31; +static constexpr uint16_t SETTING_TITLE_SIZE_WIDTH = 253; +static constexpr uint16_t SETTING_TITLE_SIZE_HEIGHT = 53; +static constexpr uint16_t SETTING_TITLE_TEXT_SIZE = 38; +static constexpr uint16_t SETTING_TIMERLABEL_POSITION_X = 86; +static constexpr uint16_t SETTING_TIMERLABEL_POSITION_Y = 88; +static constexpr uint16_t SETTING_TIMERLABEL_SIZE_WIDTH = 48; +static constexpr uint16_t SETTING_TIMERLABEL_SIZE_HEIGHT = 42; +static constexpr uint16_t SETTING_TIMERLABEL_FONT = 18; +static constexpr uint16_t SETTING_START_POSITION_X = 112; +static constexpr uint16_t SETTING_START_POSITION_Y = 347; +static constexpr uint16_t SETTING_START_SIZE_WIDTH = 232; +static constexpr uint16_t SETTING_START_SIZE_HEIGHT = 76; +static constexpr uint16_t SETTING_START_FONT = 40; +static constexpr uint16_t TIMERPICKER_POSX1 = 61; +static constexpr uint16_t TIMERPICKER_POSX2 = 183; +static constexpr uint16_t TIMERPICKER_POSX3 = 305; +static constexpr uint16_t TIMERPICKER_POSY = 119; +static constexpr uint16_t SETTING_TIMERPICKER_SIZE_WIDTH = 88; +static constexpr uint16_t SETTING_TIMERPICKER_SIZE_HEIGHT = 189; +static constexpr uint16_t TIMERPICKER_RADIUS = 11; +static constexpr uint16_t SETTING_TIMERPICKER_ITEM_HEIGHT = 70; +static constexpr uint16_t SETTING_TIMERPICKER_HOUR = 24; +static constexpr uint16_t SETTING_TIMERPICKER_HOURS = 23; +static constexpr uint16_t SETTING_TIMERPICKER_MIN = 60; +static constexpr uint16_t SETTING_TIMERPICKER_MINS = 59; +static constexpr uint16_t SETTING_PICKERGROUP_POSX = 70; +static constexpr uint16_t SETTING_PICKERGROUP_POSY = 132; +static constexpr uint16_t SETTING_PICKERGROUP_SIZE_WIDTH = 80; +static constexpr uint16_t SETTING_PICKERGROUP_SIZE_HEIGHT = 208; +static constexpr uint16_t HOUR_TIME = 3600; +static constexpr uint16_t MIN_TIME = 60; +static constexpr uint16_t POX1_MIN = 86; +static constexpr uint16_t POX1_MAX = 174; +static constexpr uint16_t POX2_MIN = 206; +static constexpr uint16_t POX2_MAX = 294; +static constexpr uint16_t POX3_MIN = 332; +static constexpr uint16_t POX3_MAX = 420; +static constexpr uint16_t POY_MIN = 119; +static constexpr uint16_t POY_MAX = 308; +static constexpr uint16_t SLEEP = 500; +static constexpr uint16_t SUM_2 = 2; + +REGIST_SLICE_PAGE(VIEW_TIMER, TIMER_PAGES::TIMER_SETTING_PAGE, TimerSettingPage, false); + +TimerSettingPage::~TimerSettingPage() +{ + bool ret = ImageCacheManager::GetInstance().UnloadAllInMultiRes(TIMER_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnloadTimerImage fail"); + } + + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (title != nullptr) { + delete title; + title = nullptr; + } + + if (back != nullptr) { + delete back; + back = nullptr; + } + + for (int i = 0; i < TIMERPICKER_MAX; i++) { + if (timerPicker[i] != nullptr) { + delete timerPicker[i]; + timerPicker[i] = nullptr; + } + } + + if (start != nullptr) { + delete start; + start = nullptr; + } + + if (timerLabel != nullptr) { + delete timerLabel; + timerLabel = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerSettingPage::~TimerSettingPage"); +} + +void TimerSettingPage::OnStart(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerSettingPage::OnStart() Start"); + bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(TIMER_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadTimerImage fail"); + return; + } + image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_BEGIN_GRAY, TIMER_IMAGE); + if (image1 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadTimerImage image1 fail"); + return; + } + image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_BEGIN_ORANGE, TIMER_IMAGE); + if (image2 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadTimerImage image2 fail"); + return; + } + // 标题 + if (title == nullptr) { + title = new UILabel(); + } + title->SetPosition(SETTING_TITLE_POSITION_X, SETTING_TITLE_POSITION_Y); + title->Resize(SETTING_TITLE_SIZE_WIDTH, SETTING_TITLE_SIZE_HEIGHT); + title->SetText("设置时间"); + title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_TITLE_TEXT_SIZE); + title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + title->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + if (group == nullptr) { + group = new UIScrollView(); + } + group->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + group->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + group->SetThrowDrag(true); + CreateLabel(); + CreateStartButton(); + CreatePicker(); + group->Add(title); + group->SetOnDragListener(this); + AddViewToPageContainer(group); +} + +void TimerSettingPage::CreateLabel(void) +{ + // Add Label to App + if (timerLabel == nullptr) { + timerLabel = new UILabel(); + } + timerLabel->SetPosition(SETTING_TIMERLABEL_POSITION_X, + SETTING_TIMERLABEL_POSITION_Y); // widget's left position and top position + timerLabel->Resize(SETTING_TIMERLABEL_SIZE_WIDTH, + SETTING_TIMERLABEL_SIZE_HEIGHT); // widget's width and height + timerLabel->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFFFBF00); + timerLabel->SetStyle(STYLE_BACKGROUND_OPA, 0xef); + timerLabel->SetStyle(STYLE_BORDER_RADIUS, BORDER_RADIUS); + timerLabel->SetStyle(STYLE_PADDING_TOP, PADDING); + timerLabel->SetStyle(STYLE_PADDING_BOTTOM, PADDING); + timerLabel->SetStyle(STYLE_TEXT_FONT, TEXT_FONT); + + // Set additional property + timerLabel->SetText("小时"); + timerLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + timerLabel->SetTextColor(Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0xff)); + timerLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timerLabel->SetDirect(TEXT_DIRECT_MIXED); + timerLabel->SetRollSpeed(0); + timerLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_TIMERLABEL_FONT); + timerLabel->SetVisible(false); + // Add to rootView + group->Add(timerLabel); +} + +void TimerSettingPage::CreateStartButton(void) +{ + // 开始按钮 + if (start == nullptr) { + start = new UIImageView(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage:: new start UIImageView"); + } + start->SetPosition(SETTING_START_POSITION_X, SETTING_START_POSITION_Y); + start->Resize(SETTING_START_SIZE_WIDTH, SETTING_START_SIZE_HEIGHT); + start->SetViewId(START_TIMING); + start->SetTouchable(false); + start->SetOnClickListener(this); + start->SetSrc(image1); + group->Add(start); +} + +// 时间选择器分钟与秒钟列 +const char *uiPickerData[] = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", + "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", + "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", + "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", + "51", "52", "53", "54", "55", "56", "57", "58", "59", "00"}; + +// 时间选择器小时列 +const char *uiPicker5Data[] = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", + "15", "16", "17", "18", "19", "20", "21", "22", "23", "00"}; + +void TimerSettingPage::CreatePicker() +{ + // Add Picker to App + int posX[TIMERPICKER_MAX] = {TIMERPICKER_POSX1, TIMERPICKER_POSX2, TIMERPICKER_POSX3}; + int posY = TIMERPICKER_POSY; + for (int i = 0; i < TIMERPICKER_MAX; i++) { + if (timerPicker[i] == nullptr) { + timerPicker[i] = new UIPicker(); + } + timerPicker[i]->SetPosition(posX[i], posY); // widget's left position and top position + timerPicker[i]->Resize(SETTING_TIMERPICKER_SIZE_WIDTH, SETTING_TIMERPICKER_SIZE_HEIGHT); + timerPicker[i]->SetViewId("hourPicker"); // Set style + timerPicker[i]->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + timerPicker[i]->SetStyle(STYLE_BORDER_WIDTH, TIMERPICKER_MAX); + timerPicker[i]->SetStyle(STYLE_BORDER_RADIUS, TIMERPICKER_RADIUS); + timerPicker[i]->SetStyle(STYLE_BORDER_COLOR, 0xffb9b9b9); + timerPicker[i]->SetItemHeight(SETTING_TIMERPICKER_ITEM_HEIGHT); + timerPicker[i]->SetLoopState(true); + timerPicker[i]->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); + timerPicker[i]->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); + timerPicker[i]->SetTextColor(Color::GetColorFromRGBA(0x64, 0x69, 0x6e, 0xff), + Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); + if (i == 0) { + timerPicker[i]->SetValues(uiPicker5Data, SETTING_TIMERPICKER_HOUR); + timerPicker[i]->SetSelected(SETTING_TIMERPICKER_HOURS); + } else { + timerPicker[i]->SetValues(uiPickerData, SETTING_TIMERPICKER_MIN); + timerPicker[i]->SetSelected(SETTING_TIMERPICKER_MINS); + } + timerPicker[i]->SetOnClickListener(this); + timerPicker[i]->SetDraggable(true); + timerPicker[i]->SetOnDragListener(this); + timerPicker[i]->RegisterSelectedListener(this); + group->Add(timerPicker[i]); + } + + timerPicker[0]->SetViewId("hourPicker"); // Set style + timerPicker[1]->SetViewId("minPicker"); // Set style + timerPicker[SUM_2]->SetViewId("secPicker"); // Set style +} + +bool TimerSettingPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + std::string viewId = view.GetViewId(); + if (viewId == START_TIMING) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerSettingPage::OnClick viewId == START_TIMING"); + TimerModel::GetInstance().SetSaveTime(true, 0); + uint8_t hour = std::stoi(uiPicker5Data[timerPicker[0]->GetSelected()]); + uint8_t minute = std::stoi(uiPickerData[timerPicker[1]->GetSelected()]); + uint8_t second = std::stoi(uiPickerData[timerPicker[SUM_2]->GetSelected()]); + uint32_t durationTime = (hour * HOUR_TIME) + (minute * MIN_TIME) + (second); + TimerModel::GetInstance().SetDurationTime(durationTime); + NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_TIMING_PAGE); + } + timerLabel->Invalidate(); + return true; +} + +bool TimerSettingPage::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_MAIN_PAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerSettingPage::OnDrag SwitchSlice(TIMER_MAIN_PAGE)"); + } + if (view.GetViewId() == "hourPicker") { + timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[0]->Invalidate(); + timerPicker[1]->Invalidate(); + timerPicker[SUM_2]->Invalidate(); + timerLabel->SetVisible(true); + timerLabel->SetPosition(POX1_MIN, SETTING_TIMERLABEL_POSITION_Y); + timerLabel->SetText("小时"); + timerLabel->Invalidate(); + } else if (view.GetViewId() == "minPicker") { + timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[0]->Invalidate(); + timerPicker[1]->Invalidate(); + timerPicker[SUM_2]->Invalidate(); + timerLabel->SetVisible(true); + timerLabel->SetPosition(POX2_MIN, SETTING_TIMERLABEL_POSITION_Y); + timerLabel->SetText("分钟"); + timerLabel->Invalidate(); + } else if (view.GetViewId() == "secPicker") { + timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker[0]->Invalidate(); + timerPicker[1]->Invalidate(); + timerPicker[SUM_2]->Invalidate(); + timerLabel->SetVisible(true); + timerLabel->SetPosition(POX3_MIN, SETTING_TIMERLABEL_POSITION_Y); + timerLabel->SetText("秒"); + timerLabel->Invalidate(); + } + return true; +} + +void TimerSettingPage::OnPickerStoped(UIPicker& picker) +{ + if (picker.GetViewId() == "hourPicker") { + uint16_t hour = picker.GetSelected(); + timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[0]->Invalidate(); + timerPicker[1]->Invalidate(); + timerPicker[SUM_2]->Invalidate(); + if ((hour == SETTING_TIMERPICKER_HOURS) && (timerPicker[1]->GetSelected() == SETTING_TIMERPICKER_MINS) && + (timerPicker[SUM_2]->GetSelected() == SETTING_TIMERPICKER_MINS)) { + start->SetTouchable(false); + start->SetSrc(image1); + } else { + start->SetTouchable(true); + start->SetSrc(image2); + } + timerLabel->SetVisible(true); + timerLabel->SetPosition(POX1_MIN, SETTING_TIMERLABEL_POSITION_Y); + timerLabel->SetText("小时"); + timerLabel->Invalidate(); + } else if (picker.GetViewId() == "minPicker") { + uint16_t minute = picker.GetSelected(); + timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[0]->Invalidate(); + timerPicker[1]->Invalidate(); + timerPicker[SUM_2]->Invalidate(); + if ((timerPicker[0]->GetSelected() == SETTING_TIMERPICKER_HOURS) && (minute == SETTING_TIMERPICKER_MINS) && + (timerPicker[SUM_2]->GetSelected() == SETTING_TIMERPICKER_MINS)) { + start->SetTouchable(false); + start->SetSrc(image1); + } else { + start->SetTouchable(true); + start->SetSrc(image2); + } + timerLabel->SetVisible(true); + timerLabel->SetPosition(POX2_MIN, SETTING_TIMERLABEL_POSITION_Y); + timerLabel->SetText("分钟"); + timerLabel->Invalidate(); + } else { + uint16_t sec = picker.GetSelected(); + timerPicker[0]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[1]->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full); + timerPicker[SUM_2]->SetStyle(STYLE_BORDER_COLOR, Color::Orange().full); + timerPicker[0]->Invalidate(); + timerPicker[1]->Invalidate(); + timerPicker[SUM_2]->Invalidate(); + if ((timerPicker[0]->GetSelected() == SETTING_TIMERPICKER_HOURS) && + (timerPicker[1]->GetSelected() == SETTING_TIMERPICKER_MINS) && (sec == SETTING_TIMERPICKER_MINS)) { + start->SetTouchable(false); + start->SetSrc(image1); + } else { + start->SetTouchable(true); + start->SetSrc(image2); + } + timerLabel->SetVisible(true); + timerLabel->SetPosition(POX3_MIN, SETTING_TIMERLABEL_POSITION_Y); + timerLabel->SetText("秒"); + timerLabel->Invalidate(); + } +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerTimingPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerTimingPage.cpp new file mode 100644 index 000000000..f9da1e9bd --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/timers/src/TimerTimingPage.cpp @@ -0,0 +1,548 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TimerTimingPage + * Create: 2025-06-09 + */ + +#include +#include +#include "timers/TimerTimingPage.h" +#include "ui_test_group.h" +#include "timers/TimerPresenter.h" +#include "wearable_log.h" +#include "timers/TimerView.h" +#include "SlicePageFactory.h" +#include "common/image_cache_manager.h" +#include "pwm.h" +#include "main/LoadImg.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif + +namespace OHOS { +static constexpr uint16_t NUM_TEN = 10; +static constexpr uint16_t TIMING_TITLE_POSITION_X = 170; +static constexpr uint16_t TIMING_TITLE_POSITION_Y = 110; +static constexpr uint16_t TIMING_TITLE_SIZE_WIDTH = 114; +static constexpr uint16_t TIMING_TITLE_SIZE_HEIGHT = 38; +static constexpr uint16_t TIMING_TITLE_FONT = 38; +static constexpr uint16_t TIMING_LABEL_CURTIME_XPOS = 199; +static constexpr uint16_t TIMING_LABEL_CURTIME_YPOS = 54; +static constexpr uint16_t TIMING_LABEL_CURTIME_WIDTH = 67; +static constexpr uint16_t TIMING_LABEL_CURTIME_HEIGHT = 24; +static constexpr uint16_t TIMING_LABEL_CURTIME_FONT_SIZE = 24; +static constexpr uint16_t TIMING_START_IMAGE_XPOS = 251; +static constexpr uint16_t TIMING_START_IMAGE_YPOS = 306; +static constexpr uint16_t TIMING_START_IMAGE_SIZE = 96; +static constexpr uint16_t TIMING_RESET_IMAGE_XPOS = 107; +static constexpr uint16_t TIMING_RESET_IMAGE_YPOS = 306; +static constexpr uint16_t TIMING_RESET_IMAGE_SIZE = 96; +static constexpr uint16_t TIMING_TIMER_TIME_XPOS = 85; +static constexpr uint16_t TIMING_TIMER_TIME_YPOS = 182; +static constexpr uint16_t TIMING_TIMER_TIME_WIDTH = 322; +static constexpr uint16_t TIMING_TIMER_TIME_HEIGHT = 90; +static constexpr uint16_t TIMING_TIMER_TIME_FONT_SIZE = 72; +static constexpr uint16_t HOUR_TIME = 3600; +static constexpr uint16_t MIN_TIME = 60; +static constexpr uint16_t TIMING_CIRCLE_LINE_WIDTH = 10; +static constexpr uint16_t TIMING_CIRCLE = 227; +static constexpr uint16_t CIRCLE_RADIUS = 222; +static constexpr uint16_t TIMING_CIRCLE_END = 360; +static constexpr uint32_t TIMING_CIRCLE_RANGE = 100000; +static constexpr uint16_t MAX_SCR_DIS = 1000; +static constexpr uint32_t HOUR_RANGE = 60000; +static constexpr uint16_t TIMING_HAND_POSITION_XPOS = 224; +static constexpr uint16_t TIMING_HAND_POSITION_YPOS = 4; +static constexpr uint16_t TIMING_HAND_CENTER_XPOS = 3; +static constexpr uint16_t TIMING_HAND_CENTER_YPOS = 223; +static constexpr uint16_t TIMING_HAND_WIDTH = 2; +static constexpr uint16_t TIMING_HAND_HEIGHT = 5; + +REGIST_SLICE_PAGE(VIEW_TIMER, TIMER_PAGES::TIMER_TIMING_PAGE, TimerTimingPage, false); + +static std::string GetCurrentTimeStr() +{ + struct tm localTime; + time_t seconds = time(nullptr); + localtime_r(&seconds, &localTime); + std::string currTime; + if (localTime.tm_hour < NUM_TEN) { + currTime += "0"; + } + currTime += std::to_string(localTime.tm_hour) + ":"; + if (localTime.tm_min < NUM_TEN) { + currTime += "0"; + } + currTime += std::to_string(localTime.tm_min); + return currTime; +} + +TimerTimingPage::~TimerTimingPage() +{ + bool ret = ImageCacheManager::GetInstance().UnloadAllInMultiRes(TIMER_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UnloadTimerImage fail"); + } + + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (sweepClock_ != nullptr) { + sweepClock_->RemoveAll(); + delete sweepClock_; + sweepClock_ = nullptr; + } + + if (dClock != nullptr) { + delete dClock; + dClock = nullptr; + } + + if (title != nullptr) { + delete title; + title = nullptr; + } + + if (timerTime != nullptr) { + delete timerTime; + timerTime = nullptr; + } + + if (reset != nullptr) { + delete reset; + reset = nullptr; + } + + if (start != nullptr) { + delete start; + start = nullptr; + } + + if (circleProgress != nullptr) { + delete circleProgress; + circleProgress = nullptr; + } + + if (currentTime_ != nullptr) { + delete currentTime_; + currentTime_ = nullptr; + } + + if (timeCallback_ != nullptr) { + delete timeCallback_; + timeCallback_ = nullptr; + } + + if (timeAnimator_ != nullptr) { + delete timeAnimator_; + timeAnimator_ = nullptr; + } + + if (callBack_ != nullptr) { + delete callBack_; + callBack_ = nullptr; + } + + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + + if (secondHand_ != nullptr) { + delete secondHand_; + secondHand_ = nullptr; + } + + if (backround != nullptr) { + delete backround; + backround = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::~TimerTimingPage"); +} + +void TimerTimingPage::OnStart(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart() Start!"); + bool ret = ImageCacheManager::GetInstance().LoadAllInMultiRes(TIMER_IMAGE); + if (ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadTimerImage fail"); + return; + } + if (group == nullptr) { + group = new UIScrollView(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart new group"); + } + group->SetPosition(0, 0, VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + group->SetThrowDrag(true); + + if (backround == nullptr) { + backround = new UIImageView(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart new backround"); + } + ImageInfo *image = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_BG, TIMER_IMAGE); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart backround source fail"); + return; + } + backround->SetSrc(image); + backround->SetPosition(0, 0, VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + + if (sweepClock_ == nullptr) { + sweepClock_ = new UISweepClock(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart new sweepClock_"); + } + sweepClock_->SetPosition(0, 0); + sweepClock_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + sweepClock_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + if (secondHand_ == nullptr) { + secondHand_ = new Image(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart new secondHand_"); + } + ImageInfo *second = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_TIMER_POINTER, TIMER_IMAGE); + if (second == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart second source fail"); + return; + } + secondHand_->SetSrc(second); + sweepClock_->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand_, + {TIMING_HAND_POSITION_XPOS, TIMING_HAND_POSITION_YPOS}, {TIMING_HAND_CENTER_XPOS, TIMING_HAND_CENTER_YPOS}); + sweepClock_->SetHandLine(UISweepClock::HandType::HOUR_HAND, {TIMING_HAND_POSITION_XPOS, TIMING_HAND_POSITION_YPOS}, + {TIMING_HAND_CENTER_XPOS, TIMING_HAND_CENTER_YPOS}, Color::White(), TIMING_HAND_WIDTH, TIMING_HAND_HEIGHT, + OPA_TRANSPARENT); + sweepClock_->SetHandLine(UISweepClock::HandType::MINUTE_HAND, + {TIMING_HAND_POSITION_XPOS, TIMING_HAND_POSITION_YPOS}, {TIMING_HAND_CENTER_XPOS, TIMING_HAND_CENTER_YPOS}, + Color::White(), TIMING_HAND_WIDTH, TIMING_HAND_HEIGHT, OPA_TRANSPARENT); + + // 标题 + if (title == nullptr) { + title = new UILabel(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart new title"); + } + title->SetPosition(TIMING_TITLE_POSITION_X, TIMING_TITLE_POSITION_Y); + title->Resize(TIMING_TITLE_SIZE_WIDTH, TIMING_TITLE_SIZE_HEIGHT); + title->SetText("计时器"); + title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIMING_TITLE_FONT); + title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + if (currentTime_ == nullptr) { + currentTime_ = new UILabel(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart new currentTime_"); + } + currentTime_->SetPosition(TIMING_LABEL_CURTIME_XPOS, TIMING_LABEL_CURTIME_YPOS); + currentTime_->Resize(TIMING_LABEL_CURTIME_WIDTH, TIMING_LABEL_CURTIME_HEIGHT); + currentTime_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIMING_LABEL_CURTIME_FONT_SIZE); + currentTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + currentTime_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + currentTime_->SetVisible(true); + + group->Add(backround); + CircleProgress(); + group->Add(sweepClock_); + CreateButton(); + CreateTimerTime(); + group->Add(title); + group->Add(currentTime_); + group->SetOnDragListener(this); + AddViewToPageContainer(group); + + if (timeCallback_ == nullptr) { + timeCallback_ = new TimeAnimatorCallback(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart new timeCallback_"); + } + + if (timeAnimator_ == nullptr) { + timeAnimator_ = new Animator(timeCallback_, currentTime_, 0, true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnStart new Animator timeAnimator_"); + } + timeAnimator_->Start(); +} + +void TimerTimingPage::OnResume() +{ + if (TimerModel::GetInstance().GetExistTimer()) { + SetAnimatorStatus(true); + TimerModel::GetInstance().SetExistTimer(false); + } + if (timeAnimator_ != nullptr) { + if (timeAnimator_->GetState() == Animator::STOP) { + timeAnimator_->Start(); + } + } + if (!start->IsTouchable()) { + LOADIMG::LoadImageViewImg(start, TIMER_IMAGE, IMAGE_CONVERTER_TOOL_TIMER_PAUSE); + } +} + +void TimerTimingPage::OnPause() +{ + if (TimerModel::GetInstance().GetIsTiming()) { + TimerModel::GetInstance().SetExistTimer(true); + } + if (timeAnimator_ != nullptr) { + if (timeAnimator_->GetState() != Animator::STOP) { + timeAnimator_->Stop(); + } + } + SetAnimatorStatus(false); +} + +void TimerTimingPage::CreateButton() +{ + ImageInfo *image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_PLAY, TIMER_IMAGE); + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_EXIT, TIMER_IMAGE); + // 开始/暂停按钮 + if (start == nullptr) { + start = new UIImageView(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::CreateButton new start"); + } + start->SetPosition(TIMING_START_IMAGE_XPOS, TIMING_START_IMAGE_YPOS); + start->Resize(TIMING_START_IMAGE_SIZE, TIMING_START_IMAGE_SIZE); + start->SetViewId(START_PAUSE); + start->SetTouchable(true); + start->SetOnClickListener(this); + start->SetSrc(image1); + group->Add(start); + + // 复位按钮 + ImageInfo *image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_EXIT, TIMER_IMAGE); + if (reset == nullptr) { + reset = new UIImageView(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::CreateButton new reset"); + } + reset->SetPosition(TIMING_RESET_IMAGE_XPOS, TIMING_RESET_IMAGE_YPOS); + reset->Resize(TIMING_RESET_IMAGE_SIZE, TIMING_RESET_IMAGE_SIZE); + reset->SetViewId(RESET); + reset->SetTouchable(true); + reset->SetOnClickListener(this); + reset->SetSrc(image2); + group->Add(reset); +} + +void TimerTimingPage::CreateTimerTime() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::CreateTimerTime() Start!"); + if (timerTime == nullptr) { + timerTime = new UIDigitalClock(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::CreateTimerTime() new timerTime!"); + } + timerTime->SetPosition(TIMING_TIMER_TIME_XPOS, TIMING_TIMER_TIME_YPOS); + timerTime->Resize(TIMING_TIMER_TIME_WIDTH, TIMING_TIMER_TIME_HEIGHT); + timerTime->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIMING_TIMER_TIME_FONT_SIZE); + timerTime->SetDisplayMode(UIDigitalClock::DISPLAY_24_HOUR); + timerTime->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + uint32_t durationTime = TimerModel::GetInstance().GetDurationTime(); + uint8_t hour = durationTime / HOUR_TIME; + uint8_t minute = durationTime % HOUR_TIME / MIN_TIME; + uint8_t second = durationTime % MIN_TIME; + timerTime->SetTime24Hour(hour, minute, second); + group->Add(timerTime); +} + +void TimerTimingPage::CircleProgress() +{ + // 动态计时圈 + if (circleProgress == nullptr) { + circleProgress = new UICircleProgress(); + } + circleProgress->SetPosition(0, 0); // widget's left position and top position + circleProgress->Resize(RESOLUTION_WIDTH, RESOLUTION_HEIGHT); // widget's width and height + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_BG_CIR, TIMER_IMAGE); + ImageInfo *image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_PBG, TIMER_IMAGE); + circleProgress->SetImage(image1, image); + circleProgress->EnableBackground(true); + circleProgress->SetBackgroundStyle(STYLE_LINE_WIDTH, TIMING_CIRCLE_LINE_WIDTH); + circleProgress->SetForegroundStyle(STYLE_LINE_WIDTH, TIMING_CIRCLE_LINE_WIDTH); + circleProgress->EnableBackground(true); + circleProgress->SetCenterPosition(TIMING_CIRCLE, TIMING_CIRCLE); + circleProgress->SetRadius(CIRCLE_RADIUS); + circleProgress->SetStartAngle(0); + circleProgress->SetEndAngle(TIMING_CIRCLE_END); + circleProgress->SetRange(TIMING_CIRCLE_RANGE, 0); + circleProgress->SetValue(TIMING_CIRCLE_RANGE); + // Add to rootView + SetupAnimator(); + group->Add(circleProgress); +} + +// 单位为毫秒计算 +void TimerTimingPage::SetTimerTime(uint32_t onTime) +{ + uint64_t time = onTime / MAX_SCR_DIS; + uint8_t hour = time / HOUR_TIME; + uint8_t minute = time % HOUR_TIME / MIN_TIME; + uint8_t second = time % MIN_TIME; + timerTime->SetTime24Hour(hour, minute, second); + uint32_t totalTime = TimerModel::GetInstance().GetDurationTime(); + double percentage = static_cast(onTime) / (totalTime * MAX_SCR_DIS); + double value = round(percentage * TIMING_CIRCLE_RANGE); + circleProgress->SetValue(value); + sweepClock_->SetSweepTime24Hour(0, 0, percentage * HOUR_RANGE); + + if (onTime <= 0) { + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_PAUSE, TIMER_IMAGE); + ImageInfo *image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_EXIT, TIMER_IMAGE); + start->SetSrc(image); + start->SetTouchable(false); + reset->SetSrc(image1); + TimerModel::GetInstance().SetIsPause(false); + TimerModel::GetInstance().SetIsTiming(false); + start->Invalidate(); + reset->Invalidate(); + } + circleProgress->Invalidate(); + timerTime->Invalidate(); +} + +void TimerTimingPage::SetupAnimator() +{ + callBack_ = new TimerTimingCallback(this); + animator_ = new Animator(callBack_, nullptr, 0, true); +} + +void TimerTimingPage::TimerTimingCallback::Callback(UIView *view) +{ + (void)view; + static int count = 0; + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + + uint32_t overTime = TimerModel::GetInstance().GetDurationTime(); + uint32_t s_time = TimerModel::GetInstance().GetStartTime(); + uint32_t saveTime = TimerModel::GetInstance().GetSaveTime(); + uint64_t c_time = current_time.tv_sec * MAX_SCR_DIS + current_time.tv_usec / MAX_SCR_DIS; + int32_t remTime = overTime * MAX_SCR_DIS - (c_time - s_time) - saveTime; + + page_->SetTimerTime(remTime); + if (remTime <= 0) { + page_->animator_->Stop(); + page_->SetTimerTime(0); + // 调用pwm接口实现马达震动,客户自实现 + } +} + +void TimerTimingPage::SetAnimatorStatus(bool status) +{ + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_PAUSE_ORANGE, TIMER_IMAGE); + ImageInfo *image1 = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_PLAY, TIMER_IMAGE); + ImageInfo *image2 = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_RESTART, TIMER_IMAGE); + if (status) { + start->SetSrc(image); + reset->SetSrc(image2); + animator_->Start(); + TimerModel::GetInstance().InitTimer(); + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::SetAnimatorStatus status == false"); + animator_->Stop(); + start->SetSrc(image1); + TimerModel::GetInstance().DisableTimer(); + } +} + +bool TimerTimingPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + if (TimerModel::GetInstance().GetIsTiming()) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnDrag ChangeSlice(VIEW_APPLIST)"); + } else { + NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_MAIN_PAGE); + } + } + return true; +} + +bool TimerTimingPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + std::string viewId = view.GetViewId(); + if (viewId == RESET) { + if (TimerModel::GetInstance().GetIsTiming()) { + // 停止计时器 修改复位图标 重新将时间复原 + SetAnimatorStatus(false); + TimerModel::GetInstance().SetIsTiming(false); + uint32_t durationTime = TimerModel::GetInstance().GetDurationTime(); + uint8_t hour = durationTime / HOUR_TIME; + uint8_t minute = durationTime % HOUR_TIME / MIN_TIME; + uint8_t second = durationTime % MIN_TIME; + timerTime->SetTime24Hour(hour, minute, second); + TimerModel::GetInstance().SetSaveTime(true, 0); + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_EXIT, TIMER_IMAGE); + reset->SetSrc(image); + circleProgress->SetValue(TIMING_CIRCLE_RANGE); + sweepClock_->SetSweepTime24Hour(0, 0, 0); + } else if (! TimerModel::GetInstance().GetIsTiming() && TimerModel::GetInstance().GetIsPause()) { + TimerModel::GetInstance().SetIsTiming(false); + uint32_t durationTime = TimerModel::GetInstance().GetDurationTime(); + uint8_t hour = durationTime / HOUR_TIME; + uint8_t minute = durationTime % HOUR_TIME / MIN_TIME; + uint8_t second = durationTime % MIN_TIME; + timerTime->SetTime24Hour(hour, minute, second); + TimerModel::GetInstance().SetSaveTime(true, 0); + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes( + IMAGE_CONVERTER_TOOL_TIMER_EXIT, TIMER_IMAGE); + reset->SetSrc(image); + circleProgress->SetValue(TIMING_CIRCLE_RANGE); + sweepClock_->SetSweepTime24Hour(0, 0, 0); + TimerModel::GetInstance().SetIsPause(false); + } else { + NativeAbility::GetInstance().SwitchSlice(VIEW_TIMER, TIMER_PAGES::TIMER_MAIN_PAGE); + } + } else if (viewId == START_PAUSE) { + if (TimerModel::GetInstance().GetIsTiming()) { + SetAnimatorStatus(false); + TimerModel::GetInstance().SetIsTiming(false); + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + uint32_t time = (current_time.tv_sec * MAX_SCR_DIS + current_time.tv_usec / MAX_SCR_DIS) - + TimerModel::GetInstance().GetStartTime(); + TimerModel::GetInstance().SetSaveTime(false, time); + TimerModel::GetInstance().SetIsPause(true); + } else { + SetAnimatorStatus(true); + TimerModel::GetInstance().SetIsTiming(true); + struct timeval current_time; + gettimeofday(¤t_time, nullptr); + uint32_t s_time = current_time.tv_sec * MAX_SCR_DIS + current_time.tv_usec / MAX_SCR_DIS; // 转换成ms + TimerModel::GetInstance().SetStartTime(s_time); + TimerModel::GetInstance().SetIsPause(false); + } + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimerTimingPage::OnClick"); + return false; + } + return true; +} + +void TimerTimingPage::TimeAnimatorCallback::Callback(UIView *view) +{ + UILabel *timeLabel = dynamic_cast(view); + if (timeLabel == nullptr) { + return; + } + std::string currTime = GetCurrentTimeStr(); + timeLabel->SetText(currTime.c_str()); + timeLabel->Invalidate(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/DataView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/DataView.cpp new file mode 100644 index 000000000..0abd0f6d3 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/DataView.cpp @@ -0,0 +1,363 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Data View + * Create: 2025-03-22 + */ +#include "training/DataView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TrainingPresenter.h" + +namespace OHOS { +static constexpr uint16_t TOP_VALUE_LABEL_FONT = 80; +static constexpr uint16_t VALUE_LABEL_FONT = 60; +static constexpr uint16_t UNIT_LABEL_FONT = 30; +static constexpr uint16_t TOP_VALUE_LABEL_X = 164; +static constexpr uint16_t TOP_VALUE_LABEL_Y = 45; +static constexpr uint16_t TOP_VALUE_LABEL_W = 200; +static constexpr uint16_t TOP_VALUE_LABEL_H = 60; +static constexpr uint16_t TOP_UNIT_LABEL_X = 184; +static constexpr uint16_t TOP_UNIT_LABEL_Y = 135; +static constexpr uint16_t TOP_UNIT_LABEL_W = 200; +static constexpr uint16_t TOP_UNIT_LABEL_H = 60; +static constexpr uint16_t LEFT_VALUE_LABEL_X = 52; +static constexpr uint16_t LEFT_VALUE_LABEL_Y = 176; +static constexpr uint16_t LEFT_VALUE_LABEL_W = 200; +static constexpr uint16_t LEFT_VALUE_LABEL_H = 60; +static constexpr uint16_t LEFT_UNIT_LABEL_X = 71; +static constexpr uint16_t LEFT_UNIT_LABEL_Y = 247; +static constexpr uint16_t LEFT_UNIT_LABEL_W = 200; +static constexpr uint16_t LEFT_UNIT_LABEL_H = 60; +static constexpr uint16_t RIGHT_VALUE_LABEL_X = 310; +static constexpr uint16_t RIGHT_VALUE_LABEL_Y = 181; +static constexpr uint16_t RIGHT_VALUE_LABEL_W = 200; +static constexpr uint16_t RIGHT_VALUE_LABEL_H = 60; +static constexpr uint16_t RIGHT_UNIT_LABEL_X = 323; +static constexpr uint16_t RIGHT_UNIT_LABEL_Y = 253; +static constexpr uint16_t RIGHT_UNIT_LABEL_W = 200; +static constexpr uint16_t RIGHT_UNIT_LABEL_H = 60; +static constexpr uint16_t BOTTOM_VALUE_LABEL_X = 113; +static constexpr uint16_t BOTTOM_VALUE_LABEL_Y = 297; +static constexpr uint16_t BOTTOM_VALUE_LABEL_W = 200; +static constexpr uint16_t BOTTOM_VALUE_LABEL_H = 60; +static constexpr uint16_t BOTTOM_UNIT_LABEL_X = 217; +static constexpr uint16_t BOTTOM_UNIT_LABEL_Y = 374; +static constexpr uint16_t BOTTOM_UNIT_LABEL_W = 200; +static constexpr uint16_t BOTTOM_UNIT_LABEL_H = 60; +static constexpr uint16_t SEP_LINE_X = 234; +static constexpr uint16_t SEP_LINE_Y = 181; +static constexpr uint16_t SEP_LINE_W = 4; +static constexpr uint16_t SEP_LINE_H = 85; + +static DataView *g_pDataView{nullptr}; + +DataView::DataView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DataView::DataView"); + g_pDataView = this; +} + +DataView::~DataView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DataView::~DataView"); + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (backGround != nullptr) { + delete backGround; + backGround = nullptr; + } + if (heartrate != nullptr) { + delete heartrate; + heartrate = nullptr; + } + if (sepLine != nullptr) { + delete sepLine; + sepLine = nullptr; + } + if (topValueLabel != nullptr) { + delete topValueLabel; + topValueLabel = nullptr; + } + if (topUnitLabel != nullptr) { + delete topUnitLabel; + topUnitLabel = nullptr; + } + if (leftValueLabel != nullptr) { + delete leftValueLabel; + leftValueLabel = nullptr; + } + if (leftUnitLabel != nullptr) { + delete leftUnitLabel; + leftUnitLabel = nullptr; + } + if (rightValueLabel != nullptr) { + delete rightValueLabel; + rightValueLabel = nullptr; + } + if (rightUnitLabel != nullptr) { + delete rightUnitLabel; + rightUnitLabel = nullptr; + } + if (bottomValueLabel != nullptr) { + delete bottomValueLabel; + bottomValueLabel = nullptr; + } + if (bottomUnitLabel != nullptr) { + delete bottomUnitLabel; + bottomUnitLabel = nullptr; + } + g_pDataView = nullptr; +} + +DataView *DataView::GetInstance() +{ + return g_pDataView; +} + +void DataView::ShowupBackgroup() +{ + backGround = new UIImageView(); + if (backGround == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGroundFirst new fail"); + return; + } + backGround->SetPosition(0, 0); + backGround->SetSrc(PNG_WALK_BACK_GROUND); + group->Add(backGround); +} + +void DataView::ShowupTopView() +{ + // Add Label to App + if (topValueLabel == nullptr) { + topValueLabel = new UILabel(); + } + topValueLabel->SetPosition(TOP_VALUE_LABEL_X, TOP_VALUE_LABEL_Y); + topValueLabel->Resize(TOP_VALUE_LABEL_W, TOP_VALUE_LABEL_H); + + // Set additional property + topValueLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + topValueLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + topValueLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, VALUE_LABEL_FONT); + + // Add to rootView + group->Add(topValueLabel); + + // Add Label to App + if (topUnitLabel == nullptr) { + topUnitLabel = new UILabel(); + } + topUnitLabel->SetPosition(TOP_UNIT_LABEL_X, TOP_UNIT_LABEL_Y); + topUnitLabel->Resize(TOP_UNIT_LABEL_W, TOP_UNIT_LABEL_H); + + // Set additional property + topUnitLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + topUnitLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + topUnitLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, UNIT_LABEL_FONT); + + // Add to rootView + group->Add(topUnitLabel); +} + +void DataView::ShowupLeftView() +{ + // Add Label to App + if (leftValueLabel == nullptr) { + leftValueLabel = new UILabel(); + } + leftValueLabel->SetPosition(LEFT_VALUE_LABEL_X, LEFT_VALUE_LABEL_Y); + leftValueLabel->Resize(LEFT_VALUE_LABEL_W, LEFT_VALUE_LABEL_H); + + // Set additional property + leftValueLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + leftValueLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + leftValueLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, VALUE_LABEL_FONT); + + // Add to rootView + group->Add(leftValueLabel); + + // Add Label to App + if (leftUnitLabel == nullptr) { + leftUnitLabel = new UILabel(); + } + leftUnitLabel->SetPosition(LEFT_UNIT_LABEL_X, LEFT_UNIT_LABEL_Y); + leftUnitLabel->Resize(LEFT_UNIT_LABEL_W, LEFT_UNIT_LABEL_H); + + // Set additional property + leftUnitLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + leftUnitLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + leftUnitLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, UNIT_LABEL_FONT); + + // Add to rootView + group->Add(leftUnitLabel); +} + +void DataView::ShowupRightView() +{ + // Add Label to App + if (rightValueLabel == nullptr) { + rightValueLabel = new UILabel(); + } + rightValueLabel->SetPosition(RIGHT_VALUE_LABEL_X, RIGHT_VALUE_LABEL_Y); + rightValueLabel->Resize(RIGHT_VALUE_LABEL_W, RIGHT_VALUE_LABEL_H); + + // Set additional property + rightValueLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + rightValueLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + rightValueLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, VALUE_LABEL_FONT); + + // Add to rootView + group->Add(rightValueLabel); + + // Add Label to App + if (rightUnitLabel == nullptr) { + rightUnitLabel = new UILabel(); + } + rightUnitLabel->SetPosition(RIGHT_UNIT_LABEL_X, RIGHT_UNIT_LABEL_Y); + rightUnitLabel->Resize(RIGHT_UNIT_LABEL_W, RIGHT_UNIT_LABEL_H); + + // Set additional property + rightUnitLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + rightUnitLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + rightUnitLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, UNIT_LABEL_FONT); + + // Add to rootView + group->Add(rightUnitLabel); +} + +void DataView::ShowupBottomView() +{ + // Add Label to App + if (bottomValueLabel == nullptr) { + bottomValueLabel = new UILabel(); + } + bottomValueLabel->SetPosition(BOTTOM_VALUE_LABEL_X, BOTTOM_VALUE_LABEL_Y); + bottomValueLabel->Resize(BOTTOM_VALUE_LABEL_W, BOTTOM_VALUE_LABEL_H); + + // Set additional property + bottomValueLabel->SetText("00:12:15"); + bottomValueLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + bottomValueLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + bottomValueLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, VALUE_LABEL_FONT); + + // Add to rootView + group->Add(bottomValueLabel); + + // Add Label to App + if (bottomUnitLabel == nullptr) { + bottomUnitLabel = new UILabel(); + } + bottomUnitLabel->SetPosition(BOTTOM_UNIT_LABEL_X, BOTTOM_UNIT_LABEL_Y); + bottomUnitLabel->Resize(BOTTOM_UNIT_LABEL_W, BOTTOM_UNIT_LABEL_H); + + // Set additional property + bottomUnitLabel->SetText("时间"); + bottomUnitLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + bottomUnitLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + bottomUnitLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, UNIT_LABEL_FONT); + + // Add to rootView + group->Add(bottomUnitLabel); +} + +void DataView::ShowupSepLine() +{ + sepLine = new UICanvas(); + if (sepLine == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowupSepLine new fail"); + return; + } + sepLine->SetPosition(SEP_LINE_X, SEP_LINE_Y, SEP_LINE_W, SEP_LINE_H); + sepLine->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + sepLine->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + group->Add(sepLine); +} + +UIViewGroup *DataView::InitShowUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DataView init"); + if (group == nullptr) { + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + } + ShowupBackgroup(); + ShowupTopView(); + ShowupLeftView(); + ShowupRightView(); + ShowupBottomView(); + ShowupSepLine(); + UIView::OnDragListener *trainingDragListener = (UIView::OnDragListener *)OHOS::TrainingPresenter::GetInstance(); + if (trainingDragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "trainingDragListener GetInstance fail"); + return nullptr; + } + group->SetOnDragListener(trainingDragListener); + group->SetViewId(DATA_VIEW_ID); + group->SetDraggable(true); + group->SetTouchable(true); + return group; +} + +void DataView::UpdateDataViewByType() +{ + uint8_t trainingType = TrainingModel::GetInstance().GetCurTrainingType(); + if (trainingType == TRAINING_TYPE_OUTDOOR_RUNNING) { + topValueLabel->SetText("105"); + topUnitLabel->SetText("心率(次/分钟)"); + leftValueLabel->SetText("00'35\""); + leftUnitLabel->SetText("配速(/km)"); + rightValueLabel->SetText("3.25"); + rightUnitLabel->SetText("距离(km)"); + } else if (trainingType == TRAINING_TYPE_INDOOR_RUNNING) { + topValueLabel->SetText("105"); + topUnitLabel->SetText("心率(次/分钟)"); + leftValueLabel->SetText("00'35\""); + leftUnitLabel->SetText("配速(/km)"); + rightValueLabel->SetText("3.25"); + rightUnitLabel->SetText("距离(km)"); + } else if (trainingType == TRAINING_TYPE_CYCLING) { + topValueLabel->SetText("105"); + topUnitLabel->SetText("心率(次/分钟)"); + leftValueLabel->SetText("00'35\""); + leftUnitLabel->SetText("配速(/km)"); + rightValueLabel->SetText("3.25"); + rightUnitLabel->SetText("距离(km)"); + } else if (trainingType == TRAINING_TYPE_CLIMBING) { + topValueLabel->SetText("198"); + topUnitLabel->SetText("海拔(m)"); + leftValueLabel->SetText("535"); + leftUnitLabel->SetText("累计上升(m)"); + rightValueLabel->SetText("180"); + rightUnitLabel->SetText("累计下降(m)"); + } else if (trainingType == TRAINING_TYPE_INDOOR_SWIMMING) { + topValueLabel->SetText("105"); + topUnitLabel->SetText("心率(次/分钟)"); + leftValueLabel->SetText("235"); + leftUnitLabel->SetText("热量(kcal)"); + rightValueLabel->SetText("125"); + rightUnitLabel->SetText("距离(km)"); + } else if (trainingType == TRAINING_TYPE_OUTDOOR_SWIMMING) { + topValueLabel->SetText("105"); + topUnitLabel->SetText("心率(次/分钟)"); + leftValueLabel->SetText("235"); + leftUnitLabel->SetText("热量(kcal)"); + rightValueLabel->SetText("125"); + rightUnitLabel->SetText("距离(km)"); + } + topValueLabel->Invalidate(); + topUnitLabel->Invalidate(); + leftValueLabel->Invalidate(); + leftUnitLabel->Invalidate(); + rightValueLabel->Invalidate(); + rightUnitLabel->Invalidate(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/MenuView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/MenuView.cpp new file mode 100644 index 000000000..e313fd6d2 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/MenuView.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Menu View + * Create: 2025-03-22 + */ +#include "training/MenuView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TrainingPresenter.h" + +namespace OHOS { +static constexpr uint16_t TITLI_LABEL_FONT = 50; +static constexpr uint16_t TITLI_LABEL_X = 133; +static constexpr uint16_t TITLI_LABEL_Y = 36; +static constexpr uint16_t TITLI_LABEL_W = 200; +static constexpr uint16_t TITLI_LABEL_H = 60; +static constexpr uint16_t LIST_X = 42; +static constexpr uint16_t LIST_Y = 95; +static constexpr uint16_t LIST_W = 420; +static constexpr uint16_t LIST_H = 305; + +static MenuView *g_pMenuView{nullptr}; + +MenuView::MenuView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MenuView::MenuView"); + g_pMenuView = this; +} + +MenuView::~MenuView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MenuView::~MenuView"); + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (titleLabel != nullptr) { + delete titleLabel; + titleLabel = nullptr; + } + if (trainingList != nullptr) { + delete trainingList; + trainingList = nullptr; + } + if (listAdapter_ != nullptr) { + delete listAdapter_; + listAdapter_ = nullptr; + } + g_pMenuView = nullptr; +} + +MenuView *MenuView::GetInstance() +{ + return g_pMenuView; +} + +void MenuView::CreateUILabel() +{ + // Add Label to App + if (titleLabel == nullptr) { + titleLabel = new UILabel(); + } + titleLabel->SetPosition(TITLI_LABEL_X, TITLI_LABEL_Y); + titleLabel->Resize(TITLI_LABEL_W, TITLI_LABEL_H); + + // Set additional property + titleLabel->SetText("体能训练"); + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLI_LABEL_FONT); + + // Add to rootView + group->Add(titleLabel); +} + +void MenuView::CreateUIList() +{ + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::TrainingPresenter::GetInstance(); + if (clickListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener nullptr"); + return; + } + + // Add List to App + if (trainingList == nullptr) { + trainingList = new UIList(); + } + trainingList->SetPosition(LIST_X, LIST_Y); + trainingList->Resize(LIST_W, LIST_H); + + // Set additional property + if (listAdapter_ == nullptr) { + listAdapter_ = new TrainingAdapter(); + } + listAdapter_->SetItemClickListener(clickListener); + std::list trainingItemList(trainings, trainings + TRAINING_TYPE_MAX); + listAdapter_->SetData(trainingItemList); + + trainingList->SetAdapter(listAdapter_); + trainingList->RefreshList(); + + // Add to rootView + group->Add(trainingList); +} + +UIViewGroup *MenuView::InitShowUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MenuView init"); + if (group == nullptr) { + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + } + CreateUILabel(); + CreateUIList(); + UIView::OnDragListener *trainingDragListener = (UIView::OnDragListener *)OHOS::TrainingPresenter::GetInstance(); + if (trainingDragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "trainingDragListener GetInstance fail"); + return nullptr; + } + group->SetOnDragListener(trainingDragListener); + group->SetViewId(MENU_VIEW_ID); + group->SetDraggable(true); + group->SetTouchable(true); + return group; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/PauseView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/PauseView.cpp new file mode 100644 index 000000000..17e343462 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/PauseView.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Pause View + * Create: 2025-03-22 + */ +#include "training/PauseView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TrainingPresenter.h" + +namespace OHOS { +static constexpr uint16_t TIME_LABEL_FONT = 30; +static constexpr uint16_t TIME_LABEL_X = 194; +static constexpr uint16_t TIME_LABEL_Y = 42; +static constexpr uint16_t TIME_LABEL_W = 200; +static constexpr uint16_t TIME_LABEL_H = 60; +static constexpr uint16_t TEXT_LABEL_FONT = 70; +static constexpr uint16_t TEXT_LABEL_X = 128; +static constexpr uint16_t TEXT_LABEL_Y = 133; +static constexpr uint16_t TEXT_LABEL_W = 337; +static constexpr uint16_t TEXT_LABEL_H = 152; +static constexpr uint16_t BUTTON_FONT = 40; +static constexpr uint16_t BUTTON_X = 136; +static constexpr uint16_t BUTTON_Y1 = 236; +static constexpr uint16_t BUTTON_Y2 = 329; +static constexpr uint16_t BUTTON_W = 193; +static constexpr uint16_t BUTTON_H = 75; + +#define BUTTON_TEXT_CONTINUE "ç»§ç»­" +#define BUTTON_TEXT_FINISH "结束" + +static PauseView *g_pPauseView{nullptr}; + +PauseView::PauseView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PauseView::PauseView"); + g_pPauseView = this; +} + +PauseView::~PauseView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PauseView::~PauseView"); + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (timeLabel != nullptr) { + delete timeLabel; + timeLabel = nullptr; + } + if (textLabel != nullptr) { + delete textLabel; + textLabel = nullptr; + } + if (continueButton != nullptr) { + delete continueButton; + continueButton = nullptr; + } + if (finishButton != nullptr) { + delete finishButton; + finishButton = nullptr; + } + g_pPauseView = nullptr; +} + +PauseView *PauseView::GetInstance() +{ + return g_pPauseView; +} + +void PauseView::CreateUILabel() +{ + // Add Label to App + if (timeLabel == nullptr) { + timeLabel = new UILabel(); + } + timeLabel->SetPosition(TIME_LABEL_X, TIME_LABEL_Y); + timeLabel->Resize(TIME_LABEL_W, TIME_LABEL_H); + + // Set additional property + timeLabel->SetText("11:59"); + timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIME_LABEL_FONT); + + // Add to rootView + group->Add(timeLabel); + + // Add Label to App + if (textLabel == nullptr) { + textLabel = new UILabel(); + } + textLabel->SetPosition(TEXT_LABEL_X, TEXT_LABEL_Y); + textLabel->Resize(TEXT_LABEL_W, TEXT_LABEL_H); + + // Set additional property + textLabel->SetText("已暂停"); + textLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + textLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + textLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TEXT_LABEL_FONT); + + // Add to rootView + group->Add(textLabel); +} + +void PauseView::CreateUIButton() +{ + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::TrainingPresenter::GetInstance(); + if (clickListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener nullptr"); + return; + } + // Add LabelButtonExt to App + if (continueButton == nullptr) { + continueButton = new UILabelButton(); + } + continueButton->SetPosition(BUTTON_X, BUTTON_Y1); + continueButton->Resize(BUTTON_W, BUTTON_H); + continueButton->SetViewId(TRAINING_PAUSE_CONTINUE_BUTTON); + + // Set additional property + continueButton->SetText(BUTTON_TEXT_CONTINUE); + continueButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_FONT); + continueButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + continueButton->SetOnClickListener(clickListener); + + // Add to rootView + group->Add(continueButton); + + // Add LabelButtonExt to App + if (finishButton == nullptr) { + finishButton = new UILabelButton(); + } + finishButton->SetPosition(BUTTON_X, BUTTON_Y2); + finishButton->Resize(BUTTON_W, BUTTON_H); + finishButton->SetViewId(TRAINING_PAUSE_FINISH_BUTTON); + finishButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffbc321e); + + // Set additional property + finishButton->SetText(BUTTON_TEXT_FINISH); + finishButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_FONT); + finishButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + finishButton->SetOnClickListener(clickListener); + + // Add to rootView + group->Add(finishButton); +} + +UIViewGroup *PauseView::InitShowUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PauseView init"); + if (group == nullptr) { + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + } + CreateUILabel(); + CreateUIButton(); + UIView::OnDragListener *trainingDragListener = (UIView::OnDragListener *)OHOS::TrainingPresenter::GetInstance(); + if (trainingDragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "trainingDragListener GetInstance fail"); + return nullptr; + } + group->SetOnDragListener(trainingDragListener); + group->SetViewId(PAUSE_VIEW_ID); + group->SetDraggable(true); + group->SetTouchable(true); + return group; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/PrepareView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/PrepareView.cpp new file mode 100644 index 000000000..1e2e14af0 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/PrepareView.cpp @@ -0,0 +1,345 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Prepare View + * Create: 2025-03-22 + */ +#include "training/PrepareView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TrainingPresenter.h" +#include "screensetting/ScreenModels.h" +#include "ui_resource_image.h" + +namespace OHOS { + +static constexpr uint16_t HEARTBEAT_IMAGE_X = 366; +static constexpr uint16_t HEARTBEAT_IMAGE_Y = 165; +static constexpr uint16_t HEARTBEAT_IMAGE_W = 56; +static constexpr uint16_t HEARTBEAT_IMAGE_H = 56; +static constexpr uint16_t HEARTBEAT_IMAGE_NUM = 19; +static constexpr uint16_t HEARTBEAT_DELAY = 50; +static constexpr uint16_t HEARTBEAT_LABEL_X = 363; +static constexpr uint16_t HEARTBEAT_LABEL_Y = 241; +static constexpr uint16_t HEARTBEAT_LABEL_W = 86; +static constexpr uint16_t HEARTBEAT_LABEL_H = 30; +static constexpr uint16_t HEARTBEAT_LABEL_FONT = 30; +static constexpr uint16_t BATTERY_X = 175; +static constexpr uint16_t BATTERY_Y = 84; +static constexpr uint16_t BATTERY_LABEL_FONT = 30; +static constexpr uint16_t BATTERY_LABEL_X = 232; +static constexpr uint16_t BATTERY_LABEL_Y = 75; +static constexpr uint16_t BATTERY_LABEL_W = 86; +static constexpr uint16_t BATTERY_LABEL_H = 30; +static constexpr uint16_t GPS_X = 30; +static constexpr uint16_t GPS_Y = 167; +static constexpr uint16_t GPS_W = 56; +static constexpr uint16_t GPS_H = 56; +static constexpr uint16_t GPS_LABEL_FONT = 30; +static constexpr uint16_t GPS_LABEL_X = 29; +static constexpr uint16_t GPS_LABEL_Y = 227; +static constexpr uint16_t GPS_LABEL_W = 200; +static constexpr uint16_t GPS_LABEL_H = 60; +static constexpr uint16_t TIME_LABEL_FONT = 30; +static constexpr uint16_t TIME_LABEL_X = 177; +static constexpr uint16_t TIME_LABEL_Y = 36; +static constexpr uint16_t TIME_LABEL_W = 100; +static constexpr uint16_t TIME_LABEL_H = 30; +static constexpr uint16_t LOCATING_LABEL_FONT = 25; +static constexpr uint16_t LOCATING_LABEL_X = 127; +static constexpr uint16_t LOCATING_LABEL_Y = 348; +static constexpr uint16_t LOCATING_LABEL_W = 200; +static constexpr uint16_t LOCATING_LABEL_H = 80; +static constexpr uint16_t WALK_BUTTON_X = 138; +static constexpr uint16_t WALK_BUTTON_Y = 136; +static constexpr uint16_t WALK_BUTTON_W = 180; +static constexpr uint16_t WALK_BUTTON_H = 180; +static constexpr uint16_t START_BUTTON_X = 196; +static constexpr uint16_t START_BUTTON_Y = 373; +static constexpr uint16_t START_BUTTON_W = 73; +static constexpr uint16_t START_BUTTON_H = 73; +static constexpr uint16_t START_BUTTON_FONT = 30; + +static PrepareView *g_pPrepareView{nullptr}; + +PrepareView::PrepareView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PrepareView::PrepareView"); + g_pPrepareView = this; +} + +PrepareView::~PrepareView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PrepareView::~PrepareView"); + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (timeLabel != nullptr) { + delete timeLabel; + timeLabel = nullptr; + } + if (battery != nullptr) { + delete battery; + battery = nullptr; + } + if (batteryLabel != nullptr) { + delete batteryLabel; + batteryLabel = nullptr; + } + if (gpsImageView != nullptr) { + delete gpsImageView; + gpsImageView = nullptr; + } + if (gpsLabel != nullptr) { + delete gpsLabel; + gpsLabel = nullptr; + } + if (heartRateImageView != nullptr) { + delete heartRateImageView; + heartRateImageView = nullptr; + } + if (heartRateLabel != nullptr) { + delete heartRateLabel; + heartRateLabel = nullptr; + } + if (locatingLabel != nullptr) { + delete locatingLabel; + locatingLabel = nullptr; + } + if (startButton != nullptr) { + delete startButton; + startButton = nullptr; + } + if (iconImageView != nullptr) { + delete iconImageView; + iconImageView = nullptr; + } + g_pPrepareView = nullptr; +} + +PrepareView *PrepareView::GetInstance() +{ + return g_pPrepareView; +} + +bool PrepareView::InitTimeLableVIew() +{ + timeLabel = new UILabel(); + if (timeLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel new fail"); + return false; + } + timeLabel->SetPosition(TIME_LABEL_X, TIME_LABEL_Y, TIME_LABEL_W, TIME_LABEL_H); + timeLabel->SetText("11:59"); + timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIME_LABEL_FONT); + timeLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + timeLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + group->Add(timeLabel); + return true; +} + +bool PrepareView::InitLocatingLableVIew() +{ + locatingLabel = new UILabel(); + if (locatingLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locatingLabel new fail"); + return false; + } + locatingLabel->SetPosition(LOCATING_LABEL_X, LOCATING_LABEL_Y, LOCATING_LABEL_W, LOCATING_LABEL_H); + locatingLabel->SetText("定位中\n请在空旷处等待"); + locatingLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LOCATING_LABEL_FONT); + locatingLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + locatingLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + group->Add(locatingLabel); + return true; +} + +bool PrepareView::InitBatteryView() // 加载电量 +{ + battery = new UIImageView(); // 电量状态显示 + if (battery == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery new fail"); + return false; + } + battery->SetPosition(BATTERY_X, BATTERY_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, battery, DROPDOWN_DROPDOWN_BATTERY); + group->Add(battery); + + batteryLabel = new UILabel(); + if (batteryLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel new fail"); + return false; + } + batteryLabel->SetPosition(BATTERY_LABEL_X, BATTERY_LABEL_Y, BATTERY_LABEL_W, BATTERY_LABEL_H); + batteryLabel->SetText("30%"); + batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BATTERY_LABEL_FONT); + batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + group->Add(batteryLabel); + return true; +} + +bool PrepareView::InitCenterView() +{ + iconImageView = new UIButton(); // 步行状态显示 + if (iconImageView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "iconImageView new fail"); + return false; + } + + iconImageView->SetPosition(WALK_BUTTON_X, WALK_BUTTON_Y, WALK_BUTTON_W, WALK_BUTTON_H); + + group->Add(iconImageView); + return true; +} + +bool PrepareView::InitGPSView() +{ + // Add ImageView to App + if (gpsImageView == nullptr) { + gpsImageView = new UIImageView(); + } + gpsImageView->SetPosition(GPS_X, GPS_Y); + gpsImageView->Resize(GPS_W, GPS_H); + + // Set additional property + + // Add to rootView + group->Add(gpsImageView); + + // Add Label to App + if (gpsLabel == nullptr) { + gpsLabel = new UILabel(); + } + gpsLabel->SetPosition(GPS_LABEL_X, GPS_LABEL_Y); + gpsLabel->Resize(GPS_LABEL_W, GPS_LABEL_H); + + // Set additional property + gpsLabel->SetText("GPS"); + gpsLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + gpsLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + gpsLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, GPS_LABEL_FONT); + + // Add to rootView + group->Add(gpsLabel); + return true; +} + +bool PrepareView::InitHeartrateView() +{ + // Add ImageView to App + if (heartRateImageView == nullptr) { + heartRateImageView = new UIImageView(); + } + heartRateImageView->SetPosition(HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y); + heartRateImageView->Resize(HEARTBEAT_IMAGE_W, HEARTBEAT_IMAGE_H); + + // Add to rootView + group->Add(heartRateImageView); + + heartRateLabel = new UILabel(); + if (heartRateLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateLabel new fail"); + return false; + } + heartRateLabel->SetPosition(HEARTBEAT_LABEL_X, HEARTBEAT_LABEL_Y, HEARTBEAT_LABEL_W, HEARTBEAT_LABEL_H); + heartRateLabel->SetText("95"); + heartRateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, HEARTBEAT_LABEL_FONT); + heartRateLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + group->Add(heartRateLabel); + return true; +} + +bool PrepareView::InitStartButtonView() +{ + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::TrainingPresenter::GetInstance(); + if (clickListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener nullptr"); + return false; + } + + // Add LabelButtonExt to App + if (startButton == nullptr) { + startButton = new UILabelButton(); + } + startButton->SetPosition(START_BUTTON_X, START_BUTTON_Y); // widget's left position and top position + startButton->Resize(START_BUTTON_W, START_BUTTON_H); // widget's width and height + startButton->SetViewId(TRAINING_PREPARE_START_BUTTON); // Set style + startButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff1500); + + // Set additional property + startButton->SetText("开始"); + startButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, START_BUTTON_FONT); + startButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + startButton->SetOnClickListener(clickListener); + + // Add to rootView + group->Add(startButton); + return true; +} + +UIViewGroup *PrepareView::InitShowUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PrepareView init"); + if (group == nullptr) { + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + } + InitTimeLableVIew(); + InitBatteryView(); + // InitLocatingLableVIew(); + InitCenterView(); + InitGPSView(); + InitHeartrateView(); + InitStartButtonView(); + UIView::OnDragListener *trainingDragListener = (UIView::OnDragListener *)OHOS::TrainingPresenter::GetInstance(); + if (trainingDragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "trainingDragListener GetInstance fail"); + return nullptr; + } + group->SetOnDragListener(trainingDragListener); + group->SetViewId(PREPARE_VIEW_ID); + group->SetDraggable(true); + group->SetTouchable(true); + return group; +} + +void PrepareView::UpdateViewByTrainingType(uint8_t trainingType) +{ + if (trainingType == TRAINING_TYPE_OUTDOOR_RUNNING) { + gpsImageView->SetVisible(true); + gpsLabel->SetVisible(true); + iconImageView->SetImageSrc(PNG_WALK_IMAGE, PNG_WALK_IMAGE); + } else if (trainingType == TRAINING_TYPE_INDOOR_RUNNING) { + gpsImageView->SetVisible(false); + gpsLabel->SetVisible(false); + iconImageView->SetImageSrc(PNG_WALK_IMAGE, PNG_WALK_IMAGE); + } else if (trainingType == TRAINING_TYPE_CYCLING) { + gpsImageView->SetVisible(true); + gpsLabel->SetVisible(true); + iconImageView->SetImageSrc(PNG_WALK_IMAGE, PNG_WALK_IMAGE); + } else if (trainingType == TRAINING_TYPE_CLIMBING) { + gpsImageView->SetVisible(true); + gpsLabel->SetVisible(true); + iconImageView->SetImageSrc(PNG_WALK_IMAGE, PNG_WALK_IMAGE); + } else if (trainingType == TRAINING_TYPE_INDOOR_SWIMMING) { + gpsImageView->SetVisible(false); + gpsLabel->SetVisible(false); + iconImageView->SetImageSrc(PNG_WALK_IMAGE, PNG_WALK_IMAGE); + } else if (trainingType == TRAINING_TYPE_OUTDOOR_SWIMMING) { + gpsImageView->SetVisible(true); + gpsLabel->SetVisible(true); + iconImageView->SetImageSrc(PNG_WALK_IMAGE, PNG_WALK_IMAGE); + } + iconImageView->Invalidate(); + gpsImageView->Invalidate(); + gpsLabel->Invalidate(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/PromptView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/PromptView.cpp new file mode 100644 index 000000000..581a2c555 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/PromptView.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Prompt View + * Create: 2025-03-22 + */ +#include "training/PromptView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TrainingPresenter.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 65; +static constexpr uint16_t LABELS_Y = 100; +static constexpr uint16_t LABELS_W = 324; +static constexpr uint16_t LABELS_H = 160; +static constexpr uint16_t LABELS_FONT = 35; +static constexpr uint16_t BUTTON_X1 = 85; +static constexpr uint16_t BUTTON_X2 = 279; +static constexpr uint16_t BUTTON_Y = 320; +static constexpr uint16_t BUTTON_W = 90; +static constexpr uint16_t BUTTON_H = 90; +static const char *PROMPT_CONTENT = "本次运动距离过短,不会记录数据。是否结束?"; +static PromptView *g_pPromptView{nullptr}; + +PromptView::PromptView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PromptView::PromptView"); + g_pPromptView = this; +} + +PromptView::~PromptView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PromptView::~PromptView"); + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (titleLabel != nullptr) { + delete titleLabel; + titleLabel = nullptr; + } + if (cancelButton != nullptr) { + delete cancelButton; + cancelButton = nullptr; + } + if (confirmButton != nullptr) { + delete confirmButton; + confirmButton = nullptr; + } + g_pPromptView = nullptr; +} + +PromptView *PromptView::GetInstance() +{ + return g_pPromptView; +} + +void PromptView::CreateUILabel() +{ + if (titleLabel == nullptr) { + titleLabel = new UILabel(); + if (titleLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PromptView titleLabel new fail"); + return; + } + titleLabel->SetPosition(LABELS_X, LABELS_Y, LABELS_W, LABELS_H); + titleLabel->SetText(PROMPT_CONTENT); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABELS_FONT); + titleLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + group->Add(titleLabel); + } +} + +void PromptView::CreateUIButton() +{ + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::TrainingPresenter::GetInstance(); + if (clickListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener nullptr"); + return; + } + + if (cancelButton == nullptr) { + cancelButton = new UIButton(); + if (cancelButton == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PromptView cancelButton new fail"); + return; + } + cancelButton->SetPosition(BUTTON_X1, BUTTON_Y, BUTTON_W, BUTTON_H); + cancelButton->SetViewId(TRAINING_PROMPT_CANCEL_BUTTON); + cancelButton->SetImageSrc(ALARM_DELETE_ADD_PATH, ALARM_DELETE_ADD_PATH); + cancelButton->SetOnClickListener(clickListener); + group->Add(cancelButton); + } + if (confirmButton == nullptr) { + confirmButton = new UIButton(); + if (confirmButton == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PromptView confirmButton new fail"); + return; + } + confirmButton->SetPosition(BUTTON_X2, BUTTON_Y, BUTTON_W, BUTTON_H); + confirmButton->SetViewId(TRAINING_PROMPT_CONFIRM_BUTTON); + confirmButton->SetImageSrc(ALARM_TRUE_ADD_PATH, ALARM_TRUE_ADD_PATH); + confirmButton->SetOnClickListener(clickListener); + group->Add(confirmButton); + } +} + +UIViewGroup *PromptView::InitShowUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PromptView InitShowUpView"); + if (group == nullptr) { + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + } + CreateUILabel(); + CreateUIButton(); + UIView::OnDragListener *trainingDragListener = (UIView::OnDragListener *)OHOS::TrainingPresenter::GetInstance(); + if (trainingDragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "trainingDragListener GetInstance fail"); + return nullptr; + } + group->SetOnDragListener(trainingDragListener); + group->SetViewId(PROMPT_VIEW_ID); + group->SetDraggable(true); + group->SetTouchable(true); + return group; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetAdapter.cpp new file mode 100644 index 000000000..a19958b65 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetAdapter.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TargetAdapter + * Author: + * Create: 2025-11-23 + */ +#include "training/TargetAdapter.h" +#include "training/TargetItemView.h" + +namespace OHOS { +TargetAdapter::TargetAdapter() {} + +TargetAdapter::~TargetAdapter() +{ + listData_.clear(); +} + +uint16_t TargetAdapter::GetCount(void) +{ + return listData_.size(); +} + +void TargetAdapter::SetData(const std::list &data) +{ + if (!listData_.empty()) { + listData_.clear(); + } + listData_ = data; +} + +UIView *TargetAdapter::GetView(UIView *inView, int16_t index) +{ + if (listData_.empty()) { + return nullptr; + } + if (index < 0) { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData_.size()) { + return nullptr; + } + + std::list::iterator it = listData_.begin(); + for (int i = 0; i < index; i++) { + it++; + } + TargetItem itemData = *it; + TargetItemView *item = nullptr; + if (inView == nullptr) { + item = new TargetItemView(); + } else { + item = static_cast(inView); + } + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + return item; +} + +void TargetAdapter::AddListItem(const TargetItem &item) +{ + listData_.push_back(item); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetItemView.cpp new file mode 100644 index 000000000..6814bb1b5 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetItemView.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TargetItemView + * Author: + * Create: 2025-02-15 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TargetItemView.h" + +namespace OHOS { +static constexpr uint16_t ITEM_X = 0; +static constexpr uint16_t ITEM_Y = 0; +static constexpr uint16_t ITEM_W = 382; +static constexpr uint16_t ITEM_H = 100; +static constexpr uint16_t ICON_X = 0; +static constexpr uint16_t ICON_Y = 0; +static constexpr uint16_t LABEL_X = 100; +static constexpr uint16_t LABEL_Y = 0; +static constexpr uint16_t LABEL_W = 200; +static constexpr uint16_t LABEL_H = 100; +static constexpr uint16_t LABEL_FONT = 35; +static constexpr uint16_t IMAGE_W = 300; +static constexpr uint16_t IMAGE_H = 0; + +TargetItemView::TargetItemView() +{ + InitView(); +} + +TargetItemView::~TargetItemView() +{ + Remove(&sIcon); + Remove(&sLabel); + Remove(&sNextImage); +} + +bool TargetItemView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TargetItemView::InitView"); + SetPosition(ITEM_X, ITEM_Y, ITEM_W, ITEM_H); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetTouchable(true); + + sIcon.SetPosition(ICON_X, ICON_Y); + sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + sLabel.SetPosition(LABEL_X, LABEL_Y); + sLabel.Resize(LABEL_W, LABEL_H); + sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + sLabel.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + sLabel.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + sNextImage.SetSrc(PNG_SETTING_NEXT_IMAGE); + sNextImage.SetPosition(IMAGE_W, IMAGE_H); + sNextImage.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + Add(&sIcon); + Add(&sLabel); + Add(&sNextImage); + return true; +} + +void TargetItemView::SetItemInfo(const TargetItem itemInfo) +{ + sItemInfo = itemInfo; + sIcon.SetSrc(itemInfo.icon); + sLabel.SetText(itemInfo.label); + SetViewId(itemInfo.viewId); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetSettingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetSettingView.cpp new file mode 100644 index 000000000..1e2eee87c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetSettingView.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TargetSetting View + * Create: 2025-03-22 + */ +#include "training/TargetSettingView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TrainingPresenter.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 153; +static constexpr uint16_t LABELS_Y = 30; +static constexpr uint16_t LABELS_W = 200; +static constexpr uint16_t LABELS_H = 50; +static constexpr uint16_t LABELS_FONT = 40; +static constexpr uint16_t PICKER_X = 160; +static constexpr uint16_t PICKER_Y = 85; +static constexpr uint16_t PICKER_W = 199; +static constexpr uint16_t PICKER_H = 241; +static constexpr uint16_t PICKER_ITEM_H = 50; +static constexpr uint16_t BUTTON_X = 87; +static constexpr uint16_t BUTTON_Y = 351; +static constexpr uint16_t BUTTON_W = 279; +static constexpr uint16_t BUTTON_H = 116; +static constexpr uint16_t BUTTON_FONT = 40; +static constexpr uint8_t BACKGROUND_FONT = 40; +static constexpr uint8_t HIGHTLIGHT_FONT = 50; + +static TargetSettingView *g_pTargetSettingView{nullptr}; + +TargetSettingView::TargetSettingView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TargetSettingView::TargetSettingView"); + g_pTargetSettingView = this; +} + +TargetSettingView::~TargetSettingView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TargetSettingView::~TargetSettingView"); + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (titleLabel != nullptr) { + delete titleLabel; + titleLabel = nullptr; + } + if (picker != nullptr) { + delete picker; + picker = nullptr; + } + if (confirmButton != nullptr) { + delete confirmButton; + confirmButton = nullptr; + } + g_pTargetSettingView = nullptr; +} + +TargetSettingView *TargetSettingView::GetInstance() +{ + return g_pTargetSettingView; +} + +void TargetSettingView::CreateUILabel() +{ + // Add Label to App + if (titleLabel == nullptr) { + titleLabel = new UILabel(); + } + titleLabel->SetPosition(LABELS_X, LABELS_Y); + titleLabel->Resize(LABELS_W, LABELS_H); + titleLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + // Set additional property + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABELS_FONT); + + // Add to rootView + group->Add(titleLabel); +} + +void TargetSettingView::CreateUIPicker() +{ + // Add Picker to App + if (picker == nullptr) { + picker = new UIPicker(); + } + picker->SetPosition(PICKER_X, PICKER_Y); + picker->Resize(PICKER_W, PICKER_H); + picker->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + // Set additional property + picker->SetItemHeight(PICKER_ITEM_H); + + picker->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); + picker->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); + + // Add to rootView + group->Add(picker); +} + +void TargetSettingView::CreateUIButton() +{ + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::TrainingPresenter::GetInstance(); + if (clickListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener nullptr"); + return; + } + + // Add LabelButtonExt to App + if (confirmButton == nullptr) { + confirmButton = new UILabelButton(); + } + confirmButton->SetPosition(BUTTON_X, BUTTON_Y); + confirmButton->Resize(BUTTON_W, BUTTON_H); + confirmButton->SetViewId(TARGET_SETTING_CONFIRM_BUTTON); + confirmButton->SetTouchable(true); + + // Set additional property + confirmButton->SetText("确定"); + confirmButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_FONT); + + confirmButton->SetOnClickListener(clickListener); + + // Add to rootView + group->Add(confirmButton); +} + +UIViewGroup *TargetSettingView::InitShowUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TargetSettingView InitShowUpView"); + if (group == nullptr) { + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + } + CreateUILabel(); + CreateUIPicker(); + CreateUIButton(); + UIView::OnDragListener *trainingDragListener = (UIView::OnDragListener *)OHOS::TrainingPresenter::GetInstance(); + if (trainingDragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "trainingDragListener GetInstance fail"); + return nullptr; + } + group->SetOnDragListener(trainingDragListener); + group->SetViewId(TARGET_SETTING_VIEW_ID); + group->SetDraggable(true); + group->SetTouchable(true); + return group; +} + +void TargetSettingView::UpdateViewByTargetType(uint8_t targetType) +{ + if (targetType == TRAINING_TARGET_DISTANCE) { + titleLabel->SetText("距离"); + const char *uiDistanceData[] = {"1km", "3km", "5km", "10km"}; + picker->SetValues(uiDistanceData, sizeof(uiDistanceData) / sizeof(uiDistanceData[0])); + picker->SetTextColor(Color::Gray(), Color::Teal()); + confirmButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Teal().full); + } else if (targetType == TRAINING_TARGET_TIME) { + titleLabel->SetText("时间"); + const char *uiTimeData[] = {"10分钟", "20分钟", "30分钟", "60分钟"}; + picker->SetValues(uiTimeData, sizeof(uiTimeData) / sizeof(uiTimeData[0])); + picker->SetTextColor(Color::Gray(), Color::Orange()); + confirmButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Orange().full); + } else if (targetType == TRAINING_TARGET_CALORIE) { + titleLabel->SetText("热量"); + const char *uiCalorieData[] = {"100千卡", "200千卡", "300千卡", "500千卡", "1000千卡"}; + picker->SetValues(uiCalorieData, sizeof(uiCalorieData) / sizeof(uiCalorieData[0])); + picker->SetTextColor(Color::Gray(), Color::Magenta()); + confirmButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Magenta().full); + } + titleLabel->Invalidate(); + picker->Invalidate(); + confirmButton->Invalidate(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetView.cpp new file mode 100644 index 000000000..46d55c0d8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TargetView.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: Target View + * Create: 2025-03-22 + */ +#include "training/TargetView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TrainingPresenter.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 133; +static constexpr uint16_t LABELS_Y = 36; +static constexpr uint16_t LABELS_W = 200; +static constexpr uint16_t LABELS_H = 60; +static constexpr uint16_t LABELS_FONT = 50; +static constexpr uint16_t LIST_X = 42; +static constexpr uint16_t LIST_Y = 95; +static constexpr uint16_t LIST_W = 382; +static constexpr uint16_t LIST_H = 305; + +static TargetView *g_pTargetView{nullptr}; + +TargetView::TargetView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TargetView::TargetView"); + g_pTargetView = this; +} + +TargetView::~TargetView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TargetView::~TargetView"); + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (titleLabel != nullptr) { + delete titleLabel; + titleLabel = nullptr; + } + if (targetList != nullptr) { + delete targetList; + targetList = nullptr; + } + if (listAdapter_ != nullptr) { + delete listAdapter_; + listAdapter_ = nullptr; + } + g_pTargetView = nullptr; +} + +TargetView *TargetView::GetInstance() +{ + return g_pTargetView; +} + +void TargetView::CreateUILabel() +{ + // Add Label to App + if (titleLabel == nullptr) { + titleLabel = new UILabel(); + } + titleLabel->SetPosition(LABELS_X, LABELS_Y); + titleLabel->Resize(LABELS_W, LABELS_H); + + // Set additional property + titleLabel->SetText("目标"); + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABELS_FONT); + + // Add to rootView + group->Add(titleLabel); +} + +void TargetView::CreateUIList() +{ + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::TrainingPresenter::GetInstance(); + if (clickListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener nullptr"); + return; + } + + // Add List to App + if (targetList == nullptr) { + targetList = new UIList(); + } + targetList->SetPosition(LIST_X, LIST_Y); + targetList->Resize(LIST_W, LIST_H); + targetList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + + // Set additional property + if (listAdapter_ == nullptr) { + listAdapter_ = new TargetAdapter(); + } + listAdapter_->SetItemClickListener(clickListener); + std::list targetItemList(targets, targets + TRAINING_TARGET_MAX); + listAdapter_->SetData(targetItemList); + + targetList->SetAdapter(listAdapter_); + targetList->RefreshList(); + + // Add to rootView + group->Add(targetList); +} + +UIViewGroup *TargetView::InitShowUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TargetView InitShowUpView"); + if (group == nullptr) { + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + } + CreateUILabel(); + CreateUIList(); + UIView::OnDragListener *trainingDragListener = (UIView::OnDragListener *)OHOS::TrainingPresenter::GetInstance(); + if (trainingDragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "trainingDragListener GetInstance fail"); + return nullptr; + } + group->SetOnDragListener(trainingDragListener); + group->SetViewId(TARGET_VIEW_ID); + group->SetDraggable(true); + group->SetTouchable(true); + return group; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingAdapter.cpp new file mode 100644 index 000000000..9ae2d4c94 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingAdapter.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingAdapter.cpp + * Author: + * Create: 2025-11-23 + */ +#include "training/TrainingAdapter.h" +#include "training/TrainingItemView.h" + +namespace OHOS { +TrainingAdapter::TrainingAdapter() {} + +TrainingAdapter::~TrainingAdapter() +{ + listData_.clear(); +} + +uint16_t TrainingAdapter::GetCount(void) +{ + return listData_.size(); +} + +void TrainingAdapter::SetData(const std::list &data) +{ + if (!listData_.empty()) { + listData_.clear(); + } + listData_ = data; +} + +UIView *TrainingAdapter::GetView(UIView *inView, int16_t index) +{ + if (listData_.empty()) { + return nullptr; + } + if (index < 0) { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData_.size()) { + return nullptr; + } + + std::list::iterator it = listData_.begin(); + for (int i = 0; i < index; i++) { + it++; + } + TrainingItem itemData = *it; + TrainingItemView *item = nullptr; + if (inView == nullptr) { + item = new TrainingItemView(); + } else { + item = static_cast(inView); + } + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + return item; +} + +void TrainingAdapter::AddListItem(const TrainingItem &item) +{ + listData_.push_back(item); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingItemView.cpp new file mode 100644 index 000000000..ff03e79b8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingItemView.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: temperature + * Author: + * Create: 2025-02-15 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include "training/TrainingItemView.h" +#include "screensetting/ScreenModels.h" + +namespace OHOS { +static constexpr uint16_t ITEM_X = 0; +static constexpr uint16_t ITEM_Y = 0; +static constexpr uint16_t ITEM_W = 382; +static constexpr uint16_t ITEM_H = 100; +static constexpr uint16_t ICON_X = 0; +static constexpr uint16_t ICON_Y = 0; +static constexpr uint16_t LABEL_X = 100; +static constexpr uint16_t LABEL_Y = 0; +static constexpr uint16_t LABEL_W = 200; +static constexpr uint16_t LABEL_H = 100; +static constexpr uint16_t LABEL_FONT = 35; +static constexpr uint16_t IMAGE_W = 300; +static constexpr uint16_t IMAGE_H = 0; + +TrainingItemView::TrainingItemView() +{ + InitView(); +} + +TrainingItemView::~TrainingItemView() +{ + Remove(&sIcon); + Remove(&sLabel); + Remove(&sSettingImage); +} + +bool TrainingItemView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingItemView::InitView"); + SetPosition(ITEM_X, ITEM_Y, ITEM_W, ITEM_H); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetTouchable(true); + + sIcon.SetPosition(ICON_X, ICON_Y); + sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + sLabel.SetPosition(LABEL_X, LABEL_Y); + sLabel.Resize(LABEL_W, LABEL_H); + sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + sLabel.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + sLabel.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, &sSettingImage, DROPDOWN_DROPDOWN_SETTING); + sSettingImage.SetPosition(IMAGE_W, IMAGE_H); + sSettingImage.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + Add(&sIcon); + Add(&sLabel); + Add(&sSettingImage); + return true; +} + +void TrainingItemView::SetItemInfo(const TrainingItem itemInfo) +{ + sItemInfo = itemInfo; + sIcon.SetSrc(itemInfo.icon); + sLabel.SetText(itemInfo.label); + SetViewId(itemInfo.viewId); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingModel.cpp new file mode 100644 index 000000000..9efb70247 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingModel.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingModel.cpp + * Author: + * Create: 2025-11-23 + */ + +#include "training/TrainingModel.h" + +namespace OHOS { +TrainingModel::TrainingModel() {} + +TrainingModel::~TrainingModel() {} + +TrainingModel &TrainingModel::GetInstance() +{ + static TrainingModel instance; + return instance; +} + +void TrainingModel::SetCurView(int16_t viewNum) +{ + curView_ = viewNum; +} + +int16_t TrainingModel::GetCurView(void) +{ + return curView_; +} + +void TrainingModel::SetCurTrainingType(int8_t trainingType) +{ + trainingType_ = trainingType; +} + +int8_t TrainingModel::GetCurTrainingType(void) +{ + return trainingType_; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingPresenter.cpp new file mode 100644 index 000000000..5c34aa19f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingPresenter.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: SettingPresenter.cpp + * Author: + * Create: 2025-11-23 + */ + +#include "training/TrainingModel.h" +#include "training/TrainingPresenter.h" +#include "NativeRegisterManager.h" +namespace OHOS { + +REGIST_MENU(VIEW_TRAINING, TrainingView, TrainingPresenter, PNG_APPLIST_WALK_IMAGE, PNG_APPLIST_DEFAULT_IMG, + "体能训练"); + +static TrainingPresenter *g_trainingPresenter = nullptr; +TrainingPresenter::TrainingPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::TrainingPresenter"); + trainingModel_ = &TrainingModel::GetInstance(); + g_trainingPresenter = this; +} + +TrainingPresenter::~TrainingPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::~TrainingPresenter"); + g_trainingPresenter = nullptr; +} + +TrainingPresenter *TrainingPresenter::GetInstance(void) +{ + return g_trainingPresenter; +} + +void TrainingPresenter::OnResume(void) +{ + Presenter::OnResume(); +} + +void TrainingPresenter::OnPause(void) +{ + Presenter::OnPause(); + return; +} + +void TrainingPresenter::ClickStartButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick ClickStartButton"); + view_->ChangeView(TRAINING_VIEW_PREPARE, TRAINING_VIEW_DATA); + DataView::GetInstance()->UpdateDataViewByType(); +} + +void TrainingPresenter::ClickCountineButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick ClickCountineButton"); + view_->ChangeView(TRAINING_VIEW_PAUSE, TRAINING_VIEW_DATA); + DataView::GetInstance()->UpdateDataViewByType(); +} + +void TrainingPresenter::ClickFinishButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick ClickFinishButton"); + view_->ChangeView(TRAINING_VIEW_PAUSE, TRAINING_VIEW_PROMPT); +} + +void TrainingPresenter::ClickCancelButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick ClickCancelButton"); + view_->ChangeView(TRAINING_VIEW_PROMPT, TRAINING_VIEW_PAUSE); +} + +void TrainingPresenter::ClickConfirmButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick ClickConfirmButton"); + view_->ChangeView(TRAINING_VIEW_PROMPT, TRAINING_VIEW_MENU); +} + +void TrainingPresenter::TrainingSetting(uint8_t trainingType) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick TrainingSetting, type = %d", trainingType); + view_->ChangeView(TRAINING_VIEW_MENU, TRAINING_VIEW_SETTING); +} + +void TrainingPresenter::StartTraining(uint8_t trainingType) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick TrainingSetting, type = %d", trainingType); + view_->ChangeView(TRAINING_VIEW_MENU, TRAINING_VIEW_PREPARE); + trainingModel_->SetCurTrainingType(trainingType); + PrepareView::GetInstance()->UpdateViewByTrainingType(trainingType); +} + +void TrainingPresenter::EnterTarget(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick EnterTarget"); + view_->ChangeView(TRAINING_VIEW_SETTING, TRAINING_VIEW_TARGET); +} + +void TrainingPresenter::SettingTarget(uint8_t targetType) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick SettingTarget, type = %d", targetType); + view_->ChangeView(TRAINING_VIEW_TARGET, TRAINING_VIEW_TARGET_SETTING); + TargetSettingView::GetInstance()->UpdateViewByTargetType(targetType); +} + +void TrainingPresenter::ConfirmTargetSetting(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresenter::OnClick ConfirmTargetSetting"); + view_->ChangeView(TRAINING_VIEW_TARGET_SETTING, TRAINING_VIEW_SETTING); +} + +bool TrainingPresenter::OnClick(UIView &view, const ClickEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingPresent::OnClick view:%s", view.GetViewId()); + bool isSettingClicked = event.GetCurrentPos().x > 350 ? true : false; + if (strcmp(view.GetViewId(), TRAINING_PREPARE_START_BUTTON) == 0) { + ClickStartButton(); + } else if (strcmp(view.GetViewId(), TRAINING_PAUSE_CONTINUE_BUTTON) == 0) { + ClickCountineButton(); + } else if (strcmp(view.GetViewId(), TRAINING_PAUSE_FINISH_BUTTON) == 0) { + ClickFinishButton(); + } else if (strcmp(view.GetViewId(), TRAINING_PROMPT_CANCEL_BUTTON) == 0) { + ClickCancelButton(); + } else if (strcmp(view.GetViewId(), TRAINING_PROMPT_CONFIRM_BUTTON) == 0) { + ClickConfirmButton(); + } else if (strcmp(view.GetViewId(), TRAINING_SETTING_ITEM_TARGET) == 0) { + EnterTarget(); + } else if (strcmp(view.GetViewId(), TRAINING_TARGET_ITEM_DISTANCE) == 0) { + SettingTarget(TRAINING_TARGET_DISTANCE); + } else if (strcmp(view.GetViewId(), TRAINING_TARGET_ITEM_TIME) == 0) { + SettingTarget(TRAINING_TARGET_TIME); + } else if (strcmp(view.GetViewId(), TRAINING_TARGET_ITEM_CALORIE) == 0) { + SettingTarget(TRAINING_TARGET_CALORIE); + } else if (strcmp(view.GetViewId(), TARGET_SETTING_CONFIRM_BUTTON) == 0) { + ConfirmTargetSetting(); + } else if (strcmp(view.GetViewId(), TRAINING_ITEM_OUTDOOR_RUNNING) == 0) { + if (isSettingClicked) { + TrainingSetting(TRAINING_TYPE_OUTDOOR_RUNNING); + } else { + StartTraining(TRAINING_TYPE_OUTDOOR_RUNNING); + } + } else if (strcmp(view.GetViewId(), TRAINING_ITEM_INDOOR_RUNNING) == 0) { + if (isSettingClicked) { + TrainingSetting(TRAINING_TYPE_INDOOR_RUNNING); + } else { + StartTraining(TRAINING_TYPE_INDOOR_RUNNING); + } + } else if (strcmp(view.GetViewId(), TRAINING_ITEM_CYCLING) == 0) { + if (isSettingClicked) { + TrainingSetting(TRAINING_TYPE_CYCLING); + } else { + StartTraining(TRAINING_TYPE_CYCLING); + } + } else if (strcmp(view.GetViewId(), TRAINING_ITEM_CLIMBING) == 0) { + if (isSettingClicked) { + TrainingSetting(TRAINING_TYPE_CLIMBING); + } else { + StartTraining(TRAINING_TYPE_CLIMBING); + } + } else if (strcmp(view.GetViewId(), TRAINING_ITEM_INDOOR_SWIMMING) == 0) { + if (isSettingClicked) { + TrainingSetting(TRAINING_TYPE_INDOOR_SWIMMING); + } else { + StartTraining(TRAINING_TYPE_INDOOR_SWIMMING); + } + } else if (strcmp(view.GetViewId(), TRAINING_ITEM_OUTDOOR_SWIMMING) == 0) { + if (isSettingClicked) { + TrainingSetting(TRAINING_TYPE_OUTDOOR_SWIMMING); + } else { + StartTraining(TRAINING_TYPE_OUTDOOR_SWIMMING); + } + } + return true; +} + +bool TrainingPresenter::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingOnDragListener::OnDrag"); + if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { + if (strcmp(view.GetViewId(), MENU_VIEW_ID) == 0) { + // view_->ChangeView(TRAINING_VIEW_MENU, TRAINING_VIEW_PREPARE); + } else if (strcmp(view.GetViewId(), PREPARE_VIEW_ID) == 0) { + // view_->ChangeView(TRAINING_VIEW_PREPARE, TRAINING_VIEW_DATA); + // DataView::GetInstance()->UpdateDataViewByType(); + } else if (strcmp(view.GetViewId(), DATA_VIEW_ID) == 0) { + view_->ChangeView(TRAINING_VIEW_DATA, TRAINING_VIEW_PAUSE); + } else if (strcmp(view.GetViewId(), PAUSE_VIEW_ID) == 0) { + // view_->ChangeView(TRAINING_VIEW_PAUSE, TRAINING_VIEW_PROMPT); + } else if (strcmp(view.GetViewId(), PROMPT_VIEW_ID) == 0) { + // view_->ChangeView(TRAINING_VIEW_PROMPT, TRAINING_VIEW_MENU); + } + } else if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + if (strcmp(view.GetViewId(), MENU_VIEW_ID) == 0) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } else if (strcmp(view.GetViewId(), PREPARE_VIEW_ID) == 0) { + view_->ChangeView(TRAINING_VIEW_PREPARE, TRAINING_VIEW_MENU); + } else if (strcmp(view.GetViewId(), DATA_VIEW_ID) == 0) { + view_->ChangeView(TRAINING_VIEW_DATA, TRAINING_VIEW_PREPARE); + } else if (strcmp(view.GetViewId(), PAUSE_VIEW_ID) == 0) { + view_->ChangeView(TRAINING_VIEW_PAUSE, TRAINING_VIEW_DATA); + } else if (strcmp(view.GetViewId(), PROMPT_VIEW_ID) == 0) { + view_->ChangeView(TRAINING_VIEW_PROMPT, TRAINING_VIEW_PAUSE); + } else if (strcmp(view.GetViewId(), SETTING_VIEW_ID) == 0) { + view_->ChangeView(TRAINING_VIEW_SETTING, TRAINING_VIEW_MENU); + } else if (strcmp(view.GetViewId(), TARGET_VIEW_ID) == 0) { + view_->ChangeView(TRAINING_VIEW_TARGET, TRAINING_VIEW_SETTING); + } else if (strcmp(view.GetViewId(), TARGET_SETTING_VIEW_ID) == 0) { + view_->ChangeView(TRAINING_VIEW_TARGET_SETTING, TRAINING_VIEW_TARGET); + } + } + return false; +} + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingSettingAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingSettingAdapter.cpp new file mode 100644 index 000000000..f7fa89945 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingSettingAdapter.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingSettingAdapter.cpp + * Author: + * Create: 2025-11-23 + */ +#include "training/TrainingSettingAdapter.h" +#include "training/TrainingSettingItemView.h" + +namespace OHOS { +TrainingSettingAdapter::TrainingSettingAdapter() {} + +TrainingSettingAdapter::~TrainingSettingAdapter() +{ + listData_.clear(); +} + +uint16_t TrainingSettingAdapter::GetCount(void) +{ + return listData_.size(); +} + +void TrainingSettingAdapter::SetData(const std::list &data) +{ + if (!listData_.empty()) { + listData_.clear(); + } + listData_ = data; +} + +UIView *TrainingSettingAdapter::GetView(UIView *inView, int16_t index) +{ + if (listData_.empty()) { + return nullptr; + } + if (index < 0) { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData_.size()) { + return nullptr; + } + + std::list::iterator it = listData_.begin(); + for (int i = 0; i < index; i++) { + it++; + } + TrainingSettingItem itemData = *it; + TrainingSettingItemView *item = nullptr; + if (inView == nullptr) { + item = new TrainingSettingItemView(); + } else { + item = static_cast(inView); + } + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + return item; +} + +void TrainingSettingAdapter::AddListItem(const TrainingSettingItem &item) +{ + listData_.push_back(item); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingSettingItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingSettingItemView.cpp new file mode 100644 index 000000000..4d135b462 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingSettingItemView.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingSettingItemView.cpp + * Author: + * Create: 2025-02-15 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TrainingSettingItemView.h" + +namespace OHOS { +static constexpr uint16_t ITEM_X = 0; +static constexpr uint16_t ITEM_Y = 0; +static constexpr uint16_t ITEM_W = 382; +static constexpr uint16_t ITEM_H = 100; +static constexpr uint16_t ICON_X = 0; +static constexpr uint16_t ICON_Y = 0; +static constexpr uint16_t LABEL_X = 100; +static constexpr uint16_t LABEL_Y = 0; +static constexpr uint16_t LABEL_W = 200; +static constexpr uint16_t LABEL_H = 100; +static constexpr uint16_t LABEL_FONT = 35; +static constexpr uint16_t IMAGE_W = 300; +static constexpr uint16_t IMAGE_H = 0; + +TrainingSettingItemView::TrainingSettingItemView() +{ + InitView(); +} + +TrainingSettingItemView::~TrainingSettingItemView() +{ + Remove(&sIcon); + Remove(&sLabel); + Remove(&sNextImage); +} + +bool TrainingSettingItemView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingSettingItemView::InitView"); + SetPosition(ITEM_X, ITEM_Y, ITEM_W, ITEM_H); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + SetTouchable(true); + + sIcon.SetPosition(ICON_X, ICON_Y); + sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + sLabel.SetPosition(LABEL_X, LABEL_Y); + sLabel.Resize(LABEL_W, LABEL_H); + sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); + sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + sLabel.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + sLabel.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + + sNextImage.SetSrc(PNG_SETTING_NEXT_IMAGE); + sNextImage.SetPosition(IMAGE_W, IMAGE_H); + sNextImage.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + Add(&sIcon); + Add(&sLabel); + Add(&sNextImage); + return true; +} + +void TrainingSettingItemView::SetItemInfo(const TrainingSettingItem itemInfo) +{ + sItemInfo = itemInfo; + sIcon.SetSrc(itemInfo.icon); + sLabel.SetText(itemInfo.label); + SetViewId(itemInfo.viewId); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingSettingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingSettingView.cpp new file mode 100644 index 000000000..04d868651 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingSettingView.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingSettingView + * Create: 2025-03-22 + */ +#include "training/TrainingSettingView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "training/TrainingPresenter.h" + +namespace OHOS { +static constexpr uint16_t LABELS_X = 133; +static constexpr uint16_t LABELS_Y = 36; +static constexpr uint16_t LABELS_W = 200; +static constexpr uint16_t LABELS_H = 60; +static constexpr uint16_t LABELS_FONT = 50; +static constexpr uint16_t LIST_X = 42; +static constexpr uint16_t LIST_Y = 95; +static constexpr uint16_t LIST_W = 382; +static constexpr uint16_t LIST_H = 305; + +static TrainingSettingView *g_pSettingView{nullptr}; + +TrainingSettingView::TrainingSettingView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingSettingView::TrainingSettingView"); + g_pSettingView = this; +} + +TrainingSettingView::~TrainingSettingView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingSettingView::~TrainingSettingView"); + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (titleLabel != nullptr) { + delete titleLabel; + titleLabel = nullptr; + } + if (settingList != nullptr) { + delete settingList; + settingList = nullptr; + } + if (listAdapter_ != nullptr) { + delete listAdapter_; + listAdapter_ = nullptr; + } + g_pSettingView = nullptr; +} + +TrainingSettingView *TrainingSettingView::GetInstance() +{ + return g_pSettingView; +} + +void TrainingSettingView::CreateUILabel() +{ + // Add Label to App + if (titleLabel == nullptr) { + titleLabel = new UILabel(); + } + titleLabel->SetPosition(LABELS_X, LABELS_Y); + titleLabel->Resize(LABELS_W, LABELS_H); + + // Set additional property + titleLabel->SetText("设置"); + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABELS_FONT); + + // Add to rootView + group->Add(titleLabel); +} + +void TrainingSettingView::CreateUIList() +{ + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::TrainingPresenter::GetInstance(); + if (clickListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener nullptr"); + return; + } + + // Add List to App + if (settingList == nullptr) { + settingList = new UIList(); + } + settingList->SetPosition(LIST_X, LIST_Y); + settingList->Resize(LIST_W, LIST_H); + settingList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + + // Set additional property + if (listAdapter_ == nullptr) { + listAdapter_ = new TrainingSettingAdapter(); + } + listAdapter_->SetItemClickListener(clickListener); + std::list trainingSettingItemList(settings, settings + TRAINING_SETTING_MAX); + listAdapter_->SetData(trainingSettingItemList); + + settingList->SetAdapter(listAdapter_); + settingList->RefreshList(); + + // Add to rootView + group->Add(settingList); +} + +UIViewGroup *TrainingSettingView::InitShowUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingSettingView InitShowUpView"); + if (group == nullptr) { + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + } + CreateUILabel(); + CreateUIList(); + UIView::OnDragListener *trainingDragListener = (UIView::OnDragListener *)OHOS::TrainingPresenter::GetInstance(); + if (trainingDragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "trainingDragListener GetInstance fail"); + return nullptr; + } + group->SetOnDragListener(trainingDragListener); + group->SetViewId(SETTING_VIEW_ID); + group->SetDraggable(true); + group->SetTouchable(true); + return group; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingView.cpp new file mode 100644 index 000000000..0b2d1fa55 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/training/src/TrainingView.cpp @@ -0,0 +1,297 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: TrainingView.cpp + * Author: + * Create: 2025-11-23 + */ + +#include "training/TrainingView.h" +#include "training/TrainingPresenter.h" +#include "wearable_log.h" + +namespace OHOS { +static TrainingView *g_pTrainingView = nullptr; + +TrainingView::TrainingView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingView::TrainingView"); + preProcessView[TRAINING_VIEW_MENU] = &TrainingView::ChangeMenuView; + preProcessView[TRAINING_VIEW_PREPARE] = &TrainingView::ChangePrepareView; + preProcessView[TRAINING_VIEW_DATA] = &TrainingView::ChangeDataView; + preProcessView[TRAINING_VIEW_PAUSE] = &TrainingView::ChangePauseView; + preProcessView[TRAINING_VIEW_PROMPT] = &TrainingView::ChangePromptView; + preProcessView[TRAINING_VIEW_SETTING] = &TrainingView::ChangeSettingView; + preProcessView[TRAINING_VIEW_TARGET] = &TrainingView::ChangeTargetView; + preProcessView[TRAINING_VIEW_TARGET_SETTING] = &TrainingView::ChangeTargetSettingView; + g_pTrainingView = this; +} + +TrainingView::~TrainingView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingView::~TrainingView"); + g_pTrainingView = nullptr; +} + +TrainingView *TrainingView::GetInstance() +{ + return g_pTrainingView; +} + +void TrainingView::OnStart() +{ + ChangeView(TRAINING_VIEW_MAX, TRAINING_VIEW_MENU); +} + +void TrainingView::OnStop() +{ + if (menuView != nullptr) { + delete menuView; + menuView = nullptr; + } + if (prepareView != nullptr) { + delete prepareView; + prepareView = nullptr; + } + if (dataView != nullptr) { + delete dataView; + dataView = nullptr; + } + if (pauseView != nullptr) { + delete pauseView; + pauseView = nullptr; + } + if (promptView != nullptr) { + delete promptView; + promptView = nullptr; + } + if (settingView != nullptr) { + delete settingView; + settingView = nullptr; + } + if (targetView != nullptr) { + delete targetView; + targetView = nullptr; + } + if (targetSettingView != nullptr) { + delete targetSettingView; + targetSettingView = nullptr; + } +} + +bool TrainingView::ChangeMenuView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeMenuView"); + menuView = new MenuView(); + if (menuView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView new fail"); + return false; + } + // init view + UIViewGroup *group = menuView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool TrainingView::ChangePrepareView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangePrepareView"); + prepareView = new PrepareView(); + if (prepareView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView new fail"); + return false; + } + // init view + UIViewGroup *group = prepareView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool TrainingView::ChangeDataView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeDataView"); + dataView = new DataView(); + if (dataView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView new fail"); + return false; + } + // init view + UIViewGroup *group = dataView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool TrainingView::ChangePauseView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangePauseView"); + pauseView = new PauseView(); + if (pauseView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView new fail"); + return false; + } + // init view + UIViewGroup *group = pauseView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool TrainingView::ChangePromptView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangePromptView"); + promptView = new PromptView(); + if (promptView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView new fail"); + return false; + } + // init view + UIViewGroup *group = promptView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool TrainingView::ChangeSettingView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeSettingView"); + settingView = new TrainingSettingView(); + if (settingView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView new fail"); + return false; + } + // init view + UIViewGroup *group = settingView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool TrainingView::ChangeTargetView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTargetView"); + targetView = new TargetView(); + if (targetView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView new fail"); + return false; + } + // init view + UIViewGroup *group = targetView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool TrainingView::ChangeTargetSettingView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTargetSettingView"); + targetSettingView = new TargetSettingView(); + if (targetSettingView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView new fail"); + return false; + } + // init view + UIViewGroup *group = targetSettingView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool TrainingView::CheckViewParam(int16_t hideView, int16_t showView) +{ + if (showView < 0 || showView >= TRAINING_VIEW_MAX) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView::CheckViewParam showView err."); + return false; + } + + if (hideView < 0 || hideView > TRAINING_VIEW_MAX) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView::CheckViewParam hideView err."); + return false; + } + + return true; +} + +void TrainingView::ChangeView(int16_t hideView, int16_t showView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingView::ChangeView %d, %d", hideView, showView); + + if (!CheckViewParam(hideView, showView)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView::CheckViewParam failed."); + return; + } + + PreprosssChangeView tmpPreProcessView = preProcessView[showView]; + + if (!(this->*tmpPreProcessView)(hideView, showView)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingView::ChangeView %d %dfailed", showView, hideView); + return; + } + if (hideView != TRAINING_VIEW_MAX) { + if (container[hideView] == nullptr) { + return; + } + container[hideView]->SetVisible(false); + } + container[showView]->SetVisible(true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingView:: ChangeView end!!!%d", showView); + Draw(); +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISampleModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISampleModel.cpp index 433648409..68a75729e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISampleModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISampleModel.cpp @@ -5,7 +5,7 @@ * Create: 2021-11-23 */ -#include "UISampleModel.h" +#include "uisample/UISampleModel.h" namespace OHOS { UISampleModel::UISampleModel() {} 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 ff790b626..7d42911b9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISamplePresenter.cpp @@ -5,10 +5,10 @@ * Create: 2021-11-23 */ -#include "UISampleView.h" -#include "UISampleModel.h" -#include "UISamplePresenter.h" -#include "ui_service.h" +#include "uisample/UISampleView.h" +#include "uisample/UISampleModel.h" +#include "uisample/UISamplePresenter.h" +#include "uiservice/ui_service.h" #include "NativeRegisterManager.h" namespace OHOS { @@ -25,13 +25,11 @@ REGIST_MENU(VIEW_UISAMPLE, UISampleView, UISamplePresenter, PNG_APPLIST_UI_SAMPL void UISamplePresenter::OnResume(void) { - Presenter::OnResume(); SendMsgToUIService(UI_ADD_SLEEP_VETO, 0, nullptr, 0); } void UISamplePresenter::OnPause(void) { - Presenter::OnPause(); SendMsgToUIService(UI_RM_SLEEP_VETO, 0, nullptr, 0); return; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISampleView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISampleView.cpp index d2d7777ed..4dbb8092e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISampleView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/uisample/src/UISampleView.cpp @@ -7,8 +7,8 @@ #include -#include "UISampleView.h" -#include "UISamplePresenter.h" +#include "uisample/UISampleView.h" +#include "uisample/UISamplePresenter.h" #include "ui_test_group.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uisample/uitest/framework/src/test_case_list_adapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/uisample/uitest/framework/src/test_case_list_adapter.cpp index d2161b62d..4f652b307 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/uisample/uitest/framework/src/test_case_list_adapter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/uisample/uitest/framework/src/test_case_list_adapter.cpp @@ -19,7 +19,7 @@ #include "components/ui_label_button.h" #include "gfx_utils/list.h" #include "ui_test.h" -#include "UISampleView.h" +#include "uisample/UISampleView.h" #include "ui_test_group.h" #include "wearable_log.h" 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 e47e34e38..c2188a499 100644 --- 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 @@ -40,6 +40,7 @@ #include "ui_test_sphere_view/ui_test_sphere_view.h" #include "ui_test_nested/ui_test_nested.h" #include "ui_test_particle/ui_test_particle.h" +#include "ui_test_lottie/ui_test_lottie.h" namespace OHOS { void UITestGroup::AddTestCase(TestCaseInfo testCaseInfo) { @@ -81,6 +82,7 @@ void UITestGroup::SetUpTestCase() testCaseList_->PushBack(TestCaseInfo{"足球效果", new UITestIcosahedron()}); testCaseList_->PushBack(TestCaseInfo{"滑动冲突", new UITestNested()}); testCaseList_->PushBack(TestCaseInfo{"粒子效果", new UITestParticle()}); + testCaseList_->PushBack(TestCaseInfo{"Lottie", new UITestLottie()}); } List& UITestGroup::GetTestCase() diff --git a/code/sdk/application/wearable/nativeapp/nativeui/uiservice/src/ui_language.cpp b/code/sdk/application/wearable/nativeapp/nativeui/uiservice/src/ui_language.cpp new file mode 100644 index 000000000..60adfc133 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/uiservice/src/ui_language.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: Breath Ease + * Author: wangle + * Create: 2025-4-23 + */ +#include "uiservice/ui_language.h" +#include "ui_resource_string.h" +#include "font/font_global_manager.h" +#include "nv.h" +#include "wearable_log.h" + +#include "nv_config/include/key_id.h" +#include "nv_config/include/common.h" +#include "nv.h" + +namespace OHOS { +static constexpr const char *BIN_LANG_EN = "/music/font/en.lang"; +static constexpr const char *BIN_LANG_ZH = "/music/font/zh.lang"; + +const char* UILanguage::GetText(uint16_t textId) +{ + if (RegisterGlobalManager()) { + return FontGlobalManager::GetInstance()->GetText(textId); + } + return nullptr; +} +void UILanguage::SetLanguage(uint8_t id) +{ + sys_language_id_t lang_id = {.language_id = id}; + + errcode_t ret = uapi_nv_write(NV_ID_SYS_LANGUAGE_ID, (uint8_t*)&lang_id, sizeof(sys_language_id_t)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "nv set language id error, ret=%u", ret); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "set language id = %u", lang_id.language_id); + UpdateLanguage(); +} +void UILanguage::UpdateLanguage() +{ + sys_language_id_t lang_id = {0}; + uint16_t nvsize = 0; + + errcode_t ret = uapi_nv_read(NV_ID_SYS_LANGUAGE_ID, sizeof(sys_language_id_t), &nvsize, (uint8_t*)&lang_id); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "nv get language id error, ret=%u", ret); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "language nvsize=%u id = %u", nvsize, lang_id.language_id); + if (RegisterGlobalManager()) { + if (lang_id.language_id<0 || lang_id.language_id > OHOS::LANGUAGE_ID_MAX) { + lang_id.language_id = OHOS::LANGUAGE_ID_ZH; + } + FontGlobalManager::GetInstance()->SetCurrentLangId(lang_id.language_id); + } +} +bool UILanguage::RegisterGlobalManager() +{ + static bool isRegister = false; + if (!isRegister) { + const char *resFiles[] = {BIN_LANG_ZH, BIN_LANG_EN}; + if (!FontGlobalManager::GetInstance()->RegisterLanguageInfo( + resFiles, OHOS::LANGUAGE_ID_MAX, OHOS::LANGUAGE_ID_ZH)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "register global manager error"); + return isRegister; + } + isRegister = true; + } + return isRegister; +} +} \ No newline at end of file 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 955c25d2f..ef81ce75d 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -13,28 +13,33 @@ * limitations under the License. */ -#include "ui_service.h" +#include "uiservice/ui_service.h" #include "wearable_log.h" #include "samgr_lite.h" -#include "SettingModel.h" -#include "UiServersMsg.h" +#include "settings/SettingModel.h" +#include "main/UiServersMsg.h" #include "ohos_init.h" #include "memory_adapter.h" #include #include "service_id_define.h" #include "bundle_install_msg.h" #include "graphic_service.h" -#include "ApplistModel.h" +#include "applist/ApplistModel.h" #if defined(SUPPORT_POWER_MANAGER) #include "power_display_service.h" #endif -#include "ui_screennotify.h" -#include "HealthModel.h" +#include "screennotify/ui_screennotify.h" +#include "main/HealthModel.h" #include "bts_br_gap.h" #include "bts_le_gap.h" +#include "uiservice/ui_language.h" + #include "errcode.h" #include "pm_definition.h" +#include "NativeAbility.h" +#include "TransitionType.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); @@ -194,6 +199,14 @@ void ServiceMsgProcess(Request *request) case CONNECT_NEW_PHONE: ConnectNewPhone(); break; + case UI_UPDATE_LANGUAGE: + OHOS::UILanguage::UpdateLanguage(); + break; + case UI_OTA_UPDATE: + power_display_svr_get_api()->turn_on_screen(); + OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_SET_OTA, + OHOS::TransitionType::TRANSITION_INVALID, OHOS::gSliceDefaultPriority, true); + break; } } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/videocard/src/VideoCard.cpp b/code/sdk/application/wearable/nativeapp/nativeui/videocard/src/VideoCard.cpp index 4bd5cc73d..e97fa8fe0 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/videocard/src/VideoCard.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/videocard/src/VideoCard.cpp @@ -1,17 +1,17 @@ #include #include -#include "VideoCard.h" +#include "videocard/VideoCard.h" #include "NativeAbility.h" #include "msg_center.h" #include "securec.h" -#include "DialBinParser.h" -#include "ModelDialDataFactory.h" +#include "main/DialBinParser.h" +#include "main/dial/ModelDialDataFactory.h" #include "common/low_power_manager.h" #include "common/image_cache_manager.h" #ifdef SUPPORT_OHOSFWK -#include "ui_screennotify.h" +#include "screennotify/ui_screennotify.h" #endif -#include "MainPresenterSample.h" +#include "main/MainPresenterSample.h" #include "common/graphic_utils.h" namespace OHOS { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherAdapter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherAdapter.cpp new file mode 100644 index 000000000..65aae4f0b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherAdapter.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherAdapter + * Create: 2025-03-23 + */ + +#include "weather/WeatherAdapter.h" + +namespace OHOS { +WeatherAdapter::WeatherAdapter() {} + +WeatherAdapter::~WeatherAdapter() +{ + listData.clear(); +} + +uint16_t WeatherAdapter::GetCount(void) +{ + return listData.size(); +} + +void WeatherAdapter::SetData(std::list &data) +{ + if (!listData.empty()) { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) { + listData.push_back(*it); + } +} + +UIView *WeatherAdapter::GetView(UIView *inView, int16_t index) +{ + if (listData.empty()) { + return nullptr; + } + if (index < 0) { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData.size()) { + return nullptr; + } + + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) { + it++; + } + WeatherItem itemData = *it; + WeatherItemView *item = nullptr; + if (inView == nullptr) { + item = new WeatherItemView(); + } else { + item = static_cast(inView); + } + + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + return item; +} + +void WeatherAdapter::AddListItem(const WeatherItem &item) +{ + listData.push_back(item); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherItemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherItemView.cpp new file mode 100644 index 000000000..e417f9f1f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherItemView.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherItemView + * Create: 2025-03-23 + */ + +#include "wearable_log.h" +#include "weather/WeatherItemView.h" +#include "weather/WeatherModel.h" + +namespace OHOS { +static constexpr int16_t WEATHER_ICON_X = 155; +static constexpr int16_t WEATHER_LABEL_X = 10; +static constexpr int16_t WEATHER_LABEL2_X = 220; +static constexpr int16_t WEATHER_CHARTLINE_X = 20; +static constexpr int16_t WEATHER_CHARTLINE_Y = 78; +static constexpr int16_t WEATHER_CHARTLINE_WIDTH = 450; +static constexpr int16_t WEATHER_CHARTLINE_HEIGHT = 2; +static constexpr int16_t WEATHER_ITEM_BUTTON_WIDTH = 390; +static constexpr int16_t WEATHER_ITEM_BUTTON_HEIGHT = 83; +static constexpr int16_t WEATHER_ITEM_LABEL_WIDTH = 155; +static constexpr int16_t WEATHER_ITEM_LABEL_HEIGHT = 80; +static constexpr int16_t WEATHER_ITEM_FONT_SIZE = 35; +static constexpr int16_t WEATHER_IMAGE_SIZE = 300; +static constexpr int16_t WEATHER_ICON_Y = 15; +static constexpr int16_t NUMS_50 = 50; + +WeatherItemView::WeatherItemView() +{ + SetPosition(0, 0, WEATHER_ITEM_BUTTON_WIDTH, WEATHER_ITEM_BUTTON_HEIGHT); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + SetTouchable(true); + SetUpChild(); + + Add(&sNextImage); + Add(&sLabel_1); + Add(&sIcon); + Add(&sLabel_2); + Add(&chartLine); +} + +WeatherItemView::~WeatherItemView() +{ + Remove(&sIcon); + Remove(&sLabel_1); + Remove(&sLabel_2); + Remove(&chartLine); +} + +void WeatherItemView::SetItemInfo(const WeatherItem itemInfo) +{ + sItemInfo = itemInfo; + sLabel_1.SetText(itemInfo.label_1); + sIcon.SetSrc(itemInfo.icon); + sLabel_2.SetText(itemInfo.label_2); + chartLine.SetVisible(itemInfo.hasSecondMenu); +} + +void WeatherItemView::SetUpChild() +{ + sNextImage.SetPosition(0, 0); + sNextImage.Resize(WEATHER_IMAGE_SIZE, WEATHER_IMAGE_SIZE); + bool index = WeatherModel::GetInstance().GetDayStatus(); + ImageInfo *img = nullptr; + if (index) { + img = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_WEATHER71, WEATHER_IMAGE); + } else { + img = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_WEATHER72, WEATHER_IMAGE); + } + if (img == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::LoadOneInMultiRes fail"); + } + sNextImage.SetSrc(img); + + sLabel_1.SetPosition(WEATHER_LABEL_X, 0); + sLabel_1.Resize(WEATHER_ITEM_LABEL_WIDTH, WEATHER_ITEM_LABEL_HEIGHT); + sLabel_1.SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + sLabel_1.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sLabel_1.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + sLabel_1.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel_1.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + + sIcon.SetPosition(WEATHER_ICON_X, WEATHER_ICON_Y); + sIcon.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + sLabel_2.SetPosition(WEATHER_LABEL2_X, 0); + sLabel_2.Resize(WEATHER_ITEM_LABEL_WIDTH, WEATHER_ITEM_LABEL_HEIGHT); + sLabel_2.SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + sLabel_2.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sLabel_2.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + sLabel_2.SetStyle(STYLE_TEXT_COLOR, Color::White().full); + sLabel_2.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + chartLine.SetPosition(WEATHER_CHARTLINE_X, WEATHER_CHARTLINE_Y, WEATHER_CHARTLINE_WIDTH, WEATHER_CHARTLINE_HEIGHT); + chartLine.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); +} + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherMainPage.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherMainPage.cpp new file mode 100644 index 000000000..e1d963039 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherMainPage.cpp @@ -0,0 +1,336 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherMainPage + * Create: 2025-03-23 + */ + +#include +#include "weather/WeatherMainPage.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherModel.h" +#include "ui_resource_weather.h" +#include "common/image_cache_manager.h" +#include "wearable_log.h" +#include +#include + +static constexpr int16_t WEATHER_LABEL_SIZE_WIDTH_ONE = 250; +static constexpr int16_t WEATHER_LABEL_SIZE_HEIGHT_ONE = 60; +static constexpr int16_t WEATHER_LABEL_SIZE_WIDTH_FOUR = 210; +static constexpr int16_t WEATHER_LABEL_SIZE_HEIGHT_FOUR = 40; +static constexpr int16_t WEATHER_LABEL_SIZE_WIDTH_FIVE = 223; +static constexpr int16_t WEATHER_LABEL_SIZE_HEIGHT_FIVE = 46; +static constexpr int16_t WEATHER_LABEL_SIZE_WIDTH_SIX = 149; +static constexpr int16_t WEATHER_LABEL_SIZE_HEIGHT_SIX = 20; +static constexpr int16_t WEATHER_LABEL_FRONT_ONE = 40; +static constexpr int16_t WEATHER_LABEL_FRONT_TWO = 24; +static constexpr int16_t WEATHER_LABEL_FRONT_THREE = 36; +static constexpr int16_t WEATHER_LABEL_FRONT_FOUR = 120; +static constexpr int16_t WEATHER_LABEL_FRONT = 22; +static constexpr int16_t WEATHER_AROUND_X = 74; +static constexpr int16_t WEATHER_AROUND_Y = 323; +static constexpr int16_t WEATHER_AROUND_WIDTH = 198; +static constexpr int16_t WEATHER_AROUND_HEIGHT = 40; +static constexpr int16_t WEATHER_CODE_POSITION_X = 267; +static constexpr int16_t WEATHER_CODE_POSITION_Y = 268; +static constexpr int16_t WEATHER_CODE_POSITION_WIDTH = 72; +static constexpr int16_t WEATHER_CODE_POSITION_HEIGHT = 46; +static constexpr int16_t WEATHER_TEMP_POSITION_X = 210; +static constexpr int16_t WEATHER_TEMP_POSITION_Y = 130; +static constexpr int16_t WEATHER_TEMP_WIDTH = 190; +static constexpr int16_t WEATHER_TEMP_HEIGHT = 120; +static constexpr int16_t WEATHER_IMAGE_WIDTH = 78; +static constexpr int16_t WEATHER_IMAGE_HEIGHT = 115; +static constexpr int16_t WEATHER_IMAGEAIR_X = 78; +static constexpr int16_t WEATHER_IMAGEAIR_Y = 327; +static constexpr int16_t WEATHER_IMAGEAIR_DATA = 40; +static constexpr int16_t WEATHER_IMAGEHUMIDITY_X = 336; +static constexpr int16_t WEATHER_IMAGEHUMIDITY_Y = 327; +static constexpr int16_t WEATHER_LABLEAIR_DATA = 79; +static constexpr int16_t WEATHER_LABLEAIR_HEIGHT = 30; +static constexpr int16_t WEATHER_IMAGEHUMIDITY_DATA = 120; +static constexpr int16_t WEATHER_IMG_X = 71; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_X = 199; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_Y = 429; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_WIDTH = 56; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_HEIGHT = 10; +static constexpr int16_t WEATHER_LABELTITLE_POSITION_X = 63; +static constexpr int16_t WEATHER_LABELTITLE_POSITION_Y = 100; +static constexpr int16_t WEATHER_LABELTITLE_WIDTH = 400; +static constexpr int16_t WEATHER_ADDRESS_X = 143; +static constexpr int16_t WEATHER_ADDRESS_Y = 49; + +const char *weatherNames[] = {"晴", "多云", "阴", "阵雨", "雷阵雨", "雷阵雨伴有冰雹", "雨夹雪", + "小雨", "中雨", "大雨", "暴雨", "大暴雨", "特大暴雨", "阵雪", + "小雪", "中雪", "大雪", "暴雪", "雾", "冻雨", "沙尘暴", + "小到中雨", "中到大雨", "大到暴雨", "小到中雪", "中到大雪", "大到暴雪", "浮尘", + "扬沙", "强沙尘暴", "霾", "无天气数据"}; + +namespace OHOS { +REGIST_SLICE_PAGE(VIEW_WEATHER, WEATHER_PAGES::WEATHER_MAIN_PAGE, WeatherMainPage, true); + +WeatherMainPage::WeatherMainPage() +{ + weatherModel = &WeatherModel::GetInstance(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::WeatherMainPage"); +} + +WeatherMainPage::~WeatherMainPage() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::~WeatherMainPage"); + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (weatherImg != nullptr) { + delete weatherImg; + weatherImg = nullptr; + } + + if (mainImg != nullptr) { + delete mainImg; + mainImg = nullptr; + } + + if (aroundImg != nullptr) { + delete aroundImg; + aroundImg = nullptr; + } + + if (ImageAir != nullptr) { + delete ImageAir; + ImageAir = nullptr; + } + + if (ImageHumidity != nullptr) { + delete ImageHumidity; + ImageHumidity = nullptr; + } + + if (ImagePageKey != nullptr) { + delete ImagePageKey; + ImagePageKey = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); +} + +void WeatherMainPage::OnStart(void *data) +{ + group = new UIViewGroup(); + if (group == nullptr) { + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::InitPageFirst successful"); + group->SetPosition(0, 0); + group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + group->SetOnDragListener(this); + group->SetViewId("weather"); + group->SetDraggable(true); + group->SetTouchable(true); + flag = weatherModel->InitWeatherItem(); + cur = weatherModel->GetCurWeather(); + mainImg = new UIImageView(); + if (mainImg == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::mainImg new image fail"); + return; + } + mainImg->SetPosition(0, 0); + mainImg->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + group->Add(mainImg); + InitWeatherImage(); + InitImage(); + InitLabel(); + if (!flag) { + labelTitle = new UILabel(); + if (labelTitle == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::labelTitle new label fail"); + return; + } + labelTitle->SetText("天气未更新,请连接手机更新数据"); + labelTitle->SetPosition(WEATHER_LABELTITLE_POSITION_X, WEATHER_LABELTITLE_POSITION_Y, WEATHER_LABELTITLE_WIDTH, + WEATHER_LABEL_SIZE_HEIGHT_ONE); + labelTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT); + group->Add(labelTitle); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::InitWeatherItem fail"); + } + AddViewToPageContainer(group); +} + +void WeatherMainPage::InitImage() +{ + aroundImg = new UIImageView(); + if (aroundImg == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::aroundImage new image fail"); + return; + } + aroundImg->SetPosition(WEATHER_AROUND_X, WEATHER_AROUND_Y); + if (weatherModel->GetDayStatus()) { + LOADIMG::LoadImageViewImg(mainImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER64); + LOADIMG::LoadImageViewImg(aroundImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER75); + } else { + LOADIMG::LoadImageViewImg(mainImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER65); + LOADIMG::LoadImageViewImg(aroundImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER76); + } + ImageAir = new UIImageView(); + if (ImageAir == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::ImageAir new image fail"); + return; + } + ImageAir->SetPosition(WEATHER_IMAGEAIR_X, WEATHER_IMAGEAIR_Y); + ImageAir->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(ImageAir, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER69); + ImageHumidity = new UIImageView(); + if (ImageHumidity == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::ImageHumidity new image fail"); + return; + } + ImageHumidity->SetPosition(WEATHER_IMAGEHUMIDITY_X, WEATHER_IMAGEHUMIDITY_Y); + ImageHumidity->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(ImageHumidity, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER70); + ImagePageKey = new UIImageView(); + if (ImagePageKey == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::ImagePageKey new image fail"); + return; + } + ImagePageKey->SetPosition(WEATHER_IMAGEPAGEKEY_X, WEATHER_IMAGEPAGEKEY_Y); + ImagePageKey->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(ImagePageKey, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER66); + group->Add(aroundImg); + group->Add(ImageAir); + group->Add(ImageHumidity); + group->Add(ImagePageKey); +} + +void WeatherMainPage::InitWeatherImage() +{ + addressImg = new UIImageView(); + if (addressImg == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::img new image fail"); + return; + } + addressImg->SetPosition(WEATHER_ADDRESS_X, WEATHER_ADDRESS_Y); + addressImg->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + curWeather_code = std::atoi(cur.weather_code); + LOADIMG::LoadImageViewImg(addressImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER77); + + weatherImg = new UIImageView(); + if (weatherImg == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::img new image fail"); + return; + } + weatherImg->SetPosition(WEATHER_IMG_X, WEATHER_TEMP_POSITION_Y); + weatherImg->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + curWeather_code = std::atoi(cur.weather_code); + LOADIMG::LoadImageViewImg(weatherImg, WEATHER_IMAGE, bigWeatherImage[curWeather_code]); + group->Add(addressImg); + group->Add(weatherImg); +} + + +void WeatherMainPage::InitLabel() +{ + int posX[LABEL_COUNT] = {140, 113, 120, 222, 100, 210}; + int posY[LABEL_COUNT] = {34, 274, 332, 332, 376, 130}; + for (int i = 0; i < LABEL_COUNT; i++) { + title[i] = new UILabel(); + if (title[i] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::InitPageFirst new label:%d fail", i); + return; + } + if (i == SET_ZERO) { + title[i]->SetText(cur.address); + title[i]->SetPosition(posX[i], posY[i], WEATHER_LABEL_SIZE_WIDTH_ONE, WEATHER_LABEL_SIZE_HEIGHT_ONE); + title[i]->SetAlign(TEXT_ALIGNMENT_LEFT); + title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_ONE); + } else if (i == SET_ONE) { + std::ostringstream oss; + oss << cur.max_degree << "° / " << cur.min_degree << "° " << weatherNames[curWeather_code]; + std::string weatherTemp = oss.str(); + title[i]->SetText(weatherTemp.c_str()); + title[i]->SetPosition(posX[i], posY[i], WEATHER_LABEL_SIZE_WIDTH_FIVE, WEATHER_LABEL_SIZE_HEIGHT_FIVE); + title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_THREE); + } else if (i == SET_TWO) { + std::ostringstream oss; + oss << "空气 -"; + std::string weatherHumidity = oss.str(); + title[i]->SetText(weatherHumidity.c_str()); + title[i]->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title[i]->SetPosition(posX[i], posY[i], WEATHER_LABLEAIR_DATA, WEATHER_LABLEAIR_HEIGHT); + title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_TWO); + } else if (i == SET_THREE) { + std::ostringstream oss; + oss << "湿度" << cur.humidity <<"%"; + std::string weatherHumidity = oss.str(); + title[i]->SetText(weatherHumidity.c_str()); + title[i]->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title[i]->SetPosition(posX[i], posY[i], WEATHER_IMAGEHUMIDITY_DATA, WEATHER_LABLEAIR_HEIGHT); + title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_TWO); + } else if (i == SET_FOUR) { + std::ostringstream oss; + std::string updateTime = FormatTime(flag, cur.updateTime); + oss << "上次更新时间 " << updateTime; + updateTime = oss.str(); + title[i]->SetText(updateTime.c_str()); + title[i]->SetPosition(posX[i], posY[i], WEATHER_LABEL_SIZE_WIDTH_ONE, WEATHER_LABEL_SIZE_HEIGHT_FOUR); + title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_TWO); + } else if (i == SET_FIVE) { + std::ostringstream oss; + oss << cur.degree << "°"; + std::string weatherTemp = oss.str(); + title[i]->SetText(weatherTemp.c_str()); + title[i]->SetPosition(posX[i], posY[i], WEATHER_TEMP_WIDTH, WEATHER_TEMP_HEIGHT); + title[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABEL_FRONT_FOUR); + } + title[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + group->Add(title[i]); + } +} + +std::string WeatherMainPage::FormatTime(bool falg, const std::string &inputStr) +{ + if (!flag) { + return "--"; + } + tm inputTm = {}; + std::istringstream iss(inputStr); + iss >> std::get_time(&inputTm, "%Y%m%d%H%M"); + time_t inputTime = mktime(&inputTm); + time_t now = time(nullptr); + tm *nowTm = localtime(&now); + if (inputTm.tm_year == nowTm->tm_year && inputTm.tm_mon == nowTm->tm_mon && inputTm.tm_mday == nowTm->tm_mday) { + char buffer[6]; + strftime(buffer, sizeof(buffer), "%H:%M", &inputTm); + return std::string(buffer); + } else { + char buffer[6]; + strftime(buffer, sizeof(buffer), "%m/%d", &inputTm); + return std::string(buffer); + } +} + +bool WeatherMainPage::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPresenter::OnDrag ChangeSlice(VIEW_APPLIST)"); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_SECOND_PAGE, nullptr, + TransitionType::TRANSITION_INVALID, true); + } + return false; +} + +bool WeatherMainPage::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + return true; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherModel.cpp new file mode 100644 index 000000000..6b77b9572 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherModel.cpp @@ -0,0 +1,411 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherModel + * Create: 2025-03-23 + */ + +#include "weather/WeatherModel.h" +#include "weather/WeatherPresenter.h" +#include "wearable_log.h" +#include "ui_resource_weather.h" +#ifdef BUILD_IN_LINUX +#include "localtime.h" +#endif + +namespace OHOS { + +WeatherModel::WeatherModel() {} + +WeatherModel::~WeatherModel() {} + +WeatherModel &WeatherModel::GetInstance() +{ + static WeatherModel instance; + return instance; +} + +uint8_t WeatherModel::GetWeatherListNum() +{ + return usedLen; +} + +WeatherItem *WeatherModel::GetWeatherlistItems() +{ + if (weather[0].label_1 == nullptr) { + ImageInfo *imgSrc = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_WEATHER47, WEATHER_IMAGE); + weather[SET_ZERO] = {"今天", imgSrc, "16°/26°", true}; + weather[SET_ONE] = {"明天", imgSrc, "18°/28°", false}; + weather[SET_TWO] = {"后天", imgSrc, "17°/27°", false}; + weather[SET_THREE] = {"周四", imgSrc, "15°/24°", false}; + weather[SET_FOUR] = {"周五", imgSrc, "14°/22°", false}; + weather[SET_FIVE] = {"周六", imgSrc, "16°/25°", false}; + weather[SET_SIX] = {"周日", imgSrc, "19°/29°", false}; + usedLen = SET_SEVEN; + } + return weather; +} + +CurWeather WeatherModel::GetCurWeather() +{ + if (curWeather.min_degree == nullptr) { + curWeather.min_degree = "10"; + curWeather.max_degree = "25"; + curWeather.address = "北京市"; + curWeather.weather_code = "02"; + curWeather.degree = "18"; + curWeather.updateTime = "2023-11-15 14:30:00 20"; + curWeather.humidity = "90"; + curWeather.sunSet = "17:30"; + curWeather.sunRise = "06:45"; + } + return curWeather; +} + +std::vector WeatherModel::GetHourWeather() +{ + if (houWeather.size() < WEATHER_COUNT) { + HourWeather weatherData[] = { + {"00:00", "18", "04"}, {"01:00", "17", "06"}, {"02:00", "17", "06"}, {"03:00", "16", "06"}, + {"04:00", "16", "07"}, {"05:00", "15", "07"}, {"06:00", "16", "08"}, {"07:00", "17", "08"}, + {"08:00", "18", "04"}, {"09:00", "20", "04"}, {"10:00", "22", "04"}, {"11:00", "24", "04"}, + {"12:00", "25", "04"}, {"13:00", "26", "04"}, {"14:00", "26", "04"}, {"15:00", "25", "06"}, + {"16:00", "24", "06"}, {"17:00", "23", "06"}, {"18:00", "22", "06"}, {"19:00", "21", "07"}, + {"20:00", "20", "07"}, {"21:00", "19", "10"}, {"22:00", "18", "10"}, {"23:00", "18", "10"}}; + for (const auto &item : weatherData) { + houWeather.push_back(item); + } + } + return houWeather; +} + +bool WeatherModel::InitWeatherItem() +{ + std::ifstream file("/user/app/user/ace/data/com.vendor.Weather/weather.json"); + if (!file.is_open()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "no file"); + return false; + } + std::stringstream buffer; + buffer << file.rdbuf(); + std::string content = buffer.str(); + int intsize = sizeof(content); + cJSON *root = nullptr; + // 解析JSON字符串 + if (intsize != 0) { + root = cJSON_Parse(content.c_str()); + } + if (root == NULL) { + // 如果解析失败,输出错误信息 + const char *error_ptr; + return false; + } + // 访问JSON数据 + bool updateMsg = InitVecObserve(root); + if (updateMsg) { + InitVecForecast(root); + InitVecRise(root); + InitVecWeek(root); + InitVecAddress(root); + InitFirstPageData(); + InitSecondPageData(); + InitThirdPageData(); + } else { + cJSON_Delete(root); + return false; + } + cJSON_Delete(root); + return true; +} + +void WeatherModel::InitFirstPageData() +{ + curWeather = {0}; + static std::string sunset; + static std::string sunrise; + if (map_observe.find("min_degree") != map_observe.end()) { + curWeather.min_degree = map_observe["min_degree"].c_str(); + } + if (map_observe.find("max_degree") != map_observe.end()) { + curWeather.max_degree = map_observe["max_degree"].c_str(); + } + if (map_observe.find("degree") != map_observe.end()) { + curWeather.degree = map_observe["degree"].c_str(); + } + if (map_observe.find("weather_code") != map_observe.end()) { + curWeather.weather_code = map_observe["weather_code"].c_str(); + } + if (map_observe.find("update_time") != map_observe.end()) { + curWeather.updateTime = map_observe["update_time"].c_str(); + } + if (map_observe.find("humidity") != map_observe.end()) { + curWeather.humidity = map_observe["humidity"].c_str(); + } + if (map_address.find("city") != map_address.end()) { + curWeather.address = map_address["city"].c_str(); + } + if (map_address.find("address") != map_address.end()) { + curWeather.address = map_address["address"].c_str(); + } +} + +void WeatherModel::InitSecondPageData() +{ + houWeather.clear(); + static std::string dayTime[WEATHER_COUNT]; + static std::string dayTemp[WEATHER_COUNT]; + static std::string dayWeather[WEATHER_COUNT]; + + for (const auto &item : vec_forecast_1h) { + const std::string name = std::get<0>(item); + const std::string category = std::get<1>(item); + const int id = std::get(item); + HourWeather sample = {nullptr}; + if (name == "update_time") { + dayTime[id] = category; + } else if (name == "degree") { + dayTemp[id] = category; + } else if (name == "weather_code") { + dayWeather[id] = category; + } + } + for (int i = 0; i < WEATHER_COUNT; i++) { + HourWeather sample = {nullptr}; + sample.hour = dayTime[i].c_str(); + sample.degree = dayTemp[i].c_str(); + sample.weather = dayWeather[i].c_str(); + houWeather.push_back(sample); + } +} + +void WeatherModel::InitThirdPageData() +{ + static std::string strTmp[SET_EIGHT]; + static std::string minTemp[SET_EIGHT]; + static std::string maxTemp[SET_EIGHT]; + static std::string currentWeek[SET_EIGHT]; + static int weatherValue[SET_EIGHT]; + for (const auto &item : vec_forecast_24h) { + const std::string name = std::get<0>(item); + const std::string category = std::get<1>(item); + const int id = std::get(item); + if (name == "current_week") { + if (id == SET_ZERO) { + currentWeek[id] = "今天"; + } else if (id == SET_ONE) { + currentWeek[id] = "明天"; + } else if (id == SET_TWO) { + currentWeek[id] = "后天"; + } else { + currentWeek[id] = category; + } + } else if (name == "min_degree") { + minTemp[id] = category; + } else if (name == "max_degree") { + maxTemp[id] = category; + } else if (name == "day_weather_code") { + weatherValue[id] = std::atoi(category.c_str()); + } + } + for (int i = 0; i < SET_SEVEN; i++) { + strTmp[i] = maxTemp[i] + "°/" + minTemp[i] + "°"; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherModel::InitWeatherItem:%s", strTmp[i].c_str()); + } + // 只显示七天的天气 + for (int i = 0; i < SET_SEVEN; i++) { + int weatherIndex = weatherValue[i]; + ImageInfo *imgSrc = + ImageCacheManager::GetInstance().LoadOneInMultiRes(smallWeatherImage[weatherIndex], WEATHER_IMAGE); + weather[i] = {currentWeek[i].c_str(), imgSrc, strTmp[i].c_str(), true}; + } + usedLen = SET_SEVEN; +} + +bool WeatherModel::InitVecForecast(cJSON *root) +{ + vec_forecast_1h.clear(); + // 获取 forecast_1h 对象 + cJSON *forecast_1h = cJSON_GetObjectItemCaseSensitive(root, "forecast_1h"); + if (!cJSON_IsObject(forecast_1h)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error forecast_1h:"); + cJSON_Delete(root); + return false; + } + for (int i = 0; i < WEATHER_COUNT; i++) { + cJSON *forecast_1h_num = cJSON_GetObjectItemCaseSensitive(forecast_1h, std::to_string(i).c_str()); + if (!cJSON_IsObject(forecast_1h_num)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error forecast_1h_num:%d", i); + continue; // 跳过当前循环,继续处理下一个 + } + std::string str = cJSON_GetObjectItemCaseSensitive(forecast_1h_num, "update_time")->valuestring; + std::string hour = str.substr(SET_TWELVE, SET_TWO); + // 确保字符串长度至少为12 + if (str.length() >= WEATHER_HOUR) { + // 提取小时部分 + hour = str.substr(SET_EIGHT, SET_TWO) + ":00"; + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error forecast_1h:"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error forecast_1h hour size error"); + hour = "00:00"; + } + vec_forecast_1h.push_back(std::make_tuple("update_time", hour, i)); + vec_forecast_1h.push_back( + std::make_tuple("degree", cJSON_GetObjectItemCaseSensitive(forecast_1h_num, "degree")->valuestring, i)); + vec_forecast_1h.push_back(std::make_tuple( + "weather_code", cJSON_GetObjectItemCaseSensitive(forecast_1h_num, "weather_code")->valuestring, i)); + } + return true; +} + +bool WeatherModel::InitVecObserve(cJSON *root) +{ + map_observe.clear(); + // 获取 observe 对象 + cJSON *observe = cJSON_GetObjectItemCaseSensitive(root, "observe"); + if (!cJSON_IsObject(observe)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error observe:"); + cJSON_Delete(root); + return false; + } + map_observe.insert(std::make_pair("weather", cJSON_GetObjectItemCaseSensitive(observe, "weather")->valuestring)); + map_observe.insert(std::make_pair("degree", cJSON_GetObjectItemCaseSensitive(observe, "degree")->valuestring)); + map_observe.insert(std::make_pair("humidity", cJSON_GetObjectItemCaseSensitive(observe, "humidity")->valuestring)); + map_observe.insert( + std::make_pair("min_degree", cJSON_GetObjectItemCaseSensitive(observe, "min_degree")->valuestring)); + map_observe.insert( + std::make_pair("max_degree", cJSON_GetObjectItemCaseSensitive(observe, "max_degree")->valuestring)); + map_observe.insert( + std::make_pair("update_time", cJSON_GetObjectItemCaseSensitive(observe, "update_time")->valuestring)); + map_observe.insert( + std::make_pair("weather_code", cJSON_GetObjectItemCaseSensitive(observe, "weather_code")->valuestring)); + return true; +} + +bool WeatherModel::InitVecRise(cJSON *root) +{ + // 获取 rise 对象 + vec_rise.clear(); + cJSON *rise = cJSON_GetObjectItemCaseSensitive(root, "rise"); + if (!cJSON_IsObject(rise)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error rise:"); + cJSON_Delete(root); + return false; + } + for (int i = 0; i < SET_FOURTEEN; i++) { + cJSON *rise_num = cJSON_GetObjectItemCaseSensitive(rise, std::to_string(i).c_str()); + if (!cJSON_IsObject(rise_num)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error rise:%d", i); + continue; // 跳过当前循环,继续处理下一个 + } + std::string sunSet = cJSON_GetObjectItemCaseSensitive(rise_num, "sunset")->valuestring; + std::string sunRise = cJSON_GetObjectItemCaseSensitive(rise_num, "sunrise")->valuestring; + SetDayStatus(sunRise, sunSet); + } + return true; +} + +bool WeatherModel::InitVecWeek(cJSON *root) +{ + vec_forecast_24h.clear(); + cJSON *forecast_24h = cJSON_GetObjectItemCaseSensitive(root, "forecast_24h"); + if (!cJSON_IsObject(forecast_24h)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error forecast_24h:"); + cJSON_Delete(root); + return false; + } + for (int i = 0; i < SET_TEN; i++) { + cJSON *forecast_24h_num = cJSON_GetObjectItemCaseSensitive(forecast_24h, std::to_string(i).c_str()); + if (!cJSON_IsObject(forecast_24h_num)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error forecast_24h_num:%d", i); + continue; + } + std::istringstream iss(cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "time")->valuestring); + char dash1; + char dash2; + int year = 0; + int month = 0; + int day = 0; + const int start_year = START_YEAR; + if ((iss >> year >> dash1 >> month >> dash2 >> day) && (dash1 == '-') && (dash2 == '-')) { + std::tm timeinfo = {}; + timeinfo.tm_year = year - start_year; + timeinfo.tm_mon = month - 1; + timeinfo.tm_mday = day; + timeinfo.tm_hour = 0; + timeinfo.tm_min = 0; + timeinfo.tm_sec = 0; + timeinfo.tm_isdst = -1; + std::time_t timestamp = mktime(&timeinfo); + if (timestamp == -1) { + return false; + } + std::tm localTimeInfo; +#ifdef _WIN32 + if (localtime_s(&localTimeInfo, ×tamp) != 0) { +#else + if (localtime_r(×tamp, &localTimeInfo) == nullptr) { +#endif + return false; + } + const char *current_weeks[] = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"}; + vec_forecast_24h.push_back(std::make_tuple("current_week", current_weeks[localTimeInfo.tm_wday], i)); + vec_forecast_24h.push_back(std::make_tuple( + "min_degree", cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "min_degree")->valuestring, i)); + vec_forecast_24h.push_back(std::make_tuple( + "max_degree", cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "max_degree")->valuestring, i)); + vec_forecast_24h.push_back(std::make_tuple( + "day_weather_code", cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "day_weather_code")->valuestring, + i)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "day_weather_code:%s ", + cJSON_GetObjectItemCaseSensitive(forecast_24h_num, "day_weather_code")->valuestring); + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error Date"); + } + } + return true; +} + +bool WeatherModel::InitVecAddress(cJSON *root) +{ + map_address.clear(); + cJSON *address = cJSON_GetObjectItemCaseSensitive(root, "address"); + if (!cJSON_IsObject(address)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error address:"); + cJSON_Delete(root); + return false; + } + map_address.insert(std::make_pair("province", cJSON_GetObjectItemCaseSensitive(address, "province")->valuestring)); + map_address.insert(std::make_pair("city", cJSON_GetObjectItemCaseSensitive(address, "city")->valuestring)); + map_address.insert(std::make_pair("county", cJSON_GetObjectItemCaseSensitive(address, "county")->valuestring)); + return true; +} + +void WeatherModel::SetDayStatus(const std::string &timeRise, const std::string &timeSet) +{ +#ifdef _WIN32 + struct timeval tv; + gettimeofday(&tv, NULL); +#else + struct timeval64 tv; + gettimeofday64(&tv, NULL); +#endif + uint64_t second = tv.tv_sec; + uint64_t minute = second / MIN_TO_HOUR; + uint64_t hour = minute / MIN_TO_HOUR; + uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); + uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); + int currentTime = realHour * MIN_TO_HOUR + realMinute; + int hours = (timeRise[SET_ZERO] - '0') * SET_TEN + (timeRise[SET_ONE] - '0'); + int minutes = (timeRise[SET_THREE] - '0') * SET_TEN + (timeRise[SET_FOUR] - '0'); + int rise = hours * MIN_TO_HOUR + minutes; + hours = (timeSet[SET_ZERO] - '0') * SET_TEN + (timeSet[SET_ONE] - '0'); + minutes = (timeSet[SET_THREE] - '0') * SET_TEN + (timeSet[SET_FOUR] - '0'); + int set = hours * MIN_TO_HOUR + minutes; + isDay = (currentTime >= rise && currentTime < set) ? true : false; +} + +bool WeatherModel::GetDayStatus() +{ + return isDay; +} +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherPageSecond.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherPageSecond.cpp new file mode 100644 index 000000000..f9e9e768f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherPageSecond.cpp @@ -0,0 +1,264 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageSecond + * Create: 2025-03-15 + */ + +#include "weather/WeatherPageSecond.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherView.h" +#include "weather/WeatherModel.h" +#include "ui_resource_weather.h" +#include "common/image_cache_manager.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr uint16_t WEATHER_TITLE_WIDTH = 51; +static constexpr uint16_t WEATHER_TITLE_HEIGHT = 26; +static constexpr uint16_t WEATHER_TOPLABEL_X = 156; +static constexpr uint16_t WEATHER_TOPLABEL_Y = 22; +static constexpr uint16_t WEATHER_TOPLABEL_WIDTH = 150; +static constexpr uint16_t WEATHER_TOPLABEL_HEIGHT = 60; +static constexpr uint16_t WEATHER_TOPLABEL_FRONT = 26; +static constexpr uint16_t WEATHER_LABELTIME_FRONT = 20; +static constexpr uint16_t WEATHER_LABELTIME_FRONT_TWO = 24; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_X = 199; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_Y = 429; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_WIDTH = 56; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_HEIGHT = 10; +static constexpr uint16_t ANIMATOR_TIME = 50; + +REGIST_SLICE_PAGE(VIEW_WEATHER, WEATHER_PAGES::WEATHER_SECOND_PAGE, WeatherPageSecond, false); + +WeatherPageSecond::WeatherPageSecond() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageSecond::WeatherPageSecond"); + weatherModel = &WeatherModel::GetInstance(); +} + +WeatherPageSecond::~WeatherPageSecond() +{ + if (weatherSwipeGroup != nullptr) { + weatherSwipeGroup->RemoveAll(); + delete weatherSwipeGroup; + weatherSwipeGroup = nullptr; + } + + for (int i = 0; i < SET_THREE; ++i) { + if (swipeGroup[i] != nullptr) { + swipeGroup[i]->RemoveAll(); + delete swipeGroup[i]; + swipeGroup[i] = nullptr; + } + } + + for (int i = 0; i < SET_EIGHT; ++i) { + if (imgBack[i] != nullptr) { + delete imgBack[i]; + imgBack[i] = nullptr; + } + } + + for (int i = 0; i < SET_EIGHT; ++i) { + if (labelTime[i] != nullptr) { + delete labelTime[i]; + labelTime[i] = nullptr; + } + } + + for (int i = 0; i < SET_EIGHT; ++i) { + if (labelTemp[i] != nullptr) { + delete labelTemp[i]; + labelTemp[i] = nullptr; + } + } + + for (int i = 0; i < SET_EIGHT; ++i) { + if (imgWeather[i] != nullptr) { + delete imgWeather[i]; + imgWeather[i] = nullptr; + } + } + if (mainImg != nullptr) { + delete mainImg; + mainImg = nullptr; + } + if (ImagePageKey != nullptr) { + delete ImagePageKey; + ImagePageKey = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageSecond::~WeatherPageSecond"); +} + +void WeatherPageSecond::OnStart(void *data) +{ + weatherSwipeGroup = new UISwipeView(UISwipeView::VERTICAL); + if (weatherSwipeGroup == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "weatherSwipeGroup new fail"); + return; + } + weatherSwipeGroup->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + weatherSwipeGroup->SetViewId("weatherSwipeGroup"); + weatherSwipeGroup->SetOnDragListener(this); + weatherSwipeGroup->SetOnSwipeListener(this); + weatherSwipeGroup->SetDraggable(true); + weatherSwipeGroup->SetTouchable(true); + weatherSwipeGroup->SetAnimatorTime(ANIMATOR_TIME); + for (int i = 0; i < SET_THREE; i++) { + swipeGroup[i] = new UIViewGroup(); + if (swipeGroup[i] == nullptr) { + return; + } + WeatherInit(swipeGroup[i]); + weatherSwipeGroup->Add(swipeGroup[i]); + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::InitPageFirst successful"); + AddViewToPageContainer(weatherSwipeGroup); +} + +void WeatherPageSecond::WeatherInit(UIViewGroup *group) +{ + group->SetPosition(0, 0); + group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + group->SetOnDragListener(this); + group->SetViewId("weather"); + group->SetDraggable(true); + group->SetTouchable(true); + mainImg = new UIImageView(); + mainImg->SetPosition(0, 0); + mainImg->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + ImageInfo *imgSrc = + ImageCacheManager::GetInstance().LoadOneInMultiRes(IMAGE_CONVERTER_TOOL_WEATHER65, WEATHER_IMAGE); + if (imgSrc == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherMainPage::LoadOneInMultiRes fail"); + } + if (weatherModel->GetDayStatus()) { + LOADIMG::LoadImageViewImg(mainImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER64); + } else { + LOADIMG::LoadImageViewImg(mainImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER65); + } + group->Add(mainImg); + houWeather = weatherModel->GetHourWeather(); + ImagePageKey = new UIImageView(); + if (ImagePageKey == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::ImagePageKey new image fail"); + return; + } + ImagePageKey->SetPosition(WEATHER_IMAGEPAGEKEY_X, WEATHER_IMAGEPAGEKEY_Y, WEATHER_IMAGEPAGEKEY_WIDTH, + WEATHER_IMAGEPAGEKEY_HEIGHT); + ImagePageKey->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(ImagePageKey, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER67); + group->Add(ImagePageKey); + int count = index * SET_EIGHT; + index++; + InitImage(group, count); + InitLabel(group, count); + return; +} + +void WeatherPageSecond::InitImage(UIViewGroup *group, int count) +{ + int weatherPosX[SET_EIGHT] = {67, 161, 257, 351, 67, 161, 257, 351}; + int weatherPosY[SET_EIGHT] = {125, 125, 125, 125, 289, 289, 289, 289}; + int backPosX[SET_EIGHT] = {47, 141, 235, 329, 47, 141, 235, 329}; + int backPosY[SET_EIGHT] = {71, 71, 71, 71, 235, 235, 235, 235}; + for (int i = 0; i < SET_EIGHT; i++) { + imgBack[i] = new UIImageView(); + if (imgBack[i] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageSecond::InitPageSecond new UIImageView fail"); + return; + } + imgBack[i]->SetPosition(backPosX[i], backPosY[i]); + if (weatherModel->GetDayStatus()) { + LOADIMG::LoadImageViewImg(imgBack[i], WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER73); + } else { + LOADIMG::LoadImageViewImg(imgBack[i], WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER74); + } + + imgWeather[i] = new UIImageView(); + if (imgWeather[i] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageSecond::InitPageSecond new labelTime fail"); + return; + } + imgWeather[i]->SetPosition(weatherPosX[i], weatherPosY[i]); + int curWeather_code = std::atoi(houWeather[count + i].weather); + LOADIMG::LoadImageViewImg(imgWeather[i], WEATHER_IMAGE, smallWeatherImage[curWeather_code]); + group->Add(imgBack[i]); + group->Add(imgWeather[i]); + } +} + +void WeatherPageSecond::InitLabel(UIViewGroup *group, int count) +{ + int timePosX[SET_EIGHT] = {67, 161, 255, 349, 67, 161, 255, 349}; + int timePosY[SET_EIGHT] = {91, 91, 91, 91, 255, 255, 255, 255}; + int tempPosX[SET_EIGHT] = {75, 169, 263, 356, 75, 169, 263, 356}; + int tempPosY[SET_EIGHT] = {175, 175, 175, 175, 339, 339, 339, 339}; + UILabel *topLabel = new UILabel(); + if (topLabel == nullptr) { + return; + } + topLabel->SetText("24小时预报"); + topLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_TOPLABEL_FRONT); + topLabel->SetPosition(WEATHER_TOPLABEL_X, WEATHER_TOPLABEL_Y, WEATHER_TOPLABEL_WIDTH, WEATHER_TOPLABEL_HEIGHT); + group->Add(topLabel); + for (int i = 0; i < SET_EIGHT; i++) { + labelTemp[i] = new UILabel(); + if (labelTemp[i] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageSecond::InitPageSecond new labelTemp fail"); + return; + } + std::ostringstream oss; + oss << houWeather[count + i].degree << "°"; + std::string temp = oss.str(); + labelTemp[i]->SetText(temp.c_str()); + labelTemp[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABELTIME_FRONT_TWO); + labelTemp[i]->SetPosition(tempPosX[i], tempPosY[i], WEATHER_TITLE_WIDTH, WEATHER_TITLE_HEIGHT); + + labelTime[i] = new UILabel(); + if (labelTime[i] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageSecond::InitPageSecond new labelTime fail"); + return; + } + std::string strHour = houWeather[count + i].hour; + labelTime[i]->SetText(strHour.c_str()); + labelTime[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_LABELTIME_FRONT); + labelTime[i]->SetPosition(timePosX[i], timePosY[i], WEATHER_TITLE_WIDTH, WEATHER_TITLE_HEIGHT); + group->Add(labelTemp[i]); + group->Add(labelTime[i]); + } +} + +bool WeatherPageSecond::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_MAIN_PAGE, nullptr, + TransitionType::TRANSITION_INVALID, true); + } else if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_THIRD_PAGE, nullptr, + TransitionType::TRANSITION_INVALID, true); + } + return false; +} + +void WeatherPageSecond::OnSwipe(UISwipeView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TempPresenter::OnSwipe "); + UNUSED(view); + return; +} + +bool WeatherPageSecond::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherPageThird.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherPageThird.cpp new file mode 100644 index 000000000..d6ca8fbaf --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherPageThird.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPageThird + * Create: 2025-03-23 + */ + +#include "weather/WeatherPageThird.h" +#include "components/ui_list_nested.h" +#include "components/ui_scroll_view_nested.h" +#include "NativeAbility.h" +#include "SlicePageFactory.h" +#include "weather/WeatherPresenter.h" +#include "weather/WeatherView.h" +#include "weather/WeatherModel.h" +#include "ui_resource_weather.h" +#include "common/image_cache_manager.h" +#include "wearable_log.h" + +namespace OHOS { +static constexpr uint8_t WEATHER_ITEM_FONT_SIZE = 25; +static constexpr int16_t WEATHER_RESIZE_SIZE_WIDTH = 200; +static constexpr int16_t WEATHER_RESIZE_SIZE_HEIGHT = 50; +static constexpr int16_t WEATHER_TITLE_POSITION_X = 130; +static constexpr int16_t WEATHER_LIST_POSITION_X = 32; +static constexpr int16_t WEATHER_LIST_POSITION_Y = 70; +static constexpr int16_t WEATHER_LIST_WIDTH = 390; +static constexpr int16_t WEATHER_LIST_HEIGHT = 318; +static constexpr int16_t WEATHER_LIST_SELECT_POSITION = 80; +static constexpr int16_t LIST_POS = 20; +static constexpr int16_t WEATHER_LABEL_FRONT_ONE = 20; +static constexpr int16_t WEATHER_LABEL_FRONT = 40; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_X = 199; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_Y = 429; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_WIDTH = 56; +static constexpr int16_t WEATHER_IMAGEPAGEKEY_HEIGHT = 10; + +REGIST_SLICE_PAGE(VIEW_WEATHER, WEATHER_PAGES::WEATHER_THIRD_PAGE, WeatherPageThird, false); + +WeatherPageThird::WeatherPageThird() +{ + weatherModel = &WeatherModel::GetInstance(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageThird::WeatherPageThird"); +} + +WeatherPageThird::~WeatherPageThird() +{ + if (group != nullptr) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (contentList != nullptr) { + delete contentList; + contentList = nullptr; + } + + if (title != nullptr) { + delete title; + title = nullptr; + } + + if (listAdapter != nullptr) { + delete listAdapter; + listAdapter = nullptr; + } + + if (mainImg != nullptr) { + delete mainImg; + mainImg = nullptr; + } + + if (ImagePageKey != nullptr) { + delete ImagePageKey; + ImagePageKey = nullptr; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(WEATHER_IMAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageThird::~WeatherPageThird"); +} + +void WeatherPageThird::OnStart(void *data) +{ + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::group is nullptr"); + return; + } + group->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + group->SetOnDragListener(this); + + title = new UILabel(); + if (title == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::title is nullptr"); + return; + } + title->SetPosition(WEATHER_TITLE_POSITION_X, WEATHER_LABEL_FRONT_ONE); + title->SetText("7日天气预报"); + title->Resize(WEATHER_RESIZE_SIZE_WIDTH, WEATHER_RESIZE_SIZE_HEIGHT); + title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WEATHER_ITEM_FONT_SIZE); + title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + title->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + title->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + title->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + + mainImg = new UIImageView(); + mainImg->SetPosition(0, 0); + mainImg->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + if (weatherModel->GetDayStatus()) { + LOADIMG::LoadImageViewImg(mainImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER64); + } else { + LOADIMG::LoadImageViewImg(mainImg, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER65); + } + InitScrollView(); + InitScrollData(); + AddViewToPageContainer(group); +} + +void WeatherPageThird::InitScrollView() +{ + contentList = new UIList(); + if (contentList == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::contentList is nullptr"); + return; + } + + contentList->SetPosition(WEATHER_LIST_POSITION_X, WEATHER_LIST_POSITION_Y); + contentList->Resize(WEATHER_LIST_WIDTH, WEATHER_LIST_HEIGHT); + contentList->SetSelectPosition(WEATHER_LIST_SELECT_POSITION); + contentList->SetDraggable(true); + contentList->SetThrowDrag(true); + contentList->EnableAutoAlign(true); + contentList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + contentList->SetElastic(true); + ImagePageKey = new UIImageView(); + if (ImagePageKey == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherPageFirst::ImagePageKey new image fail"); + return; + } + ImagePageKey->SetPosition(WEATHER_IMAGEPAGEKEY_X, WEATHER_IMAGEPAGEKEY_Y, WEATHER_IMAGEPAGEKEY_WIDTH, + WEATHER_IMAGEPAGEKEY_HEIGHT); + ImagePageKey->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + LOADIMG::LoadImageViewImg(ImagePageKey, WEATHER_IMAGE, IMAGE_CONVERTER_TOOL_WEATHER68); + group->Add(mainImg); + group->Add(title); + group->Add(contentList); + group->Add(ImagePageKey); +} + +bool WeatherPageThird::InitScrollData() +{ + const WeatherItem *itemInfo = weatherModel->GetWeatherlistItems(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::InitWeatherItem %s", itemInfo); + RefreshWeathersList(itemInfo, weatherModel->GetWeatherListNum()); + return true; +} + +void WeatherPageThird::RefreshWeathersList(const WeatherItem *item, uint8_t count) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::listAdapter"); + listAdapter = new WeatherAdapter(); + if (listAdapter == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::OnStart::listAdapter is nullptr"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::RefreshWeathersList"); + if (item == nullptr) { + return; + } else { + for (int i = 0; i < count; i++) { + listAdapter->AddListItem(item[i]); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::RefreshWeathersList %d", i); + } + } + if (contentList == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::contentList fail"); + return; + } + contentList->ScrollTo(0); + contentList->SetAdapter(listAdapter); +} + +bool WeatherPageThird::OnDrag(UIView &view, const DragEvent &event) +{ + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().SwitchPageInSlice(WEATHER_PAGES::WEATHER_SECOND_PAGE, nullptr, + TransitionType::TRANSITION_INVALID, true); + } + return false; +} + +void WeatherPageThird::OnSwipe(UISwipeView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TempPresenter::OnSwipe "); + UNUSED(view); + return; +} + +bool WeatherPageThird::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherPresenter.cpp new file mode 100644 index 000000000..c9438428f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherPresenter.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: WeatherPresenter + * Create: 2025-03-23 + */ + +#include "weather/WeatherView.h" +#include "weather/WeatherModel.h" +#include "weather/WeatherPresenter.h" +#include "uiservice/ui_service.h" +#include "NativeRegisterManager.h" +#include "wearable_log.h" + +namespace OHOS { + REGIST_MENU(VIEW_WEATHER, WeatherView, WeatherPresenter, WEATHER_MAIN_ICON, WEATHER_MAIN_ICON, "天气"); +} diff --git a/code/sdk/application/wearable/ohos_deps/CMakeLists.txt b/code/sdk/application/wearable/ohos_deps/CMakeLists.txt index 09de4d2b6..3f7de56c1 100644 --- a/code/sdk/application/wearable/ohos_deps/CMakeLists.txt +++ b/code/sdk/application/wearable/ohos_deps/CMakeLists.txt @@ -5,11 +5,13 @@ set(PUBLIC_HEADER ) set(PRIVATE_HEADER + ${ROOT_DIR}/application/wearable/service/device_msg ) set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/phony_timer.c ${CMAKE_CURRENT_SOURCE_DIR}/ohos_timer.c + ${CMAKE_CURRENT_SOURCE_DIR}/wearable_onlinelog.c ) set(COMPONENT_PUBLIC_CCFLAGS diff --git a/code/sdk/application/wearable/ohos_deps/wearable_log.h b/code/sdk/application/wearable/ohos_deps/wearable_log.h index d641846ad..9e67cac16 100644 --- a/code/sdk/application/wearable/ohos_deps/wearable_log.h +++ b/code/sdk/application/wearable/ohos_deps/wearable_log.h @@ -7,11 +7,6 @@ #ifndef WEARABLE_LOG_H #define WEARABLE_LOG_H -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif #if !defined(SW_UART_DEBUG) && !defined(SW_RTT_DEBUG) #include "soc_diag_util.h" @@ -20,6 +15,13 @@ extern "C" { #else #include "debug_print.h" #endif +#include "wearable_onlinelog.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /** * @brief Enumerates logging module types. @@ -44,11 +46,13 @@ typedef enum { WEARABLE_LOG_MODULE_SMART_VOICE, /* UI SERVICE */ WEARABLE_LOG_MODULE_UI_SERVICE, + /* msg_center */ + WEARABLE_LOG_MODULE_MSG_CENTER, WEARABLE_LOG_MODULE_MAX } WearableLogModuleType; -#if !defined(SW_UART_DEBUG) && !defined(SW_RTT_DEBUG) +#if !defined(SW_UART_DEBUG) && !defined(SW_RTT_DEBUG) && !defined(CONFIG_ONLINE_LOG) #define WEARABLE_LOGE(mod, fmt, arg...) uapi_diag_error_log(0, fmt, ##arg) #define WEARABLE_LOGW(mod, fmt, arg...) uapi_diag_warning_log(0, fmt, ##arg) #define WEARABLE_LOGI(mod, fmt, arg...) uapi_diag_info_log(0, fmt, ##arg) @@ -57,6 +61,15 @@ typedef enum { #else #define WEARABLE_LOGD(mod, fmt, arg...) #endif +#elif (CONFIG_ONLINE_LOG == 1) && !defined(_WIN32) +#define WEARABLE_LOGE(mod, fmt, arg...) ONLINE_PRINT(ONLINE_ERROR, fmt "\n", ##arg) +#define WEARABLE_LOGW(mod, fmt, arg...) ONLINE_PRINT(ONLINE_WARN, fmt "\n", ##arg) +#define WEARABLE_LOGI(mod, fmt, arg...) ONLINE_PRINT(ONLINE_INFO, fmt "\n", ##arg) +#ifdef WEARABLE_LOG_DEBUG +#define WEARABLE_LOGD(mod, fmt, arg...) ONLINE_PRINT(ONLINE_INFO, fmt "\n", ##arg) +#else +#define WEARABLE_LOGD(mod, fmt, arg...) +#endif #else #define WEARABLE_LOGE(mod, fmt, arg...) PRINT("[WEARABLE E/] " fmt "\n", ##arg) #define WEARABLE_LOGW(mod, fmt, arg...) PRINT("[WEARABLE W/] " fmt "\n", ##arg) @@ -68,36 +81,36 @@ typedef enum { #endif #endif -#define CHECK_NULL_AND_RETURN(pointer, mod, fmt) \ - do { \ - if ((pointer) == nullptr) { \ - WEARABLE_LOGE((mod), (fmt)); \ - return; \ - } \ +#define CHECK_NULL_AND_RETURN(pointer, mod, fmt) \ + do { \ + if ((pointer) == nullptr) { \ + WEARABLE_LOGE((mod), (fmt)); \ + return; \ + } \ } while (0) -#define CHECK_NULL_AND_RETURN_NULL(pointer, mod, fmt) \ - do { \ - if ((pointer) == nullptr) { \ - WEARABLE_LOGE((mod), (fmt)); \ - return nullptr; \ - } \ +#define CHECK_NULL_AND_RETURN_NULL(pointer, mod, fmt) \ + do { \ + if ((pointer) == nullptr) { \ + WEARABLE_LOGE((mod), (fmt)); \ + return nullptr; \ + } \ } while (0) #define CHECK_NULL_AND_RETURN_CODE(pointer, mod, fmt, code) \ - do { \ - if ((pointer) == nullptr) { \ - WEARABLE_LOGE((mod), (fmt)); \ + do { \ + if ((pointer) == nullptr) { \ + WEARABLE_LOGE((mod), (fmt)); \ return (code); \ - } \ + } \ } while (0) -#define DELETE_IF_NOT_NULL(pointer) \ - do { \ - if ((pointer) != nullptr) { \ - delete (pointer); \ - (pointer) = nullptr; \ - } \ +#define DELETE_IF_NOT_NULL(pointer) \ + do { \ + if ((pointer) != nullptr) { \ + delete (pointer); \ + (pointer) = nullptr; \ + } \ } while (0) #ifdef __cplusplus diff --git a/code/sdk/application/wearable/ohos_deps/wearable_onlinelog.c b/code/sdk/application/wearable/ohos_deps/wearable_onlinelog.c new file mode 100644 index 000000000..8cb72c40e --- /dev/null +++ b/code/sdk/application/wearable/ohos_deps/wearable_onlinelog.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: wearable_onlinelog src fie. + * Author: CompanyName + * Create: + */ +#include "wearable_log.h" +#include "securec.h" +#include "diag_ind_src.h" +#include "diag_service.h" +#include "diag_common.h" +#include "msg_center_protocol.h" +#include "msg_center_device.h" +#if defined(SW_UART_DEBUG) +#include "uart.h" +#endif + +#if (CONFIG_ONLINE_LOG == 1) && !defined(_WIN32) +#define TL_BYTE1 1 +#define TL_BYTE2 2 +#define SHIFT_8_BIT 8 + +#define SET_UART_CHANNEL_CMD 1 +#define SET_BR_CHANNEL_CMD 2 +#define SET_BLE_CHANNEL_CMD 3 + +static uint8_t g_log_diag_channel = DIAG_FRAME_FID_PC; + +// 在线日志级别对应的字符串 +static const char *gLevelStrings[] = {"[WEARABLE D/] ", "[WEARABLE I/] ", "[WEARABLE W/] ", "[WEARABLE E/] "}; +// 在线日志过滤器; +static uint8_t gOnlineLevelFilter = 0xf; + +errcode_t uapi_diag_service_send_log(uint8_t channel, uint8_t type, uint8_t *payload, uint32_t pay_len); + +static uint8_t calculate_tl_byte(uint32_t payloadLen) +{ + uint8_t tl_byte = 0; + if (payloadLen <= 0x7f) { + tl_byte = 0; + } else if (payloadLen > 0xff) { + tl_byte = TL_BYTE2; + } else { + tl_byte = TL_BYTE1; + } + return tl_byte; +} + +void set_online_log_level(uint8_t filter) +{ + gOnlineLevelFilter = filter; +} + +static void send_uart_str(const char *s, uint32_t str_len) +{ +#if defined(SW_UART_DEBUG) + if (hal_uart_get_funcs(SW_DEBUG_UART_BUS) == NULL) { + return; + } + uapi_uart_write(SW_DEBUG_UART_BUS, (const void *)s, str_len, 0); +#endif +} + +void change_log_diag_channel(uint8_t channel) +{ + if (channel == SET_UART_CHANNEL_CMD) { + g_log_diag_channel = DIAG_FRAME_FID_PC; + } else if (channel == SET_BR_CHANNEL_CMD) { + g_log_diag_channel = DIAG_FRAME_FID_PHONE; + } else if (channel == SET_BLE_CHANNEL_CMD) { + g_log_diag_channel = DIAG_FRAME_FID_BT; + } else { + g_log_diag_channel = DIAG_FRAME_FID_PC; + } +} + +uint8_t get_log_diag_channel() +{ + return g_log_diag_channel; +} + +void online_print_str(uint16_t level, const char *str, ...) +{ + static uint8_t buffer[1024]; + uint8_t filter = (1 << level) & gOnlineLevelFilter; + if (!filter) { + return; + } + int offset = sprintf_s((char *)buffer, sizeof(buffer), "%s", gLevelStrings[level]); + if (offset < 0 || (size_t)offset >= sizeof(buffer)) { + return; + } + va_list args; + va_start(args, str); + offset += vsprintf_s((char *)(buffer + offset), sizeof(buffer) - offset, str, args); + if (offset < 0 || (size_t)offset >= sizeof(buffer)) { + va_end(args); + return; + } + va_end(args); + uint8_t channel = get_log_diag_channel(); + if (channel == DIAG_FRAME_FID_PC) { + send_uart_str((const char *)buffer, offset); + } else { + uapi_diag_service_send_log(channel, MSGCENTER_TYPE_ID_ONLINELOG_REPORT, buffer, offset); + } +} + +errcode_t uapi_diag_service_send_log(uint8_t channel, uint8_t type, uint8_t *payload, uint32_t pay_len) +{ + uint8_t size; + diag_ser_data_t *diag_data; + diag_ser_frame_t *frame; + uint32_t result = ERRCODE_FAIL; + // 计算tl的长度及填充tl数据; + uint8_t tl_byte = calculate_tl_byte(pay_len); + uint32_t tl_len = sizeof(msg_center_pkt_tlv_t) + tl_byte; + uint8_t tl_data[4]; + msg_center_pkt_tlv_t *tl = (msg_center_pkt_tlv_t *)tl_data; + tl->type = 0x80 | type; + if (tl_byte == TL_BYTE1) { + tl->len = tl_byte; + tl->data[0] = (uint8_t)pay_len; + } else if (tl_byte == TL_BYTE2) { + tl->len = tl_byte; + tl->data[0] = (uint16_t)pay_len & 0xff; + tl->data[1] = (uint16_t)pay_len >> SHIFT_8_BIT; + } else { + tl->len = 0x80 | (uint8_t)pay_len; + } + + size = sizeof(diag_ser_data_t) + sizeof(diag_ser_frame_t) + pay_len + tl_len; + diag_data = (diag_ser_data_t *)malloc(size); + if (diag_data == NULL) { + return ERRCODE_FAIL; + } + + diag_data->header.ser_id = DIAG_SER_MSG_CENTER; + diag_data->header.cmd_id = MSGCENTER_CMD_DEVICE; + diag_data->header.ack_en = false; + diag_data->header.src = DIAG_FRAME_FID_MCU; + diag_data->header.dst = channel; + diag_data->header.crc_en = 1; + diag_data->header.length = size - sizeof(diag_ser_data_t); // size = modeleId + cmdId + tlv + + frame = (diag_ser_frame_t *)&(diag_data->payload); + frame->module_id = DIAG_SER_MSG_CENTER; + frame->cmd_id = MSGCENTER_CMD_DEVICE; + (void)memcpy_s(&(frame->tlv), tl_len, tl, tl_len); + (void)memcpy_s(&(frame->tlv[tl_len]), pay_len, payload, pay_len); + result = uapi_diag_service_send_data(diag_data); + free(diag_data); + return result; +} +#endif diff --git a/code/sdk/application/wearable/ohos_deps/wearable_onlinelog.h b/code/sdk/application/wearable/ohos_deps/wearable_onlinelog.h new file mode 100644 index 000000000..9ed85ed06 --- /dev/null +++ b/code/sdk/application/wearable/ohos_deps/wearable_onlinelog.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: Wearable onlinelog header file. + * Author: + * Create: + */ + +#ifndef WEARABLE_ONLINELOG_H +#define WEARABLE_ONLINELOG_H + +#include "stdint.h" +#include "errcode.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +/* 特性: 在线日志 */ +#ifndef CONFIG_ONLINE_LOG +#define CONFIG_ONLINE_LOG 1 +#endif + +enum OnLineLogLevel { + ONLINE_DEBUG = 0, + ONLINE_INFO, + ONLINE_WARN, + ONLINE_ERROR +}; + +void online_print_str(uint16_t level, const char *str, ...); +void change_log_diag_channel(uint8_t channel); +uint8_t get_log_diag_channel(void); +void set_online_log_level(uint8_t filter); +errcode_t uapi_diag_service_send_log(uint8_t channel, uint8_t type, uint8_t *payload, uint32_t pay_len); + +#ifndef ONLINE_PRINT +#define ONLINE_PRINT(level, fmt, arg...) online_print_str(level, fmt, ##arg) +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif // WEARABLE_ONLINELOG_H \ No newline at end of file diff --git a/code/sdk/application/wearable/ohos_startup/CMakeLists.txt b/code/sdk/application/wearable/ohos_startup/CMakeLists.txt index 41c20067a..e68cca93f 100644 --- a/code/sdk/application/wearable/ohos_startup/CMakeLists.txt +++ b/code/sdk/application/wearable/ohos_startup/CMakeLists.txt @@ -14,6 +14,7 @@ set(PUBLIC_HEADER set(PRIVATE_HEADER ${ROOT_DIR}/open_source/mbedtls/mbedtls_v3.6.0/ + ${ROOT_DIR}/application/wearable/service/device_msg/ ) set(PRIVATE_DEFINES diff --git a/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c b/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c index 6b2fb6821..d1f181e8d 100644 --- a/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c +++ b/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c @@ -97,6 +97,10 @@ boot_animation_init_deinit(); if (upg_check_upgrade_need_upgrade()) return ; #endif OHOS_SystemInit(); + +#ifdef PUBLISH_TEST_DATA + PublishTestData(); +#endif #ifdef SUPPORT_POWER_MANAGER const power_display_svr_api_t *display_api = power_display_svr_get_api(); diff --git a/code/sdk/application/wearable/service/CMakeLists.txt b/code/sdk/application/wearable/service/CMakeLists.txt index 7b1691bee..1137e9b93 100644 --- a/code/sdk/application/wearable/service/CMakeLists.txt +++ b/code/sdk/application/wearable/service/CMakeLists.txt @@ -8,6 +8,8 @@ add_subdirectory_if_exist(xiaodu_navi) add_subdirectory_if_exist(xiaodu_voice) add_subdirectory_if_exist(xiaodu_navi_vector) add_subdirectory_if_exist(hc_demo_msg) +add_subdirectory_if_exist(device_msg) +add_subdirectory_if_exist(remote_msg) add_subdirectory_if_exist(auto_ota_msg) add_subdirectory_if_exist(alipay_msg) add_subdirectory_if_exist(app_store) diff --git a/code/sdk/application/wearable/service/app_store/CMakeLists.txt b/code/sdk/application/wearable/service/app_store/CMakeLists.txt index e679c5341..5cfeb9a55 100644 --- a/code/sdk/application/wearable/service/app_store/CMakeLists.txt +++ b/code/sdk/application/wearable/service/app_store/CMakeLists.txt @@ -8,7 +8,6 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/uiservice/include ) set(SOURCES diff --git a/code/sdk/application/wearable/service/app_store/app_store.cpp b/code/sdk/application/wearable/service/app_store/app_store.cpp index 8c6efbeb1..f7cc6c66d 100644 --- a/code/sdk/application/wearable/service/app_store/app_store.cpp +++ b/code/sdk/application/wearable/service/app_store/app_store.cpp @@ -8,7 +8,7 @@ #include "bundle_install_msg.h" #include "bundlems_slite_client.h" #include "appexecfwk_errors.h" -#include "ui_service.h" +#include "uiservice/ui_service.h" void AppStoreReplyAck(uint8_t cmd_id, uint8_t type, uint32_t ack) { @@ -112,7 +112,13 @@ errcode_t AppStoreGetPkgList(uint8_t cmd_id, uint8_t type, void *usr_data, uint1 for (int32_t i = 0; i < count; i++) { (void)strncpy_s((char*)unitInfo[i].pkgName, PKG_NAME_MAX_LENGTH, bundleInfos[i].bundleName, strlen(bundleInfos[i].bundleName)); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppStoreGetPkgList pkgName[%d] = %s", i, unitInfo[i].pkgName); + (void)strncpy_s((char*)unitInfo[i].versionName, VERSION_NAME_MAX_LENGTH, + bundleInfos[i].versionName, strlen(bundleInfos[i].versionName)); + (void)strncpy_s((char*)unitInfo[i].labelName, LABEL_NAME_MAX_LENGTH, + bundleInfos[i].label, strlen(bundleInfos[i].label)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppStoreGetPkgList pkgName[%d] = %s, versionName[%d] = %s,\ + labeName[%d] = %s", i, unitInfo[i].pkgName, i, unitInfo[i].versionName, i, + unitInfo[i].labelName); unitInfo[i].versionCode = bundleInfos[i].versionCode; } ret = msg_center_send_data(MSGCENTER_CMD_APP_STORE, type, infoList, len); @@ -127,3 +133,40 @@ errcode_t AppStoreGetPkgList(uint8_t cmd_id, uint8_t type, void *usr_data, uint1 } return ret; } + +errcode_t AppStoreGetBundleInfo(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + BundleInfo bundleInfo; + int32_t ret = ERRCODE_FAIL; + + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + char *bundleName = (char *)malloc(payload_len + 1); + (void)memcpy_s(bundleName, payload_len, tlv_payload, payload_len); + bundleName[payload_len] = '\0'; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bundleName = %s", bundleName); + + uint8_t bundleRet = OHOS::BundleMsClient::GetInstance().GetBundleInfo(bundleName, 0, &bundleInfo); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "get bundleInfo, ret = %d", bundleRet); + + int32_t len = sizeof(PkgUnitInfo); + PkgUnitInfo *info = (PkgUnitInfo *)malloc(len); + if (info != nullptr) { + memset_s(info, len, 0, len); + (void)strncpy_s((char*)info->pkgName, PKG_NAME_MAX_LENGTH, bundleInfo.bundleName, + strlen(bundleInfo.bundleName)); + (void)strncpy_s((char*)info->versionName, VERSION_NAME_MAX_LENGTH, bundleInfo.versionName, + strlen(bundleInfo.versionName)); + (void)strncpy_s((char*)info->labelName, LABEL_NAME_MAX_LENGTH, bundleInfo.label, strlen(bundleInfo.label)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppStoreGetBundleInfo pkgName = %s, versionName = %s, labeName = %s", + info->pkgName, info->versionName, info->labelName); + info->versionCode = bundleInfo.versionCode; + ret = msg_center_send_data(cmd_id, type, info, len); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "AppStoreGetBundleInfo send data ret = 0x%x", ret); + free(info); + free(bundleName); + } + + return ret; +} \ No newline at end of file diff --git a/code/sdk/application/wearable/service/app_store/app_store.h b/code/sdk/application/wearable/service/app_store/app_store.h index 7bbc93b96..375740141 100644 --- a/code/sdk/application/wearable/service/app_store/app_store.h +++ b/code/sdk/application/wearable/service/app_store/app_store.h @@ -18,6 +18,8 @@ extern "C" { #endif #define PKG_NAME_MAX_LENGTH 128 +#define VERSION_NAME_MAX_LENGTH 128 +#define LABEL_NAME_MAX_LENGTH 256 #define FS_DIR_APP_STORE "/user/app_store/" typedef enum { @@ -29,6 +31,7 @@ typedef enum { APP_STORE_OPERATION = 0x01, APP_STORE_NOTIFY_PROGRESS = 0x02, APP_STORE_GET_PKG_LIST = 0x03, + APP_STORE_GET_BUNDLEINFO = 0x04, } AppStoreType; typedef enum { @@ -60,10 +63,13 @@ typedef struct { typedef struct { uint8_t pkgName[PKG_NAME_MAX_LENGTH]; int32_t versionCode; + uint8_t versionName[VERSION_NAME_MAX_LENGTH]; + uint8_t labelName[LABEL_NAME_MAX_LENGTH]; } PkgUnitInfo; errcode_t AppStorePkgOperation(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); errcode_t AppStoreGetPkgList(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t AppStoreGetBundleInfo(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/application/wearable/service/app_store/app_store_msg.cpp b/code/sdk/application/wearable/service/app_store/app_store_msg.cpp index f34d838d8..d2f1f1a08 100644 --- a/code/sdk/application/wearable/service/app_store/app_store_msg.cpp +++ b/code/sdk/application/wearable/service/app_store/app_store_msg.cpp @@ -10,6 +10,7 @@ extern "C" { static const msg_center_cmd_map_t g_appStoreTbl[] = { { MSGCENTER_CMD_APP_STORE, APP_STORE_OPERATION, AppStorePkgOperation }, { MSGCENTER_CMD_APP_STORE, APP_STORE_GET_PKG_LIST, AppStoreGetPkgList }, + { MSGCENTER_CMD_APP_STORE, APP_STORE_GET_BUNDLEINFO, AppStoreGetBundleInfo }, }; errcode_t AppStoreTypeDispatch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) diff --git a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h index 54854380c..8359e67ba 100644 --- a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h +++ b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h @@ -43,7 +43,9 @@ typedef enum { TOPIC_EVENT_HFP_FINISHED, TOPIC_EVENT_HFP_PHONE_TO_WATCH, TOPIC_EVENT_HFP_WATCH_TO_PHONE, - + TOPIC_EVENT_BLOODOXYGEN_UPDATA, + TOPIC_EVENT_SPORT_DISTANCE, + TOPIC_EVENT_LOCATION, TOPIC_END_NUM = 20000, } TopicNum; diff --git a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c index 2560ff487..5fe38efd7 100644 --- a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c @@ -32,6 +32,9 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_EVENT_HFP_FINISHED, A_CORE_MASK, 1}, {TOPIC_EVENT_HFP_PHONE_TO_WATCH, A_CORE_MASK, 1}, {TOPIC_EVENT_HFP_WATCH_TO_PHONE, A_CORE_MASK, 1}, + {TOPIC_EVENT_BLOODOXYGEN_UPDATA, A_CORE_MASK, 1}, + {TOPIC_EVENT_SPORT_DISTANCE, A_CORE_MASK, 1}, + {TOPIC_EVENT_LOCATION, A_CORE_MASK, 1}, }; /* 所有的topic,其对应的位图 */ diff --git a/code/sdk/application/wearable/service/device_msg/CMakeLists.txt b/code/sdk/application/wearable/service/device_msg/CMakeLists.txt new file mode 100644 index 000000000..9ea557d33 --- /dev/null +++ b/code/sdk/application/wearable/service/device_msg/CMakeLists.txt @@ -0,0 +1,51 @@ +set(COMPONENT_NAME "device_msg") + +set(PUBLIC_HEADER +) + +set(PRIVATE_HEADER + ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits + ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits + ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include + ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/innerkits + ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits + ${ROOT_DIR}/middleware/services/media/foundation/audiomanager/interfaces/kits/audiomanager + ${ROOT_DIR}/middleware/services/gui/uikit/ui/frameworks + ${ROOT_DIR}/middleware/services/gui/uikit/surface/interfaces/kits + ${ROOT_DIR}/middleware/chips/brandy/nv/include + ${ROOT_DIR}/middleware/chips/brandy/nv/nv_config + ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include + ${ROOT_DIR}/open_source/openharmony/base/sensors/location/interfaces/kits/include + ${ROOT_DIR}/middleware/utils/dfx/diag/ +) + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/device_msg.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/device_proxy.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/msg_center_device.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/device_location.cpp +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -std=c++11 + -Wno-missing-field-initializers +) + +set(WHOLE_LINK + true +) + +set(PUBLIC_DEFINES +) + +set(PRIVATE_DEFINES + APP_PLATFORM_WATCHGT + CONFIG_ACELITE_ENABLE +) + +build_component() + + diff --git a/code/sdk/application/wearable/service/device_msg/device_location.cpp b/code/sdk/application/wearable/service/device_msg/device_location.cpp new file mode 100644 index 000000000..d24a14f75 --- /dev/null +++ b/code/sdk/application/wearable/service/device_msg/device_location.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ +#include "device_location.h" +#include "wearable_log.h" +#include "locator.h" + +using namespace OHOS::Location; + +LocationInfo_t g_locationInfo = {0}; + +class GnssStatusCallback : public IGnssStatusCallback { +public: + GnssStatusCallback() {} + ~GnssStatusCallback() {} + + void OnStatusChange(const std::shared_ptr &statusInfo) override + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "OnStatusChange, num:%d\n", statusInfo->GetSatellitesNumber()); + for (int32_t satIdx = 0; satIdx < statusInfo->GetSatellitesNumber(); satIdx++) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "sat index:%d svid:%d ele:%.3f az:%.3f cnr:%.3f \n", satIdx, + statusInfo->GetSatelliteIds()[satIdx], statusInfo->GetAltitudes()[satIdx], + statusInfo->GetAzimuths()[satIdx], statusInfo->GetCarrierToNoiseDensitys()[satIdx]); + } + } + +private: +}; + +class NmeaMessageCallback : public INmeaMessageCallback { +public: + NmeaMessageCallback() {} + ~NmeaMessageCallback() {} + + void OnMessageChange(int64_t timestamp, const std::string msg) override + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "OnMessageChange timestamp :%lld msg:%s\n", timestamp, msg.c_str()); + } + +private: +}; + +class LocatorCallback : public ILocatorCallback { +public: + LocatorCallback() {} + + ~LocatorCallback() {} + + void OnLocationReport(const std::shared_ptr &location) override + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "OnLocationReport Lat:%.3f Long:%.3f Alt:%.3f Speed:%.3f dir:%.3f\n", + location->GetLatitude(), location->GetLongitude(), location->GetAltitude(), location->GetSpeed(), + location->GetDirection()); + } + + void OnErrorReport(const int errorCode) override + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "error code:%d\n", errorCode); + } + + void OnLocatingStatusChange(const int status) override + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "OnLocatingStatusChange status:%d\n", status); + } + +private: +}; + +typedef struct { + Locator *locator; + bool isStarted; + LocatorCallback locatorCallback; + GnssStatusCallback gnssStatusCallback; + NmeaMessageCallback nmeaMessageCallback; +} LocationSampleContext; + +static LocationSampleContext g_locationContext = { + .locator = nullptr, + .isStarted = false, +}; + +int32_t deviceLocationStartLocating() +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "LocationStartLocating\n"); + if (g_locationContext.locator == nullptr) { + g_locationContext.locator = &Locator::GetInstance(); + } + if (g_locationContext.locator == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator is nullptr\n"); + return ERRCODE_FAILURE; + } + + bool isEnabled = false; + LocationErrCode errCode = g_locationContext.locator->IsLocationEnabled(isEnabled); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator IsLocationEnabled failed:%d\n", errCode); + return errCode; + } + + if (!isEnabled) { + errCode = g_locationContext.locator->EnableAbility(true); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator EnableAbility failed:%d\n", errCode); + return errCode; + } + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "RegisterGnssStatusCallback\n"); + errCode = g_locationContext.locator->RegisterGnssStatusCallback(&g_locationContext.gnssStatusCallback); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator RegisterGnssStatusCallback failed:%d\n", errCode); + return errCode; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "RegisterNmeaMessageCallback\n"); + errCode = g_locationContext.locator->RegisterNmeaMessageCallback(&g_locationContext.nmeaMessageCallback); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator RegisterNmeaMessageCallback failed:%d\n", errCode); + return errCode; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "StartLocating\n"); + RequestConfig requestConfig; + requestConfig.SetPriority(PRIORITY_ACCURACY); + errCode = g_locationContext.locator->StartLocating(&requestConfig, &g_locationContext.locatorCallback); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator StartLocating failed:%d\n", errCode); + return errCode; + } + g_locationContext.isStarted = true; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "StartLocating end\n"); + return ERRCODE_SUCCESS; +} + +int32_t deviceLocationStopLocating() +{ + if (!g_locationContext.isStarted) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator is not started\n"); + return ERRCODE_FAILURE; + } + LocationErrCode errCode = + g_locationContext.locator->UnregisterNmeaMessageCallback(&g_locationContext.nmeaMessageCallback); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator UnregisterNmeaMessageCallback failed:%d\n", errCode); + return errCode; + } + errCode = g_locationContext.locator->UnregisterGnssStatusCallback(&g_locationContext.gnssStatusCallback); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator RegisterGnssStatusCallback failed:%d\n", errCode); + return errCode; + } + errCode = g_locationContext.locator->StopLocating(&g_locationContext.locatorCallback); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator StopLocating failed:%d\n", errCode); + return errCode; + } + g_locationContext.isStarted = false; + + bool isEnabled = false; + errCode = g_locationContext.locator->IsLocationEnabled(isEnabled); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator IsLocationEnabled failed:%d\n", errCode); + return errCode; + } + if (!isEnabled) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator Is not Enabled\n"); + return ERRCODE_FAILURE; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "EnableAbility false\n"); + errCode = g_locationContext.locator->EnableAbility(false); + if (errCode != ERRCODE_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "locator EnableAbility failed:%d\n", errCode); + return errCode; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Disable end\n"); + return ERRCODE_SUCCESS; +} \ No newline at end of file diff --git a/code/sdk/application/wearable/service/device_msg/device_location.h b/code/sdk/application/wearable/service/device_msg/device_location.h new file mode 100644 index 000000000..3305d698c --- /dev/null +++ b/code/sdk/application/wearable/service/device_msg/device_location.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + */ +#ifndef DEVICE_LOCATION_H +#define DEVICE_LOCATION_H +#include + +typedef struct LocationInfo { + int32_t latitude_; + int32_t longitude_; + uint16_t altitude_; + uint16_t accuracy_; + uint16_t speed_; + uint16_t direction_; + int64_t timeStamp_; +} LocationInfo_t; + +int32_t deviceLocationStartLocating(); +int32_t deviceLocationStopLocating(); +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/device_msg/device_msg.cpp b/code/sdk/application/wearable/service/device_msg/device_msg.cpp new file mode 100644 index 000000000..3f54b45ab --- /dev/null +++ b/code/sdk/application/wearable/service/device_msg/device_msg.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: Breath Ease + * Author: wangle + * Create: 2025-4-23 + */ +#include "msg_center_protocol.h" +#include "msg_center_cmd.h" +#include "ohos_init.h" +#include "msg_center_device.h" +#ifdef PUBLISH_TEST_DATA +#include +#include +#include "graphic_timer.h" +#include "broadcast_feature.h" +#include "ohos_timer.h" +#include "heartrate/HeartModel.h" +#include "device_location.h" +#endif +namespace OHOS { + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef PUBLISH_TEST_DATA +#define BLOODOXYGEN_LOWER 90 +#define BLOODOXYGEN_RANGE 10 +#define STEP_RANGE 5 +#define DISTANCE_RANGE 10 +#define HEARTRATE_LOWER 60 +#define HEARTRATE_RANGE 60 +static uint8_t g_rotation_publish = 0; +static GraphicTimer *g_publishTestDataHandle = nullptr; +enum publishDataType { + PUBLISH_SETP = 0, + PUBLISH_DISTANCE, + PUBLISH_HEARTRATE, + PUBLISH_BLOODOXYGEN, + PUBLISH_TYPE_MAX +}; + +static void PublishTopicTestDataEvent(uint16_t topic, const void *data, size_t len) +{ + int32_t ret; + uint16_t size = len; + BroadcastApi *broadcastApi = nullptr; + IUnknown *api = nullptr; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PublishTopicTestDataEvent topic=%u!!", topic); + + void *publishData = malloc(size); + if (publishData == nullptr) { + return; + } + ret = memcpy_s(publishData, size, data, size); + if (ret != EOK) { + free(publishData); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PublishTopicTestDataEvent memcpy_s fail! ret = %d", ret); + return; + } + + Request request = { + .msgId = topic, + .len = size, + .msgValue = 0, + .data = publishData, + }; + + /* public request */ + api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME); + if (api == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetFeatureApi failed"); + free(publishData); + return; + } + ret = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi); + if (ret != 0 || broadcastApi == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QueryInterface failed"); + free(publishData); + return; + } + broadcastApi->PublishTopic((IUnknown *)broadcastApi, &request); + broadcastApi->Release((IUnknown *)broadcastApi); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PublishTopicTestDataEvent end!!"); + + return; +} + +static void PublishTestDataCallback(void *) +{ + switch (g_rotation_publish++ % PUBLISH_TYPE_MAX) { + case PUBLISH_BLOODOXYGEN: { + uint8_t blood_oxygen = BLOODOXYGEN_LOWER + rand() % BLOODOXYGEN_RANGE; + PublishTopicTestDataEvent(TOPIC_EVENT_BLOODOXYGEN_UPDATA, &blood_oxygen, sizeof(uint8_t)); + break; + } + case PUBLISH_SETP: { + uint32_t step = rand() % STEP_RANGE; + PublishTopicTestDataEvent(TOPIC_EVENT_STEPDATA_UPDATE, &step, sizeof(uint32_t)); + break; + } + case PUBLISH_HEARTRATE: { + HeartDatas heart_data = {0}; + heart_data.perSec = HEARTRATE_LOWER + rand() % HEARTRATE_RANGE; + PublishTopicTestDataEvent(TOPIC_EVENT_HEARTRATE_UPDATA, &heart_data, sizeof(HeartDatas)); + break; + } + case PUBLISH_DISTANCE: { + uint32_t distance = rand() % DISTANCE_RANGE; + PublishTopicTestDataEvent(TOPIC_EVENT_SPORT_DISTANCE, &distance, sizeof(uint32_t)); + break; + } + default: + break; + } +} + +void PublishTestData() +{ + uint32 tick = GetOSTick(5000); // 5秒发布一次测试数据 + if (g_publishTestDataHandle == nullptr) { + g_publishTestDataHandle = new GraphicTimer(tick, PublishTestDataCallback, nullptr, true); + } + if (g_publishTestDataHandle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PublishTestData new GraphicTimer failed!!"); + return; + } + bool retTimer = g_publishTestDataHandle->Start(); + if (!retTimer) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PublishTestData Start failed!!"); + if (g_publishTestDataHandle != nullptr) { + delete g_publishTestDataHandle; + g_publishTestDataHandle = nullptr; + } + return; + } +} +#endif +static const msg_center_cmd_map_t g_msg_center_device_tbl[] = { + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_GET_BATTERY_LEVEL, msg_center_get_battery_level}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_GET_STORAGE_INFO, msg_center_get_storage_info}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_GET_PRODUCT_INFO, msg_center_get_product_info}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_GET_LANGUAGE_ID, msg_center_get_language_id}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_GET_VOLUME_INFO, msg_center_get_volume_info}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SET_LANGUAGE_ID, msg_center_set_language_id}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SET_VOLUME_INFO, msg_center_set_volume_info}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_DEVICE_HEARTRATE, msg_center_device_heartrate}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_DEVICE_STEPDATA, msg_center_device_stepdata}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_DEVICE_BLOODOXYGEN, msg_center_device_bloodoxygen}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_OFFLINE_LOG_SWITCH, msg_center_offline_log_switch}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_LOCATION_GET_INFO, msg_center_location_get_info}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_LOCATION_START, msg_center_location_start}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_LOCATION_STOP, msg_center_location_stop}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_ACTION, msg_center_sport_action}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_GET_DATA, msg_center_sport_get_data}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SPORT_REPORT_DATA, msg_center_sport_report_data}, +#if (CONFIG_ONLINE_LOG == 1) + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SET_ONLINELOG_CHANNEL, msg_center_set_online_log_channel}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_SET_ONLINELOG_LEVEL, msg_center_set_online_log_level}, +#endif + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_OTA_INIT, msg_center_ota_init}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_OTA_UPDATE, msg_center_ota_update}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_OFF_FIND_PHONE, msg_center_device_findphone}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_CAMERA_WATCH_EXIT, msg_center_camera_exit}, + {MSGCENTER_CMD_DEVICE, MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE_SUCCESS, msg_center_camera_online}, +}; + +errcode_t msg_center_device_type_dispatch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tbl_size = sizeof(g_msg_center_device_tbl) / sizeof(g_msg_center_device_tbl[0]); + uint8_t i; + for (i = 0; i < tbl_size; i++) { + msg_center_cmd_map_t *item = (msg_center_cmd_map_t *)&g_msg_center_device_tbl[i]; + if ((item->type == type) && (item->handler != NULL)) { + item->handler(cmd_id, type, usr_data, usr_len); + return ERRCODE_SUCC; + } + } + return ERRCODE_NOT_SUPPORT; +} + +void device_init(void) +{ + msg_center_register_cmd(MSGCENTER_CMD_DEVICE, msg_center_device_type_dispatch); +} + +APP_FEATURE_INIT_PRI(device_init, LAYER_INIT_LEVEL_4); +#ifdef __cplusplus +} +#endif +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/service/device_msg/device_proxy.cpp b/code/sdk/application/wearable/service/device_msg/device_proxy.cpp new file mode 100644 index 000000000..336cfd7ed --- /dev/null +++ b/code/sdk/application/wearable/service/device_msg/device_proxy.cpp @@ -0,0 +1,476 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: Breath Ease + * Author: wangle + * Create: 2025-4-23 + */ +#include +#include "device_proxy.h" +#include "wearable_log.h" +#include "common_def.h" +#include "cpp/audio_manager.h" +#include "uiservice/ui_service.h" +#include "ui_resource_string.h" +#include +#include +#include "key_id.h" +#include "common.h" +#include "nv.h" +#include "upg.h" +#include "upg_porting.h" + +namespace OHOS { +static constexpr const char *MOUNT_POINT[] = {"/system", "/user", "/update", "/music"}; +static constexpr const uint16_t language_protocol[] = {(uint8_t)(0x0u << 8) | LANGUAGE_ID_ZH, + (uint8_t)(0x1u << 8) | LANGUAGE_ID_ZH, + (uint8_t)(0x2u << 8) | LANGUAGE_ID_EN}; +static constexpr const uint8_t language_mask_bits = 8; +static constexpr const uint16_t language_key_mask = 0xFF00; +static constexpr const uint16_t language_val_mask = 0x00FF; + +static constexpr const uint8_t percentage_scale = 100; // 百分比换算基数 +static constexpr const uint8_t percentage_max = 100; +static constexpr const uint8_t percentage_min = 0; + +static constexpr const uint32_t adc_reference_ratio_numerator = 450U; // 18 * 1000 +static constexpr const uint32_t adc_reference_ratio_denominator = 1024U / 2U; // 40960 / (1000/18)/2U +static constexpr const uint32_t millivolt_per_volt = 1000U; + +static constexpr const uint32_t def_samples_to_keep = 10; +static constexpr const uint32_t def_samples_to_discard = 5; +static constexpr const uint32_t def_adc_max_range_mv = 380; +static constexpr const uint32_t def_adc_min_range_mv = 0; + +template +T clamp(const T &value, const T &min_val, const T &max_val) +{ + return (value < min_val) ? (min_val) : (value > max_val ? max_val : value); +} + +void device_proxy::get_storage_info(storage_info &info) +{ + memset_s(&info, sizeof(storage_info), 0, sizeof(storage_info)); + for (size_t i = 0; i < sizeof(MOUNT_POINT) / sizeof(MOUNT_POINT[0]); i++) { + struct statfs tmpStat = {0}; + if (statfs(MOUNT_POINT[i], &tmpStat) != 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "无法获取%s的挂载点信息,%s", MOUNT_POINT[i], strerror(errno)); + continue; + } + + uint32_t total = static_cast(tmpStat.f_blocks * tmpStat.f_bsize); + uint32_t used = static_cast((tmpStat.f_blocks - tmpStat.f_bfree) * tmpStat.f_bsize); + uint32_t free = static_cast(tmpStat.f_bfree * tmpStat.f_bsize); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "挂载点%s信息, 总:%d(byte), 用:%d(byte), 剩:%d(byte)", + MOUNT_POINT[i], total, used, free); + info.total_size += total; + info.used_size += used; + info.free_size += free; + } +} +void device_proxy::get_language_id(uint8_t &id) +{ + sys_language_id_t lang_id = {0}; + uint16_t nvsize = 0; + + errcode_t ret = uapi_nv_read(NV_ID_SYS_LANGUAGE_ID, sizeof(sys_language_id_t), &nvsize, (uint8_t *)&lang_id); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "nv get language id error, ret=%u", ret); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "language nvsize=%u id = %u", nvsize, lang_id.language_id); + + for (auto key : language_protocol) { + if (lang_id.language_id == (uint8_t)(key & language_val_mask)) { + id = (uint8_t)((key & language_key_mask) >> language_mask_bits); + return; + } + } + id = LANGUAGE_ID_ZH; +} +void device_proxy::set_language_id(uint8_t id) +{ + sys_language_id_t lang_id = {.language_id = LANGUAGE_ID_ZH}; + + for (auto key : language_protocol) { + if (id == (uint8_t)((key & language_key_mask) >> language_mask_bits)) { + lang_id.language_id = (uint8_t)(key & 0xFF); + } + } + + errcode_t ret = uapi_nv_write(NV_ID_SYS_LANGUAGE_ID, (uint8_t *)&lang_id, sizeof(sys_language_id_t)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "nv set language id error, ret=%u", ret); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "set language id = %u", lang_id.language_id); + // 发送更新消息到uiservice + SendMsgToUIService(UI_UPDATE_LANGUAGE, 0, nullptr, 0); +} +void device_proxy::get_product_info(std::string &info_string) +{ + sys_product_info_t info = {0}; + uint16_t nvsize = 0; + info_string.clear(); + + errcode_t ret = uapi_nv_read(NV_ID_SYS_PRODUCT_INFO, sizeof(sys_product_info_t), &nvsize, (uint8_t *)&info); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "nv get product info error, ret=%u", ret); + return; + } + + if (nvsize < sizeof(sys_product_info_t) || info.size == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "invalid product info size: nvsize=%u, info.size=%u", nvsize, info.size); + return; + } + + info_string.assign((const char *)info.name, info.size); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "product info: nvsize=%u, strlen=%zu, data=%.*s", nvsize, info_string.size(), + static_cast(info_string.size()), info_string.c_str()); +} +void device_proxy::get_volume_info(uint8_t vol_type, std::vector &vol_info) +{ + std::vector audio_types; + + if (vol_type == vol_type_all_idx || vol_type > vol_type_max_idx) { + for (uint8_t i = 0; i < vol_type_max_idx; i++) { + uint8_t max_perc = 0; + trans_type_to_audio_stream_type(i, audio_types); + for (auto types : audio_types) { // 每个类型也由多个音频类型组成, 取声音最大的 + int32_t vol = Audio::AudioManager::GetInstance().GetVolume(types); + int32_t max_vol = Audio::AudioManager::GetInstance().GetMaxVolume(types); + int32_t min_vol = Audio::AudioManager::GetInstance().GetMinVolume(types); + uint8_t perc = calc_vol_percentage(min_vol, max_vol, vol); + max_perc = max_perc > perc ? max_perc : perc; + } + volume_info info; + info.type = i; + info.perc = max_perc; + + vol_info.push_back(info); + } + } else { + uint8_t max_perc = 0; + trans_type_to_audio_stream_type(vol_type, audio_types); + for (auto types : audio_types) { // 每个类型也由多个音频类型组成, 取声音最大的 + int32_t vol = Audio::AudioManager::GetInstance().GetVolume(types); + int32_t max_vol = Audio::AudioManager::GetInstance().GetMaxVolume(types); + int32_t min_vol = Audio::AudioManager::GetInstance().GetMinVolume(types); + uint8_t perc = calc_vol_percentage(min_vol, max_vol, vol); + max_perc = max_perc > perc ? max_perc : perc; + } + volume_info info; + info.type = vol_type; + info.perc = max_perc; + + vol_info.push_back(info); + } +} +void device_proxy::set_volume_info(volume_info &vol_info) +{ + std::vector audio_types; + trans_type_to_audio_stream_type(vol_info.type, audio_types); + for (auto types : audio_types) { + int32_t max_vol = Audio::AudioManager::GetInstance().GetMaxVolume(types); + int32_t min_vol = Audio::AudioManager::GetInstance().GetMinVolume(types); + + int32_t vol = calc_vol_volume(min_vol, max_vol, vol_info.perc); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetVolume %08X, %d", types, vol); + Audio::AudioManager::GetInstance().SetVolume(types, vol); + } +} +OTA_ERR device_proxy::ota_init(ota_info &info) +{ + // 检查OTA的当前状态 + upg_status status = uapi_upg_get_status(); + if (status == UPG_STATUS_UPDATING) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTAInit:The update module is being upgraded."); + return OTA_ERR::OTA_ERR_STATUS_UPDATING; + } + // 清理并检查升级区空间大小 + delete_file_with_cleanup(upg_get_pkg_file_dir(), upg_get_pkg_file_path()); + uint32_t total_size = uapi_upg_get_storage_size(); + if (total_size == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTAInit:OTA check storage size error, total_size is 0"); + return OTA_ERR::OTA_ERR_INVAILD_STORAGE; + } + if (info.package_size >= total_size) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTAInit:check size error, total size:%u, need size:%u", total_size, + info.package_size); + return OTA_ERR::OTA_ERR_INSUFFICIENT_STORAGE_SPACE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OTAInit:check succ"); + return OTA_ERR::OTA_SUCC; +} +OTA_ERR device_proxy::ota_update(ota_info &info) +{ + uint32_t total_size = 0; + do { + FILE *fp = fopen(upg_get_pkg_file_path(), "rb"); + if (fp == nullptr) { + break; + } + fseek(fp, 0L, SEEK_END); + total_size = ftell(fp); + fclose(fp); + } while (false); + if (total_size == 0) { + return OTA_ERR::OTA_ERR_INVAILD_STORAGE; + } + if (total_size != info.package_size) { + return OTA_ERR::OTA_ERR_PACKAGE_SIZE_ERROR; + } + return OTA_ERR::OTA_SUCC; +} + +void device_proxy::call_ui_ota_update() +{ + // 发送升级请求到uiservice + SendMsgToUIService(UI_OTA_UPDATE, 0, nullptr, 0); +} + +int device_proxy::delete_file_with_cleanup(const char *ppath, const char *path) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "path:%s, ppath:%s", path, ppath); + // 1. 删除文件 + if (unlink(path) == -1) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "unlink failed:%d", errno); + return 1; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "unlink succ"); + // 2. 打开父目录文件描述符 + int dir_fd = open(ppath, O_RDONLY); + if (dir_fd == -1) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "open parent dir failed:%d", errno); + return 1; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "open parent dir succ"); + // 3. 同步父目录元数据到磁盘 + if (fsync(dir_fd) == -1) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "fsync dir failed:%d", errno); + close(dir_fd); + return 1; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "fsync dir succ"); + close(dir_fd); + return 0; +} + +uint8_t device_proxy::calc_vol_percentage(int32_t min, int32_t max, int32_t curr) +{ + if (min >= max) { + return 0; + } + const int32_t clamped_curr = clamp(curr, min, max); + const int64_t range = static_cast(max) - min; + + const int64_t scaled_value = (static_cast(clamped_curr - min) * percentage_scale); + return static_cast(scaled_value / range); +} +int32_t device_proxy::calc_vol_volume(int32_t min, int32_t max, uint8_t percentage) +{ + if (min >= max) { + return min; + } + uint8_t clamped_percentage = clamp(percentage, percentage_min, percentage_max); + + double range = static_cast(max - min); + double percentage_ratio = static_cast(clamped_percentage) / 100.0; + int32_t curr = static_cast(min + range * percentage_ratio); + + return static_cast(clamp(curr, min, max)); +} +void device_proxy::trans_type_to_audio_stream_type(uint8_t type, std::vector &audio_types) +{ + audio_types.clear(); + switch (type) { + case vol_type_alarm: + audio_types.push_back(AUDIO_STREAM_ALARM); // 通用报警音 + audio_types.push_back(AUDIO_STREAM_ALARM_SYSTEM); // 设备报警 + audio_types.push_back(AUDIO_STREAM_ALARM_CLOCK); // 闹钟报警 + break; + case vol_type_ring: + audio_types.push_back(AUDIO_STREAM_RING); // 来电铃声 + break; + case vol_type_call: + audio_types.push_back(AUDIO_STREAM_VOICE_CALL); // 普通语音通话 + audio_types.push_back(AUDIO_STREAM_VOICE_CALL_VOIP); // 网络语音通话(如微信通话) + audio_types.push_back(AUDIO_STREAM_VOICE_CALL_BT_SCO); // 蓝牙语音通话 + audio_types.push_back(AUDIO_STREAM_VOICE_CALL_VOLTE); // 4G VOLTE 高清语音通话 + break; + case vol_type_assistant: + audio_types.push_back(AUDIO_STREAM_VOICE_ASSISTANT); // 语音助手(如 Siri、Google Assistant) + audio_types.push_back(AUDIO_STREAM_TTS); // 语音合成(如文本转语音) + break; + case vol_type_notification: + audio_types.push_back(AUDIO_STREAM_NOTIFICATION); // 通用提示音 + audio_types.push_back(AUDIO_STREAM_NOTIFICATION_SYSTEM); // 设备提示音(如蓝牙连接/断开、低电量提示) + audio_types.push_back(AUDIO_STREAM_NOTIFICATION_PROMPT); // 运动健康提示音(如运动完成提醒) + break; + case vol_type_music: + audio_types.push_back(AUDIO_STREAM_MUSIC); // 本地音乐播放。 + audio_types.push_back(AUDIO_STREAM_A2DP_MUSIC); // 蓝牙传输的媒体音(如从手机传输到蓝牙耳机的音乐)。 + break; + case vol_type_video: + audio_types.push_back(AUDIO_STREAM_FITNESS_VIDEO); // 健身视频的指导音频。 + break; + } +} + +uint8_t battery_power::get_battery_percentage() +{ + battery_power *inst = get_instance(); + if (inst == nullptr) { + return 0; + } + uint32_t voltage = 0; + // 从adc获取电压值 + if (inst->adc_context_startup()) { + voltage = inst->calc_voltage(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "calc_voltage:%u", voltage); + } + inst->adc_context_shutdown(); + // 根据电压值计算电量百分比 + return inst->calc_percentage(voltage); +} + +battery_power *battery_power::get_instance() +{ + static battery_power *instance = nullptr; + if (instance == nullptr) { + battery_power *temp = new battery_power(); + if (!temp->adc_context_init()) { + delete temp; + return nullptr; + } + instance = temp; + } + return instance; +} + +battery_power::battery_power() +{ + // 数据由海思提供 + channel = ADC_CHANNEL_3; + analog_pin = S_AGPIO_L27; + mode = PIN_MODE_0; + samples_to_keep = def_samples_to_keep; + samples_to_discard = def_samples_to_discard; + // 由测试检测而来, 测试中得到的数据应该是0.3744V(没有标注单位,猜测得到,未必准确) + // 因为要算百分比, 换算成毫伏更容易计算 + adc_max_range_mv = def_adc_max_range_mv; + adc_min_range_mv = def_adc_min_range_mv; +} + +battery_power::~battery_power() +{ + adc_context_shutdown(); +} + +bool battery_power::adc_context_init() +{ + // 初始化pin模块 + uapi_pin_init(); + // 初始化高精度计数器 + errcode_t err = uapi_tcxo_init(); + if (err != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_tcxo_init error %u", err); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_tcxo_init succ"); + // 设置pin脚模式 + err = uapi_pin_set_mode(analog_pin, mode); + if (err != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_pin_set_mode error %u", err); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_pin_set_mode succ"); + return true; +} + +bool battery_power::adc_context_startup() +{ + errcode_t err = uapi_adc_init(ADC_CLOCK_500KHZ); // 初始化adc + if (err != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_adc_init error %u", err); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_adc_init succ"); + uapi_adc_power_en(AFE_SCAN_MODE_MAX_NUM, true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_adc_power_en true"); + err = uapi_adc_open_channel(channel); + if (err != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_adc_open_channel error %u", err); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_adc_open_channel succ"); + return true; +} +void battery_power::adc_context_shutdown() +{ + errcode_t err = uapi_adc_close_channel(channel); + if (err != ERRCODE_SUCC) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_adc_close_channel error %u", err); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_adc_close_channel succ"); + uapi_adc_power_en(AFE_SCAN_MODE_MAX_NUM, false); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_adc_power_en false"); + uapi_adc_deinit(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_adc_deinit"); +} + +uint8_t battery_power::calc_percentage(uint32_t voltage) +{ + if (voltage >= adc_max_range_mv) { + return percentage_max; + } + if (voltage <= adc_min_range_mv) { + return percentage_min; + } + + uint32_t voltage_range = adc_max_range_mv - adc_min_range_mv; + uint32_t rounding_term = voltage_range / 2; + uint32_t voltage_offset = voltage - adc_min_range_mv; + return static_cast((voltage_offset * percentage_scale + rounding_term) / voltage_range); +} + +uint32_t battery_power::calc_voltage() +{ + // 丢弃初始帧数据 + for (uint32_t i = 0; i < samples_to_discard; i++) { + uapi_adc_manual_sample(ADC_CHANNEL_NONE); + uapi_tcxo_delay_ms((uint64_t)3); // 延迟3ms + } + + uint32_t stick = 0; + uint32_t stick_count = 0; + // 采集样本数 + for (uint32_t i = 0; i < samples_to_keep; i++) { + uint32_t irq_sts = osal_irq_lock(); + uint32_t sample_result = + (uint32_t)uapi_adc_manual_sample(ADC_CHANNEL_NONE); // 每次读取CHANNEL_NONE? testsuit中是这样写的 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "sample result = %u", sample_result); + if (sample_result != 0) { + stick += sample_result; + stick_count++; + } + osal_irq_restore(irq_sts); + } + + if (stick_count == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "error, no result"); + return 0; + } + + uint32_t voltage = adc_trans_sytick_to_voltages(stick / stick_count); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "adc trans voltages:%u", voltage); + return voltage; +} + +uint32_t battery_power::adc_trans_sytick_to_voltages(uint32_t sytick) +{ + // 整数运算公式:(sytick * numerator + denominator/2) / denominator + return (sytick * adc_reference_ratio_numerator + adc_reference_ratio_denominator) / adc_reference_ratio_denominator; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/service/device_msg/device_proxy.h b/code/sdk/application/wearable/service/device_msg/device_proxy.h new file mode 100644 index 000000000..7cedf8061 --- /dev/null +++ b/code/sdk/application/wearable/service/device_msg/device_proxy.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: Breath Ease + * Author: wangle + * Create: 2025-4-23 + */ +#ifndef WATCH_SETTING_PROXY_H +#define WATCH_SETTING_PROXY_H + +#include +#include +#include "msg_center_protocol.h" +#include "cpp/audio_manager.h" +#include "adc.h" +#include "tcxo.h" +#include "pinctrl.h" +#include "hal_adc.h" + +namespace OHOS { + +typedef struct storage_info { + uint32_t total_size; // 总大小 + uint32_t used_size; // 已使用 + uint32_t free_size; // 未使用 +} storage_info_t; + +typedef struct volume_info { + uint8_t type; // 类型 + uint8_t perc; // 百分比 +} volume_info_t; + +typedef struct ota_info { + uint32_t package_size; +} ota_info_t; + +enum class OTA_ERR : uint32_t { + OTA_SUCC = 0x00000000u, //"成功" + OTA_ERR_INVALID_PARAM = 0x00000001u, //"参数错误" + OTA_ERR_INITIALIZE_ERR = 0x00000002u, //"OTA初始化错误" + OTA_ERR_STATUS_UPDATING = 0x00000003u, //"OTA正在升级中" + OTA_ERR_INVAILD_STORAGE = 0x00000004u, //"获取升级区信息错误" + OTA_ERR_INSUFFICIENT_STORAGE_SPACE = 0x00000005u, //"升级区没有足够的空间" + OTA_ERR_PACKAGE_SIZE_ERROR = 0x00000006u, //"升级包大小不匹配" +}; + +static constexpr const uint8_t vol_type_all_idx = 0; +static constexpr const uint8_t vol_type_max_idx = 7; +static constexpr const uint8_t vol_type_alarm = 1; // 报警类 +static constexpr const uint8_t vol_type_ring = 2; // 来电铃声 +static constexpr const uint8_t vol_type_call = 3; // 语音通话 +static constexpr const uint8_t vol_type_assistant = 4; // 语音助手 +static constexpr const uint8_t vol_type_notification = 5; // 通用提示音 +static constexpr const uint8_t vol_type_music = 6; // 音乐 +static constexpr const uint8_t vol_type_video = 7; // 视频 + + +class device_proxy { +public: + static void get_storage_info(storage_info &info); + static void get_language_id(uint8_t &lang_id); + static void set_language_id(uint8_t lang_id); + static void get_product_info(std::string &info_string); + static void get_volume_info(uint8_t vol_type, std::vector &vol_info); + static void set_volume_info(volume_info &vol_info); + static OTA_ERR ota_init(ota_info &info); + static OTA_ERR ota_update(ota_info &info); + static void call_ui_ota_update(); +public: + static uint32_t calc_stat_size(uint64_t size); + static uint8_t calc_vol_percentage(int32_t min, int32_t max, int32_t curr); + static int32_t calc_vol_volume(int32_t min, int32_t max, uint8_t percentage); + static void trans_type_to_audio_stream_type(uint8_t type, std::vector &audio_types); + static int delete_file_with_cleanup(const char *ppath, const char *path); +}; + +class battery_power { +public: + static uint8_t get_battery_percentage(); + +protected: + static battery_power *get_instance(); + +private: + battery_power(); + ~battery_power(); + bool adc_context_init(); + bool adc_context_startup(); + void adc_context_shutdown(); + uint8_t calc_percentage(uint32_t voltage); + uint32_t calc_voltage(); + uint32_t adc_trans_sytick_to_voltages(uint32_t sytick); + +private: + adc_channel_t channel; // ADC信道 + pin_t analog_pin; // ADC输入引脚 + pin_mode_t mode; // ADC管脚工作模式 + uint32_t samples_to_keep; // 总采样次数 + uint32_t samples_to_discard; // 丢弃的初始样本数 + uint32_t adc_max_range_mv; // ADC原始值上限(单位:毫伏) + uint32_t adc_min_range_mv; // ADC原始值下限(单位:毫伏) +}; + +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/device_msg/msg_center_device.cpp b/code/sdk/application/wearable/service/device_msg/msg_center_device.cpp new file mode 100644 index 000000000..56f89c1a8 --- /dev/null +++ b/code/sdk/application/wearable/service/device_msg/msg_center_device.cpp @@ -0,0 +1,520 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: Breath Ease + * Author: wangle + * Create: 2025-4-23 + */ +#include "msg_center_protocol.h" +#include "msg_center_device.h" +#include "device_proxy.h" +#include "wearable_log.h" +#include "device_location.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "sports/SportsModel.h" +#include "findphone/FindPhoneMainPage.h" +#include "camera/CameraMainPage.h" + +#ifdef __cplusplus +extern "C" { +#endif +#include "diag_msg.h" +#include "diag_ind_src.h" + +uint8_t g_bloodoxygen = 0; +uint16_t g_heartrate = 0; +uint32_t g_stepdata = 0; +uint32_t g_distance = 0; +extern LocationInfo_t g_locationInfo; +// 获取电量 +errcode_t msg_center_get_battery_level(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get_battery_level"); + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + void *v_data = msg_center_get_tlv_payload(usr_data); + uint8_t v_len = usr_len - tl_len; + + uint8_t battery_level = OHOS::battery_power::get_battery_percentage(); + + errcode_t ret = msg_center_send_data(cmd_id, type, &battery_level, sizeof(battery_level)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send get_battery_level_ack fail, ret = %d", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +// 获取存储空间 +errcode_t msg_center_get_storage_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get_storage_info"); + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + void *v_data = msg_center_get_tlv_payload(usr_data); + uint8_t v_len = usr_len - tl_len; + uint8_t battery_level = 0; + + OHOS::storage_info info; + OHOS::device_proxy::get_storage_info(info); + + errcode_t ret = msg_center_send_data(cmd_id, type, &info, sizeof(OHOS::storage_info)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send get_storage_info_ack fail, ret = %d", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +// 获取手表类型 +errcode_t msg_center_get_product_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get_product_info"); + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + void *v_data = msg_center_get_tlv_payload(usr_data); + uint8_t v_len = usr_len - tl_len; + uint8_t battery_level = 0; + + std::string product_info; + OHOS::device_proxy::get_product_info(product_info); + + errcode_t ret = msg_center_send_data(cmd_id, type, (void *)product_info.c_str(), product_info.length()); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send get_product_info_ack fail, ret = %d", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +// 获取语言 +errcode_t msg_center_get_language_id(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get_language_id"); + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + void *v_data = msg_center_get_tlv_payload(usr_data); + uint8_t v_len = usr_len - tl_len; + uint8_t battery_level = 0; + + uint8_t language_id = 0; + OHOS::device_proxy::get_language_id(language_id); + + errcode_t ret = msg_center_send_data(cmd_id, type, &language_id, sizeof(uint8_t)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send get_language_id_ack fail, ret = %d", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +// 获取音量 +errcode_t msg_center_get_volume_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get_volume_info"); + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + void *v_data = msg_center_get_tlv_payload(usr_data); + uint8_t v_len = usr_len - tl_len; + + uint8_t vol_type = 0; + if (v_len == sizeof(uint8_t)) { + vol_type = *(uint8_t *)v_data; + } + + std::vector vol_info; + OHOS::device_proxy::get_volume_info(vol_type, vol_info); + + errcode_t ret = msg_center_send_data(cmd_id, type, &vol_info[0], vol_info.size() * sizeof(OHOS::volume_info)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send get_volume_info_ack fail, ret = %d", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +// 设置语言 +errcode_t msg_center_set_language_id(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "set_language_id"); + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + void *v_data = msg_center_get_tlv_payload(usr_data); + uint8_t v_len = usr_len - tl_len; + + uint8_t language_id = 0; + if (v_len != sizeof(uint8_t)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "v_len check error, v_len=%u, need=%u", v_len, sizeof(uint8_t)); + return ERRCODE_FAIL; + } + + language_id = *(uint8_t *)v_data; + OHOS::device_proxy::set_language_id(language_id); + + errcode_t ret = msg_center_send_data(cmd_id, type, &language_id, sizeof(uint8_t)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send set_language_id_ack fail, ret = %d", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +// 设置音量 +errcode_t msg_center_set_volume_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "set_volume_info"); + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + void *v_data = msg_center_get_tlv_payload(usr_data); + uint8_t v_len = usr_len - tl_len; + + OHOS::volume_info info; + if (v_len != sizeof(OHOS::volume_info)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "v_len check error, v_len=%u, need=%u", v_len, sizeof(uint8_t)); + return ERRCODE_FAIL; + } + + memcpy_s(&info, sizeof(OHOS::volume_info), v_data, v_len); + OHOS::device_proxy::set_volume_info(info); + + errcode_t ret = msg_center_send_data(cmd_id, type, &info, sizeof(OHOS::volume_info)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send set_volume_info_ack fail, ret = %d", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +// ota初始化 +errcode_t msg_center_ota_init(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ota_init"); + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + void *v_data = msg_center_get_tlv_payload(usr_data); + uint8_t v_len = usr_len - tl_len; + + OHOS::ota_info info; + if (v_len != sizeof(OHOS::ota_info)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "v_len check error, v_len=%u, need=%u", v_len, sizeof(uint8_t)); + return ERRCODE_FAIL; + } + + memcpy_s(&info, sizeof(OHOS::ota_info), v_data, v_len); + OHOS::OTA_ERR err = OHOS::device_proxy::ota_init(info); + + errcode_t ret = msg_center_send_data(cmd_id, type, &err, sizeof(OHOS::OTA_ERR)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send set_volume_info_ack fail, ret = %d", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +// ota检测和本地升级 +errcode_t msg_center_ota_update(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ota_update"); + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + void *v_data = msg_center_get_tlv_payload(usr_data); + uint8_t v_len = usr_len - tl_len; + + OHOS::ota_info info; + if (v_len != sizeof(OHOS::ota_info)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "v_len check error, v_len=%u, need=%u", v_len, sizeof(uint8_t)); + return ERRCODE_FAIL; + } + + memcpy_s(&info, sizeof(OHOS::ota_info), v_data, v_len); + OHOS::OTA_ERR err = OHOS::device_proxy::ota_update(info); + + errcode_t ret = msg_center_send_data(cmd_id, type, &err, sizeof(OHOS::OTA_ERR)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send set_volume_info_ack fail, ret = %d", ret); + return ERRCODE_FAIL; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send ret = %d", ret); + OHOS::device_proxy::call_ui_ota_update(); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "send ui over"); + return ERRCODE_SUCC; +} + +errcode_t msg_center_device_heartrate(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + + ret = msg_center_send_data(cmd_id, type, &g_heartrate, sizeof(g_heartrate)); + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_device_heartrate:%d\r\n", g_heartrate); + /* notify UI or call UI load */ + + return ERRCODE_SUCC; +} + +errcode_t msg_center_device_stepdata(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + + ret = msg_center_send_data(cmd_id, type, &g_stepdata, sizeof(g_stepdata)); + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_device_stepdata:%d\r\n", g_stepdata); + /* notify UI or call UI load */ + + return ERRCODE_SUCC; +} + +errcode_t msg_center_device_bloodoxygen(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + + ret = msg_center_send_data(cmd_id, type, &g_bloodoxygen, sizeof(g_bloodoxygen)); + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_device_bloodoxygen:%d\r\n", g_bloodoxygen); + /* notify UI or call UI load */ + + return ERRCODE_SUCC; +} + +/* LOCATION */ +errcode_t msg_center_location_get_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + + ret = msg_center_send_data(cmd_id, type, &g_locationInfo, sizeof(g_locationInfo)); + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_get_info latitude_:%d,longitude_:%d\n", + g_locationInfo.latitude_, g_locationInfo.longitude_); + /* notify UI or call UI load */ + + return ERRCODE_SUCC; +} + +errcode_t msg_center_location_start(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + uint8_t ack = 1; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start finish\r\n"); + ret = deviceLocationStartLocating(); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start fail\r\n"); + ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start send msg fail\r\n"); + return ERRCODE_FAIL; + } + } else { + ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start send msg fail\r\n"); + return ERRCODE_FAIL; + } + } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_start finish\r\n"); + /* notify UI or call UI load */ + + return ERRCODE_SUCC; +} + +errcode_t msg_center_location_stop(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + uint8_t ack = 1; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop\r\n"); + ret = deviceLocationStopLocating(); + ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop fail\r\n"); + ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop send msg fail\r\n"); + return ERRCODE_FAIL; + } + } else { + ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop send msg fail\r\n"); + return ERRCODE_FAIL; + } + } + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_location_stop\r\n"); + /* notify UI or call UI load */ + + return ERRCODE_SUCC; +} + +/* SPORT */ +errcode_t msg_center_sport_action(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + uint8_t ack = 1; + sport_action_t action = (sport_action_t)*tlv_payload; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_action : %d\r\n", action); + + switch (action) { + case SPORT_ACTION_START: + OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_SPORTS); + OHOS::SportsModel::GetInstance()->ResetSportsData(); + if (!OHOS::SportsModel::GetInstance()->StartSportsTimer()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_start StartSportsTimer failed\r\n"); + ret = ERRCODE_FAIL; + } + break; + case SPORT_ACTION_PAUSE: + OHOS::SportsModel::GetInstance()->StopSportsTimer(false); + break; + case SPORT_ACTION_RESUME: + if (!OHOS::SportsModel::GetInstance()->StartSportsTimer()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_resume StartSportsTimer failed\r\n"); + ret = ERRCODE_FAIL; + } + break; + case SPORT_ACTION_STOP: + OHOS::SportsModel::GetInstance()->StopSportsTimer(false); + OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + break; + default: + ret = ERRCODE_FAIL; + break; + } + + ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_resume send data failed\r\n"); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +errcode_t msg_center_sport_get_data(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_get_data\r\n"); + OHOS::sport_data_t *sportData = OHOS::SportsModel::GetInstance()->GetSportsData(); + ret = msg_center_send_data(cmd_id, type, sportData, sizeof(OHOS::sport_data_t)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_sport_get_data end data failed\r\n"); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +errcode_t msg_center_sport_report_data(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + return ERRCODE_SUCC; +} + +errcode_t msg_center_camera_exit(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "recv exit camera from phone"); + OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + return ERRCODE_SUCC; +} + +errcode_t msg_center_camera_online(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "recv connect success from phone"); + if (OHOS::CameraMainPage::GetInstance() != nullptr) { + OHOS::CameraMainPage::GetInstance()->Refresh_page(); + return ERRCODE_SUCC; + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "CameraMainPage not exist\r\n"); + return ERRCODE_FAIL; + } +} + +errcode_t msg_center_offline_log_switch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + uint8_t data = *tlv_payload; + errcode_t ret = ERRCODE_SUCC; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_offline_log_switch, data = %d\r\n", data); + if (data) { + uapi_zdiag_set_offline_log_enable(true); /*open offline log*/ + } else { + uapi_zdiag_set_offline_log_enable(false); /*close offline log*/ + } + ret = msg_center_send_data(cmd_id, type, &data, sizeof(data)); + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +#if (CONFIG_ONLINE_LOG == 1) +errcode_t msg_center_set_online_log_channel(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + uint8_t data = *tlv_payload; + errcode_t ret = ERRCODE_SUCC; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_set_online_log_channel, data = %d\r\n", data); + change_log_diag_channel(data); + ret = msg_center_send_data(cmd_id, type, &data, sizeof(data)); + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +errcode_t msg_center_set_online_log_level(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + uint8_t data = *tlv_payload; + errcode_t ret = ERRCODE_SUCC; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_set_online_log_level, data = %d\r\n", data); + set_online_log_level(data); + ret = msg_center_send_data(cmd_id, type, &data, sizeof(data)); + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +#endif + +errcode_t msg_center_device_findphone(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + bool ret = true; + if ( OHOS::FindPhoneMainPage::GetInstance() != nullptr) { + ret = OHOS::FindPhoneMainPage::GetInstance()->StopFindPhone(); + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_MSG_CENTER, "FindphonePage not exist\r\n"); + } + if (!ret) { + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/device_msg/msg_center_device.h b/code/sdk/application/wearable/service/device_msg/msg_center_device.h new file mode 100644 index 000000000..02f3c2583 --- /dev/null +++ b/code/sdk/application/wearable/service/device_msg/msg_center_device.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. + * Description: Breath Ease + * Author: wangle + * Create: 2025-4-23 + */ +#ifndef MSG_CENTER_DEVICE_H +#define MSG_CENTER_DEVICE_H + +#include "msg_center_protocol.h" +#include "wearable_log.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum sport_action { + SPORT_ACTION_START = 1, + SPORT_ACTION_PAUSE = 2, + SPORT_ACTION_RESUME = 3, + SPORT_ACTION_STOP = 4, +} sport_action_t; + +typedef enum msg_center_device_type_id { + MSGCENTER_TYPE_ID_GET_BATTERY_LEVEL = 0x1, + MSGCENTER_TYPE_ID_GET_STORAGE_INFO = 0x2, + MSGCENTER_TYPE_ID_GET_PRODUCT_INFO = 0x3, + MSGCENTER_TYPE_ID_GET_LANGUAGE_ID = 0x4, + MSGCENTER_TYPE_ID_GET_VOLUME_INFO = 0x5, + MSGCENTER_TYPE_ID_SET_LANGUAGE_ID = 0x6, + MSGCENTER_TYPE_ID_SET_VOLUME_INFO = 0x7, + MSGCENTER_TYPE_ID_DEVICE_HEARTRATE = 0x8, + MSGCENTER_TYPE_ID_DEVICE_STEPDATA = 0x9, + MSGCENTER_TYPE_ID_DEVICE_BLOODOXYGEN = 0xa, + MSGCENTER_TYPE_ID_OFFLINE_LOG_SWITCH = 0xb, + MSGCENTER_TYPE_ID_LOCATION_GET_INFO = 0x20, + MSGCENTER_TYPE_ID_LOCATION_START = 0x21, + MSGCENTER_TYPE_ID_LOCATION_STOP = 0x22, + MSGCENTER_TYPE_ID_LOCATION_REPORT = 0x23, + MSGCENTER_TYPE_ID_SPORT_ACTION = 0x27, + MSGCENTER_TYPE_ID_SPORT_GET_DATA = 0x28, + MSGCENTER_TYPE_ID_SPORT_REPORT_DATA = 0x29, + MSGCENTER_TYPE_ID_SET_ONLINELOG_CHANNEL = 0x30, + MSGCENTER_TYPE_ID_SET_ONLINELOG_LEVEL = 0x31, + MSGCENTER_TYPE_ID_ONLINELOG_REPORT = 0x33, + MSGCENTER_TYPE_ID_OTA_INIT = 0x34, + MSGCENTER_TYPE_ID_OTA_UPDATE = 0x35, + MSGCENTER_TYPE_ID_ON_FIND_PHONE = 0x36, + MSGCENTER_TYPE_ID_OFF_FIND_PHONE = 0x37, + MSGCENTER_TYPE_ID_SLEEP_DATA = 0x38, + MSGCENTER_TYPE_ID_ON_CAMERA = 0x39, + MSGCENTER_TYPE_ID_CAMERA_WATCH_EXIT = 0x40, + MSGCENTER_TYPE_ID_CAMERA_PHONE_EXIT = 0x41, + MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE = 0x42, + MSGCENTER_TYPE_ID_CAMERA_CONNECT_PHONE_SUCCESS = 0x43, +} msg_center_device_type_id_t; + +// 获取电量 +errcode_t msg_center_get_battery_level(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +// 获取存储空间 +errcode_t msg_center_get_storage_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +// 获取手表类型 +errcode_t msg_center_get_product_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +// 获取语言 +errcode_t msg_center_get_language_id(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +// 获取音量 +errcode_t msg_center_get_volume_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +// 设置语言 +errcode_t msg_center_set_language_id(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +// 设置音量 +errcode_t msg_center_set_volume_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +// ota初始化 +errcode_t msg_center_ota_init(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +// ota检测和本地升级 +errcode_t msg_center_ota_update(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +errcode_t msg_center_device_heartrate(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_device_stepdata(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_device_bloodoxygen(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +/* LOCATION */ +errcode_t msg_center_location_get_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_location_start(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_location_stop(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +/* SPORT */ +errcode_t msg_center_sport_action(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_sport_get_data(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_sport_report_data(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +/* 离线日志开关 */ +errcode_t msg_center_offline_log_switch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +/* 查找手机 */ +errcode_t msg_center_device_findphone(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +/* CAMERA */ +errcode_t msg_center_camera_exit(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_camera_online(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +#if (CONFIG_ONLINE_LOG == 1) +/* 在线日志通道 */ +errcode_t msg_center_set_online_log_channel(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +/* 在线日志级数 */ +errcode_t msg_center_set_online_log_level(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +#endif + +#ifdef PUBLISH_TEST_DATA +void PublishTestData(); +#endif +#ifdef __cplusplus +} +#endif +#endif /* MSG_CENTER_DEVICE_H */ diff --git a/code/sdk/application/wearable/service/dial_market/CMakeLists.txt b/code/sdk/application/wearable/service/dial_market/CMakeLists.txt index 058f8dc76..8c61862ab 100644 --- a/code/sdk/application/wearable/service/dial_market/CMakeLists.txt +++ b/code/sdk/application/wearable/service/dial_market/CMakeLists.txt @@ -11,7 +11,6 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils ${ROOT_DIR}/open_source/openharmony/base/startup/syspara_lite/include ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/format/interfaces/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/main/include/dial ) set(SOURCES diff --git a/code/sdk/application/wearable/service/dial_market/dial_market.cpp b/code/sdk/application/wearable/service/dial_market/dial_market.cpp new file mode 100644 index 000000000..5d6de8491 --- /dev/null +++ b/code/sdk/application/wearable/service/dial_market/dial_market.cpp @@ -0,0 +1,244 @@ +/* + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: ota upgrade handle. + * This file should be changed only infrequently and with great care. + */ +#include +#include "securec.h" +#include "msg_center.h" +#include "msg_center_protocol.h" +#include "msg_center_cmd.h" +#include "wearable_log.h" +#include "common_def.h" +#include "dial_market.h" +#include "parameter.h" +#include "main/dial/WatchInterface.h" + +#ifdef __cplusplus +extern "C" { +#endif + +errcode_t msg_center_dial_market_get_sys_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + errcode_t ret = ERRCODE_SUCC; + watch_sys_info sys; + bool op_ret = false; + + /* 组装信息 */ + strcpy_s(sys.chip_platform, MAX_CHIP_PLAT_LEN, "hisi"); + strcpy_s(sys.chip_model, MAX_CHIP_MODEL_LEN, "3321"); + char *os_version = GetOsName(); + if (os_version == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "os_version is NULL\r\n"); + return ERRCODE_FAIL; + } + strcpy_s(sys.os_version, MAX_OS_LEN, os_version); // "OpenHarmony-5.0.1.115" + + char *api_level = GetSdkApiLevel(); + if (api_level == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "api_level is NULL\r\n"); + free(os_version); + return ERRCODE_FAIL; + } + strcpy_s(sys.api_level, MAX_API_LEVEL_LEN, api_level); // "13" + + op_ret = GetWatchSystemInfo(&sys); + if (op_ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "GetWatchSystemInfo fail\r\n"); + free(os_version); + free(api_level); + return ERRCODE_FAIL; + } + + ret = msg_center_send_data(cmd_id, type, &sys, sizeof(watch_sys_info)); + if (ret != ERRCODE_SUCC) { + free(os_version); + free(api_level); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send data fail, ret = %d\r\n", ret); + return ERRCODE_FAIL; + } + + free(os_version); + free(api_level); + return ERRCODE_SUCC; +} + +errcode_t msg_center_dial_market_get_dev_cap(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + errcode_t ret = ERRCODE_SUCC; + watch_dev_cap_info cap; + bool op_ret = false; + + op_ret = GetWatchCapability(&cap); + if (op_ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "GetWatchCapability fail\r\n"); + return ERRCODE_FAIL; + } + + ret = msg_center_send_data(cmd_id, type, &cap, sizeof(watch_dev_cap_info)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send data fail, ret = %d\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +errcode_t msg_center_dial_market_get_one_watch_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + errcode_t ret = ERRCODE_SUCC; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + uint32_t uuid = *(uint32_t *)tlv_payload; + bool op_ret = false; + watch_dial_info info; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "uuid = %d\r\n", uuid); + op_ret = GetWatchFaceInfo(uuid, &info); + if (op_ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "GetWatchFaceInfo fail\r\n"); + (void)memset_s(&info, sizeof(watch_dial_info), 0, sizeof(watch_dial_info)); + info.uuid = uuid; + (void)msg_center_send_data(cmd_id, type, &info, sizeof(watch_dial_info)); + return ERRCODE_FAIL; + } + + ret = msg_center_send_data(cmd_id, type, &info, sizeof(watch_dial_info)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send data fail, ret = %d\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +errcode_t msg_center_dial_market_install_watch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + errcode_t ret = ERRCODE_SUCC; + uint32_t uuid = 0; + bool op_ret = false; + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + + char *path = (char *)malloc(payload_len + 1); + if (path == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "malloc failed.\r\n"); + return ERRCODE_FAIL; + } + + (void)memcpy_s(path, payload_len, tlv_payload, payload_len); + path[payload_len] = '\0'; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "path = %s\r\n", path); + + op_ret = GetUuidByPath(path, &uuid); + if (op_ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "install fail.\r\n"); + free(path); + return ERRCODE_FAIL; + } + + ret = msg_center_send_data(cmd_id, type, &uuid, sizeof(uint32_t)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send data fail, ret = %d\r\n", ret); + free(path); + return ERRCODE_FAIL; + } + + free(path); + return ERRCODE_SUCC; +} + +errcode_t msg_center_dial_market_uninstall_watch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + errcode_t ret = ERRCODE_SUCC; + bool op_ret = false; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + uint32_t uuid = *(uint32_t *)tlv_payload; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "uuid = %d\r\n", uuid); + op_ret = UninstallWatch(uuid); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "uninstall ret : %d\r\n", op_ret); + + ret = msg_center_send_data(cmd_id, type, &op_ret, sizeof(uint8_t)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send data fail, ret = %d\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +errcode_t msg_center_dial_market_set_watch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + errcode_t ret = ERRCODE_SUCC; + bool op_ret = false; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + uint32_t uuid = *(uint32_t *)tlv_payload; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "uuid = %d\r\n", uuid); + op_ret = SetCurrentWatchFace(uuid); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "set_current_watch_face ret : %d\r\n", op_ret); + + ret = msg_center_send_data(cmd_id, type, &op_ret, sizeof(uint8_t)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send data fail, ret = %d\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +errcode_t msg_center_dial_market_get_all_watch_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + errcode_t ret = ERRCODE_SUCC; + watch_dial_info *info = nullptr; + uint8_t watch_num = 0; + bool op_ret = false; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "get_all_watch_info\r\n"); + op_ret = GetAllWatchFaceInfo(&info, &watch_num); + if (op_ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "GetAllWatchFaceInfo fail\r\n"); + watch_num = 0; + (void)msg_center_send_data(cmd_id, type, info, sizeof(watch_dial_info) * watch_num); + return ERRCODE_FAIL; + } + + ret = msg_center_send_data(cmd_id, type, info, sizeof(watch_dial_info) * watch_num); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send data fail, ret = %d\r\n", ret); + free(info); + return ERRCODE_FAIL; + } + + free(info); + return ERRCODE_SUCC; +} + +errcode_t msg_center_dial_market_get_cur_watch_info(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + errcode_t ret = ERRCODE_SUCC; + bool op_ret = false; + watch_dial_info info; + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "get_cur_watch_info\r\n"); + op_ret = GetCurrentWatchFaceInfo(&info); + if (op_ret == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "GetCurrentWatchFaceInfo fail\r\n"); + (void)memset_s(&info, sizeof(watch_dial_info), 0, sizeof(watch_dial_info)); + info.uuid = 0xFFFFFFFF; // 异常时用全F的uuid表示 + (void)msg_center_send_data(cmd_id, type, &info, sizeof(watch_dial_info)); + return ERRCODE_FAIL; + } + + ret = msg_center_send_data(cmd_id, type, &info, sizeof(watch_dial_info)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send data fail, ret = %d\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/dial_market/dial_market_msg.cpp b/code/sdk/application/wearable/service/dial_market/dial_market_msg.cpp new file mode 100644 index 000000000..b30812e0b --- /dev/null +++ b/code/sdk/application/wearable/service/dial_market/dial_market_msg.cpp @@ -0,0 +1,47 @@ + +#include "msg_center_protocol.h" +#include "msg_center_cmd.h" +#include "ohos_init.h" +#include "dial_market.h" + +namespace OHOS { + +#ifdef __cplusplus +extern "C" { +#endif + +static const msg_center_cmd_map_t g_msg_center_dial_market_tbl[] = { + { MSGCENTER_CMD_DIAL_MARKET, MSGCENTER_TYPE_ID_DM_GET_SYS_INFO, msg_center_dial_market_get_sys_info}, + { MSGCENTER_CMD_DIAL_MARKET, MSGCENTER_TYPE_ID_DM_GET_DEV_CAP, msg_center_dial_market_get_dev_cap}, + { MSGCENTER_CMD_DIAL_MARKET, MSGCENTER_TYPE_ID_DM_GET_ONE_WATCH_INFO, msg_center_dial_market_get_one_watch_info}, + { MSGCENTER_CMD_DIAL_MARKET, MSGCENTER_TYPE_ID_DM_INSTALL_WATCH, msg_center_dial_market_install_watch}, + { MSGCENTER_CMD_DIAL_MARKET, MSGCENTER_TYPE_ID_DM_UNINSTALL_WATCH, msg_center_dial_market_uninstall_watch}, + { MSGCENTER_CMD_DIAL_MARKET, MSGCENTER_TYPE_ID_DM_SET_WATCH, msg_center_dial_market_set_watch}, + { MSGCENTER_CMD_DIAL_MARKET, MSGCENTER_TYPE_ID_DM_GET_ALL_WATCH_INFO, msg_center_dial_market_get_all_watch_info}, + { MSGCENTER_CMD_DIAL_MARKET, MSGCENTER_TYPE_ID_DM_GET_CUR_WATCH_INFO, msg_center_dial_market_get_cur_watch_info}, +}; + +errcode_t msg_center_dial_market_dispatch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tbl_size = sizeof(g_msg_center_dial_market_tbl) / sizeof(g_msg_center_dial_market_tbl[0]); + uint8_t i; + for (i = 0; i < tbl_size; i++) { + msg_center_cmd_map_t *item = (msg_center_cmd_map_t *)&g_msg_center_dial_market_tbl[i]; + if ((item->type == type) && (item->handler != NULL)) { + item->handler(cmd_id, type, usr_data, usr_len); + return ERRCODE_SUCC; + } + } + return ERRCODE_NOT_SUPPORT; +} + +void dial_market_init(void) +{ + msg_center_register_cmd(MSGCENTER_CMD_DIAL_MARKET, msg_center_dial_market_dispatch); +} + +APP_FEATURE_INIT_PRI(dial_market_init, LAYER_INIT_LEVEL_4); +#ifdef __cplusplus +} +#endif +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt index a1ac91cb3..a26eab496 100644 --- a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt @@ -18,9 +18,13 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ${ROOT_DIR}/application/wearable/service/xiaodu_voice + ${ROOT_DIR}/application/wearable/service/watch_setting_msg/include ${ROOT_DIR}/application/wearable/service/xiaodu_navi_vector ${ROOT_DIR}/application/wearable/service/xiaodu_navi_vector/libs ${ROOT_DIR}/application/wearable/service/msg_center/src/notify/ketinput/include + ${ROOT_DIR}/application/wearable/nativeapp/nativelauncher/include + ${ROOT_DIR}/application/wearable/nativeabilityfwk/include + ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/player/interfaces/kits ) set(SOURCES @@ -88,15 +92,6 @@ set(PUBLIC_HEADER ) set(PRIVATE_HEADER - ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/alarmclockmanage/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/alarmclocktimerconfig/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/alarm/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/callerlog/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/phoneservice/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/main/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/player/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/bluetooth/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/key/include ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativelauncher/include ${CMAKE_CURRENT_SOURCE_DIR}/../../ohos_deps ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include @@ -120,20 +115,13 @@ set(PRIVATE_HEADER ${ROOT_DIR}/include/middleware/services/bts/common ${ROOT_DIR}/application/auto_ota ${ROOT_DIR}/application/wearable/service/xiaodu_navi_vector + ${ROOT_DIR}/open_source/openharmony/third_party/cJSON + ${ROOT_DIR}/application/wearable/service/device_msg ${ROOT_DIR}/application/wearable/service/msg_center/src/notify/ketinput/include ${ROOT_DIR}/application/wearable/nativeapp/nativelauncher/include ${ROOT_DIR}/application/wearable/nativeabilityfwk/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/alarm/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/key/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/alarmclockmanage/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/alarmclocktimerconfig/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/main/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/callerlog/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/phoneservice/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/makephone/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/player/include - ${ROOT_DIR}/application/wearable/nativeapp/nativeui/applist/include ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/player/interfaces/kits + ) if("JS_ENABLE" IN_LIST DEFINES) @@ -144,18 +132,18 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/makephone_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/common/msg_center_common.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/common/msg_center_utils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/common/msg_center_self_cmd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/ketinput/src/NotifyOnKeyListener.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/pairing_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/phone_msg_notification.cpp ) else() set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/msg_center_customer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/msg_center_cmd.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/msg_center_self_cmd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/alarm_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/makephone_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/ketinput/src/NotifyOnKeyListener.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/pairing_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/phone_msg_notification.cpp ) endif() diff --git a/code/sdk/application/wearable/service/msg_center/brandy-auto-ota-cli/libmsg_center.a b/code/sdk/application/wearable/service/msg_center/brandy-auto-ota-cli/libmsg_center.a index 6a29e7c98..c6b588af4 100644 Binary files a/code/sdk/application/wearable/service/msg_center/brandy-auto-ota-cli/libmsg_center.a and b/code/sdk/application/wearable/service/msg_center/brandy-auto-ota-cli/libmsg_center.a differ diff --git a/code/sdk/application/wearable/service/msg_center/brandy-auto-ota-ser/libmsg_center.a b/code/sdk/application/wearable/service/msg_center/brandy-auto-ota-ser/libmsg_center.a index 1a1666e42..19e2cb51d 100644 Binary files a/code/sdk/application/wearable/service/msg_center/brandy-auto-ota-ser/libmsg_center.a and b/code/sdk/application/wearable/service/msg_center/brandy-auto-ota-ser/libmsg_center.a differ diff --git a/code/sdk/application/wearable/service/msg_center/brandy-native-js/libmsg_center.a b/code/sdk/application/wearable/service/msg_center/brandy-native-js/libmsg_center.a index c3aaaca96..b1e105a9c 100644 Binary files a/code/sdk/application/wearable/service/msg_center/brandy-native-js/libmsg_center.a and b/code/sdk/application/wearable/service/msg_center/brandy-native-js/libmsg_center.a differ diff --git a/code/sdk/application/wearable/service/msg_center/brandy-xts/libmsg_center.a b/code/sdk/application/wearable/service/msg_center/brandy-xts/libmsg_center.a index 426bb7c43..7f842a9c9 100644 Binary files a/code/sdk/application/wearable/service/msg_center/brandy-xts/libmsg_center.a and b/code/sdk/application/wearable/service/msg_center/brandy-xts/libmsg_center.a differ diff --git a/code/sdk/application/wearable/service/msg_center/include/msg_center_protocol.h b/code/sdk/application/wearable/service/msg_center/include/msg_center_protocol.h index 02cf29c8f..ed6ece04c 100644 --- a/code/sdk/application/wearable/service/msg_center/include/msg_center_protocol.h +++ b/code/sdk/application/wearable/service/msg_center/include/msg_center_protocol.h @@ -62,6 +62,8 @@ typedef enum msg_center_cmd_id { MSGCENTER_CMD_WATCH_CONNECT = 0x8, MSGCENTER_CMD_APP_STORE = 0x9, MSGCENTER_CMD_DIAL_MARKET = 0xa, + MSGCENTER_CMD_PHONE_MSG = 0xb, // 增加消息通知; + MSGCENTER_CMD_DEVICE = 0xc, MSGCENTER_CMD_MAX } msg_center_cmd_id_t; diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/notification_manager.h b/code/sdk/application/wearable/service/msg_center/include/notify/notification_manager.h index 532f1c11d..345828de1 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/notification_manager.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/notification_manager.h @@ -24,6 +24,7 @@ #include "components/ui_view_group.h" #include "alarm_notification.h" #include "makephone_notification.h" +#include "phone_msg_notification.h" constexpr uint16_t HALF_SCREEN = 2; constexpr int16_t NOTIFY_PRIORITY_DEFAULT = 4; diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/phone_msg_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/phone_msg_notification.h new file mode 100644 index 000000000..735c01edf --- /dev/null +++ b/code/sdk/application/wearable/service/msg_center/include/notify/phone_msg_notification.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: phone message notification + * Author: + * Create: 2025-04-25 + */ + +#ifndef PHONE_MSG_NOTIFICATION_H +#define PHONE_MSG_NOTIFICATION_H + +#include "components/ui_view_group.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_button_ext.h" +#include "graphic_timer.h" +#include + +struct PhoneMsg { + std::string appName; + std::string msgTitle; + std::string msgContent; +}; + +namespace OHOS { +class PhoneMsgView { +public: + static UIViewGroup *CreatePhoneMsgView(); + static void FreePhoneMsgView(void); + static void UpDatePhoneMsg(std::string appName, std::string titile, std::string content); + static void StartPhoneMsgTimer(int32_t interval); + static void DisablePhoneMsgTimer(); + static const uint32_t notifyTime = 5000; + +private: + static UIViewGroup *phoneMsgView_; + static UILabel *appNameLabel_; + static UILabel *titleLabel_; + static UILabel *contentLabel_; + static GraphicTimer *phoneMsgNotifyStop_; + static PhoneMsg phoneMsg_; + static UILabelButtonExt *cancelButton_; +}; + +class PhoneMsgViewEventListener : public OHOS::UIView::OnClickListener, + public OHOS::UIView::OnLongPressListener, + public OHOS::UIView::OnTouchListener, + public OHOS::UIView::OnDragListener { +public: + PhoneMsgViewEventListener(); + virtual ~PhoneMsgViewEventListener(); + static PhoneMsgViewEventListener *GetInstance(void); + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(OHOS::UIView& view, const OHOS::DragEvent& event) override; + bool OnClick(OHOS::UIView& view, const OHOS::ClickEvent& event) override; + bool OnPress(OHOS::UIView& view, const OHOS::PressEvent& event) override + { + return true; + } + bool OnLongPress(OHOS::UIView& view, const OHOS::LongPressEvent& event) override + { + return true; + } + bool OnRelease(OHOS::UIView& view, const OHOS::ReleaseEvent& event) override + { + return true; + } + + bool OnDragStart(OHOS::UIView& view, const OHOS::DragEvent& event) override + { + return true; + } +}; +}; // namespace OHOS + +#endif /* PHONE_MSG_NOTIFICATION_H */ diff --git a/code/sdk/application/wearable/service/msg_center/src/common/msg_center_self_cmd.cpp b/code/sdk/application/wearable/service/msg_center/src/common/msg_center_self_cmd.cpp new file mode 100644 index 000000000..ee822bec1 --- /dev/null +++ b/code/sdk/application/wearable/service/msg_center/src/common/msg_center_self_cmd.cpp @@ -0,0 +1,43 @@ +#include "msg_center_protocol.h" +#include "msg_center_cmd.h" +#include "ohos_init.h" +#include "msg_center_common.h" +namespace OHOS { + +#ifdef __cplusplus +extern "C" { +#endif + +static const msg_center_cmd_map_t g_msg_center_self_cmd_tbl[] = { +#ifdef JS_ENABLE + { MSGCENTER_CMD_PING, MSGCENTER_TYPE_ID_PING_REC, msg_center_ping_rec}, + { MSGCENTER_CMD_PING, MSGCENTER_TYPE_ID_PING_RSP, NULL}, +#endif +}; + +errcode_t msg_center_self_cmd_type(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tbl_size = sizeof(g_msg_center_self_cmd_tbl) / sizeof(g_msg_center_self_cmd_tbl[0]); + uint8_t i; + for (i = 0; i < tbl_size; i++) { + msg_center_cmd_map_t *item = (msg_center_cmd_map_t *)&g_msg_center_self_cmd_tbl[i]; + if ((item->type == type) && (item->handler != NULL)) { + item->handler(cmd_id, type, usr_data, usr_len); + return ERRCODE_SUCC; + } + } + return ERRCODE_NOT_SUPPORT; +} + +void xiaodu_self_cmd_init(void) +{ + msg_center_register_cmd(MSGCENTER_CMD_PING, msg_center_self_cmd_type); +} + +#ifdef JS_ENABLE +APP_FEATURE_INIT_PRI(xiaodu_self_cmd_init, LAYER_INIT_LEVEL_4); +#endif +#ifdef __cplusplus +} +#endif +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 04e3aa018..557dec374 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -14,9 +14,9 @@ #include "wearable_log.h" #include "service_id_define.h" #include "broadcast_service.h" -#include "AlarmClockModel.h" -#include "AlarmPopUpPresenter.h" -#include "CallerLogModel.h" +#include "alarm/AlarmClockModel.h" +#include "alarm/AlarmPopUpPresenter.h" +#include "callerlog/CallerLogModel.h" #include "notification_manager.h" #include "NativeAbility.h" #include "abilityms_slite_client.h" @@ -29,32 +29,42 @@ #include "baidumap.h" #include "common_def.h" #include "keyinput.h" -#include "KeyInputListener.h" -#include "VolumeSettingView.h" -#include "VolumeSettingPresenter.h" -#include "VolumeSettingView.h" +#include "key/KeyInputListener.h" +#include "main/VolumeSettingView.h" +#include "main/VolumeSettingPresenter.h" +#include "main/VolumeSettingView.h" +#include "cJSON.h" +#include "heartrate/HeartModel.h" +#include "device_location.h" namespace OHOS { #ifdef __cplusplus extern "C" { #endif +extern uint8_t g_bloodoxygen; +extern uint16_t g_heartrate; +extern uint32_t g_stepdata; +extern uint32_t g_distance; +extern LocationInfo_t g_locationInfo; + /* 订阅事件设定优先级 */ const PriorityMapper PRI_MAPPER[] = { {TOPIC_EVENT_ALARM_RING, PRIORITY_TWO}, {TOPIC_EVENT_NEXTDAY_UPDATE, PRIORITY_TWO}, - {TOPIC_EVENT_BLE_TRANSMIT,PRIORITY_ONE}, {TOPIC_EVENT_HFP_INCOMMING, PRIORITY_ONE}, {TOPIC_EVENT_HFP_FINISHED, PRIORITY_ONE}, {TOPIC_EVENT_HFP_PHONE_ACTIVE, PRIORITY_ONE}, {TOPIC_EVENT_HFP_WATCH_ACTIVE, PRIORITY_ONE}, {TOPIC_EVENT_HFP_WATCH_TO_PHONE, PRIORITY_ONE}, {TOPIC_EVENT_HFP_PHONE_TO_WATCH, PRIORITY_ONE}, - {TOPIC_EVENT_DEVICE_BIND, PRIORITY_ONE}, - // {TOPIC_EVENT_DEVICE_UNBIND, PRIORITY_TWO}, - // {TOPIC_EVENT_DEVICE_UNBINDING_REQUEST, PRIORITY_TWO}, - - }; + {TOPIC_DEMO_ALL_MSG, PRIORITY_TWO}, + {TOPIC_EVENT_STEPDATA_UPDATE, PRIORITY_TWO}, + {TOPIC_EVENT_HEARTRATE_UPDATA, PRIORITY_TWO}, + {TOPIC_EVENT_BLOODOXYGEN_UPDATA, PRIORITY_TWO}, + {TOPIC_EVENT_SPORT_DISTANCE, PRIORITY_TWO}, + {TOPIC_EVENT_LOCATION, PRIORITY_TWO}, +}; bool g_pressFlag = false; bool g_longPressFlag = false; @@ -86,7 +96,11 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_FINISHED); MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_PHONE_TO_WATCH); MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_WATCH_TO_PHONE); - MsgCenterSubscribeTopic(TOPIC_EVENT_DEVICE_BIND); + MsgCenterSubscribeTopic(TOPIC_EVENT_STEPDATA_UPDATE); + MsgCenterSubscribeTopic(TOPIC_EVENT_HEARTRATE_UPDATA); + MsgCenterSubscribeTopic(TOPIC_EVENT_BLOODOXYGEN_UPDATA); + MsgCenterSubscribeTopic(TOPIC_EVENT_SPORT_DISTANCE); + MsgCenterSubscribeTopic(TOPIC_EVENT_LOCATION); } static OHOS::UIViewGroup* ShowAlarmNotify(void) @@ -109,28 +123,12 @@ static OHOS::UIViewGroup* ShowMultiPhoneCallNotify(void) return OHOS::CreateMultiplePhoneView(); } - -/*显示绑定通知*/ -static OHOS::UIViewGroup* showDeviceBindingNotify(void) +static OHOS::UIViewGroup* ShowMsgNotify(void) { - return OHOS::CreateDeviceBindingView(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ShowMsgNotify"); + return OHOS::PhoneMsgView::CreatePhoneMsgView(); } -/*显示解绑通知*/ -static OHOS::UIViewGroup* showDeviceUnBindingNotify(void) -{ - return OHOS::CreateDeviceUnBindingView(); -} - -/*显示解除绑定请求(与新设备连接)通知*/ -static OHOS::UIViewGroup* showDeviceUnbindingRequestNotify(void) -{ - return OHOS::CreateDeviceUnbindingRequestGroupView(); -} -static OHOS::UIViewGroup* showtransmitNotify(void) -{ - return OHOS::transmittingShow(); -} void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) { unused(req); @@ -206,115 +204,84 @@ void MsgCenterNotifyHfpWatchProc(const Topic topic, Request* req) } } -void MsgCenterNotifyDeviceBindProc(const Topic topic, Request* req) +void MsgCenterNotifyMsgWatchProc(const Topic topic, Request* req) { - //unused(req); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyBindProc Bind!"); - const power_display_svr_api_t *display_api = power_display_svr_get_api(); - if (display_api->get_screen_state() != SCREEN_ON) - { - display_api->turn_on_screen(); + std::string msgContent((char *)(req->data), req->len); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyMsgWatchProc msgContent %s\r\n", msgContent.c_str()); + cJSON *msgJson = cJSON_Parse(msgContent.c_str()); + if (msgJson == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phone msg_result cJSON_Parse, fail = %p\r\n", msgJson); } - uint8_t* data=(uint8_t*)req->data; - uint8_t len_name = req->len; - char devname[len_name]; - if(data!=NULL && req->len>=2) - { - switch(data[0]) - { - case DEVICEBIND: - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); - len_name = req->len-2; - memset(devname,0,len_name); - if(len_name > 0) - { - memcpy(devname,(char *)req->data+2,len_name); - PairingViewEventListener::GetInstance().SetDeviceName(devname); - }else{ - PairingViewEventListener::GetInstance().SetDeviceName(NULL); - } - NotificationManager::GetInstance()->ShowNotify(showDeviceBindingNotify, (uint16_t)topic, true); - break; - case DEVICEUNBIND: - - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); - len_name = req->len-2; - memset(devname,0,len_name); - if(len_name > 0) - { - memcpy(devname,(char *)req->data+2,len_name); - // printf("devname:%s\r\n",devname); - PairingViewEventListener::GetInstance().SetDeviceName(devname); - }else{ - PairingViewEventListener::GetInstance().SetDeviceName(NULL); - } - NotificationManager::GetInstance()->ShowNotify(showDeviceUnBindingNotify, (uint16_t)topic, true); - break; - case DeviceUnBindingRequest: - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); - NotificationManager::GetInstance()->ShowNotify(showDeviceUnbindingRequestNotify, (uint16_t)topic, true); - break; - case SHUTDOWN: - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, " SHUTDOWN"); - set_lowpower_falg(3); - if (NotificationManager::GetInstance()->HasNotifyShowing()) - NotificationManager::GetInstance()->StopNotify(); - - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); - - NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); - //low_power_play(true); - break; - case REBOOT: - set_lowpower_falg(4); - if (NotificationManager::GetInstance()->HasNotifyShowing()) - NotificationManager::GetInstance()->StopNotify(); - - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); - NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); - //low_power_play(false); - break; - - default: - break; - } - + cJSON *appNameJson = cJSON_GetObjectItem(msgJson, "appName"); + cJSON *packageNameJson = cJSON_GetObjectItem(msgJson, "packageName"); + cJSON *titleJson = cJSON_GetObjectItem(msgJson, "title"); + cJSON *contentJson = cJSON_GetObjectItem(msgJson, "content"); + char *appName = appNameJson->valuestring; + char *packageName = packageNameJson->valuestring; + char *title = titleJson->valuestring; + char *content = contentJson->valuestring; + if (msgJson) { + cJSON_Delete(msgJson); + } + PhoneMsgView::UpDatePhoneMsg(appName, title, content); + if (CheckPriority(topic)) { + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(ShowMsgNotify, static_cast(topic), true); } - } -void MsgCenterNotifybleTransmit(const Topic topic, Request* req) + +void MsgCenterNotifyHeartRateProc(const Topic topic, Request* req) { unused(topic); - uint8_t* data=(uint8_t*)req->data; - - - if(data[0]==TRANS_FREE) - { - if(transmittingISShow()) - NotificationManager::GetInstance()->StopNotify(); + if(req && req->data){ + HeartDatas* heart_data = (HeartDatas*)req->data; + g_heartrate = heart_data->perSec; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyHeartRateProc per heartrate: %d\n", g_heartrate); } - else if (data[0]==IS_NEED_CAT1_OTA) - { - - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); +} - NotificationManager::GetInstance()->ShowNotify(showCat1UpdataNotify, (uint16_t)topic, true); +void MsgCenterNotifyStepDataProc(const Topic topic, Request* req) +{ + unused(topic); + uint32_t step = 0; + if(req && req->data){ + step = *(uint32_t*)req->data; + g_stepdata += step; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyStepDataProc step:%d, totalStep:%d\n", step, g_stepdata); } - else if (data[0]==FILE_IS_DONE) - { - set_transmittingShow_falg(data[0]); +} + +void MsgCenterNotifyBloodOxygenProc(const Topic topic, Request* req) +{ + unused(topic); + if(req && req->data){ + g_bloodoxygen = *(uint8_t*)req->data; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyBloodOxygenProc bloodoxygen:%d\n", g_bloodoxygen); } - else - { - set_transmittingShow_falg(data[0]); - - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); +} - NotificationManager::GetInstance()->ShowNotify(showtransmitNotify, (uint16_t)topic, true); +void MsgCenterNotifyDistanceProc(const Topic topic, Request* req) +{ + unused(topic); + uint32_t distance = 0; + if(req && req->data){ + distance = *(uint32_t*)req->data; + g_distance += distance; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyDistanceProc distance:%d\n", g_distance); } - // unused(req); +} +void MsgCenterNotifyLocationProc(const Topic topic, Request* req) +{ + unused(topic); + if(req && req->data){ + LocationInfo_t* location = (LocationInfo_t*)req->data; + g_locationInfo.latitude_ = location->latitude_; + g_locationInfo.longitude_ = location->longitude_; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "latitude_:%d,longitude_:%d\n", g_locationInfo.latitude_, g_locationInfo.longitude_); + } } + /* 订阅事件通知逻辑可定制 */ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_ALARM_RING, MsgCenterNotifyAlarmProc}, @@ -325,13 +292,13 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_HFP_WATCH_TO_PHONE, MsgCenterNotifyHfpPhoneProc}, {TOPIC_EVENT_HFP_WATCH_ACTIVE, MsgCenterNotifyHfpWatchProc}, {TOPIC_EVENT_HFP_PHONE_TO_WATCH, MsgCenterNotifyHfpWatchProc}, -{TOPIC_EVENT_BLE_TRANSMIT, MsgCenterNotifybleTransmit}, - - {TOPIC_EVENT_DEVICE_BIND, MsgCenterNotifyDeviceBindProc}, - // {TOPIC_EVENT_DEVICE_UNBIND, MsgCenterNotifyDeviceUnBindProc}, - // {TOPIC_EVENT_DEVICE_UNBINDING_REQUEST, MsgCenterNotifyDeviceUnBindingRequestProc}, - - }; + {TOPIC_DEMO_ALL_MSG, MsgCenterNotifyMsgWatchProc}, + {TOPIC_EVENT_HEARTRATE_UPDATA, MsgCenterNotifyHeartRateProc}, + {TOPIC_EVENT_STEPDATA_UPDATE, MsgCenterNotifyStepDataProc}, + {TOPIC_EVENT_BLOODOXYGEN_UPDATA, MsgCenterNotifyBloodOxygenProc}, + {TOPIC_EVENT_SPORT_DISTANCE, MsgCenterNotifyDistanceProc}, + {TOPIC_EVENT_LOCATION, MsgCenterNotifyLocationProc}, +}; static MsgCenterNotifyTable *MsgCenterGetNotifyTblCb(uint8_t idx) { @@ -506,12 +473,12 @@ void StopJsApp(char *bundleName) { ElementName* topAbility = OHOS::AbilityMsClient::GetInstance().GetTopAbility(); if (topAbility == nullptr) { - WEARABLE_LOGE(HILOG_MODULE_AAFWK, "topAbility is null"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "topAbility is null"); return; } if (strcmp(topAbility->bundleName, bundleName) != 0) { - WEARABLE_LOGE(HILOG_MODULE_AAFWK, "%s is not top active", bundleName); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "%s is not top active", bundleName); FreeElement(topAbility); return; } diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/alarm_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/alarm_notification.cpp index dc289cf8e..9b98affc0 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/alarm_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/alarm_notification.cpp @@ -8,7 +8,7 @@ #include "notification_manager.h" #include "wearable_log.h" #include "UiConfig.h" -#include "AlarmPopUpPresenter.h" +#include "alarm/AlarmPopUpPresenter.h" #include "components/ui_image_view.h" #include "components/ui_label.h" @@ -84,6 +84,7 @@ void NoOperateCallback(void* data) { (void)data; NotificationManager::GetInstance()->StopNotify(); + AlarmPopUpPresenter::GetInstance()->DelayAlarmRing(); } void StartAlarmTimer(AlarmTimerType type, int32_t interval) diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/ketinput/src/NotifyOnKeyListener.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/ketinput/src/NotifyOnKeyListener.cpp index bfcc29b0b..cfff9a774 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/ketinput/src/NotifyOnKeyListener.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/ketinput/src/NotifyOnKeyListener.cpp @@ -9,18 +9,18 @@ #include "common/key_code.h" #include "AppViewIDs.h" #include "View.h" -#include "KeyInputListener.h" -#include "VolumeSettingView.h" -#include "VolumeSettingPresenter.h" -#include "VolumeSettingView.h" +#include "key/KeyInputListener.h" +#include "main/VolumeSettingView.h" +#include "main/VolumeSettingPresenter.h" +#include "main/VolumeSettingView.h" #include "wearable_log.h" #include "UiConfig.h" #include "dock/input_device.h" #include "notification_manager.h" -#include "AlarmPopUpPresenter.h" -#include "CallerLogModel.h" -#include "MainCallingPresenter.h" -#include "ApplistModel.h" +#include "alarm/AlarmPopUpPresenter.h" +#include "callerlog/CallerLogModel.h" +#include "makephone/MainCallingPresenter.h" +#include "applist/ApplistModel.h" namespace OHOS { static bool IsNotifyCallStatus() { diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp index 29c369a94..c0929b0df 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp @@ -7,15 +7,15 @@ #include "notification_manager.h" #include "wearable_log.h" -#include "CallerLogModel.h" -#include "PhoneService.h" +#include "callerlog/CallerLogModel.h" +#include "phoneservice/PhoneService.h" #include "cmsis_os.h" #include "UiConfig.h" #include "components/ui_image_view.h" #include "components/ui_label.h" #include "common/image_cache_manager.h" -#include "VolumeSettingView.h" -#include "VolumeSettingPresenter.h" +#include "main/VolumeSettingView.h" +#include "main/VolumeSettingPresenter.h" #include "ui_resource_image.h" namespace OHOS { diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/phone_msg_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/phone_msg_notification.cpp new file mode 100644 index 000000000..eb6a40883 --- /dev/null +++ b/code/sdk/application/wearable/service/msg_center/src/notify/phone_msg_notification.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: phone message notification + * Create: 2025-04-25 + */ + +#include "notification_manager.h" +#include "ohos_timer.h" +#include "wearable_log.h" +#include +#include "main/MessageModel.h" + +namespace OHOS { +// 三方应用名 +static const uint32_t APP_NAME_POS_X = 180; +static const uint32_t APP_NAME_POS_Y = 82; +static const uint32_t APP_NAME_WIDTH = 200; +static const uint32_t APP_NAME_HEIGHT = 60; +// 三方消息主题 +static const uint32_t MSG_TITLE_POS_X = 81; +static const uint32_t MSG_TITLE_POS_Y = 122; +static const uint32_t MSG_TITLE_WIDTH = 409; +static const uint32_t MSG_TITLE_HEIGHT = 83; +// 三方消息内容 +static const uint32_t MSG_CONTENT_POS_X = 78; +static const uint32_t MSG_CONTENT_POS_Y = 176; +static const uint32_t MSG_CONTENT_WIDTH = 457; +static const uint32_t MSG_CONTENT_HEIGHT = 269; +// 取消通知 +static const uint32_t CANCEL_BUTTON_POS_X = 150; +static const uint32_t CANCEL_BUTTON_POS_Y = 323; +static const uint32_t CANCEL_BUTTON_WIDTH = 165; +static const uint32_t CANCEL_BUTTON_HEIGHT = 44; + +// 设置字体大小 +static const uint32_t APP_NAME_FONT_SIZE = 20; +static const uint32_t MSG_TITLE_FONT_SIZE = 20; +static const uint32_t MSG_CONTENT_FONT_SIZE = 40; + +UIViewGroup *PhoneMsgView::phoneMsgView_ = nullptr; +UILabel *PhoneMsgView::appNameLabel_ = nullptr; +UILabel *PhoneMsgView::titleLabel_ = nullptr; +UILabel *PhoneMsgView::contentLabel_ = nullptr; +GraphicTimer *PhoneMsgView::phoneMsgNotifyStop_ = nullptr; +PhoneMsg PhoneMsgView::phoneMsg_; +UILabelButtonExt *PhoneMsgView::cancelButton_ = nullptr; + +void PhoneMsgStopNotifyCallback(void *data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMsgStopNotifyCallback"); + (void)data; + NotificationManager::GetInstance()->StopNotify(); +} + +void PhoneMsgView::StartPhoneMsgTimer(int32_t interval) +{ + uint32_t tick = GetOSTick(interval); + phoneMsgNotifyStop_ = new GraphicTimer(tick, PhoneMsgStopNotifyCallback, nullptr, true); + phoneMsgNotifyStop_->Start(); +} + +void PhoneMsgView::DisablePhoneMsgTimer() +{ + if (phoneMsgNotifyStop_ != nullptr) { + phoneMsgNotifyStop_->Stop(); + delete phoneMsgNotifyStop_; + phoneMsgNotifyStop_ = nullptr; + } +} + +UIViewGroup *PhoneMsgView::CreatePhoneMsgView() +{ + if (phoneMsgView_ == nullptr) { + phoneMsgView_ = new UIViewGroup(); + phoneMsgView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + phoneMsgView_->SetViewId("phoneMsgView"); + } + + if (appNameLabel_ == nullptr) { + appNameLabel_ = new UILabel(); + } + appNameLabel_->SetPosition(APP_NAME_POS_X, APP_NAME_POS_Y, APP_NAME_WIDTH, APP_NAME_HEIGHT); + appNameLabel_->SetText(phoneMsg_.appName.c_str()); + appNameLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, APP_NAME_FONT_SIZE); + appNameLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + // Add to rootView + phoneMsgView_->Add(appNameLabel_); + appNameLabel_->SetVisible(true); + + if (titleLabel_ == nullptr) { + titleLabel_ = new UILabel(); + } + titleLabel_->SetPosition(MSG_TITLE_POS_X, MSG_TITLE_POS_Y, MSG_TITLE_WIDTH, MSG_TITLE_HEIGHT); + titleLabel_->SetText(phoneMsg_.msgTitle.c_str()); + titleLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MSG_TITLE_FONT_SIZE); + titleLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + // Add to rootView + phoneMsgView_->Add(titleLabel_); + titleLabel_->SetVisible(true); + + if (contentLabel_ == nullptr) { + contentLabel_ = new UILabel(); + } + contentLabel_->SetPosition(MSG_CONTENT_POS_X, MSG_CONTENT_POS_Y, MSG_CONTENT_WIDTH, MSG_CONTENT_HEIGHT); + contentLabel_->SetText(phoneMsg_.msgContent.c_str()); + contentLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MSG_CONTENT_FONT_SIZE); + contentLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + // Add to rootView + phoneMsgView_->Add(contentLabel_); + contentLabel_->SetVisible(true); + + if (cancelButton_ == nullptr) { + cancelButton_ = new UILabelButtonExt(); + } + cancelButton_->SetPosition(CANCEL_BUTTON_POS_X, CANCEL_BUTTON_POS_Y, CANCEL_BUTTON_WIDTH, CANCEL_BUTTON_HEIGHT); + cancelButton_->SetViewId("cancelButton"); + cancelButton_->SetText("取消通知"); + cancelButton_->SetTouchable(true); + cancelButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, APP_NAME_FONT_SIZE); + // Add to rootView + phoneMsgView_->Add(cancelButton_); + + phoneMsgView_->SetDraggable(true); + phoneMsgView_->SetTouchable(true); + UIView::OnDragListener *dragListener = + static_cast(PhoneMsgViewEventListener::GetInstance()); + UIView::OnClickListener *clickListener = + static_cast(PhoneMsgViewEventListener::GetInstance()); + phoneMsgView_->SetOnDragListener(dragListener); + phoneMsgView_->SetOnClickListener(clickListener); + cancelButton_->SetOnClickListener(clickListener); + StartPhoneMsgTimer(PhoneMsgView::notifyTime); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreePhoneMsgView); + return phoneMsgView_; +} + +void PhoneMsgView::FreePhoneMsgView(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreePhoneMsgView"); + if (phoneMsgView_ != nullptr) { + DisablePhoneMsgTimer(); + phoneMsgView_->RemoveAll(); + delete appNameLabel_; + appNameLabel_ = nullptr; + delete titleLabel_; + titleLabel_ = nullptr; + delete contentLabel_; + contentLabel_ = nullptr; + delete cancelButton_; + cancelButton_ = nullptr; + RootView::GetInstance()->Remove(phoneMsgView_); + delete phoneMsgView_; + phoneMsgView_ = nullptr; + } +} + +void PhoneMsgView::UpDatePhoneMsg(std::string appName, std::string titile, std::string content) +{ + phoneMsg_.appName = appName; + phoneMsg_.msgTitle = titile; + phoneMsg_.msgContent = content; + MessageModel::GetInstance().GetMessageInfo(appName, titile, content); +} + +PhoneMsgViewEventListener::PhoneMsgViewEventListener() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMsgViewEventListener :%p", this); +} + +PhoneMsgViewEventListener::~PhoneMsgViewEventListener() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~PhoneMsgViewEventListener"); +} + +PhoneMsgViewEventListener *PhoneMsgViewEventListener::GetInstance(void) +{ + static PhoneMsgViewEventListener phoneMsgViewEventListener; + return &phoneMsgViewEventListener; +} + +bool PhoneMsgViewEventListener::OnDrag(UIView &view, const DragEvent &event) +{ + return true; +} + +bool PhoneMsgViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) +{ + std::string viewId = view.GetViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMsgViewEventListener OnDragEnd %s", viewId.c_str()); + if (viewId == "phoneMsgView") { + NotificationManager::GetInstance()->StopNotify(); + } + return true; +} + +bool PhoneMsgViewEventListener::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + std::string viewId = view.GetViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PhoneMsgViewEventListener ClickListener %s", viewId.c_str()); + if (viewId == "phoneMsgView") { + NotificationManager::GetInstance()->StopNotify(); + } + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/service/power_manager/src/actions/display_action.c b/code/sdk/application/wearable/service/power_manager/src/actions/display_action.c index 6f45b72ff..3e2c29d46 100644 --- a/code/sdk/application/wearable/service/power_manager/src/actions/display_action.c +++ b/code/sdk/application/wearable/service/power_manager/src/actions/display_action.c @@ -23,7 +23,7 @@ #include "nandflash_to_os.h" #endif #ifdef SUPPORT_OHOSFWK -#include "ui_screennotify.h" +#include "screennotify/ui_screennotify.h" #endif #include "sys/time.h" #include "touch_screen_def.h" diff --git a/code/sdk/application/wearable/service/remote_msg/CMakeLists.txt b/code/sdk/application/wearable/service/remote_msg/CMakeLists.txt new file mode 100644 index 000000000..f8e5abb7a --- /dev/null +++ b/code/sdk/application/wearable/service/remote_msg/CMakeLists.txt @@ -0,0 +1,37 @@ +set(COMPONENT_NAME "remote_msg") + +set(PUBLIC_HEADER +) + +set(PRIVATE_HEADER + ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits + ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits +) + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/remote_msg.cpp +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -std=c++11 + -Wno-missing-field-initializers +) + +set(WHOLE_LINK + true +) + +set(PUBLIC_DEFINES +) + +set(PRIVATE_DEFINES + APP_PLATFORM_WATCHGT + CONFIG_ACELITE_ENABLE +) + +build_component() + + diff --git a/code/sdk/application/wearable/service/remote_msg/remote_msg.cpp b/code/sdk/application/wearable/service/remote_msg/remote_msg.cpp new file mode 100644 index 000000000..a33965430 --- /dev/null +++ b/code/sdk/application/wearable/service/remote_msg/remote_msg.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: ota upgrade handle. + * This file should be changed only infrequently and with great care. + */ +#include +#include "securec.h" +#include "msg_center.h" +#include "msg_center_protocol.h" +#include "msg_center_cmd.h" +#include "wearable_log.h" +#include "securec.h" +#include "msg_center.h" +#include "msg_center_common.h" +#include "ohos_init.h" +#include "remote_msg.h" +#ifdef __cplusplus +extern "C" { +#endif + +static const msg_center_cmd_map_t g_msg_center_phone_msg_tbl[] = { + {MSGCENTER_CMD_PHONE_MSG, MSGCENTER_TYPE_ID_MSG_THIRD_APP, msg_center_phone_msg_rec}, + {MSGCENTER_CMD_PHONE_MSG, MSGCENTER_TYPE_ID_MSG_SMS, msg_center_phone_msg_rec}, + {MSGCENTER_CMD_PHONE_MSG, MSGCENTER_TYPE_ID_MSG_PHONE, msg_center_phone_msg_rec}, +}; + +errcode_t msg_center_phone_msg_rec(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + errcode_t ret = ERRCODE_SUCC; + uint8_t msg_result = 0; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_phone_msg_rec, cmd_id = %d, type = %d\r\n", cmd_id, type); + Request request; + request.msgId = type; + request.len = payload_len; + request.data = tlv_payload; + MsgCenterNotifyProc(TOPIC_DEMO_ALL_MSG, &request); + ret = msg_center_send_data(cmd_id, type, &msg_result, sizeof(msg_result)); + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "phone msg_result fail, ret = %d\r\n", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +errcode_t msg_center_phone_msg_type_dispatch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "msg_center_phone_msg_type_dispatch, cmd_id = %d, type = %d\r\n", + cmd_id, type); + uint8_t tbl_size = sizeof(g_msg_center_phone_msg_tbl) / sizeof(g_msg_center_phone_msg_tbl[0]); + uint8_t i; + for (i = 0; i < tbl_size; i++) { + msg_center_cmd_map_t *item = (msg_center_cmd_map_t *)&g_msg_center_phone_msg_tbl[i]; + if ((item->type == type) && (item->handler != NULL)) { + item->handler(cmd_id, type, usr_data, usr_len); + return ERRCODE_SUCC; + } + } + return ERRCODE_NOT_SUPPORT; +} + +void phone_msg_init(void) +{ + msg_center_register_cmd(MSGCENTER_CMD_PHONE_MSG, msg_center_phone_msg_type_dispatch); +} + +APP_FEATURE_INIT_PRI(phone_msg_init, LAYER_INIT_LEVEL_4); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/remote_msg/remote_msg.h b/code/sdk/application/wearable/service/remote_msg/remote_msg.h new file mode 100644 index 000000000..2787377ff --- /dev/null +++ b/code/sdk/application/wearable/service/remote_msg/remote_msg.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: third application message + * Author: CompanyName + * Create: 2021-11-11 + */ + +#ifndef REMOTE_MSG_H +#define REMOTE_MSG_H + +#include "msg_center_protocol.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +typedef enum msg_center_phone_msg_type_id { + MSGCENTER_TYPE_ID_MSG_THIRD_APP = 0x1, // 三方应用消息 + MSGCENTER_TYPE_ID_MSG_SMS, // 短信 + MSGCENTER_TYPE_ID_MSG_PHONE, // 电话 + MSGCENTER_TYPE_ID_MSG_MAX, +} msg_center_msg_notify_type_id_t; + +errcode_t msg_center_phone_msg_rec(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif /* REMOTE_MSG_H */ \ No newline at end of file diff --git a/code/sdk/application/wearable/service/xiaodu_voice/xiaodu_voice.cpp b/code/sdk/application/wearable/service/xiaodu_voice/xiaodu_voice.cpp index 6ca6ae711..9e88a4365 100644 --- a/code/sdk/application/wearable/service/xiaodu_voice/xiaodu_voice.cpp +++ b/code/sdk/application/wearable/service/xiaodu_voice/xiaodu_voice.cpp @@ -20,6 +20,9 @@ #include "watchdog.h" #include "js_ability.h" #include "recording_module.h" +#ifdef CONFIG_BRANDY_BLE_TRANS_OPTIMIZE +#include "bluetooth/BluetoothChangeBle.h" +#endif #ifdef __cplusplus extern "C" { @@ -62,6 +65,43 @@ static void pcm_stream_del_queue(void) return; } +static errcode_t send_pcm_stream_data(pcm_stream_queue_msg msg) +{ + uint8_t retry_cnt = 100; + uint8_t msg_send_delay = 10; + errcode_t res; + + while (retry_cnt--) { + if (msg.msg_id == MSGCENTER_TYPE_ID_XIAODU_SEND_PCM_STREAM) { + res = msg_center_xiaodu_send_pcm_stream(MSGCENTER_CMD_XIAODU, MSGCENTER_TYPE_ID_XIAODU_SEND_PCM_STREAM, + msg.data, msg.len); + } else if (msg.msg_id == MSGCENTER_TYPE_ID_XIAODU_END_RECORD) { + res = msg_center_xiaodu_send_end_record(MSGCENTER_CMD_XIAODU, MSGCENTER_TYPE_ID_XIAODU_END_RECORD, msg.data, + msg.len); +#ifdef CONFIG_BRANDY_BLE_TRANS_OPTIMIZE + ChangeBleConnectToDefault(); +#endif + } + + if (res != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send stream fail, retry_cnt: %d, type = %d\n", retry_cnt, + msg.msg_id); + osDelay(msg_send_delay); + } else { + break; + } + } + free(msg.data); + msg.data = nullptr; + if (res != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "after retry, send stream still fail, retry_cnt: %d, type = %d\n", + retry_cnt, msg.msg_id); + pcm_stream_del_queue(); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + static errcode_t pcm_stream_task_body(void *data) { UNUSED(data); @@ -75,39 +115,22 @@ static errcode_t pcm_stream_task_body(void *data) } g_pcm_stream_end_record_sended_flag = false; +#ifdef CONFIG_BRANDY_BLE_TRANS_OPTIMIZE + ChangeBleConnectToMax(); +#endif for (;;) { osStatus_t ret = osMessageQueueGet(g_pcm_stream_msg_queue_id, &msg, nullptr, osWaitForever); if (ret != osOK) { - msg.msg_id = MSGCENTER_TYPE_ID_XIAODU_END_RECORD; - msg.data = nullptr; + continue; } - if (msg.msg_id == MSGCENTER_TYPE_ID_XIAODU_SEND_PCM_STREAM) { - res = msg_center_xiaodu_send_pcm_stream(MSGCENTER_CMD_XIAODU, MSGCENTER_TYPE_ID_XIAODU_SEND_PCM_STREAM, - msg.data, msg.len); - free(msg.data); - msg.data = nullptr; - if (res != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send pcm stream failed"); - pcm_stream_del_queue(); - return ERRCODE_FAIL; - } - } else if (msg.msg_id == MSGCENTER_TYPE_ID_XIAODU_END_RECORD) { - res = msg_center_xiaodu_send_end_record(MSGCENTER_CMD_XIAODU, MSGCENTER_TYPE_ID_XIAODU_END_RECORD, msg.data, - msg.len); - free(msg.data); - msg.data = nullptr; - if (res != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send pcm end failed"); - pcm_stream_del_queue(); - return ERRCODE_FAIL; - } - g_pcm_stream_end_record_sended_flag = true; - return ERRCODE_SUCC; + + /* pcm帧、end帧合并处理 */ + res = send_pcm_stream_data(msg); + if (res == ERRCODE_FAIL || (res == ERRCODE_SUCC && msg.msg_id == MSGCENTER_TYPE_ID_XIAODU_END_RECORD)) { + return res; } } - - return ERRCODE_SUCC; } /* @@ -163,7 +186,6 @@ errcode_t pcm_stream_create_task(void) errcode_t msg_center_xiaodu_start(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) { - unused(usr_data); uint8_t ack = 1; errcode_t ret = ERRCODE_SUCC; @@ -174,16 +196,21 @@ errcode_t msg_center_xiaodu_start(uint8_t cmd_id, uint8_t type, void *usr_data, } display_api->set_screen_set_keepon_timeout(30000); // 30000ms #endif -#ifdef JS_ENABLE - StartJsApp("com.vendor.voiceassistant"); -#endif /* ack */ ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); if (ret != ERRCODE_SUCC) { return ERRCODE_FAIL; } + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); +#ifdef JS_ENABLE + if(tlv_payload[0] == 1) { + StartJsApp("com.vendor.Aidialogue"); + } else { + StartJsApp("com.vendor.Aidial"); + } +#endif return ERRCODE_SUCC; } @@ -407,6 +434,7 @@ errcode_t msg_center_xiaodu_send_end_record(uint8_t cmd_id, uint8_t type, void * WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "send pcm stream end, usr_data = %d, usr_len = %d\r\n", *(uint8_t *)usr_data, usr_len); /* usr_data参考协议msg_center_pcm_end_flag_t */ pcm_stream_del_queue(); + g_pcm_stream_end_record_sended_flag = true; return ERRCODE_SUCC; } diff --git a/code/sdk/application/wearable/service/xiaodu_voice/xiaodu_voice_msg.cpp b/code/sdk/application/wearable/service/xiaodu_voice/xiaodu_voice_msg.cpp index ebe9e4086..1d3047a54 100644 --- a/code/sdk/application/wearable/service/xiaodu_voice/xiaodu_voice_msg.cpp +++ b/code/sdk/application/wearable/service/xiaodu_voice/xiaodu_voice_msg.cpp @@ -3,6 +3,9 @@ #include "msg_center_protocol.h" #include "msg_center_cmd.h" #include "ohos_init.h" +#include "msg_center_common.h" +#include "wearable_log.h" + namespace OHOS { #ifdef __cplusplus