Adjust DirectionDragListener

This commit is contained in:
serso 2016-03-14 21:16:28 +01:00
parent 7203dda7aa
commit e07a0d6d13
2 changed files with 5 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.PointF; import android.graphics.PointF;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View; import android.view.View;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
@ -30,17 +31,20 @@ public abstract class DirectionDragListener implements DragListener {
public boolean onDrag(@NonNull View view, @NonNull DragEvent e) { public boolean onDrag(@NonNull View view, @NonNull DragEvent e) {
final long duration = e.motionEvent.getEventTime() - e.motionEvent.getDownTime(); final long duration = e.motionEvent.getEventTime() - e.motionEvent.getDownTime();
if (duration < 40 || duration > 2500) { if (duration < 40 || duration > 2500) {
Log.v("DirectionDragListener", "Drag stopped: too fast movement, " + duration + "ms");
return false; return false;
} }
final float distance = distance(e.start, e.end); final float distance = distance(e.start, e.end);
if (distance < minDistancePxs) { if (distance < minDistancePxs) {
Log.v("DirectionDragListener", "Drag stopped: too short distance, " + distance + "pxs");
return false; return false;
} }
final double angle = toDegrees(getAngle(e.start, sum(e.start, axis), e.end, right)); final double angle = toDegrees(getAngle(e.start, sum(e.start, axis), e.end, right));
final DragDirection direction = getDirection((float) angle, right[0]); final DragDirection direction = getDirection((float) angle, right[0]);
if (direction == null) { if (direction == null) {
Log.v("DirectionDragListener", "Drag stopped: unknown direction");
return false; return false;
} }

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<dimen name="drag_min_distance">25dp</dimen> <dimen name="drag_min_distance">15dp</dimen>
</resources> </resources>