Merge remote-tracking branch 'origin/master' into tizen
[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[3];
10         private Button[] button = new Button[2];
11         private Progress[] progressBar = new Progress[3];
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             layout[1].Add(layout[2]);
71             layout[1].Add(layout[3]);
72
73             board[0] = new TextLabel();
74             board[0].WidthSpecification = 900;
75             board[0].HeightSpecification = 100;
76             board[0].PointSize = 30;
77             board[0].HorizontalAlignment = HorizontalAlignment.Center;
78             board[0].VerticalAlignment = VerticalAlignment.Center;
79             board[0].BackgroundColor = Color.Magenta;
80             board[0].Text = "log pad";
81             layout[0].Add(board[0]);
82             board[0].Focusable = true;
83             board[0].FocusGained += Board_FocusGained;
84             board[0].FocusLost += Board_FocusLost;
85             board[0].UpFocusableView = button[0];
86             FocusManager.Instance.SetCurrentFocusView(button[0]);
87         }
88
89         void CreatePropElements()
90         {
91             ///////////////////////////////////////////////Create by Properties//////////////////////////////////////////////////////////
92             board[1] = new TextLabel();
93             board[1].WidthSpecification = 380;
94             board[1].HeightSpecification = 70;
95             board[1].PointSize = 20;
96             board[1].HorizontalAlignment = HorizontalAlignment.Center;
97             board[1].VerticalAlignment = VerticalAlignment.Center;
98             board[1].BackgroundColor = Color.Magenta;
99             board[1].Text = "Property construction";
100             layout[2].Add(board[1]);
101             board[1].Focusable = true;
102             board[1].FocusGained += Board_FocusGained;
103             board[1].FocusLost += Board_FocusLost;
104
105             progressBar[0] = new Progress();
106             progressBar[0].WidthSpecification = 240;
107             progressBar[0].HeightSpecification = 4;
108             progressBar[0].MaxValue = 100;
109             progressBar[0].MinValue = 0;
110             progressBar[0].CurrentValue = 45;
111             layout[2].Add(progressBar[0]);
112
113             progressBar[1] = new Progress();
114             progressBar[1].WidthSpecification = 240;
115             progressBar[1].HeightSpecification = 4;
116             progressBar[1].MaxValue = 100;
117             progressBar[1].MinValue = 0;
118             progressBar[1].CurrentValue = 30;
119             progressBar[1].TrackColor = Color.Yellow;
120             progressBar[1].ProgressColor = Color.Black;
121             layout[2].Add(progressBar[1]);
122
123             button[0] = new Button();
124             button[0].WidthSpecification = 140;
125             button[0].HeightSpecification = 50;
126             button[0].Text = "+";
127             button[0].BackgroundColor = Color.Green;
128             layout[2].Add(button[0]);
129             button[0].Focusable = true;
130             button[0].Clicked += ProgressAdd;
131
132             button[1] = new Button();
133             button[1].WidthSpecification = 140;
134             button[1].HeightSpecification = 50;
135             button[1].Text = "-";
136             button[1].BackgroundColor = Color.Green;
137             layout[2].Add(button[1]);
138             button[1].Focusable = true;
139             button[1].Clicked += ProgressMinus;
140         }
141
142         private void CreateAttrElements()
143         {
144             ///////////////////////////////////////////////Create by attributes//////////////////////////////////////////////////////////
145             board[2] = new TextLabel();
146             board[2].WidthSpecification = 380;
147             board[2].HeightSpecification = 70;
148             board[2].PointSize = 20;
149             board[2].HorizontalAlignment = HorizontalAlignment.Center;
150             board[2].VerticalAlignment = VerticalAlignment.Center;
151             board[2].BackgroundColor = Color.Magenta;
152             board[2].Text = "Attribute construction";
153             layout[3].Add(board[2]);
154             board[2].Focusable = true;
155             board[2].FocusGained += Board_FocusGained;
156             board[2].FocusLost += Board_FocusLost;
157
158             ProgressStyle attr = new ProgressStyle
159             {
160                 Track = new ImageViewStyle
161                 {
162                     BackgroundColor = new Selector<Color>
163                     {
164                         All = Color.Cyan
165                     }
166                 },
167                 Progress = new ImageViewStyle
168                 {
169                     BackgroundColor = new Selector<Color>
170                     {
171                         All = Color.Red
172                     }
173                 },
174                 Buffer = new ImageViewStyle
175                 {
176                     BackgroundColor = new Selector<Color>
177                     {
178                         All = Color.Green
179                     }
180                 }
181             };
182             progressBar[2] = new Progress(attr);
183             progressBar[2].WidthSpecification = 240;
184             progressBar[2].HeightSpecification = 4;
185             progressBar[2].MaxValue = 100;
186             progressBar[2].MinValue = 0;
187             progressBar[2].CurrentValue = 30;
188             layout[3].Add(progressBar[2]);
189         }
190
191         private void Board_FocusLost(object sender, global::System.EventArgs e)
192         {
193             board[0].BackgroundColor = Color.Magenta;
194         }
195
196         private void Board_FocusGained(object sender, global::System.EventArgs e)
197         {
198             board[0].BackgroundColor = Color.Cyan;
199         }
200
201         private void ProgressAdd(object sender, global::System.EventArgs e)
202         {
203             if (progressBar[0].CurrentValue == 100)
204             {
205                 board[0].Text = "Current value is: 100";
206             }
207             else
208             {
209                 board[0].Text = "Current value is: " + ++progressBar[0].CurrentValue;
210             }
211         }
212         private void ProgressMinus(object sender, global::System.EventArgs e)
213         {
214             if (progressBar[0].CurrentValue == 0)
215             {
216                 board[0].Text = "Current value is: 0";
217             }
218             else
219             {
220                 board[0].Text = "Current value is: " + --progressBar[0].CurrentValue;
221             }
222         }
223
224         public void Deactivate()
225         {
226             if (layout[0] != null)
227             {
228                 layout[2].Remove(board[1]);
229                 board[1].Dispose();
230                 board[1] = null;
231                 layout[2].Remove(progressBar[0]);
232                 progressBar[0].Dispose();
233                 progressBar[0] = null;
234                 layout[2].Remove(progressBar[1]);
235                 progressBar[1].Dispose();
236                 progressBar[1] = null;
237                 layout[2].Remove(button[0]);
238                 button[0].Dispose();
239                 button[0] = null;
240                 layout[2].Remove(button[1]);
241                 button[1].Dispose();
242                 button[1] = null;
243
244                 layout[3].Remove(board[2]);
245                 board[2].Dispose();
246                 board[2] = null;
247                 layout[3].Remove(progressBar[2]);
248                 progressBar[2].Dispose();
249                 progressBar[2] = null;
250
251                 layout[1].Remove(layout[2]);
252                 layout[2].Dispose();
253                 layout[2] = null;
254                 layout[1].Remove(layout[3]);
255                 layout[3].Dispose();
256                 layout[3] = null;
257
258                 layout[0].Remove(layout[1]);
259                 layout[1].Dispose();
260                 layout[1] = null;
261                 layout[0].Remove(board[0]);
262                 board[0].Dispose();
263                 board[0] = null;
264
265                 NUIApplication.GetDefaultWindow().Remove(layout[0]);
266                 layout[0].Dispose();
267                 layout[0] = null;
268             }
269         }
270     }
271 }