support non-step-based zooming
This commit is contained in:
parent
f780734c9c
commit
c6a90066a2
@ -33,10 +33,9 @@ class GestureHelper {
|
|||||||
|
|
||||||
final ScaleGestureDetector scaleDetector = new ScaleGestureDetector(context,
|
final ScaleGestureDetector scaleDetector = new ScaleGestureDetector(context,
|
||||||
new ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
new ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
||||||
// As the zoom value is discrete we listen to scaling step and not scaling ratio
|
float SPAN_RATIO = 600;
|
||||||
float SPAN_STEP = 150;
|
|
||||||
float initialSpan;
|
float initialSpan;
|
||||||
int prevNbStep;
|
float prevNbStep;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onScaleBegin(ScaleGestureDetector detector) {
|
public boolean onScaleBegin(ScaleGestureDetector detector) {
|
||||||
@ -48,16 +47,16 @@ class GestureHelper {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onScale(ScaleGestureDetector detector) {
|
public boolean onScale(ScaleGestureDetector detector) {
|
||||||
float spanDiff = initialSpan - detector.getCurrentSpan();
|
float spanDiff = initialSpan - detector.getCurrentSpan();
|
||||||
int curNbStep = (int) (spanDiff/SPAN_STEP);
|
float curNbStep = spanDiff / SPAN_RATIO;
|
||||||
if (curNbStep != prevNbStep) {
|
|
||||||
int stepDiff = curNbStep - prevNbStep;
|
float stepDiff = curNbStep - prevNbStep;
|
||||||
if (stepDiff > 0) {
|
if (stepDiff > 0) {
|
||||||
listener.onZoomOut(stepDiff * 0.25f);
|
listener.onZoomOut(stepDiff);
|
||||||
} else {
|
} else {
|
||||||
listener.onZoomIn(Math.abs(stepDiff * 0.25f));
|
listener.onZoomIn(Math.abs(stepDiff));
|
||||||
}
|
}
|
||||||
prevNbStep = curNbStep;
|
prevNbStep = curNbStep;
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user