Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / SwitchSample.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 SwitchSample : IExample
8     {
9         private View root;
10         private View[] parentView = new View[3];
11         private TextLabel[] createText = new TextLabel[2];
12         private TextLabel[] modeText = new TextLabel[4];
13         private TextLabel[] modeText2 = new TextLabel[4];
14
15         private Switch[] utilitySwitch = new Switch[4];
16         private Switch[] familySwitch = new Switch[4];
17         private Switch[] foodSwitch = new Switch[4];
18         private Switch[] kitchenSwitch = new Switch[4];
19
20         private Switch[] utilitySwitch2 = new Switch[4];
21         private Switch[] familySwitch2 = new Switch[4];
22         private Switch[] foodSwitch2 = new Switch[4];
23         private Switch[] kitchenSwitch2 = new Switch[4];
24         private static string[] mode = new string[]
25         {
26             "Utility",
27             "Family",
28             "Food",
29             "Kitchen",
30         };
31
32         public void Activate()
33         {
34             Window window = NUIApplication.GetDefaultWindow();
35
36             root = new View()
37             {
38                 Size = new Size(1920, 1080),
39                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
40             };
41             root.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical };
42             window.Add(root);
43
44             CreateTextView();
45             CreateModeView();
46             CreateSwitchView();
47         }
48
49         private void CreateTextView()
50         {
51             // Init parent of TextView
52             parentView[0] = new View();
53             parentView[0].Size = new Size(1920, 200);
54             parentView[0].Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, LinearAlignment = LinearLayout.Alignment.CenterVertical, CellPadding = new Size2D(180, 0) };
55             root.Add(parentView[0]);
56
57             for (int i = 0; i < 2; i++)
58             {
59                 createText[i] = new TextLabel();
60                 createText[i].Size = new Size(600, 100);
61                 createText[i].PointSize = 20.0f;
62                 createText[i].BackgroundColor = Color.Magenta;
63                 createText[i].HorizontalAlignment = HorizontalAlignment.Center;
64                 createText[i].VerticalAlignment = VerticalAlignment.Center;
65                 parentView[0].Add(createText[i]);
66             }
67
68             // Text of "Create Switch just by properties"
69             createText[0].Text = "Create Switch just by Properties";
70             createText[0].Margin = new Extents(160, 0, 0, 0);
71
72             // Text of "Create Switch just by Style"
73             createText[1].Text = "Create Switch just by Style";
74         }
75
76         private void CreateModeView()
77         {
78             // Init parent of ModeView
79             parentView[1] = new View();
80             parentView[1].Size = new Size(1920, 100);
81             parentView[1].Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, CellPadding = new Size2D(0, 0) };
82             root.Add(parentView[1]);
83
84             // Create mode text
85             for (int i = 0; i < 4; i++)
86             {
87                 modeText[i] = new TextLabel();
88                 modeText[i].Text = mode[i];
89                 modeText[i].Size = new Size(196, 48);
90                 modeText[i].PointSize = 20.0f;
91                 parentView[1].Add(modeText[i]);
92             }
93             modeText[0].Margin = new Extents(100, 0, 0, 0);
94
95             for (int j = 0; j < 4; j++)
96             {
97                 modeText2[j] = new TextLabel();
98                 modeText2[j].Text = mode[j];
99                 modeText2[j].Size = new Size(196, 48);
100                 modeText2[j].PointSize = 20.0f;
101                 parentView[1].Add(modeText2[j]);
102             }
103         }
104
105         private void CreateSwitchView()
106         {
107             // Init parent of SwitchView
108             parentView[2] = new View();
109             parentView[2].Size = new Size(1920, 680);
110             parentView[2].Layout = new GridLayout() { Rows = 4, GridOrientation = GridLayout.Orientation.Horizontal };
111             root.Add(parentView[2]);
112
113             // Create switch styles
114             SwitchStyle utilitySt = new SwitchStyle
115             {
116                 Size = new Size(96, 60),
117                 IsSelectable = true,
118                 Track = new ImageViewStyle
119                 {
120                     ResourceUrl = new Selector<string>
121                     {
122                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_off.png",
123                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_on.png",
124                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_off_dim.png",
125                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_on_dim.png",
126                     },
127                     Border = new Rectangle(30, 30, 30, 30),
128                 },
129                 Thumb = new ImageViewStyle
130                 {
131                     Size = new Size(60, 60),
132                     ResourceUrl = new Selector<string>
133                     {
134                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler.png",
135                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler.png",
136                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler_dim.png",
137                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler_dim.png",
138                     },
139                 },
140             };
141             SwitchStyle familySt = new SwitchStyle
142             {
143                 IsSelectable = true,
144                 Track = new ImageViewStyle
145                 {
146                     ResourceUrl = new Selector<string>
147                     {
148                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_off.png",
149                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_switch_bg_on_24c447.png",
150                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_off_dim.png",
151                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_switch_bg_on_dim_24c447.png",
152                     },
153                     Border = new Rectangle(30, 30, 30, 30),
154                 },
155                 Thumb = new ImageViewStyle
156                 {
157                     Size = new Size(60, 60),
158                     ResourceUrl = new Selector<string>
159                     {
160                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler.png",
161                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler.png",
162                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler_dim.png",
163                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler_dim.png",
164                     },
165                 },
166             };
167             SwitchStyle foodSt = new SwitchStyle
168             {
169                 IsSelectable = true,
170                 Track = new ImageViewStyle
171                 {
172                     ResourceUrl = new Selector<string>
173                     {
174                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_off.png",
175                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_switch_bg_on_ec7510.png",
176                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_off_dim.png",
177                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_switch_bg_on_dim_ec7510.png",
178                     },
179                     Border = new Rectangle(30, 30, 30, 30),
180                 },
181                 Thumb = new ImageViewStyle
182                 {
183                     Size = new Size(60, 60),
184                     ResourceUrl = new Selector<string>
185                     {
186                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler.png",
187                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler.png",
188                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler_dim.png",
189                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler_dim.png",
190                     },
191                 },
192             };
193             SwitchStyle kitchenSt = new SwitchStyle
194             {
195                 IsSelectable = true,
196                 Track = new ImageViewStyle
197                 {
198                     ResourceUrl = new Selector<string>
199                     {
200                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_off.png",
201                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_switch_bg_on_9762d9.png",
202                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_bg_off_dim.png",
203                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_switch_bg_on_dim_9762d9.png",
204                     },
205                     Border = new Rectangle(30, 30, 30, 30),
206                 },
207                 Thumb = new ImageViewStyle
208                 {
209                     Size = new Size(60, 60),
210                     ResourceUrl = new Selector<string>
211                     {
212                         Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler.png",
213                         Selected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler.png",
214                         Disabled = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler_dim.png",
215                         DisabledSelected = CommonResource.GetFHResourcePath() + "9. Controller/controller_switch_handler_dim.png",
216                     },
217                 },
218             };
219
220             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
221             int i = 0;
222             for (; i < 4; i++)
223             {
224                 utilitySwitch[i] = new Switch();
225                 utilitySwitch[i].ApplyStyle(utilitySt);
226                 utilitySwitch[i].Size = new Size(96, 60);
227                 utilitySwitch[i].Margin = new Extents(100, 0, 20, 0);
228                 utilitySwitch[i].Feedback = true;
229                 parentView[2].Add(utilitySwitch[i]);
230             }
231             for (i = 0; i < 4; i++)
232             {
233                 familySwitch[i] = new Switch();
234                 familySwitch[i].ApplyStyle(familySt);
235                 familySwitch[i].Size = new Size(96, 60);
236                 familySwitch[i].Feedback = true;
237                 parentView[2].Add(familySwitch[i]);
238             }
239             for (i = 0; i < 4; i++)
240             {
241                 foodSwitch[i] = new Switch();
242                 foodSwitch[i].ApplyStyle(foodSt);
243                 foodSwitch[i].Size = new Size(96, 60);
244                 foodSwitch[i].Feedback = true;
245                 parentView[2].Add(foodSwitch[i]);
246             }
247             for (i = 0; i < 4; i++)
248             {
249                 kitchenSwitch[i] = new Switch();
250                 kitchenSwitch[i].ApplyStyle(kitchenSt);
251                 kitchenSwitch[i].Size = new Size(96, 60);
252                 kitchenSwitch[i].Feedback = true;
253                 parentView[2].Add(kitchenSwitch[i]);
254             }
255
256             ///////////////////////////////////////////////Create by Style//////////////////////////////////////////////////////////
257             for (i = 0; i < 4; i++)
258             {
259                 utilitySwitch2[i] = new Switch();
260                 utilitySwitch2[i].ApplyStyle(utilitySt);
261                 utilitySwitch2[i].Size = new Size(96, 60);
262                 utilitySwitch2[i].Feedback = true;
263                 parentView[2].Add(utilitySwitch2[i]);
264             }
265             for (i = 0; i < 4; i++)
266             {
267                 familySwitch2[i] = new Switch();
268                 familySwitch2[i].ApplyStyle(familySt);
269                 familySwitch2[i].Size = new Size(96, 60);
270                 familySwitch2[i].Feedback = true;
271                 parentView[2].Add(familySwitch2[i]);
272             }
273             for (i = 0; i < 4; i++)
274             {
275                 foodSwitch2[i] = new Switch();
276                 foodSwitch2[i].ApplyStyle(foodSt);
277                 foodSwitch2[i].Size = new Size(96, 60);
278                 foodSwitch2[i].Feedback = true;
279                 parentView[2].Add(foodSwitch2[i]);
280             }
281             for (i = 0; i < 4; i++)
282             {
283                 kitchenSwitch2[i] = new Switch();
284                 kitchenSwitch2[i].ApplyStyle(kitchenSt);
285                 kitchenSwitch2[i].Size = new Size(96, 60);
286                 kitchenSwitch2[i].Feedback = true;
287                 parentView[2].Add(kitchenSwitch2[i]);
288             }
289
290             utilitySwitch[2].IsEnabled = false;
291             familySwitch[2].IsEnabled = false;
292             foodSwitch[2].IsEnabled = false;
293             kitchenSwitch[2].IsEnabled = false;
294
295             utilitySwitch2[2].IsEnabled = false;
296             familySwitch2[2].IsEnabled = false;
297             foodSwitch2[2].IsEnabled = false;
298             kitchenSwitch2[2].IsEnabled = false;
299
300             utilitySwitch[3].IsEnabled = false;
301             familySwitch[3].IsEnabled = false;
302             foodSwitch[3].IsEnabled = false;
303             kitchenSwitch[3].IsEnabled = false;
304             utilitySwitch[3].IsSelected = true;
305             familySwitch[3].IsSelected = true;
306             foodSwitch[3].IsSelected = true;
307             kitchenSwitch[3].IsSelected = true;
308
309             utilitySwitch2[3].IsEnabled = false;
310             familySwitch2[3].IsEnabled = false;
311             foodSwitch2[3].IsEnabled = false;
312             kitchenSwitch2[3].IsEnabled = false;
313             utilitySwitch2[3].IsSelected = true;
314             familySwitch2[3].IsSelected = true;
315             foodSwitch2[3].IsSelected = true;
316             kitchenSwitch2[3].IsSelected = true;
317         }
318
319         public void Deactivate()
320         {
321             if (root != null)
322             {
323                 int num = 4;
324                 for (int i = 0; i < num; i++)
325                 {
326                     utilitySwitch[i].Dispose();
327                     utilitySwitch[i] = null;
328
329                     familySwitch[i].Dispose();
330                     familySwitch[i] = null;
331
332                     foodSwitch[i].Dispose();
333                     foodSwitch[i] = null;
334
335                     kitchenSwitch[i].Dispose();
336                     kitchenSwitch[i] = null;
337
338                     modeText[i].Dispose();
339                     modeText[i] = null;
340
341                     utilitySwitch2[i].Dispose();
342                     utilitySwitch2[i] = null;
343
344                     familySwitch2[i].Dispose();
345                     familySwitch2[i] = null;
346
347                     foodSwitch2[i].Dispose();
348                     foodSwitch2[i] = null;
349
350                     kitchenSwitch2[i].Dispose();
351                     kitchenSwitch2[i] = null;
352
353                     modeText2[i].Dispose();
354                     modeText2[i] = null;
355                 }
356
357                 createText[0].Dispose();
358                 createText[0] = null;
359                 createText[1].Dispose();
360                 createText[1] = null;
361
362                 for (int j = 0; j < 3; j++)
363                 {
364                     if (parentView[j] != null)
365                     {
366                         parentView[j].Dispose();
367                         parentView[j] = null;
368                     }
369                 }
370                 NUIApplication.GetDefaultWindow().Remove(root);
371                 root.Dispose();
372                 root = null;
373             }
374         }
375     }
376 }