Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"
[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         Timer tm;
17         void Initialize()
18         {
19             mainWin = NUIApplication.GetDefaultWindow();
20             mainWin.KeyEvent += OnKeyEvent;
21             mainWin.BackgroundColor = Color.Cyan;
22             mainWin.WindowSize = new Size2D(500, 500);
23
24             TextLabel text = new TextLabel("Hello Tizen NUI World");
25             text.HorizontalAlignment = HorizontalAlignment.Center;
26             text.VerticalAlignment = VerticalAlignment.Center;
27             text.TextColor = Color.Blue;
28             text.PointSize = 12.0f;
29             text.HeightResizePolicy = ResizePolicyType.FillToParent;
30             text.WidthResizePolicy = ResizePolicyType.FillToParent;
31             mainWin.Add(text);
32
33             Animation animation = new Animation(2000);
34             animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
35             animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
36             animation.Looping = true;
37             animation.Play();
38
39             log.Fatal(tag, "animation play!");
40         }
41
42         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
43         {
44             if (e.Key.State == Key.StateType.Down)
45             {
46                 log.Fatal(tag, $"key down! key={e.Key.KeyPressedName}");
47
48                 switch (e.Key.KeyPressedName)
49                 {
50                     case "XF86Back":
51                     case "Escape":
52                         //Exit();
53                         break;
54
55                     case "1":
56                         TestCase1();
57                         break;
58
59                     case "2":
60                         TestCase2();
61                         break;
62
63                     case "3":
64                         TestCase3();
65                         break;
66
67                     case "4":
68                         TestCase4();
69                         break;
70
71                     case "5":
72                         TestCase5();
73                         break;
74
75                     default:
76                         log.Fatal(tag, $"no test!");
77                         break;
78                 }
79             }
80         }
81
82         //TDD
83         void TestCase1()
84         {
85             log.Fatal(tag, "test 1 : 1) make sub window-1 2) add some dummy object");
86
87             subWin1 = new Window("subwin1", new Rectangle(500, 500, 300, 300), false);
88             subWin1.BackgroundColor = Color.Blue;
89             View dummy = new View()
90             {
91                 Size = new Size(100, 100),
92                 Position = new Position(50, 50),
93                 BackgroundColor = Color.Yellow,
94             };
95             subWin1.Add(dummy);
96             subWin1.KeyEvent += SubWin1_KeyEvent;
97         }
98         void TestCase2()
99         {
100             log.Fatal(tag, "test 2 : 1) do dispose of sub window-1 created in #1");
101             subWin1?.Dispose();
102         }
103         void TestCase3()
104         {
105             log.Fatal(tag, $"test 3 : 1) create sub window2 which doesn't have any setting 2) dispose it after 3 second delay");
106             subWin2 = null;
107             subWin2 = new Window();
108             tm = new Timer(3000);
109             tm.Tick += Tm_Tick;
110             tm.Start();
111         }
112         void TestCase4()
113         {
114             log.Fatal(tag, $"test 4 : 1) create sub window2 which has some setting 2) dispose it after 3 second delay");
115             subWin2 = null;
116             subWin2 = new Window("subWin2", new Rectangle(100, 100, 100, 100), false);
117             subWin2.BackgroundColor = Color.Red;
118             tm = new Timer(3000);
119             tm.Tick += Tm_Tick;
120             tm.Start();
121         }
122         void TestCase5()
123         {
124             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");
125             subWin2 = null;
126             subWin2 = new Window("subWin2", new Rectangle(500, 500, 300, 300), false);
127             subWin2.BackgroundColor = Color.Red;
128             View v1 = new View()
129             {
130                 Size = new Size(50, 50),
131                 Position = new Position(50, 50),
132                 BackgroundColor = Color.Yellow,
133             };
134             subWin2.Add(v1);
135
136             tm = new Timer(3000);
137             tm.Tick += Tm_Tick;
138             tm.Start();
139         }
140
141         private bool Tm_Tick(object source, Timer.TickEventArgs e)
142         {
143             log.Fatal(tag, $"after 3000ms, subwin2 dispose!");
144             subWin2?.Dispose();
145             return false;
146         }
147
148         private void SubWin1_KeyEvent(object sender, Window.KeyEventArgs e)
149         {
150             if (e.Key.State == Key.StateType.Down)
151             {
152                 log.Fatal(tag, $"subWin1 key down! key={e.Key.KeyPressedName}");
153
154                 switch (e.Key.KeyPressedName)
155                 {
156                     case "XF86Back":
157                     case "Escape":
158                         //Exit();
159                         break;
160                     case "1":
161                         mainWin.Raise();
162                         break;
163                     default:
164                         log.Fatal(tag, $"default!");
165                         break;
166                 }
167             }
168         }
169
170
171         public void Activate() { Initialize(); }
172         public void Deactivate() { }
173     }
174 }