[ACR-564] deprecate unused API
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Transit.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections;
19 using System.Collections.Generic;
20 using System.Collections.ObjectModel;
21 using System.Collections.Specialized;
22 using static Interop.Elementary;
23
24 namespace ElmSharp
25 {
26     /// <summary>
27     /// Transit is designed to apply various animated transition effects, such as translation, rotation, etc.
28     /// For using these effects, create a transit and add the desired transition effects.
29     /// </summary>
30     /// <remarks>Transit is not reusable. If the effect ends, the transit is destroyed automatically.</remarks>
31     /// <since_tizen> preview </since_tizen>
32     [Obsolete("This has been deprecated in API12")]
33     public class Transit : IDisposable
34     {
35         IntPtr _handle = IntPtr.Zero;
36         bool _isDisposed = false;
37         ObservableCollection<EvasObject> _objects = new ObservableCollection<EvasObject>();
38         ObservableCollection<Transit> _chains = new ObservableCollection<Transit>();
39         HashSet<object> _checker = new HashSet<object>();
40         Elm_Transit_Del_Cb DeletedCallback;
41         Elm_Transit_Effect_End_Cb EffectEndCallback;
42         Elm_Transit_Effect_Transition_Cb EffectTransitionCallback;
43
44         /// <summary>
45         /// A callback is called when the transit is deleted.
46         /// </summary>
47         /// <since_tizen> preview </since_tizen>
48         [Obsolete("This has been deprecated in API12")]
49         public event EventHandler Deleted;
50
51         /// <summary>
52         /// Creates and initializes a new instance of the Transit class.
53         /// </summary>
54         /// <since_tizen> preview </since_tizen>
55         [Obsolete("This has been deprecated in API12")]
56         public Transit()
57         {
58             _handle = Interop.Elementary.elm_transit_add();
59             DeletedCallback = (ptr1, ptr2) =>
60             {
61                 Deleted?.Invoke(this, EventArgs.Empty);
62                 Dispose(true);
63             };
64             Interop.Elementary.elm_transit_del_cb_set(_handle, DeletedCallback, IntPtr.Zero);
65             ((INotifyCollectionChanged)_objects).CollectionChanged += OnObjectCollectionChanged;
66             ((INotifyCollectionChanged)_chains).CollectionChanged += OnChaninCollectionChanged;
67         }
68
69         /// <summary>
70         /// Destroys the transit object.
71         /// </summary>
72         ~Transit()
73         {
74             Dispose(false);
75         }
76
77         /// <summary>
78         /// Gets or sets the transit animation time.
79         /// </summary>
80         /// <since_tizen> preview </since_tizen>
81         [Obsolete("This has been deprecated in API12")]
82         public double Duration
83         {
84             get
85             {
86                 return Interop.Elementary.elm_transit_duration_get(_handle);
87             }
88             set
89             {
90                 Interop.Elementary.elm_transit_duration_set(_handle, value);
91             }
92         }
93
94         /// <summary>
95         /// Gets or sets a value whether the objects states will be kept or not.
96         /// If it is not kept, the objects states will be reset when the transition ends.
97         /// </summary>
98         /// <since_tizen> preview </since_tizen>
99         [Obsolete("This has been deprecated in API12")]
100         public bool ObjectStateKeep
101         {
102             get
103             {
104                 return Interop.Elementary.elm_transit_objects_final_state_keep_get(_handle);
105             }
106             set
107             {
108                 Interop.Elementary.elm_transit_objects_final_state_keep_set(_handle, value);
109             }
110         }
111
112         /// <summary>
113         /// Gets or sets the transit animation acceleration type.
114         /// </summary>
115         /// <since_tizen> preview </since_tizen>
116         [Obsolete("This has been deprecated in API12")]
117         public TweenMode TweenMode
118         {
119             get
120             {
121                 return (TweenMode)Interop.Elementary.elm_transit_tween_mode_get(_handle);
122             }
123             set
124             {
125                 Interop.Elementary.elm_transit_tween_mode_set(_handle, (int)value);
126             }
127         }
128
129         /// <summary>
130         /// Gets or sets the transit repeat count.
131         /// If the repeat is a negative number, it will repeat infinite times.
132         /// </summary>
133         /// <since_tizen> preview </since_tizen>
134         [Obsolete("This has been deprecated in API12")]
135         public int Repeat
136         {
137             get
138             {
139                 return Interop.Elementary.elm_transit_repeat_times_get(_handle);
140             }
141             set
142             {
143                 Interop.Elementary.elm_transit_repeat_times_set(_handle, value);
144             }
145         }
146
147         /// <summary>
148         /// Gets or sets if auto reverse is on.
149         /// </summary>
150         /// <since_tizen> preview </since_tizen>
151         [Obsolete("This has been deprecated in API12")]
152         public bool AutoReverse
153         {
154             get
155             {
156                 return Interop.Elementary.elm_transit_auto_reverse_get(_handle);
157             }
158             set
159             {
160                 Interop.Elementary.elm_transit_auto_reverse_set(_handle, value);
161             }
162         }
163
164         /// <summary>
165         /// Gets or sets the event enabled when transit is operating.
166         /// </summary>
167         /// <since_tizen> preview </since_tizen>
168         [Obsolete("This has been deprecated in API12")]
169         public bool EventEnabled
170         {
171             get
172             {
173                 return Interop.Elementary.elm_transit_event_enabled_get(_handle);
174             }
175             set
176             {
177                 Interop.Elementary.elm_transit_event_enabled_set(_handle, value);
178             }
179         }
180
181         /// <summary>
182         /// Gets or sets the smooth scaling for transit map rendering.
183         /// This gets the smooth scaling for transit map rendering.
184         /// </summary>
185         /// <since_tizen> preview </since_tizen>
186         [Obsolete("This has been deprecated in API12")]
187         public bool Smooth
188         {
189             get
190             {
191                 return Interop.Elementary.elm_transit_smooth_get(_handle);
192             }
193             set
194             {
195                 Interop.Elementary.elm_transit_smooth_set(_handle, value);
196             }
197         }
198
199         /// <summary>
200         /// Gets the time progression of the animation (a double value between 0.0 and 1.0).
201         /// The value returned is a fraction (current time/total time).
202         /// It represents the progression position relative to the total.
203         /// </summary>
204         /// <since_tizen> preview </since_tizen>
205         [Obsolete("This has been deprecated in API12")]
206         public double Progress
207         {
208             get
209             {
210                 return Interop.Elementary.elm_transit_progress_value_get(_handle);
211             }
212         }
213
214         /// <summary>
215         /// Gets or sets the transit animation tween mode acceleration factor.
216         /// </summary>
217         /// <returns>A factor value from 0.0 to 1.0.</returns>
218         /// <since_tizen> preview </since_tizen>
219         [Obsolete("This has been deprecated in API12")]
220         public double BeginAccelerationFactor
221         {
222             get
223             {
224                 double begin = 1.0, end = 0.0;
225                 Interop.Elementary.elm_transit_tween_mode_factor_get(_handle, out begin, out end);
226                 return begin;
227             }
228             set
229             {
230                 Interop.Elementary.elm_transit_tween_mode_factor_set(_handle, value, EndAccelerationFactor);
231             }
232         }
233
234         /// <summary>
235         /// Gets or sets the transit animation tween mode acceleration factor.
236         /// </summary>
237         /// <returns>A factor value from 0.0 to 1.0.</returns>
238         /// <since_tizen> preview </since_tizen>
239         [Obsolete("This has been deprecated in API12")]
240         public double EndAccelerationFactor
241         {
242             get
243             {
244                 double begin = 1.0, end = 0.0;
245                 Interop.Elementary.elm_transit_tween_mode_factor_get(_handle, out begin, out end);
246                 return end;
247             }
248             set
249             {
250                 Interop.Elementary.elm_transit_tween_mode_factor_set(_handle, BeginAccelerationFactor, value);
251             }
252         }
253
254         /// <summary>
255         /// Starts the transition in given seconds.
256         /// Once this API is called, the transit begins to measure the time.
257         /// </summary>
258         /// <param name="interval">The interval value in seconds.</param>
259         /// <since_tizen> preview </since_tizen>
260         [Obsolete("This has been deprecated in API12")]
261         public void Go(double interval = 0)
262         {
263             if (interval == 0)
264             {
265                 // To start transition immediately, elm_transit_go() is called.
266                 Interop.Elementary.elm_transit_go(_handle);
267             }
268             else
269             {
270                 // elm_transit_go_in() uses timer so it does not start transition immediately although interval is 0.
271                 Interop.Elementary.elm_transit_go_in(_handle, interval);
272             }
273         }
274
275         /// <summary>
276         /// Pauses the transition.
277         /// </summary>
278         /// <since_tizen> preview </since_tizen>
279         [Obsolete("This has been deprecated in API12")]
280         public void Pause()
281         {
282             if (Interop.Elementary.elm_transit_paused_get(_handle) == false)
283                 Interop.Elementary.elm_transit_paused_set(_handle, true);
284         }
285
286         /// <summary>
287         /// Resumes the transition.
288         /// </summary>
289         /// <since_tizen> preview </since_tizen>
290         [Obsolete("This has been deprecated in API12")]
291         public void Resume()
292         {
293             if (Interop.Elementary.elm_transit_paused_get(_handle) == true)
294                 Interop.Elementary.elm_transit_paused_set(_handle, false);
295         }
296
297         /// <summary>
298         /// Gets the current chained transit list.
299         /// </summary>
300         /// <remarks>Cannot add the duplicate transit.</remarks>
301         /// <since_tizen> preview </since_tizen>
302         [Obsolete("This has been deprecated in API12")]
303         public IList<Transit> Chains
304         {
305             get { return _chains; }
306         }
307
308         /// <summary>
309         /// Gets the objects list of the transit.
310         /// </summary>
311         /// <remarks>Cannot add the duplicate object.</remarks>
312         /// <since_tizen> preview </since_tizen>
313         [Obsolete("This has been deprecated in API12")]
314         public IList<EvasObject> Objects
315         {
316             get { return _objects; }
317         }
318
319         /// <summary>
320         /// Adds the effect.
321         /// </summary>
322         /// <param name="effect">EffectBase object.</param>
323         /// <since_tizen> preview </since_tizen>
324         [Obsolete("This has been deprecated in API12")]
325         public void AddEffect(EffectBase effect)
326         {
327             IntPtr _effect = effect.CreateEffect(_handle);
328             EffectEndCallback = (effectPtr, transitPtr) => { effect.SendEffectEnd(); };
329             EffectTransitionCallback = (effectPtr, transitPtr, progress) => { };
330             Interop.Elementary.elm_transit_effect_add(_handle, EffectTransitionCallback, _effect, EffectEndCallback);
331         }
332
333         /// <summary>
334         /// Destroys the current object.
335         /// </summary>
336         /// <since_tizen> preview </since_tizen>
337         [Obsolete("This has been deprecated in API12")]
338         public void Dispose()
339         {
340             Dispose(true);
341             GC.SuppressFinalize(this);
342         }
343
344         /// <summary>
345         /// Releases all the resources currently used by this instance.
346         /// </summary>
347         /// <param name="disposing">
348         /// true if the managed resources should be disposed,
349         /// otherwise false.
350         /// </param>
351         /// <since_tizen> preview </since_tizen>
352         [Obsolete("This has been deprecated in API12")]
353         protected virtual void Dispose(bool disposing)
354         {
355             if (_isDisposed)
356                 return;
357
358             if (disposing)
359             {
360                 ((INotifyCollectionChanged)_chains).CollectionChanged -= OnChaninCollectionChanged;
361                 _chains.Clear();
362                 ((INotifyCollectionChanged)_objects).CollectionChanged -= OnObjectCollectionChanged;
363                 _objects.Clear();
364                 _checker.Clear();
365             }
366
367             _isDisposed = true;
368         }
369
370         void OnObjectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
371         {
372             if (e.Action == NotifyCollectionChangedAction.Add)
373             {
374                 foreach (EvasObject item in e.NewItems)
375                     AddObject(item);
376             }
377             else if (e.Action == NotifyCollectionChangedAction.Remove)
378             {
379                 foreach (EvasObject item in e.OldItems)
380                     RemoveObject(item);
381             }
382         }
383
384         void OnChaninCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
385         {
386             if (e.Action == NotifyCollectionChangedAction.Add)
387             {
388                 foreach (Transit item in e.NewItems)
389                     AddChainedTransit(item);
390             }
391             else if (e.Action == NotifyCollectionChangedAction.Remove)
392             {
393                 foreach (Transit item in e.OldItems)
394                     DeleteChainedTransit(item);
395             }
396         }
397
398         /// <summary>
399         /// Adds a new object to apply the effects.
400         /// After the first addition of an object to transit, if its object list becomes empty again, the transit will be killed.
401         /// If the object belongs to another transit, the object will be removed from it and it will only belong to the other transit.
402         /// </summary>
403         /// <remarks>It is not allowed to add a new object after the transit begins.</remarks>
404         /// <param name="obj">Object to be animated.</param>
405         void AddObject(EvasObject obj)
406         {
407             if (_checker.Contains(obj))
408                 throw new InvalidOperationException("Cannot add the duplicate object.");
409
410             _checker.Add(obj);
411             Interop.Elementary.elm_transit_object_add(_handle, obj);
412         }
413
414         /// <summary>
415         /// Removes an added object from the transit.
416         /// </summary>
417         /// <param name="obj">Object to be removed from transit.</param>
418         void RemoveObject(EvasObject obj)
419         {
420             if (_checker.Contains(obj))
421                 _checker.Remove(obj);
422
423             Interop.Elementary.elm_transit_object_remove(_handle, obj);
424         }
425
426         /// <summary>
427         /// Makes the chain relationship between two transits.
428         /// </summary>
429         /// <param name="transit">The chain transit object. This transit will be operated after the transit is done.</param>
430         void AddChainedTransit(Transit transit)
431         {
432             if (_checker.Contains(transit))
433                 throw new InvalidOperationException("Cannot add the duplicate transit.");
434
435             _checker.Add(transit);
436             Interop.Elementary.elm_transit_chain_transit_add(_handle, transit._handle);
437         }
438
439         /// <summary>
440         /// Cuts off the chain relationship between two transits.
441         /// </summary>
442         /// <param name="transit">The chain transit object.</param>
443         void DeleteChainedTransit(Transit transit)
444         {
445             if (_checker.Contains(transit))
446                 _checker.Remove(transit);
447
448             Interop.Elementary.elm_transit_chain_transit_del(_handle, transit._handle);
449         }
450     }
451 }