2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
19 using System.Runtime.InteropServices;
\r
22 namespace MyCSharpExample
\r
26 // This is simple structure to contain Control name and implement state at once
\r
27 // name : control name
\r
28 // isImplemented : the state which the control is implemented in public or not
\r
32 public bool isImplemented;
\r
34 public Item(String name, bool isImplemented)
\r
37 this.isImplemented = isImplemented;
\r
41 private Application _application;
\r
42 private TableView _contentContainer;
\r
43 private Stage _stage;
\r
44 private Popup _popup;
\r
47 private Item[] mViewList = {
\r
48 new Item("PushButton", true), new Item("DropDown", false), new Item("Toggle", true),
\r
49 new Item("InputField", false), new Item("AnimateGif", false), new Item("Loading", false),
\r
50 new Item("ProgressBar", false), new Item("CheckBox", false), new Item("RadioButton", true),
\r
51 new Item("Tooltip", true), new Item("Popup", true), new Item("Toast", true),
\r
52 new Item("ItemView", false), new Item("CheckBox", true)
\r
55 public Example(Application application)
\r
57 _application = application;
\r
58 _application.Initialized += OnInitialize;
\r
61 public void OnInitialize(object source, NUIApplicationInitEventArgs e)
\r
63 Tizen.Log.Debug("NUI", "Customized Application Initialize event handler");
\r
64 _stage = Stage.Instance;
\r
65 _stage.BackgroundColor = Color.White;
\r
68 TextLabel topLabel = new TextLabel();
\r
69 topLabel.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
70 topLabel.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
\r
71 topLabel.AnchorPoint = AnchorPoint.TopCenter;
\r
72 topLabel.ParentOrigin = ParentOrigin.TopCenter;
\r
73 topLabel.SizeModeFactor = new Vector3(0.0f, 0.1f, 0.0f);
\r
74 topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
\r
75 topLabel.TextColor = Color.Yellow;
\r
76 topLabel.Text = " DALi Views Ver.0216-01";
\r
77 topLabel.HorizontalAlignment = "BEGIN";
\r
78 topLabel.VerticalAlignment = "CENTER";
\r
80 topLabel.FontFamily = "BreezeSans";
\r
81 PropertyMap _map = new PropertyMap();
\r
82 _map.Add("width", new PropertyValue("regular"));
\r
83 _map.Add("weight", new PropertyValue("bold"));
\r
84 _map.Add("slant", new PropertyValue("italic"));
\r
85 topLabel.FontStyle = _map;
\r
86 topLabel.PointSize = 15.0f;
\r
88 _stage.GetDefaultLayer().Add(topLabel);
\r
90 // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
\r
91 _contentContainer = new TableView(6, 5);
\r
92 _contentContainer.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
93 _contentContainer.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
\r
94 _contentContainer.SizeModeFactor = new Vector3(0.0f, 0.9f, 0.0f);
\r
95 _contentContainer.AnchorPoint = AnchorPoint.BottomCenter;
\r
96 _contentContainer.ParentOrigin = ParentOrigin.BottomCenter;
\r
97 _contentContainer.SetRelativeHeight(0, 0.07f);
\r
98 _contentContainer.SetRelativeHeight(1, 0.26f);
\r
99 _contentContainer.SetRelativeHeight(2, 0.07f);
\r
100 _contentContainer.SetRelativeHeight(3, 0.26f);
\r
101 _contentContainer.SetRelativeHeight(4, 0.07f);
\r
102 _contentContainer.SetRelativeHeight(5, 0.26f);
\r
103 _contentContainer.Focusable = true;
\r
104 _stage.GetDefaultLayer().Add(_contentContainer);
\r
108 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
\r
110 View _testView = new View();
\r
111 Tizen.Log.Debug("NUI", "1) test view sizewidth = " + _testView.SizeWidth + " sizeHeight= " + _testView.SizeHeight);
\r
112 _testView.Size = new Size(1.0f, 2.0f, 0.0f);
\r
113 Tizen.Log.Debug("NUI", "2) test view sizewidth = " + _testView.SizeWidth + " sizeHeight= " + _testView.SizeHeight);
\r
114 _testView.WidthResizePolicy = ResizePolicyType.Fixed;
\r
115 _testView.HeightResizePolicy = ResizePolicyType.Fixed;
\r
116 _testView.Size = new Size(1.0f, 2.0f, 0.0f);
\r
117 Tizen.Log.Debug("NUI", "3) test view sizewidth = " + _testView.SizeWidth + " sizeHeight= " + _testView.SizeHeight);
\r
120 Window _win = new Window(new RectInteger(100, 100, 500, 500), "win test", false);
\r
121 Window _win = _application.GetWindow();
\r
123 _win.ShowIndicator(Window.IndicatorVisibleMode.VISIBLE);
\r
124 _win.SetIndicatorBgOpacity(Window.IndicatorBgOpacity.OPAQUE);
\r
125 Any _any = _win.GetNativeHandle();
\r
129 // Callback for KeyboardFocusManager
\r
130 private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
\r
132 if (!e.ProposedView && !e.CurrentView)
\r
134 e.ProposedView = View.DownCast(_contentContainer.GetChildAt(1));
\r
136 return e.ProposedView;
\r
139 private void CreateContent()
\r
141 for (int i = 0; i < mViewList.Length; i++)
\r
143 CreateItem(mViewList[i], i);
\r
147 private void CreateItem(Item item, int idx)
\r
149 // Make label for item
\r
150 TextLabel itemLabel = new TextLabel(" " + item.name);
\r
151 itemLabel.Size = new Size(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.05f, 0.0f);
\r
152 itemLabel.HorizontalAlignment = "BEGIN";
\r
153 itemLabel.VerticalAlignment = "BOTTOM";
\r
154 //itemLabel.PointSize = 10.0f;
\r
155 _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
\r
157 // If item is implemented in public, attach it on stage
\r
158 if (item.isImplemented)
\r
160 if (item.name.CompareTo("PushButton") == 0)
\r
162 PushButton pushButton = new PushButton();
\r
163 pushButton.LabelText = "Push Button";
\r
164 pushButton.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
165 pushButton.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
166 pushButton.UnselectedColor = new Color(1.0f, 0.0f, 0.0f, 1.0f);
\r
167 pushButton.SelectedColor = new Color(0.0f, 1.0f, 0.0f, 1.0f);
\r
168 pushButton.Clicked += (obj, e) =>
\r
170 Button sender = (Button)(obj);
\r
171 sender.LabelText = "Click Me";
\r
172 sender.UnselectedColor = new Color(0.0f, 0.0f, 1.0f, 1.0f);
\r
176 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
178 if (item.name.CompareTo("DropDown") == 0)
\r
182 if (item.name.CompareTo("Toggle") == 0)
\r
184 ToggleButton toggleButton = new ToggleButton();
\r
185 Tizen.NUI.PropertyArray array = new Tizen.NUI.PropertyArray();
\r
186 array.Add(new Tizen.NUI.PropertyValue("/home/owner/apps_rw/NUISamples.TizenTV/res/images/star-highlight.png"));
\r
187 array.Add(new Tizen.NUI.PropertyValue("/home/owner/apps_rw/NUISamples.TizenTV/res/images/star-mod.png"));
\r
188 array.Add(new Tizen.NUI.PropertyValue("/home/owner/apps_rw/NUISamples.TizenTV/res/images/star-dim.png"));
\r
189 toggleButton.StateVisuals = array;
\r
191 Tizen.NUI.PropertyArray tooltips = new Tizen.NUI.PropertyArray();
\r
192 tooltips.Add(new Tizen.NUI.PropertyValue("State A"));
\r
193 tooltips.Add(new Tizen.NUI.PropertyValue("State B"));
\r
194 tooltips.Add(new Tizen.NUI.PropertyValue("State C"));
\r
195 toggleButton.Tooltips = tooltips;
\r
197 toggleButton.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
198 toggleButton.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
199 toggleButton.Clicked += (obj, e) =>
\r
201 Console.WriteLine("Toggle button state changed.");
\r
205 _contentContainer.AddChild(toggleButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
207 if (item.name.CompareTo("InputField") == 0)
\r
211 if (item.name.CompareTo("AnimateGif") == 0)
\r
215 if (item.name.CompareTo("Loading") == 0)
\r
219 if (item.name.CompareTo("ProgressBar") == 0)
\r
223 if (item.name.CompareTo("ScrollBar") == 0)
\r
227 if (item.name.CompareTo("CheckBox") == 0)
\r
229 CheckBoxButton checkBoxButton = new CheckBoxButton();
\r
230 checkBoxButton.LabelText = "Yes";
\r
232 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
234 if (item.name.CompareTo("RadioButton") == 0)
\r
236 TableView tableView = new TableView(2, 1);
\r
237 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
238 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
240 RadioButton rButton = new RadioButton();
\r
241 rButton.LabelText = "Yes";
\r
242 rButton.Selected = true;
\r
243 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
\r
245 rButton = new RadioButton();
\r
246 rButton.LabelText = "No";
\r
248 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
\r
250 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
252 if (item.name.CompareTo("Tooltip") == 0)
\r
254 TableView tableView = new TableView(2, 1);
\r
255 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
256 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
258 // Create two push buttons and add them to a table view
\r
259 PushButton buttonWithSimpleTooltip = new PushButton();
\r
260 buttonWithSimpleTooltip.LabelText = "Tooltip with text only";
\r
261 buttonWithSimpleTooltip.UnselectedColor = new Color(0.5f, 0.5f, 0.7f, 1.0f);
\r
262 buttonWithSimpleTooltip.SelectedColor = new Color(0.7f, 0.5f, 0.7f, 1.0f);
\r
263 buttonWithSimpleTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
264 tableView.AddChild(buttonWithSimpleTooltip, new TableView.CellPosition(0, 0));
\r
266 PushButton buttonWithIconTooltip = new PushButton();
\r
267 buttonWithIconTooltip.LabelText = "Tooltip with Text and Icon";
\r
268 buttonWithIconTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
269 buttonWithIconTooltip.UnselectedColor = new Color(0.5f, 0.5f, 0.7f, 1.0f);
\r
270 buttonWithIconTooltip.SelectedColor = new Color(0.7f, 0.5f, 0.7f, 1.0f);
\r
271 tableView.AddChild(buttonWithIconTooltip, new TableView.CellPosition(1, 0));
\r
273 // Add a simple text only tooltip to the first push button
\r
274 buttonWithSimpleTooltip.TooltipText = "Simple Tooltip";
\r
276 // Create a property map for a tooltip with one icon and one text
\r
277 PropertyArray iconTooltipContent = new PropertyArray();
\r
279 PropertyMap iconVisual = new PropertyMap();
\r
280 iconVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Image))
\r
281 .Add(Tizen.NUI.Constants.ImageVisualProperty.URL, new PropertyValue("/home/owner/apps_rw/NUISamples.TizenTV/res/images/star-highlight.png"));
\r
282 iconTooltipContent.Add(new PropertyValue(iconVisual));
\r
284 PropertyMap textVisual = new PropertyMap();
\r
285 textVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Text))
\r
286 .Add(Tizen.NUI.Constants.TextVisualProperty.Text, new PropertyValue("Tooltip with Icon"));
\r
287 iconTooltipContent.Add(new PropertyValue(textVisual));
\r
289 PropertyMap iconTooltip = new PropertyMap();
\r
290 iconTooltip.Add(Tizen.NUI.Constants.Tooltip.Property.Content, new PropertyValue(iconTooltipContent))
\r
291 .Add(Tizen.NUI.Constants.Tooltip.Property.Tail, new PropertyValue(true));
\r
293 // Add the tooltip with icon and text to the second push button
\r
294 buttonWithIconTooltip.Tooltip = iconTooltip;
\r
296 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
298 if (item.name.CompareTo("Popup") == 0)
\r
300 PushButton button = new PushButton();
\r
301 button.LabelText = "Popup";
\r
302 button.ParentOrigin = ParentOrigin.Center;
\r
303 button.AnchorPoint = AnchorPoint.Center;
\r
304 //button.MaximumSize = new Vector2(90.0f,50.0f);
\r
305 _popup = CreatePopup();
\r
306 _popup.SetTitle(CreateTitle("Popup"));
\r
308 TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
\r
309 text.MixColor = Color.White;
\r
310 text.MultiLine = true;
\r
311 text.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
312 text.HeightResizePolicy = ResizePolicyType.DimensionDependency;
\r
313 text.Padding = new Vector4(10.0f, 10.0f, 20.0f, 0.0f);
\r
314 _popup.SetContent(text);
\r
315 _popup.Focusable = true;
\r
316 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
318 button.Clicked += (obj, ee) =>
\r
320 _stage.GetDefaultLayer().Add(_popup);
\r
321 _popup.SetDisplayState(Popup.DisplayStateType.Shown);
\r
322 FocusManager.Instance.SetCurrentFocusView(View.DownCast((_popup.FindChildByName("Footer")).FindChildByName("OKButton")));
\r
325 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
327 if (item.name.CompareTo("Toast") == 0)
\r
329 PushButton button = new PushButton();
\r
330 button.LabelText = "Toast";
\r
331 button.ParentOrigin = ParentOrigin.Center;
\r
332 button.AnchorPoint = AnchorPoint.Center;
\r
333 button.Clicked += (obj, ee) =>
\r
335 TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo("PopupToast"));
\r
338 BaseHandle baseHandle = typeInfo.CreateInstance();
\r
341 Popup toast = Popup.DownCast(baseHandle);
\r
342 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
\r
343 text.TextColor = Color.White;
\r
344 text.MultiLine = true;
\r
345 text.HorizontalAlignment = "center";
\r
346 toast.SetTitle(text);
\r
347 _stage.GetDefaultLayer().Add(toast);
\r
348 toast.SetDisplayState(Popup.DisplayStateType.Shown);
\r
353 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
355 if (item.name.CompareTo("ItemView") == 0)
\r
362 ImageView notSupportView = new ImageView("/home/owner/apps_rw/NUISamples.TizenTV/res/images/not_yet_sign.png");
\r
363 notSupportView.Size = new Size(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.25f, 0.0f);
\r
364 notSupportView.Focusable = true;
\r
365 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
368 Popup CreatePopup()
\r
370 Popup confirmationPopup = new Popup();
\r
372 Actor footer = new Actor();
\r
373 footer.Name = "Footer";
\r
374 footer.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
375 footer.HeightResizePolicy = ResizePolicyType.Fixed;
\r
376 footer.Size = new Size(0.0f, 80.0f, 0.0f);
\r
377 footer.ParentOrigin = ParentOrigin.Center;
\r
378 footer.AnchorPoint = AnchorPoint.Center;
\r
380 PushButton okButton = CreateOKButton();
\r
381 okButton.ParentOrigin = ParentOrigin.Center;
\r
382 okButton.AnchorPoint = AnchorPoint.Center;
\r
383 okButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
384 okButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
385 okButton.SizeModeFactor = new Vector3(-20.0f, -20.0f, 0.0f);
\r
387 PushButton cancelButton = CreateCancelButton();
\r
388 cancelButton.ParentOrigin = ParentOrigin.Center;
\r
389 cancelButton.AnchorPoint = AnchorPoint.Center;
\r
390 cancelButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
391 cancelButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
392 cancelButton.SizeModeFactor = new Vector3(-20.0f, -20.0f, 0.0f);
\r
394 TableView controlLayout = new TableView(1, 2);
\r
395 controlLayout.ParentOrigin = ParentOrigin.Center;
\r
396 controlLayout.AnchorPoint = AnchorPoint.Center;
\r
397 controlLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
398 controlLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
399 controlLayout.SetCellPadding(new Size2D(10.0f, 10.0f));
\r
400 controlLayout.SetRelativeWidth(0, 0.5f);
\r
401 controlLayout.SetRelativeWidth(1, 0.5f);
\r
402 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
\r
403 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
\r
404 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
\r
405 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
\r
407 footer.Add(controlLayout);
\r
409 confirmationPopup.SetFooter(footer);
\r
410 return confirmationPopup;
\r
412 Actor CreateTitle(string title)
\r
414 TextLabel titleActor = new TextLabel(title);
\r
415 titleActor.TextColor = Color.White;
\r
416 titleActor.MultiLine = true;
\r
417 titleActor.HorizontalAlignment = "center";
\r
421 PushButton CreateOKButton()
\r
423 PushButton okayButton = new PushButton();
\r
424 okayButton.Name = "OKButton";
\r
425 okayButton.LabelText = "OK";
\r
426 okayButton.Focusable = true;
\r
427 okayButton.Clicked += (obj, ee) =>
\r
429 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
434 PushButton CreateCancelButton()
\r
436 PushButton cancelButton = new PushButton();
\r
437 cancelButton.LabelText = "Cancel";
\r
438 cancelButton.Focusable = true;
\r
439 cancelButton.Clicked += (obj, ee) =>
\r
441 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
444 return cancelButton;
\r
447 public void MainLoop()
\r
449 _application.MainLoop();
\r
453 /// The main entry point for the application.
\r
457 static void Main(string[] args)
\r
459 Tizen.Log.Debug("NUI", "dali c# control-dashboard! main() is called!");
\r
461 Example example = new Example(Application.NewApplication("/home/owner/apps_rw/NUISamples.TizenTV/res/json/control-dashboard-theme.json"));
\r
462 example.MainLoop();
\r