c363f7d1514699e4774423546b025a649acf2929
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Animation / Animation.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 namespace Tizen.NUI
19 {
20     using System;
21     using System.ComponentModel;
22     using System.Runtime.InteropServices;
23     using System.Collections.Generic;
24     using System.Linq;
25     using System.Reflection;
26     using System.Globalization;
27     using System.Diagnostics.CodeAnalysis;
28
29     using Tizen.NUI.BaseComponents;
30
31     /// <summary>
32     /// Animation can be used to animate the properties of any number of objects, typically view.<br />
33     /// If the "Finished" event is connected to a member function of an object, it must be disconnected before the object is destroyed.<br />
34     /// This is typically done in the object destructor, and requires either the animation handle to be stored.<br />
35     /// The overall animation time is superseded by the values given in the animation time used when calling the AnimateTo(), AnimateBy(), AnimateBetween() and AnimatePath() methods.<br />
36     /// If any of the individual calls to those functions exceeds the overall animation time (Duration), then the overall animation time is automatically extended.<br />
37     /// </summary>
38     /// <since_tizen> 3 </since_tizen>
39     public class Animation : BaseHandle
40     {
41         private static bool? disableAnimation = null;
42
43         private AnimationFinishedEventCallbackType animationFinishedEventCallback;
44         private System.IntPtr finishedCallbackOfNative;
45
46         private AnimationProgressReachedEventCallbackType animationProgressReachedEventCallback;
47
48         private string[] properties = null;
49         private string[] destValue = null;
50         private int[] startTime = null;
51         private int[] endTime = null;
52
53         private List<string> propertyList = null;
54         private List<string> destValueList = null;
55         private List<int> startTimeList = null;
56         private List<int> endTimeList = null;
57
58         /// <summary>
59         /// Creates an initialized animation.<br />
60         /// The animation will not loop.<br />
61         /// The default end action is "Cancel".<br />
62         /// The default alpha function is linear.<br />
63         /// </summary>
64         /// <remarks>DurationmSeconds must be greater than zero.</remarks>
65         /// <param name="durationMilliSeconds">The duration in milliseconds.</param>
66         /// <since_tizen> 3 </since_tizen>
67         public Animation(int durationMilliSeconds) : this(Interop.Animation.New((float)durationMilliSeconds / 1000.0f), true)
68         {
69             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70         }
71
72         internal Animation(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
73         {
74             animationFinishedEventCallback = OnFinished;
75             finishedCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(animationFinishedEventCallback);
76         }
77
78         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
79         private delegate void AnimationFinishedEventCallbackType(IntPtr data);
80
81         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
82         private delegate void AnimationProgressReachedEventCallbackType(IntPtr data);
83
84         private event EventHandler animationFinishedEventHandler;
85
86         /**
87         * @brief Event for the finished signal which can be used to subscribe or unsubscribe the event handler.
88         * The finished signal is emitted when an animation's animations have finished.
89         */
90         /// <since_tizen> 3 </since_tizen>
91         public event EventHandler Finished
92         {
93             add
94             {
95                 if (animationFinishedEventHandler == null && disposed == false)
96                 {
97                     AnimationSignal finishedSignal = FinishedSignal();
98                     finishedSignal.Connect(finishedCallbackOfNative);
99                     finishedSignal.Dispose();
100                 }
101                 animationFinishedEventHandler += value;
102             }
103             remove
104             {
105                 animationFinishedEventHandler -= value;
106
107                 AnimationSignal finishedSignal = FinishedSignal();
108                 if (animationFinishedEventHandler == null && finishedSignal.Empty() == false)
109                 {
110                     finishedSignal.Disconnect(finishedCallbackOfNative);
111                 }
112                 finishedSignal.Dispose();
113             }
114         }
115
116         private event EventHandler animationProgressReachedEventHandler;
117
118         /**
119        * @brief Event for the ProgressReached signal, which can be used to subscribe or unsubscribe the event handler.
120        * The ProgressReached signal is emitted when the animation has reached a given progress percentage, this is set in the api SetProgressNotification.
121        */
122         /// <since_tizen> 3 </since_tizen>
123         public event EventHandler ProgressReached
124         {
125             add
126             {
127                 if (animationProgressReachedEventHandler == null)
128                 {
129                     animationProgressReachedEventCallback = OnProgressReached;
130                     AnimationSignal progressReachedSignal = ProgressReachedSignal();
131                     progressReachedSignal?.Connect(animationProgressReachedEventCallback);
132                     progressReachedSignal?.Dispose();
133                 }
134
135                 animationProgressReachedEventHandler += value;
136             }
137             remove
138             {
139                 animationProgressReachedEventHandler -= value;
140
141                 AnimationSignal progressReachedSignal = ProgressReachedSignal();
142                 if (animationProgressReachedEventHandler == null && progressReachedSignal?.Empty() == false)
143                 {
144                     progressReachedSignal?.Disconnect(animationProgressReachedEventCallback);
145                 }
146                 progressReachedSignal.Dispose();
147             }
148         }
149
150         /// <summary>
151         /// Enumeration for what to do when the animation ends, stopped, or destroyed.
152         /// </summary>
153         /// <since_tizen> 3 </since_tizen>
154         [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names")]
155         public enum EndActions
156         {
157             /// <summary>
158             /// When the animation ends, the animated property values are saved.
159             /// </summary>
160             Cancel,
161             /// <summary>
162             /// When the animation ends, the animated property values are forgotten.
163             /// </summary>
164             Discard,
165             /// <summary>
166             /// If the animation is stopped, the animated property values are saved as if the animation had run to completion, otherwise behaves like cancel.
167             /// </summary>
168             StopFinal
169         }
170
171         /// <summary>
172         /// Enumeration for what interpolation method to use on key-frame animations.
173         /// </summary>
174         /// <since_tizen> 3 </since_tizen>
175         public enum Interpolation
176         {
177             /// <summary>
178             /// Values in between key frames are interpolated using a linear polynomial. (Default)
179             /// </summary>
180             Linear,
181             /// <summary>
182             /// Values in between key frames are interpolated using a cubic polynomial.
183             /// </summary>
184             Cubic
185         }
186
187         /// <summary>
188         /// Enumeration for what state the animation is in.
189         /// </summary>
190         /// <remarks>Calling Reset() on this class will not reset the animation. It will call the BaseHandle.Reset() which drops the object handle.</remarks>
191         /// <since_tizen> 3 </since_tizen>
192         [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names")]
193         public enum States
194         {
195             /// <summary>
196             /// The animation has stopped.
197             /// </summary>
198             Stopped,
199             /// <summary>
200             /// The animation is playing.
201             /// </summary>
202             Playing,
203             /// <summary>
204             /// The animation is paused.
205             /// </summary>
206             Paused
207         }
208
209         /// <summary>
210         /// Gets or sets the duration in milliseconds of the animation.
211         /// </summary>
212         /// <since_tizen> 3 </since_tizen>
213         public int Duration
214         {
215             set
216             {
217                 SetDuration(MilliSecondsToSeconds(value));
218             }
219             get
220             {
221                 return SecondsToMilliSeconds(GetDuration());
222             }
223         }
224
225         /// <summary>
226         ///  Gets or sets the default alpha function for the animation.
227         /// </summary>
228         /// <since_tizen> 3 </since_tizen>
229         public AlphaFunction DefaultAlphaFunction
230         {
231             set
232             {
233                 SetDefaultAlphaFunction(value);
234             }
235             get
236             {
237                 AlphaFunction ret = GetDefaultAlphaFunction();
238                 return ret;
239             }
240         }
241
242         /// <summary>
243         /// Queries the state of the animation.
244         /// </summary>
245         /// <since_tizen> 3 </since_tizen>
246         public States State
247         {
248             get
249             {
250                 return GetState();
251             }
252         }
253
254         /// <summary>
255         /// Set: Enables looping for a specified number of repeats. A zero is the same as Looping = true; i.e., repeat forever.<br />
256         /// This property resets the looping value and should not be used with the Looping property.<br />
257         /// Setting this parameter does not cause the animation to Play().<br />
258         /// Get: Gets the loop count. A zero is the same as Looping = true; i.e., repeat forever.<br />
259         /// The loop count is initially 1 for play once.<br />
260         /// </summary>
261         /// <since_tizen> 3 </since_tizen>
262         public int LoopCount
263         {
264             set
265             {
266                 SetLoopCount(value);
267             }
268             get
269             {
270                 int ret = GetLoopCount();
271                 return ret;
272             }
273         }
274
275         /// <summary>
276         /// Gets or sets the status of whether the animation will loop.<br />
277         /// This property resets the loop count and should not be used with the LoopCount property.<br />
278         /// Setting this parameter does not cause the animation to Play().<br />
279         /// </summary>
280         /// <since_tizen> 3 </since_tizen>
281         public bool Looping
282         {
283             set
284             {
285                 SetLooping(value);
286             }
287             get
288             {
289                 bool ret = IsLooping();
290                 return ret;
291             }
292         }
293
294
295         /// <summary>
296         /// Gets or sets the end action of the animation.<br />
297         /// This action is performed when the animation ends or if it is stopped.<br />
298         /// The default end action is cancel.<br />
299         /// </summary>
300         /// <since_tizen> 3 </since_tizen>
301         public EndActions EndAction
302         {
303             set
304             {
305                 SetEndAction(value);
306             }
307             get
308             {
309                 return GetEndAction();
310             }
311         }
312
313         /// <summary>
314         /// Gets the current loop count.<br />
315         /// A value 0 indicating the current loop count when looping.<br />
316         /// </summary>
317         /// <since_tizen> 3 </since_tizen>
318         public int CurrentLoop
319         {
320             get
321             {
322                 return GetCurrentLoop();
323             }
324         }
325
326         /// <summary>
327         /// Gets or sets the disconnect action.<br />
328         /// If any of the animated property owners are disconnected from the stage while the animation is being played, then this action is performed.<br />
329         /// The default action is cancel.<br />
330         /// </summary>
331         /// <since_tizen> 3 </since_tizen>
332         public EndActions DisconnectAction
333         {
334             set
335             {
336                 Interop.Animation.SetDisconnectAction(SwigCPtr, (int)value);
337                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338             }
339             get
340             {
341                 Animation.EndActions ret = (Animation.EndActions)Interop.Animation.GetDisconnectAction(SwigCPtr);
342                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
343                 return ret;
344             }
345         }
346
347
348         /// <summary>
349         /// Gets or sets the progress of the animation.<br />
350         /// The animation will play (or continue playing) from this point.<br />
351         /// The progress must be in the 0-1 interval or in the play range interval if defined<br />
352         /// otherwise, it will be ignored.<br />
353         /// </summary>
354         /// <since_tizen> 3 </since_tizen>
355         public float CurrentProgress
356         {
357             set
358             {
359                 Interop.Animation.SetCurrentProgress(SwigCPtr, value);
360                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361             }
362             get
363             {
364                 float ret = Interop.Animation.GetCurrentProgress(SwigCPtr);
365                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
366                 return ret;
367             }
368         }
369
370         /// <summary>
371         /// Gets or sets specifications of a speed factor for the animation.<br />
372         /// The speed factor is a multiplier of the normal velocity of the animation.<br />
373         /// Values between [0, 1] will slow down the animation and values above one will speed up the animation.<br />
374         /// It is also possible to specify a negative multiplier to play the animation in reverse.<br />
375         /// </summary>
376         /// <since_tizen> 3 </since_tizen>
377         public float SpeedFactor
378         {
379             set
380             {
381                 Interop.Animation.SetSpeedFactor(SwigCPtr, value);
382                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383             }
384             get
385             {
386                 float ret = Interop.Animation.GetSpeedFactor(SwigCPtr);
387                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
388                 return ret;
389             }
390         }
391
392         /// <summary>
393         /// Gets or sets the playing range.<br />
394         /// Animation will play between the values specified. Both values (range.x and range.y ) should be between 0-1,
395         /// otherwise they will be ignored. If the range provided is not in proper order (minimum, maximum ), it will be reordered.<br />
396         /// </summary>
397         /// <since_tizen> 3 </since_tizen>
398         public RelativeVector2 PlayRange
399         {
400             set
401             {
402                 Interop.Animation.SetPlayRange(SwigCPtr, Vector2.getCPtr(value));
403                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
404             }
405             get
406             {
407                 Vector2 ret = new Vector2(Interop.Animation.GetPlayRange(SwigCPtr), true);
408                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
409                 return ret;
410             }
411         }
412
413
414         /// <summary>
415         /// Gets or sets the progress notification marker which triggers the ProgressReachedSignal.<br />
416         /// Percentage of animation progress should be greater than 0 and less than 1, for example, 0.3 for 30% <br />
417         /// One notification can be set on each animation.
418         /// </summary>
419         /// <since_tizen> 3 </since_tizen>
420         public float ProgressNotification
421         {
422             set
423             {
424                 Interop.Animation.SetProgressNotification(SwigCPtr, value);
425                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
426             }
427             get
428             {
429                 float ret = Interop.Animation.GetProgressNotification(SwigCPtr);
430                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
431                 return ret;
432             }
433         }
434
435         /// <summary>
436         /// Gets or sets the properties of the animation.
437         /// </summary>
438         //ToDo : will raise deprecated-ACR, [Obsolete("Deprecated in API9, Will be removed in API11, Please use PropertyList instead")]
439         [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This API will be deprecated, so suppressing the warning for now")]
440         public string[] Properties
441         {
442             get
443             {
444                 return properties;
445             }
446             set
447             {
448                 properties = value;
449             }
450         }
451
452         /// <summary>
453         /// Gets or sets the destination value for each property of the animation.
454         /// </summary>
455         //ToDo : will raise deprecated-ACR, [Obsolete("Deprecated in API9, Will be removed in API11, Please use DestValueList instead")]
456         [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This API will be deprecated, so suppressing the warning for now")]
457         public string[] DestValue
458         {
459             get
460             {
461                 return destValue;
462             }
463             set
464             {
465                 destValue = value;
466             }
467         }
468
469         /// <summary>
470         /// Gets or sets the start time for each property of the animation.
471         /// </summary>
472         //ToDo : will raise deprecated-ACR, [Obsolete("Deprecated in API9, Will be removed in API11, Please use StartTimeList instead")]
473         [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This API will be deprecated, so suppressing the warning for now")]
474         public int[] StartTime
475         {
476             get
477             {
478                 return startTime;
479             }
480             set
481             {
482                 startTime = value;
483             }
484         }
485
486         /// <summary>
487         /// Gets or sets the end time for each property of the animation.
488         /// </summary>
489         //ToDo : will raise deprecated-ACR, [Obsolete("Deprecated in API9, Will be removed in API11, Please use EndTimeList instead")]
490         [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This API will be deprecated, so suppressing the warning for now")]
491         public int[] EndTime
492         {
493             get
494             {
495                 return endTime;
496             }
497             set
498             {
499                 endTime = value;
500             }
501         }
502
503         /// <summary>
504         /// Get the list of the properties of the animation.
505         /// </summary>
506         [EditorBrowsable(EditorBrowsableState.Never)]
507         public IList<string> PropertyList
508         {
509             get
510             {
511                 if (null == propertyList)
512                 {
513                     propertyList = new List<string>();
514                 }
515
516                 return propertyList;
517             }
518         }
519
520         /// <summary>
521         /// Get the list of the destination value for each property of the animation.
522         /// </summary>
523         [EditorBrowsable(EditorBrowsableState.Never)]
524         public IList<string> DestValueList
525         {
526             get
527             {
528                 if (null == destValueList)
529                 {
530                     destValueList = new List<string>();
531                 }
532
533                 return destValueList;
534             }
535         }
536
537         /// <summary>
538         /// Get the list of the start time for each property of the animation.
539         /// </summary>
540         [EditorBrowsable(EditorBrowsableState.Never)]
541         public IList<int> StartTimeList
542         {
543             get
544             {
545                 if (null == startTimeList)
546                 {
547                     startTimeList = new List<int>();
548                 }
549
550                 return startTimeList;
551             }
552         }
553
554         /// <summary>
555         /// Get the list of end time for each property of the animation.
556         /// </summary>
557         [EditorBrowsable(EditorBrowsableState.Never)]
558         public IList<int> EndTimeList
559         {
560             get
561             {
562                 if (null == endTimeList)
563                 {
564                     endTimeList = new List<int>();
565                 }
566
567                 return endTimeList;
568             }
569         }
570
571         private bool DisableAnimation
572         {
573             get
574             {
575                 if (disableAnimation.HasValue == false)
576                 {
577                     string type = Environment.GetEnvironmentVariable("PlatformSmartType");
578                     if (type == "Entry")
579                         disableAnimation = true;
580                     else
581                         disableAnimation = false;
582                 }
583                 return disableAnimation.Value;
584             }
585         }
586
587         /// <summary>
588         /// Downcasts a handle to animation handle.<br />
589         /// If handle points to an animation object, the downcast produces a valid handle.<br />
590         /// If not, the returned handle is left uninitialized.<br />
591         /// </summary>
592         /// <param name="handle">Handle to an object.</param>
593         /// <returns>Handle to an animation object or an uninitialized handle.</returns>
594         /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
595         internal static Animation DownCast(BaseHandle handle)
596         {
597             if (handle == null)
598             {
599                 throw new ArgumentNullException(nameof(handle));
600             }
601             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Animation;
602             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
603             return ret;
604         }
605
606         /// <summary>
607         /// Stops the animation.
608         /// </summary>
609         /// <param name="action">The end action can be set.</param>
610         /// <since_tizen> 3 </since_tizen>
611         public void Stop(EndActions action = EndActions.Cancel)
612         {
613             SetEndAction(action);
614             Interop.Animation.Stop(SwigCPtr);
615             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
616         }
617
618         /// <summary>
619         /// Animates a property value by a relative amount.<br />
620         /// </summary>
621         /// <param name="target">The target object to animate.</param>
622         /// <param name="property">The target property to animate.</param>
623         /// <param name="relativeValue">The property value will change by this amount.</param>
624         /// <param name="alphaFunction">The alpha function to apply.</param>
625         /// <exception cref="ArgumentNullException"> Thrown when target or property or relativeValue is null. </exception>
626         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given relativeValue is invalid format. </exception>
627         /// <since_tizen> 3 </since_tizen>
628         public void AnimateBy(View target, string property, object relativeValue, AlphaFunction alphaFunction = null)
629         {
630             if (target == null)
631             {
632                 throw new ArgumentNullException(nameof(target));
633             }
634             if (property == null)
635             {
636                 throw new ArgumentNullException(nameof(property));
637             }
638             if (relativeValue == null)
639             {
640                 throw new ArgumentNullException(nameof(relativeValue));
641             }
642
643             using (var result = PropertyHelper.Search(target, property))
644             {
645                 if (result == null)
646                 {
647                     throw new ArgumentException("string property is invalid");
648                 }
649
650                 var current = result;
651                 while (current != null)
652                 {
653                     var targetValue = current.RefineValue(relativeValue) ?? throw new ArgumentException("Invalid " + nameof(relativeValue));
654                     AnimateBy(current.Property, targetValue, alphaFunction);
655                     targetValue.Dispose();
656                     current = current.NextResult;
657                 }
658             }
659         }
660
661         /// <summary>
662         /// Animates a property value by a relative amount.<br />
663         /// </summary>
664         /// <param name="target">The target object to animate.</param>
665         /// <param name="property">The target property to animate.</param>
666         /// <param name="relativeValue">The property value will change by this amount.</param>
667         /// <param name="startTime">The start time of the animation.</param>
668         /// <param name="endTime">The end time of the animation.</param>
669         /// <param name="alphaFunction">The alpha function to apply.</param>
670         /// <exception cref="ArgumentNullException"> Thrown when target or property or relativeValue is null. </exception>
671         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given relativeValue is invalid format. </exception>
672         /// <since_tizen> 3 </since_tizen>
673         public void AnimateBy(View target, string property, object relativeValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
674         {
675             if (target == null)
676             {
677                 throw new ArgumentNullException(nameof(target));
678             }
679             if (property == null)
680             {
681                 throw new ArgumentNullException(nameof(property));
682             }
683             if (relativeValue == null)
684             {
685                 throw new ArgumentNullException(nameof(relativeValue));
686             }
687
688             using (var result = PropertyHelper.Search(target, property))
689             {
690                 if (result == null)
691                 {
692                     throw new ArgumentException("string property is invalid");
693                 }
694
695                 var current = result;
696                 using (var time = new TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime)))
697                     while (current != null)
698                     {
699                         var targetValue = current.RefineValue(relativeValue) ?? throw new ArgumentException("Invalid " + nameof(relativeValue));
700                         AnimateBy(current.Property, targetValue, alphaFunction, time);
701                         targetValue.Dispose();
702                         current = current.NextResult;
703                     }
704             }
705         }
706
707         /// <summary>
708         /// Animates a property to a destination value.<br />
709         /// </summary>
710         /// <param name="target">The target object to animate.</param>
711         /// <param name="property">The target property to animate.</param>
712         /// <param name="destinationValue">The destination value.</param>
713         /// <param name="alphaFunction">The alpha function to apply.</param>
714         /// <exception cref="ArgumentNullException"> Thrown when target or property or destinationValue is null. </exception>
715         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given destinationValue is invalid format. </exception>
716         /// <since_tizen> 3 </since_tizen>
717         public void AnimateTo(View target, string property, object destinationValue, AlphaFunction alphaFunction = null)
718         {
719             if (target == null)
720             {
721                 throw new ArgumentNullException(nameof(target));
722             }
723             if (property == null)
724             {
725                 throw new ArgumentNullException(nameof(property));
726             }
727             if (destinationValue == null)
728             {
729                 throw new ArgumentNullException(nameof(destinationValue));
730             }
731
732             using (var result = PropertyHelper.Search(target, property))
733             {
734                 if (result == null)
735                 {
736                     throw new ArgumentException("string property is invalid");
737                 }
738
739                 var current = result;
740                 while (current != null)
741                 {
742                     var targetValue = current.RefineValue(destinationValue) ?? throw new ArgumentException("Invalid " + nameof(destinationValue));
743                     AnimateTo(current.Property, targetValue, alphaFunction);
744                     targetValue.Dispose();
745                     current = current.NextResult;
746                 }
747             }
748         }
749
750         /// <summary>
751         /// Animates one or more properties to a destination value.<br />
752         /// </summary>
753         /// <param name="target">The target object to animate.</param>
754         /// <exception cref="ArgumentNullException"> Thrown when target is null. </exception>
755         public void PlayAnimateTo(View target)
756         {
757             if (target == null)
758             {
759                 throw new ArgumentNullException(nameof(target));
760             }
761
762             Clear();
763
764             if (null != propertyList && null != destValueList && null != startTimeList && null != endTimeList)
765             {
766                 if (propertyList.Count == destValueList.Count
767                     &&
768                     startTimeList.Count == endTimeList.Count
769                     &&
770                     propertyList.Count == startTimeList.Count)
771                 {
772                     int count = propertyList.Count;
773                     for (int index = 0; index < count; index++)
774                     {
775                         var elementType = target.GetType();
776                         PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == propertyList[index]);
777
778                         if (propertyInfo != null)
779                         {
780                             object destinationValue = ConvertTo(destValueList[index], propertyInfo.PropertyType);
781
782                             if (destinationValue != null)
783                             {
784                                 AnimateTo(target, propertyList[index], destinationValue, startTimeList[index], endTimeList[index]);
785                             }
786                         }
787                     }
788                     Play();
789                 }
790             }
791             else
792             {
793                 if (properties.Length == destValue.Length && startTime.Length == endTime.Length && properties.Length == startTime.Length)
794                 {
795                     int length = properties.Length;
796                     for (int index = 0; index < length; index++)
797                     {
798                         //object destinationValue = _destValue[index];
799                         var elementType = target.GetType();
800                         PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == properties[index]);
801                         //var propertyInfo = elementType.GetRuntimeProperties().FirstOrDefault(p => p.Name == localName);
802                         if (propertyInfo != null)
803                         {
804                             object destinationValue = ConvertTo(destValue[index], propertyInfo.PropertyType);
805
806                             if (destinationValue != null)
807                             {
808                                 AnimateTo(target, properties[index], destinationValue, startTime[index], endTime[index]);
809                             }
810                         }
811                     }
812                     Play();
813                 }
814             }
815         }
816
817         /// <summary>
818         /// Animates a property to a destination value.<br />
819         /// </summary>
820         /// <param name="target">The target object to animate.</param>
821         /// <param name="property">The target property to animate.</param>
822         /// <param name="destinationValue">The destination value.</param>
823         /// <param name="startTime">The start time of the animation.</param>
824         /// <param name="endTime">The end time of the animation.</param>
825         /// <param name="alphaFunction">The alpha function to apply.</param>
826         /// <exception cref="ArgumentNullException"> Thrown when target or property or destinationValue is null. </exception>
827         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given destinationValue is invalid format. </exception>
828         /// <since_tizen> 3 </since_tizen>
829         public void AnimateTo(View target, string property, object destinationValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
830         {
831             if (target == null)
832             {
833                 throw new ArgumentNullException(nameof(target));
834             }
835             if (property == null)
836             {
837                 throw new ArgumentNullException(nameof(property));
838             }
839             if (destinationValue == null)
840             {
841                 throw new ArgumentNullException(nameof(destinationValue));
842             }
843
844             using (var result = PropertyHelper.Search(target, property))
845             {
846                 if (result == null)
847                 {
848                     throw new ArgumentException("string property is invalid");
849                 }
850
851                 var current = result;
852                 using (var time = new TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime)))
853                     while (current != null)
854                     {
855                         var targetValue = current.RefineValue(destinationValue) ?? throw new ArgumentException("Invalid " + nameof(destinationValue));
856                         AnimateTo(current.Property, targetValue, alphaFunction, time);
857                         targetValue.Dispose();
858                         current = current.NextResult;
859                     }
860             }
861         }
862
863         /// <summary>
864         /// Animates a property between keyframes.
865         /// </summary>
866         /// <param name="target">The target object to animate.</param>
867         /// <param name="property">The target property to animate.</param>
868         /// <param name="keyFrames">The set of time or value pairs between which to animate.</param>
869         /// <param name="interpolation">The method used to interpolate between values.</param>
870         /// <param name="alphaFunction">The alpha function to apply.</param>
871         /// <exception cref="ArgumentNullException"> Thrown when target or property or keyFrames is null. </exception>
872         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given keyFrames has invalid value. </exception>
873         /// <since_tizen> 3 </since_tizen>
874         public void AnimateBetween(View target, string property, KeyFrames keyFrames, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
875         {
876             if (target == null)
877             {
878                 throw new ArgumentNullException(nameof(target));
879             }
880             if (property == null)
881             {
882                 throw new ArgumentNullException(nameof(property));
883             }
884             if (keyFrames == null)
885             {
886                 throw new ArgumentNullException(nameof(keyFrames));
887             }
888
889             using (var result = PropertyHelper.Search(target, property))
890             {
891                 if (result == null)
892                 {
893                     throw new ArgumentException("string property is invalid");
894                 }
895
896                 var current = result;
897                 while (current != null)
898                 {
899                     // NOTE Do not dispose keyFrames object returned by GetRefinedKeyFrames() here.
900                     AnimateBetween(current.Property, current.RefineKeyFrames(keyFrames) ?? throw new ArgumentException("Invalid " + nameof(keyFrames)), alphaFunction, interpolation);
901                     current = current.NextResult;
902                 }
903             }
904         }
905
906         /// <summary>
907         /// Animates a property between keyframes.
908         /// </summary>
909         /// <param name="target">The target object to animate</param>
910         /// <param name="property">The target property to animate</param>
911         /// <param name="keyFrames">The set of time/value pairs between which to animate</param>
912         /// <param name="startTime">The start time of animation in milliseconds.</param>
913         /// <param name="endTime">The end time of animation in milliseconds.</param>
914         /// <param name="interpolation">The method used to interpolate between values.</param>
915         /// <param name="alphaFunction">The alpha function to apply.</param>
916         /// <exception cref="ArgumentNullException"> Thrown when target or property or keyFrames is null. </exception>
917         /// <exception cref="ArgumentException"> Thrown when it failed to find a property from given string or the given keyFrames has invalid value. </exception>
918         /// <since_tizen> 3 </since_tizen>
919         public void AnimateBetween(View target, string property, KeyFrames keyFrames, int startTime, int endTime, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
920         {
921             if (target == null)
922             {
923                 throw new ArgumentNullException(nameof(target));
924             }
925             if (property == null)
926             {
927                 throw new ArgumentNullException(nameof(property));
928             }
929             if (keyFrames == null)
930             {
931                 throw new ArgumentNullException(nameof(keyFrames));
932             }
933
934             using (var result = PropertyHelper.Search(target, property))
935             {
936                 if (result == null)
937                 {
938                     throw new ArgumentException("string property is invalid");
939                 }
940
941                 var current = result;
942                 using (var time = new TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime)))
943                     while (current != null)
944                     {
945                         // NOTE Do not dispose keyFrames object returned by GetRefinedKeyFrames() here.
946                         AnimateBetween(current.Property, current.RefineKeyFrames(keyFrames) ?? throw new ArgumentException("Invalid " + nameof(keyFrames)), alphaFunction, time, interpolation);
947                         current = current.NextResult;
948                     }
949             }
950         }
951
952         /// <summary>
953         /// Animates the view's position and orientation through a predefined path.<br />
954         /// The view will rotate to orient the supplied forward vector with the path's tangent.<br />
955         /// If forward is the zero vector then no rotation will happen.<br />
956         /// </summary>
957         /// <param name="view">The view to animate.</param>
958         /// <param name="path">It defines position and orientation.</param>
959         /// <param name="forward">The vector (in local space coordinate system) will be oriented with the path's tangent direction.</param>
960         /// <param name="alphaFunction">The alpha function to apply.</param>
961         /// <since_tizen> 3 </since_tizen>
962         public void AnimatePath(View view, Path path, Vector3 forward, AlphaFunction alphaFunction = null)
963         {
964             if (alphaFunction == null)
965             {
966                 Animate(view, path, forward);
967             }
968             else
969             {
970                 Animate(view, path, forward, alphaFunction);
971             }
972         }
973
974         /// <summary>
975         /// Animates the view's position and orientation through a predefined path.<br />
976         /// The view will rotate to orient the supplied forward vector with the path's tangent.<br />
977         /// If forward is the zero vector then no rotation will happen.<br />
978         /// </summary>
979         /// <param name="view">The view to animate.</param>
980         /// <param name="path">It defines position and orientation.</param>
981         /// <param name="forward">The vector (in local space coordinate system) will be oriented with the path's tangent direction.</param>
982         /// <param name="startTime">The start time of the animation.</param>
983         /// <param name="endTime">The end time of the animation.</param>
984         /// <param name="alphaFunction">The alpha function to apply.</param>
985         /// <since_tizen> 3 </since_tizen>
986         public void AnimatePath(View view, Path path, Vector3 forward, int startTime, int endTime, AlphaFunction alphaFunction = null)
987         {
988             TimePeriod time = new TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime));
989             if (alphaFunction == null)
990             {
991                 Animate(view, path, forward, time);
992             }
993             else
994             {
995                 Animate(view, path, forward, alphaFunction, time);
996             }
997             time.Dispose();
998         }
999
1000         /// <summary>
1001         /// Creates an initialized animation.<br />
1002         /// The animation will not loop.<br />
1003         /// The default end action is "Cancel".<br />
1004         /// The default alpha function is linear.<br />
1005         /// </summary>
1006         /// <since_tizen> 3 </since_tizen>
1007         public Animation() : this(Interop.Animation.New(0.0f), true)
1008         {
1009             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1010         }
1011
1012         /// <summary>
1013         /// Plays the animation.
1014         /// </summary>
1015         /// <since_tizen> 3 </since_tizen>
1016         public void Play()
1017         {
1018             Interop.Animation.Play(SwigCPtr);
1019             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1020
1021             if (DisableAnimation == true)
1022                 Stop(EndActions.StopFinal);
1023         }
1024
1025         /// <summary>
1026         /// Plays the animation from a given point.<br />
1027         /// The progress must be in the 0-1 interval or in the play range interval if defined,
1028         /// otherwise, it will be ignored.<br />
1029         /// </summary>
1030         /// <param name="progress">A value between [0,1], or between the play range if specified, from where the animation should start playing.</param>
1031         /// <since_tizen> 3 </since_tizen>
1032         public void PlayFrom(float progress)
1033         {
1034             Interop.Animation.PlayFrom(SwigCPtr, progress);
1035             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1036         }
1037
1038         /// <summary>
1039         /// Plays the animation after a given delay time.<br/>
1040         /// The delay time is not included in the looping time.<br/>
1041         /// When the delay time is a negative value, it would treat as play immediately.<br/>
1042         /// </summary>
1043         /// <param name="delayMilliseconds">The delay time.</param>
1044         /// <since_tizen> 4 </since_tizen>
1045         public void PlayAfter(int delayMilliseconds)
1046         {
1047             Interop.Animation.PlayAfter(SwigCPtr, MilliSecondsToSeconds(delayMilliseconds));
1048             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1049         }
1050
1051         /// <summary>
1052         /// Pauses the animation.
1053         /// </summary>
1054         /// <since_tizen> 3 </since_tizen>
1055         public void Pause()
1056         {
1057             Interop.Animation.Pause(SwigCPtr);
1058             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1059         }
1060
1061         /// <summary>
1062         /// Stops the animation.
1063         /// </summary>
1064         /// <since_tizen> 3 </since_tizen>
1065         public void Stop()
1066         {
1067             Interop.Animation.Stop(SwigCPtr);
1068             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1069         }
1070
1071         /// <summary>
1072         /// Clears the animation.<br />
1073         /// This disconnects any objects that were being animated, effectively stopping the animation.<br />
1074         /// </summary>
1075         /// <since_tizen> 3 </since_tizen>
1076         public void Clear()
1077         {
1078             Interop.Animation.Clear(SwigCPtr);
1079             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1080         }
1081
1082         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Animation obj)
1083         {
1084             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
1085         }
1086
1087         internal object ConvertTo(object value, Type toType)
1088         {
1089             Func<object> getConverter = () =>
1090             {
1091                 string converterTypeName = GetTypeConverterTypeName(toType.GetTypeInfo().CustomAttributes);
1092                 if (converterTypeName == null)
1093                     return null;
1094
1095                 Type convertertype = Type.GetType(converterTypeName);
1096                 return Activator.CreateInstance(convertertype);
1097             };
1098
1099             return ConvertTo(value, toType, getConverter);
1100         }
1101
1102         internal object ConvertTo(object value, Type toType, Func<object> getConverter)
1103         {
1104             if (value == null)
1105                 return null;
1106
1107             var str = value as string;
1108             if (str != null)
1109             {
1110                 //If there's a [TypeConverter], use it
1111                 object converter = getConverter?.Invoke();
1112                 var xfTypeConverter = converter as Tizen.NUI.Binding.TypeConverter;
1113                 if (xfTypeConverter != null)
1114                     return value = xfTypeConverter.ConvertFromInvariantString(str);
1115                 var converterType = converter?.GetType();
1116                 if (converterType != null)
1117                 {
1118                     var convertFromStringInvariant = converterType.GetRuntimeMethod("ConvertFromInvariantString",
1119                         new[] { typeof(string) });
1120                     if (convertFromStringInvariant != null)
1121                         return value = convertFromStringInvariant.Invoke(converter, new object[] { str });
1122                 }
1123
1124                 //If the type is nullable, as the value is not null, it's safe to assume we want the built-in conversion
1125                 if (toType.GetTypeInfo().IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>))
1126                     toType = Nullable.GetUnderlyingType(toType);
1127
1128                 //Obvious Built-in conversions
1129                 if (toType.GetTypeInfo().IsEnum)
1130                     return Enum.Parse(toType, str, true);
1131                 if (toType == typeof(SByte))
1132                     return SByte.Parse(str, CultureInfo.InvariantCulture);
1133                 if (toType == typeof(Int16))
1134                     return Int16.Parse(str, CultureInfo.InvariantCulture);
1135                 if (toType == typeof(Int32))
1136                     return Int32.Parse(str, CultureInfo.InvariantCulture);
1137                 if (toType == typeof(Int64))
1138                     return Int64.Parse(str, CultureInfo.InvariantCulture);
1139                 if (toType == typeof(Byte))
1140                     return Byte.Parse(str, CultureInfo.InvariantCulture);
1141                 if (toType == typeof(UInt16))
1142                     return UInt16.Parse(str, CultureInfo.InvariantCulture);
1143                 if (toType == typeof(UInt32))
1144                     return UInt32.Parse(str, CultureInfo.InvariantCulture);
1145                 if (toType == typeof(UInt64))
1146                     return UInt64.Parse(str, CultureInfo.InvariantCulture);
1147                 if (toType == typeof(Single))
1148                     return Single.Parse(str, CultureInfo.InvariantCulture);
1149                 if (toType == typeof(Double))
1150                     return Double.Parse(str, CultureInfo.InvariantCulture);
1151                 if (toType == typeof(Boolean))
1152                     return Boolean.Parse(str);
1153                 if (toType == typeof(TimeSpan))
1154                     return TimeSpan.Parse(str, CultureInfo.InvariantCulture);
1155                 if (toType == typeof(DateTime))
1156                     return DateTime.Parse(str, CultureInfo.InvariantCulture);
1157                 if (toType == typeof(Char))
1158                 {
1159                     char c = '\0';
1160                     _ = Char.TryParse(str, out c);
1161                     return c;
1162                 }
1163                 if (toType == typeof(String) && str.StartsWith("{}", StringComparison.Ordinal))
1164                     return str.Substring(2);
1165                 if (toType == typeof(String))
1166                     return value;
1167                 if (toType == typeof(Decimal))
1168                     return Decimal.Parse(str, CultureInfo.InvariantCulture);
1169             }
1170
1171             //if the value is not assignable and there's an implicit conversion, convert
1172             if (value != null && !toType.IsAssignableFrom(value.GetType()))
1173             {
1174                 var opImplicit = GetImplicitConversionOperator(value.GetType(), value.GetType(), toType)
1175                                  ?? GetImplicitConversionOperator(toType, value.GetType(), toType);
1176                 //var opImplicit = value.GetType().GetImplicitConversionOperator(fromType: value.GetType(), toType: toType)
1177                 //                ?? toType.GetImplicitConversionOperator(fromType: value.GetType(), toType: toType);
1178
1179                 if (opImplicit != null)
1180                 {
1181                     value = opImplicit.Invoke(null, new[] { value });
1182                     return value;
1183                 }
1184             }
1185
1186             return value;
1187         }
1188
1189         internal string GetTypeConverterTypeName(IEnumerable<CustomAttributeData> attributes)
1190         {
1191             var converterAttribute =
1192                 attributes.FirstOrDefault(cad => Tizen.NUI.Binding.TypeConverterAttribute.TypeConvertersType.Contains(cad.AttributeType.FullName));
1193             if (converterAttribute == null)
1194                 return null;
1195             if (converterAttribute.ConstructorArguments[0].ArgumentType == typeof(string))
1196                 return (string)converterAttribute.ConstructorArguments[0].Value;
1197             if (converterAttribute.ConstructorArguments[0].ArgumentType == typeof(Type))
1198                 return ((Type)converterAttribute.ConstructorArguments[0].Value).AssemblyQualifiedName;
1199             return null;
1200         }
1201
1202         internal MethodInfo GetImplicitConversionOperator(Type onType, Type fromType, Type toType)
1203         {
1204 #if NETSTANDARD1_0
1205             var mi = onType.GetRuntimeMethod("op_Implicit", new[] { fromType });
1206 #else
1207             var bindingFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy;
1208             var mi = onType.GetMethod("op_Implicit", bindingFlags, null, new[] { fromType }, null);
1209 #endif
1210             if (mi == null) return null;
1211             if (!mi.IsSpecialName) return null;
1212             if (!mi.IsPublic) return null;
1213             if (!mi.IsStatic) return null;
1214             if (!toType.IsAssignableFrom(mi.ReturnType)) return null;
1215
1216             return mi;
1217         }
1218
1219         internal Animation(float durationSeconds) : this(Interop.Animation.New(durationSeconds), true)
1220         {
1221             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1222
1223         }
1224
1225         internal Animation(Animation handle) : this(Interop.Animation.NewAnimation(Animation.getCPtr(handle)), true)
1226         {
1227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1228         }
1229
1230         internal Animation Assign(Animation rhs)
1231         {
1232             Animation ret = new Animation(Interop.Animation.Assign(SwigCPtr, Animation.getCPtr(rhs)), false);
1233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1234             return ret;
1235         }
1236
1237         internal void SetDuration(float seconds)
1238         {
1239             Interop.Animation.SetDuration(SwigCPtr, seconds);
1240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1241         }
1242
1243         internal float GetDuration()
1244         {
1245             float ret = Interop.Animation.GetDuration(SwigCPtr);
1246             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1247             return ret;
1248         }
1249
1250         internal void SetLooping(bool looping)
1251         {
1252             Interop.Animation.SetLooping(SwigCPtr, looping);
1253             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1254         }
1255
1256         internal void SetLoopCount(int count)
1257         {
1258             Interop.Animation.SetLoopCount(SwigCPtr, count);
1259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1260         }
1261
1262         internal int GetLoopCount()
1263         {
1264             int ret = Interop.Animation.GetLoopCount(SwigCPtr);
1265             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1266             return ret;
1267         }
1268
1269         internal int GetCurrentLoop()
1270         {
1271             int ret = Interop.Animation.GetCurrentLoop(SwigCPtr);
1272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1273             return ret;
1274         }
1275
1276         internal bool IsLooping()
1277         {
1278             bool ret = Interop.Animation.IsLooping(SwigCPtr);
1279             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1280             return ret;
1281         }
1282
1283         internal void SetEndAction(Animation.EndActions action)
1284         {
1285             Interop.Animation.SetEndAction(SwigCPtr, (int)action);
1286             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1287         }
1288
1289         internal Animation.EndActions GetEndAction()
1290         {
1291             Animation.EndActions ret = (Animation.EndActions)Interop.Animation.GetEndAction(SwigCPtr);
1292             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1293             return ret;
1294         }
1295
1296         internal void SetDisconnectAction(Animation.EndActions disconnectAction)
1297         {
1298             Interop.Animation.SetDisconnectAction(SwigCPtr, (int)disconnectAction);
1299             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1300         }
1301
1302         internal Animation.EndActions GetDisconnectAction()
1303         {
1304             Animation.EndActions ret = (Animation.EndActions)Interop.Animation.GetDisconnectAction(SwigCPtr);
1305             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1306             return ret;
1307         }
1308
1309         internal void SetDefaultAlphaFunction(AlphaFunction alpha)
1310         {
1311             Interop.Animation.SetDefaultAlphaFunction(SwigCPtr, AlphaFunction.getCPtr(alpha));
1312             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1313         }
1314
1315         internal AlphaFunction GetDefaultAlphaFunction()
1316         {
1317             AlphaFunction ret = new AlphaFunction(Interop.Animation.GetDefaultAlphaFunction(SwigCPtr), true);
1318             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1319             return ret;
1320         }
1321
1322         internal void SetCurrentProgress(float progress)
1323         {
1324             Interop.Animation.SetCurrentProgress(SwigCPtr, progress);
1325             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1326         }
1327
1328         internal float GetCurrentProgress()
1329         {
1330             float ret = Interop.Animation.GetCurrentProgress(SwigCPtr);
1331             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1332             return ret;
1333         }
1334
1335         internal void SetSpeedFactor(float factor)
1336         {
1337             Interop.Animation.SetSpeedFactor(SwigCPtr, factor);
1338             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1339         }
1340
1341         internal float GetSpeedFactor()
1342         {
1343             float ret = Interop.Animation.GetSpeedFactor(SwigCPtr);
1344             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1345             return ret;
1346         }
1347
1348         internal void SetPlayRange(Vector2 range)
1349         {
1350             Interop.Animation.SetPlayRange(SwigCPtr, Vector2.getCPtr(range));
1351             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1352         }
1353
1354         internal Vector2 GetPlayRange()
1355         {
1356             Vector2 ret = new Vector2(Interop.Animation.GetPlayRange(SwigCPtr), true);
1357             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1358             return ret;
1359         }
1360
1361         internal Animation.States GetState()
1362         {
1363             Animation.States ret = (Animation.States)Interop.Animation.GetState(SwigCPtr);
1364             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1365             return ret;
1366         }
1367
1368         internal AnimationSignal FinishedSignal()
1369         {
1370             AnimationSignal ret = new AnimationSignal(Interop.Animation.FinishedSignal(SwigCPtr), false);
1371             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1372             return ret;
1373         }
1374
1375         internal AnimationSignal ProgressReachedSignal()
1376         {
1377             AnimationSignal ret = new AnimationSignal(Interop.Animation.ProgressReachedSignal(SwigCPtr), false);
1378             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1379             return ret;
1380         }
1381
1382         internal void AnimateBy(Property target, PropertyValue relativeValue, AlphaFunction alpha)
1383         {
1384             if (alpha == null)
1385             {
1386                 Interop.Animation.AnimateBy(SwigCPtr, Property.getCPtr(target), PropertyValue.getCPtr(relativeValue));
1387             }
1388             else
1389             {
1390                 Interop.Animation.AnimateByAlphaFunction(SwigCPtr, Property.getCPtr(target), PropertyValue.getCPtr(relativeValue), AlphaFunction.getCPtr(alpha));
1391             }
1392             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1393         }
1394
1395         internal void AnimateBy(Property target, PropertyValue relativeValue, AlphaFunction alpha, TimePeriod period)
1396         {
1397             if (alpha == null)
1398             {
1399                 Interop.Animation.AnimateByTimePeriod(SwigCPtr, Property.getCPtr(target), PropertyValue.getCPtr(relativeValue), TimePeriod.getCPtr(period));
1400             }
1401             else
1402             {
1403                 Interop.Animation.AnimateBy(SwigCPtr, Property.getCPtr(target), PropertyValue.getCPtr(relativeValue), AlphaFunction.getCPtr(alpha), TimePeriod.getCPtr(period));
1404             }
1405             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1406         }
1407
1408         internal void AnimateTo(Property target, PropertyValue destinationValue, AlphaFunction alpha)
1409         {
1410             if (alpha == null)
1411             {
1412                 Interop.Animation.AnimateTo(SwigCPtr, Property.getCPtr(target), PropertyValue.getCPtr(destinationValue));
1413             }
1414             else
1415             {
1416                 Interop.Animation.AnimateToAlphaFunction(SwigCPtr, Property.getCPtr(target), PropertyValue.getCPtr(destinationValue), AlphaFunction.getCPtr(alpha));
1417             }
1418             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1419         }
1420
1421         internal void AnimateTo(Property target, PropertyValue destinationValue, AlphaFunction alpha, TimePeriod period)
1422         {
1423             if (alpha == null)
1424             {
1425                 Interop.Animation.AnimateToTimePeriod(SwigCPtr, Property.getCPtr(target), PropertyValue.getCPtr(destinationValue), TimePeriod.getCPtr(period));
1426             }
1427             else
1428             {
1429                 Interop.Animation.AnimateTo(SwigCPtr, Property.getCPtr(target), PropertyValue.getCPtr(destinationValue), AlphaFunction.getCPtr(alpha), TimePeriod.getCPtr(period));
1430             }
1431             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1432         }
1433
1434         internal void AnimateBetween(Property target, KeyFrames keyFrames)
1435         {
1436             Interop.Animation.AnimateBetween(SwigCPtr, Property.getCPtr(target), KeyFrames.getCPtr(keyFrames));
1437             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1438         }
1439
1440         internal void AnimateBetween(Property target, KeyFrames keyFrames, AlphaFunction alpha)
1441         {
1442             Interop.Animation.AnimateBetweenAlphaFunction(SwigCPtr, Property.getCPtr(target), KeyFrames.getCPtr(keyFrames), AlphaFunction.getCPtr(alpha));
1443             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1444         }
1445
1446         internal void AnimateBetween(Property target, KeyFrames keyFrames, AlphaFunction alpha, Animation.Interpolation interpolation)
1447         {
1448             if (alpha == null)
1449             {
1450                 Interop.Animation.AnimateBetween(SwigCPtr, Property.getCPtr(target), KeyFrames.getCPtr(keyFrames), (int)interpolation);
1451             }
1452             else
1453             {
1454                 Interop.Animation.AnimateBetweenAlphaFunctionInterpolation(SwigCPtr, Property.getCPtr(target), KeyFrames.getCPtr(keyFrames), AlphaFunction.getCPtr(alpha), (int)interpolation);
1455             }
1456             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1457         }
1458
1459         internal void AnimateBetween(Property target, KeyFrames keyFrames, TimePeriod period)
1460         {
1461             Interop.Animation.AnimateBetweenTimePeriod(SwigCPtr, Property.getCPtr(target), KeyFrames.getCPtr(keyFrames), TimePeriod.getCPtr(period));
1462             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1463         }
1464
1465         internal void AnimateBetween(Property target, KeyFrames keyFrames, AlphaFunction alpha, TimePeriod period)
1466         {
1467             Interop.Animation.AnimateBetween(SwigCPtr, Property.getCPtr(target), KeyFrames.getCPtr(keyFrames), AlphaFunction.getCPtr(alpha), TimePeriod.getCPtr(period));
1468             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1469         }
1470
1471         internal void AnimateBetween(Property target, KeyFrames keyFrames, AlphaFunction alpha, TimePeriod period, Animation.Interpolation interpolation)
1472         {
1473             if (alpha == null)
1474             {
1475                 Interop.Animation.AnimateBetweenTimePeriodInterpolation(SwigCPtr, Property.getCPtr(target), KeyFrames.getCPtr(keyFrames), TimePeriod.getCPtr(period), (int)interpolation);
1476             }
1477             else
1478             {
1479                 Interop.Animation.AnimateBetween(SwigCPtr, Property.getCPtr(target), KeyFrames.getCPtr(keyFrames), AlphaFunction.getCPtr(alpha), TimePeriod.getCPtr(period), (int)interpolation);
1480             }
1481             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1482         }
1483
1484         internal void Animate(View view, Path path, Vector3 forward)
1485         {
1486             Interop.Animation.Animate(SwigCPtr, View.getCPtr(view), Path.getCPtr(path), Vector3.getCPtr(forward));
1487             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1488         }
1489
1490         internal void Animate(View view, Path path, Vector3 forward, AlphaFunction alpha)
1491         {
1492             Interop.Animation.AnimateAlphaFunction(SwigCPtr, View.getCPtr(view), Path.getCPtr(path), Vector3.getCPtr(forward), AlphaFunction.getCPtr(alpha));
1493             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1494         }
1495
1496         internal void Animate(View view, Path path, Vector3 forward, TimePeriod period)
1497         {
1498             Interop.Animation.AnimateTimePeriod(SwigCPtr, View.getCPtr(view), Path.getCPtr(path), Vector3.getCPtr(forward), TimePeriod.getCPtr(period));
1499             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1500         }
1501
1502         internal void Animate(View view, Path path, Vector3 forward, AlphaFunction alpha, TimePeriod period)
1503         {
1504             Interop.Animation.Animate(SwigCPtr, View.getCPtr(view), Path.getCPtr(path), Vector3.getCPtr(forward), AlphaFunction.getCPtr(alpha), TimePeriod.getCPtr(period));
1505             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1506         }
1507
1508         internal void Show(View view, float delaySeconds)
1509         {
1510             Interop.Animation.Show(SwigCPtr, View.getCPtr(view), delaySeconds);
1511             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1512         }
1513
1514         internal void Hide(View view, float delaySeconds)
1515         {
1516             Interop.Animation.Hide(SwigCPtr, View.getCPtr(view), delaySeconds);
1517             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1518         }
1519
1520         /// <summary>
1521         /// To make animation instance be disposed.
1522         /// </summary>
1523         /// <since_tizen> 3 </since_tizen>
1524         protected override void Dispose(DisposeTypes type)
1525         {
1526             if (disposed)
1527             {
1528                 return;
1529             }
1530
1531             if (animationFinishedEventHandler != null)
1532             {
1533                 AnimationSignal finishedSignal = FinishedSignal();
1534                 finishedSignal?.Disconnect(finishedCallbackOfNative);
1535                 finishedSignal?.Dispose();
1536                 animationFinishedEventHandler = null;
1537             }
1538
1539             if (animationProgressReachedEventCallback != null)
1540             {
1541                 AnimationSignal progressReachedSignal = ProgressReachedSignal();
1542                 progressReachedSignal?.Disconnect(animationProgressReachedEventCallback);
1543                 progressReachedSignal?.Dispose();
1544                 animationProgressReachedEventCallback = null;
1545             }
1546
1547             base.Dispose(type);
1548         }
1549
1550         /// This will not be public opened.
1551         [EditorBrowsable(EditorBrowsableState.Never)]
1552         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1553         {
1554             if (swigCPtr.Handle == IntPtr.Zero || this.HasBody() == false)
1555             {
1556                 Tizen.Log.Fatal("NUI", $"[ERROR] Animation ReleaseSwigCPtr()! IntPtr=0x{swigCPtr.Handle:X} HasBody={this.HasBody()}");
1557                 return;
1558             }
1559             Interop.Animation.DeleteAnimation(swigCPtr);
1560         }
1561
1562         private void OnFinished(IntPtr data)
1563         {
1564             if (animationFinishedEventHandler != null)
1565             {
1566                 //here we send all data to user event handlers
1567                 animationFinishedEventHandler(this, null);
1568             }
1569         }
1570
1571         private void OnProgressReached(IntPtr data)
1572         {
1573             if (animationProgressReachedEventHandler != null)
1574             {
1575                 //here we send all data to user event handlers
1576                 animationProgressReachedEventHandler(this, null);
1577             }
1578         }
1579
1580         private float MilliSecondsToSeconds(int millisec)
1581         {
1582             return (float)millisec / 1000.0f;
1583         }
1584
1585         private int SecondsToMilliSeconds(float sec)
1586         {
1587             return (int)(sec * 1000);
1588         }
1589     }
1590 }