Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / DropDownSample.cs
1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class DropDownSample : IExample
8     {
9         private View root;
10         private View parent1;
11         private View parent2;
12
13         private TextLabel[] createText = new TextLabel[2];
14
15         private DropDown dropDown = null;
16         private DropDown dropDown2 = null;
17         private ScrollBar scrollBar = null;
18         private ScrollBar scrollBar2 = null;
19
20         private static string[] mode = new string[]
21         {
22             "Utility DropDown",
23             "Family DropDown",
24             "Food DropDown",
25             "Kitchen DropDown",
26         };
27         private static Color[] color = new Color[]
28         {
29         new Color(0.05f, 0.63f, 0.9f, 1),//#ff0ea1e6 Utility
30         new Color(0.14f, 0.77f, 0.28f, 1),//#ff24c447 Family
31         new Color(0.75f, 0.46f, 0.06f, 1),//#ffec7510 Food
32         new Color(0.59f, 0.38f, 0.85f, 1),//#ff9762d9 Kitchen
33         };
34         public void Activate()
35         {
36             Window window = NUIApplication.GetDefaultWindow();
37
38             //Create root view with linear layout.
39             root = new View()
40             {
41                 Size = new Size(1920, 1080),
42                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
43                 Layout = new LinearLayout()
44                 {
45                     LinearOrientation = LinearLayout.Orientation.Horizontal,
46                     CellPadding = new Size(50, 50),
47                     LinearAlignment = LinearLayout.Alignment.Center,
48                 }
49             };
50             window.Add(root);
51
52             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
53             parent1 = new View()
54             {
55                 Size = new Size(900, 800),
56                 Layout = new LinearLayout()
57                 {
58                     LinearOrientation = LinearLayout.Orientation.Vertical,
59                     CellPadding = new Size(50, 50),
60                     LinearAlignment = LinearLayout.Alignment.Top,
61                 }
62             };
63
64             root.Add(parent1);
65             // Create a description text.
66             createText[0] = new TextLabel();
67             createText[0].Text = "Create DropDown just by properties";
68             createText[0].Size = new Size(800, 100);
69             createText[0].MultiLine = true;
70             parent1.Add(createText[0]);
71
72             //Create a dropdown by property.
73             #region CreateByProperty
74             dropDown = new DropDown();
75             var style = dropDown.Style;
76             style.Button.BackgroundImage = "";
77             style.Button.Icon.ResourceUrl = CommonResource.GetFHResourcePath() + "6. List/list_ic_dropdown.png";
78             style.Button.Text.PointSize = 20;
79             style.Button.Text.FontFamily = "SamsungOneUI 500";
80             style.Button.Text.TextColor = new Color(0, 0, 0, 1);
81             dropDown.ApplyStyle(style);
82             dropDown.Size = new Size(900, 108);
83             dropDown.HeaderText.Text = "TitleArea";
84             dropDown.HeaderText.TextColor = new Color(0, 0, 0, 1);
85             dropDown.HeaderText.PointSize = 28;
86             dropDown.HeaderText.FontFamily = "SamsungOneUI 500C";
87             dropDown.HeaderText.PositionX = 50;
88             dropDown.Button.TextLabel.Text = "DropDown Text";
89             dropDown.Button.Icon.Size = new Size(48, 48);
90             dropDown.Button.IconRelativeOrientation = Button.IconOrientation.Right;
91             dropDown.Button.ParentOrigin = ParentOrigin.CenterLeft;
92             dropDown.Button.PivotPoint = PivotPoint.CenterLeft;
93             dropDown.Button.PositionX = 56;
94             dropDown.SpaceBetweenButtonTextAndIcon = 8;
95             dropDown.ListBackgroundImage.ResourceUrl = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_bg.png";
96             dropDown.ListBackgroundImage.Border = new Rectangle(51, 51, 51, 51);
97             dropDown.ListBackgroundImage.Size = new Size(360, 500);
98             dropDown.ListMargin.Start = 20;
99             dropDown.ListMargin.Top = 20;
100             dropDown.ListPadding = new Extents(4, 4, 4, 4);
101             dropDown.BackgroundColor = new Color(1, 1, 1, 1);
102             parent1.Add(dropDown);
103             for (int i = 0; i < 8; i++)
104             {
105                 DropDown.DropDownDataItem item = new DropDown.DropDownDataItem();
106                 item.Size = new Size(360, 96);
107                 item.BackgroundColor= new Selector<Color>
108                 {
109                     Pressed = new Color(0, 0, 0, 0.4f),
110                     Other = new Color(1, 1, 1, 0),
111                 };
112                 item.Text = "Normal list " + i;
113                 item.PointSize = 18;
114                 item.FontFamily = "SamsungOne 500";
115                 item.TextPosition = new Position(28, 0);
116                 item.CheckImageSize = new Size(40, 40);
117                 item.CheckImageResourceUrl = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png";
118                 item.CheckImageGapToBoundary = 16;
119                 dropDown.AddItem(item);
120             }
121
122             dropDown.SelectedItemIndex = 3;
123
124             ////////Attach scrollbar///////////
125             scrollBar = new ScrollBar();
126             scrollBar.Direction = ScrollBar.DirectionType.Vertical;
127             scrollBar.Size = new Size(4, 446);
128             scrollBar.TrackColor = Color.Green;
129             scrollBar.ThumbSize = new Size(4, 30);
130             scrollBar.ThumbColor = Color.Yellow;
131             scrollBar.TrackImageURL = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
132             dropDown.AttachScrollBar(scrollBar);
133
134             #endregion
135             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
136             parent2 = new View()
137             {
138                 Size = new Size(900, 800),
139                 Layout = new LinearLayout()
140                 {
141                     LinearOrientation = LinearLayout.Orientation.Vertical,
142                     CellPadding = new Size(50, 50),
143                     LinearAlignment = LinearLayout.Alignment.Top,
144                 }
145             };
146             root.Add(parent2);
147
148             // Create a description text.
149             createText[1] = new TextLabel();
150             createText[1].Text = "Create DropDown just by Attributes";
151             createText[1].Size = new Size(800, 100);
152             createText[1].MultiLine = true;
153             parent2.Add(createText[1]);
154
155             //Create a dropdown by style.
156             #region CreateByStyle
157
158             DropDownStyle dropDownStyle = new DropDownStyle
159             {
160                 HeaderText = new TextLabelStyle
161                 {
162                     Text = new Selector<string> { All = "TitleArea" },
163                     PointSize = new Selector<float?> { All = 28 },
164                     TextColor = new Selector<Color> { All = new Color(0, 0, 0, 1) },
165                     FontFamily = "SamsungOneUI 500C",
166                     PositionX = 50,
167                 },
168
169                 Button = new ButtonStyle
170                 {
171                     Text = new TextLabelStyle
172                     {
173                         Text = new Selector<string> { All = "DropDown Text" },
174                         PointSize = new Selector<float?> { All = 20 },
175                         TextColor = new Selector<Color> { All = new Color(0, 0, 0, 1) },
176                         FontFamily = "SamsungOneUI 500",
177                     },
178                     Icon = new ImageViewStyle
179                     {
180                         Size = new Size(48, 48),
181                         ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "6. List/list_ic_dropdown.png" },
182                     },
183                     IconRelativeOrientation = Button.IconOrientation.Right,
184                     PositionX = 56,
185                     BackgroundImage = "",
186                 },
187                 ListBackgroundImage = new ImageViewStyle
188                 {
189                     ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_bg.png" },
190                     Border = new Selector<Rectangle> { All = new Rectangle(51, 51, 51, 51) },
191                     Size = new Size(360, 500),
192                 },
193                 SpaceBetweenButtonTextAndIcon = 8,
194                 ListMargin = new Extents(20, 0, 20, 0),
195                 BackgroundColor = new Selector<Color> { All = new Color(1, 1, 1, 1) },
196                 ListPadding = new Extents(4, 4, 4, 4),
197             };
198
199             dropDown2 = new DropDown(dropDownStyle);
200             dropDown2.Size = new Size(900, 108);
201             parent2.Add(dropDown2);
202
203             DropDownItemStyle itemStyle = new DropDownItemStyle
204             {
205                 BackgroundColor = new Selector<Color>
206                 {
207                     Pressed = new Color(0, 0, 0, 0.4f),
208                     Other = new Color(1, 1, 1, 0),
209                 },
210                 Text = new TextLabelStyle
211                 {
212                     PointSize = new Selector<float?> { All = 18 },
213                     FontFamily = "SamsungOne 500",
214                     Position = new Position(28, 0),
215                 },
216                 CheckImage = new ImageViewStyle
217                 {
218                     Size = new Size(40, 40),
219                     ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png" },
220                 },
221                 CheckImageGapToBoundary = 16,
222             };
223
224             for (int i = 0; i < 8; i++)
225             {
226                 DropDown.DropDownDataItem item = new DropDown.DropDownDataItem(itemStyle);
227                 item.Size = new Size(360, 96);
228                 item.Text = "Normal list " + i;
229                 dropDown2.AddItem(item);
230             }
231             dropDown2.SelectedItemIndex = 0;
232
233             ////////Attach scrollbar///////////
234             scrollBar2 = new ScrollBar();
235             scrollBar2.Direction = ScrollBar.DirectionType.Vertical;
236             scrollBar2.Size = new Size(4, 446);
237             scrollBar2.TrackColor = Color.Green;
238             scrollBar2.ThumbSize = new Size(4, 30);
239             scrollBar2.ThumbColor = Color.Yellow;
240             scrollBar2.TrackImageURL = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
241             dropDown2.AttachScrollBar(scrollBar2);
242
243             #endregion
244             //Add all views into root view.
245             root.Add(parent1);
246             root.Add(parent2);
247         }
248
249         public void Deactivate()
250         {
251             if (root != null)
252             {
253                 if (dropDown != null)
254                 {
255                     if (scrollBar != null)
256                     {
257                         dropDown.DetachScrollBar();
258                         scrollBar.Dispose();
259                         scrollBar = null;
260                     }
261
262                     parent1.Remove(dropDown);
263                     dropDown.Dispose();
264                     dropDown = null;
265                 }
266                 if (dropDown2 != null)
267                 {
268                     if (scrollBar2 != null)
269                     {
270                         dropDown2.DetachScrollBar();
271                         scrollBar2.Dispose();
272                         scrollBar2 = null;
273                     }
274
275                     parent2.Remove(dropDown2);
276                     dropDown2.Dispose();
277                     dropDown2 = null;
278                 }
279
280                 if (createText[0] != null)
281                 {
282                     parent1.Remove(createText[0]);
283                     createText[0].Dispose();
284                     createText[0] = null;
285                 }
286                 if (createText[1] != null)
287                 {
288                     parent2.Remove(createText[1]);
289                     createText[1].Dispose();
290                     createText[1] = null;
291                 }
292
293                 root.Remove(parent1);
294                 parent1.Dispose();
295                 parent1 = null;
296                 root.Remove(parent2);
297                 parent2.Dispose();
298                 parent2 = null;
299
300                 NUIApplication.GetDefaultWindow().Remove(root);
301                 root.Dispose();
302                 root = null;
303             }
304         }
305     }
306 }