--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-10 11:58:37
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-08-10 11:01:46
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp
+ */
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+#include "UiConfig.h"
+#include "dnotdisturb/include/DnotDisturbView.h"
+#include "dnotdisturb/include/DnotDisturbPresenter.h"
+#include "dnotdisturb/include/DnotDisturbModel.h"
+#include "common/key_code.h"
+#include <custom_utils.h>
+#include "NativeRegisterManager.h"
+namespace OHOS
+{
+ REGIST_SLICE(VIEW_DNOTDISTURB, DnotDisturbView, DnotDisturbPresenter);
+
+ // 当前Presenter属性实例化的内存指针
+ static DnotDisturbPresenter *g_pDnotDisturbPresenter = nullptr;
+
+ DnotDisturbPresenter::DnotDisturbPresenter()
+ {
+ g_pDnotDisturbPresenter = this;
+ }
+
+ DnotDisturbPresenter::~DnotDisturbPresenter()
+ {
+ g_pDnotDisturbPresenter = nullptr;
+ }
+
+ DnotDisturbPresenter *DnotDisturbPresenter::GetInstance()
+ {
+ return g_pDnotDisturbPresenter;
+ }
+
+ void DnotDisturbPresenter::OnStart()
+ {
+ }
+
+ void DnotDisturbPresenter::OnPause(void)
+ {
+ Presenter<DnotDisturbView>::OnPause();
+ }
+
+ void DnotDisturbPresenter::OnResume(void)
+ {
+ Presenter<DnotDisturbView>::OnResume();
+ }
+
+ void DnotDisturbPresenter::OnStop(void)
+ {
+ }
+
+ bool DnotDisturbPresenter::OnDrag(UIView &view, const DragEvent &event)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnDrag");
+ UNUSED(view);
+ if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
+ {
+ DnotDisturbPresenter::X_DRAG_FLAG = true;
+ }
+ return true;
+ }
+
+ bool DnotDisturbPresenter::OnDragEnd(UIView &view, const DragEvent &event)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnDragEnd");
+ UNUSED(event);
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && DnotDisturbPresenter::X_DRAG_FLAG)
+ {
+ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ DnotDisturbPresenter::X_DRAG_FLAG = false;
+ }
+ return true;
+ }
+
+ bool DnotDisturbPresenter::OnClick(UIView &view, const ClickEvent &event)
+ {
+ UNUSED(event);
+ DnotDisturbView *p_DnotDisturbView = DnotDisturbView::GetInstance();
+ if (p_DnotDisturbView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::GetInstance fail!!");
+ return false;
+ }
+ if (&view == p_DnotDisturbView->GetButtonOn()) // 开启勿扰模式
+ {
+ bool state = DnotDisturbModel::GetInstance().GetDoNotDisturbModeEnabled();
+ DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(state ? false : true);
+ }
+ else if (&view == p_DnotDisturbView->GetButtonOff())
+ {
+ // NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ }
+ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ return true;
+ }
+
+ // 增加按键事件
+ bool DnotDisturbPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnKeyAct");
+ uint16_t keyID = event.GetKeyId();
+ uint16_t keyState = event.GetState();
+ // 如果是power键就返回上一级
+ if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
+ {
+ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ }
+ return true;
+ }
+
+ void DnotDisturbPresenter::Notify()
+ {
+ // DnotDisturbView::GetInstance()->UpdataTime();
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-10 11:58:21
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2025-02-24 18:06:56
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbView.cpp
+ */
+#include "dnotdisturb/include/DnotDisturbView.h"
+#include "dnotdisturb/include/DnotDisturbPresenter.h"
+#include "dnotdisturb/include/DnotDisturbModel.h"
+#include "wearable_log.h"
+#include "screensetting/include/ScreenModels.h"
+#include "UiConfig.h"
+#include "ui_resource_image.h"
+#include "uicomponents/UIComponents.h"
+#include "ui_resource_string.h"
+namespace OHOS
+{
+
+ static DnotDisturbView *g_pDnotDisturbView{nullptr};
+
+ DnotDisturbView::DnotDisturbView()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::DnotDisturbView");
+ g_pDnotDisturbView = this;
+ }
+
+ DnotDisturbView::~DnotDisturbView()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::~DnotDisturbView");
+ ClearAll();
+ g_pDnotDisturbView = nullptr;
+ }
+
+ DnotDisturbView *DnotDisturbView::GetInstance()
+ {
+ return g_pDnotDisturbView;
+ }
+
+ void DnotDisturbView::ClearAll(void)
+ {
+ if (scrollView != nullptr)
+ {
+ scrollView->RemoveAll();
+
+ if (showTitleLabel != nullptr)
+ {
+ delete showTitleLabel;
+ showTitleLabel = nullptr;
+ }
+
+ if (DnotDisturbImage != nullptr)
+ {
+ delete DnotDisturbImage;
+ DnotDisturbImage = nullptr;
+ }
+
+ if (AttentionLabel != nullptr)
+ {
+ delete AttentionLabel;
+ AttentionLabel = nullptr;
+ }
+
+ if (ButtonOn != nullptr)
+ {
+ delete ButtonOn;
+ ButtonOn = nullptr;
+ }
+
+ if (ButtonOff != nullptr)
+ {
+ delete ButtonOff;
+ ButtonOff = nullptr;
+ }
+ if (temp != nullptr)
+ {
+ delete temp;
+ temp = nullptr;
+ }
+ delete scrollView;
+ scrollView = nullptr;
+ }
+ }
+
+ void DnotDisturbView::DnotDisturbViewInit(void)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::DnotDisturbViewInit");
+ if (scrollView == nullptr)
+ {
+ scrollView = new UIScrollView();
+ if (scrollView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::scrollView new fail!!");
+ return;
+ }
+ scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+ scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ scrollView->SetTouchable(true);
+ scrollView->SetDraggable(true);
+ scrollView->SetScrollBlankSize(30);
+ scrollView->SetReboundSize(30);
+ scrollView->SetDirection(1);
+ scrollView->SetThrowDrag(true); // 设置手指抬起屏幕后是否继续滚动。
+ scrollView->SetMaxScrollDistance(1000); // 设置手指抬起屏幕后的最大滚动距离。
+ scrollView->SetSwipeACCLevel(200); /*设置手指抬起屏幕后的补偿距离。*/
+ FocusManager::GetInstance()->RequestFocus(scrollView);
+ FocusManager::GetInstance()->RequestFocusByDirection(FOCUS_DIRECTION_UP);
+ scrollView->SetRotateFactor(1.0);
+ UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(DnotDisturbPresenter::GetInstance());
+ if (dragListener == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::dragListener new fail!!");
+ return;
+ }
+ scrollView->SetOnDragListener(dragListener);
+ /* -------------------------------------------------------------------------- */
+ showTitleLabel = new UILabelExt();
+ if (showTitleLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::showTitleLabel new fail!!");
+ return;
+ }
+ showTitleLabel->SetPosition(83, 52, 300, 35);
+ showTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ showTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ showTitleLabel->SetTextId(STR_DO_NOT_DISTURB);
+ showTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
+ showTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ showTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ scrollView->Add(showTitleLabel);
+ /* -------------------------------------------------------------------------- */
+ DnotDisturbImage = new UIImageView();
+ if (DnotDisturbImage == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::DnotDisturbImage new fail!!");
+ return;
+ }
+ DnotDisturbImage->SetPosition(186, 110);
+ DnotDisturbImage->Resize(94, 94);
+ DnotDisturbImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xff8120e2);
+ DnotDisturbImage->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ DnotDisturbImage->SetStyle(STYLE_BORDER_RADIUS, 100);
+ DnotDisturbImage->SetAutoEnable(false);
+ DnotDisturbImage->SetResizeMode(UIImageView::FILL);
+ DnotDisturbImage->SetSrc(PNG_APPLIST_DISTURB_IMAGE);
+ scrollView->Add(DnotDisturbImage);
+ /* -------------------------------------------------------------------------- */
+ AttentionLabel = new UILabelExt();
+ if (AttentionLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::AttentionLabel new fail!!");
+ return;
+ }
+ AttentionLabel->SetPosition(33, 228, 400, 70);
+ AttentionLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ AttentionLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ // bool ?勿扰模式已开启是否关闭:开启勿扰模式,手表将不会发出震动与铃声,是否开启
+ AttentionLabel->SetTextId(DnotDisturbModel::GetInstance().GetDoNotDisturbModeEnabled() ? STR_DISTURBNOTE_OFF : STR_DO_NOT_DISTURB_MODE);
+ AttentionLabel->SetLineBreakMode(UILabelExt::LINE_BREAK_WRAP);
+ AttentionLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
+ AttentionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ AttentionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ scrollView->Add(AttentionLabel);
+ /* -------------------------------------------------------------------------- */
+ ButtonOn = new UILabelButtonExt();
+ if (ButtonOn == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::ButtonOn new fail!!");
+ return;
+ }
+ ButtonOn->SetPosition(256, AttentionLabel->GetY() + AttentionLabel->GetHeight() + 20, 120, 120);
+ ButtonOn->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ ButtonOn->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+ const char *ButtonOnImgSrc = "/user/res/SYSTEM_CheckOn.bin";
+ ButtonOn->SetImageSrc(ButtonOnImgSrc, ButtonOnImgSrc);
+ ButtonOn->SetImagePosition(10, 10);
+ ButtonOn->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED);
+ ButtonOn->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);
+ ButtonOn->SetOnClickListener(presenter_);
+ scrollView->Add(ButtonOn);
+ /* -------------------------------------------------------------------------- */
+ ButtonOff = new UILabelButtonExt();
+ if (ButtonOff == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::ButtonOff new fail!!");
+ return;
+ }
+ ButtonOff->SetPosition(111, AttentionLabel->GetY() + AttentionLabel->GetHeight() + 20, 120, 120);
+ ButtonOff->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ ButtonOff->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+ const char *ButtonOffImgSrc = "/user/res/SYSTEM_CheckOff.bin";
+ ButtonOff->SetImageSrc(ButtonOffImgSrc, ButtonOffImgSrc);
+ ButtonOff->SetImagePosition(10, 10);
+ ButtonOff->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED);
+ ButtonOff->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);
+ ButtonOff->SetOnClickListener(presenter_);
+ scrollView->Add(ButtonOff);
+ /* -------------------------------------------------------------------------- */
+ if ((ButtonOff->GetY() + ButtonOff->GetHeight() > Screen::GetInstance().GetHeight()))
+ {
+ if (temp == nullptr)
+ {
+ temp = new UIImageView();
+ if (temp == nullptr)
+ {
+ return;
+ }
+
+ temp->SetPosition(43, ButtonOff->GetY() + ButtonOff->GetHeight(), 380, 40);
+ temp->SetVisible(false);
+ scrollView->Add(temp);
+ }
+ }
+ }
+ }
+
+ /*更新当前时间*/
+ void DnotDisturbView::UpdataTime()
+ {
+#if 0
+ // 获取当前时间
+ struct tm pTM;
+ time_t seconds;
+ time(&seconds);
+ localtime_r(&seconds, &pTM);
+
+ // 解析时间
+ int hour = pTM.tm_hour;
+ int minute = pTM.tm_min;
+
+ // 将时间和日期转换为字符串
+ std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
+ showTitleLabel->SetText(stringtime.c_str());
+#endif
+ }
+
+ UILabelButtonExt *DnotDisturbView::GetButtonOn(void)
+ {
+ return ButtonOn;
+ }
+
+ UILabelButtonExt *DnotDisturbView::GetButtonOff(void)
+ {
+ return ButtonOff;
+ }
+
+ void DnotDisturbView::OnStart()
+ {
+ DnotDisturbViewInit();
+
+ if (scrollView)
+ {
+ AddViewToRootContainer(scrollView);
+ }
+ }
+}
\ No newline at end of file