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