--- /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.
+ */
+
+#ifndef _CLOCK_COMMON_COUNTER_ANIMATOR_H_
+#define _CLOCK_COMMON_COUNTER_ANIMATOR_H_
+
+#include <Ecore.h>
+#include <vector>
+#include <functional>
+
+namespace common {
+
+ class CounterAnimator {
+ public:
+ CounterAnimator();
+ ~CounterAnimator();
+
+ bool Start(void);
+ bool Stop(void);
+ bool Resume(void);
+ void Remove(void);
+
+ void SetFrametime(double time);
+
+ void RegisterSignal(std::function<void(void)>func);
+
+ private:
+ Ecore_Animator *animator_;
+
+
+ std::vector<std::function<void(void)>> signals_;
+
+ void EmitSignal(void);
+ static Eina_Bool Task(void *data);
+ };
+}
+
+#endif //_CLOCK_COMMON_COUNTER_ANIMATOR_H_
--- /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.
+ */
+
+#ifndef _CLOCK_MODEL_COUNTER_H_
+#define _CLOCK_MODEL_COUNTER_H_
+
+#include <chrono>
+#include <string>
+#include <vector>
+#include <Ecore.h>
+
+namespace model {
+
+ class Counter {
+ public:
+ Counter();
+ ~Counter();
+
+ bool Run(void);
+ bool Stop(void);
+ bool Reset(void);
+ bool Resume(void);
+
+ std::chrono::milliseconds GetTime(void);
+ std::chrono::milliseconds GetTimeSinceEpoch(void);
+ std::chrono::milliseconds GetStartTime(void);
+
+ private:
+ std::chrono::milliseconds start_time_;
+ std::chrono::milliseconds pause_time_;
+ };
+}
+
+#endif //_CLOCK_MODEL_COUNTER_H_
-#ifndef _CLOCK_STOPWATCH_H_
-#define _CLOCK_STOPWATCH_H_
+/*
+ * 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.
+ */
+
+#ifndef _CLOCK_MODEL_STOPWATCH_H_
+#define _CLOCK_MODEL_STOPWATCH_H_
+
+#include <chrono>
+#include <vector>
+
+#include "Model/Counter.h"
namespace model {
- class StopWatch {
- public:
- void Start();
- void Stop();
- void EndLap();
- void Reset();
- time_t ElapsedTime();
- std::vector<StopWatchLap> GetLaps();
- private:
- time_t start_time;
- std::vector<StopWatchLap> laps;
+
+ class Lap {
+ public:
+ inline std::chrono::milliseconds GetTime(void) const { return lap_time_; };
+ inline std::chrono::milliseconds GetSplitTime(void) const { return split_time_; };
+ inline unsigned GetNo(void) const { return No_; };
+
+ inline void SetTime(std::chrono::milliseconds time) { lap_time_ = time; };
+ inline void SetSplitTime(std::chrono::milliseconds time) { split_time_ = time; };
+ inline void SetNo(unsigned num) { No_ = num; };
+ private:
+ unsigned No_;
+
+ std::chrono::milliseconds split_time_;
+ std::chrono::milliseconds lap_time_;
+ };
+
+ class StopWatch : public Counter {
+ public:
+ void ClearList(void);
+ void AddLap(void);
+
+ const Lap *GetLastLap(void);
+ private:
+ std::vector<Lap *> laps_;
};
-} /* model */
+}
-#endif
+#endif //_CLOCK_MODEL_STOPWATCH_H_
+++ /dev/null
-#ifndef _CLOCK_STOPWATCH_LAP_H_
-#define _CLOCK_STOPWATCH_LA_H_
-
-namespace model {
- class StopWatchLap {
- public:
- StopWatchLap(time_t start, time_t duration);
- ~StopWatchLap();
- time_t LapDuration();
- time_t LapStartTime();
- };
-} /* model */
-
-#endif
--- /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.
+ */
+
+#ifndef _CLOCK_PRESENTER_STOPWATCH_H_
+#define _CLOCK_PRESENTER_STOPWATCH_H_
+
+#include <Elementary.h> //remove after main view has getEvasObject method
+#include <functional>
+#include <chrono>
+
+#include "View/StopWatchView.h"
+#include "View/CounterView.h"
+#include "View/View.h"
+#include "Model/StopWatch.h"
+#include "Common/CounterAnimator.h"
+#include "Utils/Time.h"
+
+namespace presenter {
+
+ class StopWatchPresenter {
+ public:
+ StopWatchPresenter(view::StopWatchView *ui, model::StopWatch *model);
+ ~StopWatchPresenter();
+
+ private:
+ view::StopWatchView *ui_;
+ model::StopWatch *model_;
+
+ common::CounterAnimator animator_;
+
+ void StartButtonClicked(void);
+ void StopButtonClicked(void);
+ void ResumeButtonClicked(void);
+ void ResetButtonClicked(void);
+ void LapButtonClicked(void);
+ void TimeUpdateRequest(void);
+
+ std::string GetTimeString(std::chrono::milliseconds time);
+ utils::Time GetTimeStructure(std::chrono::milliseconds time);
+ };
+}
+
+#endif //_CLOCK_PRESENTER_STOPWATCH_H_
+++ /dev/null
-#ifndef _CLOCK_UI_VIEW_H_
-#define _CLOCK_UI_VIEW_H_
-
-#include <Elementary.h>
-
-namespace ui {
- class IView {
- public:
- virtual Evas_Object *GetEvasObject() = 0;
- };
-};
-
-#endif
};
class CLOCK_EXPORT_API Time : public utils::ISerializable {
public:
- unsigned int Hour, Min, Sec;
- Time() : Hour(0), Min(0), Sec(0) {}
- Time(unsigned int h, unsigned int m, unsigned int s) : Hour(h), Min(m), Sec(s) {}
+ unsigned int Hour, Min, Sec, Msec;
+ Time() : Hour(0), Min(0), Sec(0) , Msec(0) {}
+ Time(unsigned int h, unsigned int m, unsigned int s, unsigned int ms = 0) : Hour(h), Min(m), Sec(s), Msec(ms) {}
Time(utils::IReader &);
void Serialize(utils::IWriter &w) const;
inline bool operator==(const Time &a) { return (a.Hour == Hour ) &&
- (a.Min == Min) && (a.Sec == Sec); }
+ (a.Min == Min) && (a.Sec == Sec) && (a.Msec == Msec); }
std::string Format(enum Format format) const;
std::string Meridiem() const;
std::string getFormattedTime(const char *icu_format) const;
#ifndef ALARMVIEW_H_
#define ALARMVIEW_H_
-#include "UI/View.h"
+#include "View/View.h"
#include "Model/WeekFlags.h"
#include "Utils/Time.h"
--- /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.
+ */
+
+#ifndef _CLOCK_VIEW_COUNTER_H_
+#define _CLOCK_VIEW_COUNTER_H_
+
+#include <Elementary.h>
+
+#include "View/View.h"
+
+namespace view {
+
+ enum class CounterType {
+ COUNTER_TYPE_STOPWATCH,
+ COUNTER_TYPE_SIMPLE,
+ COUNTER_TYPE_TIMER
+ };
+
+ class CounterView : public ui::IView {
+ public:
+ CounterView(ui::IView &parent, CounterType type = CounterType::COUNTER_TYPE_STOPWATCH);
+ ~CounterView();
+
+ Evas_Object *GetEvasObject(void);
+
+ void DisplayTime(int hour, int min, int sec, int msec);
+
+ void Expand(void);
+ void Contract(void);
+ void Show(void);
+ void Hide(void);
+ void Reset(void);
+
+ bool IsVisible(void);
+ private:
+ Evas_Object *layout_;
+
+ CounterType type_;
+ bool visible_;
+
+ static const char *EDJE_FILE;
+ static const char *GROUP;
+ static const char *GROUP_EXPANDED;
+ static const char *GROUP_TIMER;
+ static const char *GROUP_SIMPLE;
+ static const char *GROUP_SIMPLE_EXPANDED;
+
+ const char *GetEdjeFilePath(void);
+
+ bool SetDigitText(const char *text, unsigned col);
+ bool SetTheme(CounterType type, bool expand = false);
+ };
+}
+
+
+#endif //_CLOCK_VIEW_COUNTER_H_
#include <Evas.h>
#include "View/PageView.h"
-#include "UI/View.h"
+#include "View/View.h"
/**
* @file MainView.h
#define NAVIFRAME_PAGE_VIEW_H_
#include <Elementary.h>
-#include "UI/View.h"
+#include "View/View.h"
/**
* @file pageView.h
* limitations under the License.
*/
-#ifndef STOPWATCHVIEW_H_
-#define STOPWATCHVIEW_H_
+#ifndef _CLOCK_VIEW_STOPWATCH_H_
+#define _CLOCK_VIEW_STOPWATCH_H_
-#include "View/PageView.h"
-#include "UI/View.h"
+#include <Elementary.h>
+#include <functional>
+#include <vector>
+
+#include "View/CounterView.h"
+#include "View/View.h"
+
+#define PART_LAP_NO "txt.lap.no"
+#define PART_LAP_SPLIT "txt.lap.split"
+#define PART_LAP_TIME "txt.lap.time"
namespace view {
+ enum class Signal {
+ BUTTON_START_CLICKED,
+ BUTTON_STOP_CLICKED,
+ BUTTON_LAP_CLICKED,
+ BUTTON_RESUME_CLICKED,
+ BUTTON_RESET_CLICKED,
+ MAX
+ };
+
+ class Lap {
+ public:
+ Lap(const char *no, const char *splitTime, const char *lapTime);
+ ~Lap();
+
+ char *GetNo(void) {return No_; };
+ char *GetSplitTime(void) {return split_time_; };
+ char *GetLapTime(void) {return lap_time_; };
+
+ private:
+ char *No_;
+ char *split_time_;
+ char *lap_time_;
+ };
+
class StopWatchView : public ui::IView {
- public:
+ public:
StopWatchView();
- Evas_Object *GetEvasObject(){return stopwatch_;};
+ ~StopWatchView();
+
+ Evas_Object *GetEvasObject(void);
+
+ void RegisterSignal(std::function<void(void)>func, Signal type);
+ void ShowRunningMenu(void);
+ void ShowStoppedMenu(void);
+ void ShowStartupMenu(void);
+
+ void AddLap(const char *no, const char *splitTime, const char *lapTime);
+ void HideList(void);
+ void ShowList(void);
+
+ void DisplayTime(unsigned hour, unsigned minute, unsigned second, unsigned millisecond);
+ void DisplayLapTime(unsigned hour, unsigned minute, unsigned second, unsigned millisecond);
private:
- Evas_Object *stopwatch_;
+ view::CounterView *main_counter_;
+ view::CounterView *lap_counter_;
+
+ Evas_Object *layout_;
+
+ void CreateButton(Evas_Object *parent, const char *name,
+ const char *part, Evas_Smart_Cb cb);
+ void CreateMenuButtons(void);
+ Evas_Object *CreateList(void);
+ void FreeListItemsData(Evas_Object *list);
+ void EmitSignal(Signal type);
+
+ const char *GetEdjeFilePath(void);
+
+ std::vector<std::function<void(void)>> signals
+ = std::vector<std::function<void(void)>> ((int)Signal::MAX, nullptr);
+
+ static const char *EDJE_FILE;
+ static const char *GROUP;
+
+ static const Elm_Genlist_Item_Class list_itc;
+
+ static char *GetListText(void *data, Evas_Object *obj, const char *part);
+
+ static void StartButtonClicked(void *data, Evas_Object *obj, void *event_info);
+ static void StopButtonClicked(void *data, Evas_Object *obj, void *event_info);
+ static void LapButtonClicked(void *data, Evas_Object *obj, void *event_info);
+ static void ResumeButtonClicked(void *data, Evas_Object *obj, void *event_info);
+ static void ResetButtonClicked(void *data, Evas_Object *obj, void *event_info);
};
}
-#endif /* STOPWATCHVIEW_H_ */
+#endif //_CLOCK_VIEW_STOPWATCH_H_
* limitations under the License.
*/
-#ifndef TIMERVIEW_H_
-#define TIMERVIEW_H_
+#ifndef _CLOCK_VIEW_TIMER_H_
+#define _CLOCK_VIEW_TIMER_H_
#include "View/PageView.h"
-#include "UI/View.h"
+#include "View/View.h"
namespace view {
class TimerView : public ui::IView {
};
}
-#endif /* TIMERVIEW_H_ */
+#endif //_CLOCK_VIEW_TIMER_H_
#include <Elementary.h>
-namespace worldclock {
- namespace view {
- class IView {
- public:
- virtual Evas_Object *GetEvasObject() = 0;
- virtual ~IView(){};
- };
+namespace ui {
+ class IView {
+ public:
+ virtual Evas_Object *GetEvasObject() = 0;
};
};
#define WORLDCLOCKVIEW_H_
#include "View/PageView.h"
-#include "UI/View.h"
+#include "View/View.h"
namespace view {
class WorldClockView : public ui::IView {
profile = mobile-3.0
# C Sources
-USER_SRCS = src/*.cpp src/Controller/*.cpp src/View/*.cpp src/Presenter/*.cpp src/Model/*.cpp src/Utils/*.cpp
+USER_SRCS = src/*.cpp src/Controller/*.cpp src/View/*.cpp src/Presenter/*.cpp src/Model/*.cpp src/Utils/*.cpp src/Common/*.cpp
USER_SRCS_ABS =
# EDC Sources
# EDC Flags
USER_EXT_EDC_KEYS = EDC0
-USER_EXT_EDC0_EDCS = res/edje/clock.edc res/edje/alarm.edc
+USER_EXT_EDC0_EDCS = res/edje/clock.edc res/edje/alarm.edc res/edje/StopWatch.edc res/edje/Counter.edc
USER_EXT_EDC0_EDCS_IMAGE_DIRS = edje/images
USER_EXT_EDC0_EDCS_IMAGE_DIRS_ABS =
USER_EXT_EDC0_EDCS_SOUND_DIRS = edje/sounds
--- /dev/null
+collections {
+
+ styles {
+ style {
+ name: "ATO010";
+ base: "font=Tizen:style=Thin color=#FAFAFA wrap=none font_size=160 align=center";
+ }
+ style {
+ name: "ATO011";
+ base: "font=Tizen:style=Thin color=#FAFAFA wrap=none font_size=170 align=center";
+ }
+ style {
+ name: "ATO011L";
+ base: "font=Tizen:style=Thin color=#FAFAFA wrap=none font_size=150 align=center";
+ }
+ style {
+ name: "ATO012";
+ base: "font=Tizen:style=Thin color=#FAFAFA wrap=none font_size=108 align=center";
+ }
+ style {
+ name: "ATO012L";
+ base: "font=Tizen:style=Thin color=#FAFAFA wrap=none font_size=88 align=center";
+ }
+ }
+
+ base_scale: 2.6;
+
+ group { "Digit";
+ parts {
+ textblock { "digit";
+ desc { "default";
+ text.style: "ATO011";
+ }
+ desc { "default.expanded";
+ text.style: "ATO011L";
+ }
+ desc { "simple";
+ text.style: "ATO012L";
+ }
+ desc { "timer";
+ text.style: "ATO010";
+ }
+ }
+ program {
+ signal: "digits,set,stopwatch,expand";
+ source: "counter";
+ action: STATE_SET "default.expanded";
+ target: "digit";
+ }
+ program {
+ signal: "digits,set,stopwatch,contract";
+ source: "counter";
+ action: STATE_SET "default";
+ target: "digit";
+ }
+ program {
+ signal: "digits,set,simple";
+ source: "counter";
+ action: STATE_SET "simple";
+ target: "digit";
+ }
+ program {
+ signal: "digits,set,timer";
+ source: "counter";
+ action: STATE_SET "timer";
+ target: "digit";
+ }
+ }
+ }
+
+ group { "ExtraDigit";
+ parts {
+ textblock { "digit"; scale;
+ desc { "default";
+ max: -1 145;
+ rel1.offset: 0 65;
+ rel2.offset: 0 -17;
+ text.style: "ATO012";
+ }
+ desc { "default.expanded";
+ inherit: "default";
+ max: -1 117;
+ rel1.offset: 0 66;
+ rel2.offset: 0 -17;
+ text.style: "ATO012L";
+ }
+ desc { "simple";
+ text.style: "ATO012L";
+ }
+ }
+ program {
+ signal: "digits,set,stopwatch,expand";
+ source: "counter";
+ action: STATE_SET "default.expanded";
+ target: "digit";
+ }
+ program {
+ signal: "digits,set,stopwatch,contract";
+ source: "counter";
+ action: STATE_SET "default";
+ target: "digit";
+ }
+ program {
+ signal: "digits,set,simple";
+ source: "counter";
+ action: STATE_SET "simple";
+ target: "digit";
+ }
+ }
+ }
+
+ group { "Colon";
+ parts {
+ textblock { "colon";
+ desc { "default";
+ text {
+ style: "ATO011";
+ text: ":";
+ }
+ }
+ desc { "default.expanded";
+ inherit: "default";
+ text.style: "ATO011L";
+ }
+ desc { "simple";
+ inherit: "default";
+ text.style: "ATO012L";
+ }
+ desc { "timer";
+ inherit: "default";
+ text.style: "ATO010";
+ }
+ }
+ program {
+ signal: "digits,set,stopwatch,expand";
+ source: "counter";
+ action: STATE_SET "default.expanded";
+ target: "colon";
+ }
+ program {
+ signal: "digits,set,stopwatch,contract";
+ source: "counter";
+ action: STATE_SET "default";
+ target: "colon";
+ }
+ program {
+ signal: "digits,set,simple";
+ source: "counter";
+ action: STATE_SET "simple";
+ target: "colon";
+ }
+ program {
+ signal: "digits,set,timer";
+ source: "counter";
+ action: STATE_SET "timer";
+ target: "colon";
+ }
+ }
+ }
+
+ group { "Dot";
+ parts {
+ textblock { "dot"; scale;
+ desc { "default";
+ rel1.offset: 0 66;
+ rel2.offset: 0 -17;
+ text {
+ style: "ATO012";
+ text: ".";
+ }
+ }
+ desc { "default.expanded";
+ inherit: "default";
+ text.style: "ATO012L";
+ rel1.offset: 0 65;
+ }
+ desc { "simple";
+ text.style: "ATO012L";
+ text.text: ".";
+ }
+ }
+ program {
+ signal: "digits,set,stopwatch,expand";
+ source: "counter";
+ action: STATE_SET "default.expanded";
+ target: "dot";
+ }
+ program {
+ signal: "digits,set,stopwatch,contract";
+ source: "counter";
+ action: STATE_SET "default";
+ target: "dot";
+ }
+ program {
+ signal: "digits,set,simple";
+ source: "counter";
+ action: STATE_SET "simple";
+ target: "dot";
+ }
+ }
+ }
+
+ group { "Counter";
+ parts {
+ table { "digits"; scale;
+ desc { "default";
+ max: 528 -1;
+ }
+ desc { "hidden";
+ inherit: "default";
+ hid;
+ }
+ table {
+ items {
+ #define ITEM(part_name, source_name, pos, wg) \
+ item { \
+ source: source_name; \
+ name: part_name; \
+ position: pos 0; \
+ weight: wg 1.0; \
+ span: 1 1; \
+ align: -1.0 -1.0; \
+ }
+ ITEM("m.digit.1", "Digit", 3, 1.0);
+ ITEM("m.digit.2", "Digit", 4, 1.0);
+ ITEM("s.colon", "Colon", 5, 0.15);
+ ITEM("s.digit.1", "Digit", 6, 1.0);
+ ITEM("s.digit.2", "Digit", 7, 1.0);
+ ITEM("ms.dot", "Dot", 8, 0.15);
+ ITEM("ms.digit.1", "ExtraDigit", 9, 0.7);
+ ITEM("ms.digit.2", "ExtraDigit", 10, 0.7);
+ }
+ }
+ }
+ program {
+ signal: "counter,set,hidden";
+ source: "counter";
+ action: STATE_SET "hidden";
+ target: "digits";
+ }
+ program {
+ signal: "counter,set,visible";
+ source: "counter";
+ action: STATE_SET "default";
+ target: "digits";
+ }
+ }
+ }
+
+ group { "Counter.expanded";
+ parts {
+ table { "digits"; scale;
+ desc { "default";
+ max: 648 -1;
+ }
+ desc { "hidden";
+ inherit: "default";
+ hid;
+ }
+ table {
+ items {
+ #define ITEM(part_name, source_name, pos, wg) \
+ item { \
+ source: source_name; \
+ name: part_name; \
+ position: pos 0; \
+ weight: wg 1.0; \
+ span: 1 1; \
+ align: -1.0 -1.0; \
+ }
+ ITEM("h.digit.1", "Digit", 0, 1.0);
+ ITEM("h.digit.2", "Digit", 1, 1.0);
+ ITEM("m.colon", "Colon", 2, 0.15);
+ ITEM("m.digit.1", "Digit", 3, 1.0);
+ ITEM("m.digit.2", "Digit", 4, 1.0);
+ ITEM("s.colon", "Colon", 5, 0.15);
+ ITEM("s.digit.1", "Digit", 6, 1.0);
+ ITEM("s.digit.2", "Digit", 7, 1.0);
+ ITEM("ms.dot", "Dot", 8, 0.15);
+ ITEM("ms.digit.1", "ExtraDigit", 9, 0.7);
+ ITEM("ms.digit.2", "ExtraDigit", 10, 0.7);
+ }
+ }
+ }
+ program {
+ signal: "counter,set,hidden";
+ source: "counter";
+ action: STATE_SET "hidden";
+ target: "digits";
+ }
+ program {
+ signal: "counter,set,visible";
+ source: "counter";
+ action: STATE_SET "default";
+ target: "digits";
+ }
+ }
+ }
+
+ group { "Counter.simple";
+ parts {
+ table { "digits"; scale;
+ desc { "default";
+ max: 350 -1;
+ }
+ desc { "hidden";
+ inherit: "default";
+ hid;
+ }
+ table {
+ items {
+ #define ITEM(part_name, source_name, pos, wg) \
+ item { \
+ source: source_name; \
+ name: part_name; \
+ position: pos 0; \
+ weight: wg 1.0; \
+ span: 1 1; \
+ align: -1.0 -1.0; \
+ }
+ ITEM("m.digit.1", "Digit", 3, 1.0);
+ ITEM("m.digit.2", "Digit", 4, 1.0);
+ ITEM("s.colon", "Colon", 5, 0.15);
+ ITEM("s.digit.1", "Digit", 6, 1.0);
+ ITEM("s.digit.2", "Digit", 7, 1.0);
+ ITEM("ms.dot", "Dot", 8, 0.15);
+ ITEM("ms.digit.1", "ExtraDigit", 9, 1.0);
+ ITEM("ms.digit.2", "ExtraDigit", 10, 1.0);
+ }
+ }
+ }
+ program {
+ signal: "counter,set,hidden";
+ source: "counter";
+ action: STATE_SET "hidden";
+ target: "digits";
+ }
+ program {
+ signal: "counter,set,visible";
+ source: "counter";
+ action: STATE_SET "default";
+ target: "digits";
+ }
+ }
+ }
+
+ group { "Counter.simple.expanded";
+ parts {
+ table { "digits"; scale;
+ desc { "default";
+ max: 469 -1;
+ }
+ desc { "hidden";
+ inherit: "default";
+ hid;
+ }
+ table {
+ items {
+ #define ITEM(part_name, source_name, pos, wg) \
+ item { \
+ source: source_name; \
+ name: part_name; \
+ position: pos 0; \
+ weight: wg 1.0; \
+ span: 1 1; \
+ align: -1.0 -1.0; \
+ }
+ ITEM("h.digit.1", "Digit", 0, 1.0);
+ ITEM("h.digit.2", "Digit", 1, 1.0);
+ ITEM("m.colon", "Colon", 2, 0.15);
+ ITEM("m.digit.1", "Digit", 3, 1.0);
+ ITEM("m.digit.2", "Digit", 4, 1.0);
+ ITEM("s.colon", "Colon", 5, 0.15);
+ ITEM("s.digit.1", "Digit", 6, 1.0);
+ ITEM("s.digit.2", "Digit", 7, 1.0);
+ ITEM("ms.dot", "Dot", 8, 0.15);
+ ITEM("ms.digit.1", "ExtraDigit", 9, 1.0);
+ ITEM("ms.digit.2", "ExtraDigit", 10, 1.0);
+ }
+ }
+ }
+ program {
+ signal: "counter,set,hidden";
+ source: "counter";
+ action: STATE_SET "hidden";
+ target: "digits";
+ }
+ program {
+ signal: "counter,set,visible";
+ source: "counter";
+ action: STATE_SET "default";
+ target: "digits";
+ }
+ }
+ }
+
+
+ group { "Counter.timer";
+ parts {
+ textblock { "sign"; scale;
+ desc { "default";
+ max: 36 -1;
+ align: 1.0 0.5;
+ rel1 { to_y: "digits"; }
+ rel2 { relative: 0.0 1.0; to: "digits"; }
+ text {
+ style: "ATO010";
+ text: "-";
+ align: 1.0 0.5;
+ }
+ hid;
+ }
+ desc { "visible";
+ inherit: "default";
+ vis;
+ }
+ desc { "hidden";
+ inherit: "default";
+ }
+ }
+ table { "digits"; scale;
+ desc { "default";
+ max: 620 -1;
+ }
+ desc { "hidden";
+ inherit: "default";
+ hid;
+ }
+ desc { "visible";
+ inherit: "default";
+ vis;
+ }
+ table {
+ items {
+ #define ITEM(part_name, source_name, pos, wg) \
+ item { \
+ source: source_name; \
+ name: part_name; \
+ position: pos 0; \
+ weight: wg 1.0; \
+ span: 1 1; \
+ align: -1.0 -1.0; \
+ }
+ ITEM("h.digit.1", "Digit", 0, 1.0);
+ ITEM("h.digit.2", "Digit", 1, 1.0);
+ ITEM("m.colon", "Colon", 2, 0.15);
+ ITEM("m.digit.1", "Digit", 3, 1.0);
+ ITEM("m.digit.2", "Digit", 4, 1.0);
+ ITEM("s.colon", "Colon", 5, 0.15);
+ ITEM("s.digit.1", "Digit", 6, 1.0);
+ ITEM("s.digit.2", "Digit", 7, 1.0);
+ }
+ }
+ }
+ program {
+ signal: "counter,set,hidden";
+ source: "counter";
+ action: STATE_SET "hidden";
+ target: "sign";
+ target: "digits";
+ }
+ program {
+ signal: "counter,set,visible";
+ source: "counter";
+ action: STATE_SET "visible";
+ target: "digits";
+ }
+ program {
+ signal: "counter,show,sign";
+ source: "counter";
+ action: STATE_SET "visible";
+ target: "sign";
+ }
+ }
+ }
+}
--- /dev/null
+collections {
+
+ base_scale: 2.6;
+
+ group { "StopWatch";
+ parts {
+ rect { "btn.bg"; scale;
+ desc { "default";
+ min: 0 0;
+ max: -1 150;
+ align: 0.5 1.0;
+ color: 255 255 255 255;
+ }
+ }
+ rect { "pd.btn.bg"; scale;
+ desc { "default";
+ min: 0 40;
+ max: -1 40;
+ align: 0.5 1.0;
+ color: 240 240 240 255;
+ rel2 { relative: 1.0 0.0; to: "btn.bg"; }
+ hid;
+ }
+ desc { "list.visible";
+ inherit: "default";
+ vis;
+ }
+ }
+ spacer { "pd.bottom"; scale;
+ desc { "default";
+ min: 0 95;
+ max: -1 95;
+ align: 0.5 1.0;
+ rel2 { relative: 1.0 0.0; to: "btn.bg"; }
+ }
+ desc { "expanded";
+ inherit: "default";
+ min: 0 80;
+ max: -1 80;
+ }
+ desc { "list.visible";
+ inherit: "default";
+ min: 0 57;
+ max: -1 57;
+ rel2 { relative: 1.0 0.0; to: "sw.list"; }
+ }
+ }
+ swallow { "sw.counter"; scale;
+ desc { "default";
+ min: 0 227;
+ max: -1 227;
+ align: 0.5 0.5;
+ rel2 { relative: 1.0 0.0; to: "pd.bottom"; }
+ }
+ desc { "expanded";
+ inherit: "default";
+ min: 0 200;
+ max: -1 200;
+ }
+ }
+ swallow { "sw.lap.counter"; scale;
+ desc { "default";
+ min: 0 100;
+ max: -1 100;
+ align: 0.5 0.0;
+ rel1 { relative: 0.0 1.0; to: "sw.counter"; }
+ rel2 { relative: 1.0 1.0; to_x: "sw.counter"; }
+ }
+ }
+ swallow { "sw.subcounter"; scale;
+ desc { "default";
+ min: 0 0;
+ max: -1 120;
+ rel1 { relative: 0.0 1.0; to: "sw.counter"; }
+ }
+ }
+ swallow { "sw.list"; scale;
+ desc { "default";
+ min: 0 360;
+ max: -1 360;
+ align: 0.5 1.0;
+ rel2 { relative: 1.0 0.0; to: "pd.btn.bg"; }
+ hid;
+ }
+ desc { "list.visible";
+ inherit: "default";
+ vis;
+ }
+ }
+ swallow { "sw.btn.start"; scale;
+ desc { "default";
+ align: 0.5 0.5;
+ max: 500 -1;
+ rel1.to: "btn.bg";
+ rel2.to: "btn.bg";
+ }
+ desc { "hidden";
+ inherit: "default";
+ hid;
+ }
+ }
+ swallow { "sw.btn.stop"; scale;
+ desc { "default";
+ align: 0.1 0.5;
+ max: 300 -1;
+ rel1.to: "btn.bg";
+ rel2.to: "btn.bg";
+ hid;
+ }
+ desc { "visible";
+ inherit: "default";
+ vis;
+ }
+ }
+ swallow { "sw.btn.lap"; scale;
+ desc { "default";
+ align: 0.9 0.5;
+ max: 300 -1;
+ rel1.to: "btn.bg";
+ rel2.to: "btn.bg";
+ hid;
+ }
+ desc { "visible";
+ inherit: "default";
+ vis;
+ }
+ }
+ swallow { "sw.btn.resume"; scale;
+ desc { "default";
+ align: 0.1 0.5;
+ max: 300 -1;
+ rel1.to: "btn.bg";
+ rel2.to: "btn.bg";
+ hid;
+ }
+ desc { "visible";
+ inherit: "default";
+ vis;
+ }
+ }
+ swallow { "sw.btn.reset"; scale;
+ desc { "default";
+ align: 0.9 0.5;
+ max: 300 -1;
+ rel1.to: "btn.bg";
+ rel2.to: "btn.bg";
+ hid;
+ }
+ desc { "visible";
+ inherit: "default";
+ vis;
+ }
+ }
+ program {
+ signal: "list.show";
+ source: "stopwatch";
+ action: STATE_SET "list.visible" ;
+ target: "pd.bottom";
+ target: "sw.list";
+ target: "pd.btn.bg";
+ }
+ program {
+ signal: "list.hide";
+ source: "stopwatch";
+ action: STATE_SET "default" ;
+ target: "pd.bottom";
+ target: "sw.list";
+ target: "pd.btn.bg";
+ }
+ program {
+ signal: "counter.expand";
+ source: "stopwatch";
+ action: STATE_SET "expanded" ;
+ target: "sw.counter";
+ }
+ program {
+ signal: "menu.startup.show";
+ source: "stopwatch";
+ script {
+ set_state(PART:"sw.btn.stop", "default", 0.0);
+ set_state(PART:"sw.btn.lap", "default", 0.0);
+ set_state(PART:"sw.btn.resume", "default", 0.0);
+ set_state(PART:"sw.btn.reset", "defualt", 0.0);
+ set_state(PART:"sw.btn.start", "default", 0.0);
+ }
+ }
+ program {
+ signal: "menu.running.show";
+ source: "stopwatch";
+ script {
+ set_state(PART:"sw.btn.stop", "visible", 0.0);
+ set_state(PART:"sw.btn.lap", "visible", 0.0);
+ set_state(PART:"sw.btn.resume", "default", 0.0);
+ set_state(PART:"sw.btn.reset", "default", 0.0);
+ set_state(PART:"sw.btn.start", "hidden", 0.0);
+ }
+ }
+ program {
+ signal: "menu.stopped.show";
+ source: "stopwatch";
+ script {
+ set_state(PART:"sw.btn.stop", "default", 0.0);
+ set_state(PART:"sw.btn.lap", "default", 0.0);
+ set_state(PART:"sw.btn.resume", "visible", 0.0);
+ set_state(PART:"sw.btn.reset", "visible", 0.0);
+ set_state(PART:"sw.btn.start", "hidden", 0.0);
+ }
+ }
+ }
+ }
+
+ group { name: "elm/genlist/item/lap/default";
+ alias: "elm/layout/lap/default";
+
+ styles {
+ style {
+ name: "ATO013";
+ base: "font=Tizen:style=Light color=#000000 wrap=none font_size=42";
+ }
+ style {
+ name: "ATO014";
+ base: "font=Tizen:style=Light color=#000000 wrap=none font_size=42 align=right";
+ }
+ style {
+ name: "ATO015";
+ base: "font=Tizen:style=Light color=#0000AA wrap=none font_size=42 align=right";
+ }
+
+ }
+
+ data.item: "texts" "txt.lap.no txt.lap.split txt.lap.time";
+ data.item: "banded_bg_area" "elm.swallow.bg";
+
+ parts {
+ swallow { "elm.swallow.bg"; scale;
+ desc { "default";
+ rel1.to: "bg";
+ rel2.to: "bg";
+ }
+ }
+ spacer { "bg"; scale;
+ desc { "default";
+ min: 0 120;
+ max: -1 120;
+ }
+ }
+ spacer { "pd.left"; scale;
+ desc {
+ min: 32 0;
+ max: 32 -1;
+ align: 0.0 0.5;
+ rel1.to: "bg";
+ rel2.to: "bg";
+ }
+ }
+ spacer { "pd.right"; scale;
+ desc {
+ min: 32 0;
+ max: 32 -1;
+ align: 1.0 0.5;
+ rel1.to: "bg";
+ rel2.to: "bg";
+ }
+ }
+ spacer { "pd.split"; scale;
+ desc {
+ min: 252 0;
+ max: 252 -1;
+ align: 1.0 0.5;
+ rel2 { relative: 0.0 1.0; to: "pd.right"; }
+ }
+ }
+ textblock { "txt.lap.no"; scale;
+ desc { "default";
+ min: 64 0;
+ max: 64 -1;
+ align: 0.0 0.5;
+ rel1 { relative: 1.0 0.0; to: "pd.left"; }
+ rel2.to: "bg";
+ text.style: "ATO013";
+ }
+ }
+ textblock { "txt.lap.split"; scale;
+ desc { "default";
+ min: 174 0;
+ align: 1.0 0.5;
+ rel2 { relative: 0.0 1.0; to: "pd.split"; }
+ text {
+ style: "ATO014";
+ min: 1 0;
+ elipsis: -1;
+ }
+ }
+ }
+ textblock { "txt.lap.time"; scale;
+ desc { "default";
+ min: 174 0;
+ align: 1.0 0.5;
+ //rel1 { relative: 1.0 0.0; to: "pd.split.time"; }
+ rel2 { relative: 0.0 1.0; to: "pd.right"; }
+ text {
+ style: "ATO015";
+ min: 1 0;
+ elipsis: -1;
+ }
+ }
+ }
+ }
+ }
+}
--- /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 "Common/CounterAnimator.h"
+#include "log.h"
+
+namespace common {
+
+CounterAnimator::CounterAnimator()
+{
+}
+
+CounterAnimator::~CounterAnimator()
+{
+ Remove();
+}
+
+void CounterAnimator::SetFrametime(double time)
+{
+ ecore_animator_frametime_set(time);
+}
+
+bool CounterAnimator::Start()
+{
+ animator_ = ecore_animator_add(Task, this);
+ if (!animator_) {
+ ERR("Animator == NULL");
+ return false;
+ }
+
+ return true;
+}
+
+bool CounterAnimator::Stop()
+{
+ if (!animator_) {
+ ERR("Animator is not initialized yet");
+ return false;
+ }
+
+ ecore_animator_freeze(animator_);
+ return true;
+}
+
+bool CounterAnimator::Resume()
+{
+ if (!animator_) {
+ ERR("Animator is not initialized yet");
+ return false;
+ }
+
+ ecore_animator_thaw(animator_);
+ return true;
+}
+
+void CounterAnimator::Remove()
+{
+ ecore_animator_del(animator_);
+}
+
+void CounterAnimator::RegisterSignal(std::function<void(void)>func)
+{
+ signals_.push_back(func);
+}
+
+
+Eina_Bool CounterAnimator::Task(void *data)
+{
+ CounterAnimator *object = (CounterAnimator *)data;
+
+ object->EmitSignal();
+
+ return ECORE_CALLBACK_RENEW;
+}
+
+void CounterAnimator::EmitSignal()
+{
+ for (auto func: signals_)
+ func();
+}
+
+} //namespace common
--- /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 "Model/Counter.h"
+#include "log.h"
+
+namespace model {
+
+using namespace std;
+using namespace std::chrono;
+
+Counter::Counter()
+{
+ start_time_ = milliseconds::zero();
+ pause_time_ = milliseconds::zero();
+}
+
+Counter::~Counter()
+{
+}
+
+bool Counter::Run()
+{
+ start_time_ = GetTimeSinceEpoch();
+
+ if (start_time_.count() < 0) {
+ ERR("Failed to get start time");
+ return false;
+ }
+
+ return true;
+}
+
+bool Counter::Reset()
+{
+ pause_time_ = milliseconds::zero();
+
+ if (pause_time_ != milliseconds(0)) {
+ ERR("Could not set pause time to zero");
+ return false;
+ }
+
+ return true;
+}
+
+bool Counter::Resume()
+{
+ if (!Run()) {
+ ERR("Run time counter failed");
+ return false;
+ }
+
+ return true;
+}
+
+bool Counter::Stop()
+{
+ pause_time_ += duration_cast<milliseconds>(GetTimeSinceEpoch() - start_time_);
+
+ if (pause_time_.count() < 0)
+ return false;
+
+ return true;
+}
+
+milliseconds Counter::GetTime()
+{
+ return GetTimeSinceEpoch() - start_time_ + pause_time_;
+}
+
+milliseconds Counter::GetTimeSinceEpoch()
+{
+ return duration_cast<milliseconds>(system_clock::now().time_since_epoch());
+}
+
+milliseconds Counter::GetStartTime()
+{
+ return start_time_;
+}
+
+} //namespace model
--- /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 "Model/StopWatch.h"
+#include "log.h"
+
+namespace model {
+
+using namespace std::chrono;
+
+void StopWatch::AddLap()
+{
+ Lap *lap = new Lap();
+
+ lap->SetSplitTime(GetTime());
+
+ if (!laps_.empty()) {
+ Lap *last = laps_.back();
+ lap->SetTime(lap->GetSplitTime() - last->GetSplitTime());
+ } else
+ lap->SetTime(lap->GetSplitTime());
+
+ lap->SetNo(laps_.size() + 1);
+ laps_.push_back(lap);
+}
+
+const Lap *StopWatch::GetLastLap()
+{
+ if (laps_.empty())
+ return nullptr;
+
+ return laps_.back();
+}
+
+void StopWatch::ClearList()
+{
+ for (Lap *item: laps_)
+ delete(item);
+
+ laps_.clear();
+}
+
+} //namespace model
--- /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 <chrono>
+#include <sstream>
+#include <cmath>
+#include "Presenter/StopWatchPresenter.h"
+#include "log.h"
+
+namespace presenter {
+
+using namespace std::chrono;
+
+StopWatchPresenter::StopWatchPresenter(view::StopWatchView *ui, model::StopWatch *model)
+ : ui_(ui), model_(model)
+{
+ ui_->RegisterSignal(std::bind(&StopWatchPresenter::StartButtonClicked, this),
+ view::Signal::BUTTON_START_CLICKED);
+ ui_->RegisterSignal(std::bind(&StopWatchPresenter::StopButtonClicked, this),
+ view::Signal::BUTTON_STOP_CLICKED);
+ ui_->RegisterSignal(std::bind(&StopWatchPresenter::ResumeButtonClicked, this),
+ view::Signal::BUTTON_RESUME_CLICKED);
+ ui_->RegisterSignal(std::bind(&StopWatchPresenter::ResetButtonClicked, this),
+ view::Signal::BUTTON_RESET_CLICKED);
+ ui_->RegisterSignal(std::bind(&StopWatchPresenter::LapButtonClicked, this),
+ view::Signal::BUTTON_LAP_CLICKED);
+
+ animator_.RegisterSignal(std::bind(&StopWatchPresenter::TimeUpdateRequest, this));
+}
+
+StopWatchPresenter::~StopWatchPresenter()
+{
+}
+
+void StopWatchPresenter::StartButtonClicked()
+{
+ if (!animator_.Start()) {
+ ERR("Animator could not start");
+ return;
+ }
+
+ if (!model_->Run()) {
+ ERR("Could not run counter");
+ return;
+ }
+
+ ui_->ShowRunningMenu();
+}
+
+void StopWatchPresenter::StopButtonClicked()
+{
+ if (!animator_.Stop()) {
+ ERR("Could not stop animator");
+ return;
+ }
+
+ if (!model_->Stop()) {
+ ERR("Could not stop model");
+ return;
+ }
+ ui_->ShowStoppedMenu();
+}
+
+void StopWatchPresenter::ResumeButtonClicked()
+{
+ if (!animator_.Resume()) {
+ ERR("Could not resume animator");
+ return;
+ }
+
+ if (!model_->Resume()) {
+ ERR("Could not resume model");
+ return;
+ }
+
+ ui_->ShowRunningMenu();
+}
+
+void StopWatchPresenter::ResetButtonClicked()
+{
+ if (!model_->Reset()) {
+ ERR("Model reset failed");
+ return;
+ }
+
+ ui_->HideList();
+ ui_->ShowStartupMenu();
+
+ model_->ClearList();
+}
+
+void StopWatchPresenter::LapButtonClicked()
+{
+ model_->AddLap();
+
+ const model::Lap *last = model_->GetLastLap();
+ if (!last)
+ return;
+
+ std::string lapNoStr = std::to_string(last->GetNo());
+
+ if (last->GetNo() < 10)
+ lapNoStr.insert(0, 1, '0');
+
+ std::string splitTime = GetTimeString(last->GetSplitTime());
+ std::string lapTime = GetTimeString(last->GetTime());
+
+ ui_->AddLap(lapNoStr.c_str(), splitTime.c_str(), lapTime.c_str());
+}
+
+void StopWatchPresenter::TimeUpdateRequest()
+{
+ milliseconds time = model_->GetTime();
+
+ utils::Time ts = GetTimeStructure(time);
+ ui_->DisplayTime(ts.Hour, ts.Min, ts.Sec, ts.Msec);
+
+ const model::Lap *last = model_->GetLastLap();
+ if (!last)
+ return;
+
+ time = model_->GetTime() - last->GetSplitTime();
+ ts = GetTimeStructure(time);
+ ui_->DisplayLapTime(ts.Hour, ts.Min, ts.Sec, ts.Msec);
+}
+
+utils::Time StopWatchPresenter::GetTimeStructure(milliseconds time)
+{
+ utils::Time ts;
+
+ ts.Hour = duration_cast<hours>(time).count() % 100;
+ ts.Min = duration_cast<minutes>(time).count() % 60;
+ ts.Sec = duration_cast<seconds>(time).count() % 60;
+ ts.Msec = duration_cast<milliseconds>(time).count() % 1000;
+
+ return ts;
+}
+
+std::string StopWatchPresenter::GetTimeString(std::chrono::milliseconds time)
+{
+ auto ts = GetTimeStructure(time);
+ std::stringstream stringStream;
+
+ ts.Msec = (unsigned)std::round(ts.Msec / 10);
+
+ if (ts.Hour > 0)
+ stringStream << (unsigned)(ts.Hour / 10) << ts.Hour % 10 << ":";
+
+ stringStream << (unsigned)(ts.Min / 10) << ts.Min % 10 << ":";
+ stringStream << (unsigned)(ts.Sec / 10) << ts.Sec % 10 << ".";
+ stringStream << (unsigned)(ts.Msec / 10) << ts.Msec % 10;
+
+ return stringStream.str();
+}
+
+} //namespace presenter
utils::Deserialize(r, Hour);
utils::Deserialize(r, Min);
utils::Deserialize(r, Sec);
+ utils::Deserialize(r, Msec);
}
void Time::Serialize(utils::IWriter &w) const
utils::Serialize(w, Hour);
utils::Serialize(w, Min);
utils::Serialize(w, Sec);
+ utils::Serialize(w, Msec);
}
std::string Time::Format(enum Format format) const
--- /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 <ctime>
+#include <string>
+
+#include "View/CounterView.h"
+#include "Utils/Utils.h"
+#include "log.h"
+
+#define SIGNAL_SET_COUNTER_SIMPLE "digits,set,simple"
+#define SIGNAL_SET_COUNTER_TIMER "digits,set,timer"
+#define SIGNAL_SET_COUNTER_CONTRACT "digits,set,stopwatch,contract"
+#define SIGNAL_SET_COUNTER_EXPAND "digits,set,stopwatch,expand"
+
+namespace view {
+
+const char *CounterView::EDJE_FILE = "edje/Counter.edj";
+const char *CounterView::GROUP = "Counter";
+const char *CounterView::GROUP_EXPANDED = "Counter.expanded";
+const char *CounterView::GROUP_SIMPLE = "Counter.simple";
+const char *CounterView::GROUP_SIMPLE_EXPANDED = "Counter.simple.expanded";
+const char *CounterView::GROUP_TIMER = "Counter.timer";
+
+CounterView::CounterView(ui::IView &parent, CounterType type)
+{
+ Evas_Object *parentEo = parent.GetEvasObject();
+
+ layout_ = elm_layout_add(parentEo);
+
+ if (SetTheme(type)) {
+ ERR("Could not set layout");
+ evas_object_del(layout_);
+ return;
+ }
+
+ evas_object_size_hint_weight_set(layout_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout_, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ if (type == CounterType::COUNTER_TYPE_SIMPLE)
+ elm_object_part_content_set(parentEo, "sw.lap.counter", layout_);
+ else
+ elm_object_part_content_set(parentEo, "sw.counter", layout_);
+
+ evas_object_show(layout_);
+
+ Reset();
+
+ visible_ = true;
+}
+
+CounterView::~CounterView()
+{
+ evas_object_del(layout_);
+}
+
+bool CounterView::SetTheme(CounterType type, bool expand)
+{
+ const char *group = NULL;
+ const char *signal = NULL;
+
+ switch (type) {
+ case CounterType::COUNTER_TYPE_TIMER:
+ group = GROUP_TIMER;
+ signal = SIGNAL_SET_COUNTER_TIMER;
+ break;
+ case CounterType::COUNTER_TYPE_SIMPLE:
+ group = expand ? GROUP_SIMPLE_EXPANDED : GROUP_SIMPLE;
+ signal = SIGNAL_SET_COUNTER_SIMPLE;
+ break;
+ case CounterType::COUNTER_TYPE_STOPWATCH:
+ group = expand ? GROUP_EXPANDED : GROUP;
+ signal = expand ? SIGNAL_SET_COUNTER_EXPAND : SIGNAL_SET_COUNTER_CONTRACT;
+ break;
+ default:
+ ERR("Unhandled counter theme type");
+ return true;
+ }
+
+ this->type_ = type;
+
+ if (!elm_layout_file_set(layout_, GetEdjeFilePath(), group)) {
+ DBG("elm_layout_file_set failed");
+ return true;
+ }
+
+ Evas_Object *ly = elm_layout_edje_get(layout_);
+ Evas_Object *digit = NULL;
+ unsigned i = 0;
+
+ for (unsigned i = 0; i < 11; ++i) {
+ digit = edje_object_part_table_child_get(ly, "digits", i, 0);
+ if (digit && signal)
+ edje_object_signal_emit(digit, signal, "counter");
+ }
+
+ return false;
+}
+
+Evas_Object *CounterView::GetEvasObject()
+{
+ return layout_;
+}
+
+const char *CounterView::GetEdjeFilePath()
+{
+ return utils::Utils::GetAppResourcePath(utils::Utils::APP_DIR_RESOURCE, EDJE_FILE);
+}
+
+void CounterView::DisplayTime(int hour, int min, int sec, int msec)
+{
+ msec /= 10;
+
+ if (hour > 0) {
+ SetDigitText(std::to_string((unsigned)(hour/10)).c_str(), 0);
+ SetDigitText(std::to_string((unsigned)(hour%10)).c_str(), 1);
+ Expand();
+ } else
+ Contract();
+
+ SetDigitText(std::to_string((unsigned)(min/10)).c_str(), 3);
+ SetDigitText(std::to_string((unsigned)(min%10)).c_str(), 4);
+ SetDigitText(std::to_string((unsigned)(sec/10)).c_str(), 6);
+ SetDigitText(std::to_string((unsigned)(sec%10)).c_str(), 7);
+ SetDigitText(std::to_string((unsigned)(msec/10)).c_str(), 9);
+ SetDigitText(std::to_string((unsigned)(msec%10)).c_str(), 10);
+}
+
+bool CounterView::SetDigitText(const char *text, unsigned col)
+{
+ Evas_Object *ly = elm_layout_edje_get(layout_);
+ if (!ly) {
+ ERR("Could not get layout");
+ return true;
+ }
+
+ Evas_Object *digit = edje_object_part_table_child_get(ly, "digits", col, 0);
+ if (!digit)
+ return true;
+
+ if(!edje_object_part_text_set(digit, "digit", text))
+ return true;
+
+ return false;
+}
+
+void CounterView::Reset()
+{
+ for (int i = 0; i < 11; ++i)
+ SetDigitText("0", i);
+}
+
+void CounterView::Expand()
+{
+ SetTheme(this->type_, true);
+}
+
+void CounterView::Contract()
+{
+ SetTheme(this->type_, false);
+}
+
+void CounterView::Show()
+{
+ if (!IsVisible()) {
+ elm_object_signal_emit(layout_, "counter,set,visible", "counter");
+ visible_ = true;
+ }
+}
+
+void CounterView::Hide()
+{
+ if (IsVisible()) {
+ elm_object_signal_emit(layout_, "counter,set,hidden", "counter");
+ visible_ = false;
+ }
+}
+
+bool CounterView::IsVisible()
+{
+ return visible_;
+}
+
+} //namespace view
#include "Presenter/AlarmPresenter.h"
#include "Model/AlarmProvider.h"
+#include "Presenter/StopWatchPresenter.h"
+
using namespace view;
using namespace presenter;
using namespace utils;
AlarmView *alarm = new AlarmView();
new AlarmPresenter(alarm, AlarmProvider::GetInstance());
alarm_ = alarm;
+
world_clock_ = new WorldClockView();
- stop_watch_ = new StopWatchView();
+
+ StopWatchView *stopWatch = new StopWatchView();
+ model::StopWatch *stopWatchModel = new model::StopWatch();
+ new StopWatchPresenter(stopWatch, stopWatchModel);
+
+ stop_watch_ = stopWatch;
timer_ = new TimerView();
}
* limitations under the License.
*/
-#include "View/StopWatchView.h"
#include "View/MainView.h"
+#include "View/StopWatchView.h"
+#include "Presenter/StopWatchPresenter.h"
#include "Utils/Utils.h"
-using namespace view;
-using namespace utils;
+#include "log.h"
+
+namespace view {
+
+const char *StopWatchView::EDJE_FILE = "edje/StopWatch.edj";
+const char *StopWatchView::GROUP = "StopWatch";
+
+const Elm_Genlist_Item_Class StopWatchView::list_itc = {
+ .item_style = "lap",
+ .func.text_get = GetListText,
+};
StopWatchView::StopWatchView()
{
- /*Create content here and use main_layout_ as a parent*/
+ layout_ = elm_layout_add(MainView::GetInstance().GetEvasObject());
+
+ if (!elm_layout_file_set(layout_, GetEdjeFilePath(), GROUP)) {
+ ERR("elm_layout_file_set failed");
+ evas_object_del(layout_);
+ return;
+ }
+
+ evas_object_size_hint_weight_set(layout_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout_, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ elm_theme_overlay_add(NULL, GetEdjeFilePath());
+
+ CreateMenuButtons();
+ CreateList();
+
+ main_counter_ = new CounterView(*this);
+ lap_counter_ = new CounterView(*this, CounterType::COUNTER_TYPE_SIMPLE);
+
+ ShowStartupMenu();
+}
+
+StopWatchView::~StopWatchView()
+{
+ delete(main_counter_);
+ delete(lap_counter_);
+
+ evas_object_del(layout_);
+}
+
+const char *StopWatchView::GetEdjeFilePath()
+{
+ return utils::Utils::GetAppResourcePath(utils::Utils::APP_DIR_RESOURCE, EDJE_FILE);
+}
+
+Evas_Object *StopWatchView::GetEvasObject()
+{
+ return layout_;
+}
+
+void StopWatchView::CreateMenuButtons()
+{
+ CreateButton(layout_, "Start", "sw.btn.start", StartButtonClicked);
+ CreateButton(layout_, "Stop", "sw.btn.stop", StopButtonClicked);
+ CreateButton(layout_, "Lap", "sw.btn.lap", LapButtonClicked);
+ CreateButton(layout_, "Resume", "sw.btn.resume", ResumeButtonClicked);
+ CreateButton(layout_, "Reset", "sw.btn.reset", ResetButtonClicked);
+}
+
+void StopWatchView::ShowStartupMenu()
+{
+ main_counter_->Reset();
+ main_counter_->Contract();
+ lap_counter_->Reset();
+ lap_counter_->Hide();
+
+ elm_object_signal_emit(layout_, "menu.startup.show", "stopwatch");
+}
+
+void StopWatchView::ShowRunningMenu()
+{
+ elm_object_signal_emit(layout_, "menu.running.show", "stopwatch");
+}
+
+void StopWatchView::ShowStoppedMenu()
+{
+ elm_object_signal_emit(layout_, "menu.stopped.show", "stopwatch");
+}
+
+void StopWatchView::CreateButton(Evas_Object *parent, const char *name,
+ const char *part, Evas_Smart_Cb cb)
+{
+ Evas_Object *button = elm_object_part_content_get(layout_, part);
+ if (button)
+ return;
+
+ button = elm_button_add(parent);
+
+ elm_object_text_set(button, name);
- /*Temporary Code*/
- stopwatch_ = elm_layout_add(MainView::GetInstance().GetEvasObject());
+ elm_object_style_set(button, "bottom");
+ elm_object_part_content_set(layout_, part, button);
- elm_layout_file_set(stopwatch_, Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE, "edje/clock.edj"), "main");
+ evas_object_smart_callback_add(button, "clicked", cb, this);
- evas_object_size_hint_align_set(stopwatch_, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_size_hint_weight_set(stopwatch_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_show(button);
+}
- Evas_Object *label = elm_label_add(stopwatch_);
+void StopWatchView::StartButtonClicked(void *data, Evas_Object *obj, void *event_info)
+{
+ StopWatchView *object = static_cast<StopWatchView *>(data);
+ object->EmitSignal(Signal::BUTTON_START_CLICKED);
+}
- elm_object_text_set(label, "Stop Watch");
- elm_layout_content_set(stopwatch_, "bg", label);
+void StopWatchView::StopButtonClicked(void *data, Evas_Object *obj, void *event_info)
+{
+ StopWatchView *object = static_cast<StopWatchView *>(data);
+ object->EmitSignal(Signal::BUTTON_STOP_CLICKED);
+}
+
+void StopWatchView::LapButtonClicked(void *data, Evas_Object *obj, void *event_info)
+{
+ StopWatchView *object = static_cast<StopWatchView *>(data);
+ object->EmitSignal(Signal::BUTTON_LAP_CLICKED);
}
+
+void StopWatchView::ResumeButtonClicked(void *data, Evas_Object *obj, void *event_info)
+{
+
+ StopWatchView *object = static_cast<StopWatchView *>(data);
+ object->EmitSignal(Signal::BUTTON_RESUME_CLICKED);
+}
+
+void StopWatchView::ResetButtonClicked(void *data, Evas_Object *obj, void *event_info)
+{
+ StopWatchView *object = static_cast<StopWatchView *>(data);
+ object->EmitSignal(Signal::BUTTON_RESET_CLICKED);
+}
+
+Evas_Object *StopWatchView::CreateList()
+{
+ Evas_Object *list = elm_genlist_add(layout_);
+
+ evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ elm_scroller_policy_set(list, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
+ elm_object_part_content_set(layout_, "sw.list", list);
+
+ evas_object_show(list);
+
+ return list;
+}
+
+void StopWatchView::ShowList()
+{
+ Evas_Object *list = elm_object_part_content_get(layout_, "sw.list");
+ if (!list)
+ list = CreateList();
+
+ elm_object_signal_emit(layout_, "list.show", "stopwatch");
+}
+
+void StopWatchView::FreeListItemsData(Evas_Object *list)
+{
+ unsigned count = elm_genlist_items_count(list);
+ Lap *lap = NULL;
+ Elm_Object_Item *item = NULL;
+
+ for (unsigned i = 0; i < count; ++i) {
+ item = elm_genlist_nth_item_get(list, i);
+ lap = (Lap *)elm_object_item_data_get(item);
+
+ delete lap;
+ }
+}
+
+void StopWatchView::HideList()
+{
+ Evas_Object *list = elm_object_part_content_unset(layout_, "sw.list");
+ if (list) {
+ FreeListItemsData(list);
+ evas_object_del(list);
+ }
+
+ elm_object_signal_emit(layout_, "list.hide", "stopwatch");
+}
+
+void StopWatchView::AddLap(const char *no, const char *splitTime, const char *lapTime)
+{
+ Evas_Object *list = elm_object_part_content_get(layout_, "sw.list");
+ if (!list)
+ list = CreateList();
+ ShowList();
+
+ Lap *lap = new Lap(no, splitTime, lapTime);
+
+ Elm_Genlist_Item *item = elm_genlist_item_prepend(list, &list_itc, lap,
+ NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
+ elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
+
+ if (!lap_counter_->IsVisible())
+ lap_counter_->Show();
+}
+
+char *StopWatchView::GetListText(void *data, Evas_Object *obj, const char *part)
+{
+ Lap *lap = (Lap *)data;
+ if (!lap || !lap->GetNo() || !lap->GetSplitTime() || !lap->GetLapTime())
+ return NULL;
+
+ if(!strcmp(PART_LAP_NO, part))
+ return strdup(lap->GetNo());
+ else if (!strcmp(PART_LAP_SPLIT, part))
+ return strdup(lap->GetSplitTime());
+ else if (!strcmp(PART_LAP_TIME, part))
+ return strdup(lap->GetLapTime());
+
+ return NULL;
+}
+
+void StopWatchView::RegisterSignal(std::function<void(void)>func, Signal type)
+{
+ signals.at((int)type) = func;
+}
+
+void StopWatchView::EmitSignal(Signal type)
+{
+ if (signals.at((int)type) != nullptr)
+ signals.at((int)type)();
+}
+
+void StopWatchView::DisplayTime(unsigned hour, unsigned minute, unsigned second, unsigned millisecond)
+{
+ main_counter_->DisplayTime(hour, minute, second, millisecond);
+}
+
+void StopWatchView::DisplayLapTime(unsigned hour, unsigned minute, unsigned second, unsigned millisecond)
+{
+ lap_counter_->DisplayTime(hour, minute, second, millisecond);
+}
+
+Lap::Lap(const char *no, const char *splitTime, const char *lapTime)
+{
+ this->No_ = strdup(no);
+ this->split_time_ = strdup(splitTime);
+ this->lap_time_ = strdup(lapTime);
+}
+
+Lap::~Lap()
+{
+ free(No_);
+ free(split_time_);
+ free(lap_time_);
+}
+
+} //namespace view
#include "View/MainView.h"
#include "Utils/Utils.h"
-using namespace view;
-using namespace utils;
+namespace view {
+using namespace utils;
TimerView::TimerView()
{
elm_layout_content_set(timer_, "bg", label);
}
+} //namespace view