예제 #1
0
        public bool OnItemLongClick(AWidget.AdapterView parent, AViews.View view, int position, long id)
        {
            object selectedItem = null;

            //if (_element.ItemsSource.GetType().GetInterfaces().Any(x => x == typeof(IGroupedOrderable)))

            if (element.ItemsSource is IGroupedOrderableCollection grouped)
            {
                selectedItem = grouped.GetItemFromFlatIndex(id);
            }
            else
            {
                selectedItem = ((IList)element.ItemsSource)[(int)id];
            }

            // Creating drag state
            DragItem dragItem = new DragItem(NormalizeListPosition(position), view, selectedItem);

            // Creating a blank clip data object (we won't depend on this)
            var data = ClipData.NewPlainText(string.Empty, string.Empty);

            // Creating the default drag shadow for the item (the translucent version of the view)
            // NOTE: Can create a custom view in order to change the dragged item view
            AViews.View.DragShadowBuilder shadowBuilder = new AViews.View.DragShadowBuilder(view);

            // Setting the original view cell to be invisible
            view.Visibility = AViews.ViewStates.Invisible;

            // NOTE: this method is introduced in Android 24, for earlier versions the StartDrag method should be used
            view.StartDragAndDrop(data, shadowBuilder, dragItem, 0);

            return(true);
        }
예제 #2
0
        private int InsertOntoView(AViews.View view, DragItem item)
        {
            var positionEntered   = GetListPositionForView(view);
            var correctedPosition = positionEntered;

            // If the view already has a translation, we need to adjust the position
            // If the view has a positive translation, that means that the current position
            // is actually one index down then where it started.
            // If the view has a negative translation, that means it actually moved
            // up previous now we will need to move it down.
            if (view.TranslationY > 0)
            {
                correctedPosition += 1;
            }
            else if (view.TranslationY < 0)
            {
                correctedPosition -= 1;
            }

            // If the current index of the dragging item is bigger than the target
            // That means the dragging item is moving up, and the target view should
            // move down, and vice-versa
            var translationCoef = item.Index > correctedPosition ? 1 : -1;

            // We translate the item as much as the height of the drag item (up or down)
            var translationTarget = view.TranslationY + (translationCoef * item.View.Height);

            ObjectAnimator anim = ObjectAnimator.OfFloat(view, "TranslationY", view.TranslationY, translationTarget);

            anim.SetDuration(100);
            anim.Start();

            return(correctedPosition);
        }