Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / PlaceHolderImageTest.cs
1 /*
2  * Copyright(c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using Tizen.NUI.BaseComponents;
19
20 namespace Tizen.NUI.Samples
21 {
22     using log = Tizen.Log;
23     public class PlaceHolderImageSample : IExample
24     {
25         private const string tag = "NUITEST";
26         private Window mainWin;
27         private ImageView[] imageViews = null;
28         const int imageWidth = 500;
29         const int imageHeight = 500;
30         const int imageMax = 6;
31         Timer mTimer;
32         int image_count = 0;
33
34         private static string[] url = new string[]
35         {
36             "https://images.pexels.com/photos/16027424/pexels-photo-16027424.jpeg",
37             "https://images.pexels.com/photos/214574/pexels-photo-214574.jpeg",
38             "https://images.pexels.com/photos/39853/woman-girl-freedom-happy-39853.jpeg",
39             "https://images.pexels.com/photos/842711/pexels-photo-842711.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2",
40             "https://images.pexels.com/photos/15828302/pexels-photo-15828302.jpeg",
41             "",
42         };
43
44         public void Activate()
45         {
46             Initialize();
47         }
48
49         public void Deactivate()
50         {
51         }
52
53         private void Initialize()
54         {
55             mainWin = NUIApplication.GetDefaultWindow();
56             mainWin.BackgroundColor = Color.White;
57             mainWin.WindowSize = new Size2D(1920,1080);
58             Size2D windowSize = new Size2D(mainWin.Size.Width,mainWin.Size.Height);
59
60             imageViews = new ImageView[imageMax];
61             for(int i=0; i<imageMax; i++)
62             {
63                 int width = (i%(imageMax/2))*imageWidth;
64                 int height = (i/(imageMax/2))*imageHeight;
65                 imageViews[i] = new ImageView();
66                 imageViews[i].Size2D = new Size2D(imageWidth, imageHeight);
67                 imageViews[i].Position2D = new Position2D(width,height);
68                 imageViews[i].ResourceUrl = url[i];
69                 imageViews[i].PlaceHolderUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "images/placeholder_image.png";
70                 imageViews[i].TransitionEffect = true;
71                 mainWin.Add(imageViews[i]);
72             }
73
74             mTimer = new Timer(5000);
75             mTimer.Tick += ((object target, Timer.TickEventArgs args) =>
76             {
77                 image_count++;
78                 for(int i=0;i<imageMax;i++)
79                 {
80                     imageViews[i].ResourceUrl = url[(image_count+i)%imageMax];
81                 }
82                 return true;
83             });
84
85             mTimer.Start();
86         }
87     }
88 }