public:
void ClearList(void);
void AddLap(void);
+ unsigned GetLapsCount(void);
const Lap *GetLastLap(void);
private:
#ifndef _CLOCK_PRESENTER_STOPWATCH_H_
#define _CLOCK_PRESENTER_STOPWATCH_H_
-#include <Elementary.h> //remove after main view has getEvasObject method
#include <functional>
#include <chrono>
--- /dev/null
+/*
+ * 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_
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_;
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."
laps_.clear();
}
+unsigned StopWatch::GetLapsCount()
+{
+ return laps_.size();
+}
+
} //namespace model
void StopWatchPresenter::LapButtonClicked()
{
+ if (model_->GetLapsCount() >= ui_->MAX_LAPS_RECORDS) {
+ ui_->ShowMaxRecordsReachedPopup();
+ return;
+ }
+
model_->AddLap();
const model::Lap *last = model_->GetLastLap();
--- /dev/null
+/*
+ * 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
#include "View/StopWatchView.h"
#include "Presenter/StopWatchPresenter.h"
#include "Utils/Utils.h"
+#include "Utils/PopupManager.h"
#include "log.h"
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);