Direction and dpi update resConfig

Signed-off-by: fangzhiyuan <fangzhiyuan5@huawei.com>
Change-Id: I1ba506a54958bff15e3c8c4606c61d17351115fc
This commit is contained in:
fangzhiyuan 2024-09-27 16:42:13 +08:00 committed by fangzhiyuan
parent 0cd4e15c59
commit cac01b2596
8 changed files with 100 additions and 10 deletions

View File

@ -44,6 +44,7 @@
#include "adapter/ohos/osal/resource_adapter_impl_v2.h"
#include "adapter/ohos/osal/system_bar_style_ohos.h"
#include "adapter/ohos/osal/view_data_wrap_ohos.h"
#include "adapter/ohos/osal/window_utils.h"
#include "base/i18n/localization.h"
#include "base/json/json_util.h"
#include "base/log/ace_trace.h"
@ -981,6 +982,7 @@ void AceContainer::InitializeCallback()
CHECK_NULL_VOID(container);
auto aceContainer = DynamicCast<AceContainer>(container);
CHECK_NULL_VOID(aceContainer);
aceContainer->UpdateResourceDensity(density);
aceContainer->NotifyDensityUpdate();
}
};
@ -3296,4 +3298,25 @@ void AceContainer::RemoveWatchSystemParameter()
SystemProperties::RemoveWatchSystemParameter(
ENABLE_PERFORMANCE_MONITOR_KEY, this, SystemProperties::EnableSystemParameterPerformanceMonitorCallback);
}
void AceContainer::UpdateResourceOrientation(int32_t orientation)
{
DeviceOrientation newOrientation = WindowUtils::GetDeviceOrientation(orientation);
auto resConfig = GetResourceConfiguration();
resConfig.SetOrientation(newOrientation);
if (SystemProperties::GetResourceDecoupling()) {
ResourceManager::GetInstance().UpdateResourceConfig(resConfig, false);
}
SetResourceConfiguration(resConfig);
}
void AceContainer::UpdateResourceDensity(double density)
{
auto resConfig = GetResourceConfiguration();
resConfig.SetDensity(density);
if (SystemProperties::GetResourceDecoupling()) {
ResourceManager::GetInstance().UpdateResourceConfig(resConfig, false);
}
SetResourceConfiguration(resConfig);
}
} // namespace OHOS::Ace::Platform

View File

@ -685,6 +685,8 @@ public:
return paramUie_;
}
void UpdateResourceOrientation(int32_t orientation);
void UpdateResourceDensity(double density);
private:
virtual bool MaybeRelease() override;
void InitializeFrontend();

View File

@ -184,16 +184,16 @@ void AddResConfigInfo(
aceResCfg.SetAppHasDarkRes(resConfig->GetAppDarkRes());
auto preferredLocaleInfo = resConfig->GetPreferredLocaleInfo();
if (preferredLocaleInfo != nullptr) {
std::string preferredlanguage = preferredLocaleInfo->getLanguage();
std::string preferredLanguage = preferredLocaleInfo->getLanguage();
std::string script = preferredLocaleInfo->getScript();
std::string country = preferredLocaleInfo->getCountry();
if (!script.empty()) {
preferredlanguage += "-" + script;
preferredLanguage += "-" + script;
}
if (!country.empty()) {
preferredlanguage += "-" + country;
preferredLanguage += "-" + country;
}
aceResCfg.SetPreferredLanguage(preferredlanguage);
aceResCfg.SetPreferredLanguage(preferredLanguage);
}
}
@ -2485,10 +2485,18 @@ void UIContentImpl::UpdateViewportConfigWithAnimation(const ViewportConfig& conf
CHECK_NULL_VOID(aceView);
Platform::AceViewOhos::SetViewportMetrics(aceView, modifyConfig); // update density into pipeline
};
auto updateDeviceOrientationTask = [container, modifyConfig, reason]() {
if (reason == OHOS::Rosen::WindowSizeChangeReason::ROTATION) {
container->UpdateResourceOrientation(modifyConfig.Orientation());
}
};
if (taskExecutor->WillRunOnCurrentThread(TaskExecutor::TaskType::UI)) {
updateDensityTask(); // ensure density has been updated before load first page
updateDeviceOrientationTask();
} else {
taskExecutor->PostTask(std::move(updateDensityTask), TaskExecutor::TaskType::UI, "ArkUIUpdateDensity");
taskExecutor->PostTask(
std::move(updateDeviceOrientationTask), TaskExecutor::TaskType::UI, "ArkUIDeviceOrientation");
}
RefPtr<NG::SafeAreaManager> safeAreaManager = nullptr;
auto pipelineContext = container->GetPipelineContext();

View File

@ -79,6 +79,7 @@ template("ace_osal_ohos_source_set") {
"trace_id_impl.cpp",
"view_data_wrap_ohos.cpp",
"want_wrap_ohos.cpp",
"window_utils.cpp",
]
external_deps += [

View File

@ -24,6 +24,7 @@
#include "parameters.h"
#include "adapter/ohos/entrance/ace_container.h"
#include "adapter/ohos/osal/window_utils.h"
#include "core/common/ace_application_info.h"
#ifdef OHOS_STANDARD_SYSTEM
#include "systemcapability.h"
@ -64,8 +65,6 @@ constexpr char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_anima
#endif
constexpr int32_t CONVERT_ASTC_THRESHOLD = 2;
using RsOrientation = Rosen::DisplayOrientation;
bool IsOpIncEnabled()
{
return (system::GetParameter(IS_OPINC_ENABLE, "2") == "2");
@ -585,10 +584,7 @@ void SystemProperties::InitDeviceInfo(
ACE_WEAK_SYM void SystemProperties::SetDeviceOrientation(int32_t orientation)
{
int32_t newOrientation = ((orientation == static_cast<int32_t>(RsOrientation::LANDSCAPE)) ||
(orientation == static_cast<int32_t>(RsOrientation::LANDSCAPE_INVERTED)))
? ORIENTATION_LANDSCAPE
: ORIENTATION_PORTRAIT;
auto newOrientation = static_cast<int32_t>(WindowUtils::GetDeviceOrientation(orientation));
if (newOrientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
Swap(deviceWidth_, deviceHeight_);
orientation_ = DeviceOrientation::PORTRAIT;

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "adapter/ohos/osal/window_utils.h"
#include "dm/dm_common.h"
namespace OHOS::Ace {
DeviceOrientation WindowUtils::GetDeviceOrientation(int32_t windowOrientation)
{
DeviceOrientation newOrientation =
((windowOrientation == static_cast<int32_t>(Rosen::DisplayOrientation::LANDSCAPE)) ||
(windowOrientation == static_cast<int32_t>(Rosen::DisplayOrientation::LANDSCAPE_INVERTED)))
? DeviceOrientation::LANDSCAPE
: DeviceOrientation::PORTRAIT;
return newOrientation;
}
} // namespace OHOS::Ace

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_ACE_ADAPTER_OHOS_OSAL_WINDOW_UTILS_H
#define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_WINDOW_UTILS_H
#include "base/utils/device_config.h"
#include "base/utils/macros.h"
namespace OHOS::Ace {
class ACE_FORCE_EXPORT WindowUtils final {
public:
static DeviceOrientation GetDeviceOrientation(int32_t windowOrientation);
};
} // namespace OHOS::Ace
#endif

View File

@ -86,6 +86,7 @@
OHOS::Ace::Matrix4::*;
OHOS::Ace::NG::DragDropFuncWrapper::*;
OHOS::Ace::NG::DragDropGlobalController::*;
OHOS::Ace::WindowUtils::*;
OHOS::Ace::ColumnModel::*;
OHOS::Ace::FlexModel::*;