2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "notification-ex/exception.h"
22 #include "notification-ex/progress_item.h"
23 #include "notification-ex/progress_item_implementation.h"
24 #include "notification-ex/factory_manager.h"
30 #define LOG_TAG "NOTIFICATION_EX"
31 #define PROGRESS_MIN_KEY "__PROGRESS_MIN_KEY__"
32 #define PROGRESS_CURRENT_KEY "__PROGRESS_CURRENT_KEY__"
33 #define PROGRESS_MAX_KEY "__PROGRESS_MAX_KEY__"
34 #define PROGRESS_TYPE_KEY "__PROGRESS_TYPE_KEY__"
35 #define PROGRESS_UNIT_KEY "__PROGRESS_UNIT_KEY__"
38 using namespace tizen_base;
40 namespace notification {
43 ProgressItem::ProgressItem(float min_val, float current, float max_val,
44 std::shared_ptr<AbstractAction> action)
45 : AbstractItem(action),
46 impl_(new Impl(min_val, current, max_val, this)) {
49 ProgressItem::ProgressItem(string id, float min_val, float current,
50 float max_val, std::shared_ptr<AbstractAction> action)
51 : AbstractItem(id, action),
52 impl_(new Impl(min_val, current, max_val, this)) {
55 ProgressItem::~ProgressItem() = default;
56 ProgressItem::Impl::~Impl() = default;
58 ProgressItem::Impl::Impl(float min_val, float current, float max_val,
60 : min_(min_val), current_(current), max_(max_val), parent_(parent) {
61 if (min_val > current || max_val < current)
62 THROW(ERROR_INVALID_PARAMETER);
64 type_ = ProgressItem::Type::Default;
65 LOGI("ProgressItem impl created");
68 int ProgressItem::GetType() const {
69 return AbstractItem::Progress;
72 Bundle ProgressItem::Serialize() const {
74 b = AbstractItem::Serialize();
75 b.Add(PROGRESS_MIN_KEY, to_string(impl_->min_));
76 b.Add(PROGRESS_CURRENT_KEY, to_string(impl_->current_));
77 b.Add(PROGRESS_MAX_KEY, to_string(impl_->max_));
78 b.Add(PROGRESS_TYPE_KEY, to_string(static_cast<int>(impl_->type_)));
79 b.Add(PROGRESS_UNIT_KEY, impl_->unit_);
83 void ProgressItem::Deserialize(Bundle b) {
84 AbstractItem::Deserialize(b);
85 impl_->min_ = strtof(b.GetString(PROGRESS_MIN_KEY).c_str(), 0);
86 impl_->current_ = strtof(b.GetString(PROGRESS_CURRENT_KEY).c_str(), 0);
87 impl_->max_ = strtof(b.GetString(PROGRESS_MAX_KEY).c_str(), 0);
88 impl_->type_ = static_cast<Type>(std::stoi(b.GetString(PROGRESS_TYPE_KEY)));
89 impl_->unit_ = b.GetString(PROGRESS_UNIT_KEY);
92 bool ProgressItem::IsItemTypeExist(int type) {
93 if (GetType() == type)
98 float ProgressItem::GetCurrent() const {
99 return impl_->current_;
102 void ProgressItem::SetCurrent(float current) {
103 impl_->current_ = current;
106 float ProgressItem::GetMin() const {
110 float ProgressItem::GetMax() const {
114 void ProgressItem::SetProgressType(ProgressItem::Type type) {
118 ProgressItem::Type ProgressItem::GetProgressType() const {
122 void ProgressItem::SetDefaultUnit(std::string unit)
127 std::string ProgressItem::GetDefaultUnit() const {
132 } // namespace notification