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
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
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
27 REGIST_SLICE(VIEW_SOUND_VIBRATION, SoundAndVibrationView, SoundAndVibrationPresenter);
\r
28 // 当前Presenter属性实例化的内存指针
\r
29 static SoundAndVibrationPresenter *g_pSoundAndVibrationPresenter = nullptr;
\r
31 SoundAndVibrationPresenter::SoundAndVibrationPresenter()
\r
33 g_pSoundAndVibrationPresenter = this;
\r
36 SoundAndVibrationPresenter::~SoundAndVibrationPresenter()
\r
38 g_pSoundAndVibrationPresenter = nullptr;
\r
41 SoundAndVibrationPresenter *SoundAndVibrationPresenter::GetInstance()
\r
43 return g_pSoundAndVibrationPresenter;
\r
46 void SoundAndVibrationPresenter::OnStart()
\r
50 void SoundAndVibrationPresenter::OnPause(void)
\r
52 Presenter<SoundAndVibrationView>::OnPause();
\r
55 void SoundAndVibrationPresenter::OnResume(void)
\r
57 if (view_ == nullptr)
\r
61 RootView::GetInstance()->SetOnKeyActListener(this);
\r
64 void SoundAndVibrationPresenter::OnStop(void)
\r
68 bool SoundAndVibrationPresenter::OnDrag(UIView &view, const DragEvent &event)
\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
74 SoundAndVibrationPresenter::X_DRAG_FLAG = true;
\r
79 bool SoundAndVibrationPresenter::OnDragEnd(UIView &view, const DragEvent &event)
\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
86 if (viewId == VIBRATION_MODE_VIEWID) // 如果在震动提醒子视图
\r
88 view_->GetVibrationModeView()->UpdatePickerSelectIndex();
\r
89 SoundAndVibrationView::GetInstance()->ChangeView(VIBRATIONMODEVIEW, SOUNDANDVIBRATIONVIEW);
\r
93 NativeAbility::GetInstance().Back();
\r
95 SoundAndVibrationPresenter::X_DRAG_FLAG = false;
\r
101 bool SoundAndVibrationPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件
\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
110 NativeAbility::GetInstance().Back();
\r
115 bool SoundAndVibrationPresenter::OnClick(UIView &view, const ClickEvent &event)
\r
118 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnKeyAct");
\r
119 if (strcmp(view.GetViewId(), SYSTEM_VOLUME_BUTTON) == 0)
\r
121 NativeAbility::GetInstance().EnterSlice(VIEW_SYSTEM_VOLUME);
\r
123 else if (strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0)
\r
125 NativeAbility::GetInstance().EnterSlice(VIEW_CALL_VOLUME);
\r
127 else if (strcmp(view.GetViewId(), VIBRATION_REMINDER_BUTTON) == 0)
\r
129 view_->ChangeView(SOUNDANDVIBRATIONVIEW, VIBRATIONMODEVIEW);
\r
131 else if ((view_->GetVibrationModeView() != nullptr) && (&view == view_->GetVibrationModeView()->GetVibrationModeLabelButton()))
\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
142 bool SoundAndVibrationPresenter::OnChange(UICheckBox::UICheckBoxState state)
\r
144 SoundAndVibrationModel *p_SoundAndVibrationModel = SoundAndVibrationModel::GetInstance();
\r
147 case UICheckBox::SELECTED:
\r
148 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SilentMode is enable!");
\r
149 p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(true);
\r
151 case UICheckBox::UNSELECTED:
\r
152 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SilentMode is disable!");
\r
153 p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(false);
\r
161 bool SoundAndVibrationPresenter::OnRotate(UIView &view, const RotateEvent &event)
\r
168 bool SoundAndVibrationPresenter::OnRotateEnd(UIView &view, const RotateEvent &event)
\r