diff --git a/resources/rk3568/pages/confirm.json b/resources/rk3568/pages/confirm.json index 71b69b9f2292df00ad6ee88710173c5df189a748..9cfc8183dff64825f488c1dd401fc6c9b417ef7c 100644 --- a/resources/rk3568/pages/confirm.json +++ b/resources/rk3568/pages/confirm.json @@ -10,9 +10,12 @@ "fontColor": "#000000e6", "align" : "center", "style" : "normal", - "focusedBgColor": "#f1f3f5ff", - "focusedFontColor": "#000000e6", - "focusable" : false, + "focusInfo": { + "focusedBgColor": "#f1f3f5ff", + "focusedFontColor": "#000000e6", + "focusable" : false + }, + "touchable" : false, "lineBreakMode" : "ellipsis" }, "UIImageView": { diff --git a/resources/rk3568/pages/menu.json b/resources/rk3568/pages/menu.json index 078c2747a5db46638954823dd9fa77447041c82d..df0f9beb6a8367c2dc4574b038b1b04e39fb9c29 100644 --- a/resources/rk3568/pages/menu.json +++ b/resources/rk3568/pages/menu.json @@ -24,9 +24,12 @@ "fontColor": "#000000e6", "align" : "center", "style": "normal", - "focusedBgColor": "#f1f3f5ff", - "focusedFontColor": "#000000e6", - "focusable": false, + "focusInfo": { + "focusedBgColor": "#f1f3f5ff", + "focusedFontColor": "#000000e6", + "focusable": false + }, + "touchable": false, "lineBreakMode" : "ellipsis" }, "UIImageView": { diff --git a/resources/rk3568/pages/upd.json b/resources/rk3568/pages/upd.json index ba88fe0f06d8146058534e549870de4c7c7d4f43..0d14f831afabffd211b233b3c606b00af53fc174 100644 --- a/resources/rk3568/pages/upd.json +++ b/resources/rk3568/pages/upd.json @@ -88,9 +88,12 @@ "fontColor": "#ffffffe6", "align" : "center", "style" : "normal", - "focusedBgColor": "#000000ff", - "focusedFontColor": "#ffffffe6", - "focusable": false, + "focusInfo": { + "focusedBgColor": "#000000ff", + "focusedFontColor": "#ffffffe6", + "focusable": false + }, + "touchable": false, "lineBreakMode" : "ellipsis" }, "UIImageView": { diff --git a/services/ui/control/event_listener.cpp b/services/ui/control/event_listener.cpp index 0f7ce6b8da9cd86f32c2b06bfe23319dff7c8d1b..fe148c9de884702330bc212802df016c25ab7968 100644 --- a/services/ui/control/event_listener.cpp +++ b/services/ui/control/event_listener.cpp @@ -80,31 +80,13 @@ void CallBackDecorator::CallbackWithGuard(Callback cb, OHOS::UIView &view) } } -bool LabelOnEventListener::OnClick(OHOS::UIView &view, [[maybe_unused]] const OHOS::ClickEvent &event) +bool LabelOnTouchListener::OnRelease(OHOS::UIView &view, [[maybe_unused]] const OHOS::ReleaseEvent &event) { + // wrap cb_ with CallBackDecorator, then call operator()() CallBackDecorator{cb_}(view, cb_.isAsync); return isConsumed_; } -bool LabelOnEventListener::OnPress(OHOS::UIView &view, [[maybe_unused]] const OHOS::PressEvent &event) -{ - KeyListener::SetButtonPressed(true); - return true; -} - -bool LabelOnEventListener::OnRelease(OHOS::UIView &view, [[maybe_unused]] const OHOS::ReleaseEvent &event) -{ - KeyListener::SetButtonPressed(false); - CallBackDecorator{cb_}(view, cb_.isAsync); - return isConsumed_; -} - -bool LabelOnEventListener::OnCancel(OHOS::UIView &view, [[maybe_unused]] const OHOS::CancelEvent &event) -{ - KeyListener::SetButtonPressed(false); - return true; -} - bool BtnOnEventListener::OnClick(OHOS::UIView &view, [[maybe_unused]] const OHOS::ClickEvent &event) { CallBackDecorator{cb_}(view, cb_.isAsync); @@ -188,6 +170,9 @@ bool KeyListener::ProcessPowerKey(OHOS::UIView &view, const OHOS::KeyEvent &even if (event.GetState() == OHOS::InputDevice::STATE_PRESS) { LOG(DEBUG) << "OnPress"; pView->OnClickEvent(OHOS::Point { centerX, centerY }); + } else if (event.GetState() == OHOS::InputDevice::STATE_RELEASE) { + LOG(DEBUG) << "OnRelease"; + pView->OnReleaseEvent(OHOS::Point { centerX, centerY }); } #endif return true; diff --git a/services/ui/control/event_listener.h b/services/ui/control/event_listener.h index 969dee845b82a22ac841ee57c2e5fb88b7348a7a..1fb01d969a58675258f6f4add438aa5ed8dff8cb 100644 --- a/services/ui/control/event_listener.h +++ b/services/ui/control/event_listener.h @@ -45,15 +45,12 @@ private: static std::mutex mtx_; }; -class LabelOnEventListener final : public OHOS::UIView::OnClickListener, public OHOS::UIView::OnTouchListener { +class LabelOnTouchListener final : public OHOS::UIView::OnTouchListener { public: - LabelOnEventListener(Callback cb, bool isConsumed) + LabelOnTouchListener(Callback cb, bool isConsumed) : cb_(cb), isConsumed_(isConsumed) {} - ~LabelOnEventListener() = default; - bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) override; - bool OnPress(OHOS::UIView &view, const OHOS::PressEvent &event) override; + ~LabelOnTouchListener() = default; bool OnRelease(OHOS::UIView &view, const OHOS::ReleaseEvent &event) override; - bool OnCancel(OHOS::UIView &view, const OHOS::CancelEvent &event) override; private: Callback cb_; diff --git a/services/ui/control/event_manager.cpp b/services/ui/control/event_manager.cpp index 43839c194a674047e303ee6052ee414db5cd748b..fccf36623a8430fe792d5f68cd450a0b24a7f014 100644 --- a/services/ui/control/event_manager.cpp +++ b/services/ui/control/event_manager.cpp @@ -38,21 +38,15 @@ EventManager &EventManager::GetInstance() return instance; } -void EventManager::Add(const ComInfo &viewId, std::unique_ptr listener) +void EventManager::Add(const ComInfo &viewId, std::unique_ptr listener) { if (!pgMgr_.IsValidCom(viewId)) { LOG(ERROR) << "not an valid view " << viewId; return; } auto com = pgMgr_[viewId.pageId][viewId.comId].As(); - // both click and touch listener - LabelOnEventListener *labelListener = listener.get(); - // save this listener - labelOnClickListener_.push_back(std::move(listener)); - com->SetOnClickListener(labelListener); - // this touch listener used to disable volume key when pressing button - com->SetTouchable(true); - com->SetOnTouchListener(labelListener); + labelOnTouchListener_.push_back(std::move(listener)); + com->SetOnTouchListener(labelOnTouchListener_.back().get()); } void EventManager::Add(const ComInfo &viewId, std::unique_ptr listener) @@ -94,10 +88,9 @@ void EventManager::Add(const ComInfo &viewId, EventType evt, Callback cb) switch (evt) { case EventType::CLICKEVENT: Add(viewId, std::make_unique(cb, true)); - Add(viewId, std::make_unique(cb, true)); break; case EventType::TOUCHEVENT: - Add(viewId, std::make_unique(cb, true)); + Add(viewId, std::make_unique(cb, true)); break; case EventType::DRAGEVENT: Add(viewId, std::make_unique(cb, true)); diff --git a/services/ui/control/event_manager.h b/services/ui/control/event_manager.h index 4a13f3e239b7621b00fab79926268462dd28b26c..9165b961f415596f810b05c473567f25ff842bba 100644 --- a/services/ui/control/event_manager.h +++ b/services/ui/control/event_manager.h @@ -32,7 +32,7 @@ public: EventManager(); ~EventManager() = default; static EventManager &GetInstance(); - void Add(const ComInfo &viewId, std::unique_ptr listener); + void Add(const ComInfo &viewId, std::unique_ptr listener); void Add(const ComInfo &viewId, std::unique_ptr listener); void Add(const ComInfo &viewId, std::unique_ptr listener); void Add(const ComInfo &viewId, EventType evt, Callback cb); @@ -40,7 +40,7 @@ public: private: PageManager &pgMgr_; std::unique_ptr helper_ {}; - std::vector> labelOnClickListener_; + std::vector> labelOnTouchListener_; std::vector> btnOnClickListener_; std::vector> btnOnDragListener; }; diff --git a/services/ui/updater_ui_traits.h b/services/ui/updater_ui_traits.h index 474b3285f01fe922d43ad1b3fb366cad8d10bf9d..74de8dd4fa35734e47c2686876b3d3db5bbfe434 100644 --- a/services/ui/updater_ui_traits.h +++ b/services/ui/updater_ui_traits.h @@ -77,9 +77,8 @@ DEFINE_TRAIT(UxLabelInfo, TextLabelAdapter::COMPONENT_TYPE, (std::string, fontColor), (std::string, bgColor), (std::string, style), - (std::string, focusedFontColor), - (std::string, focusedBgColor), - (bool, focusable), + (LabelFocusInfo, focusInfo), + (bool, touchable), (std::string, lineBreakMode) ); diff --git a/services/ui/view/component/img_view_adapter.cpp b/services/ui/view/component/img_view_adapter.cpp index ea9c47da2874cd8cec25aa895daad3e5762676ae..8b1b61e0db55fe7041ddc42f59871c150ef4cd83 100644 --- a/services/ui/view/component/img_view_adapter.cpp +++ b/services/ui/view/component/img_view_adapter.cpp @@ -85,6 +85,7 @@ ImgViewAdapter::ImgViewAdapter(const UxViewInfo &info) currId_ = 0; valid_ = true; this->SetAutoEnable(false); + this->SetTouchable(true); SetViewCommonInfo(info.commonInfo); LOG(DEBUG) << "dir:" << dir_ << ", imgCnt:" << imgCnt_ << ", interval:" << interval_; if (interval_ == 0) { diff --git a/services/ui/view/component/text_label_adapter.cpp b/services/ui/view/component/text_label_adapter.cpp index 5c94d9ee92ba006075a0c615e7d0695c4561901c..4f21ccadc27f58dd8248cfc666f1a45e9ec0b2ce 100644 --- a/services/ui/view/component/text_label_adapter.cpp +++ b/services/ui/view/component/text_label_adapter.cpp @@ -83,13 +83,14 @@ TextLabelAdapter::TextLabelAdapter(const UxViewInfo &info) auto bgColor = StrToColor(spec.bgColor); this->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, bgColor.full); this->SetStyle(OHOS::STYLE_BACKGROUND_OPA, bgColor.alpha); - if (spec.focusable) { + this->SetTouchable(spec.touchable); + if (spec.focusInfo.focusable) { LOG(DEBUG) << "init focus listener for " << viewId_; - InitFocus(fontColor, bgColor, StrToColor(spec.focusedFontColor), - StrToColor(spec.focusedBgColor)); + InitFocus(fontColor, bgColor, StrToColor(spec.focusInfo.focusedFontColor), + StrToColor(spec.focusInfo.focusedBgColor)); + this->SetTouchable(true); } else { this->SetFocusable(false); - this->SetTouchable(false); } if (spec.lineBreakMode == "marquee") { diff --git a/services/ui/view/component/text_label_adapter.h b/services/ui/view/component/text_label_adapter.h index caabeb31d3335da3fbdd9dcc7983c5239f59d50b..5c5ec9832a27c34189e4161f9120e6503ebc0fad 100644 --- a/services/ui/view/component/text_label_adapter.h +++ b/services/ui/view/component/text_label_adapter.h @@ -17,9 +17,16 @@ #include "component_common.h" #include "components/ui_label.h" +#include "json_visitor.h" #include "macros_updater.h" namespace Updater { +DEFINE_STRUCT_TRAIT(LabelFocusInfo, "", + (std::string, focusedFontColor), + (std::string, focusedBgColor), + (bool, focusable) +); + struct UxLabelInfo { uint8_t fontSize; std::string text; @@ -27,9 +34,8 @@ struct UxLabelInfo { std::string fontColor; std::string bgColor; std::string style; - std::string focusedFontColor; - std::string focusedBgColor; - bool focusable; + LabelFocusInfo focusInfo; + bool touchable; std::string lineBreakMode; }; struct UxViewInfo; diff --git a/test/unittest/test_data/ui/layout/all.json b/test/unittest/test_data/ui/layout/all.json index 36f327d459be9e44a84b05a7cb6a9d3ba83f6267..58dc3182a1c919492e1064e41bd7fbcc67198de6 100644 --- a/test/unittest/test_data/ui/layout/all.json +++ b/test/unittest/test_data/ui/layout/all.json @@ -16,9 +16,12 @@ "bgColor" : "#ffffffff", "fontColor" : "#ffffffff", "style" : "normal", - "focusedBgColor" : "#ffffffff", - "focusedFontColor" : "#ffffffff", - "focusable" : false, + "focusInfo" : { + "focusedBgColor" : "#ffffffff", + "focusedFontColor" : "#ffffffff", + "focusable" : false + }, + "touchable" : false, "lineBreakMode" : "ellipsis" }, { diff --git a/test/unittest/test_data/ui/layout/commonInvalid.json b/test/unittest/test_data/ui/layout/commonInvalid.json index 883862c0178f2b06f58bd1c993f9c2046d1988f6..722bf9f46f5bc3a903de6175e8eb21178a5f84db 100644 --- a/test/unittest/test_data/ui/layout/commonInvalid.json +++ b/test/unittest/test_data/ui/layout/commonInvalid.json @@ -10,9 +10,12 @@ "fontColor" : "#ffffffff", "align" : "center", "style" : "normal", - "focusedBgColor" : "#000000ff", - "focusedFontColor" : "#ffffffff", - "focusable" : false, + "focusInfo" : { + "focusedBgColor" : "#000000ff", + "focusedFontColor" : "#ffffffff", + "focusable" : false + }, + "touchable" : false, "lineBreakMode" : "ellipsis" } }, diff --git a/test/unittest/test_data/ui/layout/label.json b/test/unittest/test_data/ui/layout/label.json index 0e586368ec20f69db718f5cb3ae2ab513f5bbd64..787d9c9ab5efadcc8f1396d7aca7dd5a6b605a6e 100644 --- a/test/unittest/test_data/ui/layout/label.json +++ b/test/unittest/test_data/ui/layout/label.json @@ -17,9 +17,12 @@ "bgColor" : "#ffffffff", "fontColor" : "#ffffffff", "style" : "normal", - "focusedBgColor" : "#ffffffff", - "focusedFontColor" : "#ffffffff", - "focusable" : false, + "focusInfo" : { + "focusedBgColor" : "#ffffffff", + "focusedFontColor" : "#ffffffff", + "focusable" : false + }, + "touchable" : false, "lineBreakMode" : "ellipsis" } ] diff --git a/test/unittest/test_data/ui/layout/menu.json b/test/unittest/test_data/ui/layout/menu.json index c202d46c1d658b4153c3fb77527e9445a7528dfb..83cb40c4530b13ec38bed88cf7e3f952bfc678e2 100644 --- a/test/unittest/test_data/ui/layout/menu.json +++ b/test/unittest/test_data/ui/layout/menu.json @@ -10,9 +10,12 @@ "fontColor" : "#ffffffff", "align" : "center", "style" : "normal", - "focusedBgColor" : "#000000ff", - "focusedFontColor" : "#ffffffff", - "focusable" : false, + "focusInfo" : { + "focusedBgColor" : "#000000ff", + "focusedFontColor" : "#ffffffff", + "focusable" : false + }, + "touchable" : false, "lineBreakMode" : "ellipsis" } }, diff --git a/test/unittest/test_data/ui/layout/typeInvalid.json b/test/unittest/test_data/ui/layout/typeInvalid.json index 1e5dfdaa4397c12ef4c2e9256261340e248c9f93..637732e8c9175ad7494014603236b77d37b97e7f 100644 --- a/test/unittest/test_data/ui/layout/typeInvalid.json +++ b/test/unittest/test_data/ui/layout/typeInvalid.json @@ -10,9 +10,12 @@ "fontColor" : "#ffffffff", "align" : "center", "style" : "normal", - "focusedBgColor" : "#000000ff", - "focusedFontColor" : "#ffffffff", - "focusable" : false, + "focusInfo" : { + "focusedBgColor" : "#000000ff", + "focusedFontColor" : "#ffffffff", + "focusable" : false + }, + "touchable" : false, "lineBreakMode" : "ellipsis" } }, diff --git a/test/unittest/updater_ui_test/view/ui_component_unittest.cpp b/test/unittest/updater_ui_test/view/ui_component_unittest.cpp index 69de97b8dc0a09abc4b4ba02abceced745a99ff6..0b85ae39098f7bbd948d5ed37df7c5c7363c4148 100644 --- a/test/unittest/updater_ui_test/view/ui_component_unittest.cpp +++ b/test/unittest/updater_ui_test/view/ui_component_unittest.cpp @@ -361,7 +361,7 @@ HWTEST_F(UpdaterUiComponentUnitTest, test_text_label_adapter_constructor, TestSi { constexpr auto labelText = "hello"; UxLabelInfo specInfo {100, "hello", "center", "#000000ff", "#000000ff", "normal", - "#000000ff", "#000000ff", false, "ellipsis"}; + {"#000000ff", "#000000ff", false}, false, "ellipsis"}; UxViewCommonInfo commonInfo {0, 0, 0, 0, "id", "UILabel", false}; UxViewInfo info {commonInfo, specInfo}; TextLabelAdapter textLabel {info}; @@ -381,7 +381,7 @@ HWTEST_F(UpdaterUiComponentUnitTest, test_text_label_adapter_set_text, TestSize. { TextLabelAdapter textLabel {UxViewInfo {{0, 0, 0, 0, "id", "UILabel", false}, UxLabelInfo {255, "", "", "#000000ff", "#000000ff", "normal", - "#000000ff", "#000000ff", false, "ellipsis"}}}; + {"#000000ff", "#000000ff", false}, false, "ellipsis"}}}; constexpr auto testString = "test text"; textLabel.SetText(testString); EXPECT_STREQ(textLabel.GetText(), testString); diff --git a/test/unittest/updater_ui_test/view/ui_layout_unittest.cpp b/test/unittest/updater_ui_test/view/ui_layout_unittest.cpp index 8717fe4a6cb3ae5de0dfd414ec036590098417c6..ec4ee4e5bfc59ff884b7c0b414aceaf0ae3fe33a 100644 --- a/test/unittest/updater_ui_test/view/ui_layout_unittest.cpp +++ b/test/unittest/updater_ui_test/view/ui_layout_unittest.cpp @@ -109,8 +109,9 @@ HWTEST_F(UpdaterUiLayoutParserUnitTest, test_label_parser, TestSize.Level0) "#ffffffff", "#ffffffff", "normal", + {"#ffffffff", "#ffffffff", - "#ffffffff", + false}, false, "ellipsis" } }; @@ -156,8 +157,9 @@ HWTEST_F(UpdaterUiLayoutParserUnitTest, test_all, TestSize.Level1) "#ffffffff", "#ffffffff", "normal", + {"#ffffffff", "#ffffffff", - "#ffffffff", + false}, false, "ellipsis" } }; @@ -189,8 +191,9 @@ HWTEST_F(UpdaterUiLayoutParserUnitTest, test_all_default, TestSize.Level0) "#ffffffff", "#000000ff", "normal", - "#ffffffff", + {"#ffffffff", "#000000ff", + false}, false, "ellipsis" } }; diff --git a/test/unittest/updater_ui_test/view/ui_page_manager_unittest.cpp b/test/unittest/updater_ui_test/view/ui_page_manager_unittest.cpp index e2c6c4c0f18232fdb6c8326acf885d45736ea6ca..5d1eca4de760d8566179917a7f2874ee0b86a5ee 100644 --- a/test/unittest/updater_ui_test/view/ui_page_manager_unittest.cpp +++ b/test/unittest/updater_ui_test/view/ui_page_manager_unittest.cpp @@ -75,7 +75,7 @@ const std::vector UpdaterUiPageManagerUnitTest::pageInfos_ = { 300, 400, 600, 200, "label_id_0", "UILabel", true}, UxLabelInfo { 50, "this is page1", "center", "#ff0000ff", "#000000ff", "normal", - "#ff0000ff", "#000000ff", false, "ellipsis"}}, + {"#ff0000ff", "#000000ff", false}, false, "ellipsis"}}, UxViewInfo { UxViewCommonInfo { 300, 700, 400, 400, "image_view", "UIImageView", false}, @@ -92,7 +92,7 @@ const std::vector UpdaterUiPageManagerUnitTest::pageInfos_ = { 300, 400, 600, 200, "label_id_0", "UILabel", true}, UxLabelInfo { 50, "this is page2", "center", "#00ff00ff", "#000000ff", "normal", - "#00ff00ff", "#000000ff", false, "ellipsis"}}, + {"#00ff00ff", "#000000ff", false}, false, "ellipsis"}}, UxViewInfo { UxViewCommonInfo { 300, 700, 400, 400, "image_view", "UIImageView", false}, @@ -108,7 +108,7 @@ const std::vector UpdaterUiPageManagerUnitTest::pageInfos_ = { 300, 400, 600, 200, "label_id_0", "UILabel", true}, UxLabelInfo { 50, "this is page2", "center", "#0000ffff", "#000000ff", "normal", - "#0000ffff", "#000000ff", false, "ellipsis"}}, + {"#0000ffff", "#000000ff", false}, false, "ellipsis"}}, UxViewInfo { UxViewCommonInfo { 300, 700, 400, 400, "image_view", "UIImageView", false}, @@ -146,7 +146,7 @@ HWTEST_F(UpdaterUiPageManagerUnitTest, test_page_manager_init_failed, TestSize.L 300, 400, 600, 200, "label_id_0", "UILabel", true}, UxLabelInfo { 50, "this is page1", "center", "#ff0ff", "#0", "normal", - "#ff0ff", "#0", false, "ellipsis"}}}, {}} + {"#ff0ff", "#0", false}, false, "ellipsis"}}}, {}} }; EXPECT_FALSE(GetInstance().Init(pageInfo, "page1")); } @@ -161,7 +161,7 @@ HWTEST_F(UpdaterUiPageManagerUnitTest, test_page_manager_init_failed, TestSize.L 300, 400, 600, 200, "label_id_0", "UILabel", true}, UxLabelInfo { 50, "this is page1", "center", "#000000ff", "#000000ff", "normal", - "#000000ff", "#000000ff", false, "ellipsis"}}}, + {"#000000ff", "#000000ff", false}, false, "ellipsis"}}}, {{UxSubPageInfo {"", "#000000ff", {"label_id_0"}}}}}}; EXPECT_FALSE(GetInstance().Init(pageInfo, "page1"));