/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
namespace ElmSharp
{
///
/// Enumeration for the AnimationView state
///
/// preview
public enum AnimationViewState
{
///
/// Animation is not ready to play.
///
NotReady,
///
/// Animation is on playing.
///
Play,
///
/// Animation is on reverse playing.
///
ReversedPlay,
///
/// Animation has been paused.
///
Pause,
///
/// AnimationView successfully loaded a file then readied for playing. Otherwise after finished animation or stopped forcely by request.
///
Stop
}
///
/// The AnimationView is designed to show and play animation of vector graphics based content.
/// Currently ElmSharp AnimationView is supporting only json format (known for Lottie file as well).
///
/// preview
public class AnimationView : EvasObject
{
private SmartEvent _started;
private SmartEvent _repeated;
private SmartEvent _finished;
private SmartEvent _paused;
private SmartEvent _resumed;
private SmartEvent _stopped;
private SmartEvent _updated;
///
/// Creates and initializes a new instance of the AnimationView class.
///
/// The parent is a given container, which will be attached by AnimationView as a child. It's type.
/// preview
public AnimationView(EvasObject parent) : base(parent)
{
_started = new SmartEvent(this, this.Handle, "play,start");
_repeated = new SmartEvent(this, this.Handle, "play,repeat");
_finished = new SmartEvent(this, this.Handle, "play,done");
_paused = new SmartEvent(this, this.Handle, "play,pause");
_resumed = new SmartEvent(this, this.Handle, "play,resume");
_stopped = new SmartEvent(this, this.Handle, "play,stop");
_updated = new SmartEvent(this, this.Handle, "play,update");
_started.On += (sender, e) =>
{
Started?.Invoke(this, EventArgs.Empty);
};
_repeated.On += (sender, e) =>
{
Repeated?.Invoke(this, EventArgs.Empty);
};
_finished.On += (sender, e) =>
{
Finished?.Invoke(this, EventArgs.Empty);
};
_paused.On += (sender, e) =>
{
Paused?.Invoke(this, EventArgs.Empty);
};
_resumed.On += (sender, e) =>
{
Resumed?.Invoke(this, EventArgs.Empty);
};
_stopped.On += (sender, e) =>
{
Stopped?.Invoke(this, EventArgs.Empty);
};
_updated.On += (sender, e) =>
{
Updated?.Invoke(this, EventArgs.Empty);
};
}
///
/// It occurs when the animation is just started.
///
/// preview
public event EventHandler Started;
///
/// It occurs when the animation is just repeated.
///
/// preview
public event EventHandler Repeated;
///
/// It occurs when the animation is just finished.
///
/// preview
public event EventHandler Finished;
///
/// It occurs when the animation is just paused.
///
/// preview
public event EventHandler Paused;
///
/// It occurs when the animation is just resumed.
///
/// preview
public event EventHandler Resumed;
///
/// It occurs when the animation is just stopped.
///
/// preview
public event EventHandler Stopped;
///
/// It occurs when the animation is updated to the next frame.
///
/// preview
public event EventHandler Updated;
///
/// Sets or gets whether to play animation automatically.
///
/// If AutoPlay is true, animation will be started when it's readied.
/// The condition of AutoPlay is when AnimationView opened file successfully, yet to play it plus when the object is visible.
/// If AnimationView is disabled, invisible, it turns to pause state then resume animation when it's visible again.
/// This AutoPlay will be only affected to the next animation source. So must be called before SetAnimation()
///
///
/// preview
public bool AutoPlay
{
get
{
return Interop.Elementary.elm_animation_view_auto_play_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_auto_play_set(Handle, value);
}
}
///
/// Sets or gets whether to turn on/off animation looping.
///
/// If AutoRepeat is true, it repeats animation when animation frame is reached to end.
/// This AutoRepeat mode is valid to both Play and ReversePlay cases.
///
///
/// preview
public bool AutoRepeat
{
get
{
return Interop.Elementary.elm_animation_view_auto_repeat_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_auto_repeat_set(Handle, value);
}
}
///
/// Sets or gets the animation speed.
///
/// Control animation speed by multiplying Speed value.
/// If you want to play animation double-time faster, you can give Speed 2.
/// If you want to play animation double-time slower, you can give Speed 0.5.
/// Speed must be greater than zero.
///
///
/// preview
public double Speed
{
get
{
return Interop.Elementary.elm_animation_view_speed_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_speed_set(Handle, value);
}
}
///
/// Get the duration of animation in seconds.
///
///
/// Returns total duration time of current animation in the seconds.
/// If current animation source isn't animatable, it returns zero.
///
/// preview
public double DurationTime
{
get
{
return Interop.Elementary.elm_animation_view_duration_time_get(Handle);
}
}
///
/// Sets or gets current progress position of animation view.
///
/// When you required to jump on a certain progress instantly,
/// you can change current position by using this property
/// The range of progress is 0 ~ 1.
///
///
/// preview
public double Progress
{
get
{
return Interop.Elementary.elm_animation_view_progress_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_progress_set(Handle, value);
}
}
///
/// Sets or gets current frame position of animation view.
///
/// The range of frame is from 0 to FrameCount - 1
///
///
/// preview
public int Frame
{
get
{
return Interop.Elementary.elm_animation_view_frame_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_frame_set(Handle, value);
}
}
///
/// Get the default view size that specified from vector resource.
///
/// preview
public Size DefaultSize
{
get
{
Interop.Elementary.elm_animation_view_default_size_get(Handle, out int w, out int h);
return new Size(w, h);
}
}
///
/// Get current animation view state.
///
/// preview
public AnimationViewState State
{
get
{
return (AnimationViewState)Interop.Elementary.elm_animation_view_state_get(Handle);
}
}
///
/// Get the status whether current animation is on playing forward or backward.
///
///
/// If AnimationView is not on playing, it will return False.
///
/// preview
public bool IsReversedPlaying
{
get
{
return Interop.Elementary.elm_animation_view_is_playing_back(Handle);
}
}
///
/// Get the index of end frame of the AnimationView, if it's animated.
///
///
/// Frame number starts with 0.
///
/// preview
public int FrameCount
{
get
{
return Interop.Elementary.elm_animation_view_frame_count_get(Handle);
}
}
///
/// Sets or Gets the start progress of the play
///
///
/// Default value is 0.
///
/// preview
public double MinProgress
{
get
{
return Interop.Elementary.elm_animation_view_min_progress_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_min_progress_set(Handle, value);
}
}
///
/// Sets or Gets the last progress of the play
///
///
/// Default value is 1.
///
/// preview
public double MaxProgress
{
get
{
return Interop.Elementary.elm_animation_view_max_progress_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_max_progress_set(Handle, value);
}
}
///
/// Sets or Gets the start frame of the play
///
///
/// Default value is 0.
///
/// preview
public int MinFrame
{
get
{
return Interop.Elementary.elm_animation_view_min_frame_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_min_frame_set(Handle, value);
}
}
///
/// Sets or Gets the last frame of the play
///
///
/// Default value is FrameCount -1.
///
/// preview
public int MaxFrame
{
get
{
return Interop.Elementary.elm_animation_view_max_frame_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_max_frame_set(Handle, value);
}
}
///
/// Sets the animation source file.
///
/// The animation file path.
/// preview
public void SetAnimation(string file)
{
Interop.Elementary.elm_animation_view_file_set(Handle, file, null);
}
///
/// Play animation one time instantly when it's available.
///
/// If current keyframe is on a certain position by playing reverse, this will play forward from there.
/// Play request will be ignored if animation source is not set yet or animation is paused state or it's already on playing.
///
///
/// preview
public void Play()
{
Interop.Elementary.elm_animation_view_play(Handle);
}
///
/// Play animation one time instantly when it's available.
///
/// If current keyframe is on a certain position by playing reverse and isReverse is ture, this will play forward from there.
/// And if current keyframe is on a certain position by playing and isReverse is false, this will play backward from there.
/// Play request will be ignored if animation source is not set yet or animation is paused state or it's already on playing.
///
///
/// Whether the animation play or reverse play.
/// preview
public void Play(bool isReverse)
{
if (!isReverse)
{
Interop.Elementary.elm_animation_view_play(Handle);
}
else
{
Interop.Elementary.elm_animation_view_play_back(Handle);
}
}
///
/// Pause current animation instantly.
///
/// Once animation is paused, animation view must get resume to play continue again.
/// Animation must be on playing or playing back status.
///
///
/// preview
public void Pause()
{
Interop.Elementary.elm_animation_view_pause(Handle);
}
///
/// Resume paused animation to continue animation.
///
///
/// This resume must be called on animation paused status.
///
/// preview
public void Resume()
{
Interop.Elementary.elm_animation_view_resume(Handle);
}
///
/// Stop playing animation.
///
/// Stop animation instatly regardless of it's status and reset to
/// show first frame of animation.Even though current animation is paused,
/// the animation status will be stopped.
///
///
/// preview
public void Stop()
{
Interop.Elementary.elm_animation_view_stop(Handle);
}
///
/// Creates a AnimationView handle.
///
/// Parent EvasObject.
/// Handle IntPtr.
/// preview
protected override IntPtr CreateHandle(EvasObject parent)
{
return Interop.Elementary.elm_animation_view_add(parent.Handle);
}
}
}