2 * Copyright(c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using global::System.Runtime.InteropServices;
20 using System.ComponentModel;
21 using System.Collections.Generic;
22 using System.Globalization;
24 namespace Tizen.NUI.BaseComponents
27 using tlog = Tizen.Log;
31 /// LottieAnimationView renders an animated vector image (Lottie file).
33 /// <since_tizen> 7 </since_tizen>
34 public class LottieAnimationView : ImageView
36 #region Constructor, Destructor, Dispose
38 /// LottieAnimationView constructor
40 /// <param name="scale">The factor of scaling image, default : 1.0f</param>
41 /// <param name="shown">false : not displayed (hidden), true : displayed (shown), default : true</param>
43 /// If the shown parameter is false, the animation is not visible even if the LottieAnimationView instance is created.
47 /// LottieAnimationView myLottie = new LottieAnimationView();
48 /// LottieAnimationView myLottie2 = new LottieAnimationView(2.0f);
49 /// LottieAnimationView myLottie3 = new LottieAnimationView(1.0f, false);
52 /// <since_tizen> 7 </since_tizen>
53 public LottieAnimationView(float scale = 1.0f, bool shown = true) : base()
55 tlog.Fatal(tag, $"< constructor GetId={GetId()} >");
56 currentStates.url = "";
57 currentStates.frame = -1;
58 currentStates.loopCount = 1;
59 currentStates.loopMode = LoopingModeType.Restart;
60 currentStates.stopEndAction = StopBehaviorType.CurrentFrame;
61 currentStates.framePlayRangeMin = -1;
62 currentStates.framePlayRangeMax = -1;
63 currentStates.changed = false;
64 currentStates.totalFrame = -1;
65 currentStates.scale = scale;
66 currentStates.redrawInScalingDown = true;
71 /// Dispose(DisposeTypes type)
73 /// <param name="type"></param>
74 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
75 [EditorBrowsable(EditorBrowsableState.Never)]
76 protected override void Dispose(DisposeTypes type)
83 tlog.Fatal(tag, $"<[{GetId()}] type={type}");
85 //Release your own unmanaged resources here.
86 //You should not access any managed member here except static instance.
87 //because the execution order of Finalizes is non-deterministic.
89 //disconnect event signal
90 if (finishedEventHandler != null && visualEventSignalCallback != null)
92 VisualEventSignal().Disconnect(visualEventSignalCallback);
93 finishedEventHandler = null;
94 tlog.Fatal(tag, $"disconnect event signal");
98 tlog.Fatal(tag, $"[{GetId()}]>");
100 #endregion Constructor, Destructor, Dispose
105 /// Set or Get resource URL of Lottie file.
107 /// <since_tizen> 7 </since_tizen>
112 string ret = (value == null ? "" : value);
113 currentStates.url = ret;
114 currentStates.changed = true;
116 tlog.Fatal(tag, $"<[{GetId()}]SET url={currentStates.url}");
118 PropertyMap map = new PropertyMap();
119 map.Add(Visual.Property.Type, new PropertyValue((int)DevelVisual.Type.AnimatedVectorImage))
120 .Add(ImageVisualProperty.URL, new PropertyValue(currentStates.url))
121 .Add(ImageVisualProperty.LoopCount, new PropertyValue(currentStates.loopCount))
122 .Add(ImageVisualProperty.StopBehavior, new PropertyValue((int)currentStates.stopEndAction))
123 .Add(ImageVisualProperty.LoopingMode, new PropertyValue((int)currentStates.loopMode));
126 currentStates.contentInfo = null;
128 if (currentStates.scale != 1.0f)
130 Scale = new Vector3(currentStates.scale, currentStates.scale, 0.0f);
132 tlog.Fatal(tag, $"<[{GetId()}]>");
136 string ret = currentStates.url;
137 tlog.Fatal(tag, $"<[{GetId()}] GET");
139 PropertyMap map = Image;
142 PropertyValue val = map.Find(ImageVisualProperty.URL);
145 if (val.Get(out ret))
147 tlog.Fatal(tag, $"gotten url={ret} >");
152 Tizen.Log.Error(tag, $" [ERROR][{GetId()}](LottieAnimationView) Fail to get URL from dali >");
158 /// Gets the playing state
160 /// <since_tizen> 7 </since_tizen>
161 public PlayStateType PlayState
165 tlog.Fatal(tag, $"< Get!");
166 PropertyMap map = base.Image;
170 PropertyValue val = map.Find(ImageVisualProperty.PlayState);
173 if (val.Get(out ret))
175 currentStates.playState = (PlayStateType)ret;
176 tlog.Fatal(tag, $"gotten play state={ret} >");
182 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}]Fail to get PlayState from dali currentStates.playState={currentStates.playState}>");
184 return currentStates.playState;
189 /// Get the number of total frames
191 /// <since_tizen> 7 </since_tizen>
192 public int TotalFrame
197 PropertyMap map = Image;
200 PropertyValue val = map.Find(ImageVisualProperty.TotalFrameNumber);
203 if (val.Get(out ret))
205 //tlog.Fatal(tag, $"TotalFrameNumber get! ret={ret}");
206 currentStates.totalFrame = ret;
211 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get TotalFrameNumber from dali>");
217 /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
220 /// 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.
223 /// We assume that the animation in myLottie.json file has 100 frames originally. If so, its frame index will be 0 - 99.
225 /// LottieAnimationView myLottie = new LottieAnimationView();
226 /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
227 /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
228 /// myLottie.CurrentFrame = 200; //display 99 frame
229 /// myLottie.SetMinMaxFrame(10, 20);
230 /// myLottie.CurrentFrame = 15; //display 15 frame
231 /// myLottie.CurrentFrame = 50; //display 20 frame, because the MinMax is set (10,20) above
234 /// <since_tizen> 7 </since_tizen>
235 public int CurrentFrame
239 currentStates.frame = value;
240 tlog.Fatal(tag, $"<[{GetId()}]SET frame={currentStates.frame}>");
241 DoAction(ImageView.Property.IMAGE, (int)actionType.jumpTo, new PropertyValue(currentStates.frame));
246 PropertyMap map = Image;
249 PropertyValue val = map.Find(ImageVisualProperty.CurrentFrameNumber);
252 if (val.Get(out ret))
254 //tlog.Fatal(tag, $"CurrentFrameNumber get! val={ret}");
259 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get CurrentFrameNumber from dali!! ret={ret}>");
265 /// Sets or gets the looping mode of Lottie animation.
267 /// <since_tizen> 7 </since_tizen>
268 public LoopingModeType LoopingMode
272 currentStates.loopMode = (LoopingModeType)value;
273 currentStates.changed = true;
275 tlog.Fatal(tag, $"<[{GetId()}] SET loopMode={currentStates.loopMode}>");
276 PropertyMap map = new PropertyMap();
277 map.Add(ImageVisualProperty.LoopingMode, new PropertyValue((int)currentStates.loopMode));
278 DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
282 //tlog.Fatal(tag, $"LoopMode get!");
283 PropertyMap map = base.Image;
287 PropertyValue val = map.Find(ImageVisualProperty.LoopingMode);
290 if (val.Get(out ret))
292 //tlog.Fatal(tag, $"gotten LoopMode={ret}");
293 if (ret != (int)currentStates.loopMode && ret > 0)
295 tlog.Fatal(tag, $" [ERROR][{GetId()}](LottieAnimationView) different LoopMode! gotten={ret}, loopMode={currentStates.loopMode}");
297 currentStates.loopMode = (LoopingModeType)ret;
298 return (LoopingModeType)ret;
302 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get loopMode from dali>");
303 return currentStates.loopMode;
308 /// Sets or gets the loop count.
311 /// The minus value means the infinite loop count.
315 /// LottieAnimationView myLottie = new LottieAnimationView();
316 /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
317 /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
318 /// myLottie.LoopCount = -1; //infinite loop
320 /// myLottie.Stop(); //it plays continuously unless Stop() is called
321 /// myLottie.LoopCount = 2;
322 /// myLottie.Play(); //it plays only 2 times and stops automatically
325 /// <since_tizen> 7 </since_tizen>
330 currentStates.changed = true;
331 currentStates.loopCount = value;
332 tlog.Fatal(tag, $"<[{GetId()}]SET currentStates.loopCount={currentStates.loopCount}>");
333 PropertyMap map = new PropertyMap();
334 map.Add(ImageVisualProperty.LoopCount, new PropertyValue(currentStates.loopCount));
335 DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
339 //tlog.Fatal(tag, $"LoopCount get!");
340 PropertyMap map = base.Image;
344 PropertyValue val = map.Find(ImageVisualProperty.LoopCount);
347 if (val.Get(out ret))
349 //tlog.Fatal(tag, $"gotten loop count={ret}");
350 if (ret != currentStates.loopCount && ret > 0)
352 tlog.Fatal(tag, $"<[ERROR][{GetId()}](LottieAnimationView) different loop count! gotten={ret}, loopCount={currentStates.loopCount}>");
354 currentStates.loopCount = ret;
355 return currentStates.loopCount;
359 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get LoopCount from dali currentStates.loopCount={currentStates.loopCount}>");
360 return currentStates.loopCount;
365 /// Sets or gets the stop behavior.
367 /// <since_tizen> 7 </since_tizen>
368 public StopBehaviorType StopBehavior
372 currentStates.stopEndAction = (StopBehaviorType)value;
373 currentStates.changed = true;
375 tlog.Fatal(tag, $"<[{GetId()}]SET val={currentStates.stopEndAction}>");
376 PropertyMap map = new PropertyMap();
377 map.Add(ImageVisualProperty.StopBehavior, new PropertyValue((int)currentStates.stopEndAction));
378 DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
382 //tlog.Fatal(tag, $"StopBehavior get!");
383 PropertyMap map = base.Image;
387 PropertyValue val = map.Find(ImageVisualProperty.StopBehavior);
390 if (val.Get(out ret))
392 //tlog.Fatal(tag, $"gotten StopBehavior={ret}");
393 if (ret != (int)currentStates.stopEndAction)
395 tlog.Fatal(tag, $"<[ERROR][{GetId()}](LottieAnimationView) different StopBehavior! gotten={ret}, StopBehavior={currentStates.stopEndAction}>");
397 currentStates.stopEndAction = (StopBehaviorType)ret;
398 return (StopBehaviorType)ret;
402 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get StopBehavior from dali>");
403 return currentStates.stopEndAction;
408 /// Whether to redraw the image when the visual is scaled down.
412 /// It is used in the AnimatedVectorImageVisual.The default is true.
414 [EditorBrowsable(EditorBrowsableState.Never)]
415 public bool RedrawInScalingDown
419 currentStates.changed = true;
420 currentStates.redrawInScalingDown = value;
421 tlog.Fatal(tag, $"<[{GetId()}]SET currentStates.redrawInScalingDown={currentStates.redrawInScalingDown}>");
422 PropertyMap map = new PropertyMap();
423 map.Add(ImageVisualProperty.RedrawInScalingDown, new PropertyValue(currentStates.redrawInScalingDown));
424 DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
428 PropertyMap map = base.Image;
432 PropertyValue val = map.Find(ImageVisualProperty.RedrawInScalingDown);
435 if (val.Get(out ret))
437 if (ret != currentStates.redrawInScalingDown)
439 tlog.Fatal(tag, $"<[ERROR][{GetId()}](LottieAnimationView) different redrawInScalingDown! gotten={ret}, redrawInScalingDown={currentStates.redrawInScalingDown}>");
441 currentStates.redrawInScalingDown = ret;
442 return currentStates.redrawInScalingDown;
446 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get redrawInScalingDown from dali currentStates.redrawInScalingDown={currentStates.redrawInScalingDown}>");
447 return currentStates.redrawInScalingDown;
455 /// Set the minimum and the maximum frame.
457 /// <param name="minFrame">minimum frame</param>
458 /// <param name="maxFrame">maximum frame</param>
459 /// <since_tizen> 7 </since_tizen>
460 public void SetMinMaxFrame(int minFrame, int maxFrame)
462 tlog.Fatal(tag, $"< [{GetId()}] SetPlayRange({minFrame}, {maxFrame})");
464 currentStates.changed = true;
465 currentStates.framePlayRangeMin = minFrame;
466 currentStates.framePlayRangeMax = maxFrame;
468 PropertyArray array = new PropertyArray();
469 array.PushBack(new PropertyValue(currentStates.framePlayRangeMin));
470 array.PushBack(new PropertyValue(currentStates.framePlayRangeMax));
472 PropertyMap map = new PropertyMap();
473 map.Add(ImageVisualProperty.PlayRange, new PropertyValue(array));
474 DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
475 tlog.Fatal(tag, $" [{GetId()}] currentStates.min:({currentStates.framePlayRangeMin}, max:{currentStates.framePlayRangeMax})>");
481 /// <since_tizen> 7 </since_tizen>
482 public new void Play()
484 tlog.Fatal(tag, $"<[{GetId()}] Play()");
487 tlog.Fatal(tag, $"[{GetId()}]>");
493 /// <since_tizen> 7 </since_tizen>
494 public new void Pause()
496 tlog.Fatal(tag, $"<[{GetId()}] Pause()>");
499 tlog.Fatal(tag, $"[{GetId()}]>");
505 /// <since_tizen> 7 </since_tizen>
506 public new void Stop()
508 tlog.Fatal(tag, $"<[{GetId()}] Stop()");
511 tlog.Fatal(tag, $"[{GetId()}]>");
515 /// Get the list of layers' information such as the start frame and the end frame in the Lottie file.
517 /// <returns>List of Tuple (string of layer name, integer of start frame, integer of end frame)</returns>
518 /// <since_tizen> 7 </since_tizen>
519 public List<Tuple<string, int, int>> GetContentInfo()
521 tlog.Fatal(tag, $"<");
522 if (currentStates.contentInfo != null)
524 return currentStates.contentInfo;
527 PropertyMap imageMap = base.Image;
528 PropertyMap contentMap = new PropertyMap();
529 if (imageMap != null)
531 PropertyValue val = imageMap.Find(ImageVisualProperty.ContentInfo);
534 if (val.Get(contentMap))
536 currentStates.contentInfo = new List<Tuple<string, int, int>>();
537 for (uint i = 0; i < contentMap.Count(); i++)
539 string key = contentMap.GetKeyAt(i).StringKey;
540 PropertyArray arr = new PropertyArray();
541 contentMap.GetValue(i).Get(arr);
544 int startFrame, endFrame;
545 arr.GetElementAt(0).Get(out startFrame);
546 arr.GetElementAt(1).Get(out endFrame);
548 tlog.Fatal(tag, $"[{i}] layer name={key}, startFrame={startFrame}, endFrame={endFrame}");
550 Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);
552 currentStates.contentInfo?.Add(item);
558 tlog.Fatal(tag, $">");
559 return currentStates.contentInfo;
563 /// A marker has its start frame and end frame.
564 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
565 /// Or animation will play between the start frame of the first marker and the end frame of the second marker if two markers are specified. *
567 /// <param name="marker1">First marker</param>
568 /// <param name="marker2">Second marker</param>
569 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
570 [EditorBrowsable(EditorBrowsableState.Never)]
571 public void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
573 tlog.Fatal(tag, $"< [{GetId()}] SetMinMaxFrameByMarker({marker1}, {marker2})");
575 currentStates.changed = true;
576 currentStates.mark1 = marker1;
577 currentStates.mark2 = marker2;
579 PropertyArray array = new PropertyArray();
580 array.PushBack(new PropertyValue(currentStates.mark1));
583 array.PushBack(new PropertyValue(currentStates.mark2));
586 PropertyMap map = new PropertyMap();
587 map.Add(ImageVisualProperty.PlayRange, new PropertyValue(array));
588 DoAction(ImageView.Property.IMAGE, (int)actionType.updateProperty, new PropertyValue(map));
589 tlog.Fatal(tag, $" [{GetId()}] currentStates.mark1:{currentStates.mark1}, mark2:{currentStates.mark2} >");
595 /// <returns>Tuple of Min and Max frames</returns>
596 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
597 [EditorBrowsable(EditorBrowsableState.Never)]
598 public Tuple<int, int> GetMinMaxFrame()
600 tlog.Fatal(tag, $"< [{GetId()}] GetMinMaxFrame()! total frame={currentStates.totalFrame}");
602 PropertyMap map = Image;
605 PropertyValue val = map.Find(ImageVisualProperty.PlayRange);
608 PropertyArray array = new PropertyArray();
611 uint cnt = array.Count();
612 int item1 = -1, item2 = -1;
613 for (uint i = 0; i < cnt; i++)
615 PropertyValue v = array.GetElementAt(i);
617 if (v.Get(out intRet))
619 tlog.Fatal(tag, $"Got play range of string [{i}]: {intRet}");
631 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#1");
634 tlog.Fatal(tag, $" [{GetId()}] GetMinMaxFrame(min:{item1}, max:{item2})! >");
635 return new Tuple<int, int>(item1, item2);
639 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#2");
640 return new Tuple<int, int>(-1, -1);
645 #region Event, Enum, Struct, ETC
647 /// Animation finished event.
649 /// <since_tizen> 7 </since_tizen>
650 public event EventHandler Finished
654 if (finishedEventHandler == null)
656 tlog.Fatal(tag, $"<[{GetId()}] Finished eventhandler added>");
657 visualEventSignalCallback = onVisualEventSignal;
658 VisualEventSignal().Connect(visualEventSignalCallback);
660 finishedEventHandler += value;
664 tlog.Fatal(tag, $"<[{GetId()}] Finished eventhandler removed>");
665 finishedEventHandler -= value;
666 if (finishedEventHandler == null && visualEventSignalCallback != null)
668 VisualEventSignal().Disconnect(visualEventSignalCallback);
674 /// Enumeration for what state the vector animation is in
676 /// <since_tizen> 7 </since_tizen>
677 public enum PlayStateType
682 /// <since_tizen> 7 </since_tizen>
685 /// Vector Animation has stopped
687 /// <since_tizen> 7 </since_tizen>
690 /// The vector animation is playing
692 /// <since_tizen> 7 </since_tizen>
695 /// The vector animation is paused
697 /// <since_tizen> 7 </since_tizen>
702 /// Enumeration for what to do when the animation is stopped.
704 /// <since_tizen> 7 </since_tizen>
705 public enum StopBehaviorType
708 /// When the animation is stopped, the current frame is shown.
710 /// <since_tizen> 7 </since_tizen>
713 /// When the animation is stopped, the min frame (first frame) is shown.
715 /// <since_tizen> 7 </since_tizen>
718 /// When the animation is stopped, the max frame (last frame) is shown.
720 /// <since_tizen> 7 </since_tizen>
725 /// Enumeration for what looping mode is in.
727 /// <since_tizen> 7 </since_tizen>
728 public enum LoopingModeType
731 /// When the animation arrives at the end in looping mode, the animation restarts from the beginning.
733 /// <since_tizen> 7 </since_tizen>
736 /// When the animation arrives at the end in looping mode, the animation reverses direction and runs backwards again.
738 /// <since_tizen> 7 </since_tizen>
741 #endregion Event, Enum, Struct, ETC
745 internal class VisualEventSignalArgs : EventArgs
747 public int VisualIndex
759 internal event EventHandler<VisualEventSignalArgs> VisualEvent
763 if (visualEventSignalHandler == null)
765 visualEventSignalCallback = onVisualEventSignal;
766 VisualEventSignal().Connect(visualEventSignalCallback);
768 visualEventSignalHandler += value;
772 visualEventSignalHandler -= value;
773 if (visualEventSignalHandler == null && VisualEventSignal().Empty() == false)
775 VisualEventSignal().Disconnect(visualEventSignalCallback);
780 internal void EmitVisualEventSignal(int visualIndex, int signalId)
782 VisualEventSignal().Emit(this, visualIndex, signalId);
785 internal VisualEventSignal VisualEventSignal()
787 VisualEventSignal ret = new VisualEventSignal(Interop.VisualEventSignal.NewWithView(View.getCPtr(this)), false);
788 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
795 private struct states
799 internal int loopCount;
800 internal LoopingModeType loopMode;
801 internal StopBehaviorType stopEndAction;
802 internal int framePlayRangeMin;
803 internal int framePlayRangeMax;
804 internal bool changed;
805 internal int totalFrame;
806 internal float scale;
807 internal PlayStateType playState;
808 internal List<Tuple<string, int, int>> contentInfo;
809 internal string mark1, mark2;
810 internal bool redrawInScalingDown;
812 private states currentStates;
814 private enum actionType
823 private struct DevelVisual
827 AnimatedGradient = Visual.Type.AnimatedImage + 1,
828 AnimatedVectorImage = Visual.Type.AnimatedImage + 2,
832 private const string tag = "NUITEST";
833 private event EventHandler finishedEventHandler;
835 private void OnFinished()
837 tlog.Fatal(tag, $"<[{GetId()}] OnFinished()>");
838 finishedEventHandler?.Invoke(this, null);
841 private void onVisualEventSignal(IntPtr targetView, int visualIndex, int signalId)
845 if (targetView != IntPtr.Zero)
847 View v = Registry.GetManagedBaseHandleFromNativePtr(targetView) as View;
850 tlog.Fatal(tag, $"targetView is not null! name={v.Name}");
854 tlog.Fatal(tag, $"target is something created from dali");
857 VisualEventSignalArgs e = new VisualEventSignalArgs();
858 e.VisualIndex = visualIndex;
859 e.SignalId = signalId;
860 visualEventSignalHandler?.Invoke(this, e);
862 tlog.Fatal(tag, $"<[{GetId()}] onVisualEventSignal()! visualIndex={visualIndex}, signalId={signalId}>");
865 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
866 private delegate void VisualEventSignalCallbackType(IntPtr targetView, int visualIndex, int signalId);
868 private VisualEventSignalCallbackType visualEventSignalCallback;
869 private EventHandler<VisualEventSignalArgs> visualEventSignalHandler;
871 private void debugPrint()
873 tlog.Fatal(tag, $"===================================");
874 tlog.Fatal(tag, $"<[{GetId()}] get currentStates : url={currentStates.url}, loopCount={currentStates.loopCount}, \nframePlayRangeMin/Max({currentStates.framePlayRangeMin},{currentStates.framePlayRangeMax}) ");
875 tlog.Fatal(tag, $" get from Property : StopBehavior={StopBehavior}, LoopMode={LoopingMode}, LoopCount={LoopCount}, PlayState={PlayState}");
876 tlog.Fatal(tag, $" RedrawInScalingDown={RedrawInScalingDown} >");
877 tlog.Fatal(tag, $"===================================");
883 /// A class containing frame informations for a LottieAnimationView.
885 [EditorBrowsable(EditorBrowsableState.Never)]
886 public class LottieFrameInfo : ICloneable
889 /// Creates a new instance with a playing range.
891 [EditorBrowsable(EditorBrowsableState.Never)]
892 public LottieFrameInfo(int startFrame, int endFrame)
894 StartFrame = startFrame;
899 /// Creates a new instance with a still image frame.
901 [EditorBrowsable(EditorBrowsableState.Never)]
902 public LottieFrameInfo(int stillImageFrame) : this(stillImageFrame, stillImageFrame)
907 /// Create a new instance from a pair notation.
909 [EditorBrowsable(EditorBrowsableState.Never)]
910 public static implicit operator LottieFrameInfo((int, int) pair)
912 return new LottieFrameInfo(pair.Item1, pair.Item2);
916 /// Create a new instance from an int value.
918 [EditorBrowsable(EditorBrowsableState.Never)]
919 public static implicit operator LottieFrameInfo(int stillImageFrame)
921 return new LottieFrameInfo(stillImageFrame);
925 /// Create a new instance from string.
926 /// Possible input : "0, 10", "10"
928 [EditorBrowsable(EditorBrowsableState.Never)]
929 public static implicit operator LottieFrameInfo(string pair)
936 string[] parts = pair.Split(',');
937 if (parts.Length == 1)
939 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture));
941 else if (parts.Length == 2)
943 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), Int32.Parse(parts[1].Trim(), CultureInfo.InvariantCulture));
946 Tizen.Log.Error("NUI", $"Can not convert string {pair} to LottieFrameInfo");
951 /// The start frame of the lottie animation.
953 [EditorBrowsable(EditorBrowsableState.Never)]
954 public int StartFrame { get; }
957 /// The end frame of the lottie animation.
959 [EditorBrowsable(EditorBrowsableState.Never)]
960 public int EndFrame { get; }
963 /// Create LottieFrameInfo struct with animation range information
965 [EditorBrowsable(EditorBrowsableState.Never)]
966 public static LottieFrameInfo CreateAnimationRange(int startFrame, int endFrame)
968 return new LottieFrameInfo(startFrame, endFrame);
972 /// Create LottieFrameInfo struct with still image information
974 [EditorBrowsable(EditorBrowsableState.Never)]
975 public static LottieFrameInfo CreateStillImage(int stillImageFrame)
977 return new LottieFrameInfo(stillImageFrame, stillImageFrame);
982 /// Whether this LottieFrameInfo represents one frame or more.
984 [EditorBrowsable(EditorBrowsableState.Never)]
985 public bool IsStillImage()
987 return StartFrame == EndFrame;
992 /// Play specified LottieAnimationView with this frame information.
994 /// <param name="lottieView">The target LottieAnimationView to play.</param>
995 /// <param name="noPlay">Whether go direct to the EndFrame. It is false by default.</param>
996 [EditorBrowsable(EditorBrowsableState.Never)]
997 public void Show(LottieAnimationView lottieView, bool noPlay = false)
999 if (!BeReadyToShow(lottieView))
1004 lottieView.SetMinMaxFrame(StartFrame, Math.Min(EndFrame, lottieView.TotalFrame - 1));
1006 if (IsStillImage() || noPlay)
1008 lottieView.CurrentFrame = EndFrame;
1012 lottieView.CurrentFrame = StartFrame;
1018 [EditorBrowsable(EditorBrowsableState.Never)]
1019 public object Clone() => new LottieFrameInfo(StartFrame, EndFrame);
1021 private bool BeReadyToShow(LottieAnimationView lottieView)
1023 // Validate input lottieView
1024 if (null == lottieView || lottieView.PlayState == LottieAnimationView.PlayStateType.Invalid)
1029 // Stop if it was playing
1030 if (lottieView.PlayState == LottieAnimationView.PlayStateType.Playing)