--- /dev/null
+#include "notification_manager.h"
+#include "wearable_log.h"
+#include "components/ui_label_button.h"
+#include "components/ui_image_view.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_scroll_view.h"
+#include "../notify/debug_output_notification/debug_output_notification_adapter.h"
+#include "../notify/debug_output_notification/debug_output_notification_itemview.h"
+#include <custom_runtime.h>
+namespace OHOS
+{
+
+ struct DebugOutputViewMapper
+ {
+ const int16_t viewId;
+ bool (DebugOutputViewEventListener::*func)(int16_t thisView);
+ };
+
+ static const DebugOutputViewMapper ViewMapper[] = {
+ {0, &DebugOutputViewEventListener::ChangeDebugOutputMainView},
+ {1, &DebugOutputViewEventListener::ChangeDebugOutputView1},
+ };
+
+ /* -------------------------------------------------------------------------- */
+ UIViewGroup *DebugGroupView{nullptr};
+ UIScrollView *DebugScrollView[sizeof(ViewMapper) / sizeof(ViewMapper[0])]{nullptr};
+ UIList *debugOutputList{nullptr};
+ DebugOutputAdapter *debugOutputAdapter{nullptr};
+ UILabel *debugOutputLabel{nullptr};
+ UILabelButton *debugOutputLabelButton{nullptr};
+ /* -------------------------------------------------------------------------- */
+
+ void DebugOutputViewEventListener::InitDebugOutputItem()
+ {
+ int index = 0;
+ debugOutputItemInfo[index++] = {0, "debugOutpt"}; // 标题:设置()
+ debugOutputItemInfo[index++] = {1, "bt_ble_connectstat"};
+ debugOutputItemInfo[index++] = {2, "cat1_runtime_status_t"};
+ debugOutputItemInfo[index++] = {3, "runtime_status_t"};
+ usedLen = index;
+ /* -------------------------------- Add data -------------------------------- */
+ for (uint8_t i = 0; i < usedLen; i++)
+ {
+ if (debugOutputAdapter)
+ debugOutputAdapter->AddListItem(debugOutputItemInfo[i]);
+ }
+ /* -------------------------------------------------------------------------- */
+ }
+
+ DebugOutputViewEventListener::DebugOutputViewEventListener()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::DebugOutputViewEventListener");
+ }
+
+ DebugOutputViewEventListener::~DebugOutputViewEventListener()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::DebugOutputViewEventListener");
+ }
+
+ DebugOutputViewEventListener &DebugOutputViewEventListener::GetInstance()
+ {
+ static DebugOutputViewEventListener instance;
+ return instance;
+ }
+
+ std::string DebugOutputViewEventListener::get_bt_runtime_status_t(void)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_bt_runtime_status_t");
+ std::string result = "bt_powerOn:" + std::to_string(uapi_dev_runtime_get_bt_powerstat()) + " ";
+ result += "bt_ble_connectstat:" + std::to_string(uapi_dev_runtime_get_ble_connect_stat()) + " ";
+ result += "bt_br_connectstat:" + std::to_string(uapi_dev_runtime_get_br_connect_stat()) + " ";
+ result += "bt_earphone_connectstat:" + std::to_string(uapi_dev_runtime_get_earphone_connect_stat()) + " ";
+ result += "android_app_connected:" + std::to_string(uapi_dev_runtime_get_android_connection_status()) + " ";
+ result += "ble_kumi_service_handler: ";
+ result += "ble_factory_service_handler: ";
+ result += "ble_alipay_service_handler: ";
+ result += "ble_hrs_service_handler: ";
+ result += "ble_hid_service_handler: ";
+ result += "ble_ancs_client_id:" + std::to_string(uapi_dev_runtime_get_ancs_clientid()) + " ";
+ result += "ad2p_service_handler: ";
+ result += "spp_service_handler: ";
+ result += "hfp_service_handler: ";
+
+ return result;
+ }
+
+ std::string DebugOutputViewEventListener::get_cat1_runtime_status_t(void)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_cat1_runtime_status_t");
+ std::string cat1_powerOn = std::to_string(uapi_dev_runtime_get_cat1_powerstat());
+ std::string volte;
+ std::string network_on = std::to_string(uapi_dev_runtime_get_cat1_networkstat());
+ std::string cat1_network_type = std::to_string(uapi_dev_runtime_get_cat1_networtype());
+ std::string sim = std::to_string(uapi_dev_runtime_get_cat1_simstat());
+ std::string signal = std::to_string(uapi_dev_runtime_get_cat1_signal());
+ std::string opera = uapi_dev_runtime_get_cat1_operator();
+ std::string pyVer = uapi_dev_runtime_get_cat1_pyver();
+ std::string modemVer = uapi_dev_runtime_get_cat1_modemver();
+ std::string result = "cat1_powerOn:" + cat1_powerOn + " " + "volte: " + "network_on:" + network_on + " " + "cat1_network_type:" + cat1_network_type + " " + "sim:" + sim + " " + "signal:" + signal + " " + "opera:" + opera + " " + "pyVer:" + pyVer + " " + "modemVer:" + modemVer + " ";
+
+ return result;
+ }
+
+ std::string DebugOutputViewEventListener::get_runtime_status_t(void)
+ {
+ std::string result;
+ return result;
+ }
+
+ bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
+ {
+ int viewIndex;
+ if (&view == debugOutputLabelButton)
+ {
+ viewIndex = GetCurViewIndex();
+ }
+ else
+ {
+ DebugOutputItemView *debugOutputItemView = static_cast<DebugOutputItemView *>(&view);
+ int viewIndex = debugOutputItemView->GetViewIndex();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "viewIndex:%d", viewIndex);
+ ChangeView(0, 1);
+ if (debugOutputLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabel is nullptr");
+ return false;
+ }
+ SetCurViewIndex(viewIndex);
+ }
+ std::string str;
+ switch (viewIndex)
+ {
+ case 1:
+ str = get_bt_runtime_status_t();
+ debugOutputLabel->SetText(str.c_str());
+ break;
+ case 2:
+ str = get_cat1_runtime_status_t();
+ debugOutputLabel->SetText(str.c_str());
+ break;
+ case 3:
+ str = get_runtime_status_t();
+ debugOutputLabel->SetText(str.c_str());
+ break;
+
+ default:
+ break;
+ }
+
+ if (debugOutputLabelButton)
+ {
+ debugOutputLabelButton->SetHeight(debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
+ debugOutputLabelButton->Invalidate();
+ }
+ debugOutputLabel->Invalidate();
+
+ return true;
+ }
+
+ bool DebugOutputViewEventListener::OnDrag(UIView &view, const DragEvent &event)
+ {
+ UNUSED(view);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::OnDrag");
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+ {
+ int16_t deltaX;
+ int16_t deltaY;
+ deltaX = event.GetDeltaX();
+ deltaY = event.GetDeltaY();
+ if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > 30)
+ {
+ X_DRAG_FLAG = true;
+ }
+ }
+ return true;
+ }
+
+ bool DebugOutputViewEventListener::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
+ {
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG)
+ {
+ if (&view == DebugGroupView)
+ {
+ NotificationManager::GetInstance()->StopNotify();
+ }
+ else if (&view == DebugScrollView[1])
+ {
+ ChangeView(1, 0);
+ }
+ X_DRAG_FLAG = false;
+ }
+ return true;
+ }
+
+ 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;
+ }
+ DebugScrollView[hideView]->SetVisible(false);
+ ClickFunc(showView);
+ DebugScrollView[showView]->SetVisible(true);
+ RootView::GetInstance()->Invalidate();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hideView:%d -> showView:%d success!!", hideView, showView);
+ }
+
+ UIScrollView *CreateDebugOutputView1(void)
+ {
+ if (DebugScrollView[1] == nullptr)
+ {
+ DebugScrollView[1] = new UIScrollView();
+ if (DebugScrollView[1] == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::DebugScrollView[0] is new fail!!");
+ return nullptr;
+ }
+ }
+ DebugScrollView[1]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+ DebugScrollView[1]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+ DebugScrollView[1]->SetStyle(STYLE_BACKGROUND_OPA, 255);
+ DebugScrollView[1]->SetHorizontalScrollState(false);
+ DebugScrollView[1]->SetTouchable(true);
+ DebugScrollView[1]->SetScrollBlankSize(70);
+ DebugScrollView[1]->SetReboundSize(35);
+ DebugScrollView[1]->SetThrowDrag(true);
+ UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(&DebugOutputViewEventListener::GetInstance());
+ if (dragListener == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dragListener is new fail!!");
+ return nullptr;
+ }
+ DebugScrollView[1]->SetOnDragListener(dragListener);
+ /* -------------------------------------------------------------------------- */
+ debugOutputLabel = new UILabel();
+ if (debugOutputLabel == nullptr)
+ {
+ if (debugOutputLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabel is new fail!!");
+ return nullptr;
+ }
+ }
+ debugOutputLabel->SetPosition(53, 120, 360, 100);
+ debugOutputLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ debugOutputLabel->SetText("123");
+ debugOutputLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ debugOutputLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
+ DebugScrollView[1]->Add(debugOutputLabel);
+ /* -------------------------------------------------------------------------- */
+ if (debugOutputLabelButton == nullptr)
+ {
+ debugOutputLabelButton = new UILabelButton();
+ if (debugOutputLabelButton == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabelButton is new fail!!");
+ return nullptr;
+ }
+ }
+ debugOutputLabelButton->SetPosition(43, debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
+ debugOutputLabelButton->Resize(380, 100);
+ debugOutputLabelButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+ debugOutputLabelButton->SetText("刷新");
+ debugOutputLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
+ debugOutputLabelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);
+ UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(&DebugOutputViewEventListener::GetInstance());
+ if (clickListener == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener is new fail!!");
+ return nullptr;
+ }
+ debugOutputLabelButton->SetOnClickListener(clickListener);
+ DebugScrollView[1]->Add(debugOutputLabelButton);
+
+ return DebugScrollView[1];
+ }
+
+ bool DebugOutputViewEventListener::ChangeDebugOutputMainView(int16_t thisView)
+ {
+ if (DebugScrollView[thisView] == nullptr)
+ {
+ DebugGroupView->Add(DebugScrollView[thisView]);
+ }
+ return true;
+ }
+
+ bool DebugOutputViewEventListener::ChangeDebugOutputView1(int16_t thisView)
+ {
+ if (DebugScrollView[thisView] == nullptr)
+ {
+ DebugScrollView[thisView] = CreateDebugOutputView1();
+ if (DebugScrollView[thisView] == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new DebugScrollView[%d] fail", thisView);
+ return false;
+ }
+ DebugGroupView->Add(DebugScrollView[thisView]);
+ }
+ return true;
+ }
+
+ void DebugOutputViewEventListener::SetCurViewIndex(int16_t viewNum)
+ {
+ curView = viewNum;
+ }
+
+ int DebugOutputViewEventListener::GetCurViewIndex(void)
+ {
+ return curView;
+ }
+
+ /*创建调试专用主窗口视图*/
+ 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, "SettingView::OnStart::DebugGroupView is new fail!!");
+ return nullptr;
+ }
+ }
+ DebugGroupView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+ UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(&DebugOutputViewEventListener::GetInstance());
+ if (dragListener == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dragListener is new fail!!");
+ return nullptr;
+ }
+ DebugGroupView->SetOnDragListener(dragListener);
+ /* -------------------------------------------------------------------------- */
+ if (DebugScrollView[0] == nullptr)
+ {
+ DebugScrollView[0] = new UIScrollView();
+ if (DebugScrollView[0] == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::DebugScrollView[0] is new fail!!");
+ return nullptr;
+ }
+ }
+ DebugScrollView[0]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+ DebugScrollView[0]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+ DebugScrollView[0]->SetStyle(STYLE_BACKGROUND_OPA, 255);
+ DebugScrollView[0]->SetHorizontalScrollState(false);
+ DebugScrollView[0]->SetTouchable(true);
+ DebugScrollView[0]->SetThrowDrag(true);
+ DebugGroupView->Add(DebugScrollView[0]);
+ /* -------------------------------------------------------------------------- */
+ if (debugOutputAdapter == nullptr)
+ {
+ debugOutputAdapter = new DebugOutputAdapter();
+ if (debugOutputAdapter == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputAdapter is new fail!!");
+ return nullptr;
+ }
+ }
+ UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(&DebugOutputViewEventListener::GetInstance());
+ if (clickListener == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener is new fail!!");
+ return nullptr;
+ }
+ debugOutputAdapter->SetItemClickListener(clickListener);
+ DebugOutputViewEventListener::GetInstance().InitDebugOutputItem();
+ /* -------------------------------------------------------------------------- */
+ if (debugOutputList == nullptr)
+ {
+ debugOutputList = new UIList(UIList::VERTICAL);
+ if (debugOutputList == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputList is new fail!!");
+ return nullptr;
+ }
+ }
+ debugOutputList->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+ debugOutputList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ debugOutputList->EnableAutoAlign(true); // 设置此列表的自动对齐状态。当滚动停止时,子视图被选中,其位置自动与预设位置对齐
+ debugOutputList->SetThrowDrag(true); // 设置手指抬起屏幕后是否继续滚动。
+ debugOutputList->SetMaxScrollDistance(1000); // 设置手指抬起屏幕后的最大滚动距离。
+ debugOutputList->SetSwipeACCLevel(800); /*设置手指抬起屏幕后的补偿距离。*/
+ debugOutputList->SetAdapter(debugOutputAdapter);
+ debugOutputList->RefreshList();
+ debugOutputList->SetReboundSize(30);
+ // debugOutputList->SetScrollBlankSize(30);
+ debugOutputList->SetRotateFactor(1.0);
+ DebugScrollView[0]->Add(debugOutputList);
+ /* -------------------------------------------------------------------------- */
+ NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDebugOutputMainView);
+ /* -------------------------------------------------------------------------- */
+ }
+ return DebugGroupView;
+ }
+
+ /*释放调试专用主窗口视图*/
+ void FreeDebugOutputMainView(void)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView");
+
+ if (DebugGroupView != nullptr)
+ {
+ DebugGroupView->RemoveAll();
+ if (DebugScrollView[0] != nullptr)
+ {
+ DebugScrollView[0]->RemoveAll();
+
+ delete debugOutputList;
+ debugOutputList = nullptr;
+
+ delete debugOutputAdapter;
+ debugOutputAdapter = nullptr;
+
+ delete DebugScrollView[0];
+ DebugScrollView[0] = nullptr;
+ }
+ if (DebugScrollView[1] != nullptr)
+ {
+ DebugScrollView[1]->RemoveAll();
+
+ delete debugOutputLabel;
+ debugOutputLabel = nullptr;
+
+ delete debugOutputLabelButton;
+ debugOutputLabelButton = nullptr;
+
+ delete DebugScrollView[1];
+ DebugScrollView[1] = nullptr;
+ }
+ RootView::GetInstance()->Remove(DebugGroupView);
+ delete DebugGroupView;
+ DebugGroupView = nullptr;
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView success!!");
+ }
+ return;
+ }
+}