Release 10.0.0.17837
[platform/core/csapi/tizenfx.git] / test / PerformanceTest / PerformanceTest.cs
1 using System.Net.Mime;
2 using System.Drawing;
3 using System.ComponentModel;
4 /*
5  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 using System;
22 using System.Linq;
23 using System.Collections.Generic;
24 using Tizen.NUI;
25 using Tizen.NUI.Components;
26 using Tizen.NUI.BaseComponents;
27 using Tizen.NUI.Binding;
28 using System.Reflection;
29
30 namespace PerformanceTest
31 {
32     class Program : NUIApplication
33     {
34         private Window window;
35         private Navigator navigator;
36         private ContentPage page;
37         private string path;
38
39         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
40         {
41             // FIXME:: Navigator should provide Back/Escape event processing.
42             if (e.Key.State == Key.StateType.Up)
43             {
44                 if (e.Key.KeyPressedName == "Escape" || e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "BackSpace")
45                 {
46                         navigator?.Pop();
47                         Exit();
48                 }
49             }
50         }
51         protected override void OnCreate()
52         {
53             base.OnCreate();
54             Initialize();
55             SetMainPage();
56
57             //enable FocusManger default algorithm
58             //FocusManager.Instance.EnableDefaultAlgorithm(true);
59         }
60         private void Initialize()
61         {
62             window = GetDefaultWindow();
63             window.Title = "세탁코스";
64             window.KeyEvent += OnKeyEvent;
65             path = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
66         }
67
68         private View GetAILaundryCard()
69         {
70
71             var aiLaundry = new View()
72             {
73                 BackgroundColor = new Tizen.NUI.Color(0.4f, 0.4f, 0.4f, 0.5f),
74                 CornerRadius = 10,
75                 WidthSpecification = 500,
76                 HeightSpecification = LayoutParamPolicies.MatchParent,
77                 Padding = new Extents(50, 50, 10, 10),
78                 Layout = new LinearLayout()
79                 {
80                     LinearOrientation = LinearLayout.Orientation.Vertical,
81                     HorizontalAlignment = HorizontalAlignment.Center,
82                     VerticalAlignment = VerticalAlignment.Top,
83                     CellPadding = new Size2D(0, 30),
84                 }
85             };
86
87             var laundryTitle = new TextLabel()
88             {
89                 Text = "AI 맞춤세탁",
90                 PointSize = 30,
91             };
92             aiLaundry.Add(laundryTitle);
93
94             var laundryDuration = new TextLabel()
95             {
96                 Text = "1시간 20분",
97                 PointSize = 20,
98             };
99             aiLaundry.Add(laundryDuration);
100
101             var aiLaundryIconView = new View()
102             {
103                 WidthSpecification = LayoutParamPolicies.MatchParent,
104                 HeightSpecification = LayoutParamPolicies.MatchParent,
105                 Layout = new LinearLayout()
106                 {
107                     LinearOrientation = LinearLayout.Orientation.Horizontal,
108                     HorizontalAlignment = HorizontalAlignment.Center,
109                     VerticalAlignment = VerticalAlignment.Center,
110                     CellPadding = new Size2D(10, 0),
111                 }
112             };
113
114
115             var tempIcon = new ImageView()
116             {
117                 ResourceUrl = path + "temp.png",
118                 WidthSpecification = 50,
119                 HeightSpecification = 50,
120             };
121             aiLaundryIconView.Add(tempIcon);
122
123             var cleaningIcon = new ImageView()
124             {
125                 ResourceUrl = path + "cleaning.png",
126                 WidthSpecification = 50,
127                 HeightSpecification = 50,
128             };
129             aiLaundryIconView.Add(cleaningIcon);
130
131             var dryIcon = new ImageView()
132             {
133                 ResourceUrl = path + "dry.png",
134                 WidthSpecification = 50,
135                 HeightSpecification = 50,
136             };
137             aiLaundryIconView.Add(dryIcon);
138             aiLaundry.Add(aiLaundryIconView);
139
140             return aiLaundry;
141         }
142
143         private View GetStdLaundryCard()
144         {
145
146             var stdLaundry = new View()
147             {
148                 BackgroundColor = new Tizen.NUI.Color(0.4f, 0.4f, 0.4f, 0.5f),
149                 CornerRadius = 10,
150                 WidthSpecification = 250,
151                 HeightSpecification = LayoutParamPolicies.MatchParent,
152                 Padding = new Extents(50, 50, 10, 10),
153                 Layout = new LinearLayout()
154                 {
155                     LinearOrientation = LinearLayout.Orientation.Vertical,
156                     HorizontalAlignment = HorizontalAlignment.Center,
157                     VerticalAlignment = VerticalAlignment.Top,
158                     CellPadding = new Size2D(0, 30),
159                 }
160             };
161
162             var laundryTitle = new TextLabel()
163             {
164                 Text = "표준세탁",
165                 PointSize = 30,
166             };
167             stdLaundry.Add(laundryTitle);
168
169             var laundryDuration = new TextLabel()
170             {
171                 Text = "59분",
172                 PointSize = 20,
173             };
174             stdLaundry.Add(laundryDuration);
175
176             return stdLaundry;
177         }
178
179         private View GetPetCareLaundryCard()
180         {
181
182             var petCareLaundry = new View()
183             {
184                 BackgroundColor = new Tizen.NUI.Color(0.4f, 0.4f, 0.4f, 0.5f),
185                 CornerRadius = 10,
186                 WidthSpecification = 250,
187                 HeightSpecification = LayoutParamPolicies.MatchParent,
188                 Padding = new Extents(50, 50, 10, 10),
189                 Layout = new LinearLayout()
190                 {
191                     LinearOrientation = LinearLayout.Orientation.Vertical,
192                     HorizontalAlignment = HorizontalAlignment.Center,
193                     VerticalAlignment = VerticalAlignment.Top,
194                     CellPadding = new Size2D(0, 30),
195                 }
196             };
197
198             var laundryTitle = new TextLabel()
199             {
200                 Text = "펫케어세탁",
201                 PointSize = 30,
202             };
203             petCareLaundry.Add(laundryTitle);
204
205             var laundryDuration = new TextLabel()
206             {
207                 Text = "2시간 30분",
208                 PointSize = 20,
209             };
210             petCareLaundry.Add(laundryDuration);
211
212             return petCareLaundry;
213         }
214
215         private View GetLaundryView()
216         {
217             var aiCard = GetAILaundryCard();
218             var stdCard = GetStdLaundryCard();
219             var petCareCard = GetPetCareLaundryCard();
220
221
222             var laundryContent = new View()
223             {
224                 WidthSpecification = 1070,
225                 HeightSpecification = LayoutParamPolicies.MatchParent,
226                 Padding = new Extents(10, 10, 10, 10),
227                 Layout = new LinearLayout()
228                 {
229                     LinearOrientation = LinearLayout.Orientation.Horizontal,
230                     HorizontalAlignment = HorizontalAlignment.Center,
231                     VerticalAlignment = VerticalAlignment.Center,
232                     CellPadding = new Size2D(20, 0),
233                 }
234             };
235             laundryContent.Add(aiCard);
236             laundryContent.Add(stdCard);
237             laundryContent.Add(petCareCard);
238
239             return laundryContent;
240         }
241
242         private View GetDryerCard(string title, string duration, bool start, float progress = 0f)
243         {
244             var dryCard  = new View()
245             {
246                 BackgroundColor = new Tizen.NUI.Color(0.4f, 0.4f, 0.4f, 0.5f),
247                 CornerRadius = 10,
248                 WidthSpecification = LayoutParamPolicies.MatchParent,
249                 HeightSpecification = LayoutParamPolicies.MatchParent,
250                 Padding = new Extents(10, 10, 10, 10),
251                 Layout = new LinearLayout()
252                 {
253                     LinearOrientation = LinearLayout.Orientation.Vertical,
254                     HorizontalAlignment = HorizontalAlignment.Center,
255                     VerticalAlignment = VerticalAlignment.Center,
256                     CellPadding = new Size2D(0, 10),
257                 }
258             };
259
260             var laundryTitle = new TextLabel()
261             {
262                 Text = title,
263                 PointSize = 30,
264             };
265             dryCard.Add(laundryTitle);
266
267             var dryDurationPlay  = new View()
268             {
269                 WidthSpecification = LayoutParamPolicies.MatchParent,
270                 HeightSpecification = LayoutParamPolicies.WrapContent,
271                 Padding = new Extents(0, 0, 10, 10),
272                 Layout = new LinearLayout()
273                 {
274                     LinearOrientation = LinearLayout.Orientation.Horizontal,
275                     HorizontalAlignment = HorizontalAlignment.Center,
276                     VerticalAlignment = VerticalAlignment.Center,
277                     CellPadding = new Size2D(0, 10),
278                 }
279             };
280
281             var laundryDuration = new TextLabel()
282             {
283                 WidthSpecification = LayoutParamPolicies.MatchParent,
284                 Text = duration,
285                 PointSize = 20,
286             };
287             dryDurationPlay.Add(laundryDuration);
288
289             var laundryPauseIcon = new ImageView()
290             {
291                 ResourceUrl = path + (start? "pause.png" :"play.png"),
292                 WidthSpecification = 50,
293                 HeightSpecification = 50,
294             };
295             dryDurationPlay.Add(laundryPauseIcon);
296             dryCard.Add(dryDurationPlay);
297
298             var dryProgress = new Progress()
299             {
300                 WidthSpecification = LayoutParamPolicies.MatchParent,
301                 MinValue = 0f,
302                 MaxValue = 1f,
303                 CurrentValue = progress,
304             };
305             dryCard.Add(dryProgress);
306
307             return dryCard;
308         }
309
310         private View GetDryerView()
311         {
312             var stdDryerdard = GetDryerCard("표준 건조", "1시간 20분", true, 0.35f);
313             var aiDryerdard = GetDryerCard("AI 건조", "2시간 00분", false);
314
315             var dryerContent = new View()
316             {
317                 WidthSpecification = 1070,
318                 HeightSpecification = LayoutParamPolicies.MatchParent,
319                 Padding = new Extents(10, 10, 10, 10),
320                 Layout = new LinearLayout()
321                 {
322                     LinearOrientation = LinearLayout.Orientation.Vertical,
323                     HorizontalAlignment = HorizontalAlignment.Center,
324                     VerticalAlignment = VerticalAlignment.Center,
325                     CellPadding = new Size2D(0, 20),
326                 }
327             };
328             dryerContent.Add(stdDryerdard);
329             dryerContent.Add(aiDryerdard);
330
331             return dryerContent;
332         }
333
334         private void SetMainPage()
335         {
336             var rootView = new View()
337             {
338                 BackgroundColor = Tizen.NUI.Color.Black,
339                 WidthSpecification = LayoutParamPolicies.MatchParent,
340                 HeightSpecification = LayoutParamPolicies.MatchParent,
341                 Padding = new Extents(5, 5, 5, 5),
342                 Layout = new LinearLayout()
343                 {
344                     LinearOrientation = LinearLayout.Orientation.Vertical,
345                     HorizontalAlignment = HorizontalAlignment.Center,
346                     VerticalAlignment = VerticalAlignment.Top,
347                     CellPadding = new Size2D(0, 0),
348                 }
349             };
350
351             var luandryContent = GetLaundryView();
352             var dryerContent = GetDryerView();
353
354             var contentView = new ScrollableBase()
355             {
356                 BackgroundColor = new Tizen.NUI.Color(0.2f,0.2f,0.2f,0.5f),
357                 WidthSpecification = LayoutParamPolicies.MatchParent,
358                 HeightSpecification = LayoutParamPolicies.MatchParent,
359                 Padding = new Extents(5, 5, 5, 5),
360                 ScrollingDirection = ScrollableBase.Direction.Horizontal,
361                 SnapToPage = true,
362                 Layout = new LinearLayout()
363                 {
364                     LinearOrientation = LinearLayout.Orientation.Horizontal,
365                     HorizontalAlignment = HorizontalAlignment.Begin,
366                     VerticalAlignment = VerticalAlignment.Center,
367                     CellPadding = new Size2D(10, 0),
368                 }
369             };
370             contentView.Add(luandryContent);
371             contentView.Add(dryerContent);
372
373             var laundryBtn = new Button()
374             {
375                 CornerRadius = 0,
376                 Text = "세탁기"
377             };
378
379             laundryBtn.Clicked += (object sender, ClickedEventArgs e) =>
380             {
381                 contentView.ScrollToIndex(0);
382             };
383
384             var dryerBtn = new Button()
385             {
386                 CornerRadius = 0,
387                 Text = "건조기"
388             };
389
390             dryerBtn.Clicked += (object sender, ClickedEventArgs e) =>
391             {
392                 contentView.ScrollToIndex(1);
393             };
394
395             var buttonView = new View()
396             {
397                 WidthSpecification = LayoutParamPolicies.MatchParent,
398                 HeightSpecification = 80,
399                 Layout = new LinearLayout()
400                 {
401                     LinearOrientation = LinearLayout.Orientation.Horizontal,
402                     HorizontalAlignment = HorizontalAlignment.Begin,
403                     VerticalAlignment = VerticalAlignment.Center,
404                     CellPadding = new Size2D(10, 0),
405                 }
406             };
407
408             buttonView.Add(laundryBtn);
409             buttonView.Add(dryerBtn);
410
411             rootView.Add(buttonView);
412             rootView.Add(contentView);
413
414             window.Add(rootView);
415         }
416
417 /*
418         private void FullGC()
419         {
420             global::System.GC.Collect();
421             global::System.GC.WaitForPendingFinalizers();
422             global::System.GC.Collect();
423         }
424 */
425         static void Main(string[] args)
426         {
427             var app = new Program();
428             app.Run(args);
429         }
430     }
431 }