[NUI] Add public types to replace nested types (CA1034 of StyleCop) (#1692)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Wearable / src / public / WearableList.cs
1 /* Copyright (c) 2020 Samsung Electronics Co., Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  */
16 using System;
17 using Tizen.NUI.BaseComponents;
18 using Tizen.NUI.Components;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI.Wearable
22 {
23     /// <summary>
24     /// [Draft] This class provides a list view styled by wearable ux.
25     /// List will lay out all items with Fish-Eye layout manager.
26     /// </summary>
27     /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
28     [EditorBrowsable(EditorBrowsableState.Never)]
29     public class WearableList : RecyclerView
30     {
31         private RecycleItem FocusedItem = null;
32
33         /// <summary>
34         /// Default constructor.
35         /// </summary>
36         /// <param name="adapter">Recycle adapter of List.</param>
37         /// <since_tizen> 8 </since_tizen>
38         /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
39         [EditorBrowsable(EditorBrowsableState.Never)]
40         public WearableList() : base(new RecycleAdapter(), new FishEyeLayoutManager())
41         {
42             ScrollingDirection = ScrollableBase.Direction.Vertical;
43
44             ScrollDragStarted += OnScrollDragStarted;
45             ScrollAnimationEnded += OnAnimationEnded;
46
47             ContentContainer.PositionUsesPivotPoint = true;
48             ContentContainer.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
49             ContentContainer.PivotPoint = Tizen.NUI.PivotPoint.TopCenter;
50             NoticeAnimationEndBeforePosition = 50;
51
52             ScrollAvailableArea = new Vector2(0, ContentContainer.SizeHeight);
53
54             SetFocus(0, false);
55
56             Scrollbar = new CircularScrollbar();
57         }
58
59         protected override void SetScrollbar()
60         {
61             if(LayoutManager != null)
62             {
63                 Scrollbar.Initialize(ContentContainer.Size.Height, LayoutManager.StepSize, ContentContainer.CurrentPosition.Y, false);
64             }
65         }
66
67         public new RecycleAdapter Adapter
68         {
69             get
70             {
71                 return base.Adapter;
72             }
73
74             set
75             {
76                 base.Adapter = value;
77
78                 foreach (View child in Children)
79                 {
80                     child.PositionUsesPivotPoint = true;
81                     child.ParentOrigin = Tizen.NUI.ParentOrigin.TopCenter;
82                 }
83
84                 ScrollAvailableArea = new Vector2( 0, ContentContainer.SizeHeight );
85             }
86         }
87
88         /// <summary>
89         /// Set focus to item which has specific data index.
90         /// </summary>
91         /// <param name="dataIndex">Data index of item.</param>
92         /// <param name="animated">If set true, scroll to item using animation.</param>
93         /// <since_tizen> 8 </since_tizen>
94         /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
95         public void SetFocus(int dataIndex, bool animated)
96         {
97             foreach (RecycleItem item in Children)
98             {
99                 if (item.DataIndex == dataIndex)
100                 {
101                     RecycleItem prevFocusedItem = FocusedItem;
102                     prevFocusedItem?.OnFocusLost();
103                     FocusedItem = item;
104                     FocusedItem.OnFocusGained();
105
106                     ScrollTo(item.DataIndex * mLayoutManager.StepSize, animated);
107                 }
108             }
109         }
110
111         private void OnAnimationEnded(object source, ScrollEventArgs args)
112         {
113         }
114
115         /// <summary>
116         /// This helps developer who wants to know before scroll is reaching target position.
117         /// </summary>
118         /// <param name="targetPosition">Index of item.</param>
119         /// <since_tizen> 8 </since_tizen>
120         /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
121         protected override void OnPreReachedTargetPosition(float targetPosition)
122         {
123             int targetDataIndex = (int)Math.Round(Math.Abs(targetPosition) / mLayoutManager.StepSize);
124
125             for (int i = 0; i < Children.Count; i++)
126             {
127                 RecycleItem item = Children[i] as RecycleItem;
128
129                 if (targetDataIndex == item.DataIndex)
130                 {
131                     FocusedItem = item;
132                     item.OnFocusGained();
133                     break;
134                 }
135             }
136         }
137
138         private void OnScrollDragStarted(object source, ScrollEventArgs args)
139         {
140             RecycleItem prevFocusedItem = FocusedItem;
141             prevFocusedItem?.OnFocusLost();
142         }
143     }
144 }