Merge "[Telephony] Sample App implementation."
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / IndexTest1.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     class IndexTest1 : TestCaseBase
24     {
25         Dictionary<IndexItem, GenListItem> _indexTable = new Dictionary<IndexItem, GenListItem>();
26         public override string TestName => "IndexTest1";
27         public override string TestDescription => "To test group operation of Index";
28         public override void Run(Window window)
29         {
30             Conformant conformant = new Conformant(window);
31             conformant.Show();
32             Box box = new Box(window)
33             {
34                 AlignmentX = -1,
35                 AlignmentY = -1,
36                 WeightX = 1,
37                 WeightY = 1,
38                 IsHorizontal = true,
39             };
40             box.Show();
41             GenList list = new GenList(window)
42             {
43                 Homogeneous = false,
44                 AlignmentX = -1,
45                 AlignmentY = -1,
46                 WeightX = 1,
47                 WeightY = 1
48             };
49             list.Show();
50             Index index = new Index(window)
51             {
52                 IsHorizontal = false,
53                 AlignmentY = -1,
54                 WeightY = 1,
55                 MinimumWidth = 100,
56                 AutoHide = false,
57                 Style = "fastscroll"
58             };
59             index.Show();
60
61             GenItemClass groupClass = new GenItemClass("group_index")
62             {
63                 GetTextHandler = (obj, part) =>
64                 {
65                     return string.Format("{0} - {1}", (string)obj, part);
66                 }
67             };
68
69             GenListItem[] groups = new GenListItem[10];
70
71             for (int i = 0; i < 10; i++)
72             {
73                 groups[i] = list.Append(groupClass, string.Format("{0}", i), GenListItemType.Group);
74                 var indexitem = index.Append(string.Format("{0}", i));
75                 indexitem.Selected += (s, e) =>
76                 {
77                     Console.WriteLine("Index selected : {0}", ((IndexItem)s).Text);
78                     list.ScrollTo(_indexTable[(IndexItem)s], ScrollToPosition.In, true);
79                 };
80                 _indexTable[indexitem] = groups[i];
81             }
82
83             GenItemClass defaultClass = new GenItemClass("default")
84             {
85                 GetTextHandler = (obj, part) =>
86                 {
87                     return string.Format("{0} - {1}", (string)obj, part);
88                 }
89             };
90
91             for (int j = 0; j < 10; j++)
92             {
93                 for (int i = 0; i < 20; i++)
94                 {
95                     list.Append(defaultClass, string.Format("{0} Item", i), GenListItemType.Normal, groups[j]);
96                 }
97             }
98
99             list.ItemSelected += List_ItemSelected;
100             index.Update(0);
101             box.PackEnd(list);
102             box.PackEnd(index);
103             box.SetLayoutCallback(() =>
104             {
105                 list.Geometry = box.Geometry;
106                 index.Geometry = box.Geometry;
107             });
108             conformant.SetContent(box);
109         }
110
111         private void List_ItemSelected(object sender, GenListItemEventArgs e)
112         {
113             Console.WriteLine("{0} Item was selected", (string)(e.Item.Data));
114         }
115     }
116 }