Program: 45435
Project: 45435
Buggy source:
@Override public boolean onTouch(View view,MotionEvent event){
  context.handleZoom();
  x=event.getX();
  y=event.getY();
  if (context.getDragPlot()) {
switch (event.getAction()) {
case (MotionEvent.ACTION_DOWN):
      focusedPlot=garden.plotAt(x,y,m);
    if (focusedPlot == context.newPlot) {
      focusedPlot.getShape().getPaint().setColor(0xFF7BB518);
      focusedPlot.getShape().getPaint().setStrokeWidth(5);
      status=START_DRAGGING;
    }
  break;
case (MotionEvent.ACTION_UP):
status=STOP_DRAGGING;
if (focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(Color.BLACK);
focusedPlot.getShape().getPaint().setStrokeWidth(3);
}
break;
case (MotionEvent.ACTION_MOVE):
if (status == START_DRAGGING && focusedPlot != null) {
float[] dxy={x,y,prevX,prevY};
Matrix inverse=new Matrix();
m.invert(inverse);
inverse.mapPoints(dxy);
focusedPlot.getShape().getBounds().offset((int)(-dxy[2] + dxy[0]),(int)(-dxy[3] + dxy[1]));
}
break;
}
}
 else {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
dragMode=false;
downX=x;
downY=y;
focusedPlot=garden.plotAt(x,y,m);
if (focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(0xFF7BB518);
focusedPlot.getShape().getPaint().setStrokeWidth(5);
}
}
 else {
float dx=x - prevX, dy=y - prevY;
dragMatrix.postTranslate(dx / zoomScale,dy / zoomScale);
bgDragMatrix.postTranslate(dx,dy);
if (!dragMode) dragMode=Math.abs(downX - x) > 5 || Math.abs(downY - y) > 5;
if (dragMode && focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(Color.BLACK);
focusedPlot.getShape().getPaint().setStrokeWidth(3);
}
}
if (event.getAction() == MotionEvent.ACTION_UP && !dragMode) {
if (focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(Color.BLACK);
focusedPlot.getShape().getPaint().setStrokeWidth(3);
}
performClick();
}
}
prevX=x;
prevY=y;
invalidate();
return true;
}

Fixed version (ground truth):
@Override public boolean onTouch(View view,MotionEvent event){
  context.handleZoom();
  x=event.getX();
  y=event.getY();
  if (context.getDragPlot()) {
switch (event.getAction()) {
case (MotionEvent.ACTION_DOWN):
      Matrix inv=new Matrix();
    m.invert(inv);
  float[] xy={x,y};
inv.mapPoints(xy);
if (context.newPlot.contains(xy[0],xy[1])) {
focusedPlot=context.newPlot;
focusedPlot.getShape().getPaint().setColor(0xFF7BB518);
focusedPlot.getShape().getPaint().setStrokeWidth(5);
status=START_DRAGGING;
}
break;
case (MotionEvent.ACTION_UP):
status=STOP_DRAGGING;
if (focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(Color.BLACK);
focusedPlot.getShape().getPaint().setStrokeWidth(3);
}
break;
case (MotionEvent.ACTION_MOVE):
if (status == START_DRAGGING && focusedPlot != null) {
float[] dxy={x,y,prevX,prevY};
Matrix inverse=new Matrix();
m.invert(inverse);
inverse.mapPoints(dxy);
focusedPlot.getShape().getBounds().offset((int)(-dxy[2] + dxy[0]),(int)(-dxy[3] + dxy[1]));
}
break;
}
}
 else {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
dragMode=false;
downX=x;
downY=y;
focusedPlot=garden.plotAt(x,y,m);
if (focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(0xFF7BB518);
focusedPlot.getShape().getPaint().setStrokeWidth(5);
}
}
 else {
float dx=x - prevX, dy=y - prevY;
dragMatrix.postTranslate(dx / zoomScale,dy / zoomScale);
bgDragMatrix.postTranslate(dx,dy);
if (!dragMode) dragMode=Math.abs(downX - x) > 5 || Math.abs(downY - y) > 5;
if (dragMode && focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(Color.BLACK);
focusedPlot.getShape().getPaint().setStrokeWidth(3);
}
}
if (event.getAction() == MotionEvent.ACTION_UP && !dragMode) {
if (focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(Color.BLACK);
focusedPlot.getShape().getPaint().setStrokeWidth(3);
}
performClick();
}
}
prevX=x;
prevY=y;
invalidate();
return true;
}