2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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.
20 namespace ElmSharp.Test.Wearable
22 public class ImageTest1 : WearableTestCase
24 public override string TestName => "ImageTest1";
25 public override string TestDescription => "To test basic operation of Image";
29 string[] btn_names = new string[] {"File1", "File2", "Uri", "Strm", "FileA1", "FileA2", "UriA", "StrmA"};
31 public override void Run(Window window)
33 Rect square = window.GetInnerSquare();
35 Button[] btns = new Button[8];
36 Size btnSize = new Size(square.Width / 4 - 2, square.Height / 5 - 1);
37 for (int i = 0; i < 2; i++)
39 for (int j = 0; j < 4; j++)
41 btns[i * 4 + j] = new Button(window)
43 Text = "<span color=#ffffff font_size=12>" + btn_names[i * 4 + j] + "</span>",
45 int x = j * btnSize.Width + j *2;
46 int y = i * btnSize.Height + i;
47 btns[i * 4 + j].Geometry = new Rect(square.X + x, square.Y + y, btnSize.Width, btnSize.Height);
48 btns[i * 4 + j].Show();
52 lbInfo = new Label(window)
60 lbInfo.Geometry = new Rect(square.X, square.Y + square.Height, square.Width, 15);
62 image = new Image(window)
69 image.Load(Path.Combine(TestRunner.ResourceDir, "picture.png"));
70 image.Geometry = new Rect(square.X, square.Y + btnSize.Height * 2 + 2 , square.Width, btnSize.Height * 3);
71 image.Clicked += (s, e) =>
73 Console.WriteLine("Image has been clicked. (IsFixedAspect = {0}", image.IsFixedAspect);
74 image.IsFixedAspect = image.IsFixedAspect == true ? false : true;
77 btns[0].Clicked += (s, e) => LoadFile("TED/large/a.jpg");
78 btns[1].Clicked += (s, e) => LoadFile("TED/large/b.jpg");
79 btns[2].Clicked += (s, e) => LoadUri("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
80 btns[3].Clicked += (s, e) => LoadStream(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/c.jpg"), FileMode.Open, FileAccess.Read));
82 btns[4].Clicked += (s, e) => LoadFileAsync("TED/large/d.jpg");
83 btns[5].Clicked += (s, e) => LoadFileAsync("TED/large/e.jpg");
84 btns[6].Clicked += (s, e) => LoadUriAsync("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
85 btns[7].Clicked += (s, e) => LoadStreamAsync(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/f.jpg"), FileMode.Open, FileAccess.Read));
88 void LoadFile(string file)
90 bool ret = image.Load(Path.Combine(TestRunner.ResourceDir, file));
92 UpdateLabelText(lbInfo, image.File);
94 UpdateLabelText(lbInfo, "Loading Failed.");
97 void LoadUri(string uri)
99 bool ret = image.Load(uri);
101 UpdateLabelText(lbInfo, image.File);
103 UpdateLabelText(lbInfo, "Loading Failed.");
106 void LoadStream(Stream stream)
108 bool ret = image.Load(stream);
110 UpdateLabelText(lbInfo, image.File);
112 UpdateLabelText(lbInfo, "Loading Failed.");
115 async void LoadFileAsync(string file)
117 var ret = await image.LoadAsync(Path.Combine(TestRunner.ResourceDir, file));
119 UpdateLabelText(lbInfo, image.File);
121 UpdateLabelText(lbInfo, "Loading Failed.");
124 async void LoadUriAsync(string uri)
126 var ret = await image.LoadAsync(uri);
128 UpdateLabelText(lbInfo, image.File);
130 UpdateLabelText(lbInfo, "Loading Failed.");
133 async void LoadStreamAsync(Stream stream)
135 var ret = await image.LoadAsync(stream);
137 UpdateLabelText(lbInfo, image.File);
139 UpdateLabelText(lbInfo, "Loading Failed.");
142 void UpdateLabelText(Label lable, string text)
144 lable.Text = "<span color=#ffffff font_size=12>" + text + "</span>";