Merge "[Telephony] Sample App implementation."
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / ToolbarTest1.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18 using ElmSharp;
19 using System.Collections.Generic;
20
21 namespace ElmSharp.Test
22 {
23     public class ToolbarTest1 : TestCaseBase
24     {
25         Dictionary<ToolbarItem, int> _itemTable = new Dictionary<ToolbarItem, int>();
26         Dictionary<int, ToolbarItem> _reverseItemTable = new Dictionary<int, ToolbarItem>();
27         int currentItemIndex = 0;
28         public override string TestName => "ToolbarTest1";
29         public override string TestDescription => "To test basic operation of Toolbar";
30         public override void Run(Window window)
31         {
32             Conformant conformant = new Conformant(window);
33             conformant.Show();
34             Box outterBox = new Box(window)
35             {
36                 AlignmentX = -1,
37                 AlignmentY = -1,
38                 WeightX = 1,
39                 WeightY = 1,
40                 IsHorizontal = false,
41             };
42             outterBox.Show();
43
44             Toolbar toolbar = new Toolbar(window)
45             {
46                 AlignmentX = -1,
47                 WeightX = 1,
48                 ShrinkMode = ToolbarShrinkMode.Scroll
49             };
50
51             toolbar.Show();
52             outterBox.PackEnd(toolbar);
53
54
55             Scroller scroller = new Scroller(window)
56             {
57                 AlignmentX = -1,
58                 AlignmentY = -1,
59                 WeightX = 1,
60                 WeightY = 1,
61                 ScrollBlock = ScrollBlock.Vertical,
62                 HorizontalPageScrollLimit = 1,
63             };
64             scroller.SetPageSize(1.0, 1.0);
65             scroller.Show();
66
67             Box box = new Box(window)
68             {
69                 AlignmentX = -1,
70                 AlignmentY = -1,
71                 WeightX = 1,
72                 WeightY = 1,
73                 IsHorizontal = true,
74             };
75             box.Show();
76             scroller.SetContent(box);
77
78             var rnd = new Random();
79             for (int i = 0; i < 5; i++)
80             {
81                 int r = rnd.Next(255);
82                 int g = rnd.Next(255);
83                 int b = rnd.Next(255);
84                 Color color = Color.FromRgb(r, g, b);
85                 Rectangle colorBox = new Rectangle(window)
86                 {
87                     AlignmentX = -1,
88                     AlignmentY = -1,
89                     WeightX = 1,
90                     WeightY = 1,
91                     Color = color,
92                     MinimumWidth = window.ScreenSize.Width,
93                 };
94                 colorBox.Show();
95                 box.PackEnd(colorBox);
96                 ToolbarItem item = toolbar.Append(string.Format("{0} Item", i), "home");
97                 _itemTable[item] = i;
98                 _reverseItemTable[i] = item;
99                 item.Selected += (s, e) =>
100                 {
101                     scroller.ScrollTo(_itemTable[(ToolbarItem)s], 0, true);
102                 };
103             }
104             scroller.Scrolled += (s, e) =>
105             {
106                 if (scroller.HorizontalPageIndex != currentItemIndex)
107                 {
108                     currentItemIndex = scroller.HorizontalPageIndex;
109                     _reverseItemTable[currentItemIndex].IsSelected = true;
110                 }
111             };
112             conformant.SetContent(outterBox);
113             outterBox.PackEnd(scroller);
114         }
115     }
116 }