[NUI] integration from DevelNUI to master (#3309)
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / CollectionViewFocusTest / CollectionViewItem.xaml.cs
1 /*
2  * Copyright(c) 2021 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 using Tizen.NUI.BaseComponents;
18 using Tizen.NUI;
19 using System;
20
21 namespace NUITizenGallery
22 {
23     public partial class CollectionViewItemClickedEventArgs : EventArgs
24     {
25         public int ClickedItemId = -1;
26         public CollectionViewItemClickedEventArgs(int id)
27         {
28             ClickedItemId = id;
29         }
30     }
31
32     public partial class CollectionViewItem : View
33     {
34         private int ItemId = -1;
35         public event EventHandler<CollectionViewItemClickedEventArgs> CollectionViewItemClicked;
36
37         private Animation animation;
38
39         public CollectionViewItem(int id, string poster, string name, string description)
40         {
41             ItemId = id;
42             InitializeComponent();
43
44             ItemPoster.ResourceUrl = poster;
45             ItemTitle.Text = name;
46             ItemDescription.Text = description;
47             ItemDescription.MultiLine = true;
48
49             TouchEvent += OnTouchEvent;
50             animation = new Animation();
51         }
52
53         public bool OnTouchEvent(object sender, TouchEventArgs args)
54         {
55             if (args.Touch.GetState(0) == Tizen.NUI.PointStateType.Finished) {
56                 CollectionViewItemClicked.Invoke(this, new CollectionViewItemClickedEventArgs(ItemId));
57             }
58
59             return false;
60         }
61
62         public void SetFocused()
63         {
64             ItemBackground.BackgroundColor = Color.Blue;
65
66             animation.AnimateTo(ItemBackground, "SizeWidth", 340, 0, 100);
67             animation.AnimateTo(ItemBackground, "SizeHeight", 900, 0, 100);
68             animation.AnimateTo(ItemPoster, "SizeWidth", 340, 0, 100);
69             animation.AnimateTo(ItemPoster, "SizeHeight", 496, 0, 100);
70             animation.AnimateTo(ItemTitle, "SizeWidth", 340, 0, 100);
71             animation.AnimateTo(ItemDescription, "SizeWidth", 340, 0, 100);
72             animation.AnimateTo(ItemDescription, "SizeHeight", 350, 0, 100);
73             animation.Looping = false;
74             animation.Play();
75         }
76
77         public void SetNormal()
78         {
79             ItemBackground.BackgroundColor = Color.Red;
80             animation.AnimateTo(ItemBackground, "SizeWidth", 300, 0, 100);
81             animation.AnimateTo(ItemBackground, "SizeHeight", 700, 0, 100);
82             animation.AnimateTo(ItemPoster, "SizeWidth", 300, 0, 100);
83             animation.AnimateTo(ItemPoster, "SizeHeight", 438, 0, 100);
84             animation.AnimateTo(ItemTitle, "SizeWidth", 300, 0, 100);
85             animation.AnimateTo(ItemDescription, "SizeWidth", 300, 0, 100);
86             animation.AnimateTo(ItemDescription, "SizeHeight", 50, 0, 100);
87             animation.Looping = false;
88             animation.Play();
89         }
90     }
91 }