2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrl_EditTimePresenter.cpp
20 * @brief This is the implementation file for the _EditTimePresenter class.
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"
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;
44 namespace Tizen { namespace Ui { namespace Controls
46 _EditTimePresenter::_EditTimePresenter(const String& title)
47 : __pEditDateTimeModel(null)
49 , __bounds(FloatRectangle())
50 , __titleBounds(FloatRectangle())
51 , __ampmString(String())
52 , __hourString(String())
53 , __minuteString(String())
56 , __is24hoursSet(false)
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 , __pAmPmBgHighlightedColorReplacementBitmap(null)
66 , __pAmPmBgEffectNomralBitmap(null)
67 , __pAmPmBgEffectPressedBitmap(null)
68 , __pAmPmBgEffectDisabledBitmap(null)
69 , __pColonColorReplacementBitmap(null)
70 , __pColonDisabledColorReplacementBitmap(null)
71 , __pContentBgNormalColorReplacementBitmap(null)
72 , __pContentBgDisabledColorReplacementBitmap(null)
73 , __pContentBgPressedColorReplacementBitmap(null)
74 , __pContentBgHighlightedColorReplacementBitmap(null)
75 , __pContentBgEffectNormalBitmap(null)
76 , __pContentBgEffectPressedBitmap(null)
77 , __pContentBgEffectDisabledBitmap(null)
78 , __pContentProvider(null)
82 , __amPmTextSize(0.0f)
83 , __titleFontSize(0.0f)
84 , __timeFontSize(0.0f)
85 , __isAnimating(false)
86 , __isEditTimeInitialized(false)
90 _EditTimePresenter::~_EditTimePresenter(void)
92 __textObject.RemoveAll();
93 __titleObject.RemoveAll();
95 delete __pEditDateTimeModel;
96 __pEditDateTimeModel = null;
98 delete __pAmPmBgNormalColorReplacementBitmap;
99 __pAmPmBgNormalColorReplacementBitmap = null;
101 delete __pAmPmBgDisabledColorReplacementBitmap;
102 __pAmPmBgDisabledColorReplacementBitmap = null;
104 delete __pAmPmBgPressedColorReplacementBitmap;
105 __pAmPmBgPressedColorReplacementBitmap = null;
107 delete __pAmPmBgHighlightedColorReplacementBitmap;
108 __pAmPmBgHighlightedColorReplacementBitmap = null;
110 delete __pAmPmBgEffectNomralBitmap;
111 __pAmPmBgEffectNomralBitmap = null;
113 delete __pAmPmBgEffectPressedBitmap;
114 __pAmPmBgEffectPressedBitmap = null;
116 delete __pAmPmBgEffectDisabledBitmap;
117 __pAmPmBgEffectDisabledBitmap = null;
119 delete __pColonColorReplacementBitmap;
120 __pColonColorReplacementBitmap = null;
122 delete __pColonDisabledColorReplacementBitmap;
123 __pColonDisabledColorReplacementBitmap = null;
125 delete __pContentBgNormalColorReplacementBitmap;
126 __pContentBgNormalColorReplacementBitmap = null;
128 delete __pContentBgDisabledColorReplacementBitmap;
129 __pContentBgDisabledColorReplacementBitmap = null;
131 delete __pContentBgPressedColorReplacementBitmap;
132 __pContentBgPressedColorReplacementBitmap = null;
134 delete __pContentBgHighlightedColorReplacementBitmap;
135 __pContentBgHighlightedColorReplacementBitmap = null;
137 delete __pContentBgEffectNormalBitmap;
138 __pContentBgEffectNormalBitmap = null;
140 delete __pContentBgEffectPressedBitmap;
141 __pContentBgEffectPressedBitmap = null;
143 delete __pContentBgEffectDisabledBitmap;
144 __pContentBgEffectDisabledBitmap = null;
148 _EditTimePresenter::CreateInstanceN(const _EditTime& editTime, const String& title)
150 _EditTimePresenter* pEditTimePresenter = new (std::nothrow) _EditTimePresenter(title);
151 SysTryReturn(NID_UI_CTRL, pEditTimePresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
153 pEditTimePresenter->__pEditTime = const_cast <_EditTime*>(&editTime);
155 pEditTimePresenter->__pEditDateTimeModel = new (std::nothrow) _DateTimeModel;
156 SysTryCatch(NID_UI_CTRL, pEditTimePresenter->__pEditDateTimeModel, , E_OUT_OF_MEMORY,
157 "[E_OUT_OF_MEMORY] Memory allocation failed.");
159 return pEditTimePresenter;
162 delete pEditTimePresenter;
167 _EditTimePresenter::GetTime(void) const
170 time.SetValue(DATETIME_YEAR_MIN, DATETIME_MONTH_MIN, DATETIME_DAY_MIN, GetHour(), GetMinute(), 0);
176 _EditTimePresenter::GetHour(void) const
178 return __pEditDateTimeModel->GetHour();
182 _EditTimePresenter::GetMinute(void) const
184 return __pEditDateTimeModel->GetMinute();
188 _EditTimePresenter::SetTime(const DateTime& time)
190 __pEditDateTimeModel->SetDateTime(time);
194 _EditTimePresenter::SetCurrentTime(void)
196 __pEditDateTimeModel->SetCurrentDateTime();
201 _EditTimePresenter::SetHour(int hour)
203 return __pEditDateTimeModel->SetHour(hour);
207 _EditTimePresenter::SetMinute(int minute)
209 return __pEditDateTimeModel->SetMinute(minute);
213 _EditTimePresenter::SetTimePickerEnabled(bool enable)
215 __timePickerEnabled = enable;
220 _EditTimePresenter::IsTimePickerEnabled(void) const
222 return __timePickerEnabled;
226 _EditTimePresenter::Set24HourNotationEnabled(bool enable)
229 __is24hoursSet = true;
234 _EditTimePresenter::Is24HourNotationEnabled(void) const
240 _EditTimePresenter::SetTimeConversion(void)
242 int hour = GetHour();
243 int minute = GetMinute();
245 if (__24hours == false)
247 int max = DATETIME_HOUR_MAX_FOR_24NOTATION;
251 __hourString.Format(10, L"%02d", hour - max);
253 else if (hour == DATETIME_HOUR_MIN)
255 __hourString.Format(10, L"%02d", hour + DATETIME_HOUR_MAX_FOR_24NOTATION);
259 __hourString.Format(10, L"%02d", hour);
262 __minuteString.Format(10, L"%02d", minute);
266 __hourString.Format(10, L"%02d", hour);
267 __minuteString.Format(10, L"%02d", minute);
274 _EditTimePresenter::SetAmEnabled(bool amEnable)
279 _DateTimeUtils dateTimeUtils;
280 dateTimeUtils.GetAmPm(textAm, AM_TYPE);
281 dateTimeUtils.GetAmPm(textPm, PM_TYPE);
283 __amEnable = amEnable;
284 int hour = GetHour();
286 if (__amEnable == true)
288 __ampmString = textAm;
289 if (hour >= DATETIME_HOUR_MAX_FOR_24NOTATION)
291 SetHour(hour - DATETIME_HOUR_MAX_FOR_24NOTATION);
296 __ampmString = textPm;
297 if (hour < DATETIME_HOUR_MAX_FOR_24NOTATION)
299 SetHour(hour + DATETIME_HOUR_MAX_FOR_24NOTATION);
307 _EditTimePresenter::GetAmEnabled(void) const
313 _EditTimePresenter::GetDisplayAreaBoundsFromHoursStyle(_DateTimeId displayBoxId) const
315 SysTryReturn(NID_UI_CTRL, displayBoxId >= DATETIME_ID_HOUR && displayBoxId <= DATETIME_ID_AMPM, FloatRectangle(),
316 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] displayBoxId is out of range.");
318 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
320 float editTimeHeight = 0.0f;
321 float colonWidth = 0.0f;
322 float timeAmPmMargin = 0.0f;
323 float colonMargin = 0.0f;
324 float timeElementWidth = 0.0f;
325 float amPmHeight = 0.0f;
326 float timeHeight = 0.0f;
327 float titleTimeMargin = 0.0f;
328 float leftMargin = 0.0f;
330 GET_SHAPE_CONFIG(EDITTIME::HEIGHT, __pEditTime->GetOrientation(), editTimeHeight);
331 GET_SHAPE_CONFIG(EDITTIME::COLON_WIDTH, __pEditTime->GetOrientation(), colonWidth);
332 GET_SHAPE_CONFIG(EDITTIME::TIME_AMPM_MARGIN, __pEditTime->GetOrientation(), timeAmPmMargin);
333 GET_SHAPE_CONFIG(EDITTIME::COLON_MARGIN, __pEditTime->GetOrientation(), colonMargin);
334 GET_SHAPE_CONFIG(EDITTIME::AMPM_HEIGHT, __pEditTime->GetOrientation(), amPmHeight);
335 GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, __pEditTime->GetOrientation(), titleTimeMargin);
336 GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, __pEditTime->GetOrientation(), timeHeight);
338 GET_SHAPE_CONFIG(EDITTIME::TIME_TEXT_LEFT_MARGIN, __pEditTime->GetOrientation(), leftMargin);
340 if (__pEditTime->GetBoundsF().height > bounds.height)
342 editTimeHeight = __pEditTime->GetBoundsF().height;
345 bounds.y = (editTimeHeight - timeHeight) / 2.0f;
347 if (!__title.IsEmpty())
349 if (displayBoxId == DATETIME_ID_AMPM)
351 bounds.y = __titleBounds.y + __titleBounds.height;
355 bounds.y = __titleBounds.y + __titleBounds.height + titleTimeMargin;
359 bounds.x = leftMargin;
360 bounds.height = timeHeight;
362 timeElementWidth = GetTimeElementWidth();
364 if (displayBoxId == DATETIME_ID_HOUR)
366 bounds.width = timeElementWidth;
368 else if (displayBoxId == DATETIME_ID_MINUTE)
370 bounds.x = bounds.x + timeElementWidth + colonWidth + (2.0f * colonMargin);
371 bounds.width = timeElementWidth;
373 else if (displayBoxId == DATETIME_ID_AMPM)
375 bounds.x = leftMargin + (2.0f * timeElementWidth) + colonWidth + (2.0f * colonMargin) + timeAmPmMargin;
377 if (__title.IsEmpty())
379 bounds.y = (editTimeHeight - amPmHeight) / 2.0f;
382 GET_SHAPE_CONFIG(EDITTIME::AMPM_WIDTH, __pEditTime->GetOrientation(), bounds.width);
383 bounds.height = amPmHeight;
390 _EditTimePresenter::GetTextWidth(_DateTimeId boxId) const
392 result r = E_SUCCESS;
394 TextObject dateObject;
398 hourString.Format(10, L"%02d", GetHour());
399 minuteString.Format(10, L"%02d", GetMinute());
401 r = dateObject.Construct();
402 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
404 TextSimple* pSimpleText = null;
406 if (boxId == DATETIME_ID_HOUR)
408 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(hourString.GetPointer())), hourString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
410 else if (boxId == DATETIME_ID_MINUTE)
412 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(minuteString.GetPointer())), minuteString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
415 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), dim.width, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
417 (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
419 dateObject.AppendElement(*pSimpleText);
420 dateObject.SetFont(__pFont, 0, dateObject.GetTextLength());
421 dim = dateObject.GetTextExtentF(0, dateObject.GetTextLength());
423 dateObject.RemoveAll();
428 _EditTimePresenter::SetTitleBounds(void)
430 GET_SHAPE_CONFIG(EDITTIME::TITLE_TEXT_LEFT_MARGIN, __pEditTime->GetOrientation(), __titleBounds.x);
431 GET_SHAPE_CONFIG(EDITTIME::WIDTH, __pEditTime->GetOrientation(), __titleBounds.width);
432 GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, __pEditTime->GetOrientation(), __titleBounds.height);
434 __titleBounds.width = __titleBounds.width - __titleBounds.x;
439 _EditTimePresenter::GetTitleBounds(void) const
441 return __titleBounds;
445 _EditTimePresenter::LoadResource(void)
447 result r = E_SUCCESS;
449 Color buttonNormalBgColor;
450 Color buttonDisabledBgColor;
451 Color buttonPressedColor;
452 Color buttonHighlightedColor;
453 Color contentNormalBgColor;
454 Color contentDisabledBgColor;
455 Color contentPressedColor;
456 Color contentHighlightedColor;
457 Color colonTextColor;
458 Color colonTextDisabledColor;
459 Bitmap* pTempBitmap = null;
461 GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_NORMAL, buttonNormalBgColor);
462 GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_PRESSED, buttonPressedColor);
463 GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_DISABLED, buttonDisabledBgColor);
464 GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_HIGHLIGHTED, buttonHighlightedColor);
466 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_NORMAL, contentNormalBgColor);
467 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_DISABLED, contentDisabledBgColor);
468 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentPressedColor);
469 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
471 GET_COLOR_CONFIG(EDITTIME::TEXT_NORMAL, colonTextColor);
472 GET_COLOR_CONFIG(EDITTIME::TEXT_DISABLED, colonTextDisabledColor);
474 GET_SHAPE_CONFIG(EDITTIME::AMPM_FONT_SIZE, __pEditTime->GetOrientation(), __amPmTextSize);
476 r = GET_BITMAP_CONFIG_N(EDITTIME::COLON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
477 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
479 __pColonColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA),
481 SysTryCatch(NID_UI_CTRL, (__pColonColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
482 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
484 __pColonDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA),
485 colonTextDisabledColor);
486 SysTryCatch(NID_UI_CTRL, (__pColonDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
487 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
492 r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
493 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
495 __pAmPmBgNormalColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonNormalBgColor);
496 SysTryCatch(NID_UI_CTRL, (__pAmPmBgNormalColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
497 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
502 r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
503 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
505 __pAmPmBgDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonDisabledBgColor);
506 SysTryCatch(NID_UI_CTRL, (__pAmPmBgDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
507 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
512 r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
513 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
515 __pAmPmBgPressedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonPressedColor);
516 SysTryCatch(NID_UI_CTRL, (__pAmPmBgPressedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
517 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
522 r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
523 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
525 __pAmPmBgHighlightedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonHighlightedColor);
526 SysTryCatch(NID_UI_CTRL, (__pAmPmBgHighlightedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
527 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
532 r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
533 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
535 __pContentBgNormalColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentNormalBgColor);
536 SysTryCatch(NID_UI_CTRL, (__pContentBgNormalColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
537 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
542 r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
543 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
545 __pContentBgPressedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentPressedColor);
546 SysTryCatch(NID_UI_CTRL, (__pContentBgPressedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
547 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
552 r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
553 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
555 __pContentBgDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentDisabledBgColor);
556 SysTryCatch(NID_UI_CTRL, (__pContentBgDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
557 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
562 r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
563 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
565 __pContentBgHighlightedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentHighlightedColor);
566 SysTryCatch(NID_UI_CTRL, (__pContentBgHighlightedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
567 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
569 r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectNomralBitmap);
570 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
572 r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectPressedBitmap);
573 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
575 r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectDisabledBitmap);
576 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
578 r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectNormalBitmap);
579 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
581 r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectPressedBitmap);
582 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
584 r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectDisabledBitmap);
585 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
597 delete __pAmPmBgNormalColorReplacementBitmap;
598 __pAmPmBgNormalColorReplacementBitmap = null;
600 delete __pAmPmBgPressedColorReplacementBitmap;
601 __pAmPmBgPressedColorReplacementBitmap = null;
603 delete __pAmPmBgDisabledColorReplacementBitmap;
604 __pAmPmBgDisabledColorReplacementBitmap = null;
606 delete __pAmPmBgHighlightedColorReplacementBitmap;
607 __pAmPmBgHighlightedColorReplacementBitmap = null;
609 delete __pContentBgNormalColorReplacementBitmap;
610 __pContentBgNormalColorReplacementBitmap = null;
612 delete __pContentBgPressedColorReplacementBitmap;
613 __pContentBgPressedColorReplacementBitmap = null;
615 delete __pContentBgDisabledColorReplacementBitmap;
616 __pContentBgDisabledColorReplacementBitmap = null;
618 delete __pContentBgHighlightedColorReplacementBitmap;
619 __pContentBgHighlightedColorReplacementBitmap = null;
621 delete __pAmPmBgEffectNomralBitmap;
622 __pAmPmBgEffectNomralBitmap = null;
624 delete __pAmPmBgEffectPressedBitmap;
625 __pAmPmBgEffectPressedBitmap = null;
627 delete __pAmPmBgEffectDisabledBitmap;
628 __pAmPmBgEffectDisabledBitmap = null;
630 delete __pContentBgEffectNormalBitmap;
631 __pContentBgEffectNormalBitmap = null;
633 delete __pContentBgEffectPressedBitmap;
634 __pContentBgEffectPressedBitmap = null;
636 delete __pContentBgEffectDisabledBitmap;
637 __pContentBgEffectDisabledBitmap = null;
639 delete __pColonColorReplacementBitmap;
640 __pColonColorReplacementBitmap = null;
642 delete __pColonDisabledColorReplacementBitmap;
643 __pColonDisabledColorReplacementBitmap = null;
649 _EditTimePresenter::DrawResourceBitmap(Canvas& canvas, const FloatRectangle& bounds, Bitmap* pBitmap)
651 result r = E_SUCCESS;
658 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
660 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
661 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
665 r = canvas.DrawBitmap(bounds, *pBitmap);
666 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
673 _EditTimePresenter::GetTimeElementWidth(void) const
675 FloatRectangle bounds;
676 FloatDimension minSize;
677 bounds = __pEditTime->GetBoundsF();
679 float timeElementWidth = 0.0f;
680 float timeElementMinWidth = 0.0f;
681 float editTimeWidth = 0.0f;
683 GET_SHAPE_CONFIG(EDITTIME::HOUR_MINUTE_WIDTH, __pEditTime->GetOrientation(), timeElementWidth);
684 GET_SHAPE_CONFIG(EDITTIME::HOUR_MINUTE_MIN_WIDTH, __pEditTime->GetOrientation(), timeElementMinWidth);
685 GET_SHAPE_CONFIG(EDITTIME::WIDTH, __pEditTime->GetOrientation(), editTimeWidth);
687 GET_DIMENSION_CONFIG(EDITTIME::MIN_SIZE, __pEditTime->GetOrientation(), minSize);
689 if (bounds.width >= editTimeWidth)
691 return timeElementWidth;
694 if (bounds.width <= minSize.width)
696 timeElementWidth = timeElementMinWidth;
698 else if (bounds.width < editTimeWidth && bounds.width > minSize.width)
700 timeElementWidth = timeElementWidth -
701 ((timeElementWidth - timeElementMinWidth) / (editTimeWidth - minSize.width)) * (editTimeWidth - bounds.width);
704 return timeElementWidth;
708 _EditTimePresenter::InitializeTitleObject(void)
710 result r = E_SUCCESS;
712 Color titleNormalColor;
714 GET_COLOR_CONFIG(EDITTIME::TITLE_TEXT_NORMAL, titleNormalColor);
716 r = __titleObject.Construct();
717 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
719 TextSimple* pSimpleText = null;
721 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
722 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
724 __titleObject.AppendElement(*pSimpleText);
726 __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
727 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
728 __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
729 __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
730 __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
736 _EditTimePresenter::InitializeTextObject(void)
738 result r = E_SUCCESS;
740 r = __textObject.Construct();
741 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
743 TextSimple* pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
744 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
745 "[E_OUT_OF_MEMORY] Memory allocation failed.");
747 __textObject.AppendElement(*pSimpleText);
749 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
750 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
751 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
752 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
758 _EditTimePresenter::Draw(void)
760 result r = E_SUCCESS;
767 Canvas* pCanvas = __pEditTime->GetCanvasN();
768 SysAssertf((pCanvas != null), "Failed to get canvas.");
770 FloatRectangle colonBounds(0.0f, 0.0f, 0.0f, 0.0f);
772 float colonMargin = 0.0f;
776 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
779 FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
780 FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
781 FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
782 bool isCustomBitmap = false;
783 Bitmap* pReplacementBitmap = null;
784 Bitmap* pEffectBitmap = null;
786 hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
787 minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
789 if (__24hours == false)
791 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
793 if (!__pEditTime->IsEnabled())
795 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_DISABLED);
796 pReplacementBitmap = __pAmPmBgDisabledColorReplacementBitmap;
797 pEffectBitmap = __pAmPmBgEffectDisabledBitmap;
799 else if (__selectedId != DATETIME_ID_AMPM)
801 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_NORMAL);
802 pReplacementBitmap = __pAmPmBgNormalColorReplacementBitmap;
803 pEffectBitmap = __pAmPmBgEffectNomralBitmap;
807 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_PRESSED);
808 pReplacementBitmap = __pAmPmBgPressedColorReplacementBitmap;
809 pEffectBitmap = __pAmPmBgEffectPressedBitmap;
813 if (GetHour() >= DATETIME_HOUR_MAX_FOR_24NOTATION)
824 GET_SHAPE_CONFIG(EDITTIME::COLON_WIDTH, __pEditTime->GetOrientation(), colonBounds.width);
825 GET_SHAPE_CONFIG(EDITTIME::COLON_MARGIN, __pEditTime->GetOrientation(), colonMargin);
826 GET_SHAPE_CONFIG(EDITTIME::AMPM_HEIGHT, __pEditTime->GetOrientation(), colonBounds.height);
828 colonBounds.x = hourBounds.x + hourBounds.width + colonMargin;
829 colonBounds.y = hourBounds.y + (hourBounds.height - colonBounds.height) / 2.0f;
831 if (__title.IsEmpty() == false)
833 r = DrawTitle(*pCanvas);
834 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
837 r = DrawText(*pCanvas, hourBounds, __hourString, DATETIME_ID_HOUR);
838 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
840 r = DrawText(*pCanvas, minuteBounds, __minuteString, DATETIME_ID_MINUTE);
841 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
843 r = DrawColon(*pCanvas, colonBounds);
844 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
846 if (__24hours == false)
848 r = DrawResourceBitmap(*pCanvas, ampmBounds, pReplacementBitmap);
849 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
853 r = DrawResourceBitmap(*pCanvas, ampmBounds, pEffectBitmap);
854 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
857 r = DrawText(*pCanvas, ampmBounds, __ampmString, DATETIME_ID_AMPM, __amPmTextSize);
858 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
868 _EditTimePresenter::DrawColon(Canvas& canvas, const FloatRectangle& bounds)
870 result r = E_SUCCESS;
872 if (!__pEditTime->IsEnabled())
874 r = DrawResourceBitmap(canvas, bounds, __pColonDisabledColorReplacementBitmap);
878 r = DrawResourceBitmap(canvas, bounds, __pColonColorReplacementBitmap);
885 _EditTimePresenter::DrawTitle(Canvas& canvas)
887 if (!__pEditTime->IsEnabled())
889 Color titleDisabledColor;
890 GET_COLOR_CONFIG(EDITTIME::TITLE_TEXT_DISABLED, titleDisabledColor);
891 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
894 (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
895 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
896 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
898 __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
904 _EditTimePresenter::DrawContentBitmap(Canvas& canvas, const FloatRectangle& bounds, _DateTimeId boxId)
906 result r = E_SUCCESS;
908 bool isCustomBitmap = false;
909 Bitmap* pReplacementBitmap = null;
910 Bitmap* pEffectBitmap = null;
912 if (!__pEditTime->IsEnabled())
914 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_DISABLED);
915 pReplacementBitmap = __pContentBgDisabledColorReplacementBitmap;
916 pEffectBitmap = __pContentBgEffectDisabledBitmap;
918 else if (__selectedId != boxId)
920 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated() &&
921 (GetLastSelectedId() == boxId))
923 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
924 pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
925 pEffectBitmap = __pContentBgEffectPressedBitmap;
929 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_NORMAL);
930 pReplacementBitmap = __pContentBgNormalColorReplacementBitmap;
931 pEffectBitmap = __pContentBgEffectNormalBitmap;
936 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
937 pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
938 pEffectBitmap = __pContentBgEffectPressedBitmap;
941 r = DrawResourceBitmap(canvas, bounds, pReplacementBitmap);
942 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
946 r = DrawResourceBitmap(canvas, bounds, pEffectBitmap);
947 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
954 _EditTimePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, _DateTimeId boxId, float textSize)
956 result r = E_SUCCESS;
959 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
961 if (!__pEditTime->IsEnabled())
963 if (boxId == DATETIME_ID_AMPM)
965 GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_DISABLED, textColor);
969 GET_COLOR_CONFIG(EDITTIME::TEXT_DISABLED, textColor);
974 GET_COLOR_CONFIG(EDITTIME::TEXT_NORMAL, textColor);
976 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated() &&
977 (GetLastSelectedId() == boxId))
979 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
980 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
983 if (boxId == DATETIME_ID_AMPM)
985 GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_NORMAL, textColor);
988 if (boxId > -1 && boxId == __selectedId)
990 if (boxId == DATETIME_ID_AMPM)
992 GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_PRESSED, textColor);
996 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
997 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1002 if (boxId != DATETIME_ID_AMPM)
1004 DrawContentBitmap(canvas, bounds, boxId);
1007 FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
1008 drawAreaBounds = bounds;
1010 TextSimple* pSimpleText = null;
1011 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1012 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1014 __textObject.RemoveAll();
1016 (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1017 __textObject.AppendElement(*pSimpleText);
1019 if (boxId == DATETIME_ID_AMPM)
1021 (_FontImpl::GetInstance(*__pFont))->SetSize(textSize);
1024 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1026 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
1027 __textObject.SetBounds(drawAreaBounds);
1028 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
1034 _EditTimePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
1036 _DateTimeId displayBoxId = DATETIME_ID_NONE;
1038 FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1039 FloatRectangle hoursBounds(0.0f, 0.0f, 0.0f, 0.0f);
1040 FloatRectangle minutesBounds(0.0f, 0.0f, 0.0f, 0.0f);
1042 if (__24hours == false)
1044 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
1047 hoursBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1048 minutesBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1050 if (point.y < hoursBounds.y || point.y > hoursBounds.y + hoursBounds.height)
1052 return displayBoxId;
1055 if (hoursBounds.Contains(point) == true)
1057 displayBoxId = DATETIME_ID_HOUR;
1059 else if (minutesBounds.Contains(point) == true)
1061 displayBoxId = DATETIME_ID_MINUTE;
1063 else if (ampmBounds.Contains(point) == true)
1065 displayBoxId = DATETIME_ID_AMPM;
1068 return displayBoxId;
1072 _EditTimePresenter::SetLastSelectedId(_DateTimeId boxId)
1074 __lastSelectedId = boxId;
1079 _EditTimePresenter::GetLastSelectedId(void) const
1081 return __lastSelectedId;
1085 _EditTimePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1087 SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
1089 if (&source != __pEditTime)
1094 __touchMoveHandled = false;
1096 FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
1097 FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1098 FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1100 hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1101 minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1103 if (__24hours == false)
1105 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
1108 FloatPoint point = touchinfo.GetCurrentPosition();
1110 _DateTimeId boxId = GetBoxIdFromPosition(point);
1114 int displayValue = -1;
1116 if (boxId == DATETIME_ID_HOUR)
1118 if (__pEditTime->GetDateTimeBar() != null)
1120 if (__24hours == false)
1124 minValue = DATETIME_HOUR_MIN + 1;
1125 maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1126 displayValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1128 else if (GetHour() > DATETIME_HOUR_MAX_FOR_24NOTATION)
1130 minValue = DATETIME_HOUR_MIN + 1;
1131 maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1132 displayValue = GetHour() - DATETIME_HOUR_MAX_FOR_24NOTATION;
1136 minValue = DATETIME_HOUR_MIN + 1;
1137 maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1138 displayValue = GetHour();
1143 minValue = DATETIME_HOUR_MIN;
1144 maxValue = DATETIME_HOUR_MAX;
1145 displayValue = GetHour();
1148 if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1150 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1153 __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1156 __bounds = hourBounds;
1158 else if (boxId == DATETIME_ID_MINUTE)
1160 if (__pEditTime->GetDateTimeBar() != null)
1162 minValue = DATETIME_MINUTE_MIN;
1163 maxValue = DATETIME_MINUTE_MAX;
1164 displayValue = GetMinute();
1166 if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1168 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1171 __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1174 __bounds = minuteBounds;
1176 else if (boxId == DATETIME_ID_AMPM)
1178 __selectedId = boxId;
1179 __bounds = ampmBounds;
1184 __selectedId = DATETIME_ID_NONE;
1188 __selectedId = boxId;
1194 _EditTimePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1196 SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
1198 if (&source != __pEditTime)
1203 FloatRectangle bounds = __pEditTime->GetBoundsF();
1205 FloatPoint startPoint(0.0f, 0.0f);
1207 float titleHeight = 0;
1208 GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, __pEditTime->GetOrientation(), titleHeight);
1210 __bounds = FloatRectangle(0.0f, titleHeight, bounds.width, bounds.height);
1212 FloatPoint point = touchinfo.GetCurrentPosition();
1214 _DateTimeId boxId = GetBoxIdFromPosition(point);
1216 if ((boxId == GetLastSelectedId() && boxId != DATETIME_ID_AMPM) || boxId != __selectedId || boxId == DATETIME_ID_NONE)
1218 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1220 __pEditTime->GetDateTimeBar()->SetVisibleState(false);
1221 __pEditTime->GetDateTimeBar()->Close();
1224 __selectedId = DATETIME_ID_NONE;
1225 SetLastSelectedId(__selectedId);
1232 SetLastSelectedId(__selectedId);
1234 __lastSelectedValue = "";
1235 _DateTimeUtils dateTimeUtils;
1237 if (GetLastSelectedId() == DATETIME_ID_HOUR)
1239 int hours = GetHour();
1241 if (!Is24HourNotationEnabled())
1245 if (hours == DATETIME_HOUR_MIN)
1247 hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
1250 __lastSelectedValue.Format(10, L"%02d", hours);
1251 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1253 else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1255 __lastSelectedValue.Format(10, L"%02d", GetMinute());
1256 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1258 else if (GetLastSelectedId() == DATETIME_ID_AMPM)
1260 SetAmEnabled(!GetAmEnabled());
1261 __pEditTime->FireTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1262 __pEditTime->UpdateAccessibilityElement();
1263 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1265 __selectedId = DATETIME_ID_NONE;
1267 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1269 __pEditTime->GetDateTimeBar()->SetVisibleState(false);
1270 __pEditTime->GetDateTimeBar()->Close();
1280 if ((__pEditTime->GetDateTimeBar() != null) && (boxId != DATETIME_ID_AMPM) && (GetLastSelectedId() != DATETIME_ID_NONE))
1282 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1283 bounds = GetDisplayAreaBoundsFromHoursStyle(GetLastSelectedId());
1284 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1285 absoluteBounds = __pEditTime->GetAbsoluteBoundsF();
1286 bounds.x += absoluteBounds.x;
1288 __pEditTime->GetDateTimeBar()->CalculateArrowBounds(bounds);
1290 if (__pEditTime->GetDateTimeBar()->IsActivated())
1292 __pEditTime->GetDateTimeBar()->RefreshItems();
1296 __pEditTime->GetDateTimeBar()->SetVisibleState(true);
1297 __pEditTime->GetDateTimeBar()->Open();
1301 __selectedId = DATETIME_ID_NONE;
1306 _EditTimePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1308 if (&source != __pEditTime)
1313 __selectedId = DATETIME_ID_NONE;
1319 _EditTimePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1321 if (&source != __pEditTime)
1326 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1335 _EditTimePresenter::OnTouchMoveHandled(const _Control& control)
1337 __touchMoveHandled = true;
1338 __selectedId = DATETIME_ID_NONE;
1344 _EditTimePresenter::OnFontChanged(Font* pFont)
1348 if (__pEditTime->GetDateTimeBar() != null)
1350 __pEditTime->GetDateTimeBar()->SetFont(*pFont);
1357 _EditTimePresenter::OnFontInfoRequested(unsigned long& style, float& size)
1359 style = FONT_STYLE_PLAIN;
1360 size = __timeFontSize;
1366 _EditTimePresenter::Initialize(void)
1368 result r = E_SUCCESS;
1370 float titleTimeMargin = 0;
1371 float timeHeight = 0;
1372 float editTimeHeight = 0;
1374 GET_SHAPE_CONFIG(EDITTIME::TEXT_FONT_SIZE, __pEditTime->GetOrientation(), __titleFontSize);
1375 GET_SHAPE_CONFIG(EDITTIME::TIME_FONT_SIZE, __pEditTime->GetOrientation(), __timeFontSize);
1376 GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, __pEditTime->GetOrientation(), titleTimeMargin);
1377 GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, __pEditTime->GetOrientation(), timeHeight);
1378 GET_SHAPE_CONFIG(EDITTIME::HEIGHT, __pEditTime->GetOrientation(), editTimeHeight);
1380 if (__pEditTime->GetBoundsF().height > editTimeHeight)
1382 editTimeHeight = __pEditTime->GetBoundsF().height;
1385 if (__title.IsEmpty() == false)
1388 if (!__isEditTimeInitialized)
1390 r = InitializeTitleObject();
1391 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1394 __titleBounds.y = (editTimeHeight - (__titleBounds.height + titleTimeMargin + timeHeight)) / 2.0f;
1395 __titleObject.SetBounds(__titleBounds);
1398 __pFont = __pEditTime->GetFallbackFont();
1399 r = GetLastResult();
1400 SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1402 if (!__isEditTimeInitialized)
1405 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1407 r = InitializeTextObject();
1408 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1411 __isEditTimeInitialized = true;
1418 _EditTimePresenter::UpdateTimeFormat(void)
1420 if (!__is24hoursSet)
1422 String key(L"http://tizen.org/setting/locale.time.format.24hour");
1423 SettingInfo::GetValue(key , __24hours);
1430 _EditTimePresenter::Animate(void)
1432 SysAssertf((__pFont != null), "Font instance must not be null.");
1434 (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1436 result r = E_SUCCESS;
1437 FloatRectangle rect;
1439 String minuteString;
1442 _DateTimeUtils dateTimeUtils;
1443 int hours = GetHour();
1444 if (!Is24HourNotationEnabled())
1448 if (hours == DATETIME_HOUR_MIN)
1450 hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
1453 hourString.Format(10, L"%02d", hours);
1454 minuteString.Format(10, L"%02d", GetMinute());
1456 if (GetLastSelectedId() == DATETIME_ID_HOUR)
1458 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(hourString) == false), E_SUCCESS, "[E_SUCCESS] Hour string matched.");
1460 newValue = hourString;
1461 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1463 else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1465 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(minuteString) == false), E_SUCCESS, "[E_SUCCESS] Minute string matched.");
1467 newValue = minuteString;
1468 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1471 FloatDimension newTextDim;
1472 FloatDimension oldTextDim;
1473 FloatPoint textPoint;
1474 VisualElement* pNewVisualElement = null;
1475 VisualElement* pOldVisualElement = null;
1476 VisualElement* pEditTimeElement = null;
1477 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
1478 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
1479 Canvas *pCanvas = null;
1480 Color contentBgColor;
1481 Color textNormalColor;
1482 Color textPressedColor;
1484 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentBgColor);
1485 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textPressedColor);
1487 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1488 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1490 if (newTextDim.width > oldTextDim.width)
1492 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1496 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1499 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditTime->GetBounds().width), E_SUCCESS, "Rolling animation cann't be played.");
1501 __isAnimating = true;
1503 __pContentProvider = new (std::nothrow) VisualElement();
1504 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1506 r = __pContentProvider->Construct();
1507 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1509 __pContentProvider->SetShowState(true);
1510 __pContentProvider->SetClipChildrenEnabled(true);
1511 __pContentProvider->SetImplicitAnimationEnabled(false);
1513 pEditTimeElement = __pEditTime->GetVisualElement();
1514 r = GetLastResult();
1515 SysTryCatch(NID_UI_CTRL, (pEditTimeElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1517 pNewVisualElement = new (std::nothrow) VisualElement();
1518 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1520 r = pNewVisualElement->Construct();
1523 pNewVisualElement->Destroy();
1525 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1527 pNewVisualElement->SetShowState(true);
1529 pOldVisualElement = new (std::nothrow) VisualElement();
1530 if (pOldVisualElement == null)
1532 pNewVisualElement->Destroy();
1534 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1536 r = pOldVisualElement->Construct();
1539 pNewVisualElement->Destroy();
1540 pOldVisualElement->Destroy();
1542 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1544 pOldVisualElement->SetShowState(true);
1546 if (newTextDim.width > oldTextDim.width)
1548 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1549 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1550 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1551 pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1553 rect.x = __pContentProvider->GetBounds().x;
1554 rect.y = __pContentProvider->GetBounds().y;
1555 rect.width = __pContentProvider->GetBounds().width;
1556 rect.height = __pContentProvider->GetBounds().height;
1558 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1559 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1561 pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1565 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1566 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1567 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1568 pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1570 rect.x = __pContentProvider->GetBounds().x;
1571 rect.y = __pContentProvider->GetBounds().y;
1572 rect.width = __pContentProvider->GetBounds().width;
1573 rect.height = __pContentProvider->GetBounds().height;
1575 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1576 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1578 pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1581 pCanvas = pEditTimeElement->GetCanvasN(rect);
1582 pCanvas->SetBackgroundColor(contentBgColor);
1586 pEditTimeElement->AttachChild(*__pContentProvider);
1588 __pContentProvider->AttachChild(*pOldVisualElement);
1589 __pContentProvider->AttachChild(*pNewVisualElement);
1591 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1592 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1594 pNewBoundsAnimation->SetDuration(300);
1595 pNewBoundsAnimation->SetPropertyName("bounds.position");
1596 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
1597 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
1598 pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1600 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1601 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1603 pOldBoundsAnimation->SetDuration(300);
1604 pOldBoundsAnimation->SetPropertyName("bounds.position");
1605 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, 0.0f)));
1606 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
1607 pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1609 pCanvas = pOldVisualElement->GetCanvasN();
1610 r = GetLastResult();
1611 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1613 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1615 pCanvas->SetForegroundColor(textPressedColor);
1616 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1617 pCanvas->SetFont(*__pFont);
1618 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), __lastSelectedValue);
1623 pCanvas = pNewVisualElement->GetCanvasN();
1624 r = GetLastResult();
1625 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1627 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1629 pCanvas->SetForegroundColor(textPressedColor);
1630 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1631 pCanvas->SetFont(*__pFont);
1632 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), newValue);
1637 pOldVisualElement->SetImplicitAnimationEnabled(false);
1638 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1640 pNewVisualElement->SetImplicitAnimationEnabled(false);
1641 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1643 delete pOldBoundsAnimation;
1644 delete pNewBoundsAnimation;
1649 __isAnimating = false;
1650 __pContentProvider->Destroy();
1652 delete pNewBoundsAnimation;
1653 pNewBoundsAnimation = null;
1655 delete pOldBoundsAnimation;
1656 pOldBoundsAnimation = null;
1665 _EditTimePresenter::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
1667 result r = E_SUCCESS;
1668 __isAnimating = false;
1670 VisualElement* pEditTimeElement = __pEditTime->GetVisualElement();
1671 r = GetLastResult();
1672 SysTryReturnVoidResult(NID_UI_CTRL, (pEditTimeElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1674 pEditTimeElement->DetachChild(*__pContentProvider);
1675 __pContentProvider->Destroy();
1681 }}} // Tizen::Ui::Controls