Implement Animation PlayAfter() API
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-impl.cpp
index 920479e..b7cc899 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 // CLASS HEADER
 #include <dali/internal/event/animation/animation-impl.h>
+#include <dali/public-api/object/property-map.h>
+
+// EXTERNAL INCLUDES
 
 // INTERNAL INCLUDES
-#include <dali/public-api/actors/actor.h>
-#include <dali/public-api/animation/alpha-functions.h>
+#include <dali/public-api/animation/alpha-function.h>
 #include <dali/public-api/animation/time-period.h>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/radian.h>
-#include <dali/internal/event/actors/actor-impl.h>
 #include <dali/internal/event/animation/animation-playlist.h>
 #include <dali/internal/event/animation/animator-connector.h>
+#include <dali/internal/event/animation/path-impl.h>
 #include <dali/internal/event/common/notification-manager.h>
 #include <dali/internal/event/common/property-helper.h>
 #include <dali/internal/event/common/stage-impl.h>
 #include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/event/effects/shader-effect-impl.h>
+#include <dali/internal/update/animation/scene-graph-animator.h>
 #include <dali/internal/update/manager/update-manager.h>
 
 using Dali::Internal::SceneGraph::UpdateManager;
@@ -78,39 +80,57 @@ TypeAction action3( mType, ACTION_PAUSE, &Animation::DoAction );
 const Dali::Animation::EndAction DEFAULT_END_ACTION( Dali::Animation::Bake );
 const Dali::Animation::EndAction DEFAULT_DISCONNECT_ACTION( Dali::Animation::BakeFinal );
 const Dali::Animation::Interpolation DEFAULT_INTERPOLATION( Dali::Animation::Linear );
+const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION( Dali::AlphaFunction::DEFAULT );
 
 } // anon namespace
 
 
 AnimationPtr Animation::New(float durationSeconds)
 {
-  ThreadLocalStorage& tls = ThreadLocalStorage::Get();
-  UpdateManager& updateManager = tls.GetUpdateManager();
+  Stage* stage = Stage::GetCurrent();
+
+  if( stage )
+  {
+    AnimationPlaylist& playlist = stage->GetAnimationPlaylist();
 
-  AnimationPlaylist& playlist = Stage::GetCurrent()->GetAnimationPlaylist();
+    if( durationSeconds < 0.0f )
+    {
+      DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
+      durationSeconds = 0.0f;
+    }
 
-  AnimationPtr animation = new Animation( updateManager, playlist, durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, Dali::AlphaFunctions::Linear );
+    AnimationPtr animation = new Animation( *stage, playlist, durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, DEFAULT_ALPHA_FUNCTION );
 
-  // Second-phase construction
-  animation->Initialize();
+    // Second-phase construction
+    animation->Initialize();
 
-  return animation;
+    return animation;
+  }
+  else
+  {
+    return NULL;
+  }
 }
 
-Animation::Animation( UpdateManager& updateManager, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
-: mUpdateManager( updateManager ),
+Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
+: mAnimation( NULL ),
+  mEventThreadServices( eventThreadServices ),
   mPlaylist( playlist ),
-  mAnimation( NULL ),
-  mNotificationCount( 0 ),
-  mFinishedCallback( NULL ),
-  mFinishedCallbackObject( NULL ),
+  mFinishedSignal(),
+  mConnectors(),
+  mConnectorTargetValues(),
+  mPlayRange( Vector2(0.0f,1.0f)),
   mDurationSeconds( durationSeconds ),
   mSpeedFactor(1.0f),
-  mIsLooping( false ),
-  mPlayRange( Vector2(0.0f,1.0f)),
+  mNotificationCount( 0 ),
+  mLoopCount(1),
+  mCurrentLoop(0),
   mEndAction( endAction ),
   mDisconnectAction( disconnectAction ),
-  mDefaultAlpha( defaultAlpha )
+  mDefaultAlpha( defaultAlpha ),
+  mState(Dali::Animation::STOPPED),
+  mProgressReachedMarker( 0.0f ),
+  mDelaySeconds( 0.0f )
 {
 }
 
@@ -142,14 +162,10 @@ void Animation::CreateSceneObject()
 {
   DALI_ASSERT_DEBUG( mAnimation == NULL );
 
-  // Create a new animation, temporarily owned
-  SceneGraph::Animation* animation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mIsLooping, mEndAction, mDisconnectAction );
-
-  // Keep a const pointer to the animation.
-  mAnimation = animation;
-
-  // Transfer animation ownership to the update manager through a message
-  AddAnimationMessage( mUpdateManager, animation );
+  // Create a new animation, Keep a const pointer to the animation.
+  mAnimation = SceneGraph::Animation::New( mDurationSeconds, mSpeedFactor, mPlayRange, mLoopCount, mEndAction, mDisconnectAction );
+  OwnerPointer< SceneGraph::Animation > transferOwnership( const_cast< SceneGraph::Animation* >( mAnimation ) );
+  AddAnimationMessage( mEventThreadServices.GetUpdateManager(), transferOwnership );
 }
 
 void Animation::DestroySceneObject()
@@ -157,18 +173,35 @@ void Animation::DestroySceneObject()
   if ( mAnimation != NULL )
   {
     // Remove animation using a message to the update manager
-    RemoveAnimationMessage( mUpdateManager, *mAnimation );
+    RemoveAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
     mAnimation = NULL;
   }
 }
 
 void Animation::SetDuration(float seconds)
 {
+  if( seconds < 0.0f )
+  {
+    DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
+    seconds = 0.0f;
+  }
+
   // Cache for public getters
   mDurationSeconds = seconds;
 
   // mAnimation is being used in a separate thread; queue a message to set the value
-  SetDurationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, seconds );
+  SetDurationMessage( mEventThreadServices, *mAnimation, seconds );
+}
+
+void Animation::SetProgressNotification( float progress )
+{
+  // mAnimation is being used in a separate thread; queue a message to set the value
+  mProgressReachedMarker = progress;
+}
+
+float Animation::GetProgressNotification()
+{
+  return mProgressReachedMarker;
 }
 
 float Animation::GetDuration() const
@@ -177,19 +210,33 @@ float Animation::GetDuration() const
   return mDurationSeconds;
 }
 
-void Animation::SetLooping(bool looping)
+void Animation::SetLooping(bool on)
+{
+  SetLoopCount( on ? 0 : 1 );
+}
+
+void Animation::SetLoopCount(int count)
 {
   // Cache for public getters
-  mIsLooping = looping;
+  mLoopCount = count;
 
   // mAnimation is being used in a separate thread; queue a message to set the value
-  SetLoopingMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, looping );
+  SetLoopingMessage( mEventThreadServices, *mAnimation, mLoopCount );
+}
+
+int Animation::GetLoopCount()
+{
+  return mLoopCount;
+}
+
+int Animation::GetCurrentLoop()
+{
+  return mCurrentLoop;
 }
 
 bool Animation::IsLooping() const
 {
-  // This is not animatable; the cached value is up-to-date.
-  return mIsLooping;
+  return mLoopCount != 1;
 }
 
 void Animation::SetEndAction(EndAction action)
@@ -198,7 +245,7 @@ void Animation::SetEndAction(EndAction action)
   mEndAction = action;
 
   // mAnimation is being used in a separate thread; queue a message to set the value
-  SetEndActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
+  SetEndActionMessage( mEventThreadServices, *mAnimation, action );
 }
 
 Dali::Animation::EndAction Animation::GetEndAction() const
@@ -213,7 +260,7 @@ void Animation::SetDisconnectAction(EndAction action)
   mDisconnectAction = action;
 
   // mAnimation is being used in a separate thread; queue a message to set the value
-  SetDisconnectActionMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, action );
+  SetDisconnectActionMessage( mEventThreadServices, *mAnimation, action );
 }
 
 Dali::Animation::EndAction Animation::GetDisconnectAction() const
@@ -227,8 +274,14 @@ void Animation::Play()
   // Update the current playlist
   mPlaylist.OnPlay( *this );
 
+  mState = Dali::Animation::PLAYING;
+
+  NotifyObjects();
+
+  SendFinalProgressNotificationMessage();
+
   // mAnimation is being used in a separate thread; queue a Play message
-  PlayAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
+  PlayAnimationMessage( mEventThreadServices, *mAnimation );
 }
 
 void Animation::PlayFrom( float progress )
@@ -238,21 +291,56 @@ void Animation::PlayFrom( float progress )
     // Update the current playlist
     mPlaylist.OnPlay( *this );
 
+    mState = Dali::Animation::PLAYING;
+
+    NotifyObjects();
+
+    SendFinalProgressNotificationMessage();
+
     // mAnimation is being used in a separate thread; queue a Play message
-    PlayAnimationFromMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
+    PlayAnimationFromMessage( mEventThreadServices, *mAnimation, progress );
   }
 }
 
+void Animation::PlayAfter( float delaySeconds )
+{
+  // The negative delay means play immediately.
+  delaySeconds = std::max( 0.f, delaySeconds );
+
+  mDelaySeconds = delaySeconds;
+
+  // Update the current playlist
+  mPlaylist.OnPlay( *this );
+
+  mState = Dali::Animation::PLAYING;
+
+  NotifyObjects();
+
+  SendFinalProgressNotificationMessage();
+
+  // mAnimation is being used in a separate thread; queue a message to set the value
+  PlayAfterMessage( mEventThreadServices, *mAnimation, delaySeconds );
+}
+
 void Animation::Pause()
 {
+  mState = Dali::Animation::PAUSED;
+
   // mAnimation is being used in a separate thread; queue a Pause message
-  PauseAnimationMessage( mUpdateManager.GetEventToUpdate(), *mAnimation );
+  PauseAnimationMessage( mEventThreadServices, *mAnimation );
+}
+
+Dali::Animation::State Animation::GetState() const
+{
+  return mState;
 }
 
 void Animation::Stop()
 {
+  mState = Dali::Animation::STOPPED;
+
   // mAnimation is being used in a separate thread; queue a Stop message
-  StopAnimationMessage( mUpdateManager, *mAnimation );
+  StopAnimationMessage( mEventThreadServices.GetUpdateManager(), *mAnimation );
 }
 
 void Animation::Clear()
@@ -262,6 +350,9 @@ void Animation::Clear()
   // Remove all the connectors
   mConnectors.Clear();
 
+  // Reset the connector target values
+  mConnectorTargetValues.clear();
+
   // Replace the old scene-object with a new one
   DestroySceneObject();
   CreateSceneObject();
@@ -275,26 +366,45 @@ void Animation::Clear()
 
 void Animation::AnimateBy(Property& target, Property::Value& relativeValue)
 {
-  AnimateBy(target, relativeValue, AlphaFunctions::Default, mDurationSeconds);
+  AnimateBy(target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
 }
 
 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha)
 {
-  AnimateBy(target, relativeValue, alpha, mDurationSeconds);
+  AnimateBy(target, relativeValue, alpha, TimePeriod(mDurationSeconds));
 }
 
 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period)
 {
-  AnimateBy(target, relativeValue, AlphaFunctions::Default, period);
+  AnimateBy(target, relativeValue, mDefaultAlpha, period);
 }
 
 void Animation::AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period)
 {
-  Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
+  Object& object = GetImplementation(target.object);
+  const Property::Type targetType = object.GetPropertyType(target.propertyIndex);
+  const Property::Type destinationType = relativeValue.GetType();
 
-  ExtendDuration( period );
+  if ( object.GetPropertyComponentIndex( target.propertyIndex ) != Property::INVALID_COMPONENT_INDEX )
+  {
+    DALI_ASSERT_ALWAYS(Property::FLOAT == destinationType && "Animated value and Property type don't match");
+  }
+  else
+  {
+    DALI_ASSERT_ALWAYS(targetType == destinationType && "Animated value and Property type don't match");
+  }
+
+  ExtendDuration(period);
 
-  switch ( relativeValue.GetType() )
+  // Store data to later notify the object that its property is being animated
+  ConnectorTargetValues connectorPair;
+  connectorPair.targetValue = relativeValue;
+  connectorPair.connectorIndex = mConnectors.Count();
+  connectorPair.timePeriod = period;
+  connectorPair.animatorType = Animation::BY;
+  mConnectorTargetValues.push_back( connectorPair );
+
+  switch ( targetType )
   {
     case Property::BOOLEAN:
     {
@@ -307,17 +417,6 @@ void Animation::AnimateBy(Property& target, Property::Value& relativeValue, Alph
       break;
     }
 
-    case Property::FLOAT:
-    {
-      AddAnimatorConnector( AnimatorConnector<float>::New( object,
-                                                           target.propertyIndex,
-                                                           target.componentIndex,
-                                                           new AnimateByFloat(relativeValue.Get<float>()),
-                                                           alpha,
-                                                           period ) );
-      break;
-    }
-
     case Property::INTEGER:
     {
       AddAnimatorConnector( AnimatorConnector<int>::New( object,
@@ -329,6 +428,17 @@ void Animation::AnimateBy(Property& target, Property::Value& relativeValue, Alph
       break;
     }
 
+    case Property::FLOAT:
+    {
+      AddAnimatorConnector( AnimatorConnector<float>::New( object,
+                                                           target.propertyIndex,
+                                                           target.componentIndex,
+                                                           new AnimateByFloat(relativeValue.Get<float>()),
+                                                           alpha,
+                                                           period ) );
+      break;
+    }
+
     case Property::VECTOR2:
     {
       AddAnimatorConnector( AnimatorConnector<Vector2>::New( object,
@@ -376,50 +486,60 @@ void Animation::AnimateBy(Property& target, Property::Value& relativeValue, Alph
     }
 
     default:
-      DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
-      break;
+    {
+      // non animatable types handled already
+    }
   }
 }
 
 void Animation::AnimateTo(Property& target, Property::Value& destinationValue)
 {
-  AnimateTo(target, destinationValue, AlphaFunctions::Default, mDurationSeconds);
+  AnimateTo(target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds));
 }
 
 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha)
 {
-  AnimateTo(target, destinationValue, alpha, mDurationSeconds);
+  AnimateTo(target, destinationValue, alpha, TimePeriod(mDurationSeconds));
 }
 
 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period)
 {
-  AnimateTo(target, destinationValue, AlphaFunctions::Default, period);
+  AnimateTo(target, destinationValue, mDefaultAlpha, period);
 }
 
 void Animation::AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
 {
-  Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
+  Object& object = GetImplementation(target.object);
 
   AnimateTo( object, target.propertyIndex, target.componentIndex, destinationValue, alpha, period );
 }
 
 void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period)
 {
-  Property::Type type = targetObject.GetPropertyType(targetPropertyIndex);
-  if(componentIndex != Property::INVALID_COMPONENT_INDEX)
+  Property::Type targetType = targetObject.GetPropertyType(targetPropertyIndex);
+  if( componentIndex != Property::INVALID_COMPONENT_INDEX )
   {
-    if( type == Property::VECTOR2
-        || type == Property::VECTOR3
-        || type == Property::VECTOR4 )
+    if( ( targetType == Property::VECTOR2 ) ||
+        ( targetType == Property::VECTOR3 ) ||
+        ( targetType == Property::VECTOR4 ) )
     {
-      type = Property::FLOAT;
+      targetType = Property::FLOAT;
     }
   }
-  DALI_ASSERT_ALWAYS( type == destinationValue.GetType() && "DestinationValue does not match Target Property type" );
+  const Property::Type destinationType = destinationValue.GetType();
+  DALI_ASSERT_ALWAYS( targetType == destinationType && "Animated value and Property type don't match" );
 
   ExtendDuration( period );
 
-  switch (destinationValue.GetType())
+  // Store data to later notify the object that its property is being animated
+  ConnectorTargetValues connectorPair;
+  connectorPair.targetValue = destinationValue;
+  connectorPair.connectorIndex = mConnectors.Count();
+  connectorPair.timePeriod = period;
+  connectorPair.animatorType = Animation::TO;
+  mConnectorTargetValues.push_back( connectorPair );
+
+  switch ( destinationType )
   {
     case Property::BOOLEAN:
     {
@@ -432,17 +552,6 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn
       break;
     }
 
-    case Property::FLOAT:
-    {
-      AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
-                                                           targetPropertyIndex,
-                                                           componentIndex,
-                                                           new AnimateToFloat( destinationValue.Get<float>() ),
-                                                           alpha,
-                                                           period ) );
-      break;
-    }
-
     case Property::INTEGER:
     {
       AddAnimatorConnector( AnimatorConnector<int>::New( targetObject,
@@ -454,6 +563,17 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn
       break;
     }
 
+    case Property::FLOAT:
+    {
+      AddAnimatorConnector( AnimatorConnector<float>::New( targetObject,
+                                                           targetPropertyIndex,
+                                                           componentIndex,
+                                                           new AnimateToFloat( destinationValue.Get<float>() ),
+                                                           alpha,
+                                                           period ) );
+      break;
+    }
+
     case Property::VECTOR2:
     {
       AddAnimatorConnector( AnimatorConnector<Vector2>::New( targetObject,
@@ -467,17 +587,6 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn
 
     case Property::VECTOR3:
     {
-      if ( Dali::Actor::Property::SIZE == targetPropertyIndex )
-      {
-        // Test whether this is actually an Actor
-        Actor* maybeActor = dynamic_cast<Actor*>( &targetObject );
-        if ( maybeActor )
-        {
-          // Notify the actor that its size is being animated
-          maybeActor->NotifySizeAnimation( *this, destinationValue.Get<Vector3>() );
-        }
-      }
-
       AddAnimatorConnector( AnimatorConnector<Vector3>::New( targetObject,
                                                              targetPropertyIndex,
                                                              componentIndex,
@@ -510,19 +619,20 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn
     }
 
     default:
-      DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
-      break;
+    {
+      // non animatable types handled already
+    }
   }
 }
 
 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames)
 {
-  AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds, DEFAULT_INTERPOLATION );
+  AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION );
 }
 
 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Interpolation interpolation )
 {
-  AnimateBetween(target, keyFrames, mDefaultAlpha, mDurationSeconds, interpolation );
+  AnimateBetween(target, keyFrames, mDefaultAlpha, TimePeriod(mDurationSeconds), interpolation );
 }
 
 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period)
@@ -537,12 +647,12 @@ void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Time
 
 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha)
 {
-  AnimateBetween(target, keyFrames, alpha, mDurationSeconds, DEFAULT_INTERPOLATION);
+  AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), DEFAULT_INTERPOLATION);
 }
 
 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation)
 {
-  AnimateBetween(target, keyFrames, alpha, mDurationSeconds, interpolation);
+  AnimateBetween(target, keyFrames, alpha, TimePeriod(mDurationSeconds), interpolation);
 }
 
 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
@@ -552,10 +662,18 @@ void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Alph
 
 void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation)
 {
-  Object& object = dynamic_cast<Object&>( GetImplementation(target.object) );
+  Object& object = GetImplementation( target.object );
 
   ExtendDuration( period );
 
+  // Store data to later notify the object that its property is being animated
+  ConnectorTargetValues connectorPair;
+  connectorPair.targetValue = keyFrames.GetLastKeyFrameValue();
+  connectorPair.connectorIndex = mConnectors.Count();
+  connectorPair.timePeriod = period;
+  connectorPair.animatorType = BETWEEN;
+  mConnectorTargetValues.push_back( connectorPair );
+
   switch(keyFrames.GetType())
   {
     case Dali::Property::BOOLEAN:
@@ -572,20 +690,6 @@ void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Alph
       break;
     }
 
-    case Dali::Property::FLOAT:
-    {
-      const KeyFrameNumber* kf;
-      GetSpecialization(keyFrames, kf);
-      KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
-      AddAnimatorConnector( AnimatorConnector<float>::New( object,
-                                                           target.propertyIndex,
-                                                           target.componentIndex,
-                                                           new KeyFrameNumberFunctor(kfCopy,interpolation),
-                                                           alpha,
-                                                           period ) );
-      break;
-    }
-
     case Dali::Property::INTEGER:
     {
       const KeyFrameInteger* kf;
@@ -600,6 +704,20 @@ void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Alph
       break;
     }
 
+    case Dali::Property::FLOAT:
+    {
+      const KeyFrameNumber* kf;
+      GetSpecialization(keyFrames, kf);
+      KeyFrameNumberPtr kfCopy = KeyFrameNumber::Clone(*kf);
+      AddAnimatorConnector( AnimatorConnector<float>::New( object,
+                                                           target.propertyIndex,
+                                                           target.componentIndex,
+                                                           new KeyFrameNumberFunctor(kfCopy,interpolation),
+                                                           alpha,
+                                                           period ) );
+      break;
+    }
+
     case Dali::Property::VECTOR2:
     {
       const KeyFrameVector2* kf;
@@ -656,23 +774,29 @@ void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Alph
       break;
     }
 
-    default: // not all property types are animateable
-      break;
+    default:
+    {
+      // non animatable types handled by keyframes
+    }
   }
 }
 
 bool Animation::HasFinished()
 {
   bool hasFinished(false);
-  const int playCount(mAnimation->GetPlayCount());
+  const int playedCount(mAnimation->GetPlayedCount());
 
   // If the play count has been incremented, then another notification is required
-  if (playCount > mNotificationCount)
+  mCurrentLoop = mAnimation->GetCurrentLoop();
+
+  if (playedCount > mNotificationCount)
   {
     // Note that only one signal is emitted, if the animation has been played repeatedly
-    mNotificationCount = playCount;
+    mNotificationCount = playedCount;
 
     hasFinished = true;
+
+    mState = Dali::Animation::STOPPED;
   }
 
   return hasFinished;
@@ -683,6 +807,11 @@ Dali::Animation::AnimationSignalType& Animation::FinishedSignal()
   return mFinishedSignal;
 }
 
+Dali::Animation::AnimationSignalType& Animation::ProgressReachedSignal()
+{
+  return mProgressReachedSignal;
+}
+
 void Animation::EmitSignalFinish()
 {
   if ( !mFinishedSignal.Empty() )
@@ -690,20 +819,23 @@ void Animation::EmitSignalFinish()
     Dali::Animation handle( this );
     mFinishedSignal.Emit( handle );
   }
+}
 
-  // This callback is used internally, to avoid the overhead of using a signal.
-  if ( mFinishedCallback )
+void Animation::EmitSignalProgressReached()
+{
+  if ( !mProgressReachedSignal.Empty() )
   {
-    mFinishedCallback( mFinishedCallbackObject );
+    Dali::Animation handle( this );
+    mProgressReachedSignal.Emit( handle );
   }
 }
 
 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
 {
   bool connected( true );
-  Animation* animation = dynamic_cast<Animation*>(object);
+  Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type.
 
-  if ( 0 == strcmp( signalName.c_str(), SIGNAL_FINISHED ) )
+  if( 0 == signalName.compare( SIGNAL_FINISHED ) )
   {
     animation->FinishedSignal().Connect( tracker, functor );
   }
@@ -716,12 +848,6 @@ bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface*
   return connected;
 }
 
-void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
-{
-  mFinishedCallback = callback;
-  mFinishedCallbackObject = object;
-}
-
 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
 {
   DALI_ASSERT_DEBUG( NULL != connector );
@@ -733,12 +859,12 @@ void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
 
 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward )
 {
-  Animate( actor, path, forward, mDefaultAlpha, TimePeriod(0.0f,GetDuration()) );
+  Animate( actor, path, forward, mDefaultAlpha, TimePeriod(mDurationSeconds) );
 }
 
 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, AlphaFunction alpha )
 {
-  Animate( actor, path, forward, alpha, TimePeriod(0.0f,GetDuration()) );
+  Animate( actor, path, forward, alpha, TimePeriod(mDurationSeconds) );
 }
 
 void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward, TimePeriod period )
@@ -765,7 +891,7 @@ void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward,
   {
     //Rotation animation
     AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
-                                                              Dali::Actor::Property::ROTATION,
+                                                              Dali::Actor::Property::ORIENTATION,
                                                               Property::INVALID_COMPONENT_INDEX,
                                                               new PathRotationFunctor( pathCopy, forward ),
                                                               alpha,
@@ -773,168 +899,6 @@ void Animation::Animate( Actor& actor, const Path& path, const Vector3& forward,
   }
 }
 
-void Animation::MoveBy(Actor& actor, float x, float y, float z)
-{
-  MoveBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha)
-{
-  MoveBy(actor, displacement, alpha, 0.0f, GetDuration());
-}
-
-void Animation::MoveBy(Actor& actor, const Vector3& displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
-                                                         Dali::Actor::Property::POSITION,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateByVector3(displacement),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::MoveTo(Actor& actor, float x, float y, float z)
-{
-  MoveTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha)
-{
-  MoveTo(actor, position, alpha, 0.0f, GetDuration());
-}
-
-void Animation::MoveTo(Actor& actor, const Vector3& position, AlphaFunction alpha,  float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
-                                                         Dali::Actor::Property::POSITION,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateToVector3(position),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis)
-{
-  RotateBy(actor, angle, axis, mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
-{
-  RotateBy(actor, angle, axis, alpha, 0.0f, GetDuration());
-}
-
-void Animation::RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
-                                                            Dali::Actor::Property::ROTATION,
-                                                            Property::INVALID_COMPONENT_INDEX,
-                                                            new RotateByAngleAxis(angle, axis),
-                                                            alpha,
-                                                            TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis)
-{
-  Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
-  normalizedAxis.Normalize();
-
-  Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
-
-  RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::RotateTo(Actor& actor, const Quaternion& orientation)
-{
-  RotateTo(actor, orientation, mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha)
-{
-  Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
-  normalizedAxis.Normalize();
-
-  Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
-
-  RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
-}
-
-void Animation::RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha)
-{
-  RotateTo(actor, orientation, alpha, 0.0f, GetDuration());
-}
-
-void Animation::RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  Vector4 normalizedAxis(axis.x, axis.y, axis.z, 0.0f);
-  normalizedAxis.Normalize();
-
-  Quaternion orientation(Quaternion::FromAxisAngle(normalizedAxis, angle));
-
-  RotateTo(actor, orientation, alpha, delaySeconds, durationSeconds);
-}
-
-void Animation::RotateTo(Actor& actor, const Quaternion& rotation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Quaternion>::New( actor,
-                                                            Dali::Actor::Property::ROTATION,
-                                                            Property::INVALID_COMPONENT_INDEX,
-                                                            new RotateToQuaternion(rotation),
-                                                            alpha,
-                                                            TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::ScaleBy(Actor& actor, float x, float y, float z)
-{
-  ScaleBy(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha)
-{
-  ScaleBy(actor, scale, alpha, 0.0f, GetDuration());
-}
-
-void Animation::ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
-                                                         Dali::Actor::Property::SCALE,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateByVector3(scale),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::ScaleTo(Actor& actor, float x, float y, float z)
-{
-  ScaleTo(actor, Vector3(x, y, z), mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha)
-{
-  ScaleTo(actor, scale, alpha, 0.0f, GetDuration());
-}
-
-void Animation::ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
-                                                         Dali::Actor::Property::SCALE,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateToVector3(scale),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
 void Animation::Show(Actor& actor, float delaySeconds)
 {
   ExtendDuration( TimePeriod(delaySeconds, 0) );
@@ -943,7 +907,7 @@ void Animation::Show(Actor& actor, float delaySeconds)
                                                       Dali::Actor::Property::VISIBLE,
                                                       Property::INVALID_COMPONENT_INDEX,
                                                       new AnimateToBoolean(SHOW_VALUE),
-                                                      AlphaFunctions::Default,
+                                                      mDefaultAlpha,
                                                       TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
 }
 
@@ -955,173 +919,33 @@ void Animation::Hide(Actor& actor, float delaySeconds)
                                                       Dali::Actor::Property::VISIBLE,
                                                       Property::INVALID_COMPONENT_INDEX,
                                                       new AnimateToBoolean(HIDE_VALUE),
-                                                      AlphaFunctions::Default,
+                                                      mDefaultAlpha,
                                                       TimePeriod(delaySeconds, 0.0f/*immediate*/) ) );
 }
 
-void Animation::OpacityBy(Actor& actor, float opacity)
-{
-  OpacityBy(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha)
-{
-  OpacityBy(actor, opacity, alpha, 0.0f, GetDuration());
-}
-
-void Animation::OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
-                                                         Dali::Actor::Property::COLOR,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateByOpacity(opacity),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::OpacityTo(Actor& actor, float opacity)
-{
-  OpacityTo(actor, opacity, mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha)
-{
-  OpacityTo(actor, opacity, alpha, 0.0f, GetDuration());
-}
-
-void Animation::OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
-                                                         Dali::Actor::Property::COLOR,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateToOpacity(opacity),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::ColorBy(Actor& actor, const Vector4& color)
-{
-  ColorBy(actor, color, mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha)
-{
-  ColorBy(actor, color, alpha, 0.0f, GetDuration());
-}
-
-void Animation::ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
-                                                         Dali::Actor::Property::COLOR,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateByVector4(color),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::ColorTo(Actor& actor, const Vector4& color)
-{
-  ColorTo(actor, color, mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha)
-{
-  ColorTo(actor, color, alpha, 0.0f, GetDuration());
-}
-
-void Animation::ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  AddAnimatorConnector( AnimatorConnector<Vector4>::New( actor,
-                                                         Dali::Actor::Property::COLOR,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateToVector4(color),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::Resize(Actor& actor, float width, float height)
-{
-  Resize(actor, width, height, mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha)
-{
-  Resize(actor, width, height, alpha, 0.0f, GetDuration());
-}
-
-void Animation::Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  Vector3 targetSize( width, height, std::min(width, height) );
-
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  // Notify the actor impl that its size is being animated
-  actor.NotifySizeAnimation( *this, targetSize );
-
-  AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
-                                                         Dali::Actor::Property::SIZE,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateToVector3(targetSize),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-void Animation::Resize(Actor& actor, const Vector3& size)
-{
-  Resize(actor, size, mDefaultAlpha, 0.0f, GetDuration());
-}
-
-void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha)
-{
-  Resize(actor, size, alpha, 0.0f, GetDuration());
-}
-
-void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
-{
-  ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
-
-  // Notify the actor impl that its size is being animated
-  actor.NotifySizeAnimation( *this, size );
-
-  AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
-                                                         Dali::Actor::Property::SIZE,
-                                                         Property::INVALID_COMPONENT_INDEX,
-                                                         new AnimateToVector3(size),
-                                                         alpha,
-                                                         TimePeriod(delaySeconds, durationSeconds) ) );
-}
-
-bool Animation::DoAction( BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes )
+bool Animation::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
 {
   bool done = false;
   Animation* animation = dynamic_cast<Animation*>( object );
 
   if( animation )
   {
-    if( 0 == strcmp( actionName.c_str(), ACTION_PLAY ) )
+    if( 0 == actionName.compare( ACTION_PLAY ) )
     {
-      if( attributes.size() > 0 )
+      if( Property::Value* value = attributes.Find("duration", Property::FLOAT) )
       {
-        animation->SetDuration( attributes[0].Get<float>() );
+        animation->SetDuration( value->Get<float>() );
       }
 
       animation->Play();
       done = true;
     }
-    else if( 0 == strcmp( actionName.c_str(), ACTION_STOP ) )
+    else if( 0 == actionName.compare( ACTION_STOP ) )
     {
       animation->Stop();
       done = true;
     }
-    else if( 0 == strcmp( actionName.c_str(), ACTION_PAUSE ) )
+    else if( 0 == actionName.compare( ACTION_PAUSE ) )
     {
       animation->Pause();
       done = true;
@@ -1136,7 +960,7 @@ void Animation::SetCurrentProgress(float progress)
   if( mAnimation && progress >= mPlayRange.x && progress <= mPlayRange.y )
   {
     // mAnimation is being used in a separate thread; queue a message to set the current progress
-    SetCurrentProgressMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, progress );
+    SetCurrentProgressMessage( mEventThreadServices, *mAnimation, progress );
   }
 }
 
@@ -1165,7 +989,7 @@ void Animation::SetSpeedFactor( float factor )
   if( mAnimation )
   {
     mSpeedFactor = factor;
-    SetSpeedFactorMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, factor );
+    SetSpeedFactorMessage( mEventThreadServices, *mAnimation, factor );
   }
 }
 
@@ -1190,7 +1014,7 @@ void Animation::SetPlayRange( const Vector2& range)
     mPlayRange = orderedRange;
 
     // mAnimation is being used in a separate thread; queue a message to set play range
-    SetPlayRangeMessage( mUpdateManager.GetEventToUpdate(), *mAnimation, orderedRange );
+    SetPlayRangeMessage( mEventThreadServices, *mAnimation, orderedRange );
   }
 }
 
@@ -1199,6 +1023,43 @@ Vector2 Animation::GetPlayRange() const
   return mPlayRange;
 }
 
+bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs )
+{
+  return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) );
+}
+
+void Animation::NotifyObjects()
+{
+  if( mEndAction != EndAction::Discard ) // If the animation is discarded, then we do not want to change the target values
+  {
+    // Sort according to end time with earlier end times coming first, if the end time is the same, then the connectors are not moved
+    std::stable_sort( mConnectorTargetValues.begin(), mConnectorTargetValues.end(), CompareConnectorEndTimes );
+
+    // Loop through all connector target values sorted by increasing end time
+    ConnectorTargetValuesContainer::const_iterator iter = mConnectorTargetValues.begin();
+    const ConnectorTargetValuesContainer::const_iterator endIter = mConnectorTargetValues.end();
+    for( ; iter != endIter; ++iter )
+    {
+      AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ];
+
+      Object* object = connector->GetObject();
+      if( object )
+      {
+        object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue, iter->animatorType );
+      }
+    }
+  }
+}
+
+
+void Animation::SendFinalProgressNotificationMessage()
+{
+  if ( mProgressReachedMarker > 0.0f )
+  {
+    float progressMarkerSeconds = mDurationSeconds * mProgressReachedMarker;
+    SetProgressNotificationMessage( mEventThreadServices, *mAnimation, progressMarkerSeconds );
+  }
+}
 
 } // namespace Internal