From ebedde6ecf771a4feddac357f834bc2d1d9e3c9f Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 25 Jun 2025 10:48:45 +0800 Subject: [PATCH] =?utf8?q?=E9=97=B9=E9=92=9F=E5=BC=B9=E7=AA=97=E7=95=8C?= =?utf8?q?=E9=9D=A2=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/notify/alarm_notification.h | 105 +- .../msg_center/src/msg_center_customer.cpp | 12 +- .../src/notify/alarm_notification.cpp | 984 ++++++++++-------- 3 files changed, 641 insertions(+), 460 deletions(-) diff --git a/code/sdk/application/wearable/fd230/service/msg_center/include/notify/alarm_notification.h b/code/sdk/application/wearable/fd230/service/msg_center/include/notify/alarm_notification.h index 986be0075..9491ccb00 100644 --- a/code/sdk/application/wearable/fd230/service/msg_center/include/notify/alarm_notification.h +++ b/code/sdk/application/wearable/fd230/service/msg_center/include/notify/alarm_notification.h @@ -8,58 +8,69 @@ #ifndef ALARM_NOTIFICATION_H #define ALARM_NOTIFICATION_H -static constexpr const char* ALARM_IMAGE_DELETE = "alarm_delete"; -static constexpr const char* ALARM_IMAGE_CLOCK = "alarm_clock"; -static constexpr const char* ALARM_VIEW_CLOSE = "alarm_close"; -static constexpr const char* ALARM_VIEW_DELAY = "alarm_delay"; -static constexpr const char* ALARM_VIEW_POPUP = "alarm_popup"; +constexpr const char *ALARM_IMAGE_STOP = "alarm_stop"; // 闹钟停止 +constexpr const char *ALARM_IMAGE_CLOCK = "alarm_clock"; +constexpr const char *ALARM_VIEW_CLOSE = "alarm_close"; +constexpr const char *ALARM_VIEW_DELAY = "alarm_delay"; +constexpr const char *ALARM_VIEW_POPUP = "alarm_popup"; // 闹钟弹窗 -enum class AlarmTimerType { - NOTIFY_ALARM_CLOSE = 0, - NOTIFY_ALARM_DELAY = 1, - NOTIFY_ALARM_RING = 2, - NOTIFY_ALARM_UNKNOWN = 10, +enum class AlarmTimerType +{ + NOTIFY_ALARM_CLOSE = 0, // 关闭闹钟 + NOTIFY_ALARM_DELAY = 1, // 延迟闹钟 + NOTIFY_ALARM_RING = 2, // 响铃闹钟 + NOTIFY_ALARM_UNKNOWN = 10, // 无效闹钟类型 }; -namespace OHOS { -UIViewGroup* CreateAlarmView(void); -UIViewGroup *CreateAlarmCloseView(void); -UIViewGroup *CreateAlarmRingView(void); -void FreeAlarmCloseView(void); -void FreeAlarmRingView(void); -void FreeAlarmView(void); -void StartAlarmTimer(AlarmTimerType type, int32_t interval); -void DisableAlarmTimer(AlarmTimerType type); +namespace OHOS +{ + UIViewGroup *CreateAlarmView(void); + UIViewGroup *CreateAlarmCloseView(void); + UIViewGroup *CreateAlarmRingView(void); + void FreeAlarmCloseView(void); + void FreeAlarmRingView(void); + void FreeAlarmView(void); + void StartAlarmTimer(AlarmTimerType type, int32_t interval); + void DisableAlarmTimer(AlarmTimerType type); -class AlarmViewEventListener : public OHOS::UIView::OnClickListener, - public OHOS::UIView::OnLongPressListener, - public OHOS::UIView::OnTouchListener, - public OHOS::UIView::OnDragListener { -public: - AlarmViewEventListener(); - virtual ~AlarmViewEventListener(); - static AlarmViewEventListener *GetInstance(void); - bool OnDrag(UIView& view, const DragEvent& event) override; - bool OnDragEnd(OHOS::UIView& view, const OHOS::DragEvent& event) override; - bool OnClick(OHOS::UIView& view, const OHOS::ClickEvent& event) override; - bool OnPress(OHOS::UIView& view, const OHOS::PressEvent& event) override + class AlarmViewEventListener : public OHOS::UIView::OnClickListener, + public OHOS::UIView::OnLongPressListener, + public OHOS::UIView::OnTouchListener, + public RootView::OnKeyActListener, + public OHOS::UIView::OnDragListener { - return true; - } - bool OnLongPress(OHOS::UIView& view, const OHOS::LongPressEvent& event) override - { - return true; - } - bool OnRelease(OHOS::UIView& view, const OHOS::ReleaseEvent& event) override - { - return true; - } - - bool OnDragStart(OHOS::UIView& view, const OHOS::DragEvent& event) override - { - return true; - } -}; + public: + AlarmViewEventListener(); + virtual ~AlarmViewEventListener(); + static AlarmViewEventListener *GetInstance(void); + void PopAlarmRing(); + void CancelAlarmRing(); + void DelayAlarmRing(); + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event) override; + bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) override; + bool OnPress(OHOS::UIView &view, const OHOS::PressEvent &event) override + { + return true; + } + bool OnLongPress(OHOS::UIView &view, const OHOS::LongPressEvent &event) override + { + return true; + } + bool OnRelease(OHOS::UIView &view, const OHOS::ReleaseEvent &event) override + { + return true; + } + bool OnDragStart(OHOS::UIView &view, const OHOS::DragEvent &event) override + { + return true; + } + bool OnKeyAct(UIView &view, const KeyEvent &event) override + { + return true; + } + static uint8_t pre_screen_status; + }; }; // namespace OHOS #endif /* ALARM_NOTIFICATION_H */ diff --git a/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp index c4d12737e..f7d30a95d 100644 --- a/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp @@ -68,7 +68,7 @@ extern "C" { /* 订阅事件设定优先级 */ const PriorityMapper PRI_MAPPER[] = { - {TOPIC_EVENT_ALARM_RING, PRIORITY_TWO}, + {TOPIC_EVENT_ALARM_RING, PRIORITY_ONE}, {TOPIC_EVENT_NEXTDAY_UPDATE, PRIORITY_TWO}, {TOPIC_EVENT_HFP_INCOMMING, PRIORITY_ONE}, {TOPIC_EVENT_HFP_FINISHED, PRIORITY_ONE}, @@ -221,14 +221,16 @@ void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) unused(req); // The alarm notification is not displayed if the incoming call notification is already being processed if (CheckPriority(topic)) { - AlarmClockModel::GetInstance()->PopInterPlayMusic(); - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + // AlarmClockModel::GetInstance()->PopInterPlayMusic(); + // AlarmViewEventListener::GetInstance()->PopAlarmRing(); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); NotificationManager::GetInstance()->ShowNotify(ShowAlarmNotify, static_cast(topic), true); } else { // just delay the alarm WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "just delay the alarm"); - AlarmClockModel::GetInstance()->AlarmGetClockNum(); - AlarmPopUpPresenter::GetInstance()->DelayAlarmRing(); + // AlarmClockModel::GetInstance()->AlarmGetClockNum(); + // AlarmPopUpPresenter::GetInstance()->DelayAlarmRing(); + AlarmViewEventListener::GetInstance()->DelayAlarmRing(); } } diff --git a/code/sdk/application/wearable/fd230/service/msg_center/src/notify/alarm_notification.cpp b/code/sdk/application/wearable/fd230/service/msg_center/src/notify/alarm_notification.cpp index dc289cf8e..20b62a70a 100644 --- a/code/sdk/application/wearable/fd230/service/msg_center/src/notify/alarm_notification.cpp +++ b/code/sdk/application/wearable/fd230/service/msg_center/src/notify/alarm_notification.cpp @@ -8,468 +8,636 @@ #include "notification_manager.h" #include "wearable_log.h" #include "UiConfig.h" -#include "AlarmPopUpPresenter.h" +#include "alarm/include/AlarmPopUpPresenter.h" #include "components/ui_image_view.h" -#include "components/ui_label.h" - -namespace OHOS { -static constexpr const char* RING_AGAIN = "响铃将在十分钟后再次响起"; -constexpr int32_t NOTIFY_THREE_SECONDS = 3000; -constexpr int32_t NOTIFY_ONE_SECOND = 1000; -constexpr int32_t NOTIFY_THIRTY_SECONDS = 30000; -constexpr int32_t NOTIFY_ONE_MINUTE = 60000; -constexpr int32_t NOTOFY_NO_OPERATE_TIME = 35000; -GraphicTimer* g_notifyStopHandle = nullptr; // timer of close view and alarm ring view -GraphicTimer* g_alarmRing = nullptr; // timer of alarm view - -UIViewGroup* g_alarmView = nullptr; -UIViewGroup* g_closeView = nullptr; -UIViewGroup* g_ringView = nullptr; -UIImageView* g_imageClose = nullptr; -UIImageView* g_imageRing = nullptr; -UIImageView* g_imageDelete = nullptr; -UIImageView* g_imageClock = nullptr; -UILabel* g_closeLable = nullptr; -UILabel* g_ringLable = nullptr; -UILabel* g_mainLable = nullptr; -UIDigitalClock* g_dClock = nullptr; - -// alarm close view -constexpr int16_t MAX_SET_ZERO_LEN = 0; -constexpr int16_t MAX_SET_SRC_LEN = 90; -constexpr int16_t MAX_IMAGE_X_LEN = 165; -constexpr int16_t MAX_IMAGE_Y_LEN = 150; -constexpr int16_t MAX_LABEL_X_LEN = 187; -constexpr int16_t MAX_LABEL_Y_LEN = 300; -constexpr int16_t MAX_LABEL_LENGTH_LEN = 350; -constexpr int16_t MAX_LABEL_HEIGHT_LEN = 40; -constexpr int16_t MAX_LABEL_FONT_LEN = 35; - -// alarm main view -constexpr int16_t CONTAINER_X = 0; -constexpr int16_t CONTAINER_Y = 0; -constexpr int16_t LABEL_X = 185; -constexpr int16_t LABEL_Y = 100; -constexpr int16_t LABEL_WIDTH = 250; -constexpr int16_t LABEL_HEIGHT = 45; -constexpr int16_t LABEL_FONT = 40; -constexpr int16_t CLOCK_FONT = 70; -constexpr int16_t CLOCK_X = 140; -constexpr int16_t CLOCK_Y = 170; -constexpr int16_t IMAGE_DELETE_X = 85; -constexpr int16_t IMAGE_DELETE_Y = 300; -constexpr int16_t IMAGE_CLOCK_X = 275; -constexpr int16_t IMAGE_CLOCK_Y = 300; -constexpr int16_t DIGITAL_CLOCK_WIDTH = 350; -constexpr int16_t DIGITAL_CLOCK_HEIGHT = 75; - -// alarm delay view -constexpr int16_t SET_ZERO = 0; -constexpr int16_t SET_SRC = 150; -constexpr int16_t DELAY_IMAGE_X = 150; -constexpr int16_t DELAY_IMAGE_Y = 140; -constexpr int16_t DELAY_LABEL_X = 80; -constexpr int16_t DELAY_LABEL_Y = 300; -constexpr int16_t DELAY_LABEL_LENGTH = 350; -constexpr int16_t DELAY_LABEL_HEIGHT = 35; -constexpr int16_t DELAY_LABEL_FONT = 25; - -void StopNotifyCallback(void* data) +#include "components/ui_label_ext.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_digital_clock.h" +#include "time.h" +#include "cmsis_os2.h" +#include "cmsis_os.h" +#include +#include "ConfigModel.h" +#include +#include +#include +#include "alarm_notification.h" +#include "vibrator/service/vibrator_service.h" +#include "ui_resource_string.h" +#include "findwatch_notification.h" + +namespace OHOS { - (void)data; - NotificationManager::GetInstance()->StopNotify(); -} + constexpr int32_t NOTIFY_THREE_SECONDS = 3000; + constexpr int32_t NOTIFY_ONE_SECOND = 1000; + constexpr int32_t NOTIFY_THIRTY_SECONDS = 30 * 1000; // 30秒 + constexpr int32_t NOTIFY_ONE_MINUTE = 60 * 1000; + static int popalarm_time = 40; + constexpr int32_t NOTOFY_NO_OPERATE_TIME = 30 * 1000; // 无操作30s超时时间 + osTimerId_t g_notifyStopHandle = nullptr; // timer of close view and alarm ring view + osTimerId_t g_alarmRing = nullptr; // timer of alarm view + + UIViewGroup *g_alarmView = nullptr; + UIViewGroup *g_closeView = nullptr; + UIViewGroup *g_ringView = nullptr; + UIImageView *g_imageClose = nullptr; + UIImageView *g_imageRing = nullptr; + UIImageView *g_imageDelete = nullptr; + UILabelButtonExt *g_StopBtn = nullptr; + UIImageView *g_ClockPrompt = nullptr; + UIImageView *g_imageClock = nullptr; + UILabel *g_closeLable = nullptr; + UILabel *g_ringLable = nullptr; + UILabelExt *g_mainLable = nullptr; + UILabelExt *g_popTime = nullptr; + UIDigitalClock *g_dClock = nullptr; + + // alarm close view + constexpr int16_t MAX_SET_ZERO_LEN = 0; + constexpr int16_t MAX_SET_SRC_LEN = 90; + constexpr int16_t MAX_IMAGE_X_LEN = 165; + constexpr int16_t MAX_IMAGE_Y_LEN = 150; + constexpr int16_t MAX_LABEL_X_LEN = 187; + constexpr int16_t MAX_LABEL_Y_LEN = 300; + constexpr int16_t MAX_LABEL_LENGTH_LEN = 350; + constexpr int16_t MAX_LABEL_HEIGHT_LEN = 40; + constexpr int16_t MAX_LABEL_FONT_LEN = 35; + + // alarm main view + constexpr int16_t CONTAINER_X = 0; + constexpr int16_t CONTAINER_Y = 0; + constexpr int16_t LABEL_X = 185; + constexpr int16_t LABEL_Y = 100; + constexpr int16_t LABEL_WIDTH = 250; + constexpr int16_t LABEL_HEIGHT = 45; + constexpr int16_t LABEL_FONT = 40; + constexpr int16_t CLOCK_FONT = 70; + constexpr int16_t CLOCK_X = 140; + constexpr int16_t CLOCK_Y = 170; + constexpr int16_t IMAGE_DELETE_X = 85; + constexpr int16_t IMAGE_DELETE_Y = 300; + constexpr int16_t IMAGE_CLOCK_X = 275; + constexpr int16_t IMAGE_CLOCK_Y = 300; + constexpr int16_t DIGITAL_CLOCK_WIDTH = 350; + constexpr int16_t DIGITAL_CLOCK_HEIGHT = 75; + + // alarm delay view + constexpr int16_t SET_ZERO = 0; + constexpr int16_t SET_SRC = 150; + constexpr int16_t DELAY_IMAGE_X = 150; + constexpr int16_t DELAY_IMAGE_Y = 140; + constexpr int16_t DELAY_LABEL_X = 80; + constexpr int16_t DELAY_LABEL_Y = 300; + constexpr int16_t DELAY_LABEL_LENGTH = 350; + constexpr int16_t DELAY_LABEL_HEIGHT = 35; + constexpr int16_t DELAY_LABEL_FONT = 25; + + uint8_t AlarmViewEventListener::pre_screen_status = 0;//屏幕之前的状态 + static OHOS::RootView::OnKeyActListener *g_onKeyActListener = nullptr; + + void StopNotifyCallback() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopNotifyCallback"); + NotificationManager::GetInstance()->StopNotify(); + } -void NoOperateCallback(void* data) -{ - (void)data; - NotificationManager::GetInstance()->StopNotify(); -} + static void NoOperateCallbackProc(int data) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NoOperateCallback"); + popalarm_time--; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NoOperateCallback popalarm_time = %d",popalarm_time); + if (popalarm_time <= 0) + { + NotificationManager::GetInstance()->StopNotify(); + } + else + { + // if (true == ConfigModel::GetInstance()->GetDnotdisturb() || (uapi_sleep_mode_flag_get())) + // { + // return; + // } + if (g_alarmView) + { + ui_api_vibrate_once_func(); + } + } + } -void StartAlarmTimer(AlarmTimerType type, int32_t interval) -{ - uint32_t tick; - bool retTimer; - if (type >= AlarmTimerType::NOTIFY_ALARM_UNKNOWN) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartAlarmTimer type:%d invalid!!", type); - return; + static void NoOperateCallback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(NoOperateCallbackProc, data)); } - switch (type) { + + /* + * @brief 启动特定类型的闹钟定时器 + * @param 1 闹钟定时器的类型 + * @param 2 时间间隔,以毫秒为单位 + */ + void StartAlarmTimer(AlarmTimerType type, int32_t interval) + { + uint32_t tick; + osStatus_t retTimer; + // 1.检查传入的闹钟类型是否有效 + if (type >= AlarmTimerType::NOTIFY_ALARM_UNKNOWN) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartAlarmTimer type:%d invalid!!", type); + return; + } + switch (type) + { case AlarmTimerType::NOTIFY_ALARM_CLOSE: case AlarmTimerType::NOTIFY_ALARM_DELAY: - tick = GetOSTick(interval); - g_notifyStopHandle = new GraphicTimer(tick, StopNotifyCallback, nullptr, true); - retTimer = g_notifyStopHandle->Start(); - if (!retTimer && g_notifyStopHandle != nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "StartAlarmTimer osTimerStart failed, type= %d!!", type); - delete g_notifyStopHandle; - g_notifyStopHandle = nullptr; - return; + if (g_notifyStopHandle == nullptr) + { + g_notifyStopHandle = osTimerNew((osTimerFunc_t)StopNotifyCallback, osTimerPeriodic, nullptr, nullptr); + tick = osMs2Tick(interval); + retTimer = osTimerStart(g_notifyStopHandle, tick); + if (retTimer != osOK && g_notifyStopHandle != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartAlarmTimer osTimerStart failed, type= %d ret = %lx!!", type, retTimer); + osTimerDelete(g_notifyStopHandle); + g_notifyStopHandle = nullptr; + return; + } } break; case AlarmTimerType::NOTIFY_ALARM_RING: - tick = GetOSTick(interval); - g_alarmRing = new GraphicTimer(tick, NoOperateCallback, nullptr, true); - retTimer = g_alarmRing->Start(); - if (!retTimer && g_alarmRing != nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "StartAlarmTimer osTimerStart failed, type= %d!!", type); - delete g_alarmRing; - g_alarmRing = nullptr; - return; + if (g_alarmRing == nullptr) + { + g_alarmRing = osTimerNew((osTimerFunc_t)NoOperateCallback, osTimerPeriodic, nullptr, nullptr); + tick = osMs2Tick(interval); + retTimer = osTimerStart(g_alarmRing, tick); + if (retTimer != osOK && g_alarmRing != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartAlarmTimer osTimerStart failed, type= %d ret = %lx!!", type, retTimer); + osTimerDelete(g_alarmRing); + g_alarmRing = nullptr; + return; + } } break; default: break; + } } -} -void DisableAlarmTimer(AlarmTimerType type) -{ - if (type >= AlarmTimerType::NOTIFY_ALARM_UNKNOWN) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisableAlarmTimer type:%d invalid!!", type); - return; - } - switch (type) { + /* + * @brief 取消特定类型的闹钟定时器 + * @param 闹钟定时器的类型 + */ + void DisableAlarmTimer(AlarmTimerType type) + { + if (type >= AlarmTimerType::NOTIFY_ALARM_UNKNOWN) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisableAlarmTimer type:%d invalid!!", type); + return; + } + osStatus_t ret; + switch (type) + { case AlarmTimerType::NOTIFY_ALARM_CLOSE: case AlarmTimerType::NOTIFY_ALARM_DELAY: - if (g_notifyStopHandle != nullptr) { - delete g_notifyStopHandle; + if (g_notifyStopHandle != nullptr) + { + osTimerStop(g_notifyStopHandle); + ret = osTimerDelete(g_notifyStopHandle); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisableAlarmTimer failed, type= %d ret = %lx!", type, ret); + return; + } g_notifyStopHandle = nullptr; } break; case AlarmTimerType::NOTIFY_ALARM_RING: - if (g_alarmRing != nullptr) { - delete g_alarmRing; + if (g_alarmRing != nullptr) + { + osTimerStop(g_alarmRing); + ret = osTimerDelete(g_alarmRing); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisableAlarmTimer failed, type= %d ret = %lx!", type, ret); + return; + } g_alarmRing = nullptr; + popalarm_time = 40; } break; default: break; + } } -} -UIViewGroup *CreateAlarmCloseView() -{ - g_closeView = new UIViewGroup(); - if (g_closeView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmCloseView g_closeView null!"); - return nullptr; - } - g_closeView->SetPosition(MAX_SET_ZERO_LEN, MAX_SET_ZERO_LEN); - g_closeView->SetWidth(Screen::GetInstance().GetWidth()); - g_closeView->SetHeight(Screen::GetInstance().GetHeight()); - g_imageClose = new UIImageView(); - if (g_imageClose == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmCloseView g_imageClose null!"); - delete g_closeView; - g_closeView = nullptr; - return nullptr; + UIViewGroup *CreateAlarmCloseView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreateAlarmCloseView"); + g_closeView = new UIViewGroup(); + if (g_closeView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmCloseView g_closeView null!"); + return nullptr; + } + g_closeView->SetPosition(MAX_SET_ZERO_LEN, MAX_SET_ZERO_LEN); + g_closeView->SetWidth(Screen::GetInstance().GetWidth()); + g_closeView->SetHeight(Screen::GetInstance().GetHeight()); + g_imageClose = new UIImageView(); + if (g_imageClose == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmCloseView g_imageClose null!"); + delete g_closeView; + g_closeView = nullptr; + return nullptr; + } + g_imageClose->SetPosition(MAX_IMAGE_X_LEN, MAX_IMAGE_Y_LEN); + g_imageClose->SetWidth(MAX_SET_SRC_LEN); + g_imageClose->SetHeight(MAX_SET_SRC_LEN); + g_imageClose->SetSrc(ALARM_CLOCK_CLOSE_ADD_PATH); + g_imageClose->SetTouchable(true); + g_closeView->Add(g_imageClose); + + g_closeLable = new UILabel(); + if (g_closeLable == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmCloseView g_closeLable null!"); + delete g_closeView; + g_closeView = nullptr; + delete g_imageClose; + g_imageClose = nullptr; + return nullptr; + } + g_closeLable->SetPosition(MAX_LABEL_X_LEN, MAX_LABEL_Y_LEN, MAX_LABEL_LENGTH_LEN, MAX_LABEL_HEIGHT_LEN); + g_closeLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MAX_LABEL_FONT_LEN); + g_closeLable->SetText("CLOSE"); + g_closeView->Add(g_closeLable); + g_closeView->SetViewId(ALARM_VIEW_CLOSE); + UIView::OnDragListener *listener = static_cast(AlarmViewEventListener::GetInstance()); + g_closeView->SetOnDragListener(listener); + g_closeView->SetDraggable(true); + g_closeView->SetTouchable(true); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeAlarmCloseView); + return g_closeView; } - g_imageClose->SetPosition(MAX_IMAGE_X_LEN, MAX_IMAGE_Y_LEN); - g_imageClose->SetWidth(MAX_SET_SRC_LEN); - g_imageClose->SetHeight(MAX_SET_SRC_LEN); - g_imageClose->SetSrc(ALARM_CLOCK_CLOSE_ADD_PATH); - g_imageClose->SetTouchable(true); - g_closeView->Add(g_imageClose); - g_closeLable = new UILabel(); - if (g_closeLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmCloseView g_closeLable null!"); - delete g_closeView; - g_closeView = nullptr; - delete g_imageClose; - g_imageClose = nullptr; - return nullptr; + void FreeAlarmCloseView(void) + { + if (g_closeView != nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeAlarmCloseView"); + DisableAlarmTimer(AlarmTimerType::NOTIFY_ALARM_CLOSE); + g_closeView->RemoveAll(); + delete g_imageClose; + g_imageClose = nullptr; + delete g_closeLable; + g_closeLable = nullptr; + RootView::GetInstance()->Remove(g_closeView); + delete g_closeView; + g_closeView = nullptr; + } } - g_closeLable->SetPosition(MAX_LABEL_X_LEN, MAX_LABEL_Y_LEN, MAX_LABEL_LENGTH_LEN, MAX_LABEL_HEIGHT_LEN); - g_closeLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, MAX_LABEL_FONT_LEN); - g_closeLable->SetText("CLOSE"); - g_closeView->Add(g_closeLable); - g_closeView->SetViewId(ALARM_VIEW_CLOSE); - UIView::OnDragListener *listener = static_cast(AlarmViewEventListener::GetInstance()); - g_closeView->SetOnDragListener(listener); - g_closeView->SetDraggable(true); - g_closeView->SetTouchable(true); - NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeAlarmCloseView); - return g_closeView; -} -void FreeAlarmCloseView(void) -{ - if (g_closeView != nullptr) { - DisableAlarmTimer(AlarmTimerType::NOTIFY_ALARM_CLOSE); - g_closeView->RemoveAll(); - delete g_imageClose; - g_imageClose = nullptr; - delete g_closeLable; - g_closeLable = nullptr; - RootView::GetInstance()->Remove(g_closeView); - delete g_closeView; - g_closeView = nullptr; + /*创建一个响铃闹钟视图*/ + UIViewGroup *CreateAlarmRingView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreateAlarmRingView"); + if (g_ringView == nullptr) + { + g_ringView = new UIViewGroup(); + if (g_ringView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmRingView g_ringView null!"); + return nullptr; + } + g_ringView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + g_ringView->SetViewId(ALARM_VIEW_DELAY); + UIView::OnDragListener *listener = static_cast(AlarmViewEventListener::GetInstance()); + if (listener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmViewEventListener::GetInstance fail!!"); + return nullptr; + } + g_ringView->SetOnDragListener(listener); + g_ringView->SetDraggable(true); + g_ringView->SetTouchable(true); + /* -------------------------------------------------------------------------- */ + if (g_imageRing == nullptr) + { + g_imageRing = new UIImageView(); + if (g_imageRing == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmRingView g_imageRing null!"); + return nullptr; + } + } + g_imageRing->SetPosition(DELAY_IMAGE_X, DELAY_IMAGE_Y); + g_imageRing->SetWidth(SET_SRC); + g_imageRing->SetHeight(SET_SRC); + g_imageRing->SetSrc(ALARM_CLOCK_POP_ADD_PATH); + /* -------------------------------------------------------------------------- */ + if (g_ringLable == nullptr) + { + g_ringLable = new UILabel(); + if (g_ringLable == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmRingView::g_ringLable null!"); + return nullptr; + } + } + g_ringLable->SetPosition(DELAY_LABEL_X, DELAY_LABEL_Y, DELAY_LABEL_LENGTH, DELAY_LABEL_HEIGHT); + g_ringLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DELAY_LABEL_FONT); + g_ringLable->SetText("响铃将在十分钟后再次响起"); + /* ----------------------------------- Add ---------------------------------- */ + g_ringView->Add(g_imageRing); + g_ringView->Add(g_ringLable); + } + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeAlarmRingView); + return g_ringView; } -} -UIViewGroup *CreateAlarmRingView() -{ - g_ringView = new UIViewGroup(); - if (g_ringView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmRingView g_ringView null!"); - return nullptr; - } - g_ringView->SetPosition(SET_ZERO, SET_ZERO); - g_ringView->SetWidth(Screen::GetInstance().GetWidth()); - g_ringView->SetHeight(Screen::GetInstance().GetHeight()); - g_imageRing = new UIImageView(); - if (g_imageRing == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmRingView g_imageRing null!"); - delete g_ringView; - g_ringView = nullptr; - return nullptr; - } - g_imageRing->SetPosition(DELAY_IMAGE_X, DELAY_IMAGE_Y); - g_imageRing->SetWidth(SET_SRC); - g_imageRing->SetHeight(SET_SRC); - g_imageRing->SetSrc(ALARM_CLOCK_POP_ADD_PATH); - g_ringView->Add(g_imageRing); - g_ringLable = new UILabel(); - if (g_ringLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmRingView::g_ringLable null!"); - delete g_ringView; - g_ringView = nullptr; - delete g_imageRing; - return nullptr; + // 析构一个响铃闹钟视图 + void FreeAlarmRingView(void) + { + if (g_ringView != nullptr) + { + DisableAlarmTimer(AlarmTimerType::NOTIFY_ALARM_DELAY); + g_ringView->RemoveAll(); + if (g_imageRing) + { + delete g_imageRing; + g_imageRing = nullptr; + } + if (g_ringLable) + { + delete g_ringLable; + g_ringLable = nullptr; + } + RootView::GetInstance()->Remove(g_ringView); + delete g_ringView; + g_ringView = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeAlarmRingView over!!"); + } } - g_ringLable->SetPosition(DELAY_LABEL_X, DELAY_LABEL_Y, DELAY_LABEL_LENGTH, DELAY_LABEL_HEIGHT); - g_ringLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DELAY_LABEL_FONT); - g_ringLable->SetText(RING_AGAIN); - g_ringView->Add(g_ringLable); - g_ringView->SetViewId(ALARM_VIEW_DELAY); - UIView::OnDragListener *listener = static_cast(AlarmViewEventListener::GetInstance()); - g_ringView->SetOnDragListener(listener); - g_ringView->SetDraggable(true); - g_ringView->SetTouchable(true); - NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeAlarmRingView); - return g_ringView; -} -void FreeAlarmRingView(void) -{ - if (g_ringView != nullptr) { - DisableAlarmTimer(AlarmTimerType::NOTIFY_ALARM_DELAY); - g_ringView->RemoveAll(); - delete g_imageRing; - g_imageRing = nullptr; - delete g_ringLable; - g_ringLable = nullptr; - RootView::GetInstance()->Remove(g_ringView); - delete g_ringView; - g_ringView = nullptr; + // 创建一个闹钟弹窗视图 + UIViewGroup *CreateAlarmView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreateAlarmView"); + AlarmClockModel::GetInstance()->AlarmGetClockNum(); + if (g_alarmView == nullptr) + { + g_alarmView = new UIViewGroup(); + if (g_alarmView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmView g_alarmView null!"); + return nullptr; + } + g_alarmView->SetPosition(CONTAINER_X, CONTAINER_Y, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + g_alarmView->SetViewId(ALARM_VIEW_POPUP); + g_alarmView->SetDraggable(true); + g_alarmView->SetTouchable(true); + UIView::OnDragListener *listener = static_cast(AlarmViewEventListener::GetInstance()); + if (nullptr == listener) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmViewEventListener::GetInstance fail!!"); + return nullptr; + } + g_alarmView->SetOnDragListener(listener); + /* -------------------------------------------------------------------------- */ + if (g_mainLable == nullptr) + { + g_mainLable = new UILabelExt(); + if (g_mainLable == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmView g_mainLable is nullptr"); + return nullptr; + } + } + g_mainLable->SetPosition(83, 50, 300, 35); + g_mainLable->SetTextId(STR_ALARM); // 闹钟 + g_mainLable->SetStyle(STYLE_TEXT_FONT, 30); + g_mainLable->SetStyle(STYLE_LINE_HEIGHT, 35); + g_mainLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + g_mainLable->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + g_mainLable->SetRollSpeed(23); + g_mainLable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + g_alarmView->Add(g_mainLable); + /* -------------------------------------------------------------------------- */ + if (g_ClockPrompt == nullptr) + { + g_ClockPrompt = new UIImageView(); + if (g_ClockPrompt == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmView g_ClockPrompt is nullptr"); + return nullptr; + } + } + g_ClockPrompt->SetPosition(184, 129, 100, 100); + g_ClockPrompt->SetSrc("/user/res/Alarm/alarm_prompt.bin"); + g_alarmView->Add(g_ClockPrompt); + /* -------------------------------------------------------------------------- */ + struct tm localTime; + int16 thisHour; + int16 thisMin; + if (g_dClock == nullptr) + { + g_dClock = new UIDigitalClock(); + if (g_dClock == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmViewLabel g_dClock is nullptr"); + return nullptr; + } + } + g_dClock->SetPosition((g_alarmView->GetWidth() - 200) / 2, 236, 200, 70); + g_dClock->SetStyle(STYLE_TEXT_FONT, 60); + g_dClock->SetStyle(STYLE_LINE_HEIGHT, 69); + g_dClock->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 60); + time_t seconds = time(nullptr); + if (localtime_r(&seconds, &localTime) == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmViewLabel get localtime error!"); + return nullptr; + } + AlarmClockModel::GetInstance()->GetPopTimeData(&thisHour, &thisMin); + g_dClock->SetDisplayMode(UIDigitalClock::DISPLAY_24_HOUR_NO_SECONDS); + g_dClock->SetTime24Hour(thisHour, thisMin, 0); + g_dClock->SetVisible(false); + g_alarmView->Add(g_dClock); + /* -------------------------------- g_popTime ------------------------------- */ + if (g_popTime == nullptr) + { + g_popTime = new UILabelExt(); + if (g_popTime == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmView g_popTime is nullptr"); + return nullptr; + } + } + g_popTime->SetPosition(83, 236, 200, 70); + // std::string poptime = std::to_string(thisHour) + ":" + std::to_string(thisMin); + char poptime[12] = {0}; + sprintf(poptime, "%02d:%02d", thisHour, thisMin); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "poptime = %s",poptime); + g_popTime->SetText(poptime); + g_popTime->SetStyle(STYLE_TEXT_FONT, 60); + g_popTime->SetStyle(STYLE_LINE_HEIGHT, 70); + g_popTime->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 60); + g_popTime->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + g_popTime->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + g_alarmView->Add(g_popTime); + g_popTime->SetPosition((g_alarmView->GetWidth() - g_popTime->GetTextWidth()) / 2, 236); + /* -------------------------------------------------------------------------- */ + if (g_StopBtn == nullptr) + { + g_StopBtn = new UILabelButtonExt(); + if (g_StopBtn == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmView g_StopBtn is nullptr"); + return nullptr; + } + } + g_StopBtn->SetPosition(0, 366, 466, 100); + g_StopBtn->SetViewId(ALARM_IMAGE_STOP); + g_StopBtn->SetTextId(STR_STOP); // 停止 + g_StopBtn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + g_StopBtn->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); + g_StopBtn->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE); + g_StopBtn->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x00, UIButton::PRESSED); + g_StopBtn->SetTouchable(true); + UIView::OnClickListener *closeListener = static_cast(AlarmViewEventListener::GetInstance()); + if (nullptr == closeListener) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmViewEventListener::GetInstance fail!!"); + return nullptr; + } + g_StopBtn->SetOnClickListener(closeListener); + g_alarmView->Add(g_StopBtn); + /* -------------------------------------------------------------------------- */ + StartAlarmTimer(AlarmTimerType::NOTIFY_ALARM_RING, NOTIFY_ONE_SECOND); + + AlarmViewEventListener::GetInstance()->PopAlarmRing(); //闹钟响铃 + g_onKeyActListener = RootView::GetInstance()->GetOnKeyActListener(); + RootView::GetInstance()->SetOnKeyActListener(AlarmViewEventListener::GetInstance()); + + AlarmViewEventListener::pre_screen_status = uapi_dev_runtime_get_screen_always_on_status();//获取闹钟弹窗之前是否是长亮屏状态 + if(!AlarmViewEventListener::pre_screen_status) + { + ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); + } + } + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeAlarmView); + return g_alarmView; } -} - -static bool CreateAlarmViewImage(void) -{ - g_imageDelete = new UIImageView(); - if (g_imageDelete == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showAlarmNotify g_imageDelete null!"); - return false; + // 释放闹钟视图 + void FreeAlarmView(void) + { + if (g_alarmView != nullptr) + { + AlarmViewEventListener::GetInstance()->CancelAlarmRing();//取消闹钟响铃 + g_alarmView->RemoveAll(); + if (g_mainLable != nullptr) + { + delete g_mainLable; + g_mainLable = nullptr; + } + if (g_dClock != nullptr) + { + delete g_dClock; + g_dClock = nullptr; + } + if (g_popTime != nullptr) + { + delete g_popTime; + g_popTime = nullptr; + } + if (g_ClockPrompt != nullptr) + { + delete g_ClockPrompt; + g_ClockPrompt = nullptr; + } + if (g_StopBtn != nullptr) + { + delete g_StopBtn; + g_StopBtn = nullptr; + } + RootView::GetInstance()->SetOnKeyActListener(g_onKeyActListener); + RootView::GetInstance()->Remove(g_alarmView); + delete g_alarmView; + g_alarmView = nullptr; + if(!AlarmViewEventListener::pre_screen_status) //如果闹钟弹窗之前不是长亮屏状态,就取消闹钟弹窗设置的常亮屏 + { + ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeAlarmView over!!"); + } } - g_imageDelete->SetPosition(IMAGE_DELETE_X, IMAGE_DELETE_Y); - g_imageDelete->SetWidth(MAX_SET_SRC_LEN); - g_imageDelete->SetHeight(MAX_SET_SRC_LEN); - g_imageDelete->SetViewId(ALARM_IMAGE_DELETE); - g_imageDelete->SetSrc(ALARM_DELETE_ADD_PATH); - g_imageDelete->SetTouchable(true); - UIView::OnClickListener *closeListener = static_cast\ - (AlarmViewEventListener::GetInstance()); - g_imageDelete->SetOnClickListener(closeListener); - g_imageClock = new UIImageView(); - if (g_imageClock == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showAlarmNotify g_imageClock null!"); - delete g_imageDelete; - return false; + AlarmViewEventListener::AlarmViewEventListener() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmViewEventListener :%p", this); } - g_imageClock->SetPosition(IMAGE_CLOCK_X, IMAGE_CLOCK_Y); - g_imageClock->SetWidth(MAX_SET_SRC_LEN); - g_imageClock->SetHeight(MAX_SET_SRC_LEN); - g_imageClock->SetViewId(ALARM_IMAGE_CLOCK); - g_imageClock->SetSrc(ALARM_CLOCK_ADD_PATH); - g_imageClock->SetTouchable(true); - g_imageClock->SetTouchable(true); - UIView::OnClickListener *clockListener = static_cast\ - (OHOS::AlarmViewEventListener::GetInstance()); - g_imageClock->SetOnClickListener(clockListener); - return true; -} - -static void FreeAlarmViewImage(void) -{ - delete g_imageDelete; - g_imageDelete = nullptr; - delete g_imageClock; - g_imageClock = nullptr; -} - -static bool CreateAlarmViewLabel(void) -{ - struct tm localTime; - int16 thisHour; - int16 thisMin; - g_mainLable = new UILabel(); - if (g_mainLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmViewLabel g_mainLable is nullptr"); - return false; + AlarmViewEventListener::~AlarmViewEventListener() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~AlarmViewEventListener"); } - g_mainLable->SetPosition(LABEL_X, LABEL_Y, LABEL_WIDTH, LABEL_HEIGHT); - g_mainLable->SetText("闹钟"); - g_mainLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT); - g_dClock = new UIDigitalClock(); - if (g_dClock == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmViewLabel g_dClock is nullptr"); - delete g_mainLable; - return false; + AlarmViewEventListener *AlarmViewEventListener::GetInstance(void) + { + static AlarmViewEventListener alarmViewEventListener; + return &alarmViewEventListener; } - g_dClock->SetPosition(CLOCK_X, CLOCK_Y); - g_dClock->Resize(DIGITAL_CLOCK_WIDTH, DIGITAL_CLOCK_HEIGHT); - g_dClock->SetFont(DEFAULT_VECTOR_FONT_FILENAME, CLOCK_FONT); - time_t seconds = time(nullptr); - if (localtime_r(&seconds, &localTime) == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmViewLabel get localtime error!"); - delete g_mainLable; - delete g_dClock; - return false; - } - AlarmClockModel::GetInstance()->GetPopTimeData(&thisHour, &thisMin); - g_dClock->SetDisplayMode(UIDigitalClock::DISPLAY_24_HOUR_NO_SECONDS); - g_dClock->SetTime24Hour(thisHour, thisMin, 0); - return true; -} - -static void FreeAlarmViewLabel(void) -{ - delete g_mainLable; - g_mainLable = nullptr; - delete g_dClock; - g_dClock = nullptr; -} -UIViewGroup* CreateAlarmView(void) -{ - AlarmClockModel::GetInstance()->AlarmGetClockNum(); - g_alarmView = new UIViewGroup(); - if (g_alarmView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateAlarmView g_alarmView null!"); - return nullptr; + bool AlarmViewEventListener::OnDrag(UIView &view, const DragEvent &event) + { + return true; } - g_alarmView->SetPosition(CONTAINER_X, CONTAINER_Y, - Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - g_alarmView->SetViewId(ALARM_VIEW_POPUP); - if (!CreateAlarmViewLabel()) { - delete g_alarmView; - g_alarmView = nullptr; - return nullptr; + bool AlarmViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) + { + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + if (strcmp(view.GetViewId(), ALARM_VIEW_POPUP) == 0) + { + NotificationManager::GetInstance()->StopNotify(); + } + } + return true; } - if (!CreateAlarmViewImage()) { - delete g_alarmView; - g_alarmView = nullptr; - FreeAlarmViewLabel(); - return nullptr; + bool AlarmViewEventListener::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlamNotify ClickListener %s", view.GetViewId()); + if (strcmp(view.GetViewId(), ALARM_IMAGE_STOP) == 0) // 点击停止闹钟响铃 + { + NotificationManager::GetInstance()->StopNotify(); + } + return true; } - g_alarmView->Add(g_mainLable); - g_alarmView->Add(g_dClock); - g_alarmView->Add(g_imageDelete); - g_alarmView->Add(g_imageClock); - g_alarmView->SetDraggable(true); - g_alarmView->SetTouchable(true); - UIView::OnDragListener *listener = static_cast(AlarmViewEventListener::GetInstance()); - g_alarmView->SetOnDragListener(listener); - StartAlarmTimer(AlarmTimerType::NOTIFY_ALARM_RING, NOTOFY_NO_OPERATE_TIME); - NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeAlarmView); - return g_alarmView; -} -void FreeAlarmView(void) -{ - if (g_alarmView != nullptr) { - DisableAlarmTimer(AlarmTimerType::NOTIFY_ALARM_RING); - g_alarmView->RemoveAll(); - FreeAlarmViewLabel(); - FreeAlarmViewImage(); - RootView::GetInstance()->Remove(g_alarmView); - delete g_alarmView; - g_alarmView = nullptr; + void AlarmViewEventListener::PopAlarmRing() + { +#ifdef SINGLE_USER_PARTITION + FindWatchViewEventListener::GetInstance().PopInterPlayMusic("/user/music/ring/alarm.mp3");//播放铃声 +#else + FindWatchViewEventListener::GetInstance().PopInterPlayMusic("/music/ring/alarm.mp3");//播放铃声 +#endif + //如果闹钟铃声播放成功,记录该事件 + uapi_save_runtime_log(RUNTIME_LOG_RING_PLAY_START_ALARM);//TOOD* } -} - -AlarmViewEventListener::AlarmViewEventListener() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmViewEventListener :%p", this); -} -AlarmViewEventListener::~AlarmViewEventListener() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~AlarmViewEventListener"); -} - -AlarmViewEventListener *AlarmViewEventListener::GetInstance(void) -{ - static AlarmViewEventListener alarmViewEventListener; - return &alarmViewEventListener; -} - -bool AlarmViewEventListener::OnDrag(UIView& view, const DragEvent& event) -{ - return true; -} - -bool AlarmViewEventListener::OnDragEnd(UIView& view, const DragEvent& event) -{ - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - if (strcmp(view.GetViewId(), ALARM_VIEW_POPUP) == 0) { - DisableAlarmTimer(AlarmTimerType::NOTIFY_ALARM_RING); - AlarmPopUpPresenter::GetInstance()->DelayAlarmRing(); - UIViewGroup* alarmRingView = CreateAlarmRingView(); - NotificationManager::GetInstance()->screenContainer_->SetVisible(false); - RootView::GetInstance()->Add(alarmRingView); - alarmRingView->SetVisible(true); - StartAlarmTimer(AlarmTimerType::NOTIFY_ALARM_DELAY, NOTIFY_THREE_SECONDS); - } else if (strcmp(view.GetViewId(), ALARM_VIEW_CLOSE) == 0 || - strcmp(view.GetViewId(), ALARM_VIEW_DELAY) == 0) { - NotificationManager::GetInstance()->StopNotify(); - } + void AlarmViewEventListener::CancelAlarmRing() + { + DisableAlarmTimer(AlarmTimerType::NOTIFY_ALARM_RING); + FindWatchViewEventListener::GetInstance().PopInterCancelMusic(); + AlarmClockModel::GetInstance()->CancelAlarmRing(); + //如果闹钟铃声停止播放成功,记录该事件 + uapi_save_runtime_log(RUNTIME_LOG_RING_PLAY_STOP_ALARM);//TOOD* } - return true; -} -bool AlarmViewEventListener::OnClick(UIView& view, const ClickEvent& event) -{ - UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlamNotify ClickListener %s", view.GetViewId()); - if (strcmp(view.GetViewId(), ALARM_IMAGE_DELETE) == 0) { - DisableAlarmTimer(AlarmTimerType::NOTIFY_ALARM_RING); - AlarmPopUpPresenter::GetInstance()->CancelAlarmRing(); - UIViewGroup* alarmCloseView = CreateAlarmCloseView(); - NotificationManager::GetInstance()->screenContainer_->SetVisible(false); - RootView::GetInstance()->Add(alarmCloseView); - alarmCloseView->SetVisible(true); - StartAlarmTimer(AlarmTimerType::NOTIFY_ALARM_CLOSE, NOTIFY_THREE_SECONDS); - return true; - } else if (strcmp(view.GetViewId(), ALARM_IMAGE_CLOCK) == 0) { - DisableAlarmTimer(AlarmTimerType::NOTIFY_ALARM_RING); - AlarmPopUpPresenter::GetInstance()->DelayAlarmRing(); - UIViewGroup* alarmRingView = CreateAlarmRingView(); - NotificationManager::GetInstance()->screenContainer_->SetVisible(false); - RootView::GetInstance()->Add(alarmRingView); - alarmRingView->SetVisible(true); - StartAlarmTimer(AlarmTimerType::NOTIFY_ALARM_DELAY, NOTIFY_THREE_SECONDS); + void AlarmViewEventListener::DelayAlarmRing() + { + CancelAlarmRing();//先取消闹铃 + AlarmClockModel::GetInstance()->AlarmGetClockNum(); + AlarmClockModel::GetInstance()->DelayAlarmRing(); } - return true; -} -} // namespace OHOS +} // namespace OHOS -- 2.17.1