Code example for DragEvent

Methods: getActiongetClipDatagetLocalStategetXgetY

0
	} 
 
	@Override 
	public boolean onDrag(View v, DragEvent event)
	{ 
		switch (event.getAction())
		{ 
		case DragEvent.ACTION_DRAG_STARTED: 
			Log.d("drag", "registered");
			break; 
			 
		case DragEvent.ACTION_DRAG_ENTERED:
				 
			break; 
 
		case DragEvent.ACTION_DRAG_LOCATION:
			break; 
 
		case DragEvent.ACTION_DRAG_ENDED:
			 
			break; 
 
		case DragEvent.ACTION_DRAG_EXITED: 
			 
			break; 
 
		case DragEvent.ACTION_DROP: 
			// check minpositions, hide grid, display overlay at new position and reposition the element at droptarget 
			 
			//check if new object generated 
			ClipData.Item item = event.getClipData().getItemAt(0);
			 
			//if (item.getText().equals(ItemboxFragment.DRAG_EVENT_ORIGIN_ITEMBOX)) 
			{ 
				View screen = (View) event.getLocalState();
				screen.setVisibility(View.VISIBLE);
				 
				int posX = Math.round(event.getX() - screen.getMeasuredWidth() / 2);
				int posY = Math.round(event.getY() - screen.getMeasuredHeight() / 2);
				RelativeLayout.LayoutParams activeParams = (RelativeLayout.LayoutParams) screen.getLayoutParams();
				 
				activeParams.leftMargin = posX;
				activeParams.topMargin = posY;
				screen.setLayoutParams(activeParams);