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 NUILog.Debug($" [{GetId()}] resourceUrl={resourceUrl}) ]AnimatedVectorImageView END]");
114 // Suppress warning : This has been being used by users, so that the interface can not be changed.
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public new string ResourceUrl
120 return GetValue(ResourceUrlProperty) as string;
124 SetValue(ResourceUrlProperty, value);
125 NotifyPropertyChanged();
129 private string InternalResourceUrl
133 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] ResourceUrl SET");
134 this.ResourceURL = value;
135 NUILog.Debug($" [{GetId()}] value={value}) ]AnimatedVectorImageView END]");
139 NUILog.Debug($"[AnimatedVectorImageView [ [{GetId()}] ResourceUrl GET");
140 return this.ResourceURL;
146 /// RepeatCount of animation.
147 /// The repeat count is 0 by default.
148 /// If the RepeatCount is 0, the animation is never repeated.
149 /// If the RepeatCount is greater than 0, the repeat mode will be taken into account.
150 /// If RepeatCount is -1, animation is infinite loops.
152 [EditorBrowsable(EditorBrowsableState.Never)]
153 public int RepeatCount
157 return (int)GetValue(RepeatCountProperty);
161 SetValue(RepeatCountProperty, value);
162 NotifyPropertyChanged();
166 private int InternalRepeatCount
170 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] RepeatCount SET");
172 repeatCnt = (value < -1) ? -1 : value;
173 LoopCount = (repeatCnt < 0) ? repeatCnt : repeatCnt + 1;
175 NUILog.Debug($"[{GetId()}] repeatCnt={repeatCnt} ]AnimatedVectorImageView END]");
181 /// TotalFrame of animation.
183 [EditorBrowsable(EditorBrowsableState.Never)]
184 public new int TotalFrame
186 get => totalFrameNum;
189 private int totalFrameNum
191 get => base.TotalFrame;
195 /// CurrentFrame of animation.
197 /// <returns> Returns user set value for the current frame. Cannot provide actual playing current frame. </returns>
198 [EditorBrowsable(EditorBrowsableState.Never)]
199 public new int CurrentFrame
203 return (int)GetValue(CurrentFrameProperty);
207 SetValue(CurrentFrameProperty, value);
208 NotifyPropertyChanged();
212 private int InternalCurrentFrame
216 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] CurrentFrame SET");
218 if (string.IsNullOrEmpty(resourceUrl))
220 throw new InvalidOperationException("Resource Url not yet Set");
228 innerCurrentFrame = value;
229 AnimationState = AnimationStates.Paused;
231 base.SetMinMaxFrame(0, IntegerMaxValue);
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 > maximumFrame)
323 NUILog.Debug($" [{GetId()}] minimumFrame:{minimumFrame} > maximumFrame:{maximumFrame}) ]AnimatedVectorImageView END]");
327 NUILog.Debug($" [{GetId()}] minimumFrame:{minimumFrame}, maximumFrame:{maximumFrame}) ]AnimatedVectorImageView END]");
331 /// SetMinMaxFrame(int startFrame, int endFrame)
333 /// <param name="minFrame"></param>
334 /// <param name="maxFrame"></param>
335 [EditorBrowsable(EditorBrowsableState.Never)]
336 public new void SetMinMaxFrame(int minFrame, int maxFrame)
338 NUILog.Debug($"SetMinMaxFrame({minFrame}, {maxFrame})!!!");
340 minimumFrame = (minFrame) > 0 ? minFrame : 0;
341 maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
342 isMinMaxFrameSet = minMaxSetTypes.SetByBaseSetMinMaxFrameMethod;
344 if (minimumFrame >= totalFrameNum)
346 minimumFrame = totalFrameNum - 1;
349 if (maximumFrame >= totalFrameNum)
351 maximumFrame = totalFrameNum - 1;
354 base.SetMinMaxFrame(minimumFrame, maximumFrame);
358 /// A marker has its start frame and end frame.
359 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
360 /// 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. *
362 /// <param name="marker1">First marker</param>
363 /// <param name="marker2">Second marker</param>
364 [EditorBrowsable(EditorBrowsableState.Never)]
365 public new void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
367 NUILog.Debug($"SetMinMaxFrameByMarker({marker1}, {marker2})");
368 isMinMaxFrameSet = minMaxSetTypes.SetByMarker;
369 base.SetMinMaxFrameByMarker(marker1, marker2);
375 [EditorBrowsable(EditorBrowsableState.Never)]
376 public new void Play()
378 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
380 if (string.IsNullOrEmpty(resourceUrl))
382 throw new InvalidOperationException("Resource Url not yet Set");
385 switch (isMinMaxFrameSet)
387 case minMaxSetTypes.NotSetByUser:
388 base.SetMinMaxFrame(0, totalFrameNum - 1);
389 base.CurrentFrame = 0;
390 innerCurrentFrame = 0;
393 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
394 base.SetMinMaxFrame(minimumFrame, maximumFrame);
395 base.CurrentFrame = minimumFrame;
396 innerCurrentFrame = minimumFrame;
399 case minMaxSetTypes.SetByMarker:
400 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
407 AnimationState = AnimationStates.Playing;
409 NUILog.Debug($" [{GetId()}] isMinMaxFrameSet={isMinMaxFrameSet}) ]AnimatedVectorImageView END]");
415 [EditorBrowsable(EditorBrowsableState.Never)]
416 public new void Pause()
418 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
420 if (string.IsNullOrEmpty(resourceUrl))
422 throw new InvalidOperationException("Resource Url not yet Set");
426 AnimationState = AnimationStates.Paused;
428 NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
434 /// <param name="endAction">Defines, what should be behaviour after cancel operation
435 /// End action is Cancel, Animation Stops at the Current Frame.
436 /// End action is Discard, Animation Stops at the Min Frame
437 /// End action is StopFinal, Animation Stops at the Max Frame
439 [EditorBrowsable(EditorBrowsableState.Never)]
440 public void Stop(EndActions endAction = EndActions.Cancel)
442 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] endAction:({endAction}), PlayState={PlayState}");
444 if (string.IsNullOrEmpty(resourceUrl))
446 throw new InvalidOperationException("Resource Url not yet Set");
449 if (AnimationState == AnimationStates.Stopped)
454 if (innerEndAction != endAction)
456 innerEndAction = endAction;
459 case EndActions.Cancel:
460 StopBehavior = StopBehaviorType.CurrentFrame;
462 case EndActions.Discard:
463 StopBehavior = StopBehaviorType.MinimumFrame;
465 case EndActions.StopFinal:
466 StopBehavior = StopBehaviorType.MaximumFrame;
469 NUILog.Debug($" [{GetId()}] no endAction : default set");
473 AnimationState = AnimationStates.Stopped;
477 NUILog.Debug($"isMinMaxFrameSet:{isMinMaxFrameSet}, base.CurrentFrame:{base.CurrentFrame}, totalFrameNum:{totalFrameNum}, minimumFrame:{minimumFrame}, maximumFrame:{maximumFrame}, StopBehavior:{StopBehavior}, endAction:{endAction}");
479 switch (isMinMaxFrameSet)
481 case minMaxSetTypes.NotSetByUser:
484 case EndActions.Cancel:
485 innerCurrentFrame = base.CurrentFrame;
487 case EndActions.Discard:
488 base.CurrentFrame = innerCurrentFrame = 0;
490 case EndActions.StopFinal:
491 base.CurrentFrame = innerCurrentFrame= totalFrameNum - 1;
496 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
499 case EndActions.Cancel:
500 innerCurrentFrame = base.CurrentFrame;
502 case EndActions.Discard:
503 base.CurrentFrame = innerCurrentFrame = minimumFrame;
505 case EndActions.StopFinal:
506 base.CurrentFrame = innerCurrentFrame = maximumFrame;
510 case minMaxSetTypes.SetByMarker:
511 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
516 NUILog.Debug($" [{GetId()}] innerCurrentFrame={innerCurrentFrame}, base.CurrentFrame={base.CurrentFrame}");
517 NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
522 #region Event, Enum, Struct, ETC
524 /// RepeatMode of animation.
526 // Suppress warning : This has been being used by users, so that the interface can not be changed.
527 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
528 [EditorBrowsable(EditorBrowsableState.Never)]
529 public enum RepeatModes
532 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
534 [EditorBrowsable(EditorBrowsableState.Never)]
535 Restart = LoopingModeType.Restart,
537 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
539 [EditorBrowsable(EditorBrowsableState.Never)]
540 Reverse = LoopingModeType.AutoReverse
544 /// EndActions of animation.
546 // Suppress warning : This has been being used by users, so that the interface can not be changed.
547 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
548 [EditorBrowsable(EditorBrowsableState.Never)]
549 public enum EndActions
551 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
552 [EditorBrowsable(EditorBrowsableState.Never)]
554 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
555 [EditorBrowsable(EditorBrowsableState.Never)]
557 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
558 [EditorBrowsable(EditorBrowsableState.Never)]
563 /// AnimationStates of animation.
565 // Suppress warning : This has been being used by users, so that the interface can not be changed.
566 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
567 [EditorBrowsable(EditorBrowsableState.Never)]
568 public enum AnimationStates
570 /// <summary> The animation has stopped.</summary>
571 [EditorBrowsable(EditorBrowsableState.Never)]
572 Stopped = PlayStateType.Stopped,
573 /// <summary> The animation is playing.</summary>
574 [EditorBrowsable(EditorBrowsableState.Never)]
575 Playing = PlayStateType.Playing,
576 /// <summary> The animation is paused.</summary>
577 [EditorBrowsable(EditorBrowsableState.Never)]
578 Paused = PlayStateType.Paused
580 #endregion Event, Enum, Struct, ETC
588 private string resourceUrl = null;
589 private int repeatCnt = 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 AnimationStates CurrentAnimationState = AnimationStates.Stopped;
604 private const int IntegerMaxValue = 0x7FFFFFFF;