1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
5 namespace Tizen.NUI.Samples
7 public class SwitchSample : IExample
11 private TextLabel[] createText = new TextLabel[2];
12 private TextLabel[] modeText = new TextLabel[4];
13 private TextLabel[] modeText2 = new TextLabel[4];
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];
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];
25 private static string[] mode = new string[]
32 public void Activate()
34 Window window = NUIApplication.GetDefaultWindow();
38 Size2D = new Size2D(1920, 1080),
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]);
50 for (int i = 0; i < num; i++)
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]);
59 for (int i = 0; i < num; i++)
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>
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",
72 utilitySwitch[i].Style.Thumb.ResourceUrl = new Selector<string>
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",
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>
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",
92 familySwitch[i].Style.Thumb.ResourceUrl = new Selector<string>
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",
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>
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",
111 foodSwitch[i].Style.Thumb.ResourceUrl = new Selector<string>
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",
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>
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",
131 kitchenSwitch[i].Style.Thumb.ResourceUrl = new Selector<string>
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",
139 root.Add(utilitySwitch[i]);
140 root.Add(familySwitch[i]);
141 root.Add(foodSwitch[i]);
142 root.Add(kitchenSwitch[i]);
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]);
152 for (int i = 0; i < num; i++)
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]);
161 SwitchStyle utilityAttrs = new SwitchStyle
164 Track = new ImageViewStyle
166 ResourceUrl = new Selector<string>
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",
174 Thumb = new ImageViewStyle
176 Size = new Size(60, 60),
177 ResourceUrl = new Selector<string>
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",
186 SwitchStyle familyAttrs = new SwitchStyle
189 Track = new ImageViewStyle
191 ResourceUrl = new Selector<string>
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",
199 Thumb = new ImageViewStyle
201 Size = new Size(60, 60),
202 ResourceUrl = new Selector<string>
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",
211 SwitchStyle foodAttrs = new SwitchStyle
214 Track = new ImageViewStyle
216 ResourceUrl = new Selector<string>
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",
224 Thumb = new ImageViewStyle
226 Size = new Size(60, 60),
227 ResourceUrl = new Selector<string>
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",
236 SwitchStyle kitchenAttrs = new SwitchStyle
239 Track = new ImageViewStyle
241 ResourceUrl = new Selector<string>
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",
249 Thumb = new ImageViewStyle
251 Size = new Size(60, 60),
252 ResourceUrl = new Selector<string>
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",
261 for (int i = 0; i < num; i++)
263 utilitySwitch2[i] = new Switch(utilityAttrs);
264 utilitySwitch2[i].Size2D = new Size2D(96, 60);
265 utilitySwitch2[i].Position2D = new Position2D(1100, 300 + i * 100);
267 familySwitch2[i] = new Switch(familyAttrs);
268 familySwitch2[i].Size2D = new Size2D(96, 60);
269 familySwitch2[i].Position2D = new Position2D(1300, 300 + i * 100);
271 foodSwitch2[i] = new Switch(foodAttrs);
272 foodSwitch2[i].Size2D = new Size2D(96, 60);
273 foodSwitch2[i].Position2D = new Position2D(1500, 300 + i * 100);
275 kitchenSwitch2[i] = new Switch(kitchenAttrs);
276 kitchenSwitch2[i].Size2D = new Size2D(96, 60);
277 kitchenSwitch2[i].Position2D = new Position2D(1700, 300 + i * 100);
279 root.Add(utilitySwitch2[i]);
280 root.Add(familySwitch2[i]);
281 root.Add(foodSwitch2[i]);
282 root.Add(kitchenSwitch2[i]);
285 utilitySwitch[2].IsEnabled = false;
286 familySwitch[2].IsEnabled = false;
287 foodSwitch[2].IsEnabled = false;
288 kitchenSwitch[2].IsEnabled = false;
290 utilitySwitch2[2].IsEnabled = false;
291 familySwitch2[2].IsEnabled = false;
292 foodSwitch2[2].IsEnabled = false;
293 kitchenSwitch2[2].IsEnabled = false;
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;
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;
314 public void Deactivate()
319 for (int i = 0; i < num; i++)
321 root.Remove(utilitySwitch[i]);
322 utilitySwitch[i].Dispose();
323 utilitySwitch[i] = null;
325 root.Remove(familySwitch[i]);
326 familySwitch[i].Dispose();
327 familySwitch[i] = null;
329 root.Remove(foodSwitch[i]);
330 foodSwitch[i].Dispose();
331 foodSwitch[i] = null;
333 root.Remove(kitchenSwitch[i]);
334 kitchenSwitch[i].Dispose();
335 kitchenSwitch[i] = null;
337 root.Remove(modeText[i]);
338 modeText[i].Dispose();
341 root.Remove(utilitySwitch2[i]);
342 utilitySwitch2[i].Dispose();
343 utilitySwitch2[i] = null;
345 root.Remove(familySwitch2[i]);
346 familySwitch2[i].Dispose();
347 familySwitch2[i] = null;
349 root.Remove(foodSwitch2[i]);
350 foodSwitch2[i].Dispose();
351 foodSwitch2[i] = null;
353 root.Remove(kitchenSwitch2[i]);
354 kitchenSwitch2[i].Dispose();
355 kitchenSwitch2[i] = null;
357 root.Remove(modeText2[i]);
358 modeText2[i].Dispose();
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;
369 NUIApplication.GetDefaultWindow().Remove(root);