public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (!canScroll()) {
return false;
}
if (DEBUG) {
Log.i(TAG, "onFling");
}
if (Math.abs(velocityX) > (mMinFlingVelocity * 4) || Math.abs(velocityY) > (mMinFlingVelocity * 4)) {
if (DEBUG) {
Log.v(TAG, "velocity: " + velocityY);
Log.v(TAG, "diff: " + (e2.getY() - e1.getY()));
}
final float scale = Math.min(Math.max(2f, getScale() / 2), 3.f);
float scaledDistanceX = ((velocityX) / mMaxFlingVelocity) * (getWidth() * scale);
float scaledDistanceY = ((velocityY) / mMaxFlingVelocity) * (getHeight() * scale);
if (DEBUG) {
Log.v(TAG, "scale: " + getScale() + ", scale_final: " + scale);
Log.v(TAG, "scaledDistanceX: " + scaledDistanceX);
Log.v(TAG, "scaledDistanceY: " + scaledDistanceY);
}
mUserScaled = true;
double total = Math.sqrt(Math.pow(scaledDistanceX, 2) + Math.pow(scaledDistanceY, 2));
scrollBy(scaledDistanceX, scaledDistanceY, (long) Math.min(Math.max(300, total / 5), 800));
postInvalidate();
return true;
}
return false;
}