[ElmSharp] Modify source file mode (#621)
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / WindowUtilTest.cs
1 using Tizen.Applications;
2 /*
3  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 using System;
19 using System.IO;
20 using ElmSharp;
21 using System.Diagnostics;
22
23 namespace ElmSharp.Test
24 {
25     class WindowUtilTest : TestCaseBase
26     {
27         public override string TestName => "WindowUtilTest";
28         public override string TestDescription => "Window Util Test";
29
30         void DeleteWin(Window window)
31         {
32             window.Hide();
33             window.Unrealize();
34             GC.Collect();
35             GC.WaitForPendingFinalizers();
36         }
37
38         Window CreateWin(Window parent, WindowType type, bool whiteBg)
39         {
40             Window win = new Window(parent, "testwin", type);
41             win.Show();
42
43             win.BackButtonPressed += (s, e) =>
44             {
45                 DeleteWin(win);
46             };
47
48             if (whiteBg)
49             {
50                 Conformant conformant = new Conformant(win);
51                 conformant.Show();
52                 Box box = new Box(win)
53                 {
54                     AlignmentX = -1,
55                     AlignmentY = -1,
56                     WeightX = 1,
57                     WeightY = 1,
58                 };
59                 box.Show();
60                 var bg = new Background(win);
61                 bg.Color = Color.White;
62                 bg.SetContent(box);
63                 conformant.SetContent(bg);
64             }
65
66             Button button = new Button(win)
67             {
68                 Text = "Delete Window",                
69             };
70             button.Resize(win.ScreenSize.Width, 100);
71             button.Move(0, win.ScreenSize.Height - 105);
72             button.SetPartColor("bg", Color.Red);
73             button.Show();
74
75             button.Clicked += (e, o) =>
76             {
77                 DeleteWin(win);
78             };
79
80             return win;
81         }
82
83         public override void Run(Window window)
84         {
85             int buttonW = window.ScreenSize.Width / 2 - 10;
86             int buttonH = 110;
87
88             Button button1 = new Button(window)
89             {
90                 Text = "Brightness</br>30",
91             };
92             button1.Resize(buttonW, buttonH);
93             button1.Move(5, 5);
94             button1.Show();
95
96             button1.Clicked += (e, o) =>
97             {
98                 window.Brightness = 30;
99             };
100
101             Button button2 = new Button(window)
102             {
103                 Text = "Brightness</br>Default",
104             };
105             button2.Resize(buttonW, buttonH);
106             button2.Move(buttonW + 15, 5);
107             button2.Show();
108
109             button2.Clicked += (e, o) =>
110             {
111                 window.Brightness = -1;
112             };
113
114             Button button3 = new Button(window)
115             {
116                 Text = "ScreenMode</br>AlwaysOn",
117             };
118             button3.Resize(buttonW, buttonH);
119             button3.Move(5, buttonH + 15);
120             button3.Show();
121
122             button3.Clicked += (e, o) =>
123             {
124                 window.ScreenMode = ScreenMode.AlwaysOn;
125             };
126
127             Button button4 = new Button(window)
128             {
129                 Text = "ScreenMode</br>Default",
130             };
131             button4.Resize(buttonW, buttonH);
132             button4.Move(buttonW + 15, buttonH + 15);
133             button4.Show();
134
135             button4.Clicked += (e, o) =>
136             {
137                 window.ScreenMode = ScreenMode.Default;
138             };
139
140             Button button5 = new Button(window)
141             {
142                 Text = "Window Notification Level</br>Top",
143             };
144             button5.Resize(window.ScreenSize.Width - 10, buttonH);
145             button5.Move(5, (buttonH +10)* 2 + 5);
146             button5.Show();
147
148             button5.Clicked += (e, o) =>
149             {
150                 Window win = CreateWin(window, WindowType.Notification, true);
151
152                 Console.WriteLine("Notifiaction Level : {0}", win.NotificationLevel);
153                 win.NotificationLevel = NotificationLevel.Top;
154                 Console.WriteLine("Notifiaction Level : {0}", win.NotificationLevel);
155
156                 Label label = new Label(win)
157                 {
158                     Text = string.Format("This Notification Window Level : {0}", win.NotificationLevel),
159                     Color = Color.White,
160                 };
161                 label.Resize(window.ScreenSize.Width, 100);
162                 label.Move(0, 100);
163                 label.Show();
164             };
165         }
166     }
167 }