From 1d51973210224bbbc1df0ad9f63177d12e22daea Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 26 Mar 2025 15:50:52 +0800 Subject: [PATCH] =?utf8?q?=E7=A7=92=E8=A1=A8slice=E5=90=88=E5=B9=B6?= =?utf8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/MainStopWatchPresenter.h | 77 ++++ .../stopwatch/include/MainStopWatchView.h | 82 ++++ .../stopwatch/include/StopWatchAdapter.h | 47 ++ .../stopwatch/include/StopWatchItemView.h | 32 ++ .../stopwatch/include/StopWatchModel.h | 43 ++ .../include/StopWatchRecordCycleToLimitView.h | 39 ++ .../include/StopWatchRecordTimeToLimitView.h | 39 ++ .../stopwatch/src/MainStopWatchPresenter.cpp | 377 ++++++++++++++++ .../stopwatch/src/MainStopWatchView.cpp | 417 ++++++++++++++++++ .../stopwatch/src/StopWatchAdapter.cpp | 83 ++++ .../stopwatch/src/StopWatchItemView.cpp | 74 ++++ .../nativeui/stopwatch/src/StopWatchModel.cpp | 210 +++++++++ .../src/StopWatchRecordCycleToLimitView.cpp | 156 +++++++ .../src/StopWatchRecordTimeToLimitView.cpp | 178 ++++++++ 14 files changed, 1854 insertions(+) create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchAdapter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchItemView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchModel.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchAdapter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchItemView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchModel.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h new file mode 100644 index 000000000..1152b15bd --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h @@ -0,0 +1,77 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-04 15:13:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-10-30 14:51:08 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h + */ +#ifndef MAIN_STOPWATCH_PRESENTER_H +#define MAIN_STOPWATCH_PRESENTER_H + +#include "Presenter.h" +#include "View.h" +#include "MainStopWatchView.h" +#include +#include "ui_resource_string.h" +#include "ModelListenerSample.h" +/*秒表主视图*/ +namespace OHOS +{ + static constexpr int STOPWATCH_TIMER_DURATION = 10; // 定时器周期,每10毫秒定时器会触发一次 + static constexpr int MAX_RECORD_LOOPS = 99; // 最大记录圈数为99 + static const char *MAX_RECORD_TIME = "99:59.99"; // 最高记录时间为99:59.99 + typedef enum + { + MAIN_STOPWATCH = 0, // 秒表主视图 + STOPWATCH_RECORD_CYCLE_TO_LIMIT, // 到达秒表计时的最高记录圈数后弹出视图 + STOPWATCH_RECORD_TIME_TO_LIMIT, // 到达秒表最大的记录时间后弹出该视图 + STOPWATCH_MAXVIEWID, // 秒表的视图id数量 + } StopWatchViewId; + class MainStopWatchView; + class MainStopWatchPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener, + public UICheckBox::OnChangeListener, + public ModelListenerSample + { + public: + MainStopWatchPresenter(); + virtual ~MainStopWatchPresenter(); + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + static MainStopWatchPresenter *GetInstance(); + void SetCheckBoxAndButton(UICheckBox *checkbox, UIButton *button); + void SetLable(UILabel *label1, UILabel *label2); + void SetShowTimeLableStyle(UILabel *label, int x, int y, int TextFont, int LineHeight); + void SetList(UIList *list, TextAdapter *listadapter, List *listdata); + void SetImage(UIImageView *image); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnChange(UICheckBox::UICheckBoxState state) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + void Notify() override; + private: + UICheckBox *m_checkbox{nullptr}; + UIButton *m_button{nullptr}; + UILabel *m_stopWatchlabel{nullptr}; + UILabel *m_showTimelabel{nullptr}; + UIImageView *m_image{nullptr}; + UIList *m_list = nullptr; + TextAdapter *m_listadapter = nullptr; + List *m_listdata = nullptr; + uint64_t lastRecordTime = 0; // 上次记录时间 + int RecordCycleNumber{0}; // 用来记录计时圈数 + bool X_DRAG_FLAG{false}; + bool isStartMark{false}; + bool TimerIsRunning{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h new file mode 100644 index 000000000..ffbaadbd7 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h @@ -0,0 +1,82 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-04 15:13:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2025-02-24 17:21:50 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h + */ +#ifndef MAIN_STOPWATCH_VIEW_H +#define MAIN_STOPWATCH_VIEW_H + + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_checkbox.h" +#include "components/ui_button.h" +#include "components/ui_list.h" +#include "components/text_adapter.h" +#include "stopwatch/include/StopWatchRecordCycleToLimitView.h" +#include "stopwatch/include/StopWatchRecordTimeToLimitView.h" +#include "stopwatch/include/StopWatchAdapter.h" +/*秒表主视图*/ +namespace OHOS +{ + + static const char *checkBox1selectedImg = "/user/res/countdown/COUNTDOWM_PLAY.bin"; // 播放 + static const char *checkBox1unSelectedImg = "/user/res/countdown/COUNTDOWM_PAUSE.bin"; // 暂停 + static const char *ResetOrMarkButtonImg_Reset1 = "/user/res/stopwatch/STOPWATH_RESET1.bin"; // 重置_灰色 图片 + static const char *ResetOrMarkButtonImg_Reset2 = "/user/res/stopwatch/STOPWATH_RESET2.bin"; // 重置_白色 图片 + static const char *ResetOrMarkButtonImg_Mark = "/user/res/stopwatch/STOPWATCH_MARK.bin"; // 标记 图片 + static const char *PlayOrPausecheckBoxVIEWID = "PlayOrPausecheckBox"; // 播放或暂停复选框视图ID + static const char *ResetOrMarkButton_RESET1_VIEWID = "ResetOrMarkButtonReset1"; // ResetOrMarkButtonReset1 + static const char *ResetOrMarkButton_RESET2_VIEWID = "ResetOrMarkButtonReset2"; // ResetOrMarkButtonReset2 + static const char *ResetOrMarkButton_MARK_VIEWID = "ResetOrMarkButtonMark"; // ResetOrMarkButtonMark + static const char *CycleToLimitReturnButton_VIEWID = "CycleToLimitReturnButton"; // CycleToLimitReturnButton + static const char *TimeToLimitReturnButton_VIEWID = "TimeToLimitReturnButton"; // TimeToLimitReturnButton + class MainStopWatchPresenter; + class MainStopWatchView : public View + { + + public: + MainStopWatchView(); + virtual ~MainStopWatchView(); + static MainStopWatchView *GetInstance(void); + + void OnStart() override; + void SetViewIsVisible(UIView *view, bool status); + bool ClickFunc(int16_t interface); + void ChangeView(int16_t hideView, int16_t showView); + bool ChangeMainStopWatch(int16_t thisView); + bool ChangeStopWatchRecordCycleLimit(int16_t thisView); + bool ChangeMainStopWatchRecordTimeLimit(int16_t thisView); + UILabelExt *GetShowTimelabel(void); + UICheckBox *GetPlayOrPausecheckBox(void); + void ChangeRecordTimeToLimitView(void); + UIScrollView *GetScrollView(int16_t index); + StopWatchAdapter *GetStopWatchAdapter(void); + private: + void InitMainStopWatchView(void); + void ClearAll(void); + + private: + StopWatchRecordCycleToLimitView *p_StopWatchRecordCycleToLimitView{nullptr}; // 圈数到达上限后弹出该视图 + StopWatchRecordTimeToLimitView *p_StopWatchRecordTimeToLimitView{nullptr}; // 计时时间到达上限后弹出该视图 + + private: + UIViewGroup *group = nullptr; + UIScrollView *scrollView[3] = {nullptr}; + UILabelExt *stopWatchlabel = nullptr; // 内容为“秒表”的标签 + UILabelExt *showTimelabel = nullptr; // 用来显示计时时间 + UICheckBox *PlayOrPausecheckBox = nullptr; // 播放或暂停复选框 + UIButton *ResetOrMarkbutton = nullptr; // 重置或标记按钮 + UIImageView *LineImage{nullptr}; + UIList *list = nullptr; + TextAdapter *listadapter = nullptr; + List *listdata = nullptr; + + StopWatchAdapter *stopWatchAdapter{nullptr}; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchAdapter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchAdapter.h new file mode 100644 index 000000000..8720b6901 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchAdapter.h @@ -0,0 +1,47 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-12-12 11:03:15 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-16 11:43:14 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchAdapter.h + */ + +#ifndef STOPWATCH_ADAPTER_H +#define STOPWATCH_ADAPTER_H + +#include "components/ui_list.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 "components/abstract_adapter.h" +#include +#include + +namespace OHOS +{ + typedef struct + { + std::string RecordCycleNumber; + std::string formattedTime; + std::string formattedDiff; + int curSelectItemViewIndex; + } StopWatchItem; + + class StopWatchAdapter : public AbstractAdapter + { + public: + explicit StopWatchAdapter(); + ~StopWatchAdapter() override; + uint16_t GetCount(void) override; + void ClearData(void); + void setSelectedIndex(int index); + UIView *GetView(UIView *inView, int16_t index) override; + void AddListItem(const StopWatchItem &item); + + private: + std::list listData; + int curSelectItemViewIndex{-1}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchItemView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchItemView.h new file mode 100644 index 000000000..9f5f11a60 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchItemView.h @@ -0,0 +1,32 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-16 14:42:31 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItemView.h + */ + +#ifndef STOPWATCH_ITEM_VIEW_H +#define STOPWATCH_ITEM_VIEW_H + +#include "components/ui_label_ext.h" +#include "components/ui_view_group.h" +#include "stopwatch/include/StopWatchAdapter.h" +namespace OHOS +{ + class StopWatchItemView : public UIViewGroup + { + public: + explicit StopWatchItemView(); + ~StopWatchItemView() override; + void SetItemInfo(const StopWatchItem itemInfo); + void SetUpChild(); + void SetItemViewColor(bool flag); + + private: + UILabel RecordCycleNumber; + UILabel formattedTime; + UILabel formattedDiff; + }; +} +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchModel.h new file mode 100644 index 000000000..b2d2a770c --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchModel.h @@ -0,0 +1,43 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-04 15:13:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-27 17:45:02 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h + */ +#ifndef STOP_WATCH_MODEL_H +#define STOP_WATCH_MODEL_H + +#include +#include +#include + +namespace OHOS +{ + + class StopWatchModel + { + public: + static std::shared_ptr GetInstance(); // shared_ptr:当没有引用指向这个实例时会自动释放内存 + ~StopWatchModel() {} + std::string DisplayStopWatchDuration(); + void StopWatch_StartTimer(uint32_t interval); + void StopWatch_StopTimer(void); + void StopWatch_PauseTimer(); + void StopWatch_ResumeTimer(uint32_t interval); + bool isReachMaxRecordTime(void); + + + private: + // 将构造函数、拷贝构造函数和赋值操作符私有化 + StopWatchModel() = default; + StopWatchModel(const StopWatchModel &) = delete; + StopWatchModel &operator=(const StopWatchModel &) = delete; + + private: + std::string stopwatchDuration; + }; + +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h new file mode 100644 index 000000000..85d24ef97 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h @@ -0,0 +1,39 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-04 15:13:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-07 16:07:11 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h + */ +#ifndef STOPWATCH_RECORD_CYCLE_TO_LIMIT_VIEW_H +#define STOPWATCH_RECORD_CYCLE_TO_LIMIT_VIEW_H + + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button_ext.h" +/*弹窗视图:到达最高圈数99时弹出*/ +namespace OHOS +{ + class StopWatchRecordCycleToLimitView + { + + public: + StopWatchRecordCycleToLimitView(); + void ClearAll(void); + virtual ~StopWatchRecordCycleToLimitView(); + static StopWatchRecordCycleToLimitView *GetInstance(void); + UIScrollView *InitStopWatchRecordCycleToLimitView(void); + + private: + UIScrollView *scrollView = nullptr; + UILabelExt *Title = nullptr; + UIImageView *AttentionImage = nullptr; + UILabelExt *AttentionLabel = nullptr; + UILabelButtonExt *button = nullptr; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h new file mode 100644 index 000000000..d5a62534a --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h @@ -0,0 +1,39 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-04 15:13:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-07 16:28:41 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h + */ +#ifndef STOPWATCH_RECORD_TIME_TO_LIMIT_VIEW_H +#define STOPWATCH_RECORD_TIME_TO_LIMIT_VIEW_H + + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button_ext.h" +/*弹窗视图:到达最高时间99:59.99时弹出*/ +namespace OHOS +{ + class StopWatchRecordTimeToLimitView + { + public: + StopWatchRecordTimeToLimitView(); + virtual ~StopWatchRecordTimeToLimitView(); + static StopWatchRecordTimeToLimitView *GetInstance(void); + UIScrollView *InitStopWatchRecordTimeToLimitView(void); + void ClearAll(void); + + private: + UIScrollView *scrollView = nullptr; + UILabelExt *Title = nullptr; + UIImageView *AttentionImage = nullptr; + UILabelExt *AttentionLabel_1 = nullptr; + UILabelExt *AttentionLabel_2 = nullptr; + UILabelButtonExt *button = nullptr; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp new file mode 100644 index 000000000..249a639cb --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -0,0 +1,377 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "UiConfig.h" +#include "stopwatch/include/MainStopWatchPresenter.h" +#include "stopwatch/include/StopWatchModel.h" +#include "common/key_code.h" +#include +/*秒表主视图*/ +#include "gfx_utils/mem_check.h" + +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_MENU_PRO(VIEW_MAIN_STOPWATCH, MainStopWatchView, MainStopWatchPresenter, + PNG_APPLIST_STOPWATCH_IMAGE_BIG, PNG_APPLIST_STOPWATCH_IMAGE, PNG_APPLIST_STOPWATCH_IMAGE, "秒表", STR_STOPWATCH); + + // 当前Presenter属性实例化的内存指针 + static MainStopWatchPresenter *g_pMainStopWatchPresenter = nullptr; + + MainStopWatchPresenter::MainStopWatchPresenter() + { + g_pMainStopWatchPresenter = this; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + } + + MainStopWatchPresenter::~MainStopWatchPresenter() + { + StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 退出删除并清理定时器资源 + g_pMainStopWatchPresenter = nullptr; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + } + + MainStopWatchPresenter *MainStopWatchPresenter::GetInstance() + { + return g_pMainStopWatchPresenter; + } + + void MainStopWatchPresenter::OnStart() + { + // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 长亮屏 + } + + void MainStopWatchPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void MainStopWatchPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void MainStopWatchPresenter::OnStop(void) + { + // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消长亮屏 + } + + /// @brief 设置复选框和按钮 + /// @param checkbox + /// @param button + void MainStopWatchPresenter::SetCheckBoxAndButton(UICheckBox *checkbox, UIButton *button) + { + m_checkbox = checkbox; + m_button = button; + } + + /// @brief 设置标签 + /// @param label1 + /// @param label2 + void MainStopWatchPresenter::SetLable(UILabel *label1, UILabel *label2) + { + m_stopWatchlabel = label1; + m_showTimelabel = label2; + } + + /// @brief 设置显示时间的标签样式 + /// @param label + /// @param x + /// @param y + /// @param TextFont + /// @param LineHeight + void MainStopWatchPresenter::SetShowTimeLableStyle(UILabel *label, int x, int y, int TextFont, int LineHeight) + { + label->SetPosition(x, y, 466, LineHeight); + label->SetStyle(STYLE_TEXT_FONT, TextFont); + label->SetStyle(STYLE_LINE_HEIGHT, LineHeight); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, TextFont); + label->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->Invalidate(); + } + + void MainStopWatchPresenter::SetList(UIList *list, TextAdapter *listadapter, List *listdata) + { + m_list = list; + m_listadapter = listadapter; + m_listdata = listdata; + } + + void MainStopWatchPresenter::SetImage(UIImageView *image) + { + m_image = image; + } + + bool MainStopWatchPresenter::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + MainStopWatchPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool MainStopWatchPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnDragEnd"); + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainStopWatchPresenter::X_DRAG_FLAG) + { + if (&view == view_->GetScrollView(MAIN_STOPWATCH)) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + else if (&view == view_->GetScrollView(STOPWATCH_RECORD_CYCLE_TO_LIMIT)) + { + view_->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); + } + else if (&view == view_->GetScrollView(STOPWATCH_RECORD_TIME_TO_LIMIT)) + { + view_->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); + } + X_DRAG_FLAG = false; + } + return true; + } + + /* + * Converts a time string in the format "mm:ss.ms" to milliseconds. + * + * @param timeStr The time string to convert. + * @return The time in milliseconds. + */ + static unsigned long TimeStrToMilliseconds(const char *timeStr) + { + unsigned minutes, seconds, milliseconds; + + // Assuming the format is "mm:ss.ms" + if (sscanf(timeStr, "%u:%u.%u", &minutes, &seconds, &milliseconds) == 3) + { + // 将分钟转换为毫秒,将秒转换为毫秒,并将它们相加 + unsigned long totalMilliseconds = (minutes * 60 * 1000) + (seconds * 1000) + (milliseconds * 10); + return totalMilliseconds; + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Invalid time format."); + return 0; + } + } + + /*将毫秒级数转成格式为"mm:ss.ms"*/ + static void MillisecondsToTimeStr(unsigned long milliseconds, char *buffer) + { + unsigned minutes = milliseconds / (60 * 1000); + milliseconds %= (60 * 1000); // Remaining milliseconds after converting to minutes + unsigned seconds = milliseconds / 1000; + unsigned ms = milliseconds % 1000; // Remaining milliseconds after converting to seconds + + // Assuming ms needs to be in hundredths of a second for the ".ms" format + unsigned msHundredths = ms / 10; // Convert to hundredths of a second + + // Write the formatted time string to the buffer + sprintf(buffer, "%02u:%02u.%02u", minutes, seconds, msHundredths); + } + + bool MainStopWatchPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(view); + MainStopWatchView *mainStopWatchView = MainStopWatchView::GetInstance(); + const char *clickedViewId = view.GetViewId(); + if (strcmp(clickedViewId, ResetOrMarkButton_MARK_VIEWID) == 0) // 点击标记按钮 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordCycleNumber:%d\n", RecordCycleNumber); + if (RecordCycleNumber >= MAX_RECORD_LOOPS) // 到达最高记录圈数 + { + m_checkbox->SetState(UICheckBox::UNSELECTED); + mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_CYCLE_TO_LIMIT); + return true; + } + else + { + RecordCycleNumber += 1; + } + + if (isStartMark == false) // 第一次标记 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "isStartMark = %d", isStartMark); + mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false); + SetShowTimeLableStyle(m_showTimelabel, 0, 60, 65, 78); + mainStopWatchView->SetViewIsVisible(m_list, true); + mainStopWatchView->SetViewIsVisible(m_image, true); + isStartMark = true; + } + + uint64_t currentRecordTime = TimeStrToMilliseconds(MainStopWatchView::GetInstance()->GetShowTimelabel()->GetText()); // 获取当前时间 + uint64_t timeDifference = 0; // 时间差值 + if (lastRecordTime > 0) + { + // 如果不是第一次标记,则计算与上一次记录的时间差 + timeDifference = currentRecordTime - lastRecordTime; + } + // 将时间和时间差格式化为字符串,更新到UI + const char *formattedTime = MainStopWatchView::GetInstance()->GetShowTimelabel()->GetText(); + char formattedDiff[64] = {0}; + MillisecondsToTimeStr(timeDifference, formattedDiff); + // char *PickerData = (char *)malloc(128); + // if (lastRecordTime == 0) // 如果是第一次标记 + // { + // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedTime); + // } + // else + // { + // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedDiff); + // } + // m_listdata->PushFront(const_cast(PickerData)); + // m_listadapter->SetData(m_listdata); + // m_list->SetAdapter(m_listadapter); + // char PickerData[128]={0}; + // if (lastRecordTime == 0) // 如果是第一次标记 + // { + // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedTime); + // } + // else + // { + // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedDiff); + // } + + StopWatchItem item = {"", "", "", 0}; + char buffer[3] = {0}; // 足够存放两位数字及字符串结束符'\0' + std::sprintf(buffer, "%02d", RecordCycleNumber); + item.RecordCycleNumber = buffer; + item.formattedTime = std::string(formattedTime); + ; + item.formattedDiff = "+" + std::string((lastRecordTime == 0) ? formattedTime : formattedDiff); // lastRecordTime == 0,如果是第一次标记 + item.curSelectItemViewIndex = RecordCycleNumber - 1; + + view_->GetStopWatchAdapter()->setSelectedIndex(RecordCycleNumber - 1); + view_->GetStopWatchAdapter()->AddListItem(item); + m_list->SetAdapter(view_->GetStopWatchAdapter()); + m_list->SetStartIndex(RecordCycleNumber - 1); + m_list->SetSelectPosition(RecordCycleNumber); + m_list->RefreshList(); + // 保存当前时间为“上一次记录时间”,为下一次标记做准备 + lastRecordTime = currentRecordTime; + return true; + } + else if (strcmp(clickedViewId, ResetOrMarkButton_RESET2_VIEWID) == 0) // 点击重置按钮 + { + StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 停止定时器 + mainStopWatchView->GetShowTimelabel()->SetText("00:00.00"); + lastRecordTime = 0; + view_->GetStopWatchAdapter()->ClearData(); + m_list->SetAdapter(nullptr); + m_list->RefreshList(); + + m_button->SetViewId(ResetOrMarkButton_RESET1_VIEWID); + m_button->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1); + m_button->Invalidate(); + + if (isStartMark == true) // 重置标记 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "isStartMark = %d", isStartMark); + mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, true); + SetShowTimeLableStyle(m_showTimelabel, 0, 160, 84, 94); + mainStopWatchView->SetViewIsVisible(m_image, false); + mainStopWatchView->SetViewIsVisible(m_list, false); + isStartMark = false; + } + + // if (m_listdata != nullptr) + // { + // // 遍历列表,释放每个元素所占用的内存 + // ListNode *node = m_listdata->Head(); + // int cnt = 0; + // while (node != m_listdata->End()) + // { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", ++cnt); + // const char *p = node->data_; + // free(const_cast(p)); + + // node = m_listdata->Remove(node); + // } + // m_listdata->Clear(); + // } + // else + // { + // // Handle error or log the issue + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: m_listdata is nullptr"); + // } + RecordCycleNumber = 0; + } + else if (strcmp(clickedViewId, CycleToLimitReturnButton_VIEWID) == 0) // 点击返回按钮 + { + mainStopWatchView->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); + } + else if (strcmp(clickedViewId, TimeToLimitReturnButton_VIEWID) == 0) // 点击返回按钮 + { + mainStopWatchView->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); + } + else if (strcmp(clickedViewId, PlayOrPausecheckBoxVIEWID) == 0) // 点击播放和暂停按钮 + { + if (StopWatchModel::GetInstance()->isReachMaxRecordTime()) // 到达最大时间不能再计时 + { + mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_TIME_TO_LIMIT); + } + } + return true; + } + + bool MainStopWatchPresenter::OnChange(UICheckBox::UICheckBoxState state) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnChange,state = %d", state); + if (state == UICheckBox::UICheckBoxState::SELECTED) + { + StopWatchModel::GetInstance()->StopWatch_StartTimer(STOPWATCH_TIMER_DURATION); // 开启定时器,如果定时器存在会直接返回 + StopWatchModel::GetInstance()->StopWatch_ResumeTimer(STOPWATCH_TIMER_DURATION); // 恢复定时器 + + m_button->SetViewId(ResetOrMarkButton_MARK_VIEWID); + m_button->SetImageSrc(ResetOrMarkButtonImg_Mark, ResetOrMarkButtonImg_Mark); + m_button->Invalidate(); // 图片重新赋值要刷新该区域 + TimerIsRunning = true; + } + else + { + StopWatchModel::GetInstance()->StopWatch_PauseTimer(); // 暂停定时器 + m_button->SetViewId(ResetOrMarkButton_RESET2_VIEWID); + m_button->SetImageSrc(ResetOrMarkButtonImg_Reset2, ResetOrMarkButtonImg_Reset2); + m_button->Invalidate(); + TimerIsRunning = false; + } + return true; + } + + // 增加按键事件 + bool MainStopWatchPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return false; + } + + void MainStopWatchPresenter::Notify() + { + if (view_->GetScrollView(MAIN_STOPWATCH) && view_->GetScrollView(MAIN_STOPWATCH)->IsVisible()) + { + if (TimerIsRunning) + { + view_->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration().c_str()); + view_->GetShowTimelabel()->Invalidate(); + } + } + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp new file mode 100644 index 000000000..547ddf7af --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp @@ -0,0 +1,417 @@ +#include "stopwatch/include/MainStopWatchView.h" +#include "stopwatch/include/MainStopWatchPresenter.h" +#include "UiConfig.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +#include "wearable_log.h" +/*秒表主视图*/ +namespace OHOS +{ + + static MainStopWatchView *g_pMainStopWatchView{nullptr}; + + MainStopWatchView::MainStopWatchView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::MainStopWatchView"); + g_pMainStopWatchView = this; + } + + MainStopWatchView::~MainStopWatchView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::~MainStopWatchView"); + ClearAll(); + g_pMainStopWatchView = nullptr; + } + + MainStopWatchView *MainStopWatchView::GetInstance() + { + return g_pMainStopWatchView; + } + + void MainStopWatchView::ClearAll() + { + if (group != nullptr) + { + group->RemoveAll(); + scrollView[MAIN_STOPWATCH]->RemoveAll(); + + if (stopWatchlabel != nullptr) + { + delete stopWatchlabel; + stopWatchlabel = nullptr; + } + + if (showTimelabel != nullptr) + { + delete showTimelabel; + showTimelabel = nullptr; + } + + if (PlayOrPausecheckBox != nullptr) + { + delete PlayOrPausecheckBox; + PlayOrPausecheckBox = nullptr; + } + + if (ResetOrMarkbutton != nullptr) + { + delete ResetOrMarkbutton; + ResetOrMarkbutton = nullptr; + } + + if (LineImage != nullptr) + { + delete LineImage; + LineImage = nullptr; + } + + if (stopWatchAdapter != nullptr) + { + delete stopWatchAdapter; + stopWatchAdapter = nullptr; + } + + if (list != nullptr) + { + delete list; + list = nullptr; + } + + if (listadapter != nullptr) + { + delete listadapter; + listadapter = nullptr; + } + + if (listdata != nullptr) + { + listdata->Clear(); + delete listdata; + listdata = nullptr; + } + + if (scrollView[MAIN_STOPWATCH] != nullptr) + { + delete scrollView[MAIN_STOPWATCH]; + scrollView[MAIN_STOPWATCH] = nullptr; + } + + if (p_StopWatchRecordCycleToLimitView != nullptr) + { + delete p_StopWatchRecordCycleToLimitView; + p_StopWatchRecordCycleToLimitView = nullptr; + } + + if (p_StopWatchRecordTimeToLimitView != nullptr) + { + delete p_StopWatchRecordTimeToLimitView; + p_StopWatchRecordTimeToLimitView = nullptr; + } + + for (int i = MAIN_STOPWATCH; i < STOPWATCH_MAXVIEWID; i++) + { + scrollView[MAIN_STOPWATCH] = nullptr; + } + + delete group; + group = nullptr; + } + } + + /// @brief 设置视图是否可见 + /// @param view 具体视图 + /// @param status true 可见 false 不可见 + void MainStopWatchView::SetViewIsVisible(UIView *view, bool status) + { + if (status == true) + { + view->SetVisible(true); + } + else + { + view->SetVisible(false); + } + view->Invalidate(); + } + + // 1.切换到秒表主视图 + bool MainStopWatchView::ChangeMainStopWatch(int16_t thisView) + { + if (scrollView[thisView] == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::ChangeMainStopWatch"); + group->Add(scrollView[thisView]); + } + return true; + } + + // 2.切换到秒表到达最高圈数视图 + bool MainStopWatchView::ChangeStopWatchRecordCycleLimit(int16_t thisView) + { + if (scrollView[thisView] == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::StopWatchRecordCycleToLimitView"); + p_StopWatchRecordCycleToLimitView = new StopWatchRecordCycleToLimitView(); + if (p_StopWatchRecordCycleToLimitView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainStopWatchView:: new scrollView[%d] fail", thisView); + return false; + } + scrollView[thisView] = p_StopWatchRecordCycleToLimitView->InitStopWatchRecordCycleToLimitView(); + group->Add(scrollView[thisView]); + } + return true; + } + + // 3.切换到秒表到达最大时间计时视图 + bool MainStopWatchView::ChangeMainStopWatchRecordTimeLimit(int16_t thisView) + { + if (scrollView[thisView] == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::ChangeMainStopWatchRecordTimeLimit"); + p_StopWatchRecordTimeToLimitView = new StopWatchRecordTimeToLimitView(); + if (p_StopWatchRecordTimeToLimitView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainStopWatchView:: new scrollView[%d] fail", thisView); + return false; + } + scrollView[thisView] = p_StopWatchRecordTimeToLimitView->InitStopWatchRecordTimeToLimitView(); + group->Add(scrollView[thisView]); + } + return true; + } + /* -------------------------------------------------------------------------- */ + // 1.MainStopWatchViewMapper:结构体定义了一个将视图ID映射到特定成员函数指针的映射表。 + struct MainStopWatchViewMapper + { + const int16_t viewId; + bool (MainStopWatchView::*func)(int16_t thisView); + }; + + // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与MainStopWatchView类中的特定成员函数指针进行了绑定。 + static const MainStopWatchViewMapper ViewMapper[] = { + {MAIN_STOPWATCH, &MainStopWatchView::ChangeMainStopWatch}, + {STOPWATCH_RECORD_CYCLE_TO_LIMIT, &MainStopWatchView::ChangeStopWatchRecordCycleLimit}, + {STOPWATCH_RECORD_TIME_TO_LIMIT, &MainStopWatchView::ChangeMainStopWatchRecordTimeLimit}, + }; + + // 3.根据传入的interface参数执行相应视图ID关联的成员函数。 + bool MainStopWatchView::ClickFunc(int16_t interface) + { + int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); + for (int i = 0; i < funcSize; i++) + { + if (interface == ViewMapper[i].viewId) + { + bool jug = (this->*(ViewMapper[i].func))(interface); + if (jug == false) + { + return false; + } + return true; + } + } + return false; + } + + // 4.切换视图 + void MainStopWatchView::ChangeView(int16_t hideView, int16_t showView) + { + if (hideView > STOPWATCH_MAXVIEWID) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainStopWatchView:: StopWatchViewId Overstep ones bounds"); + return; + } + scrollView[hideView]->SetVisible(false); + ClickFunc(showView); + scrollView[showView]->SetVisible(true); + Draw(); + } + /* -------------------------------------------------------------------------- */ + // 初始化秒表主视图 + void MainStopWatchView::InitMainStopWatchView() + { + if (group == nullptr) + { + /* ---------------------------------- group --------------------------------- */ + group = new UIViewGroup(); + if (group == nullptr) + { + return; + } + group->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + /* ----------------------- scrollView[MAIN_STOPWATCH] ----------------------- */ + if (scrollView[MAIN_STOPWATCH] == nullptr) + { + scrollView[MAIN_STOPWATCH] = new UIScrollView(); + } + scrollView[MAIN_STOPWATCH]->SetPosition(0, 0, 466, 466); + scrollView[MAIN_STOPWATCH]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView[MAIN_STOPWATCH]->SetTouchable(true); + scrollView[MAIN_STOPWATCH]->SetDraggable(true); + scrollView[MAIN_STOPWATCH]->SetOnDragListener(presenter_); + /* ----------------------------- stopWatchlabel ----------------------------- */ + stopWatchlabel = new UILabelExt(); + if (stopWatchlabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stopWatchlabel new fail!!"); + return; + } + stopWatchlabel->SetPosition(83, 50, 300, 35); + stopWatchlabel->SetStyle(STYLE_TEXT_FONT, 30); + stopWatchlabel->SetStyle(STYLE_LINE_HEIGHT, 35); + stopWatchlabel->SetTextId(STR_STOPWATCH); // 秒表 + stopWatchlabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + stopWatchlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + stopWatchlabel->SetRollSpeed(23); + stopWatchlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + stopWatchlabel->SetVisible(true); + /* ------------------------------ showTimelabel ----------------------------- */ + showTimelabel = new UILabelExt(); + if (showTimelabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showTimelabel new fail!!"); + return; + } + showTimelabel->SetPosition(0, 160, 466, 94); + showTimelabel->SetStyle(STYLE_TEXT_FONT, 84); + showTimelabel->SetStyle(STYLE_LINE_HEIGHT, 94); + showTimelabel->SetText("00:00.00"); + showTimelabel->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); + showTimelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + showTimelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 84); + /* -------------------------------- LineImage ------------------------------- */ + LineImage = new UIImageView(); + if (LineImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LineImage new fail!!"); + return; + } + LineImage->SetPosition(53, 150); + const char *imageimagesPath = "/user/res/stopwatch/STOPWATCH_LINE.bin"; + LineImage->SetSrc(imageimagesPath); + LineImage->SetVisible(false); + /* ---------------------------- stopWatchAdapter ---------------------------- */ + stopWatchAdapter = new StopWatchAdapter(); + if (stopWatchAdapter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stopWatchAdapter new fail!!"); + return; + } + /* ---------------------------------- list ---------------------------------- */ + list = new UIList(); + if (list == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail!!"); + return; + } + list->SetPosition(56, 170, 360, 130); + list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + list->SetReboundSize(30); + list->SetThrowDrag(true); + list->SetIntercept(true); + list->SetMaxScrollDistance(1000); + list->SetDragACCLevel(5); + list->SetSwipeACCLevel(200); /*设置手指抬起屏幕后的补偿距离。*/ + list->SetVisible(false); + list->RequestFocus(); + list->SetRotateFactor(1.0); + /* ------------------------------- listadapter ------------------------------ */ + listadapter = new TextAdapter(); + if (listadapter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "listadapter new fail!!"); + return; + } + listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 28); + listadapter->SetWidth(356); + listadapter->SetHeight(32); + listadapter->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); + /* -------------------------------- listdata -------------------------------- */ + listdata = new List(); + if (listdata == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "listdata new fail!!"); + return; + } + /* --------------------------- PlayOrPausecheckBox -------------------------- */ + PlayOrPausecheckBox = new UICheckBox(); + if (PlayOrPausecheckBox == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayOrPausecheckBox new fail!!"); + return; + } + PlayOrPausecheckBox->SetPosition(118, 321, 120, 120); + PlayOrPausecheckBox->SetViewId(PlayOrPausecheckBoxVIEWID); + PlayOrPausecheckBox->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + PlayOrPausecheckBox->SetStyle(STYLE_BORDER_RADIUS, 51); + PlayOrPausecheckBox->SetImages(checkBox1selectedImg, checkBox1unSelectedImg); + PlayOrPausecheckBox->SetVisible(true); + /* ---------------------------- ResetOrMarkbutton --------------------------- */ + ResetOrMarkbutton = new UIButton(); + if (ResetOrMarkbutton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ResetOrMarkbutton new fail!!"); + return; + } + ResetOrMarkbutton->SetPosition(256, 333, 100, 100); + ResetOrMarkbutton->SetViewId(ResetOrMarkButton_RESET1_VIEWID); + ResetOrMarkbutton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + ResetOrMarkbutton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + ResetOrMarkbutton->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1); + ResetOrMarkbutton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + ResetOrMarkbutton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + ResetOrMarkbutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + ResetOrMarkbutton->SetVisible(true); + /* -------------------------------------------------------------------------- */ + MainStopWatchPresenter::GetInstance()->SetCheckBoxAndButton(PlayOrPausecheckBox, ResetOrMarkbutton); + MainStopWatchPresenter::GetInstance()->SetLable(stopWatchlabel, showTimelabel); + MainStopWatchPresenter::GetInstance()->SetImage(LineImage); + MainStopWatchPresenter::GetInstance()->SetList(list, listadapter, listdata); + // Add the CallBack about events + PlayOrPausecheckBox->SetOnChangeListener(presenter_); + PlayOrPausecheckBox->SetOnClickListener(presenter_); + ResetOrMarkbutton->SetOnClickListener(presenter_); + } + } + + UILabelExt *MainStopWatchView::GetShowTimelabel(void) + { + return showTimelabel; + } + + UICheckBox *MainStopWatchView::GetPlayOrPausecheckBox(void) + { + return PlayOrPausecheckBox; + } + + /*切换到记录时间到达上线视图*/ + void MainStopWatchView::ChangeRecordTimeToLimitView(void) + { + ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_TIME_TO_LIMIT); + } + + UIScrollView *MainStopWatchView::GetScrollView(int16_t index) + { + return scrollView[index]; + } + + StopWatchAdapter *MainStopWatchView::GetStopWatchAdapter(void) + { + return stopWatchAdapter; + } + + void MainStopWatchView::OnStart() + { + InitMainStopWatchView(); + + scrollView[MAIN_STOPWATCH]->Add(stopWatchlabel); + scrollView[MAIN_STOPWATCH]->Add(showTimelabel); + scrollView[MAIN_STOPWATCH]->Add(LineImage); + scrollView[MAIN_STOPWATCH]->Add(list); + scrollView[MAIN_STOPWATCH]->Add(PlayOrPausecheckBox); + scrollView[MAIN_STOPWATCH]->Add(ResetOrMarkbutton); + group->Add(scrollView[MAIN_STOPWATCH]); + AddViewToRootContainer(group); + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchAdapter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchAdapter.cpp new file mode 100644 index 000000000..352b06c23 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchAdapter.cpp @@ -0,0 +1,83 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-12-12 11:07:26 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-16 11:43:35 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchAdapter.cpp + */ +#include "stopwatch/include/StopWatchAdapter.h" +#include "stopwatch/include/StopWatchItemView.h" +#include "wearable_log.h" +namespace OHOS +{ + StopWatchAdapter::StopWatchAdapter() {} + StopWatchAdapter::~StopWatchAdapter() + { + listData.clear(); + } + uint16_t StopWatchAdapter::GetCount(void) + { + return listData.size(); + } + + void StopWatchAdapter::ClearData(void) + { + listData.clear(); + curSelectItemViewIndex = -1; + } + + void StopWatchAdapter::setSelectedIndex(int index) + { + curSelectItemViewIndex = index; + } + + UIView *StopWatchAdapter::GetView(UIView *inView, int16_t index) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetView:%d", 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++; + } + const StopWatchItem itemData = *it; + StopWatchItemView *item = nullptr; + if (inView == nullptr) + { + item = new StopWatchItemView(); + } + else + { + item = static_cast(inView); + } + item->SetViewIndex(index); + item->SetItemInfo(itemData); + if(curSelectItemViewIndex == itemData.curSelectItemViewIndex) + { + item->SetItemViewColor(true); + } + else + { + item->SetItemViewColor(false); + } + return item; + } + + void StopWatchAdapter::AddListItem(const StopWatchItem &item) + { + listData.push_front(item); + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchItemView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchItemView.cpp new file mode 100644 index 000000000..c632d8c19 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchItemView.cpp @@ -0,0 +1,74 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-12-12 14:40:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-16 11:40:34 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchItemView.cpp + */ +#include "stopwatch/include/StopWatchItemView.h" +#include "wearable_log.h" +namespace OHOS +{ + StopWatchItemView::StopWatchItemView() + { + SetPosition(0, 0, 360, 42); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, 255); + SetUpChild(); + Add(&RecordCycleNumber); + Add(&formattedTime); + Add(&formattedDiff); + } + + StopWatchItemView::~StopWatchItemView() + { + RemoveAll(); + } + + void StopWatchItemView::SetItemInfo(const StopWatchItem itemInfo) + { + RecordCycleNumber.SetText(itemInfo.RecordCycleNumber.c_str()); + formattedTime.SetText(itemInfo.formattedTime.c_str()); + formattedDiff.SetText(itemInfo.formattedDiff.c_str()); + } + + void StopWatchItemView::SetUpChild() + { + RecordCycleNumber.SetPosition(0, 0, 80, 32); + RecordCycleNumber.SetStyle(STYLE_TEXT_FONT, 28); + RecordCycleNumber.SetStyle(STYLE_LINE_HEIGHT, 32); + RecordCycleNumber.SetLineBreakMode(UILabel::LINE_BREAK_CLIP); + RecordCycleNumber.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + RecordCycleNumber.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + + formattedTime.SetPosition(80, 0, 120, 32); + formattedTime.SetStyle(STYLE_TEXT_FONT, 28); + formattedTime.SetStyle(STYLE_LINE_HEIGHT, 32); + formattedTime.SetLineBreakMode(UILabel::LINE_BREAK_CLIP); + formattedTime.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + formattedTime.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + + formattedDiff.SetPosition(230, 0, 130, 32); + formattedDiff.SetStyle(STYLE_TEXT_FONT, 28); + formattedDiff.SetStyle(STYLE_LINE_HEIGHT, 32); + formattedDiff.SetLineBreakMode(UILabel::LINE_BREAK_CLIP); + formattedDiff.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + formattedDiff.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + } + + void StopWatchItemView::SetItemViewColor(bool flag) + { + if (flag) + { + RecordCycleNumber.SetTextColor(Color::GetColorFromRGBA(0xff, 0x8a, 0x36, 0xff)); + formattedTime.SetTextColor(Color::GetColorFromRGBA(0xff, 0x8a, 0x36, 0xff)); + formattedDiff.SetTextColor(Color::GetColorFromRGBA(0xff, 0x8a, 0x36, 0xff)); + } + else + { + RecordCycleNumber.SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff)); + formattedTime.SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff)); + formattedDiff.SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff)); + } + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchModel.cpp new file mode 100644 index 000000000..ff9d68503 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchModel.cpp @@ -0,0 +1,210 @@ +#include "stopwatch/include/StopWatchModel.h" +#include "cmsis_os.h" +#include +#include +#include "custom_utils.h" +#include "wearable_log.h" +#include +#include "stopwatch/include/MainStopWatchView.h" +namespace OHOS +{ + + std::shared_ptr StopWatchModel::GetInstance() // shared_ptr:当没有引用指向这个实例时会自动释放内存 + { + static std::shared_ptr instance(new StopWatchModel()); + return instance; + } + + /* ----------------------------------- 定时器 ---------------------------------- */ + // 声明定时器变量 + static osTimerId_t g_timer = nullptr; + static uint32_t g_StopWatchTimes = {0}; + static constexpr int32 NUM_TEN = 10; // 主要用于格式化输出,当小时、分钟或秒小于10时,在其前面添加一个’0’以保持常规时间格式 + static constexpr int16 ERROR = 0; + static constexpr int16 SUCCESS = 1; + static constexpr int16 NUM_TIME_MIN = 60; + static constexpr int16 NUM_TIME_HOUR = 3600; + static constexpr int32 NUM_TIME_DAY = 86400; + static constexpr uint32_t MAX_STOPWATCH_TIME = (99 * 60 * 1000) + (59 * 1000) + 990; // 99分59秒990毫秒 + static uint64_t g_timerStartTimestamp = 0; // 添加一个全局变量来存储定时器开始的时间戳 + /* + * @brief 显示倒计时(分钟、秒、毫秒),毫秒显示为两位数 + */ + std::string StopWatchModel::DisplayStopWatchDuration() + { + stopwatchDuration.erase(); + std::string minute; + std::string seconds; + std::string milliseconds; + + // 假设 g_StopWatchTimes 是毫秒数 + int min = g_StopWatchTimes / (60 * 1000); // 60,000 毫秒 = 1 分钟 + int sec = (g_StopWatchTimes % (60 * 1000)) / 1000; // 1,000 毫秒 = 1 秒 + int msec = (g_StopWatchTimes % 1000) / 10; // 获得两位数的毫秒,最大值为99 + + if (min < 10) + { + minute = "0" + std::to_string(min); + } + else + { + minute = std::to_string(min); + } + + if (sec < 10) + { + seconds = "0" + std::to_string(sec); + } + else + { + seconds = std::to_string(sec); + } + + // 格式化毫秒为两位数 + if (msec < 10) + { + milliseconds = "0" + std::to_string(msec); + } + else + { + milliseconds = std::to_string(msec); + } + + // 拼接分钟、秒和毫秒 + stopwatchDuration = minute + ":" + seconds + "." + milliseconds; + + return stopwatchDuration.c_str(); + } + + // 检查是否达到最大记录时间 + bool StopWatchModel::isReachMaxRecordTime(void) + { + if (g_StopWatchTimes >= MAX_STOPWATCH_TIME) + { + return true; + } + return false; + } + + static void StopWatch_TimerCallbackProc(int data) + { + if (MainStopWatchView::GetInstance() == nullptr) + { + return; + } + MainStopWatchView::GetInstance()->GetPlayOrPausecheckBox()->SetState(UICheckBox::UNSELECTED); + MainStopWatchView::GetInstance()->ChangeRecordTimeToLimitView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "已到达记录最高时间:%d",g_StopWatchTimes); + g_StopWatchTimes = MAX_STOPWATCH_TIME; + MainStopWatchView::GetInstance()->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration().c_str()); + uapi_set_screen_on_api(); + } + + /* + * @brief 倒计时回调函数 + */ + static void StopWatch_TimerCallback(int data) + { + g_StopWatchTimes += 10; // 每次回调增加10毫秒 + if(StopWatchModel::GetInstance()->isReachMaxRecordTime()) //达到最大时间 + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data)); + } + } + + /* + * @brief 开启定时器函数 + * @param interval 时间间隔,单位ms + */ + void StopWatchModel::StopWatch_StartTimer(uint32_t interval) + { + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_timer != nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopWatchModel::StopWatch_StartTimer Timer already exists!!"); + return; + } + + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_timer = osTimerNew((osTimerFunc_t)StopWatch_TimerCallback, osTimerPeriodic, nullptr, nullptr); + // 检查定时器创建是否成功 + if (g_timer == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopWatchModel::StopWatch_StartTimer Timer create failed!!"); + return; + } + + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + + /* --------------------------------- 4.启动定时器 -------------------------------- */ + // g_timerStartTimestamp = GetCurrentTimestamp(); // 假设GetCurrentTimestamp()是获取当前时间戳的函数 + osStatus_t ret = osTimerStart(g_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[StopWatch_StartTimer]osTimerDelete failed, ret = %lx!!", ret); + if (g_timer != nullptr) + { + ret = osTimerDelete(g_timer); + } + g_timer = nullptr; + return; + } + return; + } + + /* + * @brief 停止定时器 + */ + void StopWatchModel::StopWatch_StopTimer(void) + { + // 检查定时器是否存在 + if (g_timer != nullptr) + { + osTimerStop(g_timer); + // 删除定时器并置为 nullptr + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = nullptr; + g_StopWatchTimes = 0; + } + } + /* + * @brief 暂停定时器 + */ + void StopWatchModel::StopWatch_PauseTimer(void) + { + // 检查定时器是否存在 + if (g_timer != nullptr) + { + // 暂停定时器,但不删除它 + osStatus_t ret = osTimerStop(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopWatch_PauseTimer osTimerStop failed, ret = %lx!!", ret); + } + } + } + + /* + * @brief 恢复定时器 + */ + void StopWatchModel::StopWatch_ResumeTimer(uint32_t interval) + { + // 检查定时器是否存在 + if (g_timer != nullptr) + { + int tick = osMs2Tick(interval); + // 恢复定时器 + osStatus_t ret = osTimerStart(g_timer, tick); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopWatch_ResumeTimer osTimerStart failed, ret = %lx!!", ret); + } + } + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp new file mode 100644 index 000000000..a6bf75f58 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp @@ -0,0 +1,156 @@ +#include "stopwatch/include/StopWatchRecordCycleToLimitView.h" +#include "stopwatch/include/MainStopWatchPresenter.h" +#include "UiConfig.h" +#include "wearable_log.h" +/*弹窗视图:到达最高圈数99时弹出*/ +namespace OHOS +{ + + static StopWatchRecordCycleToLimitView *g_pStopWatchRecordCycleToLimitView{nullptr}; + + StopWatchRecordCycleToLimitView::StopWatchRecordCycleToLimitView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopWatchRecordCycleToLimitView::StopWatchRecordCycleToLimitView"); + g_pStopWatchRecordCycleToLimitView = this; + } + + StopWatchRecordCycleToLimitView::~StopWatchRecordCycleToLimitView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopWatchRecordCycleToLimitView::~StopWatchRecordCycleToLimitView"); + ClearAll(); + g_pStopWatchRecordCycleToLimitView = nullptr; + } + + StopWatchRecordCycleToLimitView *StopWatchRecordCycleToLimitView::GetInstance() + { + return g_pStopWatchRecordCycleToLimitView; + } + // 初始化秒表到达最高圈数时弹出的视图 + UIScrollView *StopWatchRecordCycleToLimitView::InitStopWatchRecordCycleToLimitView() + { + if (scrollView == nullptr) + { + scrollView = new UIScrollView(); + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView->SetTouchable(true); + scrollView->SetDraggable(true); + UIView::OnDragListener *draglistener = static_cast(MainStopWatchPresenter::GetInstance()); + if (draglistener == nullptr) + { + return nullptr; + } + scrollView->SetOnDragListener(draglistener); + /* -------------------------------------------------------------------------- */ + if (Title == nullptr) + { + Title = new UILabelExt(); + if (Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Title new fail"); + return nullptr; + } + } + Title->SetPosition(83, 50, 300, 35); + Title->SetStyle(STYLE_TEXT_FONT, 30); + Title->SetStyle(STYLE_LINE_HEIGHT, 35); + Title->SetTextId(STR_STOPWATCH); // 秒表 + Title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Title->SetRollSpeed(23); + Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + if (AttentionImage == nullptr) + { + AttentionImage = new UIImageView(); + if (AttentionImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AttentionImage new fail"); + return nullptr; + } + } + AttentionImage->SetPosition(193, 121, 100, 100); + AttentionImage->SetStyle(STYLE_BORDER_RADIUS, 100); + AttentionImage->SetSrc(PNG_ATTENTION_IMAGE); + /* -------------------------------------------------------------------------- */ + if (AttentionLabel == nullptr) + { + AttentionLabel = new UILabelExt(); + if (AttentionLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AttentionLabel new fail"); + return nullptr; + } + } + AttentionLabel->SetPosition(83, 253, 300, 35); + AttentionLabel->SetStyle(STYLE_TEXT_FONT, 30); + AttentionLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + AttentionLabel->SetTextId(STR_TMCHBR); // 当前已达到了最高计数 + AttentionLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + AttentionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AttentionLabel->SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff)); + AttentionLabel->SetRollSpeed(23); + AttentionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + if (button == nullptr) + { + button = new UILabelButtonExt(); + if (button == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "button new fail"); + return nullptr; + } + } + button->SetPosition(0, 366, 466, 100); + button->SetViewId(CycleToLimitReturnButton_VIEWID); + button->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE); + button->SetTextId(STR_KONW); + button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + button->SetStyle(STYLE_LINE_HEIGHT, 35); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + UIView::OnClickListener *buttonClick = static_cast(MainStopWatchPresenter::GetInstance()); + if (buttonClick == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "buttonClick new fail"); + return nullptr; + } + button->SetOnClickListener(buttonClick); + /* ----------------------------------- Add ---------------------------------- */ + scrollView->Add(Title); + scrollView->Add(AttentionImage); + scrollView->Add(AttentionLabel); + scrollView->Add(button); + } + return scrollView; + } + + void StopWatchRecordCycleToLimitView::ClearAll() + { + if (scrollView != nullptr) + { + scrollView->RemoveAll(); + if (Title != nullptr) + { + delete Title; + Title = nullptr; + } + if (AttentionImage != nullptr) + { + delete AttentionImage; + AttentionImage = nullptr; + } + if (AttentionLabel != nullptr) + { + delete AttentionLabel; + AttentionLabel = nullptr; + } + if (button != nullptr) + { + delete button; + button = nullptr; + } + delete scrollView; + scrollView = nullptr; + } + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp new file mode 100644 index 000000000..403064dfd --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp @@ -0,0 +1,178 @@ +#include "stopwatch/include/StopWatchRecordTimeToLimitView.h" +#include "stopwatch/include/MainStopWatchPresenter.h" +#include "UiConfig.h" +#include "wearable_log.h" +/*弹窗视图:到达最高时间99:59.99时弹出*/ +namespace OHOS +{ + + static StopWatchRecordTimeToLimitView *g_pStopWatchRecordTimeToLimitView{nullptr}; + + StopWatchRecordTimeToLimitView::StopWatchRecordTimeToLimitView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopWatchRecordTimeToLimitView::StopWatchRecordTimeToLimitView"); + g_pStopWatchRecordTimeToLimitView = this; + } + + StopWatchRecordTimeToLimitView::~StopWatchRecordTimeToLimitView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopWatchRecordTimeToLimitView::~StopWatchRecordTimeToLimitView"); + ClearAll(); + g_pStopWatchRecordTimeToLimitView = nullptr; + } + + StopWatchRecordTimeToLimitView *StopWatchRecordTimeToLimitView::GetInstance() + { + + return g_pStopWatchRecordTimeToLimitView; + } + + UIScrollView *StopWatchRecordTimeToLimitView::InitStopWatchRecordTimeToLimitView() + { + if (scrollView == nullptr) + { + scrollView = new UIScrollView(); + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView->SetTouchable(true); + scrollView->SetDraggable(true); + UIView::OnDragListener *draglistener = static_cast(MainStopWatchPresenter::GetInstance()); + if (draglistener == nullptr) + { + return nullptr; + } + scrollView->SetOnDragListener(draglistener); + /* -------------------------------------------------------------------------- */ + if (Title == nullptr) + { + Title = new UILabelExt(); + if (Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Title new fail"); + return nullptr; + } + } + Title->SetPosition(83, 50, 300, 35); + Title->SetStyle(STYLE_TEXT_FONT, 30); + Title->SetStyle(STYLE_LINE_HEIGHT, 35); + Title->SetTextId(STR_STOPWATCH); // 秒表 + Title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Title->SetRollSpeed(23); + Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + if (AttentionImage == nullptr) + { + AttentionImage = new UIImageView(); + if (AttentionImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AttentionImage new fail"); + return nullptr; + } + } + AttentionImage->SetPosition(193, 121, 100, 100); + AttentionImage->SetStyle(STYLE_BORDER_RADIUS, 100); + AttentionImage->SetSrc(PNG_ATTENTION_IMAGE); + /* ---------------------------- AttentionLabel_1 ---------------------------- */ + if (AttentionLabel_1 == nullptr) + { + AttentionLabel_1 = new UILabelExt(); + if (AttentionLabel_1 == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AttentionLabel_1 new fail"); + return nullptr; + } + } + AttentionLabel_1->SetPosition(83, 235, 300, 35); + AttentionLabel_1->SetStyle(STYLE_TEXT_FONT, 30); + AttentionLabel_1->SetStyle(STYLE_LINE_HEIGHT, 35); + AttentionLabel_1->SetTextId(STR_MAXIMUM_TIME_REACH_NOTE); // 当前已达到了最长时间 + AttentionLabel_1->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + AttentionLabel_1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AttentionLabel_1->SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff)); + AttentionLabel_1->SetRollSpeed(23); + AttentionLabel_1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ---------------------------- AttentionLabel_2 ---------------------------- */ + if (AttentionLabel_2 == nullptr) + { + AttentionLabel_2 = new UILabelExt(); + if (AttentionLabel_2 == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AttentionLabel_2 new fail"); + return nullptr; + } + } + AttentionLabel_2->SetPosition(53, 279, 360, 35); + AttentionLabel_2->SetStyle(STYLE_TEXT_FONT, 30); + AttentionLabel_2->SetStyle(STYLE_LINE_HEIGHT, 35); + AttentionLabel_2->SetTextId(STR_STOPWATCH_STOP_NOTE); // 秒表自动暂停,请重新开始 + AttentionLabel_2->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + AttentionLabel_2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AttentionLabel_2->SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff)); + AttentionLabel_2->SetRollSpeed(23); + AttentionLabel_2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + if (button == nullptr) + { + button = new UILabelButtonExt(); + if (button == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "button new fail"); + return nullptr; + } + } + button->SetPosition(0, 366, 466, 100); + button->SetViewId(TimeToLimitReturnButton_VIEWID); + button->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE); + button->SetTextId(STR_KONW); + button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + button->SetStyle(STYLE_LINE_HEIGHT, 35); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + UIView::OnClickListener *buttonClick = static_cast(MainStopWatchPresenter::GetInstance()); + if (buttonClick == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "buttonClick new fail"); + return nullptr; + } + button->SetOnClickListener(buttonClick); + /* ----------------------------------- Add ---------------------------------- */ + scrollView->Add(Title); + scrollView->Add(AttentionImage); + scrollView->Add(AttentionLabel_1); + scrollView->Add(AttentionLabel_2); + scrollView->Add(button); + } + return scrollView; + } + + void StopWatchRecordTimeToLimitView::ClearAll() + { + if (scrollView != nullptr) + { + scrollView->RemoveAll(); + if (Title != nullptr) + { + delete Title; + Title = nullptr; + } + if (AttentionImage != nullptr) + { + delete AttentionImage; + AttentionImage = nullptr; + } + if (AttentionLabel_1 != nullptr) + { + delete AttentionLabel_1; + AttentionLabel_1 = nullptr; + } + if (button != nullptr) + { + delete button; + button = nullptr; + } + + delete scrollView; + scrollView = nullptr; + } + } +} \ No newline at end of file -- 2.17.1