Dali C#: csharp dll initial upload
[platform/core/csapi/nui.git] / etc / SampleApplication / NUISamples / NUISamples.Tizen / examples / control-dashboard.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using NUI;
21
22 namespace MyCSharpExample
23 {
24     class Example
25     {
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
29         private struct Item
30         {
31             public String name;
32             public bool isImplemented;
33
34             public Item(String name, bool isImplemented)
35             {
36                 this.name = name;
37                 this.isImplemented = isImplemented;
38             }
39         }
40
41         private NUI.Application _application;
42         private TableView _contentContainer;
43         private Stage _stage;
44         private Popup _popup;
45
46         // List of items
47         private Item[] mViewList = {
48             new Item("PushButton", true),  new Item("DropDown", false),    new Item("Toggle", false),
49             new Item("InputField", false),  new Item("AnimateGif", false),  new Item("Loading", false),
50             new Item("ProgressBar", false), new Item("CheckBox", false),    new Item("RadioButton", true),
51             new Item("Tooltip", false),     new Item("Popup", true),       new Item("Toast", true),
52             new Item("ItemView", false),    new Item("CheckBox", true)
53         };
54
55         public Example(NUI.Application application)
56         {
57             _application = application;
58             _application.Initialized += OnInitialize;
59         }
60
61         public void OnInitialize(object source, EventArgs e)
62         {
63             Console.WriteLine("Customized Application Initialize event handler");
64             _stage = Stage.GetCurrent();
65             _stage.BackgroundColor = Color.White;
66
67             // Top label
68             TextLabel topLabel = new TextLabel();
69             topLabel.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
70             topLabel.SetResizePolicy(ResizePolicyType.SIZE_RELATIVE_TO_PARENT, DimensionType.HEIGHT);
71             topLabel.AnchorPoint = NDalic.AnchorPointTopCenter;
72             topLabel.ParentOrigin = NDalic.ParentOriginTopCenter;
73             topLabel.SizeModeFactor = new Vector3( 0.0f, 0.1f, 0.0f );
74             topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
75             topLabel.TextColor = NDalic.WHITE;
76             topLabel.Text = " DALi Views";
77             topLabel.HorizontalAlignment = "BEGIN";
78             topLabel.VerticalAlignment = "CENTER";
79             topLabel.SetStyleName("TextLabelFontSize4");
80             _stage.Add(topLabel);
81
82             // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
83             _contentContainer = new TableView(6, 5);
84             _contentContainer.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
85             _contentContainer.SetResizePolicy(ResizePolicyType.SIZE_RELATIVE_TO_PARENT, DimensionType.HEIGHT);
86             _contentContainer.SizeModeFactor = new Vector3( 0.0f, 0.9f, 0.0f );
87             _contentContainer.AnchorPoint = NDalic.AnchorPointBottomCenter;
88             _contentContainer.ParentOrigin = NDalic.ParentOriginBottomCenter;
89             _contentContainer.SetRelativeHeight(0, 0.07f);
90             _contentContainer.SetRelativeHeight(1, 0.26f);
91             _contentContainer.SetRelativeHeight(2, 0.07f);
92             _contentContainer.SetRelativeHeight(3, 0.26f);
93             _contentContainer.SetRelativeHeight(4, 0.07f);
94             _contentContainer.SetRelativeHeight(5, 0.26f);
95             _contentContainer.StateFocusEnable = true;
96             _stage.Add(_contentContainer);
97
98             CreateContent();
99
100             FocusManager.Instance.PreFocusChange += OnPreFocusChange;
101         }
102
103         // Callback for KeyboardFocusManager
104         private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
105         {
106             if (!e.Proposed && !e.Current)
107             {
108                 e.Proposed = _contentContainer.GetChildViewAt(1);
109             }
110             return e.Proposed;
111         }
112
113         private void CreateContent()
114         {
115             for (int i = 0; i < mViewList.Length; i++)
116             {
117                 CreateItem(mViewList[i], i);
118             }
119         }
120
121         private void CreateItem(Item item, int idx)
122         {
123             // Make label for item
124             TextLabel itemLabel = new TextLabel("   " + item.name);
125             itemLabel.Size = new Vector3(_stage.GetSize().Width * 0.2f, _stage.GetSize().Height * 0.05f, 0.0f);
126             itemLabel.HorizontalAlignment = "BEGIN";
127             itemLabel.VerticalAlignment = "BOTTOM";
128             //itemLabel.PointSize = 10.0f;
129             _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
130
131             // If item is implemented in public, attach it on stage
132             if (item.isImplemented)
133             {
134                 if (item.name.CompareTo("PushButton") == 0)
135                 {
136                     PushButton pushButton = new PushButton();
137                     pushButton.LabelText = "Push Button";
138                     pushButton.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
139                     pushButton.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
140                     pushButton.UnselectedColor = new Vector4(1.0f,0.0f,0.0f,1.0f);
141                     pushButton.SelectedColor = new Vector4(0.0f,1.0f,0.0f,1.0f);
142                     pushButton.Clicked += (obj, e) =>
143                     {
144                         Button sender = (Button)(obj);
145                         sender.LabelText = "Click Me";
146                         sender.UnselectedColor = new Vector4(0.0f,0.0f,1.0f,1.0f);
147                         return true;
148                     };
149
150                     _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
151                 }
152                 if (item.name.CompareTo("DropDown") == 0)
153                 {
154
155                 }
156                 if (item.name.CompareTo("Toggle") == 0)
157                 {
158
159                 }
160                 if (item.name.CompareTo("InputField") == 0)
161                 {
162
163                 }
164                 if (item.name.CompareTo("AnimateGif") == 0)
165                 {
166
167                 }
168                 if (item.name.CompareTo("Loading") == 0)
169                 {
170
171                 }
172                 if (item.name.CompareTo("ProgressBar") == 0)
173                 {
174
175                 }
176                 if (item.name.CompareTo("ScrollBar") == 0)
177                 {
178
179                 }
180                 if (item.name.CompareTo("CheckBox") == 0)
181                 {
182                     CheckBoxButton checkBoxButton = new CheckBoxButton();
183                     checkBoxButton.LabelText = "Yes";
184
185                     _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
186                 }
187                 if (item.name.CompareTo("RadioButton") == 0)
188                 {
189                     TableView tableView = new TableView(2, 1);
190                     tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
191                     tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
192
193                     RadioButton rButton = new RadioButton();
194                     rButton.LabelText = "Yes";
195                     rButton.Selected = true;
196                     tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
197
198                     rButton = new RadioButton();
199                     rButton.LabelText = "No";
200
201                     tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
202
203                     _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
204                 }
205                 if (item.name.CompareTo("Tooltip") == 0)
206                 {
207
208                 }
209                 if (item.name.CompareTo("Popup") == 0)
210                 {
211                     PushButton button = new PushButton();
212                     button.LabelText = "Popup";
213                     button.ParentOrigin = NDalic.ParentOriginCenter;
214                     button.AnchorPoint = NDalic.AnchorPointCenter;
215                     //button.MaximumSize = new Vector2(90.0f,50.0f);
216                     _popup = CreatePopup();
217                     _popup.SetTitle(CreateTitle("Popup"));
218
219                     TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
220                     text.BackgroundColor = Color.White;
221                     text.MultiLine = true;
222                     text.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
223                     text.SetResizePolicy(ResizePolicyType.DIMENSION_DEPENDENCY, DimensionType.HEIGHT);
224                     text.SetPadding(new RectFloat(10.0f, 10.0f, 20.0f, 0.0f));
225                     _popup.SetContent(text);
226                     _popup.StateFocusEnable = true;
227                     _popup.SetDisplayState(Popup.DisplayStateType.HIDDEN);
228
229                     button.Clicked += (obj, ee) =>
230                     {
231                         _stage.Add(_popup);
232                         _popup.SetDisplayState(Popup.DisplayStateType.SHOWN);
233                         FocusManager.Instance.SetCurrentFocusView(View.DownCast((_popup.FindChildByName( "Footer" )).FindChildByName("OKButton")));
234                         return true;
235                     };
236                     _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
237                 }
238                 if (item.name.CompareTo("Toast") == 0)
239                 {
240                     PushButton button = new PushButton();
241                     button.LabelText = "Toast";
242                     button.ParentOrigin = NDalic.ParentOriginCenter;
243                     button.AnchorPoint = NDalic.AnchorPointCenter;
244                     button.Clicked += (obj, ee) =>
245                     {
246                         TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo( "PopupToast" ));
247                         if( typeInfo )
248                         {
249                             BaseHandle baseHandle = typeInfo.CreateInstance();
250                             if( baseHandle )
251                             {
252                                 Popup toast = Popup.DownCast( baseHandle );
253                                 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
254                                 text.TextColor = Color.White;
255                                 text.MultiLine = true;
256                                 text.HorizontalAlignment = "center";
257                                 toast.SetTitle( text);
258                                 _stage.Add(toast);
259                                 toast.SetDisplayState( Popup.DisplayStateType.SHOWN);
260                             }
261                         }
262                         return true;
263                     };
264                     _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
265                 }
266                 if (item.name.CompareTo("ItemView") == 0)
267                 {
268
269                 }
270             }
271             else
272             {
273                 ImageView notSupportView = new ImageView("/home/owner/apps_rw/NUISamples.Tizen/res/images/not_yet_sign.png");
274                 notSupportView.Size = new Vector3(_stage.GetSize().Width * 0.2f, _stage.GetSize().Height * 0.25f, 0.0f);
275                 notSupportView.StateFocusEnable = true;
276                 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
277             }
278         }
279         Popup CreatePopup()
280         {
281             Popup confirmationPopup = new Popup();
282
283             Actor footer = new Actor();
284             footer.SetName("Footer");
285             footer.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
286             footer.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.HEIGHT);
287             footer.Size = new Size3D(new Size(0.0f, 80.0f));
288             footer.ParentOrigin = NDalic.ParentOriginCenter;
289             footer.AnchorPoint = NDalic.AnchorPointCenter;
290
291             PushButton okButton = CreateOKButton();
292             okButton.ParentOrigin = NDalic.ParentOriginCenter;
293             okButton.AnchorPoint = NDalic.AnchorPointCenter;
294             okButton.SetResizePolicy(ResizePolicyType.SIZE_FIXED_OFFSET_FROM_PARENT, DimensionType.ALL_DIMENSIONS);
295             okButton.SizeModeFactor = new Vector3(-20.0f, -20.0f, 0.0f);
296
297             PushButton cancelButton = CreateCancelButton();
298             cancelButton.ParentOrigin = NDalic.ParentOriginCenter;
299             cancelButton.AnchorPoint = NDalic.AnchorPointCenter;
300             cancelButton.SetResizePolicy(ResizePolicyType.SIZE_FIXED_OFFSET_FROM_PARENT, DimensionType.ALL_DIMENSIONS);
301             cancelButton.SizeModeFactor = new Vector3(-20.0f, -20.0f, 0.0f);
302
303             TableView controlLayout = new TableView(1, 2);
304             controlLayout.ParentOrigin = NDalic.ParentOriginCenter;
305             controlLayout.AnchorPoint = NDalic.AnchorPointCenter;
306             controlLayout.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.ALL_DIMENSIONS);
307             controlLayout.SetCellPadding(new Size(10.0f, 10.0f));
308             controlLayout.SetRelativeWidth(0, 0.5f);
309             controlLayout.SetRelativeWidth(1, 0.5f);
310             controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.CENTER, VerticalAlignmentType.CENTER);
311             controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.CENTER, VerticalAlignmentType.CENTER);
312             controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
313             controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
314
315             footer.Add(controlLayout);
316
317             confirmationPopup.SetFooter(footer);
318             return confirmationPopup;
319         }
320         Actor CreateTitle(string title)
321         {
322             TextLabel titleActor = new TextLabel(title);
323             titleActor.TextColor = Color.White;
324             titleActor.MultiLine = true;
325             titleActor.HorizontalAlignment = "center";
326             return titleActor;
327         }
328
329         PushButton CreateOKButton()
330         {
331             PushButton okayButton = new PushButton();
332             okayButton.SetName("OKButton");
333             okayButton.LabelText = "OK";
334             okayButton.StateFocusEnable = true;
335             okayButton.Clicked += (obj, ee) =>
336             {
337                 _popup.SetDisplayState(Popup.DisplayStateType.HIDDEN);
338                 return true;
339             };
340             return okayButton;
341         }
342         PushButton CreateCancelButton()
343         {
344             PushButton cancelButton = new PushButton();
345             cancelButton.LabelText = "Cancel";
346             cancelButton.StateFocusEnable = true;
347             cancelButton.Clicked += (obj, ee) =>
348             {
349                 _popup.SetDisplayState(Popup.DisplayStateType.HIDDEN);
350                 return true;
351             };
352             return cancelButton;
353         }
354
355         public void MainLoop()
356         {
357             _application.MainLoop();
358         }
359
360         /// <summary>
361         /// The main entry point for the application.
362         /// </summary>
363
364         [STAThread]
365         static void Main(string[] args)
366         {
367             Console.WriteLine("Hello Mono World");
368
369             Example example = new Example(Application.NewApplication());
370             example.MainLoop();
371         }
372     }
373 }