ef7f4397e7f42e9a4ba8618bc8abbee3fe10f2aa
[mirrors/FD230.git] /
1 /*\r
2  * @Author: luozheng 1732036298@qq.com\r
3  * @Date: 2024-02-19 10:39:11\r
4  * @LastEditors: luozheng 1732036298@qq.com\r
5  * @LastEditTime: 2024-11-05 14:42:21\r
6  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp\r
7  */\r
8 \r
9 #include "AppViewIDs.h"\r
10 #include "components/ui_label_ext.h"\r
11 #include "ui_resource_string.h"\r
12 #include "NativeAbility.h"\r
13 #include "graphic_math.h"\r
14 #include "string.h"\r
15 #include "soundandvibration/include/SoundAndVibrationPresenter.h"\r
16 #include "common/key_code.h"\r
17 #include "custom_utils.h"\r
18 #include "ConfigModel.h"\r
19 #include <ohos_types.h>\r
20 #include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h"\r
21 #include "UiConfig.h"\r
22 #include "vibrator_service.h"\r
23 #include "NativeRegisterManager.h"\r
24 \r
25 namespace OHOS\r
26 {\r
27     REGIST_SLICE(VIEW_SOUND_VIBRATION, SoundAndVibrationView, SoundAndVibrationPresenter);\r
28     // 当前Presenter属性实例化的内存指针\r
29     static SoundAndVibrationPresenter *g_pSoundAndVibrationPresenter = nullptr;\r
30 \r
31     SoundAndVibrationPresenter::SoundAndVibrationPresenter()\r
32     {\r
33         g_pSoundAndVibrationPresenter = this;\r
34     }\r
35 \r
36     SoundAndVibrationPresenter::~SoundAndVibrationPresenter()\r
37     {\r
38         g_pSoundAndVibrationPresenter = nullptr;\r
39     }\r
40 \r
41     SoundAndVibrationPresenter *SoundAndVibrationPresenter::GetInstance()\r
42     {\r
43         return g_pSoundAndVibrationPresenter;\r
44     }\r
45 \r
46     void SoundAndVibrationPresenter::OnStart()\r
47     {\r
48     }\r
49 \r
50     void SoundAndVibrationPresenter::OnPause(void)\r
51     {\r
52         Presenter<SoundAndVibrationView>::OnPause();\r
53     }\r
54 \r
55     void SoundAndVibrationPresenter::OnResume(void)\r
56     {\r
57         if (view_ == nullptr)\r
58         {\r
59             return;\r
60         }\r
61         RootView::GetInstance()->SetOnKeyActListener(this);\r
62     }\r
63 \r
64     void SoundAndVibrationPresenter::OnStop(void)\r
65     {\r
66     }\r
67 \r
68     bool SoundAndVibrationPresenter::OnDrag(UIView &view, const DragEvent &event)\r
69     {\r
70         UNUSED(view);\r
71         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RespiratoryTrainingPresenter::OnDrag");\r
72         if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动\r
73         {\r
74             SoundAndVibrationPresenter::X_DRAG_FLAG = true;\r
75         }\r
76         return true;\r
77     }\r
78 \r
79     bool SoundAndVibrationPresenter::OnDragEnd(UIView &view, const DragEvent &event)\r
80     {\r
81         UNUSED(view);\r
82         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnDragEnd");\r
83         std::string viewId = view.GetViewId();\r
84         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SoundAndVibrationPresenter::X_DRAG_FLAG)\r
85         {\r
86             if (viewId == VIBRATION_MODE_VIEWID) // 如果在震动提醒子视图\r
87             {\r
88                 view_->GetVibrationModeView()->UpdatePickerSelectIndex();\r
89                 SoundAndVibrationView::GetInstance()->ChangeView(VIBRATIONMODEVIEW, SOUNDANDVIBRATIONVIEW);\r
90             }\r
91             else\r
92             {\r
93                 NativeAbility::GetInstance().Back();\r
94             }\r
95             SoundAndVibrationPresenter::X_DRAG_FLAG = false;\r
96         }\r
97 \r
98         return true;\r
99     }\r
100 \r
101     bool SoundAndVibrationPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件\r
102     {\r
103         UNUSED(view);\r
104         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnKeyAct");\r
105         uint16 keyID = event.GetKeyId();\r
106         uint16 keyState = event.GetState();\r
107         // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
108         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)\r
109         {\r
110             NativeAbility::GetInstance().Back();\r
111         }\r
112         return true;\r
113     }\r
114 \r
115     bool SoundAndVibrationPresenter::OnClick(UIView &view, const ClickEvent &event)\r
116     {\r
117         UNUSED(event);\r
118         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnKeyAct");\r
119         if (strcmp(view.GetViewId(), SYSTEM_VOLUME_BUTTON) == 0)\r
120         {\r
121             NativeAbility::GetInstance().EnterSlice(VIEW_SYSTEM_VOLUME);\r
122         }\r
123         else if (strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0)\r
124         {\r
125             NativeAbility::GetInstance().EnterSlice(VIEW_CALL_VOLUME);\r
126         }\r
127         else if (strcmp(view.GetViewId(), VIBRATION_REMINDER_BUTTON) == 0)\r
128         {\r
129             view_->ChangeView(SOUNDANDVIBRATIONVIEW, VIBRATIONMODEVIEW);\r
130         }\r
131         else if ((view_->GetVibrationModeView() != nullptr) && (&view == view_->GetVibrationModeView()->GetVibrationModeLabelButton()))\r
132         {\r
133             int VibrationMode = view_->GetVibrationModeView()->GetVibrationModePicker()->GetSelected();\r
134             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VibrationMode = %d", VibrationMode);\r
135             SoundAndVibrationModel::GetInstance()->SetVibrationReminderToggleButtonStaus(VibrationMode);\r
136             custom_VibratorFunc_int(0);\r
137             view_->ChangeView(VIBRATIONMODEVIEW, SOUNDANDVIBRATIONVIEW);\r
138         }\r
139         return true;\r
140     }\r
141 \r
142     bool SoundAndVibrationPresenter::OnChange(UICheckBox::UICheckBoxState state)\r
143     {\r
144         SoundAndVibrationModel *p_SoundAndVibrationModel = SoundAndVibrationModel::GetInstance();\r
145         switch (state)\r
146         {\r
147         case UICheckBox::SELECTED:\r
148             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SilentMode is enable!");\r
149             p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(true);\r
150             break;\r
151         case UICheckBox::UNSELECTED:\r
152             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SilentMode is disable!");\r
153             p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(false);\r
154             break;\r
155         default:\r
156             break;\r
157         }\r
158         return true;\r
159     }\r
160 \r
161     bool SoundAndVibrationPresenter::OnRotate(UIView &view, const RotateEvent &event)\r
162     {\r
163         UNUSED(view);\r
164         UNUSED(event);\r
165         return true;\r
166     }\r
167 \r
168     bool SoundAndVibrationPresenter::OnRotateEnd(UIView &view, const RotateEvent &event)\r
169     {\r
170         UNUSED(view);\r
171         UNUSED(event);\r
172         return true;\r
173     }\r
174 }