diff --git a/README b/README.md similarity index 100% rename from README rename to README.md diff --git a/lib/src/main/java/com/artifex/mupdf/viewer/DocumentActivity.java b/lib/src/main/java/com/artifex/mupdf/viewer/DocumentActivity.java index 90f00aa..a0e1d89 100644 --- a/lib/src/main/java/com/artifex/mupdf/viewer/DocumentActivity.java +++ b/lib/src/main/java/com/artifex/mupdf/viewer/DocumentActivity.java @@ -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; @@ -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(); @@ -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); diff --git a/lib/src/main/java/com/artifex/mupdf/viewer/ReaderView.java b/lib/src/main/java/com/artifex/mupdf/viewer/ReaderView.java index 5fed6f1..7345410 100644 --- a/lib/src/main/java/com/artifex/mupdf/viewer/ReaderView.java +++ b/lib/src/main/java/com/artifex/mupdf/viewer/ReaderView.java @@ -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; @@ -66,6 +64,7 @@ public class ReaderView private int mScrollerLastY; private float mLastScaleFocusX; private float mLastScaleFocusY; + private boolean mHorizontalScrolling = true; protected Stack mHistory; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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; @@ -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; @@ -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)); @@ -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, @@ -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, @@ -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) diff --git a/lib/src/main/res/drawable/ic_change_circle_white_24dp.xml b/lib/src/main/res/drawable/ic_change_circle_white_24dp.xml new file mode 100644 index 0000000..b3a5c20 --- /dev/null +++ b/lib/src/main/res/drawable/ic_change_circle_white_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/lib/src/main/res/layout/document_activity.xml b/lib/src/main/res/layout/document_activity.xml index 57f7571..c99e0cb 100644 --- a/lib/src/main/res/layout/document_activity.xml +++ b/lib/src/main/res/layout/document_activity.xml @@ -35,6 +35,14 @@ android:textColor="@android:color/white" /> + +