[NUI] Re-structuring NUI by classifying modules
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Animation / TransitionOptions.cs
1 /*
2  * Copyright (c) 2020 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.Generic;
19 using System.ComponentModel;
20 using System.Text;
21 using Tizen.Applications;
22 using Tizen.NUI.BaseComponents;
23
24 namespace Tizen.NUI
25 {
26     /// <summary>
27     /// Setting screen transition options.
28     /// This is used to describe the transition of NUIApplication.
29     /// </summary>
30     /// <seealso cref="NUIApplication.TransitionOptions" />
31     [EditorBrowsable(EditorBrowsableState.Never)]
32     public class TransitionOptions : IDisposable
33     {
34         private bool disposed = false;
35         private FrameProvider frameProvider;
36         private DefaultFrameBroker frameBroker;
37
38         private bool enableTransition = false;
39         private Window mainWindow;
40         private View animatedTarget;
41         private string sharedId;
42
43         /// <summary>
44         /// Initializes the TransitionOptions class.
45         /// </summary>
46         /// <param name="window">The window instance of NUI Window</param>
47         [EditorBrowsable(EditorBrowsableState.Never)]
48         public TransitionOptions(Window window)
49         {
50             mainWindow = window;
51         }
52
53
54         /// <summary>
55         /// Set animated view of seamless animation.
56         /// </summary>
57         [EditorBrowsable(EditorBrowsableState.Never)]
58         public View AnimatedTarget
59         {
60             get
61             {
62                 return animatedTarget;
63             }
64             set
65             {
66                 animatedTarget = value;
67             }
68         }
69
70         /// <summary>
71         /// Gets or sets transition enable
72         /// </summary>
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public bool EnableTransition
75         {
76             get
77             {
78                 return enableTransition;
79             }
80
81             set
82             {
83                 if (value)
84                 {
85                     frameBroker = new DefaultFrameBroker(mainWindow);
86                     frameBroker.mainView = animatedTarget;
87                     frameBroker.AnimationInitialized += FrameBroker_TransitionAnimationInitialized;
88                     frameBroker.AnimationFinished += FrameBroker_TransitionAnimationFinished;
89                     EnableProvider();
90                 }
91                 enableTransition = value;
92             }
93         }
94
95         private void EnableProvider()
96         {
97             frameProvider = new FrameProvider(mainWindow);
98             frameProvider.Shown += FrameProvider_Shown;
99             frameProvider.Hidden += FrameProvider_Hidden;
100         }
101
102         /// <summary>
103         /// Gets or sets the Shared object Id
104         /// </summary>
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public String SharedId
107         {
108             set
109             {
110                 sharedId = value;
111             }
112             get
113             {
114                 return sharedId;
115             }
116         }
117
118         /// <summary>
119         /// Gets or sets the forward animation of launching
120         /// </summary>
121         [EditorBrowsable(EditorBrowsableState.Never)]
122         public TransitionAnimation ForwardAnimation
123         {
124             get
125             {
126                 return frameBroker?.ForwardAnimation;
127             }
128             set
129             {
130                 if (frameBroker != null)
131                 {
132                     frameBroker.ForwardAnimation = value;
133                 }
134             }
135         }
136
137         /// <summary>
138         /// Gets or sets the backward animation of launching
139         /// </summary>
140         [EditorBrowsable(EditorBrowsableState.Never)]
141         public TransitionAnimation BackwardAnimation
142
143         {
144             get
145             {
146                 return frameBroker?.BackwardAnimation;
147             }
148             set
149             {
150                 if (frameBroker != null)
151                 {
152                     frameBroker.BackwardAnimation = value;
153                 }
154             }
155         }
156
157         /// <summary>
158         /// Emits the event when the animation is started.
159         /// </summary>
160         [EditorBrowsable(EditorBrowsableState.Never)]
161         public delegate void AnimationEventHandler(bool direction);
162
163         /// <summary>
164         /// Emits the event when the animation is started.
165         /// </summary>
166         [EditorBrowsable(EditorBrowsableState.Never)]
167         public event AnimationEventHandler AnimationInitialized;
168
169         /// <summary>
170         /// Emits the event when the animation is finished.
171         /// </summary>
172         [EditorBrowsable(EditorBrowsableState.Never)]
173         public event AnimationEventHandler AnimationFinished;
174
175         private void FrameBroker_TransitionAnimationFinished(bool direction)
176         {
177             AnimationFinished?.Invoke(direction);
178         }
179
180         private void FrameBroker_TransitionAnimationInitialized(bool direction)
181         {
182             AnimationInitialized?.Invoke(direction);
183         }
184
185         /// <summary>
186         /// Occurs whenever the window is shown on caller application.
187         /// </summary>
188         [EditorBrowsable(EditorBrowsableState.Never)]
189         public event EventHandler CallerScreenShown;
190
191         /// <summary>
192         /// Occurs whenever the window is hidden on caller application.
193         /// </summary>
194         [EditorBrowsable(EditorBrowsableState.Never)]
195         public event EventHandler CallerScreenHidden;
196
197         private void FrameProvider_Shown(object sender, EventArgs e)
198         {
199             Bundle bundle = new Bundle();
200             //Set information of shared object
201             frameProvider?.NotifyShowStatus(bundle);
202
203             CallerScreenShown?.Invoke(this, e);
204             bundle.Dispose();
205             bundle = null;
206         }
207
208         private void FrameProvider_Hidden(object sender, EventArgs e)
209         {
210             Bundle bundle = new Bundle();
211             //Set information of shared object
212             frameProvider?.NotifyHideStatus(bundle);
213
214             CallerScreenHidden?.Invoke(this, e);
215             bundle.Dispose();
216             bundle = null;
217         }
218
219         internal void SendLaunchRequest(AppControl appControl)
220         {
221             this.frameBroker.SendLaunchRequest(appControl, true);
222         }
223
224         /// <summary>
225         /// Hidden API (Inhouse API).
226         /// Dispose.
227         /// </summary>
228         /// <param name="disposing"></param>
229         [EditorBrowsable(EditorBrowsableState.Never)]
230         protected virtual void Dispose(bool disposing)
231         {
232             if (!disposed)
233             {
234                 if (frameBroker != null)
235                 {
236                     frameBroker.Dispose();
237                 }
238
239                 if (frameProvider != null)
240                 {
241                     frameProvider.Dispose();
242                 }
243                 disposed = true;
244             }
245         }
246
247         /// <summary>
248         /// Dispose for IDisposable pattern
249         /// </summary>
250         [EditorBrowsable(EditorBrowsableState.Never)]
251         public void Dispose()
252         {
253             Dispose(true);
254             System.GC.SuppressFinalize(this);
255         }
256     }
257 }