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 (mResourceURL == null || mResourceURL == String.Empty)
175 throw new InvalidOperationException("Resource Url not yet Set");
182 else if (value >= mTotalFrameNum)
184 value = mTotalFrameNum - 1;
187 mCurrentFrame = value;
188 AnimationState = AnimationStates.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 RepeatModes RepeatMode
207 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] RepeatMode SET");
212 case RepeatModes.Restart:
213 LoopingMode = LoopingModeType.Restart;
215 case RepeatModes.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 AnimationStates AnimationState
243 /// Set minimum frame and maximum frame
245 /// <param name="minFrame">minimum frame.</param>
246 /// <param name="maxFrame">maximum frame.</param>
247 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
248 [EditorBrowsable(EditorBrowsableState.Never)]
249 public void SetMinAndMaxFrame(int minFrame, int maxFrame)
251 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] SetMinAndMaxFrame({minFrame}, {maxFrame})");
253 mMinFrame = (minFrame) > 0 ? minFrame : 0;
254 mMaxFrame = (maxFrame) > 0 ? maxFrame : 0;
255 mIsMinMaxSet = minMaxSetTypes.SetByMinAndMaxFrameMethod;
257 if (mMinFrame >= mTotalFrameNum)
259 mMinFrame = mTotalFrameNum - 1;
262 if (mMaxFrame >= mTotalFrameNum)
264 mMaxFrame = mTotalFrameNum - 1;
267 if (mMinFrame > mMaxFrame)
272 tlog.Fatal(tag, $" [{GetId()}] mMinFrame:{mMinFrame}, mMaxFrame:{mMaxFrame}) ]VAV END]");
276 /// SetMinMaxFrame(int startFrame, int endFrame)
278 /// <param name="minFrame"></param>
279 /// <param name="maxFrame"></param>
280 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
281 [EditorBrowsable(EditorBrowsableState.Never)]
282 public new void SetMinMaxFrame(int minFrame, int maxFrame)
284 tlog.Fatal(tag, $"SetMinMaxFrame({minFrame}, {maxFrame})!!!");
286 mMinFrame = (minFrame) > 0 ? minFrame : 0;
287 mMaxFrame = (maxFrame) > 0 ? maxFrame : 0;
288 mIsMinMaxSet = minMaxSetTypes.SetByBaseSetMinMaxFrameMethod;
290 if (mMinFrame >= mTotalFrameNum)
292 mMinFrame = mTotalFrameNum - 1;
295 if (mMaxFrame >= mTotalFrameNum)
297 mMaxFrame = mTotalFrameNum - 1;
300 base.SetMinMaxFrame(mMinFrame, mMaxFrame);
304 /// A marker has its start frame and end frame.
305 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
306 /// 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. *
308 /// <param name="marker1">First marker</param>
309 /// <param name="marker2">Second marker</param>
310 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
311 [EditorBrowsable(EditorBrowsableState.Never)]
312 public new void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
314 tlog.Fatal(tag, $"SetMinMaxFrameByMarker({marker1}, {marker2})");
315 mIsMinMaxSet = minMaxSetTypes.SetByMarker;
316 base.SetMinMaxFrameByMarker(marker1, marker2);
322 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
323 [EditorBrowsable(EditorBrowsableState.Never)]
324 public new void Play()
326 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
328 if (mResourceURL == null || mResourceURL == String.Empty)
330 throw new InvalidOperationException("Resource Url not yet Set");
333 switch (mIsMinMaxSet)
335 case minMaxSetTypes.NotSetByUser:
336 base.SetMinMaxFrame(0, mTotalFrameNum - 1);
337 base.CurrentFrame = 0;
340 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
341 base.SetMinMaxFrame(mMinFrame, mMaxFrame);
342 base.CurrentFrame = mMinFrame;
345 case minMaxSetTypes.SetByMarker:
346 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
353 Extents tmp = base.Margin;
357 AnimationState = AnimationStates.Playing;
359 tlog.Fatal(tag, $" [{GetId()}] mIsMinMaxSet={mIsMinMaxSet}) ]VAV END]");
365 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
366 [EditorBrowsable(EditorBrowsableState.Never)]
367 public new void Pause()
369 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
371 if (mResourceURL == null || mResourceURL == String.Empty)
373 throw new InvalidOperationException("Resource Url not yet Set");
377 AnimationState = AnimationStates.Paused;
379 tlog.Fatal(tag, $" [{GetId()}] ]VAV END]");
385 /// <param name="endAction">Defines, what should be behaviour after cancel operation
386 /// End action is Cancel, Animation Stops at the Current Frame.
387 /// End action is Discard, Animation Stops at the Min Frame
388 /// End action is StopFinal, Animation Stops at the Max Frame
390 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
391 [EditorBrowsable(EditorBrowsableState.Never)]
392 public void Stop(EndActions endAction = EndActions.Cancel)
394 tlog.Fatal(tag, $"[VAV START[ [{GetId()}] endAction:({endAction}), PlayState={PlayState}");
396 if (mResourceURL == null || mResourceURL == String.Empty)
398 throw new InvalidOperationException("Resource Url not yet Set");
401 if (AnimationState == AnimationStates.Stopped)
406 if (mEndAction != endAction)
408 mEndAction = endAction;
411 case EndActions.Cancel:
412 StopBehavior = StopBehaviorType.CurrentFrame;
414 case EndActions.Discard:
415 StopBehavior = StopBehaviorType.MinimumFrame;
417 case EndActions.StopFinal:
418 StopBehavior = StopBehaviorType.MaximumFrame;
421 tlog.Fatal(tag, $" [{GetId()}] no endAction : default set");
425 AnimationState = AnimationStates.Stopped;
429 if (endAction == EndActions.StopFinal)
431 switch (mIsMinMaxSet)
433 case minMaxSetTypes.NotSetByUser:
434 if (base.CurrentFrame != mTotalFrameNum - 1)
436 tlog.Fatal(tag, $"mIsMinMaxSet:{mIsMinMaxSet}, CurrentFrameNumber:{base.CurrentFrame}, mTotalFrameNum:{ mTotalFrameNum}");
437 base.CurrentFrame = mTotalFrameNum - 1;
438 tlog.Fatal(tag, $"set CurrentFrameNumber({base.CurrentFrame}) as mTotalFrameNum({mMaxFrame}) - 1 !");
442 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
443 if (base.CurrentFrame != mMaxFrame)
445 tlog.Fatal(tag, $"mIsMinMaxSet:{mIsMinMaxSet}, CurrentFrameNumber:{base.CurrentFrame}, mMaxFrame:{ mMaxFrame}");
446 base.CurrentFrame = mMaxFrame;
447 tlog.Fatal(tag, $"set CurrentFrameNumber({base.CurrentFrame}) as mMaxFrame({mMaxFrame})!!!");
450 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
451 case minMaxSetTypes.SetByMarker:
457 tlog.Fatal(tag, $" [{GetId()}] ]VAV END]");
462 #region Event, Enum, Struct, ETC
464 /// RepeatMode of animation.
466 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
467 [EditorBrowsable(EditorBrowsableState.Never)]
468 public enum RepeatModes
471 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
473 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
474 [EditorBrowsable(EditorBrowsableState.Never)]
475 Restart = LoopingModeType.Restart,
477 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
479 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
480 [EditorBrowsable(EditorBrowsableState.Never)]
481 Reverse = LoopingModeType.AutoReverse
485 /// EndActions of animation.
487 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
488 [EditorBrowsable(EditorBrowsableState.Never)]
489 public enum EndActions
491 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
492 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
493 [EditorBrowsable(EditorBrowsableState.Never)]
495 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
496 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
497 [EditorBrowsable(EditorBrowsableState.Never)]
499 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
500 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
501 [EditorBrowsable(EditorBrowsableState.Never)]
506 /// AnimationStates of animation.
508 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
509 [EditorBrowsable(EditorBrowsableState.Never)]
510 public enum AnimationStates
512 /// <summary> The animation has stopped.</summary>
513 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
514 [EditorBrowsable(EditorBrowsableState.Never)]
515 Stopped = PlayStateType.Stopped,
516 /// <summary> The animation is playing.</summary>
517 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
518 [EditorBrowsable(EditorBrowsableState.Never)]
519 Playing = PlayStateType.Playing,
520 /// <summary> The animation is paused.</summary>
521 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
522 [EditorBrowsable(EditorBrowsableState.Never)]
523 Paused = PlayStateType.Paused
525 #endregion Event, Enum, Struct, ETC
533 private string mResourceURL = null;
534 private int mRepeatCount = 0;
535 private int mTotalFrameNum = 0;
536 private RepeatModes mRepeatMode = RepeatModes.Restart;
537 private int mMinFrame = -1, mMaxFrame = -1;
538 private minMaxSetTypes mIsMinMaxSet = minMaxSetTypes.NotSetByUser;
539 private int mCurrentFrame = -1;
540 private EndActions mEndAction = EndActions.Cancel;
541 private enum minMaxSetTypes
544 SetByMinAndMaxFrameMethod,
546 SetByBaseSetMinMaxFrameMethod,
549 private string tag = "NUITEST";