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