秒表视图修改
author罗正yun <1732036298@qq.com>
Fri, 15 Dec 2023 03:48:12 +0000 (11:48 +0800)
committer罗正yun <1732036298@qq.com>
Fri, 15 Dec 2023 03:48:12 +0000 (11:48 +0800)
code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h
code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h
code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp
code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp
code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp
code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp

index e355ed6..43da705 100755 (executable)
@@ -3,9 +3,6 @@
 \r
 #include "Presenter.h"\r
 #include "MainStopWatchView.h"\r
-#include "components/ui_checkbox.h"\r
-#include "components/ui_button.h"\r
-#include "components/ui_label.h"\r
 #include <string>\r
 /*秒表主视图*/\r
 namespace OHOS\r
@@ -34,7 +31,8 @@ namespace OHOS
         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
-\r
+        void SetList(UIList *list, TextAdapter *listadapter, List<const char *> *listdata);\r
+        void SetImage(UIImageView *image);\r
     private:\r
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
         bool OnClick(UIView &view, const ClickEvent &event) override;\r
@@ -46,6 +44,10 @@ namespace OHOS
         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
         int RecordCycleNumber{0};              // 用来记录点击计时按钮("Mark")的次数\r
         std::string RecordMaxTime{"99:59.59"}; // 计时时间最高为99:59.59\r
     };\r
index 9429c9b..3af8a0e 100755 (executable)
@@ -8,6 +8,8 @@
 #include "components/ui_label.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
 /*秒表主视图*/\r
@@ -23,6 +25,8 @@ namespace OHOS
     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
@@ -59,6 +63,10 @@ namespace OHOS
         UILabel *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
index dd5f176..18eda3c 100755 (executable)
@@ -83,6 +83,18 @@ namespace OHOS
         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
         UNUSED(view);\r
@@ -97,44 +109,59 @@ namespace OHOS
     bool MainStopWatchPresenter::OnClick(UIView &view, const ClickEvent &event)\r
     {\r
         UNUSED(view);\r
-        if (strcmp(view.GetViewId(), ResetOrMarkButton_MARK_VIEWID) == 0)\r
+        MainStopWatchView *mainStopWatchView = MainStopWatchView::GetInstance();\r
+        const char *clickedViewId = view.GetViewId();\r
+        if (strcmp(clickedViewId, ResetOrMarkButton_MARK_VIEWID) == 0)\r
         {\r
-            printf("mark!\n");\r
             RecordCycleNumber += 1;\r
             printf("RecordCycleNumber:%d\n", RecordCycleNumber);\r
-            if (RecordCycleNumber > 3)\r
+            if (RecordCycleNumber >= 99)\r
             {\r
-                // MainStopWatchView::GetInstance()->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_CYCLE_TO_LIMIT);\r
-                MainStopWatchView::GetInstance()->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_TIME_TO_LIMIT);\r
+                mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_CYCLE_TO_LIMIT);\r
                 return true;\r
             }\r
-            /* -------------------------------------------------------------------------- */\r
-            MainStopWatchView::GetInstance()->SetViewIsVisible(m_stopWatchlabel, false);\r
-            /* -------------------------------------------------------------------------- */\r
-            SetShowTimeLableStyle(m_showTimelabel, 93, 60, 65, 78);\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
+            }\r
+            char PickerData[128] = {0};\r
+            sprintf(PickerData, "0%d    %s    %s", RecordCycleNumber, "00:08:09", "+00:08:09");\r
+            m_listdata->PushBack(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
+            // m_list->Invalidate();\r
+            return true;\r
         }\r
-        else if (strcmp(view.GetViewId(), ResetOrMarkButton_RESET2_VIEWID) == 0)\r
+        else if (strcmp(clickedViewId, ResetOrMarkButton_RESET2_VIEWID) == 0)\r
         {\r
-            printf("Reset2!\n");\r
             m_button->SetViewId(ResetOrMarkButton_RESET1_VIEWID);\r
             m_button->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1);\r
             m_button->Invalidate();\r
-            /* -------------------------------------------------------------------------- */\r
-            MainStopWatchView::GetInstance()->SetViewIsVisible(m_stopWatchlabel, true);\r
-            /* -------------------------------------------------------------------------- */\r
+\r
+            mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, true);\r
             SetShowTimeLableStyle(m_showTimelabel, 63, 160, 80, 94);\r
-            /* -------------------------------------------------------------------------- */\r
+            mainStopWatchView->SetViewIsVisible(m_image, false);\r
+            if (m_listdata != nullptr)\r
+            {\r
+                m_listdata->Clear();\r
+            }\r
+            mainStopWatchView->SetViewIsVisible(m_list, false);\r
+            m_list->Invalidate();\r
+            RecordCycleNumber = 0;\r
         }\r
-        else if (strcmp(view.GetViewId(), "CycleToLimitReturnButton") == 0)\r
+        else if (strcmp(clickedViewId, CycleToLimitReturnButton_VIEWID) == 0)\r
         {\r
-            MainStopWatchView::GetInstance()->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH);\r
-            return true;\r
+            mainStopWatchView->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH);\r
         }\r
-        else if (strcmp(view.GetViewId(), "TimeToLimitReturnButton") == 0)\r
+        else if (strcmp(clickedViewId, TimeToLimitReturnButton_VIEWID) == 0)\r
         {\r
-            MainStopWatchView::GetInstance()->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH);\r
-            return true;\r
+            mainStopWatchView->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH);\r
         }\r
         return true;\r
     }\r
index 5c42304..d5f854c 100755 (executable)
@@ -43,7 +43,7 @@ namespace OHOS
         {\r
             view->SetVisible(false);\r
         }\r
-        RootView::GetInstance()->Invalidate();\r
+        view->Invalidate();\r
     }\r
 \r
     // 切换到秒表主视图\r
@@ -98,11 +98,10 @@ namespace OHOS
 \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
-    };\r
+        {\r
+            {MAIN_STOPWATCH, &MainStopWatchView::ChangeMainStopWatch},\r
+            {STOPWATCH_RECORD_CYCLE_TO_LIMIT, &MainStopWatchView::ChangeStopWatchRecordCycleLimit},\r
+            {STOPWATCH_RECORD_TIME_TO_LIMIT, &MainStopWatchView::ChangeMainStopWatchRecordTimeLimit}};\r
 \r
     // 3.根据传入的interface参数执行相应视图ID关联的成员函数。\r
     bool MainStopWatchView::ClickFunc(int16_t interface)\r
@@ -185,6 +184,35 @@ namespace OHOS
         scrollView[MAIN_STOPWATCH]->Add(showTimelabel);\r
         showTimelabel->SetVisible(true);\r
         /* -------------------------------------------------------------------------- */\r
+        if (LineImage == nullptr)\r
+        {\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
+            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
+            listadapter = new TextAdapter();\r
+        }\r
+        listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28);\r
+        if (listdata == nullptr)\r
+        {\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
@@ -219,6 +247,8 @@ namespace OHOS
         /* -------------------------------------------------------------------------- */\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
@@ -248,6 +278,27 @@ namespace OHOS
             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
index 51c9cdd..24318e8 100755 (executable)
@@ -37,7 +37,6 @@ namespace OHOS
         scrollView1_->Resize(466, 466);\r
         scrollView1_->SetViewId("scrollView1");\r
         scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
-        // container_->Add(scrollView1_);\r
         scrollView1_->SetVisible(true);\r
         /* -------------------------------------------------------------------------- */\r
         if (label1_ == nullptr)\r
@@ -96,7 +95,7 @@ namespace OHOS
         }\r
         button1_->SetPosition(0, 366);\r
         button1_->Resize(466, 100);\r
-        button1_->SetViewId("CycleToLimitReturnButton");\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
@@ -111,19 +110,15 @@ namespace OHOS
         // Add to scrollView1\r
         scrollView1_->Add(button1_);\r
         button1_->SetVisible(true);\r
+        viewInitStatus == true;\r
         return scrollView1_;\r
     }\r
 \r
     void StopWatchRecordCycleToLimitView::DeInitView()\r
     {\r
-        if (container_ != nullptr)\r
-        {\r
-            container_->RemoveAll();\r
-            delete container_;\r
-            container_ = nullptr;\r
-        }\r
         if (scrollView1_ != nullptr)\r
         {\r
+            scrollView1_->RemoveAll();\r
             delete scrollView1_;\r
             scrollView1_ = nullptr;\r
         }\r
index a9ce7de..eaf3cb6 100755 (executable)
@@ -97,7 +97,7 @@ namespace OHOS
         }\r
         button1_->SetPosition(0, 366);\r
         button1_->Resize(466, 100);\r
-        button1_->SetViewId("TimeToLimitReturnButton");\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
@@ -117,5 +117,31 @@ namespace OHOS
 \r
     void StopWatchRecordTimeToLimitView::DeInitView()\r
     {\r
+        if (scrollView1_ != nullptr)\r
+        {\r
+            scrollView1_->RemoveAll();\r
+            delete scrollView1_;\r
+            scrollView1_ = nullptr;\r
+        }\r
+        if (label1_ != nullptr)\r
+        {\r
+            delete label1_;\r
+            label1_ = nullptr;\r
+        }\r
+        if (image1_ != nullptr)\r
+        {\r
+            delete image1_;\r
+            image1_ = nullptr;\r
+        }\r
+        if (label3_ != nullptr)\r
+        {\r
+            delete label3_;\r
+            label3_ = nullptr;\r
+        }\r
+        if (button1_ != nullptr)\r
+        {\r
+            delete button1_;\r
+            button1_ = nullptr;\r
+        }\r
     }\r
 }
\ No newline at end of file