2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
21 using Tizen.NUI.Constants;
23 namespace ControlDashboard
25 class Example : NUIApplication
27 // This is simple structure to contain Control name and implement state at once
28 // name : control name
29 // isImplemented : the state which the control is implemented in public or not
33 public bool isImplemented;
35 public Item(String name, bool isImplemented)
38 this.isImplemented = isImplemented;
42 private TableView _contentContainer;
46 private ProgressBar _progressBar;
47 private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
50 private Item[] mViewList = {
51 new Item("PushButton", true), new Item("DropDown", false), new Item("Toggle", true),
52 new Item("InputField", false), new Item("AnimateGif", false), new Item("Loading", false),
53 new Item("ProgressBar", true), new Item("CheckBox", false), new Item("RadioButton", true),
54 new Item("Tooltip", true), new Item("Popup", true), new Item("Toast", true),
55 new Item("ItemView", false), new Item("CheckBox", true)
58 public Example() : base()
62 public Example(string stylesheet) : base(stylesheet)
66 public Example(string stylesheet, NUIApplication.WindowMode windowMode) : base(stylesheet, windowMode)
70 protected override void OnCreate()
76 public void Initialize()
78 Console.WriteLine("Customized Application Initialize event handler");
79 _stage = Stage.Instance;
80 _stage.BackgroundColor = Color.White;
83 TextLabel topLabel = new TextLabel();
84 topLabel.WidthResizePolicy = ResizePolicyType.FillToParent;
85 topLabel.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
86 topLabel.AnchorPoint = AnchorPoint.TopCenter;
87 topLabel.ParentOrigin = ParentOrigin.TopCenter;
88 topLabel.SetSizeModeFactor(new Vector3(0.0f, 0.1f, 0.0f));
89 topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
90 topLabel.TextColor = Color.White;
91 topLabel.Text = " DALi Views";
92 topLabel.HorizontalAlignment = "BEGIN";
93 topLabel.VerticalAlignment = "CENTER";
94 topLabel.PointSize = 42.0f;
95 _stage.GetDefaultLayer().Add(topLabel);
96 //StyleManager.Get().ApplyStyle(topLabel, _resPath + "/json/control-dashboard-theme.json", "TextFieldFontSize4");
97 topLabel.SetStyleName("TextFieldFontSize4");
99 // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
100 _contentContainer = new TableView(6, 5);
101 _contentContainer.WidthResizePolicy = ResizePolicyType.FillToParent;
102 _contentContainer.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
103 _contentContainer.SetSizeModeFactor(new Vector3(0.0f, 0.9f, 0.0f));
104 _contentContainer.AnchorPoint = AnchorPoint.BottomCenter;
105 _contentContainer.ParentOrigin = ParentOrigin.BottomCenter;
106 _contentContainer.SetRelativeHeight(0, 0.07f);
107 _contentContainer.SetRelativeHeight(1, 0.26f);
108 _contentContainer.SetRelativeHeight(2, 0.07f);
109 _contentContainer.SetRelativeHeight(3, 0.26f);
110 _contentContainer.SetRelativeHeight(4, 0.07f);
111 _contentContainer.SetRelativeHeight(5, 0.26f);
112 _contentContainer.Focusable = (true);
113 _stage.GetDefaultLayer().Add(_contentContainer);
117 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
120 // Callback for KeyboardFocusManager
121 private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
123 if (!e.ProposedView && !e.CurrentView)
125 e.ProposedView = View.DownCast(_contentContainer.GetChildAt(1));
127 return e.ProposedView;
130 private void CreateContent()
132 for (int i = 0; i < mViewList.Length; i++)
134 CreateItem(mViewList[i], i);
138 private void CreateItem(Item item, int idx)
140 // Make label for item
141 TextLabel itemLabel = new TextLabel(" " + item.name);
142 itemLabel.Size = new Vector3(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.05f, 0.0f);
143 itemLabel.HorizontalAlignment = "BEGIN";
144 itemLabel.VerticalAlignment = "BOTTOM";
145 //itemLabel.PointSize = 18.0f;
146 _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
148 // If item is implemented in public, attach it on stage
149 if (item.isImplemented)
151 if (item.name.CompareTo("PushButton") == 0)
153 PushButton pushButton = new PushButton();
154 pushButton.LabelText = "Push Button";
155 pushButton.WidthResizePolicy = ResizePolicyType.FillToParent;
156 pushButton.HeightResizePolicy = ResizePolicyType.FillToParent;
157 pushButton.UnselectedColor = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
158 pushButton.SelectedColor = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
159 pushButton.Clicked += (obj, e) =>
161 Button sender = obj as Button;
162 sender.LabelText = "Click Me";
163 sender.UnselectedColor = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
167 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
169 if (item.name.CompareTo("DropDown") == 0)
173 if (item.name.CompareTo("Toggle") == 0)
175 ToggleButton toggleButton = new ToggleButton();
176 PropertyArray array = new PropertyArray();
177 array.Add(new PropertyValue(_resPath + "/images/star-highlight.png"));
178 array.Add(new PropertyValue(_resPath + "/images/star-mod.png"));
179 array.Add(new PropertyValue(_resPath + "/images/star-dim.png"));
180 toggleButton.StateVisuals = array;
182 PropertyArray tooltips = new PropertyArray();
183 tooltips.Add(new PropertyValue("State A"));
184 tooltips.Add(new PropertyValue("State B"));
185 tooltips.Add(new PropertyValue("State C"));
186 toggleButton.Tooltips = tooltips;
188 toggleButton.WidthResizePolicy = ResizePolicyType.FillToParent;
189 toggleButton.HeightResizePolicy = ResizePolicyType.FillToParent;
190 toggleButton.Clicked += (obj, e) =>
192 Console.WriteLine("Toggle button state changed.");
196 _contentContainer.AddChild(toggleButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
198 if (item.name.CompareTo("InputField") == 0)
202 if (item.name.CompareTo("AnimateGif") == 0)
206 if (item.name.CompareTo("Loading") == 0)
210 if (item.name.CompareTo("ProgressBar") == 0)
212 _progressBar = new ProgressBar();
213 _progressBar.WidthResizePolicy = ResizePolicyType.FillToParent;
214 _progressBar.HeightResizePolicy = ResizePolicyType.Fixed;
215 _progressBar.Size2D = new Size2D(0, 100);
217 _progressBar.ValueChanged += OnProgressBarValueChanged;
219 _timer = new Timer(100);
220 _timer.Tick += (obj, e) =>
222 float progress = (float)Math.Round(_progressBar.ProgressValue, 2);
224 if (progress == 1.0f)
226 _progressBar.ProgressValue = 0.0f;
227 _progressBar.SecondaryProgressValue = 0.01f;
231 _progressBar.ProgressValue = progress + 0.01f;
232 _progressBar.SecondaryProgressValue = progress + 0.21f;
238 _contentContainer.AddChild(_progressBar, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
240 if (item.name.CompareTo("ScrollBar") == 0)
244 if (item.name.CompareTo("CheckBox") == 0)
246 CheckBoxButton checkBoxButton = new CheckBoxButton();
247 checkBoxButton.LabelText = "Yes";
249 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
251 if (item.name.CompareTo("RadioButton") == 0)
253 TableView tableView = new TableView(2, 1);
254 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
255 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
257 RadioButton rButton = new RadioButton();
258 rButton.LabelText = "Yes";
259 rButton.Selected = true;
260 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
262 rButton = new RadioButton();
263 rButton.LabelText = "No";
265 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
267 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
269 if (item.name.CompareTo("Tooltip") == 0)
271 TableView tableView = new TableView(2, 1);
272 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
273 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
275 // Create two push buttons and add them to a table view
276 PushButton buttonWithSimpleTooltip = new PushButton();
277 buttonWithSimpleTooltip.LabelText = "Tooltip with text only";
278 buttonWithSimpleTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
279 buttonWithSimpleTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
280 buttonWithSimpleTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
281 tableView.AddChild(buttonWithSimpleTooltip, new TableView.CellPosition(0, 0));
283 PushButton buttonWithIconTooltip = new PushButton();
284 buttonWithIconTooltip.LabelText = "Tooltip with Text and Icon";
285 buttonWithIconTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
286 buttonWithIconTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
287 buttonWithIconTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
288 tableView.AddChild(buttonWithIconTooltip, new TableView.CellPosition(1, 0));
290 // Add a simple text only tooltip to the first push button
291 buttonWithSimpleTooltip.TooltipText = "Simple Tooltip";
293 // Create a property map for a tooltip with one icon and one text
294 PropertyArray iconTooltipContent = new PropertyArray();
296 PropertyMap iconVisual = new PropertyMap();
297 iconVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image))
298 .Add(ImageVisualProperty.URL, new PropertyValue(_resPath + "/images/star-highlight.png"));
299 iconTooltipContent.Add(new PropertyValue(iconVisual));
301 PropertyMap textVisual = new PropertyMap();
302 textVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text))
303 .Add(TextVisualProperty.Text, new PropertyValue("Tooltip with Icon"));
304 iconTooltipContent.Add(new PropertyValue(textVisual));
306 PropertyMap iconTooltip = new PropertyMap();
307 iconTooltip.Add(Tooltip.Property.Content, new PropertyValue(iconTooltipContent))
308 .Add(Tooltip.Property.Tail, new PropertyValue(true));
310 // Add the tooltip with icon and text to the second push button
311 buttonWithIconTooltip.Tooltip = iconTooltip;
313 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
315 if (item.name.CompareTo("Popup") == 0)
317 PushButton button = new PushButton();
318 button.LabelText = "Popup";
319 button.ParentOrigin = ParentOrigin.Center;
320 button.AnchorPoint = AnchorPoint.Center;
321 button.MaximumSize = new Size2D(150, 100);
322 _popup = CreatePopup();
323 _popup.SetTitle(CreateTitle("Popup"));
325 TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
326 text.BackgroundColor = Color.White;
327 text.MultiLine = true;
328 text.WidthResizePolicy = ResizePolicyType.FillToParent;
329 text.HeightResizePolicy = ResizePolicyType.DimensionDependency;
330 text.SetPadding(new PaddingType(10.0f, 10.0f, 20.0f, 0.0f));
331 _popup.SetContent(text);
332 _popup.Focusable = (true);
333 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
335 button.Clicked += (obj, ee) =>
337 _stage.GetDefaultLayer().Add(_popup);
338 _popup.SetDisplayState(Popup.DisplayStateType.Shown);
339 FocusManager.Instance.SetCurrentFocusView(View.DownCast((_popup.FindChildByName("Footer")).FindChildByName("OKButton")));
342 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
344 if (item.name.CompareTo("Toast") == 0)
346 PushButton button = new PushButton();
347 button.LabelText = "Toast";
348 button.ParentOrigin = ParentOrigin.Center;
349 button.AnchorPoint = AnchorPoint.Center;
350 button.Clicked += (obj, ee) =>
352 TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo("PopupToast"));
355 BaseHandle baseHandle = typeInfo.CreateInstance();
358 Popup toast = Popup.DownCast(baseHandle);
359 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
360 text.TextColor = Color.White;
361 text.MultiLine = true;
362 text.HorizontalAlignment = "center";
363 toast.SetTitle(text);
364 _stage.GetDefaultLayer().Add(toast);
365 toast.SetDisplayState(Popup.DisplayStateType.Shown);
370 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
372 if (item.name.CompareTo("ItemView") == 0)
379 ImageView notSupportView = new ImageView(_resPath + "/images/not_yet_sign.png");
380 notSupportView.Size = new Vector3(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.25f, 0.0f);
381 notSupportView.Focusable = (true);
382 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
387 Popup confirmationPopup = new Popup();
389 Actor footer = new Actor();
390 footer.Name = ("Footer");
391 footer.WidthResizePolicy = ResizePolicyType.FillToParent;
392 footer.HeightResizePolicy = ResizePolicyType.Fixed;
393 footer.Size = new Size(0.0f, 80.0f, 0.0f);
394 footer.ParentOrigin = ParentOrigin.Center;
395 footer.AnchorPoint = AnchorPoint.Center;
397 PushButton okButton = CreateOKButton();
398 okButton.ParentOrigin = ParentOrigin.Center;
399 okButton.AnchorPoint = AnchorPoint.Center;
400 okButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
401 okButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
402 okButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
404 PushButton cancelButton = CreateCancelButton();
405 cancelButton.ParentOrigin = ParentOrigin.Center;
406 cancelButton.AnchorPoint = AnchorPoint.Center;
407 cancelButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
408 cancelButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
409 cancelButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
411 TableView controlLayout = new TableView(1, 2);
412 controlLayout.ParentOrigin = ParentOrigin.Center;
413 controlLayout.AnchorPoint = AnchorPoint.Center;
414 controlLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
415 controlLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
416 controlLayout.SetCellPadding(new Size2D(10, 10));
417 controlLayout.SetRelativeWidth(0, 0.5f);
418 controlLayout.SetRelativeWidth(1, 0.5f);
419 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
420 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
421 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
422 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
424 footer.Add(controlLayout);
426 confirmationPopup.SetFooter(footer);
427 return confirmationPopup;
429 Actor CreateTitle(string title)
431 TextLabel titleActor = new TextLabel(title);
432 titleActor.TextColor = Color.White;
433 titleActor.MultiLine = true;
434 titleActor.HorizontalAlignment = "center";
438 PushButton CreateOKButton()
440 PushButton okayButton = new PushButton();
441 okayButton.Name = ("OKButton");
442 okayButton.LabelText = "OK";
443 okayButton.Focusable = (true);
444 okayButton.Clicked += (obj, ee) =>
446 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
451 PushButton CreateCancelButton()
453 PushButton cancelButton = new PushButton();
454 cancelButton.LabelText = "Cancel";
455 cancelButton.Focusable = (true);
456 cancelButton.Clicked += (obj, ee) =>
458 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
464 void OnProgressBarValueChanged(object source, ProgressBar.ValueChangedEventArgs e)
466 PropertyMap labelVisual = new PropertyMap();
467 labelVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text))
468 .Add(TextVisualProperty.Text, new PropertyValue(Math.Round(e.ProgressBar.ProgressValue, 2) + " / " + Math.Round(e.ProgressBar.SecondaryProgressValue, 2)))
469 .Add(TextVisualProperty.PointSize, new PropertyValue(10.0f));
470 e.ProgressBar.LabelVisual = labelVisual;
476 /// The main entry point for the application.
480 static void _Main(string[] args)
482 Console.WriteLine("Hello Mono World");
484 Example example = new Example("/home/owner/apps_rw/NUISamples.TizenTV/res/json/control-dashboard-theme.json");