1.ConfigModel添加震动提醒和静音模式保存功能
authorluozheng <1732036298@qq.com>
Tue, 2 Apr 2024 03:47:24 +0000 (11:47 +0800)
committerluozheng <1732036298@qq.com>
Tue, 2 Apr 2024 03:47:24 +0000 (11:47 +0800)
code/sdk/application/wearable/fd230app/nativeui/config/ConfigModel.json
code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h
code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp
code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationModel.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp

index 8386097..55a811f 100644 (file)
@@ -7,5 +7,7 @@
     "Dial_Id": 0,
     "Dial_Name": "KUMI",
     "Language_Id": 0,
-    "Language_Code": "zh"
+    "Language_Code": "zh",
+    "VibrationReminder":false,
+    "SilentMode":false
 }
\ No newline at end of file
index 5c5a0f0..efbd9af 100644 (file)
@@ -38,7 +38,8 @@ namespace OHOS
 
         /* -------------------------------------------------------------------------- */
         std::string ReadJsonData_String(const cJSON *json_obj, const char *field_name);
-        double ReadJsonData_Number(const cJSON *json_obj, const char *field_name);
+        double ReadJsonData_Double(const cJSON *json_obj, const char *field_name);
+        int ReadJsonData_Int(const cJSON *json_obj, const char *field_name);
         bool ReadJsonData_Bool(const cJSON *json_obj, const char *field_name);
         int ReadJsonData_ArraySize(const cJSON *json_obj, const char *field_name);
 
@@ -77,6 +78,10 @@ namespace OHOS
         void SetmoderVer(char *str);
         void SetLanguageCode(char *languagecode);
         const char *GetLanguageCode(void);
+        void SetVibrationReminder(bool state);
+        bool GetVibrationReminder(void);
+        void SetSilentMode(bool state);
+        bool GetSilentMode(void);
         // -------------------------------------------------------------------------- */
     private:
         ConfigModel();                                        // 私有构造函数,确保无法在外部实例化
@@ -90,7 +95,7 @@ namespace OHOS
         /* ------------------------------- json中要读取的键 ------------------------------- */
         bool RaiseToBrightnessCheckBoxButtonState{false};    // 抬腕按钮状态 ,默认补选中
         unsigned char ScreenBrightnessValue{255};            // 亮度值 ,默认最大亮度
-        unsigned int ScreenDurationRadioButtonSlectValue{1}; // 亮屏时长 ,0对应5秒熄屏,1对应10秒熄屏,2对应15秒熄屏
+        unsigned int ScreenDurationRadioButtonSlectValue{1}; // 亮屏时长按钮选中编号 ,0对应5秒熄屏,1对应10秒熄屏,2对应15秒熄屏
         bool TradionalBlueToothToggleButtonState{false};     // 用来记录蓝牙开关状态,默认关闭状态
         int HeartRateOrBloodOxygenQuickAccessSwitch{0};      // 心率或血氧快速访问开关,默认快速访问血氧打开
         int dialid_;                                         // 表盘Id
@@ -100,6 +105,8 @@ namespace OHOS
         char *pyVer = NULL;
         char *moderVer = NULL;
         std::string LanguageCode = "zh";
+        bool VibrationReminder{false}; // 震动提醒
+        bool SilentMode{false};        // 静音模式
         cat1_msg_config cat1_msg_config_t;
         /* -------------------------------------------------------------------------- */
     };
index 47f27e0..1203c03 100644 (file)
@@ -65,12 +65,12 @@ namespace OHOS
     }
 
     /*
-     * @brief 读取数字
+     * @brief 读取数字(浮点数)
      * @param {cJSON} json对象
      * @param {char*} 字段名
      * @return {double} 读取到的数字
      */
-    double ConfigModel::ReadJsonData_Number(const cJSON *json_obj, const char *field_name)
+    double ConfigModel::ReadJsonData_Double(const cJSON *json_obj, const char *field_name)
     {
         const cJSON *field_item = cJSON_GetObjectItem(json_obj, field_name);
         if (field_item != NULL && cJSON_IsNumber(field_item))
@@ -81,6 +81,23 @@ namespace OHOS
         return -1; // 或者返回一个错误值
     }
 
+    /*
+     * @brief 读取数字(整数)
+     * @param {cJSON} json对象
+     * @param {char*} 字段名
+     * @return {int} 读取到的数字
+     */
+    int  ConfigModel::ReadJsonData_Int(const cJSON *json_obj, const char *field_name)
+    {
+        const cJSON *field_item = cJSON_GetObjectItem(json_obj, field_name);
+        if (field_item != NULL && cJSON_IsNumber(field_item))
+        {
+            return static_cast<int>(field_item->valuedouble);
+        }
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Field not found or not a number");
+        return -1; // 或者返回一个错误值
+    }
+
     /*
      * @brief 读取布尔值
      * @param {cJSON} json对象
@@ -92,7 +109,7 @@ namespace OHOS
         const cJSON *field_item = cJSON_GetObjectItem(json_obj, field_name);
         if (field_item != NULL && cJSON_IsBool(field_item))
         {
-            return field_item->valueint != 0;
+            return cJSON_IsTrue(field_item) ? true : false;
         }
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Field not found or not a boolean");
         return false; // 或者返回一个错误值
@@ -304,7 +321,7 @@ namespace OHOS
             return;
         }
 
-        FILE *fp = fopen(file_path, "w+");
+        FILE *fp = fopen(file_path, "w");
         if (fp == NULL)
         {
             printf("Failed to open file: %s\n", file_path);
@@ -517,6 +534,43 @@ namespace OHOS
         }
         return;
     }
+
+    /*
+     * @brief 设置震动提醒
+     * @param {bool} true 开启
+     * @param {bool} false 关闭
+     */
+    void ConfigModel::SetVibrationReminder(bool state)
+    {
+        VibrationReminder = state;
+        WriteJsonData_Bool(GetcJSON(), "VibrationReminder", VibrationReminder); // 应该放到关机时候写
+    }
+
+    /*获取震动提醒是否开启*/
+    bool ConfigModel::GetVibrationReminder(void)
+    {
+        VibrationReminder = ReadJsonData_Bool(GetcJSON(), "VibrationReminder"); // 应该放到开机时候读
+        return VibrationReminder;
+    }
+
+    /*
+     * @brief 设置静音模式
+     * @param {bool} true 开启
+     * @param {bool} false 关闭
+     */
+    void ConfigModel::SetSilentMode(bool state)
+    {
+        SilentMode = state;
+        WriteJsonData_Bool(GetcJSON(), "SilentMode", SilentMode); // 应该放到关机时候写
+    }
+
+    /*获取静音模式是否开启*/
+    bool ConfigModel::GetSilentMode(void)
+    {
+        SilentMode = ReadJsonData_Bool(GetcJSON(), "SilentMode"); // 应该放到开机时候读
+        return SilentMode;
+    }
+
     /* ------------------------------ ImageAnimator ----------------------------- */
 
     ImageAnimator::ImageAnimator()
index 3b65448..85c09a4 100644 (file)
@@ -1,6 +1,8 @@
 #include "displaybrightness/include/DisplayBrightnessModel.h"
 #include "displaybrightness/include/DisplayBrightnessPresenter.h"
 #include "wearable_log.h"
+#include "cat1_ctl.h"
+#include "../../../../../../drivers/peripheral/slip/cat1Service/cat1_ctl.h"
 namespace OHOS
 {
 
@@ -38,7 +40,7 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessViewAndSubViewComponentsStatusInit DisplayBrightnessPresenter GetInstance fail");
             return false;
         }
-        displayBrightnessPresent->SetRaiseToBrightnessState(RaiseToBrightnessCheckBoxButtonState); // 抬腕按钮的状态
+        displayBrightnessPresent->SetRaiseToBrightnessState(uapi_cat1_get_power_stat()); // 抬腕按钮的状态
         return true;
     }
 
index df3df6e..8869a90 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-02-19 10:39:08\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-03-21 11:49:25\r
+ * @LastEditTime: 2024-04-01 19:33:48\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h\r
  */\r
 #ifndef SOUND_AND_VIBRATION_PRESENTER_H\r
@@ -11,6 +11,7 @@
 #include "Presenter.h"\r
 #include "SoundAndVibrationView.h"\r
 #include "KeyInputListener.h"\r
+#include "soundandvibration/include/SoundAndVibrationModel.h"\r
 \r
 namespace OHOS\r
 {\r
index 328c2d5..98e1239 100644 (file)
@@ -1,10 +1,23 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-02-23 09:17:00
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-04-01 18:19:45
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationModel.cpp
+ */
 #include "soundandvibration/include/SoundAndVibrationModel.h"
 #include "soundandvibration/include/SoundAndVibrationPresenter.h"
 #include "wearable_log.h"
+#include "config/include/ConfigModel.h"
 namespace OHOS
 {
 
-    SoundAndVibrationModel::SoundAndVibrationModel() {}
+    SoundAndVibrationModel::SoundAndVibrationModel()
+    {
+        ConfigModel *p_ConfigModel  = ConfigModel::GetInstance();
+        VibrationReminderToggleButtonState = p_ConfigModel->GetVibrationReminder();
+        SilentModeToggleButtonState = p_ConfigModel->GetSilentMode();
+    }
 
     SoundAndVibrationModel::~SoundAndVibrationModel() {}
 
index 9ff5d09..062f1e7 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-02-19 10:39:11\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-03-21 14:23:38\r
+ * @LastEditTime: 2024-04-02 09:14:23\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp\r
  */\r
 \r
@@ -13,9 +13,9 @@
 #include "graphic_math.h"\r
 #include "string.h"\r
 #include "soundandvibration/include/SoundAndVibrationPresenter.h"\r
-#include "soundandvibration/include/SoundAndVibrationModel.h"\r
 #include "common/key_code.h"\r
 #include "custom_utils.h"\r
+#include "config/include/ConfigModel.h"\r
 \r
 namespace OHOS\r
 {\r
@@ -54,7 +54,6 @@ namespace OHOS
         if (value != false)\r
         {\r
             p_SoundAndVibrationView->SetVibrationReminderToggleButtonState(true);\r
-            SoundAndVibrationModel::GetInstance()->SetVibrationReminderToggleButtonStaus(false); // 将Model层保存的状态清除\r
         }\r
     }\r
 \r
@@ -71,7 +70,6 @@ namespace OHOS
         if (value != false)\r
         {\r
             p_SoundAndVibrationView->SetSilentModeToggleButtonState(true);\r
-            SoundAndVibrationModel::GetInstance()->SetSilentModeToggleButtonStatus(false); // 将Model层保存的状态清除\r
         }\r
     }\r
 \r
@@ -160,20 +158,23 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::GetInstance fail!");\r
             return false;\r
         }\r
-\r
+        SoundAndVibrationModel* p_SoundAndVibrationModel = SoundAndVibrationModel::GetInstance();\r
+        ConfigModel *p_ConfigModel = ConfigModel::GetInstance();\r
         switch (state)\r
         {\r
         case UICheckBox::SELECTED:\r
             if (p_SoundAndVibrationView->GetVibrationReminderToggleButton() == (UIView *)view_)\r
             {\r
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VibrationReminder is enable!");\r
-\r
+                p_SoundAndVibrationModel->SetVibrationReminderToggleButtonStaus(true);\r
+                p_ConfigModel->SetVibrationReminder(true);\r
                 return true;\r
             }\r
             else if (p_SoundAndVibrationView->GetSilentModeToggleButton() == (UIView *)view_)\r
             {\r
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentMode is enable!");\r
-\r
+                p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(true);\r
+                p_ConfigModel->SetSilentMode(true);\r
                 return true;\r
             }\r
             break;\r
@@ -181,13 +182,15 @@ namespace OHOS
             if (p_SoundAndVibrationView->GetVibrationReminderToggleButton() == (UIView *)view_)\r
             {\r
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VibrationReminder is disable!");\r
-\r
+                p_SoundAndVibrationModel->SetVibrationReminderToggleButtonStaus(false);\r
+                p_ConfigModel->SetVibrationReminder(false);\r
                 return true;\r
             }\r
             else if (p_SoundAndVibrationView->GetSilentModeToggleButton() == (UIView *)view_)\r
             {\r
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentMode is disable!");\r
-\r
+                p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(false);\r
+                p_ConfigModel->SetSilentMode(false);\r
                 return true;\r
             }\r
             break;\r
index 404fe08..6d2a219 100644 (file)
@@ -45,18 +45,6 @@ namespace OHOS
         {\r
             SoundAndVibrationScrollView->RemoveAll();\r
 \r
-            bool state = GetVibrationReminderToggleButtonState();\r
-            if (state == true)\r
-            {\r
-                SoundAndVibrationModel::GetInstance()->SetVibrationReminderToggleButtonStaus(true);\r
-            }\r
-            state = GetSilentModeToggleButtonState();\r
-\r
-            if (state == true)\r
-            {\r
-                SoundAndVibrationModel::GetInstance()->SetSilentModeToggleButtonStatus(true);\r
-            }\r
-\r
             delete Title;\r
             Title = nullptr;\r
 \r
index 151f972..86590a3 100644 (file)
@@ -180,7 +180,7 @@ namespace OHOS
 \r
     void VoumeProcessSliderEventListener::OnChange(int32_t value)\r
     {\r
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnChange %d", value);\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnChange %d", value);\r
         ChangeVolumeValue(OTHER, value);\r
     }\r
 \r