Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"
[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(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
69
70                     Overlay = new ImageViewStyle
71                     {
72                         ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
73                         Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
74                     },
75
76                     Text = new TextLabelStyle
77                     {
78                         PointSize = new Selector<float?> { All = 20 },
79                         HorizontalAlignment = HorizontalAlignment.Center,
80                         VerticalAlignment = VerticalAlignment.Center,
81                         WidthResizePolicy = ResizePolicyType.FillToParent,
82                         HeightResizePolicy = ResizePolicyType.FillToParent,
83
84                         TextColor = new Selector<Color>
85                         {
86                             Normal = new Color(0.141f, 0.769f, 0.278f, 1),
87                             Selected = new Color(1, 1, 1, 1),
88                         },
89                     }
90                 };
91                 but1 = new Button(aStyle);
92                 but1.Size2D = new Size2D(GetRatio(32, boxSize.Width), GetRatio(10, boxSize.Height));
93                 but1.PositionUsesPivotPoint = true;
94                 but1.ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft;
95                 but1.PivotPoint = Tizen.NUI.ParentOrigin.BottomLeft;
96                 but1.Style.Text.Text = new Selector<string>
97                 {
98                     Normal = "Button1 Normal",
99                     Selected = "Button1 Selected",
100                     Disabled = "Button2 Disabled",
101                 };
102                 this.Add(but1);
103
104                 but2 = new Button(aStyle);
105                 but2.Size2D = new Size2D(GetRatio(32, boxSize.Width), GetRatio(10, boxSize.Height));
106                 but2.PositionUsesPivotPoint = true;
107                 but2.ParentOrigin = Tizen.NUI.ParentOrigin.BottomCenter;
108                 but2.PivotPoint = Tizen.NUI.ParentOrigin.BottomCenter;
109                 but2.Style.Text.Text = new Selector<string>
110                 {
111                     Normal = "Button2 Normal",
112                     Selected = "Button2 Selected",
113                     Disabled = "Button2 Disabled",
114                 };
115                 this.Add(but2);
116
117                 but3 = new Button(aStyle);
118                 but3.Size2D = new Size2D(GetRatio(32, boxSize.Width), GetRatio(10, boxSize.Height));
119                 but3.PositionUsesPivotPoint = true;
120                 but3.ParentOrigin = Tizen.NUI.ParentOrigin.BottomRight;
121                 but3.PivotPoint = Tizen.NUI.ParentOrigin.BottomRight;
122                 but3.Style.Text.Text = new Selector<string>
123                 {
124                     Normal = "Button3 Normal",
125                     Selected = "Button3 Selected",
126                     Disabled = "Button2 Disabled",
127                 };
128                 this.Add(but3);
129             }
130
131         }
132         public void Activate()
133         {
134             resPath = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
135             root = new View();
136             root.BackgroundColor = Color.Green;
137             root.Size2D = new Size2D(NUIApplication.GetDefaultWindow().Size.Width, NUIApplication.GetDefaultWindow().Size.Height);
138             var layer = new LinearLayout();
139             layer.LinearAlignment = LinearLayout.Alignment.CenterHorizontal;
140             layer.LinearOrientation = LinearLayout.Orientation.Vertical;
141             root.Layout = layer;
142             NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(root);
143
144             box = new Box(new Size2D(root.Size2D.Width, GetRatio(40, root.Size2D.Height)), "AGIF Test", resPath + "images/AGIF/dali-logo-anim.gif");
145             root.Add(box);
146
147             box.image.SetValues();
148             box.but1.Clicked += But1_Clicked;
149             box.but1.Style.Text.Text = new Selector<string>
150             {
151                 Normal = "Pause !",
152                 Selected = "Play !"
153             };
154             box.but2.Clicked += But2_Clicked;
155             box.but2.Style.Text.Text = new Selector<string>
156             {
157                 Normal = "Stop !",
158                 Selected = "Play !"
159             };
160             box.status.Text = "playing now";
161             box.but3.IsEnabled = false;
162
163             box2 = new Box(new Size2D(root.Size2D.Width, GetRatio(40, root.Size2D.Height)), "Image array Test", "");
164             root.Add(box2);
165
166             for (int i = 1; i <= 8; i++)
167             {
168                 box2.image.URLs.Add(resPath + "images/AGIF/dog-anim-00" + i + ".png");
169             }
170             box2.image.Play();
171
172             box2.but1.Clicked += But1_Clicked1;
173             box2.but1.Style.Text.Text = new Selector<string>
174             {
175                 Normal = "Pause !",
176                 Selected = "Play by reseting frame dalay and loop count!",
177             };
178             box2.but1.Style.Text.PointSize = new Selector<float?>
179             {
180                 Normal = 20,
181                 Selected = 15,
182             };
183             box2.but1.Style.Text.MultiLine = true;
184
185
186             box2.but2.Clicked += But2_Clicked1;
187             box2.but2.IsSelectable = false;
188             box2.but2.Style.Text.Text = new Selector<string>
189             {
190                 Normal = "Increase frame delay",
191                 Pressed = "Up 100ms",
192             };
193
194             box2.but3.Clicked += But3_Clicked;
195             box2.but3.IsSelectable = false;
196             box2.but3.Style.Text.Text = new Selector<string>
197             {
198                 Normal = "Increase loop count",
199                 Pressed = "Up 1 count",
200             };
201             box2.status.Text = $"playing now,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
202
203         }
204
205         private void But3_Clicked(object sender, ClickedEventArgs e)
206         {
207             tlog.Fatal(tag, $"But3_Clicked()!");
208             var src = sender as Button;
209             if (src != null)
210             {
211                 box2.image.LoopCount += 1;
212                 box2.image.Play();
213                 box2.status.Text = $"playing now,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
214             }
215         }
216
217         private void But2_Clicked1(object sender, ClickedEventArgs e)
218         {
219             tlog.Fatal(tag, $"But2_Clicked1()!");
220             var src = sender as Button;
221             if (src != null)
222             {
223                 box2.image.FrameDelay += 100;
224                 box2.image.Play();
225                 box2.status.Text = $"playing now,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
226             }
227         }
228         private void But1_Clicked1(object sender, ClickedEventArgs e)
229         {
230             tlog.Fatal(tag, $"But1_Clicked1()!");
231             var src = sender as Button;
232             if (src != null)
233             {
234                 tlog.Fatal(tag, $"is selected: {src.IsSelected}");
235                 if (src.IsSelected)
236                 {
237                     box2.image.Pause();
238                     box2.status.Text = $"paused,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
239                 }
240                 else
241                 {
242                     box2.image.FrameDelay = 0;
243                     box2.image.LoopCount = -1;
244                     box2.image.Play();
245                     box2.status.Text = $"playing now,  frame delay: {box2.image.FrameDelay}ms,  loop count: {box2.image.LoopCount}";
246                 }
247             }
248         }
249
250         private void But2_Clicked(object sender, ClickedEventArgs e)
251         {
252             tlog.Fatal(tag, $"But2_Clicked()!");
253             var src = sender as Button;
254             if (src != null)
255             {
256                 if (src.IsSelected)
257                 {
258                     box.image.Stop();
259                     box.status.Text = "stopped";
260                 }
261                 else
262                 {
263                     box.image.Play();
264                     box.status.Text = "playing now";
265                 }
266             }
267         }
268
269         private void But1_Clicked(object sender, ClickedEventArgs e)
270         {
271             tlog.Fatal(tag, $"But1_Clicked()!");
272             var src = sender as Button;
273             if (src != null)
274             {
275                 tlog.Fatal(tag, $"is selected: {src.IsSelected}");
276                 if (src.IsSelected)
277                 {
278                     box.image.Pause();
279                     box.status.Text = "paused";
280                 }
281                 else
282                 {
283                     box.image.Play();
284                     box.status.Text = "playing now";
285                 }
286             }
287         }
288
289         public void Deactivate()
290         {
291         }
292     }
293 }