From 2b4d36f7d3ff96703573ebd962b7b92df769a115 Mon Sep 17 00:00:00 2001 From: huzhanjiang Date: Fri, 11 Oct 2024 18:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90toast=E3=80=91=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=B7=B1=E8=89=B2=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=9B=9E=E9=80=80=E4=B8=ADtoast=E9=A2=9C=E8=89=B2=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huzhanjiang Change-Id: I5722d34ff5fab3e2562c0f20aca4c567b172fdf5 --- .../ohos/entrance/subwindow/subwindow_ohos.cpp | 7 ++++++- adapter/ohos/entrance/ui_content_impl.cpp | 16 ++++++++++++++-- adapter/ohos/entrance/ui_content_impl.h | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp b/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp index e3e20fda0ce..247a96f4f6c 100644 --- a/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp +++ b/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp @@ -1217,7 +1217,12 @@ bool SubwindowOhos::InitToastDialogWindow(int32_t width, int32_t height, int32_t windowOption->SetFocusable(!isToast); int32_t dialogId = gToastDialogId.fetch_add(1, std::memory_order_relaxed); std::string windowName = "ARK_APP_SUBWINDOW_TOAST_DIALOG_" + std::to_string(dialogId); - dialogWindow_ = OHOS::Rosen::Window::Create(windowName, windowOption); + if (isToast) { + auto context = OHOS::AbilityRuntime::Context::GetApplicationContext(); + dialogWindow_ = OHOS::Rosen::Window::Create(windowName, windowOption, context); + } else { + dialogWindow_ = OHOS::Rosen::Window::Create(windowName, windowOption); + } CHECK_NULL_RETURN(dialogWindow_, false); dialogWindow_->SetLayoutFullScreen(true); return true; diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index 24af359178c..6219dfaac3e 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -2792,10 +2792,22 @@ void UIContentImpl::DumpInfo(const std::vector& params, std::vector } } -void UIContentImpl::UpdateDialogResourceConfiguration(RefPtr& container) +void UIContentImpl::UpdateDialogResourceConfiguration(RefPtr& container, + const std::shared_ptr& context) { auto dialogContainer = AceType::DynamicCast(container); if (dialogContainer) { + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + CHECK_NULL_VOID(context); + auto resourceManager = context->GetResourceManager(); + if (resourceManager != nullptr) { + resourceManager->GetResConfig(*resConfig); + if (resConfig->GetColorMode() == OHOS::Global::Resource::ColorMode::DARK) { + SystemProperties::SetColorMode(ColorMode::DARK); + } else { + SystemProperties::SetColorMode(ColorMode::LIGHT); + } + } auto aceResCfg = dialogContainer->GetResourceConfiguration(); aceResCfg.SetOrientation(SystemProperties::GetDeviceOrientation()); aceResCfg.SetDensity(SystemProperties::GetResolution()); @@ -2836,7 +2848,7 @@ void UIContentImpl::InitializeSubWindow(OHOS::Rosen::Window* window, bool isDial icu::Locale locale = icu::Locale::forLanguageTag(Global::I18n::LocaleConfig::GetSystemLanguage(), status); AceApplicationInfo::GetInstance().SetLocale(locale.getLanguage(), locale.getCountry(), locale.getScript(), ""); container = AceType::MakeRefPtr(instanceId_, FrontendType::DECLARATIVE_JS); - UpdateDialogResourceConfiguration(container); + UpdateDialogResourceConfiguration(container, context); } else { #ifdef NG_BUILD container = AceType::MakeRefPtr(instanceId_, frontendType, diff --git a/adapter/ohos/entrance/ui_content_impl.h b/adapter/ohos/entrance/ui_content_impl.h index ca40be5ac39..57f3e45882a 100644 --- a/adapter/ohos/entrance/ui_content_impl.h +++ b/adapter/ohos/entrance/ui_content_impl.h @@ -83,7 +83,8 @@ public: // UI content event process bool ProcessBackPressed() override; - void UpdateDialogResourceConfiguration(RefPtr& container); + void UpdateDialogResourceConfiguration(RefPtr& container, + const std::shared_ptr& context); bool ProcessPointerEvent(const std::shared_ptr& pointerEvent) override; bool ProcessPointerEventWithCallback( const std::shared_ptr& pointerEvent, const std::function& callback) override;