From: luozheng <1732036298@qq.com> Date: Sun, 7 Apr 2024 09:24:37 +0000 (+0800) Subject: 1.实现秒表功能,制定计时时间如"99:59.99"不知道如何实现 X-Git-Tag: release_V1.2.70_20241020_135402~1229^2~1 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=781f6a809b902814bfe7847856a8f247b90f8e48;p=mirrors%2FFD230.git 1.实现秒表功能,制定计时时间如"99:59.99"不知道如何实现 2.在UiConfig.h更新了两张通用图片,将之前遗留的重复图片删除 --- diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h index 757e573d4..61bea2d6f 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h @@ -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"; diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp index 527843111..b98408148 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp @@ -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) diff --git a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/FastTrainingAttentionView.cpp b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/FastTrainingAttentionView.cpp index 35d0b96ef..7ef2532ef 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/FastTrainingAttentionView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/FastTrainingAttentionView.cpp @@ -77,7 +77,7 @@ namespace OHOS } image7_->SetPosition(193, 121); image7_->Resize(80, 80); - image7_->SetSrc(PNG_ORANGE_ATTENTION_VECTOR_IMAGE); + image7_->SetSrc(PNG_ATTENTION_IMAGE); // Add to scrollView1 scrollView1_->Add(image7_); diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h index ccb4d9e7c..253b6a2c7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-04 15:13:51 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-04 16:05:17 + * @LastEditTime: 2024-04-07 17:22:21 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h */ #ifndef MAIN_STOPWATCH_PRESENTER_H @@ -15,6 +15,9 @@ /*秒表主视图*/ namespace OHOS { + static constexpr int STOPWATCH_TIMER_DURATION = 10; // 定时器周期,每10毫秒定时器会触发一次 + static constexpr int MAX_RECORD_LOOPS = 99; // 最大记录圈数为99 + static const char *MAX_RECORD_TIME = "99:59.99"; // 最高记录时间为99:59.99 typedef enum { MAIN_STOPWATCH = 0, // 秒表主视图 @@ -42,6 +45,7 @@ namespace OHOS 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; @@ -57,8 +61,8 @@ namespace OHOS 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 + uint64_t lastRecordTime = 0; // 上次记录时间 + int RecordCycleNumber{0}; // 用来记录计时圈数 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h index 3af8a0e0b..e65e9b7ad 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-04 15:13:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-07 10:04:54 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h + */ #ifndef MAIN_STOPWATCH_VIEW_H #define MAIN_STOPWATCH_VIEW_H @@ -5,7 +12,7 @@ #include "View.h" #include "components/ui_view_group.h" #include "components/ui_scroll_view.h" -#include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_checkbox.h" #include "components/ui_button.h" #include "components/ui_list.h" @@ -46,31 +53,26 @@ namespace OHOS bool ChangeMainStopWatch(int16_t thisView); bool ChangeStopWatchRecordCycleLimit(int16_t thisView); bool ChangeMainStopWatchRecordTimeLimit(int16_t thisView); - + UILabelExt *GetShowTimelabel(void); private: void InitMainStopWatchView(void); - void DeInitView(void); - void PreLoad(void); + void ClearAll(void); private: StopWatchRecordCycleToLimitView *p_StopWatchRecordCycleToLimitView{nullptr}; // 圈数到达上限后弹出该视图 StopWatchRecordTimeToLimitView *p_StopWatchRecordTimeToLimitView{nullptr}; // 计时时间到达上限后弹出该视图 private: - UIViewGroup *container_ = nullptr; + UIViewGroup *group = nullptr; UIScrollView *scrollView[3] = {nullptr}; - UILabel *stopWatchlabel = nullptr; // 内容为“秒表”的标签 - UILabel *showTimelabel = nullptr; // 用来显示计时时间 + UILabelExt *stopWatchlabel = nullptr; // 内容为“秒表”的标签 + UILabelExt *showTimelabel = nullptr; // 用来显示计时时间 UICheckBox *PlayOrPausecheckBox = nullptr; // 播放或暂停复选框 UIButton *ResetOrMarkbutton = nullptr; // 重置或标记按钮 UIImageView *LineImage{nullptr}; UIList *list = nullptr; TextAdapter *listadapter = nullptr; List *listdata = nullptr; - UIView::OnDragListener *draglistener{nullptr}; - UICheckBox::OnChangeListener *PlayOrPausecheckBoxChangeListener{nullptr}; - UIView::OnClickListener *ResetOrMarkbuttonClick{nullptr}; - bool viewInitStatus{false}; }; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h index 66baa6de1..2eb3ba26f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-04 15:13:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-07 10:35:43 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h + */ #ifndef STOP_WATCH_MODEL_H #define STOP_WATCH_MODEL_H @@ -7,12 +14,18 @@ namespace OHOS { + class StopWatchModel { public: static std::shared_ptr GetInstance(); // shared_ptr:当没有引用指向这个实例时会自动释放内存 ~StopWatchModel() {} - char *DisplayMotionDuration(); + char *DisplayStopWatchDuration(); + void StopWatch_StartTimer(uint32_t interval); + void StopWatch_StopTimer(void); + void StopWatch_PauseTimer(); + void StopWatch_ResumeTimer(uint32_t interval); + private: // 将构造函数、拷贝构造函数和赋值操作符私有化 @@ -21,9 +34,7 @@ namespace OHOS StopWatchModel &operator=(const StopWatchModel &) = delete; private: - static int oneDaySec; // 一天的秒数 - static int oneHourSec; // 一个小时的秒数 - static int oneMinuteSec; // 一分钟秒数 + std::string stopwatchDuration; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h index 390fa0c36..1ccd6aa29 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-04 15:13:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-07 16:07:11 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h + */ #ifndef STOPWATCH_RECORD_CYCLE_TO_LIMIT_VIEW_H #define STOPWATCH_RECORD_CYCLE_TO_LIMIT_VIEW_H @@ -5,9 +12,9 @@ #include "View.h" #include "components/ui_view_group.h" #include "components/ui_scroll_view.h" -#include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_image_view.h" -#include "components/ui_button.h" +#include "components/ui_label_button_ext.h" /*弹窗视图:到达最高圈数99时弹出*/ namespace OHOS { @@ -16,19 +23,17 @@ namespace OHOS public: StopWatchRecordCycleToLimitView(); - void DeInitView(void); + void ClearAll(void); virtual ~StopWatchRecordCycleToLimitView(); static StopWatchRecordCycleToLimitView *GetInstance(void); UIScrollView *InitStopWatchRecordCycleToLimitView(void); private: - UIViewGroup *container_ = nullptr; - UIScrollView *scrollView1_ = nullptr; - UILabel *label1_ = nullptr; - UIImageView *image1_ = nullptr; - UILabel *label3_ = nullptr; - UIButton *button1_ = nullptr; - bool viewInitStatus{false}; + UIScrollView *scrollView = nullptr; + UILabelExt *Title = nullptr; + UIImageView *AttentionImage = nullptr; + UILabelExt *AttentionLabel = nullptr; + UILabelButtonExt *button = nullptr; }; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h index 22495f27c..98c3ecc5d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-04 15:13:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-07 16:28:41 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h + */ #ifndef STOPWATCH_RECORD_TIME_TO_LIMIT_VIEW_H #define STOPWATCH_RECORD_TIME_TO_LIMIT_VIEW_H @@ -5,9 +12,9 @@ #include "View.h" #include "components/ui_view_group.h" #include "components/ui_scroll_view.h" -#include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_image_view.h" -#include "components/ui_button.h" +#include "components/ui_label_button_ext.h" /*弹窗视图:到达最高时间99:59.99时弹出*/ namespace OHOS { @@ -18,15 +25,15 @@ namespace OHOS virtual ~StopWatchRecordTimeToLimitView(); static StopWatchRecordTimeToLimitView *GetInstance(void); UIScrollView *InitStopWatchRecordTimeToLimitView(void); - void DeInitView(void); + void ClearAll(void); private: - UIScrollView *scrollView1_ = nullptr; - UILabel *label1_ = nullptr; - UIImageView *image1_ = nullptr; - UILabel *label3_ = nullptr; - UIButton *button1_ = nullptr; - bool viewInitStatus{false}; + UIScrollView *scrollView = nullptr; + UILabelExt *Title = nullptr; + UIImageView *AttentionImage = nullptr; + UILabelExt *AttentionLabel_1 = nullptr; + UILabelExt *AttentionLabel_2 = nullptr; + UILabelButtonExt *button = nullptr; }; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp index 4c5e74255..8b4c1c6e3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -1,6 +1,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" #include "stopwatch/include/MainStopWatchPresenter.h" +#include "stopwatch/include/StopWatchModel.h" #include "common/key_code.h" #include /*秒表主视图*/ @@ -18,7 +19,7 @@ namespace OHOS MainStopWatchPresenter::~MainStopWatchPresenter() { - + StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 退出删除并清理定时器资源 g_pMainStopWatchPresenter = nullptr; } @@ -30,8 +31,8 @@ namespace OHOS void MainStopWatchPresenter::OnStart() { - Presenter::OnStart(); + ScreenAlwaysOnCtr(1); // 长亮屏 } void MainStopWatchPresenter::OnPause(void) @@ -48,8 +49,8 @@ namespace OHOS void MainStopWatchPresenter::OnStop(void) { - Presenter::OnStop(); + ScreenAlwaysOnCtr(0); // 取消长亮屏 } /// @brief 设置复选框和按钮 @@ -108,6 +109,45 @@ namespace OHOS return true; } + /* + * Converts a time string in the format "mm:ss.ms" to milliseconds. + * + * @param timeStr The time string to convert. + * @return The time in milliseconds. + */ + static unsigned long TimeStrToMilliseconds(const char *timeStr) + { + unsigned minutes, seconds, milliseconds; + + // Assuming the format is "mm:ss.ms" + if (sscanf(timeStr, "%u:%u.%u", &minutes, &seconds, &milliseconds) == 3) + { + // 将分钟转换为毫秒,将秒转换为毫秒,并将它们相加 + unsigned long totalMilliseconds = (minutes * 60 * 1000) + (seconds * 1000) + (milliseconds * 10); + return totalMilliseconds; + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Invalid time format."); + return 0; + } + } + + /*将毫秒级数转成格式为"mm:ss.ms"*/ + static void MillisecondsToTimeStr(unsigned long milliseconds, char *buffer) + { + unsigned minutes = milliseconds / (60 * 1000); + milliseconds %= (60 * 1000); // Remaining milliseconds after converting to minutes + unsigned seconds = milliseconds / 1000; + unsigned ms = milliseconds % 1000; // Remaining milliseconds after converting to seconds + + // Assuming ms needs to be in hundredths of a second for the ".ms" format + unsigned msHundredths = ms / 10; // Convert to hundredths of a second + + // Write the formatted time string to the buffer + sprintf(buffer, "%02u:%02u.%02u", minutes, seconds, msHundredths); + } + bool MainStopWatchPresenter::OnClick(UIView &view, const ClickEvent &event) { UNUSED(view); @@ -115,39 +155,67 @@ namespace OHOS const char *clickedViewId = view.GetViewId(); if (strcmp(clickedViewId, ResetOrMarkButton_MARK_VIEWID) == 0) { - RecordCycleNumber += 1; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordCycleNumber:%d\n",RecordCycleNumber); - if (RecordCycleNumber >= 99) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordCycleNumber:%d\n", RecordCycleNumber); + if (RecordCycleNumber >= MAX_RECORD_LOOPS) // 到达最高记录圈数 { + m_checkbox->SetState(UICheckBox::UNSELECTED); mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_CYCLE_TO_LIMIT); return true; } else { - mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false); - SetShowTimeLableStyle(m_showTimelabel, 93, 60, 65, 78); - mainStopWatchView->SetViewIsVisible(m_list, true); - mainStopWatchView->SetViewIsVisible(m_image, true); + RecordCycleNumber += 1; } + mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false); + SetShowTimeLableStyle(m_showTimelabel, 93, 60, 65, 78); + mainStopWatchView->SetViewIsVisible(m_list, true); + mainStopWatchView->SetViewIsVisible(m_image, true); + + uint64_t currentRecordTime = TimeStrToMilliseconds(MainStopWatchView::GetInstance()->GetShowTimelabel()->GetText()); // 获取当前时间 + uint64_t timeDifference = 0; // 时间差值 + if (lastRecordTime > 0) + { + // 如果不是第一次标记,则计算与上一次记录的时间差 + timeDifference = currentRecordTime - lastRecordTime; + } + // 将时间和时间差格式化为字符串,更新到UI + const char *formattedTime = MainStopWatchView::GetInstance()->GetShowTimelabel()->GetText(); + char formattedDiff[64] = {0}; + MillisecondsToTimeStr(timeDifference, formattedDiff); char *PickerData = (char *)malloc(128); - sprintf(PickerData, "0%d %s %s", RecordCycleNumber, "00:08:09", "+00:08:09"); - m_listdata->PushFront(static_cast(PickerData)); + if (lastRecordTime == 0) // 如果是第一次标记 + { + sprintf(PickerData, "0%d %s +%s", RecordCycleNumber, formattedTime, formattedTime); + } + else + { + sprintf(PickerData, "0%d %s +%s", RecordCycleNumber, formattedTime, formattedDiff); + } + m_listdata->PushFront(const_cast(PickerData)); m_listadapter->SetData(m_listdata); m_list->SetAdapter(m_listadapter); m_list->SetStartIndex(RecordCycleNumber - 1); m_list->SetSelectPosition(RecordCycleNumber); m_list->RefreshList(); + // 保存当前时间为“上一次记录时间”,为下一次标记做准备 + lastRecordTime = currentRecordTime; return true; } else if (strcmp(clickedViewId, ResetOrMarkButton_RESET2_VIEWID) == 0) { + StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 停止定时器 + mainStopWatchView->GetShowTimelabel()->SetText("00:00.00"); + lastRecordTime = 0; + m_button->SetViewId(ResetOrMarkButton_RESET1_VIEWID); m_button->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1); m_button->Invalidate(); mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, true); - SetShowTimeLableStyle(m_showTimelabel, 63, 160, 80, 94); + SetShowTimeLableStyle(m_showTimelabel, 68, 160, 84, 94); mainStopWatchView->SetViewIsVisible(m_image, false); + mainStopWatchView->SetViewIsVisible(m_list, false); + if (m_listdata != nullptr) { for (int i = 0; i < m_listdata->Size(); i++) @@ -157,8 +225,11 @@ namespace OHOS } m_listdata->Clear(); } - mainStopWatchView->SetViewIsVisible(m_list, false); - m_list->Invalidate(); + else + { + // Handle error or log the issue + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: m_listdata is nullptr"); + } RecordCycleNumber = 0; } else if (strcmp(clickedViewId, CycleToLimitReturnButton_VIEWID) == 0) @@ -174,14 +245,19 @@ namespace OHOS bool MainStopWatchPresenter::OnChange(UICheckBox::UICheckBoxState state) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnChange"); if (state == UICheckBox::UICheckBoxState::SELECTED) { + StopWatchModel::GetInstance()->StopWatch_StartTimer(STOPWATCH_TIMER_DURATION); // 开启定时器,如果定时器存在会直接返回 + StopWatchModel::GetInstance()->StopWatch_ResumeTimer(STOPWATCH_TIMER_DURATION); // 恢复定时器 + m_button->SetViewId(ResetOrMarkButton_MARK_VIEWID); - m_button->SetImageSrc(ResetOrMarkButtonImg_Mark, nullptr); + m_button->SetImageSrc(ResetOrMarkButtonImg_Mark, ResetOrMarkButtonImg_Mark); m_button->Invalidate(); // 图片重新赋值要刷新该区域 } else { + StopWatchModel::GetInstance()->StopWatch_PauseTimer(); // 暂停定时器 m_button->SetViewId(ResetOrMarkButton_RESET2_VIEWID); m_button->SetImageSrc(ResetOrMarkButtonImg_Reset2, nullptr); m_button->Invalidate(); @@ -192,7 +268,7 @@ namespace OHOS // 增加按键事件 bool MainStopWatchPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnKeyAct"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnKeyAct"); uint16_t keyID = event.GetKeyId(); uint16_t keyState = event.GetState(); // 如果是power键就返回上一级 diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp index 6c31fdcf8..abfe10889 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp @@ -3,6 +3,7 @@ #include "UiConfig.h" #include "NativeAbility.h" #include "AppViewIDs.h" +#include "wearable_log.h" /*秒表主视图*/ namespace OHOS { @@ -11,25 +12,101 @@ namespace OHOS MainStopWatchView::MainStopWatchView() { - + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::MainStopWatchView"); g_pMainStopWatchView = this; } MainStopWatchView::~MainStopWatchView() { - if (viewInitStatus == true) - { - DeInitView(); - } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::~MainStopWatchView"); + ClearAll(); g_pMainStopWatchView = nullptr; } MainStopWatchView *MainStopWatchView::GetInstance() { - return g_pMainStopWatchView; } + void MainStopWatchView::ClearAll() + { + group->RemoveAll(); + scrollView[MAIN_STOPWATCH]->RemoveAll(); + + if (stopWatchlabel != nullptr) + { + delete stopWatchlabel; + stopWatchlabel = nullptr; + } + + if (showTimelabel != nullptr) + { + delete showTimelabel; + showTimelabel = nullptr; + } + + if (PlayOrPausecheckBox != nullptr) + { + delete PlayOrPausecheckBox; + PlayOrPausecheckBox = nullptr; + } + + if (ResetOrMarkbutton != nullptr) + { + delete ResetOrMarkbutton; + ResetOrMarkbutton = nullptr; + } + + if (LineImage != nullptr) + { + delete LineImage; + LineImage = nullptr; + } + + if (list != nullptr) + { + delete list; + list = nullptr; + } + + if (listadapter != nullptr) + { + delete listadapter; + listadapter = nullptr; + } + + if (listdata != nullptr) + { + listdata->Clear(); + delete listdata; + listdata = nullptr; + } + + if (scrollView[MAIN_STOPWATCH] != nullptr) + { + delete scrollView[MAIN_STOPWATCH]; + scrollView[MAIN_STOPWATCH] = nullptr; + } + + if (p_StopWatchRecordCycleToLimitView != nullptr) + { + delete p_StopWatchRecordCycleToLimitView; + p_StopWatchRecordCycleToLimitView = nullptr; + } + + if (p_StopWatchRecordTimeToLimitView != nullptr) + { + delete p_StopWatchRecordTimeToLimitView; + p_StopWatchRecordTimeToLimitView = nullptr; + } + + if (group != nullptr) + { + delete group; + group = nullptr; + } + } + /// @brief 设置视图是否可见 /// @param view 具体视图 /// @param status true 可见 false 不可见 @@ -46,19 +123,23 @@ namespace OHOS view->Invalidate(); } - // 切换到秒表主视图 + // 1.切换到秒表主视图 bool MainStopWatchView::ChangeMainStopWatch(int16_t thisView) { - container_->Add(scrollView[thisView]); + if (scrollView[thisView] == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::ChangeMainStopWatch"); + group->Add(scrollView[thisView]); + } return true; } - // 切换到秒表到达最高圈数视图 + // 2.切换到秒表到达最高圈数视图 bool MainStopWatchView::ChangeStopWatchRecordCycleLimit(int16_t thisView) { if (scrollView[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainAlarmView::StopWatchRecordCycleToLimitView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::StopWatchRecordCycleToLimitView"); p_StopWatchRecordCycleToLimitView = new StopWatchRecordCycleToLimitView(); if (p_StopWatchRecordCycleToLimitView == nullptr) { @@ -66,17 +147,17 @@ namespace OHOS return false; } scrollView[thisView] = p_StopWatchRecordCycleToLimitView->InitStopWatchRecordCycleToLimitView(); - container_->Add(scrollView[thisView]); + group->Add(scrollView[thisView]); } return true; } - // 切换到秒表到达最大时间计时视图 + // 3.切换到秒表到达最大时间计时视图 bool MainStopWatchView::ChangeMainStopWatchRecordTimeLimit(int16_t thisView) { if (scrollView[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainAlarmView::ChangeMainStopWatchRecordTimeLimit"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchView::ChangeMainStopWatchRecordTimeLimit"); p_StopWatchRecordTimeToLimitView = new StopWatchRecordTimeToLimitView(); if (p_StopWatchRecordTimeToLimitView == nullptr) { @@ -84,7 +165,7 @@ namespace OHOS return false; } scrollView[thisView] = p_StopWatchRecordTimeToLimitView->InitStopWatchRecordTimeToLimitView(); - container_->Add(scrollView[thisView]); + group->Add(scrollView[thisView]); } return true; } @@ -97,11 +178,11 @@ 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}}; + static const MainStopWatchViewMapper ViewMapper[] = { + {MAIN_STOPWATCH, &MainStopWatchView::ChangeMainStopWatch}, + {STOPWATCH_RECORD_CYCLE_TO_LIMIT, &MainStopWatchView::ChangeStopWatchRecordCycleLimit}, + {STOPWATCH_RECORD_TIME_TO_LIMIT, &MainStopWatchView::ChangeMainStopWatchRecordTimeLimit}, + }; // 3.根据传入的interface参数执行相应视图ID关联的成员函数。 bool MainStopWatchView::ClickFunc(int16_t interface) @@ -139,231 +220,165 @@ namespace OHOS // 初始化秒表主视图 void MainStopWatchView::InitMainStopWatchView() { - if (scrollView[MAIN_STOPWATCH] == nullptr) - { - scrollView[MAIN_STOPWATCH] = new UIScrollView(); - } - scrollView[MAIN_STOPWATCH]->SetPosition(0, 0); - scrollView[MAIN_STOPWATCH]->Resize(466, 466); - scrollView[MAIN_STOPWATCH]->SetViewId("scrollView1"); - scrollView[MAIN_STOPWATCH]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - container_->Add(scrollView[MAIN_STOPWATCH]); - scrollView[MAIN_STOPWATCH]->SetVisible(true); - /* -------------------------------------------------------------------------- */ - if (stopWatchlabel == nullptr) - { - stopWatchlabel = new UILabel(); - } - stopWatchlabel->SetPosition(203, 52); - stopWatchlabel->Resize(60, 35); - stopWatchlabel->SetViewId("label1"); - stopWatchlabel->SetStyle(STYLE_TEXT_FONT, 30); - stopWatchlabel->SetStyle(STYLE_LINE_HEIGHT, 35); - stopWatchlabel->SetText("秒表"); - stopWatchlabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - stopWatchlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - stopWatchlabel->SetRollSpeed(0); - stopWatchlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - scrollView[MAIN_STOPWATCH]->Add(stopWatchlabel); - stopWatchlabel->SetVisible(true); - /* -------------------------------------------------------------------------- */ - if (showTimelabel == nullptr) - { - showTimelabel = new UILabel(); - } - showTimelabel->SetPosition(63, 160); - showTimelabel->Resize(200, 60); - showTimelabel->SetViewId("showTimelabel"); - showTimelabel->SetStyle(STYLE_TEXT_FONT, 80); - showTimelabel->SetStyle(STYLE_LINE_HEIGHT, 94); - showTimelabel->SetText("00:00.00"); - showTimelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - showTimelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - showTimelabel->SetRollSpeed(0); - showTimelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 80); - scrollView[MAIN_STOPWATCH]->Add(showTimelabel); - showTimelabel->SetVisible(true); - /* -------------------------------------------------------------------------- */ - if (LineImage == nullptr) + if (group == nullptr) { + /* ---------------------------------- group --------------------------------- */ + group = new UIViewGroup(); + if (group == nullptr) + { + return; + } + group->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + UIView::OnDragListener *draglistener = static_cast(MainStopWatchPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + group->SetOnDragListener(draglistener); + group->SetTouchable(true); + group->SetDraggable(true); + /* ----------------------- scrollView[MAIN_STOPWATCH] ----------------------- */ + if (scrollView[MAIN_STOPWATCH] == nullptr) + { + scrollView[MAIN_STOPWATCH] = new UIScrollView(); + } + scrollView[MAIN_STOPWATCH]->SetPosition(0, 0, 466, 466); + scrollView[MAIN_STOPWATCH]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + /* ----------------------------- stopWatchlabel ----------------------------- */ + stopWatchlabel = new UILabelExt(); + if (stopWatchlabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stopWatchlabel new fail!!"); + return; + } + stopWatchlabel->SetPosition(83, 52, 300, 40); + stopWatchlabel->SetStyle(STYLE_TEXT_FONT, 30); + stopWatchlabel->SetStyle(STYLE_LINE_HEIGHT, 35); + stopWatchlabel->SetText("秒表"); + stopWatchlabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + stopWatchlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + stopWatchlabel->SetRollSpeed(40); + stopWatchlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + stopWatchlabel->SetVisible(true); + /* ------------------------------ showTimelabel ----------------------------- */ + showTimelabel = new UILabelExt(); + if (showTimelabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showTimelabel new fail!!"); + return; + } + showTimelabel->SetPosition(68, 160); + showTimelabel->SetStyle(STYLE_TEXT_FONT, 84); + showTimelabel->SetStyle(STYLE_LINE_HEIGHT, 94); + showTimelabel->SetText("00:00.00"); + showTimelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + showTimelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + showTimelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 84); + /* -------------------------------- LineImage ------------------------------- */ 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) - { + if (LineImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LineImage new fail!!"); + return; + } + LineImage->SetPosition(53, 150); + const char *imageimagesPath = "/user/res/stopwatch/STOPWATCH_LINE.bin"; + LineImage->SetSrc(imageimagesPath); + LineImage->SetVisible(false); + /* ---------------------------------- list ---------------------------------- */ list = new UIList(); - } - list->SetPosition(56, 170, 360, 100); - list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - list->SetReboundSize(30); - if (listadapter == nullptr) - { + if (list == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail!!"); + return; + } + list->SetPosition(56, 170, 360, 100); + list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + list->SetReboundSize(30); + list->SetVisible(false); + /* ------------------------------- listadapter ------------------------------ */ listadapter = new TextAdapter(); - } - listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); - if (listdata == nullptr) - { + if (listadapter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "listadapter new fail!!"); + return; + } + listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + /* -------------------------------- listdata -------------------------------- */ listdata = new List(); - } - scrollView[MAIN_STOPWATCH]->Add(list); - list->SetVisible(false); - /* -------------------------------------------------------------------------- */ - // Add CheckBox to App - if (PlayOrPausecheckBox == nullptr) - { + if (listdata == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "listdata new fail!!"); + return; + } + /* --------------------------- PlayOrPausecheckBox -------------------------- */ PlayOrPausecheckBox = new UICheckBox(); - } - PlayOrPausecheckBox->SetPosition(118, 321); - PlayOrPausecheckBox->Resize(120, 120); - PlayOrPausecheckBox->SetViewId(PlayOrPausecheckBoxVIEWID); - PlayOrPausecheckBox->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - PlayOrPausecheckBox->SetStyle(STYLE_BORDER_RADIUS, 51); - PlayOrPausecheckBox->SetImages(checkBox1selectedImg, checkBox1unSelectedImg); - // Add to scrollView1 - scrollView[MAIN_STOPWATCH]->Add(PlayOrPausecheckBox); - PlayOrPausecheckBox->SetVisible(true); - /* -------------------------------------------------------------------------- */ - // Add Button to App - if (ResetOrMarkbutton == nullptr) - { + if (PlayOrPausecheckBox == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayOrPausecheckBox new fail!!"); + return; + } + PlayOrPausecheckBox->SetPosition(118, 321, 120, 120); + PlayOrPausecheckBox->SetViewId(PlayOrPausecheckBoxVIEWID); + PlayOrPausecheckBox->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + PlayOrPausecheckBox->SetStyle(STYLE_BORDER_RADIUS, 51); + PlayOrPausecheckBox->SetImages(checkBox1selectedImg, checkBox1unSelectedImg); + PlayOrPausecheckBox->SetVisible(true); + /* ---------------------------- ResetOrMarkbutton --------------------------- */ ResetOrMarkbutton = new UIButton(); + if (ResetOrMarkbutton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ResetOrMarkbutton new fail!!"); + return; + } + ResetOrMarkbutton->SetPosition(256, 333, 100, 100); + ResetOrMarkbutton->SetViewId(ResetOrMarkButton_RESET1_VIEWID); + ResetOrMarkbutton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + ResetOrMarkbutton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + ResetOrMarkbutton->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1); + ResetOrMarkbutton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + ResetOrMarkbutton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + ResetOrMarkbutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + ResetOrMarkbutton->SetVisible(true); + /* -------------------------------------------------------------------------- */ + MainStopWatchPresenter::GetInstance()->SetCheckBoxAndButton(PlayOrPausecheckBox, ResetOrMarkbutton); + MainStopWatchPresenter::GetInstance()->SetLable(stopWatchlabel, showTimelabel); + MainStopWatchPresenter::GetInstance()->SetImage(LineImage); + MainStopWatchPresenter::GetInstance()->SetList(list, listadapter, listdata); + // Add the CallBack about events + UICheckBox::OnChangeListener *PlayOrPausecheckBoxChangeListener = static_cast(MainStopWatchPresenter::GetInstance()); + PlayOrPausecheckBox->SetOnChangeListener(PlayOrPausecheckBoxChangeListener); + UIView::OnClickListener *ResetOrMarkbuttonClick = static_cast(MainStopWatchPresenter::GetInstance()); + ResetOrMarkbutton->SetOnClickListener(ResetOrMarkbuttonClick); } - ResetOrMarkbutton->SetPosition(256, 333); - ResetOrMarkbutton->Resize(100, 100); - ResetOrMarkbutton->SetViewId(ResetOrMarkButton_RESET1_VIEWID); - ResetOrMarkbutton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - ResetOrMarkbutton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - ResetOrMarkbutton->SetImageSrc(ResetOrMarkButtonImg_Reset1, nullptr); - ResetOrMarkbutton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); - ResetOrMarkbutton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); - ResetOrMarkbutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - scrollView[MAIN_STOPWATCH]->Add(ResetOrMarkbutton); - ResetOrMarkbutton->SetVisible(true); - /* -------------------------------------------------------------------------- */ - MainStopWatchPresenter::GetInstance()->SetCheckBoxAndButton(PlayOrPausecheckBox, ResetOrMarkbutton); - MainStopWatchPresenter::GetInstance()->SetLable(stopWatchlabel, showTimelabel); - MainStopWatchPresenter::GetInstance()->SetImage(LineImage); - MainStopWatchPresenter::GetInstance()->SetList(list, listadapter, listdata); - // Add the CallBack about events - PlayOrPausecheckBoxChangeListener = static_cast(MainStopWatchPresenter::GetInstance()); - PlayOrPausecheckBox->SetOnChangeListener(PlayOrPausecheckBoxChangeListener); - ResetOrMarkbuttonClick = static_cast(MainStopWatchPresenter::GetInstance()); - ResetOrMarkbutton->SetOnClickListener(ResetOrMarkbuttonClick); } - void MainStopWatchView::DeInitView() + UILabelExt *MainStopWatchView::GetShowTimelabel(void) { - if (stopWatchlabel != nullptr) - { - delete stopWatchlabel; - stopWatchlabel = nullptr; - } - if (showTimelabel != nullptr) - { - delete showTimelabel; - showTimelabel = nullptr; - } - if (PlayOrPausecheckBox != nullptr) - { - delete PlayOrPausecheckBox; - PlayOrPausecheckBox = nullptr; - } - if (ResetOrMarkbutton != nullptr) - { - delete ResetOrMarkbutton; - ResetOrMarkbutton = nullptr; - } - if (LineImage != nullptr) - { - delete LineImage; - LineImage = nullptr; - } - if (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; - draglistener = nullptr; - } - if (PlayOrPausecheckBoxChangeListener != nullptr) - { - delete PlayOrPausecheckBoxChangeListener; - PlayOrPausecheckBoxChangeListener = nullptr; - } - if (ResetOrMarkbuttonClick != nullptr) - { - delete ResetOrMarkbuttonClick; - ResetOrMarkbuttonClick = nullptr; - } - if (scrollView[MAIN_STOPWATCH] != nullptr) - { - delete scrollView[MAIN_STOPWATCH]; - scrollView[MAIN_STOPWATCH] = nullptr; - } - if (container_ != nullptr) - { - container_->RemoveAll(); - delete container_; - container_ = nullptr; - } - } - void MainStopWatchView::PreLoad(void) - { - if (!viewInitStatus) - { - InitMainStopWatchView(); - viewInitStatus = true; - } + return showTimelabel; } + void MainStopWatchView::OnStart() { - // container_容器属性 new - container_ = new UIViewGroup(); - if (container_ == nullptr) - { - return; - } - // container_容器属性 扩展 - container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - draglistener = static_cast(MainStopWatchPresenter::GetInstance()); - if (draglistener == nullptr) - { - return; - } - container_->SetOnDragListener(draglistener); - container_->SetTouchable(true); - container_->SetDraggable(true); - PreLoad(); - RootView::GetInstance()->Add(container_); + View::OnStart(); + InitMainStopWatchView(); // 增加按键监听 RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainStopWatchPresenter::GetInstance(); RootView::GetInstance()->SetOnKeyActListener(keyactListener); - RootView::GetInstance()->SetIntercept(true); } void MainStopWatchView::OnSetUpView() { View::OnSetUpView(); + scrollView[MAIN_STOPWATCH]->Add(stopWatchlabel); + scrollView[MAIN_STOPWATCH]->Add(showTimelabel); + scrollView[MAIN_STOPWATCH]->Add(LineImage); + scrollView[MAIN_STOPWATCH]->Add(list); + scrollView[MAIN_STOPWATCH]->Add(PlayOrPausecheckBox); + scrollView[MAIN_STOPWATCH]->Add(ResetOrMarkbutton); + group->Add(scrollView[MAIN_STOPWATCH]); + RootView::GetInstance()->Add(group); Draw(); } @@ -378,7 +393,7 @@ namespace OHOS { View::OnStop(); - RootView::GetInstance()->ClearOnKeyActListener(); + RootView::GetInstance()->ClearOnKeyActListener(); RootView::GetInstance()->RemoveAll(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp index bb4f2be89..00d39948c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp @@ -1,12 +1,14 @@ #include "stopwatch/include/StopWatchModel.h" #include "cmsis_os2.h" #include "cmsis_os.h" - +#include +#include +#include "custom_utils.h" +#include "wearable_log.h" +#include +#include "stopwatch/include/MainStopWatchView.h" namespace OHOS { - int StopWatchModel::oneDaySec = 86400; // 一天的秒数 - int StopWatchModel::oneHourSec = 3600; // 一个小时的秒数 - int StopWatchModel::oneMinuteSec = 60; // 一分钟秒数 std::shared_ptr StopWatchModel::GetInstance() // shared_ptr:当没有引用指向这个实例时会自动释放内存 { @@ -14,8 +16,213 @@ namespace OHOS return instance; } - /* 时间显示 */ - char *StopWatchModel::DisplayMotionDuration() + /* ----------------------------------- 定时器 ---------------------------------- */ + // 声明定时器变量 + static osTimerId_t g_timer = NULL; + static int g_StopWatchTimes = {0}; + static constexpr int32 NUM_TEN = 10; + static constexpr int16 ERROR = 0; + static constexpr int16 SUCCESS = 1; + static constexpr int16 NUM_TIME_MIN = 60; + static constexpr int16 NUM_TIME_HOUR = 3600; + static constexpr int32 NUM_TIME_DAY = 86400; + static uint64_t g_timerStartTimestamp = 0; // 添加一个全局变量来存储定时器开始的时间戳 + /* + * @brief 显示倒计时(分钟、秒、毫秒),毫秒显示为两位数 + */ + char *StopWatchModel::DisplayStopWatchDuration() + { + stopwatchDuration.erase(); + std::string minute; + std::string seconds; + std::string milliseconds; + + // 假设 g_StopWatchTimes 是毫秒数 + int min = g_StopWatchTimes / (60 * 1000); // 60,000 毫秒 = 1 分钟 + int sec = (g_StopWatchTimes % (60 * 1000)) / 1000; // 1,000 毫秒 = 1 秒 + int msec = (g_StopWatchTimes % 1000) / 10; // 获得两位数的毫秒,最大值为99 + + if (min < 10) + { + minute = "0" + std::to_string(min); + } + else + { + minute = std::to_string(min); + } + + if (sec < 10) + { + seconds = "0" + std::to_string(sec); + } + else + { + seconds = std::to_string(sec); + } + + // 格式化毫秒为两位数 + if (msec < 10) + { + milliseconds = "0" + std::to_string(msec); + } + else + { + milliseconds = std::to_string(msec); + } + + // 拼接分钟、秒和毫秒 + stopwatchDuration = minute + ":" + seconds + "." + milliseconds; + + return (char *)stopwatchDuration.c_str(); + } + + /* + * @brief 在这里添加定时器到期后的处理逻辑 + */ + static void StopWatch_TimerCallbackProc(int data) + { + g_StopWatchTimes += 10; // 每次回调增加10毫秒 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_StopWatchTimes:%d\n", g_StopWatchTimes); + + if (MainStopWatchView::GetInstance() == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[StopWatch_TimerCallbackProc] GetInstance is NULL"); + return; + } + + if (MainStopWatchView::GetInstance()->GetShowTimelabel() == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[StopWatch_TimerCallbackProc] GetInstance()->GetShowTimelabel is NULL"); + return; + } + + if (StopWatchModel::GetInstance()->DisplayStopWatchDuration() == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[StopWatch_TimerCallbackProc] DisplayStopWatchDuration is NULL"); + return; + } + + MainStopWatchView::GetInstance()->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration()); + } + + /* + * @brief 倒计时回调函数 + */ + static void StopWatch_TimerCallback(int data) + { +#if 0 + uint64_t currentTimestamp = GetCurrentTimestamp(); + if ((currentTimestamp - g_timerStartTimestamp) >= 5999099) // 99分59秒99的毫秒数 + { + if (g_timer != NULL) + { + osTimerStop(g_timer); // 停止定时器 + osTimerDelete(g_timer); // 删除定时器 + g_timer = NULL; + g_timerStartTimestamp = 0; // 重置时间戳 + // 可以在这里添加额外的逻辑,比如更新界面显示等 + } + } + else + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data)); + } +#endif + GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data)); + } + + /* + * @brief 开启定时器函数 + * @param interval 时间间隔,单位ms + */ + void StopWatchModel::StopWatch_StartTimer(uint32_t interval) + { + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_timer != NULL) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopWatchModel::StopWatch_StartTimer Timer already exists!!"); + return; + } + + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_timer = osTimerNew((osTimerFunc_t)StopWatch_TimerCallback, osTimerPeriodic, NULL, NULL); + // 检查定时器创建是否成功 + if (g_timer == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopWatchModel::StopWatch_StartTimer Timer create failed!!"); + return; + } + + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + + /* --------------------------------- 4.启动定时器 -------------------------------- */ + //g_timerStartTimestamp = GetCurrentTimestamp(); // 假设GetCurrentTimestamp()是获取当前时间戳的函数 + osStatus_t ret = osTimerStart(g_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); + if (g_timer != NULL) + { + ret = osTimerDelete(g_timer); + return; + } + g_timer = NULL; + } + return; + } + + /* + * @brief 停止定时器 + */ + void StopWatchModel::StopWatch_StopTimer(void) + { + // 检查定时器是否存在 + if (g_timer != NULL) + { + // 删除定时器并置为 NULL + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = NULL; + g_StopWatchTimes = 0; + } + } + /* + * @brief 暂停定时器 + */ + void StopWatchModel::StopWatch_PauseTimer(void) + { + // 检查定时器是否存在 + if (g_timer != NULL) + { + // 暂停定时器,但不删除它 + osStatus_t ret = osTimerStop(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopWatch_PauseTimer osTimerStop failed, ret = %lx!!", ret); + } + } + } + + /* + * @brief 恢复定时器 + */ + void StopWatchModel::StopWatch_ResumeTimer(uint32_t interval) { + // 检查定时器是否存在 + if (g_timer != NULL) + { + int tick = osMs2Tick(interval); + // 恢复定时器 + osStatus_t ret = osTimerStart(g_timer, tick); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopWatch_ResumeTimer osTimerStart failed, ret = %lx!!", ret); + } + } } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp index 24318e8e0..feca45ee8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp @@ -1,5 +1,6 @@ #include "stopwatch/include/StopWatchRecordCycleToLimitView.h" #include "stopwatch/include/MainStopWatchPresenter.h" +#include "UiConfig.h" /*弹窗视图:到达最高圈数99时弹出*/ namespace OHOS { @@ -14,10 +15,7 @@ namespace OHOS StopWatchRecordCycleToLimitView::~StopWatchRecordCycleToLimitView() { - if (viewInitStatus == true) - { - DeInitView(); - } + ClearAll(); g_pStopWatchRecordCycleToLimitView = nullptr; } @@ -29,118 +27,98 @@ namespace OHOS // 初始化秒表到达最高圈数时弹出的视图 UIScrollView *StopWatchRecordCycleToLimitView::InitStopWatchRecordCycleToLimitView() { - if (scrollView1_ == nullptr) - { - scrollView1_ = new UIScrollView(); - } - scrollView1_->SetPosition(0, 0); - scrollView1_->Resize(466, 466); - scrollView1_->SetViewId("scrollView1"); - scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - scrollView1_->SetVisible(true); - /* -------------------------------------------------------------------------- */ - if (label1_ == nullptr) + if (scrollView == nullptr) { - label1_ = new UILabel(); - } - label1_->SetPosition(203, 52); - label1_->Resize(60, 35); - label1_->SetViewId("label1"); - label1_->SetStyle(STYLE_TEXT_FONT, 30); - label1_->SetStyle(STYLE_LINE_HEIGHT, 35); - label1_->SetText("秒表"); - label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label1_->SetRollSpeed(0); - label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - scrollView1_->Add(label1_); - label1_->SetVisible(true); - /* -------------------------------------------------------------------------- */ - if (image1_ == nullptr) - { - image1_ = new UIImageView(); - } - image1_->SetPosition(193, 121); - image1_->Resize(100, 100); - image1_->SetViewId("image1"); - image1_->SetStyle(STYLE_BORDER_RADIUS, 100); - char *image1imagesPath = "/user/res/countdown/COUNTDOWN_ATTENTION.bin"; - image1_->SetSrc(image1imagesPath); - scrollView1_->Add(image1_); - image1_->SetVisible(true); - /* -------------------------------------------------------------------------- */ - // Add Label to App - if (label3_ == nullptr) - { - label3_ = new UILabel(); - } - label3_->SetPosition(83, 253); - label3_->Resize(300, 35); - label3_->SetViewId("label3"); - label3_->SetStyle(STYLE_TEXT_FONT, 30); - label3_->SetStyle(STYLE_LINE_HEIGHT, 35); - label3_->SetText("当前已达到了最高圈数"); - label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label3_->SetRollSpeed(0); - label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - // Add to scrollView1 - scrollView1_->Add(label3_); - label3_->SetVisible(true); - /* -------------------------------------------------------------------------- */ - // Add Button to App - if (button1_ == nullptr) - { - button1_ = new UIButton(); - } - button1_->SetPosition(0, 366); - button1_->Resize(466, 100); - button1_->SetViewId(CycleToLimitReturnButton_VIEWID); - button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - char *button1defaultImgSrc = "/user/res/countdown/COUNTDOWN_BUTTON.bin"; - button1_->SetImageSrc(button1defaultImgSrc, nullptr); - button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); - button1_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); - button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + scrollView = new UIScrollView(); - // Add the CallBack about events - UIView::OnClickListener *button1Click = static_cast(MainStopWatchPresenter::GetInstance()); - button1_->SetOnClickListener(button1Click); - // Add to scrollView1 - scrollView1_->Add(button1_); - button1_->SetVisible(true); - viewInitStatus == true; - return scrollView1_; + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + /* -------------------------------------------------------------------------- */ + if (Title == nullptr) + { + Title = new UILabelExt(); + } + Title->SetPosition(83, 52, 300, 40); + Title->SetStyle(STYLE_TEXT_FONT, 30); + Title->SetStyle(STYLE_LINE_HEIGHT, 35); + Title->SetText("秒表"); + Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Title->SetRollSpeed(40); + Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + if (AttentionImage == nullptr) + { + AttentionImage = new UIImageView(); + } + AttentionImage->SetPosition(193, 121, 100, 100); + AttentionImage->SetStyle(STYLE_BORDER_RADIUS, 100); + AttentionImage->SetSrc(PNG_ATTENTION_IMAGE); + /* -------------------------------------------------------------------------- */ + if (AttentionLabel == nullptr) + { + AttentionLabel = new UILabelExt(); + } + AttentionLabel->SetPosition(83, 253, 300, 40); + AttentionLabel->SetStyle(STYLE_TEXT_FONT, 30); + AttentionLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + AttentionLabel->SetText("当前已达到了最高圈数"); + AttentionLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + AttentionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AttentionLabel->SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff)); + AttentionLabel->SetRollSpeed(40); + AttentionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + if (button == nullptr) + { + button = new UILabelButtonExt(); + } + button->SetPosition(0, 366, 466, 100); + button->SetViewId(CycleToLimitReturnButton_VIEWID); + button->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE); + button->SetText("知道了"); + button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + button->SetStyle(STYLE_LINE_HEIGHT, 35); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + UIView::OnClickListener *buttonClick = static_cast(MainStopWatchPresenter::GetInstance()); + button->SetOnClickListener(buttonClick); + /* ----------------------------------- Add ---------------------------------- */ + scrollView->Add(Title); + scrollView->Add(AttentionImage); + scrollView->Add(AttentionLabel); + scrollView->Add(button); + } + return scrollView; } - void StopWatchRecordCycleToLimitView::DeInitView() + void StopWatchRecordCycleToLimitView::ClearAll() { - if (scrollView1_ != nullptr) + scrollView->RemoveAll(); + + if (Title != nullptr) { - scrollView1_->RemoveAll(); - delete scrollView1_; - scrollView1_ = nullptr; + delete Title; + Title = nullptr; } - if (label1_ != nullptr) + if (AttentionImage != nullptr) { - delete label1_; - label1_ = nullptr; + delete AttentionImage; + AttentionImage = nullptr; } - if (image1_ != nullptr) + if (AttentionLabel != nullptr) { - delete image1_; - image1_ = nullptr; + delete AttentionLabel; + AttentionLabel = nullptr; } - if (label3_ != nullptr) + if (button != nullptr) { - delete label3_; - label3_ = nullptr; + delete button; + button = nullptr; } - if (button1_ != nullptr) + if (scrollView != nullptr) { - delete button1_; - button1_ = nullptr; + delete scrollView; + scrollView = nullptr; } } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp index eaf3cb638..241bd2cbb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp @@ -10,16 +10,12 @@ namespace OHOS StopWatchRecordTimeToLimitView::StopWatchRecordTimeToLimitView() { - g_pStopWatchRecordTimeToLimitView = this; } StopWatchRecordTimeToLimitView::~StopWatchRecordTimeToLimitView() { - if (viewInitStatus == true) - { - DeInitView(); - } + ClearAll(); g_pStopWatchRecordTimeToLimitView = nullptr; } @@ -31,117 +27,111 @@ namespace OHOS UIScrollView *StopWatchRecordTimeToLimitView::InitStopWatchRecordTimeToLimitView() { - if (scrollView1_ == nullptr) - { - scrollView1_ = new UIScrollView(); - } - scrollView1_->SetPosition(0, 0); - scrollView1_->Resize(466, 466); - scrollView1_->SetViewId("scrollView1"); - scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - scrollView1_->SetVisible(true); - /* -------------------------------------------------------------------------- */ - if (label1_ == nullptr) - { - label1_ = new UILabel(); - } - label1_->SetPosition(203, 52); - label1_->Resize(60, 35); - label1_->SetViewId("label1"); - label1_->SetStyle(STYLE_TEXT_FONT, 30); - label1_->SetStyle(STYLE_LINE_HEIGHT, 35); - label1_->SetText("秒表"); - label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label1_->SetRollSpeed(0); - label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - scrollView1_->Add(label1_); - label1_->SetVisible(true); - /* -------------------------------------------------------------------------- */ - if (image1_ == nullptr) - { - image1_ = new UIImageView(); - } - image1_->SetPosition(193, 121); - image1_->Resize(100, 100); - image1_->SetViewId("image1"); - image1_->SetStyle(STYLE_BORDER_RADIUS, 100); - char *image1imagesPath = "/user/res/countdown/COUNTDOWN_ATTENTION.bin"; - image1_->SetSrc(image1imagesPath); - scrollView1_->Add(image1_); - image1_->SetVisible(true); - /* -------------------------------------------------------------------------- */ - // Add Label to App - if (label3_ == nullptr) - { - label3_ = new UILabel(); - } - label3_->SetPosition(53, 235); - label3_->Resize(300, 35); - label3_->SetViewId("label3"); - label3_->SetStyle(STYLE_TEXT_FONT, 30); - label3_->SetStyle(STYLE_LINE_HEIGHT, 35); - label3_->SetText("当前已达到了最长时间\n表秒自动暂停,请重新开始"); - label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label3_->SetRollSpeed(0); - label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - // Add to scrollView1 - scrollView1_->Add(label3_); - label3_->SetVisible(true); - /* -------------------------------------------------------------------------- */ - // Add Button to App - if (button1_ == nullptr) + if (scrollView == nullptr) { - button1_ = new UIButton(); + scrollView = new UIScrollView(); + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + /* -------------------------------------------------------------------------- */ + if (Title == nullptr) + { + Title = new UILabelExt(); + } + Title->SetPosition(83, 52, 300, 40); + Title->SetStyle(STYLE_TEXT_FONT, 30); + Title->SetStyle(STYLE_LINE_HEIGHT, 35); + Title->SetText("秒表"); + Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Title->SetRollSpeed(40); + Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + if (AttentionImage == nullptr) + { + AttentionImage = new UIImageView(); + } + AttentionImage->SetPosition(193, 121, 100, 100); + AttentionImage->SetStyle(STYLE_BORDER_RADIUS, 100); + AttentionImage->SetSrc(PNG_ATTENTION_IMAGE); + /* ---------------------------- AttentionLabel_1 ---------------------------- */ + if (AttentionLabel_1 == nullptr) + { + AttentionLabel_1 = new UILabelExt(); + } + AttentionLabel_1->SetPosition(83, 235, 300, 40); + AttentionLabel_1->SetStyle(STYLE_TEXT_FONT, 30); + AttentionLabel_1->SetStyle(STYLE_LINE_HEIGHT, 35); + AttentionLabel_1->SetText("当前已达到了最长时间"); + AttentionLabel_1->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + AttentionLabel_1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AttentionLabel_1->SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff)); + AttentionLabel_1->SetRollSpeed(40); + AttentionLabel_1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ---------------------------- AttentionLabel_2 ---------------------------- */ + if (AttentionLabel_2 == nullptr) + { + AttentionLabel_2 = new UILabelExt(); + } + AttentionLabel_2->SetPosition(33, 279, 400, 40); + AttentionLabel_2->SetStyle(STYLE_TEXT_FONT, 30); + AttentionLabel_2->SetStyle(STYLE_LINE_HEIGHT, 35); + AttentionLabel_2->SetText("表秒自动暂停,请重新开始"); + AttentionLabel_2->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + AttentionLabel_2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AttentionLabel_2->SetTextColor(Color::GetColorFromRGBA(0xaa, 0xaa, 0xaa, 0xff)); + AttentionLabel_2->SetRollSpeed(40); + AttentionLabel_2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + if (button == nullptr) + { + button = new UILabelButtonExt(); + } + button->SetPosition(0, 366, 466, 100); + button->SetViewId(TimeToLimitReturnButton_VIEWID); + button->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE); + button->SetText("知道了"); + button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + button->SetStyle(STYLE_LINE_HEIGHT, 35); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + UIView::OnClickListener *buttonClick = static_cast(MainStopWatchPresenter::GetInstance()); + button->SetOnClickListener(buttonClick); + /* ----------------------------------- Add ---------------------------------- */ + scrollView->Add(Title); + scrollView->Add(AttentionImage); + scrollView->Add(AttentionLabel_1); + scrollView->Add(AttentionLabel_2); + scrollView->Add(button); } - button1_->SetPosition(0, 366); - button1_->Resize(466, 100); - button1_->SetViewId(TimeToLimitReturnButton_VIEWID); - button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - char *button1defaultImgSrc = "/user/res/countdown/COUNTDOWN_BUTTON.bin"; - button1_->SetImageSrc(button1defaultImgSrc, nullptr); - button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); - button1_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); - button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - // Add the CallBack about events - UIView::OnClickListener *button1Click = static_cast(MainStopWatchPresenter::GetInstance()); - button1_->SetOnClickListener(button1Click); - // Add to scrollView1 - scrollView1_->Add(button1_); - button1_->SetVisible(true); - viewInitStatus = true; - return scrollView1_; + return scrollView; } - void StopWatchRecordTimeToLimitView::DeInitView() + void StopWatchRecordTimeToLimitView::ClearAll() { - if (scrollView1_ != nullptr) + scrollView->RemoveAll(); + if (Title != nullptr) { - scrollView1_->RemoveAll(); - delete scrollView1_; - scrollView1_ = nullptr; + delete Title; + Title = nullptr; } - if (label1_ != nullptr) + if (AttentionImage != nullptr) { - delete label1_; - label1_ = nullptr; + delete AttentionImage; + AttentionImage = nullptr; } - if (image1_ != nullptr) + if (AttentionLabel_1 != nullptr) { - delete image1_; - image1_ = nullptr; + delete AttentionLabel_1; + AttentionLabel_1 = nullptr; } - if (label3_ != nullptr) + if (button != nullptr) { - delete label3_; - label3_ = nullptr; + delete button; + button = nullptr; } - if (button1_ != nullptr) + if (scrollView != nullptr) { - delete button1_; - button1_ = nullptr; + delete scrollView; + scrollView = nullptr; } } } \ No newline at end of file diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp index 1313f14b5..a1c358d66 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp @@ -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 diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp index e471c2afd..ff79143e1 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp @@ -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/FastTrainingAttentionVector.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Attention.bin similarity index 100% rename from code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/FastTrainingAttentionVector.bin rename to code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Attention.bin 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 index b8120b857..000000000 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 index b8120b857..000000000 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 index 5f89b6371..000000000 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