[NUI] Modify NUI Seamless animation bug (#2334)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / TransitionOptions / 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     /// </summary>
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
52         /// <summary>
53         /// Set animated view of seamless animation.
54         /// </summary>
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         public View AnimatedTarget
57         {
58             get
59             {
60                 return animatedTarget;
61             }
62             set
63             {
64                 animatedTarget = value;
65             }
66         }
67
68         /// <summary>
69         /// Gets or sets transition enable
70         /// </summary>
71         [EditorBrowsable(EditorBrowsableState.Never)]
72         public bool EnableTransition
73         {
74             get
75             {
76                 return enableTransition;
77             }
78
79             set
80             {
81                 if (value)
82                 {
83                     frameBroker = new DefaultFrameBroker(mainWindow);
84                     frameBroker.mainView = animatedTarget;
85                     frameBroker.AnimationInitialized += FrameBroker_TransitionAnimationInitialized;
86                     frameBroker.AnimationFinished += FrameBroker_TransitionAnimationFinished;
87                     EnableProvider();
88                 }
89                 enableTransition = value;
90             }
91         }
92
93         private void EnableProvider()
94         {
95             frameProvider = new FrameProvider(mainWindow);
96             frameProvider.Shown += FrameProvider_Shown;
97             frameProvider.Hidden += FrameProvider_Hidden;
98         }
99
100         /// <summary>
101         /// Gets or sets the Shared object Id
102         /// </summary>
103         [EditorBrowsable(EditorBrowsableState.Never)]
104         public String SharedId
105         {
106             set
107             {
108                 sharedId = value;
109             }
110             get
111             {
112                 return sharedId;
113             }
114         }
115
116         /// <summary>
117         /// Gets or sets the forward animation of launching
118         /// </summary>
119         [EditorBrowsable(EditorBrowsableState.Never)]
120         public TransitionAnimation ForwardAnimation
121         {
122             get
123             {
124                 return frameBroker?.ForwardAnimation;
125             }
126             set
127             {
128                 if (frameBroker != null)
129                 {
130                     frameBroker.ForwardAnimation = value;
131                 }
132             }
133         }
134
135         /// <summary>
136         /// Gets or sets the backward animation of launching
137         /// </summary>
138         [EditorBrowsable(EditorBrowsableState.Never)]
139         public TransitionAnimation BackwardAnimation
140
141         {
142             get
143             {
144                 return frameBroker?.BackwardAnimation;
145             }
146             set
147             {
148                 if (frameBroker != null)
149                 {
150                     frameBroker.BackwardAnimation = value;
151                 }
152             }
153         }
154
155         /// <summary>
156         /// Emits the event when the animation is started.
157         /// </summary>
158         [EditorBrowsable(EditorBrowsableState.Never)]
159         public delegate void AnimationEventHandler(bool direction);
160
161         /// <summary>
162         /// Emits the event when the animation is started.
163         /// </summary>
164         [EditorBrowsable(EditorBrowsableState.Never)]
165         public event AnimationEventHandler AnimationInitialized;
166
167         /// <summary>
168         /// Emits the event when the animation is finished.
169         /// </summary>
170         [EditorBrowsable(EditorBrowsableState.Never)]
171         public event AnimationEventHandler AnimationFinished;
172
173         private void FrameBroker_TransitionAnimationFinished(bool direction)
174         {
175             AnimationFinished?.Invoke(direction);
176         }
177
178         private void FrameBroker_TransitionAnimationInitialized(bool direction)
179         {
180             AnimationInitialized?.Invoke(direction);
181         }
182
183         /// <summary>
184         /// Occurs whenever the window is shown on caller application.
185         /// </summary>
186         [EditorBrowsable(EditorBrowsableState.Never)]
187         public event EventHandler CallerScreenShown;
188
189         /// <summary>
190         /// Occurs whenever the window is hidden on caller application.
191         /// </summary>
192         [EditorBrowsable(EditorBrowsableState.Never)]
193         public event EventHandler CallerScreenHidden;
194
195         private void FrameProvider_Shown(object sender, EventArgs e)
196         {
197             Bundle bundle = new Bundle();
198             //Set information of shared object
199             frameProvider?.NotifyShowStatus(bundle);
200
201             CallerScreenShown?.Invoke(this, e);
202             bundle.Dispose();
203             bundle = null;
204         }
205
206         private void FrameProvider_Hidden(object sender, EventArgs e)
207         {
208             Bundle bundle = new Bundle();
209             //Set information of shared object
210             frameProvider?.NotifyHideStatus(bundle);
211
212             CallerScreenHidden?.Invoke(this, e);
213             bundle.Dispose();
214             bundle = null;
215         }
216
217         internal void SendLaunchRequest(AppControl appControl)
218         {
219             this.frameBroker.SendLaunchRequest(appControl, true);
220         }
221
222         [EditorBrowsable(EditorBrowsableState.Never)]
223         protected virtual void Dispose(bool disposing)
224         {
225             if (!disposed)
226             {
227                 if (frameBroker != null)
228                 {
229                     frameBroker.Dispose();
230                 }
231
232                 if (frameProvider != null)
233                 {
234                     frameProvider.Dispose();
235                 }
236                 disposed = true;
237             }
238         }
239
240         /// <summary>
241         /// Dispose for IDisposable pattern
242         /// </summary>
243         [EditorBrowsable(EditorBrowsableState.Never)]
244         public void Dispose()
245         {
246             Dispose(true);
247         }
248     }
249 }