[NUI] Remove the Loading API of Images (#1714)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / LoadingSample.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 LoadingSample : IExample
8     {
9         private TextLabel[] textLabel = new TextLabel[3];
10         private Button[] button = new Button[3];
11         private Loading[] loading = new Loading[2];
12         private View root;
13         private View gridLayout;
14         private View[] layout = new View[4];
15         private string[] imageArray;
16
17         public void Activate()
18         {
19             Window window = NUIApplication.GetDefaultWindow();
20
21             root = new View()
22             {
23                 Size = new Size(1920, 1080),
24                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f)
25             };
26             window.Add(root);
27
28             gridLayout = new View()
29             {
30                 Position = new Position(400, 200),
31                 Size = new Size(1920, 1080)
32             };
33             gridLayout.Layout = new GridLayout()
34             {
35                 Rows = 4,
36                 GridOrientation = GridLayout.Orientation.Horizontal,
37                 
38             };
39             //parent.Layout.Measure(new MeasureSpecification(new LayoutLength(1000), MeasureSpecification.ModeType.Exactly), new MeasureSpecification(new LayoutLength(780), MeasureSpecification.ModeType.Exactly));
40             root.Add(gridLayout);
41
42             imageArray = new string[36];
43             for (int i = 0; i < 36; i++)
44             {
45                 if (i < 10)
46                 {
47                     imageArray[i] = CommonResource.GetFHResourcePath() + "9. Controller/Loading Sequence_Native/loading_0" + i + ".png";
48                 }
49                 else
50                 {
51                     imageArray[i] = CommonResource.GetFHResourcePath() + "9. Controller/Loading Sequence_Native/loading_" + i + ".png";
52                 }
53             }
54
55             CreatePropLayout();
56             CreateAttrLayout();
57         }
58
59         void CreatePropLayout()
60         {
61             textLabel[0] = new TextLabel();
62             textLabel[0].WidthSpecification = 500;
63             textLabel[0].HeightSpecification = 100;
64             //To set spacing between grid cells.
65             textLabel[0].Margin = new Extents(0, 20, 0, 100);
66             textLabel[0].PointSize = 20;
67             textLabel[0].HorizontalAlignment = HorizontalAlignment.Center;
68             textLabel[0].VerticalAlignment = VerticalAlignment.Center;
69             textLabel[0].BackgroundColor = Color.Magenta;
70             textLabel[0].Text = "Property construction";
71             gridLayout.Add(textLabel[0]);
72
73             // layout for loading which is created by properties.
74             // It'll update the visual when framerate is changed, so put loading into a layout.
75             layout[1] = new View();
76             layout[1].Layout = new LinearLayout()
77             {
78                 LinearOrientation = LinearLayout.Orientation.Horizontal,
79                 LinearAlignment = LinearLayout.Alignment.Center
80             };
81             loading[0] = new Loading();
82             loading[0].Size = new Size(100, 100);
83             loading[0].ImageArray = imageArray;
84             layout[1].Add(loading[0]);
85             gridLayout.Add(layout[1]);
86
87             CreatePropBtnLayout();
88
89             textLabel[1] = new TextLabel();
90             textLabel[1].PointSize = 20;
91             textLabel[1].HorizontalAlignment = HorizontalAlignment.Center;
92             textLabel[1].VerticalAlignment = VerticalAlignment.Center;
93             textLabel[1].BackgroundColor = Color.Magenta;
94             textLabel[1].Text = "log pad";
95             textLabel[1].PointSize = 15;
96             gridLayout.Add(textLabel[1]);
97         }
98
99         void CreatePropBtnLayout()
100         {
101             // layout for button.
102             // To avoid button size same as the grid cell.
103             layout[0] = new View() {};
104             layout[0].Layout = new LinearLayout()
105             { 
106                 LinearOrientation = LinearLayout.Orientation.Horizontal,
107                 LinearAlignment = LinearLayout.Alignment.Center,
108                 CellPadding = new Size(10, 50)
109             };
110            
111             button[0] = new Button();
112             button[0].Size = new Size(200, 50);
113             button[0].Text = "FPS++";
114             button[0].PointSize = 15;
115             button[0].BackgroundColor = Color.Green;
116             layout[0].Add(button[0]);
117             button[0].Focusable = true;
118             button[0].ClickEvent += propFpsAdd;
119             FocusManager.Instance.SetCurrentFocusView(button[0]);
120
121             button[1] = new Button();
122             button[1].Size = new Size(200, 50);
123             button[1].Text = "FPS--";
124             button[1].PointSize = 15;
125             button[1].BackgroundColor = Color.Green;
126             layout[0].Add(button[1]);
127             button[1].Focusable = true;
128             button[1].ClickEvent += propFpsMinus;
129             FocusManager.Instance.SetCurrentFocusView(button[1]);
130
131             gridLayout.Add(layout[0]);
132
133             button[0].RightFocusableView = button[1];
134             button[1].LeftFocusableView = button[0];
135         }
136
137         private void CreateAttrLayout()
138         {
139             textLabel[2] = new TextLabel();
140             textLabel[2].PointSize = 20;
141             textLabel[2].HorizontalAlignment = HorizontalAlignment.Center;
142             textLabel[2].VerticalAlignment = VerticalAlignment.Center;
143             textLabel[2].BackgroundColor = Color.Magenta;
144             textLabel[2].Text = "Attribute construction";
145             gridLayout.Add(textLabel[2]);
146
147             // layout for loading which is created by attributes.
148             // It'll update the visual when framerate is changed, so put loading into a layout.
149             layout[2] = new View();
150             layout[2].Layout = new LinearLayout()
151             {
152                 LinearOrientation = LinearLayout.Orientation.Horizontal,
153                 LinearAlignment = LinearLayout.Alignment.Center
154             };
155             LoadingStyle style = new LoadingStyle
156             {
157                 Images = imageArray
158             };
159             loading[1] = new Loading(style);
160             loading[1].Size = new Size(100, 100);
161             layout[2].Add(loading[1]);
162             gridLayout.Add(layout[2]);
163
164             // layout for button.
165             // To avoid button size same as the grid cell.
166             layout[3] = new View() { };
167             layout[3].Layout = new LinearLayout()
168             {
169                 LinearOrientation = LinearLayout.Orientation.Horizontal,
170                 LinearAlignment = LinearLayout.Alignment.Center
171             };
172             button[2] = new Button();
173             button[2].Size = new Size(400, 50);
174             button[2].Text = "Normal Loading";
175             button[2].PointSize = 15;
176             button[2].BackgroundColor = Color.Green;
177             layout[3].Add(button[2]);
178             gridLayout.Add(layout[3]);
179             button[2].Focusable = true;
180             FocusManager.Instance.SetCurrentFocusView(button[2]);
181         }
182
183         private void propFpsAdd(object sender, global::System.EventArgs e)
184         {
185             loading[0].FrameRate += 1;
186             textLabel[1].Text = "loading1_1 FPS: " + loading[0].FrameRate.ToString();
187         }
188
189         private void propFpsMinus(object sender, global::System.EventArgs e)
190         {
191             loading[0].FrameRate -= 1;
192             textLabel[1].Text = "loading1_1 FPS: " + loading[0].FrameRate.ToString();
193         }
194
195         private void FocusLost(object sender, global::System.EventArgs e)
196         {
197             View view = sender as View;
198             view.Scale = new Vector3(1.2f, 1.2f, 1.0f);
199         }
200
201         private void FocusGained(object sender, global::System.EventArgs e)
202         {
203             View view = sender as View;
204             view.Scale = new Vector3(1.0f, 1.0f, 1.0f);
205         }
206
207         public void Deactivate()
208         {
209             if (root != null)
210             {
211                 layout[0].Remove(button[0]);
212                 button[0].Dispose();
213                 button[0] = null;
214
215                 layout[0].Remove(button[1]);
216                 button[1].Dispose();
217                 button[1] = null;
218
219                 gridLayout.Remove(layout[0]);
220                 layout[0].Dispose();
221                 layout[0] = null;
222
223                 gridLayout.Remove(textLabel[0]);
224                 textLabel[0].Dispose();
225                 textLabel[0] = null;
226
227                 layout[1].Remove(loading[0]);
228                 loading[0].Dispose();
229                 loading[0] = null;
230
231                 gridLayout.Remove(layout[1]);
232                 layout[1].Dispose();
233                 layout[1] = null;
234
235                 gridLayout.Remove(textLabel[1]);
236                 textLabel[1].Dispose();
237                 textLabel[1] = null;
238
239                 gridLayout.Remove(textLabel[2]);
240                 textLabel[2].Dispose();
241                 textLabel[2] = null;
242
243                 layout[2].Remove(loading[1]);
244                 loading[1].Dispose();
245                 loading[1] = null;
246
247                 gridLayout.Remove(layout[2]);
248                 layout[2].Dispose();
249                 layout[2] = null;
250
251                 layout[3].Remove(button[2]);
252                 button[2].Dispose();
253                 button[2] = null;
254
255                 gridLayout.Remove(layout[3]);
256                 layout[3].Dispose();
257                 layout[3] = null;
258
259                 root.Remove(gridLayout);
260                 gridLayout.Dispose();
261                 gridLayout = null;
262
263                 NUIApplication.GetDefaultWindow().Remove(root);
264                 root.Dispose();
265                 root = null;
266             }
267         }
268     }
269 }