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_MODEL_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TIME_PICKER_TIME_PICKER_MODEL_NG_H 18 19 #include "core/components/common/layout/constants.h" 20 #include "core/components/picker/picker_base_component.h" 21 #include "core/components_ng/pattern/time_picker/timepicker_model.h" 22 23 namespace OHOS::Ace::NG { 24 using TimeChangeEvent = std::function<void(const BaseEventInfo* info)>; 25 26 class ACE_EXPORT TimePickerModelNG : public TimePickerModel { 27 public: 28 void CreateTimePicker(RefPtr<PickerTheme> pickerTheme, bool hasSecond = false) override; 29 void SetSelectedTime(const PickerTime& value) override; 30 void SetOnChange(TimeChangeEvent&& onChange) override; 31 void SetHour24(bool isUseMilitaryTime) override; 32 void SetIsEnableHapticFeedback(bool isEnableHapticFeedback) override; 33 void SetDateTimeOptions(ZeroPrefixType& hourType, 34 ZeroPrefixType& minuteType, ZeroPrefixType& secondType) override; 35 void SetWheelModeEnabled(bool wheelModeEnabled) override; 36 void SetDisappearTextStyle(const RefPtr<PickerTheme>& theme, const PickerTextStyle& value) override; 37 void SetNormalTextStyle(const RefPtr<PickerTheme>& theme, const PickerTextStyle& value) override; 38 void SetSelectedTextStyle(const RefPtr<PickerTheme>& theme, const PickerTextStyle& value) override; 39 void HasUserDefinedDisappearFontFamily(bool isUserDefined) override; 40 void HasUserDefinedNormalFontFamily(bool isUserDefined) override; 41 void HasUserDefinedSelectedFontFamily(bool isUserDefined) override; 42 void SetBackgroundColor(const Color& color) override; 43 void SetChangeEvent(TimeChangeEvent&& onChange) override; 44 void HasUserDefinedOpacity() override; 45 static void SetOnChange(FrameNode* frameNode, TimeChangeEvent&& onChange); 46 static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId); 47 48 static void SetSelectedTime(FrameNode* frameNode, const PickerTime& value); 49 static void SetDisappearTextStyle( 50 FrameNode* frameNode, const RefPtr<PickerTheme>& theme, const PickerTextStyle& value); 51 static void SetNormalTextStyle( 52 FrameNode* frameNode, const RefPtr<PickerTheme>& theme, const PickerTextStyle& value); 53 static void SetSelectedTextStyle( 54 FrameNode* frameNode, const RefPtr<PickerTheme>& theme, const PickerTextStyle& value); 55 static void SetBackgroundColor(FrameNode* frameNode, const Color& color); 56 static void SetHour24(FrameNode* frameNode, bool isUseMilitaryTime); 57 static void SetDateTimeOptions(FrameNode* frameNode, ZeroPrefixType& hourType, 58 ZeroPrefixType& minuteType, ZeroPrefixType& secondType); 59 static void SetIsEnableHapticFeedback(FrameNode* frameNode, bool isEnableHapticFeedback); 60 static PickerTextStyle getSelectedTextStyle(FrameNode* frameNode); 61 static PickerTextStyle getNormalTextStyle(FrameNode* frameNode); 62 static PickerTextStyle getDisappearTextStyle(FrameNode* frameNode); 63 static PickerTime getTimepickerSelected(FrameNode* frameNode); 64 static uint32_t getTimepickerBackgroundColor(FrameNode* frameNode); 65 static int32_t getTimepickerUseMilitaryTime(FrameNode* frameNode); 66 static int32_t getEnableHapticFeedback(FrameNode* frameNode); 67 static void SetDefaultAttributes(RefPtr<FrameNode>& frameNode, const RefPtr<PickerTheme>& pickerTheme); 68 static void SetWheelModeEnabled(FrameNode* frameNode, bool wheelModeEnabled); 69 static const Dimension ConvertFontScaleValue(const Dimension& fontSizeValue); 70 private: 71 static RefPtr<FrameNode> CreateStackNode(); 72 static RefPtr<FrameNode> CreateColumnNode(); 73 static RefPtr<FrameNode> CreateButtonNode(); 74 }; 75 76 class ACE_EXPORT TimePickerDialogModelNG : public TimePickerDialogModel { 77 public: 78 void SetTimePickerDialogShow(PickerDialogInfo& pickerDialog, NG::TimePickerSettingData& settingData, 79 std::function<void()>&& onCancel, std::function<void(const std::string&)>&& onAccept, 80 std::function<void(const std::string&)>&& onChange, TimePickerDialogEvent& timePickerDialogEvent, 81 const std::vector<ButtonInfo>& buttonInfos) override; 82 }; 83 } // namespace OHOS::Ace::NG 84 85 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TIME_PICKER_TIME_PICKER_MODEL_NG_H 86