9b8e1e52613dc720e166c7c1615b7c7e3bec364a
[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
11         private TextLabel[] createText = new TextLabel[2];
12         private TextLabel[] modeText = new TextLabel[4];
13         private TextLabel[] modeText2 = new TextLabel[4];
14
15         private RadioButton[] utilityRadioButton = new RadioButton[4];
16         private RadioButton[] familyRadioButton = new RadioButton[4];
17         private RadioButton[] foodRadioButton = new RadioButton[4];
18         private RadioButton[] kitchenRadioButton = new RadioButton[4];
19         private RadioButtonGroup[] group = new RadioButtonGroup[4];
20
21         private RadioButton[] utilityRadioButton2 = new RadioButton[4];
22         private RadioButton[] familyRadioButton2 = new RadioButton[4];
23         private RadioButton[] foodRadioButton2 = new RadioButton[4];
24         private RadioButton[] kitchenRadioButton2 = new RadioButton[4];
25         private RadioButtonGroup[] group2 = new RadioButtonGroup[4];
26
27         private static string[] mode = new string[]
28         {
29             "Utility",
30             "Family",
31             "Food",
32             "Kitchen",
33         };
34         public void Activate()
35         {
36             Window window = Window.Instance;
37
38             root = new View()
39             {
40                 Size2D = new Size2D(1920, 1080),
41                 BackgroundColor = Color.White,
42             };
43             window.Add(root);
44
45             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
46             createText[0] = new TextLabel();
47             createText[0].Text = "Create RadioButton just by properties";
48             createText[0].TextColor = Color.White;
49             createText[0].Size2D = new Size2D(500, 100);
50             createText[0].Position2D = new Position2D(400, 100);
51             root.Add(createText[0]);
52
53             int num = 4;
54             for (int i = 0; i < num; i++)
55             {
56                 group[i] = new RadioButtonGroup();
57                 modeText[i] = new TextLabel();
58                 modeText[i].Text = mode[i];
59                 modeText[i].Size2D = new Size2D(200, 48);
60                 modeText[i].Position2D = new Position2D(300 + 200 * i, 200);
61                 root.Add(modeText[i]);
62             }
63
64             for (int i = 0; i < num; i++)
65             {
66                 utilityRadioButton[i] = new RadioButton();
67                 utilityRadioButton[i].Size2D = new Size2D(48, 48);
68                 utilityRadioButton[i].Position2D = new Position2D(300, 300 + i * 100);
69                 utilityRadioButton[i].Style.Icon.Size = new Size(48, 48);
70                 utilityRadioButton[i].Style.Icon.Padding.Start = 5;
71                 utilityRadioButton[i].Style.Icon.Padding.End = 5;
72                 utilityRadioButton[i].Style.Icon.Opacity = new Selector<float?>
73                 {
74                     Normal = 1.0f,
75                     Selected = 1.0f,
76                     Disabled = 0.4f,
77                     DisabledSelected = 0.4f
78                 };
79                 utilityRadioButton[i].Style.Icon.ResourceUrl = new Selector<string>
80                 {
81                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
82                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_on.png",
83                     Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
84                     DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_on.png",
85                 };
86
87                 group[0].Add(utilityRadioButton[i]);
88                 ////////
89                 familyRadioButton[i] = new RadioButton();
90                 familyRadioButton[i].Size2D = new Size2D(48, 48);
91                 familyRadioButton[i].Position2D = new Position2D(500, 300 + i * 100);
92                 familyRadioButton[i].Style.Icon.Size = new Size(48, 48);
93                 familyRadioButton[i].Style.Icon.Padding.Start = 5;
94                 familyRadioButton[i].Style.Icon.Padding.End = 5;
95                 familyRadioButton[i].Style.Icon.Opacity = new Selector<float?>
96                 {
97                     Normal = 1.0f,
98                     Selected = 1.0f,
99                     Disabled = 0.4f,
100                     DisabledSelected = 0.4f
101                 };
102                 familyRadioButton[i].Style.Icon.ResourceUrl = new Selector<string>
103                 {
104                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
105                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
106                     Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
107                     DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
108                 };
109
110                 group[1].Add(familyRadioButton[i]);
111                 /////////
112                 foodRadioButton[i] = new RadioButton();
113                 foodRadioButton[i].Size2D = new Size2D(150, 48);
114                 foodRadioButton[i].Position2D = new Position2D(700, 300 + i * 100);
115                 foodRadioButton[i].Style.Icon.Size = new Size(48, 48);
116                 foodRadioButton[i].Style.Icon.Padding.Start = 5;
117                 foodRadioButton[i].Style.Icon.Padding.End = 5;
118                 foodRadioButton[i].Style.Icon.Opacity = new Selector<float?>
119                 {
120                     Normal = 1.0f,
121                     Selected = 1.0f,
122                     Disabled = 0.4f,
123                     DisabledSelected = 0.4f
124                 };
125                 foodRadioButton[i].Style.Icon.ResourceUrl = new Selector<string>
126                 {
127                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
128                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
129                     Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
130                     DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
131                 };
132
133                 //foodRadioButton[i].Text = "Radio" + i;
134                 //foodRadioButton[i].TextAlignment = HorizontalAlignment.Begin;
135                 //foodRadioButton[i].PointSize = 12;
136                 //foodRadioButton[i].TextPaddingLeft = 70;
137
138                 group[2].Add(foodRadioButton[i]);
139                 ////////
140                 kitchenRadioButton[i] = new RadioButton();
141                 kitchenRadioButton[i].Size2D = new Size2D(48, 48);
142                 kitchenRadioButton[i].Position2D = new Position2D(900, 300 + i * 100);
143                 kitchenRadioButton[i].Style.Icon.Size = new Size(48, 48);
144                 kitchenRadioButton[i].Style.Icon.Padding.Start = 5;
145                 kitchenRadioButton[i].Style.Icon.Padding.End = 5;
146                 kitchenRadioButton[i].Style.Icon.Opacity = new Selector<float?>
147                 {
148                     Normal = 1.0f,
149                     Selected = 1.0f,
150                     Disabled = 0.4f,
151                     DisabledSelected = 0.4f
152                 };
153                 kitchenRadioButton[i].Style.Icon.ResourceUrl = new Selector<string>
154                 {
155                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
156                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
157                     Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
158                     DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
159                 };
160
161                 group[3].Add(kitchenRadioButton[i]);
162
163                 root.Add(utilityRadioButton[i]);
164                 root.Add(familyRadioButton[i]);
165                 root.Add(foodRadioButton[i]);
166                 root.Add(kitchenRadioButton[i]);
167             }
168             //foodRadioButton[0].LayoutDirection = ViewLayoutDirectionType.RTL;
169             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
170             createText[1] = new TextLabel();
171             createText[1].Text = "Create RadioButton just by Attributes";
172             createText[1].TextColor = Color.White;
173             createText[1].Size2D = new Size2D(500, 100);
174             createText[1].Position2D = new Position2D(1200, 100);
175             root.Add(createText[1]);
176
177             for (int i = 0; i < num; i++)
178             {
179                 group2[i] = new RadioButtonGroup();
180                 modeText2[i] = new TextLabel();
181                 modeText2[i].Text = mode[i];
182                 modeText2[i].Size2D = new Size2D(200, 48);
183                 modeText2[i].Position2D = new Position2D(1100 + 200 * i, 200);
184                 root.Add(modeText2[i]);
185             }
186
187             ButtonStyle utilityAttrs = new ButtonStyle
188             {
189                 Icon = new ImageControlStyle
190                 {
191                     Size =  new Size(48, 48),
192                     Opacity = new Selector<float?>
193                     {
194                         Normal = 1.0f,
195                         Selected = 1.0f,
196                         Disabled = 0.4f,
197                         DisabledSelected = 0.4f
198                     },
199                     ResourceUrl = new Selector<string>
200                     {
201                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
202                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_on.png",
203                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
204                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_on.png",
205                     },
206                 },            
207             };         
208             ButtonStyle familyAttrs = new ButtonStyle
209             {
210                 Icon = new ImageControlStyle
211                 {
212                     Size =  new Size(48, 48),
213                     Opacity = new Selector<float?>
214                     {
215                         Normal = 1.0f,
216                         Selected = 1.0f,
217                         Disabled = 0.4f,
218                         DisabledSelected = 0.4f
219                     },
220                     ResourceUrl = new Selector<string>
221                     {
222                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
223                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
224                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
225                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
226                     },
227                 },
228             };
229             ButtonStyle foodAttrs = new ButtonStyle
230             {
231                 Icon = new ImageControlStyle
232                 {
233                     Size = new Size(48, 48),
234                     Opacity = new Selector<float?>
235                     {
236                         Normal = 1.0f,
237                         Selected = 1.0f,
238                         Disabled = 0.4f,
239                         DisabledSelected = 0.4f
240                     },
241                     ResourceUrl = new Selector<string>
242                     {
243                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
244                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
245                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
246                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
247                     },
248                 },
249             };
250             ButtonStyle kitchenAttrs = new ButtonStyle
251             {
252                 Icon = new ImageControlStyle
253                 {
254                     Size = new Size(48, 48),
255                     Opacity = new Selector<float?>
256                     {
257                         Normal = 1.0f,
258                         Selected = 1.0f,
259                         Disabled = 0.4f,
260                         DisabledSelected = 0.4f
261                     },
262                     ResourceUrl = new Selector<string>
263                     {
264                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
265                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
266                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_radio_off.png",
267                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
268                     },
269                 },
270             };
271             for (int i = 0; i < num; i++)
272             {
273                 utilityRadioButton2[i] = new RadioButton(utilityAttrs);
274                 utilityRadioButton2[i].Size2D = new Size2D(48, 48);
275                 utilityRadioButton2[i].Position2D = new Position2D(1100, 300 + i * 100);
276                 group2[0].Add(utilityRadioButton2[i]);
277
278                 familyRadioButton2[i] = new RadioButton(familyAttrs);
279                 familyRadioButton2[i].Size2D = new Size2D(48, 48);
280                 familyRadioButton2[i].Position2D = new Position2D(1300, 300 + i * 100);
281                 group2[1].Add(familyRadioButton2[i]);
282
283                 foodRadioButton2[i] = new RadioButton(foodAttrs);
284                 foodRadioButton2[i].Size2D = new Size2D(48, 48);
285                 foodRadioButton2[i].Position2D = new Position2D(1500, 300 + i * 100);
286                 group2[2].Add(foodRadioButton2[i]);
287
288                 kitchenRadioButton2[i] = new RadioButton(kitchenAttrs);
289                 kitchenRadioButton2[i].Size2D = new Size2D(48, 48);
290                 kitchenRadioButton2[i].Position2D = new Position2D(1700, 300 + i * 100);
291                 group2[3].Add(kitchenRadioButton2[i]);
292
293                 root.Add(utilityRadioButton2[i]);
294                 root.Add(familyRadioButton2[i]);
295                 root.Add(foodRadioButton2[i]);
296                 root.Add(kitchenRadioButton2[i]);
297             }
298
299             utilityRadioButton[2].IsEnabled = false;
300             familyRadioButton[2].IsEnabled = false;
301             foodRadioButton[2].IsEnabled = false;
302             kitchenRadioButton[2].IsEnabled = false;
303
304             utilityRadioButton2[2].IsEnabled = false;
305             familyRadioButton2[2].IsEnabled = false;
306             foodRadioButton2[2].IsEnabled = false;
307             kitchenRadioButton2[2].IsEnabled = false;
308
309             utilityRadioButton[3].IsEnabled = false;
310             familyRadioButton[3].IsEnabled = false;
311             foodRadioButton[3].IsEnabled = false;
312             kitchenRadioButton[3].IsEnabled = false;
313             utilityRadioButton[3].IsSelected = true;
314             familyRadioButton[3].IsSelected = true;
315             foodRadioButton[3].IsSelected = true;
316             kitchenRadioButton[3].IsSelected = true;
317
318             utilityRadioButton2[3].IsEnabled = false;
319             familyRadioButton2[3].IsEnabled = false;
320             foodRadioButton2[3].IsEnabled = false;
321             kitchenRadioButton2[3].IsEnabled = false;
322             utilityRadioButton2[3].IsSelected = true;
323             familyRadioButton2[3].IsSelected = true;
324             foodRadioButton2[3].IsSelected = true;
325             kitchenRadioButton2[3].IsSelected = true;
326         }
327
328         public void Deactivate()
329         {
330             if (root != null)
331             {
332                 int num = 4;
333                 for (int i = 0; i < num; i++)
334                 {
335                     root.Remove(utilityRadioButton[i]);
336                     utilityRadioButton[i].Dispose();
337                     utilityRadioButton[i] = null;
338
339                     root.Remove(familyRadioButton[i]);
340                     familyRadioButton[i].Dispose();
341                     familyRadioButton[i] = null;
342
343                     root.Remove(foodRadioButton[i]);
344                     foodRadioButton[i].Dispose();
345                     foodRadioButton[i] = null;
346
347                     root.Remove(kitchenRadioButton[i]);
348                     kitchenRadioButton[i].Dispose();
349                     kitchenRadioButton[i] = null;
350
351                     root.Remove(modeText[i]);
352                     modeText[i].Dispose();
353                     modeText[i] = null;
354
355                     root.Remove(utilityRadioButton2[i]);
356                     utilityRadioButton2[i].Dispose();
357                     utilityRadioButton2[i] = null;
358
359                     root.Remove(familyRadioButton2[i]);
360                     familyRadioButton2[i].Dispose();
361                     familyRadioButton2[i] = null;
362
363                     root.Remove(foodRadioButton2[i]);
364                     foodRadioButton2[i].Dispose();
365                     foodRadioButton2[i] = null;
366
367                     root.Remove(kitchenRadioButton2[i]);
368                     kitchenRadioButton2[i].Dispose();
369                     kitchenRadioButton2[i] = null;
370
371                     root.Remove(modeText2[i]);
372                     modeText2[i].Dispose();
373                     modeText2[i] = null;
374                 }
375
376                 root.Remove(createText[0]);
377                 createText[0].Dispose();
378                 createText[0] = null;
379                 root.Remove(createText[1]);
380                 createText[1].Dispose();
381                 createText[1] = null;
382
383                 Window.Instance.Remove(root);
384                 root.Dispose();
385             }
386         }
387     }
388 }