2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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.
22 /// Enumeration for the AnimationView state
24 /// <since_tizen> preview </since_tizen>
25 public enum AnimationViewState
28 /// Animation is not ready to play.
33 /// Animation is on playing.
38 /// Animation is on reverse playing.
43 /// Animation has been paused.
48 /// AnimationView successfully loaded a file then readied for playing. Otherwise after finished animation or stopped forcely by request.
54 /// The AnimationView is designed to show and play animation of vector graphics based content.
55 /// Currently ElmSharp AnimationView is supporting only json format (known for Lottie file as well).
57 /// <since_tizen> preview </since_tizen>
58 public class AnimationView : EvasObject
60 private SmartEvent _started;
61 private SmartEvent _repeated;
62 private SmartEvent _finished;
63 private SmartEvent _paused;
64 private SmartEvent _resumed;
65 private SmartEvent _stopped;
66 private SmartEvent _updated;
69 /// Creates and initializes a new instance of the AnimationView class.
71 /// <param name="parent">The parent is a given container, which will be attached by AnimationView as a child. It's <see cref="EvasObject"/> type.</param>
72 /// <since_tizen> preview </since_tizen>
73 public AnimationView(EvasObject parent) : base(parent)
75 _started = new SmartEvent(this, this.Handle, "play,start");
76 _repeated = new SmartEvent(this, this.Handle, "play,repeat");
77 _finished = new SmartEvent(this, this.Handle, "play,done");
78 _paused = new SmartEvent(this, this.Handle, "play,pause");
79 _resumed = new SmartEvent(this, this.Handle, "play,resume");
80 _stopped = new SmartEvent(this, this.Handle, "play,stop");
81 _updated = new SmartEvent(this, this.Handle, "play,update");
83 _started.On += (sender, e) =>
85 Started?.Invoke(this, EventArgs.Empty);
88 _repeated.On += (sender, e) =>
90 Repeated?.Invoke(this, EventArgs.Empty);
93 _finished.On += (sender, e) =>
95 Finished?.Invoke(this, EventArgs.Empty);
98 _paused.On += (sender, e) =>
100 Paused?.Invoke(this, EventArgs.Empty);
103 _resumed.On += (sender, e) =>
105 Resumed?.Invoke(this, EventArgs.Empty);
108 _stopped.On += (sender, e) =>
110 Stopped?.Invoke(this, EventArgs.Empty);
113 _updated.On += (sender, e) =>
115 Updated?.Invoke(this, EventArgs.Empty);
120 /// It occurs when the animation is just started.
122 /// <since_tizen> preview </since_tizen>
123 public event EventHandler Started;
126 /// It occurs when the animation is just repeated.
128 /// <since_tizen> preview </since_tizen>
129 public event EventHandler Repeated;
132 /// It occurs when the animation is just finished.
134 /// <since_tizen> preview </since_tizen>
135 public event EventHandler Finished;
138 /// It occurs when the animation is just paused.
140 /// <since_tizen> preview </since_tizen>
141 public event EventHandler Paused;
144 /// It occurs when the animation is just resumed.
146 /// <since_tizen> preview </since_tizen>
147 public event EventHandler Resumed;
150 /// It occurs when the animation is just stopped.
152 /// <since_tizen> preview </since_tizen>
153 public event EventHandler Stopped;
156 /// It occurs when the animation is updated to the next frame.
158 /// <since_tizen> preview </since_tizen>
159 public event EventHandler Updated;
162 /// Sets or gets whether to play animation automatically.
164 /// If AutoPlay is true, animation will be started when it's readied.
165 /// The condition of AutoPlay is when AnimationView opened file successfully, yet to play it plus when the object is visible.
166 /// If AnimationView is disabled, invisible, it turns to pause state then resume animation when it's visible again.
167 /// This AutoPlay will be only affected to the next animation source. So must be called before SetAnimation()
170 /// <since_tizen> preview </since_tizen>
175 return Interop.Elementary.elm_animation_view_auto_play_get(Handle);
179 Interop.Elementary.elm_animation_view_auto_play_set(Handle, value);
184 /// Sets or gets whether to turn on/off animation looping.
186 /// If AutoRepeat is true, it repeats animation when animation frame is reached to end.
187 /// This AutoRepeat mode is valid to both Play and ReversePlay cases.
190 /// <since_tizen> preview </since_tizen>
191 public bool AutoRepeat
195 return Interop.Elementary.elm_animation_view_auto_repeat_get(Handle);
199 Interop.Elementary.elm_animation_view_auto_repeat_set(Handle, value);
204 /// Sets or gets the animation speed.
206 /// Control animation speed by multiplying Speed value.
207 /// If you want to play animation double-time faster, you can give Speed 2.
208 /// If you want to play animation double-time slower, you can give Speed 0.5.
209 /// Speed must be greater than zero.
212 /// <since_tizen> preview </since_tizen>
217 return Interop.Elementary.elm_animation_view_speed_get(Handle);
221 Interop.Elementary.elm_animation_view_speed_set(Handle, value);
226 /// Get the duration of animation in seconds.
229 /// Returns total duration time of current animation in the seconds.
230 /// If current animation source isn't animatable, it returns zero.
232 /// <since_tizen> preview </since_tizen>
233 public double DurationTime
237 return Interop.Elementary.elm_animation_view_duration_time_get(Handle);
242 /// Sets or gets current progress position of animation view.
244 /// When you required to jump on a certain progress instantly,
245 /// you can change current position by using this property
246 /// The range of progress is 0 ~ 1.
249 /// <since_tizen> preview </since_tizen>
250 public double Progress
254 return Interop.Elementary.elm_animation_view_progress_get(Handle);
258 Interop.Elementary.elm_animation_view_progress_set(Handle, value);
263 /// Sets or gets current frame position of animation view.
265 /// The range of frame is from 0 to FrameCount - 1
268 /// <since_tizen> preview </since_tizen>
273 return Interop.Elementary.elm_animation_view_frame_get(Handle);
277 Interop.Elementary.elm_animation_view_frame_set(Handle, value);
282 /// Get the default view size that specified from vector resource.
284 /// <since_tizen> preview </since_tizen>
285 public Size DefaultSize
289 Interop.Elementary.elm_animation_view_default_size_get(Handle, out int w, out int h);
290 return new Size(w, h);
295 /// Get current animation view state.
297 /// <since_tizen> preview </since_tizen>
298 public AnimationViewState State
302 return (AnimationViewState)Interop.Elementary.elm_animation_view_state_get(Handle);
307 /// Get the status whether current animation is on playing forward or backward.
310 /// If AnimationView is not on playing, it will return False.
312 /// <since_tizen> preview </since_tizen>
313 public bool IsReversedPlaying
317 return Interop.Elementary.elm_animation_view_is_playing_back(Handle);
322 /// Get the index of end frame of the AnimationView, if it's animated.
325 /// Frame number starts with 0.
327 /// <since_tizen> preview </since_tizen>
328 public int FrameCount
332 return Interop.Elementary.elm_animation_view_frame_count_get(Handle);
337 /// Sets or Gets the start progress of the play
340 /// Default value is 0.
342 /// <since_tizen> preview </since_tizen>
343 public double MinProgress
347 return Interop.Elementary.elm_animation_view_min_progress_get(Handle);
351 Interop.Elementary.elm_animation_view_min_progress_set(Handle, value);
356 /// Sets or Gets the last progress of the play
359 /// Default value is 1.
361 /// <since_tizen> preview </since_tizen>
362 public double MaxProgress
366 return Interop.Elementary.elm_animation_view_max_progress_get(Handle);
370 Interop.Elementary.elm_animation_view_max_progress_set(Handle, value);
375 /// Sets or Gets the start frame of the play
378 /// Default value is 0.
380 /// <since_tizen> preview </since_tizen>
385 return Interop.Elementary.elm_animation_view_min_frame_get(Handle);
389 Interop.Elementary.elm_animation_view_min_frame_set(Handle, value);
394 /// Sets or Gets the last frame of the play
397 /// Default value is FrameCount -1.
399 /// <since_tizen> preview </since_tizen>
404 return Interop.Elementary.elm_animation_view_max_frame_get(Handle);
408 Interop.Elementary.elm_animation_view_max_frame_set(Handle, value);
413 /// Sets the animation source file.
415 /// <param name="file">The animation file path.</param>
416 /// <since_tizen> preview </since_tizen>
417 public void SetAnimation(string file)
419 Interop.Elementary.elm_animation_view_file_set(Handle, file, null);
423 /// Play animation one time instantly when it's available.
425 /// If current keyframe is on a certain position by playing reverse, this will play forward from there.
426 /// Play request will be ignored if animation source is not set yet or animation is paused state or it's already on playing.
429 /// <since_tizen> preview </since_tizen>
432 Interop.Elementary.elm_animation_view_play(Handle);
436 /// Play animation one time instantly when it's available.
438 /// If current keyframe is on a certain position by playing reverse and isReverse is ture, this will play forward from there.
439 /// And if current keyframe is on a certain position by playing and isReverse is false, this will play backward from there.
440 /// Play request will be ignored if animation source is not set yet or animation is paused state or it's already on playing.
443 /// <param name="isReverse">Whether the animation play or reverse play.</param>
444 /// <since_tizen> preview </since_tizen>
445 public void Play(bool isReverse)
449 Interop.Elementary.elm_animation_view_play(Handle);
453 Interop.Elementary.elm_animation_view_play_back(Handle);
458 /// Pause current animation instantly.
460 /// Once animation is paused, animation view must get resume to play continue again.
461 /// Animation must be on playing or playing back status.
464 /// <since_tizen> preview </since_tizen>
467 Interop.Elementary.elm_animation_view_pause(Handle);
471 /// Resume paused animation to continue animation.
474 /// This resume must be called on animation paused status.
476 /// <since_tizen> preview </since_tizen>
479 Interop.Elementary.elm_animation_view_resume(Handle);
483 /// Stop playing animation.
485 /// Stop animation instatly regardless of it's status and reset to
486 /// show first frame of animation.Even though current animation is paused,
487 /// the animation status will be stopped.
490 /// <since_tizen> preview </since_tizen>
493 Interop.Elementary.elm_animation_view_stop(Handle);
497 /// Creates a AnimationView handle.
499 /// <param name="parent">Parent EvasObject.</param>
500 /// <returns>Handle IntPtr.</returns>
501 /// <since_tizen> preview </since_tizen>
502 protected override IntPtr CreateHandle(EvasObject parent)
504 return Interop.Elementary.elm_animation_view_add(parent.Handle);