2 * Copyright (c) 2016 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
19 using System.Runtime.InteropServices;
\r
22 namespace MyCSharpExample
\r
26 // This is simple structure to contain Control name and implement state at once
\r
27 // name : control name
\r
28 // isImplemented : the state which the control is implemented in public or not
\r
32 public bool isImplemented;
\r
34 public Item(String name, bool isImplemented)
\r
37 this.isImplemented = isImplemented;
\r
41 private Application _application;
\r
42 private TableView _contentContainer;
\r
43 private Stage _stage;
\r
44 private Popup _popup;
\r
45 private Timer _timer;
\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", false), 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(Application application)
\r
58 _application = application;
\r
59 _application.Initialized += OnInitialize;
\r
62 public void OnInitialize(object source, NUIApplicationInitEventArgs e)
\r
64 Tizen.Log.Debug("NUI", "Customized Application Initialize event handler");
\r
65 _stage = Stage.Instance;
\r
66 _stage.BackgroundColor = Color.White;
\r
69 TextLabel topLabel = new TextLabel();
\r
70 topLabel.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
71 topLabel.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
\r
72 topLabel.AnchorPoint = AnchorPoint.TopCenter;
\r
73 topLabel.ParentOrigin = ParentOrigin.TopCenter;
\r
74 topLabel.SizeModeFactor = new Vector3(0.0f, 0.1f, 0.0f);
\r
75 topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
\r
76 topLabel.TextColor = Color.Yellow;
\r
77 topLabel.Text = " DALi Views Ver.0216-01";
\r
78 topLabel.HorizontalAlignment = "BEGIN";
\r
79 topLabel.VerticalAlignment = "CENTER";
\r
81 topLabel.FontFamily = "BreezeSans";
\r
82 PropertyMap _map = new PropertyMap();
\r
83 _map.Add("width", new PropertyValue("regular"));
\r
84 _map.Add("weight", new PropertyValue("bold"));
\r
85 _map.Add("slant", new PropertyValue("italic"));
\r
86 topLabel.FontStyle = _map;
\r
87 topLabel.PointSize = 15.0f;
\r
89 _stage.GetDefaultLayer().Add(topLabel);
\r
91 // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
\r
92 _contentContainer = new TableView(6, 5);
\r
93 _contentContainer.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
94 _contentContainer.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
\r
95 _contentContainer.SizeModeFactor = new Vector3(0.0f, 0.9f, 0.0f);
\r
96 _contentContainer.AnchorPoint = AnchorPoint.BottomCenter;
\r
97 _contentContainer.ParentOrigin = ParentOrigin.BottomCenter;
\r
98 _contentContainer.SetRelativeHeight(0, 0.07f);
\r
99 _contentContainer.SetRelativeHeight(1, 0.26f);
\r
100 _contentContainer.SetRelativeHeight(2, 0.07f);
\r
101 _contentContainer.SetRelativeHeight(3, 0.26f);
\r
102 _contentContainer.SetRelativeHeight(4, 0.07f);
\r
103 _contentContainer.SetRelativeHeight(5, 0.26f);
\r
104 _contentContainer.Focusable = true;
\r
105 _stage.GetDefaultLayer().Add(_contentContainer);
\r
109 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
\r
111 _timer = new Timer(500);
\r
112 _timer.Tick += OnTimerTick;
\r
116 View _testView = new View();
\r
117 Tizen.Log.Debug("NUI", "1) test view sizewidth = " + _testView.SizeWidth + " sizeHeight= " + _testView.SizeHeight);
\r
118 _testView.Size = new Size(1.0f, 2.0f, 0.0f);
\r
119 Tizen.Log.Debug("NUI", "2) test view sizewidth = " + _testView.SizeWidth + " sizeHeight= " + _testView.SizeHeight);
\r
120 _testView.WidthResizePolicy = ResizePolicyType.Fixed;
\r
121 _testView.HeightResizePolicy = ResizePolicyType.Fixed;
\r
122 _testView.Size = new Size(1.0f, 2.0f, 0.0f);
\r
123 Tizen.Log.Debug("NUI", "3) test view sizewidth = " + _testView.SizeWidth + " sizeHeight= " + _testView.SizeHeight);
\r
126 Window _win = new Window(new RectInteger(100, 100, 500, 500), "win test", false);
\r
127 Window _win = _application.GetWindow();
\r
129 _win.ShowIndicator(Window.IndicatorVisibleMode.VISIBLE);
\r
130 _win.SetIndicatorBgOpacity(Window.IndicatorBgOpacity.OPAQUE);
\r
131 Any _any = _win.GetNativeHandle();
\r
135 private bool OnTimerTick(object sender, EventArgs e)
\r
137 Tizen.Log.Debug("NUI", "OnTimerTick() is called!");
\r
141 // Callback for KeyboardFocusManager
\r
142 private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
\r
144 if (!e.ProposedView && !e.CurrentView)
\r
146 e.ProposedView = View.DownCast(_contentContainer.GetChildAt(1));
\r
148 return e.ProposedView;
\r
151 private void CreateContent()
\r
153 for (int i = 0; i < mViewList.Length; i++)
\r
155 CreateItem(mViewList[i], i);
\r
159 private void CreateItem(Item item, int idx)
\r
161 // Make label for item
\r
162 TextLabel itemLabel = new TextLabel(" " + item.name);
\r
163 itemLabel.Size = new Size(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.05f, 0.0f);
\r
164 itemLabel.HorizontalAlignment = "BEGIN";
\r
165 itemLabel.VerticalAlignment = "BOTTOM";
\r
166 //itemLabel.PointSize = 10.0f;
\r
167 _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
\r
169 // If item is implemented in public, attach it on stage
\r
170 if (item.isImplemented)
\r
172 if (item.name.CompareTo("PushButton") == 0)
\r
174 PushButton pushButton = new PushButton();
\r
175 pushButton.LabelText = "Push Button";
\r
176 pushButton.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
177 pushButton.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
178 pushButton.UnselectedColor = new Color(1.0f, 0.0f, 0.0f, 1.0f);
\r
179 pushButton.SelectedColor = new Color(0.0f, 1.0f, 0.0f, 1.0f);
\r
180 pushButton.Clicked += (obj, e) =>
\r
182 Button sender = (Button)(obj);
\r
183 sender.LabelText = "Click Me";
\r
184 sender.UnselectedColor = new Color(0.0f, 0.0f, 1.0f, 1.0f);
\r
188 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
190 if (item.name.CompareTo("DropDown") == 0)
\r
194 if (item.name.CompareTo("Toggle") == 0)
\r
196 ToggleButton toggleButton = new ToggleButton();
\r
197 Tizen.NUI.PropertyArray array = new Tizen.NUI.PropertyArray();
\r
198 array.Add(new Tizen.NUI.PropertyValue("/home/owner/apps_rw/NUISamples.TizenTV/res/images/star-highlight.png"));
\r
199 array.Add(new Tizen.NUI.PropertyValue("/home/owner/apps_rw/NUISamples.TizenTV/res/images/star-mod.png"));
\r
200 array.Add(new Tizen.NUI.PropertyValue("/home/owner/apps_rw/NUISamples.TizenTV/res/images/star-dim.png"));
\r
201 toggleButton.StateVisuals = array;
\r
203 Tizen.NUI.PropertyArray tooltips = new Tizen.NUI.PropertyArray();
\r
204 tooltips.Add(new Tizen.NUI.PropertyValue("State A"));
\r
205 tooltips.Add(new Tizen.NUI.PropertyValue("State B"));
\r
206 tooltips.Add(new Tizen.NUI.PropertyValue("State C"));
\r
207 toggleButton.Tooltips = tooltips;
\r
209 toggleButton.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
210 toggleButton.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
211 toggleButton.Clicked += (obj, e) =>
\r
213 Console.WriteLine("Toggle button state changed.");
\r
217 _contentContainer.AddChild(toggleButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
219 if (item.name.CompareTo("InputField") == 0)
\r
223 if (item.name.CompareTo("AnimateGif") == 0)
\r
227 if (item.name.CompareTo("Loading") == 0)
\r
231 if (item.name.CompareTo("ProgressBar") == 0)
\r
235 if (item.name.CompareTo("ScrollBar") == 0)
\r
239 if (item.name.CompareTo("CheckBox") == 0)
\r
241 CheckBoxButton checkBoxButton = new CheckBoxButton();
\r
242 checkBoxButton.LabelText = "Yes";
\r
244 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
246 if (item.name.CompareTo("RadioButton") == 0)
\r
248 TableView tableView = new TableView(2, 1);
\r
249 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
250 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
252 RadioButton rButton = new RadioButton();
\r
253 rButton.LabelText = "Yes";
\r
254 rButton.Selected = true;
\r
255 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
\r
257 rButton = new RadioButton();
\r
258 rButton.LabelText = "No";
\r
260 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
\r
262 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
264 if (item.name.CompareTo("Tooltip") == 0)
\r
266 TableView tableView = new TableView(2, 1);
\r
267 tableView.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
268 tableView.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
270 // Create two push buttons and add them to a table view
\r
271 PushButton buttonWithSimpleTooltip = new PushButton();
\r
272 buttonWithSimpleTooltip.LabelText = "Tooltip with text only";
\r
273 buttonWithSimpleTooltip.UnselectedColor = new Color(0.5f, 0.5f, 0.7f, 1.0f);
\r
274 buttonWithSimpleTooltip.SelectedColor = new Color(0.7f, 0.5f, 0.7f, 1.0f);
\r
275 buttonWithSimpleTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
276 tableView.AddChild(buttonWithSimpleTooltip, new TableView.CellPosition(0, 0));
\r
278 PushButton buttonWithIconTooltip = new PushButton();
\r
279 buttonWithIconTooltip.LabelText = "Tooltip with Text and Icon";
\r
280 buttonWithIconTooltip.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
281 buttonWithIconTooltip.UnselectedColor = new Color(0.5f, 0.5f, 0.7f, 1.0f);
\r
282 buttonWithIconTooltip.SelectedColor = new Color(0.7f, 0.5f, 0.7f, 1.0f);
\r
283 tableView.AddChild(buttonWithIconTooltip, new TableView.CellPosition(1, 0));
\r
285 // Add a simple text only tooltip to the first push button
\r
286 buttonWithSimpleTooltip.TooltipText = "Simple Tooltip";
\r
288 // Create a property map for a tooltip with one icon and one text
\r
289 PropertyArray iconTooltipContent = new PropertyArray();
\r
291 PropertyMap iconVisual = new PropertyMap();
\r
292 iconVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Image))
\r
293 .Add(Tizen.NUI.Constants.ImageVisualProperty.URL, new PropertyValue("/home/owner/apps_rw/NUISamples.TizenTV/res/images/star-highlight.png"));
\r
294 iconTooltipContent.Add(new PropertyValue(iconVisual));
\r
296 PropertyMap textVisual = new PropertyMap();
\r
297 textVisual.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Text))
\r
298 .Add(Tizen.NUI.Constants.TextVisualProperty.Text, new PropertyValue("Tooltip with Icon"));
\r
299 iconTooltipContent.Add(new PropertyValue(textVisual));
\r
301 PropertyMap iconTooltip = new PropertyMap();
\r
302 iconTooltip.Add(Tizen.NUI.Constants.Tooltip.Property.Content, new PropertyValue(iconTooltipContent))
\r
303 .Add(Tizen.NUI.Constants.Tooltip.Property.Tail, new PropertyValue(true));
\r
305 // Add the tooltip with icon and text to the second push button
\r
306 buttonWithIconTooltip.Tooltip = iconTooltip;
\r
308 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
310 if (item.name.CompareTo("Popup") == 0)
\r
312 PushButton button = new PushButton();
\r
313 button.LabelText = "Popup";
\r
314 button.ParentOrigin = ParentOrigin.Center;
\r
315 button.AnchorPoint = AnchorPoint.Center;
\r
316 //button.MaximumSize = new Vector2(90.0f,50.0f);
\r
317 _popup = CreatePopup();
\r
318 _popup.SetTitle(CreateTitle("Popup"));
\r
320 TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
\r
321 text.MixColor = Color.White;
\r
322 text.MultiLine = true;
\r
323 text.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
324 text.HeightResizePolicy = ResizePolicyType.DimensionDependency;
\r
325 text.Padding = new Vector4(10.0f, 10.0f, 20.0f, 0.0f);
\r
326 _popup.SetContent(text);
\r
327 _popup.Focusable = true;
\r
328 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
330 button.Clicked += (obj, ee) =>
\r
332 _stage.GetDefaultLayer().Add(_popup);
\r
333 _popup.SetDisplayState(Popup.DisplayStateType.Shown);
\r
334 FocusManager.Instance.SetCurrentFocusView(View.DownCast((_popup.FindChildByName("Footer")).FindChildByName("OKButton")));
\r
337 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
339 if (item.name.CompareTo("Toast") == 0)
\r
341 PushButton button = new PushButton();
\r
342 button.LabelText = "Toast";
\r
343 button.ParentOrigin = ParentOrigin.Center;
\r
344 button.AnchorPoint = AnchorPoint.Center;
\r
345 button.Clicked += (obj, ee) =>
\r
347 TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo("PopupToast"));
\r
350 BaseHandle baseHandle = typeInfo.CreateInstance();
\r
353 Popup toast = Popup.DownCast(baseHandle);
\r
354 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
\r
355 text.TextColor = Color.White;
\r
356 text.MultiLine = true;
\r
357 text.HorizontalAlignment = "center";
\r
358 toast.SetTitle(text);
\r
359 _stage.GetDefaultLayer().Add(toast);
\r
360 toast.SetDisplayState(Popup.DisplayStateType.Shown);
\r
365 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
367 if (item.name.CompareTo("ItemView") == 0)
\r
374 ImageView notSupportView = new ImageView("/home/owner/apps_rw/NUISamples.TizenTV/res/images/not_yet_sign.png");
\r
375 notSupportView.Size = new Size(_stage.Size.Width * 0.2f, _stage.Size.Height * 0.25f, 0.0f);
\r
376 notSupportView.Focusable = true;
\r
377 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
\r
380 Popup CreatePopup()
\r
382 Popup confirmationPopup = new Popup();
\r
384 Actor footer = new Actor();
\r
385 footer.Name = "Footer";
\r
386 footer.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
387 footer.HeightResizePolicy = ResizePolicyType.Fixed;
\r
388 footer.Size = new Size(0.0f, 80.0f, 0.0f);
\r
389 footer.ParentOrigin = ParentOrigin.Center;
\r
390 footer.AnchorPoint = AnchorPoint.Center;
\r
392 PushButton okButton = CreateOKButton();
\r
393 okButton.ParentOrigin = ParentOrigin.Center;
\r
394 okButton.AnchorPoint = AnchorPoint.Center;
\r
395 okButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
396 okButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
397 okButton.SizeModeFactor = new Vector3(-20.0f, -20.0f, 0.0f);
\r
399 PushButton cancelButton = CreateCancelButton();
\r
400 cancelButton.ParentOrigin = ParentOrigin.Center;
\r
401 cancelButton.AnchorPoint = AnchorPoint.Center;
\r
402 cancelButton.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
403 cancelButton.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
\r
404 cancelButton.SizeModeFactor = new Vector3(-20.0f, -20.0f, 0.0f);
\r
406 TableView controlLayout = new TableView(1, 2);
\r
407 controlLayout.ParentOrigin = ParentOrigin.Center;
\r
408 controlLayout.AnchorPoint = AnchorPoint.Center;
\r
409 controlLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
\r
410 controlLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
\r
411 controlLayout.SetCellPadding(new Size2D(10.0f, 10.0f));
\r
412 controlLayout.SetRelativeWidth(0, 0.5f);
\r
413 controlLayout.SetRelativeWidth(1, 0.5f);
\r
414 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
\r
415 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.Center, VerticalAlignmentType.Center);
\r
416 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
\r
417 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
\r
419 footer.Add(controlLayout);
\r
421 confirmationPopup.SetFooter(footer);
\r
422 return confirmationPopup;
\r
424 Actor CreateTitle(string title)
\r
426 TextLabel titleActor = new TextLabel(title);
\r
427 titleActor.TextColor = Color.White;
\r
428 titleActor.MultiLine = true;
\r
429 titleActor.HorizontalAlignment = "center";
\r
433 PushButton CreateOKButton()
\r
435 PushButton okayButton = new PushButton();
\r
436 okayButton.Name = "OKButton";
\r
437 okayButton.LabelText = "OK";
\r
438 okayButton.Focusable = true;
\r
439 okayButton.Clicked += (obj, ee) =>
\r
441 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
446 PushButton CreateCancelButton()
\r
448 PushButton cancelButton = new PushButton();
\r
449 cancelButton.LabelText = "Cancel";
\r
450 cancelButton.Focusable = true;
\r
451 cancelButton.Clicked += (obj, ee) =>
\r
453 _popup.SetDisplayState(Popup.DisplayStateType.Hidden);
\r
456 return cancelButton;
\r
459 public void MainLoop()
\r
461 _application.MainLoop();
\r
465 /// The main entry point for the application.
\r
469 static void Main(string[] args)
\r
471 Tizen.Log.Debug("NUI", "dali c# control-dashboard! main() is called!");
\r
473 Example example = new Example(Application.NewApplication("/home/owner/apps_rw/NUISamples.TizenTV/res/json/control-dashboard-theme.json"));
\r
474 example.MainLoop();
\r