-#include "lcdtest/LcdTestView.h"
-#include "UiConfig.h"
+#include "components/ui_scroll_view.h"
#include "components/root_view.h"
#include "common/screen.h"
-#include "wearable_log.h"
+#include "UiConfig.h"
+#include "gfx_utils/style.h"
+#include "graphic_config.h"
+#include "View.h"
-namespace OHOS {
-static void LcdTestTick(void* arg)
-{
- LcdTestView* v = reinterpret_cast<LcdTestView*>(arg);
- if (v != nullptr) {
- v->SetLCDColor(-1);
- }
-}
+// 全局变量 - 最简单的方式
+static OHOS::UIScrollView* g_lcd_test_view = nullptr;
+static OHOS::UIView* g_current_view = nullptr;
-LcdTestView* LcdTestView::self_{nullptr};
-LcdTestView::LcdTestView()
+#ifdef __cplusplus
+#if __cplusplus
+extern "C"
{
- self_ = this;
-}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
-LcdTestView::~LcdTestView()
+/**
+ * @brief 启动LCD测试视图
+ */
+void start_lcd_test_view(void)
{
- ClearAll();
- self_ = nullptr;
-}
-
-LcdTestView* LcdTestView::GetInstance()
-{
- return self_;
-}
-
-void LcdTestView::ClearAll()
-{
- if (timer_ != NULL) {
- osTimerStop(timer_);
- osTimerDelete(timer_);
- timer_ = NULL;
- }
- if (overlay != nullptr) {
- if (group != nullptr) {
- group->Remove(overlay);
- }
- delete overlay;
- overlay = nullptr;
- }
- if (group != nullptr) {
- group->RemoveAll();
- delete group;
- group = nullptr;
+ printf("=== 启动LCD测试 ===\n");
+
+ OHOS::RootView* rootView = OHOS::RootView::GetInstance();
+ if (rootView == nullptr) {
+ printf("ERROR: RootView not initialized\n");
+ return;
}
-}
-
-UIViewGroup* LcdTestView::InitShowUpView()
-{
- if (group != nullptr) {
- return group;
+
+ // 保存当前显示的view,然后切换到LCD测试view
+ g_current_view = rootView->GetChildrenHead();
+ if (g_current_view != nullptr) {
+ // 先从rootView中移除,但不删除
+ rootView->Remove(g_current_view);
+ printf("Saved and removed current view for later restore\n");
}
- group = new UIViewGroup();
- if (group == nullptr) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LcdTestView group new fail");
- return nullptr;
+
+ // 创建ScrollView用于LCD测试
+ g_lcd_test_view = new OHOS::UIScrollView();
+ if (g_lcd_test_view == nullptr) {
+ printf("ERROR: Failed to create LCD test view\n");
+ return;
}
- group->SetPosition(0, 0);
- group->SetWidth(HORIZONTAL_RESOLUTION);
- group->SetHeight(VERTICAL_RESOLUTION);
- group->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
- group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+
+ // 设置全屏红色
+ printf("fac:LCD test red\n");
+ g_lcd_test_view->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
+ g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
+ g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xffff0000); // 红色
+ g_lcd_test_view->SetTouchable(false);
+ g_lcd_test_view->SetDraggable(false);
+ g_lcd_test_view->SetVisible(true);
+
+ // 添加LCD测试view到根视图
+ rootView->Add(g_lcd_test_view);
+ rootView->Invalidate();
- overlay = new UIImageView();
- if (overlay != nullptr) {
- overlay->SetPosition(0, 0, group->GetWidth(), group->GetHeight());
- overlay->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
- overlay->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
- overlay->SetVisible(true);
- group->Add(overlay);
- }
- return group;
+ printf("LCD test started - RED background\n");
}
-void LcdTestView::StartAnimation()
+/**
+ * @brief 停止LCD测试视图
+ */
+void stop_lcd_test_view(void)
{
- if (timer_ == NULL) {
- timer_ = osTimerNew((osTimerFunc_t)LcdTestTick, osTimerPeriodic, this, NULL);
- }
- colorIndex_ = 0;
- if (timer_ != NULL) {
- osTimerStart(timer_, 1000);
+ printf("=== 停止LCD测试 ===\n");
+
+ OHOS::RootView* rootView = OHOS::RootView::GetInstance();
+ if (rootView != nullptr) {
+ // 删除LCD测试view
+ if (g_lcd_test_view != nullptr) {
+ rootView->Remove(g_lcd_test_view);
+ delete g_lcd_test_view;
+ g_lcd_test_view = nullptr;
+ printf("LCD test view removed\n");
+ }
+
+ // 恢复原来的view
+ if (g_current_view != nullptr) {
+ printf("Attempting to restore view at address: %p\n", g_current_view);
+
+ // 检查view是否还有效
+ if (g_current_view->GetParent() == nullptr) {
+ rootView->Add(g_current_view);
+ rootView->Invalidate();
+ printf("Original view restored successfully\n");
+ } else {
+ printf("Warning: Original view still has parent, cannot restore\n");
+ }
+ g_current_view = nullptr;
+ } else {
+ printf("No original view to restore\n");
+ }
}
}
-void LcdTestView::SetLCDColor(int color)
+/**
+ * @brief 设置LCD测试颜色
+ * @param color 颜色索引 (0-5): 0=绿色, 1=蓝色, 2=黄色, 3=红色, 4=白色, 5=黑色
+ */
+void set_lcd_test_color(int color)
{
- if (group == nullptr) {
+ if (g_lcd_test_view == nullptr) {
+ printf("LCD test not started\n");
return;
}
- if (color < 0) {
- color = colorIndex_++;
- }
- switch (color % 6) {
- case 0: group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); break;
- case 1: group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); break;
- case 2: group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full); break;
- case 3: group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); break;
- case 4: group->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); break;
- case 5: group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); break;
- default: break;
- }
- RootView::GetInstance()->Invalidate();
-}
+
-void LcdTestView::OnStart()
-{
- UIViewGroup* v = InitShowUpView();
- if (v != nullptr) {
- AddViewToRootContainer(v);
- StartAnimation();
+ switch (color)
+ {
+ case 0:
+ printf("fac:LCD test green\n");
+ g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Green().full);
+ break;
+ case 1:
+ printf("fac:LCD test blue\n");
+ g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Blue().full);
+ break;
+ case 2:
+ g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Yellow().full);
+ break;
+ case 3:
+ printf("fac:LCD test red\n");
+ g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Red().full);
+ break;
+ case 4:
+ g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::White().full);
+ break;
+ case 5:
+ g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Black().full);
+ break;
+ default:
+ break;
}
+ OHOS::RootView::GetInstance()->Invalidate();
}
-} // namespace OHOS
-
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
\ No newline at end of file