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 using tlog = Tizen.Log;
28 /// AnimatedVectorImageView is a class for displaying a vector resource.
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class AnimatedVectorImageView : LottieAnimationView
33 #region Constructor, Destructor, Dispose
35 /// Construct VectorAnimationView.
37 [EditorBrowsable(EditorBrowsableState.Never)]
38 public AnimatedVectorImageView() : base()
40 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ constructor objId={GetId()} ] END]");
44 /// Construct VectorAnimationView.
46 /// <param name="scale">Set scaling factor for Vector Animation, while creating.</param>
47 [EditorBrowsable(EditorBrowsableState.Never)]
48 public AnimatedVectorImageView(float scale) : base(scale)
50 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ constructor scale={scale}) objId={GetId()} ] END]");
54 /// You can override it to clean-up your own resources
56 /// <param name="type">DisposeTypes</param>
57 [EditorBrowsable(EditorBrowsableState.Never)]
58 protected override void Dispose(DisposeTypes type)
64 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] type={type})");
66 //Release your own unmanaged resources here.
67 //You should not access any managed member here except static instance.
68 //because the execution order of Finalizes is non-deterministic.
72 tlog.Fatal(tag, $"]AnimatedVectorImageView END]");
74 #endregion Constructor, Destructor, Dispose
81 // Suppress warning : This has been being used by users, so that the interface can not be changed.
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 public string ResourceURL
87 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] ResourceURL SET");
89 if (value == resourceUrl)
91 tlog.Fatal(tag, $"set same URL! ");
94 resourceUrl = (value == null) ? "" : value;
96 isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
97 totalFrameNum = base.TotalFrame;
98 tlog.Fatal(tag, $" [{GetId()}] resourceUrl={resourceUrl}) ]AnimatedVectorImageView END]");
106 // Suppress warning : This has been being used by users, so that the interface can not be changed.
107 [EditorBrowsable(EditorBrowsableState.Never)]
108 public new string ResourceUrl
112 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] ResourceUrl SET");
113 this.ResourceURL = value;
114 tlog.Fatal(tag, $" [{GetId()}] value={value}) ]AnimatedVectorImageView END]");
118 tlog.Fatal(tag, $"[AnimatedVectorImageView [ [{GetId()}] ResourceUrl GET");
119 return this.ResourceURL;
125 /// RepeatCount of animation.
126 /// The repeat count is 0 by default.
127 /// If the RepeatCount is 0, the animation is never repeated.
128 /// If the RepeatCount is greater than 0, the repeat mode will be taken into account.
129 /// If RepeatCount is -1, animation is infinite loops.
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public int RepeatCount
136 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] RepeatCount SET");
138 repeatCnt = (value < -1) ? -1 : value;
139 LoopCount = (repeatCnt < 0) ? repeatCnt : repeatCnt + 1;
141 tlog.Fatal(tag, $"[{GetId()}] repeatCnt={repeatCnt} ]AnimatedVectorImageView END]");
147 /// TotalFrame of animation.
149 [EditorBrowsable(EditorBrowsableState.Never)]
150 public new int TotalFrame
152 get => totalFrameNum;
156 /// CurrentFrame of animation.
158 /// <returns> Returns user set value for the current frame. Cannot provide actual playing current frame. </returns>
159 [EditorBrowsable(EditorBrowsableState.Never)]
160 public new int CurrentFrame
164 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] CurrentFrame SET");
166 if (string.IsNullOrEmpty(resourceUrl))
168 throw new InvalidOperationException("Resource Url not yet Set");
175 else if (value >= totalFrameNum)
177 value = totalFrameNum - 1;
180 innerCurrentFrame = value;
181 AnimationState = AnimationStates.Paused;
183 base.SetMinMaxFrame(0, totalFrameNum - 1);
184 base.CurrentFrame = innerCurrentFrame;
186 tlog.Fatal(tag, $" [{GetId()}] innerCurrentFrame={innerCurrentFrame}) ]AnimatedVectorImageView END]");
188 get => innerCurrentFrame;
192 /// RepeatMode of animation.
194 [EditorBrowsable(EditorBrowsableState.Never)]
195 public RepeatModes RepeatMode
199 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] RepeatMode SET");
204 case RepeatModes.Restart:
205 LoopingMode = LoopingModeType.Restart;
207 case RepeatModes.Reverse:
208 LoopingMode = LoopingModeType.AutoReverse;
211 LoopingMode = LoopingModeType.Restart;
215 tlog.Fatal(tag, $" [{GetId()}] repeatMode={repeatMode}) ]AnimatedVectorImageView END]");
221 /// Get state of animation.
223 [EditorBrowsable(EditorBrowsableState.Never)]
224 public AnimationStates AnimationState
228 CurrentAnimationState = value;
232 if (CurrentAnimationState == AnimationStates.Playing)
234 if (PlayState == PlayStateType.Stopped)
236 CurrentAnimationState = AnimationStates.Stopped;
239 return CurrentAnimationState;
247 /// Set minimum frame and maximum frame
249 /// <param name="minFrame">minimum frame.</param>
250 /// <param name="maxFrame">maximum frame.</param>
251 [EditorBrowsable(EditorBrowsableState.Never)]
252 public void SetMinAndMaxFrame(int minFrame, int maxFrame)
254 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] SetMinAndMaxFrame({minFrame}, {maxFrame})");
256 minimumFrame = (minFrame) > 0 ? minFrame : 0;
257 maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
258 isMinMaxFrameSet = minMaxSetTypes.SetByMinAndMaxFrameMethod;
260 if (minimumFrame >= totalFrameNum)
262 minimumFrame = totalFrameNum - 1;
265 if (maximumFrame >= totalFrameNum)
267 maximumFrame = totalFrameNum - 1;
270 if (minimumFrame > maximumFrame)
275 tlog.Fatal(tag, $" [{GetId()}] minimumFrame:{minimumFrame}, maximumFrame:{maximumFrame}) ]AnimatedVectorImageView END]");
279 /// SetMinMaxFrame(int startFrame, int endFrame)
281 /// <param name="minFrame"></param>
282 /// <param name="maxFrame"></param>
283 [EditorBrowsable(EditorBrowsableState.Never)]
284 public new void SetMinMaxFrame(int minFrame, int maxFrame)
286 tlog.Fatal(tag, $"SetMinMaxFrame({minFrame}, {maxFrame})!!!");
288 minimumFrame = (minFrame) > 0 ? minFrame : 0;
289 maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
290 isMinMaxFrameSet = minMaxSetTypes.SetByBaseSetMinMaxFrameMethod;
292 if (minimumFrame >= totalFrameNum)
294 minimumFrame = totalFrameNum - 1;
297 if (maximumFrame >= totalFrameNum)
299 maximumFrame = totalFrameNum - 1;
302 base.SetMinMaxFrame(minimumFrame, maximumFrame);
306 /// A marker has its start frame and end frame.
307 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
308 /// 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. *
310 /// <param name="marker1">First marker</param>
311 /// <param name="marker2">Second marker</param>
312 [EditorBrowsable(EditorBrowsableState.Never)]
313 public new void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
315 tlog.Fatal(tag, $"SetMinMaxFrameByMarker({marker1}, {marker2})");
316 isMinMaxFrameSet = minMaxSetTypes.SetByMarker;
317 base.SetMinMaxFrameByMarker(marker1, marker2);
323 [EditorBrowsable(EditorBrowsableState.Never)]
324 public new void Play()
326 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
328 if (string.IsNullOrEmpty(resourceUrl))
330 throw new InvalidOperationException("Resource Url not yet Set");
333 switch (isMinMaxFrameSet)
335 case minMaxSetTypes.NotSetByUser:
336 base.SetMinMaxFrame(0, totalFrameNum - 1);
337 base.CurrentFrame = 0;
340 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
341 base.SetMinMaxFrame(minimumFrame, maximumFrame);
342 base.CurrentFrame = minimumFrame;
345 case minMaxSetTypes.SetByMarker:
346 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
353 Extents tmp = base.Margin;
357 AnimationState = AnimationStates.Playing;
359 tlog.Fatal(tag, $" [{GetId()}] isMinMaxFrameSet={isMinMaxFrameSet}) ]AnimatedVectorImageView END]");
365 [EditorBrowsable(EditorBrowsableState.Never)]
366 public new void Pause()
368 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
370 if (string.IsNullOrEmpty(resourceUrl))
372 throw new InvalidOperationException("Resource Url not yet Set");
376 AnimationState = AnimationStates.Paused;
378 tlog.Fatal(tag, $" [{GetId()}] ]AnimatedVectorImageView END]");
384 /// <param name="endAction">Defines, what should be behaviour after cancel operation
385 /// End action is Cancel, Animation Stops at the Current Frame.
386 /// End action is Discard, Animation Stops at the Min Frame
387 /// End action is StopFinal, Animation Stops at the Max Frame
389 [EditorBrowsable(EditorBrowsableState.Never)]
390 public void Stop(EndActions endAction = EndActions.Cancel)
392 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] endAction:({endAction}), PlayState={PlayState}");
394 if (string.IsNullOrEmpty(resourceUrl))
396 throw new InvalidOperationException("Resource Url not yet Set");
399 if (AnimationState == AnimationStates.Stopped)
404 if (innerEndAction != endAction)
406 innerEndAction = endAction;
409 case EndActions.Cancel:
410 StopBehavior = StopBehaviorType.CurrentFrame;
412 case EndActions.Discard:
413 StopBehavior = StopBehaviorType.MinimumFrame;
415 case EndActions.StopFinal:
416 StopBehavior = StopBehaviorType.MaximumFrame;
419 tlog.Fatal(tag, $" [{GetId()}] no endAction : default set");
423 AnimationState = AnimationStates.Stopped;
427 if (endAction == EndActions.StopFinal)
429 switch (isMinMaxFrameSet)
431 case minMaxSetTypes.NotSetByUser:
432 if (base.CurrentFrame != totalFrameNum - 1)
434 tlog.Fatal(tag, $"isMinMaxFrameSet:{isMinMaxFrameSet}, CurrentFrameNumber:{base.CurrentFrame}, totalFrameNum:{ totalFrameNum}");
435 base.CurrentFrame = totalFrameNum - 1;
436 tlog.Fatal(tag, $"set CurrentFrameNumber({base.CurrentFrame}) as totalFrameNum({maximumFrame}) - 1 !");
440 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
441 if (base.CurrentFrame != maximumFrame)
443 tlog.Fatal(tag, $"isMinMaxFrameSet:{isMinMaxFrameSet}, CurrentFrameNumber:{base.CurrentFrame}, maximumFrame:{ maximumFrame}");
444 base.CurrentFrame = maximumFrame;
445 tlog.Fatal(tag, $"set CurrentFrameNumber({base.CurrentFrame}) as maximumFrame({maximumFrame})!!!");
448 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
449 case minMaxSetTypes.SetByMarker:
455 tlog.Fatal(tag, $" [{GetId()}] ]AnimatedVectorImageView END]");
460 #region Event, Enum, Struct, ETC
462 /// RepeatMode of animation.
464 // Suppress warning : This has been being used by users, so that the interface can not be changed.
465 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
466 [EditorBrowsable(EditorBrowsableState.Never)]
467 public enum RepeatModes
470 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
472 [EditorBrowsable(EditorBrowsableState.Never)]
473 Restart = LoopingModeType.Restart,
475 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
477 [EditorBrowsable(EditorBrowsableState.Never)]
478 Reverse = LoopingModeType.AutoReverse
482 /// EndActions of animation.
484 // Suppress warning : This has been being used by users, so that the interface can not be changed.
485 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
486 [EditorBrowsable(EditorBrowsableState.Never)]
487 public enum EndActions
489 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
490 [EditorBrowsable(EditorBrowsableState.Never)]
492 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
493 [EditorBrowsable(EditorBrowsableState.Never)]
495 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
496 [EditorBrowsable(EditorBrowsableState.Never)]
501 /// AnimationStates of animation.
503 // Suppress warning : This has been being used by users, so that the interface can not be changed.
504 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
505 [EditorBrowsable(EditorBrowsableState.Never)]
506 public enum AnimationStates
508 /// <summary> The animation has stopped.</summary>
509 [EditorBrowsable(EditorBrowsableState.Never)]
510 Stopped = PlayStateType.Stopped,
511 /// <summary> The animation is playing.</summary>
512 [EditorBrowsable(EditorBrowsableState.Never)]
513 Playing = PlayStateType.Playing,
514 /// <summary> The animation is paused.</summary>
515 [EditorBrowsable(EditorBrowsableState.Never)]
516 Paused = PlayStateType.Paused
518 #endregion Event, Enum, Struct, ETC
526 private string resourceUrl = null;
527 private int repeatCnt = 0;
528 private int totalFrameNum = 0;
529 private RepeatModes repeatMode = RepeatModes.Restart;
530 private int minimumFrame = -1, maximumFrame = -1;
531 private minMaxSetTypes isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
532 private int innerCurrentFrame = -1;
533 private EndActions innerEndAction = EndActions.Cancel;
534 private enum minMaxSetTypes
537 SetByMinAndMaxFrameMethod,
539 SetByBaseSetMinMaxFrameMethod,
542 private string tag = "NUITEST";
543 private AnimationStates CurrentAnimationState = AnimationStates.Stopped;