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