From: 罗正yun <1732036298@qq.com> Date: Fri, 15 Dec 2023 03:48:12 +0000 (+0800) Subject: 秒表视图修改 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=349bcd7f61e844a274db10eb5d5b943c44661773;p=mirrors%2FFD230.git 秒表视图修改 --- diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h index e355ed6e9..43da7056c 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h @@ -3,9 +3,6 @@ #include "Presenter.h" #include "MainStopWatchView.h" -#include "components/ui_checkbox.h" -#include "components/ui_button.h" -#include "components/ui_label.h" #include /*秒表主视图*/ namespace OHOS @@ -34,7 +31,8 @@ namespace OHOS void SetCheckBoxAndButton(UICheckBox *checkbox, UIButton *button); void SetLable(UILabel *label1, UILabel *label2); void SetShowTimeLableStyle(UILabel *label, int x, int y, int TextFont, int LineHeight); - + void SetList(UIList *list, TextAdapter *listadapter, List *listdata); + void SetImage(UIImageView *image); private: // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; @@ -46,6 +44,10 @@ namespace OHOS UIButton *m_button{nullptr}; UILabel *m_stopWatchlabel{nullptr}; UILabel *m_showTimelabel{nullptr}; + UIImageView *m_image{nullptr}; + UIList *m_list = nullptr; + TextAdapter *m_listadapter = nullptr; + List *m_listdata = nullptr; int RecordCycleNumber{0}; // 用来记录点击计时按钮("Mark")的次数 std::string RecordMaxTime{"99:59.59"}; // 计时时间最高为99:59.59 }; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h index 9429c9b7b..3af8a0e0b 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h @@ -8,6 +8,8 @@ #include "components/ui_label.h" #include "components/ui_checkbox.h" #include "components/ui_button.h" +#include "components/ui_list.h" +#include "components/text_adapter.h" #include "stopwatch/include/StopWatchRecordCycleToLimitView.h" #include "stopwatch/include/StopWatchRecordTimeToLimitView.h" /*秒表主视图*/ @@ -23,6 +25,8 @@ namespace OHOS static const char *ResetOrMarkButton_RESET1_VIEWID = "ResetOrMarkButtonReset1"; // ResetOrMarkButtonReset1 static const char *ResetOrMarkButton_RESET2_VIEWID = "ResetOrMarkButtonReset2"; // ResetOrMarkButtonReset2 static const char *ResetOrMarkButton_MARK_VIEWID = "ResetOrMarkButtonMark"; // ResetOrMarkButtonMark + static const char *CycleToLimitReturnButton_VIEWID = "CycleToLimitReturnButton"; // CycleToLimitReturnButton + static const char *TimeToLimitReturnButton_VIEWID = "TimeToLimitReturnButton"; // TimeToLimitReturnButton class MainStopWatchPresenter; class MainStopWatchView : public View { @@ -59,6 +63,10 @@ namespace OHOS UILabel *showTimelabel = nullptr; // 用来显示计时时间 UICheckBox *PlayOrPausecheckBox = nullptr; // 播放或暂停复选框 UIButton *ResetOrMarkbutton = nullptr; // 重置或标记按钮 + UIImageView *LineImage{nullptr}; + UIList *list = nullptr; + TextAdapter *listadapter = nullptr; + List *listdata = nullptr; UIView::OnDragListener *draglistener{nullptr}; UICheckBox::OnChangeListener *PlayOrPausecheckBoxChangeListener{nullptr}; UIView::OnClickListener *ResetOrMarkbuttonClick{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp index dd5f176a4..18eda3c6b 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -83,6 +83,18 @@ namespace OHOS label->Invalidate(); } + void MainStopWatchPresenter::SetList(UIList *list, TextAdapter *listadapter, List *listdata) + { + m_list = list; + m_listadapter = listadapter; + m_listdata = listdata; + } + + void MainStopWatchPresenter::SetImage(UIImageView *image) + { + m_image = image; + } + bool MainStopWatchPresenter::OnDrag(UIView &view, const DragEvent &event) { UNUSED(view); @@ -97,44 +109,59 @@ namespace OHOS bool MainStopWatchPresenter::OnClick(UIView &view, const ClickEvent &event) { UNUSED(view); - if (strcmp(view.GetViewId(), ResetOrMarkButton_MARK_VIEWID) == 0) + MainStopWatchView *mainStopWatchView = MainStopWatchView::GetInstance(); + const char *clickedViewId = view.GetViewId(); + if (strcmp(clickedViewId, ResetOrMarkButton_MARK_VIEWID) == 0) { - printf("mark!\n"); RecordCycleNumber += 1; printf("RecordCycleNumber:%d\n", RecordCycleNumber); - if (RecordCycleNumber > 3) + if (RecordCycleNumber >= 99) { - // MainStopWatchView::GetInstance()->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_CYCLE_TO_LIMIT); - MainStopWatchView::GetInstance()->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_TIME_TO_LIMIT); + mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_CYCLE_TO_LIMIT); return true; } - /* -------------------------------------------------------------------------- */ - MainStopWatchView::GetInstance()->SetViewIsVisible(m_stopWatchlabel, false); - /* -------------------------------------------------------------------------- */ - SetShowTimeLableStyle(m_showTimelabel, 93, 60, 65, 78); - /* -------------------------------------------------------------------------- */ + else + { + mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false); + SetShowTimeLableStyle(m_showTimelabel, 93, 60, 65, 78); + mainStopWatchView->SetViewIsVisible(m_list, true); + mainStopWatchView->SetViewIsVisible(m_image, true); + } + char PickerData[128] = {0}; + sprintf(PickerData, "0%d %s %s", RecordCycleNumber, "00:08:09", "+00:08:09"); + m_listdata->PushBack(PickerData); + m_listadapter->SetData(m_listdata); + m_list->SetAdapter(m_listadapter); + //m_list->SetStartIndex(RecordCycleNumber - 1); + m_list->SetSelectPosition(RecordCycleNumber); + m_list->RefreshList(); + // m_list->Invalidate(); + return true; } - else if (strcmp(view.GetViewId(), ResetOrMarkButton_RESET2_VIEWID) == 0) + else if (strcmp(clickedViewId, ResetOrMarkButton_RESET2_VIEWID) == 0) { - printf("Reset2!\n"); m_button->SetViewId(ResetOrMarkButton_RESET1_VIEWID); m_button->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1); m_button->Invalidate(); - /* -------------------------------------------------------------------------- */ - MainStopWatchView::GetInstance()->SetViewIsVisible(m_stopWatchlabel, true); - /* -------------------------------------------------------------------------- */ + + mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, true); SetShowTimeLableStyle(m_showTimelabel, 63, 160, 80, 94); - /* -------------------------------------------------------------------------- */ + mainStopWatchView->SetViewIsVisible(m_image, false); + if (m_listdata != nullptr) + { + m_listdata->Clear(); + } + mainStopWatchView->SetViewIsVisible(m_list, false); + m_list->Invalidate(); + RecordCycleNumber = 0; } - else if (strcmp(view.GetViewId(), "CycleToLimitReturnButton") == 0) + else if (strcmp(clickedViewId, CycleToLimitReturnButton_VIEWID) == 0) { - MainStopWatchView::GetInstance()->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); - return true; + mainStopWatchView->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); } - else if (strcmp(view.GetViewId(), "TimeToLimitReturnButton") == 0) + else if (strcmp(clickedViewId, TimeToLimitReturnButton_VIEWID) == 0) { - MainStopWatchView::GetInstance()->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); - return true; + mainStopWatchView->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); } return true; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp index 5c42304bb..d5f854c81 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp @@ -43,7 +43,7 @@ namespace OHOS { view->SetVisible(false); } - RootView::GetInstance()->Invalidate(); + view->Invalidate(); } // 切换到秒表主视图 @@ -98,11 +98,10 @@ namespace OHOS // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与MainStopWatchView类中的特定成员函数指针进行了绑定。 static const MainStopWatchViewMapper ViewMapper[] = - { - {MAIN_STOPWATCH, &MainStopWatchView::ChangeMainStopWatch}, - {STOPWATCH_RECORD_CYCLE_TO_LIMIT, &MainStopWatchView::ChangeStopWatchRecordCycleLimit}, - {STOPWATCH_RECORD_TIME_TO_LIMIT, &MainStopWatchView::ChangeMainStopWatchRecordTimeLimit} - }; + { + {MAIN_STOPWATCH, &MainStopWatchView::ChangeMainStopWatch}, + {STOPWATCH_RECORD_CYCLE_TO_LIMIT, &MainStopWatchView::ChangeStopWatchRecordCycleLimit}, + {STOPWATCH_RECORD_TIME_TO_LIMIT, &MainStopWatchView::ChangeMainStopWatchRecordTimeLimit}}; // 3.根据传入的interface参数执行相应视图ID关联的成员函数。 bool MainStopWatchView::ClickFunc(int16_t interface) @@ -185,6 +184,35 @@ namespace OHOS scrollView[MAIN_STOPWATCH]->Add(showTimelabel); showTimelabel->SetVisible(true); /* -------------------------------------------------------------------------- */ + if (LineImage == nullptr) + { + LineImage = new UIImageView(); + } + LineImage->SetPosition(53, 150); + char *imageimagesPath = "/user/res/stopwatch/STOPWATCH_LINE.bin"; + LineImage->SetSrc(imageimagesPath); + scrollView[MAIN_STOPWATCH]->Add(LineImage); + LineImage->SetVisible(false); + /* -------------------------------------------------------------------------- */ + if (list == nullptr) + { + list = new UIList(); + } + list->SetPosition(56, 170, 360, 100); + list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + list->SetReboundSize(30); + if (listadapter == nullptr) + { + listadapter = new TextAdapter(); + } + listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + if (listdata == nullptr) + { + listdata = new List(); + } + scrollView[MAIN_STOPWATCH]->Add(list); + list->SetVisible(false); + /* -------------------------------------------------------------------------- */ // Add CheckBox to App if (PlayOrPausecheckBox == nullptr) { @@ -219,6 +247,8 @@ namespace OHOS /* -------------------------------------------------------------------------- */ MainStopWatchPresenter::GetInstance()->SetCheckBoxAndButton(PlayOrPausecheckBox, ResetOrMarkbutton); MainStopWatchPresenter::GetInstance()->SetLable(stopWatchlabel, showTimelabel); + MainStopWatchPresenter::GetInstance()->SetImage(LineImage); + MainStopWatchPresenter::GetInstance()->SetList(list, listadapter, listdata); // Add the CallBack about events PlayOrPausecheckBoxChangeListener = static_cast(MainStopWatchPresenter::GetInstance()); PlayOrPausecheckBox->SetOnChangeListener(PlayOrPausecheckBoxChangeListener); @@ -248,6 +278,27 @@ namespace OHOS delete ResetOrMarkbutton; ResetOrMarkbutton = nullptr; } + if (LineImage != nullptr) + { + delete LineImage; + LineImage = nullptr; + } + if (list != nullptr) + { + delete list; + list = nullptr; + } + if (listadapter != nullptr) + { + delete listadapter; + listadapter = nullptr; + } + if (listdata != nullptr) + { + listdata->Clear(); + delete listdata; + listdata = nullptr; + } if (draglistener != nullptr) { delete draglistener; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp index 51c9cdd6c..24318e8e0 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp @@ -37,7 +37,6 @@ namespace OHOS scrollView1_->Resize(466, 466); scrollView1_->SetViewId("scrollView1"); scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - // container_->Add(scrollView1_); scrollView1_->SetVisible(true); /* -------------------------------------------------------------------------- */ if (label1_ == nullptr) @@ -96,7 +95,7 @@ namespace OHOS } button1_->SetPosition(0, 366); button1_->Resize(466, 100); - button1_->SetViewId("CycleToLimitReturnButton"); + button1_->SetViewId(CycleToLimitReturnButton_VIEWID); button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); char *button1defaultImgSrc = "/user/res/countdown/COUNTDOWN_BUTTON.bin"; @@ -111,19 +110,15 @@ namespace OHOS // Add to scrollView1 scrollView1_->Add(button1_); button1_->SetVisible(true); + viewInitStatus == true; return scrollView1_; } void StopWatchRecordCycleToLimitView::DeInitView() { - if (container_ != nullptr) - { - container_->RemoveAll(); - delete container_; - container_ = nullptr; - } if (scrollView1_ != nullptr) { + scrollView1_->RemoveAll(); delete scrollView1_; scrollView1_ = nullptr; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp index a9ce7de06..eaf3cb638 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp @@ -97,7 +97,7 @@ namespace OHOS } button1_->SetPosition(0, 366); button1_->Resize(466, 100); - button1_->SetViewId("TimeToLimitReturnButton"); + button1_->SetViewId(TimeToLimitReturnButton_VIEWID); button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); char *button1defaultImgSrc = "/user/res/countdown/COUNTDOWN_BUTTON.bin"; @@ -117,5 +117,31 @@ namespace OHOS void StopWatchRecordTimeToLimitView::DeInitView() { + if (scrollView1_ != nullptr) + { + scrollView1_->RemoveAll(); + delete scrollView1_; + scrollView1_ = nullptr; + } + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (image1_ != nullptr) + { + delete image1_; + image1_ = nullptr; + } + if (label3_ != nullptr) + { + delete label3_; + label3_ = nullptr; + } + if (button1_ != nullptr) + { + delete button1_; + button1_ = nullptr; + } } } \ No newline at end of file