1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
26
27
28
29
30
31
32
33
36
37
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
96
97
104
105
106
107
108
109
113
117
121
125
126
127
128
138
139
140
141
142
143
144
145
154
155
156
157
158
159
160
161
172
183
184
185
186
187
188
193
194
195
196
197
198
199
203
204
205
206
207
211
215
216
217
218
219
220
221
222
226
227
228
229
230
231
232
233
237
241
242
243
244
251
252
253
254
255
256
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/* ... */
#include <gui/live_data_display_screen/LiveDataDisplayView.hpp>
#include <gui/common/FrontendApplication.hpp>
#include <touchgfx/EasingEquations.hpp>
#include "BitmapDatabase.hpp"
#include <touchgfx/Color.hpp>
#include <stdlib.h>
6 includes
LiveDataDisplayView::LiveDataDisplayView() :
currentState(NO_ANIMATION),
animationCounter(0),
tickCounter(0),
dragX(0),
infoScreens(EAST),
onButtonPressed(this, &LiveDataDisplayView::buttonPressedhandler)
{
}{ ... }
LiveDataDisplayView::~LiveDataDisplayView()
{
}{ ... }
void LiveDataDisplayView::setupScreen()
{
exitButton.setBitmaps(Bitmap(BITMAP_ANIMATED_GRAPHICS_BACK_BUTTON_ID), Bitmap(BITMAP_ANIMATED_GRAPHICS_BACK_BUTTON_PRESSED_ID));
exitButton.setXY(0, HAL::DISPLAY_HEIGHT - exitButton.getHeight());
exitButton.setAction(onButtonPressed);
infoScreen[0].setBitmap(BITMAP_WEATHER_BACKGROUND_1_ID);
infoScreen[0].setCity(CityInfo::COPENHAGEN);
infoScreen[0].setTextColor(Color::getColorFrom24BitRGB(0xFA, 0xF0, 0xB4));
infoScreen[1].setBitmap(BITMAP_WEATHER_BACKGROUND_2_ID);
infoScreen[1].setCity(CityInfo::HONG_KONG);
infoScreen[1].setTextColor(Color::getColorFrom24BitRGB(0x0A, 0x45, 0x064));
infoScreen[2].setBitmap(BITMAP_WEATHER_BACKGROUND_3_ID);
infoScreen[2].setCity(CityInfo::MUMBAI);
infoScreen[2].setTextColor(Color::getColorFrom24BitRGB(0x27, 0x5F, 0x7D));
infoScreen[3].setBitmap(BITMAP_WEATHER_BACKGROUND_1_ID);
infoScreen[3].setCity(CityInfo::NEW_YORK);
infoScreen[3].setTextColor(Color::getColorFrom24BitRGB(0xBA, 0xD2, 0xDA));
infoScreens.setXY(0, 0);
infoScreens.add(infoScreen[0]);
infoScreens.add(infoScreen[1]);
infoScreens.add(infoScreen[2]);
infoScreens.add(infoScreen[3]);
infoScreensViewPort.setPosition(0, 0, HAL::DISPLAY_WIDTH, HAL::DISPLAY_HEIGHT - exitButton.getHeight());
infoScreensViewPort.add(infoScreens);
currentScreen = 0;
weekInfoBar.setPosition(0, exitButton.getY() - 87, HAL::DISPLAY_WIDTH, 60);
weekInfoBar.setTextColor(infoScreen[currentScreen].getTextColor());
weekInfoBar.setInfo(infoScreen[currentScreen].getCity());
dotIndicator.setNumberOfDots(NUMBER_OF_SCREENS);
dotIndicator.setBitmaps(Bitmap(BITMAP_WEATHER_DOT_NORMAL_ID), Bitmap(BITMAP_WEATHER_DOT_SELECTED_ID));
dotIndicator.setXY(((HAL::DISPLAY_WIDTH - dotIndicator.getWidth()) / 2), exitButton.getY() - 20);
backgroundSwipeAreaLeft.setBitmap(Bitmap(BITMAP_WEATHER_BACKGROUND_ENDING_1_ID));
backgroundSwipeAreaLeft.setXY(0, infoScreensViewPort.getY());
backgroundSwipeAreaRight.setBitmap(Bitmap(BITMAP_WEATHER_BACKGROUND_ENDING_1_ID));
backgroundSwipeAreaRight.setXY(HAL::DISPLAY_WIDTH - backgroundSwipeAreaRight.getWidth(), infoScreensViewPort.getY());
add(backgroundSwipeAreaLeft);
add(backgroundSwipeAreaRight);
add(infoScreensViewPort);
add(weekInfoBar);
add(dotIndicator);
add(exitButton);
}{ ... }
void LiveDataDisplayView::tearDownScreen()
{
}{ ... }
void LiveDataDisplayView::buttonPressedhandler(const AbstractButton& button)
{
if (&button == &exitButton)
{
static_cast<FrontendApplication*>(Application::getInstance())->gotoMenuScreen();
}if (&button == &exitButton) { ... }
}{ ... }
void LiveDataDisplayView::handleTickEvent()
{
tickCounter++;
if (currentState == ANIMATE_SWIPE_CANCELLED_LEFT)
{
animateSwipeCancelledLeft();
}if (currentState == ANIMATE_SWIPE_CANCELLED_LEFT) { ... }
else if (currentState == ANIMATE_SWIPE_CANCELLED_RIGHT)
{
animateSwipeCancelledRight();
}else if (currentState == ANIMATE_SWIPE_CANCELLED_RIGHT) { ... }
else if (currentState == ANIMATE_LEFT)
{
animateLeft();
}else if (currentState == ANIMATE_LEFT) { ... }
else if (currentState == ANIMATE_RIGHT)
{
animateRight();
}else if (currentState == ANIMATE_RIGHT) { ... }
if (tickCounter % 100 == 0)
{
for (int16_t i = 0; i < NUMBER_OF_SCREENS; i++)
{
if ((rand() % 4) == 0)
{
infoScreen[i].adjustTemperature();
}if ((rand() % 4) == 0) { ... }
}for (int16_t i = 0; i < NUMBER_OF_SCREENS; i++) { ... }
}if (tickCounter % 100 == 0) { ... }
}{ ... }
void LiveDataDisplayView::handleClickEvent(const ClickEvent& evt)
{
if (currentState != NO_ANIMATION)
{
if (evt.getY() > infoScreensViewPort.getY())
{
View<LiveDataDisplayPresenter>::handleClickEvent(evt);
}if (evt.getY() > infoScreensViewPort.getY()) { ... }
return;
}if (currentState != NO_ANIMATION) { ... }
if (evt.getType() == ClickEvent::RELEASED)
{
animateDistance = dragX;
startX = infoScreens.getX();
if (dragX < 0)
{
if (currentScreen == NUMBER_OF_SCREENS - 1 || dragX > -120)
{
currentState = ANIMATE_SWIPE_CANCELLED_LEFT;
}if (currentScreen == NUMBER_OF_SCREENS - 1 || dragX > -120) { ... }
else
{
currentState = ANIMATE_LEFT;
}else { ... }
}if (dragX < 0) { ... }
else if (dragX > 0)
{
if (currentScreen == 0 || dragX < 120)
{
currentState = ANIMATE_SWIPE_CANCELLED_RIGHT;
}if (currentScreen == 0 || dragX < 120) { ... }
else
{
currentState = ANIMATE_RIGHT;
}else { ... }
}else if (dragX > 0) { ... }
}if (evt.getType() == ClickEvent::RELEASED) { ... }
if (evt.getY() > infoScreensViewPort.getY())
{
View<LiveDataDisplayPresenter>::handleClickEvent(evt);
return;
}if (evt.getY() > infoScreensViewPort.getY()) { ... }
}{ ... }
void LiveDataDisplayView::handleDragEvent(const DragEvent& evt)
{
if (currentState != NO_ANIMATION)
{
return;
}if (currentState != NO_ANIMATION) { ... }
dragX += evt.getDeltaX();
if (currentScreen == 0 && dragX > backgroundSwipeAreaLeft.getWidth())
{
dragX = backgroundSwipeAreaLeft.getWidth();
}if (currentScreen == 0 && dragX > backgroundSwipeAreaLeft.getWidth()) { ... }
else if (currentScreen == NUMBER_OF_SCREENS - 1 && dragX < -backgroundSwipeAreaRight.getWidth())
{
dragX = -backgroundSwipeAreaRight.getWidth();
}else if (currentScreen == NUMBER_OF_SCREENS - 1 && dragX < -backgroundSwipeAreaRight.getWidth()) { ... }
adjustInfoScreens();
}{ ... }
void LiveDataDisplayView::handleGestureEvent(const GestureEvent& evt)
{
if (currentState != NO_ANIMATION)
{
return;
}if (currentState != NO_ANIMATION) { ... }
if (evt.getType() == evt.SWIPE_HORIZONTAL)
{
animateDistance = dragX;
startX = infoScreens.getX();
if (evt.getVelocity() < 0 && currentScreen < NUMBER_OF_SCREENS - 1)
{
currentState = ANIMATE_LEFT;
}if (evt.getVelocity() < 0 && currentScreen < NUMBER_OF_SCREENS - 1) { ... }
else if (evt.getVelocity() > 0 && currentScreen > 0)
{
currentState = ANIMATE_RIGHT;
}else if (evt.getVelocity() > 0 && currentScreen > 0) { ... }
}if (evt.getType() == evt.SWIPE_HORIZONTAL) { ... }
}{ ... }
void LiveDataDisplayView::adjustInfoScreens()
{
infoScreens.moveTo(- (currentScreen * HAL::DISPLAY_WIDTH) + dragX, infoScreens.getY());
int alphaAdjustment = (dragX < 0) ? -dragX : dragX;
weekInfoBar.setAlpha(255 - alphaAdjustment);
}{ ... }
void LiveDataDisplayView::animateSwipeCancelledLeft()
{
uint8_t duration = 14;
if (animationCounter <= duration)
{
int16_t delta = EasingEquations::backEaseOut(animationCounter, 0, -animateDistance, duration);
dragX = animateDistance + delta;
adjustInfoScreens();
}if (animationCounter <= duration) { ... }
else
{
currentState = NO_ANIMATION;
animationCounter = 0;
dragX = 0;
adjustInfoScreens();
}else { ... }
animationCounter++;
}{ ... }
void LiveDataDisplayView::animateSwipeCancelledRight()
{
uint8_t duration = 14;
if (animationCounter <= duration)
{
int16_t delta = EasingEquations::backEaseOut(animationCounter, 0, animateDistance, duration);
dragX = animateDistance - delta;
adjustInfoScreens();
}if (animationCounter <= duration) { ... }
else
{
currentState = NO_ANIMATION;
animationCounter = 0;
dragX = 0;
adjustInfoScreens();
}else { ... }
animationCounter++;
}{ ... }
void LiveDataDisplayView::animateLeft()
{
uint8_t duration = 10;
if (animationCounter <= duration)
{
int16_t delta = EasingEquations::cubicEaseOut(animationCounter, 0, infoScreensViewPort.getWidth() + animateDistance, duration);
dragX = animateDistance - delta;
adjustInfoScreens();
}if (animationCounter <= duration) { ... }
else
{
currentState = NO_ANIMATION;
animationCounter = 0;
currentScreen++;
dragX = 0;
weekInfoBar.setTextColor(infoScreen[currentScreen].getTextColor());
weekInfoBar.setInfo(infoScreen[currentScreen].getCity());
adjustInfoScreens();
dotIndicator.goRight();
}else { ... }
animationCounter++;
}{ ... }
void LiveDataDisplayView::animateRight()
{
uint8_t duration = 10;
if (animationCounter <= duration)
{
int16_t delta = EasingEquations::cubicEaseOut(animationCounter, 0, infoScreensViewPort.getWidth() - animateDistance, duration);
dragX = animateDistance + delta;
adjustInfoScreens();
}if (animationCounter <= duration) { ... }
else
{
currentState = NO_ANIMATION;
animationCounter = 0;
currentScreen--;
dragX = 0;
weekInfoBar.setTextColor(infoScreen[currentScreen].getTextColor());
weekInfoBar.setInfo(infoScreen[currentScreen].getCity());
adjustInfoScreens();
dotIndicator.goLeft();
}else { ... }
animationCounter++;
}{ ... }