1 /* 2 * Copyright (c) 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_PATTERN_TIME_PICKER_TIME_PICKER_MODEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_MODEL_H 18 19 #include <mutex> 20 21 #include "base/i18n/time_format.h" 22 #include "core/components/picker/picker_data.h" 23 #include "core/components/picker/picker_theme.h" 24 #include "core/components_ng/pattern/picker/picker_model.h" 25 #include "core/components_ng/pattern/picker/picker_type_define.h" 26 27 namespace OHOS::Ace { 28 using ChangeEvent = std::function<void(const BaseEventInfo* info)>; 29 struct TimePickerDialogEvent { 30 std::function<void()> onDidAppear; 31 std::function<void()> onDidDisappear; 32 std::function<void()> onWillAppear; 33 std::function<void()> onWillDisappear; 34 }; 35 class TimePickerModel { 36 public: 37 static TimePickerModel* GetInstance(); 38 virtual ~TimePickerModel() = default; 39 40 virtual void CreateTimePicker(RefPtr<PickerTheme> pickerTheme, bool hasSecond = false) = 0; 41 virtual void SetSelectedTime(const PickerTime& value) = 0; 42 virtual void SetOnChange(ChangeEvent&& onChange) = 0; 43 virtual void SetHour24(bool isUseMilitaryTime) = 0; SetIsEnableHapticFeedback(bool isEnableHapticFeedback)44 virtual void SetIsEnableHapticFeedback(bool isEnableHapticFeedback) {}; SetDateTimeOptions(ZeroPrefixType & hourType,ZeroPrefixType & minuteType,ZeroPrefixType & secondType)45 virtual void SetDateTimeOptions(ZeroPrefixType& hourType, 46 ZeroPrefixType& minuteType, ZeroPrefixType& secondType) {}; 47 virtual void SetWheelModeEnabled(bool wheelModeEnabled) = 0; 48 virtual void SetDisappearTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0; 49 virtual void SetNormalTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0; 50 virtual void SetSelectedTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0; 51 virtual void HasUserDefinedDisappearFontFamily(bool isUserDefined) = 0; 52 virtual void HasUserDefinedNormalFontFamily(bool isUserDefined) = 0; 53 virtual void HasUserDefinedSelectedFontFamily(bool isUserDefined) = 0; 54 virtual void SetBackgroundColor(const Color& color) = 0; 55 virtual void SetChangeEvent(ChangeEvent&& onChange) = 0; 56 virtual void HasUserDefinedOpacity() = 0; 57 58 private: 59 static std::unique_ptr<TimePickerModel> timePickerInstance_; 60 static std::mutex mutex_; 61 }; 62 63 class TimePickerDialogModel { 64 public: 65 static TimePickerDialogModel* GetInstance(); 66 virtual ~TimePickerDialogModel() = default; 67 68 virtual void SetTimePickerDialogShow(PickerDialogInfo& pickerDialog, NG::TimePickerSettingData& settingData, 69 std::function<void()>&& onCancel, std::function<void(const std::string&)>&& onAccept, 70 std::function<void(const std::string&)>&& onChange, TimePickerDialogEvent& timePickerDialogEvent, 71 const std::vector<ButtonInfo>& buttonInfos) = 0; 72 73 private: 74 static std::unique_ptr<TimePickerDialogModel> timePickerDialogInstance_; 75 static std::mutex mutex_; 76 }; 77 } // namespace OHOS::Ace 78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_MODEL_H 79