查找手表弹窗添加
authorluozheng <1732036298@qq.com>
Thu, 29 May 2025 09:34:08 +0000 (17:34 +0800)
committerluozheng <1732036298@qq.com>
Thu, 29 May 2025 09:34:08 +0000 (17:34 +0800)
code/sdk/application/wearable/fd230/service/broadcast/include/broadcast_feature.h
code/sdk/application/wearable/fd230/service/broadcast/src/broadcast_implement.c
code/sdk/application/wearable/fd230/service/msg_center/CMakeLists.txt
code/sdk/application/wearable/fd230/service/msg_center/include/notify/findwatch_notification.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp
code/sdk/application/wearable/fd230/service/msg_center/src/notify/findwatch_notification.cpp [new file with mode: 0644]
code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c

index 242cde1..80216b2 100644 (file)
@@ -89,7 +89,6 @@ typedef enum {
     TOPIC_EVENT_ENTER_CMAERA,\r
     TOPIC_EVENT_CANCEL_CMAERA,\r
     TOPIC_EVENT_FIND_WATCH, //查找手表\r
-    TOPIC_EVENT_CANCEL_FIND_WATCH,//取消查找\r
     TOPIC_EVENT_DRINKREMINDER,//喝水提醒\r
     TOPIC_EVENT_MESSAGENOTE, //消息通知\r
     TOPIC_EVENT_MESSAGE_UPDATA, //消息更新通知\r
index 17361a1..90c5893 100644 (file)
@@ -39,6 +39,7 @@ static const TopicToCore topicToCoreArray[] = {
     {TOPIC_EVENT_LOWPOWER_ALARM, A_CORE_MASK, 1},
     {TOPIC_EVENT_AR_ALERT_TYPE_UPDATE, A_CORE_MASK, 1},
     {TOPIC_EVENT_INACTIVITY_UPDATE, A_CORE_MASK, 1},
+    {TOPIC_EVENT_FIND_WATCH, A_CORE_MASK, 1},
 };
 
 /* 所有的topic,其对应的位图 */
index 36a4d55..9038d1a 100644 (file)
@@ -152,6 +152,7 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/charge_notification.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/motion_recognition_notification.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sedentaryReminder_notification.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/findwatch_notification.cpp
 )
 else()
 set(SOURCES
@@ -166,6 +167,7 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/charge_notification.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/motion_recognition_notification.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sedentaryReminder_notification.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/findwatch_notification.cpp
     
 )
 endif()
diff --git a/code/sdk/application/wearable/fd230/service/msg_center/include/notify/findwatch_notification.h b/code/sdk/application/wearable/fd230/service/msg_center/include/notify/findwatch_notification.h
new file mode 100644 (file)
index 0000000..e4f6928
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-25 17:31:19
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-12-24 17:51:31
+ * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/findwatch_notification.h
+ */
+#ifndef FIND_WATCH_NOTIFICATION_H
+#define FIND_WATCH_NOTIFICATION_H
+
+#include "audio_manager.h"
+#include "source.h"
+#include "player.h"
+
+namespace OHOS
+{
+    UIViewGroup *CreateFindWatchView(void);
+    void FreeFindWatchView(void);
+
+    using OHOS::Media::Player;
+    using OHOS::Media::Source;
+    using namespace OHOS::Media;
+    using namespace Audio;
+    using Audio::AudioManager;
+
+    // 播放器
+    class FindWatchRingPlayerListener : public InterruptListener
+    {
+    public:
+        FindWatchRingPlayerListener() {}
+        ~FindWatchRingPlayerListener() {}
+
+        void SetOwner(std::shared_ptr<Player> player);
+        void RestFlag();
+        bool IsPaused();
+        bool IsDelayed();
+        bool IsResumed();
+        bool IsBeginStopped();
+        bool IsEndStopped();
+        void StopFindWatchRing();
+        void StartFindWatchRing();
+        void OnInterrupt(int32_t type, int32_t hint) override;
+
+    private:
+        std::shared_ptr<Player> player_{nullptr};
+        bool isPaused_{false};
+        bool isDelayed_{false};
+        bool isResumed_{false};
+        bool isBeginStopped_{false};
+        bool isEndStopped_{false};
+    };
+
+    // 播放器回调
+    class FindWatchRingPlayerCallbackImpl : public OHOS::Media::PlayerCallback
+    {
+    public:
+        FindWatchRingPlayerCallbackImpl() {}
+        ~FindWatchRingPlayerCallbackImpl() {}
+        void OnPlaybackComplete();
+        void OnError(int32_t errorType, int32_t errorCode);
+        void OnInfo(int type, int extra);
+        void OnRewindToComplete();
+    };
+
+    class FindWatchViewEventListener : public UIView::OnTouchListener, public UIView::OnDragListener,public RootView::OnKeyActListener
+    {
+    public:
+        static FindWatchViewEventListener &GetInstance(void);
+        void PopInterCancelMusic(void);
+        void PopInterPlayMusic(const char *path);
+        void PopInterPlayMusic_product(const char *path);
+        void PopInterCancelMusic_product();
+        int FindWatchRingPlayStop(void);
+        int FindWatchRingPlayStart(const char *path);
+        int FindWatchRingPlayerInit(const char *path);
+        int FindWatchRingPlayerStat(void);
+        bool GetFindWatchNotifyFlag(void);
+        void SetFindWatchNotifyFlag(bool flag);
+        void SetVibration(void);
+        void SetLCDFlicker(bool state);
+        void SetScreenBrightness(void);
+        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;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override
+        {
+            return true;
+        }
+        
+        const char *GetPath();
+
+        void setVolumeVal(int val);
+
+        static uint8_t pre_screen_status;
+
+    private:
+        FindWatchViewEventListener();
+        ~FindWatchViewEventListener();
+        FindWatchViewEventListener(const FindWatchViewEventListener &) = delete;
+        const FindWatchViewEventListener &operator=(const FindWatchViewEventListener &);
+        std::string uri;
+        std::shared_ptr<PlayerCallback> playerCallback{nullptr};
+        std::shared_ptr<Player> playerCtr{nullptr};
+        std::map<std::string, std::string> header;
+        std::shared_ptr<Source> source{nullptr};
+        std::shared_ptr<FindWatchRingPlayerListener> playerInterruptListener{nullptr};
+        AudioSession sessionId;
+        AudioInterrupt interrupt;
+#ifdef SINGLE_USER_PARTITION
+        const char *RingMusicName = "/user/music/ring/findwatch.mp3";
+#else
+        const char *RingMusicName = "/music/ring/findwatch.mp3";
+#endif
+        const char * path_{nullptr};
+        bool FindWatchNotifyFlag{false}; // 判断是查找手表, 由notify生成界面
+        bool X_DRAG_FLAG{false};
+    };
+}
+#endif
\ No newline at end of file
index 405baf3..8dfb756 100644 (file)
@@ -45,6 +45,7 @@
 #include "charge_notification.h"
 #include "motion_recognition_notification.h"
 #include "sedentaryReminder_notification.h"
+#include "findwatch_notification.h"
 
 #ifdef SUPPORT_POWER_MANAGER
 #include "power_display_service.h"
@@ -78,6 +79,8 @@ const PriorityMapper PRI_MAPPER[] = {
     {TOPIC_EVENT_AR_ALERT_TYPE_UPDATE, PRIORITY_TWO},
     {TOPIC_EVENT_INACTIVITY_UPDATE, PRIORITY_TWO},
     // #endif
+    {TOPIC_EVENT_FIND_WATCH,PRIORITY_TWO},      // 查找找手表 
+
 
 };
 
@@ -122,6 +125,7 @@ void MsgCenterSubscribe()
     MsgCenterSubscribeTopic(TOPIC_EVENT_AR_ALERT_TYPE_UPDATE);
     MsgCenterSubscribeTopic(TOPIC_EVENT_INACTIVITY_UPDATE);
     // #endif
+    MsgCenterSubscribeTopic(TOPIC_EVENT_FIND_WATCH);
     
 }
 
@@ -191,6 +195,12 @@ static OHOS::UIViewGroup* showSedentaryReminderNotify(void)
     return OHOS::CreateSedentaryReminderView();
 }
 
+//查找手表
+static OHOS::UIViewGroup* showFindWatchNotify(void)
+{
+    return OHOS::CreateFindWatchView();
+}
+
 void MsgCenterNotifyAlarmProc(const Topic topic, Request* req)
 {
     unused(req);
@@ -590,6 +600,31 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
     #endif
 }
 
+//查找手表通知
+void MsgCenterNotifyFindWatchProc(const Topic topic, Request* req)
+{
+    WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyFindWatchProc !");
+    if (CheckPriority(topic))
+    {
+        uint8_t* type=(uint8_t*)req->data;
+        if(*type == 1)
+        {
+            FindWatchViewEventListener::GetInstance().SetFindWatchNotifyFlag(true);
+            FindWatchViewEventListener::GetInstance().PopInterPlayMusic(nullptr);//播放铃声
+            NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
+            NotificationManager::GetInstance()->ShowNotify(showFindWatchNotify, (uint16_t)topic, true);
+            //如果查找手表铃声播放成功,记录该事件
+            uapi_save_runtime_log(RUNTIME_LOG_RING_PLAY_START_FINDWATCH);//TOOD*
+        } else {
+            if (FindWatchViewEventListener::GetInstance().GetFindWatchNotifyFlag() == true) {
+                NotificationManager::GetInstance()->StopNotify();
+            }
+            FindWatchViewEventListener::GetInstance().SetFindWatchNotifyFlag(false);
+        }
+    } else {
+        WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "NotifyPriority = %d ",NotificationManager::GetInstance()->GetNotifyPriority());
+    }
+}
 #endif
 
 /* 订阅事件通知逻辑可定制 */
@@ -613,6 +648,7 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = {
     {TOPIC_EVENT_AR_ALERT_TYPE_UPDATE,       MsgCenterNotifyArAlertProc},
     {TOPIC_EVENT_INACTIVITY_UPDATE,       MsgCenterNotifyInactivityProc},
     // #endif
+    {TOPIC_EVENT_FIND_WATCH,MsgCenterNotifyFindWatchProc},
     // {TOPIC_EVENT_DEVICE_UNBIND,   MsgCenterNotifyDeviceUnBindProc},   
     // {TOPIC_EVENT_DEVICE_UNBINDING_REQUEST,   MsgCenterNotifyDeviceUnBindingRequestProc},   
 
diff --git a/code/sdk/application/wearable/fd230/service/msg_center/src/notify/findwatch_notification.cpp b/code/sdk/application/wearable/fd230/service/msg_center/src/notify/findwatch_notification.cpp
new file mode 100644 (file)
index 0000000..7dfe823
--- /dev/null
@@ -0,0 +1,607 @@
+#include "notification_manager.h"
+#include "wearable_log.h"
+#include "components/ui_button.h"
+#include <iostream>
+#include "uiservice/include/ui_service.h"
+#include <graphic_service.h>
+#include "bleEvent.h"
+#include <UiConfig.h>
+#include <power_display_service.h>
+#include "ConfigModel.h"
+#include <cmsis_os2.h>
+#include <cmsis_os.h>
+#include "vibrator_service.h"
+#include "custom_runtime.h"
+#include <custom_utils.h>
+#include "aivoice/include/AiVoiceModel.h"
+#include <custom_save_runtime.h>
+#include "findwatch_notification.h"
+
+namespace OHOS
+{
+    UIViewGroup *FindWatchGroupView{nullptr};
+    UIButton *FindWatchButton{nullptr};
+    uint8_t FindWatchViewEventListener::pre_screen_status = 0;//屏幕之前的状态
+    static OHOS::RootView::OnKeyActListener *g_onKeyActListener = nullptr;
+    FindWatchViewEventListener::FindWatchViewEventListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatchViewEventListener");
+    }
+
+    FindWatchViewEventListener::~FindWatchViewEventListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::~FindWatchViewEventListener");
+    }
+
+    FindWatchViewEventListener &FindWatchViewEventListener::GetInstance(void)
+    {
+        static FindWatchViewEventListener instance;
+        return instance;
+    }
+
+    bool FindWatchViewEventListener::OnRelease(UIView &view, const ReleaseEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::OnRelease");
+        UNUSED(event);
+        if (&view == FindWatchButton || &FindWatchGroupView) // 手表已找到
+        {
+#ifdef SUPPORT_BLE_SERVICE
+            setFindWatchFlag(2); // 表示已找到手表
+#endif
+            // 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;
+    }
+
+    const char *FindWatchViewEventListener::GetPath()
+    {
+        return path_;
+    }
+
+    void FindWatchViewEventListener::SetFindWatchNotifyFlag(bool flag)
+    {
+        FindWatchNotifyFlag = flag;
+    }
+
+    // 获取查找手表通知状态
+    bool FindWatchViewEventListener::GetFindWatchNotifyFlag(void)
+    {
+        return FindWatchNotifyFlag;
+    }
+
+    // 震动
+    void FindWatchViewEventListener::SetVibration(void)
+    {
+        if (nullptr != FindWatchGroupView)
+        {
+            ui_api_vibrate_once_func();
+        }
+    }
+
+    // 闪烁屏幕
+    void FindWatchViewEventListener::SetLCDFlicker(bool state)
+    {
+        if (nullptr != FindWatchGroupView)
+        {
+            FindWatchGroupView->SetStyle(STYLE_BACKGROUND_COLOR, state ? 0xff000000 : 0xffffffff);
+            FindWatchGroupView->Invalidate();
+        }
+    }
+
+    /*设置屏幕亮度100%*/
+    void FindWatchViewEventListener::SetScreenBrightness(void)
+    {
+        const power_display_svr_api_t *display_api = power_display_svr_get_api();
+        if (display_api)
+        {
+            /*100%亮度*/
+            int max_brightness_value = MAX_BRIGHTNESS;
+            if (display_api->set_brightness(max_brightness_value) != ERRCODE_SUCC)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindWatchViewEventListener] set_brightness fail!!");
+                return;
+            }
+        }
+    }
+
+    /*恢复屏幕亮度*/
+    void FindWatchViewEventListener::ResumeScreenBrightness(void)
+    {
+        const power_display_svr_api_t *display_api = power_display_svr_get_api();
+        if (display_api)
+        {
+            int brightnessValue;
+            if (uapi_dev_runtime_get_saveele_status()) // 如果是省电模式状态下退出要把亮度设置为最低
+            {
+                brightnessValue = MIN_BRIGHTNESS; // 恢复到最低亮度
+            }
+            else
+            {
+                brightnessValue = ConfigModel::GetInstance()->GetBrightness();
+            }
+            if (display_api->set_brightness(brightnessValue) != ERRCODE_SUCC)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindWatchViewEventListener] resume_brightness fail!");
+                return;
+            }
+        }
+    }
+
+    /*
+     * @brief 初始化查找手表播放铃声的播放器
+     * @param {char*} RingMusicName 铃声文件
+     */
+    int FindWatchViewEventListener::FindWatchRingPlayerInit(const char *path)
+    {
+        // 本地播放文件路径和状态
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RingPlayerInit start!,%s", path);
+        uri = path;
+        // 创建 AM
+        playerCtr = std::make_shared<Player>();
+        if (playerCtr == nullptr || playerCtr.get() == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr new fail");
+            return OHOS_FAILURE;
+        }
+        playerCallback = std::make_shared<FindWatchRingPlayerCallbackImpl>();
+        if (playerCallback.get() == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCallback new fail");
+            return OHOS_FAILURE;
+        }
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RingPlayerInit end!");
+        return OHOS_SUCCESS;
+    }
+
+    /*
+     * @brief 准备并播放铃声
+     */
+    int FindWatchViewEventListener::FindWatchRingPlayerStat(void)
+    {
+        /* -------------------------------- 1.检查播放器实例 ------------------------------- */
+        int32_t ret;
+        int32_t state;
+        if (playerCtr.get() == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatchRingPlayerStat playerCtr nullptr");
+            return OHOS_FAILURE;
+        }
+        playerCtr->GetPlayerState(state);
+        /* -------------------------------- 2.设置播放器回调 ------------------------------- */
+        playerCtr->SetPlayerCallback(playerCallback);
+        /* -------------------------------- 3.创建并设置音频源 -------------------------------- */
+        source = std::make_shared<Source>(uri, header);
+        if (source.get() == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "source new fail");
+            return OHOS_FAILURE;
+        }
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatchRing Player url:%s", uri.c_str());
+        playerCtr->SetSource(*source);
+        /* --------------------------------- 4.配置播放器 -------------------------------- */
+        playerCtr->SetAudioStreamType(AUDIO_STREAM_NOTIFICATION_SYSTEM); // 设置播放器的音频流类型,支持混音
+        playerCtr->Prepare();                                            // 准备播放器对象以播放音频。
+        /* -------------------------------- 5.请求音频焦点 -------------------------------- */
+        AudioManager &amIntance = AudioManager::GetInstance();
+        sessionId = amIntance.MakeSessionId();
+        if (sessionId == AUDIO_SESSION_ID_NONE)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "session invalid");
+            return OHOS_FAILURE;
+        }
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MakeSessionId  %d", sessionId);
+        playerInterruptListener = std::make_shared<FindWatchRingPlayerListener>();
+        if (playerInterruptListener.get() == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerInterruptListener new fail");
+            return OHOS_FAILURE;
+        }
+        playerInterruptListener->SetOwner(playerCtr);
+        interrupt = {AUDIO_STREAM_NOTIFICATION_SYSTEM, sessionId, playerInterruptListener};
+        // 激活音频中断 5s超时
+        if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ActivateAudioInterrupt faild");
+            return OHOS_FAILURE;
+        }
+        playerCtr->SetVolume(300, 300); // 将左声道和右声道音量都设置为50
+        playerCtr->SetAudioSessionId(sessionId);
+        // 播放
+        playerCtr->Play();
+        playerCtr->EnableSingleLooping(true); // 设置是否循环播放
+        return OHOS_SUCCESS;
+    }
+
+    void FindWatchViewEventListener::setVolumeVal(int val)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "volume:%d", AudioManager::GetInstance().GetVolume(AUDIO_STREAM_NOTIFICATION_SYSTEM));
+        AudioManager::GetInstance().SetVolume(AUDIO_STREAM_NOTIFICATION_SYSTEM,val);
+    }
+
+    /*
+     * @brief 停止查找手表铃声
+     */
+    int FindWatchViewEventListener::FindWatchRingPlayStop(void)
+    {
+        int32_t ret = 0;
+        AudioManager &amIntance = AudioManager::GetInstance();
+        if (playerCtr.get() == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatchRingPlayStop playerCtr nullptr");
+            return OHOS_FAILURE;
+        }
+
+        ret = playerCtr->Stop();
+        playerCtr->Reset();
+        playerCtr->Release();
+        if (amIntance.DeactivateAudioInterrupt(interrupt) != 0)
+        {
+            return OHOS_FAILURE;
+        }
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret);
+        return OHOS_SUCCESS;
+    }
+
+    /*
+     * @brief 开启查找手表铃声
+     */
+    int FindWatchViewEventListener::FindWatchRingPlayStart(const char *path)
+    {
+        FindWatchRingPlayStop(); // 如果playerCtr上音频资源没被释放,先释放
+        FindWatchRingPlayerInit(((path == nullptr) ? RingMusicName : path));
+        FindWatchRingPlayerStat();
+        return OHOS_SUCCESS;
+    }
+
+    /*
+     * @brief 停止铃声播放的事件
+     */
+    void FindWatchViewEventListener::PopInterCancelMusic(void)
+    {
+        // SendMsgToUIService(SCREEN_TURN_OFF_TO_UI, 0, nullptr, 0);
+        // ScreenTurnOff();
+        GraphicService::GetInstance()->PostGraphicEvent(
+            std::bind(&FindWatchViewEventListener::FindWatchRingPlayStop, &FindWatchViewEventListener::GetInstance()));
+    }
+
+    /*
+     * @brief 开始铃声播放的事件
+     */
+    void FindWatchViewEventListener::PopInterPlayMusic(const char *path)
+    {
+        path_ = path;
+        // ScreenTurnOn(-1); // 亮屏操作
+        // 将"开启查找手表铃声"任务发布到异步线程
+        GraphicService::GetInstance()->PostGraphicEvent(
+            std::bind(&FindWatchViewEventListener::FindWatchRingPlayStart, &FindWatchViewEventListener::GetInstance(), path_));
+    }
+
+    void FindWatchViewEventListener::PopInterCancelMusic_product()
+    {
+        FindWatchRingPlayStop();
+    }
+    void FindWatchViewEventListener::PopInterPlayMusic_product(const char *path)
+    {
+        FindWatchRingPlayStart(path);
+    }
+
+    // 声明定时器变量
+    static osTimerId_t g_timer = nullptr;
+    static bool findwatch_time = true;
+    /*定时器到期时的处理*/
+    static void FindWatch_TimerCallbackProc(int data)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatch_TimerCallbackProc");
+        findwatch_time = !findwatch_time;
+        FindWatchViewEventListener::GetInstance().SetVibration();
+        FindWatchViewEventListener::GetInstance().SetLCDFlicker(findwatch_time);
+    }
+
+    /*
+     * @brief 回调函数
+     */
+    static void FindWatch_TimerCallback(int data)
+    {
+        GraphicService::GetInstance()->PostGraphicEvent(std::bind(FindWatch_TimerCallbackProc, data));
+    }
+
+    /*开启定时器*/
+    void FindWatchViewEventListener::FindWatch_StartTimer(int interval)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatch_StartTimer");
+        /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
+        if (g_timer != nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " Timer already exists!!");
+            return;
+        }
+
+        /* --------------------------------- 2.创建定时器 -------------------------------- */
+        g_timer = osTimerNew((osTimerFunc_t)FindWatch_TimerCallback, osTimerPeriodic, nullptr, nullptr);
+        // 检查定时器创建是否成功
+        if (g_timer == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!");
+            return;
+        }
+
+        /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */
+        int tick = osMs2Tick(interval);
+
+        /* --------------------------------- 4.启动定时器 -------------------------------- */
+        osStatus_t ret = osTimerStart(g_timer, tick);
+        /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */
+        if (ret != osOK)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
+            if (g_timer != nullptr)
+            {
+                ret = osTimerDelete(g_timer);
+            }
+            g_timer = nullptr;
+            return;
+        }
+
+        return;
+    }
+
+    /*停止定时器*/
+    void FindWatchViewEventListener::FindWatch_StopTimer(void)
+    {
+        // 检查定时器是否存在
+        if (g_timer != nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatch_StopTimer");
+            osTimerStop(g_timer);
+            // 删除定时器并置为 nullptr
+            osStatus_t ret = osTimerDelete(g_timer);
+            if (ret != osOK)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
+            }
+            g_timer = nullptr;
+        }
+    }
+
+    /*
+     * @brief 创建查找手表视图
+     */
+    UIViewGroup *CreateFindWatchView(void)
+    {
+        if (FindWatchGroupView == nullptr)
+        {
+            FindWatchGroupView = new UIViewGroup();
+            if (FindWatchGroupView == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateFindWatchView] FindWatchGroupView new fail!!");
+                return nullptr;
+            }
+            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<UIView::OnTouchListener *>(&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<UIView::OnDragListener *>(&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)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateFindWatchView] FindWatchButton new fail!!");
+                return nullptr;
+            }
+            FindWatchButton->SetPosition(183, 183, 100, 100);
+            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, 0xfff0f0f0, UIButton::PRESSED);
+            FindWatchButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0xfff0f0f0, UIButton::PRESSED);
+            FindWatchButton->SetOnTouchListener(touchListener);
+
+            FindWatchGroupView->Add(FindWatchButton);
+        }
+
+        FindWatchViewEventListener::GetInstance().FindWatch_StartTimer(700);
+        FindWatchViewEventListener::GetInstance().SetScreenBrightness();
+
+        g_onKeyActListener = RootView::GetInstance()->GetOnKeyActListener();
+        RootView::GetInstance()->SetOnKeyActListener(&FindWatchViewEventListener::GetInstance());
+
+        FindWatchViewEventListener::pre_screen_status = uapi_dev_runtime_get_screen_always_on_status();//获取查找手表之前是否是长亮屏状态
+        if(!FindWatchViewEventListener::pre_screen_status)
+        {
+            ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
+        }
+
+        NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeFindWatchView);
+        return FindWatchGroupView;
+    }
+
+    /*
+     * @brief 释放查找手表视图
+     */
+    void FreeFindWatchView(void)
+    {
+        if (FindWatchGroupView != nullptr)
+        {
+            FindWatchGroupView->Remove(FindWatchButton);
+
+            delete FindWatchButton;
+            FindWatchButton = nullptr;
+
+            RootView::GetInstance()->SetOnKeyActListener(g_onKeyActListener);
+            RootView::GetInstance()->Remove(FindWatchGroupView);
+
+            delete FindWatchGroupView;
+            FindWatchGroupView = nullptr;
+        }
+
+        FindWatchViewEventListener::GetInstance().FindWatchRingPlayStop();
+        FindWatchViewEventListener::GetInstance().ResumeScreenBrightness();
+        FindWatchViewEventListener::GetInstance().FindWatch_StopTimer();
+        if(!FindWatchViewEventListener::pre_screen_status) //如果查找手表之前不是长亮屏状态,就取消查找手表设置的常亮屏
+        {
+            ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
+        }
+        //如果查找手表铃声停止播放成功,记录该事件
+        uapi_save_runtime_log(RUNTIME_LOG_RING_PLAY_STOP_FINDWATCH);//TOOD*
+    }
+
+    /* ----------------------- FindWatchRingPlayerListener ---------------------- */
+    void FindWatchRingPlayerListener::SetOwner(std::shared_ptr<Player> player)
+    {
+        player_ = player;
+    }
+
+    void FindWatchRingPlayerListener::RestFlag()
+    {
+        isPaused_ = false;
+        isDelayed_ = false;
+        isResumed_ = false;
+        isBeginStopped_ = false;
+        isEndStopped_ = false;
+    }
+
+    bool FindWatchRingPlayerListener::IsPaused()
+    {
+        return isPaused_;
+    }
+
+    bool FindWatchRingPlayerListener::IsDelayed()
+    {
+        return isDelayed_;
+    }
+
+    bool FindWatchRingPlayerListener::IsResumed()
+    {
+        return isResumed_;
+    }
+
+    bool FindWatchRingPlayerListener::IsBeginStopped()
+    {
+        return isBeginStopped_;
+    }
+
+    bool FindWatchRingPlayerListener::IsEndStopped()
+    {
+        return isEndStopped_;
+    }
+
+    static void Start(void)
+    {
+        FindWatchViewEventListener::GetInstance().PopInterPlayMusic(nullptr);
+    }
+
+    static void Stop(void)
+    {
+        FindWatchViewEventListener::GetInstance().PopInterCancelMusic();
+    }
+
+    void FindWatchRingPlayerListener::StartFindWatchRing(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FindWatchRingPlayerListener::StopFindWatchRing] start");
+        GraphicService::GetInstance()->PostGraphicEvent(Start);
+    }
+
+    void FindWatchRingPlayerListener::StopFindWatchRing(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FindWatchRingPlayerListener::StopFindWatchRing] start");
+        GraphicService::GetInstance()->PostGraphicEvent(Stop);
+    }
+
+    /*响应外部的音频中断事件*/
+    void FindWatchRingPlayerListener::OnInterrupt(int32_t type, int32_t hint)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnInterrupt go in, type %d, hint %d.", type, hint);
+        if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_PAUSE)
+        {
+            isDelayed_ = true;
+        }
+
+        if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_STOP)
+        {
+            StopFindWatchRing();
+        }
+        else if (type == INTERRUPT_TYPE_END && isDelayed_)
+        {
+            // 重新开始查找手表的音乐播放
+            StartFindWatchRing();
+            isDelayed_ = false;
+        }
+        return;
+    }
+
+    /* --------------------- FindWatchRingPlayerCallbackImpl -------------------- */
+    void FindWatchRingPlayerCallbackImpl::OnPlaybackComplete(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnPlaybackComplete");
+        // FindWatchViewEventListener::GetInstance().PopInterCancelMusic();
+        // const char *path = FindWatchViewEventListener::GetInstance().GetPath();
+        // FindWatchViewEventListener::GetInstance().PopInterPlayMusic((path != nullptr) ? path : nullptr);
+    }
+
+    void FindWatchRingPlayerCallbackImpl::OnError(int32_t errorType, int32_t errorCode)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnError test, errorType %d, errorCode %d", errorType, errorCode);
+        // 此处实现代码处理错误事件
+    }
+
+    void FindWatchRingPlayerCallbackImpl::OnInfo(int type, int extra)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnInfo test, type %d, extra %d.", type, extra);
+        // 此处实现代码处理普通事件
+    }
+
+    void FindWatchRingPlayerCallbackImpl::OnRewindToComplete(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRewindToComplete test");
+        // 此处实现代码处理进度控制完成的事件
+    }
+
+}
index d2c02a7..e6062d6 100644 (file)
@@ -4063,12 +4063,13 @@ static void findWatchCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totald
         uint8_t findFlag = data[0];\r
         //弹窗界面\r
         if(findFlag)//查找手表弹窗界面\r
-        {\r
-            CustomEventPublish(TOPIC_EVENT_FIND_WATCH,NULL,0);\r
-        }else//停止查找手表 如果在查找手表界面就要停止回到上一级界面\r
-        {\r
-            CustomEventPublish(TOPIC_EVENT_CANCEL_FIND_WATCH,NULL,0);\r
-        }\r
+        // {\r
+        //     CustomEventPublish(TOPIC_EVENT_FIND_WATCH,&findFlag,sizeof(findFlag));\r
+        // }else//停止查找手表 如果在查找手表界面就要停止回到上一级界面\r
+        // {\r
+        //     CustomEventPublish(TOPIC_EVENT_CANCEL_FIND_WATCH,NULL,0);\r
+        // }\r
+        CustomEventPublish(TOPIC_EVENT_FIND_WATCH,&findFlag,sizeof(findFlag));\r
         setFindWatchFlag(1);\r
     }else\r
     {\r