From da81b64dbfc4914ae94e18dda1509467c206bbd0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E7=BD=97=E6=AD=A3?= <1732036298@qq.com> Date: Thu, 21 Nov 2024 12:23:06 +0000 Subject: [PATCH] Merge #1438 into sdk602patch0911 from refs/changes/1438/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 罗正 * refs/changes/1438/head: (16 commits squashed) - applsit拨号盘实现:目前,滑动一下屏幕APP转动一次,后续优化为多次转动 - 解决倒计时界面内存泄漏问题 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 修改显示方式页面多国语言显示问题 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 解决查找手表后变成长亮屏 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 拨号盘样式,实现跟手滑动效果 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 解决ChatGPT,设置Key后不能用问题 - 修改拨号盘图片显示bug - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - #865,手表与手机同时进行10分钟倒计时,手机倒计时已结束手表还剩余40秒bug - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 删除直线列表风格 Signed-off-by: 罗正 <1732036298@qq.com> Reviewed-by: Caisking <3449750381@qq.com> Reviewed-by: 罗正 <1732036298@qq.com> Reviewed-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Reviewed-by: aliyun6865282430 <1624952103@qq.com> Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1438 --- .../countdown/include/CountDownModel.h | 29 ++++++- .../nativeui/countdown/src/CountDownModel.cpp | 77 ++++++++++++++++++- .../themestyle/include/ThemeStyleModel.h | 6 +- .../themestyle/include/ThemeStyleView.h | 4 +- .../themestyle/src/ThemeStyleView.cpp | 11 ++- 5 files changed, 112 insertions(+), 15 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h index 674c40329..41c1aa3d6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h @@ -1,8 +1,8 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-07 18:15:53 - * @LastEditors: SnickerSun snickersun@163.com - * @LastEditTime: 2024-10-21 11:35:37 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-21 16:06:32 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h */ #ifndef COUNTDOWN_MODEL_H @@ -98,8 +98,30 @@ namespace OHOS void RequestStopRingtone(void); int ResetRingtonePlayback(void); + void countdownstart(); + void countdownpause(); + void countdownresume(); + void countdownstop(); + + void SetisRunning(bool val) { + isRunning = val; + } + bool GetisRunning(void) const { + return isRunning; + } + void SetisPaused(bool val) { + isPaused = val; + } + bool GetisPaused(void) const { + return isPaused; + } + uint32_t get_current_time();//获取当前系统时间戳 public: static int g_CountDownTimes; + static int totalSeconds; //要到计时总秒数 + static uint32_t startTime; //开始时间戳 + static uint32_t pauseTime; //暂停时间戳 + static uint32_t endTime; //结束时间戳 private: CountDownModel() {} @@ -127,6 +149,9 @@ namespace OHOS std::string CountTimeBackup{"00:00:00"}; bool IsChanageToStartCountDownViewFlag{false};//是否需要切换到开始倒计时界面标志 bool CountDownTimerIsPauseFlag{false}; + + bool isRunning{false};//记录倒计时是否正在运行 + bool isPaused{false}; //记录倒计时是否暂停 }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp index c0832fc16..9c8817f6a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-07 18:15:53 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-05 11:49:33 + * @LastEditTime: 2024-11-21 16:38:01 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp */ #include "countdown/include/CountDownModel.h" @@ -19,12 +19,17 @@ #include "AppViewIDs.h" #include "NativeAbility.h" #include +#include namespace OHOS { /* -------------------------------------------------------------------------- */ // 声明定时器变量 static osTimerId_t g_timer = nullptr; int CountDownModel::g_CountDownTimes = {0}; + int CountDownModel::totalSeconds = 0; //总的倒计时时间 + uint32_t CountDownModel::startTime = 0; + uint32_t CountDownModel::pauseTime = 0; + uint32_t CountDownModel::endTime = 0; static constexpr int32 NUM_TEN = 10; // 主要用于格式化输出,当小时、分钟或秒小于10时,在其前面添加一个’0’以保持常规时间格式,例如“09:05:03”。 static constexpr int16 NUM_TIME_MIN = 60; static constexpr int16 NUM_TIME_HOUR = 3600; @@ -441,11 +446,67 @@ namespace OHOS */ static void CountDown_TimerCallback(int data) { - CountDownModel::g_CountDownTimes--; // 每次回调减少1秒 - if (CountDownModel::g_CountDownTimes <= 0) // 检查倒计时是否结束 + + /*拿系统时间实现倒计时功能*/ + bool isRunning = CountDownModel::GetInstance()->GetisRunning(); + bool isPaused = CountDownModel::GetInstance()->GetisPaused(); + + if (isRunning &&!isPaused) { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(CountDown_TimerCallbackProc, data)); + uint32_t currentTime = CountDownModel::GetInstance()->get_current_time(); + CountDownModel::g_CountDownTimes = CountDownModel::totalSeconds - (currentTime - CountDownModel::startTime); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "当前时间戳:%u,倒计时剩余时间:%d", currentTime ,CountDownModel::g_CountDownTimes); + if (CountDownModel::g_CountDownTimes <= 0 && currentTime == CountDownModel::endTime) { + // 这里可以添加倒计时结束后的操作,比如发出提示音等 + GraphicService::GetInstance()->PostGraphicEvent(std::bind(CountDown_TimerCallbackProc, data)); + } + } + } + + uint32_t CountDownModel::get_current_time() + { + uint32_t time; + if (uapi_get_timestampe_ss(&time) != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp"); + return 0; } + return time; + } + + void CountDownModel::countdownstart() + { + isRunning = true; + isPaused = false; + CountDownModel::totalSeconds = CountDownModel::g_CountDownTimes; + CountDownModel::startTime = get_current_time(); //获取开始时间戳 + CountDownModel::endTime = CountDownModel::startTime + g_CountDownTimes; //获取结束时间戳 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startTime:%u,endTime:%u",CountDownModel::startTime,CountDownModel::endTime); + + } + + void CountDownModel::countdownpause() + { + if (isRunning &&!isPaused) { + isPaused = true; + CountDownModel::pauseTime = get_current_time(); + } + } + void CountDownModel::countdownresume() + { + if (isRunning && isPaused) { + isPaused = false; + uint32_t currentTime = get_current_time(); + uint32_t pauseDuration = currentTime - CountDownModel::pauseTime; + CountDownModel::endTime = CountDownModel::endTime + pauseDuration; + CountDownModel::totalSeconds = CountDownModel::totalSeconds + pauseDuration; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startTime:%u,pauseDuration:%u,endTime:%u",CountDownModel::startTime,pauseDuration,CountDownModel::endTime); + } + } + + void CountDownModel::countdownstop() + { + isRunning = false; + isPaused = false; } /* @@ -461,6 +522,8 @@ namespace OHOS return; } + countdownstart(); + /* --------------------------------- 2.创建定时器 -------------------------------- */ g_timer = osTimerNew((osTimerFunc_t)CountDown_TimerCallback, osTimerPeriodic, nullptr, nullptr); // 检查定时器创建是否成功 @@ -498,6 +561,8 @@ namespace OHOS // 检查定时器是否存在 if (g_timer != nullptr) { + countdownstop(); + osTimerStop(g_timer); // 删除定时器并置为 nullptr osStatus_t ret = osTimerDelete(g_timer); @@ -518,6 +583,8 @@ namespace OHOS // 检查定时器是否存在 if (g_timer != nullptr) { + countdownpause(); + // 暂停定时器,但不删除它 osStatus_t ret = osTimerStop(g_timer); if (ret != osOK) @@ -535,6 +602,8 @@ namespace OHOS // 检查定时器是否存在 if (g_timer != nullptr) { + countdownresume(); + int tick = osMs2Tick(interval); // 恢复定时器 osStatus_t ret = osTimerStart(g_timer, tick); diff --git a/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h b/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h index d7217a7a4..7acf1ac2b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-14 09:40:13 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-14 14:25:34 + * @LastEditTime: 2024-11-21 17:21:29 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h */ #ifndef SET_THEMESTYLE_MODEL_H @@ -26,10 +26,10 @@ namespace OHOS typedef enum : uint16_t { - APPLIST_STYLE, // 列表显示 - HEXAGONS_STYLE, // 蜂窝显示 ARC_SCALE_LIST_STYLE,//弧形列表 + HEXAGONS_STYLE, // 蜂窝显示 CIRCLE_LIST_STYLE,//拨号盘 + APPLIST_STYLE, // 列表显示 FOOTBALL_STYLE, //足球 MAX_THEME_STYLE, } ThemeStyle; diff --git a/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleView.h b/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleView.h index 4db787a98..fc0a0a20f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-14 09:40:13 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-14 14:37:34 + * @LastEditTime: 2024-11-21 17:22:12 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleView.h */ @@ -24,7 +24,7 @@ namespace OHOS { - static constexpr const uint16_t MAX_STYLE = MAX_THEME_STYLE - 1; + static constexpr const uint16_t MAX_STYLE = MAX_THEME_STYLE - 2; //直线列表和足球不显示所以删除了两个 static constexpr char *THEME_STYLE_LIST = "themestyleList"; // 列表 static constexpr char *THEME_STYLE_HEXAGONS = "themestyleHexagons"; // 蜂窝 static constexpr char *THEME_STYLE_FOOTBALL = "themestyleFootball"; // 足球 diff --git a/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleView.cpp b/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleView.cpp index de6fde7b8..ea79708c6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-14 09:40:20 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-18 17:19:28 + * @LastEditTime: 2024-11-21 17:12:45 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleView.cpp */ @@ -184,7 +184,8 @@ namespace OHOS titleText->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); scrollView->Add(titleText); /* -------------------------------------------------------------------------- */ - int16_t textId[] = {STR_LIST_DISPLAY, STR_CELLULAR_DISPLAY, STR_ARC_SCALE_LIST_DISPLAY,STR_DIAL_PLATE}; + // int16_t textId[] = {STR_LIST_DISPLAY, STR_CELLULAR_DISPLAY, STR_ARC_SCALE_LIST_DISPLAY,STR_DIAL_PLATE}; + int16_t textId[] = {STR_ARC_SCALE_LIST_DISPLAY, STR_CELLULAR_DISPLAY,STR_DIAL_PLATE}; LabelConfig labelConfig = { .left = 143, .top = 153, @@ -236,7 +237,8 @@ namespace OHOS .viewId = THEME_STYLE_LIST, }; - const char *viewId[] = {THEME_STYLE_LIST, THEME_STYLE_HEXAGONS, THEME_STYLE_ARC_LIST,THEME_STYLE_CIRCLE_LIST}; + // const char *viewId[] = {THEME_STYLE_LIST, THEME_STYLE_HEXAGONS, THEME_STYLE_ARC_LIST,THEME_STYLE_CIRCLE_LIST}; + const char *viewId[] = {THEME_STYLE_ARC_LIST, THEME_STYLE_HEXAGONS,THEME_STYLE_CIRCLE_LIST}; for (int i = 0; i < sizeof(viewId) / sizeof(viewId[0]); i++) { labelbuttonconfig.top = 120 + 120 * i; @@ -277,7 +279,8 @@ namespace OHOS .src = THEMESTYLE_LIST_IMAGEPATH, }; int y = 150; - const char *src[MAX_STYLE] = {THEMESTYLE_LIST_IMAGEPATH, THEMESTYLE_HEXAGONS_IMAGEPATH, THEMESTYLE_ARCLIST_IMAGEPATH,THEMESTYLE_CIRCLELIST_IMAGEPATH}; + // const char *src[MAX_STYLE] = {THEMESTYLE_LIST_IMAGEPATH, THEMESTYLE_HEXAGONS_IMAGEPATH, THEMESTYLE_ARCLIST_IMAGEPATH,THEMESTYLE_CIRCLELIST_IMAGEPATH}; + const char *src[] = {THEMESTYLE_ARCLIST_IMAGEPATH, THEMESTYLE_HEXAGONS_IMAGEPATH,THEMESTYLE_CIRCLELIST_IMAGEPATH}; for (int i = 0; i < sizeof(src) / sizeof(src[0]); i++) { imageconfig.y = y + 120 * i; -- 2.17.1