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())); }
//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); }
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 hoveredView, DragEvent e) { ViewGroup hoveredContainer = null; View dragged = (View)e.LocalState; bool hoveredIsRv = hoveredView is RecyclerView; Log("HoveredView : " + hoveredView); Log("HoveredView.Parent : " + hoveredView.Parent); //Log("Dragged.Parent : " + (dragged.Parent is FrameLayout)); // FrameLayout --> Dragged is a CloneInstance if (hoveredView is LinearLayout layout) { if (hoveredView.Parent is ScrollView) { hoveredContainer = layout; } } if (hoveredView is InstructionContainer || hoveredIsRv) { // It can be an InstructionContainer or a ConditionContainer hoveredContainer = (ViewGroup)hoveredView; // TODO Tabs // TODO solve problem : Si les InstructionContainer sont acceptés pour le onDrag(true returned dans DragAction.Started) // TODO , alors des problemes de scroll apparaissent dans le RecyclerView. // TODO scroll automatique aux bords if (hoveredView is InstructionContainer) { if (((BlockView)hoveredView.Parent.Parent).Depth >= MaxBlockDepth && dragged is ContainerBlockView) { Toast.MakeText(this, "Forbidden to nest more than " + MaxBlockDepth + " Blocks in depth.", ToastLength.Long).Show(); return(false); } } // dragged.Parent is FrameLayout --> Dragged is a CloneInstance placed in the RecyclerView // this appears not to be the origin of the problem // if (hoveredIsRv && dragged.Parent is FrameLayout) // { // Log("dragged == LastClonedRbv TRUE"); // return false; // } } switch (e.Action) { case DragAction.Started: Log("OnDrag Started"); // Determines if this View can accept the dragged bool res = hoveredContainer != null; Log("Res : " + res); Log("Dragged : " + dragged); return(res); case DragAction.Entered: hoveredView.Background.SetColorFilter(Color.ParseColor("#FFE082"), PorterDuff.Mode.SrcIn); hoveredView.Invalidate(); return(true); case DragAction.Exited: hoveredView.Background.ClearColorFilter(); hoveredView.Invalidate(); if (!hoveredIsRv) { ((ViewGroup)dragged.Parent).RemoveView(dragged); } return(true); case DragAction.Location: if (hoveredIsRv) { SmoothScrolling = false; return(true); } // TODO check out for coordinates : view.onInterceptTouchEvent if (dragged.Parent?.Parent.Parent is ScrollView) { if (e.GetY() < ScrollView.ScrollY + 100) { SmoothScrolling = true; IsScrollingUp = false; } else if (e.GetY() + 150 > ScrollView.ScrollY + ScrollView.Height) { SmoothScrolling = true; IsScrollingUp = true; } else { SmoothScrolling = false; } } AddDraggedView(dragged, hoveredContainer, e.GetY()); return(true); case DragAction.Drop: Log("OnDrag Drop"); hoveredView.Background.ClearColorFilter(); hoveredView.Invalidate(); if (hoveredIsRv) { return(true); } if (hoveredContainer != null) { AddDraggedView(dragged, hoveredContainer, e.GetY()); } return(true); case DragAction.Ended: Log("OnDrag Ended. Result : " + (e.Result ? "SUCCESS" : "FAILURE")); SmoothScrolling = false; hoveredView.Background.ClearColorFilter(); hoveredView.Invalidate(); if (LastTouchedView is RecyclerBlockView view) { view.RemoveCloneInstance(); Log("LastTouchedView : RBV : " + view); Count = 0; // ensures we will make a new copy if this view is dragged again from the RecyclerView LastClonedRbv.SetOnTouchListener(this); } if (hoveredIsRv) { return(true); } Log("new Parent : " + dragged.Parent + "\n\n"); if (!e.Result) { ResetDraggedView(dragged); } // sov 10988671 dragged.Post(() => { dragged.Visibility = ViewStates.Visible; }); return(true); } return(false); }