1.实现秒表功能,制定计时时间如"99:59.99"不知道如何实现
authorluozheng <1732036298@qq.com>
Sun, 7 Apr 2024 09:24:37 +0000 (17:24 +0800)
committerluozheng <1732036298@qq.com>
Sun, 7 Apr 2024 09:24:37 +0000 (17:24 +0800)
2.在UiConfig.h更新了两张通用图片,将之前遗留的重复图片删除

19 files changed:
code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h
code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp
code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/FastTrainingAttentionView.cpp
code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h
code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h
code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h
code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h
code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h
code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp
code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp
code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp
code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp
code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp
code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Attention.bin [moved from code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/FastTrainingAttentionVector.bin with 100% similarity]
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/OrangeAttentionVector.bin [deleted file]
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/countdown/COUNTDOWN_ATTENTION.bin [deleted file]
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/countdown/COUNTDOWN_BUTTON.bin [deleted file]

index 757e573..61bea2d 100644 (file)
@@ -265,8 +265,9 @@ namespace OHOS
     static constexpr const char *PNG_SYSTEM_CHECK_OFF_IMAGE = APP_RES_PATH "/SYSTEM_CheckOff.bin";             // 叉
     static constexpr const char *PNG_TOGGLEBUTTON_OFF_IMAGE = APP_RES_PATH "/TOGGLEBUTTON_OFF.bin";            // togglebuttton未选中图片
     static constexpr const char *PNG_TOGGLEBUTTON_ON_IMAGE = APP_RES_PATH "/TOGGLEBUTTON_ON.bin";              // togglebuttton选中图片
+    static constexpr const char *PNG_ATTENTION_IMAGE = APP_RES_PATH "/Attention.bin";                          // 注意
+    static constexpr const char *PNG_466x100BUTTON_IMAGE = APP_RES_PATH "/466x100button.bin";                  // 466x100button图片
 
-    static constexpr const char *PNG_ORANGE_ATTENTION_VECTOR_IMAGE = APP_RES_PATH "/OrangeAttentionVector.bin"; // 橘黄色感叹号图标
     /* -------------------------------- 已删除的不必要图片 ------------------------------- */
     static constexpr const char *PNG_APPLIST_UI_SAMPLE_IMAGE = APP_RES_PATH "/APPLIST_UI_SAMPLE.bin"; // Applist图标
     static constexpr const char *PNG_APPLIST_TEMP_IMAGE = APP_RES_PATH "/TEMP_IMAGE.bin";
index 5278431..b984081 100644 (file)
@@ -2,13 +2,14 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 10:47:46
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-27 19:39:53
+ * @LastEditTime: 2024-04-07 16:57:52
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp
  */
 #include "findphone/include/FindPhoneView.h"
 #include "findphone/include/FindPhonePresenter.h"
 #include "wearable_log.h"
 #include "findphone/include/FindPhoneModel.h"
+#include "UiConfig.h"
 namespace OHOS
 {
 
@@ -142,8 +143,7 @@ namespace OHOS
                 return;
             }
             FindPhoneImageView->SetPosition(193, 140, 80, 80);
-            const char *imagesPath = "/user/res/FastTrainingAttentionVector.bin";
-            FindPhoneImageView->SetSrc(imagesPath);
+            FindPhoneImageView->SetSrc(PNG_ATTENTION_IMAGE);
             /* ----------------------------- FindPhoneLabel ----------------------------- */
             FindPhoneLabel = new UILabelExt();
             if (FindPhoneLabel == nullptr)
index 35d0b96..7ef2532 100644 (file)
@@ -77,7 +77,7 @@ namespace OHOS
         }\r
         image7_->SetPosition(193, 121);\r
         image7_->Resize(80, 80);\r
-        image7_->SetSrc(PNG_ORANGE_ATTENTION_VECTOR_IMAGE);\r
+        image7_->SetSrc(PNG_ATTENTION_IMAGE);\r
 \r
         // Add to scrollView1\r
         scrollView1_->Add(image7_);\r
index ccb4d9e..253b6a2 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-04-04 15:13:51\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-04 16:05:17\r
+ * @LastEditTime: 2024-04-07 17:22:21\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h\r
  */\r
 #ifndef MAIN_STOPWATCH_PRESENTER_H\r
@@ -15,6 +15,9 @@
 /*秒表主视图*/\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
@@ -42,6 +45,7 @@ namespace OHOS
         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
@@ -57,8 +61,8 @@ namespace OHOS
         UIList *m_list = nullptr;\r
         TextAdapter *m_listadapter = nullptr;\r
         List<const char *> *m_listdata = nullptr;\r
-        int RecordCycleNumber{0};              // 用来记录点击计时按钮("Mark")的次数\r
-        std::string RecordMaxTime{"99:59.59"}; // 计时时间最高为99:59.59\r
+        uint64_t lastRecordTime = 0; // 上次记录时间\r
+        int RecordCycleNumber{0};    // 用来记录计时圈数\r
     };\r
 } // namespace OHOS\r
 \r
index 3af8a0e..e65e9b7 100644 (file)
@@ -1,3 +1,10 @@
+/*\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 10:04:54\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
@@ -5,7 +12,7 @@
 #include "View.h"\r
 #include "components/ui_view_group.h"\r
 #include "components/ui_scroll_view.h"\r
-#include "components/ui_label.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
@@ -46,31 +53,26 @@ namespace OHOS
         bool ChangeMainStopWatch(int16_t thisView);\r
         bool ChangeStopWatchRecordCycleLimit(int16_t thisView);\r
         bool ChangeMainStopWatchRecordTimeLimit(int16_t thisView);\r
-\r
+        UILabelExt *GetShowTimelabel(void);\r
     private:\r
         void InitMainStopWatchView(void);\r
-        void DeInitView(void);\r
-        void PreLoad(void);\r
+        void ClearAll(void);\r
 \r
     private:\r
         StopWatchRecordCycleToLimitView *p_StopWatchRecordCycleToLimitView{nullptr}; // 圈数到达上限后弹出该视图\r
         StopWatchRecordTimeToLimitView *p_StopWatchRecordTimeToLimitView{nullptr};   // 计时时间到达上限后弹出该视图\r
 \r
     private:\r
-        UIViewGroup *container_ = nullptr;\r
+        UIViewGroup *group = nullptr;\r
         UIScrollView *scrollView[3] = {nullptr};\r
-        UILabel *stopWatchlabel = nullptr;         // 内容为“秒表”的标签\r
-        UILabel *showTimelabel = 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
-        UIView::OnDragListener *draglistener{nullptr};\r
-        UICheckBox::OnChangeListener *PlayOrPausecheckBoxChangeListener{nullptr};\r
-        UIView::OnClickListener *ResetOrMarkbuttonClick{nullptr};\r
-        bool viewInitStatus{false};\r
     };\r
 } // namespace OHOS\r
 #endif
\ No newline at end of file
index 66baa6d..2eb3ba2 100644 (file)
@@ -1,3 +1,10 @@
+/*\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 10:35:43\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
 \r
 namespace OHOS\r
 {\r
+    \r
     class StopWatchModel\r
     {\r
     public:\r
         static std::shared_ptr<StopWatchModel> GetInstance(); // shared_ptr:当没有引用指向这个实例时会自动释放内存\r
         ~StopWatchModel() {}\r
-        char *DisplayMotionDuration();\r
+        char *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
+        \r
 \r
     private:\r
         // 将构造函数、拷贝构造函数和赋值操作符私有化\r
@@ -21,9 +34,7 @@ namespace OHOS
         StopWatchModel &operator=(const StopWatchModel &) = delete;\r
 \r
     private:\r
-        static int oneDaySec;    // 一天的秒数\r
-        static int oneHourSec;   // 一个小时的秒数\r
-        static int oneMinuteSec; // 一分钟秒数\r
+        std::string stopwatchDuration;\r
     };\r
 \r
 }\r
index 390fa0c..1ccd6aa 100644 (file)
@@ -1,3 +1,10 @@
+/*\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
@@ -5,9 +12,9 @@
 #include "View.h"\r
 #include "components/ui_view_group.h"\r
 #include "components/ui_scroll_view.h"\r
-#include "components/ui_label.h"\r
+#include "components/ui_label_ext.h"\r
 #include "components/ui_image_view.h"\r
-#include "components/ui_button.h"\r
+#include "components/ui_label_button_ext.h"\r
 /*弹窗视图:到达最高圈数99时弹出*/\r
 namespace OHOS\r
 {\r
@@ -16,19 +23,17 @@ namespace OHOS
 \r
     public:\r
         StopWatchRecordCycleToLimitView();\r
-        void DeInitView(void);\r
+        void ClearAll(void);\r
         virtual ~StopWatchRecordCycleToLimitView();\r
         static StopWatchRecordCycleToLimitView *GetInstance(void);\r
         UIScrollView *InitStopWatchRecordCycleToLimitView(void);\r
 \r
     private:\r
-        UIViewGroup *container_ = nullptr;\r
-        UIScrollView *scrollView1_ = nullptr;\r
-        UILabel *label1_ = nullptr;\r
-        UIImageView *image1_ = nullptr;\r
-        UILabel *label3_ = nullptr;\r
-        UIButton *button1_ = nullptr;\r
-        bool viewInitStatus{false};\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
index 22495f2..98c3ecc 100644 (file)
@@ -1,3 +1,10 @@
+/*\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
@@ -5,9 +12,9 @@
 #include "View.h"\r
 #include "components/ui_view_group.h"\r
 #include "components/ui_scroll_view.h"\r
-#include "components/ui_label.h"\r
+#include "components/ui_label_ext.h"\r
 #include "components/ui_image_view.h"\r
-#include "components/ui_button.h"\r
+#include "components/ui_label_button_ext.h"\r
 /*弹窗视图:到达最高时间99:59.99时弹出*/\r
 namespace OHOS\r
 {\r
@@ -18,15 +25,15 @@ namespace OHOS
         virtual ~StopWatchRecordTimeToLimitView();\r
         static StopWatchRecordTimeToLimitView *GetInstance(void);\r
         UIScrollView *InitStopWatchRecordTimeToLimitView(void);\r
-        void DeInitView(void);\r
+        void ClearAll(void);\r
 \r
     private:\r
-        UIScrollView *scrollView1_ = nullptr;\r
-        UILabel *label1_ = nullptr;\r
-        UIImageView *image1_ = nullptr;\r
-        UILabel *label3_ = nullptr;\r
-        UIButton *button1_ = nullptr;\r
-        bool viewInitStatus{false};\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
index 4c5e742..8b4c1c6 100644 (file)
@@ -1,6 +1,7 @@
 #include "AppViewIDs.h"\r
 #include "NativeAbility.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
@@ -18,7 +19,7 @@ namespace OHOS
 \r
     MainStopWatchPresenter::~MainStopWatchPresenter()\r
     {\r
-\r
+        StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 退出删除并清理定时器资源\r
         g_pMainStopWatchPresenter = nullptr;\r
     }\r
 \r
@@ -30,8 +31,8 @@ namespace OHOS
 \r
     void MainStopWatchPresenter::OnStart()\r
     {\r
-\r
         Presenter<MainStopWatchView>::OnStart();\r
+        ScreenAlwaysOnCtr(1); // 长亮屏\r
     }\r
 \r
     void MainStopWatchPresenter::OnPause(void)\r
@@ -48,8 +49,8 @@ namespace OHOS
 \r
     void MainStopWatchPresenter::OnStop(void)\r
     {\r
-\r
         Presenter<MainStopWatchView>::OnStop();\r
+        ScreenAlwaysOnCtr(0); // 取消长亮屏\r
     }\r
 \r
     /// @brief 设置复选框和按钮\r
@@ -108,6 +109,45 @@ namespace OHOS
         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
@@ -115,39 +155,67 @@ namespace OHOS
         const char *clickedViewId = view.GetViewId();\r
         if (strcmp(clickedViewId, ResetOrMarkButton_MARK_VIEWID) == 0)\r
         {\r
-            RecordCycleNumber += 1;\r
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordCycleNumber:%d\n",RecordCycleNumber);\r
-            if (RecordCycleNumber >= 99)\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
-                mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false);\r
-                SetShowTimeLableStyle(m_showTimelabel, 93, 60, 65, 78);\r
-                mainStopWatchView->SetViewIsVisible(m_list, true);\r
-                mainStopWatchView->SetViewIsVisible(m_image, true);\r
+                RecordCycleNumber += 1;\r
             }\r
+            mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false);\r
+            SetShowTimeLableStyle(m_showTimelabel, 93, 60, 65, 78);\r
+            mainStopWatchView->SetViewIsVisible(m_list, true);\r
+            mainStopWatchView->SetViewIsVisible(m_image, true);\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
-            sprintf(PickerData, "0%d    %s    %s", RecordCycleNumber, "00:08:09", "+00:08:09");\r
-            m_listdata->PushFront(static_cast<char *>(PickerData));\r
+            if (lastRecordTime == 0) // 如果是第一次标记\r
+            {\r
+                sprintf(PickerData, "0%d    %s    +%s", RecordCycleNumber, formattedTime, formattedTime);\r
+            }\r
+            else\r
+            {\r
+                sprintf(PickerData, "0%d    %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
             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
+\r
             m_button->SetViewId(ResetOrMarkButton_RESET1_VIEWID);\r
             m_button->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1);\r
             m_button->Invalidate();\r
 \r
             mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, true);\r
-            SetShowTimeLableStyle(m_showTimelabel, 63, 160, 80, 94);\r
+            SetShowTimeLableStyle(m_showTimelabel, 68, 160, 84, 94);\r
             mainStopWatchView->SetViewIsVisible(m_image, false);\r
+            mainStopWatchView->SetViewIsVisible(m_list, false);\r
+\r
             if (m_listdata != nullptr)\r
             {\r
                 for (int i = 0; i < m_listdata->Size(); i++)\r
@@ -157,8 +225,11 @@ namespace OHOS
                 }\r
                 m_listdata->Clear();\r
             }\r
-            mainStopWatchView->SetViewIsVisible(m_list, false);\r
-            m_list->Invalidate();\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
@@ -174,14 +245,19 @@ namespace OHOS
 \r
     bool MainStopWatchPresenter::OnChange(UICheckBox::UICheckBoxState state)\r
     {\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnChange");\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, nullptr);\r
+            m_button->SetImageSrc(ResetOrMarkButtonImg_Mark, ResetOrMarkButtonImg_Mark);\r
             m_button->Invalidate(); // 图片重新赋值要刷新该区域\r
         }\r
         else\r
         {\r
+            StopWatchModel::GetInstance()->StopWatch_PauseTimer(); // 暂停定时器\r
             m_button->SetViewId(ResetOrMarkButton_RESET2_VIEWID);\r
             m_button->SetImageSrc(ResetOrMarkButtonImg_Reset2, nullptr);\r
             m_button->Invalidate();\r
@@ -192,7 +268,7 @@ namespace OHOS
     // 增加按键事件\r
     bool MainStopWatchPresenter::OnKeyAct(UIView &view, const KeyEvent &event)\r
     {\r
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnKeyAct");\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnKeyAct");\r
         uint16_t keyID = event.GetKeyId();\r
         uint16_t keyState = event.GetState();\r
         // 如果是power键就返回上一级\r
index 6c31fdc..abfe108 100644 (file)
@@ -3,6 +3,7 @@
 #include "UiConfig.h"\r
 #include "NativeAbility.h"\r
 #include "AppViewIDs.h"\r
+#include "wearable_log.h"\r
 /*秒表主视图*/\r
 namespace OHOS\r
 {\r
@@ -11,25 +12,101 @@ namespace OHOS
 \r
     MainStopWatchView::MainStopWatchView()\r
     {\r
-\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::MainStopWatchView");\r
         g_pMainStopWatchView = this;\r
     }\r
 \r
     MainStopWatchView::~MainStopWatchView()\r
     {\r
-        if (viewInitStatus == true)\r
-        {\r
-            DeInitView();\r
-        }\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::~MainStopWatchView");\r
+        ClearAll();\r
         g_pMainStopWatchView = nullptr;\r
     }\r
 \r
     MainStopWatchView *MainStopWatchView::GetInstance()\r
     {\r
-\r
         return g_pMainStopWatchView;\r
     }\r
 \r
+    void MainStopWatchView::ClearAll()\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 (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
+        if (group != nullptr)\r
+        {\r
+            delete group;\r
+            group = nullptr;\r
+        }\r
+    }\r
+\r
     /// @brief 设置视图是否可见\r
     /// @param view 具体视图\r
     /// @param status true 可见 false 不可见\r
@@ -46,19 +123,23 @@ namespace OHOS
         view->Invalidate();\r
     }\r
 \r
-    // 切换到秒表主视图\r
+    // 1.切换到秒表主视图\r
     bool MainStopWatchView::ChangeMainStopWatch(int16_t thisView)\r
     {\r
-        container_->Add(scrollView[thisView]);\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
-    // 切换到秒表到达最高圈数视图\r
+    // 2.切换到秒表到达最高圈数视图\r
     bool MainStopWatchView::ChangeStopWatchRecordCycleLimit(int16_t thisView)\r
     {\r
         if (scrollView[thisView] == nullptr)\r
         {\r
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainAlarmView::StopWatchRecordCycleToLimitView");\r
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::StopWatchRecordCycleToLimitView");\r
             p_StopWatchRecordCycleToLimitView = new StopWatchRecordCycleToLimitView();\r
             if (p_StopWatchRecordCycleToLimitView == nullptr)\r
             {\r
@@ -66,17 +147,17 @@ namespace OHOS
                 return false;\r
             }\r
             scrollView[thisView] = p_StopWatchRecordCycleToLimitView->InitStopWatchRecordCycleToLimitView();\r
-            container_->Add(scrollView[thisView]);\r
+            group->Add(scrollView[thisView]);\r
         }\r
         return true;\r
     }\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, "MainAlarmView::ChangeMainStopWatchRecordTimeLimit");\r
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::ChangeMainStopWatchRecordTimeLimit");\r
             p_StopWatchRecordTimeToLimitView = new StopWatchRecordTimeToLimitView();\r
             if (p_StopWatchRecordTimeToLimitView == nullptr)\r
             {\r
@@ -84,7 +165,7 @@ namespace OHOS
                 return false;\r
             }\r
             scrollView[thisView] = p_StopWatchRecordTimeToLimitView->InitStopWatchRecordTimeToLimitView();\r
-            container_->Add(scrollView[thisView]);\r
+            group->Add(scrollView[thisView]);\r
         }\r
         return true;\r
     }\r
@@ -97,11 +178,11 @@ namespace OHOS
     };\r
 \r
     // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与MainStopWatchView类中的特定成员函数指针进行了绑定。\r
-    static const MainStopWatchViewMapper ViewMapper[] =\r
-        {\r
-            {MAIN_STOPWATCH, &MainStopWatchView::ChangeMainStopWatch},\r
-            {STOPWATCH_RECORD_CYCLE_TO_LIMIT, &MainStopWatchView::ChangeStopWatchRecordCycleLimit},\r
-            {STOPWATCH_RECORD_TIME_TO_LIMIT, &MainStopWatchView::ChangeMainStopWatchRecordTimeLimit}};\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
@@ -139,231 +220,165 @@ namespace OHOS
     // 初始化秒表主视图\r
     void MainStopWatchView::InitMainStopWatchView()\r
     {\r
-        if (scrollView[MAIN_STOPWATCH] == nullptr)\r
-        {\r
-            scrollView[MAIN_STOPWATCH] = new UIScrollView();\r
-        }\r
-        scrollView[MAIN_STOPWATCH]->SetPosition(0, 0);\r
-        scrollView[MAIN_STOPWATCH]->Resize(466, 466);\r
-        scrollView[MAIN_STOPWATCH]->SetViewId("scrollView1");\r
-        scrollView[MAIN_STOPWATCH]->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
-        container_->Add(scrollView[MAIN_STOPWATCH]);\r
-        scrollView[MAIN_STOPWATCH]->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        if (stopWatchlabel == nullptr)\r
-        {\r
-            stopWatchlabel = new UILabel();\r
-        }\r
-        stopWatchlabel->SetPosition(203, 52);\r
-        stopWatchlabel->Resize(60, 35);\r
-        stopWatchlabel->SetViewId("label1");\r
-        stopWatchlabel->SetStyle(STYLE_TEXT_FONT, 30);\r
-        stopWatchlabel->SetStyle(STYLE_LINE_HEIGHT, 35);\r
-        stopWatchlabel->SetText("秒表");\r
-        stopWatchlabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);\r
-        stopWatchlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
-        stopWatchlabel->SetRollSpeed(0);\r
-        stopWatchlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
-        scrollView[MAIN_STOPWATCH]->Add(stopWatchlabel);\r
-        stopWatchlabel->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        if (showTimelabel == nullptr)\r
-        {\r
-            showTimelabel = new UILabel();\r
-        }\r
-        showTimelabel->SetPosition(63, 160);\r
-        showTimelabel->Resize(200, 60);\r
-        showTimelabel->SetViewId("showTimelabel");\r
-        showTimelabel->SetStyle(STYLE_TEXT_FONT, 80);\r
-        showTimelabel->SetStyle(STYLE_LINE_HEIGHT, 94);\r
-        showTimelabel->SetText("00:00.00");\r
-        showTimelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);\r
-        showTimelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
-        showTimelabel->SetRollSpeed(0);\r
-        showTimelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 80);\r
-        scrollView[MAIN_STOPWATCH]->Add(showTimelabel);\r
-        showTimelabel->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        if (LineImage == nullptr)\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
+            UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(MainStopWatchPresenter::GetInstance());\r
+            if (draglistener == nullptr)\r
+            {\r
+                return;\r
+            }\r
+            group->SetOnDragListener(draglistener);\r
+            group->SetTouchable(true);\r
+            group->SetDraggable(true);\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
+            /* ----------------------------- 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, 52, 300, 40);\r
+            stopWatchlabel->SetStyle(STYLE_TEXT_FONT, 30);\r
+            stopWatchlabel->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+            stopWatchlabel->SetText("秒表");\r
+            stopWatchlabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
+            stopWatchlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+            stopWatchlabel->SetRollSpeed(40);\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(68, 160);\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_ADAPT);\r
+            showTimelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+            showTimelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 84);\r
+            /* -------------------------------- LineImage ------------------------------- */\r
             LineImage = new UIImageView();\r
-        }\r
-        LineImage->SetPosition(53, 150);\r
-        char *imageimagesPath = "/user/res/stopwatch/STOPWATCH_LINE.bin";\r
-        LineImage->SetSrc(imageimagesPath);\r
-        scrollView[MAIN_STOPWATCH]->Add(LineImage);\r
-        LineImage->SetVisible(false);\r
-        /* -------------------------------------------------------------------------- */\r
-        if (list == nullptr)\r
-        {\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
+            /* ---------------------------------- list ---------------------------------- */\r
             list = new UIList();\r
-        }\r
-        list->SetPosition(56, 170, 360, 100);\r
-        list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);\r
-        list->SetReboundSize(30);\r
-        if (listadapter == nullptr)\r
-        {\r
+            if (list == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail!!");\r
+                return;\r
+            }\r
+            list->SetPosition(56, 170, 360, 100);\r
+            list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);\r
+            list->SetReboundSize(30);\r
+            list->SetVisible(false);\r
+            /* ------------------------------- listadapter ------------------------------ */\r
             listadapter = new TextAdapter();\r
-        }\r
-        listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28);\r
-        if (listdata == nullptr)\r
-        {\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, 28);\r
+            /* -------------------------------- listdata -------------------------------- */\r
             listdata = new List<const char *>();\r
-        }\r
-        scrollView[MAIN_STOPWATCH]->Add(list);\r
-        list->SetVisible(false);\r
-        /* -------------------------------------------------------------------------- */\r
-        // Add CheckBox to App\r
-        if (PlayOrPausecheckBox == nullptr)\r
-        {\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
-        }\r
-        PlayOrPausecheckBox->SetPosition(118, 321);\r
-        PlayOrPausecheckBox->Resize(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
-        // Add to scrollView1\r
-        scrollView[MAIN_STOPWATCH]->Add(PlayOrPausecheckBox);\r
-        PlayOrPausecheckBox->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        // Add Button to App\r
-        if (ResetOrMarkbutton == nullptr)\r
-        {\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
+            UICheckBox::OnChangeListener *PlayOrPausecheckBoxChangeListener = static_cast<UICheckBox::OnChangeListener *>(MainStopWatchPresenter::GetInstance());\r
+            PlayOrPausecheckBox->SetOnChangeListener(PlayOrPausecheckBoxChangeListener);\r
+            UIView::OnClickListener *ResetOrMarkbuttonClick = static_cast<UIView::OnClickListener *>(MainStopWatchPresenter::GetInstance());\r
+            ResetOrMarkbutton->SetOnClickListener(ResetOrMarkbuttonClick);\r
         }\r
-        ResetOrMarkbutton->SetPosition(256, 333);\r
-        ResetOrMarkbutton->Resize(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, nullptr);\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
-        scrollView[MAIN_STOPWATCH]->Add(ResetOrMarkbutton);\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
-        PlayOrPausecheckBoxChangeListener = static_cast<UICheckBox::OnChangeListener *>(MainStopWatchPresenter::GetInstance());\r
-        PlayOrPausecheckBox->SetOnChangeListener(PlayOrPausecheckBoxChangeListener);\r
-        ResetOrMarkbuttonClick = static_cast<UIView::OnClickListener *>(MainStopWatchPresenter::GetInstance());\r
-        ResetOrMarkbutton->SetOnClickListener(ResetOrMarkbuttonClick);\r
     }\r
 \r
-    void MainStopWatchView::DeInitView()\r
+    UILabelExt *MainStopWatchView::GetShowTimelabel(void)\r
     {\r
-        if (stopWatchlabel != nullptr)\r
-        {\r
-            delete stopWatchlabel;\r
-            stopWatchlabel = nullptr;\r
-        }\r
-        if (showTimelabel != nullptr)\r
-        {\r
-            delete showTimelabel;\r
-            showTimelabel = nullptr;\r
-        }\r
-        if (PlayOrPausecheckBox != nullptr)\r
-        {\r
-            delete PlayOrPausecheckBox;\r
-            PlayOrPausecheckBox = nullptr;\r
-        }\r
-        if (ResetOrMarkbutton != nullptr)\r
-        {\r
-            delete ResetOrMarkbutton;\r
-            ResetOrMarkbutton = nullptr;\r
-        }\r
-        if (LineImage != nullptr)\r
-        {\r
-            delete LineImage;\r
-            LineImage = nullptr;\r
-        }\r
-        if (list != nullptr)\r
-        {\r
-            delete list;\r
-            list = nullptr;\r
-        }\r
-        if (listadapter != nullptr)\r
-        {\r
-            delete listadapter;\r
-            listadapter = nullptr;\r
-        }\r
-        if (listdata != nullptr)\r
-        {\r
-            listdata->Clear();\r
-            delete listdata;\r
-            listdata = nullptr;\r
-        }\r
-        if (draglistener != nullptr)\r
-        {\r
-            delete draglistener;\r
-            draglistener = nullptr;\r
-        }\r
-        if (PlayOrPausecheckBoxChangeListener != nullptr)\r
-        {\r
-            delete PlayOrPausecheckBoxChangeListener;\r
-            PlayOrPausecheckBoxChangeListener = nullptr;\r
-        }\r
-        if (ResetOrMarkbuttonClick != nullptr)\r
-        {\r
-            delete ResetOrMarkbuttonClick;\r
-            ResetOrMarkbuttonClick = nullptr;\r
-        }\r
-        if (scrollView[MAIN_STOPWATCH] != nullptr)\r
-        {\r
-            delete scrollView[MAIN_STOPWATCH];\r
-            scrollView[MAIN_STOPWATCH] = nullptr;\r
-        }\r
-        if (container_ != nullptr)\r
-        {\r
-            container_->RemoveAll();\r
-            delete container_;\r
-            container_ = nullptr;\r
-        }\r
-    }\r
-    void MainStopWatchView::PreLoad(void)\r
-    {\r
-        if (!viewInitStatus)\r
-        {\r
-            InitMainStopWatchView();\r
-            viewInitStatus = true;\r
-        }\r
+        return showTimelabel;\r
     }\r
+\r
     void MainStopWatchView::OnStart()\r
     {\r
-        // container_容器属性 new\r
-        container_ = new UIViewGroup();\r
-        if (container_ == nullptr)\r
-        {\r
-            return;\r
-        }\r
-        // container_容器属性 扩展\r
-        container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());\r
-        draglistener = static_cast<UIView::OnDragListener *>(MainStopWatchPresenter::GetInstance());\r
-        if (draglistener == nullptr)\r
-        {\r
-            return;\r
-        }\r
-        container_->SetOnDragListener(draglistener);\r
-        container_->SetTouchable(true);\r
-        container_->SetDraggable(true);\r
-        PreLoad();\r
-        RootView::GetInstance()->Add(container_);\r
+        View<MainStopWatchPresenter>::OnStart();\r
+        InitMainStopWatchView();\r
         // 增加按键监听\r
         RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainStopWatchPresenter::GetInstance();\r
         RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
-        RootView::GetInstance()->SetIntercept(true);\r
     }\r
 \r
     void MainStopWatchView::OnSetUpView()\r
     {\r
 \r
         View<MainStopWatchPresenter>::OnSetUpView();\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
+        RootView::GetInstance()->Add(group);\r
         Draw();\r
     }\r
 \r
@@ -378,7 +393,7 @@ namespace OHOS
     {\r
 \r
         View<MainStopWatchPresenter>::OnStop();\r
-         RootView::GetInstance()->ClearOnKeyActListener();\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
         RootView::GetInstance()->RemoveAll();\r
         return;\r
     }\r
index bb4f2be..00d3994 100644 (file)
@@ -1,12 +1,14 @@
 #include "stopwatch/include/StopWatchModel.h"\r
 #include "cmsis_os2.h"\r
 #include "cmsis_os.h"\r
-\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
-    int StopWatchModel::oneDaySec = 86400; // 一天的秒数\r
-    int StopWatchModel::oneHourSec = 3600; // 一个小时的秒数\r
-    int StopWatchModel::oneMinuteSec = 60; // 一分钟秒数\r
 \r
     std::shared_ptr<StopWatchModel> StopWatchModel::GetInstance() // shared_ptr:当没有引用指向这个实例时会自动释放内存\r
     {\r
@@ -14,8 +16,213 @@ namespace OHOS
         return instance;\r
     }\r
 \r
-    /* 时间显示 */\r
-    char *StopWatchModel::DisplayMotionDuration()\r
+    /* ----------------------------------- 定时器 ---------------------------------- */\r
+    // 声明定时器变量\r
+    static osTimerId_t g_timer = NULL;\r
+    static int g_StopWatchTimes = {0};\r
+    static constexpr int32 NUM_TEN = 10;\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 uint64_t g_timerStartTimestamp = 0; // 添加一个全局变量来存储定时器开始的时间戳\r
+    /*\r
+     * @brief 显示倒计时(分钟、秒、毫秒),毫秒显示为两位数\r
+     */\r
+    char *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 (char *)stopwatchDuration.c_str();\r
+    }\r
+\r
+    /*\r
+     * @brief 在这里添加定时器到期后的处理逻辑\r
+     */\r
+    static void StopWatch_TimerCallbackProc(int data)\r
+    {\r
+        g_StopWatchTimes += 10; // 每次回调增加10毫秒\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_StopWatchTimes:%d\n", g_StopWatchTimes);\r
+\r
+        if (MainStopWatchView::GetInstance() == nullptr)\r
+        {\r
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[StopWatch_TimerCallbackProc] GetInstance is NULL");\r
+            return;\r
+        }\r
+\r
+        if (MainStopWatchView::GetInstance()->GetShowTimelabel() == nullptr)\r
+        {\r
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[StopWatch_TimerCallbackProc] GetInstance()->GetShowTimelabel is NULL");\r
+            return;\r
+        }\r
+\r
+        if (StopWatchModel::GetInstance()->DisplayStopWatchDuration() == nullptr)\r
+        {\r
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[StopWatch_TimerCallbackProc] DisplayStopWatchDuration is NULL");\r
+            return;\r
+        }\r
+\r
+        MainStopWatchView::GetInstance()->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration());\r
+    }\r
+\r
+    /*\r
+     * @brief 倒计时回调函数\r
+     */\r
+    static void StopWatch_TimerCallback(int data)\r
+    {\r
+#if 0\r
+        uint64_t currentTimestamp = GetCurrentTimestamp();\r
+        if ((currentTimestamp - g_timerStartTimestamp) >= 5999099) // 99分59秒99的毫秒数\r
+        {\r
+            if (g_timer != NULL)\r
+            {\r
+                osTimerStop(g_timer);   // 停止定时器\r
+                osTimerDelete(g_timer); // 删除定时器\r
+                g_timer = NULL;\r
+                g_timerStartTimestamp = 0; // 重置时间戳\r
+                // 可以在这里添加额外的逻辑,比如更新界面显示等\r
+            }\r
+        }\r
+        else\r
+        {\r
+            GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data));\r
+        }\r
+#endif\r
+        GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data));\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 != NULL)\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, NULL, NULL);\r
+        // 检查定时器创建是否成功\r
+        if (g_timer == NULL)\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.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */\r
+        if (ret != osOK)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret);\r
+            if (g_timer != NULL)\r
+            {\r
+                ret = osTimerDelete(g_timer);\r
+                return;\r
+            }\r
+            g_timer = NULL;\r
+        }\r
+        return;\r
+    }\r
+\r
+    /*\r
+     * @brief 停止定时器\r
+     */\r
+    void StopWatchModel::StopWatch_StopTimer(void)\r
+    {\r
+        // 检查定时器是否存在\r
+        if (g_timer != NULL)\r
+        {\r
+            // 删除定时器并置为 NULL\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 = NULL;\r
+            g_StopWatchTimes = 0;\r
+        }\r
+    }\r
+    /*\r
+     * @brief 暂停定时器\r
+     */\r
+    void StopWatchModel::StopWatch_PauseTimer(void)\r
+    {\r
+        // 检查定时器是否存在\r
+        if (g_timer != NULL)\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 != NULL)\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
index 24318e8..feca45e 100644 (file)
@@ -1,5 +1,6 @@
 #include "stopwatch/include/StopWatchRecordCycleToLimitView.h"\r
 #include "stopwatch/include/MainStopWatchPresenter.h"\r
+#include "UiConfig.h"\r
 /*弹窗视图:到达最高圈数99时弹出*/\r
 namespace OHOS\r
 {\r
@@ -14,10 +15,7 @@ namespace OHOS
 \r
     StopWatchRecordCycleToLimitView::~StopWatchRecordCycleToLimitView()\r
     {\r
-        if (viewInitStatus == true)\r
-        {\r
-            DeInitView();\r
-        }\r
+        ClearAll();\r
         g_pStopWatchRecordCycleToLimitView = nullptr;\r
     }\r
 \r
@@ -29,118 +27,98 @@ namespace OHOS
     // 初始化秒表到达最高圈数时弹出的视图\r
     UIScrollView *StopWatchRecordCycleToLimitView::InitStopWatchRecordCycleToLimitView()\r
     {\r
-        if (scrollView1_ == nullptr)\r
-        {\r
-            scrollView1_ = new UIScrollView();\r
-        }\r
-        scrollView1_->SetPosition(0, 0);\r
-        scrollView1_->Resize(466, 466);\r
-        scrollView1_->SetViewId("scrollView1");\r
-        scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
-        scrollView1_->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        if (label1_ == nullptr)\r
+        if (scrollView == nullptr)\r
         {\r
-            label1_ = new UILabel();\r
-        }\r
-        label1_->SetPosition(203, 52);\r
-        label1_->Resize(60, 35);\r
-        label1_->SetViewId("label1");\r
-        label1_->SetStyle(STYLE_TEXT_FONT, 30);\r
-        label1_->SetStyle(STYLE_LINE_HEIGHT, 35);\r
-        label1_->SetText("秒表");\r
-        label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);\r
-        label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
-        label1_->SetRollSpeed(0);\r
-        label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
-        scrollView1_->Add(label1_);\r
-        label1_->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        if (image1_ == nullptr)\r
-        {\r
-            image1_ = new UIImageView();\r
-        }\r
-        image1_->SetPosition(193, 121);\r
-        image1_->Resize(100, 100);\r
-        image1_->SetViewId("image1");\r
-        image1_->SetStyle(STYLE_BORDER_RADIUS, 100);\r
-        char *image1imagesPath = "/user/res/countdown/COUNTDOWN_ATTENTION.bin";\r
-        image1_->SetSrc(image1imagesPath);\r
-        scrollView1_->Add(image1_);\r
-        image1_->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        // Add Label to App\r
-        if (label3_ == nullptr)\r
-        {\r
-            label3_ = new UILabel();\r
-        }\r
-        label3_->SetPosition(83, 253);\r
-        label3_->Resize(300, 35);\r
-        label3_->SetViewId("label3");\r
-        label3_->SetStyle(STYLE_TEXT_FONT, 30);\r
-        label3_->SetStyle(STYLE_LINE_HEIGHT, 35);\r
-        label3_->SetText("当前已达到了最高圈数");\r
-        label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);\r
-        label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
-        label3_->SetRollSpeed(0);\r
-        label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
-        // Add to scrollView1\r
-        scrollView1_->Add(label3_);\r
-        label3_->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        // Add Button to App\r
-        if (button1_ == nullptr)\r
-        {\r
-            button1_ = new UIButton();\r
-        }\r
-        button1_->SetPosition(0, 366);\r
-        button1_->Resize(466, 100);\r
-        button1_->SetViewId(CycleToLimitReturnButton_VIEWID);\r
-        button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);\r
-        button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
-        char *button1defaultImgSrc = "/user/res/countdown/COUNTDOWN_BUTTON.bin";\r
-        button1_->SetImageSrc(button1defaultImgSrc, nullptr);\r
-        button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED);\r
-        button1_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);\r
-        button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);\r
+            scrollView = new UIScrollView();\r
 \r
-        // Add the CallBack about events\r
-        UIView::OnClickListener *button1Click = static_cast<UIView::OnClickListener *>(MainStopWatchPresenter::GetInstance());\r
-        button1_->SetOnClickListener(button1Click);\r
-        // Add to scrollView1\r
-        scrollView1_->Add(button1_);\r
-        button1_->SetVisible(true);\r
-        viewInitStatus == true;\r
-        return scrollView1_;\r
+            scrollView->SetPosition(0, 0, 466, 466);\r
+            scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
+            /* -------------------------------------------------------------------------- */\r
+            if (Title == nullptr)\r
+            {\r
+                Title = new UILabelExt();\r
+            }\r
+            Title->SetPosition(83, 52, 300, 40);\r
+            Title->SetStyle(STYLE_TEXT_FONT, 30);\r
+            Title->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+            Title->SetText("秒表");\r
+            Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
+            Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+            Title->SetRollSpeed(40);\r
+            Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+            /* -------------------------------------------------------------------------- */\r
+            if (AttentionImage == nullptr)\r
+            {\r
+                AttentionImage = new UIImageView();\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
+            }\r
+            AttentionLabel->SetPosition(83, 253, 300, 40);\r
+            AttentionLabel->SetStyle(STYLE_TEXT_FONT, 30);\r
+            AttentionLabel->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+            AttentionLabel->SetText("当前已达到了最高圈数");\r
+            AttentionLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
+            AttentionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+            AttentionLabel->SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff));\r
+            AttentionLabel->SetRollSpeed(40);\r
+            AttentionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+            /* -------------------------------------------------------------------------- */\r
+            if (button == nullptr)\r
+            {\r
+                button = new UILabelButtonExt();\r
+            }\r
+            button->SetPosition(0, 366, 466, 100);\r
+            button->SetViewId(CycleToLimitReturnButton_VIEWID);\r
+            button->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE);\r
+            button->SetText("知道了");\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
+            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::DeInitView()\r
+    void StopWatchRecordCycleToLimitView::ClearAll()\r
     {\r
-        if (scrollView1_ != nullptr)\r
+        scrollView->RemoveAll();\r
+\r
+        if (Title != nullptr)\r
         {\r
-            scrollView1_->RemoveAll();\r
-            delete scrollView1_;\r
-            scrollView1_ = nullptr;\r
+            delete Title;\r
+            Title = nullptr;\r
         }\r
-        if (label1_ != nullptr)\r
+        if (AttentionImage != nullptr)\r
         {\r
-            delete label1_;\r
-            label1_ = nullptr;\r
+            delete AttentionImage;\r
+            AttentionImage = nullptr;\r
         }\r
-        if (image1_ != nullptr)\r
+        if (AttentionLabel != nullptr)\r
         {\r
-            delete image1_;\r
-            image1_ = nullptr;\r
+            delete AttentionLabel;\r
+            AttentionLabel = nullptr;\r
         }\r
-        if (label3_ != nullptr)\r
+        if (button != nullptr)\r
         {\r
-            delete label3_;\r
-            label3_ = nullptr;\r
+            delete button;\r
+            button = nullptr;\r
         }\r
-        if (button1_ != nullptr)\r
+        if (scrollView != nullptr)\r
         {\r
-            delete button1_;\r
-            button1_ = nullptr;\r
+            delete scrollView;\r
+            scrollView = nullptr;\r
         }\r
     }\r
 }
\ No newline at end of file
index eaf3cb6..241bd2c 100644 (file)
@@ -10,16 +10,12 @@ namespace OHOS
 \r
     StopWatchRecordTimeToLimitView::StopWatchRecordTimeToLimitView()\r
     {\r
-\r
         g_pStopWatchRecordTimeToLimitView = this;\r
     }\r
 \r
     StopWatchRecordTimeToLimitView::~StopWatchRecordTimeToLimitView()\r
     {\r
-        if (viewInitStatus == true)\r
-        {\r
-            DeInitView();\r
-        }\r
+        ClearAll();\r
         g_pStopWatchRecordTimeToLimitView = nullptr;\r
     }\r
 \r
@@ -31,117 +27,111 @@ namespace OHOS
 \r
     UIScrollView *StopWatchRecordTimeToLimitView::InitStopWatchRecordTimeToLimitView()\r
     {\r
-        if (scrollView1_ == nullptr)\r
-        {\r
-            scrollView1_ = new UIScrollView();\r
-        }\r
-        scrollView1_->SetPosition(0, 0);\r
-        scrollView1_->Resize(466, 466);\r
-        scrollView1_->SetViewId("scrollView1");\r
-        scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
-        scrollView1_->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        if (label1_ == nullptr)\r
-        {\r
-            label1_ = new UILabel();\r
-        }\r
-        label1_->SetPosition(203, 52);\r
-        label1_->Resize(60, 35);\r
-        label1_->SetViewId("label1");\r
-        label1_->SetStyle(STYLE_TEXT_FONT, 30);\r
-        label1_->SetStyle(STYLE_LINE_HEIGHT, 35);\r
-        label1_->SetText("秒表");\r
-        label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);\r
-        label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
-        label1_->SetRollSpeed(0);\r
-        label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
-        scrollView1_->Add(label1_);\r
-        label1_->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        if (image1_ == nullptr)\r
-        {\r
-            image1_ = new UIImageView();\r
-        }\r
-        image1_->SetPosition(193, 121);\r
-        image1_->Resize(100, 100);\r
-        image1_->SetViewId("image1");\r
-        image1_->SetStyle(STYLE_BORDER_RADIUS, 100);\r
-        char *image1imagesPath = "/user/res/countdown/COUNTDOWN_ATTENTION.bin";\r
-        image1_->SetSrc(image1imagesPath);\r
-        scrollView1_->Add(image1_);\r
-        image1_->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        // Add Label to App\r
-        if (label3_ == nullptr)\r
-        {\r
-            label3_ = new UILabel();\r
-        }\r
-        label3_->SetPosition(53, 235);\r
-        label3_->Resize(300, 35);\r
-        label3_->SetViewId("label3");\r
-        label3_->SetStyle(STYLE_TEXT_FONT, 30);\r
-        label3_->SetStyle(STYLE_LINE_HEIGHT, 35);\r
-        label3_->SetText("当前已达到了最长时间\n表秒自动暂停,请重新开始");\r
-        label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);\r
-        label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
-        label3_->SetRollSpeed(0);\r
-        label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
-        // Add to scrollView1\r
-        scrollView1_->Add(label3_);\r
-        label3_->SetVisible(true);\r
-        /* -------------------------------------------------------------------------- */\r
-        // Add Button to App\r
-        if (button1_ == nullptr)\r
+        if (scrollView == nullptr)\r
         {\r
-            button1_ = new UIButton();\r
+            scrollView = new UIScrollView();\r
+            scrollView->SetPosition(0, 0, 466, 466);\r
+            scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
+            /* -------------------------------------------------------------------------- */\r
+            if (Title == nullptr)\r
+            {\r
+                Title = new UILabelExt();\r
+            }\r
+            Title->SetPosition(83, 52, 300, 40);\r
+            Title->SetStyle(STYLE_TEXT_FONT, 30);\r
+            Title->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+            Title->SetText("秒表");\r
+            Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
+            Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+            Title->SetRollSpeed(40);\r
+            Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+            /* -------------------------------------------------------------------------- */\r
+            if (AttentionImage == nullptr)\r
+            {\r
+                AttentionImage = new UIImageView();\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
+            }\r
+            AttentionLabel_1->SetPosition(83, 235, 300, 40);\r
+            AttentionLabel_1->SetStyle(STYLE_TEXT_FONT, 30);\r
+            AttentionLabel_1->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+            AttentionLabel_1->SetText("当前已达到了最长时间");\r
+            AttentionLabel_1->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
+            AttentionLabel_1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+            AttentionLabel_1->SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff));\r
+            AttentionLabel_1->SetRollSpeed(40);\r
+            AttentionLabel_1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+            /* ---------------------------- AttentionLabel_2 ---------------------------- */\r
+            if (AttentionLabel_2 == nullptr)\r
+            {\r
+                AttentionLabel_2 = new UILabelExt();\r
+            }\r
+            AttentionLabel_2->SetPosition(33, 279, 400, 40);\r
+            AttentionLabel_2->SetStyle(STYLE_TEXT_FONT, 30);\r
+            AttentionLabel_2->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+            AttentionLabel_2->SetText("表秒自动暂停,请重新开始");\r
+            AttentionLabel_2->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
+            AttentionLabel_2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+            AttentionLabel_2->SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff));\r
+            AttentionLabel_2->SetRollSpeed(40);\r
+            AttentionLabel_2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+            /* -------------------------------------------------------------------------- */\r
+            if (button == nullptr)\r
+            {\r
+                button = new UILabelButtonExt();\r
+            }\r
+            button->SetPosition(0, 366, 466, 100);\r
+            button->SetViewId(TimeToLimitReturnButton_VIEWID);\r
+            button->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE);\r
+            button->SetText("知道了");\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
+            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
-        button1_->SetPosition(0, 366);\r
-        button1_->Resize(466, 100);\r
-        button1_->SetViewId(TimeToLimitReturnButton_VIEWID);\r
-        button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);\r
-        button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
-        char *button1defaultImgSrc = "/user/res/countdown/COUNTDOWN_BUTTON.bin";\r
-        button1_->SetImageSrc(button1defaultImgSrc, nullptr);\r
-        button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED);\r
-        button1_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);\r
-        button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);\r
-        // Add the CallBack about events\r
-        UIView::OnClickListener *button1Click = static_cast<UIView::OnClickListener *>(MainStopWatchPresenter::GetInstance());\r
-        button1_->SetOnClickListener(button1Click);\r
-        // Add to scrollView1\r
-        scrollView1_->Add(button1_);\r
-        button1_->SetVisible(true);\r
-        viewInitStatus = true;\r
-        return scrollView1_;\r
+        return scrollView;\r
     }\r
 \r
-    void StopWatchRecordTimeToLimitView::DeInitView()\r
+    void StopWatchRecordTimeToLimitView::ClearAll()\r
     {\r
-        if (scrollView1_ != nullptr)\r
+        scrollView->RemoveAll();\r
+        if (Title != nullptr)\r
         {\r
-            scrollView1_->RemoveAll();\r
-            delete scrollView1_;\r
-            scrollView1_ = nullptr;\r
+            delete Title;\r
+            Title = nullptr;\r
         }\r
-        if (label1_ != nullptr)\r
+        if (AttentionImage != nullptr)\r
         {\r
-            delete label1_;\r
-            label1_ = nullptr;\r
+            delete AttentionImage;\r
+            AttentionImage = nullptr;\r
         }\r
-        if (image1_ != nullptr)\r
+        if (AttentionLabel_1 != nullptr)\r
         {\r
-            delete image1_;\r
-            image1_ = nullptr;\r
+            delete AttentionLabel_1;\r
+            AttentionLabel_1 = nullptr;\r
         }\r
-        if (label3_ != nullptr)\r
+        if (button != nullptr)\r
         {\r
-            delete label3_;\r
-            label3_ = nullptr;\r
+            delete button;\r
+            button = nullptr;\r
         }\r
-        if (button1_ != nullptr)\r
+        if (scrollView != nullptr)\r
         {\r
-            delete button1_;\r
-            button1_ = nullptr;\r
+            delete scrollView;\r
+            scrollView = nullptr;\r
         }\r
     }\r
 }
\ No newline at end of file
index 1313f14..a1c358d 100644 (file)
@@ -207,7 +207,7 @@ namespace OHOS
         alarm_img->SetViewId("image1");// Set style
 
         // Set additional property
-        const char *imageimagesPath = "/user/res/FastTrainingAttentionVector.bin";
+        const char *imageimagesPath = "/user/res/Attention.bin";
         alarm_img->SetSrc(imageimagesPath);
 
         // Add to rootView
index e471c2a..ff79143 100644 (file)
@@ -447,7 +447,7 @@ namespace OHOS
                 return nullptr;
             }
             DeviceUnbindingRequestViewImageView->SetPosition(193, 121, 80, 80);
-            const char *imageimagesPath = "/user/res/FastTrainingAttentionVector.bin";
+            const char *imageimagesPath = "/user/res/Attention.bin";
             DeviceUnbindingRequestViewImageView->SetSrc(imageimagesPath);
 
             /* --------------------- DeviceUnbindingRequestViewLabel[0] -------------------- */
diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/OrangeAttentionVector.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/OrangeAttentionVector.bin
deleted file mode 100644 (file)
index b8120b8..0000000
Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/OrangeAttentionVector.bin and /dev/null differ
diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/countdown/COUNTDOWN_ATTENTION.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/countdown/COUNTDOWN_ATTENTION.bin
deleted file mode 100644 (file)
index b8120b8..0000000
Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/countdown/COUNTDOWN_ATTENTION.bin and /dev/null differ
diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/countdown/COUNTDOWN_BUTTON.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/countdown/COUNTDOWN_BUTTON.bin
deleted file mode 100644 (file)
index 5f89b63..0000000
Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/countdown/COUNTDOWN_BUTTON.bin and /dev/null differ