2 * Copyright (c) 2017 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.
18 using System.Collections;
19 using System.Collections.Generic;
20 using System.Collections.ObjectModel;
21 using System.Collections.Specialized;
22 using static Interop.Elementary;
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.
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
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;
45 /// A callback is called when the transit is deleted.
47 /// <since_tizen> preview </since_tizen>
48 [Obsolete("This has been deprecated in API12")]
49 public event EventHandler Deleted;
52 /// Creates and initializes a new instance of the Transit class.
54 /// <since_tizen> preview </since_tizen>
55 [Obsolete("This has been deprecated in API12")]
58 _handle = Interop.Elementary.elm_transit_add();
59 DeletedCallback = (ptr1, ptr2) =>
61 Deleted?.Invoke(this, EventArgs.Empty);
64 Interop.Elementary.elm_transit_del_cb_set(_handle, DeletedCallback, IntPtr.Zero);
65 ((INotifyCollectionChanged)_objects).CollectionChanged += OnObjectCollectionChanged;
66 ((INotifyCollectionChanged)_chains).CollectionChanged += OnChaninCollectionChanged;
70 /// Destroys the transit object.
78 /// Gets or sets the transit animation time.
80 /// <since_tizen> preview </since_tizen>
81 [Obsolete("This has been deprecated in API12")]
82 public double Duration
86 return Interop.Elementary.elm_transit_duration_get(_handle);
90 Interop.Elementary.elm_transit_duration_set(_handle, value);
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.
98 /// <since_tizen> preview </since_tizen>
99 [Obsolete("This has been deprecated in API12")]
100 public bool ObjectStateKeep
104 return Interop.Elementary.elm_transit_objects_final_state_keep_get(_handle);
108 Interop.Elementary.elm_transit_objects_final_state_keep_set(_handle, value);
113 /// Gets or sets the transit animation acceleration type.
115 /// <since_tizen> preview </since_tizen>
116 [Obsolete("This has been deprecated in API12")]
117 public TweenMode TweenMode
121 return (TweenMode)Interop.Elementary.elm_transit_tween_mode_get(_handle);
125 Interop.Elementary.elm_transit_tween_mode_set(_handle, (int)value);
130 /// Gets or sets the transit repeat count.
131 /// If the repeat is a negative number, it will repeat infinite times.
133 /// <since_tizen> preview </since_tizen>
134 [Obsolete("This has been deprecated in API12")]
139 return Interop.Elementary.elm_transit_repeat_times_get(_handle);
143 Interop.Elementary.elm_transit_repeat_times_set(_handle, value);
148 /// Gets or sets if auto reverse is on.
150 /// <since_tizen> preview </since_tizen>
151 [Obsolete("This has been deprecated in API12")]
152 public bool AutoReverse
156 return Interop.Elementary.elm_transit_auto_reverse_get(_handle);
160 Interop.Elementary.elm_transit_auto_reverse_set(_handle, value);
165 /// Gets or sets the event enabled when transit is operating.
167 /// <since_tizen> preview </since_tizen>
168 [Obsolete("This has been deprecated in API12")]
169 public bool EventEnabled
173 return Interop.Elementary.elm_transit_event_enabled_get(_handle);
177 Interop.Elementary.elm_transit_event_enabled_set(_handle, value);
182 /// Gets or sets the smooth scaling for transit map rendering.
183 /// This gets the smooth scaling for transit map rendering.
185 /// <since_tizen> preview </since_tizen>
186 [Obsolete("This has been deprecated in API12")]
191 return Interop.Elementary.elm_transit_smooth_get(_handle);
195 Interop.Elementary.elm_transit_smooth_set(_handle, value);
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.
204 /// <since_tizen> preview </since_tizen>
205 [Obsolete("This has been deprecated in API12")]
206 public double Progress
210 return Interop.Elementary.elm_transit_progress_value_get(_handle);
215 /// Gets or sets the transit animation tween mode acceleration factor.
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
224 double begin = 1.0, end = 0.0;
225 Interop.Elementary.elm_transit_tween_mode_factor_get(_handle, out begin, out end);
230 Interop.Elementary.elm_transit_tween_mode_factor_set(_handle, value, EndAccelerationFactor);
235 /// Gets or sets the transit animation tween mode acceleration factor.
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
244 double begin = 1.0, end = 0.0;
245 Interop.Elementary.elm_transit_tween_mode_factor_get(_handle, out begin, out end);
250 Interop.Elementary.elm_transit_tween_mode_factor_set(_handle, BeginAccelerationFactor, value);
255 /// Starts the transition in given seconds.
256 /// Once this API is called, the transit begins to measure the time.
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)
265 // To start transition immediately, elm_transit_go() is called.
266 Interop.Elementary.elm_transit_go(_handle);
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);
276 /// Pauses the transition.
278 /// <since_tizen> preview </since_tizen>
279 [Obsolete("This has been deprecated in API12")]
282 if (Interop.Elementary.elm_transit_paused_get(_handle) == false)
283 Interop.Elementary.elm_transit_paused_set(_handle, true);
287 /// Resumes the transition.
289 /// <since_tizen> preview </since_tizen>
290 [Obsolete("This has been deprecated in API12")]
293 if (Interop.Elementary.elm_transit_paused_get(_handle) == true)
294 Interop.Elementary.elm_transit_paused_set(_handle, false);
298 /// Gets the current chained transit list.
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
305 get { return _chains; }
309 /// Gets the objects list of the transit.
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
316 get { return _objects; }
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)
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);
334 /// Destroys the current object.
336 /// <since_tizen> preview </since_tizen>
337 [Obsolete("This has been deprecated in API12")]
338 public void Dispose()
341 GC.SuppressFinalize(this);
345 /// Releases all the resources currently used by this instance.
347 /// <param name="disposing">
348 /// true if the managed resources should be disposed,
351 /// <since_tizen> preview </since_tizen>
352 [Obsolete("This has been deprecated in API12")]
353 protected virtual void Dispose(bool disposing)
360 ((INotifyCollectionChanged)_chains).CollectionChanged -= OnChaninCollectionChanged;
362 ((INotifyCollectionChanged)_objects).CollectionChanged -= OnObjectCollectionChanged;
370 void OnObjectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
372 if (e.Action == NotifyCollectionChangedAction.Add)
374 foreach (EvasObject item in e.NewItems)
377 else if (e.Action == NotifyCollectionChangedAction.Remove)
379 foreach (EvasObject item in e.OldItems)
384 void OnChaninCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
386 if (e.Action == NotifyCollectionChangedAction.Add)
388 foreach (Transit item in e.NewItems)
389 AddChainedTransit(item);
391 else if (e.Action == NotifyCollectionChangedAction.Remove)
393 foreach (Transit item in e.OldItems)
394 DeleteChainedTransit(item);
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.
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)
407 if (_checker.Contains(obj))
408 throw new InvalidOperationException("Cannot add the duplicate object.");
411 Interop.Elementary.elm_transit_object_add(_handle, obj);
415 /// Removes an added object from the transit.
417 /// <param name="obj">Object to be removed from transit.</param>
418 void RemoveObject(EvasObject obj)
420 if (_checker.Contains(obj))
421 _checker.Remove(obj);
423 Interop.Elementary.elm_transit_object_remove(_handle, obj);
427 /// Makes the chain relationship between two transits.
429 /// <param name="transit">The chain transit object. This transit will be operated after the transit is done.</param>
430 void AddChainedTransit(Transit transit)
432 if (_checker.Contains(transit))
433 throw new InvalidOperationException("Cannot add the duplicate transit.");
435 _checker.Add(transit);
436 Interop.Elementary.elm_transit_chain_transit_add(_handle, transit._handle);
440 /// Cuts off the chain relationship between two transits.
442 /// <param name="transit">The chain transit object.</param>
443 void DeleteChainedTransit(Transit transit)
445 if (_checker.Contains(transit))
446 _checker.Remove(transit);
448 Interop.Elementary.elm_transit_chain_transit_del(_handle, transit._handle);