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/item_factory.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__"
36 namespace notification {
39 ProgressItem::ProgressItem(float min_val, float current, float max_val,
40 std::shared_ptr<AbstractAction> action)
41 : AbstractItem(AbstractItem::Progress, action),
42 impl_(new Impl(min_val, current, max_val, this)) {
45 ProgressItem::ProgressItem(string id, float min_val, float current, float max_val,
46 std::shared_ptr<AbstractAction> action)
47 : AbstractItem(id, AbstractItem::Progress, action),
48 impl_(new Impl(min_val, current, max_val, this)) {
51 ProgressItem::~ProgressItem() = default;
52 ProgressItem::Impl::~Impl() = default;
54 ProgressItem::Impl::Impl(float min_val, float current, float max_val, ProgressItem* parent)
55 : min_(min_val), current_(current), max_(max_val), parent_(parent) {
56 if (min_val > current || max_val < current)
57 THROW(NOTIFICATION_ERROR_INVALID_PARAMETER);
58 LOGI("ProgressItem impl created");
61 Bundle ProgressItem::Serialize() {
63 b = AbstractItem::Serialize();
64 b.Add(PROGRESS_MIN_KEY, to_string(impl_->min_));
65 b.Add(PROGRESS_CURRENT_KEY, to_string(impl_->current_));
66 b.Add(PROGRESS_MAX_KEY, to_string(impl_->max_));
70 void ProgressItem::Deserialize(Bundle b) {
71 AbstractItem::Deserialize(b);
72 impl_->min_ = strtof(b.GetString(PROGRESS_MIN_KEY).c_str(), 0);
73 impl_->current_ = strtof(b.GetString(PROGRESS_CURRENT_KEY).c_str(), 0);
74 impl_->max_ = strtof(b.GetString(PROGRESS_MAX_KEY).c_str(), 0);
77 AbstractItem& ProgressItem::FindByID(std::string id) {
80 return ItemFactory::GetNullItem();
83 float ProgressItem::GetCurrent() const {
84 return impl_->current_;
87 void ProgressItem::SetCurrent(float current) {
88 impl_->current_ = current;
91 float ProgressItem::GetMin() const {
95 float ProgressItem::GetMax() const {
100 } // namespace notification