@Override public boolean canZoom() { return mAttacher.canZoom(); }
public final void onScale(float scaleFactor, float focusX, float focusY) { if (DEBUG) { Log.d(LOG_TAG, String.format("onScale: scale: %.2f. fX: %.2f. fY: %.2f", scaleFactor, focusX, focusY)); } if (hasDrawable(getImageView()) && (getScale() < mMaxScale || scaleFactor < 1f)) { mSuppMatrix.postScale(scaleFactor, scaleFactor, focusX, focusY); checkAndDisplayMatrix(); } }
/** * Helper method that simply checks the Matrix, and then displays the result */ private void checkAndDisplayMatrix() { checkMatrixBounds(); setImageViewMatrix(getDisplayMatrix()); }
@Override public final RectF getDisplayRect() { checkMatrixBounds(); return getDisplayRect(getDisplayMatrix()); }
private void setImageViewMatrix(Matrix matrix) { ImageView imageView = getImageView(); if (null != imageView) { checkImageViewScaleType(); imageView.setImageMatrix(matrix); // Call MatrixChangedListener if needed if (null != mMatrixChangeListener) { RectF displayRect = getDisplayRect(matrix); if (null != displayRect) { mMatrixChangeListener.onMatrixChanged(displayRect); } } } }
public final void onDrag(float dx, float dy) { if (DEBUG) { Log.d(LOG_TAG, String.format("onDrag: dx: %.2f. dy: %.2f", dx, dy)); } ImageView imageView = getImageView(); if (null != imageView && hasDrawable(imageView)) { mSuppMatrix.postTranslate(dx, dy); checkAndDisplayMatrix(); /** * Here we decide whether to let the ImageView's parent to start * taking over the touch event. * * First we check whether this function is enabled. We never want * the parent to take over if we're scaling. We then check the edge * we're on, and the direction of the scroll (i.e. if we're pulling * against the edge, aka 'overscrolling', let the parent take over). */ if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling()) { if (mScrollEdge == EDGE_BOTH || (mScrollEdge == EDGE_LEFT && dx >= 1f) || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) { imageView.getParent().requestDisallowInterceptTouchEvent(false); } } } }
cancelFling(); break; if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true;
private void checkMatrixBounds() { final ImageView imageView = getImageView(); if (null == imageView) { return; final RectF rect = getDisplayRect(getDisplayMatrix()); if (null == rect) { return;
@Override public void run() { ImageView imageView = getImageView(); if (null != imageView && mScroller.computeScrollOffset()) { final int newX = mScroller.getCurrX(); final int newY = mScroller.getCurrY(); if (DEBUG) { Log.d(LOG_TAG, "fling run(). CurrentX:" + mCurrentX + " CurrentY:" + mCurrentY + " NewX:" + newX + " NewY:" + newY); } mSuppMatrix.postTranslate(mCurrentX - newX, mCurrentY - newY); setImageViewMatrix(getDisplayMatrix()); mCurrentX = newX; mCurrentY = newY; // Post On animation Compat.postOnAnimation(imageView, this); } } }
public final boolean onSingleTapConfirmed(MotionEvent e) { ImageView imageView = getImageView(); if (null != imageView) { if (null != mPhotoTapListener) { final RectF displayRect = getDisplayRect(); if (null != displayRect) { final float x = e.getX(), y = e.getY(); // Check to see if the user tapped on the photo if (displayRect.contains(x, y)) { float xResult = (x - displayRect.left) / displayRect.width(); float yResult = (y - displayRect.top) / displayRect.height(); mPhotoTapListener.onPhotoTap(imageView, xResult, yResult); return true; } } } if (null != mViewTapListener) { mViewTapListener.onViewTap(imageView, e.getX(), e.getY()); } } return false; }
public final ImageView getImageView() { ImageView imageView = null; if (null != mImageView) { imageView = mImageView.get(); } // If we don't have an ImageView, call cleanup() if (null == imageView) { cleanup(); throw new IllegalStateException( "ImageView no longer exists. You should not use this PhotoViewAttacher any more."); } return imageView; }
@Override public void setMinScale(float minScale) { // checkZoomLevels(minScale, mMidScale, mMaxScale); checkZoomLevels(minScale, mMaxScale); mMinScale = minScale; }
@Override public RectF getDisplayRect() { return mAttacher.getDisplayRect(); }
public EasePhotoView(Context context, AttributeSet attr, int defStyle) { super(context, attr, defStyle); super.setScaleType(ScaleType.MATRIX); mAttacher = new PhotoViewAttacher(this); if (null != mPendingScaleType) { setScaleType(mPendingScaleType); mPendingScaleType = null; } }
@Override public final RectF getDisplayRect() { checkMatrixBounds(); return getDisplayRect(getDisplayMatrix()); }
private void setImageViewMatrix(Matrix matrix) { ImageView imageView = getImageView(); if (null != imageView) { checkImageViewScaleType(); imageView.setImageMatrix(matrix); // Call MatrixChangedListener if needed if (null != mMatrixChangeListener) { RectF displayRect = getDisplayRect(matrix); if (null != displayRect) { mMatrixChangeListener.onMatrixChanged(displayRect); } } } }
public final void onDrag(float dx, float dy) { if (DEBUG) { Log.d(LOG_TAG, String.format("onDrag: dx: %.2f. dy: %.2f", dx, dy)); } ImageView imageView = getImageView(); if (null != imageView && hasDrawable(imageView)) { mSuppMatrix.postTranslate(dx, dy); checkAndDisplayMatrix(); /** * Here we decide whether to let the ImageView's parent to start * taking over the touch event. * * First we check whether this function is enabled. We never want * the parent to take over if we're scaling. We then check the edge * we're on, and the direction of the scroll (i.e. if we're pulling * against the edge, aka 'overscrolling', let the parent take over). */ if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling()) { if (mScrollEdge == EDGE_BOTH || (mScrollEdge == EDGE_LEFT && dx >= 1f) || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) { imageView.getParent().requestDisallowInterceptTouchEvent(false); } } } }
cancelFling(); break; if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true;
private void checkMatrixBounds() { final ImageView imageView = getImageView(); if (null == imageView) { return; final RectF rect = getDisplayRect(getDisplayMatrix()); if (null == rect) { return;
@Override public void run() { ImageView imageView = getImageView(); if (null != imageView && mScroller.computeScrollOffset()) { final int newX = mScroller.getCurrX(); final int newY = mScroller.getCurrY(); if (DEBUG) { Log.d(LOG_TAG, "fling run(). CurrentX:" + mCurrentX + " CurrentY:" + mCurrentY + " NewX:" + newX + " NewY:" + newY); } mSuppMatrix.postTranslate(mCurrentX - newX, mCurrentY - newY); setImageViewMatrix(getDisplayMatrix()); mCurrentX = newX; mCurrentY = newY; // Post On animation Compat.postOnAnimation(imageView, this); } } }