Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for scale changed listener #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public interface OnLayoutChangeListener {
*/
void onLayoutChanged( boolean changed, int left, int top, int right, int bottom );
};

public interface OnScaleChangeListener {
/**
* Callback invoked when the user scale status has changed
* @param isScaled
*/
void onScaleChanged(boolean isScaled);
}

/**
* Use this to change the {@link ImageViewTouchBase#setDisplayType(DisplayType)} of
Expand Down Expand Up @@ -90,6 +98,7 @@ public enum DisplayType {
private int mThisWidth = -1;
private int mThisHeight = -1;
private PointF mCenter = new PointF();
private float mOldScale;

protected DisplayType mScaleType = DisplayType.NONE;
private boolean mScaleTypeChanged;
Expand All @@ -103,6 +112,7 @@ public enum DisplayType {

private OnDrawableChangeListener mDrawableChangeListener;
private OnLayoutChangeListener mOnLayoutChangeListener;
private OnScaleChangeListener mOnScaleChangeListener;

public ImageViewTouchBase( Context context ) {
this( context, null );
Expand All @@ -124,6 +134,10 @@ public void setOnDrawableChangedListener( OnDrawableChangeListener listener ) {
public void setOnLayoutChangeListener( OnLayoutChangeListener listener ) {
mOnLayoutChangeListener = listener;
}

public void setOnScaleChangeListener( OnScaleChangeListener listener ) {
mOnScaleChangeListener = listener;
}

protected void init( Context context, AttributeSet attrs, int defStyle ) {
setScaleType( ImageView.ScaleType.MATRIX );
Expand Down Expand Up @@ -509,6 +523,12 @@ protected void fireOnDrawableChangeListener( Drawable drawable ) {
mDrawableChangeListener.onDrawableChanged( drawable );
}
}

protected void fireOnScaleChanged() {
if (null != mOnScaleChangeListener) {
mOnScaleChangeListener.onScaleChanged(getMinScale() != getScale());
}
}

/**
* Called just after {@link #onLayout(boolean, int, int, int, int)}
Expand Down Expand Up @@ -757,6 +777,10 @@ public float getScale() {
public float getBaseScale() {
return getScale( mBaseMatrix );
}

public boolean isUserScaled() {
return mUserScaled;
}

protected void center( boolean horizontal, boolean vertical ) {
final Drawable drawable = getDrawable();
Expand Down Expand Up @@ -869,7 +893,12 @@ protected void zoomTo( float scale, float centerX, float centerY ) {
center( true, true );
}

protected void onZoom( float scale ){}
protected void onZoom( float scale ) {
if (scale != mOldScale) {
fireOnScaleChanged();
}
mOldScale = scale;
}

protected void onZoomAnimationCompleted( float scale ){}

Expand Down