1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
5 namespace Tizen.NUI.Samples
7 using tlog = Tizen.Log;
8 public class AnimatedImageViewTest : IExample
13 const string tag = "NUITEST";
15 internal static int GetRatio(int percent, float value)
17 return (int)(value * (percent / 100.0f));
20 public class Box : View
22 public TextLabel title;
23 public AnimatedImageView image;
24 public TextLabel status;
29 public Box(Size2D boxSize, string boxTitle, string imageUrl)
31 this.Size2D = boxSize;
32 this.Margin = new Extents(0, 0, 20, 20);
33 this.BackgroundColor = Color.Magenta;
35 title = new TextLabel(boxTitle);
36 title.Size2D = new Size2D(boxSize.Width, GetRatio(20, boxSize.Height));
37 title.Position2D = new Position2D(0, 0);
38 title.MultiLine = true;
39 title.BackgroundColor = Color.Blue;
40 title.TextColor = Color.Yellow;
43 image = new AnimatedImageView();
44 image.Size2D = new Size2D(boxSize.Width, GetRatio(50, boxSize.Height));
45 image.Position2D = new Position2D(0, title.Size2D.Height);
46 image.ResourceUrl = imageUrl;
50 status = new TextLabel("Initialized");
51 status.Size2D = new Size2D(boxSize.Width, GetRatio(20, boxSize.Height));
52 status.Position2D = new Position2D(0, image.Position2D.Y + image.Size2D.Height);
53 status.MultiLine = true;
54 status.BackgroundColor = Color.White;
55 status.PointSize = 20;
58 ButtonStyle aStyle = new ButtonStyle
61 BackgroundImage = new Selector<string>
63 Normal = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_toggle_btn_normal_24c447.png",
64 Selected = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_point_btn_normal_24c447.png",
66 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
68 Shadow = new ImageViewStyle
70 ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png" },
71 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) }
74 Overlay = new ImageViewStyle
76 ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
77 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
80 Text = new TextLabelStyle
82 PointSize = new Selector<float?> { All = 20 },
83 HorizontalAlignment = HorizontalAlignment.Center,
84 VerticalAlignment = VerticalAlignment.Center,
85 WidthResizePolicy = ResizePolicyType.FillToParent,
86 HeightResizePolicy = ResizePolicyType.FillToParent,
88 TextColor = new Selector<Color>
90 Normal = new Color(0.141f, 0.769f, 0.278f, 1),
91 Selected = new Color(1, 1, 1, 1),
95 but1 = new Button(aStyle);
96 but1.Size2D = new Size2D(GetRatio(32, boxSize.Width), GetRatio(10, boxSize.Height));
97 but1.PositionUsesPivotPoint = true;
98 but1.ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft;
99 but1.PivotPoint = Tizen.NUI.ParentOrigin.BottomLeft;
100 but1.Style.Text.Text = new Selector<string>
102 Normal = "Button1 Normal",
103 Selected = "Button1 Selected",
104 Disabled = "Button2 Disabled",
108 but2 = new Button(aStyle);
109 but2.Size2D = new Size2D(GetRatio(32, boxSize.Width), GetRatio(10, boxSize.Height));
110 but2.PositionUsesPivotPoint = true;
111 but2.ParentOrigin = Tizen.NUI.ParentOrigin.BottomCenter;
112 but2.PivotPoint = Tizen.NUI.ParentOrigin.BottomCenter;
113 but2.Style.Text.Text = new Selector<string>
115 Normal = "Button2 Normal",
116 Selected = "Button2 Selected",
117 Disabled = "Button2 Disabled",
121 but3 = new Button(aStyle);
122 but3.Size2D = new Size2D(GetRatio(32, boxSize.Width), GetRatio(10, boxSize.Height));
123 but3.PositionUsesPivotPoint = true;
124 but3.ParentOrigin = Tizen.NUI.ParentOrigin.BottomRight;
125 but3.PivotPoint = Tizen.NUI.ParentOrigin.BottomRight;
126 but3.Style.Text.Text = new Selector<string>
128 Normal = "Button3 Normal",
129 Selected = "Button3 Selected",
130 Disabled = "Button2 Disabled",
136 public void Activate()
138 resPath = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
140 root.BackgroundColor = Color.Green;
141 root.Size2D = new Size2D(Window.Instance.Size.Width, Window.Instance.Size.Height);
142 var layer = new LinearLayout();
143 layer.LinearAlignment = LinearLayout.Alignment.CenterHorizontal;
144 layer.LinearOrientation = LinearLayout.Orientation.Vertical;
146 Window.Instance.GetDefaultLayer().Add(root);
148 box = new Box(new Size2D(root.Size2D.Width, GetRatio(40, root.Size2D.Height)), "AGIF Test", resPath + "images/AGIF/dali-logo-anim.gif");
151 box.image.SetValues();
152 box.but1.ClickEvent += But1_ClickEvent;
153 box.but1.Style.Text.Text = new Selector<string>
158 box.but2.ClickEvent += But2_ClickEvent;
159 box.but2.Style.Text.Text = new Selector<string>
164 box.status.Text = "playing now";
165 box.but3.IsEnabled = false;
167 box2 = new Box(new Size2D(root.Size2D.Width, GetRatio(40, root.Size2D.Height)), "Image array Test", "");
170 var list = new List<string>();
171 for (int i = 1; i <= 8; i++)
173 list.Add(resPath + "images/AGIF/dog-anim-00" + i + ".png");
175 box2.image.URLs = list;
178 box2.but1.ClickEvent += But1_ClickEvent1;
179 box2.but1.Style.Text.Text = new Selector<string>
182 Selected = "Play by reseting frame dalay and loop count!",
184 box2.but1.Style.Text.PointSize = new Selector<float?>
189 box2.but1.Style.Text.MultiLine = true;
192 box2.but2.ClickEvent += But2_ClickEvent1;
193 box2.but2.IsSelectable = false;
194 box2.but2.Style.Text.Text = new Selector<string>
196 Normal = "Increase frame delay",
197 Pressed = "Up 100ms",
200 box2.but3.ClickEvent += But3_ClickEvent;
201 box2.but3.IsSelectable = false;
202 box2.but3.Style.Text.Text = new Selector<string>
204 Normal = "Increase loop count",
205 Pressed = "Up 1 count",
207 box2.status.Text = $"playing now, frame delay: {box2.image.FrameDelay}ms, loop count: {box2.image.LoopCount}";
211 private void But3_ClickEvent(object sender, Button.ClickEventArgs e)
213 tlog.Fatal(tag, $"But3_ClickEvent()!");
214 var src = sender as Button;
217 box2.image.LoopCount += 1;
219 box2.status.Text = $"playing now, frame delay: {box2.image.FrameDelay}ms, loop count: {box2.image.LoopCount}";
223 private void But2_ClickEvent1(object sender, Button.ClickEventArgs e)
225 tlog.Fatal(tag, $"But2_ClickEvent1()!");
226 var src = sender as Button;
229 box2.image.FrameDelay += 100;
231 box2.status.Text = $"playing now, frame delay: {box2.image.FrameDelay}ms, loop count: {box2.image.LoopCount}";
234 private void But1_ClickEvent1(object sender, Button.ClickEventArgs e)
236 tlog.Fatal(tag, $"But1_ClickEvent1()!");
237 var src = sender as Button;
240 tlog.Fatal(tag, $"is selected: {src.IsSelected}");
244 box2.status.Text = $"paused, frame delay: {box2.image.FrameDelay}ms, loop count: {box2.image.LoopCount}";
248 box2.image.FrameDelay = 0;
249 box2.image.LoopCount = -1;
251 box2.status.Text = $"playing now, frame delay: {box2.image.FrameDelay}ms, loop count: {box2.image.LoopCount}";
256 private void But2_ClickEvent(object sender, Button.ClickEventArgs e)
258 tlog.Fatal(tag, $"But2_ClickEvent()!");
259 var src = sender as Button;
265 box.status.Text = "stopped";
270 box.status.Text = "playing now";
275 private void But1_ClickEvent(object sender, Button.ClickEventArgs e)
277 tlog.Fatal(tag, $"But1_ClickEvent()!");
278 var src = sender as Button;
281 tlog.Fatal(tag, $"is selected: {src.IsSelected}");
285 box.status.Text = "paused";
290 box.status.Text = "playing now";
295 public void Deactivate()