Release 8.0.0.15408
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / PopupSample.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 PopupSample : 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 Popup popup = null;
16         private Popup popup2 = null;
17         private TextLabel contentText = null;
18         private TextLabel contentText2 = null;
19         private int index = 0;
20         private int index2 = 0;
21         private Button button = null;
22
23         private static string[] buttonStyles = new string[]
24         {
25             "UtilityPopupButton",
26             "FamilyPopupButton",
27             "FoodPopupButton",
28             "KitchenPopupButton",
29         };
30         private static Color[] color = new Color[]
31         {
32             new Color(0.05f, 0.63f, 0.9f, 1),//#ff0ea1e6
33             new Color(0.14f, 0.77f, 0.28f, 1),//#ff24c447
34             new Color(0.75f, 0.46f, 0.06f, 1),//#ffec7510
35             new Color(0.59f, 0.38f, 0.85f, 1),//#ff9762d9
36         };
37         public void Activate()
38         {
39             Window window = NUIApplication.GetDefaultWindow();
40
41             root = new View()
42             {
43                 Size = new Size(1920, 1080),
44                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
45             };
46             window.Add(root);
47
48             parent1 = new View()
49             {
50                 Size = new Size(1920, 1080),
51             };
52             parent1.Layout = new LinearLayout()
53             {
54                 LinearOrientation = LinearLayout.Orientation.Horizontal,
55                 LinearAlignment = LinearLayout.Alignment.Center,
56                 CellPadding = new Size(50, 50)
57             };
58
59             parent2 = new View()
60             {
61                 Size = new Size(1032, 980),
62             };
63             parent2.Layout = new LinearLayout()
64             {
65                 LinearOrientation = LinearLayout.Orientation.Vertical,
66                 LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
67                 CellPadding = new Size(400, 400)
68             };
69             
70             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
71             createText[0] = new TextLabel();
72             createText[0].Text = "Create Popup just by properties";
73             createText[0].WidthSpecification = 500;
74             createText[0].HeightSpecification = 100;
75             parent2.Add(createText[0]);
76
77             popup = new Popup();
78             popup.MinimumSize = new Size(1032, 184);
79             popup.Size = new Size(1032, 400);
80             popup.Position = new Position(150, 100);
81
82             // Title
83             popup.Title.PointSize = 25;
84             popup.Title.Size = new Size(0, 68);
85             popup.Title.PositionUsesPivotPoint = true;
86             popup.Title.ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft;
87             popup.Title.PivotPoint = Tizen.NUI.PivotPoint.TopLeft;
88             popup.Title.HorizontalAlignment = HorizontalAlignment.Begin;
89             popup.Title.VerticalAlignment = VerticalAlignment.Bottom;
90             popup.Title.Position = new Position(64, 52);
91             popup.Title.Text = "Popup Title";
92             popup.Title.Padding = 0;
93
94             // Shadow
95             popup.ImageShadow = new ImageShadow
96             {
97                 Url = CommonResource.GetFHResourcePath() + "11. Popup/popup_background_shadow.png",
98                 Border = new Rectangle(24, 24, 24, 24),
99                 Extents = new Vector2(48, 48)
100             };
101
102             // Background
103             popup.BackgroundImage = CommonResource.GetFHResourcePath() + "11. Popup/popup_background.png";
104             popup.BackgroundImageBorder = new Rectangle(0, 0, 81, 81);
105
106             // Buttons
107             popup.AddButton("Yes");
108             popup.AddButton("Exit");
109             popup.ButtonBackground = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png";
110             popup.ButtonBackgroundBorder = new Rectangle(5, 5, 5, 5);
111             popup.ButtonOverLayBackgroundColorSelector = new Selector<Color>
112             {
113                 Normal = new Color(1.0f, 1.0f, 1.0f, 0.5f),
114                 Pressed = new Color(0.0f, 0.0f, 0.0f, 0.5f)
115             };
116             popup.ButtonImageShadow = new ImageShadow
117             {
118                 Url = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png",
119                 Border = new Rectangle(5, 5, 5, 5)
120             };
121             popup.ButtonTextColor = color[0];
122             popup.ButtonHeight = 132;
123             popup.PopupButtonClickEvent += PopupButtonClickedEvent;
124             popup.LayoutDirectionChanged += PopupLayoutDirectionChanged;
125             popup.Post(window);
126
127             contentText = new TextLabel();
128             contentText.Size = new Size(1032, 100);
129             contentText.PointSize = 20;
130             contentText.HorizontalAlignment = HorizontalAlignment.Begin;
131             contentText.VerticalAlignment = VerticalAlignment.Center;
132             contentText.Text = "Popup ButtonStyle is " + buttonStyles[index];
133             contentText.TextColor = new Color(0,0,222,1);
134             popup.AddContentText(contentText);
135
136             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
137             createText[1] = new TextLabel();
138             createText[1].Text = "Create Popup just by Attributes";
139             createText[1].WidthSpecification = 500;
140             createText[1].HeightSpecification = 100;
141             parent2.Add(createText[1]);
142
143             PopupStyle attrs = new PopupStyle
144             {
145                 MinimumSize = new Size(1032, 184),
146                 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "11. Popup/popup_background.png" },
147                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(0, 0, 81, 81) },
148                 ImageShadow = new ImageShadow
149                 {
150                     Url = CommonResource.GetFHResourcePath() + "11. Popup/popup_background_shadow.png",
151                     Border = new Rectangle(24, 24, 24, 24),
152                     Extents = new Vector2(48, 48),
153                 },
154                 Title = new TextLabelStyle
155                 {
156                     PointSize = new Selector<float?> { All = 25 },
157                     TextColor = new Selector<Color> { All = Color.Black },
158                     Size = new Size(0, 68),
159                     PositionUsesPivotPoint = true,
160                     ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
161                     PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
162                     HorizontalAlignment = HorizontalAlignment.Begin,
163                     VerticalAlignment = VerticalAlignment.Bottom,
164                     Position = new Position(64, 52),
165                     Text = new Selector<string> { All = "Popup Title" },
166                 },
167                 Buttons = new ButtonStyle
168                 {
169                     PositionUsesPivotPoint = true,
170                     ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
171                     PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
172                     BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png" },
173                     BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
174                     ImageShadow = new ImageShadow
175                     {
176                         Url = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png",
177                         Border = new Rectangle(5, 5, 5, 5),
178                     },
179                     Overlay = new ImageViewStyle
180                     {
181                         PositionUsesPivotPoint = true,
182                         ParentOrigin = Tizen.NUI.ParentOrigin.Center,
183                         PivotPoint = Tizen.NUI.PivotPoint.Center,
184                         WidthResizePolicy = ResizePolicyType.FillToParent,
185                         HeightResizePolicy = ResizePolicyType.FillToParent,
186                         BackgroundColor = new Selector<Color>
187                         {
188                             Normal = new Color(1.0f, 1.0f, 1.0f, 0.5f),
189                             Pressed = new Color(0.0f, 0.0f, 0.0f, 0.5f),
190                         }
191                     },
192                     Text = new TextLabelStyle
193                     {
194                         PositionUsesPivotPoint = true,
195                         ParentOrigin = Tizen.NUI.ParentOrigin.Center,
196                         PivotPoint = Tizen.NUI.PivotPoint.Center,
197                         HorizontalAlignment = HorizontalAlignment.Center,
198                         VerticalAlignment = VerticalAlignment.Center,
199                         TextColor = new Selector<Color> { All = color[index2] }
200                     },
201                 },
202             };
203
204             popup2 = new Popup(attrs);
205             popup2.Size = new Size(1032, 400);
206             popup2.Position = new Position(150, 600);
207             popup2.AddButton("Yes");
208             popup2.AddButton("Exit");
209             popup2.ButtonHeight = 132;
210             popup2.PopupButtonClickEvent += PopupButtonClickedEvent;
211             popup2.LayoutDirectionChanged += Popup2LayoutDirectionChanged;
212             popup2.Post(window);
213
214             contentText2 = new TextLabel();
215             contentText2.Size = new Size(1032, 100);
216             contentText2.PointSize = 20;
217             contentText2.HorizontalAlignment = HorizontalAlignment.Begin;
218             contentText2.VerticalAlignment = VerticalAlignment.Center;
219             contentText2.Text = "Popup2 ButtonStyle is " + buttonStyles[index];
220             popup2.ContentView.Add(contentText2);
221
222             button = new Button();
223             button.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
224             button.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
225             button.WidthSpecification = 580;
226             button.HeightSpecification = 80;
227             button.TextLabel.Text = "LayoutDirection is left to right";
228             button.ClickEvent += ButtonClickEvent;
229
230             parent1.Add(parent2);
231             parent1.Add(button);
232             root.Add(parent1);
233         }
234
235         private void Popup2LayoutDirectionChanged(object sender, View.LayoutDirectionChangedEventArgs e)
236         {
237             if (contentText2.HorizontalAlignment == HorizontalAlignment.Begin)
238             {
239                 contentText2.HorizontalAlignment = HorizontalAlignment.End;
240             }
241             else if (contentText2.HorizontalAlignment == HorizontalAlignment.End)
242             {
243                 contentText2.HorizontalAlignment = HorizontalAlignment.Begin;
244             }
245         }
246
247         private void PopupLayoutDirectionChanged(object sender, View.LayoutDirectionChangedEventArgs e)
248         {
249             if (contentText.HorizontalAlignment == HorizontalAlignment.Begin)
250             {
251                 contentText.HorizontalAlignment = HorizontalAlignment.End;
252             }
253             else if (contentText.HorizontalAlignment == HorizontalAlignment.End)
254             {
255                 contentText.HorizontalAlignment = HorizontalAlignment.Begin;
256             }
257         }
258
259         private void PopupButtonClickedEvent(object sender, Popup.ButtonClickEventArgs e)
260         {
261             Popup obj = sender as Popup;
262             if (obj != null && e.ButtonIndex == 0)
263             {
264                 if(obj == popup)
265                 {
266                     index++;
267                     index = index % buttonStyles.Length;
268                     obj.ButtonTextColor = color[index];
269                     contentText.Text = "Popup ButtonStyle is " + buttonStyles[index];
270                 }
271                 else
272                 {
273                     index2++;
274                     index2 = index2 % buttonStyles.Length;
275                     obj.ButtonTextColor = color[index2];
276                     contentText2.Text = "Popup2 ButtonStyle is " + buttonStyles[index2];
277                 }               
278             }
279         }
280
281         private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
282         {
283             if (popup.LayoutDirection == ViewLayoutDirectionType.LTR)
284             {
285                 popup.LayoutDirection = ViewLayoutDirectionType.RTL;
286                 popup2.LayoutDirection = ViewLayoutDirectionType.RTL;
287                 button.TextLabel.Text = "LayoutDirection is right to left";
288             }
289             else
290             {
291                 popup.LayoutDirection = ViewLayoutDirectionType.LTR;
292                 popup2.LayoutDirection = ViewLayoutDirectionType.LTR;
293                 button.TextLabel.Text = "LayoutDirection is left to right";
294             }           
295         }
296
297         public void Deactivate()
298         {
299             if (root != null)
300             {
301                 if (popup != null)
302                 {
303                     if (contentText != null)
304                     {
305                         popup.ContentView.Remove(contentText);
306                         contentText.Dispose();
307                         contentText = null;
308                     }
309
310                     root.Remove(popup);
311                     popup.Dismiss();
312                     popup.Dispose();
313                     popup = null;
314                 }
315
316                 if (popup2 != null)
317                 {
318                     if (contentText2 != null)
319                     {
320                         popup2.ContentView.Remove(contentText2);
321                         contentText2.Dispose();
322                         contentText2 = null;
323                     }
324
325                     root.Remove(popup2);
326                     popup2.Dismiss();
327                     popup2.Dispose();
328                     popup2 = null;
329                 }
330
331                 if (createText[0] != null)
332                 {
333                     root.Remove(createText[0]);
334                     createText[0].Dispose();
335                     createText[0] = null;
336                 }
337
338                 if (createText[1] != null)
339                 {
340                     root.Remove(createText[1]);
341                     createText[1].Dispose();
342                     createText[1] = null;
343                 }
344
345                 if (button != null)
346                 {
347                     root.Remove(button);
348                     button.Dispose();
349                     button = null;
350                 }
351
352                 NUIApplication.GetDefaultWindow().Remove(root);
353                 root.Dispose();
354             }
355         }
356     }
357 }