2 * Copyright(c) 2019 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 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
31 [EditorBrowsable(EditorBrowsableState.Never)]
32 public class AnimatedVectorImageView : LottieAnimationView
34 #region Constructor, Distructor, Dispose
36 /// Construct VectorAnimationView.
38 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
39 [EditorBrowsable(EditorBrowsableState.Never)]
40 public AnimatedVectorImageView() : base()
42 tlog.Fatal(tag, $"[VAV START[ constuctor objId={GetId()} ]VAV END]");
46 /// Construct VectorAnimationView.
48 /// <param name="scale">Set scaling factor for Vector Animation, while creating.</param>
49 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 public AnimatedVectorImageView(float scale) : base(scale)
53 tlog.Fatal(tag, $"[VAV START[ constuctor scale={scale}) objId={GetId()} ]VAV END]");
57 /// You can override it to clean-up your own resources
59 /// <param name="type">DisposeTypes</param>
60 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
61 [EditorBrowsable(EditorBrowsableState.Never)]
62 protected override void Dispose(DisposeTypes type)
68 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] type={type})");
70 //Release your own unmanaged resources here.
71 //You should not access any managed member here except static instance.
72 //because the execution order of Finalizes is non-deterministic.
76 tlog.Fatal(tag, $"]VAV END]");
78 #endregion Constructor, Distructor, Dispose
85 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public string ResourceURL
91 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] ResourceURL SET");
93 if (value == mResourceURL)
95 tlog.Fatal(tag, $"set same URL! ");
98 mResourceURL = (value == null) ? "" : value;
100 mIsMinMaxSet = minMaxSetTypes.NotSetByUser;
101 mTotalFrameNum = base.TotalFrame;
102 tlog.Fatal(tag, $" [{GetId()}] mResourceURL={mResourceURL}) ]VAV END]");
110 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
111 [EditorBrowsable(EditorBrowsableState.Never)]
112 public new string ResourceUrl
116 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] ResourceUrl SET");
117 this.ResourceURL = value;
118 tlog.Fatal(tag, $" [{GetId()}] value={value}) ]VAV END]");
122 tlog.Fatal(tag, $"[VAV [ [{GetId()}] ResourceUrl GET");
123 return this.ResourceURL;
129 /// RepeatCount of animation.
130 /// The repeat count is 0 by default.
131 /// If the RepeatCount is 0, the animation is never repeated.
132 /// If the RepeatCount is greater than 0, the repeat mode will be taken into account.
133 /// If RepeatCount is -1, animation is infinite loops.
135 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
136 [EditorBrowsable(EditorBrowsableState.Never)]
137 public int RepeatCount
141 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] RepeatCount SET");
143 mRepeatCount = (value < -1) ? -1 : value;
144 LoopCount = (mRepeatCount < 0) ? mRepeatCount : mRepeatCount + 1;
146 tlog.Fatal(tag, $"[{GetId()}] mRepeatCount={mRepeatCount} ]VAV END]");
152 /// TotalFrame of animation.
154 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
155 [EditorBrowsable(EditorBrowsableState.Never)]
156 public new int TotalFrame
158 get => mTotalFrameNum;
162 /// CurrentFrame of animation.
164 /// <returns> Returns user set value for the current frame. Cannot provide actual playing current frame. </returns>
165 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
166 [EditorBrowsable(EditorBrowsableState.Never)]
167 public new int CurrentFrame
171 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] CurrentFrame SET");
173 if (string.IsNullOrEmpty(mResourceURL))
175 throw new InvalidOperationException("Resource Url not yet Set");
182 else if (value >= mTotalFrameNum)
184 value = mTotalFrameNum - 1;
187 mCurrentFrame = value;
188 AnimationState = State.Paused;
190 base.SetMinMaxFrame(0, mTotalFrameNum - 1);
191 base.CurrentFrame = mCurrentFrame;
193 tlog.Fatal(tag, $" [{GetId()}] mCurrentFrame={mCurrentFrame}) ]VAV END]");
195 get => mCurrentFrame;
199 /// RepeatMode of animation.
201 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
202 [EditorBrowsable(EditorBrowsableState.Never)]
203 public RepeatModeType RepeatMode
207 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] RepeatMode SET");
212 case RepeatModeType.Restart:
213 LoopingMode = LoopingModeType.Restart;
215 case RepeatModeType.Reverse:
216 LoopingMode = LoopingModeType.AutoReverse;
219 LoopingMode = LoopingModeType.Restart;
223 tlog.Fatal(tag, $" [{GetId()}] mRepeatMode={mRepeatMode}) ]VAV END]");
229 /// Get state of animation.
231 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
232 [EditorBrowsable(EditorBrowsableState.Never)]
233 public State AnimationState
237 CurrentAnimationState = value;
241 if (CurrentAnimationState == State.Playing)
243 if (PlayState == PlayStateType.Stopped)
245 CurrentAnimationState = State.Stopped;
248 return CurrentAnimationState;
256 /// Set minimum frame and maximum frame
258 /// <param name="minFrame">minimum frame.</param>
259 /// <param name="maxFrame">maximum frame.</param>
260 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
261 [EditorBrowsable(EditorBrowsableState.Never)]
262 public void SetMinAndMaxFrame(int minFrame, int maxFrame)
264 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] SetMinAndMaxFrame({minFrame}, {maxFrame})");
266 mMinFrame = (minFrame) > 0 ? minFrame : 0;
267 mMaxFrame = (maxFrame) > 0 ? maxFrame : 0;
268 mIsMinMaxSet = minMaxSetTypes.SetByMinAndMaxFrameMethod;
270 if (mMinFrame >= mTotalFrameNum)
272 mMinFrame = mTotalFrameNum - 1;
275 if (mMaxFrame >= mTotalFrameNum)
277 mMaxFrame = mTotalFrameNum - 1;
280 if (mMinFrame > mMaxFrame)
285 tlog.Fatal(tag, $" [{GetId()}] mMinFrame:{mMinFrame}, mMaxFrame:{mMaxFrame}) ]VAV END]");
289 /// SetMinMaxFrame(int startFrame, int endFrame)
291 /// <param name="minFrame"></param>
292 /// <param name="maxFrame"></param>
293 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
294 [EditorBrowsable(EditorBrowsableState.Never)]
295 public new void SetMinMaxFrame(int minFrame, int maxFrame)
297 tlog.Fatal(tag, $"SetMinMaxFrame({minFrame}, {maxFrame})!!!");
299 mMinFrame = (minFrame) > 0 ? minFrame : 0;
300 mMaxFrame = (maxFrame) > 0 ? maxFrame : 0;
301 mIsMinMaxSet = minMaxSetTypes.SetByBaseSetMinMaxFrameMethod;
303 if (mMinFrame >= mTotalFrameNum)
305 mMinFrame = mTotalFrameNum - 1;
308 if (mMaxFrame >= mTotalFrameNum)
310 mMaxFrame = mTotalFrameNum - 1;
313 base.SetMinMaxFrame(mMinFrame, mMaxFrame);
317 /// A marker has its start frame and end frame.
318 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
319 /// 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. *
321 /// <param name="marker1">First marker</param>
322 /// <param name="marker2">Second marker</param>
323 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
324 [EditorBrowsable(EditorBrowsableState.Never)]
325 public new void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
327 tlog.Fatal(tag, $"SetMinMaxFrameByMarker({marker1}, {marker2})");
328 mIsMinMaxSet = minMaxSetTypes.SetByMarker;
329 base.SetMinMaxFrameByMarker(marker1, marker2);
335 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
336 [EditorBrowsable(EditorBrowsableState.Never)]
337 public new void Play()
339 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
341 if (string.IsNullOrEmpty(mResourceURL))
343 throw new InvalidOperationException("Resource Url not yet Set");
346 switch (mIsMinMaxSet)
348 case minMaxSetTypes.NotSetByUser:
349 base.SetMinMaxFrame(0, mTotalFrameNum - 1);
350 base.CurrentFrame = 0;
353 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
354 base.SetMinMaxFrame(mMinFrame, mMaxFrame);
355 base.CurrentFrame = mMinFrame;
358 case minMaxSetTypes.SetByMarker:
359 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
366 Extents tmp = base.Margin;
370 AnimationState = State.Playing;
372 tlog.Fatal(tag, $" [{GetId()}] mIsMinMaxSet={mIsMinMaxSet}) ]VAV END]");
378 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
379 [EditorBrowsable(EditorBrowsableState.Never)]
380 public new void Pause()
382 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
384 if (string.IsNullOrEmpty(mResourceURL))
386 throw new InvalidOperationException("Resource Url not yet Set");
390 AnimationState = State.Paused;
392 tlog.Fatal(tag, $" [{GetId()}] ]VAV END]");
398 /// <param name="endAction">Defines, what should be behaviour after cancel operation
399 /// End action is Cancel, Animation Stops at the Current Frame.
400 /// End action is Discard, Animation Stops at the Min Frame
401 /// End action is StopFinal, Animation Stops at the Max Frame
403 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
404 [EditorBrowsable(EditorBrowsableState.Never)]
405 public void Stop(EndAction endAction = EndAction.Cancel)
407 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] endAction:({endAction}), PlayState={PlayState}");
409 if (string.IsNullOrEmpty(mResourceURL))
411 throw new InvalidOperationException("Resource Url not yet Set");
414 if (AnimationState == State.Stopped)
419 if (mEndAction != endAction)
421 mEndAction = endAction;
424 case EndAction.Cancel:
425 StopBehavior = StopBehaviorType.CurrentFrame;
427 case EndAction.Discard:
428 StopBehavior = StopBehaviorType.MinimumFrame;
430 case EndAction.StopFinal:
431 StopBehavior = StopBehaviorType.MaximumFrame;
434 tlog.Fatal(tag, $" [{GetId()}] no endAction : default set");
438 AnimationState = State.Stopped;
442 if (endAction == EndAction.StopFinal)
444 switch (mIsMinMaxSet)
446 case minMaxSetTypes.NotSetByUser:
447 if (base.CurrentFrame != mTotalFrameNum - 1)
449 tlog.Fatal(tag, $"mIsMinMaxSet:{mIsMinMaxSet}, CurrentFrameNumber:{base.CurrentFrame}, mTotalFrameNum:{ mTotalFrameNum}");
450 base.CurrentFrame = mTotalFrameNum - 1;
451 tlog.Fatal(tag, $"set CurrentFrameNumber({base.CurrentFrame}) as mTotalFrameNum({mMaxFrame}) - 1 !");
455 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
456 if (base.CurrentFrame != mMaxFrame)
458 tlog.Fatal(tag, $"mIsMinMaxSet:{mIsMinMaxSet}, CurrentFrameNumber:{base.CurrentFrame}, mMaxFrame:{ mMaxFrame}");
459 base.CurrentFrame = mMaxFrame;
460 tlog.Fatal(tag, $"set CurrentFrameNumber({base.CurrentFrame}) as mMaxFrame({mMaxFrame})!!!");
463 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
464 case minMaxSetTypes.SetByMarker:
470 tlog.Fatal(tag, $" [{GetId()}] ]VAV END]");
475 #region Event, Enum, Struct, ETC
477 /// RepeatMode of animation.
479 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.RepeatModeType instead!")]
480 [EditorBrowsable(EditorBrowsableState.Never)]
481 public enum RepeatModes
484 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
486 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.RepeatModeType.Restart instead!")]
487 [EditorBrowsable(EditorBrowsableState.Never)]
488 Restart = LoopingModeType.Restart,
490 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
492 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.RepeatModeType.Reverse instead!")]
493 [EditorBrowsable(EditorBrowsableState.Never)]
494 Reverse = LoopingModeType.AutoReverse
498 /// RepeatMode type of animation.
500 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
501 [EditorBrowsable(EditorBrowsableState.Never)]
502 public enum RepeatModeType
505 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
507 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
508 [EditorBrowsable(EditorBrowsableState.Never)]
509 Restart = LoopingModeType.Restart,
511 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
513 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
514 [EditorBrowsable(EditorBrowsableState.Never)]
515 Reverse = LoopingModeType.AutoReverse
519 /// EndActions of animation.
521 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.EndAction instead!")]
522 [EditorBrowsable(EditorBrowsableState.Never)]
523 public enum EndActions
525 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
526 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.EndAction.Cancel instead!")]
527 [EditorBrowsable(EditorBrowsableState.Never)]
529 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
530 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.EndAction.Discard instead!")]
531 [EditorBrowsable(EditorBrowsableState.Never)]
533 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
534 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.EndAction.StopFinal instead!")]
535 [EditorBrowsable(EditorBrowsableState.Never)]
540 /// EndAction of animation.
542 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
543 [EditorBrowsable(EditorBrowsableState.Never)]
544 public enum EndAction
546 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
547 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
548 [EditorBrowsable(EditorBrowsableState.Never)]
550 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
551 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
552 [EditorBrowsable(EditorBrowsableState.Never)]
554 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
555 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
556 [EditorBrowsable(EditorBrowsableState.Never)]
561 /// AnimationState of animation.
563 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.State instead!")]
564 [EditorBrowsable(EditorBrowsableState.Never)]
565 public enum AnimationStates
567 /// <summary> The animation has stopped.</summary>
568 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.State.Stopped instead!")]
569 [EditorBrowsable(EditorBrowsableState.Never)]
570 Stopped = PlayStateType.Stopped,
571 /// <summary> The animation is playing.</summary>
572 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.State.Playing instead!")]
573 [EditorBrowsable(EditorBrowsableState.Never)]
574 Playing = PlayStateType.Playing,
575 /// <summary> The animation is paused.</summary>
576 [Obsolete("Please do not use! This will be removed. Please use AnimatedVectorImageView.State.Paused instead!")]
577 [EditorBrowsable(EditorBrowsableState.Never)]
578 Paused = PlayStateType.Paused
582 /// Animation State of animation.
584 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
585 [EditorBrowsable(EditorBrowsableState.Never)]
588 /// <summary> The animation has stopped.</summary>
589 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
590 [EditorBrowsable(EditorBrowsableState.Never)]
591 Stopped = PlayStateType.Stopped,
592 /// <summary> The animation is playing.</summary>
593 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
594 [EditorBrowsable(EditorBrowsableState.Never)]
595 Playing = PlayStateType.Playing,
596 /// <summary> The animation is paused.</summary>
597 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
598 [EditorBrowsable(EditorBrowsableState.Never)]
599 Paused = PlayStateType.Paused
601 #endregion Event, Enum, Struct, ETC
609 private string mResourceURL = null;
610 private int mRepeatCount = 0;
611 private int mTotalFrameNum = 0;
612 private RepeatModeType mRepeatMode = RepeatModeType.Restart;
613 private int mMinFrame = -1, mMaxFrame = -1;
614 private minMaxSetTypes mIsMinMaxSet = minMaxSetTypes.NotSetByUser;
615 private int mCurrentFrame = -1;
616 private EndAction mEndAction = EndAction.Cancel;
617 private enum minMaxSetTypes
620 SetByMinAndMaxFrameMethod,
622 SetByBaseSetMinMaxFrameMethod,
625 private string tag = "NUITEST";
626 private State CurrentAnimationState = State.Stopped;