UI:优化部分界面的英语显示
authorCaisking <3449750381@qq.com>
Fri, 13 Dec 2024 08:44:00 +0000 (16:44 +0800)
committerCaisking <3449750381@qq.com>
Fri, 13 Dec 2024 08:44:00 +0000 (16:44 +0800)
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingControlView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDetailView.cpp

index 80a4ae0..cbc8169 100644 (file)
@@ -25,80 +25,79 @@ SleepView::~SleepView() {
   g_pSleepView = nullptr;
 }
 
-void SleepView::SleepDataRefresh() {  
-  // 获取睡眠数据内存  
-  SleepModel &sleepModel = SleepModel::GetInstance();  
-  sleepModel.ReInitData();  
-
-  int sleep_hour = sleepModel.get_sleep_hour();  
-  int sleep_min = sleepModel.get_sleep_min();  
-  int total_sleep = sleepModel.get_sleep_total();  
-  int sleep_goal = sleepModel.get_sleep_goal();  
-
-  // 检查是否超过24小时  
-  if (sleep_hour >= 24) {  
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "异常:睡眠时长超过24小时");  
-    return; 
-  }  
-
-  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,  
-                "SleepDataRefresh %d %d sleep_goal:%d total_sleep:%d",  
-                sleep_hour, sleep_min, sleep_goal * 60, total_sleep);  
-
-  // 补零操作  
-  std::string hour_str = (sleep_hour < 10) ? "0" + std::to_string(sleep_hour)  
-                                           : std::to_string(sleep_hour);  
-  std::string min_str = (sleep_min < 10) ? "0" + std::to_string(sleep_min)  
-                                         : std::to_string(sleep_min);  
-
-  // 有数据才刷新  
-  if (sleep_hour != 0 || sleep_min != 0) {  
-    // 更新时间显示  
-    if (time_hour != nullptr) {  
-      time_hour->SetText(hour_str.c_str());  
-    }  
-    if (time_minute != nullptr) {  
-      time_minute->SetText(min_str.c_str());  
-    }  
-
-    // 计算进度百分比,确保目标睡眠时间不为零  
-    float progress_value = 0.0f;  
-    if (sleep_goal > 0) {  
-      progress_value =  
-          static_cast<float>(total_sleep) / (sleep_goal * 60); // 计算进度  
-    }  
-
-    // 日志输出进度百分比  
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Progress value: %.2f%%",  
-                  progress_value * 100); // 显示为百分比  
-
-    // 更新进度条  
-    circleProgress_->SetValue(progress_value *  
-                              100); // 更新进度条值,范围为 0 到 100  
-    circleProgress_->SetCapType(CAP_ROUND);  
-  }  
-  
-  // 更新时间  
-  if (sleep_update_time != nullptr) {  
-    std::string update_time = sleepModel.GetUpdateSleepTime();  
-    if (!update_time.empty()) // 检查返回值是否有效  
-    {  
-      std::string update_time_str;  
-      // TODO:多国语言  
-      if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) {  
-        update_time_str = update_time + " 更新";  
-      }  
-      else {  
-        update_time_str = update_time + " update";  
-      }  
-      sleep_update_time->SetText(update_time_str.c_str());  
-      // UpdateLabel(sleep_update_time, sleep_goal, STR_SLEEPMGOAL); // TODO:  
-      // 多国语言支持  
-    }  
-  }  
-  
-  // 刷新视图  
-  RootView::GetInstance()->Invalidate();  
+void SleepView::SleepDataRefresh() {
+  // 获取睡眠数据内存
+  SleepModel &sleepModel = SleepModel::GetInstance();
+  sleepModel.ReInitData();
+
+  int sleep_hour = sleepModel.get_sleep_hour();
+  int sleep_min = sleepModel.get_sleep_min();
+  int total_sleep = sleepModel.get_sleep_total();
+  int sleep_goal = sleepModel.get_sleep_goal();
+
+  // 检查是否超过24小时
+  if (sleep_hour >= 24) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "异常:睡眠时长超过24小时");
+    return;
+  }
+
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                "SleepDataRefresh %d %d sleep_goal:%d total_sleep:%d",
+                sleep_hour, sleep_min, sleep_goal * 60, total_sleep);
+
+  // 补零操作
+  std::string hour_str = (sleep_hour < 10) ? "0" + std::to_string(sleep_hour)
+                                           : std::to_string(sleep_hour);
+  std::string min_str = (sleep_min < 10) ? "0" + std::to_string(sleep_min)
+                                         : std::to_string(sleep_min);
+
+  // 有数据才刷新
+  if (sleep_hour != 0 || sleep_min != 0) {
+    // 更新时间显示
+    if (time_hour != nullptr) {
+      time_hour->SetText(hour_str.c_str());
+    }
+    if (time_minute != nullptr) {
+      time_minute->SetText(min_str.c_str());
+    }
+
+    // 计算进度百分比,确保目标睡眠时间不为零
+    float progress_value = 0.0f;
+    if (sleep_goal > 0) {
+      progress_value =
+          static_cast<float>(total_sleep) / (sleep_goal * 60); // 计算进度
+    }
+
+    // 日志输出进度百分比
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Progress value: %.2f%%",
+                  progress_value * 100); // 显示为百分比
+
+    // 更新进度条
+    circleProgress_->SetValue(progress_value *
+                              100); // 更新进度条值,范围为 0 到 100
+    circleProgress_->SetCapType(CAP_ROUND);
+  }
+
+  // 更新时间
+  if (sleep_update_time != nullptr) {
+    std::string update_time = sleepModel.GetUpdateSleepTime();
+    if (!update_time.empty()) // 检查返回值是否有效
+    {
+      std::string update_time_str;
+      // TODO:多国语言
+      if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) {
+        update_time_str = update_time + " 更新";
+      } else {
+        update_time_str = update_time + " update";
+      }
+      sleep_update_time->SetText(update_time_str.c_str());
+      // UpdateLabel(sleep_update_time, sleep_goal, STR_SLEEPMGOAL); // TODO:
+      // 多国语言支持
+    }
+  }
+
+  // 刷新视图
+  RootView::GetInstance()->Invalidate();
 }
 
 void SleepView::ClearAll() {
@@ -159,6 +158,18 @@ bool SleepView::InitPage(void) {
   InitLabelExt(minute, 295, 246, 100, 75, "lableminute", STR_MIN,
                DEFAULT_VECTOR_FONT_FILENAME, 26);
   minute->SetTextColor(Color::Gray());
+  if (ConfigModel::GetInstance()->GetLanguage() != ZH_CN) {
+    //需要缩小
+    title->SetFont(DEFAULT_VECTOR_FONT_FILENAME,26);
+    hour->SetFont(DEFAULT_VECTOR_FONT_FILENAME,24);
+    minute->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24);
+
+    minute->SetText("Min");//多国语言
+    hour->SetText("Hour");
+  } else {
+    minute->SetText("分钟");
+    hour->SetText("小时");
+    }
   /*初始化image*/
   InitImageView(roomimage, 192, 127, 82, 82, "image", roomimagePath);
   InitImageView(upiconimage, 213, 420, 40, 40, "image", upimagePath);
index 82f4bd1..50ffe5e 100644 (file)
@@ -2,17 +2,18 @@
 #include "traing/training_card/include/TrainingDetailView.h"
 #include "traing/training_card/include/TraingCardView.h"
 
+#include "ConfigModel.h"
 #include "UiConfig.h"
 #include "common/image_cache_manager.h"
 #include "components/ui_button.h"
 #include "components/ui_label_ext.h"
+#include "languagecode/LanguageInit.h"
 #include "traing/Training_UiConfig.h"
 #include "traing/include/TraingModel.h"
 #include "ui_resource_image.h"
 #include "ui_resource_string.h"
 #include "uicomponents/UIComponents.h"
 #include <ui_scroll_view.h>
-
 namespace OHOS {
 
 static TrainingDetailView *g_pTrainingDetailView{nullptr};
@@ -52,12 +53,22 @@ bool TrainingDetailView ::InitPage() {
   Add(lineimage2_);
 
   // 初始化Lable
-  InitRollLabel(u_milelabel, 16, 234, 220, 35, "label2", STR_RANGE_SETTING,
-               DEFAULT_VECTOR_FONT_FILENAME, 30);
-  InitRollLabel(u_stepslabel, 73, 362, 320, 35, "label3", STR_STEP_NUMBER,
-               DEFAULT_VECTOR_FONT_FILENAME, 30);
-  InitRollLabel(u_calorielabel, 225, 235, 230, 35, "label4", STR_CALORIE_SETTING,
-               DEFAULT_VECTOR_FONT_FILENAME, 30);
+  InitRollLabel(u_milelabel, 16, 234, 230, 35, "label2", STR_RANGE_SETTING,
+                DEFAULT_VECTOR_FONT_FILENAME, 30);
+  InitRollLabel(u_calorielabel, 225, 235, 230, 35, "label4",
+                STR_CALORIE_SETTING, DEFAULT_VECTOR_FONT_FILENAME, 30);
+  InitRollLabel(u_stepslabel, 73, 362, 320, 35, "label3", STR_STEP_SETTING,
+                DEFAULT_VECTOR_FONT_FILENAME, 30);
+  //多国语言
+  if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) {
+    u_milelabel->SetText("距离(公里");
+    u_stepslabel->SetText("步数(步)");
+    u_calorielabel->SetText("卡路里(千卡)");
+  } else {
+    u_milelabel->SetText("Distance (km)");
+    u_stepslabel->SetText("Steps");
+    u_calorielabel->SetText("Calorie (kcal)");
+  }
   u_milelabel->SetTextColor(Color::Gray());
   u_stepslabel->SetTextColor(Color::Gray());
   u_calorielabel->SetTextColor(Color::Gray());
@@ -69,7 +80,7 @@ bool TrainingDetailView ::InitPage() {
             DEFAULT_VECTOR_FONT_FILENAME_EN, 65);
   InitLabel(steplabel, 133, 285, 200, 80, "label8", "210.03",
             DEFAULT_VECTOR_FONT_FILENAME_EN, 65);
-  
+
   Add(u_milelabel);
   Add(u_stepslabel);
   Add(u_calorielabel);