2 * Copyright (c) 2017 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
21 namespace ControlDashboard
\r
23 class Example : NUIApplication
\r
25 // This is simple structure to contain Control name and implement state at once
\r
26 // name : control name
\r
27 // isImplemented : the state which the control is implemented in public or not
\r
31 public bool isImplemented;
\r
33 public Item(String name, bool isImplemented)
\r
36 this.isImplemented = isImplemented;
\r
40 private TableView _contentContainer;
\r
41 private Timer _timer;
\r
42 private Stage _stage;
\r
43 private Popup _popup;
\r
44 private ProgressBar _progressBar;
\r
45 private const string _resPath = "/home/owner/apps_rw/NUISample2.Tizen/res";
\r
48 private Item[] mViewList = {
\r
49 new Item("PushButton", true), new Item("DropDown", false), new Item("Toggle", true),
\r
50 new Item("InputField", false), new Item("AnimateGif", false), new Item("Loading", false),
\r
51 new Item("ProgressBar", true), new Item("CheckBox", false), new Item("RadioButton", true),
\r
52 new Item("Tooltip", true), new Item("Popup", true), new Item("Toast", true),
\r
53 new Item("ItemView", false), new Item("CheckBox", true)
\r
56 public Example() : base()
\r
60 public Example(string stylesheet) : base(stylesheet)
\r
64 public Example(string stylesheet, NUIApplication.WindowMode windowMode) : base(stylesheet, windowMode)
\r
68 protected override void OnCreate()
\r
74 protected override void OnTerminate()
\r
79 public void Initialize()
\r
81 Console.WriteLine("Customized Application Initialize event handler");
\r
82 _stage = Stage.Instance;
\r
83 _stage.BackgroundColor = Color.White;
\r
84 _stage.Key += _stage_Key;
\r
87 TextLabel topLabel = new TextLabel();
\r
88 topLabel.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
89 topLabel.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
\r
90 topLabel.PivotPoint = PivotPoint.TopCenter;
\r
91 topLabel.PositionUsesPivotPoint = true;
\r
92 topLabel.ParentOrigin = ParentOrigin.TopCenter;
\r
93 topLabel.SetSizeModeFactor(new Vector3(0.0f, 0.1f, 0.0f));
\r
94 topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
\r
95 topLabel.TextColor = Color.White;
\r
96 topLabel.Text = " DALi Views";
\r
97 topLabel.HorizontalAlignment = "BEGIN";
\r
98 topLabel.VerticalAlignment = "CENTER";
\r
99 topLabel.PointSize = 42.0f;
\r
100 _stage.GetDefaultLayer().Add(topLabel);
\r
101 //StyleManager.Get().ApplyStyle(topLabel, _resPath + "/json/control-dashboard-theme.json", "TextFieldFontSize4");
\r
102 topLabel.SetStyleName("TextFieldFontSize4");
\r
104 // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
\r
105 _contentContainer = new TableView(6, 5);
\r
106 _contentContainer.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
107 _contentContainer.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
\r
108 _contentContainer.SetSizeModeFactor(new Vector3(0.0f, 0.9f, 0.0f));
\r
109 _contentContainer.PivotPoint = PivotPoint.BottomCenter;
\r
110 _contentContainer.PositionUsesPivotPoint = true;
\r
111 _contentContainer.ParentOrigin = ParentOrigin.BottomCenter;
\r
112 _contentContainer.SetRelativeHeight(0, 0.07f);
\r
113 _contentContainer.SetRelativeHeight(1, 0.26f);
\r
114 _contentContainer.SetRelativeHeight(2, 0.07f);
\r
115 _contentContainer.SetRelativeHeight(3, 0.26f);
\r
116 _contentContainer.SetRelativeHeight(4, 0.07f);
\r
117 _contentContainer.SetRelativeHeight(5, 0.26f);
\r
118 _contentContainer.Focusable = (true);
\r
119 _stage.GetDefaultLayer().Add(_contentContainer);
\r
123 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
\r
126 private void _stage_Key(object sender, Stage.KeyEventArgs e)
\r
128 if (e.Key.KeyPressedName == "XF86Back")
\r
134 // Callback for KeyboardFocusManager
\r
135 private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
\r
137 if (!e.ProposedView && !e.CurrentView)
\r
139 e.ProposedView = View.DownCast(_contentContainer.GetChildAt(1));
\r
141 return e.ProposedView;
\r
144 private void CreateContent()
\r
146 for (int i = 0; i < mViewList.Length; i++)
\r
148 CreateItem(mViewList[i], i);
\r
152 private void CreateItem(Item item, int idx)
\r
154 // Make label for item
\r
155 TextLabel itemLabel = new TextLabel(" " + item.name);
\r
156 itemLabel.Size = new Vector3(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.05f, 0.0f);
\r
157 itemLabel.HorizontalAlignment = "BEGIN";
\r
158 itemLabel.VerticalAlignment = "BOTTOM";
\r
159 //itemLabel.PointSize = 18.0f;
\r
160 _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
\r
162 // If item is implemented in public, attach it on stage
\r
163 if (item.isImplemented)
\r
165 if (item.name.CompareTo("PushButton") == 0)
\r
167 PushButton pushButton = new PushButton();
\r
168 pushButton.LabelText = "Push Button";
\r
169 pushButton.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
170 pushButton.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
171 pushButton.UnselectedColor = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
\r
172 pushButton.SelectedColor = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
\r
173 pushButton.Clicked += (obj, e) =>
\r
175 Button sender = obj as Button;
\r
176 sender.LabelText = "Click Me";
\r
177 sender.UnselectedColor = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
\r
181 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
183 if (item.name.CompareTo("DropDown") == 0)
\r
187 if (item.name.CompareTo("Toggle") == 0)
\r
189 ToggleButton toggleButton = new ToggleButton();
\r
190 PropertyArray array = new PropertyArray();
\r
191 array.Add(new PropertyValue(_resPath + "/images/star-highlight.png"));
\r
192 array.Add(new PropertyValue(_resPath + "/images/star-mod.png"));
\r
193 array.Add(new PropertyValue(_resPath + "/images/star-dim.png"));
\r
194 toggleButton.StateVisuals = array;
\r
196 PropertyArray tooltips = new PropertyArray();
\r
197 tooltips.Add(new PropertyValue("State A"));
\r
198 tooltips.Add(new PropertyValue("State B"));
\r
199 tooltips.Add(new PropertyValue("State C"));
\r
200 toggleButton.Tooltips = tooltips;
\r
202 toggleButton.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
203 toggleButton.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
204 toggleButton.Clicked += (obj, e) =>
\r
206 Console.WriteLine("Toggle button state changed.");
\r
210 _contentContainer.AddChild(toggleButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
212 if (item.name.CompareTo("InputField") == 0)
\r
216 if (item.name.CompareTo("AnimateGif") == 0)
\r
220 if (item.name.CompareTo("Loading") == 0)
\r
224 if (item.name.CompareTo("ProgressBar") == 0)
\r
226 _progressBar = new ProgressBar();
\r
227 _progressBar.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
228 _progressBar.HeightResizePolicy = ResizePolicyType.Fixed;
\r
229 _progressBar.Size2D = new Size2D(0, 100);
\r
231 _progressBar.ValueChanged += OnProgressBarValueChanged;
\r
233 _timer = new Timer(100);
\r
234 _timer.Tick += (obj, e) =>
\r
236 float progress = (float)Math.Round(_progressBar.ProgressValue, 2);
\r
238 if (progress == 1.0f)
\r
240 _progressBar.ProgressValue = 0.0f;
\r
241 _progressBar.SecondaryProgressValue = 0.01f;
\r
245 _progressBar.ProgressValue = progress + 0.01f;
\r
246 _progressBar.SecondaryProgressValue = progress + 0.21f;
\r
252 _contentContainer.AddChild(_progressBar, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
254 if (item.name.CompareTo("ScrollBar") == 0)
\r
258 if (item.name.CompareTo("CheckBox") == 0)
\r
260 CheckBoxButton checkBoxButton = new CheckBoxButton();
\r
261 checkBoxButton.LabelText = "Yes";
\r
263 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
265 if (item.name.CompareTo("RadioButton") == 0)
\r
267 TableView tableView = new TableView(2, 1);
\r
268 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
269 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
271 RadioButton rButton = new RadioButton();
\r
272 rButton.LabelText = "Yes";
\r
273 rButton.Selected = true;
\r
274 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
\r
276 rButton = new RadioButton();
\r
277 rButton.LabelText = "No";
\r
279 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
\r
281 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
283 if (item.name.CompareTo("Tooltip") == 0)
\r
285 TableView tableView = new TableView(2, 1);
\r
286 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
287 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
289 // Create two push buttons and add them to a table view
\r
290 PushButton buttonWithSimpleTooltip = new PushButton();
\r
291 buttonWithSimpleTooltip.LabelText = "Tooltip with text only";
\r
292 buttonWithSimpleTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
\r
293 buttonWithSimpleTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
\r
294 buttonWithSimpleTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
295 tableView.AddChild(buttonWithSimpleTooltip, new TableView.CellPosition(0, 0));
\r
297 PushButton buttonWithIconTooltip = new PushButton();
\r
298 buttonWithIconTooltip.LabelText = "Tooltip with Text and Icon";
\r
299 buttonWithIconTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
300 buttonWithIconTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
\r
301 buttonWithIconTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
\r
302 tableView.AddChild(buttonWithIconTooltip, new TableView.CellPosition(1, 0));
\r
304 // Add a simple text only tooltip to the first push button
\r
305 buttonWithSimpleTooltip.TooltipText = "Simple Tooltip";
\r
307 // Create a property map for a tooltip with one icon and one text
\r
308 PropertyArray iconTooltipContent = new PropertyArray();
\r
310 PropertyMap iconVisual = new PropertyMap();
\r
311 iconVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Image))
\r
312 .Add(Tizen.NUI.Constants.ImageVisualProperty.URL, new PropertyValue(_resPath + "/images/star-highlight.png"));
\r
313 iconTooltipContent.Add(new PropertyValue(iconVisual));
\r
315 PropertyMap textVisual = new PropertyMap();
\r
316 textVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Text))
\r
317 .Add(Tizen.NUI.Constants.TextVisualProperty.Text, new PropertyValue("Tooltip with Icon"));
\r
318 iconTooltipContent.Add(new PropertyValue(textVisual));
\r
320 PropertyMap iconTooltip = new PropertyMap();
\r
321 iconTooltip.Add(Tizen.NUI.Constants.Tooltip.Property.Content, new PropertyValue(iconTooltipContent))
\r
322 .Add(Tizen.NUI.Constants.Tooltip.Property.Tail, new PropertyValue(true));
\r
324 // Add the tooltip with icon and text to the second push button
\r
325 buttonWithIconTooltip.Tooltip = iconTooltip;
\r
327 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
329 if (item.name.CompareTo("Popup") == 0)
\r
331 PushButton button = new PushButton();
\r
332 button.LabelText = "Popup";
\r
333 button.ParentOrigin = ParentOrigin.Center;
\r
334 button.PivotPoint = PivotPoint.Center;
\r
335 button.PositionUsesPivotPoint = true;
\r
336 button.MaximumSize = new Size2D(150, 100);
\r
337 _popup = CreatePopup();
\r
338 _popup.SetTitle(CreateTitle("Popup"));
\r
340 TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
\r
341 text.BackgroundColor = Color.White;
\r
342 text.MultiLine = true;
\r
343 text.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
344 text.HeightResizePolicy = ResizePolicyType.DimensionDependency;
\r
345 text.SetPadding(new PaddingType(10.0f, 10.0f, 20.0f, 0.0f));
\r
346 _popup.SetContent(text);
\r
347 _popup.Focusable = (true);
\r
348 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
350 button.Clicked += (obj, ee) =>
\r
352 _stage.GetDefaultLayer().Add(_popup);
\r
353 _popup.SetDisplayState(Popup.DisplayStateType.Shown);
\r
354 FocusManager.Instance.SetCurrentFocusView(View.DownCast((_popup.FindChildByName("Footer")).FindChildByName("OKButton")));
\r
357 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
359 if (item.name.CompareTo("Toast") == 0)
\r
361 PushButton button = new PushButton();
\r
362 button.LabelText = "Toast";
\r
363 button.ParentOrigin = ParentOrigin.Center;
\r
364 button.PivotPoint = PivotPoint.Center;
\r
365 button.PositionUsesPivotPoint = true;
\r
366 button.Clicked += (obj, ee) =>
\r
368 TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo("PopupToast"));
\r
371 BaseHandle baseHandle = typeInfo.CreateInstance();
\r
374 Popup toast = Popup.DownCast(baseHandle);
\r
375 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
\r
376 text.TextColor = Color.White;
\r
377 text.MultiLine = true;
\r
378 text.HorizontalAlignment = "center";
\r
379 toast.SetTitle(text);
\r
380 _stage.GetDefaultLayer().Add(toast);
\r
381 toast.SetDisplayState(Popup.DisplayStateType.Shown);
\r
386 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
388 if (item.name.CompareTo("ItemView") == 0)
\r
395 ImageView notSupportView = new ImageView(_resPath + "/images/not_yet_sign.png");
\r
396 notSupportView.Size = new Vector3(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.25f, 0.0f);
\r
397 notSupportView.Focusable = (true);
\r
398 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
401 Popup CreatePopup()
\r
403 Popup confirmationPopup = new Popup();
\r
405 Actor footer = new Actor();
\r
406 footer.Name = ("Footer");
\r
407 footer.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
408 footer.HeightResizePolicy = ResizePolicyType.Fixed;
\r
409 footer.Size = new Size(0.0f, 80.0f, 0.0f);
\r
410 footer.ParentOrigin = ParentOrigin.Center;
\r
411 footer.PivotPoint = PivotPoint.Center;
\r
412 footer.PositionUsesPivotPoint = true;
\r
414 PushButton okButton = CreateOKButton();
\r
415 okButton.ParentOrigin = ParentOrigin.Center;
\r
416 okButton.PivotPoint = PivotPoint.Center;
\r
417 okButton.PositionUsesPivotPoint = true;
\r
418 okButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
419 okButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
420 okButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
\r
422 PushButton cancelButton = CreateCancelButton();
\r
423 cancelButton.ParentOrigin = ParentOrigin.Center;
\r
424 cancelButton.PivotPoint = PivotPoint.Center;
\r
425 cancelButton.PositionUsesPivotPoint = true;
\r
426 cancelButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
427 cancelButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
428 cancelButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
\r
430 TableView controlLayout = new TableView(1, 2);
\r
431 controlLayout.ParentOrigin = ParentOrigin.Center;
\r
432 controlLayout.PivotPoint = PivotPoint.Center;
\r
433 controlLayout.PositionUsesPivotPoint = true;
\r
434 controlLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
435 controlLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
436 controlLayout.SetCellPadding(new Size2D(10, 10));
\r
437 controlLayout.SetRelativeWidth(0, 0.5f);
\r
438 controlLayout.SetRelativeWidth(1, 0.5f);
\r
439 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
\r
440 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
\r
441 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
\r
442 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
\r
444 footer.Add(controlLayout);
\r
446 confirmationPopup.SetFooter(footer);
\r
447 return confirmationPopup;
\r
449 Actor CreateTitle(string title)
\r
451 TextLabel titleActor = new TextLabel(title);
\r
452 titleActor.TextColor = Color.White;
\r
453 titleActor.MultiLine = true;
\r
454 titleActor.HorizontalAlignment = "center";
\r
458 PushButton CreateOKButton()
\r
460 PushButton okayButton = new PushButton();
\r
461 okayButton.Name = ("OKButton");
\r
462 okayButton.LabelText = "OK";
\r
463 okayButton.Focusable = (true);
\r
464 okayButton.Clicked += (obj, ee) =>
\r
466 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
471 PushButton CreateCancelButton()
\r
473 PushButton cancelButton = new PushButton();
\r
474 cancelButton.LabelText = "Cancel";
\r
475 cancelButton.Focusable = (true);
\r
476 cancelButton.Clicked += (obj, ee) =>
\r
478 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
481 return cancelButton;
\r
484 void OnProgressBarValueChanged(object source, ProgressBar.ValueChangedEventArgs e)
\r
486 PropertyMap labelVisual = new PropertyMap();
\r
487 labelVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Text))
\r
488 .Add(Tizen.NUI.Constants.TextVisualProperty.Text, new PropertyValue(Math.Round(e.ProgressBar.ProgressValue, 2) + " / " + Math.Round(e.ProgressBar.SecondaryProgressValue, 2)))
\r
489 .Add(Tizen.NUI.Constants.TextVisualProperty.PointSize, new PropertyValue(10.0f));
\r
490 e.ProgressBar.LabelVisual = labelVisual;
\r
496 /// The main entry point for the application.
\r
500 static void Main(string[] args)
\r
502 Tizen.Log.Debug("NUI", "control-dashboard app Main()");
\r
504 Example example = new Example("/home/owner/apps_rw/NUISample2.Tizen/res/json/control-dashboard-theme.json");
\r