@Override protected void onLayoutChanged(final int left, final int top, final int right, final int bottom) { super.onLayoutChanged(left, top, right, bottom); Log.v(TAG, "min: " + getMinScale() + ", max: " + getMaxScale() + ", result: " + (getMaxScale() - getMinScale()) / 2f); mScaleFactor = ((getMaxScale() - getMinScale()) / 2f) + 0.5f; }
@Override public boolean onDoubleTap(MotionEvent e) { if (DEBUG) { Log.i(TAG, "onDoubleTap. double tap enabled? " + mDoubleTapEnabled); } if (mDoubleTapEnabled) { if (Build.VERSION.SDK_INT >= 19) { if (mScaleDetector.isQuickScaleEnabled()) { return true; } } mUserScaled = true; float scale = getScale(); float targetScale; targetScale = onDoubleTapPost(scale, getMaxScale(), getMinScale()); targetScale = Math.min(getMaxScale(), Math.max(targetScale, getMinScale())); zoomTo(targetScale, e.getX(), e.getY(), mDefaultAnimationDuration); } if (null != mDoubleTapListener) { mDoubleTapListener.onDoubleTap(); } return super.onDoubleTap(e); }
@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() - MIN_SCALE_DIFF)); 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; }
@Override public float getMaxScale() { return Math.max(2f, super.getMaxScale()); }
@Override protected void _setImageDrawable( final Drawable drawable, final Matrix initial_matrix, float min_zoom, float max_zoom) { super._setImageDrawable(drawable, initial_matrix, min_zoom, max_zoom); mScaleFactor = getMaxScale() / 3; }
@Override public boolean onDoubleTapEvent(MotionEvent e) { if (mScaleModeAuto && e.getAction() == MotionEvent.ACTION_UP) { float targetScale = Math.min(getMaxScale(), Math.max(onDoubleTapPost(getScale()), getMinScale())); zoomTo(targetScale, e.getX(), e.getY(), DEFAULT_ANIMATION_DURATION); invalidate(); } mScaleModeAuto = true; return super.onDoubleTapEvent(e); }
@Override public boolean onScale(ScaleGestureDetector detector) { float span = detector.getCurrentSpan() - detector.getPreviousSpan(); float targetScale = getScale() * detector.getScaleFactor(); if (mScaleEnabled) { mScaleModeAuto = false; if (mScaled && span != 0) { mUserScaled = true; targetScale = Math.min(getMaxScale(), Math.max(targetScale, getMinScale() - 0.1f)); zoomTo(targetScale, detector.getFocusX(), detector.getFocusY()); invalidate(); return true; } // This is to prevent a glitch the first time image is scaled. if (!mScaled) mScaled = true; } return true; } }