Release 8.0.0.15408
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / AnimatedImageViewTest.cs
1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     using tlog = Tizen.Log;
8     public class AnimatedImageViewTest : IExample
9     {
10         View root;
11         Box box, box2;
12         string resPath;
13         const string tag = "NUITEST";
14
15         internal static int GetRatio(int percent, float value)
16         {
17             return (int)(value * (percent / 100.0f));
18         }
19
20         public class Box : View
21         {
22             public TextLabel title;
23             public AnimatedImageView image;
24             public TextLabel status;
25             public Button but1;
26             public Button but2;
27             public Button but3;
28
29             public Box(Size2D boxSize, string boxTitle, string imageUrl)
30             {
31                 this.Size2D = boxSize;
32                 this.Margin = new Extents(0, 0, 20, 20);
33                 this.BackgroundColor = Color.Magenta;
34
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;
41                 this.Add(title);
42
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;
47                 image.Play();
48                 this.Add(image);
49
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;
56                 this.Add(status);
57
58                 ButtonStyle aStyle = new ButtonStyle
59                 {
60                     IsSelectable = true,
61                     BackgroundImage = new Selector<string>
62                     {
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",
65                     },
66                     BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
67
68                     ImageShadow = new ImageShadow
69                     {
70                         Url = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png",
71                         Border = new Rectangle(5, 5, 5, 5)
72                     },
73
74                     Overlay = new ImageViewStyle
75                     {
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) },
78                     },
79
80                     Text = new TextLabelStyle
81                     {
82                         PointSize = new Selector<float?> { All = 20 },
83                         HorizontalAlignment = HorizontalAlignment.Center,
84                         VerticalAlignment = VerticalAlignment.Center,
85                         WidthResizePolicy = ResizePolicyType.FillToParent,
86                         HeightResizePolicy = ResizePolicyType.FillToParent,
87
88                         TextColor = new Selector<Color>
89                         {
90                             Normal = new Color(0.141f, 0.769f, 0.278f, 1),
91                             Selected = new Color(1, 1, 1, 1),
92                         },
93                     }
94                 };
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>
101                 {
102                     Normal = "Button1 Normal",
103                     Selected = "Button1 Selected",
104                     Disabled = "Button2 Disabled",
105                 };
106                 this.Add(but1);
107
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>
114                 {
115                     Normal = "Button2 Normal",
116                     Selected = "Button2 Selected",
117                     Disabled = "Button2 Disabled",
118                 };
119                 this.Add(but2);
120
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>
127                 {
128                     Normal = "Button3 Normal",
129                     Selected = "Button3 Selected",
130                     Disabled = "Button2 Disabled",
131                 };
132                 this.Add(but3);
133             }
134
135         }
136         public void Activate()
137         {
138             resPath = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
139             root = new View();
140             root.BackgroundColor = Color.Green;
141             root.Size2D = new Size2D(NUIApplication.GetDefaultWindow().Size.Width, NUIApplication.GetDefaultWindow().Size.Height);
142             var layer = new LinearLayout();
143             layer.LinearAlignment = LinearLayout.Alignment.CenterHorizontal;
144             layer.LinearOrientation = LinearLayout.Orientation.Vertical;
145             root.Layout = layer;
146             NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(root);
147
148             box = new Box(new Size2D(root.Size2D.Width, GetRatio(40, root.Size2D.Height)), "AGIF Test", resPath + "images/AGIF/dali-logo-anim.gif");
149             root.Add(box);
150
151             box.image.SetValues();
152             box.but1.ClickEvent += But1_ClickEvent;
153             box.but1.Style.Text.Text = new Selector<string>
154             {
155                 Normal = "Pause !",
156                 Selected = "Play !"
157             };
158             box.but2.ClickEvent += But2_ClickEvent;
159             box.but2.Style.Text.Text = new Selector<string>
160             {
161                 Normal = "Stop !",
162                 Selected = "Play !"
163             };
164             box.status.Text = "playing now";
165             box.but3.IsEnabled = false;
166
167             box2 = new Box(new Size2D(root.Size2D.Width, GetRatio(40, root.Size2D.Height)), "Image array Test", "");
168             root.Add(box2);
169
170             var list = new List<string>();
171             for (int i = 1; i <= 8; i++)
172             {
173                 list.Add(resPath + "images/AGIF/dog-anim-00" + i + ".png");
174             }
175             box2.image.URLs = list;
176             box2.image.Play();
177
178             box2.but1.ClickEvent += But1_ClickEvent1;
179             box2.but1.Style.Text.Text = new Selector<string>
180             {
181                 Normal = "Pause !",
182                 Selected = "Play by reseting frame dalay and loop count!",
183             };
184             box2.but1.Style.Text.PointSize = new Selector<float?>
185             {
186                 Normal = 20,
187                 Selected = 15,
188             };
189             box2.but1.Style.Text.MultiLine = true;
190
191
192             box2.but2.ClickEvent += But2_ClickEvent1;
193             box2.but2.IsSelectable = false;
194             box2.but2.Style.Text.Text = new Selector<string>
195             {
196                 Normal = "Increase frame delay",
197                 Pressed = "Up 100ms",
198             };
199
200             box2.but3.ClickEvent += But3_ClickEvent;
201             box2.but3.IsSelectable = false;
202             box2.but3.Style.Text.Text = new Selector<string>
203             {
204                 Normal = "Increase loop count",
205                 Pressed = "Up 1 count",
206             };
207             box2.status.Text = $"playing now,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
208
209         }
210
211         private void But3_ClickEvent(object sender, Button.ClickEventArgs e)
212         {
213             tlog.Fatal(tag, $"But3_ClickEvent()!");
214             var src = sender as Button;
215             if (src != null)
216             {
217                 box2.image.LoopCount += 1;
218                 box2.image.Play();
219                 box2.status.Text = $"playing now,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
220             }
221         }
222
223         private void But2_ClickEvent1(object sender, Button.ClickEventArgs e)
224         {
225             tlog.Fatal(tag, $"But2_ClickEvent1()!");
226             var src = sender as Button;
227             if (src != null)
228             {
229                 box2.image.FrameDelay += 100;
230                 box2.image.Play();
231                 box2.status.Text = $"playing now,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
232             }
233         }
234         private void But1_ClickEvent1(object sender, Button.ClickEventArgs e)
235         {
236             tlog.Fatal(tag, $"But1_ClickEvent1()!");
237             var src = sender as Button;
238             if (src != null)
239             {
240                 tlog.Fatal(tag, $"is selected: {src.IsSelected}");
241                 if (src.IsSelected)
242                 {
243                     box2.image.Pause();
244                     box2.status.Text = $"paused,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
245                 }
246                 else
247                 {
248                     box2.image.FrameDelay = 0;
249                     box2.image.LoopCount = -1;
250                     box2.image.Play();
251                     box2.status.Text = $"playing now,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
252                 }
253             }
254         }
255
256         private void But2_ClickEvent(object sender, Button.ClickEventArgs e)
257         {
258             tlog.Fatal(tag, $"But2_ClickEvent()!");
259             var src = sender as Button;
260             if (src != null)
261             {
262                 if (src.IsSelected)
263                 {
264                     box.image.Stop();
265                     box.status.Text = "stopped";
266                 }
267                 else
268                 {
269                     box.image.Play();
270                     box.status.Text = "playing now";
271                 }
272             }
273         }
274
275         private void But1_ClickEvent(object sender, Button.ClickEventArgs e)
276         {
277             tlog.Fatal(tag, $"But1_ClickEvent()!");
278             var src = sender as Button;
279             if (src != null)
280             {
281                 tlog.Fatal(tag, $"is selected: {src.IsSelected}");
282                 if (src.IsSelected)
283                 {
284                     box.image.Pause();
285                     box.status.Text = "paused";
286                 }
287                 else
288                 {
289                     box.image.Play();
290                     box.status.Text = "playing now";
291                 }
292             }
293         }
294
295         public void Deactivate()
296         {
297         }
298     }
299 }