2 * Copyright(c) 2021 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 System.ComponentModel;
21 namespace Tizen.NUI.BaseComponents
24 /// AnimatedVectorImageView is a class for displaying a vector resource.
26 [EditorBrowsable(EditorBrowsableState.Never)]
27 public partial class AnimatedVectorImageView : LottieAnimationView
29 #region Constructor, Destructor, Dispose
31 /// Construct VectorAnimationView.
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public AnimatedVectorImageView() : base()
36 NUILog.Debug($"[AnimatedVectorImageView START[ constructor objId={GetId()} ] END]");
40 /// Construct VectorAnimationView.
42 /// <param name="scale">Set scaling factor for Vector Animation, while creating.</param>
43 [EditorBrowsable(EditorBrowsableState.Never)]
44 public AnimatedVectorImageView(float scale) : base(scale)
46 NUILog.Debug($"[AnimatedVectorImageView START[ constructor scale={scale}) objId={GetId()} ] END]");
50 /// You can override it to clean-up your own resources
52 /// <param name="type">DisposeTypes</param>
53 [EditorBrowsable(EditorBrowsableState.Never)]
54 protected override void Dispose(DisposeTypes type)
60 NUILog.Debug($"AnimatedVectorImageView START");
62 //Release your own unmanaged resources here.
63 //You should not access any managed member here except static instance.
64 //because the execution order of Finalizes is non-deterministic.
68 NUILog.Debug($"AnimatedVectorImageView END");
70 #endregion Constructor, Destructor, Dispose
77 // Suppress warning : This has been being used by users, so that the interface can not be changed.
78 [EditorBrowsable(EditorBrowsableState.Never)]
79 public string ResourceURL
83 return GetValue(ResourceURLProperty) as string;
87 SetValue(ResourceURLProperty, value);
88 NotifyPropertyChanged();
92 private string InternalResourceURL
96 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] ResourceURL SET");
98 if (value == resourceUrl)
100 NUILog.Debug($"set same URL! ");
103 resourceUrl = (value == null) ? "" : value;
105 isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
106 totalFrameNum = base.TotalFrame;
107 NUILog.Debug($" [{GetId()}] resourceUrl={resourceUrl}) ]AnimatedVectorImageView END]");
115 // Suppress warning : This has been being used by users, so that the interface can not be changed.
116 [EditorBrowsable(EditorBrowsableState.Never)]
117 public new string ResourceUrl
121 return GetValue(ResourceUrlProperty) as string;
125 SetValue(ResourceUrlProperty, value);
126 NotifyPropertyChanged();
130 private string InternalResourceUrl
134 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] ResourceUrl SET");
135 this.ResourceURL = value;
136 NUILog.Debug($" [{GetId()}] value={value}) ]AnimatedVectorImageView END]");
140 NUILog.Debug($"[AnimatedVectorImageView [ [{GetId()}] ResourceUrl GET");
141 return this.ResourceURL;
147 /// RepeatCount of animation.
148 /// The repeat count is 0 by default.
149 /// If the RepeatCount is 0, the animation is never repeated.
150 /// If the RepeatCount is greater than 0, the repeat mode will be taken into account.
151 /// If RepeatCount is -1, animation is infinite loops.
153 [EditorBrowsable(EditorBrowsableState.Never)]
154 public int RepeatCount
158 return (int)GetValue(RepeatCountProperty);
162 SetValue(RepeatCountProperty, value);
163 NotifyPropertyChanged();
167 private int InternalRepeatCount
171 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] RepeatCount SET");
173 repeatCnt = (value < -1) ? -1 : value;
174 LoopCount = (repeatCnt < 0) ? repeatCnt : repeatCnt + 1;
176 NUILog.Debug($"[{GetId()}] repeatCnt={repeatCnt} ]AnimatedVectorImageView END]");
182 /// TotalFrame of animation.
184 [EditorBrowsable(EditorBrowsableState.Never)]
185 public new int TotalFrame
187 get => totalFrameNum;
191 /// CurrentFrame of animation.
193 /// <returns> Returns user set value for the current frame. Cannot provide actual playing current frame. </returns>
194 [EditorBrowsable(EditorBrowsableState.Never)]
195 public new int CurrentFrame
199 return (int)GetValue(CurrentFrameProperty);
203 SetValue(CurrentFrameProperty, value);
204 NotifyPropertyChanged();
208 private int InternalCurrentFrame
212 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] CurrentFrame SET");
214 if (string.IsNullOrEmpty(resourceUrl))
216 throw new InvalidOperationException("Resource Url not yet Set");
223 else if (value >= totalFrameNum)
225 value = totalFrameNum - 1;
228 innerCurrentFrame = value;
229 AnimationState = AnimationStates.Paused;
231 base.SetMinMaxFrame(0, totalFrameNum - 1);
232 base.CurrentFrame = innerCurrentFrame;
234 NUILog.Debug($" [{GetId()}] innerCurrentFrame={innerCurrentFrame}) ]AnimatedVectorImageView END]");
236 get => innerCurrentFrame;
240 /// RepeatMode of animation.
242 [EditorBrowsable(EditorBrowsableState.Never)]
243 public RepeatModes RepeatMode
247 return (RepeatModes)GetValue(RepeatModeProperty);
251 SetValue(RepeatModeProperty, value);
252 NotifyPropertyChanged();
256 private RepeatModes InternalRepeatMode
260 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] RepeatMode SET");
265 case RepeatModes.Restart:
266 LoopingMode = LoopingModeType.Restart;
268 case RepeatModes.Reverse:
269 LoopingMode = LoopingModeType.AutoReverse;
272 LoopingMode = LoopingModeType.Restart;
276 NUILog.Debug($" [{GetId()}] repeatMode={repeatMode}) ]AnimatedVectorImageView END]");
282 /// Get state of animation.
284 [EditorBrowsable(EditorBrowsableState.Never)]
285 public AnimationStates AnimationState
289 CurrentAnimationState = value;
293 if (CurrentAnimationState == AnimationStates.Playing)
295 if (PlayState == PlayStateType.Stopped)
297 CurrentAnimationState = AnimationStates.Stopped;
300 return CurrentAnimationState;
308 /// Set minimum frame and maximum frame
310 /// <param name="minFrame">minimum frame.</param>
311 /// <param name="maxFrame">maximum frame.</param>
312 [EditorBrowsable(EditorBrowsableState.Never)]
313 public void SetMinAndMaxFrame(int minFrame, int maxFrame)
315 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] SetMinAndMaxFrame({minFrame}, {maxFrame})");
317 minimumFrame = (minFrame) > 0 ? minFrame : 0;
318 maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
319 isMinMaxFrameSet = minMaxSetTypes.SetByMinAndMaxFrameMethod;
321 if (minimumFrame >= totalFrameNum)
323 minimumFrame = totalFrameNum - 1;
326 if (maximumFrame >= totalFrameNum)
328 maximumFrame = totalFrameNum - 1;
331 if (minimumFrame > maximumFrame)
336 NUILog.Debug($" [{GetId()}] minimumFrame:{minimumFrame}, maximumFrame:{maximumFrame}) ]AnimatedVectorImageView END]");
340 /// SetMinMaxFrame(int startFrame, int endFrame)
342 /// <param name="minFrame"></param>
343 /// <param name="maxFrame"></param>
344 [EditorBrowsable(EditorBrowsableState.Never)]
345 public new void SetMinMaxFrame(int minFrame, int maxFrame)
347 NUILog.Debug($"SetMinMaxFrame({minFrame}, {maxFrame})!!!");
349 minimumFrame = (minFrame) > 0 ? minFrame : 0;
350 maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
351 isMinMaxFrameSet = minMaxSetTypes.SetByBaseSetMinMaxFrameMethod;
353 if (minimumFrame >= totalFrameNum)
355 minimumFrame = totalFrameNum - 1;
358 if (maximumFrame >= totalFrameNum)
360 maximumFrame = totalFrameNum - 1;
363 base.SetMinMaxFrame(minimumFrame, maximumFrame);
367 /// A marker has its start frame and end frame.
368 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
369 /// 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. *
371 /// <param name="marker1">First marker</param>
372 /// <param name="marker2">Second marker</param>
373 [EditorBrowsable(EditorBrowsableState.Never)]
374 public new void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
376 NUILog.Debug($"SetMinMaxFrameByMarker({marker1}, {marker2})");
377 isMinMaxFrameSet = minMaxSetTypes.SetByMarker;
378 base.SetMinMaxFrameByMarker(marker1, marker2);
384 [EditorBrowsable(EditorBrowsableState.Never)]
385 public new void Play()
387 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
389 if (string.IsNullOrEmpty(resourceUrl))
391 throw new InvalidOperationException("Resource Url not yet Set");
394 switch (isMinMaxFrameSet)
396 case minMaxSetTypes.NotSetByUser:
397 base.SetMinMaxFrame(0, totalFrameNum - 1);
398 base.CurrentFrame = 0;
401 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
402 base.SetMinMaxFrame(minimumFrame, maximumFrame);
403 base.CurrentFrame = minimumFrame;
406 case minMaxSetTypes.SetByMarker:
407 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
414 Extents tmp = base.Margin;
418 AnimationState = AnimationStates.Playing;
420 NUILog.Debug($" [{GetId()}] isMinMaxFrameSet={isMinMaxFrameSet}) ]AnimatedVectorImageView END]");
426 [EditorBrowsable(EditorBrowsableState.Never)]
427 public new void Pause()
429 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
431 if (string.IsNullOrEmpty(resourceUrl))
433 throw new InvalidOperationException("Resource Url not yet Set");
437 AnimationState = AnimationStates.Paused;
439 NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
445 /// <param name="endAction">Defines, what should be behaviour after cancel operation
446 /// End action is Cancel, Animation Stops at the Current Frame.
447 /// End action is Discard, Animation Stops at the Min Frame
448 /// End action is StopFinal, Animation Stops at the Max Frame
450 [EditorBrowsable(EditorBrowsableState.Never)]
451 public void Stop(EndActions endAction = EndActions.Cancel)
453 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] endAction:({endAction}), PlayState={PlayState}");
455 if (string.IsNullOrEmpty(resourceUrl))
457 throw new InvalidOperationException("Resource Url not yet Set");
460 if (AnimationState == AnimationStates.Stopped)
465 if (innerEndAction != endAction)
467 innerEndAction = endAction;
470 case EndActions.Cancel:
471 StopBehavior = StopBehaviorType.CurrentFrame;
473 case EndActions.Discard:
474 StopBehavior = StopBehaviorType.MinimumFrame;
476 case EndActions.StopFinal:
477 StopBehavior = StopBehaviorType.MaximumFrame;
480 NUILog.Debug($" [{GetId()}] no endAction : default set");
484 AnimationState = AnimationStates.Stopped;
488 if (endAction == EndActions.StopFinal)
490 switch (isMinMaxFrameSet)
492 case minMaxSetTypes.NotSetByUser:
493 if (base.CurrentFrame != totalFrameNum - 1)
495 NUILog.Debug($"isMinMaxFrameSet:{isMinMaxFrameSet}, CurrentFrameNumber:{base.CurrentFrame}, totalFrameNum:{ totalFrameNum}");
496 base.CurrentFrame = totalFrameNum - 1;
497 NUILog.Debug($"set CurrentFrameNumber({base.CurrentFrame}) as totalFrameNum({maximumFrame}) - 1 !");
501 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
502 if (base.CurrentFrame != maximumFrame)
504 NUILog.Debug($"isMinMaxFrameSet:{isMinMaxFrameSet}, CurrentFrameNumber:{base.CurrentFrame}, maximumFrame:{ maximumFrame}");
505 base.CurrentFrame = maximumFrame;
506 NUILog.Debug($"set CurrentFrameNumber({base.CurrentFrame}) as maximumFrame({maximumFrame})!!!");
509 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
510 case minMaxSetTypes.SetByMarker:
516 NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
521 #region Event, Enum, Struct, ETC
523 /// RepeatMode of animation.
525 // Suppress warning : This has been being used by users, so that the interface can not be changed.
526 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
527 [EditorBrowsable(EditorBrowsableState.Never)]
528 public enum RepeatModes
531 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
533 [EditorBrowsable(EditorBrowsableState.Never)]
534 Restart = LoopingModeType.Restart,
536 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
538 [EditorBrowsable(EditorBrowsableState.Never)]
539 Reverse = LoopingModeType.AutoReverse
543 /// EndActions of animation.
545 // Suppress warning : This has been being used by users, so that the interface can not be changed.
546 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
547 [EditorBrowsable(EditorBrowsableState.Never)]
548 public enum EndActions
550 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
551 [EditorBrowsable(EditorBrowsableState.Never)]
553 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
554 [EditorBrowsable(EditorBrowsableState.Never)]
556 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
557 [EditorBrowsable(EditorBrowsableState.Never)]
562 /// AnimationStates of animation.
564 // Suppress warning : This has been being used by users, so that the interface can not be changed.
565 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
566 [EditorBrowsable(EditorBrowsableState.Never)]
567 public enum AnimationStates
569 /// <summary> The animation has stopped.</summary>
570 [EditorBrowsable(EditorBrowsableState.Never)]
571 Stopped = PlayStateType.Stopped,
572 /// <summary> The animation is playing.</summary>
573 [EditorBrowsable(EditorBrowsableState.Never)]
574 Playing = PlayStateType.Playing,
575 /// <summary> The animation is paused.</summary>
576 [EditorBrowsable(EditorBrowsableState.Never)]
577 Paused = PlayStateType.Paused
579 #endregion Event, Enum, Struct, ETC
587 private string resourceUrl = null;
588 private int repeatCnt = 0;
589 private int totalFrameNum = 0;
590 private RepeatModes repeatMode = RepeatModes.Restart;
591 private int minimumFrame = -1, maximumFrame = -1;
592 private minMaxSetTypes isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
593 private int innerCurrentFrame = -1;
594 private EndActions innerEndAction = EndActions.Cancel;
595 private enum minMaxSetTypes
598 SetByMinAndMaxFrameMethod,
600 SetByBaseSetMinMaxFrameMethod,
603 private string tag = "NUITEST";
604 private AnimationStates CurrentAnimationState = AnimationStates.Stopped;