蓝牙界面:利用ConfigModel类保存蓝牙是否开启状态
authorluozheng <1732036298@qq.com>
Thu, 29 Feb 2024 08:06:44 +0000 (16:06 +0800)
committerluozheng <1732036298@qq.com>
Thu, 29 Feb 2024 08:06:44 +0000 (16:06 +0800)
显示与亮度界面:保存设置的亮度值,亮屏时长
快速访问界面:保存用户设置的快速访问app

13 files changed:
code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h
code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp
code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp
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/displaybrightness/include/DisplayBrightnessModel.h
code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp
code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp
code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp
code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/include/SecondaryFunctionModel.h
code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/QuickAccessView.cpp
code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionModel.cpp
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/ConfigModel/ConfigModel.json

index 85ef8b6..849e455 100644 (file)
@@ -3,7 +3,11 @@
 \r
 namespace OHOS\r
 {\r
-    ClassicBlueToothModel::ClassicBlueToothModel() {}\r
+    ClassicBlueToothModel::ClassicBlueToothModel()\r
+    {\r
+        ConfigModel *p_ConfigModel = ConfigModel::GetInstance();\r
+        TradionalBlueToothToggleButtonState = (p_ConfigModel->ReadJsonData<bool>(p_ConfigModel->GetcJSON(), "TradionalBlueToothToggleButtonState"));\r
+    }\r
 \r
     ClassicBlueToothModel::~ClassicBlueToothModel() {}\r
 \r
index e1e0ec7..cdfe2ad 100644 (file)
@@ -34,6 +34,12 @@ namespace OHOS
             if (state == true)\r
             {\r
                 ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(true);\r
+                ConfigModel::GetInstance()->WriteJsonData(ConfigModel::GetInstance()->GetcJSON(), "TradionalBlueToothToggleButtonState", true);\r
+            }\r
+            else\r
+            {\r
+                ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(false);\r
+                ConfigModel::GetInstance()->WriteJsonData(ConfigModel::GetInstance()->GetcJSON(), "TradionalBlueToothToggleButtonState", false);\r
             }\r
 \r
             delete Title;\r
index 7897dae..e92562c 100644 (file)
@@ -1,3 +1,7 @@
 {
-    "RaiseToBrightnessCheckBoxButtonState":true
+    "RaiseToBrightnessCheckBoxButtonState": false,
+    "ScreenBrightnessValue": 255,
+    "ScreenDurationRadioButtonSlectValue": 1,
+    "TradionalBlueToothToggleButtonState": false,
+    "HeartRateOrBloodOxygenQuickAccessSwitch": 0
 }
\ No newline at end of file
index ce53ac0..bfbc508 100644 (file)
@@ -83,7 +83,7 @@ namespace OHOS
         }
 
         cJSON *data_obj = cJSON_CreateNull();
-        if constexpr (std::is_same<T, int>::value || std::is_same<T, long>::value || std::is_same<T, long long>::value)
+        if constexpr (std::is_same<T, int>::value || std::is_same<T, unsigned char>::value || std::is_same<T, unsigned int>::value)
         {
             data_obj = cJSON_CreateNumber(static_cast<double>(data));
         }
@@ -110,15 +110,16 @@ namespace OHOS
                 FILE *file = fopen(filePath.c_str(), "wb");
                 if (file)
                 {
-                    //fputs(jsonString, file);
-                    fwrite(jsonString, 1, strlen(jsonString), file); // 将 JSON 字符串写入文件
+                    fputs(jsonString, file);
+                    //fwrite(jsonString, 1, strlen(jsonString), file); // 将 JSON 字符串写入文件
                     fclose(file);
                 }
                 free(jsonString);
             }
             else
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Open JSON filePath fail!");
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jsonString is nullptr");
+                return;
             }
         }
     }
index d400d0b..491717b 100644 (file)
@@ -31,6 +31,7 @@ namespace OHOS
 \r
             unsigned char value = BrightnessControlViewSlider->GetValue();\r
             DisplayBrightnessModel::GetInstance()->KeepScreenBrightnessValues(value);\r
+            ConfigModel::GetInstance()->WriteJsonData(ConfigModel::GetInstance()->GetcJSON(),"ScreenBrightnessValue",value);\r
 \r
             delete BrightnessControlViewSlider;\r
             BrightnessControlViewSlider = nullptr;\r
index ec7b5ff..d0121fc 100644 (file)
@@ -1,6 +1,5 @@
 #include "displaybrightness/include/DisplayBrightnessModel.h"
 #include "displaybrightness/include/DisplayBrightnessPresenter.h"
-#include "config/include/ConfigModel.h"
 #include "wearable_log.h"
 namespace OHOS
 {
@@ -9,6 +8,8 @@ namespace OHOS
     {
         ConfigModel *p_ConfigModel = ConfigModel::GetInstance();
         RaiseToBrightnessCheckBoxButtonState = p_ConfigModel->ReadJsonData<bool>(p_ConfigModel->GetcJSON(), "RaiseToBrightnessCheckBoxButtonState");
+        ScreenBrightnessValue = static_cast<unsigned char>(p_ConfigModel->ReadJsonData<int>(p_ConfigModel->GetcJSON(), "ScreenBrightnessValue"));
+        ScreenDurationRadioButtonSlectValue = static_cast<unsigned char>(p_ConfigModel->ReadJsonData<int>(p_ConfigModel->GetcJSON(), "ScreenDurationRadioButtonSlectValue"));
     }
 
     DisplayBrightnessModel::~DisplayBrightnessModel() {}
index 845a5e5..8306da8 100644 (file)
@@ -40,6 +40,7 @@ namespace OHOS
                 }\r
             }\r
             DisplayBrightnessModel::GetInstance()->KeepScreenDurationRadioButtonSlectStatus(i);\r
+            ConfigModel::GetInstance()->WriteJsonData(ConfigModel::GetInstance()->GetcJSON(),"ScreenDurationRadioButtonSlectValue",i);\r
 \r
             delete ScreenDurationTitleLabel;\r
             ScreenDurationTitleLabel = nullptr;\r
index 0fa5897..1bcb732 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef SECONDARY_FUNCTION_MODEL_H
 #define SECONDARY_FUNCTION_MODEL_H
 
+#include "config/include/ConfigModel.h"
 namespace OHOS
 {
     class SecondaryFunctionModel
@@ -11,8 +12,8 @@ namespace OHOS
         bool HeartRateOrBloodOxygenQuickAccessRadioButtonSelectStateInit(void);
         bool GetHeartRateOrBloodOxygenQuickAccessSwitch(void);
     private:
-        SecondaryFunctionModel() {}
-        ~SecondaryFunctionModel() {}
+        SecondaryFunctionModel();
+        ~SecondaryFunctionModel();
         SecondaryFunctionModel(const SecondaryFunctionModel &);
         SecondaryFunctionModel &operator=(const SecondaryFunctionModel &);
 
index fc6fffd..47122fe 100644 (file)
@@ -40,10 +40,12 @@ namespace OHOS
             if (QuickAccessRadioButton[0]->GetState() == UICheckBox::SELECTED)\r
             {\r
                 SecondaryFunctionModel::GetInstance()->KeepHeartRateOrBloodOxygenQuickAccessRadioButtonSelectState(0);\r
+                ConfigModel::GetInstance()->WriteJsonData(ConfigModel::GetInstance()->GetcJSON(), "HeartRateOrBloodOxygenQuickAccessSwitch", 0);\r
             }\r
             else if (QuickAccessRadioButton[1]->GetState() == UICheckBox::SELECTED)\r
             {\r
                 SecondaryFunctionModel::GetInstance()->KeepHeartRateOrBloodOxygenQuickAccessRadioButtonSelectState(1);\r
+                ConfigModel::GetInstance()->WriteJsonData(ConfigModel::GetInstance()->GetcJSON(), "HeartRateOrBloodOxygenQuickAccessSwitch", 1);\r
             }\r
 \r
             // 循环删除 UIImageView 和 UIRadioButton指针数组\r
index 6fb72ee..5c558be 100644 (file)
@@ -5,6 +5,13 @@
 
 namespace OHOS
 {
+    SecondaryFunctionModel::SecondaryFunctionModel()
+    {
+        ConfigModel *p_ConfigModel = ConfigModel::GetInstance();
+        HeartRateOrBloodOxygenQuickAccessSwitch = (p_ConfigModel->ReadJsonData<bool>(p_ConfigModel->GetcJSON(), "HeartRateOrBloodOxygenQuickAccessSwitch"));
+    }
+    SecondaryFunctionModel::~SecondaryFunctionModel() {}
+
     SecondaryFunctionModel *SecondaryFunctionModel::GetInstance(void)
     {
         static SecondaryFunctionModel instacne;
index 7897dae..e92562c 100644 (file)
@@ -1,3 +1,7 @@
 {
-    "RaiseToBrightnessCheckBoxButtonState":true
+    "RaiseToBrightnessCheckBoxButtonState": false,
+    "ScreenBrightnessValue": 255,
+    "ScreenDurationRadioButtonSlectValue": 1,
+    "TradionalBlueToothToggleButtonState": false,
+    "HeartRateOrBloodOxygenQuickAccessSwitch": 0
 }
\ No newline at end of file