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