2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using Tizen.NUI.BaseComponents;
20 namespace Tizen.NUI.Samples
22 using log = Tizen.Log;
23 public class SubWindowTest : IExample
25 private const string tag = "NUITEST";
26 private const string KEY_BACK = "XF86Back";
27 private const string KEY_ESCAPE = "Escape";
28 private const string KEY_NUM_1 = "1";
29 private const string KEY_NUM_2 = "2";
30 private const string KEY_NUM_3 = "3";
31 private const string KEY_NUM_4 = "4";
32 private const string KEY_NUM_5 = "5";
33 private const string KEY_PARENT_ABOVE = "6";
34 private const string KEY_PARENT_BELOW = "7";
35 private Window mainWin;
36 private Window subWinFirst;
37 private Window subWinSecond;
38 private Window subWinThird;
39 private Timer disposeTimer;
40 private bool belowParent;
41 private const int oneSecond = 1000;
42 private const int testSize = 100;
43 private const int testPosition = 100;
44 private const float testPointSize = 12.0f;
46 public void Activate()
51 public void Deactivate()
55 private void Initialize()
57 mainWin = NUIApplication.GetDefaultWindow();
58 mainWin.KeyEvent += OnKeyEvent;
59 mainWin.BackgroundColor = Color.Cyan;
60 mainWin.WindowSize = new Size2D(5 * testSize, 5 * testSize);
61 mainWin.TouchEvent += WinTouchEvent;
64 TextLabel testText = new TextLabel("Hello Tizen NUI World")
66 HorizontalAlignment = HorizontalAlignment.Center,
67 VerticalAlignment = VerticalAlignment.Center,
68 TextColor = Color.Blue,
69 PointSize = testPointSize,
70 HeightResizePolicy = ResizePolicyType.FillToParent,
71 WidthResizePolicy = ResizePolicyType.FillToParent
73 mainWin.Add(testText);
75 Animation testRotationAnim = new Animation(2 * oneSecond);
76 testRotationAnim.AnimateTo(testText, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, oneSecond);
77 testRotationAnim.AnimateTo(testText, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), oneSecond, 2 * oneSecond);
78 testRotationAnim.Looping = true;
79 testRotationAnim.Play();
81 log.Debug(tag, "animation play!");
84 private void CreateSubWinThird()
88 log.Debug(tag, $"subWinThird is already created");
91 subWinThird = new Window("subWinThird", new Rectangle(0, 0, 3 * testSize, 3 * testSize), false)
93 BackgroundColor = Color.Blue
95 View childDummyView = new View()
97 Size = new Size(testSize, testSize),
98 Position = new Position(testPosition, testPosition),
99 BackgroundColor = Color.Yellow,
101 subWinThird.Add(childDummyView);
102 subWinThird.KeyEvent += SubWinThirdKeyEvent;
105 private void SetParentAbove()
108 subWinThird.SetParent(mainWin, false);
111 private void SetParentBelow()
114 subWinThird.SetParent(mainWin, true);
117 private void SubWinThirdKeyEvent(object sender, Window.KeyEventArgs e)
119 if (e.Key.State == Key.StateType.Down)
121 log.Debug(tag, $"key down! key={e.Key.KeyPressedName}");
123 switch (e.Key.KeyPressedName)
125 case KEY_PARENT_ABOVE:
128 case KEY_PARENT_BELOW:
135 private void WinTouchEvent(object sender, Window.TouchEventArgs e)
137 if (e.Touch.GetState(0) == PointStateType.Up)
139 if (belowParent == false)
152 private void OnKeyEvent(object sender, Window.KeyEventArgs e)
154 if (e.Key.State == Key.StateType.Down)
156 log.Debug(tag, $"key down! key={e.Key.KeyPressedName}");
158 switch (e.Key.KeyPressedName)
165 TestMakeSubWindowAndAddSomeDummyObject();
169 TestDisposeSubWindowFirstWhichWasCreatedInPrivousTestCase();
173 TestCreateSubWindowSecondWhichDoesNotHaveAnySettingAndDisposeItAfterThreeSecondsDelay();
177 TestCreateSubWindowSecondWhichHasSomeSettingAndDisposeItAfterThreeSecondsDelay();
181 TestCreateSubWindowSecondWhichHasSomeSettingAndAddSomeDummyObjectAndDisposeItAfterThreeSecondsDelay();
184 case KEY_PARENT_ABOVE:
188 case KEY_PARENT_BELOW:
193 log.Debug(tag, $"no test!");
200 private void TestMakeSubWindowAndAddSomeDummyObject()
202 subWinFirst = new Window("subWinFirst", new Rectangle(5 * testPosition, 5 * testPosition, 3 * testSize, 3 * testSize), false)
204 BackgroundColor = Color.Blue
206 View childView = new View()
208 Size = new Size(testSize, testSize),
209 Position = new Position(testPosition, testPosition),
210 BackgroundColor = Color.Yellow,
212 subWinFirst.Add(childView);
213 subWinFirst.KeyEvent += SubWinFirstKeyEvent;
216 private void TestDisposeSubWindowFirstWhichWasCreatedInPrivousTestCase()
218 subWinFirst?.Dispose();
221 private void TestCreateSubWindowSecondWhichDoesNotHaveAnySettingAndDisposeItAfterThreeSecondsDelay()
224 subWinSecond = new Window();
225 disposeTimer = new Timer(3 * oneSecond);
226 disposeTimer.Tick += OnDisposeTimerTick;
227 disposeTimer.Start();
230 private void TestCreateSubWindowSecondWhichHasSomeSettingAndDisposeItAfterThreeSecondsDelay()
233 subWinSecond = new Window("subWinSecond", new Rectangle(testPosition, testPosition, testSize, testSize), false)
235 BackgroundColor = Color.Red
237 disposeTimer = new Timer(3 * oneSecond);
238 disposeTimer.Tick += OnDisposeTimerTick;
239 disposeTimer.Start();
242 private void TestCreateSubWindowSecondWhichHasSomeSettingAndAddSomeDummyObjectAndDisposeItAfterThreeSecondsDelay()
245 subWinSecond = new Window("subWinSecond", new Rectangle(5 * testPosition, 5 * testPosition, 3 * testSize, 3 * testSize), false)
247 BackgroundColor = Color.Red
249 View testView = new View()
251 Size = new Size(testSize, testSize),
252 Position = new Position(testPosition, testPosition),
253 BackgroundColor = Color.Yellow,
255 subWinSecond.Add(testView);
257 disposeTimer = new Timer(3 * oneSecond);
258 disposeTimer.Tick += OnDisposeTimerTick;
259 disposeTimer.Start();
262 private bool OnDisposeTimerTick(object source, Timer.TickEventArgs e)
264 log.Debug(tag, $"after 3000ms, subWinSecond dispose!");
265 subWinSecond?.Dispose();
269 private void SubWinFirstKeyEvent(object sender, Window.KeyEventArgs e)
271 if (e.Key.State == Key.StateType.Down)
273 log.Debug(tag, $"subWinFirst key down! key={e.Key.KeyPressedName}");
275 switch (e.Key.KeyPressedName)
284 log.Debug(tag, $"default!");