/
Animation.cs
executable file
·1420 lines (1262 loc) · 60 KB
/
Animation.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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright(c) 2017 Samsung Electronics Co., Ltd.
*
* 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.
*
*/
namespace Tizen.NUI
{
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Tizen.NUI.BaseComponents;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml;
using Tizen.NUI.Binding.Internals;
using Tizen.NUI.Binding;
using System.Globalization;
using Tizen.NUI.Xaml.Internals;
/// <summary>
/// Animation can be used to animate the properties of any number of objects, typically view.<br />
/// If the "Finished" event is connected to a member function of an object, it must be disconnected before the object is destroyed.<br />
/// This is typically done in the object destructor, and requires either the animation handle to be stored.<br />
/// The overall animation time is superseded by the values given in the animation time used when calling the AnimateTo(), AnimateBy(), AnimateBetween() and AnimatePath() methods.<br />
/// If any of the individual calls to those functions exceeds the overall animation time (Duration), then the overall animation time is automatically extended.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public class Animation : BaseHandle
{
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
internal Animation(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Animation_SWIGUpcast(cPtr), cMemoryOwn)
{
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
_animationFinishedEventCallback = OnFinished;
_finishedCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(_animationFinishedEventCallback);
}
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Animation obj)
{
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
/// <summary>
/// To make animation instance be disposed.
/// </summary>
/// <since_tizen> 3 </since_tizen>
protected override void Dispose(DisposeTypes type)
{
if (this != null)
{
if (_animationFinishedEventCallback != null)
{
FinishedSignal().Disconnect(_finishedCallbackOfNative);
}
if (_animationProgressReachedEventCallback != null)
{
ProgressReachedSignal().Disconnect(_animationProgressReachedEventCallback);
}
}
if(disposed)
{
return;
}
if(type == DisposeTypes.Explicit)
{
//Called by User
//Release your own managed resources here.
//You should release all of your own disposable objects here.
}
else if(type == DisposeTypes.Implicit)
{
}
if (this != null)
{
this.Clear();
}
//Release your own unmanaged resources here.
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
if (swigCMemOwn)
{
swigCMemOwn = false;
NDalicPINVOKE.delete_Animation(swigCPtr);
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
base.Dispose(type);
}
/// <summary>
/// Creates an initialized animation.<br />
/// The animation will not loop.<br />
/// The default end action is "Cancel".<br />
/// The default alpha function is linear.<br />
/// </summary>
/// <remarks>DurationmSeconds must be greater than zero.</remarks>
/// <param name="durationMilliSeconds">The duration in milliseconds.</param>
/// <since_tizen> 3 </since_tizen>
public Animation(int durationMilliSeconds) : this(NDalicPINVOKE.Animation_New((float)durationMilliSeconds / 1000.0f), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
private AnimationFinishedEventCallbackType _animationFinishedEventCallback;
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void AnimationFinishedEventCallbackType(IntPtr data);
private event EventHandler _animationFinishedEventHandler;
private System.IntPtr _finishedCallbackOfNative;
/**
* @brief Event for the finished signal which can be used to subscribe or unsubscribe the event handler.
* The finished signal is emitted when an animation's animations have finished.
*/
/// <since_tizen> 3 </since_tizen>
public event EventHandler Finished
{
add
{
if (_animationFinishedEventHandler == null && disposed == false)
{
FinishedSignal().Connect(_finishedCallbackOfNative);
}
_animationFinishedEventHandler += value;
}
remove
{
_animationFinishedEventHandler -= value;
if (_animationFinishedEventHandler == null && FinishedSignal().Empty() == false)
{
FinishedSignal().Disconnect(_finishedCallbackOfNative);
}
}
}
private void OnFinished(IntPtr data)
{
if (_animationFinishedEventHandler != null)
{
//here we send all data to user event handlers
_animationFinishedEventHandler(this, null);
}
}
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void AnimationProgressReachedEventCallbackType(IntPtr data);
private AnimationProgressReachedEventCallbackType _animationProgressReachedEventCallback;
private event EventHandler _animationProgressReachedEventHandler;
/**
* @brief Event for the ProgressReached signal, which can be used to subscribe or unsubscribe the event handler.
* The ProgressReached signal is emitted when the animation has reached a given progress percentage, this is set in the api SetProgressNotification.
*/
/// <since_tizen> 3 </since_tizen>
public event EventHandler ProgressReached
{
add
{
if (_animationProgressReachedEventHandler == null)
{
_animationProgressReachedEventCallback = OnProgressReached;
ProgressReachedSignal().Connect(_animationProgressReachedEventCallback);
}
_animationProgressReachedEventHandler += value;
}
remove
{
_animationProgressReachedEventHandler -= value;
if (_animationProgressReachedEventHandler == null && ProgressReachedSignal().Empty() == false)
{
ProgressReachedSignal().Disconnect(_animationProgressReachedEventCallback);
}
}
}
private void OnProgressReached(IntPtr data)
{
if (_animationProgressReachedEventHandler != null)
{
//here we send all data to user event handlers
_animationProgressReachedEventHandler(this, null);
}
}
private float MilliSecondsToSeconds(int millisec)
{
return (float)millisec / 1000.0f;
}
private int SecondsToMilliSeconds(float sec)
{
return (int)(sec * 1000);
}
/// <summary>
/// Gets or sets the duration in milliseconds of the animation.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public int Duration
{
set
{
SetDuration(MilliSecondsToSeconds(value));
}
get
{
return SecondsToMilliSeconds(GetDuration());
}
}
/// <summary>
/// Gets or sets the default alpha function for the animation.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public AlphaFunction DefaultAlphaFunction
{
set
{
SetDefaultAlphaFunction(value);
}
get
{
AlphaFunction ret = GetDefaultAlphaFunction();
return ret;
}
}
/// <summary>
/// Queries the state of the animation.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public States State
{
get
{
return GetState();
}
}
/// <summary>
/// Set: Enables looping for a specified number of repeats. A zero is the same as Looping = true; i.e., repeat forever.<br />
/// This property resets the looping value and should not be used with the Looping property.<br />
/// Setting this parameter does not cause the animation to Play().<br />
/// Get: Gets the loop count. A zero is the same as Looping = true; i.e., repeat forever.<br />
/// The loop count is initially 1 for play once.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public int LoopCount
{
set
{
SetLoopCount(value);
}
get
{
int ret = GetLoopCount();
return ret;
}
}
/// <summary>
/// Gets or sets the status of whether the animation will loop.<br />
/// This property resets the loop count and should not be used with the LoopCount property.<br />
/// Setting this parameter does not cause the animation to Play().<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public bool Looping
{
set
{
SetLooping(value);
}
get
{
bool ret = IsLooping();
return ret;
}
}
/// <summary>
/// Gets or sets the end action of the animation.<br />
/// This action is performed when the animation ends or if it is stopped.<br />
/// The default end action is cancel.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public EndActions EndAction
{
set
{
SetEndAction(value);
}
get
{
return GetEndAction();
}
}
/// <summary>
/// Stops the animation.
/// </summary>
/// <param name="action">The end action can be set.</param>
/// <since_tizen> 3 </since_tizen>
public void Stop(EndActions action = EndActions.Cancel)
{
SetEndAction(action);
NDalicPINVOKE.Animation_Stop(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// Gets the current loop count.<br />
/// A value 0 indicating the current loop count when looping.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public int CurrentLoop
{
get
{
return GetCurrentLoop();
}
}
/// <summary>
/// Gets or sets the disconnect action.<br />
/// If any of the animated property owners are disconnected from the stage while the animation is being played, then this action is performed.<br />
/// The default action is cancel.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public EndActions DisconnectAction
{
set
{
NDalicPINVOKE.Animation_SetDisconnectAction(swigCPtr, (int)value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
Animation.EndActions ret = (Animation.EndActions)NDalicPINVOKE.Animation_GetDisconnectAction(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
/// <summary>
/// Gets or sets the progress of the animation.<br />
/// The animation will play (or continue playing) from this point.<br />
/// The progress must be in the 0-1 interval or in the play range interval if defined<br />
/// otherwise, it will be ignored.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public float CurrentProgress
{
set
{
NDalicPINVOKE.Animation_SetCurrentProgress(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
float ret = NDalicPINVOKE.Animation_GetCurrentProgress(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
/// <summary>
/// Gets or sets specificifications of a speed factor for the animation.<br />
/// The speed factor is a multiplier of the normal velocity of the animation.<br />
/// Values between [0, 1] will slow down the animation and values above one will speed up the animation.<br />
/// It is also possible to specify a negative multiplier to play the animation in reverse.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public float SpeedFactor
{
set
{
NDalicPINVOKE.Animation_SetSpeedFactor(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
float ret = NDalicPINVOKE.Animation_GetSpeedFactor(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
/// <summary>
/// Gets or sets the playing range.<br />
/// Animation will play between the values specified. Both values (range.x and range.y ) should be between 0-1,
/// otherwise they will be ignored. If the range provided is not in proper order (minimum, maximum ), it will be reordered.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public RelativeVector2 PlayRange
{
set
{
NDalicPINVOKE.Animation_SetPlayRange(swigCPtr, Vector2.getCPtr(value));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
Vector2 ret = new Vector2(NDalicPINVOKE.Animation_GetPlayRange(swigCPtr), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
/// <summary>
/// Gets or sets the progress notification marker which triggers the ProgressReachedSignal.<br />
/// Percentage of animation progress should be greater than 0 and less than 1, for example, 0.3 for 30% <br />
/// One notification can be set on each animation.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public float ProgressNotification
{
set
{
NDalicPINVOKE.Animation_SetProgressNotification(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
float ret = NDalicPINVOKE.Animation_GetProgressNotification(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
/// <summary>
/// Animates a property value by a relative amount.<br />
/// </summary>
/// <param name="target">The target object to animate.</param>
/// <param name="property">The target property to animate.</param>
/// <param name="relativeValue">The property value will change by this amount.</param>
/// <param name="alphaFunction">The alpha function to apply.</param>
/// <since_tizen> 3 </since_tizen>
public void AnimateBy(View target, string property, object relativeValue, AlphaFunction alphaFunction = null)
{
Property _prop = PropertyHelper.GetPropertyFromString(target, property);
PropertyType propertyType = target.GetPropertyType(_prop.propertyIndex);
if(propertyType.Equals(PropertyType.Float))
{
System.Type type = relativeValue.GetType();
if (type.Equals(typeof(System.Int32)) || type.Equals(typeof(int)))
{
int num = (int)relativeValue;
relativeValue = (float)num;
}
}
PropertyValue val = PropertyValue.CreateFromObject(relativeValue);
if (alphaFunction != null)
{
AnimateBy(_prop, val, alphaFunction);
}
else
{
AnimateBy(_prop, val);
}
}
/// <summary>
/// Animates a property value by a relative amount.<br />
/// </summary>
/// <param name="target">The target object to animate.</param>
/// <param name="property">The target property to animate.</param>
/// <param name="relativeValue">The property value will change by this amount.</param>
/// <param name="startTime">The start time of the animation.</param>
/// <param name="endTime">The end time of the animation.</param>
/// <param name="alphaFunction">The alpha function to apply.</param>
/// <since_tizen> 3 </since_tizen>
public void AnimateBy(View target, string property, object relativeValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
{
Property _prop = PropertyHelper.GetPropertyFromString(target, property);
PropertyType propertyType = target.GetPropertyType(_prop.propertyIndex);
if(propertyType.Equals(PropertyType.Float))
{
System.Type type = relativeValue.GetType();
if (type.Equals(typeof(System.Int32)) || type.Equals(typeof(int)))
{
int num = (int)relativeValue;
relativeValue = (float)num;
}
}
PropertyValue val = PropertyValue.CreateFromObject(relativeValue);
if (alphaFunction != null)
{
Tizen.NUI.TimePeriod time = new Tizen.NUI.TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime));
AnimateBy(_prop, val, alphaFunction, time);
}
else
{
Tizen.NUI.TimePeriod time = new Tizen.NUI.TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime));
AnimateBy(_prop, val, time);
}
}
/// <summary>
/// Animates a property to a destination value.<br />
/// </summary>
/// <param name="target">The target object to animate.</param>
/// <param name="property">The target property to animate.</param>
/// <param name="destinationValue">The destination value.</param>
/// <param name="alphaFunction">The alpha function to apply.</param>
/// <since_tizen> 3 </since_tizen>
public void AnimateTo(View target, string property, object destinationValue, AlphaFunction alphaFunction = null)
{
Property _prop = PropertyHelper.GetPropertyFromString(target, property);
PropertyType propertyType = target.GetPropertyType(_prop.propertyIndex);
if(propertyType.Equals(PropertyType.Float))
{
System.Type type = destinationValue.GetType();
if (type.Equals(typeof(System.Int32)) || type.Equals(typeof(int)))
{
int num = (int)destinationValue;
destinationValue = (float)num;
}
}
PropertyValue val = PropertyValue.CreateFromObject(destinationValue);
if (alphaFunction != null)
{
AnimateTo(_prop, val, alphaFunction);
}
else
{
AnimateTo(_prop, val);
}
}
private string[] _properties = null;
/// <summary>
/// Gets or sets the properties of the animation.
/// </summary>
public string[] Properties
{
get
{
return _properties;
}
set
{
_properties = value;
}
}
private string[] _destValue = null;
/// <summary>
/// Gets or sets the destination value for each property of the animation.
/// </summary>
public string[] DestValue
{
get
{
return _destValue;
}
set
{
_destValue = value;
}
}
private int[] _startTime = null;
/// <summary>
/// Gets or sets the start time for each property of the animation.
/// </summary>
public int[] StartTime
{
get
{
return _startTime;
}
set
{
_startTime = value;
}
}
private int[] _endTime = null;
/// <summary>
/// Gets or sets the end time for each property of the animation.
/// </summary>
public int[] EndTime
{
get
{
return _endTime;
}
set
{
_endTime = value;
}
}
/// <summary>
/// Animates one or more properties to a destination value.<br />
/// </summary>
/// <param name="target">The target object to animate.</param>
public void PlayAnimateTo(View target)
{
Clear();
if (_properties.Length == _destValue.Length && _startTime.Length == _endTime.Length && _properties.Length == _startTime.Length)
{
int length = _properties.Length;
for (int index = 0; index < length; index++)
{
//object destinationValue = _destValue[index];
var elementType = target.GetType();
PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == _properties[index]);
//var propertyInfo = elementType.GetRuntimeProperties().FirstOrDefault(p => p.Name == localName);
if (propertyInfo != null)
{
object destinationValue = ConvertTo(_destValue[index], propertyInfo.PropertyType);
if(destinationValue != null)
{
AnimateTo(target, _properties[index], destinationValue, _startTime[index], _endTime[index]);
}
}
}
Play();
}
}
internal object ConvertTo(object value, Type toType)
{
Func<object> getConverter = () =>
{
MemberInfo memberInfo;
string converterTypeName = GetTypeConverterTypeName(toType.GetTypeInfo().CustomAttributes);
if (converterTypeName == null)
return null;
Type convertertype = Type.GetType(converterTypeName);
return Activator.CreateInstance(convertertype);
};
return ConvertTo(value, toType, getConverter);
}
internal object ConvertTo(object value, Type toType, Func<object> getConverter)
{
if (value == null)
return null;
var str = value as string;
if (str != null)
{
//If there's a [TypeConverter], use it
object converter = getConverter?.Invoke();
var xfTypeConverter = converter as Tizen.NUI.Binding.TypeConverter;
if (xfTypeConverter != null)
return value = xfTypeConverter.ConvertFromInvariantString(str);
var converterType = converter?.GetType();
if (converterType != null)
{
var convertFromStringInvariant = converterType.GetRuntimeMethod("ConvertFromInvariantString",
new[] { typeof(string) });
if (convertFromStringInvariant != null)
return value = convertFromStringInvariant.Invoke(converter, new object[] { str });
}
//If the type is nullable, as the value is not null, it's safe to assume we want the built-in conversion
if (toType.GetTypeInfo().IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>))
toType = Nullable.GetUnderlyingType(toType);
//Obvious Built-in conversions
if (toType.GetTypeInfo().IsEnum)
return Enum.Parse(toType, str, true);
if (toType == typeof(SByte))
return SByte.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(Int16))
return Int16.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(Int32))
return Int32.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(Int64))
return Int64.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(Byte))
return Byte.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(UInt16))
return UInt16.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(UInt32))
return UInt32.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(UInt64))
return UInt64.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(Single))
return Single.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(Double))
return Double.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(Boolean))
return Boolean.Parse(str);
if (toType == typeof(TimeSpan))
return TimeSpan.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(DateTime))
return DateTime.Parse(str, CultureInfo.InvariantCulture);
if (toType == typeof(Char))
{
char c = '\0';
Char.TryParse(str, out c);
return c;
}
if (toType == typeof(String) && str.StartsWith("{}", StringComparison.Ordinal))
return str.Substring(2);
if (toType == typeof(String))
return value;
if (toType == typeof(Decimal))
return Decimal.Parse(str, CultureInfo.InvariantCulture);
}
//if the value is not assignable and there's an implicit conversion, convert
if (value != null && !toType.IsAssignableFrom(value.GetType()))
{
var opImplicit = GetImplicitConversionOperator(value.GetType(), value.GetType(), toType)
?? GetImplicitConversionOperator(toType, value.GetType(), toType);
//var opImplicit = value.GetType().GetImplicitConversionOperator(fromType: value.GetType(), toType: toType)
// ?? toType.GetImplicitConversionOperator(fromType: value.GetType(), toType: toType);
if (opImplicit != null)
{
value = opImplicit.Invoke(null, new[] { value });
return value;
}
}
var nativeValueConverterService = DependencyService.Get<INativeValueConverterService>();
object nativeValue = null;
if (nativeValueConverterService != null && nativeValueConverterService.ConvertTo(value, toType, out nativeValue))
return nativeValue;
return value;
}
internal string GetTypeConverterTypeName(IEnumerable<CustomAttributeData> attributes)
{
var converterAttribute =
attributes.FirstOrDefault(cad => Tizen.NUI.Binding.TypeConverterAttribute.TypeConvertersType.Contains(cad.AttributeType.FullName));
if (converterAttribute == null)
return null;
if (converterAttribute.ConstructorArguments[0].ArgumentType == typeof(string))
return (string)converterAttribute.ConstructorArguments[0].Value;
if (converterAttribute.ConstructorArguments[0].ArgumentType == typeof(Type))
return ((Type)converterAttribute.ConstructorArguments[0].Value).AssemblyQualifiedName;
return null;
}
internal MethodInfo GetImplicitConversionOperator(Type onType, Type fromType, Type toType)
{
#if NETSTANDARD1_0
var mi = onType.GetRuntimeMethod("op_Implicit", new[] { fromType });
#else
var bindingFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy;
var mi = onType.GetMethod("op_Implicit", bindingFlags, null, new[] { fromType }, null);
#endif
if (mi == null) return null;
if (!mi.IsSpecialName) return null;
if (!mi.IsPublic) return null;
if (!mi.IsStatic) return null;
if (!toType.IsAssignableFrom(mi.ReturnType)) return null;
return mi;
}
/// <summary>
/// Animates a property to a destination value.<br />
/// </summary>
/// <param name="target">The target object to animate.</param>
/// <param name="property">The target property to animate.</param>
/// <param name="destinationValue">The destination value.</param>
/// <param name="startTime">The start time of the animation.</param>
/// <param name="endTime">The end time of the animation.</param>
/// <param name="alphaFunction">The alpha function to apply.</param>
/// <since_tizen> 3 </since_tizen>
public void AnimateTo(View target, string property, object destinationValue, int startTime, int endTime, AlphaFunction alphaFunction = null)
{
Property _prop = PropertyHelper.GetPropertyFromString(target, property);
PropertyType propertyType = target.GetPropertyType(_prop.propertyIndex);
if(propertyType.Equals(PropertyType.Float))
{
System.Type type = destinationValue.GetType();
if (type.Equals(typeof(System.Int32)) || type.Equals(typeof(int)))
{
int num = (int)destinationValue;
destinationValue = (float)num;
}
}
PropertyValue val = PropertyValue.CreateFromObject(destinationValue);
if (alphaFunction != null)
{
Tizen.NUI.TimePeriod time = new Tizen.NUI.TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime));
AnimateTo(_prop, val, alphaFunction, time);
}
else
{
Tizen.NUI.TimePeriod time = new Tizen.NUI.TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime));
AnimateTo(_prop, val, time);
}
}
/// <summary>
/// Animates a property between keyframes.
/// </summary>
/// <param name="target">The target object to animate.</param>
/// <param name="property">The target property to animate.</param>
/// <param name="keyFrames">The set of time or value pairs between which to animate.</param>
/// <param name="interpolation">The method used to interpolate between values.</param>
/// <param name="alphaFunction">The alpha function to apply.</param>
/// <since_tizen> 3 </since_tizen>
public void AnimateBetween(View target, string property, KeyFrames keyFrames, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
{
Property _prop = PropertyHelper.GetPropertyFromString(target, property);
if (_prop.propertyIndex == Property.INVALID_INDEX)
{
throw new System.ArgumentException("second argument string property is invalid parameter!");
}
if (alphaFunction != null)
{
AnimateBetween(_prop, keyFrames, alphaFunction, interpolation);
}
else
{
AnimateBetween(_prop, keyFrames, interpolation);
}
}
/// <summary>
/// Animates a property between keyframes.
/// </summary>
/// <param name="target">The target object to animate</param>
/// <param name="property">The target property to animate</param>
/// <param name="keyFrames">The set of time/value pairs between which to animate</param>
/// <param name="startTime">The start time of animation in milliseconds.</param>
/// <param name="endTime">The end time of animation in milliseconds.</param>
/// <param name="interpolation">The method used to interpolate between values.</param>
/// <param name="alphaFunction">The alpha function to apply.</param>
/// <since_tizen> 3 </since_tizen>
public void AnimateBetween(View target, string property, KeyFrames keyFrames, int startTime, int endTime, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null)
{
Property _prop = PropertyHelper.GetPropertyFromString(target, property);
Tizen.NUI.TimePeriod time = new Tizen.NUI.TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime));
if (alphaFunction != null)
{
AnimateBetween(_prop, keyFrames, alphaFunction, time, interpolation);
}
else
{
AnimateBetween(_prop, keyFrames, time, interpolation);
}
}
/// <summary>
/// Animates the view's position and orientation through a predefined path.<br />
/// The view will rotate to orient the supplied forward vector with the path's tangent.<br />
/// If forward is the zero vector then no rotation will happen.<br />
/// </summary>
/// <param name="view">The view to animate.</param>
/// <param name="path">It defines position and orientation.</param>
/// <param name="forward">The vector (in local space coordinate system) will be oriented with the path's tangent direction.</param>
/// <param name="alphaFunction">The alpha function to apply.</param>
/// <since_tizen> 3 </since_tizen>
public void AnimatePath(View view, Path path, Vector3 forward, AlphaFunction alphaFunction = null)
{
if (alphaFunction == null)
{
Animate(view, path, forward);
}
else
{
Animate(view, path, forward, alphaFunction);
}
}
/// <summary>
/// Animates the view's position and orientation through a predefined path.<br />
/// The view will rotate to orient the supplied forward vector with the path's tangent.<br />
/// If forward is the zero vector then no rotation will happen.<br />
/// </summary>
/// <param name="view">The view to animate.</param>
/// <param name="path">It defines position and orientation.</param>
/// <param name="forward">The vector (in local space coordinate system) will be oriented with the path's tangent direction.</param>
/// <param name="startTime">The start time of the animation.</param>
/// <param name="endTime">The end time of the animation.</param>
/// <param name="alphaFunction">The alpha function to apply.</param>
/// <since_tizen> 3 </since_tizen>
public void AnimatePath(View view, Path path, Vector3 forward, int startTime, int endTime, AlphaFunction alphaFunction = null)
{
TimePeriod time = new TimePeriod(MilliSecondsToSeconds(startTime), MilliSecondsToSeconds(endTime - startTime));
if (alphaFunction == null)
{
Animate(view, path, forward, time);
}
else
{
Animate(view, path, forward, alphaFunction, time);
}
}
/// <summary>
/// Creates an initialized animation.<br />
/// The animation will not loop.<br />
/// The default end action is "Cancel".<br />
/// The default alpha function is linear.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public Animation() : this(NDalicPINVOKE.Animation_New(0.0f), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal Animation(float durationSeconds) : this(NDalicPINVOKE.Animation_New(durationSeconds), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// Downcasts a handle to animation handle.<br />
/// If handle points to an animation object, the downcast produces a valid handle.<br />
/// If not, the returned handle is left uninitialized.<br />
/// </summary>
/// <param name="handle">Handle to an object.</param>
/// <returns>Handle to an animation object or an uninitialized handle.</returns>
/// <since_tizen> 3 </since_tizen>
public static Animation DownCast(BaseHandle handle)
{
Animation ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Animation;
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal Animation(Animation handle) : this(NDalicPINVOKE.new_Animation__SWIG_1(Animation.getCPtr(handle)), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal Animation Assign(Animation rhs)
{
Animation ret = new Animation(NDalicPINVOKE.Animation_Assign(swigCPtr, Animation.getCPtr(rhs)), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal void SetDuration(float seconds)
{
NDalicPINVOKE.Animation_SetDuration(swigCPtr, seconds);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();