[NUI] Revert patch about StyleManager (#1970)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / LottieAnimationView.cs
index a38a43b..7e9ebb3 100755 (executable)
@@ -39,7 +39,7 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="scale">The factor of scaling image, default : 1.0f</param>
         /// <param name="shown">false : not displayed (hidden), true : displayed (shown), default : true</param>
         /// <remarks>
-        /// If shown parameter is false, it is not visible even the LottieAnimationView instance is created.
+        /// If the shown parameter is false, the animation is not visible even if the LottieAnimationView instance is created.
         /// </remarks>
         /// <example>
         /// <code>
@@ -153,7 +153,7 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// Get playing state
+        /// Gets the playing state
         /// </summary>
         /// <since_tizen> 7 </since_tizen>
         public PlayStateType PlayState
@@ -184,7 +184,7 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// Get the number of total frame
+        /// Get the number of total frames
         /// </summary>
         /// <since_tizen> 7 </since_tizen>
         public int TotalFrame
@@ -212,17 +212,17 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// Set or Get current frame. When setting a specific frame, it is displayed as a still image.
+        /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
         /// </summary>
         /// <remarks>
-        /// Giving user set value when getting. If the out ranged frame is set, it is reset as minimum frame or maximum frame.
+        /// Gets the value set by a user. If the setting value is out-ranged, it is reset as a minimum frame or a maximum frame.
         /// </remarks>
         /// <example>
-        /// Let's say myLottie.json file has 100 frames originally, then it will have 0 ~ 99 range of frame index.
+        /// We assume that the animation in myLottie.json file has 100 frames originally. If so, its frame index will be 0 - 99.
         /// <code>
         /// LottieAnimationView myLottie = new LottieAnimationView();
         /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
-        /// Window.Instance.GetDefaultLayer().Add(myLottie);
+        /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
         /// myLottie.CurrentFrame = 200; //display 99 frame
         /// myLottie.SetMinMaxFrame(10, 20);
         /// myLottie.CurrentFrame = 15; //display 15 frame
@@ -236,7 +236,7 @@ namespace Tizen.NUI.BaseComponents
             {
                 currentStates.frame = value;
                 tlog.Fatal(tag, $"<[{GetId()}]SET frame={currentStates.frame}>");
-                DoAction(vectorImageVisualIndex, (int)actionType.jumpTo, new PropertyValue(currentStates.frame));
+                DoAction(ImageView.Property.IMAGE, (int)actionType.jumpTo, new PropertyValue(currentStates.frame));
             }
             get
             {
@@ -260,7 +260,7 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// Set or Get looping mode of Lottie animation.
+        /// Sets or gets the looping mode of Lottie animation.
         /// </summary>
         /// <since_tizen> 7 </since_tizen>
         public LoopingModeType LoopingMode
@@ -273,7 +273,7 @@ namespace Tizen.NUI.BaseComponents
                 tlog.Fatal(tag, $"<[{GetId()}] SET loopMode={currentStates.loopMode}>");
                 PropertyMap map = new PropertyMap();
                 map.Add(ImageVisualProperty.LoopingMode, new PropertyValue((int)currentStates.loopMode));
-                DoAction(vectorImageVisualIndex, (int)actionType.updateProperty, new PropertyValue(map));
+                DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
             }
             get
             {
@@ -303,16 +303,16 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// Set or Get loop count. 
+        /// Sets or gets the loop count. 
         /// </summary>
         /// <remarks>
-        /// Minus value means infinite loop count.
+        /// The minus value means the infinite loop count.
         /// </remarks>
         /// <example>
         /// <code>
         /// LottieAnimationView myLottie = new LottieAnimationView();
         /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
-        /// Window.Instance.GetDefaultLayer().Add(myLottie);
+        /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
         /// myLottie.LoopCount = -1; //infinite loop
         /// myLottie.Play();
         /// myLottie.Stop(); //it plays continuously unless Stop() is called
@@ -330,7 +330,7 @@ namespace Tizen.NUI.BaseComponents
                 tlog.Fatal(tag, $"<[{GetId()}]SET currentStates.loopCount={currentStates.loopCount}>");
                 PropertyMap map = new PropertyMap();
                 map.Add(ImageVisualProperty.LoopCount, new PropertyValue(currentStates.loopCount));
-                DoAction(vectorImageVisualIndex, (int)actionType.updateProperty, new PropertyValue(map));
+                DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
             }
             get
             {
@@ -360,7 +360,7 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// Set or Get stop behavior.
+        /// Sets or gets the stop behavior.
         /// </summary>
         /// <since_tizen> 7 </since_tizen>
         public StopBehaviorType StopBehavior
@@ -373,7 +373,7 @@ namespace Tizen.NUI.BaseComponents
                 tlog.Fatal(tag, $"<[{GetId()}]SET val={currentStates.stopEndAction}>");
                 PropertyMap map = new PropertyMap();
                 map.Add(ImageVisualProperty.StopBehavior, new PropertyValue((int)currentStates.stopEndAction));
-                DoAction(vectorImageVisualIndex, (int)actionType.updateProperty, new PropertyValue(map));
+                DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
             }
             get
             {
@@ -406,7 +406,7 @@ namespace Tizen.NUI.BaseComponents
 
         #region Method
         /// <summary>
-        /// Set minimum and maximum frame.
+        /// Set the minimum and the maximum frame.
         /// </summary>
         /// <param name="minFrame">minimum frame</param>
         /// <param name="maxFrame">maximum frame</param>
@@ -425,7 +425,7 @@ namespace Tizen.NUI.BaseComponents
 
             PropertyMap map = new PropertyMap();
             map.Add(ImageVisualProperty.PlayRange, new PropertyValue(array));
-            DoAction(vectorImageVisualIndex, (int)actionType.updateProperty, new PropertyValue(map));
+            DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
             tlog.Fatal(tag, $"  [{GetId()}] currentStates.min:({currentStates.framePlayRangeMin}, max:{currentStates.framePlayRangeMax})>");
         }
 
@@ -466,7 +466,7 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// Get the list of layers' information (start frame, end frame) in Lottie file.
+        /// Get the list of layers' information such as the start frame and the end frame in the Lottie file.
         /// </summary>
         /// <returns>List of Tuple (string of layer name, integer of start frame, integer of end frame)</returns>
         /// <since_tizen> 7 </since_tizen>
@@ -539,7 +539,7 @@ namespace Tizen.NUI.BaseComponents
 
             PropertyMap map = new PropertyMap();
             map.Add(ImageVisualProperty.PlayRange, new PropertyValue(array));
-            DoAction(vectorImageVisualIndex, (int)actionType.updateProperty, new PropertyValue(map));
+            DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
             tlog.Fatal(tag, $"  [{GetId()}] currentStates.mark1:{currentStates.mark1}, mark2:{currentStates.mark2} >");
         }
 
@@ -783,7 +783,6 @@ namespace Tizen.NUI.BaseComponents
         }
 
         private const string tag = "NUITEST";
-        private const int vectorImageVisualIndex = 10000000 + 1000 + 2;
         private event EventHandler finishedEventHandler;
 
         private void OnFinished()
@@ -831,4 +830,131 @@ namespace Tizen.NUI.BaseComponents
         }
         #endregion Private
     }
+
+    /// <summary>
+    /// A class containing frame informations for a LottieAnimationView.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class LottieFrameInfo
+    {
+        /// <summary>
+        /// Creates a new instance with a playing range.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public LottieFrameInfo(int startFrame, int endFrame)
+        {
+            StartFrame = startFrame;
+            EndFrame = endFrame;
+        }
+
+        /// <summary>
+        /// Creates a new instance with a still image frame.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public LottieFrameInfo(int stillImageFrame) : this(stillImageFrame, stillImageFrame)
+        {
+        }
+
+        /// <summary>
+        /// Create a new instance from a pair notation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static implicit operator LottieFrameInfo((int, int) pair)
+        {
+            return new LottieFrameInfo(pair.Item1, pair.Item2);
+        }
+
+        /// <summary>
+        /// Create a new instance from an int value.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static implicit operator LottieFrameInfo(int stillImageFrame)
+        {
+            return new LottieFrameInfo(stillImageFrame);
+        }
+
+        /// <summary>
+        /// The start frame of the lottie animation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int StartFrame { get; }
+
+        /// <summary>
+        /// The end frame of the lottie animation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int EndFrame { get; }
+
+        /// <summary>
+        /// Create LottieFrameInfo struct with animation range information
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static LottieFrameInfo CreateAnimationRange(int startFrame, int endFrame)
+        {
+            return new LottieFrameInfo(startFrame, endFrame);
+        }
+
+        /// <summary>
+        /// Create LottieFrameInfo struct with still image information
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static LottieFrameInfo CreateStillImage(int stillImageFrame)
+        {
+            return new LottieFrameInfo(stillImageFrame, stillImageFrame);
+        }
+
+        /// <summary>
+        /// Inhouse API.
+        /// Whether this LottieFrameInfo represents one frame or more.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool IsStillImage()
+        {
+            return StartFrame == EndFrame;
+        }
+
+        /// <summary>
+        /// Inhouse API.
+        /// Play specified LottieAnimationView with this frame information.
+        /// </summary>
+        /// <param name="lottieView">The target LottieAnimationView to play.</param>
+        /// <param name="noPlay">Whether go direct to the EndFrame. It is false by default.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Show(LottieAnimationView lottieView, bool noPlay = false)
+        {
+            if (!BeReadyToShow(lottieView))
+            {
+                return;
+            }
+
+            lottieView.SetMinMaxFrame(StartFrame, Math.Min(EndFrame, lottieView.TotalFrame - 1));
+
+            if (IsStillImage() || noPlay)
+            {
+                lottieView.CurrentFrame = EndFrame;
+            }
+            else
+            {
+                lottieView.CurrentFrame = StartFrame;
+                lottieView.Play();
+            }
+        }
+
+        private bool BeReadyToShow(LottieAnimationView lottieView)
+        {
+            // Validate input lottieView
+            if (null== lottieView || lottieView.PlayState == LottieAnimationView.PlayStateType.Invalid)
+            {
+                return false;
+            }
+
+            // Stop if it was playing
+            if (lottieView.PlayState == LottieAnimationView.PlayStateType.Playing)
+            {
+                lottieView.Stop();
+            }
+
+            return true;
+        }
+    }
 }
\ No newline at end of file