Java Code Examples for android.view.ScaleGestureDetector#getCurrentSpan()

The following examples show how to use android.view.ScaleGestureDetector#getCurrentSpan() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapViewScaleGestureDetectorListener.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    if (!scaling) {
        return true;
    }
    currentScale = detector.getCurrentSpan() / firstSpan;

    float focusX = detector.getFocusX();
    float focusY = detector.getFocusY();

    this.mapView.setScale(currentScale);
    this.mapView.getController().offsetDeltaScroll(lastFocusX - focusX, lastFocusY - focusY);
    this.mapView.getController().panBy(lastFocusX - focusX, lastFocusY - focusY, true);

    lastFocusX = focusX;
    lastFocusY = focusY;
    return true;
}
 
Example 2
Source File: ImageViewTouch.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
@Override
public boolean onScale( ScaleGestureDetector detector ) {
	float span = detector.getCurrentSpan() - detector.getPreviousSpan();
	float targetScale = getScale() * detector.getScaleFactor();
	
	if ( mScaleEnabled ) {
		if( mScaled && span != 0 ) {
			mUserScaled = true;
			targetScale = Math.min( getMaxScale(), Math.max( targetScale, getMinScale() - 0.1f ) );
			zoomTo( targetScale, detector.getFocusX(), detector.getFocusY() );
			mDoubleTapDirection = 1;
			invalidate();
			return true;
		}
		
		// This is to prevent a glitch the first time 
		// image is scaled.
		if( !mScaled ) mScaled = true;
	}
	return true;
}
 
Example 3
Source File: ImageViewTouch.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public boolean onScale( ScaleGestureDetector detector ) {
	float span = detector.getCurrentSpan() - detector.getPreviousSpan();
	float targetScale = getScale() * detector.getScaleFactor();
	
	if ( mScaleEnabled ) {
		if( mScaled && span != 0 ) {
			mUserScaled = true;
			targetScale = Math.min( getMaxScale(), Math.max( targetScale, getMinScale() - 0.1f ) );
			zoomTo( targetScale, detector.getFocusX(), detector.getFocusY() );
			mDoubleTapDirection = 1;
			invalidate();
			return true;
		}
		
		// This is to prevent a glitch the first time 
		// image is scaled.
		if( !mScaled ) mScaled = true;
	}
	return true;
}
 
Example 4
Source File: ZoomScaleGestureListener.java    From pixelvisualcorecamera with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
  label.setText(formatZoomLabel(zoomLevel));
  label.setVisibility(View.VISIBLE);
  startingSpan = detector.getCurrentSpan();
  return true;
}
 
Example 5
Source File: PreviewChartTouchHandler.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    if (isZoomEnabled) {
        float scale = detector.getCurrentSpan() / detector.getPreviousSpan();
        if (Float.isInfinite(scale)) {
            scale = 1;
        }
        return chartZoomer.scale(computator, detector.getFocusX(), detector.getFocusY(), scale);
    }

    return false;
}
 
Example 6
Source File: MapViewScaleGestureDetectorListener.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
    lastFocusX = detector.getFocusX();
    lastFocusY = detector.getFocusY();
    firstSpan = detector.getCurrentSpan();
    currentScale = 1.0f;
    if (!this.mapView.isAnimating()) {
        this.mapView.setIsAnimating(true);
        this.mapView.getController().aboutToStartAnimation(lastFocusX, lastFocusY);
        scaling = true;
    }
    return true;
}
 
Example 7
Source File: MapView.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void zoomStart(ScaleGestureDetector scaleGestureDetector)
{

    if (mDrawingState == DRAW_STATE_zooming) {
        return;
    }

    mDrawingState = DRAW_STATE_zooming;
    mCurrentSpan = scaleGestureDetector.getCurrentSpan();
    mCurrentFocusLocation.set(
            -scaleGestureDetector.getFocusX(), -scaleGestureDetector.getFocusY());
    mScaleFactor = 1.f;

    mMap.buffer(0, 0, 1);
}
 
Example 8
Source File: FlickableImageView.java    From FlickableView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    float span = detector.getCurrentSpan() - detector.getPreviousSpan();
    float targetScale = getScale() * detector.getScaleFactor();

    if (mScaleEnabled) {
        if (mOnZoomListener != null) {
            if (!mScaling) {
                mOnZoomListener.onStartZoom();
                mScaling = true;
            }
        }

        if (mScaled && span != 0) {
            mUserScaled = true;
            targetScale = Math.min(getMaxScale(), Math.max(targetScale, getMinScale() - 0.1f));
            zoomTo(targetScale, detector.getFocusX(), detector.getFocusY());
            mDoubleTapDirection = 1;
            invalidate();
            return true;
        }

        if (!mScaled) {
            mScaled = true;
        }
    }
    return true;
}
 
Example 9
Source File: PreviewChartTouchHandler.java    From SmartChart with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    if (isZoomEnabled) {
        float scale = detector.getCurrentSpan() / detector.getPreviousSpan();
        if (Float.isInfinite(scale)) {
            scale = 1;
        }
        return chartZoomer.scale(computator, detector.getFocusX(), detector.getFocusY(), scale);
    }

    return false;
}
 
Example 10
Source File: ScaleGesture.java    From AudioVideoCodec with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    if (detector.getCurrentSpan() > scaleCapacity) {
        listener.zoomLarge();
    } else {
        listener.zoomLittle();
    }
    scaleCapacity = detector.getCurrentSpan();
    return false;
}
 
Example 11
Source File: ZoomScaleGestureListener.java    From pixelvisualcorecamera with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
  float currentSpan = detector.getCurrentSpan();
  double distanceChange = currentSpan - startingSpan;
  double zoomLevelChange = (distanceChange / DP_PER_ZOOM_FACTOR);

  // Clamp the zoom level to valid intervals.
  intermediateZoomLevel = Math.min(
      Math.max(zoomLevel + zoomLevelChange, DEFAULT_ZOOM),
      maxZoom);
  controller.setZoom(intermediateZoomLevel);
  label.setText(formatZoomLabel(intermediateZoomLevel));

  return true;
}
 
Example 12
Source File: ZoomScaleGestureListener.java    From pixelvisualcorecamera with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
  float currentSpan = detector.getCurrentSpan();
  double distanceChange = currentSpan - startingSpan;
  double zoomLevelChange = distanceChange / DP_PER_ZOOM_INTERVAL;

  // Clamp the zoom level to valid intervals.
  intermediateZoomLevel = Math.min(
      Math.max((int) Math.round(zoomLevel + zoomLevelChange), 0),
      maxZoom);
  controller.setZoom(intermediateZoomLevel);
  label.setText(formatZoomLabel(intermediateZoomLevel));

  return true;
}
 
Example 13
Source File: ZoomScaleGestureListener.java    From pixelvisualcorecamera with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
  label.setText(formatZoomLabel(zoomLevel));
  label.setVisibility(View.VISIBLE);
  startingSpan = detector.getCurrentSpan();
  return true;
}
 
Example 14
Source File: ScaleGestureDetectorCompat.java    From EazeGraph with Apache License 2.0 5 votes vote down vote up
/**
 * @see android.view.ScaleGestureDetector#getCurrentSpanY()
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static float getCurrentSpanY(ScaleGestureDetector scaleGestureDetector) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return scaleGestureDetector.getCurrentSpanY();
    } else {
        return scaleGestureDetector.getCurrentSpan();
    }
}
 
Example 15
Source File: ScaleGestureCompat.java    From Cinema-App-Concept with MIT License 5 votes vote down vote up
/**
 * @see ScaleGestureDetector#getCurrentSpanX()
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static float getCurrentSpanX(ScaleGestureDetector scaleGestureDetector) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return scaleGestureDetector.getCurrentSpanX();
    } else {
        return scaleGestureDetector.getCurrentSpan();
    }
}
 
Example 16
Source File: ScaleGestureDetectorCompat.java    From EazeGraph with Apache License 2.0 5 votes vote down vote up
/**
 * @see android.view.ScaleGestureDetector#getCurrentSpanX()
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static float getCurrentSpanX(ScaleGestureDetector scaleGestureDetector) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return scaleGestureDetector.getCurrentSpanX();
    } else {
        return scaleGestureDetector.getCurrentSpan();
    }
}
 
Example 17
Source File: PinchToOverviewListener.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    if (mThresholdManager.getPassedThreshold() == PinchThresholdManager.THRESHOLD_THREE) {
        // We completed the pinch, so stop listening to further movement until user lets go.
        return true;
    }
    if (mLauncher.getDragController().isDragging()) {
        mLauncher.getDragController().cancelDrag();
    }

    float pinchDist = detector.getCurrentSpan() - detector.getPreviousSpan();
    if (pinchDist < 0 && mWorkspace.isInOverviewMode() ||
            pinchDist > 0 && !mWorkspace.isInOverviewMode()) {
        // Pinching the wrong way, so ignore.
        return false;
    }
    // Pinch distance must equal the workspace width before switching states.
    int pinchDistanceToCompleteTransition = mWorkspace.getWidth();
    float overviewScale = mWorkspace.getOverviewModeShrinkFactor();
    float initialWorkspaceScale = mWorkspace.isInOverviewMode() ? overviewScale : 1f;
    float pinchScale = initialWorkspaceScale + pinchDist / pinchDistanceToCompleteTransition;
    // Bound the scale between the overview scale and the normal workspace scale (1f).
    pinchScale = Math.max(overviewScale, Math.min(pinchScale, 1f));
    // Progress ranges from 0 to 1, where 0 corresponds to the overview scale and 1
    // corresponds to the normal workspace scale (1f).
    float progress = (pinchScale - overviewScale) / (1f - overviewScale);
    float interpolatedProgress = mInterpolator.getInterpolation(progress);

    mAnimationManager.setAnimationProgress(interpolatedProgress);
    float passedThreshold = mThresholdManager.updateAndAnimatePassedThreshold(
            interpolatedProgress, mAnimationManager);
    if (passedThreshold == PinchThresholdManager.THRESHOLD_THREE) {
        return true;
    }

    mProgressDelta = interpolatedProgress - mPreviousProgress;
    mPreviousProgress = interpolatedProgress;
    mTimeDelta = System.currentTimeMillis() - mPreviousTimeMillis;
    mPreviousTimeMillis = System.currentTimeMillis();
    return false;
}
 
Example 18
Source File: GOSurfaceView.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
	startSpan = detector.getCurrentSpan();
	startZoom();
	return true;
}
 
Example 19
Source File: ScaleGesture.java    From AudioVideoCodec with Apache License 2.0 4 votes vote down vote up
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
    scaleCapacity = detector.getCurrentSpan();
    listener.zoomEnd();
}
 
Example 20
Source File: ScaleGesture.java    From AudioVideoCodec with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
    scaleCapacity = detector.getCurrentSpan();
    return true;
}