1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ui/base/agingadapation/aging_adapation_dialog_util.h"
17
18 #include "core/common/agingadapation/aging_adapation_dialog_theme.h"
19 #include "core/common/agingadapation/aging_adapation_dialog_util.h"
20 #include "interfaces/inner_api/ace_kit/src/view/frame_node_impl.h"
21 #include "ui/base/utils/utils.h"
22 #include "base/utils/utf_helper.h"
23
24 namespace OHOS::Ace::Kit {
25
ShowLongPressDialog(const std::string & message,const int32_t iconNodeId,const IconNodeType type,bool isWithDialogTheme)26 RefPtr<FrameNode> AgingAdapationDialogUtil::ShowLongPressDialog(
27 const std::string& message, const int32_t iconNodeId, const IconNodeType type, bool isWithDialogTheme)
28 {
29 int32_t themeScopedId = 0;
30 auto context = PipelineBase::GetCurrentContext();
31 CHECK_NULL_RETURN(context, nullptr);
32 auto dialogTheme = context->GetTheme<AgingAdapationDialogTheme>(themeScopedId);
33 CHECK_NULL_RETURN(dialogTheme, nullptr);
34 float scale = context->GetFontScale();
35 if (LessNotEqual(scale, AgingAdapationDialogUtil::GetDialogBigFontSizeScale())) {
36 return nullptr;
37 }
38 if (type == IconNodeType::TEXT) {
39 auto dialogNode = OHOS::Ace::NG::AgingAdapationDialogUtil::ShowLongPressDialog(UtfUtils::Str8ToStr16(message));
40 CHECK_NULL_RETURN(dialogNode, nullptr);
41 RefPtr<FrameNode> node = AceType::MakeRefPtr<FrameNodeImpl>(AceType::RawPtr(dialogNode));
42 dialogNode->SetKitNode(node);
43 return node;
44 }
45 auto uiNode = ElementRegister::GetInstance()->GetUINodeById(iconNodeId);
46 CHECK_NULL_RETURN(uiNode, nullptr);
47 auto frameNode = AceType::DynamicCast<NG::FrameNode>(uiNode);
48 CHECK_NULL_RETURN(frameNode, nullptr);
49 RefPtr<AceNode> dialogNode = nullptr;
50 switch (type) {
51 case IconNodeType::SYMBOL:
52 dialogNode = OHOS::Ace::NG::AgingAdapationDialogUtil::ShowLongPressDialog(
53 message, frameNode, isWithDialogTheme);
54 break;
55 case IconNodeType::IMAGE:
56 {
57 auto imageProperty = frameNode->GetLayoutProperty<NG::ImageLayoutProperty>();
58 CHECK_NULL_RETURN(imageProperty, nullptr);
59 ImageSourceInfo sourceInfo = imageProperty->GetImageSourceInfoValue();
60 dialogNode = OHOS::Ace::NG::AgingAdapationDialogUtil::ShowLongPressDialog(message, sourceInfo);
61 break;
62 }
63 default:
64 break;
65 }
66 CHECK_NULL_RETURN(dialogNode, nullptr);
67 RefPtr<FrameNode> node = AceType::MakeRefPtr<FrameNodeImpl>(AceType::RawPtr(dialogNode));
68 dialogNode->SetKitNode(node);
69 return node;
70 }
71
GetDialogBigFontSizeScale()72 float AgingAdapationDialogUtil::GetDialogBigFontSizeScale()
73 {
74 return OHOS::Ace::NG::AgingAdapationDialogUtil::GetDialogBigFontSizeScale();
75 }
76
GetDialogLargeFontSizeScale()77 float AgingAdapationDialogUtil::GetDialogLargeFontSizeScale()
78 {
79 return OHOS::Ace::NG::AgingAdapationDialogUtil::GetDialogLargeFontSizeScale();
80 }
81
GetDialogMaxFontSizeScale()82 float AgingAdapationDialogUtil::GetDialogMaxFontSizeScale()
83 {
84 return OHOS::Ace::NG::AgingAdapationDialogUtil::GetDialogMaxFontSizeScale();
85 }
86 } // OHOS::Ace::Kit