* @Author: luozheng 1732036298@qq.com
* @Date: 2024-03-25 17:33:47
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-10-10 11:50:28
+ * @LastEditTime: 2024-10-18 18:02:00
* @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp
* @details:实现查找手表的功能一般需要手表和智能手机之间的配合,通常是通过手机上的应用(App)或其他设备发送指令给手表,触发手表的查找功能。
* 以下是基本的实现步骤:
void FindWatchViewEventListener::SetFindWatchNotifyFlag(bool flag)
{
FindWatchNotifyFlag = flag;
- // if(FindWatchNotifyFlag)
- // {
- // FindWatch_StartTimer();
- // }
- // else
- // {
- // FindWatch_StopTimer();
- // }
}
// 获取查找手表通知状态
return FindWatchNotifyFlag;
}
+ // 震动
void FindWatchViewEventListener::SetVibration(void)
{
- // if(true == ConfigModel::GetInstance()->GetDnotdisturb() || (uapi_sleep_mode_flag_get()))
- // {
- // return;
- // }
-
- if(nullptr != FindWatchGroupView)
+ if (nullptr != FindWatchGroupView)
{
ui_api_vibrate_once_func();
}
}
+ // 闪烁屏幕
void FindWatchViewEventListener::SetLCDFlicker(bool state)
{
- if(nullptr != FindWatchGroupView)
+ 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)
{
int brightnessValue;
- if(uapi_dev_runtime_get_saveele_status()) //如果是省电模式状态下退出要把亮度设置为最低
+ if (uapi_dev_runtime_get_saveele_status()) // 如果是省电模式状态下退出要把亮度设置为最低
{
- brightnessValue = MIN_BRIGHTNESS;//恢复到最低亮度
+ brightnessValue = MIN_BRIGHTNESS; // 恢复到最低亮度
}
else
{
- brightnessValue= ConfigModel::GetInstance()->GetBrightness();
+ brightnessValue = ConfigModel::GetInstance()->GetBrightness();
}
if (display_api->set_brightness(brightnessValue) != ERRCODE_SUCC)
{
{
// 本地播放文件路径和状态
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RingPlayerInit start!,%s", path);
- // std::string strSrcMusic("/music/ring");
- // std::string tempStr("/");
- // std::string strName = RingMusicName;
- // uri = strSrcMusic + tempStr + strName;
uri = path;
// 创建 AM
playerCtr = std::make_shared<Player>();
- if (playerCtr.get() == nullptr)
+ if (playerCtr == nullptr || playerCtr.get() == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr new fail");
return OHOS_FAILURE;
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchRing Player url:%s", uri.c_str());
playerCtr->SetSource(*source);
/* --------------------------------- 4.配置播放器 -------------------------------- */
- playerCtr->SetAudioStreamType(AUDIO_STREAM_MUSIC); // 设置播放器的音频流类型为闹钟音乐。
- playerCtr->Prepare(); // 准备播放器对象以播放音频。
+ playerCtr->SetAudioStreamType(AUDIO_STREAM_NOTIFICATION_SYSTEM); // 设置播放器的音频流类型,支持混音
+ playerCtr->Prepare(); // 准备播放器对象以播放音频。
/* -------------------------------- 5.请求音频焦点 -------------------------------- */
AudioManager &amIntance = AudioManager::GetInstance();
sessionId = amIntance.MakeSessionId();
return OHOS_FAILURE;
}
playerInterruptListener->SetOwner(playerCtr);
- interrupt = {AUDIO_STREAM_MUSIC, sessionId, playerInterruptListener};
+ interrupt = {AUDIO_STREAM_NOTIFICATION_SYSTEM, sessionId, playerInterruptListener};
// 激活音频中断 5s超时
if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED)
{
playerCtr->SetAudioSessionId(sessionId);
// 播放
playerCtr->Play();
+ playerCtr->EnableSingleLooping(true); // 设置是否循环播放
return OHOS_SUCCESS;
}
/*
{
path_ = path;
ScreenTurnOn(-1); // 亮屏操作
-
- // if(true == ConfigModel::GetInstance()->GetDnotdisturb() || (uapi_sleep_mode_flag_get()))
- // {
- // return;
- // }
-
// 将"开启查找手表铃声"任务发布到异步线程
GraphicService::GetInstance()->PostGraphicEvent(
std::bind(&FindWatchViewEventListener::FindWatchRingPlayStart, &FindWatchViewEventListener::GetInstance(), path_));
}
// 声明定时器变量
- static osTimerId_t g_timer = NULL;
+ static osTimerId_t g_timer = nullptr;
static bool findwatch_time = true;
/*定时器到期时的处理*/
static void FindWatch_TimerCallbackProc(int data)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatch_StartTimer");
/* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
- if (g_timer != NULL)
+ if (g_timer != nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " Timer already exists!!");
return;
}
/* --------------------------------- 2.创建定时器 -------------------------------- */
- g_timer = osTimerNew((osTimerFunc_t)FindWatch_TimerCallback, osTimerPeriodic, NULL, NULL);
+ g_timer = osTimerNew((osTimerFunc_t)FindWatch_TimerCallback, osTimerPeriodic, nullptr, nullptr);
// 检查定时器创建是否成功
- if (g_timer == NULL)
+ if (g_timer == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!");
return;
/* --------------------------------- 4.启动定时器 -------------------------------- */
osStatus_t ret = osTimerStart(g_timer, tick);
- /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */
+ /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */
if (ret != osOK)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
- if (g_timer != NULL)
+ if (g_timer != nullptr)
{
ret = osTimerDelete(g_timer);
}
- g_timer = NULL;
+ g_timer = nullptr;
return;
}
void FindWatchViewEventListener::FindWatch_StopTimer(void)
{
// 检查定时器是否存在
- if (g_timer != NULL)
+ if (g_timer != nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatch_StopTimer");
osTimerStop(g_timer);
- // 删除定时器并置为 NULL
+ // 删除定时器并置为 nullptr
osStatus_t ret = osTimerDelete(g_timer);
if (ret != osOK)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
}
- g_timer = NULL;
+ g_timer = nullptr;
}
}
FindWatchViewEventListener::GetInstance().FindWatch_StartTimer(700);
FindWatchViewEventListener::GetInstance().SetScreenBrightness();
-
+
NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeFindWatchView);
return FindWatchGroupView;
}
void FindWatchRingPlayerCallbackImpl::OnPlaybackComplete(void)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnPlaybackComplete");
- FindWatchViewEventListener::GetInstance().PopInterCancelMusic();
- const char *path = FindWatchViewEventListener::GetInstance().GetPath();
- FindWatchViewEventListener::GetInstance().PopInterPlayMusic((path != nullptr) ? path : nullptr);
+ // 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)