129 lines
3.7 KiB
C++
129 lines
3.7 KiB
C++
#include "TjdUiAppDrainPresenter.h"
|
|
#include "TjdUiAppDrainView.h"
|
|
#include "TjdUiRegisterManager.h"
|
|
#include "dock/input_device.h"
|
|
#include "player_sample_wrapper.h"
|
|
extern "C" {
|
|
#include "task_ancillary.h"
|
|
}
|
|
#include "wearable_log.h"
|
|
|
|
namespace TJD {
|
|
|
|
TJD_REGIST_SLICE(TJD_APP_VIEW_DRAIN, TjdUiAppDrainView, TjdUiAppDrainPresenter);
|
|
|
|
#ifndef ARRAY_SIZE
|
|
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
|
#endif
|
|
|
|
typedef void (*DrainPostEventHandleFunction)(void);
|
|
static DrainPostEventHandleFunction g_postEventCallback = nullptr;
|
|
|
|
struct DrainEventInfo
|
|
{
|
|
signed int (*func_event_handler)(void *param); // 事件处理函数
|
|
void *param; // 事件处理函数入参
|
|
void (*func_event_debug)(char *str, ...); // 打印
|
|
void *payload;
|
|
};
|
|
|
|
static signed int EventHandler(void *param)
|
|
{
|
|
if (g_postEventCallback != nullptr) {
|
|
g_postEventCallback();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static TjdUiAppDrainPresenter *g_pv_AppDrainPresenter = nullptr;
|
|
|
|
TjdUiAppDrainPresenter::TjdUiAppDrainPresenter() { g_pv_AppDrainPresenter = this; }
|
|
|
|
TjdUiAppDrainPresenter::~TjdUiAppDrainPresenter() { g_pv_AppDrainPresenter = nullptr; }
|
|
|
|
TjdUiAppDrainPresenter *TjdUiAppDrainPresenter::GetInstance(void) { return g_pv_AppDrainPresenter; }
|
|
|
|
void TjdUiAppDrainPresenter::OnStart()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
void TjdUiAppDrainPresenter::OnPause() { Presenter::OnPause(); }
|
|
|
|
void TjdUiAppDrainPresenter::OnResume() { Presenter::OnResume(); }
|
|
|
|
void TjdUiAppDrainPresenter::OnStop()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
bool TjdUiAppDrainPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { return false; }
|
|
|
|
void TjdUiAppDrainPresenter::ViewExitEvent(OHOS::UIView &view, const OHOS::DragEvent &event)
|
|
{
|
|
if (TjdUiAppDrainView::GetInstance()->timerdrain1_ != nullptr) {
|
|
TjdUiAppDrainView::GetInstance()->timerdrain1_->Stop();
|
|
delete TjdUiAppDrainView::GetInstance()->timerdrain1_;
|
|
TjdUiAppDrainView::GetInstance()->timerdrain1_ = nullptr;
|
|
}
|
|
if (TjdUiAppDrainView::GetInstance()->timerdrain2_ != nullptr) {
|
|
TjdUiAppDrainView::GetInstance()->timerdrain2_->Stop();
|
|
delete TjdUiAppDrainView::GetInstance()->timerdrain2_;
|
|
TjdUiAppDrainView::GetInstance()->timerdrain2_ = nullptr;
|
|
}
|
|
|
|
OHOS::NativeAbility::GetInstance().ChangePreSlice();
|
|
|
|
return;
|
|
}
|
|
|
|
bool TjdUiAppDrainPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
|
|
{
|
|
if (!TjdUiCommonOnKeyListener::GetInstance()->CheckIsExitEvent(event)) {
|
|
return true;
|
|
}
|
|
OHOS::NativeAbility::GetInstance().ChangePreSlice();
|
|
return true;
|
|
}
|
|
|
|
static void PostEventHandle(DrainPostEventHandleFunction event)
|
|
{
|
|
DrainEventInfo g_msg_data = {
|
|
.func_event_handler = EventHandler,
|
|
.param = NULL,
|
|
.func_event_debug = NULL,
|
|
.payload = NULL,
|
|
};
|
|
g_postEventCallback = event;
|
|
static unsigned int g_msg_size = sizeof(DrainEventInfo);
|
|
osal_msg_queue_write_copy(tjd_task_ancillary_get_queue_id(), &g_msg_data, g_msg_size, 0);
|
|
}
|
|
|
|
int TjdUiAppDrainPresenter::PlayerStart()
|
|
{
|
|
PostEventHandle([]() {
|
|
const char *argv[] = {"xx", "/user/drain.mp3", "1", "0"};
|
|
PlayerSample(ARRAY_SIZE(argv), argv);
|
|
});
|
|
return 0;
|
|
}
|
|
|
|
int TjdUiAppDrainPresenter::PlayerStop()
|
|
{
|
|
PostEventHandle([]() {
|
|
const char *argv[] = {"stop"};
|
|
PlayerSample(ARRAY_SIZE(argv), argv);
|
|
});
|
|
return 0;
|
|
}
|
|
|
|
int TjdUiAppDrainPresenter::LoopPlayerStart()
|
|
{
|
|
PostEventHandle([]() {
|
|
const char *argv[] = {"loopon"};
|
|
PlayerSample(ARRAY_SIZE(argv), argv);
|
|
});
|
|
return 0;
|
|
}
|
|
|
|
} // namespace TJD
|