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