private bool IsItemVisible(float scrollPosition, RecycleItem item)
        {
            bool result = false;
            View list   = Container.GetParent() as View;

            if (list == null)
            {
                return(result);
            }

            Vector2 visibleArea = new Vector2(Math.Abs(scrollPosition),
                                              Math.Abs(scrollPosition) + (LayoutOrientation == Orientation.Horizontal ?
                                                                          list.Size.Width : list.Size.Height)
                                              );

            float firstCheckPoint  = LayoutOrientation == Orientation.Horizontal ? item.Position.X : item.Position.Y;
            float secondCheckPoint = LayoutOrientation == Orientation.Horizontal ?
                                     firstCheckPoint + item.Size.Width :
                                     firstCheckPoint + item.Size.Height;

            // Tizen.Log.Error("NUI", "[1p] "+visibleArea.X+ " =< "+firstCheckPoint+" =< "+visibleArea.Y+" ==== \n");
            // Tizen.Log.Error("NUI", "[2p] "+visibleArea.X+ " =< "+secondCheckPoint+" =< "+visibleArea.Y+" ==== \n");

            result = (firstCheckPoint >= visibleArea.X && firstCheckPoint <= visibleArea.Y) || (secondCheckPoint >= visibleArea.X && secondCheckPoint <= visibleArea.Y);

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is called to find out where items are lain out according to current scroll position.
        /// </summary>
        /// <param name="scrollPosition">Scroll position which is calculated by ScrollableBase</param>
        /// <since_tizen> 8 </since_tizen>
        /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
        public override void Layout(float scrollPosition)
        {
            int itemInGroup = LayoutOrientation == Orientation.Vertical ? Rows : Columns;

            firstVisibleItemIndex = -1;
            lastVisibleItemIndex  = -1;

            RecycleItem previousItem = null;

            for (int i = 0; i < Container.Children.Count; i++)
            {
                RecycleItem item = Container.Children[i] as RecycleItem;

                if (previousItem != null)
                {
                    item.Position = LayoutOrientation == Orientation.Vertical ?
                                    new Position(
                        (i % itemInGroup == 0 ?
                         previousItem.Position.X + (previousItem.CurrentSize.Width != 0 ?
                                                    previousItem.CurrentSize.Width :
                                                    previousItem.Size.Width) :
                         previousItem.Position.X),
                        (i % itemInGroup == 0 ?
                         0 :
                         previousItem.PositionY + (previousItem.CurrentSize.Height != 0 ?
                                                   previousItem.CurrentSize.Height :
                                                   previousItem.Size.Height))
                        ) :
                                    new Position(
                        (i % itemInGroup == 0 ?
                         0 :
                         previousItem.PositionX + (previousItem.CurrentSize.Width != 0 ?
                                                   previousItem.CurrentSize.Width :
                                                   previousItem.Size.Width)),
                        (i % itemInGroup == 0 ?
                         previousItem.Position.Y + (previousItem.CurrentSize.Height != 0 ?
                                                    previousItem.CurrentSize.Height :
                                                    previousItem.Size.Height) :
                         previousItem.Position.Y)
                        );
                }

                bool isVisible = IsItemVisible(scrollPosition, item);

                if (isVisible)
                {
                    firstVisibleItemIndex = firstVisibleItemIndex == -1 ? i : firstVisibleItemIndex;
                    lastVisibleItemIndex  = i;
                }

                previousItem = item;
            }

            if (StepSize == 0)
            {
                StepSize = LayoutOrientation == Orientation.Vertical ? ItemSize.Width : ItemSize.Height;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This is called to find out which items should be recycled according to current scroll position.
        /// </summary>
        /// <param name="scrollPosition">Scroll position which is calculated by ScrollableBase</param>
        /// <returns>List of RecycleItems which should be recycled.</returns>
        /// <since_tizen> 8 </since_tizen>
        /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
        public override List <RecycleItem> Recycle(float scrollPosition)
        {
            List <RecycleItem> result = new List <RecycleItem>();
            bool checkFront           = (PrevScrollPosition - scrollPosition) > 0;

            int itemInGroup = LayoutOrientation == Orientation.Vertical ? Rows : Columns;

            if (checkFront)
            {
                int currentGroupNum = (int)(firstVisibleItemIndex / itemInGroup) + 1;

                if (currentGroupNum > 2)
                {
                    // Too many item is in front!!! move first item to back!!!!
                    for (int i = 0; i < itemInGroup; i++)
                    {
                        RecycleItem target = Container.Children[0] as RecycleItem;
                        if (target != null)
                        {
                            target.DataIndex    = target.DataIndex + Container.Children.Count;
                            target.SiblingOrder = Container.Children.Count - 1;

                            result.Add(target);
                        }
                    }
                }
            }
            else
            {
                int currentGroupNum = (int)(lastVisibleItemIndex / itemInGroup) + 1;

                if (currentGroupNum < (int)(Container.Children.Count / itemInGroup) - 3)
                {
                    for (int i = 0; i < itemInGroup; i++)
                    {
                        RecycleItem prevFirstItem = Container.Children[itemInGroup] as RecycleItem;
                        RecycleItem target        = Container.Children[Container.Children.Count - 1] as RecycleItem;
                        if (prevFirstItem != null && target != null)
                        {
                            target.Position = new Position(
                                LayoutOrientation == Orientation.Vertical ? (prevFirstItem.Position.X - target.Size.Width) : prevFirstItem.Position.X,
                                LayoutOrientation == Orientation.Vertical ? prevFirstItem.Position.Y : (prevFirstItem.Position.Y - target.Size.Height)
                                );
                            target.DataIndex    = target.DataIndex - Container.Children.Count;
                            target.SiblingOrder = 0;

                            result.Add(target);
                        }
                    }
                }
            }


            PrevScrollPosition = scrollPosition;

            return(result);
        }
        /// <summary>
        /// This is called to find out where items are lain out according to current scroll position.
        /// </summary>
        /// <param name="scrollPosition">Scroll position which is calculated by ScrollableBase</param>
        /// <since_tizen> 8 </since_tizen>
        /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
        public override void Layout(float scrollPosition)
        {
            firstVisibleItemIndex = -1;
            lastVisibleItemIndex  = -1;

            RecycleItem previousItem = null;

            for (int i = 0; i < Container.Children.Count; i++)
            {
                RecycleItem item = Container.Children[i] as RecycleItem;

                if (previousItem != null && item != null)
                {
                    item.Position = LayoutOrientation == Orientation.Horizontal ?
                                    new Position(
                        previousItem.Position.X + (previousItem.CurrentSize.Width != 0 ?
                                                   previousItem.CurrentSize.Width :
                                                   previousItem.Size.Width),
                        item.PositionY
                        ) :
                                    new Position(
                        item.PositionX,
                        previousItem.Position.Y + (previousItem.CurrentSize.Height != 0 ?
                                                   previousItem.CurrentSize.Height :
                                                   previousItem.Size.Height)
                        );
                }

                bool isVisible = IsItemVisible(scrollPosition, item);

                if (isVisible)
                {
                    firstVisibleItemIndex = firstVisibleItemIndex == -1 ? i : firstVisibleItemIndex;
                    lastVisibleItemIndex  = i;
                }

                previousItem = item;

                // Tizen.Log.Error("NUI","["+item.DataIndex+"] "+item.Position.Y+" ==== \n");
            }

            if (StepSize == 0)
            {
                StepSize = LayoutOrientation == Orientation.Horizontal ? ItemSize.Width : ItemSize.Height;
            }
        }
        /// <summary>
        /// This is called to find out which items should be recycled according to current scroll position.
        /// </summary>
        /// <param name="scrollPosition">Scroll position which is calculated by ScrollableBase</param>
        /// <returns>List of RecycleItems which should be recycled.</returns>
        /// <since_tizen> 8 </since_tizen>
        /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
        public override List <RecycleItem> Recycle(float scrollPosition)
        {
            List <RecycleItem> result = new List <RecycleItem>();

            bool checkFront = (PrevScrollPosition - scrollPosition) > 0;

            if (checkFront)
            {
                if (firstVisibleItemIndex > 3)
                {
                    // Too many item is in front!!! move first item to back!!!!
                    RecycleItem target = Container.Children[0] as RecycleItem;
                    if (target != null)
                    {
                        target.DataIndex    = target.DataIndex + Container.Children.Count;
                        target.SiblingOrder = Container.Children.Count - 1;

                        result.Add(target);
                    }
                }
            }
            else
            {
                if (lastVisibleItemIndex < Container.Children.Count - 3)
                {
                    RecycleItem prevFirstItem = Container.Children[0] as RecycleItem;
                    RecycleItem target        = Container.Children[Container.Children.Count - 1] as RecycleItem;
                    if (prevFirstItem != null && target != null)
                    {
                        target.Position = new Position(
                            LayoutOrientation == Orientation.Horizontal ? (prevFirstItem.Position.X - target.Size.Width) : prevFirstItem.Position.X,
                            LayoutOrientation == Orientation.Horizontal ? prevFirstItem.Position.Y : (prevFirstItem.Position.Y - target.Size.Height)
                            );
                        target.DataIndex    = target.DataIndex - Container.Children.Count;
                        target.SiblingOrder = 0;

                        result.Add(target);
                    }
                }
            }

            PrevScrollPosition = scrollPosition;

            return(result);
        }
        public override View RequestNextFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
        {
            View nextFocusedView = null;
            int  targetSibling   = -1;
            bool isHorizontal    = LayoutOrientation == Orientation.Horizontal;

            switch (direction)
            {
            case View.FocusDirection.Left:
            {
                targetSibling = isHorizontal ? currentFocusedView.SiblingOrder - 1 : targetSibling;
                break;
            }

            case View.FocusDirection.Right:
            {
                targetSibling = isHorizontal ? currentFocusedView.SiblingOrder + 1 : targetSibling;
                break;
            }

            case View.FocusDirection.Up:
            {
                targetSibling = isHorizontal ? targetSibling : currentFocusedView.SiblingOrder - 1;
                break;
            }

            case View.FocusDirection.Down:
            {
                targetSibling = isHorizontal ? targetSibling : currentFocusedView.SiblingOrder + 1;
                break;
            }
            }

            if (targetSibling > -1 && targetSibling < Container.Children.Count)
            {
                RecycleItem candidate = Container.Children[targetSibling] as RecycleItem;
                if (candidate != null && candidate.DataIndex >= 0 && candidate.DataIndex < DataCount)
                {
                    nextFocusedView = candidate;
                }
            }

            return(nextFocusedView);
        }
Ejemplo n.º 7
0
        private bool IsItemVisible(float scrollPosition, RecycleItem item)
        {
            bool result = false;
            View list   = Container.GetParent() as View;

            Vector2 visibleArea = new Vector2(Math.Abs(scrollPosition),
                                              Math.Abs(scrollPosition) + (LayoutOrientation == Orientation.Vertical ?
                                                                          list.Size.Width : list.Size.Height)
                                              );

            float firstCheckPoint  = LayoutOrientation == Orientation.Vertical ? item.Position.X : item.Position.Y;
            float secondCheckPoint = LayoutOrientation == Orientation.Vertical ?
                                     firstCheckPoint + item.Size.Width :
                                     firstCheckPoint + item.Size.Height;

            result = (firstCheckPoint >= visibleArea.X && firstCheckPoint <= visibleArea.Y) || (secondCheckPoint >= visibleArea.X && secondCheckPoint <= visibleArea.Y);

            return(result);
        }
Ejemplo n.º 8
0
        private void InitializeItems()
        {
            for (int i = Children.Count - 1; i > -1; i--)
            {
                Children[i].Unparent();
                notifications[i].Notified -= OnItemSizeChanged;
                notifications.RemoveAt(i);
            }

            for (int i = 0; i < totalItemCount; i++)
            {
                RecycleItem item = adapter.CreateRecycleItem();
                item.DataIndex = i;
                item.Name      = "[" + i + "] recycle";

                if (i < adapter.Data.Count)
                {
                    adapter.BindData(item);
                }
                Add(item);

                PropertyNotification noti = item.AddPropertyNotification("size", PropertyCondition.Step(0.1f));
                noti.Notified += OnItemSizeChanged;
                notifications.Add(noti);
            }

            layoutManager.Layout(0.0f);

            if (ScrollingDirection == Direction.Horizontal)
            {
                ContentContainer.SizeWidth = layoutManager.CalculateLayoutOrientationSize();
            }
            else
            {
                ContentContainer.SizeHeight = layoutManager.CalculateLayoutOrientationSize();
            }
        }
Ejemplo n.º 9
0
        public override View GetNextFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
        {
            View nextFocusedView = null;

            if (!focusedView)
            {
                // If focusedView is null, find child which has previous data index
                if (Children.Count > 0 && Adapter.Data.Count > 0)
                {
                    for (int i = 0; i < Children.Count; i++)
                    {
                        RecycleItem item = Children[i] as RecycleItem;
                        if (item.DataIndex == prevFocusedDataIndex)
                        {
                            nextFocusedView = item;
                            break;
                        }
                    }
                }
            }
            else
            {
                // If this is not first focus, request next focus to LayoutManager
                if (LayoutManager != null)
                {
                    nextFocusedView = LayoutManager.RequestNextFocusableView(currentFocusedView, direction, loopEnabled);
                }
            }

            if (nextFocusedView)
            {
                // Check next focused view is inside of visible area.
                // If it is not, move scroll position to make it visible.
                Position scrollPosition = ContentContainer.CurrentPosition;
                float    targetPosition = -(ScrollingDirection == Direction.Horizontal ? scrollPosition.X : scrollPosition.Y);

                float left   = nextFocusedView.Position.X;
                float right  = nextFocusedView.Position.X + nextFocusedView.Size.Width;
                float top    = nextFocusedView.Position.Y;
                float bottom = nextFocusedView.Position.Y + nextFocusedView.Size.Height;

                float visibleRectangleLeft   = -scrollPosition.X;
                float visibleRectangleRight  = -scrollPosition.X + Size.Width;
                float visibleRectangleTop    = -scrollPosition.Y;
                float visibleRectangleBottom = -scrollPosition.Y + Size.Height;

                if (ScrollingDirection == Direction.Horizontal)
                {
                    if ((direction == View.FocusDirection.Left || direction == View.FocusDirection.Up) && left < visibleRectangleLeft)
                    {
                        targetPosition = left;
                    }
                    else if ((direction == View.FocusDirection.Right || direction == View.FocusDirection.Down) && right > visibleRectangleRight)
                    {
                        targetPosition = right - Size.Width;
                    }
                }
                else
                {
                    if ((direction == View.FocusDirection.Up || direction == View.FocusDirection.Left) && top < visibleRectangleTop)
                    {
                        targetPosition = top;
                    }
                    else if ((direction == View.FocusDirection.Down || direction == View.FocusDirection.Right) && bottom > visibleRectangleBottom)
                    {
                        targetPosition = bottom - Size.Height;
                    }
                }

                focusedView = nextFocusedView;
                if ((nextFocusedView as RecycleItem) != null)
                {
                    prevFocusedDataIndex = (nextFocusedView as RecycleItem).DataIndex;
                }

                ScrollTo(targetPosition, true);
            }
            else
            {
                // If nextView is null, it means that we should move focus to outside of Control.
                // Return FocusableView depending on direction.
                switch (direction)
                {
                case View.FocusDirection.Left:
                {
                    nextFocusedView = LeftFocusableView;
                    break;
                }

                case View.FocusDirection.Right:
                {
                    nextFocusedView = RightFocusableView;
                    break;
                }

                case View.FocusDirection.Up:
                {
                    nextFocusedView = UpFocusableView;
                    break;
                }

                case View.FocusDirection.Down:
                {
                    nextFocusedView = DownFocusableView;
                    break;
                }
                }

                if (nextFocusedView)
                {
                    focusedView = null;
                }
                else
                {
                    //If FocusableView doesn't exist, not move focus.
                    nextFocusedView = focusedView;
                }
            }

            return(nextFocusedView);
        }
Ejemplo n.º 10
0
 public virtual void BindData(RecycleItem item)
 {
 }