TizenRefApp-5593 Implement Progress bar popup 96/58496/2
authorNataliia Sydorchuk <n.sydorchuk@samsung.com>
Mon, 1 Feb 2016 14:23:07 +0000 (16:23 +0200)
committerNataliia Sydorchuk <n.sydorchuk@samsung.com>
Mon, 1 Feb 2016 14:23:07 +0000 (16:23 +0200)
Change-Id: I0c569922ba3ea68082d2e4fd5a760d23bed0fad3
Signed-off-by: Nataliia Sydorchuk <n.sydorchuk@samsung.com>
lib-common/inc/Ui/ProgressPopup.h [new file with mode: 0644]
lib-common/res/common/edje/CommonProgressbarLayout.h [new file with mode: 0644]
lib-common/res/common/edje/common-progressbar-layout.edc [new file with mode: 0644]
lib-common/src/Ui/ProgressPopup.cpp [new file with mode: 0644]

diff --git a/lib-common/inc/Ui/ProgressPopup.h b/lib-common/inc/Ui/ProgressPopup.h
new file mode 100644 (file)
index 0000000..b6c67fc
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 UI_PROGRESS_POPUP_H
+#define UI_PROGRESS_POPUP_H
+
+#include "Ui/Popup.h"
+
+namespace Ui
+{
+       class EXPORT_API ProgressPopup : public Popup
+       {
+       public:
+               /**
+                * @brief Create progress popup.
+                * @param[in]   maxValue    Max value of progressbar
+                */
+               ProgressPopup(size_t maxValue);
+
+               /**
+                * @brief Set progress of the progressbar
+                * @param[in]   value   Progress value
+                */
+               void setProgress(size_t value);
+
+       private:
+               virtual Evas_Object *onCreate(Evas_Object *parent) override;
+
+       private:
+               size_t m_MaxValue;
+               Evas_Object *m_Progressbar;
+       };
+}
+
+#endif /* UI_PROGRESS_POPUP_H */
diff --git a/lib-common/res/common/edje/CommonProgressbarLayout.h b/lib-common/res/common/edje/CommonProgressbarLayout.h
new file mode 100644 (file)
index 0000000..5ce9b7c
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 COMMON_PROGRESSBAR_LAYOUT_H
+#define COMMON_PROGRESSBAR_LAYOUT_H
+
+#include "CommonPath.h"
+
+#define COMMON_PROGRESSBAR_LAYOUT_EDJ      COMMON_EDJ_DIR"common-progressbar-layout.edj"
+
+#define GROUP_PROGRESSBAR_LAYOUT       "progressbar_layout"
+
+#define PART_PROGRESSBAR           "swallow.progressbar"
+
+#define PROGRESSBAR_PAD_X          32
+#define PROGRESSBAR_PAD_Y          17
+
+#endif /* COMMON_PROGRESSBAR_LAYOUT_H */
diff --git a/lib-common/res/common/edje/common-progressbar-layout.edc b/lib-common/res/common/edje/common-progressbar-layout.edc
new file mode 100644 (file)
index 0000000..4bfdc58
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 "CommonProgressbarLayout.h"
+
+collections {
+       base_scale: 2.6;
+       group {
+               name: GROUP_PROGRESSBAR_LAYOUT;
+
+               parts {
+                       spacer { "spacer.top"; scale;
+                               desc { "default";
+                                       min: 0 PROGRESSBAR_PAD_Y;
+                                       align: 0.5 0.0;
+                                       rel1.relative: 0.0 0.0;
+                                       rel2.relative: 1.0 0.0;
+                               }
+                       }
+                       spacer { "spacer.left"; scale;
+                               desc { "default";
+                                       min: PROGRESSBAR_PAD_X 0;
+                                       align: 0.0 0.5;
+                                       rel1.relative: 0.0 0.0;
+                                       rel2.relative: 0.0 1.0;
+                               }
+                       }
+                       spacer { "spacer.right"; scale;
+                               desc { "default";
+                                       min: PROGRESSBAR_PAD_X 0;
+                                       align: 1.0 0.5;
+                                       rel1.relative: 1.0 0.0;
+                                       rel2.relative: 1.0 1.0;
+                               }
+                       }
+                       spacer { "spacer.bottom"; scale;
+                               desc { "default";
+                                       min: 0 PROGRESSBAR_PAD_Y;
+                                       align: 0.5 1.0;
+                                       rel1.relative: 0.0 1.0;
+                                       rel2.relative: 1.0 1.0;
+                               }
+                       }
+                       swallow { PART_PROGRESSBAR; scale;
+                               desc { "default";
+                                       rel1 { relative: 1.0 1.0; to_x: "spacer.left"; to_y: "spacer.top"; }
+                                       rel2 { relative: 0.0 0.0; to_x: "spacer.right"; to_y: "spacer.bottom"; }
+                               }
+                       }
+               }
+       }
+}
\ No newline at end of file
diff --git a/lib-common/src/Ui/ProgressPopup.cpp b/lib-common/src/Ui/ProgressPopup.cpp
new file mode 100644 (file)
index 0000000..f41f4ee
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 "App/Path.h"
+#include "Ui/ProgressPopup.h"
+#include "Utils/Logger.h"
+
+#include "CommonProgressbarLayout.h"
+
+#define BUFFER_SIZE        64
+
+#define ZERO_PROGRESS      "0%"
+
+using namespace Ui;
+
+namespace
+{
+       const std::string layoutFilePath = App::getResourcePath(COMMON_PROGRESSBAR_LAYOUT_EDJ);
+}
+
+ProgressPopup::ProgressPopup(size_t maxValue)
+       : m_MaxValue(maxValue), m_Progressbar(nullptr)
+{
+}
+
+void ProgressPopup::setProgress(size_t value)
+{
+       RETM_IF(value > m_MaxValue, "value is bigger than max value");
+       double progressValue = (double)value / m_MaxValue;
+
+       char progress[BUFFER_SIZE] = { 0, };
+       snprintf(progress, sizeof(progress), "%d%%", (int)(100.0 * progressValue));
+
+       char total[BUFFER_SIZE] = { 0, };
+       snprintf(total, sizeof(total), "%d/%d", value, m_MaxValue);
+
+       elm_progressbar_value_set(m_Progressbar, progressValue);
+       elm_object_part_text_set(m_Progressbar, "elm.text.bottom.left", progress);
+       elm_object_part_text_set(m_Progressbar, "elm.text.bottom.right", total);
+}
+
+Evas_Object *ProgressPopup::onCreate(Evas_Object *parent)
+{
+       Evas_Object *popup = Popup::onCreate(parent);
+
+       Evas_Object *layout = elm_layout_add(popup);
+       elm_layout_file_set(layout, layoutFilePath.c_str(), GROUP_PROGRESSBAR_LAYOUT);
+
+       m_Progressbar = elm_progressbar_add(layout);
+       elm_progressbar_pulse(m_Progressbar, EINA_TRUE);
+
+       char total[BUFFER_SIZE] = { 0, };
+       snprintf(total, sizeof(total), "%d/%d", 0, m_MaxValue);
+       elm_object_part_text_set(m_Progressbar, "elm.text.bottom.left", ZERO_PROGRESS);
+       elm_object_part_text_set(m_Progressbar, "elm.text.bottom.right", total);
+
+       elm_object_part_content_set(layout, PART_PROGRESSBAR, m_Progressbar);
+       elm_object_content_set(popup, layout);
+
+       return popup;
+}