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

Feature/scrollbars #30

Merged
merged 10 commits into from
Jun 14, 2018
7 changes: 6 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="horizontal|vertical"
app:hasClickableChildren="true"
app:horizontalPanEnabled="true"
app:verticalPanEnabled="true"
Expand All @@ -27,7 +28,11 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="gone" />
android:scrollbars="horizontal|vertical"
android:visibility="gone"
app:horizontalPanEnabled="true"
app:verticalPanEnabled="true"
app:zoomEnabled="true" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
22 changes: 22 additions & 0 deletions library/src/main/java/com/otaliastudios/zoom/ZoomImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,34 @@ public boolean onTouchEvent(MotionEvent ev) {
public void onUpdate(ZoomEngine helper, Matrix matrix) {
mMatrix.set(matrix);
setImageMatrix(mMatrix);

awakenScrollBars();
}

@Override
public void onIdle(ZoomEngine engine) {
}

@Override
protected int computeHorizontalScrollOffset() {
return (int) (-1 * mEngine.getPanX() * mEngine.getRealZoom());
}

@Override
protected int computeHorizontalScrollRange() {
return (int) (mDrawableRect.width() * mEngine.getRealZoom());
}

@Override
protected int computeVerticalScrollOffset() {
return (int) (-1 * mEngine.getPanY() * mEngine.getRealZoom());
}

@Override
protected int computeVerticalScrollRange() {
return (int) (mDrawableRect.height() * mEngine.getRealZoom());
}

//endregion

//region APIs
Expand Down
33 changes: 30 additions & 3 deletions library/src/main/java/com/otaliastudios/zoom/ZoomLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public ZoomLayout(@NonNull Context context, @Nullable AttributeSet attrs, @AttrR
if (minZoom > -1) setMinZoom(minZoom, minZoomMode);
if (maxZoom > -1) setMaxZoom(maxZoom, maxZoomMode);
setHasClickableChildren(hasChildren);

setWillNotDraw(false);
}

//region Internal
Expand Down Expand Up @@ -156,23 +158,48 @@ public void onUpdate(ZoomEngine helper, Matrix matrix) {
} else {
invalidate();
}

awakenScrollBars();
}

@Override
public void onIdle(ZoomEngine engine) {
}

@Override
protected int computeHorizontalScrollOffset() {
return (int) (-1 * mEngine.getPanX() * mEngine.getRealZoom());
}

@Override
protected int computeHorizontalScrollRange() {
return (int) (mChildRect.width() * mEngine.getRealZoom());
}

@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);
}

return result;
}

//endregion
Expand Down