Program: 26971
Project: 26971
Buggy source:
@Override public boolean onTouch(View v,MotionEvent event){
  if (mTouchMode == NONE) {
    mGestureDetector.onTouchEvent(event);
  }
  if (!mChart.isDragEnabled() && !mDrawingEnabled)   return true;
  mDrawingContext.init(mChart.getDrawListener(),mChart.isAutoFinishEnabled());
  LineData data=null;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
    if (event.getPointerCount() == 1 && mDrawingEnabled) {
      if (mLastHighlighted != null) {
        Entry highlightedEntry=mChart.getDataCurrent().getEntryForHighlight(mLastHighlighted);
        Entry currentHoveredEntry=mChart.getEntryByTouchPoint(event.getX(),event.getY());
        if (highlightedEntry != null && highlightedEntry == currentHoveredEntry) {
          mTouchMode=MOVE_POINT;
          mDrawingContext.setMovingEntry(currentHoveredEntry);
          break;
        }
      }
      mTouchMode=DRAWING;
      mStartTimestamp=System.currentTimeMillis();
      mDrawingContext.createNewDrawingDataSet(data);
      Log.i("String_Node_Str","String_Node_Str");
    }
 else {
      mSavedMatrix.set(mMatrix);
    }
  mTouchStartPoint.set(event.getX(),event.getY());
break;
case MotionEvent.ACTION_POINTER_DOWN:
if (event.getPointerCount() == 2) {
long deltaT=System.currentTimeMillis() - mStartTimestamp;
if ((mTouchMode == DRAWING && deltaT < 1000) || !mDrawingEnabled) {
  mDrawingContext.deleteLastDrawingEntry(data);
  mSavedXDist=getXDist(event);
  mSavedYDist=getYDist(event);
  mSavedDist=spacing(event);
  if (mSavedDist > 10f) {
    if (mChart.isPinchZoomEnabled()) {
      mTouchMode=PINCH_ZOOM;
    }
 else {
      if (mSavedXDist > mSavedYDist)       mTouchMode=X_ZOOM;
 else       mTouchMode=Y_ZOOM;
    }
    mSavedMatrix.set(mMatrix);
    midPoint(mTouchPointCenter,event);
    mChart.disableScroll();
  }
}
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (mTouchMode == DRAWING) {
long deltaT=System.currentTimeMillis() - mStartTimestamp;
if (deltaT < 1000 && Math.abs(event.getX() - mTouchStartPoint.x) < 25f) {
mDrawingContext.deleteLastDrawingEntry(data);
onSingleTapConfirmed(event);
Log.i("String_Node_Str","String_Node_Str");
}
 else {
mDrawingContext.finishNewDrawingEntry(data);
mChart.notifyDataSetChanged();
Log.i("String_Node_Str","String_Node_Str");
}
}
 else {
mChart.enableScroll();
}
mDrawingContext.setMovingEntry(null);
mTouchMode=NONE;
break;
case MotionEvent.ACTION_POINTER_UP:
mTouchMode=POSTZOOM;
break;
case MotionEvent.ACTION_MOVE:
if (mTouchMode == DRAWING || mTouchMode == MOVE_POINT) {
PointD p=mChart.getValuesByTouchPoint(event.getX(),event.getY());
int xIndex=(int)p.x;
float yVal=(float)p.y;
if (xIndex < 0) xIndex=0;
if (xIndex >= data.getXValCount()) {
xIndex=data.getXValCount() - 1;
}
boolean added=false;
if (mTouchMode == MOVE_POINT) {
mDrawingContext.getMovingEntry().setVal(yVal);
mDrawingContext.notifyEntryMoved(data);
added=true;
}
 else {
Entry entry=new Entry((float)yVal,xIndex);
added=mDrawingContext.addNewDrawingEntry(entry,data);
}
if (added) {
mChart.notifyDataSetChanged();
}
}
 else if (((mTouchMode == NONE && !mDrawingEnabled) || (mTouchMode != DRAG && event.getPointerCount() == 3)) && Math.abs(distance(event.getX(),mTouchStartPoint.x,event.getY(),mTouchStartPoint.y)) > 25f) {
mSavedMatrix.set(mMatrix);
mTouchStartPoint.set(event.getX(),event.getY());
mTouchMode=DRAG;
mChart.disableScroll();
}
 else if (mTouchMode == DRAG) {
mMatrix.set(mSavedMatrix);
PointF dragPoint=new PointF(event.getX(),event.getY());
if (!mChart.isInvertYAxisEnabled()) {
mMatrix.postTranslate(dragPoint.x - mTouchStartPoint.x,dragPoint.y - mTouchStartPoint.y);
}
 else {
mMatrix.postTranslate(dragPoint.x - mTouchStartPoint.x,-(dragPoint.y - mTouchStartPoint.y));
}
}
 else if (mTouchMode == X_ZOOM || mTouchMode == Y_ZOOM || mTouchMode == PINCH_ZOOM) {
float totalDist=spacing(event);
if (totalDist > 10f) {
PointF t=getTrans(mTouchPointCenter.x,mTouchPointCenter.y);
if (mTouchMode == PINCH_ZOOM) {
float scale=totalDist / mSavedDist;
mMatrix.set(mSavedMatrix);
mMatrix.postScale(scale,scale,t.x,t.y);
}
 else if (mTouchMode == X_ZOOM) {
float xDist=getXDist(event);
float scaleX=xDist / mSavedXDist;
mMatrix.set(mSavedMatrix);
mMatrix.postScale(scaleX,1f,t.x,t.y);
}
 else if (mTouchMode == Y_ZOOM) {
float yDist=getYDist(event);
float scaleY=yDist / mSavedYDist;
mMatrix.set(mSavedMatrix);
mMatrix.postScale(1f,scaleY,t.x,t.y);
}
}
}
 else if (mTouchMode == LONGPRESS) {
mChart.disableScroll();
}
break;
}
mMatrix=mChart.refreshTouch(mMatrix);
return true;
}

Fixed version (ground truth):
@Override public boolean onTouch(View v,MotionEvent event){
  if (mTouchMode == NONE) {
    mGestureDetector.onTouchEvent(event);
  }
  if (!mChart.isDragScaleEnabled() && !mDrawingEnabled)   return true;
  mDrawingContext.init(mChart.getDrawListener(),mChart.isAutoFinishEnabled());
  LineData data=null;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
    if (event.getPointerCount() == 1 && mDrawingEnabled) {
      if (mLastHighlighted != null) {
        Entry highlightedEntry=mChart.getDataCurrent().getEntryForHighlight(mLastHighlighted);
        Entry currentHoveredEntry=mChart.getEntryByTouchPoint(event.getX(),event.getY());
        if (highlightedEntry != null && highlightedEntry == currentHoveredEntry) {
          mTouchMode=MOVE_POINT;
          mDrawingContext.setMovingEntry(currentHoveredEntry);
          break;
        }
      }
      mTouchMode=DRAWING;
      mStartTimestamp=System.currentTimeMillis();
      mDrawingContext.createNewDrawingDataSet(data);
      Log.i("String_Node_Str","String_Node_Str");
    }
 else {
      mSavedMatrix.set(mMatrix);
    }
  mTouchStartPoint.set(event.getX(),event.getY());
break;
case MotionEvent.ACTION_POINTER_DOWN:
if (event.getPointerCount() == 2) {
long deltaT=System.currentTimeMillis() - mStartTimestamp;
if ((mTouchMode == DRAWING && deltaT < 1000) || !mDrawingEnabled) {
  mDrawingContext.deleteLastDrawingEntry(data);
  mSavedXDist=getXDist(event);
  mSavedYDist=getYDist(event);
  mSavedDist=spacing(event);
  if (mSavedDist > 10f) {
    if (mChart.isPinchZoomEnabled()) {
      mTouchMode=PINCH_ZOOM;
    }
 else {
      if (mSavedXDist > mSavedYDist)       mTouchMode=X_ZOOM;
 else       mTouchMode=Y_ZOOM;
    }
    mSavedMatrix.set(mMatrix);
    midPoint(mTouchPointCenter,event);
    mChart.disableScroll();
  }
}
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (mTouchMode == DRAWING) {
long deltaT=System.currentTimeMillis() - mStartTimestamp;
if (deltaT < 1000 && Math.abs(event.getX() - mTouchStartPoint.x) < 25f) {
mDrawingContext.deleteLastDrawingEntry(data);
onSingleTapConfirmed(event);
Log.i("String_Node_Str","String_Node_Str");
}
 else {
mDrawingContext.finishNewDrawingEntry(data);
mChart.notifyDataSetChanged();
Log.i("String_Node_Str","String_Node_Str");
}
}
 else {
mChart.enableScroll();
}
mDrawingContext.setMovingEntry(null);
mTouchMode=NONE;
break;
case MotionEvent.ACTION_POINTER_UP:
mTouchMode=POSTZOOM;
break;
case MotionEvent.ACTION_MOVE:
if (mTouchMode == DRAWING || mTouchMode == MOVE_POINT) {
PointD p=mChart.getValuesByTouchPoint(event.getX(),event.getY());
int xIndex=(int)p.x;
float yVal=(float)p.y;
if (xIndex < 0) xIndex=0;
if (xIndex >= data.getXValCount()) {
xIndex=data.getXValCount() - 1;
}
boolean added=false;
if (mTouchMode == MOVE_POINT) {
mDrawingContext.getMovingEntry().setVal(yVal);
mDrawingContext.notifyEntryMoved(data);
added=true;
}
 else {
Entry entry=new Entry((float)yVal,xIndex);
added=mDrawingContext.addNewDrawingEntry(entry,data);
}
if (added) {
mChart.notifyDataSetChanged();
}
}
 else if (((mTouchMode == NONE && !mDrawingEnabled) || (mTouchMode != DRAG && event.getPointerCount() == 3)) && Math.abs(distance(event.getX(),mTouchStartPoint.x,event.getY(),mTouchStartPoint.y)) > 25f) {
mSavedMatrix.set(mMatrix);
mTouchStartPoint.set(event.getX(),event.getY());
mTouchMode=DRAG;
mChart.disableScroll();
}
 else if (mTouchMode == DRAG) {
mMatrix.set(mSavedMatrix);
PointF dragPoint=new PointF(event.getX(),event.getY());
if (!mChart.isInvertYAxisEnabled()) {
mMatrix.postTranslate(dragPoint.x - mTouchStartPoint.x,dragPoint.y - mTouchStartPoint.y);
}
 else {
mMatrix.postTranslate(dragPoint.x - mTouchStartPoint.x,-(dragPoint.y - mTouchStartPoint.y));
}
}
 else if (mTouchMode == X_ZOOM || mTouchMode == Y_ZOOM || mTouchMode == PINCH_ZOOM) {
float totalDist=spacing(event);
if (totalDist > 10f) {
PointF t=getTrans(mTouchPointCenter.x,mTouchPointCenter.y);
if (mTouchMode == PINCH_ZOOM) {
float scale=totalDist / mSavedDist;
mMatrix.set(mSavedMatrix);
mMatrix.postScale(scale,scale,t.x,t.y);
}
 else if (mTouchMode == X_ZOOM) {
float xDist=getXDist(event);
float scaleX=xDist / mSavedXDist;
mMatrix.set(mSavedMatrix);
mMatrix.postScale(scaleX,1f,t.x,t.y);
}
 else if (mTouchMode == Y_ZOOM) {
float yDist=getYDist(event);
float scaleY=yDist / mSavedYDist;
mMatrix.set(mSavedMatrix);
mMatrix.postScale(1f,scaleY,t.x,t.y);
}
}
}
 else if (mTouchMode == LONGPRESS) {
mChart.disableScroll();
}
break;
}
mMatrix=mChart.refreshTouch(mMatrix);
return true;
}