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 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_NORMAL);
921 pReplacementBitmap = __pContentBgNormalColorReplacementBitmap;
922 pEffectBitmap = __pContentBgEffectNormalBitmap;
926 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
927 pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
928 pEffectBitmap = __pContentBgEffectPressedBitmap;
931 r = DrawResourceBitmap(canvas, bounds, pReplacementBitmap);
932 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
936 r = DrawResourceBitmap(canvas, bounds, pEffectBitmap);
937 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
944 _EditTimePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, _DateTimeId boxId, float textSize)
946 result r = E_SUCCESS;
950 if (!__pEditTime->IsEnabled())
952 if (boxId == DATETIME_ID_AMPM)
954 GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_DISABLED, textColor);
958 GET_COLOR_CONFIG(EDITTIME::TEXT_DISABLED, textColor);
963 GET_COLOR_CONFIG(EDITTIME::TEXT_NORMAL, textColor);
965 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated() &&
966 (GetLastSelectedId() == boxId))
968 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
971 if (boxId == DATETIME_ID_AMPM)
973 GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_NORMAL, textColor);
976 if (boxId > -1 && boxId == __selectedId)
978 if (boxId == DATETIME_ID_AMPM)
980 GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_PRESSED, textColor);
984 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
989 if (boxId != DATETIME_ID_AMPM)
991 DrawContentBitmap(canvas, bounds, boxId);
994 FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
995 drawAreaBounds = bounds;
997 TextSimple* pSimpleText = null;
998 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
999 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1001 __textObject.RemoveAll();
1003 (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1004 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1006 __textObject.AppendElement(*pSimpleText);
1008 if (boxId == __selectedId && boxId != DATETIME_ID_AMPM)
1010 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1013 if (boxId == DATETIME_ID_AMPM)
1015 (_FontImpl::GetInstance(*__pFont))->SetSize(textSize);
1018 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1020 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
1021 __textObject.SetBounds(drawAreaBounds);
1022 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
1028 _EditTimePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
1030 _DateTimeId displayBoxId = DATETIME_ID_NONE;
1032 FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1033 FloatRectangle hoursBounds(0.0f, 0.0f, 0.0f, 0.0f);
1034 FloatRectangle minutesBounds(0.0f, 0.0f, 0.0f, 0.0f);
1036 if (__24hours == false)
1038 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
1041 hoursBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1042 minutesBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1044 if (point.y < hoursBounds.y || point.y > hoursBounds.y + hoursBounds.height)
1046 return displayBoxId;
1049 if (hoursBounds.Contains(point) == true)
1051 displayBoxId = DATETIME_ID_HOUR;
1053 else if (minutesBounds.Contains(point) == true)
1055 displayBoxId = DATETIME_ID_MINUTE;
1057 else if (ampmBounds.Contains(point) == true)
1059 displayBoxId = DATETIME_ID_AMPM;
1062 return displayBoxId;
1066 _EditTimePresenter::SetLastSelectedId(_DateTimeId boxId)
1068 __lastSelectedId = boxId;
1073 _EditTimePresenter::GetLastSelectedId(void) const
1075 return __lastSelectedId;
1079 _EditTimePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1081 SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
1083 if (&source != __pEditTime)
1088 __touchMoveHandled = false;
1090 FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
1091 FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1092 FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1094 hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1095 minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1097 if (__24hours == false)
1099 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
1102 FloatPoint point = touchinfo.GetCurrentPosition();
1104 _DateTimeId boxId = GetBoxIdFromPosition(point);
1108 int displayValue = -1;
1110 if (boxId == DATETIME_ID_HOUR)
1112 if (__pEditTime->GetDateTimeBar() != null)
1114 if (__24hours == false)
1118 minValue = DATETIME_HOUR_MIN + 1;
1119 maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1120 displayValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1122 else if (GetHour() > DATETIME_HOUR_MAX_FOR_24NOTATION)
1124 minValue = DATETIME_HOUR_MIN + 1;
1125 maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1126 displayValue = GetHour() - DATETIME_HOUR_MAX_FOR_24NOTATION;
1130 minValue = DATETIME_HOUR_MIN + 1;
1131 maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1132 displayValue = GetHour();
1137 minValue = DATETIME_HOUR_MIN;
1138 maxValue = DATETIME_HOUR_MAX;
1139 displayValue = GetHour();
1142 if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1144 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1147 __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1150 __bounds = hourBounds;
1152 else if (boxId == DATETIME_ID_MINUTE)
1154 if (__pEditTime->GetDateTimeBar() != null)
1156 minValue = DATETIME_MINUTE_MIN;
1157 maxValue = DATETIME_MINUTE_MAX;
1158 displayValue = GetMinute();
1160 if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1162 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1165 __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1168 __bounds = minuteBounds;
1170 else if (boxId == DATETIME_ID_AMPM)
1172 __selectedId = boxId;
1173 __bounds = ampmBounds;
1178 __selectedId = DATETIME_ID_NONE;
1182 __selectedId = boxId;
1188 _EditTimePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1190 SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
1192 if (&source != __pEditTime)
1197 FloatRectangle bounds = __pEditTime->GetBoundsF();
1199 FloatPoint startPoint(0.0f, 0.0f);
1201 float titleHeight = 0;
1202 GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, __pEditTime->GetOrientation(), titleHeight);
1204 __bounds = FloatRectangle(0.0f, titleHeight, bounds.width, bounds.height);
1206 FloatPoint point = touchinfo.GetCurrentPosition();
1208 _DateTimeId boxId = GetBoxIdFromPosition(point);
1210 if ((boxId == GetLastSelectedId() && boxId != DATETIME_ID_AMPM) || boxId != __selectedId || boxId == DATETIME_ID_NONE)
1212 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1214 __pEditTime->GetDateTimeBar()->SetVisibleState(false);
1215 __pEditTime->GetDateTimeBar()->Close();
1218 __selectedId = DATETIME_ID_NONE;
1219 SetLastSelectedId(__selectedId);
1226 SetLastSelectedId(__selectedId);
1228 __lastSelectedValue = "";
1229 _DateTimeUtils dateTimeUtils;
1231 if (GetLastSelectedId() == DATETIME_ID_HOUR)
1233 int hours = GetHour();
1235 if (!Is24HourNotationEnabled())
1239 if (hours == DATETIME_HOUR_MIN)
1241 hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
1244 __lastSelectedValue.Format(10, L"%02d", hours);
1245 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1247 else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1249 __lastSelectedValue.Format(10, L"%02d", GetMinute());
1250 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1252 else if (GetLastSelectedId() == DATETIME_ID_AMPM)
1254 SetAmEnabled(!GetAmEnabled());
1255 __pEditTime->FireTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1256 __pEditTime->UpdateAccessibilityElement();
1257 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1259 __selectedId = DATETIME_ID_NONE;
1261 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1263 __pEditTime->GetDateTimeBar()->SetVisibleState(false);
1264 __pEditTime->GetDateTimeBar()->Close();
1274 if ((__pEditTime->GetDateTimeBar() != null) && (boxId != DATETIME_ID_AMPM) && (GetLastSelectedId() != DATETIME_ID_NONE))
1276 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1277 bounds = GetDisplayAreaBoundsFromHoursStyle(GetLastSelectedId());
1278 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1279 absoluteBounds = __pEditTime->GetAbsoluteBoundsF();
1280 bounds.x += absoluteBounds.x;
1282 __pEditTime->GetDateTimeBar()->CalculateArrowBounds(bounds);
1284 if (__pEditTime->GetDateTimeBar()->IsActivated())
1286 __pEditTime->GetDateTimeBar()->RefreshItems();
1290 __pEditTime->GetDateTimeBar()->SetVisibleState(true);
1291 __pEditTime->GetDateTimeBar()->Open();
1295 __selectedId = DATETIME_ID_NONE;
1300 _EditTimePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1302 if (&source != __pEditTime)
1307 __selectedId = DATETIME_ID_NONE;
1313 _EditTimePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1315 if (&source != __pEditTime)
1320 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1329 _EditTimePresenter::OnTouchMoveHandled(const _Control& control)
1331 __touchMoveHandled = true;
1332 __selectedId = DATETIME_ID_NONE;
1338 _EditTimePresenter::OnFontChanged(Font* pFont)
1342 if (__pEditTime->GetDateTimeBar() != null)
1344 __pEditTime->GetDateTimeBar()->SetFont(*pFont);
1351 _EditTimePresenter::OnFontInfoRequested(unsigned long& style, float& size)
1353 style = FONT_STYLE_PLAIN;
1354 size = __timeFontSize;
1360 _EditTimePresenter::Initialize(void)
1362 result r = E_SUCCESS;
1364 float titleTimeMargin = 0;
1365 float timeHeight = 0;
1366 float editTimeHeight = 0;
1368 GET_SHAPE_CONFIG(EDITTIME::TEXT_FONT_SIZE, __pEditTime->GetOrientation(), __titleFontSize);
1369 GET_SHAPE_CONFIG(EDITTIME::TIME_FONT_SIZE, __pEditTime->GetOrientation(), __timeFontSize);
1370 GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, __pEditTime->GetOrientation(), titleTimeMargin);
1371 GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, __pEditTime->GetOrientation(), timeHeight);
1372 GET_SHAPE_CONFIG(EDITTIME::HEIGHT, __pEditTime->GetOrientation(), editTimeHeight);
1374 if (__pEditTime->GetBoundsF().height > editTimeHeight)
1376 editTimeHeight = __pEditTime->GetBoundsF().height;
1379 if (__title.IsEmpty() == false)
1382 if (!__isEditTimeInitialized)
1384 r = InitializeTitleObject();
1385 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1388 __titleBounds.y = (editTimeHeight - (__titleBounds.height + titleTimeMargin + timeHeight)) / 2.0f;
1389 __titleObject.SetBounds(__titleBounds);
1392 __pFont = __pEditTime->GetFallbackFont();
1393 r = GetLastResult();
1394 SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1396 if (!__isEditTimeInitialized)
1399 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1401 r = InitializeTextObject();
1402 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1405 __isEditTimeInitialized = true;
1412 _EditTimePresenter::UpdateTimeFormat(void)
1414 if (!__is24hoursSet)
1416 String key(L"http://tizen.org/setting/locale.time.format.24hour");
1417 SettingInfo::GetValue(key , __24hours);
1424 _EditTimePresenter::Animate(void)
1426 SysAssertf((__pFont != null), "Font instance must not be null.");
1428 (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1430 result r = E_SUCCESS;
1431 FloatRectangle rect;
1433 String minuteString;
1436 _DateTimeUtils dateTimeUtils;
1437 int hours = GetHour();
1438 if (!Is24HourNotationEnabled())
1442 if (hours == DATETIME_HOUR_MIN)
1444 hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
1447 hourString.Format(10, L"%02d", hours);
1448 minuteString.Format(10, L"%02d", GetMinute());
1450 if (GetLastSelectedId() == DATETIME_ID_HOUR)
1452 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(hourString) == false), E_SUCCESS, "[E_SUCCESS] Hour string matched.");
1454 newValue = hourString;
1455 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1457 else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1459 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(minuteString) == false), E_SUCCESS, "[E_SUCCESS] Minute string matched.");
1461 newValue = minuteString;
1462 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1465 FloatDimension newTextDim;
1466 FloatDimension oldTextDim;
1467 FloatPoint textPoint;
1468 VisualElement* pNewVisualElement = null;
1469 VisualElement* pOldVisualElement = null;
1470 VisualElement* pEditTimeElement = null;
1471 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
1472 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
1473 Canvas *pCanvas = null;
1474 Color contentBgColor;
1475 Color textNormalColor;
1476 Color textPressedColor;
1478 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentBgColor);
1479 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textPressedColor);
1481 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1482 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1484 if (newTextDim.width > oldTextDim.width)
1486 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1490 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1493 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditTime->GetBounds().width), E_SUCCESS, "Rolling animation cann't be played.");
1495 __isAnimating = true;
1497 __pContentProvider = new (std::nothrow) VisualElement();
1498 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1500 r = __pContentProvider->Construct();
1501 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1503 __pContentProvider->SetShowState(true);
1504 __pContentProvider->SetClipChildrenEnabled(true);
1505 __pContentProvider->SetImplicitAnimationEnabled(false);
1507 pEditTimeElement = __pEditTime->GetVisualElement();
1508 r = GetLastResult();
1509 SysTryCatch(NID_UI_CTRL, (pEditTimeElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1511 pNewVisualElement = new (std::nothrow) VisualElement();
1512 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1514 r = pNewVisualElement->Construct();
1517 pNewVisualElement->Destroy();
1519 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1521 pNewVisualElement->SetShowState(true);
1523 pOldVisualElement = new (std::nothrow) VisualElement();
1524 if (pOldVisualElement == null)
1526 pNewVisualElement->Destroy();
1528 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1530 r = pOldVisualElement->Construct();
1533 pNewVisualElement->Destroy();
1534 pOldVisualElement->Destroy();
1536 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1538 pOldVisualElement->SetShowState(true);
1540 if (newTextDim.width > oldTextDim.width)
1542 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1543 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1544 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1545 pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1547 rect.x = __pContentProvider->GetBounds().x;
1548 rect.y = __pContentProvider->GetBounds().y;
1549 rect.width = __pContentProvider->GetBounds().width;
1550 rect.height = __pContentProvider->GetBounds().height;
1552 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1553 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1555 pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1559 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1560 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1561 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1562 pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1564 rect.x = __pContentProvider->GetBounds().x;
1565 rect.y = __pContentProvider->GetBounds().y;
1566 rect.width = __pContentProvider->GetBounds().width;
1567 rect.height = __pContentProvider->GetBounds().height;
1569 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1570 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1572 pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1575 pCanvas = pEditTimeElement->GetCanvasN(rect);
1576 pCanvas->SetBackgroundColor(contentBgColor);
1580 pEditTimeElement->AttachChild(*__pContentProvider);
1582 __pContentProvider->AttachChild(*pOldVisualElement);
1583 __pContentProvider->AttachChild(*pNewVisualElement);
1585 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1586 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1588 pNewBoundsAnimation->SetDuration(300);
1589 pNewBoundsAnimation->SetPropertyName("bounds.position");
1590 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
1591 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
1592 pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1594 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1595 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1597 pOldBoundsAnimation->SetDuration(300);
1598 pOldBoundsAnimation->SetPropertyName("bounds.position");
1599 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, 0.0f)));
1600 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
1601 pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1603 pCanvas = pOldVisualElement->GetCanvasN();
1604 r = GetLastResult();
1605 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1607 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1609 pCanvas->SetForegroundColor(textPressedColor);
1610 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1611 pCanvas->SetFont(*__pFont);
1612 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), __lastSelectedValue);
1617 pCanvas = pNewVisualElement->GetCanvasN();
1618 r = GetLastResult();
1619 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1621 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1623 pCanvas->SetForegroundColor(textPressedColor);
1624 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1625 pCanvas->SetFont(*__pFont);
1626 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), newValue);
1631 pOldVisualElement->SetImplicitAnimationEnabled(false);
1632 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1634 pNewVisualElement->SetImplicitAnimationEnabled(false);
1635 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1637 delete pOldBoundsAnimation;
1638 delete pNewBoundsAnimation;
1643 __isAnimating = false;
1644 __pContentProvider->Destroy();
1646 delete pNewBoundsAnimation;
1647 pNewBoundsAnimation = null;
1649 delete pOldBoundsAnimation;
1650 pOldBoundsAnimation = null;
1659 _EditTimePresenter::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
1661 result r = E_SUCCESS;
1662 __isAnimating = false;
1664 VisualElement* pEditTimeElement = __pEditTime->GetVisualElement();
1665 r = GetLastResult();
1666 SysTryReturnVoidResult(NID_UI_CTRL, (pEditTimeElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1668 pEditTimeElement->DetachChild(*__pContentProvider);
1669 __pContentProvider->Destroy();
1675 }}} // Tizen::Ui::Controls