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.AnchorPoint = AnchorPoint.TopCenter;
\r
91 topLabel.ParentOrigin = ParentOrigin.TopCenter;
\r
92 topLabel.SetSizeModeFactor(new Vector3(0.0f, 0.1f, 0.0f));
\r
93 topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
\r
94 topLabel.TextColor = Color.White;
\r
95 topLabel.Text = " DALi Views";
\r
96 topLabel.HorizontalAlignment = "BEGIN";
\r
97 topLabel.VerticalAlignment = "CENTER";
\r
98 topLabel.PointSize = 42.0f;
\r
99 _stage.GetDefaultLayer().Add(topLabel);
\r
100 //StyleManager.Get().ApplyStyle(topLabel, _resPath + "/json/control-dashboard-theme.json", "TextFieldFontSize4");
\r
101 topLabel.SetStyleName("TextFieldFontSize4");
\r
103 // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
\r
104 _contentContainer = new TableView(6, 5);
\r
105 _contentContainer.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
106 _contentContainer.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
\r
107 _contentContainer.SetSizeModeFactor(new Vector3(0.0f, 0.9f, 0.0f));
\r
108 _contentContainer.AnchorPoint = AnchorPoint.BottomCenter;
\r
109 _contentContainer.ParentOrigin = ParentOrigin.BottomCenter;
\r
110 _contentContainer.SetRelativeHeight(0, 0.07f);
\r
111 _contentContainer.SetRelativeHeight(1, 0.26f);
\r
112 _contentContainer.SetRelativeHeight(2, 0.07f);
\r
113 _contentContainer.SetRelativeHeight(3, 0.26f);
\r
114 _contentContainer.SetRelativeHeight(4, 0.07f);
\r
115 _contentContainer.SetRelativeHeight(5, 0.26f);
\r
116 _contentContainer.Focusable = (true);
\r
117 _stage.GetDefaultLayer().Add(_contentContainer);
\r
121 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
\r
124 private void _stage_Key(object sender, Stage.KeyEventArgs e)
\r
126 if (e.Key.KeyPressedName == "XF86Back")
\r
132 // Callback for KeyboardFocusManager
\r
133 private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
\r
135 if (!e.ProposedView && !e.CurrentView)
\r
137 e.ProposedView = View.DownCast(_contentContainer.GetChildAt(1));
\r
139 return e.ProposedView;
\r
142 private void CreateContent()
\r
144 for (int i = 0; i < mViewList.Length; i++)
\r
146 CreateItem(mViewList[i], i);
\r
150 private void CreateItem(Item item, int idx)
\r
152 // Make label for item
\r
153 TextLabel itemLabel = new TextLabel(" " + item.name);
\r
154 itemLabel.Size = new Vector3(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.05f, 0.0f);
\r
155 itemLabel.HorizontalAlignment = "BEGIN";
\r
156 itemLabel.VerticalAlignment = "BOTTOM";
\r
157 //itemLabel.PointSize = 18.0f;
\r
158 _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
\r
160 // If item is implemented in public, attach it on stage
\r
161 if (item.isImplemented)
\r
163 if (item.name.CompareTo("PushButton") == 0)
\r
165 PushButton pushButton = new PushButton();
\r
166 pushButton.LabelText = "Push Button";
\r
167 pushButton.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
168 pushButton.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
169 pushButton.UnselectedColor = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
\r
170 pushButton.SelectedColor = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
\r
171 pushButton.Clicked += (obj, e) =>
\r
173 Button sender = obj as Button;
\r
174 sender.LabelText = "Click Me";
\r
175 sender.UnselectedColor = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
\r
179 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
181 if (item.name.CompareTo("DropDown") == 0)
\r
185 if (item.name.CompareTo("Toggle") == 0)
\r
187 ToggleButton toggleButton = new ToggleButton();
\r
188 PropertyArray array = new PropertyArray();
\r
189 array.Add(new PropertyValue(_resPath + "/images/star-highlight.png"));
\r
190 array.Add(new PropertyValue(_resPath + "/images/star-mod.png"));
\r
191 array.Add(new PropertyValue(_resPath + "/images/star-dim.png"));
\r
192 toggleButton.StateVisuals = array;
\r
194 PropertyArray tooltips = new PropertyArray();
\r
195 tooltips.Add(new PropertyValue("State A"));
\r
196 tooltips.Add(new PropertyValue("State B"));
\r
197 tooltips.Add(new PropertyValue("State C"));
\r
198 toggleButton.Tooltips = tooltips;
\r
200 toggleButton.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
201 toggleButton.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
202 toggleButton.Clicked += (obj, e) =>
\r
204 Console.WriteLine("Toggle button state changed.");
\r
208 _contentContainer.AddChild(toggleButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
210 if (item.name.CompareTo("InputField") == 0)
\r
214 if (item.name.CompareTo("AnimateGif") == 0)
\r
218 if (item.name.CompareTo("Loading") == 0)
\r
222 if (item.name.CompareTo("ProgressBar") == 0)
\r
224 _progressBar = new ProgressBar();
\r
225 _progressBar.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
226 _progressBar.HeightResizePolicy = ResizePolicyType.Fixed;
\r
227 _progressBar.Size2D = new Size2D(0, 100);
\r
229 _progressBar.ValueChanged += OnProgressBarValueChanged;
\r
231 _timer = new Timer(100);
\r
232 _timer.Tick += (obj, e) =>
\r
234 float progress = (float)Math.Round(_progressBar.ProgressValue, 2);
\r
236 if (progress == 1.0f)
\r
238 _progressBar.ProgressValue = 0.0f;
\r
239 _progressBar.SecondaryProgressValue = 0.01f;
\r
243 _progressBar.ProgressValue = progress + 0.01f;
\r
244 _progressBar.SecondaryProgressValue = progress + 0.21f;
\r
250 _contentContainer.AddChild(_progressBar, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
252 if (item.name.CompareTo("ScrollBar") == 0)
\r
256 if (item.name.CompareTo("CheckBox") == 0)
\r
258 CheckBoxButton checkBoxButton = new CheckBoxButton();
\r
259 checkBoxButton.LabelText = "Yes";
\r
261 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
263 if (item.name.CompareTo("RadioButton") == 0)
\r
265 TableView tableView = new TableView(2, 1);
\r
266 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
267 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
269 RadioButton rButton = new RadioButton();
\r
270 rButton.LabelText = "Yes";
\r
271 rButton.Selected = true;
\r
272 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
\r
274 rButton = new RadioButton();
\r
275 rButton.LabelText = "No";
\r
277 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
\r
279 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
281 if (item.name.CompareTo("Tooltip") == 0)
\r
283 TableView tableView = new TableView(2, 1);
\r
284 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
285 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
287 // Create two push buttons and add them to a table view
\r
288 PushButton buttonWithSimpleTooltip = new PushButton();
\r
289 buttonWithSimpleTooltip.LabelText = "Tooltip with text only";
\r
290 buttonWithSimpleTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
\r
291 buttonWithSimpleTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
\r
292 buttonWithSimpleTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
293 tableView.AddChild(buttonWithSimpleTooltip, new TableView.CellPosition(0, 0));
\r
295 PushButton buttonWithIconTooltip = new PushButton();
\r
296 buttonWithIconTooltip.LabelText = "Tooltip with Text and Icon";
\r
297 buttonWithIconTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
298 buttonWithIconTooltip.UnselectedColor = new Vector4(0.5f, 0.5f, 0.7f, 1.0f);
\r
299 buttonWithIconTooltip.SelectedColor = new Vector4(0.7f, 0.5f, 0.7f, 1.0f);
\r
300 tableView.AddChild(buttonWithIconTooltip, new TableView.CellPosition(1, 0));
\r
302 // Add a simple text only tooltip to the first push button
\r
303 buttonWithSimpleTooltip.TooltipText = "Simple Tooltip";
\r
305 // Create a property map for a tooltip with one icon and one text
\r
306 PropertyArray iconTooltipContent = new PropertyArray();
\r
308 PropertyMap iconVisual = new PropertyMap();
\r
309 iconVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Image))
\r
310 .Add(Tizen.NUI.Constants.ImageVisualProperty.URL, new PropertyValue(_resPath + "/images/star-highlight.png"));
\r
311 iconTooltipContent.Add(new PropertyValue(iconVisual));
\r
313 PropertyMap textVisual = new PropertyMap();
\r
314 textVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Text))
\r
315 .Add(Tizen.NUI.Constants.TextVisualProperty.Text, new PropertyValue("Tooltip with Icon"));
\r
316 iconTooltipContent.Add(new PropertyValue(textVisual));
\r
318 PropertyMap iconTooltip = new PropertyMap();
\r
319 iconTooltip.Add(Tizen.NUI.Constants.Tooltip.Property.Content, new PropertyValue(iconTooltipContent))
\r
320 .Add(Tizen.NUI.Constants.Tooltip.Property.Tail, new PropertyValue(true));
\r
322 // Add the tooltip with icon and text to the second push button
\r
323 buttonWithIconTooltip.Tooltip = iconTooltip;
\r
325 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
327 if (item.name.CompareTo("Popup") == 0)
\r
329 PushButton button = new PushButton();
\r
330 button.LabelText = "Popup";
\r
331 button.ParentOrigin = ParentOrigin.Center;
\r
332 button.AnchorPoint = AnchorPoint.Center;
\r
333 button.MaximumSize = new Size2D(150, 100);
\r
334 _popup = CreatePopup();
\r
335 _popup.SetTitle(CreateTitle("Popup"));
\r
337 TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
\r
338 text.BackgroundColor = Color.White;
\r
339 text.MultiLine = true;
\r
340 text.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
341 text.HeightResizePolicy = ResizePolicyType.DimensionDependency;
\r
342 text.SetPadding(new PaddingType(10.0f, 10.0f, 20.0f, 0.0f));
\r
343 _popup.SetContent(text);
\r
344 _popup.Focusable = (true);
\r
345 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
347 button.Clicked += (obj, ee) =>
\r
349 _stage.GetDefaultLayer().Add(_popup);
\r
350 _popup.SetDisplayState(Popup.DisplayStateType.Shown);
\r
351 FocusManager.Instance.SetCurrentFocusView(View.DownCast((_popup.FindChildByName("Footer")).FindChildByName("OKButton")));
\r
354 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
356 if (item.name.CompareTo("Toast") == 0)
\r
358 PushButton button = new PushButton();
\r
359 button.LabelText = "Toast";
\r
360 button.ParentOrigin = ParentOrigin.Center;
\r
361 button.AnchorPoint = AnchorPoint.Center;
\r
362 button.Clicked += (obj, ee) =>
\r
364 TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo("PopupToast"));
\r
367 BaseHandle baseHandle = typeInfo.CreateInstance();
\r
370 Popup toast = Popup.DownCast(baseHandle);
\r
371 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
\r
372 text.TextColor = Color.White;
\r
373 text.MultiLine = true;
\r
374 text.HorizontalAlignment = "center";
\r
375 toast.SetTitle(text);
\r
376 _stage.GetDefaultLayer().Add(toast);
\r
377 toast.SetDisplayState(Popup.DisplayStateType.Shown);
\r
382 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
384 if (item.name.CompareTo("ItemView") == 0)
\r
391 ImageView notSupportView = new ImageView(_resPath + "/images/not_yet_sign.png");
\r
392 notSupportView.Size = new Vector3(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.25f, 0.0f);
\r
393 notSupportView.Focusable = (true);
\r
394 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
397 Popup CreatePopup()
\r
399 Popup confirmationPopup = new Popup();
\r
401 Actor footer = new Actor();
\r
402 footer.Name = ("Footer");
\r
403 footer.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
404 footer.HeightResizePolicy = ResizePolicyType.Fixed;
\r
405 footer.Size = new Size(0.0f, 80.0f, 0.0f);
\r
406 footer.ParentOrigin = ParentOrigin.Center;
\r
407 footer.AnchorPoint = AnchorPoint.Center;
\r
409 PushButton okButton = CreateOKButton();
\r
410 okButton.ParentOrigin = ParentOrigin.Center;
\r
411 okButton.AnchorPoint = AnchorPoint.Center;
\r
412 okButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
413 okButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
414 okButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
\r
416 PushButton cancelButton = CreateCancelButton();
\r
417 cancelButton.ParentOrigin = ParentOrigin.Center;
\r
418 cancelButton.AnchorPoint = AnchorPoint.Center;
\r
419 cancelButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
420 cancelButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
421 cancelButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
\r
423 TableView controlLayout = new TableView(1, 2);
\r
424 controlLayout.ParentOrigin = ParentOrigin.Center;
\r
425 controlLayout.AnchorPoint = AnchorPoint.Center;
\r
426 controlLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
427 controlLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
428 controlLayout.SetCellPadding(new Size2D(10, 10));
\r
429 controlLayout.SetRelativeWidth(0, 0.5f);
\r
430 controlLayout.SetRelativeWidth(1, 0.5f);
\r
431 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
\r
432 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
\r
433 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
\r
434 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
\r
436 footer.Add(controlLayout);
\r
438 confirmationPopup.SetFooter(footer);
\r
439 return confirmationPopup;
\r
441 Actor CreateTitle(string title)
\r
443 TextLabel titleActor = new TextLabel(title);
\r
444 titleActor.TextColor = Color.White;
\r
445 titleActor.MultiLine = true;
\r
446 titleActor.HorizontalAlignment = "center";
\r
450 PushButton CreateOKButton()
\r
452 PushButton okayButton = new PushButton();
\r
453 okayButton.Name = ("OKButton");
\r
454 okayButton.LabelText = "OK";
\r
455 okayButton.Focusable = (true);
\r
456 okayButton.Clicked += (obj, ee) =>
\r
458 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
463 PushButton CreateCancelButton()
\r
465 PushButton cancelButton = new PushButton();
\r
466 cancelButton.LabelText = "Cancel";
\r
467 cancelButton.Focusable = (true);
\r
468 cancelButton.Clicked += (obj, ee) =>
\r
470 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
473 return cancelButton;
\r
476 void OnProgressBarValueChanged(object source, ProgressBar.ValueChangedEventArgs e)
\r
478 PropertyMap labelVisual = new PropertyMap();
\r
479 labelVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Text))
\r
480 .Add(Tizen.NUI.Constants.TextVisualProperty.Text, new PropertyValue(Math.Round(e.ProgressBar.ProgressValue, 2) + " / " + Math.Round(e.ProgressBar.SecondaryProgressValue, 2)))
\r
481 .Add(Tizen.NUI.Constants.TextVisualProperty.PointSize, new PropertyValue(10.0f));
\r
482 e.ProgressBar.LabelVisual = labelVisual;
\r
488 /// The main entry point for the application.
\r
492 static void Main(string[] args)
\r
494 Tizen.Log.Debug("NUI", "control-dashboard app Main()");
\r
496 Example example = new Example("/home/owner/apps_rw/NUISample2.Tizen/res/json/control-dashboard-theme.json");
\r