mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
sporadic program freeze has been fixed
This commit is contained in:
parent
34add4aec3
commit
692c749ef6
3 changed files with 44 additions and 88 deletions
|
@ -43,7 +43,6 @@ public final class FBView extends ZLTextView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModel(ZLTextModel model) {
|
public void setModel(ZLTextModel model) {
|
||||||
myIsManualScrollingActive = false;
|
|
||||||
super.setModel(model);
|
super.setModel(model);
|
||||||
if (myFooter != null) {
|
if (myFooter != null) {
|
||||||
myFooter.resetTOCMarks();
|
myFooter.resetTOCMarks();
|
||||||
|
@ -52,7 +51,6 @@ public final class FBView extends ZLTextView {
|
||||||
|
|
||||||
private int myStartX;
|
private int myStartX;
|
||||||
private int myStartY;
|
private int myStartY;
|
||||||
private boolean myIsManualScrollingActive;
|
|
||||||
private boolean myIsBrightnessAdjustmentInProgress;
|
private boolean myIsBrightnessAdjustmentInProgress;
|
||||||
private int myStartBrightness;
|
private int myStartBrightness;
|
||||||
|
|
||||||
|
@ -77,10 +75,6 @@ public final class FBView extends ZLTextView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isScrollingActive()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myReader.FooterIsSensitiveOption.getValue()) {
|
if (myReader.FooterIsSensitiveOption.getValue()) {
|
||||||
Footer footer = getFooterArea();
|
Footer footer = getFooterArea();
|
||||||
if (footer != null && y > myContext.getHeight() - footer.getTapHeight()) {
|
if (footer != null && y > myContext.getHeight() - footer.getTapHeight()) {
|
||||||
|
@ -128,10 +122,6 @@ public final class FBView extends ZLTextView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isScrollingActive()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myReader.FooterIsSensitiveOption.getValue()) {
|
if (myReader.FooterIsSensitiveOption.getValue()) {
|
||||||
Footer footer = getFooterArea();
|
Footer footer = getFooterArea();
|
||||||
if (footer != null && y > myContext.getHeight() - footer.getTapHeight()) {
|
if (footer != null && y > myContext.getHeight() - footer.getTapHeight()) {
|
||||||
|
@ -158,8 +148,6 @@ public final class FBView extends ZLTextView {
|
||||||
fingerScrolling == ScrollingPreferences.FingerScrolling.byTapAndFlick) {
|
fingerScrolling == ScrollingPreferences.FingerScrolling.byTapAndFlick) {
|
||||||
myStartX = x;
|
myStartX = x;
|
||||||
myStartY = y;
|
myStartY = y;
|
||||||
setScrollingActive(true);
|
|
||||||
myIsManualScrollingActive = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,32 +168,28 @@ public final class FBView extends ZLTextView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isScrollingActive() && myIsManualScrollingActive) {
|
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
||||||
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
final int diff = horizontal ? x - myStartX : y - myStartY;
|
||||||
final int diff = horizontal ? x - myStartX : y - myStartY;
|
final Direction direction = horizontal ? Direction.rightToLeft : Direction.up;
|
||||||
final Direction direction = horizontal ? Direction.rightToLeft : Direction.up;
|
if (diff >= 0) {
|
||||||
if (diff >= 0) {
|
final ZLTextWordCursor cursor = getStartCursor();
|
||||||
final ZLTextWordCursor cursor = getStartCursor();
|
if (cursor == null || cursor.isNull()) {
|
||||||
if (cursor == null || cursor.isNull()) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
if (!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst()) {
|
||||||
if (!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst()) {
|
myReader.scrollViewManually(myStartX, myStartY, x, y, direction);
|
||||||
myReader.scrollViewManually(myStartX, myStartY, x, y, direction);
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
final ZLTextWordCursor cursor = getEndCursor();
|
||||||
final ZLTextWordCursor cursor = getEndCursor();
|
if (cursor == null || cursor.isNull()) {
|
||||||
if (cursor == null || cursor.isNull()) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
if (!cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast()) {
|
||||||
if (!cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast()) {
|
myReader.scrollViewManually(myStartX, myStartY, x, y, direction);
|
||||||
myReader.scrollViewManually(myStartX, myStartY, x, y, direction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onFingerRelease(int x, int y) {
|
public boolean onFingerRelease(int x, int y) {
|
||||||
|
@ -215,39 +199,34 @@ public final class FBView extends ZLTextView {
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
myIsBrightnessAdjustmentInProgress = false;
|
myIsBrightnessAdjustmentInProgress = false;
|
||||||
if (isScrollingActive() && myIsManualScrollingActive) {
|
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
||||||
setScrollingActive(false);
|
final int diff = horizontal ? x - myStartX : y - myStartY;
|
||||||
myIsManualScrollingActive = false;
|
boolean doScroll = false;
|
||||||
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
if (diff > 0) {
|
||||||
final int diff = horizontal ? x - myStartX : y - myStartY;
|
ZLTextWordCursor cursor = getStartCursor();
|
||||||
boolean doScroll = false;
|
if (cursor != null && !cursor.isNull()) {
|
||||||
if (diff > 0) {
|
doScroll = !cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst();
|
||||||
ZLTextWordCursor cursor = getStartCursor();
|
|
||||||
if (cursor != null && !cursor.isNull()) {
|
|
||||||
doScroll = !cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst();
|
|
||||||
}
|
|
||||||
} else if (diff < 0) {
|
|
||||||
ZLTextWordCursor cursor = getEndCursor();
|
|
||||||
if (cursor != null && !cursor.isNull()) {
|
|
||||||
doScroll = !cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (doScroll) {
|
} else if (diff < 0) {
|
||||||
final int h = myContext.getHeight();
|
ZLTextWordCursor cursor = getEndCursor();
|
||||||
final int w = myContext.getWidth();
|
if (cursor != null && !cursor.isNull()) {
|
||||||
final int minDiff = horizontal ?
|
doScroll = !cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast();
|
||||||
(w > h ? w / 4 : w / 3) :
|
|
||||||
(h > w ? h / 4 : h / 3);
|
|
||||||
final PageIndex pageIndex =
|
|
||||||
Math.abs(diff) < minDiff
|
|
||||||
? PageIndex.current
|
|
||||||
: (diff < 0 ? PageIndex.next : PageIndex.previous);
|
|
||||||
startAutoScrolling(pageIndex, horizontal ? Direction.rightToLeft : Direction.up, ScrollingPreferences.Instance().AnimationSpeedOption.getValue());
|
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
|
if (doScroll) {
|
||||||
|
final int h = myContext.getHeight();
|
||||||
|
final int w = myContext.getWidth();
|
||||||
|
final int minDiff = horizontal ?
|
||||||
|
(w > h ? w / 4 : w / 3) :
|
||||||
|
(h > w ? h / 4 : h / 3);
|
||||||
|
final PageIndex pageIndex =
|
||||||
|
Math.abs(diff) < minDiff
|
||||||
|
? PageIndex.current
|
||||||
|
: (diff < 0 ? PageIndex.next : PageIndex.previous);
|
||||||
|
startAutoScrolling(pageIndex, horizontal ? Direction.rightToLeft : Direction.up, ScrollingPreferences.Instance().AnimationSpeedOption.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onFingerLongPress(int x, int y) {
|
public boolean onFingerLongPress(int x, int y) {
|
||||||
|
|
|
@ -67,7 +67,6 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
myCurrentPage.reset();
|
myCurrentPage.reset();
|
||||||
myPreviousPage.reset();
|
myPreviousPage.reset();
|
||||||
myNextPage.reset();
|
myNextPage.reset();
|
||||||
setScrollingActive(false);
|
|
||||||
if (myModel != null) {
|
if (myModel != null) {
|
||||||
final int paragraphsNumber = myModel.getParagraphsNumber();
|
final int paragraphsNumber = myModel.getParagraphsNumber();
|
||||||
if (paragraphsNumber > 0) {
|
if (paragraphsNumber > 0) {
|
||||||
|
@ -195,35 +194,16 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
return (myModel == null) || myModel.getMarks().isEmpty();
|
return (myModel == null) || myModel.getMarks().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private volatile boolean myScrollingIsActive;
|
|
||||||
protected boolean isScrollingActive() {
|
|
||||||
return myScrollingIsActive;
|
|
||||||
}
|
|
||||||
protected void setScrollingActive(boolean active) {
|
|
||||||
myScrollingIsActive = active;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final synchronized void startAutoScrolling(PageIndex pageIndex, Direction direction, int speed) {
|
public final synchronized void startAutoScrolling(PageIndex pageIndex, Direction direction, int speed) {
|
||||||
if (isScrollingActive()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setScrollingActive(true);
|
|
||||||
ZLApplication.Instance().startViewAutoScrolling(pageIndex, direction, speed);
|
ZLApplication.Instance().startViewAutoScrolling(pageIndex, direction, speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final synchronized void startAutoScrolling(PageIndex pageIndex, Direction direction, int x, int y, int speed) {
|
public final synchronized void startAutoScrolling(PageIndex pageIndex, Direction direction, int x, int y, int speed) {
|
||||||
if (isScrollingActive()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setScrollingActive(true);
|
|
||||||
ZLApplication.Instance().startViewAutoScrolling(pageIndex, direction, x, y, speed);
|
ZLApplication.Instance().startViewAutoScrolling(pageIndex, direction, x, y, speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onScrollingFinished(PageIndex pageIndex) {
|
public synchronized void onScrollingFinished(PageIndex pageIndex) {
|
||||||
setScrollingActive(false);
|
|
||||||
switch (pageIndex) {
|
switch (pageIndex) {
|
||||||
case current:
|
case current:
|
||||||
break;
|
break;
|
||||||
|
@ -970,10 +950,6 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized final void scrollPage(boolean forward, int scrollingMode, int value) {
|
public synchronized final void scrollPage(boolean forward, int scrollingMode, int value) {
|
||||||
if (isScrollingActive()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
preparePaintInfo(myCurrentPage);
|
preparePaintInfo(myCurrentPage);
|
||||||
myPreviousPage.reset();
|
myPreviousPage.reset();
|
||||||
myNextPage.reset();
|
myNextPage.reset();
|
||||||
|
|
|
@ -190,6 +190,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
animator.startAutoScrolling(true, -3, direction, w, h, x, y, speed);
|
animator.startAutoScrolling(true, -3, direction, w, h, x, y, speed);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
animator.doStep();
|
||||||
postInvalidate();
|
postInvalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue