d9b8dd16e05df9290fb56944bb5c944af6331e63
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / RadioButtonSample.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 RadioButtonSample : IExample
8     {
9         private View root;
10         private View left;
11         private View right;
12         private View leftbody;
13         private View rightbody;
14
15         private TextLabel[] createText = new TextLabel[2];
16         private TextLabel[] modeText = new TextLabel[4];
17         private TextLabel[] modeText2 = new TextLabel[4];
18
19         private RadioButton[] utilityRadioButton = new RadioButton[4];
20         private RadioButton[] familyRadioButton = new RadioButton[4];
21         private RadioButton[] foodRadioButton = new RadioButton[4];
22         private RadioButton[] kitchenRadioButton = new RadioButton[4];
23         private RadioButtonGroup[] group = new RadioButtonGroup[4];
24
25         private RadioButton[] utilityRadioButton2 = new RadioButton[4];
26         private RadioButton[] familyRadioButton2 = new RadioButton[4];
27         private RadioButton[] foodRadioButton2 = new RadioButton[4];
28         private RadioButton[] kitchenRadioButton2 = new RadioButton[4];
29         private RadioButtonGroup[] group2 = new RadioButtonGroup[4];
30
31         private static string[] mode = new string[]
32         {
33             "Utility",
34             "Family",
35             "Food",
36             "Kitchen",
37         };
38         public void Activate()
39         {
40             Window window = NUIApplication.GetDefaultWindow();
41
42             // Create root view.
43             root = new View()
44             {
45                 Size = new Size(1920, 1080),
46                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
47                                 Padding = new Extents(40, 40, 40, 40),
48                 Layout = new LinearLayout()
49                 {
50                     LinearOrientation = LinearLayout.Orientation.Horizontal,
51                     CellPadding = new Size(40, 40),
52                     HorizontalAlignment = HorizontalAlignment.Center,
53                     VerticalAlignment = VerticalAlignment.Center,
54                 }
55             };
56             window.Add(root);
57
58             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
59             left = new View()
60             {
61                 Size = new Size(920, 800),
62                 Layout = new LinearLayout()
63                 {
64                     LinearOrientation = LinearLayout.Orientation.Vertical
65                 }
66             };
67
68             //Create left description text.
69             createText[0] = new TextLabel();
70             createText[0].Text = "Create RadioButton just by properties";
71             createText[0].TextColor = Color.White;
72             createText[0].Size = new Size(800, 100);
73             left.Add(createText[0]);
74
75             leftbody = new View();
76             leftbody.Layout = new GridLayout() { Columns = 4 };
77             int num = 4;
78             for (int i = 0; i < num; i++)
79             {
80                 group[i] = new RadioButtonGroup();
81                 modeText[i] = new TextLabel();
82                 modeText[i].Text = mode[i];
83                 modeText[i].Size = new Size(200, 48);
84                 modeText[i].HorizontalAlignment = HorizontalAlignment.Center;
85                 modeText[i].VerticalAlignment = VerticalAlignment.Center;
86                 leftbody.Add(modeText[i]);
87             }
88
89             for (int i = 0; i < num; i++)
90             {
91                 int index = i + 1;
92
93                 // create utility radio button.
94                 utilityRadioButton[i] = new RadioButton();
95                 utilityRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
96                 {
97                     global::System.Console.WriteLine($"Left {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
98                 };
99                 var utilityStyle = utilityRadioButton[i].Style;
100                 utilityStyle.Icon.Opacity = new Selector<float?>
101                 {
102                     Normal = 1.0f,
103                     Selected = 1.0f,
104                     Disabled = 0.4f,
105                     DisabledSelected = 0.4f
106                 };
107                 utilityStyle.Icon.BackgroundImage = "";
108                 utilityStyle.Icon.ResourceUrl = new Selector<string>
109                 {
110                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
111                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_on.png",
112                     Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
113                     DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_on.png",
114                 };
115                 utilityRadioButton[i].ApplyStyle(utilityStyle);
116                 utilityRadioButton[i].Size = new Size(48, 48);
117                 utilityRadioButton[i].Icon.Size = new Size(48, 48);
118                 group[0].Add(utilityRadioButton[i]);
119
120                 // create family radio button.
121                 familyRadioButton[i] = new RadioButton();
122                 familyRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
123                 {
124                     global::System.Console.WriteLine($"Left {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
125                 };
126                 var familyStyle = familyRadioButton[i].Style;
127                 familyStyle.Icon.Opacity = new Selector<float?>
128                 {
129                     Normal = 1.0f,
130                     Selected = 1.0f,
131                     Disabled = 0.4f,
132                     DisabledSelected = 0.4f
133                 };
134                 familyStyle.Icon.BackgroundImage = "";
135                 familyStyle.Icon.ResourceUrl = new Selector<string>
136                 {
137                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
138                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
139                     Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
140                     DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
141                 };
142                 familyRadioButton[i].ApplyStyle(familyStyle);
143                 familyRadioButton[i].Size = new Size(48, 48);
144                 familyRadioButton[i].Icon.Size = new Size(48, 48);
145
146                 group[1].Add(familyRadioButton[i]);
147
148                 // create food radio button.
149                 foodRadioButton[i] = new RadioButton();
150                 foodRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
151                 {
152                     global::System.Console.WriteLine($"Left {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
153                 };
154                 var foodStyle = foodRadioButton[i].Style;
155                 foodStyle.Icon.Opacity = new Selector<float?>
156                 {
157                     Normal = 1.0f,
158                     Selected = 1.0f,
159                     Disabled = 0.4f,
160                     DisabledSelected = 0.4f
161                 };
162                 foodStyle.Icon.BackgroundImage = "";
163                 foodStyle.Icon.ResourceUrl = new Selector<string>
164                 {
165                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
166                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
167                     Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
168                     DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
169                 };
170                 foodRadioButton[i].ApplyStyle(foodStyle);
171                 foodRadioButton[i].Size = new Size(150, 48);
172                 foodRadioButton[i].Icon.Size = new Size(48, 48);
173
174                 group[2].Add(foodRadioButton[i]);
175
176                 // create kitchen radio button.
177                 kitchenRadioButton[i] = new RadioButton();
178                 kitchenRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
179                 {
180                     global::System.Console.WriteLine($"Left {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
181                 };
182                 var kitchenStyle = kitchenRadioButton[i].Style;
183                 kitchenStyle.Icon.Opacity = new Selector<float?>
184                 {
185                     Normal = 1.0f,
186                     Selected = 1.0f,
187                     Disabled = 0.4f,
188                     DisabledSelected = 0.4f
189                 };
190                 kitchenStyle.Icon.BackgroundImage = "";
191                 kitchenStyle.Icon.ResourceUrl = new Selector<string>
192                 {
193                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
194                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
195                     Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
196                     DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
197                 };
198                 kitchenRadioButton[i].ApplyStyle(kitchenStyle);
199                 kitchenRadioButton[i].Size = new Size(48, 48);
200                 kitchenRadioButton[i].Icon.Size = new Size(48, 48);
201
202                 group[3].Add(kitchenRadioButton[i]);
203
204                 leftbody.Add(utilityRadioButton[i]);
205                 leftbody.Add(familyRadioButton[i]);
206                 leftbody.Add(foodRadioButton[i]);
207                 leftbody.Add(kitchenRadioButton[i]);
208             }
209
210             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
211             right = new View()
212             {
213                 Size = new Size(920, 800),
214                 Layout = new LinearLayout()
215                 {
216                     LinearOrientation = LinearLayout.Orientation.Vertical,
217                 }
218             };
219
220             rightbody = new View();
221             rightbody.Layout = new GridLayout() { Columns = 4 };
222             createText[1] = new TextLabel();
223             createText[1].Text = "Create RadioButton just by styles";
224             createText[1].TextColor = Color.White;
225             createText[1].Size = new Size(800, 100);
226             right.Add(createText[1]);
227
228             for (int i = 0; i < num; i++)
229             {
230                 group2[i] = new RadioButtonGroup();
231                 modeText2[i] = new TextLabel();
232                 modeText2[i].Text = mode[i];
233                 modeText2[i].Size = new Size(200, 48);
234                 modeText2[i].HorizontalAlignment = HorizontalAlignment.Center;
235                 modeText2[i].VerticalAlignment = VerticalAlignment.Center;
236                 rightbody.Add(modeText2[i]);
237             }
238
239             //Create utility style of radio button.
240             ButtonStyle utilityStyle2 = new ButtonStyle
241             {
242                 Icon = new ImageViewStyle
243                 {
244                     Size =  new Size(48, 48),
245                     Opacity = new Selector<float?>
246                     {
247                         Normal = 1.0f,
248                         Selected = 1.0f,
249                         Disabled = 0.4f,
250                         DisabledSelected = 0.4f
251                     },
252                     ResourceUrl = new Selector<string>
253                     {
254                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
255                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_on.png",
256                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
257                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_on.png",
258                     },
259                 },            
260             };
261             //Create family style of radio button.
262             ButtonStyle familyStyle2 = new ButtonStyle
263             {
264                 Icon = new ImageViewStyle
265                 {
266                     Size =  new Size(48, 48),
267                     Opacity = new Selector<float?>
268                     {
269                         Normal = 1.0f,
270                         Selected = 1.0f,
271                         Disabled = 0.4f,
272                         DisabledSelected = 0.4f
273                     },
274                     ResourceUrl = new Selector<string>
275                     {
276                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
277                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
278                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
279                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
280                     },
281                 },
282             };
283             //Create food style of radio button.
284             ButtonStyle foodStyle2 = new ButtonStyle
285             {
286                 Icon = new ImageViewStyle
287                 {
288                     Size = new Size(48, 48),
289                     Opacity = new Selector<float?>
290                     {
291                         Normal = 1.0f,
292                         Selected = 1.0f,
293                         Disabled = 0.4f,
294                         DisabledSelected = 0.4f
295                     },
296                     ResourceUrl = new Selector<string>
297                     {
298                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
299                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
300                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
301                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
302                     },
303                 },
304             };
305             //Create kitchen style of radio button.
306             ButtonStyle kitchenStyle2 = new ButtonStyle
307             {
308                 Icon = new ImageViewStyle
309                 {
310                     Size = new Size(48, 48),
311                     Opacity = new Selector<float?>
312                     {
313                         Normal = 1.0f,
314                         Selected = 1.0f,
315                         Disabled = 0.4f,
316                         DisabledSelected = 0.4f
317                     },
318                     ResourceUrl = new Selector<string>
319                     {
320                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
321                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
322                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
323                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
324                     },
325                 },
326             };
327             for (int i = 0; i < num; i++)
328             {
329                 int index = i + 1;
330
331                 utilityRadioButton2[i] = new RadioButton(utilityStyle2);
332                 utilityRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
333                 {
334                     global::System.Console.WriteLine($"Right {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
335                 };
336                 utilityRadioButton2[i].Size = new Size(48, 48);
337                 group2[0].Add(utilityRadioButton2[i]);
338
339                 familyRadioButton2[i] = new RadioButton(familyStyle2);
340                 familyRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
341                 {
342                     global::System.Console.WriteLine($"Right {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
343                 };
344                 familyRadioButton2[i].Size = new Size(48, 48);
345                 group2[1].Add(familyRadioButton2[i]);
346
347                 foodRadioButton2[i] = new RadioButton(foodStyle2);
348                 foodRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
349                 {
350                     global::System.Console.WriteLine($"Right {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
351                 };
352                 foodRadioButton2[i].Size = new Size(48, 48);
353                 group2[2].Add(foodRadioButton2[i]);
354
355                 kitchenRadioButton2[i] = new RadioButton(kitchenStyle2);
356                 kitchenRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
357                 {
358                     global::System.Console.WriteLine($"Right {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
359                 };
360                 kitchenRadioButton2[i].Size = new Size(48, 48);
361                 group2[3].Add(kitchenRadioButton2[i]);
362
363                 rightbody.Add(utilityRadioButton2[i]);
364                 rightbody.Add(familyRadioButton2[i]);
365                 rightbody.Add(foodRadioButton2[i]);
366                 rightbody.Add(kitchenRadioButton2[i]);
367             }
368
369             root.Add(left);
370             root.Add(right);
371             left.Add(leftbody);
372             right.Add(rightbody);
373
374             utilityRadioButton[2].IsEnabled = false;
375             familyRadioButton[2].IsEnabled = false;
376             foodRadioButton[2].IsEnabled = false;
377             kitchenRadioButton[2].IsEnabled = false;
378
379             utilityRadioButton2[2].IsEnabled = false;
380             familyRadioButton2[2].IsEnabled = false;
381             foodRadioButton2[2].IsEnabled = false;
382             kitchenRadioButton2[2].IsEnabled = false;
383
384             utilityRadioButton[3].IsEnabled = false;
385             familyRadioButton[3].IsEnabled = false;
386             foodRadioButton[3].IsEnabled = false;
387             kitchenRadioButton[3].IsEnabled = false;
388             utilityRadioButton[3].IsSelected = true;
389             familyRadioButton[3].IsSelected = true;
390             foodRadioButton[3].IsSelected = true;
391             kitchenRadioButton[3].IsSelected = true;
392
393             utilityRadioButton2[3].IsEnabled = false;
394             familyRadioButton2[3].IsEnabled = false;
395             foodRadioButton2[3].IsEnabled = false;
396             kitchenRadioButton2[3].IsEnabled = false;
397             utilityRadioButton2[3].IsSelected = true;
398             familyRadioButton2[3].IsSelected = true;
399             foodRadioButton2[3].IsSelected = true;
400             kitchenRadioButton2[3].IsSelected = true;
401         }
402
403         public void Deactivate()
404         {
405             if (root != null)
406             {
407                 int num = 4;
408                 for (int i = 0; i < num; i++)
409                 {
410                     leftbody.Remove(utilityRadioButton[i]);
411                     utilityRadioButton[i].Dispose();
412                     utilityRadioButton[i] = null;
413
414                     leftbody.Remove(familyRadioButton[i]);
415                     familyRadioButton[i].Dispose();
416                     familyRadioButton[i] = null;
417
418                     leftbody.Remove(foodRadioButton[i]);
419                     foodRadioButton[i].Dispose();
420                     foodRadioButton[i] = null;
421
422                     leftbody.Remove(kitchenRadioButton[i]);
423                     kitchenRadioButton[i].Dispose();
424                     kitchenRadioButton[i] = null;
425
426                     leftbody.Remove(modeText[i]);
427                     modeText[i].Dispose();
428                     modeText[i] = null;
429
430                     rightbody.Remove(utilityRadioButton2[i]);
431                     utilityRadioButton2[i].Dispose();
432                     utilityRadioButton2[i] = null;
433
434                     rightbody.Remove(familyRadioButton2[i]);
435                     familyRadioButton2[i].Dispose();
436                     familyRadioButton2[i] = null;
437
438                     rightbody.Remove(foodRadioButton2[i]);
439                     foodRadioButton2[i].Dispose();
440                     foodRadioButton2[i] = null;
441
442                     rightbody.Remove(kitchenRadioButton2[i]);
443                     kitchenRadioButton2[i].Dispose();
444                     kitchenRadioButton2[i] = null;
445
446                     rightbody.Remove(modeText2[i]);
447                     modeText2[i].Dispose();
448                     modeText2[i] = null;
449                 }
450
451                 left.Remove(createText[0]);
452                 createText[0].Dispose();
453                 createText[0] = null;
454                 left.Remove(leftbody);
455                 leftbody.Dispose();
456                 leftbody = null;
457                 right.Remove(createText[1]);
458                 createText[1].Dispose();
459                 createText[1] = null;
460                 right.Remove(rightbody);
461                 rightbody.Dispose();
462                 rightbody = null;
463
464                 root.Remove(left);
465                 left.Dispose();
466                 left = null;
467                 root.Remove(right);
468                 right.Dispose();
469                 right = null;
470                 NUIApplication.GetDefaultWindow().Remove(root);
471                 root.Dispose();
472                 root = null;
473             }
474         }
475     }
476 }