• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TIME_PICKER_TIME_PICKER_ROW_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TIME_PICKER_TIME_PICKER_ROW_PATTERN_H
18 
19 #include <optional>
20 
21 #include "base/i18n/date_time_sequence.h"
22 #include "base/i18n/localization.h"
23 #include "base/i18n/time_format.h"
24 #include "base/utils/macros.h"
25 #include "core/components/common/properties/color.h"
26 #include "core/components_ng/base/inspector_filter.h"
27 #include "core/components_ng/pattern/button/button_layout_property.h"
28 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
29 #include "core/components_ng/pattern/time_picker/timepicker_column_pattern.h"
30 #include "core/components_ng/pattern/time_picker/timepicker_event_hub.h"
31 #include "core/components_ng/pattern/time_picker/timepicker_layout_property.h"
32 #include "core/components_ng/pattern/time_picker/timepicker_paint_method.h"
33 #include "core/components_ng/pattern/time_picker/timepicker_row_accessibility_property.h"
34 #include "core/components_v2/inspector/utils.h"
35 #include "core/components_ng/pattern/picker_utils/picker_column_pattern.h"
36 #ifdef SUPPORT_DIGITAL_CROWN
37 #include "core/event/crown_event.h"
38 #endif
39 
40 
41 namespace OHOS::Ace::NG {
42 namespace {
43 const Dimension TIME_FOCUS_PAINT_WIDTH = 2.0_vp;
44 }
45 
46 class TimePickerRowPattern : public LinearLayoutPattern {
47     DECLARE_ACE_TYPE(TimePickerRowPattern, LinearLayoutPattern);
48 
49 public:
TimePickerRowPattern()50     TimePickerRowPattern() : LinearLayoutPattern(false) {};
51 
52     ~TimePickerRowPattern() override = default;
53 
54     void BeforeCreateLayoutWrapper() override;
55 
IsAtomicNode()56     bool IsAtomicNode() const override
57     {
58         return true;
59     }
60 
OnColorModeChange(uint32_t colorMode)61     void OnColorModeChange(uint32_t colorMode) override
62     {
63         LinearLayoutPattern::OnColorModeChange(colorMode);
64         auto host = GetHost();
65         CHECK_NULL_VOID(host);
66         host->MarkModifyDone();
67     }
68 
CreateEventHub()69     RefPtr<EventHub> CreateEventHub() override
70     {
71         return MakeRefPtr<TimePickerEventHub>();
72     }
73 
CreateNodePaintMethod()74     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
75     {
76         auto paintMethod = MakeRefPtr<TimePickerPaintMethod>();
77         paintMethod->SetEnabled(enabled_);
78         paintMethod->SetBackgroundColor(backgroundColor_);
79         return paintMethod;
80     }
81 
CreateLayoutAlgorithm()82     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
83     {
84         return MakeRefPtr<LinearLayoutAlgorithm>();
85     }
86 
SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode)87     void SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode)
88     {
89         weakButtonConfirm_ = buttonConfirmNode;
90     }
91 
SetNextPrevButtonNode(WeakPtr<FrameNode> nextPrevButtonNode)92     void SetNextPrevButtonNode(WeakPtr<FrameNode> nextPrevButtonNode)
93     {
94         nextPrevButtonNode_ = nextPrevButtonNode;
95     }
96 
SetIsNext(bool isNext)97     void SetIsNext(bool isNext)
98     {
99         isNext_ = isNext;
100     }
101 
updateFontConfigurationEvent(const std::function<void ()> & closeDialogEvent)102     void updateFontConfigurationEvent(const std::function<void()>& closeDialogEvent)
103     {
104         closeDialogEvent_ = closeDialogEvent;
105     }
106 
SetIsShowInDialog(bool isShowInDialog)107     void SetIsShowInDialog(bool isShowInDialog)
108     {
109         isShowInDialog_ = isShowInDialog;
110     }
111 
GetIsShowInDialog()112     bool GetIsShowInDialog() const
113     {
114         return isShowInDialog_;
115     }
116 
SetIsShowInDatePickerDialog(bool isShowInDatePickerDialog)117     void SetIsShowInDatePickerDialog(bool isShowInDatePickerDialog)
118     {
119         isShowInDatePickerDialog_ = isShowInDatePickerDialog;
120     }
121 
GetIsShowInDatePickerDialog()122     bool GetIsShowInDatePickerDialog() const
123     {
124         return isShowInDatePickerDialog_;
125     }
126 
SetShowLunarSwitch(bool value)127     void SetShowLunarSwitch(bool value)
128     {
129         showLunarSwitch_ = value;
130     }
131 
GetShowLunarSwitch()132     bool GetShowLunarSwitch() const
133     {
134         return showLunarSwitch_;
135     }
136 
SetCancelNode(WeakPtr<FrameNode> buttonCancelNode)137     void SetCancelNode(WeakPtr<FrameNode> buttonCancelNode)
138     {
139         weakButtonCancel_ = buttonCancelNode;
140     }
141 
142     void OnLanguageConfigurationUpdate() override;
143     void OnFontConfigurationUpdate() override;
144     void OnFontScaleConfigurationUpdate() override;
145 
CreateLayoutProperty()146     RefPtr<LayoutProperty> CreateLayoutProperty() override
147     {
148         return MakeRefPtr<TimePickerLayoutProperty>();
149     }
150 
CreateAccessibilityProperty()151     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
152     {
153         return MakeRefPtr<TimePickerRowAccessibilityProperty>();
154     }
155 
156     void OnColumnsBuilding();
157 
GetAllChildNode()158     const std::unordered_map<std::string, WeakPtr<FrameNode>>& GetAllChildNode()
159     {
160         return allChildNode_;
161     }
162 
163     void UpdateAllChildNode();
164 
165     void HandleHourColumnBuilding();
166 
167     void HandleMinAndSecColumnBuilding();
168 
169     void HandleHourColumnBuildingRange(const PickerTime& value);
170 
171     void HandleMinAndSecColumnBuildingRange();
172 
173     void FlushColumn();
174 
175     void FlushAmPmFormatString();
176 
177     void OnDataLinking(
178         const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
179 
180     void HandleHour12Change(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
181 
182     void SetChangeCallback(ColumnChangeCallback&& value);
183 
184     void HandleColumnChange(const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, bool needNotify);
185 
186     void SetEventCallback(EventCallback&& value);
187 
188     void FireChangeEvent(bool refresh);
189 
190     void SetEnterSelectedAreaEventCallback(EventCallback&& value);
191 
192     void FireEnterSelectedAreaEvent(bool refresh);
193 
194     std::string GetSelectedObject(bool isColumnChange, int32_t status = -1);
195 
196     PickerTime GetCurrentTime();
197 
198     std::string GetEnterObject(bool isColumnChange, int32_t status = -1);
199 
200     PickerTime GetCurrentEnterTime();
201 
202     uint32_t GetHourFromAmPm(bool isAm, uint32_t amPmhour) const;
203 
HasTitleNode()204     bool HasTitleNode() const
205     {
206         return titleId_.has_value();
207     }
208 
GetTitleId()209     int32_t GetTitleId()
210     {
211         if (!titleId_.has_value()) {
212             titleId_ = ElementRegister::GetInstance()->MakeUniqueId();
213         }
214         return titleId_.value();
215     }
216 
GetShowCount()217     uint32_t GetShowCount() const
218     {
219         return showCount_;
220     }
221 
SetShowCount(uint32_t showCount)222     void SetShowCount(uint32_t showCount)
223     {
224         showCount_ = showCount;
225     }
226 
GetOptionCount(const RefPtr<FrameNode> & frameNode)227     uint32_t GetOptionCount(const RefPtr<FrameNode>& frameNode)
228     {
229         return optionsTotalCount_[frameNode];
230     }
231 
GetOptionValue(const RefPtr<FrameNode> & frmeNode,uint32_t index)232     std::string GetOptionValue(const RefPtr<FrameNode>& frmeNode, uint32_t index)
233     {
234         if (index >= GetOptionCount(frmeNode)) {
235             return nullptr;
236         }
237         return options_[frmeNode][index];
238     }
239 
HasDividerNode()240     bool HasDividerNode() const
241     {
242         return DividerId_.has_value();
243     }
244 
GetDividerId()245     int32_t GetDividerId()
246     {
247         if (!DividerId_.has_value()) {
248             DividerId_ = ElementRegister::GetInstance()->MakeUniqueId();
249         }
250         return DividerId_.value();
251     }
252 
253     const std::string& GetOptionsValue(const RefPtr<FrameNode>& frameNode, uint32_t optionIndex);
254 
GetOptionsCount()255     const std::map<WeakPtr<FrameNode>, uint32_t>& GetOptionsCount() const
256     {
257         return optionsTotalCount_;
258     }
259 
SetHour24(bool value)260     void SetHour24(bool value)
261     {
262         isForceUpdate_ = value != hour24_;
263         hour24_ = value;
264         if (!isClearFocus_) {
265             isClearFocus_ = isForceUpdate_;
266         }
267     }
268 
GetHour24()269     bool GetHour24() const
270     {
271         auto timePickerLayoutProperty = GetLayoutProperty<TimePickerLayoutProperty>();
272         CHECK_NULL_RETURN(timePickerLayoutProperty, hour24_);
273         return timePickerLayoutProperty->GetIsUseMilitaryTimeValue(hour24_);
274     }
275 
SetDateTimeOptionUpdate(bool value)276     void SetDateTimeOptionUpdate(bool value)
277     {
278         isDateTimeOptionUpdate_ = value;
279     }
280 
SetPrefixHour(ZeroPrefixType & value)281     void SetPrefixHour(ZeroPrefixType& value)
282     {
283         prefixHour_ = value;
284     }
285 
GetPrefixHour()286     ZeroPrefixType GetPrefixHour() const
287     {
288         return prefixHour_;
289     }
290 
ClearOptionsHour()291     void ClearOptionsHour()
292     {
293         if (!IsStartEndTimeDefined()) {
294             // when switch IsUseMilitaryTime state, should clear options_[hourColumn]
295             // Hour24 : Index = [0, 23] -> hour = [0, 23]
296             // Hour12 : Index = [0, 11] -> hour = [1, 12]
297             auto hourColumn = allChildNode_["hour"];
298             options_[hourColumn].clear();
299         }
300     }
301 
302     void SetSelectedTime(const PickerTime& value);
GetSelectedTime()303     const PickerTime& GetSelectedTime()
304     {
305         return selectedTime_;
306     }
307 
SetStartTime(const PickerTime & value)308     void SetStartTime(const PickerTime& value)
309     {
310         startTime_ = value;
311     }
312 
GetStartTime()313     const PickerTime& GetStartTime() const
314     {
315         return startTime_;
316     }
317 
SetEndTime(const PickerTime & value)318     void SetEndTime(const PickerTime& value)
319     {
320         endTime_ = value;
321     }
322 
GetEndTime()323     const PickerTime& GetEndTime() const
324     {
325         return endTime_;
326     }
327 
SetDialogTitleDate(const PickerDate & value)328     void SetDialogTitleDate(const PickerDate& value)
329     {
330         dialogTitleDate_ = value;
331     }
332 
GetDialogTitleDate()333     const PickerDate& GetDialogTitleDate()
334     {
335         return dialogTitleDate_;
336     }
337 
HasAmPmNode()338     bool HasAmPmNode() const
339     {
340         return amPmId_.has_value();
341     }
342 
GetAmPmId()343     int32_t GetAmPmId()
344     {
345         if (!amPmId_.has_value()) {
346             amPmId_ = ElementRegister::GetInstance()->MakeUniqueId();
347         }
348         return amPmId_.value();
349     }
350 
HasHourNode()351     bool HasHourNode() const
352     {
353         return hourId_.has_value();
354     }
355 
GetHourId()356     int32_t GetHourId()
357     {
358         if (!hourId_.has_value()) {
359             hourId_ = ElementRegister::GetInstance()->MakeUniqueId();
360         }
361         return hourId_.value();
362     }
363 
HasMinuteNode()364     bool HasMinuteNode() const
365     {
366         return minuteId_.has_value();
367     }
368 
GetMinuteId()369     int32_t GetMinuteId()
370     {
371         if (!minuteId_.has_value()) {
372             minuteId_ = ElementRegister::GetInstance()->MakeUniqueId();
373         }
374         return minuteId_.value();
375     }
376 
HasSecondNode()377     bool HasSecondNode() const
378     {
379         return secondId_.has_value();
380     }
381 
GetSecondId()382     int32_t GetSecondId()
383     {
384         if (!secondId_.has_value()) {
385             secondId_ = ElementRegister::GetInstance()->MakeUniqueId();
386         }
387         return secondId_.value();
388     }
389 
GetHasSecond()390     bool GetHasSecond() const
391     {
392         return hasSecond_;
393     }
SetHasSecond(bool value)394     void SetHasSecond(bool value)
395     {
396         hasSecond_ = value;
397     }
398 
SetPrefixMinute(ZeroPrefixType value)399     void SetPrefixMinute(ZeroPrefixType value)
400     {
401         prefixMinute_ = value;
402     }
403 
GetPrefixMinute()404     ZeroPrefixType GetPrefixMinute() const
405     {
406         auto timePickerLayoutProperty = GetLayoutProperty<TimePickerLayoutProperty>();
407         CHECK_NULL_RETURN(timePickerLayoutProperty, prefixMinute_);
408         return static_cast<ZeroPrefixType>(
409             timePickerLayoutProperty->GetPrefixMinuteValue(0));
410     }
411 
SetPrefixSecond(ZeroPrefixType value)412     void SetPrefixSecond(ZeroPrefixType value)
413     {
414         prefixSecond_ = value;
415     }
416 
GetPrefixSecond()417     ZeroPrefixType GetPrefixSecond() const
418     {
419         auto timePickerLayoutProperty = GetLayoutProperty<TimePickerLayoutProperty>();
420         CHECK_NULL_RETURN(timePickerLayoutProperty, prefixSecond_);
421         return static_cast<ZeroPrefixType>(
422             timePickerLayoutProperty->GetPrefixSecondValue(0));
423     }
424 
GetWheelModeEnabled()425     bool GetWheelModeEnabled() const
426     {
427         auto timePickerLayoutProperty = GetLayoutProperty<TimePickerLayoutProperty>();
428         CHECK_NULL_RETURN(timePickerLayoutProperty, loop_);
429         return timePickerLayoutProperty->GetLoopValue(true);
430     }
431 
GetColumn(int32_t tag)432     RefPtr<FrameNode> GetColumn(int32_t tag) const
433     {
434         auto iter = std::find_if(timePickerColumns_.begin(), timePickerColumns_.end(), [tag](const auto& c) {
435                 auto column = c.Upgrade();
436                 return column && column->GetId() == tag;
437             });
438         return (iter == timePickerColumns_.end()) ? nullptr : (*iter).Upgrade();
439     }
440 
SetColumn(const RefPtr<FrameNode> & value)441     void SetColumn(const RefPtr<FrameNode>& value)
442     {
443         timePickerColumns_.emplace_back(value);
444     }
445 
SetBackgroundColor(const Color & color)446     void SetBackgroundColor(const Color& color)
447     {
448         backgroundColor_ = color;
449     }
450 
GetBackgroundColor()451     const Color GetBackgroundColor() const
452     {
453         return backgroundColor_;
454     }
455 
SetIsEnableHaptic(bool value)456     void SetIsEnableHaptic(bool value)
457     {
458         if (isEnableHaptic_ != value) {
459             isHapticChanged_ = true;
460         }
461         isEnableHaptic_ = value;
462     }
463 
GetIsEnableHaptic()464     bool GetIsEnableHaptic() const
465     {
466         return isEnableHaptic_;
467     }
468 
469     bool IsAmHour(uint32_t hourOf24) const;
470 
471     uint32_t GetAmPmHour(uint32_t hourOf24) const;
472 
473     std::string GetAmFormatString() const;
474 
475     std::string GetPmFormatString() const;
476 
477     std::string AddZeroPrefix(const std::string& value) const;
478 
479     std::string GetHourFormatString(uint32_t hour) const;
480 
481     std::string GetMinuteFormatString(uint32_t minute) const;
482 
483     std::string GetSecondFormatString(uint32_t Second) const;
484 
GetFocusPattern()485     FocusPattern GetFocusPattern() const override
486     {
487         auto pipeline = PipelineBase::GetCurrentContext();
488         CHECK_NULL_RETURN(pipeline, FocusPattern());
489         auto pickerTheme = pipeline->GetTheme<PickerTheme>();
490         CHECK_NULL_RETURN(pickerTheme, FocusPattern());
491         auto focusColor = pickerTheme->GetFocusColor();
492         FocusPaintParam focusPaintParams;
493         focusPaintParams.SetPaintColor(focusColor);
494         focusPaintParams.SetPaintWidth(TIME_FOCUS_PAINT_WIDTH);
495         return { FocusType::NODE, true, FocusStyleType::CUSTOM_REGION, focusPaintParams };
496     }
497 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)498     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
499     {
500         /* no fixed attr below, just return */
501         if (filter.IsFastFilter()) {
502             return;
503         }
504         json->PutExtAttr("selected", selectedTime_.ToString(false, false).c_str(), filter);
505         json->PutExtAttr("start", startTime_.ToString(false, false).c_str(), filter);
506         json->PutExtAttr("end", endTime_.ToString(false, false).c_str(), filter);
507         json->PutExtAttr("enableCascade", isEnableCascade_, filter);
508         json->PutExtAttr("enableHapticFeedback", isEnableHaptic_, filter);
509     }
510 
511     void CreateAmPmNode();
512     void OnColorConfigurationUpdate() override;
513 
514     bool OnThemeScopeUpdate(int32_t themeScopeId) override;
515 
SetContentRowNode(RefPtr<FrameNode> & contentRowNode)516     void SetContentRowNode(RefPtr<FrameNode>& contentRowNode)
517     {
518         contentRowNode_ = contentRowNode;
519     }
520 
SetbuttonTitleNode(RefPtr<FrameNode> & buttonTitleNode)521     void SetbuttonTitleNode(RefPtr<FrameNode>& buttonTitleNode)
522     {
523         buttonTitleNode_ = buttonTitleNode;
524     }
525 
SetPickerTag(bool isPicker)526     void SetPickerTag(bool isPicker)
527     {
528         isPicker_ = isPicker;
529     }
530 
531     void SetFocusDisable();
532     void SetFocusEnable();
533 
UpdateLanguageAndAmPmTimeOrder()534     void UpdateLanguageAndAmPmTimeOrder()
535     {
536         if (language_ == "ug") {
537             isPreLanguageUg_ = true;
538         }
539         language_ = AceApplicationInfo::GetInstance().GetLanguage();
540 
541         auto preAmPmTimeOrder = amPmTimeOrder_;
542         amPmTimeOrder_ = DateTimeSequence::GetAmPmTimeOrder(language_).amPmTimeOrder;
543         preAmPmTimeOrder == amPmTimeOrder_ ? isAmPmTimeOrderUpdate_ = false : isAmPmTimeOrderUpdate_ = true;
544 
545         auto host = GetHost();
546         CHECK_NULL_VOID(host);
547         auto layoutProperty = host->GetLayoutProperty();
548         CHECK_NULL_VOID(layoutProperty);
549         if (language_ == "ar" && layoutProperty->GetLayoutDirection() != TextDirection::RTL) {
550             layoutProperty->UpdateLayoutDirection(TextDirection::LTR);
551             isDirectionSetByAr = true;
552         } else if (isDirectionSetByAr) {
553             layoutProperty->UpdateLayoutDirection(TextDirection::AUTO);
554             isDirectionSetByAr = false;
555         }
556     }
557 
HasUserDefinedDisappearFontFamily(bool isUserDefined)558     void HasUserDefinedDisappearFontFamily(bool isUserDefined)
559     {
560         hasUserDefinedDisappearFontFamily_ = isUserDefined;
561     }
562 
GetHasUserDefinedDisappearFontFamily()563     bool GetHasUserDefinedDisappearFontFamily()
564     {
565         return hasUserDefinedDisappearFontFamily_;
566     }
567 
HasUserDefinedNormalFontFamily(bool isUserDefined)568     void HasUserDefinedNormalFontFamily(bool isUserDefined)
569     {
570         hasUserDefinedNormalFontFamily_ = isUserDefined;
571     }
572 
GetHasUserDefinedNormalFontFamily()573     bool GetHasUserDefinedNormalFontFamily()
574     {
575         return hasUserDefinedNormalFontFamily_;
576     }
577 
HasUserDefinedSelectedFontFamily(bool isUserDefined)578     void HasUserDefinedSelectedFontFamily(bool isUserDefined)
579     {
580         hasUserDefinedSelectedFontFamily_ = isUserDefined;
581     }
582 
GetHasUserDefinedSelectedFontFamily()583     bool GetHasUserDefinedSelectedFontFamily()
584     {
585         return hasUserDefinedSelectedFontFamily_;
586     }
587 
GetTextProperties()588     const PickerTextProperties& GetTextProperties() const
589     {
590         return textProperties_;
591     }
592 
SetTextProperties(const PickerTextProperties & properties)593     void SetTextProperties(const PickerTextProperties& properties)
594     {
595         textProperties_ = properties;
596         if (properties.disappearTextStyle_.fontSize.has_value() && properties.disappearTextStyle_.fontSize->IsValid()) {
597             isUserSetGradientFont_ = true;
598             gradientHeight_ = properties.disappearTextStyle_.fontSize.value();
599         }
600 
601         if (properties.normalTextStyle_.fontSize.has_value() && properties.normalTextStyle_.fontSize->IsValid()) {
602             isUserSetGradientFont_ = true;
603             gradientHeight_ = std::max(properties.normalTextStyle_.fontSize.value(), gradientHeight_);
604         }
605 
606         if (properties.selectedTextStyle_.fontSize.has_value() && properties.selectedTextStyle_.fontSize->IsValid()) {
607             isUserSetDividerSpacingFont_ = true;
608             dividerSpacing_ = properties.selectedTextStyle_.fontSize.value();
609         }
610     }
611 
GetIsUserSetDividerSpacingFont()612     bool GetIsUserSetDividerSpacingFont()
613     {
614         return isUserSetDividerSpacingFont_;
615     }
616 
GetIsUserSetGradientFont()617     bool GetIsUserSetGradientFont()
618     {
619         return isUserSetGradientFont_;
620     }
621 
GetDividerSpacing()622     Dimension GetDividerSpacing()
623     {
624         return dividerSpacing_;
625     }
626 
GetGradientHeight()627     Dimension GetGradientHeight()
628     {
629         return gradientHeight_;
630     }
631 
SetPaintDividerSpacing(float & value)632     void SetPaintDividerSpacing(float& value)
633     {
634         paintDividerSpacing_ = value;
635     }
636 
GetPaintDividerSpacing()637     float GetPaintDividerSpacing()
638     {
639         return paintDividerSpacing_;
640     }
641 
SetCurrentFocusKeyID(int32_t value)642     void SetCurrentFocusKeyID(int32_t value)
643     {
644         focusKeyID_ = value;
645     }
646 
GetCurrentFocusKeyID()647     int32_t GetCurrentFocusKeyID()
648     {
649         return focusKeyID_;
650     }
651 
SetCurrentPage(uint32_t value)652     void SetCurrentPage(uint32_t value)
653     {
654         currentPage_ = value;
655     }
656 
GetCurrentPage()657     uint32_t GetCurrentPage()
658     {
659         return currentPage_;
660     }
661 
662     bool NeedAdaptForAging();
663 
SetUserDefinedOpacity(double opacity)664     void SetUserDefinedOpacity(double opacity)
665     {
666         curOpacity_ = opacity;
667     }
668 
SetEnableCascade(bool value)669     void SetEnableCascade(bool value)
670     {
671         isEnableCascade_ = value;
672     }
673 
GetEnableCascade()674     bool GetEnableCascade() const
675     {
676         return isEnableCascade_;
677     }
678 
679     void ColumnPatternInitHapticController();
680     void ColumnPatternStopHaptic();
681     void SetDigitalCrownSensitivity(int32_t crownSensitivity);
682     bool IsStartEndTimeDefined();
683     void UpdateUserSetSelectColor();
684     void UpdateDisappearTextStyle(const PickerTextStyle& textStyle);
685     void UpdateNormalTextStyle(const PickerTextStyle& textStyle);
686     void UpdateSelectedTextStyle(const PickerTextStyle& textStyle);
687 
688 private:
689     void SetDefaultColoumnFocus(std::unordered_map<std::string, WeakPtr<FrameNode>>::iterator& it,
690         const std::string &id, bool& focus, const std::function<void(const std::string&)>& call);
691     void ClearFocus();
692     void SetDefaultFocus();
693     bool IsCircle();
694 
695 #ifdef SUPPORT_DIGITAL_CROWN
696     void InitOnCrownEvent(const RefPtr<FocusHub>& focusHub);
697     bool OnCrownEvent(const CrownEvent& event);
698 #endif
699     void UpdateTitleNodeContent();
700     void OnModifyDone() override;
701     void OnAttachToFrameNode() override;
702     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
703 
704     void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
705     bool OnKeyEvent(const KeyEvent& event);
706     bool HandleDirectionKey(KeyCode code);
707     void InitDisabled();
708     void GetInnerFocusPaintRect(RoundRect& paintRect);
709     void PaintFocusState();
710     void AdjustFocusBoxOffset(double& centerX);
711     void SetButtonIdeaSize();
712     double SetAmPmButtonIdeaSize();
713     void GetAllChildNodeWithSecond();
714     void CreateOrDeleteSecondNode();
715     RefPtr<FrameNode> GetAmPmNode(std::list<RefPtr<UINode>>::iterator& iter);
716     RefPtr<FrameNode> GetHourNode(std::list<RefPtr<UINode>>::iterator& iter);
717     RefPtr<FrameNode> GetMinuteNode(std::list<RefPtr<UINode>>::iterator& iter);
718     RefPtr<FrameNode> GetSecondNode(std::list<RefPtr<UINode>>::iterator& iter);
719     void UpdateAllChildNodeForUg();
720     void UpdateNodePositionForUg();
721     void MountSecondNode(const RefPtr<FrameNode>& stackSecondNode);
722     void RemoveSecondNode();
723     void UpdateButtonMargin(
724         const RefPtr<FrameNode>& buttonNode, const RefPtr<DialogTheme>& dialogTheme, const bool isConfirmOrNextNode);
725     void CalcLeftTotalColumnWidth(const RefPtr<FrameNode>& host, float &leftTotalColumnWidth, float childSize);
726     bool CheckFocusID(int32_t childSize);
727     bool ParseDirectionKey(RefPtr<FrameNode>& host, RefPtr<TimePickerColumnPattern>& pattern, KeyCode& code,
728                           int32_t currentIndex, uint32_t totalOptionCount, int32_t childSize);
729     void HandleAmPmColumnBuilding(const PickerTime& value);
730     void HandleAmPmColumnChange(uint32_t selectedHour);
731     void HandleAmToPmHourColumnBuilding(uint32_t selectedHour, uint32_t startHour, uint32_t endHour);
732     void HandleMinColumnBuilding();
733     void HandleMinColumnChange(const PickerTime& value);
734     uint32_t ParseHourOf24(uint32_t hourOf24) const;
735     PickerTime AdjustTime(const PickerTime& time);
736     void HourChangeBuildTimeRange();
737     void MinuteChangeBuildTimeRange(uint32_t hourOf24);
738     void RecordHourAndMinuteOptions();
739     void RecordHourMinuteValues();
740     bool GetOptionsIndex(const RefPtr<FrameNode>& frameNode, const std::string& value, uint32_t& columnIndex);
741     std::string GetOptionsCurrentValue(const RefPtr<FrameNode>& frameNode);
742     std::string GetOptionsValueWithIndex(const RefPtr<FrameNode>& frameNode, uint32_t optionIndex);
743     void HandleColumnsChangeTimeRange(const RefPtr<FrameNode>& tag);
744     void UpdateHourAndMinuteTimeRange(const RefPtr<FrameNode>& tag);
745     void Hour24ChangeBuildTimeRange();
746     void Hour12ChangeBuildTimeRange();
747     void RecordHourOptions();
748     void UpdateSecondTimeRange();
749     void HandleSecondsChangeTimeRange(const RefPtr<FrameNode>& secondColumn);
750     void LimitSelectedTimeInRange();
751     bool IsAmJudgeByAmPmColumn(const RefPtr<FrameNode>& amPmColumn);
752     void MinOrSecColumnBuilding(
753         const RefPtr<FrameNode>& columnFrameNode, bool isZeroPrefixTypeHide, uint32_t selectedTime);
754     void InitFocusEvent();
755     void SetCallBack();
756     void UpdateDialogAgingButton(const RefPtr<FrameNode>& buttonNode, bool isNext);
757     Dimension ConvertFontScaleValue(const Dimension& fontSizeValue);
758 
759     void UpdateTextStyleCommon(
760         const PickerTextStyle& textStyle,
761         const TextStyle& defaultTextStyle,
762         std::function<void(const Color&)> updateTextColorFunc,
763         std::function<void(const Dimension&)> updateFontSizeFunc,
764         std::function<void(const std::vector<std::string>&)> updateFontFamilyFunc);
765 
766     RefPtr<ClickEvent> clickEventListener_;
767     bool enabled_ = true;
768     int32_t focusKeyID_ = 0;
769     uint32_t currentPage_ = 0;
770     std::unordered_map<std::string, WeakPtr<FrameNode>> allChildNode_;
771     std::map<WeakPtr<FrameNode>, std::unordered_map<uint32_t, std::string>> options_;
772     std::map<WeakPtr<FrameNode>, uint32_t> optionsTotalCount_;
773     uint32_t showCount_ = 0;
774     Color backgroundColor_ = Color::WHITE;
775     // true, use 24 hours style; false, use 12 hours style.
776     bool hour24_ = SystemProperties::Is24HourClock();
777     ZeroPrefixType prefixHour_ = ZeroPrefixType::AUTO;
778     ZeroPrefixType prefixMinute_ = ZeroPrefixType::AUTO;
779     ZeroPrefixType prefixSecond_ = ZeroPrefixType::AUTO;
780     PickerTime startTime_ = PickerTime(0, 0, 0);
781     PickerTime endTime_ = PickerTime(23, 59, 59);
782     PickerTime selectedTime_ = PickerTime::Current();
783     PickerDate dialogTitleDate_ = PickerDate::Current();
784     std::optional<int32_t> amPmId_;
785     std::optional<int32_t> hourId_;
786     std::optional<int32_t> minuteId_;
787     std::optional<int32_t> secondId_;
788     std::optional<int32_t> titleId_;
789     std::optional<int32_t> ButtonTitleId_;
790     std::optional<int32_t> DividerId_;
791     WeakPtr<FrameNode> weakButtonConfirm_;
792     WeakPtr<FrameNode> weakButtonCancel_;
793     WeakPtr<FrameNode> nextPrevButtonNode_;
794     bool isNext_ = true;
795     std::function<void()> closeDialogEvent_;
796     bool hasSecond_ = false;
797     bool loop_ = true;
798     std::vector<WeakPtr<FrameNode>> timePickerColumns_;
799     std::vector<std::string> vecAmPm_ = Localization::GetInstance()->GetAmPmStrings();
800 
801     bool hasUserDefinedDisappearFontFamily_ = false;
802     bool hasUserDefinedNormalFontFamily_ = false;
803     bool hasUserDefinedSelectedFontFamily_ = false;
804 
805     double curOpacity_ = 1.0;
806 
807     ACE_DISALLOW_COPY_AND_MOVE(TimePickerRowPattern);
808 
809     WeakPtr<FrameNode> buttonTitleNode_;
810     WeakPtr<FrameNode> contentRowNode_;
811     bool isPicker_ = false;
812     bool isFiredTimeChange_ = false;
813     bool isForceUpdate_ = false;
814     bool isDateTimeOptionUpdate_ = false;
815     bool isEnableHaptic_ = true;
816     bool isHapticChanged_ = false;
817     std::optional<std::string> firedTimeStr_;
818     std::string language_;
819     std::string amPmTimeOrder_;
820     bool isAmPmTimeOrderUpdate_ = false;
821     bool isPreLanguageUg_ = false;
822     bool isShowInDialog_ = false;
823     bool showLunarSwitch_ = false;
824     bool isUserSetDividerSpacingFont_ = false;
825     bool isUserSetGradientFont_ = false;
826     Dimension gradientHeight_;
827     Dimension dividerSpacing_;
828     float paintDividerSpacing_ = 1.0f;
829     PickerTextProperties textProperties_;
830     bool isShowInDatePickerDialog_ = false;
831     bool isEnableCascade_ = false;
832 
833     std::vector<std::string> definedAMHours_;
834     std::vector<std::string> definedPMHours_;
835     std::vector<std::string> defined24Hours_;
836     std::string oldHourValue_;
837     std::string oldMinuteValue_;
838     std::string selectedColumnId_;
839     bool isUserSetSelectColor_ = false;
840     bool isClearFocus_ = true;
841     bool isDirectionSetByAr = false;
842 };
843 } // namespace OHOS::Ace::NG
844 
845 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TIME_PICKER_TIME_PICKER_ROW_PATTERN_H
846