表盘:增加步数完成目标百分比
authorCaisking <3449750381@qq.com>
Fri, 25 Oct 2024 13:43:25 +0000 (21:43 +0800)
committerCaisking <3449750381@qq.com>
Fri, 25 Oct 2024 13:43:25 +0000 (21:43 +0800)
code/sdk/application/wearable/fd230app/nativeui/activity/src/ActivityModel.cpp
code/sdk/application/wearable/fd230app/nativeui/goal/include/goalmodel.h
code/sdk/application/wearable/fd230app/nativeui/goal/src/goalmodel.cpp
code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelStepgoal.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelStepgoal.cpp [new file with mode: 0644]

index 925fae3..a05caf5 100644 (file)
@@ -23,6 +23,7 @@
 #include "DialModelSteps.h"
 #include "DialModelCalorie.h"
 #include "DialModelDistance.h"
+#include "DialModelStepgoal.h"
 #include "cywee_service.h"
 #include "custom_runtime.h"
 #include "goal/include/goalmodel.h"
@@ -141,6 +142,7 @@ static void Notify(void *args, const Topic topic, Request* request)
         OHOS::ActivityModel::GetInstance()->ReviseStepCounter(counter);
 
         OHOS::DialModelSteps::GetInstance() ->UpdateSteps(counter);//更新表盘步数
+        OHOS::DialModelStepgoal::GetInstance() ->UpdateStepgoal(counter);//更新表盘目标
         OHOS::DialModelDistance::GetInstance() ->UpdateDistance(get_distance_data());//更新表盘距离
         OHOS::DialModelCalorie::GetInstance() ->UpdateCalorie(get_calories_data());//更新表盘卡路里
 
index 2c99a71..7758b33 100644 (file)
@@ -46,6 +46,7 @@ namespace OHOS
         char* getstandnew();
         void updata();
         void GoalModelInitdata();
+        uint32_t getstepgoaldata();
 
         uint8_t get_step_goal_show()
         {
index ad5a450..b051f6d 100644 (file)
@@ -12,6 +12,7 @@
 #include "ConfigModel.h"
 #include "cywee_hal.h"
 #include "goal_notification.h"
+
 namespace OHOS
 {
  
@@ -62,6 +63,10 @@ namespace OHOS
       }
       return value;
    }
+   uint32_t GoalModel::getstepgoaldata()
+   {
+      return step;
+   }
    char stepgoalstr[20];
    char *GoalModel::getstepGoal()
    {
diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelStepgoal.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelStepgoal.h
new file mode 100644 (file)
index 0000000..77ee2f5
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) CompanyNameMagicTag 2023. All rights reserved.
+ * Description: DialModelStepgoal
+ * Author:
+ * Create: 2023-12
+ */
+
+#ifndef DIAL_MODEL_Stepgoal_H
+#define DIAL_MODEL_Stepgoal_H
+
+#include "DialBaseModel.h"
+
+namespace OHOS {
+class DialModelStepgoal : public DialBaseModel {
+public:
+  DialModelStepgoal() {}
+  ~DialModelStepgoal() override {}
+  static DialModelStepgoal *GetInstance() {
+    static DialModelStepgoal instance;
+    return &instance;
+  }
+  bool GetDialFloatData(DialDataType &type, float &out) override;
+  void UpdateStepgoal(uint32_t Stepgoal);
+
+private:
+  float stepgoal_ = 0; // 11520.0: default step value as reference
+};
+} // namespace OHOS
+#endif
diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelStepgoal.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelStepgoal.cpp
new file mode 100644 (file)
index 0000000..a07e2a6
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) CompanyNameMagicTag 2023. All rights reserved.
+ * Description: DialModelSteps
+ * Author:
+ * Create: 2023-12
+ */
+
+#include "DialModelStepgoal.h"
+#include "DialBoxProgressView.h"
+#include "RegisterDialModel.h"
+#include "goal/include/goalmodel.h"
+
+REGIST_DIAL_MODULE(DialDataType::DATA_TYPE_STEPS_GOAL,
+                   OHOS::DialModelStepgoal::GetInstance());
+
+namespace OHOS {
+bool DialModelStepgoal::GetDialFloatData(DialDataType &type, float &out) {
+  (void)type;
+  out = DialBoxProgressView::GetInstance()->ConvertToRequiredFormat(
+      DialBoxDataType::STEP_TARGET, stepgoal_);
+  return true;
+}
+
+void DialModelStepgoal::UpdateStepgoal(uint32_t steps) {
+  uint32_t step_ = static_cast<float>(steps);
+  uint32_t goal = GoalModel::GetInstance().getstepgoaldata();
+  if (goal > 0) {
+    stepgoal_ = (static_cast<float>(step_) / goal) * 100;
+    if (stepgoal_ > 100)
+      stepgoal_ = 100;
+    stepgoal_ = DialBoxProgressView::GetInstance()->ConvertToRequiredFormat(
+        DialBoxDataType::STEP_TARGET, stepgoal_);
+  }
+  if (onChangeListener_ != nullptr) {
+    onChangeListener_->OnDialFloatDataUpdate(DialDataType::DATA_TYPE_STEPS_GOAL,
+                                             stepgoal_);
+  }
+}
+} // namespace OHOS