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 /// EcoreTimelineAnimator is a helper class, which provides the functions to manage animations.
24 /// <since_tizen> preview </since_tizen>
25 public class EcoreTimelineAnimator
29 Action _timelineCallback;
30 Interop.Ecore.EcoreTimelineCallback _nativeCallback;
34 /// It occurs when the animator is complete.
36 /// <since_tizen> preview </since_tizen>
37 public event EventHandler Finished;
40 /// Creates and initializes a new instance of the EcoreTimelineAnimator class.
42 /// <param name="runtime">The time to run in seconds.</param>
43 /// <param name="timelineCallback">Functions called at each time line.</param>
44 /// <since_tizen> preview </since_tizen>
45 public EcoreTimelineAnimator(double runtime, Action timelineCallback)
48 _nativeCallback = NativeCallback;
49 _timelineCallback = timelineCallback;
54 /// Gets whether the animation is running.
56 /// <since_tizen> preview </since_tizen>
57 public bool IsRunning { get; private set; }
60 /// Gets the current position of the animation.
62 /// <since_tizen> preview </since_tizen>
63 public double Position => _position;
66 /// Starts an animator that runs for a limited time.
68 /// <since_tizen> preview </since_tizen>
72 _animator = Interop.Ecore.ecore_animator_timeline_add(_runtime, _nativeCallback, IntPtr.Zero);
76 /// Stops an animator that is running.
78 /// <since_tizen> preview </since_tizen>
82 _animator = IntPtr.Zero;
86 /// Suspends the specified animator.
88 /// <since_tizen> preview </since_tizen>
91 Interop.Ecore.ecore_animator_freeze(_animator);
95 /// Restores execution of the specified animator.
97 /// <since_tizen> preview </since_tizen>
100 Interop.Ecore.ecore_animator_thaw(_animator);
104 /// Callback is called when it ticks off.
106 /// <since_tizen> preview </since_tizen>
107 protected void OnTimeline()
112 bool NativeCallback(IntPtr data, double pos)
115 if (!IsRunning) return false;
120 _animator = IntPtr.Zero;
121 Finished?.Invoke(this, EventArgs.Empty);