@Override public boolean onSingleTapConfirmed(MotionEvent e) { if (null != mSingleTapListener) { mSingleTapListener.onSingleTapConfirmed(); } return ImageViewTouch.this.onSingleTapConfirmed(e); }
@Override public void onClick(View v) { int current = mImage.getDisplayType().ordinal() + 1; if (current >= DisplayType.values().length) { current = 0; } mImage.setDisplayType(DisplayType.values()[current]); } }
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (!canScroll()) { return false; } mUserScaled = true; scrollBy(-distanceX, -distanceY); invalidate(); return true; }
protected void zoomTo(float scale, float centerX, float centerY) { if (scale > getMaxScale()) { scale = getMaxScale(); } float oldScale = getScale(); float deltaScale = scale / oldScale; postScale(deltaScale, centerX, centerY); onZoom(getScale()); center(true, true); }
@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; }
protected void center(boolean horizontal, boolean vertical) { final Drawable drawable = getDrawable(); if (drawable == null) { return; } RectF rect = getCenter(mSuppMatrix, horizontal, vertical); if (rect.left != 0 || rect.top != 0) { postTranslate(rect.left, rect.top); } }
public boolean onSingleTapUp(MotionEvent e) { if (getBitmapChanged()) { return false; } return true; }
/** * Clear the current drawable */ public void clear() { setImageBitmap(null); }
protected void fireOnLayoutChangeListener(int left, int top, int right, int bottom) { if (null != mOnLayoutChangeListener) { mOnLayoutChangeListener.onLayoutChanged(true, left, top, right, bottom); } }
protected void fireOnDrawableChangeListener(Drawable drawable) { if (null != mDrawableChangeListener) { mDrawableChangeListener.onDrawableChanged(drawable); } }
/** * Returns the current view matrix * * @return */ public Matrix getImageViewMatrix() { return getImageViewMatrix(mSuppMatrix); }
/** * Returns the current image scale * * @return */ public float getScale() { return getScale(mSuppMatrix); }
/** * Get the X Scale of the matrix for Fit Scale Calculation * @param matrix {@link Matrix} Bitmap Matrix * @return (float) Scale */ protected float getXScale(Matrix matrix) { return getValue(matrix, Matrix.MSCALE_X); }
/** * Scrolls the view by the x and y amount * * @param x * @param y */ public void scrollBy(float x, float y) { panBy(x, y); }
@Override public void run() { setImageDrawable(drawable, initialMatrix, minZoom, maxZoom); } };
/** * Returns the current maximum allowed image scale * * @return */ public float getMaxScale() { if (mMaxZoom == ZOOM_INVALID) { mMaxZoom = computeMaxZoom(); } return mMaxZoom; }
public boolean onDown(MotionEvent e) { if (getBitmapChanged()) { return false; } return true; }
/** * {@inheritDoc} Set the new image to display and reset the internal matrix. * * @param bitmap the {@link Bitmap} to display * @see {@link ImageView#setImageBitmap(Bitmap)} */ @Override public void setImageBitmap(final Bitmap bitmap) { setImageBitmap(bitmap, null, ZOOM_INVALID, ZOOM_INVALID); }