Release 8.0.0.15408
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / ToastSample.cs
1 using Tizen.NUI;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class ToastSample : IExample
8     {
9         private TextLabel[] text = new TextLabel[3];
10         private Button[] button = new Button[2];
11         private Toast toast1_1, toast2_1;  //1-null para 2-attributes; X_1-color; X_2 image track
12         private View root;
13         private View[] parentView = new View[3];
14
15         public void Activate()
16         {
17             Window window = NUIApplication.GetDefaultWindow();
18
19             root = new View()
20             {
21                 Size = new Size(1920, 1080),
22                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
23             };
24             root.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical };
25             window.Add(root);
26
27             CreateTextView();
28             CreateToastView();
29             CreateLogPadView();
30         }
31
32         private void CreateTextView()
33         {
34             // Init parent of TextView
35             parentView[0] = new View();
36             parentView[0].Size = new Size(1920, 200);
37             parentView[0].Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, LinearAlignment = LinearLayout.Alignment.Center, CellPadding = new Size2D(300, 0) };
38             root.Add(parentView[0]);
39
40             for (int i = 0; i < 2; i++)
41             {
42                 text[i] = new TextLabel();
43                 text[i].Size = new Size(400, 70);
44                 text[i].PointSize = 20.0f;
45                 text[i].BackgroundColor = Color.Magenta;
46                 text[i].HorizontalAlignment = HorizontalAlignment.Center;
47                 text[i].VerticalAlignment = VerticalAlignment.Center;
48                 text[i].Focusable = true;
49                 text[i].FocusGained += Board_FocusGained;
50                 text[i].FocusLost += Board_FocusLost;
51                 parentView[0].Add(text[i]);
52             }
53
54             // Text of "Create Switch just by properties"
55             text[0].Text = "Null Style construction";
56
57             // Text of "Create Switch just by Style"
58             text[1].Text = "Style construction";
59         }
60
61         private void CreateToastView()
62         {
63             // Init parent of ToastView
64             parentView[1] = new View();
65             parentView[1].Size = new Size(1920, 500);
66             parentView[1].Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, LinearAlignment = LinearLayout.Alignment.Center, CellPadding = new Size2D(300, 0) };
67             root.Add(parentView[1]);
68
69             // Create Toasts
70             toast1_1 = Toast.FromText("Null parameter construction", 1000);
71             toast1_1.Size = new Size(700, 132);
72             toast1_1.Post(NUIApplication.GetDefaultWindow());
73
74             ToastStyle attr = new ToastStyle
75             {
76                 Size = new Size(712, 132),
77                 BackgroundImage = CommonResource.GetFHResourcePath() + "12. Toast Popup/toast_background.png",
78                 BackgroundImageBorder = new Rectangle(64, 64, 4, 4),
79                 Duration = 3000
80             };
81
82             toast2_1 = new Toast(attr);
83             toast2_1.Message = "Style parameter construction";
84             toast2_1.Post(NUIApplication.GetDefaultWindow());
85
86             // Create Buttons
87             CreateBoardAndButtons();
88         }
89
90         private void CreateLogPadView()
91         {
92             // Init parent of LogPadView
93             parentView[2] = new View();
94             parentView[2].Size = new Size(1920, 380);
95             parentView[2].Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, LinearAlignment = LinearLayout.Alignment.Center};
96             root.Add(parentView[2]);
97
98             // Create log pad
99             text[2] = new TextLabel();
100             text[2].Size = new Size(1000, 100);
101             text[2].PointSize = 30.0f;
102             text[2].HorizontalAlignment = HorizontalAlignment.Center;
103             text[2].VerticalAlignment = VerticalAlignment.Center;
104             text[2].BackgroundColor = Color.Magenta;
105             text[2].Text = "log pad";
106             text[2].Focusable = true;
107             text[2].FocusGained += Board_FocusGained;
108             text[2].FocusLost += Board_FocusLost;
109             text[2].UpFocusableView = button[0];
110             parentView[2].Add(text[2]);
111         }
112
113         void CreateBoardAndButtons()
114         {
115             for (int i = 0; i < 2; i++)
116             {
117                 button[i] = new Button();
118                 button[i].BackgroundColor = Color.Green;
119                 button[i].Size = new Size(200, 50);
120                 button[i].Focusable = true;
121                 parentView[1].Add(button[i]);
122             }
123             button[0].Text = "toast1_1 Show";
124             button[0].ClickEvent += toast1_1Show;
125             button[1].Text = "toast2_1 Show";
126             button[1].ClickEvent += toast2_1Show;
127
128             // Set init focus
129             FocusManager.Instance.SetCurrentFocusView(button[0]);
130         }
131
132         private void Board_FocusLost(object sender, global::System.EventArgs e)
133         {
134             text[2].BackgroundColor = Color.Magenta;
135         }
136
137         private void Board_FocusGained(object sender, global::System.EventArgs e)
138         {
139             text[2].BackgroundColor = Color.Cyan;
140         }
141
142         private void toast1_1Show(object sender, global::System.EventArgs e)
143         {
144             text[2].Text = "toast1_1 show: ";
145             toast1_1.Show();
146         }
147
148         private void toast2_1Show(object sender, global::System.EventArgs e)
149         {
150             text[2].Text = "toast2_1 show: ";
151             toast2_1.Show();
152         }
153
154         public void Deactivate()
155         {
156             if (root != null)
157             {
158                 NUIApplication.GetDefaultWindow().Remove(root);
159
160                 if (toast1_1 != null)
161                 {
162                     NUIApplication.GetDefaultWindow().Remove(toast1_1);
163                     toast1_1.Dispose();
164                     toast1_1 = null;
165                 }
166
167                 if (toast2_1 != null)
168                 {
169                     NUIApplication.GetDefaultWindow().Remove(toast2_1);
170                     toast2_1.Dispose();
171                     toast2_1 = null;
172                 }
173
174                 int i = 0;
175                 for (; i < 2; i++)
176                 {
177                     button[i].Dispose();
178                     button[i] = null;
179                 }
180
181                 for (i = 0; i < 3; i++)
182                 {
183                     text[i].Dispose();
184                     text[i] = null;
185                     parentView[i].Dispose();
186                     parentView[i] = null;
187                 }
188                 root.Dispose();
189                 root = null;
190             }
191         }
192     }
193 }