Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"
[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(CommonResource.GetFHResourcePath() + "11. Popup/popup_background_shadow.png", new Rectangle(24, 24, 24, 24), extents: new Vector2(48, 48));
96
97             // Background
98             popup.BackgroundImage = CommonResource.GetFHResourcePath() + "11. Popup/popup_background.png";
99             popup.BackgroundImageBorder = new Rectangle(0, 0, 81, 81);
100
101             // Buttons
102             popup.AddButton("Yes");
103             popup.AddButton("Exit");
104             popup.ButtonBackground = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png";
105             popup.ButtonBackgroundBorder = new Rectangle(5, 5, 5, 5);
106             popup.ButtonOverLayBackgroundColorSelector = new Selector<Color>
107             {
108                 Normal = new Color(1.0f, 1.0f, 1.0f, 0.5f),
109                 Pressed = new Color(0.0f, 0.0f, 0.0f, 0.5f)
110             };
111             popup.ButtonImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
112             popup.ButtonTextColor = color[0];
113             popup.ButtonHeight = 132;
114             popup.PopupButtonClickEvent += PopupButtonClickedEvent;
115             popup.LayoutDirectionChanged += PopupLayoutDirectionChanged;
116             popup.Post(window);
117
118             contentText = new TextLabel();
119             contentText.Size = new Size(1032, 100);
120             contentText.PointSize = 20;
121             contentText.HorizontalAlignment = HorizontalAlignment.Begin;
122             contentText.VerticalAlignment = VerticalAlignment.Center;
123             contentText.Text = "Popup ButtonStyle is " + buttonStyles[index];
124             contentText.TextColor = new Color(0,0,222,1);
125             popup.AddContentText(contentText);
126
127             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
128             createText[1] = new TextLabel();
129             createText[1].Text = "Create Popup just by Attributes";
130             createText[1].WidthSpecification = 500;
131             createText[1].HeightSpecification = 100;
132             parent2.Add(createText[1]);
133
134             PopupStyle attrs = new PopupStyle
135             {
136                 MinimumSize = new Size(1032, 184),
137                 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "11. Popup/popup_background.png" },
138                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(0, 0, 81, 81) },
139                 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "11. Popup/popup_background_shadow.png", new Rectangle(24, 24, 24, 24), extents: new Vector2(48, 48)),
140                 Title = new TextLabelStyle
141                 {
142                     PointSize = new Selector<float?> { All = 25 },
143                     TextColor = new Selector<Color> { All = Color.Black },
144                     Size = new Size(0, 68),
145                     PositionUsesPivotPoint = true,
146                     ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
147                     PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
148                     HorizontalAlignment = HorizontalAlignment.Begin,
149                     VerticalAlignment = VerticalAlignment.Bottom,
150                     Position = new Position(64, 52),
151                     Text = new Selector<string> { All = "Popup Title" },
152                 },
153                 Buttons = new ButtonStyle
154                 {
155                     PositionUsesPivotPoint = true,
156                     ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
157                     PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
158                     BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png" },
159                     BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
160                     ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
161                     Overlay = new ImageViewStyle
162                     {
163                         PositionUsesPivotPoint = true,
164                         ParentOrigin = Tizen.NUI.ParentOrigin.Center,
165                         PivotPoint = Tizen.NUI.PivotPoint.Center,
166                         WidthResizePolicy = ResizePolicyType.FillToParent,
167                         HeightResizePolicy = ResizePolicyType.FillToParent,
168                         BackgroundColor = new Selector<Color>
169                         {
170                             Normal = new Color(1.0f, 1.0f, 1.0f, 0.5f),
171                             Pressed = new Color(0.0f, 0.0f, 0.0f, 0.5f),
172                         }
173                     },
174                     Text = new TextLabelStyle
175                     {
176                         PositionUsesPivotPoint = true,
177                         ParentOrigin = Tizen.NUI.ParentOrigin.Center,
178                         PivotPoint = Tizen.NUI.PivotPoint.Center,
179                         HorizontalAlignment = HorizontalAlignment.Center,
180                         VerticalAlignment = VerticalAlignment.Center,
181                         TextColor = new Selector<Color> { All = color[index2] }
182                     },
183                 },
184             };
185
186             popup2 = new Popup(attrs);
187             popup2.Size = new Size(1032, 400);
188             popup2.Position = new Position(150, 600);
189             popup2.AddButton("Yes");
190             popup2.AddButton("Exit");
191             popup2.ButtonHeight = 132;
192             popup2.PopupButtonClickEvent += PopupButtonClickedEvent;
193             popup2.LayoutDirectionChanged += Popup2LayoutDirectionChanged;
194             popup2.Post(window);
195
196             contentText2 = new TextLabel();
197             contentText2.Size = new Size(1032, 100);
198             contentText2.PointSize = 20;
199             contentText2.HorizontalAlignment = HorizontalAlignment.Begin;
200             contentText2.VerticalAlignment = VerticalAlignment.Center;
201             contentText2.Text = "Popup2 ButtonStyle is " + buttonStyles[index];
202             popup2.ContentView.Add(contentText2);
203
204             button = new Button();
205             button.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
206             button.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
207             button.WidthSpecification = 580;
208             button.HeightSpecification = 80;
209             button.TextLabel.Text = "LayoutDirection is left to right";
210             button.Clicked += ButtonClicked;
211
212             parent1.Add(parent2);
213             parent1.Add(button);
214             root.Add(parent1);
215         }
216
217         private void Popup2LayoutDirectionChanged(object sender, View.LayoutDirectionChangedEventArgs e)
218         {
219             if (contentText2.HorizontalAlignment == HorizontalAlignment.Begin)
220             {
221                 contentText2.HorizontalAlignment = HorizontalAlignment.End;
222             }
223             else if (contentText2.HorizontalAlignment == HorizontalAlignment.End)
224             {
225                 contentText2.HorizontalAlignment = HorizontalAlignment.Begin;
226             }
227         }
228
229         private void PopupLayoutDirectionChanged(object sender, View.LayoutDirectionChangedEventArgs e)
230         {
231             if (contentText.HorizontalAlignment == HorizontalAlignment.Begin)
232             {
233                 contentText.HorizontalAlignment = HorizontalAlignment.End;
234             }
235             else if (contentText.HorizontalAlignment == HorizontalAlignment.End)
236             {
237                 contentText.HorizontalAlignment = HorizontalAlignment.Begin;
238             }
239         }
240
241         private void PopupButtonClickedEvent(object sender, Popup.ButtonClickEventArgs e)
242         {
243             Popup obj = sender as Popup;
244             if (obj != null && e.ButtonIndex == 0)
245             {
246                 if(obj == popup)
247                 {
248                     index++;
249                     index = index % buttonStyles.Length;
250                     obj.ButtonTextColor = color[index];
251                     contentText.Text = "Popup ButtonStyle is " + buttonStyles[index];
252                 }
253                 else
254                 {
255                     index2++;
256                     index2 = index2 % buttonStyles.Length;
257                     obj.ButtonTextColor = color[index2];
258                     contentText2.Text = "Popup2 ButtonStyle is " + buttonStyles[index2];
259                 }               
260             }
261         }
262
263         private void ButtonClicked(object sender, ClickedEventArgs e)
264         {
265             if (popup.LayoutDirection == ViewLayoutDirectionType.LTR)
266             {
267                 popup.LayoutDirection = ViewLayoutDirectionType.RTL;
268                 popup2.LayoutDirection = ViewLayoutDirectionType.RTL;
269                 button.TextLabel.Text = "LayoutDirection is right to left";
270             }
271             else
272             {
273                 popup.LayoutDirection = ViewLayoutDirectionType.LTR;
274                 popup2.LayoutDirection = ViewLayoutDirectionType.LTR;
275                 button.TextLabel.Text = "LayoutDirection is left to right";
276             }           
277         }
278
279         public void Deactivate()
280         {
281             if (root != null)
282             {
283                 if (popup != null)
284                 {
285                     if (contentText != null)
286                     {
287                         popup.ContentView.Remove(contentText);
288                         contentText.Dispose();
289                         contentText = null;
290                     }
291
292                     root.Remove(popup);
293                     popup.Dismiss();
294                     popup.Dispose();
295                     popup = null;
296                 }
297
298                 if (popup2 != null)
299                 {
300                     if (contentText2 != null)
301                     {
302                         popup2.ContentView.Remove(contentText2);
303                         contentText2.Dispose();
304                         contentText2 = null;
305                     }
306
307                     root.Remove(popup2);
308                     popup2.Dismiss();
309                     popup2.Dispose();
310                     popup2 = null;
311                 }
312
313                 if (createText[0] != null)
314                 {
315                     root.Remove(createText[0]);
316                     createText[0].Dispose();
317                     createText[0] = null;
318                 }
319
320                 if (createText[1] != null)
321                 {
322                     root.Remove(createText[1]);
323                     createText[1].Dispose();
324                     createText[1] = null;
325                 }
326
327                 if (button != null)
328                 {
329                     root.Remove(button);
330                     button.Dispose();
331                     button = null;
332                 }
333
334                 NUIApplication.GetDefaultWindow().Remove(root);
335                 root.Dispose();
336             }
337         }
338     }
339 }