Skip to content

Add ability to toggle between vertical and horizontal scrolling #8

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ enum TopBarMode {Main, Search, More};
private TextView mPageNumberView;
private ImageButton mSearchButton;
private ImageButton mOutlineButton;
private ImageButton mToggleFlingButton;
private ViewAnimator mTopBarSwitcher;
private ImageButton mLinkButton;
private TopBarMode mTopBarMode = TopBarMode.Main;
Expand Down Expand Up @@ -369,6 +370,12 @@ public void onClick(View v) {
}
});

mToggleFlingButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mDocView.toggleFlingDirection();
}
});

mSearchClose.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
searchModeOff();
Expand Down Expand Up @@ -692,6 +699,7 @@ private void makeButtonsView() {
mPageNumberView = (TextView)mButtonsView.findViewById(R.id.pageNumber);
mSearchButton = (ImageButton)mButtonsView.findViewById(R.id.searchButton);
mOutlineButton = (ImageButton)mButtonsView.findViewById(R.id.outlineButton);
mToggleFlingButton = (ImageButton)mButtonsView.findViewById(R.id.toggleFlingButton);
mTopBarSwitcher = (ViewAnimator)mButtonsView.findViewById(R.id.switcher);
mSearchBack = (ImageButton)mButtonsView.findViewById(R.id.searchBack);
mSearchFwd = (ImageButton)mButtonsView.findViewById(R.id.searchForward);
Expand Down
27 changes: 15 additions & 12 deletions lib/src/main/java/com/artifex/mupdf/viewer/ReaderView.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class ReaderView
private static final float MIN_SCALE = 1.0f;
private static final float MAX_SCALE = 64.0f;

private static final boolean HORIZONTAL_SCROLLING = true;

private PageAdapter mAdapter;
protected int mCurrent; // Adapter's index for the current view
private boolean mResetLayout;
Expand All @@ -66,6 +64,7 @@ public class ReaderView
private int mScrollerLastY;
private float mLastScaleFocusX;
private float mLastScaleFocusY;
private boolean mHorizontalScrolling = true;

protected Stack<Integer> mHistory;

Expand Down Expand Up @@ -396,7 +395,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
Rect bounds = getScrollBounds(v);
switch(directionOfTravel(velocityX, velocityY)) {
case MOVING_LEFT:
if (HORIZONTAL_SCROLLING && bounds.left >= 0) {
if (mHorizontalScrolling && bounds.left >= 0) {
// Fling off to the left bring next view onto screen
View vl = mChildViews.get(mCurrent+1);

Expand All @@ -407,7 +406,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
}
break;
case MOVING_UP:
if (!HORIZONTAL_SCROLLING && bounds.top >= 0) {
if (!mHorizontalScrolling && bounds.top >= 0) {
// Fling off to the top bring next view onto screen
View vl = mChildViews.get(mCurrent+1);

Expand All @@ -418,7 +417,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
}
break;
case MOVING_RIGHT:
if (HORIZONTAL_SCROLLING && bounds.right <= 0) {
if (mHorizontalScrolling && bounds.right <= 0) {
// Fling off to the right bring previous view onto screen
View vr = mChildViews.get(mCurrent-1);

Expand All @@ -429,7 +428,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
}
break;
case MOVING_DOWN:
if (!HORIZONTAL_SCROLLING && bounds.bottom <= 0) {
if (!mHorizontalScrolling && bounds.bottom <= 0) {
// Fling off to the bottom bring previous view onto screen
View vr = mChildViews.get(mCurrent-1);

Expand Down Expand Up @@ -602,7 +601,7 @@ private void onLayout2(boolean changed, int left, int top, int right,
cvOffset = subScreenSizeOffset(cv);
// cv.getRight() may be out of date with the current scale
// so add left to the measured width for the correct position
if (HORIZONTAL_SCROLLING)
if (mHorizontalScrolling)
move = cv.getLeft() + cv.getMeasuredWidth() + cvOffset.x + GAP/2 + mXScroll < getWidth()/2;
else
move = cv.getTop() + cv.getMeasuredHeight() + cvOffset.y + GAP/2 + mYScroll < getHeight()/2;
Expand All @@ -617,7 +616,7 @@ private void onLayout2(boolean changed, int left, int top, int right,
onMoveToChild(mCurrent);
}

if (HORIZONTAL_SCROLLING)
if (mHorizontalScrolling)
move = cv.getLeft() - cvOffset.x - GAP/2 + mXScroll >= getWidth()/2;
else
move = cv.getTop() - cvOffset.y - GAP/2 + mYScroll >= getHeight()/2;
Expand Down Expand Up @@ -695,13 +694,13 @@ private void onLayout2(boolean changed, int left, int top, int right,
cvLeft += corr.x;
cvTop += corr.y;
cvBottom += corr.y;
} else if (HORIZONTAL_SCROLLING && cv.getMeasuredHeight() <= getHeight()) {
} else if (mHorizontalScrolling && cv.getMeasuredHeight() <= getHeight()) {
// When the current view is as small as the screen in height, clamp
// it vertically
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
cvTop += corr.y;
cvBottom += corr.y;
} else if (!HORIZONTAL_SCROLLING && cv.getMeasuredWidth() <= getWidth()) {
} else if (!mHorizontalScrolling && cv.getMeasuredWidth() <= getWidth()) {
// When the current view is as small as the screen in width, clamp
// it horizontally
Point corr = getCorrection(getScrollBounds(cvLeft, cvTop, cvRight, cvBottom));
Expand All @@ -714,7 +713,7 @@ private void onLayout2(boolean changed, int left, int top, int right,
if (mCurrent > 0) {
View lv = getOrCreateChild(mCurrent - 1);
Point leftOffset = subScreenSizeOffset(lv);
if (HORIZONTAL_SCROLLING)
if (mHorizontalScrolling)
{
int gap = leftOffset.x + GAP + cvOffset.x;
lv.layout(cvLeft - lv.getMeasuredWidth() - gap,
Expand All @@ -733,7 +732,7 @@ private void onLayout2(boolean changed, int left, int top, int right,
if (mCurrent + 1 < mAdapter.getCount()) {
View rv = getOrCreateChild(mCurrent + 1);
Point rightOffset = subScreenSizeOffset(rv);
if (HORIZONTAL_SCROLLING)
if (mHorizontalScrolling)
{
int gap = cvOffset.x + GAP + rightOffset.x;
rv.layout(cvRight + gap,
Expand Down Expand Up @@ -932,6 +931,10 @@ public boolean onSingleTapUp(MotionEvent e) {
return true;
}

public void toggleFlingDirection() {
mHorizontalScrolling = !mHorizontalScrolling;
}

protected void onChildSetup(int i, View v) {
if (SearchTaskResult.get() != null
&& SearchTaskResult.get().pageNumber == i)
Expand Down
10 changes: 10 additions & 0 deletions lib/src/main/res/drawable/ic_change_circle_white_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12,2C6.48,2 2,6.48 2,12c0,5.52 4.48,10 10,10s10,-4.48 10,-10C22,6.48 17.52,2 12,2zM12.06,19v-2.01c-0.02,0 -0.04,0 -0.06,0c-1.28,0 -2.56,-0.49 -3.54,-1.46c-1.71,-1.71 -1.92,-4.35 -0.64,-6.29l1.1,1.1c-0.71,1.33 -0.53,3.01 0.59,4.13c0.7,0.7 1.62,1.03 2.54,1.01v-2.14l2.83,2.83L12.06,19zM16.17,14.76l-1.1,-1.1c0.71,-1.33 0.53,-3.01 -0.59,-4.13C13.79,8.84 12.9,8.5 12,8.5c-0.02,0 -0.04,0 -0.06,0v2.15L9.11,7.83L11.94,5v2.02c1.3,-0.02 2.61,0.45 3.6,1.45C17.24,10.17 17.45,12.82 16.17,14.76z"/>
</vector>
8 changes: 8 additions & 0 deletions lib/src/main/res/layout/document_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
android:textColor="@android:color/white"
/>

<ImageButton
android:id="@+id/toggleFlingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button"
android:src="@drawable/ic_change_circle_white_24dp"
/>

<ImageButton
android:id="@+id/linkButton"
android:layout_width="wrap_content"
Expand Down