1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
5 namespace Tizen.NUI.Samples
7 public class RadioButtonSample : IExample
12 private View leftbody;
13 private View rightbody;
15 private TextLabel[] createText = new TextLabel[2];
16 private TextLabel[] modeText = new TextLabel[4];
17 private TextLabel[] modeText2 = new TextLabel[4];
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];
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];
31 private static string[] mode = new string[]
38 public void Activate()
40 Window window = NUIApplication.GetDefaultWindow();
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()
50 LinearOrientation = LinearLayout.Orientation.Horizontal,
51 CellPadding = new Size(40, 40),
52 LinearAlignment = LinearLayout.Alignment.Center,
57 ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
60 Size = new Size(920, 800),
61 Layout = new LinearLayout()
63 LinearOrientation = LinearLayout.Orientation.Vertical
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]);
74 leftbody = new View();
75 leftbody.Layout = new GridLayout() { Columns = 4 };
77 for (int i = 0; i < num; i++)
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]);
88 for (int i = 0; i < num; i++)
92 // create utility radio button.
93 utilityRadioButton[i] = new RadioButton();
94 utilityRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
96 global::System.Console.WriteLine($"Left {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
98 var utilityStyle = utilityRadioButton[i].Style;
99 utilityStyle.Icon.Opacity = new Selector<float?>
104 DisabledSelected = 0.4f
106 utilityStyle.Icon.BackgroundImage = "";
107 utilityStyle.Icon.ResourceUrl = new Selector<string>
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",
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]);
119 // create family radio button.
120 familyRadioButton[i] = new RadioButton();
121 familyRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
123 global::System.Console.WriteLine($"Left {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
125 var familyStyle = familyRadioButton[i].Style;
126 familyStyle.Icon.Opacity = new Selector<float?>
131 DisabledSelected = 0.4f
133 familyStyle.Icon.BackgroundImage = "";
134 familyStyle.Icon.ResourceUrl = new Selector<string>
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",
141 familyRadioButton[i].ApplyStyle(familyStyle);
142 familyRadioButton[i].Size = new Size(48, 48);
143 familyRadioButton[i].Icon.Size = new Size(48, 48);
145 group[1].Add(familyRadioButton[i]);
147 // create food radio button.
148 foodRadioButton[i] = new RadioButton();
149 foodRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
151 global::System.Console.WriteLine($"Left {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
153 var foodStyle = foodRadioButton[i].Style;
154 foodStyle.Icon.Opacity = new Selector<float?>
159 DisabledSelected = 0.4f
161 foodStyle.Icon.BackgroundImage = "";
162 foodStyle.Icon.ResourceUrl = new Selector<string>
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",
169 foodRadioButton[i].ApplyStyle(foodStyle);
170 foodRadioButton[i].Size = new Size(150, 48);
171 foodRadioButton[i].Icon.Size = new Size(48, 48);
173 group[2].Add(foodRadioButton[i]);
175 // create kitchen radio button.
176 kitchenRadioButton[i] = new RadioButton();
177 kitchenRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
179 global::System.Console.WriteLine($"Left {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
181 var kitchenStyle = kitchenRadioButton[i].Style;
182 kitchenStyle.Icon.Opacity = new Selector<float?>
187 DisabledSelected = 0.4f
189 kitchenStyle.Icon.BackgroundImage = "";
190 kitchenStyle.Icon.ResourceUrl = new Selector<string>
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",
197 kitchenRadioButton[i].ApplyStyle(kitchenStyle);
198 kitchenRadioButton[i].Size = new Size(48, 48);
199 kitchenRadioButton[i].Icon.Size = new Size(48, 48);
201 group[3].Add(kitchenRadioButton[i]);
203 leftbody.Add(utilityRadioButton[i]);
204 leftbody.Add(familyRadioButton[i]);
205 leftbody.Add(foodRadioButton[i]);
206 leftbody.Add(kitchenRadioButton[i]);
209 ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
212 Size = new Size(920, 800),
213 Layout = new LinearLayout()
215 LinearOrientation = LinearLayout.Orientation.Vertical,
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]);
227 for (int i = 0; i < num; i++)
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]);
238 //Create utility style of radio button.
239 ButtonStyle utilityStyle2 = new ButtonStyle
241 Icon = new ImageViewStyle
243 Size = new Size(48, 48),
244 Opacity = new Selector<float?>
249 DisabledSelected = 0.4f
251 ResourceUrl = new Selector<string>
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",
260 //Create family style of radio button.
261 ButtonStyle familyStyle2 = new ButtonStyle
263 Icon = new ImageViewStyle
265 Size = new Size(48, 48),
266 Opacity = new Selector<float?>
271 DisabledSelected = 0.4f
273 ResourceUrl = new Selector<string>
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",
282 //Create food style of radio button.
283 ButtonStyle foodStyle2 = new ButtonStyle
285 Icon = new ImageViewStyle
287 Size = new Size(48, 48),
288 Opacity = new Selector<float?>
293 DisabledSelected = 0.4f
295 ResourceUrl = new Selector<string>
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",
304 //Create kitchen style of radio button.
305 ButtonStyle kitchenStyle2 = new ButtonStyle
307 Icon = new ImageViewStyle
309 Size = new Size(48, 48),
310 Opacity = new Selector<float?>
315 DisabledSelected = 0.4f
317 ResourceUrl = new Selector<string>
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",
326 for (int i = 0; i < num; i++)
330 utilityRadioButton2[i] = new RadioButton(utilityStyle2);
331 utilityRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
333 global::System.Console.WriteLine($"Right {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
335 utilityRadioButton2[i].Size = new Size(48, 48);
336 group2[0].Add(utilityRadioButton2[i]);
338 familyRadioButton2[i] = new RadioButton(familyStyle2);
339 familyRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
341 global::System.Console.WriteLine($"Right {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
343 familyRadioButton2[i].Size = new Size(48, 48);
344 group2[1].Add(familyRadioButton2[i]);
346 foodRadioButton2[i] = new RadioButton(foodStyle2);
347 foodRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
349 global::System.Console.WriteLine($"Right {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
351 foodRadioButton2[i].Size = new Size(48, 48);
352 group2[2].Add(foodRadioButton2[i]);
354 kitchenRadioButton2[i] = new RadioButton(kitchenStyle2);
355 kitchenRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
357 global::System.Console.WriteLine($"Right {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
359 kitchenRadioButton2[i].Size = new Size(48, 48);
360 group2[3].Add(kitchenRadioButton2[i]);
362 rightbody.Add(utilityRadioButton2[i]);
363 rightbody.Add(familyRadioButton2[i]);
364 rightbody.Add(foodRadioButton2[i]);
365 rightbody.Add(kitchenRadioButton2[i]);
371 right.Add(rightbody);
373 utilityRadioButton[2].IsEnabled = false;
374 familyRadioButton[2].IsEnabled = false;
375 foodRadioButton[2].IsEnabled = false;
376 kitchenRadioButton[2].IsEnabled = false;
378 utilityRadioButton2[2].IsEnabled = false;
379 familyRadioButton2[2].IsEnabled = false;
380 foodRadioButton2[2].IsEnabled = false;
381 kitchenRadioButton2[2].IsEnabled = false;
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;
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;
402 public void Deactivate()
407 for (int i = 0; i < num; i++)
409 leftbody.Remove(utilityRadioButton[i]);
410 utilityRadioButton[i].Dispose();
411 utilityRadioButton[i] = null;
413 leftbody.Remove(familyRadioButton[i]);
414 familyRadioButton[i].Dispose();
415 familyRadioButton[i] = null;
417 leftbody.Remove(foodRadioButton[i]);
418 foodRadioButton[i].Dispose();
419 foodRadioButton[i] = null;
421 leftbody.Remove(kitchenRadioButton[i]);
422 kitchenRadioButton[i].Dispose();
423 kitchenRadioButton[i] = null;
425 leftbody.Remove(modeText[i]);
426 modeText[i].Dispose();
429 rightbody.Remove(utilityRadioButton2[i]);
430 utilityRadioButton2[i].Dispose();
431 utilityRadioButton2[i] = null;
433 rightbody.Remove(familyRadioButton2[i]);
434 familyRadioButton2[i].Dispose();
435 familyRadioButton2[i] = null;
437 rightbody.Remove(foodRadioButton2[i]);
438 foodRadioButton2[i].Dispose();
439 foodRadioButton2[i] = null;
441 rightbody.Remove(kitchenRadioButton2[i]);
442 kitchenRadioButton2[i].Dispose();
443 kitchenRadioButton2[i] = null;
445 rightbody.Remove(modeText2[i]);
446 modeText2[i].Dispose();
450 left.Remove(createText[0]);
451 createText[0].Dispose();
452 createText[0] = null;
453 left.Remove(leftbody);
456 right.Remove(createText[1]);
457 createText[1].Dispose();
458 createText[1] = null;
459 right.Remove(rightbody);
469 NUIApplication.GetDefaultWindow().Remove(root);