秒表slice合并提交 1711/2 1711/head
authorluozheng <1732036298@qq.com>
Wed, 26 Mar 2025 07:50:52 +0000 (15:50 +0800)
committerluozheng <1732036298@qq.com>
Wed, 26 Mar 2025 07:50:52 +0000 (15:50 +0800)
14 files changed:
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchAdapter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchItemView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchModel.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchAdapter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchItemView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchModel.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp [new file with mode: 0644]

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