mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
MoveCursorAction
This commit is contained in:
parent
6f248ab8a8
commit
1927ee39c4
7 changed files with 90 additions and 51 deletions
|
@ -1,6 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<keymap>
|
<keymap>
|
||||||
<binding key="4" action="cancelMenu"/>
|
<binding key="4" action="cancelMenu"/>
|
||||||
|
<binding key="19" action="moveCursorUp"/>
|
||||||
|
<binding key="20" action="moveCursorDown"/>
|
||||||
|
<binding key="21" action="moveCursorLeft"/>
|
||||||
|
<binding key="22" action="moveCursorRight"/>
|
||||||
<binding key="23" action="processHyperlink"/>
|
<binding key="23" action="processHyperlink"/>
|
||||||
<binding key="24" action="volumeKeyScrollBackward"/>
|
<binding key="24" action="volumeKeyScrollBackward"/>
|
||||||
<binding key="25" action="volumeKeyScrollForward"/>
|
<binding key="25" action="volumeKeyScrollForward"/>
|
||||||
|
|
|
@ -41,6 +41,11 @@ public interface ActionCode {
|
||||||
String TURN_PAGE_BACK = "previousPage";
|
String TURN_PAGE_BACK = "previousPage";
|
||||||
String TURN_PAGE_FORWARD = "nextPage";
|
String TURN_PAGE_FORWARD = "nextPage";
|
||||||
|
|
||||||
|
String MOVE_CURSOR_UP = "moveCursorUp";
|
||||||
|
String MOVE_CURSOR_DOWN = "moveCursorDown";
|
||||||
|
String MOVE_CURSOR_LEFT = "moveCursorLeft";
|
||||||
|
String MOVE_CURSOR_RIGHT = "moveCursorRight";
|
||||||
|
|
||||||
String VOLUME_KEY_SCROLL_FORWARD = "volumeKeyScrollForward";
|
String VOLUME_KEY_SCROLL_FORWARD = "volumeKeyScrollForward";
|
||||||
String VOLUME_KEY_SCROLL_BACK = "volumeKeyScrollBackward";
|
String VOLUME_KEY_SCROLL_BACK = "volumeKeyScrollBackward";
|
||||||
String SHOW_MENU = "menu";
|
String SHOW_MENU = "menu";
|
||||||
|
|
|
@ -120,6 +120,11 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
addAction(ActionCode.TURN_PAGE_FORWARD, new TurnPageAction(this, true));
|
addAction(ActionCode.TURN_PAGE_FORWARD, new TurnPageAction(this, true));
|
||||||
addAction(ActionCode.TURN_PAGE_BACK, new TurnPageAction(this, false));
|
addAction(ActionCode.TURN_PAGE_BACK, new TurnPageAction(this, false));
|
||||||
|
|
||||||
|
addAction(ActionCode.MOVE_CURSOR_UP, new MoveCursorAction(this, FBView.Direction.up));
|
||||||
|
addAction(ActionCode.MOVE_CURSOR_DOWN, new MoveCursorAction(this, FBView.Direction.down));
|
||||||
|
addAction(ActionCode.MOVE_CURSOR_LEFT, new MoveCursorAction(this, FBView.Direction.rightToLeft));
|
||||||
|
addAction(ActionCode.MOVE_CURSOR_RIGHT, new MoveCursorAction(this, FBView.Direction.leftToRight));
|
||||||
|
|
||||||
addAction(ActionCode.VOLUME_KEY_SCROLL_FORWARD, new VolumeKeyTurnPageAction(this, true));
|
addAction(ActionCode.VOLUME_KEY_SCROLL_FORWARD, new VolumeKeyTurnPageAction(this, true));
|
||||||
addAction(ActionCode.VOLUME_KEY_SCROLL_BACK, new VolumeKeyTurnPageAction(this, false));
|
addAction(ActionCode.VOLUME_KEY_SCROLL_BACK, new VolumeKeyTurnPageAction(this, false));
|
||||||
|
|
||||||
|
|
|
@ -325,25 +325,7 @@ public final class FBView extends ZLTextView {
|
||||||
(diffY > 0 ? Direction.down : Direction.up) :
|
(diffY > 0 ? Direction.down : Direction.up) :
|
||||||
(diffX > 0 ? Direction.leftToRight : Direction.rightToLeft);
|
(diffX > 0 ? Direction.leftToRight : Direction.rightToLeft);
|
||||||
|
|
||||||
ZLTextRegion region = getSelectedRegion();
|
new MoveCursorAction(myReader, direction).run();
|
||||||
final ZLTextRegion.Filter filter =
|
|
||||||
(region != null && region.getSoul() instanceof ZLTextWordRegionSoul)
|
|
||||||
|| myReader.NavigateAllWordsOption.getValue()
|
|
||||||
? ZLTextRegion.AnyRegionFilter : ZLTextRegion.ImageOrHyperlinkFilter;
|
|
||||||
region = nextRegion(direction, filter);
|
|
||||||
if (region != null) {
|
|
||||||
selectRegion(region);
|
|
||||||
} else {
|
|
||||||
if (direction == Direction.down) {
|
|
||||||
scrollPage(true, ZLTextView.ScrollingMode.SCROLL_LINES, 1);
|
|
||||||
} else if (direction == Direction.up) {
|
|
||||||
scrollPage(false, ZLTextView.ScrollingMode.SCROLL_LINES, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
myReader.getViewWidget().reset();
|
|
||||||
myReader.getViewWidget().repaint();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
58
src/org/geometerplus/fbreader/fbreader/MoveCursorAction.java
Normal file
58
src/org/geometerplus/fbreader/fbreader/MoveCursorAction.java
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007-2011 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* 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.ZLTextRegion;
|
||||||
|
import org.geometerplus.zlibrary.text.view.ZLTextWordRegionSoul;
|
||||||
|
|
||||||
|
class MoveCursorAction extends FBAction {
|
||||||
|
private final FBView.Direction myDirection;
|
||||||
|
|
||||||
|
MoveCursorAction(FBReaderApp fbreader, FBView.Direction direction) {
|
||||||
|
super(fbreader);
|
||||||
|
myDirection = direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(Object ... params) {
|
||||||
|
final FBView fbView = Reader.getTextView();
|
||||||
|
ZLTextRegion region = fbView.getSelectedRegion();
|
||||||
|
final ZLTextRegion.Filter filter =
|
||||||
|
(region != null && region.getSoul() instanceof ZLTextWordRegionSoul)
|
||||||
|
|| Reader.NavigateAllWordsOption.getValue()
|
||||||
|
? ZLTextRegion.AnyRegionFilter : ZLTextRegion.ImageOrHyperlinkFilter;
|
||||||
|
region = fbView.nextRegion(myDirection, filter);
|
||||||
|
if (region != null) {
|
||||||
|
fbView.selectRegion(region);
|
||||||
|
} else {
|
||||||
|
switch (myDirection) {
|
||||||
|
case down:
|
||||||
|
fbView.scrollPage(true, FBView.ScrollingMode.SCROLL_LINES, 1);
|
||||||
|
break;
|
||||||
|
case up:
|
||||||
|
fbView.scrollPage(false, FBView.ScrollingMode.SCROLL_LINES, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reader.getViewWidget().reset();
|
||||||
|
Reader.getViewWidget().repaint();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1467,7 +1467,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
return myCurrentPage.TextElementMap.findRegion(x, y, maxDistance, filter);
|
return myCurrentPage.TextElementMap.findRegion(x, y, maxDistance, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void selectRegion(ZLTextRegion region) {
|
public void selectRegion(ZLTextRegion region) {
|
||||||
final ZLTextRegion.Soul soul = region != null ? region.getSoul() : null;
|
final ZLTextRegion.Soul soul = region != null ? region.getSoul() : null;
|
||||||
if (soul == null || !soul.equals(mySelectedRegionSoul)) {
|
if (soul == null || !soul.equals(mySelectedRegionSoul)) {
|
||||||
myHighlightSelectedRegion = true;
|
myHighlightSelectedRegion = true;
|
||||||
|
@ -1543,7 +1543,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
myHighlightSelectedRegion = true;
|
myHighlightSelectedRegion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ZLTextRegion nextRegion(Direction direction, ZLTextRegion.Filter filter) {
|
public ZLTextRegion nextRegion(Direction direction, ZLTextRegion.Filter filter) {
|
||||||
return myCurrentPage.TextElementMap.nextRegion(getSelectedRegion(), direction, filter);
|
return myCurrentPage.TextElementMap.nextRegion(getSelectedRegion(), direction, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -392,39 +392,24 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
final ZLApplication application = ZLApplication.Instance();
|
final ZLApplication application = ZLApplication.Instance();
|
||||||
|
|
||||||
switch (keyCode) {
|
if (application.hasActionForKey(keyCode, true) ||
|
||||||
default:
|
application.hasActionForKey(keyCode, false)) {
|
||||||
if (application.hasActionForKey(keyCode, true) ||
|
if (myKeyUnderTracking != -1) {
|
||||||
application.hasActionForKey(keyCode, false)) {
|
if (myKeyUnderTracking == keyCode) {
|
||||||
if (myKeyUnderTracking != -1) {
|
return true;
|
||||||
if (myKeyUnderTracking == keyCode) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
myKeyUnderTracking = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (application.hasActionForKey(keyCode, true)) {
|
|
||||||
myKeyUnderTracking = keyCode;
|
|
||||||
myTrackingStartTime = System.currentTimeMillis();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return application.doActionByKey(keyCode, false);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
myKeyUnderTracking = -1;
|
||||||
}
|
}
|
||||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
}
|
||||||
application.getCurrentView().onTrackballRotated(-1, 0);
|
if (application.hasActionForKey(keyCode, true)) {
|
||||||
return true;
|
myKeyUnderTracking = keyCode;
|
||||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
myTrackingStartTime = System.currentTimeMillis();
|
||||||
application.getCurrentView().onTrackballRotated(1, 0);
|
|
||||||
return true;
|
|
||||||
case KeyEvent.KEYCODE_DPAD_DOWN:
|
|
||||||
application.getCurrentView().onTrackballRotated(0, 1);
|
|
||||||
return true;
|
|
||||||
case KeyEvent.KEYCODE_DPAD_UP:
|
|
||||||
application.getCurrentView().onTrackballRotated(0, -1);
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return application.doActionByKey(keyCode, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue