Code example for DragEvent

Methods: getAction, getLocalState, getResult

0
			} 
		} 
	} 
 
	private boolean dropEventNotHandled(DragEvent dragEvent) {
		return !dragEvent.getResult();
	} 
 
	class MyDragListener implements OnDragListener {
		Drawable enterShape = getResources().getDrawable(
				R.drawable.shape_droptarget); 
		Drawable normalShape = getResources().getDrawable(R.drawable.shape);
 
		@Override 
		public boolean onDrag(View v, DragEvent event) {
			// Log.e("DRAGGGG", 
			// upperLayout.toString() + " + " + lowerLayout.toString()); 
			int action = event.getAction();
			switch (event.getAction()) {
			case DragEvent.ACTION_DRAG_STARTED:
				// Do nothing 
				Log.e("drag", "drag started");
				break; 
			case DragEvent.ACTION_DRAG_ENTERED:
				v.setBackgroundDrawable(enterShape);
				Log.e("drag", "drag entered");
 
				break; 
			case DragEvent.ACTION_DRAG_EXITED:
				v.setBackgroundDrawable(normalShape);
				Log.e("drag", "drag exit");
 
				break; 
			case DragEvent.ACTION_DROP:
				// Dropped, reassign View to ViewGroup 
				View view = (View) event.getLocalState();
				Log.e("VIEWW 1",
						v.toString()
								+ " ID " 
								+ view.getParent().toString().trim()
										.equals(v.toString().trim()));
				ViewGroup owner = (ViewGroup) view.getParent();
 
				if (!view.getParent().toString().trim()
						.equals(v.toString().trim())) {
					owner.removeView(view);
					LinearLayout container = (LinearLayout) v;
					container.addView(view);
					view.setVisibility(View.VISIBLE);
					Log.e("drag", "drag drop");
					numberOfViews++;
					TextView view3 = (TextView) event.getLocalState();
					view3.setEnabled(false);
					String s = view3.getText().toString().trim();
					Log.e("TEXT", view3.getText().toString().trim());
					str.append(s);
					if (numberOfViews == x.size()) {
						if (str.toString().equals(correctAns)) {
							Toast.makeText(getApplicationContext(), "Correct",
									Toast.LENGTH_SHORT).show();
						} else { 
							Toast.makeText(getApplicationContext(), "Wrong",
									Toast.LENGTH_SHORT).show();
						} 
					} 
				} else {// dropped in same view 
					View view2 = (View) event.getLocalState();
					view2.setVisibility(View.VISIBLE);
				} 
				break; 
			case DragEvent.ACTION_DRAG_ENDED:
				v.setBackgroundDrawable(normalShape);
				Log.e("drag", "drag END");
 
				// Log.e("view", ((TextView) v).getText().toString().trim()); 
				// TextView view3 = (TextView) event.getLocalState(); 
 
				// view3.getText().toString().trim(); 
				Log.e("numberOfView", numberOfViews + "");
 
				if (dropEventNotHandled(event)) {
					View view2 = (View) event.getLocalState();
					view2.setVisibility(View.VISIBLE);
					Log.e("BANG", "NOT HANDLED");
				} 
 
			default: