std::string imagePath_ = nullptr;
}; // class ImageItem
-class EXPORT_API ProgressItem : public AbstractItem {
- public:
- ProgressItem(float min, float max, float current);
- virtual ~ProgressItem();
-
- Bundle Serialize() override;
- void Deserialize(Bundle b) override;
- AbstractItem& FindByID(std::string id) override;
- float GetCurrent() const;
- void SetCurrent(float current);
- float GetMin() const;
- float GetMax() const;
-
- private:
- float min_ = 0.0;
- float max_ = 0.0;
- float current_ = 0.0;
-}; // class ProgressItem
-
class EXPORT_API CheckBoxItem : public AbstractItem {
public:
CheckBoxItem(bool checked);
#include "notification-ex/null_item.h"
#include "notification-ex/exception.h"
#include "notification-ex/input_selector_item.h"
+#include "notification-ex/progress_item.h"
#ifdef LOG_TAG
#undef LOG_TAG
case AbstractItem::Effect :
return make_shared<ButtonItem>("");
case AbstractItem::Progress :
- return make_shared<ButtonItem>("");
+ return make_shared<ProgressItem>(0.0, 0.0, 0.0);
case AbstractItem::Custom :
return make_shared<ButtonItem>("");
}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+
+#include <memory>
+
+#include "notification-ex/exception.h"
+#include "notification-ex/progress_item.h"
+#include "notification-ex/progress_item_implementation.h"
+#include "notification-ex/item_factory.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+#define PROGRESS_MIN_KEY "__PROGRESS_MIN_KEY__"
+#define PROGRESS_CURRENT_KEY "__PROGRESS_CURRENT_KEY__"
+#define PROGRESS_MAX_KEY "__PROGRESS_MAX_KEY__"
+
+using namespace std;
+namespace notification {
+namespace item {
+
+ProgressItem::ProgressItem(float min_val, float current, float max_val,
+ std::shared_ptr<AbstractAction> action)
+ : AbstractItem(AbstractItem::Progress, action),
+ impl_(new Impl(min_val, current, max_val, this)) {
+}
+
+ProgressItem::ProgressItem(string id, float min_val, float current, float max_val,
+ std::shared_ptr<AbstractAction> action)
+ : AbstractItem(id, AbstractItem::Progress, action),
+ impl_(new Impl(min_val, current, max_val, this)) {
+}
+
+ProgressItem::~ProgressItem() = default;
+ProgressItem::Impl::~Impl() = default;
+
+ProgressItem::Impl::Impl(float min_val, float current, float max_val, ProgressItem* parent)
+ : min_(min_val), current_(current), max_(max_val), parent_(parent) {
+ if (min_val > current || max_val < current)
+ THROW(NOTIFICATION_ERROR_INVALID_PARAMETER);
+ LOGI("ProgressItem impl created");
+}
+
+Bundle ProgressItem::Serialize() {
+ Bundle b;
+ b = AbstractItem::Serialize();
+ b.Add(PROGRESS_MIN_KEY, to_string(impl_->min_));
+ b.Add(PROGRESS_CURRENT_KEY, to_string(impl_->current_));
+ b.Add(PROGRESS_MAX_KEY, to_string(impl_->max_));
+ return b;
+}
+
+void ProgressItem::Deserialize(Bundle b) {
+ AbstractItem::Deserialize(b);
+ impl_->min_ = strtof(b.GetString(PROGRESS_MIN_KEY).c_str(), 0);
+ impl_->current_ = strtof(b.GetString(PROGRESS_CURRENT_KEY).c_str(), 0);
+ impl_->max_ = strtof(b.GetString(PROGRESS_MAX_KEY).c_str(), 0);
+}
+
+AbstractItem& ProgressItem::FindByID(std::string id) {
+ if (GetId() == id)
+ return *this;
+ return ItemFactory::GetNullItem();
+}
+
+float ProgressItem::GetCurrent() const {
+ return impl_->current_;
+}
+
+void ProgressItem::SetCurrent(float current) {
+ impl_->current_ = current;
+}
+
+float ProgressItem::GetMin() const {
+ return impl_->min_;
+}
+
+float ProgressItem::GetMax() const {
+ return impl_->max_;
+}
+
+} // namespace item
+} // namespace notification
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_PROGRESS_ITEM_H_
+#define NOTIFICATION_EX_PROGRESS_ITEM_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/abstract_item.h"
+
+namespace notification {
+namespace item {
+
+class EXPORT_API ProgressItem : public AbstractItem {
+ public:
+ ProgressItem(float min, float current, float max,
+ std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+ ProgressItem(std::string id, float min, float current, float max,
+ std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+ virtual ~ProgressItem();
+
+ public:
+ virtual Bundle Serialize() override;
+ virtual void Deserialize(Bundle b) override;
+ virtual AbstractItem& FindByID(std::string id) override;
+
+ float GetCurrent() const;
+ void SetCurrent(float current);
+ float GetMin() const;
+ float GetMax() const;
+
+ private:
+ class Impl;
+ std::unique_ptr<Impl> impl_;
+};
+
+} // namespace item
+} // namespace notification
+
+#endif // NOTIFICATION_EX_PROGRESS_ITEM_H_
--- /dev/null
+
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_INPUT_SELECTOR_ITEM_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_INPUT_SELECTOR_ITEM_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/progress_item.h"
+
+namespace notification {
+namespace item {
+
+class ProgressItem::Impl {
+ public:
+ virtual ~Impl();
+
+ private:
+ Impl(float min_val, float current, float max_val,
+ ProgressItem* parent);
+
+ private:
+ friend class ProgressItem;
+
+ float min_;
+ float current_;
+ float max_;
+ ProgressItem* parent_;
+};
+
+} // namespace item
+} // namespace notification
+
+#endif // NOTIFICATION_EX_INPUT_SELECTOR_ITEM_IMPLEMENTATION_H_
--- /dev/null
+// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include <gmock/gmock.h>
+
+#include "notification-ex/progress_item.h"
+#include "notification-ex/item_inflator.h"
+
+using namespace notification::item;
+using namespace std;
+
+namespace {
+
+class ProgressItemTest : public ::testing::Test {
+ protected:
+ void SetUp() override {}
+ void TearDown() override {}
+};
+
+TEST_F(ProgressItemTest, SerializeDeserializeGetTitle) {
+ ProgressItem item(1.0, 10.0, 100.0);
+ Bundle b = item.Serialize();
+ ItemFactory factory;
+ shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
+
+ ProgressItem* gen_progress = static_cast<ProgressItem*>(gen_item.get());
+ ASSERT_EQ(item.GetCurrent(), gen_progress->GetCurrent());
+ ASSERT_EQ(item.GetMin(), gen_progress->GetMin());
+ ASSERT_EQ(item.GetMax(), gen_progress->GetMax());
+
+ ASSERT_EQ(gen_progress->GetMin(), 1.0);
+ ASSERT_EQ(gen_progress->GetCurrent(), 10.0);
+ ASSERT_EQ(gen_progress->GetMax(), 100.0);
+}
+
+} // namespace