Merge "[Telephony] Sample App implementation."
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / GenListTest8.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 GenListTest8 : TestCaseBase
24     {
25
26         Dictionary<EvasObject, Button> _cacheMap = new Dictionary<EvasObject, Button>();
27         public override string TestName => "GenListTest8";
28         public override string TestDescription => "To test group operation of GenList";
29
30         public override void Run(Window window)
31         {
32             Background bg = new Background(window)
33             {
34                 Color = Color.White,
35                 AlignmentX = -1,
36                 AlignmentY = -1,
37                 WeightX = 1,
38                 WeightY = 1
39             };
40             bg.Show();
41             bg.Lower();
42
43             window.AddResizeObject(bg);
44             Conformant conformant = new Conformant(window);
45             conformant.Show();
46             Box box = new Box(window)
47             {
48                 AlignmentX = -1,
49                 AlignmentY = -1,
50                 WeightX = 1,
51                 WeightY = 1
52             };
53             Check check = new Check(window);
54             check.Show();
55             check.IsChecked = true;
56             check.Text = "Reuse?";
57
58             GenList list = new GenList(window)
59             {
60                 Homogeneous = false,
61                 AlignmentX = -1,
62                 AlignmentY = -1,
63                 WeightX = 1,
64                 WeightY = 1
65             };
66
67             GenItemClass fullyCustomizeClass = new GenItemClass("full")
68             {
69                 GetContentHandler = (obj, part) =>
70                 {
71                     Console.WriteLine("{0} part create requested", part);
72                     var btn = new Button(window)
73                     {
74                         AlignmentX = -1,
75                         WeightX = 1,
76                         Text = (string)obj
77                     };
78                     return btn;
79                 },
80                 ReusableContentHandler = (object data, string part, EvasObject old) =>
81                 {
82                     Console.WriteLine("{0} part reuse requested", part);
83                     if (!check.IsChecked)
84                     {
85                         return null;
86                     }
87                     var btn = old as Button;
88                     btn.Text = (string)data;
89                     return old;
90                 }
91             };
92
93             for (int i = 0; i < 100; i++)
94             {
95                 list.Append(fullyCustomizeClass, string.Format("{0} Item", i), GenListItemType.Normal);
96             }
97
98             list.Show();
99             list.ItemSelected += List_ItemSelected; ;
100             box.Show();
101             box.PackEnd(check);
102             box.PackEnd(list);
103             conformant.SetContent(box);
104         }
105
106         private void List_ItemSelected(object sender, GenListItemEventArgs e)
107         {
108             Console.WriteLine("{0} Item was selected", (string)(e.Item.Data));
109         }
110     }
111 }