Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions android/src/main/java/org/wonday/pdf/PdfView.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Arrays;

import com.google.gson.Gson;

Expand Down Expand Up @@ -99,6 +100,9 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
private float restoreXOffset = 0;
private float restoreYOffset = 0;

// Configuration of the last document load started by drawPdf(), see loadConfig().
private String lastLoadConfig = null;

// used to store the parameters for `super.onSizeChanged`
private int oldW = 0;
private int oldH = 0;
Expand Down Expand Up @@ -344,6 +348,16 @@ public void drawPdf() {

if (this.path != null){

// drawPdf() runs several times per mount (setPath, onAfterUpdateTransaction,
// onAttachedToWindow) and on every prop transaction. Each reload cancels the
// in-flight DecodingAsyncTask, which never closes the native document it may
// already have opened, so skip reloads that would not change anything.
String loadConfig = this.loadConfig();
if (!this.isRecycled() && loadConfig.equals(this.lastLoadConfig)) {
return;
}
this.lastLoadConfig = loadConfig;

// set scale
this.setMinZoom(this.minScale);
this.setMaxZoom(this.maxScale);
Expand Down Expand Up @@ -414,6 +428,16 @@ public void drawPdf() {
}
}

// Every prop drawPdf() passes to the Configurator. page is left out: it tracks the
// displayed page and setPage() applies it to the live view.
private String loadConfig() {
return Arrays.asList(this.path, this.horizontal, this.spacing, this.password,
this.enableAntialiasing, this.fitPolicy, this.pageSnap, this.autoSpacing,
this.pageFling, this.singlePage, this.scrollEnabled, this.enableDoubleTapZoom,
this.enableAnnotationRendering, this.enableRTL, this.minScale,
this.maxScale).toString();
}

public void setEnableDoubleTapZoom(boolean enableDoubleTapZoom) {
this.enableDoubleTapZoom = enableDoubleTapZoom;
}
Expand Down