在 epub 阅读器中转到页面(页面Turner)
我必须在epub阅读器中实现“转到页面”功能。我尝试过在Page-Turner的源代码中实现此功能,但由于.epub文件中的多个xhtml,它无法成功工作,因为我们知道每个章节都有一个xhtml文件,并且根据此应用程序中的屏幕大小划分。所以每当屏幕大的时候,当屏幕很小的时候,总页数就会越来越少,所以没有固定的页码跳到哪里。我有编辑并尝试实现像下面的给予者。
阅读碎片.java
public void performSearch(String query) {
int index = Integer.parseInt(query);
if (index > bookView.getTotalNumberOfPages()) {
Toast.makeText(context, "Please enter number between 0 to " + bookView.getTotalNumberOfPages(), Toast.LENGTH_SHORT).show();
} else {
bookView.gotoPageNumber(index);
}
}
书评.java
public void gotoPageNumber(int pageNum) {
strategy.gotoPage(pageNum);
progressUpdate();
}
页面更改策略.java
public void gotoPage(int pageNumber);
FixedPagesStrategy.java
@Override
public void gotoPage(int pageNumber) {
PageTurnerSpine spinePos = bookView.getSpine();
this.storedPosition = -1;
int currentPage = getCurrentPage() + spinePos.getUptoPage(spinePos.getPosition());
Log.e(TAG, "Adding >> Upto Page : " + spinePos.getUptoPage(spinePos.getPosition())
+ ", currentPage : " + getCurrentPage());
Log.e(TAG, "pagenum : " + pageNum);
if (pageNumber > currentPage) { //pageNumber is greater then current page
int jumpSpine = spinePos.getIndexFromPage(pageNumber);
int currentSpine = spinePos.getPosition();
Log.e(TAG, "jumpSpine : " + jumpSpine + ", currentSpine : " + currentSpine);
if (jumpSpine == currentSpine) {
int diffrence = pageNumber - currentPage;
Log.e(TAG, "diffrence < : " + diffrence);
Log.e(TAG, "Minimum >> PageOffSets - 1 : " + (spinePos.getPageOffSets(currentSpine) - 1)
+ ", pageNum + diffrence : " + (pageNum + diffrence));
this.pageNum = Math.min(pageNum + diffrence, spinePos.getPageOffSets(currentSpine) - 1);
updatePosition();
} else {
PageTurnerSpine spine = bookView.getSpine();
if (spine == null || !spine.navigateFrontSpine(spine.getIndexFromPage(pageNumber))) {
return;
}
this.pageNum = 0;
gotoPage(pageNumber);
}
} else { //pageNumber is less then current page
int jumpSpine = spinePos.getIndexFromPage(pageNumber);
int currentSpine = spinePos.getPosition();
Log.e(TAG, "jumpSpine : " + jumpSpine + ", currentSpine : " + currentSpine);
if (jumpSpine == currentSpine) {
int diffrence = currentPage - pageNumber;
Log.e(TAG, "diffrence > : " + diffrence);
Log.e(TAG, "pagenum - diffrence : " + (pageNum - diffrence));
this.pageNum = Math.max(pageNum - diffrence, 0);
updatePosition();
} else {
PageTurnerSpine spine = bookView.getSpine();
if (spine == null || !spine.navigateBackSpine(spine.getIndexFromPage(pageNumber))) {
return;
}
this.pageNum = 0;
gotoPage(pageNumber);
}
}
Log.e(TAG, "In last pageNum : " + pageNum);
}
PageTurnerSpine.java
public int getIndexFromPage(int pageNumber) {
int total = 0;
int totalIndex = 0;
for (List<Integer> pagesPerSection : pageOffsets) {
total += pagesPerSection.size();
totalIndex = totalIndex + 1;
if (total - 1 >= pageNumber) {
return totalIndex - 1;
}
}
return 0;
}
public int getUptoPage(int position) {
int total = 0, max = 0;
for (List<Integer> pagesPerSection : pageOffsets) {
max = max + 1;
if (position == max - 1) {
return total;
}
total += pagesPerSection.size();
}
return 0;
}
public int getPageOffSets(int position) {
int max = 0;
for (List<Integer> pagesPerSection : pageOffsets) {
max = max + 1;
if (position == max - 1) {
return pagesPerSection.size();
}
}
return 0;
}
public boolean navigateFrontSpine(int indexSpine) {
if (this.position == size() - 1) {
return false;
}
this.position = indexSpine;
return true;
}
public boolean navigateBackSpine(int indexSpine) {
if (this.position == 0) {
return false;
}
this.position = indexSpine;
return true;
}
当我应用此代码并运行一段时间时,它可以正常工作。但是有一段时间它会跳到其他页码上,比如如果我输入110,那么它会跳到109上。当我试图跳到章节开始页面,然后包含剂量不变。请帮帮我。
https://github.com/NightWhistler/PageTurner在这个源代码中,我编辑了上面给出的一些文件。它们已经存在于此项目中。
大多数我看到大多数epub阅读器,如Kindle,FBReader等...不实现“转到页面”功能。所以,我也想知道是否有可能实现此功能?
感谢您的帮助:)