Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / ProgressSample.cs
1 using Tizen.NUI.BaseComponents;
2 using Tizen.NUI.Components;
3 using Tizen.NUI;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class ProgressSample : IExample
8     {
9         private TextLabel[] board = new TextLabel[4];
10         private Button[] button = new Button[2];
11         private Progress[] progressBar = new Progress[4];
12         private View[] layout = new View[4];
13
14         public void Activate()
15         {
16             Window window = NUIApplication.GetDefaultWindow();
17             // Root layout.
18             layout[0] = new View()
19             {
20                 Size = new Size(1920, 1080),
21                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
22             };
23             layout[0].Layout = new LinearLayout()
24             {
25                 LinearOrientation = LinearLayout.Orientation.Vertical,
26                 LinearAlignment = LinearLayout.Alignment.Center
27             };
28             window.Add(layout[0]);
29
30             // Layout for progress parent layout.
31             layout[1] = new View()
32             {
33                 Size = new Size(1000, 730)
34             };
35             layout[1].Layout = new LinearLayout()
36             {
37                 LinearOrientation = LinearLayout.Orientation.Horizontal,
38                 LinearAlignment = LinearLayout.Alignment.Center
39             };
40             layout[0].Add(layout[1]);
41
42             // Layout for progress layout which is created by properties.
43             layout[2] = new View()
44             {
45                 Size = new Size(450, 630)
46             };
47             layout[2].Layout = new LinearLayout()
48             {
49                 LinearOrientation = LinearLayout.Orientation.Vertical,
50                 LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
51                 CellPadding = new Size2D(50, 100)
52             };
53             layout[1].Add(layout[2]);
54
55             // Layout for progress layout which is created by attributes.
56             layout[3] = new View()
57             {
58                 Size = new Size(450, 630)
59             };
60             layout[3].Layout = new LinearLayout()
61             {
62                 LinearOrientation = LinearLayout.Orientation.Vertical,
63                 LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
64                 CellPadding = new Size2D(50, 100)
65             };
66             layout[1].Add(layout[3]);
67
68             CreatePropElements();
69             CreateAttrElements();
70             CreateIndeterminateProgress();
71             layout[1].Add(layout[2]);
72             layout[1].Add(layout[3]);
73
74             board[0] = new TextLabel();
75             board[0].WidthSpecification = 900;
76             board[0].HeightSpecification = 100;
77             board[0].PointSize = 30;
78             board[0].HorizontalAlignment = HorizontalAlignment.Center;
79             board[0].VerticalAlignment = VerticalAlignment.Center;
80             board[0].BackgroundColor = Color.Magenta;
81             board[0].Text = "log pad";
82             layout[0].Add(board[0]);
83             board[0].Focusable = true;
84             board[0].FocusGained += Board_FocusGained;
85             board[0].FocusLost += Board_FocusLost;
86             board[0].UpFocusableView = button[0];
87             FocusManager.Instance.SetCurrentFocusView(button[0]);
88         }
89
90         void CreatePropElements()
91         {
92             ///////////////////////////////////////////////Create by Properties//////////////////////////////////////////////////////////
93             board[1] = new TextLabel();
94             board[1].WidthSpecification = 380;
95             board[1].HeightSpecification = 70;
96             board[1].PointSize = 20;
97             board[1].HorizontalAlignment = HorizontalAlignment.Center;
98             board[1].VerticalAlignment = VerticalAlignment.Center;
99             board[1].BackgroundColor = Color.Magenta;
100             board[1].Text = "Property construction";
101             layout[2].Add(board[1]);
102             board[1].Focusable = true;
103             board[1].FocusGained += Board_FocusGained;
104             board[1].FocusLost += Board_FocusLost;
105
106             progressBar[0] = new Progress();
107             progressBar[0].WidthSpecification = 240;
108             progressBar[0].HeightSpecification = 4;
109             progressBar[0].MaxValue = 100;
110             progressBar[0].MinValue = 0;
111             progressBar[0].CurrentValue = 45;
112             layout[2].Add(progressBar[0]);
113
114             progressBar[1] = new Progress();
115             progressBar[1].WidthSpecification = 240;
116             progressBar[1].HeightSpecification = 4;
117             progressBar[1].MaxValue = 100;
118             progressBar[1].MinValue = 0;
119             progressBar[1].CurrentValue = 30;
120             progressBar[1].TrackColor = Color.Yellow;
121             progressBar[1].ProgressColor = Color.Black;
122             layout[2].Add(progressBar[1]);
123
124             button[0] = new Button();
125             button[0].WidthSpecification = 140;
126             button[0].HeightSpecification = 50;
127             button[0].Text = "+";
128             button[0].BackgroundColor = Color.Green;
129             layout[2].Add(button[0]);
130             button[0].Focusable = true;
131             button[0].Clicked += ProgressAdd;
132
133             button[1] = new Button();
134             button[1].WidthSpecification = 140;
135             button[1].HeightSpecification = 50;
136             button[1].Text = "-";
137             button[1].BackgroundColor = Color.Green;
138             layout[2].Add(button[1]);
139             button[1].Focusable = true;
140             button[1].Clicked += ProgressMinus;
141         }
142
143         private void CreateAttrElements()
144         {
145             ///////////////////////////////////////////////Create by attributes//////////////////////////////////////////////////////////
146             board[2] = new TextLabel();
147             board[2].WidthSpecification = 380;
148             board[2].HeightSpecification = 70;
149             board[2].PointSize = 20;
150             board[2].HorizontalAlignment = HorizontalAlignment.Center;
151             board[2].VerticalAlignment = VerticalAlignment.Center;
152             board[2].BackgroundColor = Color.Magenta;
153             board[2].Text = "Attribute construction";
154             layout[3].Add(board[2]);
155             board[2].Focusable = true;
156             board[2].FocusGained += Board_FocusGained;
157             board[2].FocusLost += Board_FocusLost;
158
159             ProgressStyle attr = new ProgressStyle
160             {
161                 Track = new ImageViewStyle
162                 {
163                     BackgroundColor = new Selector<Color>
164                     {
165                         All = Color.Cyan
166                     }
167                 },
168                 Progress = new ImageViewStyle
169                 {
170                     BackgroundColor = new Selector<Color>
171                     {
172                         All = Color.Red
173                     }
174                 },
175                 Buffer = new ImageViewStyle
176                 {
177                     BackgroundColor = new Selector<Color>
178                     {
179                         All = Color.Green
180                     }
181                 }
182             };
183             progressBar[2] = new Progress(attr);
184             progressBar[2].WidthSpecification = 240;
185             progressBar[2].HeightSpecification = 4;
186             progressBar[2].MaxValue = 100;
187             progressBar[2].MinValue = 0;
188             progressBar[2].CurrentValue = 30;
189             layout[3].Add(progressBar[2]);
190         }
191
192         private void CreateIndeterminateProgress()
193         {
194             board[3] = new TextLabel();
195             board[3].WidthSpecification = 380;
196             board[3].HeightSpecification = 70;
197             board[3].PointSize = 20;
198             board[3].HorizontalAlignment = HorizontalAlignment.Center;
199             board[3].VerticalAlignment = VerticalAlignment.Center;
200             board[3].BackgroundColor = Color.Magenta;
201             board[3].Text = "Indeterminate Progress";
202             layout[3].Add(board[3]);
203             board[3].Focusable = true;
204             board[3].FocusGained += Board_FocusGained; // Not sure to connect this event
205             board[3].FocusLost += Board_FocusLost;
206
207             progressBar[3] = new Progress();
208             progressBar[3].WidthSpecification = 240;
209             progressBar[3].HeightSpecification = 4;
210             progressBar[3].ProgressState = Progress.ProgressStatusType.Indeterminate;
211             layout[3].Add(progressBar[3]);
212         }
213
214         private void Board_FocusLost(object sender, global::System.EventArgs e)
215         {
216             board[0].BackgroundColor = Color.Magenta;
217         }
218
219         private void Board_FocusGained(object sender, global::System.EventArgs e)
220         {
221             board[0].BackgroundColor = Color.Cyan;
222         }
223
224         private void ProgressAdd(object sender, global::System.EventArgs e)
225         {
226             if (progressBar[0].CurrentValue == 100)
227             {
228                 board[0].Text = "Current value is: 100";
229             }
230             else
231             {
232                 board[0].Text = "Current value is: " + ++progressBar[0].CurrentValue;
233             }
234         }
235         private void ProgressMinus(object sender, global::System.EventArgs e)
236         {
237             if (progressBar[0].CurrentValue == 0)
238             {
239                 board[0].Text = "Current value is: 0";
240             }
241             else
242             {
243                 board[0].Text = "Current value is: " + --progressBar[0].CurrentValue;
244             }
245         }
246
247         public void Deactivate()
248         {
249             if (layout[0] != null)
250             {
251                 layout[2].Remove(board[1]);
252                 board[1].Dispose();
253                 board[1] = null;
254                 layout[2].Remove(progressBar[0]);
255                 progressBar[0].Dispose();
256                 progressBar[0] = null;
257                 layout[2].Remove(progressBar[1]);
258                 progressBar[1].Dispose();
259                 progressBar[1] = null;
260                 layout[2].Remove(button[0]);
261                 button[0].Dispose();
262                 button[0] = null;
263                 layout[2].Remove(button[1]);
264                 button[1].Dispose();
265                 button[1] = null;
266
267                 layout[3].Remove(board[2]);
268                 board[2].Dispose();
269                 board[2] = null;
270                 layout[3].Remove(progressBar[2]);
271                 progressBar[2].Dispose();
272                 progressBar[2] = null;
273
274                 layout[1].Remove(layout[2]);
275                 layout[2].Dispose();
276                 layout[2] = null;
277                 layout[1].Remove(layout[3]);
278                 layout[3].Dispose();
279                 layout[3] = null;
280
281                 layout[0].Remove(layout[1]);
282                 layout[1].Dispose();
283                 layout[1] = null;
284                 layout[0].Remove(board[0]);
285                 board[0].Dispose();
286                 board[0] = null;
287
288                 NUIApplication.GetDefaultWindow().Remove(layout[0]);
289                 layout[0].Dispose();
290                 layout[0] = null;
291             }
292         }
293     }
294 }