-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Feature/scrollbars #30
Changes from 6 commits
2b75841
8d24ccd
fe7d677
2cb6a20
3ceadcb
e383def
91d9ba1
e66283d
4152cdd
16f9a0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.Matrix; | ||
import android.graphics.Rect; | ||
import android.graphics.RectF; | ||
import android.graphics.drawable.Drawable; | ||
import android.support.annotation.AttrRes; | ||
|
@@ -89,12 +90,50 @@ public boolean onTouchEvent(MotionEvent ev) { | |
public void onUpdate(ZoomEngine helper, Matrix matrix) { | ||
mMatrix.set(matrix); | ||
setImageMatrix(mMatrix); | ||
|
||
if (!awakenScrollBars()) { | ||
invalidate(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onIdle(ZoomEngine engine) { | ||
} | ||
|
||
@Override | ||
protected int computeHorizontalScrollExtent() { | ||
Rect localRect = new Rect(); | ||
getLocalVisibleRect(localRect); | ||
return localRect.width(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason why using this rather than If there is a reason, could you cache this rect in a tempRect field? So we don't create a lot of them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I think it should also work with |
||
} | ||
|
||
@Override | ||
protected int computeHorizontalScrollOffset() { | ||
return (int) (-1 * mEngine.getPanX() * mEngine.getRealZoom()); | ||
} | ||
|
||
@Override | ||
protected int computeHorizontalScrollRange() { | ||
return (int) (mDrawableRect.width() * mEngine.getRealZoom()); | ||
} | ||
|
||
@Override | ||
protected int computeVerticalScrollExtent() { | ||
Rect localRect = new Rect(); | ||
getLocalVisibleRect(localRect); | ||
return localRect.height(); | ||
} | ||
|
||
@Override | ||
protected int computeVerticalScrollOffset() { | ||
return (int) (-1 * mEngine.getPanY() * mEngine.getRealZoom()); | ||
} | ||
|
||
@Override | ||
protected int computeVerticalScrollRange() { | ||
return (int) (mDrawableRect.height() * mEngine.getRealZoom()); | ||
} | ||
|
||
//endregion | ||
|
||
//region APIs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import android.content.res.TypedArray; | ||
import android.graphics.Canvas; | ||
import android.graphics.Matrix; | ||
import android.graphics.Rect; | ||
import android.graphics.RectF; | ||
import android.support.annotation.AttrRes; | ||
import android.support.annotation.NonNull; | ||
|
@@ -21,13 +22,13 @@ | |
* Uses {@link ZoomEngine} to allow zooming and pan events onto a view hierarchy. | ||
* The hierarchy must be contained in a single view, added to this layout | ||
* (like what you do with a ScrollView). | ||
* | ||
* <p> | ||
* If the hierarchy has clickable children that should react to touch events, you are | ||
* required to call {@link #setHasClickableChildren(boolean)} or use the attribute. | ||
* This is off by default because it is more expensive in terms of performance. | ||
* | ||
* <p> | ||
* Currently padding to this view / margins to the child view are NOT supported. | ||
* | ||
* <p> | ||
* TODO: support padding (from inside ZoomEngine that gets the view) | ||
* TODO: support layout_margin (here) | ||
*/ | ||
|
@@ -150,23 +151,66 @@ public void onUpdate(ZoomEngine helper, Matrix matrix) { | |
} else { | ||
invalidate(); | ||
} | ||
|
||
if (!awakenScrollBars()) { | ||
invalidate(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onIdle(ZoomEngine engine) { | ||
} | ||
|
||
@Override | ||
protected int computeHorizontalScrollExtent() { | ||
Rect localRect = new Rect(); | ||
getLocalVisibleRect(localRect); | ||
return localRect.width(); | ||
} | ||
|
||
@Override | ||
protected int computeHorizontalScrollOffset() { | ||
return (int) (-1 * mEngine.getPanX() * mEngine.getRealZoom()); | ||
} | ||
|
||
@Override | ||
protected int computeHorizontalScrollRange() { | ||
return (int) (mChildRect.width() * mEngine.getRealZoom()); | ||
} | ||
|
||
@Override | ||
protected int computeVerticalScrollExtent() { | ||
Rect localRect = new Rect(); | ||
getLocalVisibleRect(localRect); | ||
return localRect.height(); | ||
} | ||
|
||
@Override | ||
protected int computeVerticalScrollOffset() { | ||
return (int) (-1 * mEngine.getPanY() * mEngine.getRealZoom()); | ||
} | ||
|
||
@Override | ||
protected int computeVerticalScrollRange() { | ||
return (int) (mChildRect.height() * mEngine.getRealZoom()); | ||
} | ||
|
||
@Override | ||
protected boolean drawChild(Canvas canvas, View child, long drawingTime) { | ||
boolean result; | ||
|
||
if (!mHasClickableChildren) { | ||
int save = canvas.save(); | ||
canvas.setMatrix(mMatrix); | ||
boolean result = super.drawChild(canvas, child, drawingTime); | ||
result = super.drawChild(canvas, child, drawingTime); | ||
canvas.restoreToCount(save); | ||
return result; | ||
} else { | ||
return super.drawChild(canvas, child, drawingTime); | ||
result = super.drawChild(canvas, child, drawingTime); | ||
} | ||
|
||
onDrawScrollBars(canvas); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this and use |
||
|
||
return result; | ||
} | ||
|
||
//endregion | ||
|
@@ -205,6 +249,7 @@ public void setHasClickableChildren(boolean hasClickableChildren) { | |
|
||
/** | ||
* Gets the backing {@link ZoomEngine} so you can access its APIs. | ||
* | ||
* @return the backing engine | ||
*/ | ||
public ZoomEngine getEngine() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for this call? We should not need to invalidate. setImageMatrix will do it.
Same for ZoomLayout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for
awakenScrollBars()
states:So I added this condition. I guess if
setImageMatrix
already does it this check is useless.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think it's better to simply call awakenScrollBars() and ignore the result.
Also, you need to merge the other PR changes to merge this one. Thanks!