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