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.BaseComponents;
23 using Tizen.NUI.Constants;
25 namespace ControlDashboard
27 class Example : NUIApplication
29 // This is simple structure to contain Control name and implement state at once
30 // name : control name
31 // isImplemented : the state which the control is implemented in public or not
35 public bool isImplemented;
37 public Item(String name, bool isImplemented)
40 this.isImplemented = isImplemented;
44 private TableView _contentContainer;
46 private Window _window;
48 private ProgressBar _progressBar;
49 //private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
50 private const string _resPath = "./res"; //for ubuntu
54 private Item[] mViewList = {
55 new Item("PushButton", true), new Item("DropDown", false), new Item("Toggle", true),
56 new Item("InputField", false), new Item("AnimateGif", false), new Item("Loading", false),
57 new Item("ProgressBar", true), new Item("CheckBox", false), new Item("RadioButton", true),
58 new Item("Tooltip", true), new Item("Popup", true), new Item("Toast", true),
59 new Item("ItemView", false), new Item("CheckBox", true)
62 public Example() : base()
66 public Example(string stylesheet) : base(stylesheet)
70 public Example(string stylesheet, NUIApplication.WindowMode windowMode) : base(stylesheet, windowMode)
74 protected override void OnCreate()
80 public void Initialize()
82 Tizen.Log.Debug("NUI", "Customized Application Initialize event handler");
83 _window = Window.Instance;
84 _window.BackgroundColor = Color.White;
87 TextLabel topLabel = new TextLabel();
88 topLabel.WidthResizePolicy = ResizePolicyType.FillToParent;
89 topLabel.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
90 topLabel.PivotPoint = PivotPoint.TopCenter;
91 topLabel.SetSizeModeFactor(new Vector3(0.0f, 0.1f, 0.0f));
92 topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
93 topLabel.TextColor = Color.White;
94 topLabel.Text = " DALi Views";
95 topLabel.HorizontalAlignment = HorizontalAlignment.Begin;
96 topLabel.VerticalAlignment = VerticalAlignment.Center;
97 topLabel.PointSize = 42.0f;
98 _window.Add(topLabel);
99 //StyleManager.Get().ApplyStyle(topLabel, _resPath + "/json/control-dashboard-theme.json", "TextFieldFontSize4");
100 topLabel.SetStyleName("TextFieldFontSize4");
102 // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
103 _contentContainer = new TableView(6, 5);
104 _contentContainer.WidthResizePolicy = ResizePolicyType.FillToParent;
105 _contentContainer.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
106 _contentContainer.SetSizeModeFactor(new Vector3(0.0f, 0.9f, 0.0f));
107 _contentContainer.PivotPoint = PivotPoint.BottomCenter;
108 _contentContainer.Position = new Position(0, _window.Size.Height * 0.1f, 0);
109 _contentContainer.SetRelativeHeight(0, 0.07f);
110 _contentContainer.SetRelativeHeight(1, 0.26f);
111 _contentContainer.SetRelativeHeight(2, 0.07f);
112 _contentContainer.SetRelativeHeight(3, 0.26f);
113 _contentContainer.SetRelativeHeight(4, 0.07f);
114 _contentContainer.SetRelativeHeight(5, 0.26f);
115 _contentContainer.Focusable = (true);
116 _window.Add(_contentContainer);
120 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
123 // Callback for KeyboardFocusManager
124 private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
126 if (!e.ProposedView && !e.CurrentView)
128 e.ProposedView = _contentContainer.GetChildAt(1);
130 return e.ProposedView;
133 private void CreateContent()
135 for (int i = 0; i < mViewList.Length; i++)
137 CreateItem(mViewList[i], i);
141 private void CreateItem(Item item, int idx)
143 // Make label for item
144 TextLabel itemLabel = new TextLabel(" " + item.name);
145 itemLabel.Size2D = new Size2D((int)(_window.Size.Width * 0.2f), (int)(_window.Size.Height * 0.05f));
146 itemLabel.HorizontalAlignment = HorizontalAlignment.Begin;
147 itemLabel.VerticalAlignment = VerticalAlignment.Bottom;
148 //itemLabel.PointSize = 18.0f;
149 _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
151 // If item is implemented in public, attach it on window
152 if (item.isImplemented)
154 if (item.name.CompareTo("PushButton") == 0)
156 PushButton pushButton = new PushButton();
157 pushButton.LabelText = "Push Button";
158 pushButton.WidthResizePolicy = ResizePolicyType.FillToParent;
159 pushButton.HeightResizePolicy = ResizePolicyType.FillToParent;
160 pushButton.UnselectedColor = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
161 pushButton.SelectedColor = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
162 pushButton.Clicked += (obj, e) =>
164 Button sender = obj as Button;
165 sender.LabelText = "Click Me";
166 sender.UnselectedColor = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
170 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
172 if (item.name.CompareTo("DropDown") == 0)
176 if (item.name.CompareTo("Toggle") == 0)
178 ToggleButton toggleButton = new ToggleButton();
179 PropertyArray array = new PropertyArray();
180 array.Add(new PropertyValue(_resPath + "/images/star-highlight.png"));
181 array.Add(new PropertyValue(_resPath + "/images/star-mod.png"));
182 array.Add(new PropertyValue(_resPath + "/images/star-dim.png"));
183 toggleButton.StateVisuals = array;
185 PropertyArray tooltips = new PropertyArray();
186 tooltips.Add(new PropertyValue("State A"));
187 tooltips.Add(new PropertyValue("State B"));
188 tooltips.Add(new PropertyValue("State C"));
189 toggleButton.Tooltips = tooltips;
191 toggleButton.WidthResizePolicy = ResizePolicyType.FillToParent;
192 toggleButton.HeightResizePolicy = ResizePolicyType.FillToParent;
193 toggleButton.Clicked += (obj, e) =>
195 Tizen.Log.Debug("NUI", "Toggle button state changed.");
199 _contentContainer.AddChild(toggleButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
201 if (item.name.CompareTo("InputField") == 0)
205 if (item.name.CompareTo("AnimateGif") == 0)
209 if (item.name.CompareTo("Loading") == 0)
213 if (item.name.CompareTo("ProgressBar") == 0)
215 _progressBar = new ProgressBar();
216 _progressBar.WidthResizePolicy = ResizePolicyType.FillToParent;
217 _progressBar.HeightResizePolicy = ResizePolicyType.Fixed;
218 _progressBar.Size2D = new Size2D(0, 100);
220 _progressBar.ValueChanged += OnProgressBarValueChanged;
222 _timer = new Timer(100);
223 _timer.Tick += (obj, e) =>
225 float progress = (float)Math.Round(_progressBar.ProgressValue, 2);
227 if (progress == 1.0f)
229 _progressBar.ProgressValue = 0.0f;
230 _progressBar.SecondaryProgressValue = 0.01f;
234 _progressBar.ProgressValue = progress + 0.01f;
235 _progressBar.SecondaryProgressValue = progress + 0.21f;
241 _contentContainer.AddChild(_progressBar, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
243 if (item.name.CompareTo("ScrollBar") == 0)
247 if (item.name.CompareTo("CheckBox") == 0)
249 CheckBoxButton checkBoxButton = new CheckBoxButton();
250 checkBoxButton.LabelText = "Yes";
252 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
254 if (item.name.CompareTo("RadioButton") == 0)
256 TableView tableView = new TableView(2, 1);
257 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
258 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
260 RadioButton rButton = new RadioButton();
261 rButton.LabelText = "Yes";
262 rButton.Selected = true;
263 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
265 rButton = new RadioButton();
266 rButton.LabelText = "No";
268 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
270 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
272 if (item.name.CompareTo("Tooltip") == 0)
274 TableView tableView = new TableView(2, 1);
275 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
276 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
278 // Create two push buttons and add them to a table view
279 PushButton buttonWithSimpleTooltip = new PushButton();
280 buttonWithSimpleTooltip.LabelText = "Tooltip with text only";
281 buttonWithSimpleTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
282 buttonWithSimpleTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
283 buttonWithSimpleTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
284 tableView.AddChild(buttonWithSimpleTooltip, new TableView.CellPosition(0, 0));
286 PushButton buttonWithIconTooltip = new PushButton();
287 buttonWithIconTooltip.LabelText = "Tooltip with Text and Icon";
288 buttonWithIconTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
289 buttonWithIconTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
290 buttonWithIconTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
291 tableView.AddChild(buttonWithIconTooltip, new TableView.CellPosition(1, 0));
293 // Add a simple text only tooltip to the first push button
294 buttonWithSimpleTooltip.TooltipText = "Simple Tooltip";
296 // Create a property map for a tooltip with one icon and one text
297 PropertyArray iconTooltipContent = new PropertyArray();
299 PropertyMap iconVisual = new PropertyMap();
300 iconVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image))
301 .Add(ImageVisualProperty.URL, new PropertyValue(_resPath + "/images/star-highlight.png"));
302 iconTooltipContent.Add(new PropertyValue(iconVisual));
304 PropertyMap textVisual = new PropertyMap();
305 textVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text))
306 .Add(TextVisualProperty.Text, new PropertyValue("Tooltip with Icon"));
307 iconTooltipContent.Add(new PropertyValue(textVisual));
309 PropertyMap iconTooltip = new PropertyMap();
310 iconTooltip.Add(Tizen.NUI.Constants.Tooltip.Property.Content, new PropertyValue(iconTooltipContent))
311 .Add(Tizen.NUI.Constants.Tooltip.Property.Tail, new PropertyValue(true));
313 // Add the tooltip with icon and text to the second push button
314 buttonWithIconTooltip.Tooltip = iconTooltip;
316 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
318 if (item.name.CompareTo("Popup") == 0)
320 PushButton button = new PushButton();
321 button.LabelText = "Popup";
322 button.PivotPoint = PivotPoint.Center;
323 button.MaximumSize = new Size2D(150, 100);
324 _popup = CreatePopup();
325 _popup.SetTitle(CreateTitle("Popup"));
327 TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
328 text.BackgroundColor = Color.White;
329 text.MultiLine = true;
330 text.WidthResizePolicy = ResizePolicyType.FillToParent;
331 text.HeightResizePolicy = ResizePolicyType.DimensionDependency;
332 text.SetPadding(new PaddingType(10.0f, 10.0f, 20.0f, 0.0f));
333 _popup.SetContent(text);
334 _popup.Focusable = (true);
335 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
337 button.Clicked += (obj, ee) =>
340 _popup.SetDisplayState(Popup.DisplayStateType.Shown);
341 FocusManager.Instance.SetCurrentFocusView((_popup.FindChildByName("Footer")).FindChildByName("OKButton"));
344 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
346 if (item.name.CompareTo("Toast") == 0)
348 PushButton button = new PushButton();
349 button.LabelText = "Toast";
350 button.PivotPoint = PivotPoint.Center;
351 button.Clicked += (obj, ee) =>
353 Popup toast = new Popup();
354 toast.SizeModeFactor = new Vector3(0.75f, 0.75f, 0.75f);
355 toast.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
356 toast.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
357 toast.ContextualMode = Popup.ContextualModeType.NonContextual;
358 toast.AnimationDuration = 0.65f;
359 toast.TailVisibility = false;
361 // Disable the dimmed backing.
362 toast.BackingEnabled = false;
364 // The toast popup should fade in (not zoom).
365 toast.AnimationMode = Popup.AnimationModeType.Fade;
367 // The toast popup should auto-hide.
368 toast.AutoHideDelay = 3000;
370 // Align to the bottom of the screen.
371 toast.ParentOrigin = new Position(0.5f, 0.94f, 0.5f);
372 toast.PivotPoint = PivotPoint.BottomCenter;
374 // Let events pass through the toast popup.
375 toast.TouchTransparent = true;
377 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
378 text.TextColor = Color.White;
379 text.MultiLine = true;
380 text.HorizontalAlignment = HorizontalAlignment.Center;
381 toast.SetTitle(text);
383 toast.DisplayState = Popup.DisplayStateType.Shown;
387 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
389 if (item.name.CompareTo("ItemView") == 0)
396 ImageView notSupportView = new ImageView(_resPath + "/images/not_yet_sign.png");
397 notSupportView.Size2D = new Size2D((int)(_window.Size.Width * 0.2f), (int)(_window.Size.Height * 0.25f));
398 notSupportView.Focusable = (true);
399 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
404 Popup confirmationPopup = new Popup();
406 View footer = new View();
407 footer.Name = ("Footer");
408 footer.WidthResizePolicy = ResizePolicyType.FillToParent;
409 footer.HeightResizePolicy = ResizePolicyType.Fixed;
410 footer.Size2D = new Size2D(0, 80);
411 footer.PivotPoint = PivotPoint.Center;
413 PushButton okButton = CreateOKButton();
414 okButton.PivotPoint = PivotPoint.Center;
415 okButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
416 okButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
417 okButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
419 PushButton cancelButton = CreateCancelButton();
420 cancelButton.PivotPoint = PivotPoint.Center;
421 cancelButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
422 cancelButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
423 cancelButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
425 TableView controlLayout = new TableView(1, 2);
426 controlLayout.PivotPoint = PivotPoint.Center;
427 controlLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
428 controlLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
429 controlLayout.SetCellPadding(new Size2D(10, 10));
430 controlLayout.SetRelativeWidth(0, 0.5f);
431 controlLayout.SetRelativeWidth(1, 0.5f);
432 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
433 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
434 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
435 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
437 footer.Add(controlLayout);
439 confirmationPopup.SetFooter(footer);
440 return confirmationPopup;
442 View CreateTitle(string title)
444 TextLabel titleView = new TextLabel(title);
445 titleView.TextColor = Color.White;
446 titleView.MultiLine = true;
447 titleView.HorizontalAlignment = HorizontalAlignment.Center;
451 PushButton CreateOKButton()
453 PushButton okayButton = new PushButton();
454 okayButton.Name = ("OKButton");
455 okayButton.LabelText = "OK";
456 okayButton.Focusable = (true);
457 okayButton.Clicked += (obj, ee) =>
459 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
464 PushButton CreateCancelButton()
466 PushButton cancelButton = new PushButton();
467 cancelButton.LabelText = "Cancel";
468 cancelButton.Focusable = (true);
469 cancelButton.Clicked += (obj, ee) =>
471 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
477 void OnProgressBarValueChanged(object source, ProgressBar.ValueChangedEventArgs e)
479 PropertyMap labelVisual = new PropertyMap();
480 labelVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text))
481 .Add(TextVisualProperty.Text, new PropertyValue(Math.Round(e.ProgressBar.ProgressValue, 2) + " / " + Math.Round(e.ProgressBar.SecondaryProgressValue, 2)))
482 .Add(TextVisualProperty.PointSize, new PropertyValue(10.0f));
483 e.ProgressBar.LabelVisual = labelVisual;
489 /// The main entry point for the application.
493 static void _Main(string[] args)
495 Tizen.Log.Debug("NUI", "Hello Mono World");
497 Example example = new Example("/home/owner/apps_rw/NUISamples.TizenTV/res/json/control-dashboard-theme.json");