Release 8.0.0.15408
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / CaptureTest.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 CaptureTest : IExample
11     {
12         public void Activate()
13         {
14             log.Debug(tag, $"Activate(): start \n");
15             resourcePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
16
17             window = NUIApplication.GetDefaultWindow();
18             window.TouchEvent += Win_TouchEvent;
19
20             root = new View()
21             {
22                 Name = "test_root",
23                 Size = new Size(500, 500),
24                 Position = new Position(10, 10),
25                 BackgroundColor = Color.White,
26             };
27
28             window.Add(root);
29
30             log.Debug(tag, $"root view added \n");
31
32             capturedView0 = new ImageView(resourcePath + "/images/image1.jpg")
33             {
34                 Name = "test_v0",
35                 Size = new Size(100, 100),
36                 BackgroundColor = Color.Red,
37             };
38             root.Add(capturedView0);
39
40             capturedView1 = new ImageView(resourcePath + "/images/image2.jpg")
41             {
42                 Name = "test_v1",
43                 Size = new Size(150, 150),
44                 Position = new Position(150, 150),
45                 BackgroundColor = Color.Yellow,
46             };
47             root.Add(capturedView1);
48
49             //TDD
50             //tddTest();
51             //checkCaptureNew();
52         }
53
54         private void onCaptureFinished(object sender, CaptureFinishStateEventArgs e)
55         {
56             log.Debug(tag, $"onCaptureFinished() statue={e.Success} \n");
57
58             if (sender is Capture)
59             {
60                 log.Debug(tag, $"sender is Capture \n");
61                 var url = capture.GenerateUrl();
62                 capturedImage = new ImageView(url);
63                 log.Debug(tag, $"url={url} \n");
64
65                 capturedImage.Size = new Size(300, 300);
66                 capturedImage.Position = new Position(10, 10);
67                 root.Add(capturedImage);
68                 done = false;
69             }
70         }
71
72         private void Win_TouchEvent(object sender, Window.TouchEventArgs e)
73         {
74             if (e.Touch.GetState(0) == PointStateType.Down)
75             {
76                 if (!done)
77                 {
78                     done = true;
79                     capture = new Capture();
80                     capture.Start(root, new Size(345, 543), @"/opt/usr/nui_captured.jpg");
81                     capture.Finished += onCaptureFinished;
82                     log.Debug(tag, $"capture done \n");
83                 }
84             }
85         }
86
87         private void tddTest()
88         {
89             log.Debug(tag, $"TDD test before Assert");
90
91             Assert.IsFalse(true, "TDD test, Exception throw");
92
93             Assert.IsFalse(false, "TDD test, Exception throw");
94
95             log.Debug(tag, $"TDD test after Assert");
96         }
97
98         private void checkCaptureNew()
99         {
100             var target = new Capture();
101             Assert.IsNotNull(target, "target should not be null");
102             Assert.IsTrue(target is Capture, "target should be Capture class");
103         }
104
105         public void Deactivate()
106         {
107         }
108
109         const string tag = "NUITEST";
110         private Window window;
111         private View root, capturedView0, capturedView1;
112         private Capture capture;
113         private ImageView capturedImage;
114         private bool done = false;
115         private string resourcePath;
116     }
117 }