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 /// LottieAnimationView renders an animated vector image (Lottie file).
29 /// <since_tizen> 7 </since_tizen>
30 public partial class LottieAnimationView : ImageView
32 #region Constructor, Destructor, Dispose
34 /// LottieAnimationView constructor
36 /// <param name="scale">The factor of scaling image, default : 1.0f</param>
37 /// <param name="shown">false : not displayed (hidden), true : displayed (shown), default : true</param>
39 /// If the shown parameter is false, the animation is not visible even if the LottieAnimationView instance is created.
43 /// LottieAnimationView myLottie = new LottieAnimationView();
44 /// LottieAnimationView myLottie2 = new LottieAnimationView(2.0f);
45 /// LottieAnimationView myLottie3 = new LottieAnimationView(1.0f, false);
48 /// <since_tizen> 7 </since_tizen>
49 public LottieAnimationView(float scale = 1.0f, bool shown = true) : base()
51 ActionPlay = Interop.LottieAnimationView.AnimatedVectorImageVisualActionPlayGet();
52 ActionPause = Interop.LottieAnimationView.AnimatedVectorImageVisualActionPauseGet();
53 ActionStop = Interop.LottieAnimationView.AnimatedVectorImageVisualActionStopGet();
55 NUILog.Debug($"< 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 //Release your own unmanaged resources here.
84 //You should not access any managed member here except static instance.
85 //because the execution order of Finalizes is non-deterministic.
87 //disconnect event signal
88 if (finishedEventHandler != null && visualEventSignalCallback != null)
90 VisualEventSignal().Disconnect(visualEventSignalCallback);
91 finishedEventHandler = null;
92 NUILog.Debug($"disconnect event signal");
97 #endregion Constructor, Destructor, Dispose
102 /// Set or Get resource URL of Lottie file.
104 /// <since_tizen> 7 </since_tizen>
109 return GetValue(URLProperty) as string;
113 SetValue(URLProperty, value);
114 NotifyPropertyChanged();
118 private string InternalURL
122 string ret = (value == null ? "" : value);
123 currentStates.url = ret;
124 currentStates.changed = true;
126 NUILog.Debug($"<[{GetId()}]SET url={currentStates.url}");
128 PropertyMap map = new PropertyMap();
129 map.Add(Visual.Property.Type, new PropertyValue((int)DevelVisual.Type.AnimatedVectorImage))
130 .Add(ImageVisualProperty.URL, new PropertyValue(currentStates.url))
131 .Add(ImageVisualProperty.LoopCount, new PropertyValue(currentStates.loopCount))
132 .Add(ImageVisualProperty.StopBehavior, new PropertyValue((int)currentStates.stopEndAction))
133 .Add(ImageVisualProperty.LoopingMode, new PropertyValue((int)currentStates.loopMode));
136 currentStates.contentInfo = null;
138 if (currentStates.scale != 1.0f)
140 Scale = new Vector3(currentStates.scale, currentStates.scale, 0.0f);
142 NUILog.Debug($"<[{GetId()}]>");
146 string ret = currentStates.url;
147 NUILog.Debug($"<[{GetId()}] GET");
149 PropertyMap map = Image;
152 PropertyValue val = map.Find(ImageVisualProperty.URL);
155 if (val.Get(out ret))
157 NUILog.Debug($"gotten url={ret} >");
162 Tizen.Log.Error(tag, $" [ERROR][{GetId()}](LottieAnimationView) Fail to get URL from dali >");
168 /// Gets the playing state
170 /// <since_tizen> 7 </since_tizen>
171 public PlayStateType PlayState
175 NUILog.Debug($"< Get!");
176 PropertyMap map = base.Image;
180 PropertyValue val = map.Find(ImageVisualProperty.PlayState);
183 if (val.Get(out ret))
185 currentStates.playState = (PlayStateType)ret;
186 NUILog.Debug($"gotten play state={ret} >");
192 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}]Fail to get PlayState from dali currentStates.playState={currentStates.playState}>");
194 return currentStates.playState;
199 /// Get the number of total frames
201 /// <since_tizen> 7 </since_tizen>
202 public int TotalFrame
207 PropertyMap map = Image;
210 PropertyValue val = map.Find(ImageVisualProperty.TotalFrameNumber);
213 if (val.Get(out ret))
215 //NUILog.Debug( $"TotalFrameNumber get! ret={ret}");
216 currentStates.totalFrame = ret;
221 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get TotalFrameNumber from dali>");
227 /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
230 /// 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.
233 /// We assume that the animation in myLottie.json file has 100 frames originally. If so, its frame index will be 0 - 99.
235 /// LottieAnimationView myLottie = new LottieAnimationView();
236 /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
237 /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
238 /// myLottie.CurrentFrame = 200; //display 99 frame
239 /// myLottie.SetMinMaxFrame(10, 20);
240 /// myLottie.CurrentFrame = 15; //display 15 frame
241 /// myLottie.CurrentFrame = 50; //display 20 frame, because the MinMax is set (10,20) above
244 /// <since_tizen> 7 </since_tizen>
245 public int CurrentFrame
249 return (int)GetValue(CurrentFrameProperty);
253 SetValue(CurrentFrameProperty, value);
254 NotifyPropertyChanged();
258 private int InternalCurrentFrame
262 currentStates.frame = value;
263 NUILog.Debug($"<[{GetId()}]SET frame={currentStates.frame}>");
264 DoAction(ImageView.Property.IMAGE, ActionJumpTo, new PropertyValue(currentStates.frame));
269 PropertyMap map = Image;
272 PropertyValue val = map.Find(ImageVisualProperty.CurrentFrameNumber);
275 if (val.Get(out ret))
277 //NUILog.Debug( $"CurrentFrameNumber get! val={ret}");
282 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get CurrentFrameNumber from dali!! ret={ret}>");
288 /// Sets or gets the looping mode of Lottie animation.
290 /// <since_tizen> 7 </since_tizen>
291 public LoopingModeType LoopingMode
295 return (LoopingModeType)GetValue(LoopingModeProperty);
299 SetValue(LoopingModeProperty, value);
300 NotifyPropertyChanged();
304 private LoopingModeType InternalLoopingMode
308 currentStates.loopMode = (LoopingModeType)value;
309 currentStates.changed = true;
311 NUILog.Debug($"<[{GetId()}] SET loopMode={currentStates.loopMode}>");
312 PropertyMap map = new PropertyMap();
313 map.Add(ImageVisualProperty.LoopingMode, new PropertyValue((int)currentStates.loopMode));
314 DoAction(ImageView.Property.IMAGE, Interop.Visual.GetActionUpdateProperty(), new PropertyValue(map));
318 //NUILog.Debug( $"LoopMode get!");
319 PropertyMap map = base.Image;
323 PropertyValue val = map.Find(ImageVisualProperty.LoopingMode);
326 if (val.Get(out ret))
328 //NUILog.Debug( $"gotten LoopMode={ret}");
329 if (ret != (int)currentStates.loopMode && ret > 0)
331 NUILog.Debug($" [ERROR][{GetId()}](LottieAnimationView) different LoopMode! gotten={ret}, loopMode={currentStates.loopMode}");
333 currentStates.loopMode = (LoopingModeType)ret;
334 return (LoopingModeType)ret;
338 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get loopMode from dali>");
339 return currentStates.loopMode;
344 /// Sets or gets the loop count.
347 /// The minus value means the infinite loop count.
351 /// LottieAnimationView myLottie = new LottieAnimationView();
352 /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
353 /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
354 /// myLottie.LoopCount = -1; //infinite loop
356 /// myLottie.Stop(); //it plays continuously unless Stop() is called
357 /// myLottie.LoopCount = 2;
358 /// myLottie.Play(); //it plays only 2 times and stops automatically
361 /// <since_tizen> 7 </since_tizen>
366 return (int)GetValue(LoopCountProperty);
370 SetValue(LoopCountProperty, value);
371 NotifyPropertyChanged();
375 private int InternalLoopCount
379 currentStates.changed = true;
380 currentStates.loopCount = value;
381 NUILog.Debug($"<[{GetId()}]SET currentStates.loopCount={currentStates.loopCount}>");
382 PropertyMap map = new PropertyMap();
383 map.Add(ImageVisualProperty.LoopCount, new PropertyValue(currentStates.loopCount));
384 DoAction(ImageView.Property.IMAGE, Interop.Visual.GetActionUpdateProperty(), new PropertyValue(map));
388 //NUILog.Debug( $"LoopCount get!");
389 PropertyMap map = base.Image;
393 PropertyValue val = map.Find(ImageVisualProperty.LoopCount);
396 if (val.Get(out ret))
398 //NUILog.Debug( $"gotten loop count={ret}");
399 if (ret != currentStates.loopCount && ret > 0)
401 NUILog.Debug($"<[ERROR][{GetId()}](LottieAnimationView) different loop count! gotten={ret}, loopCount={currentStates.loopCount}>");
403 currentStates.loopCount = ret;
404 return currentStates.loopCount;
408 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get LoopCount from dali currentStates.loopCount={currentStates.loopCount}>");
409 return currentStates.loopCount;
414 /// Sets or gets the stop behavior.
416 /// <since_tizen> 7 </since_tizen>
417 public StopBehaviorType StopBehavior
421 return (StopBehaviorType)GetValue(StopBehaviorProperty);
425 SetValue(StopBehaviorProperty, value);
426 NotifyPropertyChanged();
430 private StopBehaviorType InternalStopBehavior
434 currentStates.stopEndAction = (StopBehaviorType)value;
435 currentStates.changed = true;
437 NUILog.Debug($"<[{GetId()}]SET val={currentStates.stopEndAction}>");
438 PropertyMap map = new PropertyMap();
439 map.Add(ImageVisualProperty.StopBehavior, new PropertyValue((int)currentStates.stopEndAction));
440 DoAction(ImageView.Property.IMAGE, Interop.Visual.GetActionUpdateProperty(), new PropertyValue(map));
444 //NUILog.Debug( $"StopBehavior get!");
445 PropertyMap map = base.Image;
449 PropertyValue val = map.Find(ImageVisualProperty.StopBehavior);
452 if (val.Get(out ret))
454 //NUILog.Debug( $"gotten StopBehavior={ret}");
455 if (ret != (int)currentStates.stopEndAction)
457 NUILog.Debug($"<[ERROR][{GetId()}](LottieAnimationView) different StopBehavior! gotten={ret}, StopBehavior={currentStates.stopEndAction}>");
459 currentStates.stopEndAction = (StopBehaviorType)ret;
460 return (StopBehaviorType)ret;
464 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get StopBehavior from dali>");
465 return currentStates.stopEndAction;
470 /// Whether to redraw the image when the visual is scaled down.
474 /// It is used in the AnimatedVectorImageVisual.The default is true.
476 [EditorBrowsable(EditorBrowsableState.Never)]
477 public bool RedrawInScalingDown
481 return (bool)GetValue(RedrawInScalingDownProperty);
485 SetValue(RedrawInScalingDownProperty, value);
486 NotifyPropertyChanged();
490 private bool InternalRedrawInScalingDown
494 currentStates.changed = true;
495 currentStates.redrawInScalingDown = value;
496 NUILog.Debug($"<[{GetId()}]SET currentStates.redrawInScalingDown={currentStates.redrawInScalingDown}>");
497 PropertyMap map = new PropertyMap();
498 map.Add(ImageVisualProperty.RedrawInScalingDown, new PropertyValue(currentStates.redrawInScalingDown));
499 DoAction(ImageView.Property.IMAGE, Interop.Visual.GetActionUpdateProperty(), new PropertyValue(map));
503 PropertyMap map = base.Image;
507 PropertyValue val = map.Find(ImageVisualProperty.RedrawInScalingDown);
510 if (val.Get(out ret))
512 if (ret != currentStates.redrawInScalingDown)
514 NUILog.Debug($"<[ERROR][{GetId()}](LottieAnimationView) different redrawInScalingDown! gotten={ret}, redrawInScalingDown={currentStates.redrawInScalingDown}>");
516 currentStates.redrawInScalingDown = ret;
517 return currentStates.redrawInScalingDown;
521 Tizen.Log.Error(tag, $"<[ERROR][{GetId()}](LottieAnimationView) Fail to get redrawInScalingDown from dali currentStates.redrawInScalingDown={currentStates.redrawInScalingDown}>");
522 return currentStates.redrawInScalingDown;
528 /// Actions property value to Jump to the specified frame.
529 /// This property can be redefined by child class if it use different value.
531 [EditorBrowsable(EditorBrowsableState.Never)]
532 protected int ActionJumpTo { get; set; } = Interop.LottieAnimationView.AnimatedVectorImageVisualActionJumpToGet();
538 /// Set the minimum and the maximum frame.
540 /// <param name="minFrame">minimum frame</param>
541 /// <param name="maxFrame">maximum frame</param>
542 /// <since_tizen> 7 </since_tizen>
543 public void SetMinMaxFrame(int minFrame, int maxFrame)
545 NUILog.Debug($"< [{GetId()}] SetPlayRange({minFrame}, {maxFrame})");
547 currentStates.changed = true;
548 currentStates.framePlayRangeMin = minFrame;
549 currentStates.framePlayRangeMax = maxFrame;
551 PropertyArray array = new PropertyArray();
552 array.PushBack(new PropertyValue(currentStates.framePlayRangeMin));
553 array.PushBack(new PropertyValue(currentStates.framePlayRangeMax));
555 PropertyMap map = new PropertyMap();
556 map.Add(ImageVisualProperty.PlayRange, new PropertyValue(array));
557 DoAction(ImageView.Property.IMAGE, Interop.Visual.GetActionUpdateProperty(), new PropertyValue(map));
558 NUILog.Debug($" [{GetId()}] currentStates.min:({currentStates.framePlayRangeMin}, max:{currentStates.framePlayRangeMax})>");
564 /// <since_tizen> 7 </since_tizen>
565 public new void Play()
567 NUILog.Debug($"<[{GetId()}] Play()");
570 NUILog.Debug($"[{GetId()}]>");
576 /// <since_tizen> 7 </since_tizen>
577 public new void Pause()
579 NUILog.Debug($"<[{GetId()}] Pause()>");
582 NUILog.Debug($"[{GetId()}]>");
588 /// <since_tizen> 7 </since_tizen>
589 public new void Stop()
591 NUILog.Debug($"<[{GetId()}] Stop()");
594 NUILog.Debug($"[{GetId()}]>");
598 /// Get the list of layers' information such as the start frame and the end frame in the Lottie file.
600 /// <returns>List of Tuple (string of layer name, integer of start frame, integer of end frame)</returns>
601 /// <since_tizen> 7 </since_tizen>
602 public List<Tuple<string, int, int>> GetContentInfo()
605 if (currentStates.contentInfo != null)
607 return currentStates.contentInfo;
610 PropertyMap imageMap = base.Image;
611 PropertyMap contentMap = new PropertyMap();
612 if (imageMap != null)
614 PropertyValue val = imageMap.Find(ImageVisualProperty.ContentInfo);
617 if (val.Get(contentMap))
619 currentStates.contentInfo = new List<Tuple<string, int, int>>();
620 for (uint i = 0; i < contentMap.Count(); i++)
622 string key = contentMap.GetKeyAt(i).StringKey;
623 PropertyArray arr = new PropertyArray();
624 contentMap.GetValue(i).Get(arr);
627 int startFrame, endFrame;
628 arr.GetElementAt(0).Get(out startFrame);
629 arr.GetElementAt(1).Get(out endFrame);
631 NUILog.Debug($"[{i}] layer name={key}, startFrame={startFrame}, endFrame={endFrame}");
633 Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);
635 currentStates.contentInfo?.Add(item);
642 return currentStates.contentInfo;
646 /// A marker has its start frame and end frame.
647 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
648 /// 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. *
650 /// <param name="marker1">First marker</param>
651 /// <param name="marker2">Second marker</param>
652 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
653 [EditorBrowsable(EditorBrowsableState.Never)]
654 public void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
656 NUILog.Debug($"< [{GetId()}] SetMinMaxFrameByMarker({marker1}, {marker2})");
658 currentStates.changed = true;
659 currentStates.mark1 = marker1;
660 currentStates.mark2 = marker2;
662 PropertyArray array = new PropertyArray();
663 array.PushBack(new PropertyValue(currentStates.mark1));
666 array.PushBack(new PropertyValue(currentStates.mark2));
669 PropertyMap map = new PropertyMap();
670 map.Add(ImageVisualProperty.PlayRange, new PropertyValue(array));
671 DoAction(ImageView.Property.IMAGE, Interop.Visual.GetActionUpdateProperty(), new PropertyValue(map));
672 NUILog.Debug($" [{GetId()}] currentStates.mark1:{currentStates.mark1}, mark2:{currentStates.mark2} >");
678 /// <returns>Tuple of Min and Max frames</returns>
679 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
680 [EditorBrowsable(EditorBrowsableState.Never)]
681 public Tuple<int, int> GetMinMaxFrame()
683 NUILog.Debug($"< [{GetId()}] GetMinMaxFrame()! total frame={currentStates.totalFrame}");
685 PropertyMap map = Image;
688 PropertyValue val = map.Find(ImageVisualProperty.PlayRange);
691 PropertyArray array = new PropertyArray();
694 uint cnt = array.Count();
695 int item1 = -1, item2 = -1;
696 for (uint i = 0; i < cnt; i++)
698 PropertyValue v = array.GetElementAt(i);
700 if (v.Get(out intRet))
702 NUILog.Debug($"Got play range of string [{i}]: {intRet}");
714 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#1");
717 NUILog.Debug($" [{GetId()}] GetMinMaxFrame(min:{item1}, max:{item2})! >");
718 return new Tuple<int, int>(item1, item2);
722 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#2");
723 return new Tuple<int, int>(-1, -1);
728 #region Event, Enum, Struct, ETC
730 /// Animation finished event.
732 /// <since_tizen> 7 </since_tizen>
733 public event EventHandler Finished
737 if (finishedEventHandler == null)
739 NUILog.Debug($"<[{GetId()}] Finished eventhandler added>");
740 visualEventSignalCallback = onVisualEventSignal;
741 VisualEventSignal().Connect(visualEventSignalCallback);
743 finishedEventHandler += value;
747 NUILog.Debug($"<[{GetId()}] Finished eventhandler removed>");
748 finishedEventHandler -= value;
749 if (finishedEventHandler == null && visualEventSignalCallback != null)
751 VisualEventSignal().Disconnect(visualEventSignalCallback);
757 /// Enumeration for what state the vector animation is in
759 /// <since_tizen> 7 </since_tizen>
760 public enum PlayStateType
765 /// <since_tizen> 7 </since_tizen>
768 /// Vector Animation has stopped
770 /// <since_tizen> 7 </since_tizen>
773 /// The vector animation is playing
775 /// <since_tizen> 7 </since_tizen>
778 /// The vector animation is paused
780 /// <since_tizen> 7 </since_tizen>
785 /// Enumeration for what to do when the animation is stopped.
787 /// <since_tizen> 7 </since_tizen>
788 public enum StopBehaviorType
791 /// When the animation is stopped, the current frame is shown.
793 /// <since_tizen> 7 </since_tizen>
796 /// When the animation is stopped, the min frame (first frame) is shown.
798 /// <since_tizen> 7 </since_tizen>
801 /// When the animation is stopped, the max frame (last frame) is shown.
803 /// <since_tizen> 7 </since_tizen>
808 /// Enumeration for what looping mode is in.
810 /// <since_tizen> 7 </since_tizen>
811 public enum LoopingModeType
814 /// When the animation arrives at the end in looping mode, the animation restarts from the beginning.
816 /// <since_tizen> 7 </since_tizen>
819 /// When the animation arrives at the end in looping mode, the animation reverses direction and runs backwards again.
821 /// <since_tizen> 7 </since_tizen>
824 #endregion Event, Enum, Struct, ETC
828 internal class VisualEventSignalArgs : EventArgs
830 public int VisualIndex
842 internal event EventHandler<VisualEventSignalArgs> VisualEvent
846 if (visualEventSignalHandler == null)
848 visualEventSignalCallback = onVisualEventSignal;
849 VisualEventSignal().Connect(visualEventSignalCallback);
851 visualEventSignalHandler += value;
855 visualEventSignalHandler -= value;
856 if (visualEventSignalHandler == null && VisualEventSignal().Empty() == false)
858 VisualEventSignal().Disconnect(visualEventSignalCallback);
863 internal void EmitVisualEventSignal(int visualIndex, int signalId)
865 VisualEventSignal().Emit(this, visualIndex, signalId);
868 internal VisualEventSignal VisualEventSignal()
870 VisualEventSignal ret = new VisualEventSignal(Interop.VisualEventSignal.NewWithView(View.getCPtr(this)), false);
871 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
878 private struct states
882 internal int loopCount;
883 internal LoopingModeType loopMode;
884 internal StopBehaviorType stopEndAction;
885 internal int framePlayRangeMin;
886 internal int framePlayRangeMax;
887 internal bool changed;
888 internal int totalFrame;
889 internal float scale;
890 internal PlayStateType playState;
891 internal List<Tuple<string, int, int>> contentInfo;
892 internal string mark1, mark2;
893 internal bool redrawInScalingDown;
895 private states currentStates;
897 private struct DevelVisual
901 AnimatedGradient = Visual.Type.AnimatedImage + 1,
902 AnimatedVectorImage = Visual.Type.AnimatedImage + 2,
906 private const string tag = "NUITEST";
907 private event EventHandler finishedEventHandler;
909 private void OnFinished()
911 NUILog.Debug($"<[{GetId()}] OnFinished()>");
912 finishedEventHandler?.Invoke(this, null);
915 private void onVisualEventSignal(IntPtr targetView, int visualIndex, int signalId)
919 if (targetView != IntPtr.Zero)
921 View v = Registry.GetManagedBaseHandleFromNativePtr(targetView) as View;
924 NUILog.Debug($"targetView is not null! name={v.Name}");
928 NUILog.Debug($"target is something created from dali");
931 VisualEventSignalArgs e = new VisualEventSignalArgs();
932 e.VisualIndex = visualIndex;
933 e.SignalId = signalId;
934 visualEventSignalHandler?.Invoke(this, e);
936 NUILog.Debug($"<[{GetId()}] onVisualEventSignal()! visualIndex={visualIndex}, signalId={signalId}>");
939 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
940 private delegate void VisualEventSignalCallbackType(IntPtr targetView, int visualIndex, int signalId);
942 private VisualEventSignalCallbackType visualEventSignalCallback;
943 private EventHandler<VisualEventSignalArgs> visualEventSignalHandler;
945 private void debugPrint()
947 NUILog.Debug($"===================================");
948 NUILog.Debug($"<[{GetId()}] get currentStates : url={currentStates.url}, loopCount={currentStates.loopCount}, \nframePlayRangeMin/Max({currentStates.framePlayRangeMin},{currentStates.framePlayRangeMax}) ");
949 NUILog.Debug($" get from Property : StopBehavior={StopBehavior}, LoopMode={LoopingMode}, LoopCount={LoopCount}, PlayState={PlayState}");
950 NUILog.Debug($" RedrawInScalingDown={RedrawInScalingDown} >");
951 NUILog.Debug($"===================================");
957 /// A class containing frame informations for a LottieAnimationView.
959 [EditorBrowsable(EditorBrowsableState.Never)]
960 public class LottieFrameInfo : ICloneable
963 /// Creates a new instance with a playing range.
965 [EditorBrowsable(EditorBrowsableState.Never)]
966 public LottieFrameInfo(int startFrame, int endFrame)
968 StartFrame = startFrame;
973 /// Creates a new instance with a still image frame.
975 [EditorBrowsable(EditorBrowsableState.Never)]
976 public LottieFrameInfo(int stillImageFrame) : this(stillImageFrame, stillImageFrame)
981 /// Create a new instance from a pair notation.
983 [EditorBrowsable(EditorBrowsableState.Never)]
984 public static implicit operator LottieFrameInfo((int, int) pair)
986 return new LottieFrameInfo(pair.Item1, pair.Item2);
990 /// Create a new instance from an int value.
992 [EditorBrowsable(EditorBrowsableState.Never)]
993 public static implicit operator LottieFrameInfo(int stillImageFrame)
995 return new LottieFrameInfo(stillImageFrame);
999 /// Create a new instance from string.
1000 /// Possible input : "0, 10", "10"
1002 [EditorBrowsable(EditorBrowsableState.Never)]
1003 public static implicit operator LottieFrameInfo(string pair)
1010 string[] parts = pair.Split(',');
1011 if (parts.Length == 1)
1013 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture));
1015 else if (parts.Length == 2)
1017 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), Int32.Parse(parts[1].Trim(), CultureInfo.InvariantCulture));
1020 Tizen.Log.Error("NUI", $"Can not convert string {pair} to LottieFrameInfo");
1025 /// The start frame of the lottie animation.
1027 [EditorBrowsable(EditorBrowsableState.Never)]
1028 public int StartFrame { get; }
1031 /// The end frame of the lottie animation.
1033 [EditorBrowsable(EditorBrowsableState.Never)]
1034 public int EndFrame { get; }
1037 /// Create LottieFrameInfo struct with animation range information
1039 [EditorBrowsable(EditorBrowsableState.Never)]
1040 public static LottieFrameInfo CreateAnimationRange(int startFrame, int endFrame)
1042 return new LottieFrameInfo(startFrame, endFrame);
1046 /// Create LottieFrameInfo struct with still image information
1048 [EditorBrowsable(EditorBrowsableState.Never)]
1049 public static LottieFrameInfo CreateStillImage(int stillImageFrame)
1051 return new LottieFrameInfo(stillImageFrame, stillImageFrame);
1056 /// Whether this LottieFrameInfo represents one frame or more.
1058 [EditorBrowsable(EditorBrowsableState.Never)]
1059 public bool IsStillImage()
1061 return StartFrame == EndFrame;
1066 /// Play specified LottieAnimationView with this frame information.
1068 /// <param name="lottieView">The target LottieAnimationView to play.</param>
1069 /// <param name="noPlay">Whether go direct to the EndFrame. It is false by default.</param>
1070 [EditorBrowsable(EditorBrowsableState.Never)]
1071 public void Show(LottieAnimationView lottieView, bool noPlay = false)
1073 if (!BeReadyToShow(lottieView))
1078 lottieView.SetMinMaxFrame(StartFrame, Math.Min(EndFrame, lottieView.TotalFrame - 1));
1080 if (IsStillImage() || noPlay)
1082 lottieView.CurrentFrame = EndFrame;
1086 lottieView.CurrentFrame = StartFrame;
1092 [EditorBrowsable(EditorBrowsableState.Never)]
1093 public object Clone() => new LottieFrameInfo(StartFrame, EndFrame);
1095 private bool BeReadyToShow(LottieAnimationView lottieView)
1097 // Validate input lottieView
1098 if (null == lottieView || lottieView.PlayState == LottieAnimationView.PlayStateType.Invalid)
1103 // Stop if it was playing
1104 if (lottieView.PlayState == LottieAnimationView.PlayStateType.Playing)