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