/
AnimationView.cs
507 lines (464 loc) · 16.6 KB
/
AnimationView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/*
* 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
{
/// <summary>
/// Enumeration for the AnimationView state
/// </summary>
/// <since_tizen> preview </since_tizen>
public enum AnimationViewState
{
/// <summary>
/// Animation is not ready to play.
/// </summary>
NotReady,
/// <summary>
/// Animation is on playing.
/// </summary>
Play,
/// <summary>
/// Animation is on reverse playing.
/// </summary>
ReversedPlay,
/// <summary>
/// Animation has been paused.
/// </summary>
Pause,
/// <summary>
/// AnimationView successfully loaded a file then readied for playing. Otherwise after finished animation or stopped forcely by request.
/// </summary>
Stop
}
/// <summary>
/// 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).
/// </summary>
/// <since_tizen> preview </since_tizen>
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;
/// <summary>
/// Creates and initializes a new instance of the AnimationView class.
/// </summary>
/// <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>
/// <since_tizen> preview </since_tizen>
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);
};
}
/// <summary>
/// It occurs when the animation is just started.
/// </summary>
/// <since_tizen> preview </since_tizen>
public event EventHandler Started;
/// <summary>
/// It occurs when the animation is just repeated.
/// </summary>
/// <since_tizen> preview </since_tizen>
public event EventHandler Repeated;
/// <summary>
/// It occurs when the animation is just finished.
/// </summary>
/// <since_tizen> preview </since_tizen>
public event EventHandler Finished;
/// <summary>
/// It occurs when the animation is just paused.
/// </summary>
/// <since_tizen> preview </since_tizen>
public event EventHandler Paused;
/// <summary>
/// It occurs when the animation is just resumed.
/// </summary>
/// <since_tizen> preview </since_tizen>
public event EventHandler Resumed;
/// <summary>
/// It occurs when the animation is just stopped.
/// </summary>
/// <since_tizen> preview </since_tizen>
public event EventHandler Stopped;
/// <summary>
/// It occurs when the animation is updated to the next frame.
/// </summary>
/// <since_tizen> preview </since_tizen>
public event EventHandler Updated;
/// <summary>
/// Sets or gets whether to play animation automatically.
/// <remarks>
/// 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()
/// </remarks>
/// </summary>
/// <since_tizen> preview </since_tizen>
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);
}
}
/// <summary>
/// Sets or gets whether to turn on/off animation looping.
/// <remarks>
/// 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.
/// </remarks>
/// </summary>
/// <since_tizen> preview </since_tizen>
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);
}
}
/// <summary>
/// Sets or gets the animation speed.
/// <remarks>
/// 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.
/// </remarks>
/// </summary>
/// <since_tizen> preview </since_tizen>
public double Speed
{
get
{
return Interop.Elementary.elm_animation_view_speed_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_speed_set(Handle, value);
}
}
/// <summary>
/// Get the duration of animation in seconds.
/// </summary>
/// <remarks>
/// Returns total duration time of current animation in the seconds.
/// If current animation source isn't animatable, it returns zero.
/// </remarks>
/// <since_tizen> preview </since_tizen>
public double DurationTime
{
get
{
return Interop.Elementary.elm_animation_view_duration_time_get(Handle);
}
}
/// <summary>
/// Sets or gets current progress position of animation view.
/// <remarks>
/// 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.
/// </remarks>
/// </summary>
/// <since_tizen> preview </since_tizen>
public double Progress
{
get
{
return Interop.Elementary.elm_animation_view_progress_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_progress_set(Handle, value);
}
}
/// <summary>
/// Sets or gets current frame position of animation view.
/// <remarks>
/// The range of frame is from 0 to FrameCount - 1
/// </remarks>
/// </summary>
/// <since_tizen> preview </since_tizen>
public int Frame
{
get
{
return Interop.Elementary.elm_animation_view_frame_get(Handle);
}
set
{
Interop.Elementary.elm_animation_view_frame_set(Handle, value);
}
}
/// <summary>
/// Get the default view size that specified from vector resource.
/// </summary>
/// <since_tizen> preview </since_tizen>
public Size DefaultSize
{
get
{
Interop.Elementary.elm_animation_view_default_size_get(Handle, out int w, out int h);
return new Size(w, h);
}
}
/// <summary>
/// Get current animation view state.
/// </summary>
/// <since_tizen> preview </since_tizen>
public AnimationViewState State
{
get
{
return (AnimationViewState)Interop.Elementary.elm_animation_view_state_get(Handle);
}
}
/// <summary>
/// Get the status whether current animation is on playing forward or backward.
/// </summary>
/// <remarks>
/// If AnimationView is not on playing, it will return False.
/// </remarks>
/// <since_tizen> preview </since_tizen>
public bool IsReversedPlaying
{
get
{
return Interop.Elementary.elm_animation_view_is_playing_back(Handle);
}
}
/// <summary>
/// Get the index of end frame of the AnimationView, if it's animated.
/// </summary>
/// <remarks>
/// Frame number starts with 0.
/// </remarks>
/// <since_tizen> preview </since_tizen>
public int FrameCount
{
get
{
return Interop.Elementary.elm_animation_view_frame_count_get(Handle);
}
}
/// <summary>
/// Sets or Gets the start progress of the play
/// </summary>
/// <remarks>
/// Default value is 0.
/// </remarks>
/// <since_tizen> preview </since_tizen>
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);
}
}
/// <summary>
/// Sets or Gets the last progress of the play
/// </summary>
/// <remarks>
/// Default value is 1.
/// </remarks>
/// <since_tizen> preview </since_tizen>
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);
}
}
/// <summary>
/// Sets or Gets the start frame of the play
/// </summary>
/// <remarks>
/// Default value is 0.
/// </remarks>
/// <since_tizen> preview </since_tizen>
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);
}
}
/// <summary>
/// Sets or Gets the last frame of the play
/// </summary>
/// <remarks>
/// Default value is FrameCount -1.
/// </remarks>
/// <since_tizen> preview </since_tizen>
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);
}
}
/// <summary>
/// Sets the animation source file.
/// </summary>
/// <param name="file">The animation file path.</param>
/// <since_tizen> preview </since_tizen>
public void SetAnimation(string file)
{
Interop.Elementary.elm_animation_view_file_set(Handle, file, null);
}
/// <summary>
/// Play animation one time instantly when it's available.
/// <remarks>
/// 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.
/// </remarks>
/// </summary>
/// <since_tizen> preview </since_tizen>
public void Play()
{
Interop.Elementary.elm_animation_view_play(Handle);
}
/// <summary>
/// Play animation one time instantly when it's available.
/// <remarks>
/// 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.
/// </remarks>
/// </summary>
/// <param name="isReverse">Whether the animation play or reverse play.</param>
/// <since_tizen> preview </since_tizen>
public void Play(bool isReverse)
{
if (!isReverse)
{
Interop.Elementary.elm_animation_view_play(Handle);
}
else
{
Interop.Elementary.elm_animation_view_play_back(Handle);
}
}
/// <summary>
/// Pause current animation instantly.
/// <remarks>
/// Once animation is paused, animation view must get resume to play continue again.
/// Animation must be on playing or playing back status.
/// </remarks>
/// </summary>
/// <since_tizen> preview </since_tizen>
public void Pause()
{
Interop.Elementary.elm_animation_view_pause(Handle);
}
/// <summary>
/// Resume paused animation to continue animation.
/// </summary>
/// <remarks>
/// This resume must be called on animation paused status.
/// </remarks>
/// <since_tizen> preview </since_tizen>
public void Resume()
{
Interop.Elementary.elm_animation_view_resume(Handle);
}
/// <summary>
/// Stop playing animation.
/// <remarks>
/// 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.
/// </remarks>
/// </summary>
/// <since_tizen> preview </since_tizen>
public void Stop()
{
Interop.Elementary.elm_animation_view_stop(Handle);
}
/// <summary>
/// Creates a AnimationView handle.
/// </summary>
/// <param name="parent">Parent EvasObject.</param>
/// <returns>Handle IntPtr.</returns>
/// <since_tizen> preview </since_tizen>
protected override IntPtr CreateHandle(EvasObject parent)
{
return Interop.Elementary.elm_animation_view_add(parent.Handle);
}
}
}