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 HorizontalAlignment = HorizontalAlignment.Center,
53 VerticalAlignment = VerticalAlignment.Center,
58 ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
61 Size = new Size(920, 800),
62 Layout = new LinearLayout()
64 LinearOrientation = LinearLayout.Orientation.Vertical
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]);
75 leftbody = new View();
76 leftbody.Layout = new GridLayout() { Columns = 4 };
78 for (int i = 0; i < num; i++)
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]);
89 for (int i = 0; i < num; i++)
93 // create utility radio button.
94 utilityRadioButton[i] = new RadioButton();
95 utilityRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
97 global::System.Console.WriteLine($"Left {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
99 var utilityStyle = utilityRadioButton[i].Style;
100 utilityStyle.Icon.Opacity = new Selector<float?>
105 DisabledSelected = 0.4f
107 utilityStyle.Icon.BackgroundImage = "";
108 utilityStyle.Icon.ResourceUrl = new Selector<string>
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",
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]);
120 // create family radio button.
121 familyRadioButton[i] = new RadioButton();
122 familyRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
124 global::System.Console.WriteLine($"Left {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
126 var familyStyle = familyRadioButton[i].Style;
127 familyStyle.Icon.Opacity = new Selector<float?>
132 DisabledSelected = 0.4f
134 familyStyle.Icon.BackgroundImage = "";
135 familyStyle.Icon.ResourceUrl = new Selector<string>
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",
142 familyRadioButton[i].ApplyStyle(familyStyle);
143 familyRadioButton[i].Size = new Size(48, 48);
144 familyRadioButton[i].Icon.Size = new Size(48, 48);
146 group[1].Add(familyRadioButton[i]);
148 // create food radio button.
149 foodRadioButton[i] = new RadioButton();
150 foodRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
152 global::System.Console.WriteLine($"Left {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
154 var foodStyle = foodRadioButton[i].Style;
155 foodStyle.Icon.Opacity = new Selector<float?>
160 DisabledSelected = 0.4f
162 foodStyle.Icon.BackgroundImage = "";
163 foodStyle.Icon.ResourceUrl = new Selector<string>
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",
170 foodRadioButton[i].ApplyStyle(foodStyle);
171 foodRadioButton[i].Size = new Size(150, 48);
172 foodRadioButton[i].Icon.Size = new Size(48, 48);
174 group[2].Add(foodRadioButton[i]);
176 // create kitchen radio button.
177 kitchenRadioButton[i] = new RadioButton();
178 kitchenRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
180 global::System.Console.WriteLine($"Left {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
182 var kitchenStyle = kitchenRadioButton[i].Style;
183 kitchenStyle.Icon.Opacity = new Selector<float?>
188 DisabledSelected = 0.4f
190 kitchenStyle.Icon.BackgroundImage = "";
191 kitchenStyle.Icon.ResourceUrl = new Selector<string>
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",
198 kitchenRadioButton[i].ApplyStyle(kitchenStyle);
199 kitchenRadioButton[i].Size = new Size(48, 48);
200 kitchenRadioButton[i].Icon.Size = new Size(48, 48);
202 group[3].Add(kitchenRadioButton[i]);
204 leftbody.Add(utilityRadioButton[i]);
205 leftbody.Add(familyRadioButton[i]);
206 leftbody.Add(foodRadioButton[i]);
207 leftbody.Add(kitchenRadioButton[i]);
210 ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
213 Size = new Size(920, 800),
214 Layout = new LinearLayout()
216 LinearOrientation = LinearLayout.Orientation.Vertical,
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]);
228 for (int i = 0; i < num; i++)
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]);
239 //Create utility style of radio button.
240 ButtonStyle utilityStyle2 = new ButtonStyle
242 Icon = new ImageViewStyle
244 Size = new Size(48, 48),
245 Opacity = new Selector<float?>
250 DisabledSelected = 0.4f
252 ResourceUrl = new Selector<string>
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",
261 //Create family style of radio button.
262 ButtonStyle familyStyle2 = new ButtonStyle
264 Icon = new ImageViewStyle
266 Size = new Size(48, 48),
267 Opacity = new Selector<float?>
272 DisabledSelected = 0.4f
274 ResourceUrl = new Selector<string>
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",
283 //Create food style of radio button.
284 ButtonStyle foodStyle2 = new ButtonStyle
286 Icon = new ImageViewStyle
288 Size = new Size(48, 48),
289 Opacity = new Selector<float?>
294 DisabledSelected = 0.4f
296 ResourceUrl = new Selector<string>
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",
305 //Create kitchen style of radio button.
306 ButtonStyle kitchenStyle2 = new ButtonStyle
308 Icon = new ImageViewStyle
310 Size = new Size(48, 48),
311 Opacity = new Selector<float?>
316 DisabledSelected = 0.4f
318 ResourceUrl = new Selector<string>
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",
327 for (int i = 0; i < num; i++)
331 utilityRadioButton2[i] = new RadioButton(utilityStyle2);
332 utilityRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
334 global::System.Console.WriteLine($"Right {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
336 utilityRadioButton2[i].Size = new Size(48, 48);
337 group2[0].Add(utilityRadioButton2[i]);
339 familyRadioButton2[i] = new RadioButton(familyStyle2);
340 familyRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
342 global::System.Console.WriteLine($"Right {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
344 familyRadioButton2[i].Size = new Size(48, 48);
345 group2[1].Add(familyRadioButton2[i]);
347 foodRadioButton2[i] = new RadioButton(foodStyle2);
348 foodRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
350 global::System.Console.WriteLine($"Right {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
352 foodRadioButton2[i].Size = new Size(48, 48);
353 group2[2].Add(foodRadioButton2[i]);
355 kitchenRadioButton2[i] = new RadioButton(kitchenStyle2);
356 kitchenRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
358 global::System.Console.WriteLine($"Right {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
360 kitchenRadioButton2[i].Size = new Size(48, 48);
361 group2[3].Add(kitchenRadioButton2[i]);
363 rightbody.Add(utilityRadioButton2[i]);
364 rightbody.Add(familyRadioButton2[i]);
365 rightbody.Add(foodRadioButton2[i]);
366 rightbody.Add(kitchenRadioButton2[i]);
372 right.Add(rightbody);
374 utilityRadioButton[2].IsEnabled = false;
375 familyRadioButton[2].IsEnabled = false;
376 foodRadioButton[2].IsEnabled = false;
377 kitchenRadioButton[2].IsEnabled = false;
379 utilityRadioButton2[2].IsEnabled = false;
380 familyRadioButton2[2].IsEnabled = false;
381 foodRadioButton2[2].IsEnabled = false;
382 kitchenRadioButton2[2].IsEnabled = false;
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;
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;
403 public void Deactivate()
408 for (int i = 0; i < num; i++)
410 leftbody.Remove(utilityRadioButton[i]);
411 utilityRadioButton[i].Dispose();
412 utilityRadioButton[i] = null;
414 leftbody.Remove(familyRadioButton[i]);
415 familyRadioButton[i].Dispose();
416 familyRadioButton[i] = null;
418 leftbody.Remove(foodRadioButton[i]);
419 foodRadioButton[i].Dispose();
420 foodRadioButton[i] = null;
422 leftbody.Remove(kitchenRadioButton[i]);
423 kitchenRadioButton[i].Dispose();
424 kitchenRadioButton[i] = null;
426 leftbody.Remove(modeText[i]);
427 modeText[i].Dispose();
430 rightbody.Remove(utilityRadioButton2[i]);
431 utilityRadioButton2[i].Dispose();
432 utilityRadioButton2[i] = null;
434 rightbody.Remove(familyRadioButton2[i]);
435 familyRadioButton2[i].Dispose();
436 familyRadioButton2[i] = null;
438 rightbody.Remove(foodRadioButton2[i]);
439 foodRadioButton2[i].Dispose();
440 foodRadioButton2[i] = null;
442 rightbody.Remove(kitchenRadioButton2[i]);
443 kitchenRadioButton2[i].Dispose();
444 kitchenRadioButton2[i] = null;
446 rightbody.Remove(modeText2[i]);
447 modeText2[i].Dispose();
451 left.Remove(createText[0]);
452 createText[0].Dispose();
453 createText[0] = null;
454 left.Remove(leftbody);
457 right.Remove(createText[1]);
458 createText[1].Dispose();
459 createText[1] = null;
460 right.Remove(rightbody);
470 NUIApplication.GetDefaultWindow().Remove(root);