{TOPIC_EVENT_BLOODOXYGEN_UPDATA, PRIORITY_TWO},
{TOPIC_EVENT_SPORT_DISTANCE, PRIORITY_TWO},
{TOPIC_EVENT_LOCATION, PRIORITY_TWO},
+ {TOPIC_EVENT_DEBUGOUTPUT,PRIORITY_ONE},//开发调试专用窗口
};
bool g_pressFlag = false;
MsgCenterSubscribeTopic(TOPIC_EVENT_BLOODOXYGEN_UPDATA);
MsgCenterSubscribeTopic(TOPIC_EVENT_SPORT_DISTANCE);
MsgCenterSubscribeTopic(TOPIC_EVENT_LOCATION);
+ MsgCenterSubscribeTopic(TOPIC_EVENT_DEBUGOUTPUT);
}
static OHOS::UIViewGroup* ShowAlarmNotify(void)
return OHOS::PhoneMsgView::CreatePhoneMsgView();
}
+static OHOS::UIViewGroup* showDebugOutputNotify(void)
+{
+ return OHOS::CreateDebugOutputMainView();
+}
+
void MsgCenterNotifyAlarmProc(const Topic topic, Request* req)
{
unused(req);
// SendMsgToUIService(UI_UPDATE_GOAL, 0, nullptr, 0);
}
+void MsgCenterNotifyDebugOutProc(const Topic topic, Request* req)
+{
+ unused(req);
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyDebugOutProc !");
+ if (CheckPriority(topic))
+ {
+ NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE);
+ NotificationManager::GetInstance()->ShowNotify(showDebugOutputNotify, (uint16_t)topic, true);
+ }
+}
+
+
/* 订阅事件通知逻辑可定制 */
static MsgCenterNotifyTable g_msgCenterNotifyTable[] = {
{TOPIC_EVENT_ALARM_RING, MsgCenterNotifyAlarmProc},
{TOPIC_EVENT_BLOODOXYGEN_UPDATA, MsgCenterNotifyBloodOxygenProc},
{TOPIC_EVENT_SPORT_DISTANCE, MsgCenterNotifyDistanceProc},
{TOPIC_EVENT_LOCATION, MsgCenterNotifyLocationProc},
+ {TOPIC_EVENT_DEBUGOUTPUT, MsgCenterNotifyDebugOutProc},
};
static MsgCenterNotifyTable *MsgCenterGetNotifyTblCb(uint8_t idx)
--- /dev/null
+#include "notify/debug_output_notification/debug_output_notification.h"
+#include "notification_manager.h"
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+#include "broadcast_feature.h"
+#include "broadcast_service.h"
+#include "components/ui_scroll_view.h"
+#include "components/ui_toggle_button.h"
+#include "graphic_service.h"
+#include "custom_utils.h"
+#include <custom_runtime.h>
+#include "events/key_event.h"
+#include "common/key_code.h"
+#include "dock/input_device.h"
+
+/* 避免依赖深路径头文件:声明所需 C 接口,保持 C 链接名 */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+#include "ln_api.h"
+ char *uapi_ln_get_device_id(void);
+ char *uapi_ln_get_device_iccid(void);
+ char *uapi_ln_get_device_model(void);
+ char *uapi_ln_get_device_version(void);
+#ifdef __cplusplus
+}
+#endif
+
+namespace OHOS
+{
+ struct DebugOutputViewMapper
+ {
+ const int16_t viewId;
+ bool (DebugOutputViewEventListener::*func)(int16_t thisView);
+ };
+
+ static const DebugOutputViewMapper ViewMapper[] = {};
+
+ /* -------------------------------------------------------------------------- */
+ UIViewGroup *DebugGroupView{nullptr};
+ UILabel *debugOutputtitleLabel{nullptr};
+ UILabel *debugOutputLabel{nullptr};
+ /* -------------------------------------------------------------------------- */
+ DebugOutputViewEventListener::DebugOutputViewEventListener() {}
+
+ DebugOutputViewEventListener::~DebugOutputViewEventListener() {}
+
+ DebugOutputViewEventListener &DebugOutputViewEventListener::GetInstance()
+ {
+ static DebugOutputViewEventListener instance;
+ return instance;
+ }
+
+ // 增加按键事件
+ bool DebugOutputViewEventListener::OnKeyAct(UIView &view, const KeyEvent &event)
+ {
+ uint16_t keyID = event.GetKeyId();
+ uint16_t keyState = event.GetState();
+ int screenState = uapi_get_screen_state();
+
+ // 按键事件日志
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyAct: keyID=%d, keyState=%d, screenState=%d", keyID, keyState, screenState);
+
+ uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();
+ if (notifyId == TOPIC_EVENT_DEBUGOUTPUT && keyState == InputDevice::STATE_PRESS && uapi_get_screen_state() == 0)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TOPIC_EVENT_DEBUGOUTPUT");
+ /* 使用 PRESS 触发,保证大多数机型都能响应 */
+ switch (keyID)
+ {
+ case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC):
+ NotificationManager::GetInstance()->StopNotify();
+ return true;
+ case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_VENDOR_UP):
+ {
+ static constexpr int16_t kMaxDebugViews = 1; /* 视图页数,如扩展多页可调整 */
+ int16_t idx = OHOS::DebugOutputViewEventListener::GetInstance().GetCurViewIndex();
+ idx = (idx + 1) % kMaxDebugViews;
+ OHOS::DebugOutputViewEventListener::GetInstance().SetCurViewIndex(idx);
+ OHOS::DebugOutputViewEventListener::GetInstance().UpdateView();
+ return true;
+ }
+ case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_VENDOR_DOWN):
+ {
+ static constexpr int16_t kMaxDebugViews = 1;
+ int16_t idx = OHOS::DebugOutputViewEventListener::GetInstance().GetCurViewIndex();
+ idx = (idx - 1 < 0) ? (kMaxDebugViews - 1) : (idx - 1);
+ OHOS::DebugOutputViewEventListener::GetInstance().SetCurViewIndex(idx);
+ OHOS::DebugOutputViewEventListener::GetInstance().UpdateView();
+ return true;
+ }
+ default:
+ break;
+ }
+ }
+ }
+
+ bool DebugOutputViewEventListener::ClickFunc(int16_t interface)
+ {
+ int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]);
+ for (int i = 0; i < funcSize; i++)
+ {
+ if (interface == ViewMapper[i].viewId)
+ {
+ bool jug = (this->*(ViewMapper[i].func))(interface);
+ if (jug == false)
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+ bool DebugOutputViewEventListener::CheckViewParam(int16_t hideView, int16_t showView)
+ {
+ int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]);
+ if (showView < 0 || showView > funcSize)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showView err.");
+ return false;
+ }
+
+ if (hideView < 0 || hideView > funcSize)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hideView err.");
+ return false;
+ }
+
+ return true;
+ }
+ void DebugOutputViewEventListener::ChangeView(int16_t hideView, int16_t showView)
+ {
+ if (!CheckViewParam(hideView, showView))
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckViewParam failed.");
+ return;
+ }
+ ClickFunc(showView);
+ RootView::GetInstance()->Invalidate();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hideView:%d -> showView:%d success!!", hideView, showView);
+ }
+
+ void DebugOutputViewEventListener::SetCurViewIndex(int16_t viewNum)
+ {
+ curViewIndex = viewNum;
+ }
+
+ int DebugOutputViewEventListener::GetCurViewIndex(void)
+ {
+ return curViewIndex;
+ }
+
+ std::string DebugOutputViewEventListener::GetLeiNiaoDeviceInfo(void)
+ {
+ std::string deviceInfo = "设备号:" + std::string(uapi_ln_get_device_id()) + "\n";
+ deviceInfo += "设备iccid:" + std::string(uapi_ln_get_device_iccid()) + "\n";
+ deviceInfo += "设备version:" + std::string(uapi_ln_get_device_version()) + "\n";
+ deviceInfo += "设备model:" + std::string(uapi_ln_get_device_model()) + "\n";
+ return deviceInfo;
+ }
+
+ void DebugOutputViewEventListener::UpdateView(void)
+ {
+ if (debugOutputLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabel is nullptr");
+ return;
+ }
+ if (debugOutputtitleLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputtitleLabel is nullptr");
+ return;
+ }
+ switch (GetCurViewIndex())
+ {
+ case 0:
+ debugOutputtitleLabel->SetText("雷鸟设备信息");
+ debugOutputLabel->SetText(DebugOutputViewEventListener::GetInstance().GetLeiNiaoDeviceInfo().c_str());
+ break;
+ default:
+ debugOutputtitleLabel->SetText("无标题信息");
+ debugOutputLabel->SetText("无内容信息");
+ break;
+ }
+ debugOutputtitleLabel->Invalidate();
+ debugOutputLabel->Invalidate();
+ return;
+ }
+
+ /*创建调试专用主窗口视图*/
+ UIViewGroup *CreateDebugOutputMainView(void)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateDebugOutputMainView");
+ if (DebugGroupView == nullptr)
+ {
+ if (DebugGroupView == nullptr)
+ {
+ DebugGroupView = new UIViewGroup();
+ if (DebugGroupView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugGroupView is new fail!!");
+ return nullptr;
+ }
+ }
+ DebugGroupView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+ /* -------------------------------------------------------------------------- */
+ if (debugOutputtitleLabel == nullptr)
+ {
+ debugOutputtitleLabel = new UILabel();
+ if (debugOutputtitleLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " new debugOutputtitleLabel fail");
+ return nullptr;
+ }
+ debugOutputtitleLabel->SetPosition(80, 40, 200, 35);
+ debugOutputtitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ debugOutputtitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ debugOutputtitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ debugOutputtitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ DebugGroupView->Add(debugOutputtitleLabel);
+ }
+ /* -------------------------------------------------------------------------- */
+ if (debugOutputLabel == nullptr)
+ {
+ debugOutputLabel = new UILabel();
+ if (debugOutputLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new debugOutputLabel fail");
+ return nullptr;
+ }
+ debugOutputLabel->SetPosition(30, 70, 300, 70);
+ debugOutputLabel->SetText(DebugOutputViewEventListener::GetInstance().GetLeiNiaoDeviceInfo().c_str());
+ debugOutputLabel->SetStyle(STYLE_TEXT_FONT, 24);
+ debugOutputLabel->SetStyle(STYLE_LINE_HEIGHT, 24);
+ debugOutputLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ debugOutputLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24);
+ DebugGroupView->Add(debugOutputLabel);
+ }
+ RootView::GetInstance()->SetOnKeyActListener((OHOS::RootView::OnKeyActListener *)&DebugOutputViewEventListener::GetInstance());
+ DebugOutputViewEventListener::GetInstance().UpdateView();
+ /* -------------------------------------------------------------------------- */
+ NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDebugOutputMainView);
+ /* -------------------------------------------------------------------------- */
+ }
+ return DebugGroupView;
+ }
+
+ /*释放调试专用主窗口视图*/
+ void FreeDebugOutputMainView(void)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView");
+ if (DebugGroupView != nullptr)
+ {
+ DebugGroupView->RemoveAll();
+
+ delete debugOutputtitleLabel;
+ debugOutputtitleLabel = nullptr;
+ delete debugOutputLabel;
+ debugOutputLabel = nullptr;
+
+ RootView::GetInstance()->Remove(DebugGroupView);
+ delete DebugGroupView;
+ DebugGroupView = nullptr;
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView success!!");
+ }
+ return;
+ }
+}