Program: 45434
Project: 45434
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):
      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;
tempColor=focusedPlot.getShape().getPaint().getColor();
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(tempColor);
focusedPlot.getShape().getPaint().setStrokeWidth(7);
}
break;
case (MotionEvent.ACTION_MOVE):
if (status == START_DRAGGING && focusedPlot != null) {
X=event.getX();
Y=event.getY();
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) {
tempColor=focusedPlot.getShape().getPaint().getColor();
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(tempColor);
if (focusedPlot != context.newPlot) focusedPlot.getShape().getPaint().setStrokeWidth(3);
 else focusedPlot.getShape().getPaint().setStrokeWidth(7);
}
}
if (event.getAction() == MotionEvent.ACTION_UP && !dragMode) {
if (focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(tempColor);
if (focusedPlot != context.newPlot) focusedPlot.getShape().getPaint().setStrokeWidth(3);
 else focusedPlot.getShape().getPaint().setStrokeWidth(7);
}
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;
tempColor=focusedPlot.getShape().getPaint().getColor();
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(tempColor);
focusedPlot.getShape().getPaint().setStrokeWidth(7);
}
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) {
tempColor=focusedPlot.getShape().getPaint().getColor();
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(tempColor);
if (focusedPlot != context.newPlot) focusedPlot.getShape().getPaint().setStrokeWidth(3);
 else focusedPlot.getShape().getPaint().setStrokeWidth(7);
}
}
if (event.getAction() == MotionEvent.ACTION_UP && !dragMode) {
if (focusedPlot != null) {
focusedPlot.getShape().getPaint().setColor(tempColor);
if (focusedPlot != context.newPlot) focusedPlot.getShape().getPaint().setStrokeWidth(3);
 else focusedPlot.getShape().getPaint().setStrokeWidth(7);
}
performClick();
}
}
prevX=x;
prevY=y;
invalidate();
return true;
}