c94e666eaf7c448272f9992c4ed9ae8b2c38d1a6
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / SubWindowTest.cs
1 
2 using global::System;
3 using Tizen.NUI;
4 using Tizen.NUI.BaseComponents;
5 using NUnit.Framework;
6
7 namespace Tizen.NUI.Samples
8 {
9     using log = Tizen.Log;
10     public class SubWindowTest : IExample
11     {
12         string tag = "NUITEST";
13         Window mainWin;
14         Window subWin1;
15         Window subWin2;
16         Window subWin3;
17         Timer tm;
18         bool belowParent;
19         void Initialize()
20         {
21             mainWin = NUIApplication.GetDefaultWindow();
22             mainWin.KeyEvent += OnKeyEvent;
23             mainWin.BackgroundColor = Color.Cyan;
24             mainWin.WindowSize = new Size2D(500, 500);
25             mainWin.TouchEvent += WinTouchEvent;
26             belowParent = false;
27
28             TextLabel text = new TextLabel("Hello Tizen NUI World");
29             text.HorizontalAlignment = HorizontalAlignment.Center;
30             text.VerticalAlignment = VerticalAlignment.Center;
31             text.TextColor = Color.Blue;
32             text.PointSize = 12.0f;
33             text.HeightResizePolicy = ResizePolicyType.FillToParent;
34             text.WidthResizePolicy = ResizePolicyType.FillToParent;
35             mainWin.Add(text);
36
37             Animation animation = new Animation(2000);
38             animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
39             animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
40             animation.Looping = true;
41             animation.Play();
42
43             log.Fatal(tag, "animation play!");
44         }
45
46         void CreateSubWin3()
47         {
48             if(subWin3)
49             {
50                 log.Fatal(tag, $"Sub Window3 is already created");
51                 return;
52             }
53             subWin3 = new Window("subWin3", new Rectangle(0, 0, 300, 300), false);
54             subWin3.BackgroundColor = Color.Blue;
55             View dummy = new View()
56             {
57                 Size = new Size(100, 100),
58                 Position = new Position(50, 50),
59                 BackgroundColor = Color.Yellow,
60             };
61             subWin3.Add(dummy);
62             subWin3.KeyEvent += subWin3_KeyEvent;
63         }
64
65         void SetParentAbove()
66         {
67             CreateSubWin3();
68             subWin3.SetParent(mainWin, false);
69         }
70
71         void SetParentBelow()
72         {
73             CreateSubWin3();
74             subWin3.SetParent(mainWin, true);
75         }
76
77         public void subWin3_KeyEvent(object sender, Window.KeyEventArgs e)
78         {
79             if (e.Key.State == Key.StateType.Down)
80             {
81                 log.Fatal(tag, $"key down! key={e.Key.KeyPressedName}");
82
83                 switch (e.Key.KeyPressedName)
84                 {
85                     case "6":
86                         SetParentAbove();
87                         break;
88                     case "7":
89                         SetParentBelow();
90                         break;
91                 }
92             }
93         }
94
95         public void WinTouchEvent(object sender, Window.TouchEventArgs e)
96         {
97             if (e.Touch.GetState(0) == PointStateType.Up)
98             {
99                 if(belowParent == false)
100                 {
101                     SetParentBelow();
102                     belowParent = true;
103                 }
104                 else
105                 {
106                     SetParentAbove();
107                     belowParent = false;
108                 }
109             }
110         }
111
112         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
113         {
114             if (e.Key.State == Key.StateType.Down)
115             {
116                 log.Fatal(tag, $"key down! key={e.Key.KeyPressedName}");
117
118                 switch (e.Key.KeyPressedName)
119                 {
120                     case "XF86Back":
121                     case "Escape":
122                         //Exit();
123                         break;
124
125                     case "1":
126                         TestCase1();
127                         break;
128
129                     case "2":
130                         TestCase2();
131                         break;
132
133                     case "3":
134                         TestCase3();
135                         break;
136
137                     case "4":
138                         TestCase4();
139                         break;
140
141                     case "5":
142                         TestCase5();
143                         break;
144
145                     case "6":
146                         SetParentAbove();
147                         break;
148
149                     case "7":
150                         SetParentBelow();
151                         break;
152
153                     default:
154                         log.Fatal(tag, $"no test!");
155                         break;
156                 }
157             }
158         }
159
160         //TDD
161         void TestCase1()
162         {
163             log.Fatal(tag, "test 1 : 1) make sub window-1 2) add some dummy object");
164
165             subWin1 = new Window("subwin1", new Rectangle(500, 500, 300, 300), false);
166             subWin1.BackgroundColor = Color.Blue;
167             View dummy = new View()
168             {
169                 Size = new Size(100, 100),
170                 Position = new Position(50, 50),
171                 BackgroundColor = Color.Yellow,
172             };
173             subWin1.Add(dummy);
174             subWin1.KeyEvent += SubWin1_KeyEvent;
175         }
176         void TestCase2()
177         {
178             log.Fatal(tag, "test 2 : 1) do dispose of sub window-1 created in #1");
179             subWin1?.Dispose();
180         }
181         void TestCase3()
182         {
183             log.Fatal(tag, $"test 3 : 1) create sub window2 which doesn't have any setting 2) dispose it after 3 second delay");
184             subWin2 = null;
185             subWin2 = new Window();
186             tm = new Timer(3000);
187             tm.Tick += Tm_Tick;
188             tm.Start();
189         }
190         void TestCase4()
191         {
192             log.Fatal(tag, $"test 4 : 1) create sub window2 which has some setting 2) dispose it after 3 second delay");
193             subWin2 = null;
194             subWin2 = new Window("subWin2", new Rectangle(100, 100, 100, 100), false);
195             subWin2.BackgroundColor = Color.Red;
196             tm = new Timer(3000);
197             tm.Tick += Tm_Tick;
198             tm.Start();
199         }
200         void TestCase5()
201         {
202             log.Fatal(tag, $"test 5 : 1) create sub window2 which has some setting 2) add some dummy object 3) dispose it after 3 second delay");
203             subWin2 = null;
204             subWin2 = new Window("subWin2", new Rectangle(500, 500, 300, 300), false);
205             subWin2.BackgroundColor = Color.Red;
206             View v1 = new View()
207             {
208                 Size = new Size(50, 50),
209                 Position = new Position(50, 50),
210                 BackgroundColor = Color.Yellow,
211             };
212             subWin2.Add(v1);
213
214             tm = new Timer(3000);
215             tm.Tick += Tm_Tick;
216             tm.Start();
217         }
218
219         private bool Tm_Tick(object source, Timer.TickEventArgs e)
220         {
221             log.Fatal(tag, $"after 3000ms, subwin2 dispose!");
222             subWin2?.Dispose();
223             return false;
224         }
225
226         private void SubWin1_KeyEvent(object sender, Window.KeyEventArgs e)
227         {
228             if (e.Key.State == Key.StateType.Down)
229             {
230                 log.Fatal(tag, $"subWin1 key down! key={e.Key.KeyPressedName}");
231
232                 switch (e.Key.KeyPressedName)
233                 {
234                     case "XF86Back":
235                     case "Escape":
236                         //Exit();
237                         break;
238                     case "1":
239                         mainWin.Raise();
240                         break;
241                     default:
242                         log.Fatal(tag, $"default!");
243                         break;
244                 }
245             }
246         }
247
248
249         public void Activate() { Initialize(); }
250         public void Deactivate() { }
251     }
252 }