fead2852c90ac32f09eedbba58ee7194182e7ae9
[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
11         private TextLabel[] createText = new TextLabel[2];
12
13         private DropDown dropDown = null;
14         private DropDown dropDown2 = null;
15         private ScrollBar scrollBar = null;
16         private ScrollBar scrollBar2 = null;
17
18         private static string[] mode = new string[]
19         {
20             "Utility DropDown",
21             "Family DropDown",
22             "Food DropDown",
23             "Kitchen DropDown",
24         };
25         private static Color[] color = new Color[]
26         {
27         new Color(0.05f, 0.63f, 0.9f, 1),//#ff0ea1e6 Utility
28         new Color(0.14f, 0.77f, 0.28f, 1),//#ff24c447 Family
29         new Color(0.75f, 0.46f, 0.06f, 1),//#ffec7510 Food
30         new Color(0.59f, 0.38f, 0.85f, 1),//#ff9762d9 Kitchen
31         };
32         public void Activate()
33         {
34             Window window = Window.Instance;
35
36             root = new View()
37             {
38                 Size2D = new Size2D(1920, 1080),
39                 BackgroundColor = Color.White,
40             };
41             window.Add(root);
42
43             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
44             createText[0] = new TextLabel();
45             createText[0].Text = "Create DropDown just by properties";
46             createText[0].Size2D = new Size2D(450, 100);
47             createText[0].Position2D = new Position2D(200, 100);
48             createText[0].MultiLine = true;
49             root.Add(createText[0]);
50
51             #region CreateByProperty
52             dropDown = new DropDown();
53             dropDown.Size2D = new Size2D(900, 108);
54             dropDown.Position2D = new Position2D(50, 300);
55             dropDown.Style.HeaderText.Text = "TitleArea";
56             dropDown.Style.HeaderText.TextColor = new Color(0, 0, 0, 1);
57             dropDown.Style.HeaderText.PointSize = 28;
58             dropDown.Style.HeaderText.FontFamily = "SamsungOneUI 500C";
59             dropDown.Style.Button.Text.Text = "DropDown Text";
60             dropDown.Style.Button.Text.TextColor = new Color(0, 0, 0, 1);
61             dropDown.Style.Button.Text.PointSize = 20;
62             dropDown.Style.Button.Text.FontFamily = "SamsungOneUI 500";
63             dropDown.Style.Button.Icon.ResourceUrl = CommonResource.GetFHResourcePath() + "6. List/list_ic_dropdown.png";
64             dropDown.Style.Button.Icon.Size = new Size(48, 48);
65             dropDown.Style.Button.IconRelativeOrientation = Button.IconOrientation.Right;
66             dropDown.Style.Button.PositionX = 56;
67             dropDown.SpaceBetweenButtonTextAndIcon = 8;
68             dropDown.Style.ListBackgroundImage.ResourceUrl = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_bg.png";
69             dropDown.Style.ListBackgroundImage.Border = new Rectangle(51, 51, 51, 51);
70             dropDown.Style.ListBackgroundImage.Size = new Size(360, 500);
71             dropDown.ListMargin.Start = 20;
72             dropDown.ListMargin.Top = 20;
73             dropDown.ListPadding = new Extents(4, 4, 4, 4);
74             root.Add(dropDown);
75
76             for (int i = 0; i < 8; i++)
77             {
78                 DropDown.DropDownDataItem item = new DropDown.DropDownDataItem();
79                 item.Size = new Size(360, 96);
80                 item.BackgroundColor= new Selector<Color>
81                 {
82                     Pressed = new Color(0, 0, 0, 0.4f),
83                     Other = new Color(1, 1, 1, 0),
84                 };
85                 item.Text = "Normal list " + i;
86                 item.PointSize = 18;
87                 item.FontFamily = "SamsungOne 500";
88                 item.TextPosition = new Position(28, 0);
89                 item.CheckImageSize = new Size(40, 40);
90                 item.CheckImageResourceUrl = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png";
91                 item.CheckImageGapToBoundary = 16;
92                 dropDown.AddItem(item);
93             }
94
95             dropDown.SelectedItemIndex = 3;
96             //dropDown.DeleteItem(1);
97
98             //DropDown.DropDownItemData insertItem = new DropDown.DropDownItemData();
99             //insertItem.Size2D = new Size2D(360, 96);
100             //insertItem.BackgroundColorSelector = new Selector<Color>
101             //{
102             //    Pressed = new Color(0, 0, 0, 0.4f),
103             //    Other = new Color(1, 1, 1, 0),
104             //};
105             //insertItem.Text = "Insert Normal list ";
106             //insertItem.PointSize = 18;
107             //insertItem.FontFamily = "SamsungOne 500";
108             //insertItem.TextPosition2D = new Position2D(28, 0);
109             //insertItem.CheckImageSize = new Size2D(40, 40);
110             //insertItem.CheckImageResourceUrl = CommonReosurce.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png";
111             //insertItem.CheckImageRightSpace = 16;
112             //dropDown.InsertItem(insertItem, 1);
113             ////////Attach scrollbar///////////
114             scrollBar = new ScrollBar();
115             scrollBar.Direction = ScrollBar.DirectionType.Vertical;
116             scrollBar.Position2D = new Position2D(394, 2);
117             scrollBar.Size2D = new Size2D(4, 446);
118             scrollBar.Style.Track.BackgroundColor = Color.Green;
119             scrollBar.Style.Thumb.Size = new Size(4, 30);
120             scrollBar.Style.Thumb.BackgroundColor = Color.Yellow;
121             scrollBar.Style.Track.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
122             dropDown.AttachScrollBar(scrollBar);
123
124             #endregion
125             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
126             createText[1] = new TextLabel();
127             createText[1].Text = "Create DropDown just by Attributes";
128             createText[1].Size2D = new Size2D(450, 100);
129             createText[1].Position2D = new Position2D(1000, 100);
130             createText[1].MultiLine = true;
131             root.Add(createText[1]);
132
133             #region CreateByAttributes
134
135             DropDownStyle attrs = new DropDownStyle
136             {
137                 HeaderText = new TextLabelStyle
138                 {
139                     Text = new Selector<string> { All = "TitleArea" },
140                     PointSize = new Selector<float?> { All = 28 },
141                     TextColor = new Selector<Color> { All = new Color(0, 0, 0, 1) },
142                     FontFamily = "SamsungOneUI 500C",
143                 },
144
145                 Button = new ButtonStyle
146                 {
147                     Text = new TextLabelStyle
148                     {
149                         Text = new Selector<string> { All = "DropDown Text" },
150                         PointSize = new Selector<float?> { All = 20 },
151                         TextColor = new Selector<Color> { All = new Color(0, 0, 0, 1) },
152                         FontFamily = "SamsungOneUI 500",
153                     },
154                     Icon = new ImageViewStyle
155                     {
156                         Size = new Size(48, 48),
157                         ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "6. List/list_ic_dropdown.png" },
158                     },
159                     IconRelativeOrientation = Button.IconOrientation.Right,
160                     PositionX = 56,
161                 },
162                 ListBackgroundImage = new ImageViewStyle
163                 {
164                     ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_bg.png" },
165                     Border = new Selector<Rectangle> { All = new Rectangle(51, 51, 51, 51) },
166                     Size = new Size(360, 500),
167                 },
168                 SpaceBetweenButtonTextAndIcon = 8,
169                 ListMargin = new Extents(20, 0, 20, 0),
170                 BackgroundColor = new Selector<Color> { All = new Color(1, 1, 1, 1) },
171                 ListPadding = new Extents(4, 4, 4, 4),
172             };
173
174             dropDown2 = new DropDown(attrs);
175             dropDown2.Size2D = new Size2D(900, 108);
176             dropDown2.Position2D = new Position2D(1000, 300);
177             root.Add(dropDown2);
178
179             DropDownItemStyle itemAttrs = new DropDownItemStyle
180             {
181                 BackgroundColor = new Selector<Color>
182                 {
183                     Pressed = new Color(0, 0, 0, 0.4f),
184                     Other = new Color(1, 1, 1, 0),
185                 },
186                 Text = new TextLabelStyle
187                 {
188                     PointSize = new Selector<float?> { All = 18 },
189                     FontFamily = "SamsungOne 500",
190                     Position = new Position(28, 0),
191                 },
192                 CheckImage = new ImageViewStyle
193                 {
194                     Size = new Size(40, 40),
195                     ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "10. Drop Down/dropdown_checkbox_on.png" },
196                 },
197                 CheckImageGapToBoundary = 16,
198             };
199
200             for (int i = 0; i < 8; i++)
201             {
202                 DropDown.DropDownDataItem item = new DropDown.DropDownDataItem(itemAttrs);
203                 item.Size = new Size(360, 96);
204                 item.Text = "Normal list " + i;
205                 dropDown2.AddItem(item);
206             }
207             dropDown2.SelectedItemIndex = 0;
208
209             ////////Attach scrollbar///////////
210             scrollBar2 = new ScrollBar();
211             scrollBar2.Direction = ScrollBar.DirectionType.Vertical;
212             scrollBar2.Position2D = new Position2D(394, 2);
213             scrollBar2.Size2D = new Size2D(4, 446);
214             scrollBar2.Style.Track.BackgroundColor = Color.Green;
215             scrollBar2.Style.Thumb.Size = new Size(4, 30);
216             scrollBar2.Style.Thumb.BackgroundColor = Color.Yellow;
217             scrollBar2.Style.Track.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
218             dropDown2.AttachScrollBar(scrollBar2);
219
220             #endregion
221         }
222
223         public void Deactivate()
224         {
225             if (root != null)
226             {
227                 if (dropDown != null)
228                 {
229                     if (scrollBar != null)
230                     {
231                         dropDown.DetachScrollBar();
232                         scrollBar.Dispose();
233                         scrollBar = null;
234                     }
235
236                     root.Remove(dropDown);
237                     dropDown.Dispose();
238                     dropDown = null;
239                 }
240                 if (dropDown2 != null)
241                 {
242                     if (scrollBar2 != null)
243                     {
244                         dropDown2.DetachScrollBar();
245                         scrollBar2.Dispose();
246                         scrollBar2 = null;
247                     }
248
249                     root.Remove(dropDown2);
250                     dropDown2.Dispose();
251                     dropDown2 = null;
252                 }
253
254                 if (createText[0] != null)
255                 {
256                     root.Remove(createText[0]);
257                     createText[0].Dispose();
258                     createText[0] = null;
259                 }
260                 if (createText[1] != null)
261                 {
262                     root.Remove(createText[1]);
263                     createText[1].Dispose();
264                     createText[1] = null;
265                 }
266
267                 Window.Instance.Remove(root);
268                 root.Dispose();
269                 root = null;
270             }
271         }
272     }
273 }