示例#1
0
        public static Point GetTouchPositionFromDragEvent(View item, DragEvent e)
        {
            Rect rItem = new Rect();

            item.GetGlobalVisibleRect(rItem);
            return(new Point(rItem.Left + (int)Math.Round(e.GetX()), rItem.Top + (int)Math.Round(e.GetY())));
        }
        public bool OnDrag(View view, DragEvent e)
        {
            switch (e.Action)
            {
            case DragAction.Started:

                return(true);

            case DragAction.Entered:

                return(true);

            case DragAction.Exited:

                return(true);

            case DragAction.Drop:

                objVehicleMarkDamageDetails = rentRunningTrans.RentVehicleDamage.Where(x => x.DamageNumber == Convert.ToInt32(e.ClipData.GetItemAt(0).Text)).First();
                objVehicleMarkDamageDetails.DamageLocationX = (int)e.GetX();
                objVehicleMarkDamageDetails.DamageLocationY = (int)e.GetY();
                this.DrawDamageCircle(objVehicleMarkDamageDetails);
                //view.Visibility = (ViewStates.Invisible);
                //droppedIndex = Convert.ToInt16(view.GetTag(Resource.String.keyval)); ;
                return(true);

            case DragAction.Ended:

                return(true);
            }
            return(false);
        }
            bool View.IOnDragListener.OnDrag
            (
                View backView,
                DragEvent dragEvent
            )
            {
                switch (dragEvent.Action)
                {
                case DragAction.Drop:
                {
                    _dropX = dragEvent.GetX();
                    _dropY = dragEvent.GetY();

                    break;
                }

                case DragAction.Ended:
                {
                    float halfWidth  = backView.Width / 2;
                    float halfHeight = backView.Height / 2;

                    float backX = (_dropX - halfWidth) * backView.ScaleX + halfWidth -
                                  (_draggedView.Width / 2);

                    float backY = (_dropY - halfHeight) * backView.ScaleY + halfHeight -
                                  (_draggedView.Height / 2);

                    _draggedView.SetX(backX);
                    _draggedView.SetY(backY);

                    backView.SetOnDragListener(null);

                    break;
                }
                }

                return(true);
            }
 public bool OnDrag(View v, DragEvent e)
 {
     return(DragUpdated.Invoke(v, e.Action, e.GetX(), e.GetY()));
 }
示例#5
0
        //public override bool HasStableIds => WrappedAdapter.HasStableIds;

        //public override bool IsEmpty => WrappedAdapter.IsEmpty;

        //public override int ViewTypeCount => WrappedAdapter.ViewTypeCount;

        //public override bool AreAllItemsEnabled() => WrappedAdapter.AreAllItemsEnabled();

        public bool OnDrag(View v, DragEvent e)
        {
            var dragItem = (DragItem)e.LocalState;

            switch (e.Action)
            {
            case DragAction.Started:
                break;

            case DragAction.Entered:
                System.Diagnostics.Debug.WriteLine($"DragAction.Entered from {v.GetType()}");

                if (!(v is ListView))
                {
                    //var dragItem = (DragItem)e.LocalState;

                    var targetPosition = InsertOntoView(v, dragItem);

                    dragItem.Index = targetPosition;

                    // Keep a list of items that has translation so we can reset
                    // them once the drag'n'drop is finished.
                    _translatedItems.Add(v);
                    _listView.Invalidate();
                }
                break;

            case DragAction.Location:

                var currentPosition = (int)e.GetX();

                var point = GetTouchPositionFromDragEvent(v, e);

                System.Diagnostics.Debug.WriteLine($"DragAction.Location from {v.GetType()} => {currentPosition}");
                System.Diagnostics.Debug.WriteLine($"DragAction.GLOBAL   from {v.GetType()} => {point.X}");

                int y           = Java.Lang.Math.Round(e.GetY());
                int translatedY = y - 50;
                int threshold   = 50;
                // make a scrolling up due the y has passed the threshold
                if (translatedY < threshold)
                {
                    // make a scroll up by 30 px
                    _hostScrollView.ScrollBy(0, -30);
                }
                // make a autoscrolling down due y has passed the 500 px border
                if (translatedY + threshold > 500)
                {
                    // make a scroll down by 30 px
                    _hostScrollView.ScrollBy(0, 30);
                }

                //if (point.X > App.AppScreenWidth - 50)
                //{
                //    //_hostScrollView.ScrollToAsync(_hostScrollView.ScrollX + 30, 0, true);
                //    _hostScrollView.StartScroll(50);
                //}

                //if (point.X < 50)
                //{
                //    //_hostScrollView.ScrollToAsync(_hostScrollView.ScrollX - 30, 0, true);
                //    _hostScrollView.StartScroll(-50);
                //}

                //if (currentPosition > _element.Width - 40)
                //{
                //    _hostScrollView.ScrollToAsync(_hostScrollView.ScrollX + 30, 0, true);
                //}
                //else if (currentPosition < 40)
                //{
                //    _hostScrollView.ScrollToAsync(_hostScrollView.ScrollX - 30, 0, true);
                //}

                //if (v.Right < (_hostScrollView.ScrollX + _hostScrollView.Width - 100))
                //{
                //    _hostScrollView.ScrollToAsync(_hostScrollView.ScrollX + 30, 0, true);
                //}

                //if (v.Left > (_hostScrollView.ScrollX + _hostScrollView.Width - 100))
                //{
                //    _hostScrollView.ScrollToAsync(_hostScrollView.ScrollX - 30, 0, true);
                //}

                break;

            case DragAction.Exited:
                System.Diagnostics.Debug.WriteLine($"DragAction.Entered from {v.GetType()}");

                _lastPosition = _listView.GetPositionForView(v);

                if (!(v is ListView))
                {
                    var positionEntered = GetListPositionForView(v);
                    //var item1 = _listAdapter.GetItem(positionEntered);

                    System.Diagnostics.Debug.WriteLine($"DragAction.Exited index {positionEntered}");
                }
                break;

            case DragAction.Drop:

                System.Diagnostics.Debug.WriteLine($"DragAction.Drop from {v.GetType()}");

                if (v is ListView)
                {
                    bool isDropped      = true;
                    int  positionSource = -1;
                    int  insertLocation = -1;

                    var dropItem                  = (DragItem)e.LocalState;
                    Android.Views.View view       = dropItem.View;
                    object             passedItem = dropItem.Item;

                    Android.Widget.ListView oldParent = (Android.Widget.ListView)view.Parent;

                    //DragListAdapter oldParentAdapter = (DragListAdapter)oldParent.;
                    BaseAdapter sourceAdapter = (oldParent.Adapter is IWrapperListAdapter)
                            ? ((IWrapperListAdapter)oldParent.Adapter).WrappedAdapter as BaseAdapter
                            : ((BaseAdapter)oldParent.Adapter);
                    DragAndDropListViewAdapter sourceDragListAdaptor = sourceAdapter as DragAndDropListViewAdapter;

                    //positionSource = (int)view.Tag;

                    Console.WriteLine(v.Parent.Parent);
                    Android.Widget.ListView newParent = _listView;

                    //Person customList = (Person)sourceAdapter.Collection[positionSource];
                    ObservableListCollection <Item> sourceList = sourceDragListAdaptor.Collection;
                    //customListSource.RemoveAt(positionSource);



                    //Android.Widget.ListView target = this.Element.
                    //DragListAdapter adapterTarget = (DragListAdapter)_listView.Adapter;
                    BaseAdapter destinationAdapter = (oldParent.Adapter is IWrapperListAdapter)
                            ? ((IWrapperListAdapter)newParent.Adapter).WrappedAdapter as BaseAdapter
                            : ((BaseAdapter)oldParent.Adapter);
                    DragAndDropListViewAdapter destinationDragListAdaptor = destinationAdapter as DragAndDropListViewAdapter;

                    ObservableListCollection <Item> targetList = destinationDragListAdaptor.Collection;

                    int removeLocation = oldParent.GetPositionForView(view);
                    insertLocation = newParent.GetPositionForView(dropItem.View);

                    var item = dropItem.Item as Item;

                    //if (sourceList.Contains(dropItem.Item as Item) && sourceList != targetList)
                    if (sourceList != targetList)
                    {
                        if (insertLocation >= 0)
                        {
                            targetList.Insert(insertLocation, item);
                            targetList.ItemAdded(item);
                        }
                        else
                        {
                            targetList.Add(dropItem.Item as Item);
                            targetList.ItemAdded(item);
                        }

                        sourceList.Remove(item);


                        sourceAdapter.NotifyDataSetChanged();
                        destinationAdapter.NotifyDataSetChanged();
                        v.Visibility = ViewStates.Visible;     //(View.VISIBLE);
                    }
                    else
                    {
                        if (_element.ItemsSource is IOrderable orderable)
                        {
                            if (((IList)_element.ItemsSource).Contains(dropItem.Item))
                            {
                                orderable.ChangeOrdinal(dropItem.OriginalIndex, dropItem.Index);
                            }
                        }
                    }

                    //foreach (var viewTrans in _translatedItems)
                    //{
                    //    viewTrans.TranslationY = 0;
                    //}

                    //_translatedItems.Clear();
                }

                break;

            case DragAction.Ended:
                if (!(v is ListView))
                {
                    return(false);
                }

                //System.Diagnostics.Debug.WriteLine($"DragAction.Ended from {v.GetType()}");

                var mobileItem = (DragItem)e.LocalState;

                mobileItem.View.Visibility = ViewStates.Visible;

                foreach (var view in _translatedItems)
                {
                    view.TranslationY = 0;
                }

                _translatedItems.Clear();

                //if (_element.ItemsSource is IOrderable orderable)
                //{
                //    if (((IList)_element.ItemsSource).Contains(mobileItem.Item))
                //    {
                //        orderable.ChangeOrdinal(mobileItem.OriginalIndex, mobileItem.Index);
                //    }
                //    else
                //    {
                //        orderable.ItemAdded(mobileItem.Item);
                //    }
                //}

                break;
            }

            return(true);
        }