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.UIComponents;
22 using Tizen.NUI.Constants;
24 namespace ControlDashboard
26 class Example : NUIApplication
28 // This is simple structure to contain Control name and implement state at once
29 // name : control name
30 // isImplemented : the state which the control is implemented in public or not
34 public bool isImplemented;
36 public Item(String name, bool isImplemented)
39 this.isImplemented = isImplemented;
43 private TableView _contentContainer;
47 private ProgressBar _progressBar;
48 private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
51 private Item[] mViewList = {
52 new Item("PushButton", true), new Item("DropDown", false), new Item("Toggle", true),
53 new Item("InputField", false), new Item("AnimateGif", false), new Item("Loading", false),
54 new Item("ProgressBar", true), new Item("CheckBox", false), new Item("RadioButton", true),
55 new Item("Tooltip", true), new Item("Popup", true), new Item("Toast", true),
56 new Item("ItemView", false), new Item("CheckBox", true)
59 public Example() : base()
63 public Example(string stylesheet) : base(stylesheet)
67 public Example(string stylesheet, NUIApplication.WindowMode windowMode) : base(stylesheet, windowMode)
71 protected override void OnCreate()
77 public void Initialize()
79 Tizen.Log.Debug("NUI", "Customized Application Initialize event handler");
80 _stage = Stage.Instance;
81 _stage.BackgroundColor = Color.White;
84 TextLabel topLabel = new TextLabel();
85 topLabel.WidthResizePolicy = ResizePolicyType.FillToParent;
86 topLabel.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
87 topLabel.AnchorPoint = AnchorPoint.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 = HorizontalAlignment.Begin;
93 topLabel.VerticalAlignment = 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.Position = new Position(0, _stage.Size.Height * 0.1f, 0);
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 = HorizontalAlignment.Begin;
144 itemLabel.VerticalAlignment = 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 Tizen.Log.Debug("NUI", "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(Tizen.NUI.Constants.Tooltip.Property.Content, new PropertyValue(iconTooltipContent))
308 .Add(Tizen.NUI.Constants.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.AnchorPoint = AnchorPoint.Center;
320 button.MaximumSize = new Size2D(150, 100);
321 _popup = CreatePopup();
322 _popup.SetTitle(CreateTitle("Popup"));
324 TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
325 text.BackgroundColor = Color.White;
326 text.MultiLine = true;
327 text.WidthResizePolicy = ResizePolicyType.FillToParent;
328 text.HeightResizePolicy = ResizePolicyType.DimensionDependency;
329 text.SetPadding(new PaddingType(10.0f, 10.0f, 20.0f, 0.0f));
330 _popup.SetContent(text);
331 _popup.Focusable = (true);
332 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
334 button.Clicked += (obj, ee) =>
336 _stage.GetDefaultLayer().Add(_popup);
337 _popup.SetDisplayState(Popup.DisplayStateType.Shown);
338 FocusManager.Instance.SetCurrentFocusView(View.DownCast((_popup.FindChildByName("Footer")).FindChildByName("OKButton")));
341 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
343 if (item.name.CompareTo("Toast") == 0)
345 PushButton button = new PushButton();
346 button.LabelText = "Toast";
347 button.AnchorPoint = AnchorPoint.Center;
348 button.Clicked += (obj, ee) =>
350 TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo("PopupToast"));
353 BaseHandle baseHandle = typeInfo.CreateInstance();
356 Popup toast = Popup.DownCast(baseHandle);
357 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
358 text.TextColor = Color.White;
359 text.MultiLine = true;
360 text.HorizontalAlignment = HorizontalAlignment.Center;
361 toast.SetTitle(text);
362 _stage.GetDefaultLayer().Add(toast);
363 toast.SetDisplayState(Popup.DisplayStateType.Shown);
368 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
370 if (item.name.CompareTo("ItemView") == 0)
377 ImageView notSupportView = new ImageView(_resPath + "/images/not_yet_sign.png");
378 notSupportView.Size = new Vector3(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.25f, 0.0f);
379 notSupportView.Focusable = (true);
380 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
385 Popup confirmationPopup = new Popup();
387 Actor footer = new Actor();
388 footer.Name = ("Footer");
389 footer.WidthResizePolicy = ResizePolicyType.FillToParent;
390 footer.HeightResizePolicy = ResizePolicyType.Fixed;
391 footer.Size = new Size(0.0f, 80.0f, 0.0f);
392 footer.AnchorPoint = AnchorPoint.Center;
394 PushButton okButton = CreateOKButton();
395 okButton.AnchorPoint = AnchorPoint.Center;
396 okButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
397 okButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
398 okButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
400 PushButton cancelButton = CreateCancelButton();
401 cancelButton.AnchorPoint = AnchorPoint.Center;
402 cancelButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
403 cancelButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
404 cancelButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
406 TableView controlLayout = new TableView(1, 2);
407 controlLayout.AnchorPoint = AnchorPoint.Center;
408 controlLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
409 controlLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
410 controlLayout.SetCellPadding(new Size2D(10, 10));
411 controlLayout.SetRelativeWidth(0, 0.5f);
412 controlLayout.SetRelativeWidth(1, 0.5f);
413 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
414 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
415 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
416 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
418 footer.Add(controlLayout);
420 confirmationPopup.SetFooter(footer);
421 return confirmationPopup;
423 Actor CreateTitle(string title)
425 TextLabel titleActor = new TextLabel(title);
426 titleActor.TextColor = Color.White;
427 titleActor.MultiLine = true;
428 titleActor.HorizontalAlignment = HorizontalAlignment.Center;
432 PushButton CreateOKButton()
434 PushButton okayButton = new PushButton();
435 okayButton.Name = ("OKButton");
436 okayButton.LabelText = "OK";
437 okayButton.Focusable = (true);
438 okayButton.Clicked += (obj, ee) =>
440 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
445 PushButton CreateCancelButton()
447 PushButton cancelButton = new PushButton();
448 cancelButton.LabelText = "Cancel";
449 cancelButton.Focusable = (true);
450 cancelButton.Clicked += (obj, ee) =>
452 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
458 void OnProgressBarValueChanged(object source, ProgressBar.ValueChangedEventArgs e)
460 PropertyMap labelVisual = new PropertyMap();
461 labelVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text))
462 .Add(TextVisualProperty.Text, new PropertyValue(Math.Round(e.ProgressBar.ProgressValue, 2) + " / " + Math.Round(e.ProgressBar.SecondaryProgressValue, 2)))
463 .Add(TextVisualProperty.PointSize, new PropertyValue(10.0f));
464 e.ProgressBar.LabelVisual = labelVisual;
470 /// The main entry point for the application.
474 static void _Main(string[] args)
476 Tizen.Log.Debug("NUI", "Hello Mono World");
478 Example example = new Example("/home/owner/apps_rw/NUISamples.TizenTV/res/json/control-dashboard-theme.json");