Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
truefedex committed Jun 9, 2017
1 parent 6ab4085 commit 57b40e3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ google-services.json
freeline.py
freeline/
freeline_project_description.json
/build/
1 change: 1 addition & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apdfjs-lib/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.github.truefedex.apdfjs.** { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -6485,7 +6485,7 @@ var pdfjsWebLibs;
var file;
var queryString = document.location.search.substring(1);
var params = parseQueryString(queryString);
file = 'file' in params ? params.file : DEFAULT_URL;
file = 'file' in params ? params.file : APDFJS.getFileName();
validateFileURL(file);
var waitForBeforeOpening = [];
var appConfig = PDFViewerApplication.appConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/

public class PDFJSView extends FrameLayout {
public static final String PDFJS_ASSETS_PATH = "file:///android_asset/pdfjs-1.7.225-dist/web/viewer.html";
private WebView webView;
private APDFJSInterface apdfjsInterface = new APDFJSInterface();

public PDFJSView(Context context) {
super(context);
Expand All @@ -32,13 +34,14 @@ public PDFJSView(Context context, AttributeSet attrs, int defStyleAttr) {
init();
}

@SuppressLint("SetJavaScriptEnabled")
@SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface"})
private void init() {
webView = new WebView(getContext());
addView(webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.addJavascriptInterface(apdfjsInterface, "APDFJS");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
Expand All @@ -54,12 +57,19 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
}

public void loadFromAssets(String pdfAssetsPath) {
webView.loadUrl("file:///android_asset/pdfjs-1.7.225-dist/web/viewer.html?file=file:///android_asset/" +
Uri.encode(pdfAssetsPath, "UTF-8"));
apdfjsInterface.fileName = "file:///android_asset/" + Uri.encode(pdfAssetsPath, "UTF-8");
webView.loadUrl(PDFJS_ASSETS_PATH);
}

public void loadFromFile(String pdfFilePath) {
webView.loadUrl("file:///android_asset/pdfjs-1.7.225-dist/web/viewer.html?file=file://" +
Uri.encode(pdfFilePath, "UTF-8"));
apdfjsInterface.fileName = Uri.encode(pdfFilePath, "UTF-8");
webView.loadUrl(PDFJS_ASSETS_PATH);
}

public class APDFJSInterface {
String fileName = "";
public String getFileName() {
return fileName;
}
}
}
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'proguard-rules.pro'
}
buildTypes {
release {
Expand Down

0 comments on commit 57b40e3

Please sign in to comment.