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;
22 namespace ControlDashboard
24 class Example : NUIApplication
26 // This is simple structure to contain Control name and implement state at once
27 // name : control name
28 // isImplemented : the state which the control is implemented in public or not
32 public bool isImplemented;
34 public Item(String name, bool isImplemented)
37 this.isImplemented = isImplemented;
41 private TableView _contentContainer;
45 private ProgressBar _progressBar;
46 private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
49 private Item[] mViewList = {
50 new Item("PushButton", true), new Item("DropDown", false), new Item("Toggle", true),
51 new Item("InputField", false), new Item("AnimateGif", false), new Item("Loading", false),
52 new Item("ProgressBar", true), new Item("CheckBox", false), new Item("RadioButton", true),
53 new Item("Tooltip", true), new Item("Popup", true), new Item("Toast", true),
54 new Item("ItemView", false), new Item("CheckBox", true)
57 public Example() : base()
61 public Example(string stylesheet) : base(stylesheet)
65 public Example(string stylesheet, NUIApplication.WindowMode windowMode) : base(stylesheet, windowMode)
69 protected override void OnCreate()
75 public void Initialize()
77 Console.WriteLine("Customized Application Initialize event handler");
78 _stage = Stage.Instance;
79 _stage.BackgroundColor = Color.White;
82 TextLabel topLabel = new TextLabel();
83 topLabel.WidthResizePolicy = ResizePolicyType.FillToParent;
84 topLabel.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
85 topLabel.AnchorPoint = AnchorPoint.TopCenter;
86 topLabel.ParentOrigin = ParentOrigin.TopCenter;
87 topLabel.SetSizeModeFactor(new Vector3(0.0f, 0.1f, 0.0f));
88 topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
89 topLabel.TextColor = Color.White;
90 topLabel.Text = " DALi Views";
91 topLabel.HorizontalAlignment = "BEGIN";
92 topLabel.VerticalAlignment = "CENTER";
93 topLabel.PointSize = 42.0f;
94 _stage.GetDefaultLayer().Add(topLabel);
95 //StyleManager.Get().ApplyStyle(topLabel, _resPath + "/json/control-dashboard-theme.json", "TextFieldFontSize4");
96 topLabel.SetStyleName("TextFieldFontSize4");
98 // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
99 _contentContainer = new TableView(6, 5);
100 _contentContainer.WidthResizePolicy = ResizePolicyType.FillToParent;
101 _contentContainer.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
102 _contentContainer.SetSizeModeFactor(new Vector3(0.0f, 0.9f, 0.0f));
103 _contentContainer.AnchorPoint = AnchorPoint.BottomCenter;
104 _contentContainer.ParentOrigin = ParentOrigin.BottomCenter;
105 _contentContainer.SetRelativeHeight(0, 0.07f);
106 _contentContainer.SetRelativeHeight(1, 0.26f);
107 _contentContainer.SetRelativeHeight(2, 0.07f);
108 _contentContainer.SetRelativeHeight(3, 0.26f);
109 _contentContainer.SetRelativeHeight(4, 0.07f);
110 _contentContainer.SetRelativeHeight(5, 0.26f);
111 _contentContainer.Focusable = (true);
112 _stage.GetDefaultLayer().Add(_contentContainer);
116 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
119 // Callback for KeyboardFocusManager
120 private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
122 if (!e.ProposedView && !e.CurrentView)
124 e.ProposedView = View.DownCast(_contentContainer.GetChildAt(1));
126 return e.ProposedView;
129 private void CreateContent()
131 for (int i = 0; i < mViewList.Length; i++)
133 CreateItem(mViewList[i], i);
137 private void CreateItem(Item item, int idx)
139 // Make label for item
140 TextLabel itemLabel = new TextLabel(" " + item.name);
141 itemLabel.Size = new Vector3(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.05f, 0.0f);
142 itemLabel.HorizontalAlignment = "BEGIN";
143 itemLabel.VerticalAlignment = "BOTTOM";
144 //itemLabel.PointSize = 18.0f;
145 _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
147 // If item is implemented in public, attach it on stage
148 if (item.isImplemented)
150 if (item.name.CompareTo("PushButton") == 0)
152 PushButton pushButton = new PushButton();
153 pushButton.LabelText = "Push Button";
154 pushButton.WidthResizePolicy = ResizePolicyType.FillToParent;
155 pushButton.HeightResizePolicy = ResizePolicyType.FillToParent;
156 pushButton.UnselectedColor = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
157 pushButton.SelectedColor = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
158 pushButton.Clicked += (obj, e) =>
160 Button sender = obj as Button;
161 sender.LabelText = "Click Me";
162 sender.UnselectedColor = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
166 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
168 if (item.name.CompareTo("DropDown") == 0)
172 if (item.name.CompareTo("Toggle") == 0)
174 ToggleButton toggleButton = new ToggleButton();
175 PropertyArray array = new PropertyArray();
176 array.Add(new PropertyValue(_resPath + "/images/star-highlight.png"));
177 array.Add(new PropertyValue(_resPath + "/images/star-mod.png"));
178 array.Add(new PropertyValue(_resPath + "/images/star-dim.png"));
179 toggleButton.StateVisuals = array;
181 PropertyArray tooltips = new PropertyArray();
182 tooltips.Add(new PropertyValue("State A"));
183 tooltips.Add(new PropertyValue("State B"));
184 tooltips.Add(new PropertyValue("State C"));
185 toggleButton.Tooltips = tooltips;
187 toggleButton.WidthResizePolicy = ResizePolicyType.FillToParent;
188 toggleButton.HeightResizePolicy = ResizePolicyType.FillToParent;
189 toggleButton.Clicked += (obj, e) =>
191 Console.WriteLine("Toggle button state changed.");
195 _contentContainer.AddChild(toggleButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
197 if (item.name.CompareTo("InputField") == 0)
201 if (item.name.CompareTo("AnimateGif") == 0)
205 if (item.name.CompareTo("Loading") == 0)
209 if (item.name.CompareTo("ProgressBar") == 0)
211 _progressBar = new ProgressBar();
212 _progressBar.WidthResizePolicy = ResizePolicyType.FillToParent;
213 _progressBar.HeightResizePolicy = ResizePolicyType.Fixed;
214 _progressBar.Size2D = new Size2D(0, 100);
216 _progressBar.ValueChanged += OnProgressBarValueChanged;
218 _timer = new Timer(100);
219 _timer.Tick += (obj, e) =>
221 float progress = (float)Math.Round(_progressBar.ProgressValue, 2);
223 if (progress == 1.0f)
225 _progressBar.ProgressValue = 0.0f;
226 _progressBar.SecondaryProgressValue = 0.01f;
230 _progressBar.ProgressValue = progress + 0.01f;
231 _progressBar.SecondaryProgressValue = progress + 0.21f;
237 _contentContainer.AddChild(_progressBar, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
239 if (item.name.CompareTo("ScrollBar") == 0)
243 if (item.name.CompareTo("CheckBox") == 0)
245 CheckBoxButton checkBoxButton = new CheckBoxButton();
246 checkBoxButton.LabelText = "Yes";
248 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
250 if (item.name.CompareTo("RadioButton") == 0)
252 TableView tableView = new TableView(2, 1);
253 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
254 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
256 RadioButton rButton = new RadioButton();
257 rButton.LabelText = "Yes";
258 rButton.Selected = true;
259 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
261 rButton = new RadioButton();
262 rButton.LabelText = "No";
264 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
266 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
268 if (item.name.CompareTo("Tooltip") == 0)
270 TableView tableView = new TableView(2, 1);
271 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
272 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
274 // Create two push buttons and add them to a table view
275 PushButton buttonWithSimpleTooltip = new PushButton();
276 buttonWithSimpleTooltip.LabelText = "Tooltip with text only";
277 buttonWithSimpleTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
278 buttonWithSimpleTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
279 buttonWithSimpleTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
280 tableView.AddChild(buttonWithSimpleTooltip, new TableView.CellPosition(0, 0));
282 PushButton buttonWithIconTooltip = new PushButton();
283 buttonWithIconTooltip.LabelText = "Tooltip with Text and Icon";
284 buttonWithIconTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
285 buttonWithIconTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
286 buttonWithIconTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
287 tableView.AddChild(buttonWithIconTooltip, new TableView.CellPosition(1, 0));
289 // Add a simple text only tooltip to the first push button
290 buttonWithSimpleTooltip.TooltipText = "Simple Tooltip";
292 // Create a property map for a tooltip with one icon and one text
293 PropertyArray iconTooltipContent = new PropertyArray();
295 PropertyMap iconVisual = new PropertyMap();
296 iconVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image))
297 .Add(ImageVisualProperty.URL, new PropertyValue(_resPath + "/images/star-highlight.png"));
298 iconTooltipContent.Add(new PropertyValue(iconVisual));
300 PropertyMap textVisual = new PropertyMap();
301 textVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text))
302 .Add(TextVisualProperty.Text, new PropertyValue("Tooltip with Icon"));
303 iconTooltipContent.Add(new PropertyValue(textVisual));
305 PropertyMap iconTooltip = new PropertyMap();
306 iconTooltip.Add(Tizen.NUI.Constants.Tooltip.Property.Content, new PropertyValue(iconTooltipContent))
307 .Add(Tizen.NUI.Constants.Tooltip.Property.Tail, new PropertyValue(true));
309 // Add the tooltip with icon and text to the second push button
310 buttonWithIconTooltip.Tooltip = iconTooltip;
312 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
314 if (item.name.CompareTo("Popup") == 0)
316 PushButton button = new PushButton();
317 button.LabelText = "Popup";
318 button.ParentOrigin = ParentOrigin.Center;
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.ParentOrigin = ParentOrigin.Center;
348 button.AnchorPoint = AnchorPoint.Center;
349 button.Clicked += (obj, ee) =>
351 TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo("PopupToast"));
354 BaseHandle baseHandle = typeInfo.CreateInstance();
357 Popup toast = Popup.DownCast(baseHandle);
358 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
359 text.TextColor = Color.White;
360 text.MultiLine = true;
361 text.HorizontalAlignment = "center";
362 toast.SetTitle(text);
363 _stage.GetDefaultLayer().Add(toast);
364 toast.SetDisplayState(Popup.DisplayStateType.Shown);
369 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
371 if (item.name.CompareTo("ItemView") == 0)
378 ImageView notSupportView = new ImageView(_resPath + "/images/not_yet_sign.png");
379 notSupportView.Size = new Vector3(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.25f, 0.0f);
380 notSupportView.Focusable = (true);
381 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
386 Popup confirmationPopup = new Popup();
388 Actor footer = new Actor();
389 footer.Name = ("Footer");
390 footer.WidthResizePolicy = ResizePolicyType.FillToParent;
391 footer.HeightResizePolicy = ResizePolicyType.Fixed;
392 footer.Size = new Size(0.0f, 80.0f, 0.0f);
393 footer.ParentOrigin = ParentOrigin.Center;
394 footer.AnchorPoint = AnchorPoint.Center;
396 PushButton okButton = CreateOKButton();
397 okButton.ParentOrigin = ParentOrigin.Center;
398 okButton.AnchorPoint = AnchorPoint.Center;
399 okButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
400 okButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
401 okButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
403 PushButton cancelButton = CreateCancelButton();
404 cancelButton.ParentOrigin = ParentOrigin.Center;
405 cancelButton.AnchorPoint = AnchorPoint.Center;
406 cancelButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
407 cancelButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
408 cancelButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
410 TableView controlLayout = new TableView(1, 2);
411 controlLayout.ParentOrigin = ParentOrigin.Center;
412 controlLayout.AnchorPoint = AnchorPoint.Center;
413 controlLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
414 controlLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
415 controlLayout.SetCellPadding(new Size2D(10, 10));
416 controlLayout.SetRelativeWidth(0, 0.5f);
417 controlLayout.SetRelativeWidth(1, 0.5f);
418 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
419 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
420 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
421 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
423 footer.Add(controlLayout);
425 confirmationPopup.SetFooter(footer);
426 return confirmationPopup;
428 Actor CreateTitle(string title)
430 TextLabel titleActor = new TextLabel(title);
431 titleActor.TextColor = Color.White;
432 titleActor.MultiLine = true;
433 titleActor.HorizontalAlignment = "center";
437 PushButton CreateOKButton()
439 PushButton okayButton = new PushButton();
440 okayButton.Name = ("OKButton");
441 okayButton.LabelText = "OK";
442 okayButton.Focusable = (true);
443 okayButton.Clicked += (obj, ee) =>
445 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
450 PushButton CreateCancelButton()
452 PushButton cancelButton = new PushButton();
453 cancelButton.LabelText = "Cancel";
454 cancelButton.Focusable = (true);
455 cancelButton.Clicked += (obj, ee) =>
457 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
463 void OnProgressBarValueChanged(object source, ProgressBar.ValueChangedEventArgs e)
465 PropertyMap labelVisual = new PropertyMap();
466 labelVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text))
467 .Add(TextVisualProperty.Text, new PropertyValue(Math.Round(e.ProgressBar.ProgressValue, 2) + " / " + Math.Round(e.ProgressBar.SecondaryProgressValue, 2)))
468 .Add(TextVisualProperty.PointSize, new PropertyValue(10.0f));
469 e.ProgressBar.LabelVisual = labelVisual;
475 /// The main entry point for the application.
479 static void _Main(string[] args)
481 Console.WriteLine("Hello Mono World");
483 Example example = new Example("/home/owner/apps_rw/NUISamples.TizenTV/res/json/control-dashboard-theme.json");