utils: toast popup implementation 33/90533/3
authorKamil Lipiszko <k.lipiszko@samsung.com>
Wed, 21 Sep 2016 09:32:35 +0000 (11:32 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Mon, 3 Oct 2016 10:39:59 +0000 (03:39 -0700)
Change-Id: I686649735e9beb850d4c6001ed2a2aea877b4a2b

clock/inc/Model/StopWatch.h
clock/inc/Presenter/StopWatchPresenter.h
clock/inc/Utils/PopupManager.h [new file with mode: 0644]
clock/inc/View/StopWatchView.h
clock/res/po/en_US.po
clock/src/Model/StopWatch.cpp
clock/src/Presenter/StopWatchPresenter.cpp
clock/src/Utils/PopupManager.cpp [new file with mode: 0644]
clock/src/View/StopWatchView.cpp

index ff26a40..94d7a54 100644 (file)
@@ -44,6 +44,7 @@ namespace model {
        public:
                void ClearList(void);
                void AddLap(void);
+               unsigned GetLapsCount(void);
 
                const Lap *GetLastLap(void);
        private:
index 98434ab..9ce0c45 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef _CLOCK_PRESENTER_STOPWATCH_H_
 #define _CLOCK_PRESENTER_STOPWATCH_H_
 
-#include <Elementary.h> //remove after main view has getEvasObject method
 #include <functional>
 #include <chrono>
 
diff --git a/clock/inc/Utils/PopupManager.h b/clock/inc/Utils/PopupManager.h
new file mode 100644 (file)
index 0000000..558c8a3
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016 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 <string>
+
+#include "View/View.h"
+
+#ifndef _CLOCK_UTILS_POPUP_H_
+#define _CLOCK_UTILS_POPUP_H_
+
+namespace utils {
+
+       class PopupManager {
+       public:
+               /*
+                * @brief Creates new toast popup.
+                *
+                * @param[in] parent The parent view of the popup
+                * @param[in] text The text to be shown
+                * @param[in] timeout The time after popup will be destroyed
+                *
+                */
+               static void CreatePopup(ui::IView &parent, const std::string &text, double timeout = 2.0);
+
+               /*
+                * @brief Destroys currently visible toast popup.
+                *
+                * @note Destroys before timeout elapses.
+                */
+               static void DestroyPopup();
+
+       private:
+               static Evas_Object *popup_;
+
+               PopupManager() {};
+
+               /*
+                * @brief Callback function to be called on popup dismiss.
+                *
+                */
+               static void PopupDismissedCb(void *data, Evas_Object *obj, void *event_info);
+       };
+} //namespace utils
+
+#endif //_CLOCK_UTILS_POPUP_H_
index 0ae2204..09c07cb 100644 (file)
@@ -73,9 +73,13 @@ namespace view {
 
                void DisplayTime(unsigned hour, unsigned minute, unsigned second, unsigned millisecond);
                void DisplayLapTime(unsigned hour, unsigned minute, unsigned second, unsigned millisecond);
+               void ShowMaxRecordsReachedPopup();
+
+               static const unsigned MAX_LAPS_RECORDS = 999;
+
        private:
-               view::CounterView *main_counter_;
-               view::CounterView *lap_counter_;
+               CounterView *main_counter_;
+               CounterView *lap_counter_;
 
                Evas_Object *layout_;
 
index ccb5f50..ea30f26 100644 (file)
@@ -13,3 +13,5 @@ msgstr "%d h ahead"
 msgid "IDS_CLOCK_BODY_PD_H_BEHIND_ABB"
 msgstr "%d h behind"
 
+msgid "IDS_CLOCK_MAX_RECORDS_REACHED_POPUP_ABB"
+msgstr "Maximum number of stopwatch records (%d) reached."
index 24bdfeb..280769f 100644 (file)
@@ -53,4 +53,9 @@ void StopWatch::ClearList()
        laps_.clear();
 }
 
+unsigned StopWatch::GetLapsCount()
+{
+       return laps_.size();
+}
+
 } //namespace model
index 2c44648..b97ace6 100644 (file)
@@ -104,6 +104,11 @@ void StopWatchPresenter::ResetButtonClicked()
 
 void StopWatchPresenter::LapButtonClicked()
 {
+       if (model_->GetLapsCount() >= ui_->MAX_LAPS_RECORDS) {
+               ui_->ShowMaxRecordsReachedPopup();
+               return;
+       }
+
        model_->AddLap();
 
        const model::Lap *last = model_->GetLastLap();
diff --git a/clock/src/Utils/PopupManager.cpp b/clock/src/Utils/PopupManager.cpp
new file mode 100644 (file)
index 0000000..da6b015
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016 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 "Utils/PopupManager.h"
+#include "log.h"
+
+namespace utils {
+
+Evas_Object *PopupManager::popup_;
+
+void PopupManager::CreatePopup(ui::IView &parent, const std::string &text, double timeout)
+{
+       if (popup_)
+               DestroyPopup();
+
+       popup_ = elm_popup_add(parent.GetEvasObject());
+       if (!popup_) {
+               ERR("Could not create popup");
+               return;
+       }
+
+       elm_object_style_set(popup_, "toast");
+       elm_object_text_set(popup_, text.c_str());
+       elm_popup_timeout_set(popup_, timeout);
+       elm_popup_allow_events_set(popup_, EINA_TRUE);
+
+       evas_object_smart_callback_add(popup_, "dismissed", PopupDismissedCb, NULL);
+
+       evas_object_show(popup_);
+}
+
+void PopupManager::DestroyPopup()
+{
+       if (popup_) {
+               evas_object_del(popup_);
+               popup_ = NULL;
+       }
+}
+
+void PopupManager::PopupDismissedCb(void *data, Evas_Object *obj, void *event_info)
+{
+       DestroyPopup();
+}
+
+} //namespace utils
index 7ac79cb..9f06b62 100644 (file)
@@ -18,6 +18,7 @@
 #include "View/StopWatchView.h"
 #include "Presenter/StopWatchPresenter.h"
 #include "Utils/Utils.h"
+#include "Utils/PopupManager.h"
 
 #include "log.h"
 
@@ -73,6 +74,20 @@ Evas_Object *StopWatchView::GetEvasObject()
        return layout_;
 }
 
+void StopWatchView::ShowMaxRecordsReachedPopup()
+{
+       char text[128] = {0, };
+       const char *textFormat = gettext("IDS_CLOCK_MAX_RECORDS_REACHED_POPUP_ABB");
+
+       int ret = snprintf(text, sizeof(text), textFormat, MAX_LAPS_RECORDS);
+       if (ret < 0) {
+               ERR("Could not format text");
+               return;
+       }
+
+       utils::PopupManager::CreatePopup(*this, text);
+}
+
 void StopWatchView::CreateMenuButtons()
 {
        CreateButton(layout_, "Start", "sw.btn.start", StartButtonClicked);