From: luozheng <1732036298@qq.com> Date: Thu, 1 Aug 2024 06:36:40 +0000 (+0800) Subject: 查找手表界面优化修改,目前还未适配震动和屏幕闪缩 X-Git-Tag: release_V1.2.70_20241020_135402~555^2~21^2~3 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=042cbbd59b906206c5d39101c345404d1a421dd1;p=mirrors%2FFD230.git 查找手表界面优化修改,目前还未适配震动和屏幕闪缩 --- diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/findwatch_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/findwatch_notification.h index 3411969cf..520642183 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/findwatch_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/findwatch_notification.h @@ -1,8 +1,8 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-25 17:31:19 - * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-07-24 11:16:31 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-01 14:22:04 * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/findwatch_notification.h */ #ifndef FIND_WATCH_NOTIFICATION_H @@ -62,7 +62,7 @@ namespace OHOS void OnRewindToComplete(); }; - class FindWatchViewEventListener : public UIView::OnTouchListener + class FindWatchViewEventListener : public UIView::OnTouchListener, public UIView::OnDragListener { public: static FindWatchViewEventListener &GetInstance(void); @@ -70,11 +70,19 @@ namespace OHOS void PopInterPlayMusic(const char *path); int FindWatchRingPlayStop(void); int FindWatchRingPlayStart(const char *path); - int FindWatchRingPlayerInit(const char* path); + int FindWatchRingPlayerInit(const char *path); int FindWatchRingPlayerStat(void); bool GetFindWatchNotifyFlag(void); void SetFindWatchNotifyFlag(bool flag); + void SetVibrationAndScreenBrightness(bool state); + void ResumeScreenBrightness(void); + + void FindWatch_StartTimer(int interval = 500); + void FindWatch_StopTimer(void); + bool OnRelease(UIView &view, const ReleaseEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event); + bool OnDragEnd(UIView &view, const DragEvent &event) override; private: FindWatchViewEventListener(); @@ -91,6 +99,8 @@ namespace OHOS AudioInterrupt interrupt; const char *RingMusicName = "/music/ring/findwatch.mp3"; bool FindWatchNotifyFlag{false}; // 判断是查找手表, 由notify生成界面 + int brightnessValue{51}; + bool X_DRAG_FLAG{false}; }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp index 944420330..48d59dcc1 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp @@ -1,8 +1,8 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-25 17:33:47 - * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-07-24 11:27:11 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-01 14:35:00 * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp * @details:实现查找手表的功能一般需要手表和智能手机之间的配合,通常是通过手机上的应用(App)或其他设备发送指令给手表,触发手表的查找功能。 * 以下是基本的实现步骤: @@ -32,18 +32,23 @@ #include "ui_service.h" #include #include "bleEvent.h" +#include +#include +#include "ConfigModel.h" +#include +#include namespace OHOS { UIViewGroup *FindWatchGroupView{nullptr}; UIButton *FindWatchButton{nullptr}; FindWatchViewEventListener::FindWatchViewEventListener() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatchViewEventListener"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatchViewEventListener"); } FindWatchViewEventListener::~FindWatchViewEventListener() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::~FindWatchViewEventListener"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::~FindWatchViewEventListener"); } FindWatchViewEventListener &FindWatchViewEventListener::GetInstance(void) @@ -56,7 +61,7 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::OnRelease"); UNUSED(event); - if (&view == FindWatchButton) // 手表已找到 + if (&view == FindWatchButton || &FindWatchGroupView) // 手表已找到 { #ifdef SUPPORT_BLE_SERVICE setFindWatchFlag(2); // 表示已找到手表 @@ -64,6 +69,35 @@ namespace OHOS FindWatchRingPlayStop(); NotificationManager::GetInstance()->StopNotify(); SetFindWatchNotifyFlag(false); + // ResumeScreenBrightness(); + } + return true; + } + + bool FindWatchViewEventListener::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + X_DRAG_FLAG = true; + } + return true; + } + + bool FindWatchViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) + { +#ifdef SUPPORT_BLE_SERVICE + setFindWatchFlag(2); // 表示已找到手表 +#endif + FindWatchRingPlayStop(); + NotificationManager::GetInstance()->StopNotify(); + SetFindWatchNotifyFlag(false); + // ResumeScreenBrightness(); + X_DRAG_FLAG = false; } return true; } @@ -71,6 +105,14 @@ namespace OHOS void FindWatchViewEventListener::SetFindWatchNotifyFlag(bool flag) { FindWatchNotifyFlag = flag; + // if(FindWatchNotifyFlag) + // { + // FindWatch_StartTimer(); + // } + // else + // { + // FindWatch_StopTimer(); + // } } // 获取查找手表通知状态 @@ -79,6 +121,47 @@ namespace OHOS return FindWatchNotifyFlag; } + /*设置100%亮度且手表震动*/ + void FindWatchViewEventListener::SetVibrationAndScreenBrightness(bool state) + { + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api) + { + if (state) + { + /*100%亮度*/ + int max_brightness_value = 255; + if (display_api->set_brightness(max_brightness_value) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindWatchViewEventListener] set_brightness fail!!"); + return; + } + } + else + { + /*20%亮度*/ + int min_brightness_value = 51; + if (display_api->set_brightness(min_brightness_value) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindWatchViewEventListener] set_brightness fail!!"); + return; + } + } + } + } + + /*恢复屏幕亮度*/ + void FindWatchViewEventListener::ResumeScreenBrightness(void) + { + brightnessValue = ConfigModel::GetInstance()->GetBrightness(); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api->set_brightness(brightnessValue) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindWatchViewEventListener] set_brightness fail!"); + return; + } + } + /* * @brief 初始化查找手表播放铃声的播放器 * @param {char*} RingMusicName 铃声文件 @@ -86,7 +169,7 @@ namespace OHOS int FindWatchViewEventListener::FindWatchRingPlayerInit(const char *path) { // 本地播放文件路径和状态 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RingPlayerInit start!,%s",path); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RingPlayerInit start!,%s", path); // std::string strSrcMusic("/music/ring"); // std::string tempStr("/"); // std::string strName = RingMusicName; @@ -136,7 +219,7 @@ namespace OHOS playerCtr->SetSource(*source); /* --------------------------------- 4.配置播放器 -------------------------------- */ playerCtr->SetAudioStreamType(AUDIO_STREAM_MUSIC); // 设置播放器的音频流类型为闹钟音乐。 - playerCtr->Prepare(); // 准备播放器对象以播放音频。 + playerCtr->Prepare(); // 准备播放器对象以播放音频。 /* -------------------------------- 5.请求音频焦点 -------------------------------- */ AudioManager &amIntance = AudioManager::GetInstance(); sessionId = amIntance.MakeSessionId(); @@ -222,6 +305,88 @@ namespace OHOS std::bind(&FindWatchViewEventListener::FindWatchRingPlayStart, &FindWatchViewEventListener::GetInstance(), path)); } + // 声明定时器变量 + static osTimerId_t g_timer = NULL; + static bool findwatch_time = true; + /*定时器到期时的处理*/ + static void FindWatch_TimerCallbackProc(int data) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatch_TimerCallbackProc"); + if (findwatch_time) + { + findwatch_time = true; + } + else + { + findwatch_time = false; + } + FindWatchViewEventListener::GetInstance().SetVibrationAndScreenBrightness(findwatch_time ? true : false); + } + + /* + * @brief 回调函数 + */ + static void FindWatch_TimerCallback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(FindWatch_TimerCallbackProc, data)); + } + + /*开启定时器*/ + void FindWatchViewEventListener::FindWatch_StartTimer(int interval) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatch_StartTimer"); + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_timer != NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " Timer already exists!!"); + return; + } + + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_timer = osTimerNew((osTimerFunc_t)FindWatch_TimerCallback, osTimerPeriodic, NULL, NULL); + // 检查定时器创建是否成功 + if (g_timer == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); + return; + } + + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + + /* --------------------------------- 4.启动定时器 -------------------------------- */ + osStatus_t ret = osTimerStart(g_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + if (g_timer != NULL) + { + ret = osTimerDelete(g_timer); + } + g_timer = NULL; + return; + } + return; + } + + /*停止定时器*/ + void FindWatchViewEventListener::FindWatch_StopTimer(void) + { + // 检查定时器是否存在 + if (g_timer != NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatch_StopTimer"); + // 删除定时器并置为 NULL + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = NULL; + } + } + /* * @brief 创建查找手表视图 */ @@ -238,7 +403,25 @@ namespace OHOS FindWatchGroupView->SetPosition(0, 0, 466, 466); FindWatchGroupView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); FindWatchGroupView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + FindWatchGroupView->SetTouchable(true); + FindWatchGroupView->SetDraggable(true); + UIView::OnTouchListener *touchListener = static_cast(&FindWatchViewEventListener::GetInstance()); + if (touchListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateFindWatchView] FindWatchViewEventListener::GetInstance fail!!"); + return nullptr; + } + FindWatchGroupView->SetOnTouchListener(touchListener); + + UIView::OnDragListener *dragListener = static_cast(&FindWatchViewEventListener::GetInstance()); + if (dragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateFindWatchView] FindWatchViewEventListener::GetInstance fail!!"); + return nullptr; + } + FindWatchGroupView->SetOnDragListener(dragListener); + /* -------------------------------------------------------------------------- */ FindWatchButton = new UIButton(); if (FindWatchButton == nullptr) { @@ -246,14 +429,13 @@ namespace OHOS return nullptr; } FindWatchButton->SetPosition(183, 183, 100, 100); - FindWatchButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff0000); - FindWatchButton->SetStyle(STYLE_BACKGROUND_OPA, 0x20); + FindWatchButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xfff0f0f0); + FindWatchButton->SetStyle(STYLE_BACKGROUND_OPA, 0xff); const char *buttonImgSrc = "/user/res/SYSTEM_CheckOff.bin"; FindWatchButton->SetImageSrc(buttonImgSrc, buttonImgSrc); - FindWatchButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffff0000, UIButton::PRESSED); - FindWatchButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x35, UIButton::PRESSED); - UIView::OnTouchListener *listener = static_cast(&FindWatchViewEventListener::GetInstance()); - FindWatchButton->SetOnTouchListener(listener); + FindWatchButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfff0f0f0, UIButton::PRESSED); + FindWatchButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0xfff0f0f0, UIButton::PRESSED); + FindWatchButton->SetOnTouchListener(touchListener); FindWatchGroupView->Add(FindWatchButton); }