From f8fb594896a764bac6474d5f77fe45a53bb37b69 Mon Sep 17 00:00:00 2001 From: Sreedeep Moulik Date: Tue, 25 Jun 2013 19:54:15 +0530 Subject: [PATCH] Accessibility update on Setting Change in DateTimePicker Change-Id: I604e3c40a6defa14b2608fb5e3d3d3225d2e9f40 Signed-off-by: Sreedeep Moulik --- src/ui/controls/FUiCtrl_DateTimePicker.cpp | 212 ++++++++++++++------------ src/ui/controls/FUiCtrl_DateTimePresenter.cpp | 35 ++++- src/ui/inc/FUiCtrl_DateTimePicker.h | 3 +- 3 files changed, 144 insertions(+), 106 deletions(-) diff --git a/src/ui/controls/FUiCtrl_DateTimePicker.cpp b/src/ui/controls/FUiCtrl_DateTimePicker.cpp index 899c8d0..4405059 100644 --- a/src/ui/controls/FUiCtrl_DateTimePicker.cpp +++ b/src/ui/controls/FUiCtrl_DateTimePicker.cpp @@ -830,111 +830,13 @@ _DateTimePicker::OnTouchCanceled(const _Control& source, const _TouchInfo& touch result _DateTimePicker::OnAttachedToMainTree(void) { - _AccessibilityContainer* pContainer = GetAccessibilityContainer(); - if (pContainer != null) - { - float dateTimeDisplayBoxHeight = 0.0f; - float amPmDisplayBoxHeight = 0.0f; - float topMargin = 0.0f; - float leftMargin = 0.0f; - const _DateTimeDisplayBox* pBox = null; - const _DateTimeDisplayBox* pAmPmBox = null; - - GET_SHAPE_CONFIG(DATETIMEPICKER::LEFT_MARGIN, GetOrientation(), leftMargin); - - pContainer->AddListener(*this); - - // Display Box - for (int index = 0; index < DATETIME_ID_MAX; index++) - { - pBox = __pPresenter->GetDisplayBox(index); - if (pBox != null) - { - _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true); - SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed."); - - FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds(); - int displayBoxId = pBox->GetDisplayBoxId(); - - String hintText(L"Double tap to edit"); - - switch (displayBoxId) - { - case DATETIME_ID_DAY: - pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_DAY_LC"); - pElement->SetHint(hintText); - break; - case DATETIME_ID_MONTH: - pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MONTH_LC"); - pElement->SetHint(hintText); - break; - case DATETIME_ID_YEAR: - pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_YEAR_LC"); - pElement->SetHint(hintText); - break; - case DATETIME_ID_HOUR: - pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_HOUR_LC"); - pElement->SetHint(hintText); - break; - case DATETIME_ID_MINUTE: - pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MINUTE_LC"); - pElement->SetHint(hintText); - break; - } - - GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, GetOrientation(), dateTimeDisplayBoxHeight); - GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_DISPLAY_BOX_HEIGHT, GetOrientation(), amPmDisplayBoxHeight); - topMargin = (amPmDisplayBoxHeight - dateTimeDisplayBoxHeight) / 2.0f; - - displayBoxBounds.x += leftMargin; - displayBoxBounds.y -= topMargin; - displayBoxBounds.height += 2 * topMargin; - - if (__pDisplayVisualElement) - { - displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y; - } - - pElement->SetLabel(pBox->GetText()); - pElement->SetBounds(displayBoxBounds); - pContainer->AddElement(*pElement); - } - } - - pAmPmBox = __pPresenter->GetAmPmBox(); - if (pAmPmBox != null) - { - _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true); - SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed."); - - FloatRectangle amPmBoxBounds = pAmPmBox->GetDisplayBoxBounds(); - - amPmBoxBounds.x += leftMargin; - - if (__pDisplayVisualElement) - { - amPmBoxBounds.y += __pDisplayVisualElement->GetBounds().y; - } - - pElement->SetLabel(pAmPmBox->GetText()); - pElement->SetBounds(amPmBoxBounds); - pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_BUTTON_T_TTS"); - pElement->SetHintWithStringId("IDS_TPLATFORM_BODY_DOUBLE_TAP_TO_CHANGE_T_TTS"); - pContainer->AddElement(*pElement); - } - - pContainer->GetElements(__accessibilityElements); - _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM); - - } - - return E_SUCCESS; + return CreateAllAccessibilityElements(); } result _DateTimePicker::OnDetachingFromMainTree(void) { - RemoveAllAccessibilityElement(); + RemoveAllAccessibilityElements(); return _Window::OnDetachingFromMainTree(); } @@ -1144,6 +1046,8 @@ _DateTimePicker::OnSettingChanged(Tizen::Base::String& key) { __pPresenter->UpdateLocaleDateTimeFormat(); Invalidate(); + RemoveAllAccessibilityElements(); + CreateAllAccessibilityElements(); } return; @@ -1167,14 +1071,120 @@ _DateTimePicker::InitializeFont(void) return r; } +result +_DateTimePicker::CreateAllAccessibilityElements(void) +{ + _AccessibilityContainer* pContainer = GetAccessibilityContainer(); + if (pContainer != null) + { + float dateTimeDisplayBoxHeight = 0.0f; + float amPmDisplayBoxHeight = 0.0f; + float topMargin = 0.0f; + float leftMargin = 0.0f; + const _DateTimeDisplayBox* pBox = null; + const _DateTimeDisplayBox* pAmPmBox = null; + + GET_SHAPE_CONFIG(DATETIMEPICKER::LEFT_MARGIN, GetOrientation(), leftMargin); + + pContainer->AddListener(*this); + + // Display Box + for (int index = 0; index < DATETIME_ID_MAX; index++) + { + pBox = __pPresenter->GetDisplayBox(index); + if (pBox != null) + { + _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true); + SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed."); + + FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds(); + int displayBoxId = pBox->GetDisplayBoxId(); + + String hintText(L"Double tap to edit"); + + switch (displayBoxId) + { + case DATETIME_ID_DAY: + pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_DAY_LC"); + pElement->SetHint(hintText); + break; + case DATETIME_ID_MONTH: + pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MONTH_LC"); + pElement->SetHint(hintText); + break; + case DATETIME_ID_YEAR: + pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_YEAR_LC"); + pElement->SetHint(hintText); + break; + case DATETIME_ID_HOUR: + pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_HOUR_LC"); + pElement->SetHint(hintText); + break; + case DATETIME_ID_MINUTE: + pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MINUTE_LC"); + pElement->SetHint(hintText); + break; + } + + GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, GetOrientation(), dateTimeDisplayBoxHeight); + GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_DISPLAY_BOX_HEIGHT, GetOrientation(), amPmDisplayBoxHeight); + topMargin = (amPmDisplayBoxHeight - dateTimeDisplayBoxHeight) / 2.0f; + + displayBoxBounds.x += leftMargin; + displayBoxBounds.y -= topMargin; + displayBoxBounds.height += 2 * topMargin; + + if (__pDisplayVisualElement) + { + displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y; + } + + pElement->SetLabel(pBox->GetText()); + pElement->SetBounds(displayBoxBounds); + pContainer->AddElement(*pElement); + } + } + + pAmPmBox = __pPresenter->GetAmPmBox(); + if (pAmPmBox != null) + { + _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true); + SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed."); + + FloatRectangle amPmBoxBounds = pAmPmBox->GetDisplayBoxBounds(); + + amPmBoxBounds.x += leftMargin; + + if (__pDisplayVisualElement) + { + amPmBoxBounds.y += __pDisplayVisualElement->GetBounds().y; + } + + pElement->SetLabel(pAmPmBox->GetText()); + pElement->SetBounds(amPmBoxBounds); + pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_BUTTON_T_TTS"); + pElement->SetHintWithStringId("IDS_TPLATFORM_BODY_DOUBLE_TAP_TO_CHANGE_T_TTS"); + pContainer->AddElement(*pElement); + } + + pContainer->GetElements(__accessibilityElements); + _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM); + + } + + return E_SUCCESS; +} + void -_DateTimePicker::RemoveAllAccessibilityElement(void) +_DateTimePicker::RemoveAllAccessibilityElements(void) { _AccessibilityContainer* pContainer = GetAccessibilityContainer(); SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); _AccessibilityElement* pAccessibilityElement = null; + pContainer->RemoveListener(*this); + while (__accessibilityElements.GetCount() > 0) { if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS) diff --git a/src/ui/controls/FUiCtrl_DateTimePresenter.cpp b/src/ui/controls/FUiCtrl_DateTimePresenter.cpp index 63673c0..9dae61c 100644 --- a/src/ui/controls/FUiCtrl_DateTimePresenter.cpp +++ b/src/ui/controls/FUiCtrl_DateTimePresenter.cpp @@ -1868,17 +1868,44 @@ _DateTimePresenter::DrawDividers(Canvas& canvas) canvas.SetLineWidth(dividerWidth/2.0f); - FloatRectangle yearBounds(0.0f, 0.0f, 0.0f, 0.0f); + FloatRectangle lastDateDisplayBoxBounds(0.0f, 0.0f, 0.0f, 0.0f); + + _DateTimeUtils dateTimeUtils; + int localeDateFormat = dateTimeUtils.GetLocaleDateFormat(); for (int i = 0; i < __outputBoxMaxCount; i++) { - if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_YEAR) + switch (localeDateFormat) { - yearBounds = __pDisplayBox[i]->GetDisplayBoxBounds(); + case DATE_FORMAT_DDMMYYYY: + case DATE_FORMAT_MMDDYYYY: + { + if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_YEAR) + { + lastDateDisplayBoxBounds = __pDisplayBox[i]->GetDisplayBoxBounds(); + } + } + break; + case DATE_FORMAT_YYYYMMDD: + { + if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_DAY) + { + lastDateDisplayBoxBounds = __pDisplayBox[i]->GetDisplayBoxBounds(); + } + } + break; + case DATE_FORMAT_YYYYDDMM: + { + if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_MONTH) + { + lastDateDisplayBoxBounds = __pDisplayBox[i]->GetDisplayBoxBounds(); + } + } + break; } } - lineStart.x = yearBounds.x + yearBounds.width + dividerMargin; + lineStart.x = lastDateDisplayBoxBounds.x + lastDateDisplayBoxBounds.width + dividerMargin; lineEnd.x = lineStart.x; canvas.SetForegroundColor(colorHalfLeft); diff --git a/src/ui/inc/FUiCtrl_DateTimePicker.h b/src/ui/inc/FUiCtrl_DateTimePicker.h index 117a18b..1eb971d 100644 --- a/src/ui/inc/FUiCtrl_DateTimePicker.h +++ b/src/ui/inc/FUiCtrl_DateTimePicker.h @@ -186,7 +186,8 @@ private: _DateTimePicker(const _DateTimePicker&); _DateTimePicker& operator =(const _DateTimePicker&); - void RemoveAllAccessibilityElement(void); + result CreateAllAccessibilityElements(void); + void RemoveAllAccessibilityElements(void); private: _DateTimePresenter* __pPresenter; -- 2.7.4