2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
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.
18 * @file FUiCtrl_Animation.cpp
19 * @brief This is the implementation file for the _Animation class.
22 #include <FBaseErrorDefine.h>
23 #include <FBaseSysLog.h>
24 #include "FUi_AccessibilityContainer.h"
25 #include "FUi_AccessibilityElement.h"
26 #include "FUiAnim_VisualElement.h"
27 #include "FUiCtrl_Animation.h"
28 #include "FUiCtrl_AnimationPresenter.h"
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Base::Runtime;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Ui::Animations;
35 namespace Tizen { namespace Ui { namespace Controls
38 IMPLEMENT_PROPERTY(_Animation);
40 _Animation::_Animation(void)
41 : __pAnimationPresenter(null)
42 , __pControlAnimation(null)
43 , __pAnimationEvent(null)
44 , __pAnimationFrames(null)
45 , __pAccessibilityElement(null)
47 _VisualElement* pBase = GetVisualElement();
51 pBase->SetSurfaceOpaque(false);
54 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
57 pContainer->Activate(true);
61 _Animation::~_Animation(void)
63 if (__pAnimationEvent != null)
65 delete __pAnimationEvent;
66 __pAnimationEvent = null;
69 if (__pAnimationFrames != null)
71 __pAnimationFrames->RemoveAll(false);
72 delete __pAnimationFrames;
73 __pAnimationFrames = null;
76 delete __pAnimationPresenter;
77 __pAnimationPresenter = null;
79 if (__pAccessibilityElement)
81 __pAccessibilityElement->Activate(false);
82 __pAccessibilityElement = null;
87 _Animation::CreateAnimationN(void)
91 _Animation* pAnimation = new (std::nothrow) _Animation();
92 SysTryReturn(NID_UI_CTRL, pAnimation != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
94 pAnimation->__pAnimationPresenter = _AnimationPresenter::CreateInstanceN(*pAnimation);
96 SysTryCatch(NID_UI_CTRL, pAnimation->__pAnimationPresenter, , r, "[%s] Propagating.", GetErrorMessage(r));
98 pAnimation->__pAnimationEvent = _AnimationEvent::CreateInstanceN(*pAnimation);
100 SysTryCatch(NID_UI_CTRL, pAnimation->__pAnimationEvent, , r, "[%s] Propagating.", GetErrorMessage(r));
102 pAnimation->AcquireHandle();
103 pAnimation->SetFocusable(false);
105 SetLastResult(E_SUCCESS);
117 _Animation::OnTimerExpired(Timer& timer)
119 if (__pAnimationPresenter->IsTimerExpired(timer) == true)
121 IEventArg* pEventArg = _AnimationEvent::CreateAnimationEventArgN();
122 if (pEventArg != null)
124 __pAnimationEvent->Fire(*pEventArg);
132 _Animation::OnAttachedToMainTree(void)
134 if (__pAccessibilityElement)
139 if (likely((_AccessibilityManager::IsActivated())))
141 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
145 __pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
146 if (__pAccessibilityElement)
148 __pAccessibilityElement->SetBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height));
149 __pAccessibilityElement->SetLabel(L"Animation");
150 __pAccessibilityElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
151 pContainer->AddElement(*__pAccessibilityElement);
160 _Animation::OnBoundsChanged(void)
162 if (likely(!(_AccessibilityManager::IsActivated())))
167 if (__pAccessibilityElement)
169 __pAccessibilityElement->SetBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height));
176 _Animation::SetImageCount(int imageCount)
178 __pAnimationPresenter->SetImageCount(imageCount);
184 _Animation::SetAnimationFrames(const IList& animationFrames)
188 ArrayList* pTempList = new (std::nothrow) ArrayList();
189 SysTryReturnResult(NID_UI_CTRL, pTempList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
191 result r = pTempList->Construct();
192 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
194 frameCount = animationFrames.GetCount();
196 for (int index = 0; index < frameCount; index++)
198 AnimationFrame* pInputAnimationFrame = dynamic_cast <AnimationFrame*>(const_cast <Object*>(animationFrames.GetAt(index)));
199 SysTryCatch(NID_UI_CTRL, pInputAnimationFrame != null, pTempList->RemoveAll(true), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get the AnimationFrame at index %d", index);
201 r = pTempList->Add(*pInputAnimationFrame);
202 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, pTempList->RemoveAll(true), r, "[%s] Propagating.", GetErrorMessage(r));
205 if (__pAnimationFrames != null)
207 __pAnimationFrames->RemoveAll(true);
208 delete __pAnimationFrames;
210 __pAnimationFrames = pTempList;
212 r = __pAnimationPresenter->SetAnimationFrames(__pAnimationFrames);
215 __pAnimationFrames->RemoveAll(true);
216 __pAnimationFrames = null;
230 _Animation::GetAnimationFrames(void) const
232 return __pAnimationFrames;
236 _Animation::AddAnimationEventListener(const _IAnimationEventListener& listener)
238 return __pAnimationEvent->AddListener(listener);
242 _Animation::RemoveAnimationEventListener(const _IAnimationEventListener& listener)
244 return __pAnimationEvent->RemoveListener(listener);
248 _Animation::SetPropertyRepeatCount(const Variant& repeatCount)
250 SysTryReturnResult(NID_UI_CTRL, __pAnimationPresenter->GetStatus() == ANIMATION_STOPPED, E_SYSTEM,
251 "A system error has occurred. Repeat count cannot be set during animation play.");
253 SysTryReturnResult(NID_UI_CTRL, repeatCount.ToInt() >= 0, E_INVALID_ARG, "Invalid argument(s) is used. Repeat count must be a positive integer.");
255 __pAnimationPresenter->SetRepeatCount(repeatCount.ToInt());
261 _Animation::SetRepeatCount(int count)
263 return SetProperty("repeatCount", Variant(count));
267 _Animation::GetPropertyRepeatCount(void) const
269 return Variant(__pAnimationPresenter->GetRepeatCount());
273 _Animation::GetRepeatCount(void) const
275 Variant repeatCount = GetProperty("repeatCount");
277 return repeatCount.ToInt();
281 _Animation::GetCurrentRepeatedCount(void) const
283 return __pAnimationPresenter->GetCurrentRepeatedCount();
287 _Animation::GetImageCount(void) const
289 return __pAnimationPresenter->GetImageCount();
293 _Animation::Play(void)
295 return __pAnimationPresenter->Play();
299 _Animation::Stop(void)
301 return __pAnimationPresenter->Stop();
305 _Animation::Pause(void)
307 return __pAnimationPresenter->Pause();
311 _Animation::GetStatus(void) const
313 return __pAnimationPresenter->GetStatus();
317 _Animation::OnDraw(void)
319 result r = __pAnimationPresenter->Draw();
321 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
323 SetLastResult(E_SUCCESS);
327 }}} // Tizen::Ui::Controls