Revert "nui 0.2.48 version change"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Animation.cs
old mode 100644 (file)
new mode 100755 (executable)
index badb901..4f92f82
@@ -47,28 +47,52 @@ namespace Tizen.NUI
         /// <summary>
         /// To make Animation instance be disposed.
         /// </summary>
-        public override void Dispose()
+        protected override void Dispose(DisposeTypes type)
         {
-            if (!Window.IsInstalled())
+            if(disposed)
             {
-                DisposeQueue.Instance.Add(this);
                 return;
             }
+            if(type == DisposeTypes.Explicit)
+            {
+                //Called by User
+                //Release your own managed resources here.
+                //You should release all of your own disposable objects here.
+                NUILog.Debug("Animation.Dispose(Explicit)! GetState=" + this.GetState());
+                if(this.GetState() != States.Stopped)
+                {
+                    this.Clear();
+                    this.Reset();
+                    NUILog.Error("Now Animation is playing! Clear and Reset here!");
+                }
+            }
+            else if(type == DisposeTypes.Implicit)
+            {
+                NUILog.Debug("Animation.Dispose(Implicit)! GetState=" + this.GetState());
+                if(this.GetState() != States.Stopped)
+                {
+                    this.Clear();
+                    this.Reset();
+                    NUILog.Error("Now Animation is playing! Clear and Reset here!");
+                    throw new System.InvalidOperationException("Animation Instance should not be disposed until getting Finished event. Should be a global variable");
+                }
+            }
 
-            lock (this)
+            //Release your own unmanaged resources here.
+            //You should not access any managed member here except static instance.
+            //because the execution order of Finalizes is non-deterministic.
+
+            if (swigCPtr.Handle != global::System.IntPtr.Zero)
             {
-                if (swigCPtr.Handle != global::System.IntPtr.Zero)
+                if (swigCMemOwn)
                 {
-                    if (swigCMemOwn)
-                    {
-                        swigCMemOwn = false;
-                        NDalicPINVOKE.delete_Animation(swigCPtr);
-                    }
-                    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+                    swigCMemOwn = false;
+                    NDalicPINVOKE.delete_Animation(swigCPtr);
                 }
-                global::System.GC.SuppressFinalize(this);
-                base.Dispose();
+                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
             }
+
+            base.Dispose(type);
         }
 
         /// <summary>
@@ -139,12 +163,59 @@ namespace Tizen.NUI
             }
         }
 
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void AnimationProgressReachedEventCallbackType(IntPtr data);
+        private AnimationProgressReachedEventCallbackType _animationProgressReachedEventCallback;
+        private event EventHandler _animationProgressReachedEventHandler;
+        /**
+        * @brief Event for ProgressReached signal which can be used to subscribe/unsubscribe the event handler.
+        * ProgressReached signal is emitted when the Animation has reached a given progress percentage, this is set in the api SetProgressNotification.
+        */
+        public event EventHandler ProgressReached
+        {
+            add
+            {
+                if (_animationProgressReachedEventHandler == null)
+                {
+#if DEBUG_ON
+                    Tizen.Log.Debug("NUI", "con1) ProgressReachedSignal().Empty = " + ProgressReachedSignal().Empty());
+                    Tizen.Log.Debug("NUI", "con2) ProgressReachedSignal().GetConnectionCount = " + ProgressReachedSignal().GetConnectionCount());
+#endif
+                    _animationProgressReachedEventCallback = OnProgressReached;
+                    ProgressReachedSignal().Connect(_animationProgressReachedEventCallback);
+#if DEBUG_ON
+                    Tizen.Log.Debug("NUI", "con3) ProgressReachedSignal().Empty = " + ProgressReachedSignal().Empty());
+                    Tizen.Log.Debug("NUI", "con4) ProgressReachedSignal().GetConnectionCount = " + ProgressReachedSignal().GetConnectionCount());
+#endif
+                }
+
+                _animationProgressReachedEventHandler += value;
+            }
+            remove
+            {
+                _animationProgressReachedEventHandler -= value;
 
-        internal static Animation GetAnimationFromPtr(global::System.IntPtr cPtr)
+                if (_animationProgressReachedEventHandler == null && ProgressReachedSignal().Empty() == false)
+                {
+#if DEBUG_ON
+                    Tizen.Log.Debug("NUI", "discon1) ProgressReachedSignal().Empty = " + ProgressReachedSignal().Empty());
+                    Tizen.Log.Debug("NUI", "discon2) ProgressReachedSignal().GetConnectionCount = " + ProgressReachedSignal().GetConnectionCount());
+#endif
+                    ProgressReachedSignal().Disconnect(_animationProgressReachedEventHandler);
+#if DEBUG_ON
+                    Tizen.Log.Debug("NUI", "discon3) ProgressReachedSignal().Empty = " + ProgressReachedSignal().Empty());
+                    Tizen.Log.Debug("NUI", "discon4) ProgressReachedSignal().GetConnectionCount = " + ProgressReachedSignal().GetConnectionCount());
+#endif
+                }
+            }
+        }
+        private void OnProgressReached(IntPtr data)
         {
-            Animation ret = new Animation(cPtr, false);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
+            if (_animationProgressReachedEventHandler != null)
+            {
+                //here we send all data to user event handlers
+                _animationProgressReachedEventHandler(this, null);
+            }
         }
 
         private float MilliSecondsToSeconds(int millisec)
@@ -363,6 +434,27 @@ namespace Tizen.NUI
             }
         }
 
+
+        /// <summary>
+        /// Gets/Sets the Progress notification marker which triggers the ProgressReachedSignal.<br>
+        /// percentage of animation progress should be greater than 0 and less than 1, e.g 0.3 for 30% <br>
+        /// One notification can be set on each animation
+        /// </summary>
+        public float ProgressNotification
+        {
+            set
+            {
+                NDalicPINVOKE.Animation_SetProgressNotification(swigCPtr, value);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+            get
+            {
+                float ret = NDalicPINVOKE.Animation_GetProgressNotification(swigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                return ret;
+            }
+        }
+
         /// <summary>
         /// Animates a property value by a relative amount.<br>
         /// </summary>
@@ -379,7 +471,7 @@ namespace Tizen.NUI
             Property _prop = new Property(target, _str);
             if (_prop.propertyIndex == Property.INVALID_INDEX)
             {
-                throw new System.Exception("second argument string property is invalid parameter!");
+                throw new System.ArgumentException("second argument string property is invalid parameter!");
             }
 
             PropertyType propertyType = target.GetPropertyType(_prop.propertyIndex);
@@ -423,7 +515,7 @@ namespace Tizen.NUI
             Property _prop = new Property(target, _str);
             if (_prop.propertyIndex == Property.INVALID_INDEX)
             {
-                throw new System.Exception("second argument string property is invalid parameter!");
+                throw new System.ArgumentException("second argument string property is invalid parameter!");
             }
 
             PropertyType propertyType = target.GetPropertyType(_prop.propertyIndex);
@@ -467,7 +559,7 @@ namespace Tizen.NUI
             Property _prop = new Property(target, _str);
             if (_prop.propertyIndex == Property.INVALID_INDEX)
             {
-                throw new System.Exception("second argument string property is invalid parameter!");
+                throw new System.ArgumentException("second argument string property is invalid parameter!");
             }
 
             PropertyType propertyType = target.GetPropertyType(_prop.propertyIndex);
@@ -512,7 +604,7 @@ namespace Tizen.NUI
             Property _prop = new Property(target, _str);
             if (_prop.propertyIndex == Property.INVALID_INDEX)
             {
-                throw new System.Exception("second argument string property is invalid parameter!");
+                throw new System.ArgumentException("second argument string property is invalid parameter!");
             }
 
             PropertyType propertyType = target.GetPropertyType(_prop.propertyIndex);
@@ -557,7 +649,7 @@ namespace Tizen.NUI
             Property _prop = new Property(target, _str);
             if (_prop.propertyIndex == Property.INVALID_INDEX)
             {
-                throw new System.Exception("second argument string property is invalid parameter!");
+                throw new System.ArgumentException("second argument string property is invalid parameter!");
             }
 
             if (alphaFunction != null)
@@ -590,7 +682,7 @@ namespace Tizen.NUI
             Property _prop = new Property(target, _str);
             if (_prop.propertyIndex == Property.INVALID_INDEX)
             {
-                throw new System.Exception("second argument string property is invalid parameter!");
+                throw new System.ArgumentException("second argument string property is invalid parameter!");
             }
 
             Tizen.NUI.TimePeriod time = new Tizen.NUI.TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime));
@@ -882,6 +974,13 @@ namespace Tizen.NUI
             return ret;
         }
 
+        internal AnimationSignal ProgressReachedSignal()
+        {
+            AnimationSignal ret = new AnimationSignal(NDalicPINVOKE.Animation_ProgressReachedSignal(swigCPtr), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         internal void AnimateBy(Property target, PropertyValue relativeValue)
         {
             NDalicPINVOKE.Animation_AnimateBy__SWIG_0(swigCPtr, Property.getCPtr(target), PropertyValue.getCPtr(relativeValue));