diff --git a/src/org/geometerplus/fbreader/fbreader/ActionCode.java b/src/org/geometerplus/fbreader/fbreader/ActionCode.java index f903bbbf8..e26e683fb 100644 --- a/src/org/geometerplus/fbreader/fbreader/ActionCode.java +++ b/src/org/geometerplus/fbreader/fbreader/ActionCode.java @@ -38,11 +38,11 @@ public interface ActionCode { String SET_TEXT_VIEW_MODE_VISIT_HYPERLINKS = "hyperlinksOnlyMode"; String SET_TEXT_VIEW_MODE_VISIT_ALL_WORDS = "dictionaryMode"; - String TURN_TO_PREVIOUS_PAGE = "previousPage"; - String TURN_TO_NEXT_PAGE = "nextPage"; + String TURN_PAGE_BACK = "previousPage"; + String TURN_PAGE_FORWARD = "nextPage"; String VOLUME_KEY_SCROLL_FORWARD = "volumeKeyScrollForward"; - String VOLUME_KEY_SCROLL_BACKWARD = "volumeKeyScrollBackward"; + String VOLUME_KEY_SCROLL_BACK = "volumeKeyScrollBackward"; String SHOW_MENU = "menu"; String SHOW_NAVIGATION = "navigate"; String CANCEL = "cancel"; diff --git a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java index 95cb8aca3..6b0858667 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java +++ b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java @@ -107,8 +107,11 @@ public final class FBReaderApp extends ZLApplication { addAction(ActionCode.FIND_PREVIOUS, new FindPreviousAction(this)); addAction(ActionCode.CLEAR_FIND_RESULTS, new ClearFindResultsAction(this)); - addAction(ActionCode.VOLUME_KEY_SCROLL_FORWARD, new VolumeKeyScrollingAction(this, true)); - addAction(ActionCode.VOLUME_KEY_SCROLL_BACKWARD, new VolumeKeyScrollingAction(this, false)); + addAction(ActionCode.TURN_PAGE_FORWARD, new TurnPageAction(this, true, false)); + addAction(ActionCode.TURN_PAGE_BACK, new TurnPageAction(this, false, false)); + + addAction(ActionCode.VOLUME_KEY_SCROLL_FORWARD, new TurnPageAction(this, true, true)); + addAction(ActionCode.VOLUME_KEY_SCROLL_BACK, new TurnPageAction(this, false, true)); addAction(ActionCode.CANCEL, new CancelAction(this)); //addAction(ActionCode.COPY_SELECTED_TEXT_TO_CLIPBOARD, new DummyAction(this)); diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java index 4d79ca98b..e4a42f04a 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBView.java +++ b/src/org/geometerplus/fbreader/fbreader/FBView.java @@ -48,30 +48,6 @@ public final class FBView extends ZLTextView { super.onScrollingFinished(viewPage); } - final void doScrollPage(boolean forward) { - final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue(); - if (getAnimationType() != Animation.none) { - if (forward) { - ZLTextWordCursor cursor = getEndCursor(); - if (cursor != null && - !cursor.isNull() && - (!cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast())) { - startAutoScrolling(horizontal ? PAGE_RIGHT : PAGE_BOTTOM); - } - } else { - ZLTextWordCursor cursor = getStartCursor(); - if (cursor != null && - !cursor.isNull() && - (!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst())) { - startAutoScrolling(horizontal ? PAGE_LEFT : PAGE_TOP); - } - } - } else { - scrollPage(forward, ZLTextView.ScrollingMode.NO_OVERLAPPING, 0); - myReader.repaintView(); - } - } - private int myStartX; private int myStartY; private boolean myIsManualScrollingActive; @@ -127,38 +103,31 @@ public final class FBView extends ZLTextView { } final ScrollingPreferences preferences = ScrollingPreferences.Instance(); - final ScrollingPreferences.FingerScrolling fingerScrolling = - preferences.FingerScrollingOption.getValue(); final TapZone tapZone = getZoneByCoordinates(x, y, 3); if (!preferences.HorizontalOption.getValue()) { tapZone.mirror45(); } - final boolean doTapScrolling = - fingerScrolling == ScrollingPreferences.FingerScrolling.byTap || - fingerScrolling == ScrollingPreferences.FingerScrolling.byTapAndFlick; + String actionCode = null; switch (tapZone.HIndex) { case 0: - if (doTapScrolling) { - doScrollPage(false); - } + actionCode = ActionCode.TURN_PAGE_BACK; break; case 1: switch (tapZone.VIndex) { case 0: - myReader.doAction(ActionCode.SHOW_NAVIGATION); + actionCode = ActionCode.SHOW_NAVIGATION; break; case 2: - myReader.doAction(ActionCode.SHOW_MENU); + actionCode = ActionCode.SHOW_MENU; break; } break; case 2: - if (doTapScrolling) { - doScrollPage(true); - } + actionCode = ActionCode.TURN_PAGE_FORWARD; break; } + myReader.doAction(actionCode); return true; } diff --git a/src/org/geometerplus/fbreader/fbreader/TurnPageAction.java b/src/org/geometerplus/fbreader/fbreader/TurnPageAction.java new file mode 100644 index 000000000..20cf4db1c --- /dev/null +++ b/src/org/geometerplus/fbreader/fbreader/TurnPageAction.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2007-2011 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +package org.geometerplus.fbreader.fbreader; + +import org.geometerplus.zlibrary.text.view.ZLTextWordCursor; + +class TurnPageAction extends FBAction { + private final boolean myForward; + private final boolean myIsVolumeKeyAction; + + TurnPageAction(FBReaderApp fbreader, boolean forward, boolean isVolumeKeyAction) { + super(fbreader); + myForward = forward; + myIsVolumeKeyAction = isVolumeKeyAction; + } + + public boolean isEnabled() { + final ScrollingPreferences preferences = ScrollingPreferences.Instance(); + if (myIsVolumeKeyAction && !preferences.VolumeKeysOption.getValue()) { + return false; + } + + final ScrollingPreferences.FingerScrolling fingerScrolling = + preferences.FingerScrollingOption.getValue(); + if (fingerScrolling != ScrollingPreferences.FingerScrolling.byTap && + fingerScrolling != ScrollingPreferences.FingerScrolling.byTapAndFlick) { + return false; + } + + boolean forward = myForward; + if (myIsVolumeKeyAction && preferences.InvertVolumeKeysOption.getValue()) { + forward = !forward; + } + + if (forward) { + ZLTextWordCursor cursor = Reader.getTextView().getEndCursor(); + return + cursor != null && + !cursor.isNull() && + (!cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast()); + } else { + ZLTextWordCursor cursor = Reader.getTextView().getStartCursor(); + return + cursor != null && + !cursor.isNull() && + (!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst()); + } + } + + public void run() { + final ScrollingPreferences preferences = ScrollingPreferences.Instance(); + boolean forward = myForward; + if (myIsVolumeKeyAction && preferences.InvertVolumeKeysOption.getValue()) { + forward = !forward; + } + final FBView view = Reader.getTextView(); + if (view.getAnimationType() != FBView.Animation.none) { + final boolean horizontal = preferences.HorizontalOption.getValue(); + if (forward) { + view.startAutoScrolling(horizontal ? FBView.PAGE_RIGHT : FBView.PAGE_BOTTOM); + } else { + view.startAutoScrolling(horizontal ? FBView.PAGE_LEFT : FBView.PAGE_TOP); + } + } else { + view.scrollPage(forward, FBView.ScrollingMode.NO_OVERLAPPING, 0); + Reader.repaintView(); + } + } +} diff --git a/src/org/geometerplus/fbreader/fbreader/VolumeKeyScrollingAction.java b/src/org/geometerplus/fbreader/fbreader/VolumeKeyScrollingAction.java deleted file mode 100644 index 478d86399..000000000 --- a/src/org/geometerplus/fbreader/fbreader/VolumeKeyScrollingAction.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2007-2011 Geometer Plus - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -package org.geometerplus.fbreader.fbreader; - -class VolumeKeyScrollingAction extends FBAction { - private final boolean myForward; - - VolumeKeyScrollingAction(FBReaderApp fbreader, boolean forward) { - super(fbreader); - myForward = forward; - } - - public boolean isEnabled() { - return ScrollingPreferences.Instance().VolumeKeysOption.getValue(); - } - - public void run() { - boolean isInverted = ScrollingPreferences.Instance().InvertVolumeKeysOption.getValue(); - Reader.getTextView().doScrollPage(isInverted ? !myForward : myForward); - } -}