4 using Tizen.NUI.BaseComponents;
5 using Tizen.NUI.Components;
7 using System.Collections.Generic;
10 namespace Tizen.NUI.Samples
12 using log = Tizen.Log;
13 public class WindowTest : IExample
15 string tag = "NUITEST";
24 private Window subWindow = null;
26 private const string KEY_NUM_1 = "1";
27 private const string KEY_NUM_2 = "2";
28 private const string KEY_NUM_3 = "3";
29 private const string KEY_NUM_4 = "4";
30 private const string KEY_NUM_5 = "5";
31 private const string KEY_NUM_6 = "6";
32 private const string KEY_NUM_7 = "7";
33 private const string KEY_NUM_8 = "8";
34 private const string KEY_NUM_9 = "9";
35 private const string KEY_NUM_0 = "0";
37 private static readonly string ImagePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "/images/Dali/CubeTransitionEffect/";
39 class CustomBorder : DefaultBorder
41 private static readonly string ResourcePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
42 private static readonly string MinimalizeIcon = ResourcePath + "/images/minimalize.png";
43 private static readonly string MaximalizeIcon = ResourcePath + "/images/maximalize.png";
44 private static readonly string RestoreIcon = ResourcePath + "/images/smallwindow.png";
45 private static readonly string CloseIcon = ResourcePath + "/images/close.png";
46 private static readonly string LeftCornerIcon = ResourcePath + "/images/leftCorner.png";
47 private static readonly string RightCornerIcon = ResourcePath + "/images/rightCorner.png";
49 private int width = 500;
50 private bool hide = false;
51 private View borderView;
52 private TextLabel title;
54 private ImageView minimalizeIcon;
55 private ImageView maximalizeIcon;
56 private ImageView closeIcon;
57 private ImageView leftCornerIcon;
58 private ImageView rightCornerIcon;
60 private Rectangle preWinPositonSize;
62 public CustomBorder() : base()
66 BorderLineThickness = 0;
69 public override bool CreateTopBorderView(View topView)
75 topView.Layout = new LinearLayout()
77 LinearOrientation = LinearLayout.Orientation.Horizontal,
78 VerticalAlignment = VerticalAlignment.Center,
79 CellPadding = new Size2D(20, 20),
81 title = new TextLabel()
83 Text = "CustomBorder",
86 var button = new Button()
90 button.Clicked += (s, e) =>
92 BorderWindow.EnableFloatingMode(true);
99 public override bool CreateBottomBorderView(View bottomView)
101 if (bottomView == null)
105 bottomView.Layout = new RelativeLayout();
107 minimalizeIcon = new ImageView()
109 ResourceUrl = MinimalizeIcon,
110 AccessibilityHighlightable = true,
113 maximalizeIcon = new ImageView()
115 ResourceUrl = MaximalizeIcon,
116 AccessibilityHighlightable = true,
119 closeIcon = new ImageView()
121 ResourceUrl = CloseIcon,
122 AccessibilityHighlightable = true,
125 leftCornerIcon = new ImageView()
127 ResourceUrl = LeftCornerIcon,
128 AccessibilityHighlightable = true,
131 rightCornerIcon = new ImageView()
133 ResourceUrl = RightCornerIcon,
134 AccessibilityHighlightable = true,
137 RelativeLayout.SetRightTarget(minimalizeIcon, maximalizeIcon);
138 RelativeLayout.SetRightRelativeOffset(minimalizeIcon, 0.0f);
139 RelativeLayout.SetHorizontalAlignment(minimalizeIcon, RelativeLayout.Alignment.End);
140 RelativeLayout.SetRightTarget(maximalizeIcon, closeIcon);
141 RelativeLayout.SetRightRelativeOffset(maximalizeIcon, 0.0f);
142 RelativeLayout.SetHorizontalAlignment(maximalizeIcon, RelativeLayout.Alignment.End);
143 RelativeLayout.SetRightTarget(closeIcon, rightCornerIcon);
144 RelativeLayout.SetRightRelativeOffset(closeIcon, 0.0f);
145 RelativeLayout.SetHorizontalAlignment(closeIcon, RelativeLayout.Alignment.End);
146 RelativeLayout.SetRightRelativeOffset(rightCornerIcon, 1.0f);
147 RelativeLayout.SetHorizontalAlignment(rightCornerIcon, RelativeLayout.Alignment.End);
148 bottomView.Add(leftCornerIcon);
149 bottomView.Add(minimalizeIcon);
150 bottomView.Add(maximalizeIcon);
151 bottomView.Add(closeIcon);
152 bottomView.Add(rightCornerIcon);
155 minimalizeIcon.TouchEvent += OnMinimizeIconTouched;
156 maximalizeIcon.TouchEvent += OnMaximizeIconTouched;
157 closeIcon.TouchEvent += OnCloseIconTouched;
158 leftCornerIcon.TouchEvent += OnLeftBottomCornerIconTouched;
159 rightCornerIcon.TouchEvent += OnRightBottomCornerIconTouched;
161 minimalizeIcon.AccessibilityActivated += (s, e) =>
163 MinimizeBorderWindow();
165 maximalizeIcon.AccessibilityActivated += (s, e) =>
167 MaximizeBorderWindow();
169 closeIcon.AccessibilityActivated += (s, e) =>
174 minimalizeIcon.AccessibilityNameRequested += (s, e) =>
178 maximalizeIcon.AccessibilityNameRequested += (s, e) =>
182 closeIcon.AccessibilityNameRequested += (s, e) =>
186 leftCornerIcon.AccessibilityNameRequested += (s, e) =>
190 rightCornerIcon.AccessibilityNameRequested += (s, e) =>
195 minimalizeIcon.SetAccessibilityReadingInfoTypes(Tizen.NUI.BaseComponents.AccessibilityReadingInfoTypes.Name);
196 maximalizeIcon.SetAccessibilityReadingInfoTypes(Tizen.NUI.BaseComponents.AccessibilityReadingInfoTypes.Name);
197 closeIcon.SetAccessibilityReadingInfoTypes(Tizen.NUI.BaseComponents.AccessibilityReadingInfoTypes.Name);
198 leftCornerIcon.SetAccessibilityReadingInfoTypes(Tizen.NUI.BaseComponents.AccessibilityReadingInfoTypes.Name);
199 rightCornerIcon.SetAccessibilityReadingInfoTypes(Tizen.NUI.BaseComponents.AccessibilityReadingInfoTypes.Name);
204 public override void CreateBorderView(View borderView)
206 this.borderView = borderView;
207 borderView.CornerRadius = new Vector4(0.03f, 0.03f, 0.03f, 0.03f);
208 borderView.CornerRadiusPolicy = VisualTransformPolicyType.Relative;
209 borderView.BackgroundColor = new Color(1, 1, 1, 0.3f);
212 public override void OnCreated(View borderView)
214 base.OnCreated(borderView);
218 public override bool OnCloseIconTouched(object sender, View.TouchEventArgs e)
220 base.OnCloseIconTouched(sender, e);
224 public override bool OnMinimizeIconTouched(object sender, View.TouchEventArgs e)
226 if (e.Touch.GetState(0) == PointStateType.Up)
228 if (BorderWindow.IsMaximized() == true)
230 BorderWindow.Maximize(false);
232 preWinPositonSize = BorderWindow.WindowPositionSize;
233 BorderWindow.WindowPositionSize = new Rectangle(preWinPositonSize.X, preWinPositonSize.Y, 500, 0);
238 public override void OnRequestResize()
240 if (borderView != null)
242 borderView.BackgroundColor = new Color(0, 1, 0, 0.3f); // 보더의 배경을 변경할 수 있습니다.
246 public override void OnResized(int width, int height)
248 if (borderView != null)
250 if (this.width > width && hide == false)
255 else if (this.width < width && hide == true)
260 borderView.BackgroundColor = new Color(1, 1, 1, 0.3f); // 리사이즈가 끝나면 보더의 색깔은 원래대로 돌려놓습니다.
261 base.OnResized(width, height);
266 private void UpdateIcons()
268 if (BorderWindow != null && borderView != null)
270 if (BorderWindow.IsMaximized() == true)
272 if (maximalizeIcon != null)
274 maximalizeIcon.ResourceUrl = RestoreIcon;
279 if (maximalizeIcon != null)
281 maximalizeIcon.ResourceUrl = MaximalizeIcon;
294 mainWin = NUIApplication.GetDefaultWindow();
295 mainWin.KeyEvent += OnKeyEvent;
296 mainWin.TouchEvent += WinTouchEvent;
297 mainWin.BackgroundColor = Color.Cyan;
299 Information.TryGetValue<int>("http://tizen.org/feature/screen.width", out screenWidth);
300 Information.TryGetValue<int>("http://tizen.org/feature/screen.height", out screenHeight);
301 log.Fatal(tag, $"Initialize= screenWidth {screenWidth}, screenHeight {screenHeight} ");
302 Rectangle inputRegion = new Rectangle(0, 0, screenWidth, screenHeight / 2);
303 mainWin.IncludeInputRegion(inputRegion);
307 TextLabel text = new TextLabel("NUI Window Test");
308 text.HorizontalAlignment = HorizontalAlignment.Center;
309 text.VerticalAlignment = VerticalAlignment.Center;
310 text.TextColor = Color.Blue;
311 text.PointSize = 12.0f;
312 text.HeightResizePolicy = ResizePolicyType.FillToParent;
313 text.WidthResizePolicy = ResizePolicyType.FillToParent;
316 List<Window.WindowOrientation> list = new List<Window.WindowOrientation>();
318 list.Add(Window.WindowOrientation.Landscape);
319 list.Add(Window.WindowOrientation.LandscapeInverse);
320 list.Add(Window.WindowOrientation.NoOrientationPreference);
321 list.Add(Window.WindowOrientation.Portrait);
322 list.Add(Window.WindowOrientation.PortraitInverse);
324 mainWin.SetAvailableOrientations(list);
326 Animation animation = new Animation(2000);
327 animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
328 animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
329 animation.Looping = true;
332 manualRotation = false;
336 private bool Tm_Tick(object source, Timer.TickEventArgs e)
338 bool rotating = mainWin.IsWindowRotating();
339 log.Fatal(tag, $"window is Rotating: {rotating}");
340 if (rotating && manualRotation)
343 if (rotationCount > 100)
345 log.Fatal(tag, $"call SendRotationCompletedAcknowledgement");
346 mainWin.SendRotationCompletedAcknowledgement();
353 private void WinTouchEvent(object sender, Window.TouchEventArgs e)
355 if (e.Touch.GetState(0) == PointStateType.Down)
357 Vector2 touchpoint = e.Touch.GetScreenPosition(0);
358 log.Fatal(tag, $"WinTouchEvent={touchpoint.X}, {touchpoint.Y}");
360 if (addingInput == 0)
362 if (touchpoint.Y > (screenHeight / 2 - 50))
364 int yPostion = screenHeight / 2 + 1;
365 int height = screenHeight / 2;
366 log.Fatal(tag, $"WinTouchEvent= Include {xPosition},{yPostion} {screenWidth}x{height} ");
367 mainWin.IncludeInputRegion(new Rectangle(xPosition, yPostion, screenWidth, height));
373 if (touchpoint.Y > (screenHeight - 50))
375 int yPostion = screenHeight / 2 + 1;
376 int height = screenHeight / 2;
377 log.Fatal(tag, $"WinTouchEvent= Exclude {xPosition},{yPostion} {screenWidth}x{height} ");
378 mainWin.ExcludeInputRegion(new Rectangle(xPosition, yPostion, screenWidth, height));
385 public void OnKeyEvent(object sender, Window.KeyEventArgs e)
387 if (e.Key.State == Key.StateType.Down)
389 log.Fatal(tag, $"key down! key={e.Key.KeyPressedName}");
391 switch (e.Key.KeyPressedName)
403 log.Fatal(tag, $"SetClass test");
404 mainWin.SetClass("windowTitle", "windowClass");
408 log.Fatal(tag, $"Maximize test");
409 if (mainWin.IsMaximized())
411 log.Fatal(tag, $"Unset Maximize");
412 mainWin.Maximize(false);
416 log.Fatal(tag, $"Set Maximize");
417 mainWin.Maximize(true);
422 log.Fatal(tag, $"Set MaximumSize test");
423 mainWin.SetMaximumSize(new Size2D(700, 700));
427 log.Fatal(tag, $"Set MimimumSize test");
428 mainWin.SetMimimumSize(new Size2D(100, 100));
432 log.Fatal(tag, $"manual rotation test");
433 if (manualRotation == false)
435 manualRotation = true;
439 log.Fatal(tag, $"Enable manual rotation");
443 manualRotation = false;
444 log.Fatal(tag, $"Disable manual rotation");
446 mainWin.SetNeedsRotationCompletedAcknowledgement(manualRotation);
450 log.Fatal(tag, $"Fullscreen Test");
451 if (mainWin.GetFullScreen() == false)
453 mainWin.SetFullScreen(true);
457 mainWin.SetFullScreen(false);
462 log.Fatal(tag, $"Raise Test");
467 log.Fatal(tag, $"Lower Test");
472 log.Fatal(tag, $"Activate Test");
477 log.Fatal(tag, $"no test!");
483 void CreateSubWindow()
485 if (subWindow == null)
487 CustomBorder customBorder = new CustomBorder();
488 subWindow = new Window("subwin", customBorder, new Rectangle(60, 20, 800, 800), false);
489 subWindow.InterceptTouchEvent += (s, e) =>
491 Tizen.Log.Error("NUI", $"subWindow.InterceptTouchEvent\n");
492 if (e.Touch.GetState(0) == PointStateType.Down)
494 customBorder.OverlayBorderShow();
499 var root = new View()
501 Layout = new LinearLayout()
503 HorizontalAlignment = HorizontalAlignment.Center,
505 WidthResizePolicy = ResizePolicyType.FillToParent,
506 HeightResizePolicy = ResizePolicyType.FillToParent,
507 BackgroundColor = Color.Brown,
510 var image = new ImageView()
512 Size = new Size(300, 300),
513 ResourceUrl = ImagePath + "gallery-large-5.jpg",
514 CornerRadius = new Vector4(0.03f, 0.03f, 0, 0),
515 CornerRadiusPolicy = VisualTransformPolicyType.Relative,
518 subWindow.GetDefaultLayer().Add(root);
520 List<Window.WindowOrientation> list = new List<Window.WindowOrientation>();
522 list.Add(Window.WindowOrientation.Landscape);
523 list.Add(Window.WindowOrientation.LandscapeInverse);
524 list.Add(Window.WindowOrientation.NoOrientationPreference);
525 list.Add(Window.WindowOrientation.Portrait);
526 list.Add(Window.WindowOrientation.PortraitInverse);
528 subWindow.SetAvailableOrientations(list);
530 subWindow.Moved += OnSubWindowMoved;
531 subWindow.KeyEvent += OnSubWindowKeyEvent;
532 subWindow.MoveCompleted += OnSubWindowMoveCompleted;
533 subWindow.ResizeCompleted += OnSubWindowResizeCompleted;
537 subWindow.Minimize(false);
541 private void OnSubWindowMoved(object sender, WindowMovedEventArgs e)
543 Position2D position = e.WindowPosition;
544 log.Fatal(tag, $"OnSubWindowMoved() called!, x:{position.X}, y:{position.Y}");
547 private void OnSubWindowMoveCompleted(object sender, WindowMoveCompletedEventArgs e)
549 Position2D position = e.WindowCompletedPosition;
550 log.Fatal(tag, $"OnSubWindowMoveCompleted() called!, x:{position.X}, y:{position.Y}");
553 private void OnSubWindowResizeCompleted(object sender, WindowResizeCompletedEventArgs e)
555 Size2D size = e.WindowCompletedSize;
556 log.Fatal(tag, $"OnSubWindowResizeCompleted() called!, width:{size.Width}, height:{size.Height}");
560 public void OnSubWindowKeyEvent(object sender, Window.KeyEventArgs e)
562 if (e.Key.State == Key.StateType.Down)
564 log.Fatal(tag, $"key down! key={e.Key.KeyPressedName}");
566 switch (e.Key.KeyPressedName)
570 log.Fatal(tag, $"sub window dispose test!!!");
575 log.Fatal(tag, $"Remove Available Orientation test");
576 subWindow.RemoveAvailableOrientation(Window.WindowOrientation.Portrait);
580 log.Fatal(tag, $"Set/Get Orientation test");
581 subWindow.SetPreferredOrientation(Window.WindowOrientation.Portrait);
582 Window.WindowOrientation currentPreferredOrientation = subWindow.GetPreferredOrientation();
583 log.Fatal(tag, $"current Preferred Orientation: {currentPreferredOrientation}");
584 Window.WindowOrientation currentOrientation = subWindow.GetCurrentOrientation();
585 log.Fatal(tag, $"current Orientation: {currentOrientation}");
589 log.Fatal(tag, $"Set Accept Focus test");
590 subWindow.SetAcceptFocus(true);
591 if (subWindow.IsFocusAcceptable())
593 log.Fatal(tag, $"focus is acceptable");
597 log.Fatal(tag, $"focus is not acceptable");
602 log.Fatal(tag, $"visible/show/hide test");
603 if (subWindow.IsVisible())
605 log.Fatal(tag, $"subwindow is hideing");
610 log.Fatal(tag, $"subwindow is showing");
616 log.Fatal(tag, $"Get/Set, Notification Level test");
617 if (subWindow.Type != WindowType.Notification)
619 log.Fatal(tag, $"Set notification window type");
620 subWindow.Type = WindowType.Notification;
621 log.Fatal(tag, $"Set notification level with high");
622 subWindow.SetNotificationLevel(NotificationLevel.High);
623 if (subWindow.GetNotificationLevel() == NotificationLevel.High)
625 log.Fatal(tag, $"Current notificaiton level is high");
629 log.Fatal(tag, $"Current notificaiton level is not high");
635 log.Fatal(tag, $"opaque test");
636 if (subWindow.IsOpaqueState())
638 log.Fatal(tag, $"Set opaque state with false");
639 subWindow.SetOpaqueState(false);
643 log.Fatal(tag, $"Set opaque state with true");
644 subWindow.SetOpaqueState(true);
649 log.Fatal(tag, $"Set/Get ScreenOffMode test");
650 if (subWindow.GetScreenOffMode() == ScreenOffMode.Timout)
652 log.Fatal(tag, $"SetScreenOffMode with ScreenOffMode.Never");
653 subWindow.SetScreenOffMode(ScreenOffMode.Never);
657 log.Fatal(tag, $"SetScreenOffMode with ScreenOffMode.Timout");
658 subWindow.SetScreenOffMode(ScreenOffMode.Timout);
664 log.Fatal(tag, $"Set/Get Brightness test");
665 subWindow.SetBrightness(95);
666 int currentBrightness = subWindow.GetBrightness();
667 log.Fatal(tag, $"Current Brightness: {currentBrightness}");
671 log.Fatal(tag, $"Get/Set WindowPosition Test");
672 subWindow.WindowPosition = new Position2D(10, 10);
673 log.Fatal(tag, $"subWindow x: {subWindow.WindowPosition.X}, y: {subWindow.WindowPosition.Y}");
674 //log.Fatal(tag, $"WindowPosition : " + subWindow.WindowPosition);
678 log.Fatal(tag, $"Get/Set WindowPositionSize Test");
679 Rectangle rec = new Rectangle(20, 10, 100, 200);
680 subWindow.WindowPositionSize = rec;
681 log.Fatal(tag, $"WindowPositionSize : " + subWindow.WindowPositionSize);
685 log.Fatal(tag, $"no test!");
690 public void Activate() { Initialize(); }
691 public void Deactivate() { }