mcu_hi3321_watch/tjd/ui/app/flashlight/TjdUiAppFlashlightPresenter.cpp
2025-05-26 20:15:20 +08:00

138 lines
5.0 KiB
C++

#include "TjdUiAppFlashlightPresenter.h"
#include "TjdUiAppFlashlightView.h"
#include "dock/input_device.h"
#include "power_display_service.h"
#include "sql_fit.h"
#include "sql_setting.h"
#include "wearable_log.h"
#include "TjdUiRegisterManager.h"
using namespace OHOS;
namespace TJD {
TJD_REGIST_SLICE(TJD_APP_VIEW_FLASHLIGHT, TjdUiAppFlashlightView, TjdUiAppFlashlightPresenter);
static TjdUiAppFlashlightPresenter *g_pv_AppFlashlightPresenter = nullptr;
static int8_t statussign = 0;
TjdUiAppFlashlightPresenter::TjdUiAppFlashlightPresenter() { g_pv_AppFlashlightPresenter = this; }
TjdUiAppFlashlightPresenter::~TjdUiAppFlashlightPresenter() { g_pv_AppFlashlightPresenter = nullptr; }
TjdUiAppFlashlightPresenter *TjdUiAppFlashlightPresenter::GetInstance(void) { return g_pv_AppFlashlightPresenter; }
void TjdUiAppFlashlightPresenter::OnSwipe(UISwipeView &view) {}
void TjdUiAppFlashlightPresenter::Notify()
{
if (changeFlag) {
TjdUiAppFlashlightView::GetInstance()->Changestatus();
}
}
void TjdUiAppFlashlightPresenter::OnStart()
{
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
SetPeriod(200);
}
void TjdUiAppFlashlightPresenter::OnPause()
{
Presenter::OnPause();
}
void TjdUiAppFlashlightPresenter::OnResume()
{
Presenter::OnResume();
}
void TjdUiAppFlashlightPresenter::OnStop()
{
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
}
bool TjdUiAppFlashlightPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
{
printf("TjdUiAppFlashlightPresenter onclcik\r\n");
TjdUiAppFlashlightView *flashlightView = TjdUiAppFlashlightView::GetInstance();
std::string viewId = view.GetViewId();
if (viewId.empty()) {
return false;
}
if (viewId == LASHLIGHT_OFF_ID || viewId == FLASHLIGHT_ONOFF_ID) {
flashlightView->ShowView_(FlashlightViewIndex::FLASHLIGHT_OFF_VIEW,
FlashlightViewIndex::FLASHLIGHT_ON_TO_OFF_VIEW, FlashlightViewIndex::Flashlight_VIEW);
changeFlag = !changeFlag;
statussign = 2;
return true;
} else if (viewId == LASHLIGHT_ON_ID) {
flashlightView->ShowView(FlashlightViewIndex::FLASHLIGHT_ON_VIEW,
FlashlightViewIndex::Flashlight_VIEW); // 返回flashlight
statussign = 1;
return true;
} else if (viewId == FLASHLIGHT_ID && statussign == 1) { // flashlight页面返回模式1
flashlightView->ShowView(FlashlightViewIndex::Flashlight_VIEW, FlashlightViewIndex::FLASHLIGHT_ON_VIEW);
statussign = 0;
return true;
} else if (viewId == FLASHLIGHT_ID || viewId == FLASHLIGHT_ONOFF_ID && statussign == 2) { // flashlight页面返回模式2
flashlightView->ShowView(FlashlightViewIndex::Flashlight_VIEW, FlashlightViewIndex::FLASHLIGHT_OFF_VIEW);
changeFlag = !changeFlag;
statussign = 0;
return true;
}
return false;
}
bool TjdUiAppFlashlightPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
{
if(!TjdUiCommonOnKeyListener::GetInstance()->CheckIsExitEvent(event)) {
return true;
}
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN);
return true;
}
bool TjdUiAppFlashlightPresenter::OnDrag(OHOS::UIView &view, const OHOS::DragEvent &event)
{
printf("TjdUiAppFlashlightPresenter ondragend\r\n");
std::string viewId_ = view.GetViewId();
TjdUiAppFlashlightView *flashlightView = TjdUiAppFlashlightView::GetInstance();
if (event.GetDragDirection() == OHOS::DragEvent::DIRECTION_BOTTOM_TO_TOP) { // 1 to 2 && viewId_ == LASHLIGHT_ON_ID
if (flashlightView->GetCurrentView() == FlashlightViewIndex::FLASHLIGHT_ON_VIEW) {
flashlightView->ShowView(FlashlightViewIndex::FLASHLIGHT_ON_VIEW, FlashlightViewIndex::FLASHLIGHT_OFF_VIEW);
changeFlag = !changeFlag;
return true;
}
}
if (event.GetDragDirection() == OHOS::DragEvent::DIRECTION_TOP_TO_BOTTOM) { // 2 to 1 && viewId_ == LASHLIGHT_OFF_ID
if (flashlightView->GetCurrentView() == FlashlightViewIndex::FLASHLIGHT_OFF_VIEW ||
flashlightView->GetCurrentView() == FlashlightViewIndex::FLASHLIGHT_ON_TO_OFF_VIEW) {
flashlightView->ShowView_(FlashlightViewIndex::FLASHLIGHT_OFF_VIEW,
FlashlightViewIndex::FLASHLIGHT_ON_TO_OFF_VIEW,
FlashlightViewIndex::FLASHLIGHT_ON_VIEW);
changeFlag = !changeFlag;
return true;
}
}
return TjdUiScreenDragListener::OnDrag(view, event);
}
void TjdUiAppFlashlightPresenter::SetScreenBrightness(int value)
{
const power_display_svr_api_t *handle = power_display_svr_get_api();
handle->set_brightness_mode(MANUAL);
handle->set_brightness(value);
}
int TjdUiAppFlashlightPresenter::GetScreenBrightness(void)
{
const power_display_svr_api_t *handle = power_display_svr_get_api();
return handle->get_brightness();
}
} // namespace TJD