增加静音模式开关
authorluozheng <1732036298@qq.com>
Mon, 22 Apr 2024 03:45:29 +0000 (11:45 +0800)
committerluozheng <1732036298@qq.com>
Mon, 22 Apr 2024 03:45:29 +0000 (11:45 +0800)
12 files changed:
code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h
code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h
code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationModel.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.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/SoundAndVibrationVolumeSettingPresenter.cpp
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index b96626f..e1bedb4 100644 (file)
@@ -126,9 +126,6 @@ namespace OHOS
         void SetVibrationReminder(int state);
         int GetVibrationReminder(void);
         
-        void SetSilentMode(bool state);
-        bool GetSilentMode(void);
-
         void SetCat1_4Gability(bool state);
         bool GetCat1_4Gability();
 
@@ -151,6 +148,10 @@ namespace OHOS
 
         void SetCallVolume(int value);
         int GetCallVolume(void);
+
+
+        void SetSilentMode(bool state);
+        bool GetSilentMode(void);
         /* --------------------------------- 用户配置信息 --------------------------------- */
         void SetUserAge(int age);
         int GetUserAge();
index 25e7e3d..6916184 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-17 09:32:03
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-22 09:48:51
+ * @LastEditTime: 2024-04-22 10:54:51
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h
  */
 #ifndef _CONFIG_MODEL_C_H_
@@ -50,6 +50,11 @@ void initializeRaiseToWake(void);
  * @brief 初始化系统音量和通话音量 
  */
 void initializeVolume(void);
+
+/*
+ * @brief 初始化静音模式 
+ */
+void initializeSilentModel(void);
 #ifdef __cplusplus
 #if __cplusplus
 }
index dfcfd6b..d36ff19 100644 (file)
@@ -575,7 +575,7 @@ namespace OHOS
     }
 
     /*
-     * @brief è®¾ç½®é\9c\87å\8a¨æ\8f\90é\86\92
+     * @brief è®¾ç½®é\9c\87å\8a¨æ¨¡å¼\8f强度
      * @param 马达 开关, 0 关, 1 弱, 2 中,3 强
      */
     void ConfigModel::SetVibrationReminder(int state)
@@ -583,7 +583,7 @@ namespace OHOS
         set_condigData_Bool(CONFIGMODEL_ITEM_VIBRATOR_SWITCH,state);
     }
 
-    /*è\8e·å\8f\96é\9c\87å\8a¨æ\8f\90é\86\92æ\98¯å\90¦å¼\80å\90¯*/
+    /*è\8e·å\8f\96é\9c\87å\8a¨æ¨¡å¼\8f强度*/
     int ConfigModel::GetVibrationReminder(void)
     {
         return get_configData_int(CONFIGMODEL_ITEM_VIBRATOR_SWITCH);
@@ -814,6 +814,13 @@ void initializeVolume(void)
     uapi_callVolumeSet(callVolume);
 }
 
+void initializeSilentModel(void)
+{
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "initializeVolume");
+    bool isopen = OHOS::ConfigModel::GetInstance()->GetSilentMode();
+    uapi_setSilentMode(isopen);
+}
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index 341f2d0..b22c34f 100644 (file)
@@ -9,9 +9,8 @@ namespace OHOS
         static SoundAndVibrationModel *GetInstance(void);
 
         void SetVibrationReminderToggleButtonStaus(bool value);
-        bool VibrationReminderToggleButtonStatusInit(void);
         void SetSilentModeToggleButtonStatus(bool value);
-        bool SilentModeToggleButtonStatusInit(void);
+        bool GetSilentModeToggleButtonStatus(void);
 
     private:
         SoundAndVibrationModel();
index 4440804..eca2e78 100644 (file)
@@ -33,7 +33,6 @@ namespace OHOS
         void OnStop() override;\r
 \r
         static SoundAndVibrationPresenter *GetInstance();\r
-        void SilentModeToggleButtonStateSetting(bool value);\r
 \r
     private:\r
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
index 0c06486..03ce63c 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-19 18:59:49
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-19 19:08:01
+ * @LastEditTime: 2024-04-22 11:26:38
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.h
  */
 #ifndef SOUND_AND_VIBRATION_VOLUME_SETTINGC_H
@@ -15,10 +15,11 @@ extern "C"
 #endif
 #endif
 #include <stdint.h>
+#include <stdbool.h>
 
     void SystemVolumeSet(int16_t sounding);
     void CallVolumeSet(int16_t sounding);
-
+    bool SilentModelSet(bool isopen);
 #ifdef __cplusplus
 #if __cplusplus
 }
index 1513db2..42213cb 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-02-23 09:17:00
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-18 18:03:36
+ * @LastEditTime: 2024-04-22 10:30:00
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationModel.cpp
  */
 #include "soundandvibration/include/SoundAndVibrationModel.h"
@@ -14,7 +14,7 @@ namespace OHOS
 
     SoundAndVibrationModel::SoundAndVibrationModel()
     {
-        ConfigModel *p_ConfigModel  = ConfigModel::GetInstance();
+        ConfigModel *p_ConfigModel = ConfigModel::GetInstance();
         VibrationReminderToggleButtonState = p_ConfigModel->GetVibrationReminder();
         SilentModeToggleButtonState = p_ConfigModel->GetSilentMode();
     }
@@ -41,19 +41,10 @@ namespace OHOS
         ConfigModel::GetInstance()->SetSilentMode(value);
     }
 
-    /// @brief “静音模式”切换按钮状态初始化
-    /// @param void
-    /// @return true 初始化成功 false 初始化失败
-    bool SoundAndVibrationModel::SilentModeToggleButtonStatusInit(void)
+    /// @brief 获取“静音模式”是否开启
+    bool SoundAndVibrationModel::GetSilentModeToggleButtonStatus(void)
     {
-        SoundAndVibrationPresenter *p_SoundAndVibrationPresenter = SoundAndVibrationPresenter::GetInstance();
-        if (p_SoundAndVibrationPresenter == nullptr)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentModeToggleButtonStatusInit SoundAndVibrationPresenter GetInstance fail!");
-            return false;
-        }
-        p_SoundAndVibrationPresenter->SilentModeToggleButtonStateSetting(SilentModeToggleButtonState);
-        return true;
+        return ConfigModel::GetInstance()->GetSilentMode();
     }
 
 }
index e5dac2f..d7f11eb 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-04-19 21:05:28\r
+ * @LastEditTime: 2024-04-22 11:27:48\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp\r
  */\r
 \r
@@ -17,6 +17,7 @@
 #include "custom_utils.h"\r
 #include "config/include/ConfigModel.h"\r
 #include <ohos_types.h>\r
+#include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h"\r
 \r
 namespace OHOS\r
 {\r
@@ -42,22 +43,6 @@ namespace OHOS
         return g_pSoundAndVibrationPresenter;\r
     }\r
 \r
-    /// @brief "静音模式"按钮状态设置\r
-    /// @param value true 开启 false 关闭\r
-    void SoundAndVibrationPresenter::SilentModeToggleButtonStateSetting(bool value)\r
-    {\r
-        SoundAndVibrationView *p_SoundAndVibrationView = SoundAndVibrationView::GetInstance();\r
-        if (p_SoundAndVibrationView == nullptr)\r
-        {\r
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentModeToggleButtonStateSetting SoundAndVibrationView GetInstance fail!");\r
-            return;\r
-        }\r
-        if (value != false)\r
-        {\r
-            p_SoundAndVibrationView->SetSilentModeToggleButtonState(true);\r
-        }\r
-    }\r
-\r
     void SoundAndVibrationPresenter::OnStart()\r
     {\r
 \r
@@ -140,11 +125,11 @@ namespace OHOS
         {\r
         case UICheckBox::SELECTED:\r
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentMode is enable!");\r
-            p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(true);\r
+            p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(SilentModelSet(true));\r
             break;\r
         case UICheckBox::UNSELECTED:\r
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentMode is disable!");\r
-            p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(false);\r
+            p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(SilentModelSet(false));\r
             break;\r
         default:\r
             break;\r
index c3c0a71..02b8a30 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-02-19 10:39:14\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-19 21:06:11\r
+ * @LastEditTime: 2024-04-22 10:33:47\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp\r
  */\r
 #include "soundandvibration/include/SoundAndVibrationView.h"\r
@@ -164,7 +164,7 @@ namespace OHOS
         struct ButtonSetup\r
         {\r
             int y;\r
-            const char * viewId;\r
+            const char *viewId;\r
             const char *text;\r
             bool clickEffect;\r
         };\r
@@ -209,6 +209,7 @@ namespace OHOS
         SilentModeToggleButton->SetPosition(298, 505, 100, 50);\r
         SilentModeToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
         SilentModeToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);\r
+        SilentModeToggleButton->SetState(SoundAndVibrationModel::GetInstance()->GetSilentModeToggleButtonStatus());\r
         const char *ToggleButtonSelect = "/user/res/TOGGLEBUTTON_ON.bin";\r
         const char *ToggleButtonUnSelect = "/user/res/TOGGLEBUTTON_OFF.bin";\r
         SilentModeToggleButton->SetImages(ToggleButtonSelect, ToggleButtonUnSelect);\r
@@ -256,10 +257,6 @@ namespace OHOS
         {\r
             return;\r
         }\r
-        // if (SoundAndVibrationModel::GetInstance()->SilentModeToggleButtonStatusInit() == false)\r
-        // {\r
-        //     return;\r
-        // }\r
     }\r
 \r
     void SoundAndVibrationView::OnStart()\r
index 7a240c8..bcc40fa 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-19 10:08:31
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-22 09:35:44
+ * @LastEditTime: 2024-04-22 11:28:47
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp
  */
 #include "soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h"
@@ -12,6 +12,7 @@
 #include <custom_utils.h>
 #include "phoneservice/include/PhoneAudio.h"
 #include "phoneservice/include/PhoneService.h"
+#include "../../../../../../middleware/services/media/foundation/audiomanager/frameworks/audioservice/include/audio_service.h"
 namespace OHOS
 {
 
@@ -168,6 +169,13 @@ extern "C"
         SetSpeakerVolume(sounding);
     }
 
+    /*
+     * @brief 静音模式设置 
+     */    
+    bool SilentModelSet(bool isopen)
+    {
+        return AudioServiceSetMasterMute(isopen);
+    }
 #ifdef __cplusplus
 #if __cplusplus
 }
index 8ed2104..1809eb3 100644 (file)
@@ -223,6 +223,8 @@ void startup_post_init_task(void)
     initScreenBrightness();
     initializeScreenDuration();
     initializeRaiseToWake();
+    initializeVolume();
+    initializeSilentModel();
 
     LOS_Msleep(5000);
     addressbookToRead();
@@ -634,6 +636,12 @@ void uapi_callVolumeSet(int16_t sounding)
     CallVolumeSet(sounding);
 }
 
+//设置是否静音
+void uapi_setSilentMode(bool isopen)
+{
+    SilentModelSet(isopen);
+}
+
 #include "bts_le_gap.h"
 
 
index fe407ba..48a041d 100644 (file)
@@ -61,6 +61,7 @@ int32_t uapi_get_screen_state(void);
 
 void uapi_systemVolumeSet(int16_t sounding);
 void uapi_callVolumeSet(int16_t sounding);
+void uapi_setSilentMode(bool isopen);
 
 errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr);
 errcode_t uapi_get_btname(uint8_t *buf_btname, uint32_t *len_btname);