Implemented changes to show Date / time format strings
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_EditTimePresenter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiCtrl_EditTimePresenter.cpp
20  * @brief               This is the implementation file for the _EditTimePresenter class.
21  */
22
23 #include <FSysSettingInfo.h>
24 #include <FGrp_BitmapImpl.h>
25 #include <FGrp_TextTextObject.h>
26 #include <FGrp_TextTextSimple.h>
27 #include <FGrp_FontImpl.h>
28 #include "FUi_CoordinateSystemUtils.h"
29 #include "FUi_ResourceManager.h"
30 #include "FUiCtrl_EditTimePresenter.h"
31 #include "FUiCtrl_EditTime.h"
32 #include "FUiCtrl_DateTimeModel.h"
33 #include "FUiCtrl_DateTimeUtils.h"
34 #include "FUiAnim_VisualElement.h"
35 #include "FUiAnimVisualElementPropertyAnimation.h"
36 #include "FGrpColor.h"
37
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Base;
40 using namespace Tizen::Graphics::_Text;
41 using namespace Tizen::Ui::Animations;
42 using namespace Tizen::System;
43
44 namespace Tizen { namespace Ui { namespace Controls
45 {
46 _EditTimePresenter::_EditTimePresenter(const String& title)
47         : __pEditDateTimeModel(null)
48         , __pEditTime(null)
49         , __bounds(FloatRectangle())
50         , __titleBounds(FloatRectangle())
51         , __ampmString(String())
52         , __hourString(String())
53         , __minuteString(String())
54         , __title(title)
55         , __24hours(false)
56         , __is24hoursSet(false)
57         , __amEnable(true)
58         , __timePickerEnabled(true)
59         , __selectedId(DATETIME_ID_NONE)
60         , __lastSelectedId(DATETIME_ID_NONE)
61         , __touchMoveHandled(false)
62         , __pAmPmBgNormalColorReplacementBitmap(null)
63         , __pAmPmBgDisabledColorReplacementBitmap(null)
64         , __pAmPmBgPressedColorReplacementBitmap(null)
65         , __pAmPmBgEffectNomralBitmap(null)
66         , __pAmPmBgEffectPressedBitmap(null)
67         , __pAmPmBgEffectDisabledBitmap(null)
68         , __pColonColorReplacementBitmap(null)
69         , __pColonDisabledColorReplacementBitmap(null)
70         , __pContentProvider(null)
71         , __textObject()
72         , __pFont(null)
73         , __titleObject()
74         , __amPmTextSize(0.0f)
75         , __titleFontSize(0.0f)
76         , __timeFontSize(0.0f)
77         , __isAnimating(false)
78         , __isEditTimeInitialized(false)
79 {
80 }
81
82 _EditTimePresenter::~_EditTimePresenter(void)
83 {
84         __textObject.RemoveAll();
85         __titleObject.RemoveAll();
86
87         delete __pEditDateTimeModel;
88         __pEditDateTimeModel = null;
89
90         delete __pAmPmBgNormalColorReplacementBitmap;
91         __pAmPmBgNormalColorReplacementBitmap = null;
92
93         delete __pAmPmBgDisabledColorReplacementBitmap;
94         __pAmPmBgDisabledColorReplacementBitmap = null;
95
96         delete __pAmPmBgPressedColorReplacementBitmap;
97         __pAmPmBgPressedColorReplacementBitmap = null;
98
99         delete __pAmPmBgEffectNomralBitmap;
100         __pAmPmBgEffectNomralBitmap = null;
101
102         delete __pAmPmBgEffectPressedBitmap;
103         __pAmPmBgEffectPressedBitmap = null;
104
105         delete __pAmPmBgEffectDisabledBitmap;
106         __pAmPmBgEffectDisabledBitmap = null;
107
108         delete __pColonColorReplacementBitmap;
109         __pColonColorReplacementBitmap = null;
110
111         delete __pColonDisabledColorReplacementBitmap;
112         __pColonDisabledColorReplacementBitmap = null;
113 }
114
115 _EditTimePresenter*
116 _EditTimePresenter::CreateInstanceN(const _EditTime& editTime, const String& title)
117 {
118         _EditTimePresenter* pEditTimePresenter = new (std::nothrow) _EditTimePresenter(title);
119         SysTryReturn(NID_UI_CTRL, pEditTimePresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
120
121         pEditTimePresenter->__pEditTime = const_cast <_EditTime*>(&editTime);
122
123         pEditTimePresenter->__pEditDateTimeModel = new (std::nothrow) _DateTimeModel;
124         SysTryCatch(NID_UI_CTRL, pEditTimePresenter->__pEditDateTimeModel, , E_OUT_OF_MEMORY,
125                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
126
127         return pEditTimePresenter;
128
129 CATCH:
130         delete pEditTimePresenter;
131         return null;
132 }
133
134 DateTime
135 _EditTimePresenter::GetTime(void) const
136 {
137         DateTime time;
138         time.SetValue(DATETIME_YEAR_MIN, DATETIME_MONTH_MIN, DATETIME_DAY_MIN, GetHour(), GetMinute(), 0);
139
140         return time;
141 }
142
143 int
144 _EditTimePresenter::GetHour(void) const
145 {
146         return __pEditDateTimeModel->GetHour();
147 }
148
149 int
150 _EditTimePresenter::GetMinute(void) const
151 {
152         return __pEditDateTimeModel->GetMinute();
153 }
154
155 void
156 _EditTimePresenter::SetTime(const DateTime& time)
157 {
158         __pEditDateTimeModel->SetDateTime(time);
159 }
160
161 void
162 _EditTimePresenter::SetCurrentTime(void)
163 {
164         __pEditDateTimeModel->SetCurrentDateTime();
165         return;
166 }
167
168 result
169 _EditTimePresenter::SetHour(int hour)
170 {
171         return __pEditDateTimeModel->SetHour(hour);
172 }
173
174 result
175 _EditTimePresenter::SetMinute(int minute)
176 {
177         return __pEditDateTimeModel->SetMinute(minute);
178 }
179
180 void
181 _EditTimePresenter::SetTimePickerEnabled(bool enable)
182 {
183         __timePickerEnabled = enable;
184         return;
185 }
186
187 bool
188 _EditTimePresenter::IsTimePickerEnabled(void) const
189 {
190         return __timePickerEnabled;
191 }
192
193 void
194 _EditTimePresenter::Set24HourNotationEnabled(bool enable)
195 {
196         __24hours = enable;
197         __is24hoursSet = true;
198         return;
199 }
200
201 bool
202 _EditTimePresenter::Is24HourNotationEnabled(void) const
203 {
204         return __24hours;
205 }
206
207 void
208 _EditTimePresenter::SetTimeConversion(void)
209 {
210         int hour = GetHour();
211         int minute = GetMinute();
212
213         if (__24hours == false)
214         {
215                 int max = DATETIME_HOUR_MAX_FOR_24NOTATION;
216
217                 if (hour > max)
218                 {
219                         __hourString.Format(10, L"%02d", hour - max);
220                 }
221                 else if (hour == DATETIME_HOUR_MIN)
222                 {
223                         __hourString.Format(10, L"%02d", hour + DATETIME_HOUR_MAX_FOR_24NOTATION);
224                 }
225                 else
226                 {
227                         __hourString.Format(10, L"%02d", hour);
228                 }
229
230                 __minuteString.Format(10, L"%02d", minute);
231         }
232         else
233         {
234                 __hourString.Format(10, L"%02d", hour);
235                 __minuteString.Format(10, L"%02d", minute);
236         }
237
238         return;
239 }
240
241 void
242 _EditTimePresenter::SetAmEnabled(bool amEnable)
243 {
244         String textAm;
245         String textPm;
246
247         _DateTimeUtils dateTimeUtils;
248         dateTimeUtils.GetAmPm(textAm, AM_TYPE);
249         dateTimeUtils.GetAmPm(textPm, PM_TYPE);
250
251         __amEnable = amEnable;
252         int hour = GetHour();
253
254         if (__amEnable == true)
255         {
256                 __ampmString = textAm;
257                 if (hour >= DATETIME_HOUR_MAX_FOR_24NOTATION)
258                 {
259                         SetHour(hour - DATETIME_HOUR_MAX_FOR_24NOTATION);
260                 }
261         }
262         else
263         {
264                 __ampmString = textPm;
265                 if (hour < DATETIME_HOUR_MAX_FOR_24NOTATION)
266                 {
267                         SetHour(hour + DATETIME_HOUR_MAX_FOR_24NOTATION);
268                 }
269         }
270
271         return;
272 }
273
274 bool
275 _EditTimePresenter::GetAmEnabled(void) const
276 {
277         return __amEnable;
278 }
279
280 FloatRectangle
281 _EditTimePresenter::GetDisplayAreaBoundsFromHoursStyle(_DateTimeId displayBoxId) const
282 {
283         SysTryReturn(NID_UI_CTRL, displayBoxId >= DATETIME_ID_HOUR && displayBoxId <= DATETIME_ID_AMPM, FloatRectangle(),
284                         E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] displayBoxId is out of range.");
285
286         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
287
288         float width = 0.0f;
289         float colonWidth = 0.0f;
290         float margin = 0.0f;
291         float colonMargin = 0.0f;
292         float timeElementWidth = 0.0f;
293         float amPmHeight = 0.0f;
294         float timeHeight = 0.0f;
295         float titleTimeMargin = 0.0f;
296         float leftMargin = 0.0f;
297
298         GET_SHAPE_CONFIG(EDITTIME::TIME_WIDTH, __pEditTime->GetOrientation(), width);
299         GET_SHAPE_CONFIG(EDITTIME::HEIGHT, __pEditTime->GetOrientation(), bounds.height);
300         GET_SHAPE_CONFIG(EDITTIME::COLON_WIDTH, __pEditTime->GetOrientation(), colonWidth);
301         GET_SHAPE_CONFIG(EDITTIME::TIME_AMPM_MARGIN, __pEditTime->GetOrientation(), margin);
302         GET_SHAPE_CONFIG(EDITTIME::TIME_TEXT_LEFT_MARGIN, __pEditTime->GetOrientation(), leftMargin);
303         GET_SHAPE_CONFIG(EDITTIME::COLON_MARGIN, __pEditTime->GetOrientation(), colonMargin);
304         GET_SHAPE_CONFIG(EDITTIME::HOUR_MINUTE_WIDTH, __pEditTime->GetOrientation(), timeElementWidth);
305         GET_SHAPE_CONFIG(EDITTIME::AMPM_HEIGHT, __pEditTime->GetOrientation(), amPmHeight);
306         GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, __pEditTime->GetOrientation(), titleTimeMargin);
307         GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, __pEditTime->GetOrientation(), timeHeight);
308
309         if (__pEditTime->GetBoundsF().height > bounds.height)
310         {
311                 bounds.height = __pEditTime->GetBoundsF().height;
312         }
313
314         if (!__title.IsEmpty())
315         {
316                 if (displayBoxId == DATETIME_ID_AMPM)
317                 {
318                         bounds.y = __titleBounds.y + __titleBounds.height;
319                 }
320                 else
321                 {
322                         bounds.y = __titleBounds.y + __titleBounds.height + titleTimeMargin;
323                         bounds.height = timeHeight;
324                 }
325         }
326
327         if (__pEditTime->GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
328         {
329                 leftMargin = 0.0f;
330         }
331
332         bounds.x = leftMargin + ((width - (2.0f * timeElementWidth + colonWidth + 2.0f * colonMargin)) / 2.0f);
333
334         if (displayBoxId == DATETIME_ID_HOUR)
335         {
336                 bounds.width = timeElementWidth;
337         }
338         else if (displayBoxId == DATETIME_ID_MINUTE)
339         {
340                 bounds.x = bounds.x + timeElementWidth + colonWidth + 2.0f * colonMargin;
341                 bounds.width = timeElementWidth;
342         }
343         else if (displayBoxId == DATETIME_ID_AMPM)
344         {
345                 bounds.x = leftMargin + width + margin;
346
347                 if (__title.IsEmpty())
348                 {
349                         bounds.y = bounds.y + (bounds.height - amPmHeight) / 2.0f;
350                 }
351
352                 GET_SHAPE_CONFIG(EDITTIME::AMPM_WIDTH, __pEditTime->GetOrientation(), bounds.width);
353                 bounds.height = amPmHeight;
354         }
355
356         return bounds;
357 }
358
359 void
360 _EditTimePresenter::SetTitleBounds(void)
361 {
362         GET_SHAPE_CONFIG(EDITTIME::TIME_TEXT_LEFT_MARGIN, __pEditTime->GetOrientation(), __titleBounds.x);
363         GET_SHAPE_CONFIG(EDITTIME::WIDTH, __pEditTime->GetOrientation(), __titleBounds.width);
364         GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, __pEditTime->GetOrientation(), __titleBounds.height);
365
366         return;
367 }
368
369 FloatRectangle
370 _EditTimePresenter::GetTitleBounds(void) const
371 {
372         return __titleBounds;
373 }
374
375 result
376 _EditTimePresenter::LoadResource(void)
377 {
378         result r = E_SUCCESS;
379
380         Color buttonNormalBgColor;
381         Color buttonDisabledBgColor;
382         Color buttonNormalPressedColor;
383         Color colonTextColor;
384         Color colonTextDisabledColor;
385         Bitmap* pTempBitmap = null;
386
387         GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_NORMAL, buttonNormalBgColor);
388         GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_PRESSED, buttonNormalPressedColor);
389         GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_DISABLED, buttonDisabledBgColor);
390         GET_COLOR_CONFIG(EDITTIME::TEXT_NORMAL, colonTextColor);
391         GET_COLOR_CONFIG(EDITTIME::TEXT_DISABLED, colonTextDisabledColor);
392
393         GET_SHAPE_CONFIG(EDITTIME::AMPM_FONT_SIZE, __pEditTime->GetOrientation(), __amPmTextSize);
394
395         r = GET_BITMAP_CONFIG_N(EDITTIME::COLON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
396         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
397
398         __pColonColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_WHITE),
399                                                                               colonTextColor);
400         SysTryCatch(NID_UI_CTRL, (__pColonColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
401                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
402
403         __pColonDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_WHITE),
404                         colonTextDisabledColor);
405         SysTryCatch(NID_UI_CTRL, (__pColonDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
406                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
407
408         delete pTempBitmap;
409         pTempBitmap = null;
410
411         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
412         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
413
414         __pAmPmBgNormalColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonNormalBgColor);
415         SysTryCatch(NID_UI_CTRL, (__pAmPmBgNormalColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
416                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
417
418         delete pTempBitmap;
419         pTempBitmap = null;
420
421         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
422         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
423
424         __pAmPmBgDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonDisabledBgColor);
425         SysTryCatch(NID_UI_CTRL, (__pAmPmBgDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
426                                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
427
428         delete pTempBitmap;
429         pTempBitmap = null;
430
431         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
432         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
433
434         __pAmPmBgPressedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonNormalPressedColor);
435         SysTryCatch(NID_UI_CTRL, (__pAmPmBgPressedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
436                                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
437
438         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectNomralBitmap);
439         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
440
441         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectPressedBitmap);
442         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
443
444         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectDisabledBitmap);
445         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
446
447
448         delete pTempBitmap;
449         pTempBitmap = null;
450
451         return r;
452
453 CATCH:
454         delete pTempBitmap;
455         pTempBitmap = null;
456
457         delete __pAmPmBgNormalColorReplacementBitmap;
458         __pAmPmBgNormalColorReplacementBitmap = null;
459
460         delete __pAmPmBgPressedColorReplacementBitmap;
461         __pAmPmBgPressedColorReplacementBitmap = null;
462
463         delete __pAmPmBgEffectNomralBitmap;
464         __pAmPmBgEffectNomralBitmap = null;
465
466         delete __pAmPmBgEffectPressedBitmap;
467         __pAmPmBgEffectPressedBitmap = null;
468
469         delete __pColonColorReplacementBitmap;
470         __pColonColorReplacementBitmap = null;
471
472         return r;
473 }
474
475 result
476 _EditTimePresenter::DrawResourceBitmap(Canvas& canvas, const FloatRectangle& bounds, Bitmap* pBitmap)
477 {
478         result r = E_SUCCESS;
479
480         if (pBitmap == null)
481         {
482                 return r;
483         }
484
485         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
486         {
487                 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
488                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
489         }
490         else
491         {
492                 r = canvas.DrawBitmap(bounds, *pBitmap);
493                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
494         }
495
496         return r;
497 }
498
499 result
500 _EditTimePresenter::InitializeTitleObject(void)
501 {
502         result r = E_SUCCESS;
503
504         Color titleNormalColor;
505
506         GET_COLOR_CONFIG(EDITTIME::TITLE_TEXT_NORMAL, titleNormalColor);
507
508         r = __titleObject.Construct();
509         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
510
511         TextSimple* pSimpleText = null;
512
513         pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
514         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
515
516         __titleObject.AppendElement(*pSimpleText);
517
518         __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
519         __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
520         __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
521         __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
522         __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
523
524         return r;
525 }
526
527 result
528 _EditTimePresenter::InitializeTextObject(void)
529 {
530         result r = E_SUCCESS;
531
532         r = __textObject.Construct();
533         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
534
535         TextSimple* pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
536         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
537                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
538
539         __textObject.AppendElement(*pSimpleText);
540
541         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
542         __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
543         __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
544         __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
545
546         return r;
547 }
548
549 result
550 _EditTimePresenter::Draw(void)
551 {
552         result r = E_SUCCESS;
553
554         if (__isAnimating)
555         {
556                 return E_SUCCESS;
557         }
558
559         Canvas* pCanvas = __pEditTime->GetCanvasN();
560         SysAssertf((pCanvas != null), "Failed to get canvas.");
561
562         FloatRectangle colonBounds(0.0f, 0.0f, 0.0f, 0.0f);
563
564         float colonMargin = 0.0f;
565
566         Dimension textArea;
567
568         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
569         pCanvas->Clear();
570
571         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
572         FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
573         FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
574         bool isCustomBitmap = false;
575         Bitmap* pReplacementBitmap = null;
576         Bitmap* pEffectBitmap = null;
577
578         hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
579         minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
580
581         if (__24hours == false)
582         {
583                 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
584
585                 if (!__pEditTime->IsEnabled())
586                 {
587                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_DISABLED);
588                         pReplacementBitmap = __pAmPmBgDisabledColorReplacementBitmap;
589                         pEffectBitmap = __pAmPmBgEffectDisabledBitmap;
590                 }
591                 else if (__selectedId != DATETIME_ID_AMPM)
592                 {
593                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_NORMAL);
594                         pReplacementBitmap = __pAmPmBgNormalColorReplacementBitmap;
595                         pEffectBitmap = __pAmPmBgEffectNomralBitmap;
596                 }
597                 else
598                 {
599                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_PRESSED);
600                         pReplacementBitmap = __pAmPmBgPressedColorReplacementBitmap;
601                         pEffectBitmap = __pAmPmBgEffectPressedBitmap;
602                 }
603
604                 r = DrawResourceBitmap(*pCanvas, ampmBounds, pReplacementBitmap);
605                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
606
607                 if (!isCustomBitmap)
608                 {
609                         r = DrawResourceBitmap(*pCanvas, ampmBounds, pEffectBitmap);
610                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
611                 }
612         }
613
614         if (GetHour() >= DATETIME_HOUR_MAX_FOR_24NOTATION)
615         {
616                 SetAmEnabled(false);
617         }
618         else
619         {
620                 SetAmEnabled(true);
621         }
622
623         SetTimeConversion();
624
625         GET_SHAPE_CONFIG(EDITTIME::COLON_WIDTH, __pEditTime->GetOrientation(), colonBounds.width);
626         GET_SHAPE_CONFIG(EDITTIME::COLON_MARGIN, __pEditTime->GetOrientation(), colonMargin);
627         GET_SHAPE_CONFIG(EDITTIME::AMPM_HEIGHT, __pEditTime->GetOrientation(), colonBounds.height);
628
629         colonBounds.x = hourBounds.x + hourBounds.width + colonMargin;
630         colonBounds.y = hourBounds.y + (hourBounds.height - colonBounds.height) / 2.0f;
631
632         if (__title.IsEmpty() == false)
633         {
634                 r = DrawTitle(*pCanvas);
635                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
636         }
637
638         r = DrawText(*pCanvas, hourBounds, __hourString);
639         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
640
641         r = DrawText(*pCanvas, minuteBounds, __minuteString);
642         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
643
644         if (__24hours == false)
645         {
646                 r = DrawText(*pCanvas, ampmBounds, __ampmString, __amPmTextSize);
647                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
648         }
649
650         r = DrawColon(*pCanvas, colonBounds);
651         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
652
653 CATCH:
654         delete pCanvas;
655
656         return r;
657 }
658
659 result
660 _EditTimePresenter::DrawColon(Canvas& canvas, const FloatRectangle& bounds)
661 {
662         result r = E_SUCCESS;
663
664         if (!__pEditTime->IsEnabled())
665         {
666                 r = DrawResourceBitmap(canvas, bounds, __pColonDisabledColorReplacementBitmap);
667         }
668         else
669         {
670                 r = DrawResourceBitmap(canvas, bounds, __pColonColorReplacementBitmap);
671         }
672
673         if ( r != E_SUCCESS)
674         {
675                 r = DrawText(canvas, bounds, L":");
676                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
677         }
678
679         return r;
680 }
681
682 result
683 _EditTimePresenter::DrawTitle(Canvas& canvas)
684 {
685         if (!__pEditTime->IsEnabled())
686         {
687                 Color titleDisabledColor;
688                 GET_COLOR_CONFIG(EDITTIME::TITLE_TEXT_DISABLED, titleDisabledColor);
689                 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
690         }
691
692         (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
693         __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
694
695         __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
696
697         return E_SUCCESS;
698 }
699
700 result
701 _EditTimePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, float textSize)
702 {
703         result r = E_SUCCESS;
704
705         Color textColor;
706
707         _DateTimeId boxId = DATETIME_ID_NONE;
708         boxId = GetBoxIdFromPosition(FloatPoint(bounds.x + 1.0f, bounds.y));
709
710         if (!__pEditTime->IsEnabled())
711         {
712                 if (boxId == DATETIME_ID_AMPM)
713                 {
714                         GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_DISABLED, textColor);
715                 }
716                 else
717                 {
718                         GET_COLOR_CONFIG(EDITTIME::TEXT_DISABLED, textColor);
719                 }
720         }
721         else
722         {
723                 GET_COLOR_CONFIG(EDITTIME::TEXT_NORMAL, textColor);
724
725                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated() &&
726                                 (GetLastSelectedId() == boxId))
727                 {
728                         GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
729                 }
730
731                 if (boxId == DATETIME_ID_AMPM)
732                 {
733                         GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_NORMAL, textColor);
734                 }
735
736                 if (boxId > -1 && boxId == __selectedId)
737                 {
738                         if (boxId == DATETIME_ID_AMPM)
739                         {
740                                 GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_PRESSED, textColor);
741                         }
742                         else
743                         {
744                                 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
745                         }
746                 }
747         }
748
749         FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
750         drawAreaBounds = bounds;
751
752         TextSimple* pSimpleText = null;
753         pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
754         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
755
756         __textObject.RemoveAll();
757
758         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
759
760         __textObject.AppendElement(*pSimpleText);
761
762         if (boxId == DATETIME_ID_AMPM)
763         {
764                 (_FontImpl::GetInstance(*__pFont))->SetSize(textSize);
765                 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
766         }
767         else
768         {
769                 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
770         }
771
772         __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
773         __textObject.SetBounds(drawAreaBounds);
774         __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
775
776         return r;
777 }
778
779 _DateTimeId
780 _EditTimePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
781 {
782         _DateTimeId displayBoxId = DATETIME_ID_NONE;
783
784         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
785         FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
786         FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
787
788         hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
789         minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
790
791         if (__24hours == false)
792         {
793                 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
794         }
795
796         if (point.y < hourBounds.y || point.y > hourBounds.y + hourBounds.height)
797         {
798                 return displayBoxId;
799         }
800
801         if (hourBounds.Contains(point) == true)
802         {
803                 displayBoxId = DATETIME_ID_HOUR;
804         }
805         else if (minuteBounds.Contains(point) == true)
806         {
807                 displayBoxId = DATETIME_ID_MINUTE;
808         }
809         else if (ampmBounds.Contains(point) == true)
810         {
811                 displayBoxId = DATETIME_ID_AMPM;
812         }
813
814         return displayBoxId;
815 }
816
817 void
818 _EditTimePresenter::SetLastSelectedId(_DateTimeId boxId)
819 {
820         __lastSelectedId = boxId;
821         return;
822 }
823
824 _DateTimeId
825 _EditTimePresenter::GetLastSelectedId(void) const
826 {
827         return __lastSelectedId;
828 }
829
830 bool
831 _EditTimePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
832 {
833         SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
834
835         if (&source != __pEditTime)
836         {
837                 return false;
838         }
839
840         __touchMoveHandled = false;
841
842         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
843         FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
844         FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
845
846         hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
847         minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
848
849         if (__24hours == false)
850         {
851                 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
852         }
853
854         FloatPoint point = touchinfo.GetCurrentPosition();
855
856         _DateTimeId boxId = GetBoxIdFromPosition(point);
857
858         int minValue = -1;
859         int maxValue = -1;
860         int displayValue = -1;
861
862         if (boxId == DATETIME_ID_HOUR)
863         {
864                 if (__pEditTime->GetDateTimeBar() != null)
865                 {
866                         if (__24hours == false)
867                         {
868                                 if (GetHour() == 0)
869                                 {
870                                         minValue = DATETIME_HOUR_MIN + 1;
871                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
872                                         displayValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
873                                 }
874                                 else if (GetHour() > DATETIME_HOUR_MAX_FOR_24NOTATION)
875                                 {
876                                         minValue = DATETIME_HOUR_MIN + 1;
877                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
878                                         displayValue = GetHour() - DATETIME_HOUR_MAX_FOR_24NOTATION;
879                                 }
880                                 else
881                                 {
882                                         minValue = DATETIME_HOUR_MIN + 1;
883                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
884                                         displayValue = GetHour();
885                                 }
886                         }
887                         else
888                         {
889                                 minValue = DATETIME_HOUR_MIN;
890                                 maxValue = DATETIME_HOUR_MAX;
891                                 displayValue = GetHour();
892                         }
893
894                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
895                         {
896                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
897                         }
898
899                         __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
900                 }
901
902                 __bounds = hourBounds;
903         }
904         else if (boxId == DATETIME_ID_MINUTE)
905         {
906                 if (__pEditTime->GetDateTimeBar() != null)
907                 {
908                         minValue = DATETIME_MINUTE_MIN;
909                         maxValue = DATETIME_MINUTE_MAX;
910                         displayValue = GetMinute();
911
912                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
913                         {
914                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
915                         }
916
917                         __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
918                 }
919
920                 __bounds = minuteBounds;
921         }
922         else if (boxId == DATETIME_ID_AMPM)
923         {
924                 __selectedId = boxId;
925                 __bounds = ampmBounds;
926                 Draw();
927         }
928         else
929         {
930                 __selectedId = DATETIME_ID_NONE;
931                 return false;
932         }
933
934         __selectedId = boxId;
935
936         return true;
937 }
938
939 bool
940 _EditTimePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
941 {
942         SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
943
944         if (&source != __pEditTime)
945         {
946                 return false;
947         }
948
949         FloatRectangle bounds = __pEditTime->GetBoundsF();
950
951         FloatPoint startPoint(0.0f, 0.0f);
952
953         float titleHeight = 0;
954         GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, __pEditTime->GetOrientation(), titleHeight);
955
956         __bounds = FloatRectangle(0.0f, titleHeight, bounds.width, bounds.height);
957
958         FloatPoint point = touchinfo.GetCurrentPosition();
959
960         _DateTimeId boxId = GetBoxIdFromPosition(point);
961
962         if (boxId != __selectedId || boxId == DATETIME_ID_NONE)
963         {
964                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
965                 {
966                         __pEditTime->GetDateTimeBar()->SetVisibleState(false);
967                         __pEditTime->GetDateTimeBar()->Close();
968                 }
969
970                 __selectedId = DATETIME_ID_NONE;
971                 SetLastSelectedId(__selectedId);
972
973                 Draw();
974
975                 return true;
976         }
977
978         SetLastSelectedId(__selectedId);
979
980         __lastSelectedValue = "";
981         _DateTimeUtils dateTimeUtils;
982
983         if (GetLastSelectedId() == DATETIME_ID_HOUR)
984         {
985                 int hours = GetHour();
986
987                 if (!Is24HourNotationEnabled())
988                 {
989                         hours = hours % 12;
990
991                         if (hours == DATETIME_HOUR_MIN)
992                         {
993                                 hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
994                         }
995                 }
996                 __lastSelectedValue.Format(10, L"%02d", hours);
997                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
998         }
999         else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1000         {
1001                 __lastSelectedValue.Format(10, L"%02d", GetMinute());
1002                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1003         }
1004         else if (GetLastSelectedId() == DATETIME_ID_AMPM)
1005         {
1006                 SetAmEnabled(!GetAmEnabled());
1007                 __pEditTime->FireTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1008                 __pEditTime->UpdateAccessibilityElement();
1009                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1010
1011                 __selectedId = DATETIME_ID_NONE;
1012
1013                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1014                 {
1015                         __pEditTime->GetDateTimeBar()->SetVisibleState(false);
1016                         __pEditTime->GetDateTimeBar()->Close();
1017                 }
1018
1019                 Draw();
1020
1021                 return true;
1022         }
1023
1024         Draw();
1025
1026         if ((__pEditTime->GetDateTimeBar() != null) && (boxId != DATETIME_ID_AMPM) && (GetLastSelectedId() != DATETIME_ID_NONE))
1027         {
1028                 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1029                 bounds = GetDisplayAreaBoundsFromHoursStyle(GetLastSelectedId());
1030                 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1031                 absoluteBounds = __pEditTime->GetAbsoluteBoundsF();
1032                 bounds.x += absoluteBounds.x;
1033
1034                 __pEditTime->GetDateTimeBar()->CalculateArrowBounds(bounds);
1035
1036                 if (__pEditTime->GetDateTimeBar()->IsActivated())
1037                 {
1038                         __pEditTime->GetDateTimeBar()->RefreshItems();
1039                 }
1040                 else
1041                 {
1042                         __pEditTime->GetDateTimeBar()->SetVisibleState(true);
1043                         __pEditTime->GetDateTimeBar()->Open();
1044                 }
1045         }
1046
1047         __selectedId = DATETIME_ID_NONE;
1048         return true;
1049 }
1050
1051 bool
1052 _EditTimePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1053 {
1054         if (&source != __pEditTime)
1055         {
1056                 return false;
1057         }
1058
1059         __selectedId = DATETIME_ID_NONE;
1060
1061         return true;
1062 }
1063
1064 bool
1065 _EditTimePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1066 {
1067         if (&source != __pEditTime)
1068         {
1069                 return false;
1070         }
1071
1072         if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1073         {
1074                 return true;
1075         }
1076
1077         return false;
1078 }
1079
1080 void
1081 _EditTimePresenter::OnTouchMoveHandled(const _Control& control)
1082 {
1083         __touchMoveHandled = true;
1084         __selectedId = DATETIME_ID_NONE;
1085
1086         return;
1087 }
1088
1089 void
1090 _EditTimePresenter::OnFontChanged(Font* pFont)
1091 {
1092         __pFont = pFont;
1093
1094         if (__pEditTime->GetDateTimeBar() != null)
1095         {
1096                 __pEditTime->GetDateTimeBar()->SetFont(*pFont);
1097         }
1098
1099         return;
1100 }
1101
1102 void
1103 _EditTimePresenter::OnFontInfoRequested(unsigned long& style, float& size)
1104 {
1105         style = FONT_STYLE_PLAIN;
1106         size = __timeFontSize;
1107
1108         return;
1109 }
1110
1111 result
1112 _EditTimePresenter::Initialize(void)
1113 {
1114         result r = E_SUCCESS;
1115
1116         float titleTimeMargin = 0;
1117         float timeHeight = 0;
1118         float editTimeHeight = 0;
1119
1120         GET_SHAPE_CONFIG(EDITTIME::TEXT_FONT_SIZE, __pEditTime->GetOrientation(), __titleFontSize);
1121         GET_SHAPE_CONFIG(EDITTIME::TIME_FONT_SIZE, __pEditTime->GetOrientation(), __timeFontSize);
1122         GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, __pEditTime->GetOrientation(), titleTimeMargin);
1123         GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, __pEditTime->GetOrientation(), timeHeight);
1124         GET_SHAPE_CONFIG(EDITTIME::HEIGHT, __pEditTime->GetOrientation(), editTimeHeight);
1125
1126         if (__pEditTime->GetBoundsF().height > editTimeHeight)
1127         {
1128                 editTimeHeight = __pEditTime->GetBoundsF().height;
1129         }
1130
1131         if (__title.IsEmpty() == false)
1132         {
1133                 SetTitleBounds();
1134                 if (!__isEditTimeInitialized)
1135                 {
1136                         r = InitializeTitleObject();
1137                         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1138                 }
1139
1140                 __titleBounds.y = (editTimeHeight - (__titleBounds.height + titleTimeMargin + timeHeight)) / 2.0f;
1141                 __titleObject.SetBounds(__titleBounds);
1142         }
1143
1144         __pFont = __pEditTime->GetFallbackFont();
1145         r = GetLastResult();
1146         SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1147
1148         if (!__isEditTimeInitialized)
1149         {
1150                 r = LoadResource();
1151                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1152
1153                 r = InitializeTextObject();
1154                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1155         }
1156
1157         __isEditTimeInitialized = true;
1158
1159         UpdateTimeFormat();
1160         return r;
1161 }
1162
1163 void
1164 _EditTimePresenter::UpdateTimeFormat(void)
1165 {
1166         if (!__is24hoursSet)
1167         {
1168                 String key(L"http://tizen.org/setting/locale.time.format.24hour");
1169                 SettingInfo::GetValue(key , __24hours);
1170         }
1171
1172         return;
1173 }
1174
1175 void
1176 _EditTimePresenter::Animate(void)
1177 {
1178         SysAssertf((__pFont != null), "Font instance must not be null.");
1179
1180         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1181
1182         result r = E_SUCCESS;
1183         FloatRectangle rect;
1184         String hourString;
1185         String minuteString;
1186         String newValue;
1187
1188         _DateTimeUtils dateTimeUtils;
1189         int hours = GetHour();
1190         if (!Is24HourNotationEnabled())
1191         {
1192                 hours = hours % 12;
1193
1194                 if (hours == DATETIME_HOUR_MIN)
1195                 {
1196                         hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
1197                 }
1198         }
1199         hourString.Format(10, L"%02d", hours);
1200         minuteString.Format(10, L"%02d", GetMinute());
1201
1202         if (GetLastSelectedId() == DATETIME_ID_HOUR)
1203         {
1204                 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(hourString) == false), E_SUCCESS, "[E_SUCCESS] Hour string matched.");
1205
1206                 newValue = hourString;
1207                 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1208         }
1209         else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1210         {
1211                 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(minuteString) == false), E_SUCCESS, "[E_SUCCESS] Minute string matched.");
1212
1213                 newValue = minuteString;
1214                 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1215         }
1216
1217         FloatDimension newTextDim;
1218         FloatDimension oldTextDim;
1219         FloatPoint textPoint;
1220         VisualElement* pNewVisualElement = null;
1221         VisualElement* pOldVisualElement = null;
1222         VisualElement* pEditTimeElement = null;
1223         VisualElementPropertyAnimation* pNewBoundsAnimation = null;
1224         VisualElementPropertyAnimation* pOldBoundsAnimation = null;
1225         Canvas *pCanvas = null;
1226
1227         __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1228         __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1229
1230         if (newTextDim.width > oldTextDim.width)
1231         {
1232                 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1233         }
1234         else
1235         {
1236                 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1237         }
1238
1239         SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditTime->GetBounds().width), E_SUCCESS, "Rolling animation cann't be played.");
1240
1241         __isAnimating = true;
1242
1243         __pContentProvider = new (std::nothrow) VisualElement();
1244         SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1245
1246         r = __pContentProvider->Construct();
1247         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1248
1249         __pContentProvider->SetShowState(true);
1250         __pContentProvider->SetClipChildrenEnabled(true);
1251         __pContentProvider->SetImplicitAnimationEnabled(false);
1252
1253         pEditTimeElement = __pEditTime->GetVisualElement();
1254         r = GetLastResult();
1255         SysTryCatch(NID_UI_CTRL, (pEditTimeElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1256
1257         pNewVisualElement = new (std::nothrow) VisualElement();
1258         SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1259
1260         r = pNewVisualElement->Construct();
1261         if (r != E_SUCCESS)
1262         {
1263                 pNewVisualElement->Destroy();
1264         }
1265         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1266
1267         pNewVisualElement->SetShowState(true);
1268
1269         pOldVisualElement = new (std::nothrow) VisualElement();
1270         if (pOldVisualElement == null)
1271         {
1272                 pNewVisualElement->Destroy();
1273         }
1274         SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1275
1276         r = pOldVisualElement->Construct();
1277         if (r != E_SUCCESS)
1278         {
1279                 pNewVisualElement->Destroy();
1280                 pOldVisualElement->Destroy();
1281         }
1282         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1283
1284         pOldVisualElement->SetShowState(true);
1285
1286         if (newTextDim.width > oldTextDim.width)
1287         {
1288                 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1289                 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1290                 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1291                 pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1292
1293                 rect.x = __pContentProvider->GetBounds().x;
1294                 rect.y = __pContentProvider->GetBounds().y;
1295                 rect.width = __pContentProvider->GetBounds().width;
1296                 rect.height = __pContentProvider->GetBounds().height;
1297
1298                 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1299                 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1300
1301                 pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1302         }
1303         else
1304         {
1305                 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1306                 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1307                 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1308                 pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1309
1310                 rect.x = __pContentProvider->GetBounds().x;
1311                 rect.y = __pContentProvider->GetBounds().y;
1312                 rect.width = __pContentProvider->GetBounds().width;
1313                 rect.height = __pContentProvider->GetBounds().height;
1314
1315                 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1316                 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1317
1318                 pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1319         }
1320
1321         pCanvas = pEditTimeElement->GetCanvasN(rect);
1322         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1323         pCanvas->Clear();
1324         delete pCanvas;
1325
1326         pEditTimeElement->AttachChild(*__pContentProvider);
1327
1328         __pContentProvider->AttachChild(*pOldVisualElement);
1329         __pContentProvider->AttachChild(*pNewVisualElement);
1330
1331         pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1332         SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1333
1334         pNewBoundsAnimation->SetDuration(300);
1335         pNewBoundsAnimation->SetPropertyName("bounds.position");
1336         pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
1337         pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
1338         pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1339
1340         pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1341         SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1342
1343         pOldBoundsAnimation->SetDuration(300);
1344         pOldBoundsAnimation->SetPropertyName("bounds.position");
1345         pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, 0.0f)));
1346         pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
1347         pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1348
1349         pCanvas = pOldVisualElement->GetCanvasN();
1350         r = GetLastResult();
1351         SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1352
1353         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1354         pCanvas->Clear();
1355         pCanvas->SetFont(*__pFont);
1356         pCanvas->DrawText(FloatPoint(0.0f, 0.0f), __lastSelectedValue);
1357
1358         delete pCanvas;
1359         pCanvas = null;
1360
1361         pCanvas = pNewVisualElement->GetCanvasN();
1362         r = GetLastResult();
1363         SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1364
1365         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1366         pCanvas->Clear();
1367         pCanvas->SetFont(*__pFont);
1368         pCanvas->DrawText(FloatPoint(0.0f, 0.0f), newValue);
1369
1370         delete pCanvas;
1371         pCanvas = null;
1372
1373         pOldVisualElement->SetImplicitAnimationEnabled(false);
1374         pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1375
1376         pNewVisualElement->SetImplicitAnimationEnabled(false);
1377         pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1378
1379         delete pOldBoundsAnimation;
1380         delete pNewBoundsAnimation;
1381
1382         return;
1383
1384 CATCH:
1385         __isAnimating = false;
1386         __pContentProvider->Destroy();
1387
1388         delete pNewBoundsAnimation;
1389         pNewBoundsAnimation = null;
1390
1391         delete pOldBoundsAnimation;
1392         pOldBoundsAnimation = null;
1393
1394         delete pCanvas;
1395         pCanvas = null;
1396
1397         return;
1398 }
1399
1400 void
1401 _EditTimePresenter::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
1402 {
1403         result r = E_SUCCESS;
1404         __isAnimating = false;
1405
1406         VisualElement* pEditTimeElement = __pEditTime->GetVisualElement();
1407         r = GetLastResult();
1408         SysTryReturnVoidResult(NID_UI_CTRL, (pEditTimeElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1409
1410         pEditTimeElement->DetachChild(*__pContentProvider);
1411         __pContentProvider->Destroy();
1412
1413         Draw();
1414         return;
1415 }
1416
1417 }}} // Tizen::Ui::Controls