[NUI] Revert patch about StyleManager (#1970)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / LottieAnimationView.cs
index e12f6bc..7e9ebb3 100755 (executable)
@@ -20,12 +20,12 @@ using global::System.Runtime.InteropServices;
 using System.ComponentModel;
 using System.Collections.Generic;
 
-#if (NUI_DEBUG_ON)
-using tlog = Tizen.Log;
-#endif
-
 namespace Tizen.NUI.BaseComponents
 {
+    #if (NUI_DEBUG_ON)
+    using tlog = Tizen.Log;
+    #endif
+
     /// <summary>
     /// LottieAnimationView renders an animated vector image (Lottie file).
     /// </summary>
@@ -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
@@ -172,17 +172,19 @@ namespace Tizen.NUI.BaseComponents
                         {
                             currentStates.playState = (PlayStateType)ret;
                             tlog.Fatal(tag, $"gotten play state={ret} >");
-                            return currentStates.playState;
                         }
                     }
                 }
-                Tizen.Log.Error(tag, $"<[ERROR][{GetId()}]Fail to get PlayState from dali currentStates.playState={currentStates.playState}>");
+                else
+                {
+                    Tizen.Log.Error(tag, $"<[ERROR][{GetId()}]Fail to get PlayState from dali currentStates.playState={currentStates.playState}>");
+                }
                 return currentStates.playState;
             }
         }
 
         /// <summary>
-        /// Get the number of total frame
+        /// Get the number of total frames
         /// </summary>
         /// <since_tizen> 7 </since_tizen>
         public int TotalFrame
@@ -210,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
@@ -234,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
             {
@@ -258,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
@@ -271,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
             {
@@ -301,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
@@ -328,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
             {
@@ -358,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
@@ -371,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
             {
@@ -404,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>
@@ -423,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})>");
         }
 
@@ -464,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>
@@ -485,6 +487,7 @@ namespace Tizen.NUI.BaseComponents
                 {
                     if (val.Get(contentMap))
                     {
+                        currentStates.contentInfo = new List<Tuple<string, int, int>>();
                         for (uint i = 0; i < contentMap.Count(); i++)
                         {
                             string key = contentMap.GetKeyAt(i).StringKey;
@@ -536,9 +539,60 @@ 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} >");
         }
+
+        /// <summary>
+        /// Get MinMax Frame
+        /// </summary>
+        /// <returns>Tuple of Min and Max frames</returns>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Tuple<int, int> GetMinMaxFrame()
+        {
+            tlog.Fatal(tag, $"< [{GetId()}] GetMinMaxFrame()! total frame={currentStates.totalFrame}");
+
+            PropertyMap map = Image;
+            if (map != null)
+            {
+                PropertyValue val = map.Find(ImageVisualProperty.PlayRange);
+                if (val != null)
+                {
+                    PropertyArray array = new PropertyArray();
+                    if (val.Get(array))
+                    {
+                        uint cnt = array.Count();
+                        int item1 = -1, item2 = -1;
+                        for (uint i = 0; i < cnt; i++)
+                        {
+                            PropertyValue v = array.GetElementAt(i);
+                            int intRet;
+                            if (v.Get(out intRet))
+                            {
+                                tlog.Fatal(tag, $"Got play range of string [{i}]: {intRet}");
+                                if (i == 0)
+                                {
+                                    item1 = intRet;
+                                }
+                                else if (i == 1)
+                                {
+                                    item2 = intRet;
+                                }
+                            }
+                            else
+                            {
+                                Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#1");
+                            }
+                        }
+                        tlog.Fatal(tag, $"  [{GetId()}] GetMinMaxFrame(min:{item1}, max:{item2})! >");
+                        return new Tuple<int, int>(item1, item2);
+                    }
+                }
+            }
+            Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#2");
+            return new Tuple<int, int>(-1, -1);
+        }
         #endregion Method
 
 
@@ -729,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()
@@ -777,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