Fix ImageLoading to use new smart callbacks
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / ImageTest1.cs
1 using System;
2 using System.IO;
3 using ElmSharp;
4 using System.Collections.Generic;
5
6 namespace ElmSharp.Test
7 {
8     public class ImageTest1 : TestCaseBase
9     {
10         public override string TestName => "ImageTest1";
11         public override string TestDescription => "To test basic operation of Image";
12
13         Image image;
14         Label lbInfo;
15
16         public override void Run(Window window)
17         {
18             Conformant conformant = new Conformant(window);
19             conformant.Show();
20             Box box = new Box(window);
21             conformant.SetContent(box);
22             box.Show();
23
24             Box buttonBox1 = new Box(window)
25             {
26                 IsHorizontal = true,
27                 AlignmentX = -1,
28                 AlignmentY = 0,
29             };
30             buttonBox1.Show();
31
32             Box buttonBox2 = new Box(window)
33             {
34                 IsHorizontal = true,
35                 AlignmentX = -1,
36                 AlignmentY = 0,
37             };
38             buttonBox2.Show();
39
40             Button btnFile1 = new Button(window)
41             {
42                 Text = "File1",
43                 AlignmentX = -1,
44                 AlignmentY = -1,
45                 WeightX = 1,
46                 WeightY = 1
47             };
48             btnFile1.Show();
49
50             Button btnFile2 = new Button(window)
51             {
52                 Text = "File2",
53                 AlignmentX = -1,
54                 AlignmentY = -1,
55                 WeightX = 1,
56                 WeightY = 1
57             };
58             btnFile2.Show();
59
60             Button btnUri1 = new Button(window)
61             {
62                 Text = "Uri",
63                 AlignmentX = -1,
64                 AlignmentY = -1,
65                 WeightX = 1,
66                 WeightY = 1
67             };
68             btnUri1.Show();
69
70             Button btnStream1 = new Button(window)
71             {
72                 Text = "Strm",
73                 AlignmentX = -1,
74                 AlignmentY = -1,
75                 WeightX = 1,
76                 WeightY = 1
77             };
78             btnStream1.Show();
79
80             buttonBox1.PackEnd(btnFile1);
81             buttonBox1.PackEnd(btnFile2);
82             buttonBox1.PackEnd(btnUri1);
83             buttonBox1.PackEnd(btnStream1);
84
85
86             Button btnFileAsync1 = new Button(window)
87             {
88                 Text = "FileA1",
89                 AlignmentX = -1,
90                 AlignmentY = -1,
91                 WeightX = 1,
92                 WeightY = 1
93             };
94             btnFileAsync1.Show();
95
96             Button btnFileAsync2 = new Button(window)
97             {
98                 Text = "FileA2",
99                 AlignmentX = -1,
100                 AlignmentY = -1,
101                 WeightX = 1,
102                 WeightY = 1
103             };
104             btnFileAsync2.Show();
105
106             Button btnUriAsync1 = new Button(window)
107             {
108                 Text = "UriA",
109                 AlignmentX = -1,
110                 AlignmentY = -1,
111                 WeightX = 1,
112                 WeightY = 1
113             };
114             btnUriAsync1.Show();
115
116             Button btnStreamAsync1 = new Button(window)
117             {
118                 Text = "StrmA",
119                 AlignmentX = -1,
120                 AlignmentY = -1,
121                 WeightX = 1,
122                 WeightY = 1
123             };
124             btnStreamAsync1.Show();
125
126             buttonBox2.PackEnd(btnFileAsync1);
127             buttonBox2.PackEnd(btnFileAsync2);
128             buttonBox2.PackEnd(btnUriAsync1);
129             buttonBox2.PackEnd(btnStreamAsync1);
130
131
132             lbInfo = new Label(window)
133             {
134                 Color = Color.White,
135                 AlignmentX = -1,
136                 AlignmentY = 0,
137                 WeightX = 1
138             };
139             lbInfo.Show();
140
141             image = new Image(window)
142             {
143                 IsFixedAspect = true,
144                 AlignmentX = -1,
145                 AlignmentY = -1,
146                 WeightX = 1,
147                 WeightY = 1
148             };
149             image.Show();
150             image.Load(Path.Combine(TestRunner.ResourceDir, "picture.png"));
151             image.Clicked += (s, e) =>
152             {
153                 Console.WriteLine("Image has been clicked. (IsFixedAspect = {0}", image.IsFixedAspect);
154                 image.IsFixedAspect = image.IsFixedAspect == true ? false : true;
155             };
156
157             btnFile1.Clicked += (s, e) => LoadFile("TED/large/a.jpg");
158             btnFile2.Clicked += (s, e) => LoadFile("TED/large/b.jpg");
159             btnUri1.Clicked += (s, e) => LoadUri("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
160             btnStream1.Clicked += (s, e) => LoadStream(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/c.jpg"), FileMode.Open));
161
162             btnFileAsync1.Clicked += (s, e) => LoadFileAsync("TED/large/d.jpg");
163             btnFileAsync2.Clicked += (s, e) => LoadFileAsync("TED/large/e.jpg");
164             btnUriAsync1.Clicked += (s, e) => LoadUriAsync("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
165             btnStreamAsync1.Clicked += (s, e) => LoadStreamAsync(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/f.jpg"), FileMode.Open));
166             box.PackEnd(buttonBox1);
167             box.PackEnd(buttonBox2);
168             box.PackEnd(lbInfo);
169             box.PackEnd(image);
170         }
171
172         void LoadFile(string file)
173         {
174             bool ret = image.Load(Path.Combine(TestRunner.ResourceDir, file));
175             if (ret)
176                 UpdateLabelText(lbInfo, image.File);
177             else
178                 UpdateLabelText(lbInfo, "Loading Failed.");
179         }
180
181         void LoadUri(string uri)
182         {
183             bool ret = image.Load(uri);
184             if (ret)
185                 UpdateLabelText(lbInfo, image.File);
186             else
187                 UpdateLabelText(lbInfo, "Loading Failed.");
188         }
189
190         void LoadStream(Stream stream)
191         {
192             bool ret = image.Load(stream);
193             if (ret)
194                 UpdateLabelText(lbInfo, image.File);
195             else
196                 UpdateLabelText(lbInfo, "Loading Failed.");
197         }
198
199         async void LoadFileAsync(string file)
200         {
201             var ret = await image.LoadAsync(Path.Combine(TestRunner.ResourceDir, file));
202             if (ret)
203                 UpdateLabelText(lbInfo, image.File);
204             else
205                 UpdateLabelText(lbInfo, "Loading Failed.");
206         }
207
208         async void LoadUriAsync(string uri)
209         {
210             var ret = await image.LoadAsync(uri);
211             if (ret)
212                 UpdateLabelText(lbInfo, image.File);
213             else
214                 UpdateLabelText(lbInfo, "Loading Failed.");
215         }
216
217         async void LoadStreamAsync(Stream stream)
218         {
219             var ret = await image.LoadAsync(stream);
220             if (ret)
221                 UpdateLabelText(lbInfo, image.File);
222             else
223                 UpdateLabelText(lbInfo, "Loading Failed.");
224         }
225
226         void UpdateLabelText(Label lable, string text)
227         {
228             lable.Text = "<span color=#ffffff font_size=20>" + text + "</span>";
229         }
230     }
231 }