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.
19 * @file FUiAnimIntegerAnimation.cpp
20 * @brief This file contains implementation of IntegerAnimation.cpp class
21 * This file contains implementation of IntegerAnimation.cpp class.
26 #include <FBaseSysLog.h>
27 #include <FBaseColHashMapT.h>
29 #include <FUiAnimIntegerAnimation.h>
31 #include "FUiAnim_IntegerAnimationImpl.h"
32 #include "FUiAnim_AnimationBaseImpl.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Ui::Animations;
37 using namespace Tizen::Base::Collection;
40 namespace Tizen { namespace Ui { namespace Animations
43 IntegerAnimation::IntegerAnimation(void)
44 : _pIntegerAnimationImpl(null)
48 IntegerAnimation::IntegerAnimation(int startValue, int endValue, long duration, AnimationInterpolatorType interpolator)
49 : AnimationBase(duration, interpolator)
50 , _pIntegerAnimationImpl(null)
52 result r = GetLastResult();
53 SysTryReturnVoidResult(NID_UI_ANIM, (_pAnimationBaseImpl), r, "[%s] Propagating.", GetErrorMessage(r));
55 _pIntegerAnimationImpl = new (std::nothrow) _IntegerAnimationImpl(this);
56 if (_pIntegerAnimationImpl == null)
58 SysLogException(NID_UI_ANIM, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
60 delete _pAnimationBaseImpl;
61 _pAnimationBaseImpl = null;
66 _pIntegerAnimationImpl->startValue = startValue;
67 _pIntegerAnimationImpl->endValue = endValue;
70 IntegerAnimation::~IntegerAnimation(void)
72 delete _pIntegerAnimationImpl;
73 _pIntegerAnimationImpl = null;
77 IntegerAnimation::IntegerAnimation(const IntegerAnimation& integerAnimation)
78 : AnimationBase(integerAnimation)
79 , _pIntegerAnimationImpl(null)
81 result r = GetLastResult();
82 SysTryReturnVoidResult(NID_UI_ANIM, (_pAnimationBaseImpl), r, "[%s] Propagating.", GetErrorMessage(r));
84 _pIntegerAnimationImpl = new (std::nothrow) _IntegerAnimationImpl(this);
85 SysTryCatch(NID_UI_ANIM, (_pIntegerAnimationImpl != null), , E_OUT_OF_MEMORY, "Memory allocation failed.");
87 r = _pIntegerAnimationImpl->CopyIntegerAnimationValue(integerAnimation);
88 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to copy integer animation value.");
93 delete _pAnimationBaseImpl;
94 _pAnimationBaseImpl = null;
95 delete _pIntegerAnimationImpl;
96 _pIntegerAnimationImpl = null;
100 IntegerAnimation::operator =(const IntegerAnimation& rhs)
106 result r = E_SUCCESS;
108 AnimationBase::operator =(rhs);
110 r = _pIntegerAnimationImpl->CopyIntegerAnimationValue(rhs);
111 SysTryReturn(NID_UI_ANIM, (r == E_SUCCESS), *this, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to copy integer animation.");
118 IntegerAnimation::operator ==(const IntegerAnimation& rhs) const
120 result r = E_SUCCESS;
122 if (_pAnimationBaseImpl->keyFrameList.GetCount() != rhs._pAnimationBaseImpl->keyFrameList.GetCount())
127 ArrayListT< long >* pKeyList1 = null;
128 ArrayListT< long >* pKeyList2 = null;
129 ICollectionT< long >* pKeyN = _pAnimationBaseImpl->keyFrameList.GetKeysN();
130 ICollectionT< long >* pKeyN1 = rhs._pAnimationBaseImpl->keyFrameList.GetKeysN();
132 if (_pAnimationBaseImpl->keyFrameList.GetCount() != 0)
134 pKeyList1 = new (std::nothrow) ArrayListT< long >;
135 SysTryCatch(NID_UI_ANIM, (!(pKeyList1 == null || pKeyN == null)), , E_OUT_OF_MEMORY, "Memory allocation failed.");
137 r = pKeyList1->Construct(*pKeyN);
138 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] Failed to construct key list.");
140 pKeyList2 = new (std::nothrow) ArrayListT< long >;
141 SysTryCatch(NID_UI_ANIM, !(pKeyList2 == null || pKeyN1 == null), , E_OUT_OF_MEMORY, "Memory allocation failed.");
143 r = pKeyList2->Construct(*pKeyN1);
144 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] Failed to construct key list.");
146 ComparerT< long > comparer;
148 r = pKeyList1->Sort(comparer);
149 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
151 r = pKeyList2->Sort(comparer);
152 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
156 Object* pObjValue1 = null;
157 Object* pObjValue2 = null;
158 for (int index = 0; index < _pAnimationBaseImpl->keyFrameList.GetCount(); index++)
160 pKeyList1->GetAt(index, time1);
161 pKeyList2->GetAt(index, time2);
167 _pAnimationBaseImpl->keyFrameList.GetValue(time1, pObjValue1);
168 rhs._pAnimationBaseImpl->keyFrameList.GetValue(time2, pObjValue2);
169 if ((!pObjValue1) && (!pObjValue2))
173 else if ((!pObjValue1) || (!pObjValue2))
178 Integer* pIntValue1 = dynamic_cast< Integer* >(pObjValue1);
179 if (pIntValue1 == null)
183 Integer* pIntValue2 = dynamic_cast< Integer* >(pObjValue2);
184 if (pIntValue2 == null)
188 if (!(pIntValue1->Equals(*pIntValue2)))
202 if (!((_pIntegerAnimationImpl->startValue).Equals(rhs._pIntegerAnimationImpl->startValue)) ||
203 !((_pIntegerAnimationImpl->endValue).Equals(rhs._pIntegerAnimationImpl->endValue)))
208 return _pAnimationBaseImpl->CompareTimingValues(rhs);
219 IntegerAnimation::operator !=(const IntegerAnimation& rhs) const
221 return !(*this == rhs);
225 IntegerAnimation::Equals(const Object& rhs) const
227 const IntegerAnimation* pIntAnim = dynamic_cast< const IntegerAnimation* >(&rhs);
229 if (pIntAnim == null)
234 return (*this == *pIntAnim);
238 IntegerAnimation::GetHashCode(void) const
240 return (((int) GetRepeatCount()) + ((int) GetOffset()) + ((int) GetDuration()) + ((int) GetDelay()));
244 IntegerAnimation::GetAnimatedValue(long currentTime, int& animatedValue) const
246 SysTryReturnResult(NID_UI_ANIM, (currentTime >= 0 && currentTime <= GetDuration()), E_INVALID_ARG, "Invalid argument(s) is used. currentTime = %ld", currentTime);
248 float actualProgress = _pAnimationBaseImpl->GetActualProgressValue(currentTime);
249 SysTryReturnResult(NID_UI_ANIM, (actualProgress >= 0.0f && actualProgress <= 1.0f), E_SYSTEM, "A system error has been occurred. Failed to calculate progress.");
251 return _pIntegerAnimationImpl->GetAnimatedValue(actualProgress, animatedValue);
255 IntegerAnimation::AddKeyFrame(long time, int value)
257 SysTryReturnResult(NID_UI_ANIM, (time > 0 && time != _pAnimationBaseImpl->duration), E_INVALID_ARG, "Invalid argument(s) is used. time = %ld", time);
259 result r = E_SUCCESS;
260 Integer* pIntObj = null;
262 if (time > _pAnimationBaseImpl->duration)
264 pIntObj = new (std::nothrow) Integer(_pIntegerAnimationImpl->endValue);
265 SysTryReturnResult(NID_UI_ANIM, (pIntObj), E_OUT_OF_MEMORY, "Memory allocation failed.");
267 r = _pAnimationBaseImpl->keyFrameList.Add(_pAnimationBaseImpl->duration, dynamic_cast< Object* >(pIntObj));
268 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add to key frame list.");
270 _pAnimationBaseImpl->duration = time;
271 _pIntegerAnimationImpl->endValue = value;
275 pIntObj = new (std::nothrow) Integer(value);
276 SysTryReturnResult(NID_UI_ANIM, (pIntObj), E_OUT_OF_MEMORY, "Memory allocation failed.");
277 Object* pKeyValue = null;
278 _pAnimationBaseImpl->keyFrameList.GetValue(time, pKeyValue);
281 _pAnimationBaseImpl->keyFrameList.Remove(time);
285 r = _pAnimationBaseImpl->keyFrameList.Add(time, dynamic_cast< Object* >(pIntObj));
286 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add to key frame list.");
297 IntegerAnimation::GetKeyFrameAt(int index, long& time, int& value) const
299 SysTryReturnResult(NID_UI_ANIM, (index >= 0 && index < _pAnimationBaseImpl->keyFrameList.GetCount()),
300 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index (%d) is out of range.", index);
302 result r = E_SUCCESS;
303 Object* pObjValue = null;
304 Integer* pIntValue = null;
305 ComparerT< long > comparer;
307 ArrayListT< long >* pKeyList = new (std::nothrow) ArrayListT< long >;
308 ICollectionT< long >* pKeyN = _pAnimationBaseImpl->keyFrameList.GetKeysN();
310 SysTryCatch(NID_UI_ANIM, (pKeyList != null && pKeyN != null), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
312 r = pKeyList->Construct(*pKeyN);
313 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct key list.");
315 SysTryCatch(NID_UI_ANIM, !(pKeyList->GetCount() <= 0), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Key list count is invalid.");
317 r = pKeyList->Sort(comparer);
318 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
320 r = pKeyList->GetAt(index, time);
321 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
323 r = _pAnimationBaseImpl->keyFrameList.GetValue(time, pObjValue);
324 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get key value.");
325 SysTryCatch(NID_UI_ANIM, (pObjValue != null), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get key frame.");
327 pIntValue = dynamic_cast< Integer* >(pObjValue);
330 value = pIntValue->ToInt();
343 IntegerAnimation::RemoveKeyFrame(long time)
345 return _pAnimationBaseImpl->RemoveKeyFrame(time);
349 IntegerAnimation::RemoveKeyFrameAt(int index)
351 return _pAnimationBaseImpl->RemoveKeyFrameAt(index);
355 IntegerAnimation::RemoveAllKeyFrames(void)
357 return _pAnimationBaseImpl->RemoveAllKeyFrames();
361 IntegerAnimation::SetStartValue(int startValue)
363 _pIntegerAnimationImpl->startValue = startValue;
369 IntegerAnimation::SetEndValue(int endValue)
371 _pIntegerAnimationImpl->endValue = endValue;
377 IntegerAnimation::GetStartValue(void) const
379 return _pIntegerAnimationImpl->startValue.ToInt();
383 IntegerAnimation::GetEndValue(void) const
385 return _pIntegerAnimationImpl->endValue.ToInt();
389 IntegerAnimation::GetType(void) const
391 return ANIMATION_TYPE_INTEGER_ANIMATION;
395 }}} // Tizen::Ui::Animations