[NUI] Sync Xaml code to newest (#795)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / XamlBinding / Transition.cs
1 using System.Collections.Generic;
2 using System.ComponentModel;
3 using System.IO;
4 using System.Linq;
5 using System.Reflection;
6 using Tizen.NUI.BaseComponents;
7 using Tizen.NUI.Binding;
8 using Tizen.NUI.Xaml;
9 using static Tizen.NUI.Animation;
10
11 namespace Tizen.NUI
12 {
13     /// <since_tizen> 5 </since_tizen>
14     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
15     [EditorBrowsable(EditorBrowsableState.Never)]
16     public class AnimationBehavior
17     {
18         private string _key = null;
19         /// <since_tizen> 5 </since_tizen>
20         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
21         [EditorBrowsable(EditorBrowsableState.Never)]
22         public string Key
23         {
24             get
25             {
26                 return _key;
27             }
28             set
29             {
30                 _key = value;
31             }
32         }
33
34         private string _property = null;
35
36         /// <since_tizen> 5 </since_tizen>
37         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
38         [EditorBrowsable(EditorBrowsableState.Never)]
39         public string Property
40         {
41             get
42             {
43                 return _property;
44             }
45             set
46             {
47                 _property = value;
48             }
49         }
50
51         private string _destValue = null;
52
53         /// <since_tizen> 5 </since_tizen>
54         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         public string DestValue
57         {
58             get
59             {
60                 return _destValue;
61             }
62             set
63             {
64                 _destValue = value;
65             }
66         }
67
68         private int _startTime = -1;
69
70         /// <since_tizen> 5 </since_tizen>
71         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
72         [EditorBrowsable(EditorBrowsableState.Never)]
73         public int StartTime
74         {
75             get
76             {
77                 return _startTime;
78             }
79             set
80             {
81                 _startTime = value;
82             }
83         }
84
85         private int _endTime = -1;
86
87         /// <since_tizen> 5 </since_tizen>
88         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
89         [EditorBrowsable(EditorBrowsableState.Never)]
90         public int EndTime
91         {
92             get
93             {
94                 return _endTime;
95             }
96             set
97             {
98                 _endTime = value;
99             }
100         }
101     }
102
103     /// <since_tizen> 5 </since_tizen>
104     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
105     [EditorBrowsable(EditorBrowsableState.Never)]
106     public class Transition : Animation
107     {
108         private string name;
109
110         /// <since_tizen> 5 </since_tizen>
111         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
112         [EditorBrowsable(EditorBrowsableState.Never)]
113         public string Name
114         {
115             get
116             {
117                 return name;
118             }
119             set
120             {
121                 name = value;
122             }
123         }
124
125         private Dictionary<string, AnimationBehavior> behaviors = new Dictionary<string, AnimationBehavior>();
126
127         /// <since_tizen> 5 </since_tizen>
128         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
129         [EditorBrowsable(EditorBrowsableState.Never)]
130         public AnimationBehavior[] Behaviors
131         {
132             set
133             {
134                 if (null != value)
135                 {
136                     foreach (AnimationBehavior behavior in value)
137                     {
138                         behaviors.Add(behavior.Key, behavior);
139                     }
140                 }
141             }
142         }
143
144         /// <since_tizen> 5 </since_tizen>
145         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
146         [EditorBrowsable(EditorBrowsableState.Never)]
147         public void AnimateTo(View instance, string behaviorKey)
148         {
149             AnimationBehavior behavior = null;
150             behaviors.TryGetValue(behaviorKey, out behavior);
151
152             if (null != behavior)
153             {
154                 var elementType = instance.GetType();
155                 PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == behavior.Property);
156
157                 if (propertyInfo != null)
158                 {
159                     object destinationValue = ConvertTo(behavior.DestValue, propertyInfo.PropertyType);
160
161                     if (destinationValue != null)
162                     {
163                         if (0 <= behavior.StartTime)
164                         {
165                             AnimateTo(instance, behavior.Property, destinationValue, behavior.StartTime, behavior.EndTime);
166                         }
167                         else
168                         {
169                             AnimateTo(instance, behavior.Property, destinationValue);
170                         }
171                     }
172                 }
173             }
174             else
175             {
176                 throw new XamlParseException(string.Format("Behaviors don't have key {0}", behaviorKey), new XmlLineInfo());
177             }
178         }
179
180         /// <since_tizen> 5 </since_tizen>
181         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
182         [EditorBrowsable(EditorBrowsableState.Never)]
183         public void AnimateBy(View instance, string behaviorKey)
184         {
185             AnimationBehavior behavior = null;
186             behaviors.TryGetValue(behaviorKey, out behavior);
187
188             if (null != behavior)
189             {
190                 var elementType = instance.GetType();
191                 PropertyInfo propertyInfo = elementType.GetProperties().FirstOrDefault(fi => fi.Name == behavior.Property);
192
193                 if (propertyInfo != null)
194                 {
195                     object destinationValue = ConvertTo(behavior.DestValue, propertyInfo.PropertyType);
196
197                     if (destinationValue != null)
198                     {
199                         if (0 <= behavior.StartTime)
200                         {
201                             AnimateBy(instance, behavior.Property, destinationValue, behavior.StartTime, behavior.EndTime);
202                         }
203                         else
204                         {
205                             AnimateBy(instance, behavior.Property, destinationValue);
206                         }
207                     }
208                 }
209             }
210             else
211             {
212                 throw new XamlParseException(string.Format("Behaviors don't have key {0}", behaviorKey), new XmlLineInfo());
213             }
214         }
215     }
216 }