• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_LAYOUT_PROPERTY_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "base/geometry/dimension.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components_ng/base/inspector_filter.h"
25 #include "core/components_ng/layout/layout_property.h"
26 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h"
27 #include "core/components_ng/pattern/picker_utils/picker_layout_property.h"
28 #include "core/components_ng/pattern/text/text_styles.h"
29 #include "core/components_ng/pattern/time_picker/timepicker_model_ng.h"
30 #include "core/components_ng/property/property.h"
31 
32 namespace OHOS::Ace::NG {
33 class ACE_EXPORT TimePickerLayoutProperty : public PickerLayoutProperty {
34     DECLARE_ACE_TYPE(TimePickerLayoutProperty, PickerLayoutProperty);
35 
36 public:
37     TimePickerLayoutProperty() = default;
38     ~TimePickerLayoutProperty() override = default;
39 
Clone()40     RefPtr<LayoutProperty> Clone() const override
41     {
42         auto value = MakeRefPtr<TimePickerLayoutProperty>();
43         Clone(value);
44         value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this));
45         value->propLoop_ = CloneLoop();
46         return value;
47     }
48 
Reset()49     void Reset() override
50     {
51         PickerLayoutProperty::Reset();
52         ResetLoop();
53     }
54 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)55     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
56     {
57         PickerLayoutProperty::ToJsonValue(json, filter);
58         json->PutExtAttr("useMilitaryTime",
59             V2::ConvertBoolToString(GetIsUseMilitaryTimeValue(false)).c_str(), filter);
60         json->PutExtAttr("loop", V2::ConvertBoolToString(GetLoopValue(true)).c_str(), filter);
61 
62         auto options = JsonUtil::Create(true);
63         options->Put("hour", TimeFormat::GetHourFormat(
64             GetPrefixHourValue(0), GetIsUseMilitaryTimeValue(false)).c_str());
65         options->Put("minute", TimeFormat::GetMinuteFormat(GetPrefixMinuteValue(0)).c_str());
66         if (GetPrefixSecondValue(0) != static_cast<int32_t>(ZeroPrefixType::OFF)) {
67             options->Put("second", TimeFormat::GetSecondFormat(GetPrefixSecondValue(0)).c_str());
68         }
69         json->PutExtAttr("dateTimeOptions", options, filter);
70     }
71 
72     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsUseMilitaryTime, bool, PROPERTY_UPDATE_MEASURE);
73     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Loop, bool, PROPERTY_UPDATE_MEASURE);
74     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PrefixHour, int32_t, PROPERTY_UPDATE_MEASURE);
75     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PrefixMinute, int32_t, PROPERTY_UPDATE_MEASURE);
76     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PrefixSecond, int32_t, PROPERTY_UPDATE_MEASURE);
77     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsEnableCascade, bool, PROPERTY_UPDATE_MEASURE);
78 
79 protected:
Clone(RefPtr<LayoutProperty> property)80     void Clone(RefPtr<LayoutProperty> property) const override
81     {
82         auto value = DynamicCast<TimePickerLayoutProperty>(property);
83         CHECK_NULL_VOID(value);
84         PickerLayoutProperty::Clone(value);
85     }
86 
87 private:
88     ACE_DISALLOW_COPY_AND_MOVE(TimePickerLayoutProperty);
89 };
90 } // namespace OHOS::Ace::NG
91 
92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_LAYOUT_PROPERTY_H
93