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
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];
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];
24 private static string[] mode = new string[]
32 public void Activate()
34 Window window = NUIApplication.GetDefaultWindow();
38 Size = new Size(1920, 1080),
39 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
41 root.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical };
49 private void CreateTextView()
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]);
57 for (int i = 0; i < 2; i++)
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]);
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);
72 // Text of "Create Switch just by Style"
73 createText[1].Text = "Create Switch just by Style";
76 private void CreateModeView()
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]);
85 for (int i = 0; i < 4; i++)
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]);
93 modeText[0].Margin = new Extents(100, 0, 0, 0);
95 for (int j = 0; j < 4; j++)
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]);
105 private void CreateSwitchView()
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]);
113 // Create switch styles
114 SwitchStyle utilitySt = new SwitchStyle
116 Size = new Size(96, 60),
118 Track = new ImageViewStyle
120 ResourceUrl = new Selector<string>
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",
127 Border = new Rectangle(30, 30, 30, 30),
129 Thumb = new ImageViewStyle
131 Size = new Size(60, 60),
132 ResourceUrl = new Selector<string>
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",
141 SwitchStyle familySt = new SwitchStyle
144 Track = new ImageViewStyle
146 ResourceUrl = new Selector<string>
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",
153 Border = new Rectangle(30, 30, 30, 30),
155 Thumb = new ImageViewStyle
157 Size = new Size(60, 60),
158 ResourceUrl = new Selector<string>
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",
167 SwitchStyle foodSt = new SwitchStyle
170 Track = new ImageViewStyle
172 ResourceUrl = new Selector<string>
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",
179 Border = new Rectangle(30, 30, 30, 30),
181 Thumb = new ImageViewStyle
183 Size = new Size(60, 60),
184 ResourceUrl = new Selector<string>
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",
193 SwitchStyle kitchenSt = new SwitchStyle
196 Track = new ImageViewStyle
198 ResourceUrl = new Selector<string>
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",
205 Border = new Rectangle(30, 30, 30, 30),
207 Thumb = new ImageViewStyle
209 Size = new Size(60, 60),
210 ResourceUrl = new Selector<string>
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",
220 ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
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].IsTapGestureFeedback = true;
229 parentView[2].Add(utilitySwitch[i]);
231 for (i = 0; i < 4; i++)
233 familySwitch[i] = new Switch();
234 familySwitch[i].ApplyStyle(familySt);
235 familySwitch[i].Size = new Size(96, 60);
236 familySwitch[i].IsTapGestureFeedback = true;
237 parentView[2].Add(familySwitch[i]);
239 for (i = 0; i < 4; i++)
241 foodSwitch[i] = new Switch();
242 foodSwitch[i].ApplyStyle(foodSt);
243 foodSwitch[i].Size = new Size(96, 60);
244 foodSwitch[i].IsTapGestureFeedback = true;
245 parentView[2].Add(foodSwitch[i]);
247 for (i = 0; i < 4; i++)
249 kitchenSwitch[i] = new Switch();
250 kitchenSwitch[i].ApplyStyle(kitchenSt);
251 kitchenSwitch[i].Size = new Size(96, 60);
252 kitchenSwitch[i].IsTapGestureFeedback = true;
253 parentView[2].Add(kitchenSwitch[i]);
256 ///////////////////////////////////////////////Create by Style//////////////////////////////////////////////////////////
257 for (i = 0; i < 4; i++)
259 utilitySwitch2[i] = new Switch();
260 utilitySwitch2[i].ApplyStyle(utilitySt);
261 utilitySwitch2[i].Size = new Size(96, 60);
262 utilitySwitch2[i].IsTapGestureFeedback = true;
263 parentView[2].Add(utilitySwitch2[i]);
265 for (i = 0; i < 4; i++)
267 familySwitch2[i] = new Switch();
268 familySwitch2[i].ApplyStyle(familySt);
269 familySwitch2[i].Size = new Size(96, 60);
270 familySwitch2[i].IsTapGestureFeedback = true;
271 parentView[2].Add(familySwitch2[i]);
273 for (i = 0; i < 4; i++)
275 foodSwitch2[i] = new Switch();
276 foodSwitch2[i].ApplyStyle(foodSt);
277 foodSwitch2[i].Size = new Size(96, 60);
278 foodSwitch2[i].IsTapGestureFeedback = true;
279 parentView[2].Add(foodSwitch2[i]);
281 for (i = 0; i < 4; i++)
283 kitchenSwitch2[i] = new Switch();
284 kitchenSwitch2[i].ApplyStyle(kitchenSt);
285 kitchenSwitch2[i].Size = new Size(96, 60);
286 kitchenSwitch2[i].IsTapGestureFeedback = true;
287 parentView[2].Add(kitchenSwitch2[i]);
290 utilitySwitch[2].IsEnabled = false;
291 familySwitch[2].IsEnabled = false;
292 foodSwitch[2].IsEnabled = false;
293 kitchenSwitch[2].IsEnabled = false;
295 utilitySwitch2[2].IsEnabled = false;
296 familySwitch2[2].IsEnabled = false;
297 foodSwitch2[2].IsEnabled = false;
298 kitchenSwitch2[2].IsEnabled = false;
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;
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;
319 public void Deactivate()
324 for (int i = 0; i < num; i++)
326 utilitySwitch[i].Dispose();
327 utilitySwitch[i] = null;
329 familySwitch[i].Dispose();
330 familySwitch[i] = null;
332 foodSwitch[i].Dispose();
333 foodSwitch[i] = null;
335 kitchenSwitch[i].Dispose();
336 kitchenSwitch[i] = null;
338 modeText[i].Dispose();
341 utilitySwitch2[i].Dispose();
342 utilitySwitch2[i] = null;
344 familySwitch2[i].Dispose();
345 familySwitch2[i] = null;
347 foodSwitch2[i].Dispose();
348 foodSwitch2[i] = null;
350 kitchenSwitch2[i].Dispose();
351 kitchenSwitch2[i] = null;
353 modeText2[i].Dispose();
357 createText[0].Dispose();
358 createText[0] = null;
359 createText[1].Dispose();
360 createText[1] = null;
362 for (int j = 0; j < 3; j++)
364 if (parentView[j] != null)
366 parentView[j].Dispose();
367 parentView[j] = null;
370 NUIApplication.GetDefaultWindow().Remove(root);