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_Animation.cpp
20 * @brief This is the implementation file for the _Animation class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include "FUi_AccessibilityContainer.h"
26 #include "FUi_AccessibilityElement.h"
27 #include "FUiAnim_VisualElement.h"
28 #include "FUiCtrl_Animation.h"
29 #include "FUiCtrl_AnimationPresenter.h"
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Base::Runtime;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Ui::Animations;
36 namespace Tizen { namespace Ui { namespace Controls
39 IMPLEMENT_PROPERTY(_Animation);
41 _Animation::_Animation(void)
42 : __pAnimationPresenter(null)
43 , __pControlAnimation(null)
44 , __pAnimationEvent(null)
45 , __pAnimationFrames(null)
46 , __pAccessibilityElement(null)
48 _VisualElement* pBase = GetVisualElement();
52 pBase->SetSurfaceOpaque(false);
55 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
58 pContainer->Activate(true);
62 _Animation::~_Animation(void)
64 if (__pAnimationEvent != null)
66 delete __pAnimationEvent;
67 __pAnimationEvent = null;
70 if (__pAnimationFrames != null)
72 __pAnimationFrames->RemoveAll(false);
73 delete __pAnimationFrames;
74 __pAnimationFrames = null;
77 delete __pAnimationPresenter;
78 __pAnimationPresenter = null;
80 if (__pAccessibilityElement)
82 __pAccessibilityElement->Activate(false);
83 __pAccessibilityElement = null;
88 _Animation::CreateAnimationN(void)
92 _Animation* pAnimation = new (std::nothrow) _Animation();
93 SysTryReturn(NID_UI_CTRL, pAnimation != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
95 pAnimation->__pAnimationPresenter = _AnimationPresenter::CreateInstanceN(*pAnimation);
97 SysTryCatch(NID_UI_CTRL, pAnimation->__pAnimationPresenter, , r, "[%s] Propagating.", GetErrorMessage(r));
99 pAnimation->__pAnimationEvent = _AnimationEvent::CreateInstanceN(*pAnimation);
101 SysTryCatch(NID_UI_CTRL, pAnimation->__pAnimationEvent, , r, "[%s] Propagating.", GetErrorMessage(r));
103 pAnimation->AcquireHandle();
104 pAnimation->SetFocusable(false);
106 SetLastResult(E_SUCCESS);
118 _Animation::OnTimerExpired(Timer& timer)
120 if (__pAnimationPresenter->IsTimerExpired(timer) == true)
122 IEventArg* pEventArg = _AnimationEvent::CreateAnimationEventArgN();
123 if (pEventArg != null)
125 __pAnimationEvent->Fire(*pEventArg);
133 _Animation::OnAttachedToMainTree(void)
135 if (__pAccessibilityElement)
140 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
144 __pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
145 if (__pAccessibilityElement)
147 __pAccessibilityElement->SetBounds(FloatRectangle(0, 0, GetBounds().width, GetBounds().height));
148 __pAccessibilityElement->SetName(L"Animation");
149 //__pAccessibilityElement->SetLabel(L"Processing");
150 __pAccessibilityElement->SetTrait(L"Animation");
151 pContainer->AddElement(*__pAccessibilityElement);
159 _Animation::OnBoundsChanged(void)
161 if (likely(!(_AccessibilityManager::IsActivated())))
166 if (__pAccessibilityElement)
168 __pAccessibilityElement->SetBounds(FloatRectangle(0, 0, GetBounds().width, GetBounds().height));
175 _Animation::OnCanvasRequestedN(const FloatRectangle& bounds)
177 return __pAnimationPresenter->OnCanvasRequestedN(bounds);
181 _Animation::SetImageCount(int imageCount)
183 __pAnimationPresenter->SetImageCount(imageCount);
189 _Animation::SetAnimationFrames(const IList& animationFrames)
193 ArrayList* pTempList = new (std::nothrow) ArrayList();
194 SysTryReturnResult(NID_UI_CTRL, pTempList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
196 result r = pTempList->Construct();
197 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
199 frameCount = animationFrames.GetCount();
201 for (int index = 0; index < frameCount; index++)
203 AnimationFrame* pInputAnimationFrame = dynamic_cast <AnimationFrame*>(const_cast <Object*>(animationFrames.GetAt(index)));
204 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);
206 r = pTempList->Add(*pInputAnimationFrame);
207 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, pTempList->RemoveAll(true), r, "[%s] Propagating.", GetErrorMessage(r));
210 if (__pAnimationFrames != null)
212 __pAnimationFrames->RemoveAll(true);
213 delete __pAnimationFrames;
215 __pAnimationFrames = pTempList;
217 r = __pAnimationPresenter->SetAnimationFrames(__pAnimationFrames);
220 __pAnimationFrames->RemoveAll(true);
221 __pAnimationFrames = null;
235 _Animation::GetAnimationFrames(void) const
237 return __pAnimationFrames;
241 _Animation::AddAnimationEventListener(const _IAnimationEventListener& listener)
243 return __pAnimationEvent->AddListener(listener);
247 _Animation::RemoveAnimationEventListener(const _IAnimationEventListener& listener)
249 return __pAnimationEvent->RemoveListener(listener);
253 _Animation::SetPropertyRepeatCount(const Variant& repeatCount)
255 SysTryReturnResult(NID_UI_CTRL, __pAnimationPresenter->GetStatus() == ANIMATION_STOPPED, E_SYSTEM,
256 "A system error has occurred. Repeat count cannot be set during animation play.");
258 SysTryReturnResult(NID_UI_CTRL, repeatCount.ToInt() >= 0, E_INVALID_ARG, "Invalid argument(s) is used. Repeat count must be a positive integer.");
260 __pAnimationPresenter->SetRepeatCount(repeatCount.ToInt());
266 _Animation::SetRepeatCount(int count)
268 return SetProperty("repeatCount", Variant(count));
272 _Animation::GetPropertyRepeatCount(void) const
274 return Variant(__pAnimationPresenter->GetRepeatCount());
278 _Animation::GetRepeatCount(void) const
280 Variant repeatCount = GetProperty("repeatCount");
282 return repeatCount.ToInt();
286 _Animation::GetCurrentRepeatedCount(void) const
288 return __pAnimationPresenter->GetCurrentRepeatedCount();
292 _Animation::GetImageCount(void) const
294 return __pAnimationPresenter->GetImageCount();
298 _Animation::Play(void)
300 return __pAnimationPresenter->Play();
304 _Animation::Stop(void)
306 return __pAnimationPresenter->Stop();
310 _Animation::Pause(void)
312 return __pAnimationPresenter->Pause();
316 _Animation::GetStatus(void) const
318 return __pAnimationPresenter->GetStatus();
322 _Animation::OnDraw(void)
324 result r = __pAnimationPresenter->Draw();
326 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
328 SetLastResult(E_SUCCESS);
332 }}} // Tizen::Ui::Controls