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.CurrentFrame = innerCurrentFrame;
233 NUILog.Debug($" [{GetId()}] innerCurrentFrame={innerCurrentFrame}) ]AnimatedVectorImageView END]");
235 get => innerCurrentFrame;
239 /// RepeatMode of animation.
241 [EditorBrowsable(EditorBrowsableState.Never)]
242 public RepeatModes RepeatMode
246 return (RepeatModes)GetValue(RepeatModeProperty);
250 SetValue(RepeatModeProperty, value);
251 NotifyPropertyChanged();
255 private RepeatModes InternalRepeatMode
259 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] RepeatMode SET");
264 case RepeatModes.Restart:
265 LoopingMode = LoopingModeType.Restart;
267 case RepeatModes.Reverse:
268 LoopingMode = LoopingModeType.AutoReverse;
271 LoopingMode = LoopingModeType.Restart;
275 NUILog.Debug($" [{GetId()}] repeatMode={repeatMode}) ]AnimatedVectorImageView END]");
281 /// Get state of animation.
283 [EditorBrowsable(EditorBrowsableState.Never)]
284 public AnimationStates AnimationState
288 CurrentAnimationState = value;
292 if (CurrentAnimationState == AnimationStates.Playing)
294 if (PlayState == PlayStateType.Stopped)
296 CurrentAnimationState = AnimationStates.Stopped;
299 return CurrentAnimationState;
307 /// Set minimum frame and maximum frame
309 /// <param name="minFrame">minimum frame.</param>
310 /// <param name="maxFrame">maximum frame.</param>
311 [EditorBrowsable(EditorBrowsableState.Never)]
312 public void SetMinAndMaxFrame(int minFrame, int maxFrame)
314 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] SetMinAndMaxFrame({minFrame}, {maxFrame})");
316 minimumFrame = (minFrame) > 0 ? minFrame : 0;
317 maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
318 isMinMaxFrameSet = minMaxSetTypes.SetByMinAndMaxFrameMethod;
320 if (minimumFrame > maximumFrame)
322 NUILog.Debug($" [{GetId()}] minimumFrame:{minimumFrame} > maximumFrame:{maximumFrame}) ]AnimatedVectorImageView END]");
326 NUILog.Debug($" [{GetId()}] minimumFrame:{minimumFrame}, maximumFrame:{maximumFrame}) ]AnimatedVectorImageView END]");
330 /// SetMinMaxFrame(int startFrame, int endFrame)
332 /// <param name="minFrame"></param>
333 /// <param name="maxFrame"></param>
334 [EditorBrowsable(EditorBrowsableState.Never)]
335 public new void SetMinMaxFrame(int minFrame, int maxFrame)
337 NUILog.Debug($"SetMinMaxFrame({minFrame}, {maxFrame})!!!");
339 minimumFrame = (minFrame) > 0 ? minFrame : 0;
340 maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
341 isMinMaxFrameSet = minMaxSetTypes.SetByBaseSetMinMaxFrameMethod;
343 if (minimumFrame >= totalFrameNum)
345 minimumFrame = totalFrameNum - 1;
348 if (maximumFrame >= totalFrameNum)
350 maximumFrame = totalFrameNum - 1;
353 base.SetMinMaxFrame(minimumFrame, maximumFrame);
357 /// A marker has its start frame and end frame.
358 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
359 /// 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. *
361 /// <param name="marker1">First marker</param>
362 /// <param name="marker2">Second marker</param>
363 [EditorBrowsable(EditorBrowsableState.Never)]
364 public new void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
366 NUILog.Debug($"SetMinMaxFrameByMarker({marker1}, {marker2})");
367 isMinMaxFrameSet = minMaxSetTypes.SetByMarker;
368 base.SetMinMaxFrameByMarker(marker1, marker2);
374 [EditorBrowsable(EditorBrowsableState.Never)]
375 public new void Play()
377 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
379 if (string.IsNullOrEmpty(resourceUrl))
381 throw new InvalidOperationException("Resource Url not yet Set");
384 switch (isMinMaxFrameSet)
386 case minMaxSetTypes.NotSetByUser:
387 base.SetMinMaxFrame(0, totalFrameNum - 1);
388 base.CurrentFrame = 0;
389 innerCurrentFrame = 0;
392 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
393 base.SetMinMaxFrame(minimumFrame, maximumFrame);
394 base.CurrentFrame = minimumFrame;
395 innerCurrentFrame = minimumFrame;
398 case minMaxSetTypes.SetByMarker:
399 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
406 Extents tmp = base.Margin;
410 AnimationState = AnimationStates.Playing;
412 NUILog.Debug($" [{GetId()}] isMinMaxFrameSet={isMinMaxFrameSet}) ]AnimatedVectorImageView END]");
418 [EditorBrowsable(EditorBrowsableState.Never)]
419 public new void Pause()
421 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
423 if (string.IsNullOrEmpty(resourceUrl))
425 throw new InvalidOperationException("Resource Url not yet Set");
429 AnimationState = AnimationStates.Paused;
431 NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
437 /// <param name="endAction">Defines, what should be behaviour after cancel operation
438 /// End action is Cancel, Animation Stops at the Current Frame.
439 /// End action is Discard, Animation Stops at the Min Frame
440 /// End action is StopFinal, Animation Stops at the Max Frame
442 [EditorBrowsable(EditorBrowsableState.Never)]
443 public void Stop(EndActions endAction = EndActions.Cancel)
445 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] endAction:({endAction}), PlayState={PlayState}");
447 if (string.IsNullOrEmpty(resourceUrl))
449 throw new InvalidOperationException("Resource Url not yet Set");
452 if (AnimationState == AnimationStates.Stopped)
457 if (innerEndAction != endAction)
459 innerEndAction = endAction;
462 case EndActions.Cancel:
463 StopBehavior = StopBehaviorType.CurrentFrame;
465 case EndActions.Discard:
466 StopBehavior = StopBehaviorType.MinimumFrame;
468 case EndActions.StopFinal:
469 StopBehavior = StopBehaviorType.MaximumFrame;
472 NUILog.Debug($" [{GetId()}] no endAction : default set");
476 AnimationState = AnimationStates.Stopped;
480 NUILog.Debug($"isMinMaxFrameSet:{isMinMaxFrameSet}, base.CurrentFrame:{base.CurrentFrame}, totalFrameNum:{totalFrameNum}, minimumFrame:{minimumFrame}, maximumFrame:{maximumFrame}, StopBehavior:{StopBehavior}, endAction:{endAction}");
482 switch (isMinMaxFrameSet)
484 case minMaxSetTypes.NotSetByUser:
487 case EndActions.Cancel:
488 innerCurrentFrame = base.CurrentFrame;
490 case EndActions.Discard:
491 base.CurrentFrame = innerCurrentFrame = 0;
493 case EndActions.StopFinal:
494 base.CurrentFrame = innerCurrentFrame= totalFrameNum - 1;
499 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
502 case EndActions.Cancel:
503 innerCurrentFrame = base.CurrentFrame;
505 case EndActions.Discard:
506 base.CurrentFrame = innerCurrentFrame = minimumFrame;
508 case EndActions.StopFinal:
509 base.CurrentFrame = innerCurrentFrame = maximumFrame;
513 case minMaxSetTypes.SetByMarker:
514 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
519 NUILog.Debug($" [{GetId()}] innerCurrentFrame={innerCurrentFrame}, base.CurrentFrame={base.CurrentFrame}");
520 NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
525 #region Event, Enum, Struct, ETC
527 /// RepeatMode of animation.
529 // Suppress warning : This has been being used by users, so that the interface can not be changed.
530 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
531 [EditorBrowsable(EditorBrowsableState.Never)]
532 public enum RepeatModes
535 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
537 [EditorBrowsable(EditorBrowsableState.Never)]
538 Restart = LoopingModeType.Restart,
540 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
542 [EditorBrowsable(EditorBrowsableState.Never)]
543 Reverse = LoopingModeType.AutoReverse
547 /// EndActions of animation.
549 // Suppress warning : This has been being used by users, so that the interface can not be changed.
550 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
551 [EditorBrowsable(EditorBrowsableState.Never)]
552 public enum EndActions
554 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
555 [EditorBrowsable(EditorBrowsableState.Never)]
557 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
558 [EditorBrowsable(EditorBrowsableState.Never)]
560 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
561 [EditorBrowsable(EditorBrowsableState.Never)]
566 /// AnimationStates of animation.
568 // Suppress warning : This has been being used by users, so that the interface can not be changed.
569 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
570 [EditorBrowsable(EditorBrowsableState.Never)]
571 public enum AnimationStates
573 /// <summary> The animation has stopped.</summary>
574 [EditorBrowsable(EditorBrowsableState.Never)]
575 Stopped = PlayStateType.Stopped,
576 /// <summary> The animation is playing.</summary>
577 [EditorBrowsable(EditorBrowsableState.Never)]
578 Playing = PlayStateType.Playing,
579 /// <summary> The animation is paused.</summary>
580 [EditorBrowsable(EditorBrowsableState.Never)]
581 Paused = PlayStateType.Paused
583 #endregion Event, Enum, Struct, ETC
591 private string resourceUrl = null;
592 private int repeatCnt = 0;
593 private RepeatModes repeatMode = RepeatModes.Restart;
594 private int minimumFrame = -1, maximumFrame = -1;
595 private minMaxSetTypes isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
596 private int innerCurrentFrame = -1;
597 private EndActions innerEndAction = EndActions.Cancel;
598 private enum minMaxSetTypes
601 SetByMinAndMaxFrameMethod,
603 SetByBaseSetMinMaxFrameMethod,
606 private AnimationStates CurrentAnimationState = AnimationStates.Stopped;