Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / ButtonSample.cs
1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class ButtonSample : IExample
8     {
9         private View root;
10         private View parent1;
11         private View parent2;
12         private View parent3;
13         Button textButton;
14         Button iconButton;
15
16         Button iconTextButton;
17
18         Button utilityBasicButton;
19         Button utilityServiceButton;
20         Button utilityToggleButton;
21         Button utilityOvalButton;
22
23         Button familyBasicButton;
24         Button familyServiceButton;
25         Button familyToggleButton;
26         Button familyOvalButton;
27
28         public void Activate()
29         {
30             Window window = NUIApplication.GetDefaultWindow();
31             root = new View()
32             {
33                 Size = new Size(1920, 1080),
34                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
35                 Layout = new LinearLayout()
36                 {
37                     LinearAlignment = LinearLayout.Alignment.Center,
38                     LinearOrientation = LinearLayout.Orientation.Horizontal,
39                     CellPadding = new Size(50, 50),
40                 }
41             };
42             window.Add(root);
43             window.KeyEvent += Window_KeyEvent;
44
45             parent1 = new View()
46             {
47                 Size = new Size(300, 900),
48                 Layout = new LinearLayout()
49                 {
50                     LinearAlignment = LinearLayout.Alignment.Top,
51                     LinearOrientation = LinearLayout.Orientation.Vertical,
52                     CellPadding = new Size(50, 50),
53                 }
54             };
55
56             parent2 = new View()
57             {
58                 Size = new Size(300, 900),
59                 Layout = new LinearLayout()
60                 {
61                     LinearAlignment = LinearLayout.Alignment.Top,
62                     LinearOrientation = LinearLayout.Orientation.Vertical,
63                     CellPadding = new Size(50, 50),
64                 }
65             };
66
67             // Only show a text button.
68             textButton = new Button();
69             textButton.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
70             textButton.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
71             textButton.Size = new Size(300, 80);
72             textButton.TextLabel.Text = "Button";
73             parent1.Add(textButton);
74
75             //Only show an icon button.
76             iconButton = new Button();
77             iconButton.Text = "";
78             iconButton.Name = "IconButton";
79             iconButton.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
80             iconButton.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
81             iconButton.Size = new Size(80, 80);
82             iconButton.Icon.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_radiobutton/c_radiobutton_white_check.png";
83             parent2.Add(iconButton);
84             iconButton.Clicked += (ojb, e) => {
85                 var btn = iconButton.Icon.GetParent() as Button;
86                 string name = btn.Name;
87             };
88
89             parent3 = new View()
90             {
91                 Size = new Size(600, 400),
92                 Layout = new LinearLayout()
93                 {
94                     LinearAlignment = LinearLayout.Alignment.Top,
95                     LinearOrientation = LinearLayout.Orientation.Vertical,
96                     CellPadding = new Size(50, 50),
97                 }
98             };
99
100             //Show a button with icon and text.
101             iconTextButton = new Button();
102             iconTextButton.Text = "IconTextButton";
103             iconTextButton.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
104             iconTextButton.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
105             iconTextButton.IconRelativeOrientation = Button.IconOrientation.Left;
106             iconTextButton.Icon.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_radiobutton/c_radiobutton_white_check.png";
107             iconTextButton.IconPadding = new Extents(20, 20, 20, 20);
108             iconTextButton.TextPadding = new Extents(20, 50, 20, 20);
109             iconTextButton.Size = new Size(500, 300);
110             parent3.Add(iconTextButton);
111
112             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
113             //Create utility basic style of button.
114             var utilityBasicButtonStyle = new ButtonStyle()
115             {
116                 Overlay = new ImageViewStyle()
117                 {
118                     ResourceUrl = new Selector<string>
119                     {
120                         Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
121                         Other = ""
122                     },
123                     Border = new Rectangle(5, 5, 5, 5)
124                 },
125                 Text = new TextLabelStyle()
126                 {
127                     TextColor = new Selector<Color>
128                     {
129                         Normal = new Color(0, 0, 0, 1),
130                         Pressed = new Color(0, 0, 0, 0.7f),
131                         Selected = new Color(0.058f, 0.631f, 0.92f, 1),
132                         Disabled = new Color(0, 0, 0, 0.4f)
133                     },
134                     Text = "UtilityBasicButton",
135                     PointSize = 20,
136                 },
137                 BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png",
138                 BackgroundImageBorder = new Rectangle(5, 5, 5, 5),
139             };
140             utilityBasicButton = new Button();
141             utilityBasicButton.ApplyStyle(utilityBasicButtonStyle);
142             utilityBasicButton.IsSelectable = true;
143             utilityBasicButton.ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
144             utilityBasicButton.Size = new Size(300, 80);
145             utilityBasicButton.IsEnabled = false;
146             parent1.Add(utilityBasicButton);
147
148             //Create utility service style of button.
149             var utilityServiceButtonStyle = new ButtonStyle()
150             {
151                 Overlay = new ImageViewStyle()
152                 {
153                     ResourceUrl = new Selector<string>
154                     {
155                         Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
156                         Other = ""
157                     },
158                     Border = new Rectangle(5, 5, 5, 5)
159                 },
160                 Text = new TextLabelStyle()
161                 {
162                     TextColor = new Selector<Color>
163                     {
164                         Normal = new Color(1, 1, 1, 1),
165                         Pressed = new Color(1, 1, 1, 0.7f),
166                         Disabled = new Color(1, 1, 1, 0.4f)
167                     },
168                     Text = "ServiceBasicButton",
169                     PointSize = 20,
170                 },
171                 BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_point_btn_normal.png",
172                 BackgroundImageBorder = new Rectangle(5, 5, 5, 5)
173             };
174             utilityServiceButton = new Button();
175             utilityServiceButton.ApplyStyle(utilityServiceButtonStyle);
176             utilityServiceButton.ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
177
178             utilityServiceButton.Size = new Size(300, 80);
179             parent1.Add(utilityServiceButton);
180
181             //Create utility toggle style of button.
182             var utilityToggleButtonStyle = new ButtonStyle()
183             {
184                 BackgroundImage = new Selector<string>
185                 {
186                     Normal = CommonResource.GetFHResourcePath() + "3. Button/rectangle_toggle_btn_normal.png",
187                     Selected = CommonResource.GetFHResourcePath() + "3. Button/rectangle_point_btn_normal.png",
188                 },
189                 Overlay = new ImageViewStyle()
190                 {
191                     ResourceUrl = new Selector<string>
192                     {
193                         Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
194                         Other = ""
195                     }
196                 },
197                 Text = new TextLabelStyle()
198                 {
199                     TextColor = new Selector<Color>
200                     {
201                         Normal = new Color(0.058f, 0.631f, 0.92f, 1),
202                         Selected = new Color(1, 1, 1, 1),
203                     },
204                     Text = new Selector<string>
205                     {
206                         Normal = "Toggle Off",
207                         Selected = "Toggle On"
208                     },
209                     PointSize = 20
210                 },
211                 BackgroundColor = new Selector<Color>()
212             };
213             utilityToggleButton = new Button();
214             utilityToggleButton.ApplyStyle(utilityToggleButtonStyle);
215             utilityToggleButton.IsSelectable = true;
216             utilityToggleButton.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
217             utilityToggleButton.ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
218             utilityToggleButton.OverlayImage.Border = new Rectangle(5, 5, 5, 5);
219
220             utilityToggleButton.Size = new Size(300, 80);
221             parent1.Add(utilityToggleButton);
222
223             //Create utility oval style of button.
224             var utilityOvalButtonStyle = new ButtonStyle()
225             {
226                 BackgroundImage = new Selector<string>
227                 {
228                     Normal = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_normal.png",
229                     Selected = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_select.png",
230                 },
231                 Overlay = new ImageViewStyle()
232                 {
233                     ResourceUrl = new Selector<string>
234                     {
235                         Pressed = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_press_overlay.png",
236                         Other = ""
237                     }
238                 },
239                 Text = new TextLabelStyle()
240                 {
241                     Text = "",
242                 },
243                 BackgroundColor = new Selector<Color>(),
244             };
245             utilityOvalButton = new Button();
246             utilityOvalButton.ApplyStyle(utilityOvalButtonStyle);
247             utilityOvalButton.IsSelectable = true;
248             utilityOvalButton.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
249             utilityOvalButton.ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
250             utilityOvalButton.OverlayImage.Border = new Rectangle(5, 5, 5, 5);
251
252             utilityOvalButton.Size = new Size(104, 104);
253             utilityOvalButton.TextLabel.PointSize = 20;
254             parent1.Add(utilityOvalButton);
255
256             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
257             //Create family basic style of Button.
258             ButtonStyle familyBasicButtonStyle = new ButtonStyle
259             {
260                 IsSelectable = true,
261                 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png" },
262                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
263                 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
264
265                 Overlay = new ImageViewStyle
266                 {
267                     ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
268                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
269                 },
270
271                 Text = new TextLabelStyle
272                 {
273                     PointSize = new Selector<float?> { All = 20 },
274                     HorizontalAlignment = HorizontalAlignment.Center,
275                     VerticalAlignment = VerticalAlignment.Center,
276                     WidthResizePolicy = ResizePolicyType.FillToParent,
277                     HeightResizePolicy = ResizePolicyType.FillToParent,
278
279                     TextColor = new Selector<Color>
280                     {
281                         Normal = new Color(0, 0, 0, 1),
282                         Pressed = new Color(0, 0, 0, 0.7f),
283                         Selected = new Color(0.141f, 0.769f, 0.278f, 1),
284                         Disabled = new Color(0, 0, 0, 0.4f),
285                     },
286                     Text = "FamilyBasicButton",
287                 }
288             };
289             familyBasicButton = new Button(familyBasicButtonStyle);
290             familyBasicButton.Size = new Size(300, 80);
291             parent2.Add(familyBasicButton);
292
293             //Create family service style of button.
294             ButtonStyle familyServiceButtonStyle = new ButtonStyle
295             {
296                 IsSelectable = false,
297                 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_point_btn_normal_24c447.png" },
298                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
299
300                 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
301
302                 Overlay = new ImageViewStyle
303                 {
304                     ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
305                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
306                 },
307
308                 Text = new TextLabelStyle
309                 {
310                     PointSize = new Selector<float?> { All = 20 },
311                     HorizontalAlignment = HorizontalAlignment.Center,
312                     VerticalAlignment = VerticalAlignment.Center,
313                     WidthResizePolicy = ResizePolicyType.FillToParent,
314                     HeightResizePolicy = ResizePolicyType.FillToParent,
315
316                     TextColor = new Selector<Color>
317                     {
318                         Normal = new Color(1, 1, 1, 1),
319                         Pressed = new Color(1, 1, 1, 0.7f),
320                         Disabled = new Color(1, 1, 1, 0.4f),
321                     },
322                     Text = "FamilySeviceButton"
323                 }
324             };
325             familyServiceButton = new Button(familyServiceButtonStyle);
326             familyServiceButton.Size = new Size(300, 80);
327             parent2.Add(familyServiceButton);
328
329             //Create family toggle style of button.
330             ButtonStyle familyToggleButtonStyle = new ButtonStyle
331             {
332                 IsSelectable = true,
333                 BackgroundImage = new Selector<string>
334                 {
335                     Normal = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_toggle_btn_normal_24c447.png",
336                     Selected = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_point_btn_normal_24c447.png",
337                 },
338                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
339
340                 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
341
342                 Overlay = new ImageViewStyle
343                 {
344                     ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
345                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
346                 },
347
348                 Text = new TextLabelStyle
349                 {
350                     PointSize = new Selector<float?> { All = 20 },
351                     HorizontalAlignment = HorizontalAlignment.Center,
352                     VerticalAlignment = VerticalAlignment.Center,
353                     WidthResizePolicy = ResizePolicyType.FillToParent,
354                     HeightResizePolicy = ResizePolicyType.FillToParent,
355
356                     TextColor = new Selector<Color>
357                     {
358                         Normal = new Color(0.141f, 0.769f, 0.278f, 1),
359                         Selected = new Color(1, 1, 1, 1),
360                     },
361                     Text = new Selector<string>
362                     {
363                         Normal = "Toggle Off",
364                         Selected = "Toggle On"
365                     }
366                 }
367             };
368             familyToggleButton = new Button(familyToggleButtonStyle);
369             familyToggleButton.Size = new Size(300, 80);
370             parent2.Add(familyToggleButton);
371
372             //Create family oval style of button.
373             ButtonStyle familyOvalButtonStyle = new ButtonStyle
374             {
375                 IsSelectable = true,
376                 BackgroundImage = new Selector<string>
377                 {
378                     Normal = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_normal.png",
379                     Selected = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/oval_toggle_btn_select_24c447.png",
380                 },
381                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
382
383                 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
384
385                 Overlay = new ImageViewStyle
386                 {
387                     ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_press_overlay.png", Other = "" },
388                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
389                 },
390             };
391             familyOvalButton = new Button(familyOvalButtonStyle);
392             familyOvalButton.Size = new Size(104, 104);
393             parent2.Add(familyOvalButton);
394
395             // Add three layout into root
396             root.Add(parent1);
397             root.Add(parent2);
398             root.Add(parent3);
399         }
400
401         private void Window_KeyEvent(object sender, Window.KeyEventArgs e)
402         {
403             if(e.Key.State == Key.StateType.Up)
404             {
405                 switch(e.Key.KeyPressedName)
406                 {
407                     case "1":
408                         iconTextButton.IconRelativeOrientation = Button.IconOrientation.Right;
409                         break;
410                     case "2":
411                         iconTextButton.IconRelativeOrientation = Button.IconOrientation.Top;
412                         break;
413                     case "3":
414                         iconTextButton.IconRelativeOrientation = Button.IconOrientation.Bottom;
415                         break;
416                     case "4":
417                         iconTextButton.IconRelativeOrientation = Button.IconOrientation.Left;
418                         break;
419                     case "5":
420                         iconTextButton.Icon.Padding.Start = 50;
421                         break;
422                     case "6":
423                         iconTextButton.Icon.Padding.End = 50;
424                         break;
425                     case "7":
426                         iconTextButton.LayoutDirection = ViewLayoutDirectionType.RTL;
427                         break;
428                     case "8":
429                         iconTextButton.LayoutDirection = ViewLayoutDirectionType.LTR;
430                         break;
431                 }
432             }
433         }
434
435         public void Deactivate()
436         {
437             if (root != null)
438             {
439                 parent1.Remove(textButton);
440                 textButton.Dispose();
441                 textButton = null;
442                 parent1.Remove(utilityBasicButton);
443                 utilityBasicButton.Dispose();
444                 utilityBasicButton = null;
445                 parent1.Remove(utilityServiceButton);
446                 utilityServiceButton.Dispose();
447                 utilityServiceButton = null;
448                 parent1.Remove(utilityToggleButton);
449                 utilityToggleButton.Dispose();
450                 utilityToggleButton = null;
451                 parent1.Remove(utilityOvalButton);
452                 utilityOvalButton.Dispose();
453                 utilityOvalButton = null;
454
455                 parent1.Remove(familyBasicButton);
456                 familyBasicButton.Dispose();
457                 familyBasicButton = null;
458                 parent1.Remove(familyServiceButton);
459                 familyServiceButton.Dispose();
460                 familyServiceButton = null;
461                 parent1.Remove(familyToggleButton);
462                 familyToggleButton.Dispose();
463                 familyToggleButton = null;
464                 parent1.Remove(familyOvalButton);
465                 familyOvalButton.Dispose();
466                 familyOvalButton = null;
467
468                 parent3.Remove(iconTextButton);
469                 iconTextButton.Dispose();
470                 iconTextButton = null;
471
472                 root.Remove(parent1);
473                 parent1.Dispose();
474                 parent1 = null;
475
476                 root.Remove(parent2);
477                 parent2.Dispose();
478                 parent2 = null;
479
480                 root.Remove(parent3);
481                 parent3.Dispose();
482                 parent3 = null;
483
484                 NUIApplication.GetDefaultWindow().Remove(root);
485                 root.Dispose();
486                 root = null;
487             }
488         }
489     }
490 }