266 lines
7.5 KiB
C++
266 lines
7.5 KiB
C++
/*----------------------------------------------------------------------------
|
||
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
||
*
|
||
* Description: TjdUiScreenEvent.cpp
|
||
*
|
||
* Author: luziquan@ss-tjd.com
|
||
*
|
||
* Create: 2024-10-31
|
||
*--------------------------------------------------------------------------*/
|
||
|
||
#include "TjdUiScreenEvent.h"
|
||
#include "NativeAbility.h"
|
||
#include "TjdUiAppCallModel.h"
|
||
#include "TjdUiAppLockScreenPresenter.h"
|
||
#include "TjdUiAppPasswordPresenter.h"
|
||
#include "TjdUiMsgCenter.h"
|
||
#include "TjdUiOnKeyListener.h"
|
||
#include "TjdUiScreenOffView.h"
|
||
#include "common/key_code.h"
|
||
#include "components/root_view.h"
|
||
#include "dock/input_device.h"
|
||
#include "graphic_service.h"
|
||
#include "notification_manager.h"
|
||
#include "power_display_service.h"
|
||
#include "soc_lcd_api.h"
|
||
#include "sql_setting.h"
|
||
#include "tp_api.h"
|
||
#include "ui_screennotify.h"
|
||
#include <atomic>
|
||
|
||
extern "C"
|
||
{
|
||
#include "display_action.h"
|
||
#include "pm.h"
|
||
}
|
||
|
||
static bool screenEventEnable = true;
|
||
static bool passwordEnable = true;
|
||
static Topic g_currentTopic = TOPIC_END_NUM;
|
||
|
||
static bool HasAnyView(void)
|
||
{
|
||
if (TJD::IsShowPasswordView()) {
|
||
return true;
|
||
}
|
||
if (TJD::IsShowLockScreenView()) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
static void HideAllView(void)
|
||
{
|
||
if (TJD::IsShowPasswordView()) {
|
||
TJD::HidePasswordView();
|
||
}
|
||
if (TJD::IsShowLockScreenView()) {
|
||
TJD::HideLockScreenView();
|
||
}
|
||
}
|
||
|
||
// 是否需要进入密码界面或锁屏界面
|
||
static bool IsEnterLockScreen(void)
|
||
{
|
||
if ((sql_setting_get_password_enable() && passwordEnable) || TJD::IsLockScreenEnable()) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/* 每次点击时判断 */
|
||
static bool ScreenTpTouchEvent(void)
|
||
{
|
||
if (g_currentTopic != TOPIC_END_NUM) {
|
||
return false;
|
||
}
|
||
/* 如果存在密码,显示密码界面,并且清除点击回调输入密码 */
|
||
tjd_driver_tp_unregister_touch_event();
|
||
if (sql_setting_get_password_enable() && passwordEnable) {
|
||
GraphicService::GetInstance()->PostGraphicEvent(TJD::ShowPasswordView);
|
||
TJD::SetLockScreenEnable(false);
|
||
return true;
|
||
}
|
||
if (TJD::IsLockScreenEnable()) {
|
||
GraphicService::GetInstance()->PostGraphicEvent(TJD::ShowLockScreenView);
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
class ScreenEventOnKeyActListener : public OHOS::RootView::OnKeyActListener
|
||
{
|
||
public:
|
||
bool OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
|
||
{
|
||
if (event.GetState() == OHOS::InputDevice::STATE_PRESS) {
|
||
if (event.GetKeyId() == static_cast<uint16_t>(OHOS::ZliteKeyCode::ZLITE_KEY_TJD_RIGHTUP)) {
|
||
return ScreenTpTouchEvent();
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
};
|
||
static ScreenEventOnKeyActListener g_triggerOnKeyActListener;
|
||
|
||
static void TjdUiScreenEventLockButton(void)
|
||
{
|
||
TJD::TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(&g_triggerOnKeyActListener,
|
||
TJD::KeyModelType::LOCK_TRIGGER_KEY_TYPE);
|
||
tjd_driver_tp_register_touch_event(ScreenTpTouchEvent);
|
||
}
|
||
|
||
static void TjdUiScreenEventUnlockButton(void)
|
||
{
|
||
TJD::TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(TJD::KeyModelType::LOCK_TRIGGER_KEY_TYPE);
|
||
}
|
||
|
||
/**
|
||
* @brief 亮屏时调用
|
||
*/
|
||
void TjdUiScreenEventDisplayOn(void)
|
||
{
|
||
if (TJD::IsShowScreenOffClockView()) {
|
||
return;
|
||
}
|
||
/* 转发到UI线程以达到在UI绘制完成后调用 */
|
||
GraphicService::GetInstance()->PostGraphicEvent([]() {
|
||
/* screenEventEnable为false的情况
|
||
* 1. 不需要密码或者锁屏
|
||
* 2. 已经输入密码成功或者锁屏解锁成功
|
||
*/
|
||
if (!screenEventEnable) {
|
||
return;
|
||
}
|
||
|
||
/* 每次亮屏时判断如果需要密码或者锁屏则注册回调并且替代按钮 */
|
||
if (IsEnterLockScreen()) {
|
||
TjdUiScreenEventLockButton();
|
||
} else {
|
||
screenEventEnable = false;
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* @brief 灭屏时调用
|
||
*/
|
||
void TjdUiScreenEventDisplayOff(void)
|
||
{
|
||
/* 省电模式下不进入息屏表盘 */
|
||
if (OHOS::NativeAbility::GetInstance().GetCurSliceId() == TJD_APP_BATTERY_SAVER) {
|
||
TjdUiSetScreenState(false);
|
||
return;
|
||
}
|
||
|
||
/* 灭屏清除页面释放内存 */
|
||
if (HasAnyView()) {
|
||
/* 息屏的时候还在,那下次亮屏的时候还是会有密码或者锁屏 */
|
||
screenEventEnable = true;
|
||
HideAllView();
|
||
TjdUiScreenEventUnlockButton();
|
||
}
|
||
|
||
registerChangeToHomeEventCallback([]() {
|
||
/* 5秒后跳回主表盘,可以进行锁屏逻辑判断 */
|
||
screenEventEnable = true;
|
||
passwordEnable = true;
|
||
});
|
||
|
||
/* 显示息屏表盘 */
|
||
if (sql_setting_get_off_screen()) {
|
||
GraphicService::GetInstance()->PostGraphicEvent([]() {
|
||
tjd_driver_tp_unregister_touch_event(); // 进入熄屏关闭点击触发锁屏或密码界面
|
||
TJD::ShowScreenOffClockView();
|
||
TjdUiScreenOffEvent();
|
||
});
|
||
} else {
|
||
TjdUiSetScreenState(false);
|
||
}
|
||
}
|
||
|
||
uint32_t TjdUiSetScreenState(bool isScreenOn)
|
||
{
|
||
return isScreenOn ? tjd_action_display_lcd_on() : tjd_action_display_lcd_off();
|
||
}
|
||
|
||
void TjdUiScreenEventSuccessEvent(void)
|
||
{
|
||
TjdUiScreenEventUnlockButton();
|
||
HideAllView();
|
||
screenEventEnable = false;
|
||
}
|
||
|
||
void TjdUiScreenEventEndEvent(void)
|
||
{
|
||
HideAllView();
|
||
TjdUiScreenEventLockButton();
|
||
screenEventEnable = true;
|
||
}
|
||
|
||
static void CallOutCallBack(void)
|
||
{
|
||
g_currentTopic = TOPIC_END_NUM;
|
||
GraphicService::GetInstance()->PostGraphicEvent(
|
||
[]() { TJD::TjdUiAppCallModel::GetInstance().UngisterCallOutCallBack(CallOutCallBack); });
|
||
}
|
||
|
||
void TjdUiScreenEventInitEvent(void)
|
||
{
|
||
static std::atomic<bool> has_been_called(false);
|
||
if (has_been_called.exchange(true)) {
|
||
return;
|
||
}
|
||
if (IsEnterLockScreen()) {
|
||
TjdUiScreenEventLockButton();
|
||
}
|
||
RegisterNotifyMsgCenterEventCallback([](Topic topic){
|
||
g_currentTopic = topic;
|
||
if (TJD::IsShowScreenOffClockView()) {
|
||
GraphicService::GetInstance()->PostGraphicEvent([]() {
|
||
TJD::HideScreenOffClockView();
|
||
TjdUiScreenOffEndEvent();
|
||
});
|
||
}
|
||
});
|
||
RegisterNotifyPopOutPage([]() {
|
||
if (g_currentTopic != TJDUI_TOPIC_EVENT_HFP_INCOMMING) {
|
||
g_currentTopic = TOPIC_END_NUM;
|
||
} else {
|
||
/* 如果应用是电话的话在电话析构里才会复位g_currentTopic,注册电话结束回调 */
|
||
TJD::TjdUiAppCallModel::GetInstance().RegisterCallOutCallBack(CallOutCallBack);
|
||
}
|
||
/* 灭屏清除页面释放内存 */
|
||
if (HasAnyView()) {
|
||
/* 息屏的时候还在,那下次亮屏的时候还是会有密码或者锁屏 */
|
||
screenEventEnable = true;
|
||
HideAllView();
|
||
TjdUiScreenEventUnlockButton();
|
||
}
|
||
if (IsEnterLockScreen()) {
|
||
TjdUiScreenEventLockButton();
|
||
}
|
||
});
|
||
}
|
||
|
||
void TjdUiScreenOffEvent(void)
|
||
{
|
||
const power_display_svr_api_t *displayApi = power_display_svr_get_api();
|
||
displayApi->set_brightness(0xff * 0.4);
|
||
uapi_lcd_enter_idle_mode();
|
||
}
|
||
|
||
void TjdUiScreenOffEndEvent(void)
|
||
{
|
||
const power_display_svr_api_t *displayApi = power_display_svr_get_api();
|
||
uapi_lcd_exit_idle_mode();
|
||
displayApi->set_brightness(sql_setting_get_brightness());
|
||
|
||
if (IsEnterLockScreen()) {
|
||
TjdUiScreenEventLockButton();
|
||
tjd_driver_tp_register_touch_event(ScreenTpTouchEvent);
|
||
}
|
||
}
|
||
|
||
void TjdUiScreenSetPasswordEnable(bool value) { passwordEnable = value; } |