mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
refactoring: introduced ZLViewWidget class
This commit is contained in:
parent
90f1be2dd8
commit
744934e3b7
17 changed files with 38 additions and 83 deletions
|
@ -239,7 +239,7 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
}
|
||||
}
|
||||
fbreader.clearTextCaches();
|
||||
fbreader.repaintView();
|
||||
fbreader.getViewWidget().repaint();
|
||||
break;
|
||||
}
|
||||
case CANCEL_CODE:
|
||||
|
|
|
@ -82,7 +82,7 @@ final class NavigationButtonPanel extends ControlButtonPanel {
|
|||
view.gotoPage(page);
|
||||
}
|
||||
Reader.getViewWidget().reset();
|
||||
Reader.repaintView();
|
||||
Reader.getViewWidget().repaint();
|
||||
}
|
||||
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
|
|
@ -54,7 +54,7 @@ class ProcessHyperlinkAction extends FBAction {
|
|||
final ZLTextElementRegion region = Reader.getTextView().getSelectedRegion();
|
||||
if (region instanceof ZLTextHyperlinkRegion) {
|
||||
Reader.getTextView().hideSelectedRegionBorder();
|
||||
Reader.repaintView();
|
||||
Reader.getViewWidget().repaint();
|
||||
final ZLTextHyperlink hyperlink = ((ZLTextHyperlinkRegion)region).Hyperlink;
|
||||
switch (hyperlink.Type) {
|
||||
case FBHyperlinkType.EXTERNAL:
|
||||
|
@ -71,7 +71,7 @@ class ProcessHyperlinkAction extends FBAction {
|
|||
}
|
||||
} else if (region instanceof ZLTextImageRegion) {
|
||||
Reader.getTextView().hideSelectedRegionBorder();
|
||||
Reader.repaintView();
|
||||
Reader.getViewWidget().repaint();
|
||||
final String uriString = ((ZLTextImageRegion)region).ImageElement.URI;
|
||||
if (uriString != null) {
|
||||
try {
|
||||
|
|
|
@ -35,6 +35,6 @@ class ChangeFontSizeAction extends FBAction {
|
|||
ZLTextStyleCollection.Instance().getBaseStyle().FontSizeOption;
|
||||
option.setValue(option.getValue() + myDelta);
|
||||
Reader.clearTextCaches();
|
||||
Reader.repaintView();
|
||||
Reader.getViewWidget().repaint();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ public final class FBReaderApp extends ZLApplication {
|
|||
setView(FootnoteView);
|
||||
FootnoteView.gotoPosition(label.ParagraphIndex, 0, 0);
|
||||
}
|
||||
repaintView();
|
||||
getViewWidget().repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ public final class FBReaderApp extends ZLApplication {
|
|||
Library.addBookToRecentList(book);
|
||||
}
|
||||
}
|
||||
repaintView();
|
||||
getViewWidget().repaint();
|
||||
}
|
||||
|
||||
public void gotoBookmark(Bookmark bookmark) {
|
||||
|
@ -254,7 +254,7 @@ public final class FBReaderApp extends ZLApplication {
|
|||
FootnoteView.gotoPosition(bookmark);
|
||||
setView(FootnoteView);
|
||||
}
|
||||
repaintView();
|
||||
getViewWidget().repaint();
|
||||
}
|
||||
|
||||
public void showBookTextView() {
|
||||
|
|
|
@ -89,7 +89,7 @@ public final class FBView extends ZLTextView {
|
|||
if (region != null) {
|
||||
selectRegion(region);
|
||||
myReader.getViewWidget().reset();
|
||||
myReader.repaintView();
|
||||
myReader.getViewWidget().repaint();
|
||||
myReader.doAction(ActionCode.PROCESS_HYPERLINK);
|
||||
return true;
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public final class FBView extends ZLTextView {
|
|||
if (isFlickScrollingEnabled()) {
|
||||
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
||||
final Direction direction = horizontal ? Direction.rightToLeft : Direction.up;
|
||||
myReader.scrollViewManually(myStartX, myStartY, x, y, direction);
|
||||
myReader.getViewWidget().scrollManually(myStartX, myStartY, x, y, direction);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -197,7 +197,7 @@ public final class FBView extends ZLTextView {
|
|||
Math.abs(diff) < minDiff
|
||||
? PageIndex.current
|
||||
: (diff < 0 ? PageIndex.next : PageIndex.previous);
|
||||
myReader.startViewAutoScrolling(pageIndex, direction, x, y, animationSpeed);
|
||||
myReader.getViewWidget().startAutoScrolling(pageIndex, direction, x, y, animationSpeed);
|
||||
}
|
||||
|
||||
public boolean onFingerRelease(int x, int y) {
|
||||
|
@ -229,7 +229,7 @@ public final class FBView extends ZLTextView {
|
|||
if (region != null) {
|
||||
selectRegion(region);
|
||||
myReader.getViewWidget().reset();
|
||||
myReader.repaintView();
|
||||
myReader.getViewWidget().repaint();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ public final class FBView extends ZLTextView {
|
|||
if (region != null) {
|
||||
selectRegion(region);
|
||||
myReader.getViewWidget().reset();
|
||||
myReader.repaintView();
|
||||
myReader.getViewWidget().repaint();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -293,7 +293,7 @@ public final class FBView extends ZLTextView {
|
|||
}
|
||||
|
||||
myReader.getViewWidget().reset();
|
||||
myReader.repaintView();
|
||||
myReader.getViewWidget().repaint();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ public final class FBView extends ZLTextView {
|
|||
private class Footer implements FooterArea {
|
||||
private Runnable UpdateTask = new Runnable() {
|
||||
public void run() {
|
||||
myReader.repaintView();
|
||||
myReader.getViewWidget().repaint();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -526,7 +526,7 @@ public final class FBView extends ZLTextView {
|
|||
gotoPage(page);
|
||||
}
|
||||
myReader.getViewWidget().reset();
|
||||
myReader.repaintView();
|
||||
myReader.getViewWidget().repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,6 @@ class SwitchProfileAction extends FBAction {
|
|||
public void run() {
|
||||
Reader.setColorProfileName(myProfileName);
|
||||
Reader.getViewWidget().reset();
|
||||
Reader.repaintView();
|
||||
Reader.getViewWidget().repaint();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,17 +41,18 @@ class TurnPageAction extends FBAction {
|
|||
|
||||
public void run() {
|
||||
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
|
||||
Reader.startViewAutoScrolling(
|
||||
Reader.getViewWidget().startAutoScrolling(
|
||||
myForward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
preferences.HorizontalOption.getValue()
|
||||
? FBView.Direction.rightToLeft : FBView.Direction.up,
|
||||
null, null,
|
||||
preferences.AnimationSpeedOption.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
public void runWithCoordinates(int x, int y) {
|
||||
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
|
||||
Reader.startViewAutoScrolling(
|
||||
Reader.getViewWidget().startAutoScrolling(
|
||||
myForward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
preferences.HorizontalOption.getValue()
|
||||
? FBView.Direction.rightToLeft : FBView.Direction.up,
|
||||
|
|
|
@ -41,10 +41,11 @@ class VolumeKeyTurnPageAction extends FBAction {
|
|||
forward = !forward;
|
||||
}
|
||||
|
||||
Reader.startViewAutoScrolling(
|
||||
Reader.getViewWidget().startAutoScrolling(
|
||||
forward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
preferences.HorizontalOption.getValue()
|
||||
? FBView.Direction.rightToLeft : FBView.Direction.up,
|
||||
null, null,
|
||||
preferences.AnimationSpeedOption.getValue()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ public abstract class ZLApplication {
|
|||
final ZLViewWidget widget = getViewWidget();
|
||||
if (widget != null) {
|
||||
widget.reset();
|
||||
widget.repaint();
|
||||
}
|
||||
repaintView();
|
||||
onViewChanged();
|
||||
}
|
||||
}
|
||||
|
@ -71,30 +71,6 @@ public abstract class ZLApplication {
|
|||
return myWindow != null ? myWindow.getViewWidget() : null;
|
||||
}
|
||||
|
||||
public final void repaintView() {
|
||||
if (myWindow != null) {
|
||||
myWindow.repaintView();
|
||||
}
|
||||
}
|
||||
|
||||
public final void scrollViewManually(int startX, int startY, int endX, int endY, ZLView.Direction direction) {
|
||||
if (myWindow != null) {
|
||||
myWindow.scrollViewManually(startX, startY, endX, endY, direction);
|
||||
}
|
||||
}
|
||||
|
||||
public final void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int speed) {
|
||||
if (myWindow != null) {
|
||||
myWindow.startViewAutoScrolling(pageIndex, direction, speed);
|
||||
}
|
||||
}
|
||||
|
||||
public final void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int x, int y, int speed) {
|
||||
if (myWindow != null) {
|
||||
myWindow.startViewAutoScrolling(pageIndex, direction, x, y, speed);
|
||||
}
|
||||
}
|
||||
|
||||
public final void onRepaintFinished() {
|
||||
if (myWindow != null) {
|
||||
myWindow.refreshMenu();
|
||||
|
|
|
@ -38,11 +38,6 @@ abstract public class ZLApplicationWindow {
|
|||
|
||||
abstract protected ZLViewWidget getViewWidget();
|
||||
|
||||
abstract protected void repaintView();
|
||||
abstract protected void scrollViewManually(int startX, int startY, int endX, int endY, ZLView.Direction direction);
|
||||
abstract protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int speed);
|
||||
abstract protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int x, int y, int speed);
|
||||
|
||||
abstract protected void rotate();
|
||||
abstract protected boolean canRotate();
|
||||
|
||||
|
|
|
@ -21,4 +21,8 @@ package org.geometerplus.zlibrary.core.view;
|
|||
|
||||
public interface ZLViewWidget {
|
||||
void reset();
|
||||
void repaint();
|
||||
|
||||
void scrollManually(int startX, int startY, int endX, int endY, ZLView.Direction direction);
|
||||
void startAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, Integer x, Integer y, int speed);
|
||||
}
|
||||
|
|
|
@ -273,7 +273,7 @@ final class ZLTextSelectionModel {
|
|||
public void run() {
|
||||
myView.scrollPage(forward, ZLTextView.ScrollingMode.SCROLL_LINES, 1);
|
||||
myDoUpdate = true;
|
||||
ZLApplication.Instance().repaintView();
|
||||
ZLApplication.Instance().getViewWidget().repaint();
|
||||
}
|
||||
};
|
||||
myTimer.schedule(myScrollingTask, 200, 400);
|
||||
|
|
|
@ -128,7 +128,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
preparePaintInfo(myCurrentPage);
|
||||
}
|
||||
Application.getViewWidget().reset();
|
||||
Application.repaintView();
|
||||
Application.getViewWidget().repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
(backward ? myModel.getPreviousMark(mark) : myModel.getNextMark(mark)));
|
||||
}
|
||||
Application.getViewWidget().reset();
|
||||
Application.repaintView();
|
||||
Application.getViewWidget().repaint();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
myModel.removeAllMarks();
|
||||
rebuildPaintInfo();
|
||||
Application.getViewWidget().reset();
|
||||
Application.repaintView();
|
||||
Application.getViewWidget().repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1261,7 +1261,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
public boolean onFingerMove(int x, int y) {
|
||||
if (mySelectionModel.extendTo(x, y)) {
|
||||
Application.getViewWidget().reset();
|
||||
Application.repaintView();
|
||||
Application.getViewWidget().repaint();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1280,7 +1280,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
if (isSelectionEnabled()) {
|
||||
mySelectionModel.activate(x, y);
|
||||
Application.getViewWidget().reset();
|
||||
Application.repaintView();
|
||||
Application.getViewWidget().repaint();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -72,33 +72,7 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
|||
return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
|
||||
}
|
||||
|
||||
protected void repaintView() {
|
||||
final ZLAndroidWidget widget =
|
||||
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
|
||||
widget.postInvalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void scrollViewManually(int startX, int startY, int endX, int endY, ZLView.Direction direction) {
|
||||
final ZLAndroidWidget widget =
|
||||
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
|
||||
widget.scrollManually(startX, startY, endX, endY, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int speed) {
|
||||
final ZLAndroidWidget widget =
|
||||
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
|
||||
widget.startAutoScrolling(pageIndex, direction, null, null, speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int x, int y, int speed) {
|
||||
final ZLAndroidWidget widget =
|
||||
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
|
||||
widget.startAutoScrolling(pageIndex, direction, x, y, speed);
|
||||
}
|
||||
|
||||
public void rotate() {
|
||||
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).rotateScreen();
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public abstract class ZLAndroidActivity extends Activity {
|
|||
} else {
|
||||
ZLApplication.Instance().openFile(fileToOpen);
|
||||
}
|
||||
ZLApplication.Instance().repaintView();
|
||||
ZLApplication.Instance().getViewWidget().repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -153,6 +153,10 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
|
|||
myBitmapManager.reset();
|
||||
}
|
||||
|
||||
public void repaint() {
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
public void scrollManually(int startX, int startY, int endX, int endY, ZLView.Direction direction) {
|
||||
final ZLView view = ZLApplication.Instance().getCurrentView();
|
||||
final int diff = direction.IsHorizontal ? endX - startX : endY - startY;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue