Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / PaginationSample.cs
1 using Tizen.NUI.Components;
2 using Tizen.NUI.BaseComponents;
3
4 namespace Tizen.NUI.Samples
5 {
6     public class PaginationSample : IExample
7     {
8         private TextLabel[] board = new TextLabel[2];
9         private Pagination[] pagination = new Pagination[2];
10         private View[] layout = new View[3];
11
12         private readonly int PAGE_COUNT = 5;
13
14         public void Activate()
15         {
16             Window window = NUIApplication.GetDefaultWindow();
17
18             // Root layout.
19             layout[0] = new View()
20             {
21                 Size = new Size(1920, 1080),
22                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
23             };
24             layout[0].Layout = new LinearLayout()
25             {
26                 LinearOrientation = LinearLayout.Orientation.Vertical,
27                 LinearAlignment = LinearLayout.Alignment.Center,
28                 CellPadding = new Size(20, 50)
29             };
30             window.Add(layout[0]);
31             window.KeyEvent += Window_KeyEvent;
32
33             // A pagination sample created by properties will be added to this layout.
34             layout[1]= new View()
35             {
36                 Size = new Size(700, 70),
37                 Layout = new LinearLayout()
38                 {
39                     LinearOrientation = LinearLayout.Orientation.Horizontal,
40                     LinearAlignment = LinearLayout.Alignment.Center,
41                     CellPadding = new Size(20, 50)
42                 }
43             };
44             layout[0].Add(layout[1]);
45
46             // A pagination sample created by attributes will be added to this layout.
47             layout[2] = new View()
48             {
49                 Size = new Size(700, 70),
50                 Layout = new LinearLayout()
51                 {
52                     LinearOrientation = LinearLayout.Orientation.Horizontal,
53                     LinearAlignment = LinearLayout.Alignment.Center,
54                     CellPadding = new Size(20, 50)
55                 }
56             };
57             layout[0].Add(layout[2]);
58
59             createBorads();
60
61             ///////////////////////////////////////////////Create by Properties//////////////////////////////////////////////////////////
62             pagination[0] = new Pagination();
63             var indicatorImageUrlStyle = new PaginationStyle()
64             {
65                 IndicatorSize = new Size(26, 26),
66                 IndicatorSpacing = 8,
67                 IndicatorImageUrl = new Selector<string>
68                 {
69                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/pagination_ic_nor.png",
70                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/pagination_ic_sel.png"
71                 }
72             };
73             pagination[0].ApplyStyle(indicatorImageUrlStyle);
74             pagination[0].Name = "Pagination1";
75             pagination[0].Size = new Size(300, 50);
76             pagination[0].BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.6f);
77             pagination[0].IndicatorCount = PAGE_COUNT;
78             pagination[0].SelectedIndex = 0;
79             layout[1].Add(pagination[0]);
80
81             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
82             PaginationStyle style = new PaginationStyle()
83             {
84                 IndicatorSize = new Size(15, 15),
85                 IndicatorSpacing = 20,
86                 IndicatorImageUrl = new Selector<string>
87                 {
88                     Normal = CommonResource.GetFHResourcePath() + "9. Controller/pagination_ic_nor.png",
89                     Selected = CommonResource.GetFHResourcePath() + "9. Controller/pagination_ic_sel.png"
90                 }
91             };
92             pagination[1] = new Pagination(style);
93             pagination[1].Name = "Pagination2";
94             pagination[1].Size = new Size(300, 50);
95             pagination[1].BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.6f);
96             pagination[1].IndicatorCount = PAGE_COUNT;
97             pagination[1].SelectedIndex = 0;
98             layout[2].Add(pagination[1]);
99         }
100
101         void createBorads()
102         {
103             board[0] = new TextLabel();
104             board[0].Size = new Size(300, 50);
105             board[0].PointSize = 15;
106             board[0].HorizontalAlignment = HorizontalAlignment.Center;
107             board[0].VerticalAlignment = VerticalAlignment.Center;
108             board[0].BackgroundColor = Color.Magenta;
109             board[0].Text = "Property construction";
110             layout[1].Add(board[0]);
111
112             board[1] = new TextLabel();
113             board[1].Size = new Size(300, 50);
114             board[1].PointSize = 15;
115             board[1].HorizontalAlignment = HorizontalAlignment.Center;
116             board[1].VerticalAlignment = VerticalAlignment.Center;
117             board[1].BackgroundColor = Color.Magenta;
118             board[1].Text = "Attribute construction";
119             layout[2].Add(board[1]);
120         }
121
122         private void Window_KeyEvent(object sender, Window.KeyEventArgs e)
123         {
124             if (e.Key.State == Key.StateType.Down)
125             {
126                 if (e.Key.KeyPressedName == "Left")
127                 {
128                     if (pagination[0].SelectedIndex > 0)
129                     {
130                         pagination[0].SelectedIndex = pagination[0].SelectedIndex - 1;
131                     }
132                     if (pagination[1].SelectedIndex > 0)
133                     {
134                         pagination[1].SelectedIndex = pagination[1].SelectedIndex - 1;
135                     }
136                 }
137                 else if (e.Key.KeyPressedName == "Right")
138                 {
139                     if (pagination[0].SelectedIndex < pagination[0].IndicatorCount - 1)
140                     {
141                         pagination[0].SelectedIndex = pagination[0].SelectedIndex + 1;
142                     }
143                     if (pagination[1].SelectedIndex < pagination[1].IndicatorCount - 1)
144                     {
145                         pagination[1].SelectedIndex = pagination[1].SelectedIndex + 1;
146                     }
147                 }
148             }
149         }
150
151         public void Deactivate()
152         {
153             Window window = NUIApplication.GetDefaultWindow();
154             window.KeyEvent -= Window_KeyEvent;
155
156             if (layout[0] != null)
157             {
158                 layout[1].Remove(board[0]);
159                 board[0].Dispose();
160                 board[0] = null;
161
162                 layout[1].Remove(pagination[0]);
163                 pagination[0].Dispose();
164                 pagination[0] = null;
165
166                 layout[0].Remove(layout[1]);
167                 layout[1].Dispose();
168                 layout[1] = null;
169
170                 layout[2].Remove(board[1]);
171                 board[1].Dispose();
172                 board[1] = null;
173
174                 layout[2].Remove(pagination[1]);
175                 pagination[1].Dispose();
176                 pagination[1] = null;
177
178                 layout[0].Remove(layout[2]);
179                 layout[2].Dispose();
180                 layout[2] = null;
181
182                 window.Remove(layout[0]);
183                 layout[0].Dispose();
184                 layout[0] = null;
185             }
186         }
187     }
188 }