mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
more accurate page numbering for very short (< 3 pages) books
This commit is contained in:
parent
6e44e03595
commit
99a3b7015c
3 changed files with 62 additions and 16 deletions
|
@ -144,13 +144,12 @@ final class NavigationPopup extends PopupPanel {
|
|||
final TextView text = (TextView)panel.findViewById(R.id.book_position_text);
|
||||
|
||||
final ZLTextView textView = getReader().getTextView();
|
||||
final int page = textView.computeCurrentPage();
|
||||
final int pagesNumber = textView.computePageNumber();
|
||||
final ZLTextView.PagePosition pagePosition = textView.pagePosition();
|
||||
|
||||
if (slider.getMax() != pagesNumber - 1 || slider.getProgress() != page - 1) {
|
||||
slider.setMax(pagesNumber - 1);
|
||||
slider.setProgress(page - 1);
|
||||
text.setText(makeProgressText(page, pagesNumber));
|
||||
if (slider.getMax() != pagePosition.Total - 1 || slider.getProgress() != pagePosition.Current - 1) {
|
||||
slider.setMax(pagePosition.Total - 1);
|
||||
slider.setProgress(pagePosition.Current - 1);
|
||||
text.setText(makeProgressText(pagePosition.Current, pagePosition.Total));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -489,14 +489,13 @@ public final class FBView extends ZLTextView {
|
|||
height > 10, false, false
|
||||
);
|
||||
|
||||
final int pagesProgress = computeCurrentPage();
|
||||
final int bookLength = computePageNumber();
|
||||
final PagePosition pagePosition = FBView.this.pagePosition();
|
||||
|
||||
final StringBuilder info = new StringBuilder();
|
||||
if (reader.FooterShowProgressOption.getValue()) {
|
||||
info.append(pagesProgress);
|
||||
info.append(pagePosition.Current);
|
||||
info.append("/");
|
||||
info.append(bookLength);
|
||||
info.append(pagePosition.Total);
|
||||
}
|
||||
if (reader.FooterShowBatteryOption.getValue()) {
|
||||
if (info.length() > 0) {
|
||||
|
@ -537,7 +536,7 @@ public final class FBView extends ZLTextView {
|
|||
context.drawLine(gaugeRight, lineWidth, left, lineWidth);
|
||||
|
||||
final int gaugeInternalRight =
|
||||
left + lineWidth + (int)(1.0 * myGaugeWidth * pagesProgress / bookLength);
|
||||
left + lineWidth + (int)(1.0 * myGaugeWidth * pagePosition.Current / pagePosition.Total);
|
||||
|
||||
context.setFillColor(fillColor);
|
||||
context.fillRectangle(left + 1, height - 2 * lineWidth, gaugeInternalRight, lineWidth + 1);
|
||||
|
|
|
@ -483,7 +483,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
if (myModel == null || myModel.getParagraphsNumber() == 0) {
|
||||
return 0;
|
||||
}
|
||||
ZLTextPage page = getPage(pageIndex);
|
||||
final ZLTextPage page = getPage(pageIndex);
|
||||
preparePaintInfo(page);
|
||||
if (startNotEndOfPage) {
|
||||
return Math.max(0, sizeOfTextBeforeCursor(page.StartCursor));
|
||||
|
@ -613,12 +613,60 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
return myContext.getStringWidth(pattern, 0, length) / ((float)length);
|
||||
}
|
||||
|
||||
public final synchronized int computePageNumber() {
|
||||
return computeTextPageNumber(sizeOfFullText());
|
||||
public static class PagePosition {
|
||||
public final int Current;
|
||||
public final int Total;
|
||||
|
||||
PagePosition(int current, int total) {
|
||||
Current = current;
|
||||
Total = total;
|
||||
}
|
||||
}
|
||||
|
||||
public final synchronized int computeCurrentPage() {
|
||||
return computeTextPageNumber(getCurrentCharNumber(PageIndex.current, false));
|
||||
public final synchronized PagePosition pagePosition() {
|
||||
final int currentCharIndex = getCurrentCharNumber(PageIndex.current, false);
|
||||
final int lastCharIndex = sizeOfFullText();
|
||||
int current = computeTextPageNumber(currentCharIndex);
|
||||
int total = computeTextPageNumber(lastCharIndex);
|
||||
|
||||
if (current == total) {
|
||||
if (currentCharIndex < lastCharIndex) {
|
||||
if (total <= 2) {
|
||||
total += 1;
|
||||
} else {
|
||||
current -= 1;
|
||||
}
|
||||
} else {
|
||||
if (total == 1) {
|
||||
ZLTextWordCursor cursor = myCurrentPage.StartCursor;
|
||||
if (cursor == null || cursor.isNull()) {
|
||||
preparePaintInfo(myCurrentPage);
|
||||
cursor = myCurrentPage.StartCursor;
|
||||
}
|
||||
if (cursor != null && !cursor.isNull() &&
|
||||
(!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst())) {
|
||||
total = 2;
|
||||
current = 2;
|
||||
}
|
||||
}
|
||||
if (total == 2) {
|
||||
ZLTextWordCursor cursor = myPreviousPage.StartCursor;
|
||||
if (cursor == null || cursor.isNull()) {
|
||||
preparePaintInfo(myPreviousPage);
|
||||
cursor = myPreviousPage.StartCursor;
|
||||
}
|
||||
if (cursor != null && !cursor.isNull() &&
|
||||
(!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst())) {
|
||||
total = 3;
|
||||
current = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (total == 2 && getCurrentCharNumber(PageIndex.next, false) < lastCharIndex) {
|
||||
total = 3;
|
||||
}
|
||||
|
||||
return new PagePosition(current, total);
|
||||
}
|
||||
|
||||
public final synchronized void gotoPage(int page) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue