|
|
|
@ -1,18 +1,16 @@
|
|
|
|
|
package org.grapheneos.pdfviewer;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.res.ColorStateList;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.Gravity;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.webkit.CookieManager;
|
|
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
|
|
import android.webkit.WebResourceRequest;
|
|
|
|
@ -24,13 +22,11 @@ import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
import androidx.loader.app.LoaderManager;
|
|
|
|
|
import androidx.loader.content.Loader;
|
|
|
|
|
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
|
|
|
|
|
|
|
import org.grapheneos.pdfviewer.databinding.WebviewBinding;
|
|
|
|
|
import org.grapheneos.pdfviewer.fragment.DocumentPropertiesFragment;
|
|
|
|
|
import org.grapheneos.pdfviewer.fragment.JumpToPageFragment;
|
|
|
|
|
import org.grapheneos.pdfviewer.loader.DocumentPropertiesLoader;
|
|
|
|
@ -40,13 +36,9 @@ import java.io.InputStream;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class PdfViewer extends AppCompatActivity implements LoaderManager.LoaderCallbacks<List<CharSequence>> {
|
|
|
|
|
public class PdfViewer extends WebView implements LoaderManager.LoaderCallbacks<List<CharSequence>> {
|
|
|
|
|
public static final String TAG = "PdfViewer";
|
|
|
|
|
|
|
|
|
|
private static final String STATE_URI = "uri";
|
|
|
|
|
private static final String STATE_PAGE = "page";
|
|
|
|
|
private static final String STATE_ZOOM_RATIO = "zoomRatio";
|
|
|
|
|
private static final String STATE_DOCUMENT_ORIENTATION_DEGREES = "documentOrientationDegrees";
|
|
|
|
|
private static final String KEY_PROPERTIES = "properties";
|
|
|
|
|
|
|
|
|
|
private static final String CONTENT_SECURITY_POLICY =
|
|
|
|
@ -92,12 +84,10 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
private static final float MAX_ZOOM_RATIO = 1.5f;
|
|
|
|
|
private static final int ALPHA_LOW = 130;
|
|
|
|
|
private static final int ALPHA_HIGH = 255;
|
|
|
|
|
private static final int ACTION_OPEN_DOCUMENT_REQUEST_CODE = 1;
|
|
|
|
|
private static final int STATE_LOADED = 1;
|
|
|
|
|
private static final int STATE_END = 2;
|
|
|
|
|
private static final int PADDING = 10;
|
|
|
|
|
|
|
|
|
|
private Uri mUri;
|
|
|
|
|
public int mPage;
|
|
|
|
|
public int mNumPages;
|
|
|
|
|
private float mZoomRatio = 1f;
|
|
|
|
@ -107,70 +97,27 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
private List<CharSequence> mDocumentProperties;
|
|
|
|
|
private InputStream mInputStream;
|
|
|
|
|
|
|
|
|
|
private WebviewBinding binding;
|
|
|
|
|
private TextView mTextView;
|
|
|
|
|
private Toast mToast;
|
|
|
|
|
private Snackbar snackbar;
|
|
|
|
|
|
|
|
|
|
private class Channel {
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public int getWindowInsetTop() {
|
|
|
|
|
return windowInsetTop;
|
|
|
|
|
}
|
|
|
|
|
public AppCompatActivity activity;
|
|
|
|
|
String fileName;
|
|
|
|
|
Long fileSize;
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public int getPage() {
|
|
|
|
|
return mPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public float getZoomRatio() {
|
|
|
|
|
return mZoomRatio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public int getDocumentOrientationDegrees() {
|
|
|
|
|
return mDocumentOrientationDegrees;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public void setNumPages(int numPages) {
|
|
|
|
|
mNumPages = numPages;
|
|
|
|
|
runOnUiThread(PdfViewer.this::invalidateOptionsMenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public void setDocumentProperties(final String properties) {
|
|
|
|
|
if (mDocumentProperties != null) {
|
|
|
|
|
throw new SecurityException("mDocumentProperties not null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final Bundle args = new Bundle();
|
|
|
|
|
args.putString(KEY_PROPERTIES, properties);
|
|
|
|
|
runOnUiThread(() -> LoaderManager.getInstance(PdfViewer.this).restartLoader(DocumentPropertiesLoader.ID, args, PdfViewer.this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SuppressLint({"SetJavaScriptEnabled", "ClickableViewAccessibility"})
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
binding = WebviewBinding.inflate(getLayoutInflater());
|
|
|
|
|
setContentView(binding.getRoot());
|
|
|
|
|
|
|
|
|
|
binding.webview.setBackgroundColor(Color.TRANSPARENT);
|
|
|
|
|
void init(Context context) {
|
|
|
|
|
setBackgroundColor(Color.TRANSPARENT);
|
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
|
WebView.setWebContentsDebuggingEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
binding.webview.setOnApplyWindowInsetsListener((view, insets) -> {
|
|
|
|
|
setOnApplyWindowInsetsListener((view, insets) -> {
|
|
|
|
|
windowInsetTop = insets.getSystemWindowInsetTop();
|
|
|
|
|
binding.webview.evaluateJavascript("updateInset()", null);
|
|
|
|
|
evaluateJavascript("updateInset()", null);
|
|
|
|
|
return insets;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final WebSettings settings = binding.webview.getSettings();
|
|
|
|
|
final WebSettings settings = getSettings();
|
|
|
|
|
settings.setAllowContentAccess(false);
|
|
|
|
|
settings.setAllowFileAccess(false);
|
|
|
|
|
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
|
|
|
|
@ -178,12 +125,12 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
|
|
|
|
|
CookieManager.getInstance().setAcceptCookie(false);
|
|
|
|
|
|
|
|
|
|
binding.webview.addJavascriptInterface(new Channel(), "channel");
|
|
|
|
|
addJavascriptInterface(new Channel(), "channel");
|
|
|
|
|
|
|
|
|
|
binding.webview.setWebViewClient(new WebViewClient() {
|
|
|
|
|
setWebViewClient(new WebViewClient() {
|
|
|
|
|
private WebResourceResponse fromAsset(final String mime, final String path) {
|
|
|
|
|
try {
|
|
|
|
|
InputStream inputStream = getAssets().open(path.substring(1));
|
|
|
|
|
InputStream inputStream = context.getAssets().open(path.substring(1));
|
|
|
|
|
return new WebResourceResponse(mime, null, inputStream);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
return null;
|
|
|
|
@ -237,30 +184,12 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
@Override
|
|
|
|
|
public void onPageFinished(WebView view, String url) {
|
|
|
|
|
mDocumentState = STATE_LOADED;
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
activity.invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
GestureHelper.attach(PdfViewer.this, binding.webview,
|
|
|
|
|
GestureHelper.attach(context, this,
|
|
|
|
|
new GestureHelper.GestureListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTapUp() {
|
|
|
|
|
if (mUri != null) {
|
|
|
|
|
binding.webview.evaluateJavascript("isTextSelected()", selection -> {
|
|
|
|
|
if (!Boolean.parseBoolean(selection)) {
|
|
|
|
|
if ((getWindow().getDecorView().getSystemUiVisibility() &
|
|
|
|
|
View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
|
|
|
|
hideSystemUi();
|
|
|
|
|
} else {
|
|
|
|
|
showSystemUi();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onZoomIn(float value) {
|
|
|
|
|
zoomIn(value, false);
|
|
|
|
@ -277,56 +206,82 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mTextView = new TextView(this);
|
|
|
|
|
mTextView = new TextView(context);
|
|
|
|
|
mTextView.setBackgroundColor(Color.DKGRAY);
|
|
|
|
|
mTextView.setTextColor(ColorStateList.valueOf(Color.WHITE));
|
|
|
|
|
mTextView.setTextSize(18);
|
|
|
|
|
mTextView.setPadding(PADDING, 0, PADDING, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If loaders are not being initialized in onCreate(), the result will not be delivered
|
|
|
|
|
// after orientation change (See FragmentHostCallback), thus initialize the
|
|
|
|
|
// loader manager impl so that the result will be delivered.
|
|
|
|
|
LoaderManager.getInstance(this);
|
|
|
|
|
public PdfViewer(@NonNull Context context) {
|
|
|
|
|
super(context);
|
|
|
|
|
init(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snackbar = Snackbar.make(binding.webview, "", Snackbar.LENGTH_LONG);
|
|
|
|
|
public PdfViewer(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
|
|
|
super(context, attrs);
|
|
|
|
|
init(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final Intent intent = getIntent();
|
|
|
|
|
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
|
|
if (!"application/pdf".equals(intent.getType())) {
|
|
|
|
|
snackbar.setText(R.string.invalid_mime_type).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mUri = intent.getData();
|
|
|
|
|
mPage = 1;
|
|
|
|
|
public PdfViewer(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
|
init(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onCreateOptionMenu(Menu menu) {
|
|
|
|
|
MenuInflater inflater = activity.getMenuInflater();
|
|
|
|
|
inflater.inflate(R.menu.pdf_viewer, menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class Channel {
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public int getWindowInsetTop() {
|
|
|
|
|
return windowInsetTop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public int getPage() {
|
|
|
|
|
return mPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
|
mUri = savedInstanceState.getParcelable(STATE_URI);
|
|
|
|
|
mPage = savedInstanceState.getInt(STATE_PAGE);
|
|
|
|
|
mZoomRatio = savedInstanceState.getFloat(STATE_ZOOM_RATIO);
|
|
|
|
|
mDocumentOrientationDegrees = savedInstanceState.getInt(STATE_DOCUMENT_ORIENTATION_DEGREES);
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public float getZoomRatio() {
|
|
|
|
|
return mZoomRatio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mUri != null) {
|
|
|
|
|
if ("file".equals(mUri.getScheme())) {
|
|
|
|
|
snackbar.setText(R.string.legacy_file_uri).show();
|
|
|
|
|
return;
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public int getDocumentOrientationDegrees() {
|
|
|
|
|
return mDocumentOrientationDegrees;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public void setNumPages(int numPages) {
|
|
|
|
|
mNumPages = numPages;
|
|
|
|
|
activity.runOnUiThread(activity::invalidateOptionsMenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
public void setDocumentProperties(final String properties) {
|
|
|
|
|
if (mDocumentProperties != null) {
|
|
|
|
|
throw new SecurityException("mDocumentProperties not null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadPdf();
|
|
|
|
|
final Bundle args = new Bundle();
|
|
|
|
|
args.putString(KEY_PROPERTIES, properties);
|
|
|
|
|
activity.runOnUiThread(() -> LoaderManager.getInstance(PdfViewer.this.activity).restartLoader(DocumentPropertiesLoader.ID, args, PdfViewer.this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
|
@Override
|
|
|
|
|
public Loader<List<CharSequence>> onCreateLoader(int id, Bundle args) {
|
|
|
|
|
return new DocumentPropertiesLoader(this, args.getString(KEY_PROPERTIES), mNumPages, mUri);
|
|
|
|
|
return new DocumentPropertiesLoader(activity, args.getString(KEY_PROPERTIES), mNumPages, fileName, fileSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLoadFinished(@NonNull Loader<List<CharSequence>> loader, List<CharSequence> data) {
|
|
|
|
|
mDocumentProperties = data;
|
|
|
|
|
LoaderManager.getInstance(this).destroyLoader(DocumentPropertiesLoader.ID);
|
|
|
|
|
LoaderManager.getInstance(activity).destroyLoader(DocumentPropertiesLoader.ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -334,23 +289,18 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
mDocumentProperties = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadPdf() {
|
|
|
|
|
try {
|
|
|
|
|
if (mInputStream != null) {
|
|
|
|
|
mInputStream.close();
|
|
|
|
|
}
|
|
|
|
|
mInputStream = getContentResolver().openInputStream(mUri);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
snackbar.setText(R.string.io_error).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showSystemUi();
|
|
|
|
|
binding.webview.loadUrl("https://localhost/viewer.html");
|
|
|
|
|
public void loadPdf(InputStream inputStream, String fileName, Long fileSize) {
|
|
|
|
|
mPage = 1;
|
|
|
|
|
mDocumentProperties = null;
|
|
|
|
|
mInputStream = inputStream;
|
|
|
|
|
this.fileName = fileName;
|
|
|
|
|
this.fileSize = fileSize;
|
|
|
|
|
loadUrl("https://localhost/viewer.html");
|
|
|
|
|
activity.invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void renderPage(final int zoom) {
|
|
|
|
|
binding.webview.evaluateJavascript("onRenderPage(" + zoom + ")", null);
|
|
|
|
|
evaluateJavascript("onRenderPage(" + zoom + ")", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void documentOrientationChanged(final int orientationDegreesOffset) {
|
|
|
|
@ -361,18 +311,11 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
renderPage(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void openDocument() {
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
|
intent.setType("application/pdf");
|
|
|
|
|
startActivityForResult(intent, ACTION_OPEN_DOCUMENT_REQUEST_CODE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void zoomIn(float value, boolean end) {
|
|
|
|
|
if (mZoomRatio < MAX_ZOOM_RATIO) {
|
|
|
|
|
mZoomRatio = Math.min(mZoomRatio + value, MAX_ZOOM_RATIO);
|
|
|
|
|
renderPage(end ? 1 : 2);
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
activity.invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -380,7 +323,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
if (mZoomRatio > MIN_ZOOM_RATIO) {
|
|
|
|
|
mZoomRatio = Math.max(mZoomRatio - value, MIN_ZOOM_RATIO);
|
|
|
|
|
renderPage(end ? 1 : 2);
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
activity.invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -403,48 +346,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
mPage = selected_page;
|
|
|
|
|
renderPage(0);
|
|
|
|
|
showPageNumber();
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showSystemUi() {
|
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(
|
|
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
|
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
|
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void hideSystemUi() {
|
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(
|
|
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
|
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
|
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
|
|
|
|
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
|
|
|
|
View.SYSTEM_UI_FLAG_FULLSCREEN |
|
|
|
|
|
View.SYSTEM_UI_FLAG_IMMERSIVE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
|
|
|
|
|
super.onSaveInstanceState(savedInstanceState);
|
|
|
|
|
savedInstanceState.putParcelable(STATE_URI, mUri);
|
|
|
|
|
savedInstanceState.putInt(STATE_PAGE, mPage);
|
|
|
|
|
savedInstanceState.putFloat(STATE_ZOOM_RATIO, mZoomRatio);
|
|
|
|
|
savedInstanceState.putInt(STATE_DOCUMENT_ORIENTATION_DEGREES, mDocumentOrientationDegrees);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent resultData) {
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, resultData);
|
|
|
|
|
|
|
|
|
|
if (requestCode == ACTION_OPEN_DOCUMENT_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
|
|
|
|
if (resultData != null) {
|
|
|
|
|
mUri = resultData.getData();
|
|
|
|
|
mPage = 1;
|
|
|
|
|
mDocumentProperties = null;
|
|
|
|
|
loadPdf();
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|
activity.invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -453,22 +355,13 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
mToast.cancel();
|
|
|
|
|
}
|
|
|
|
|
mTextView.setText(String.format("%s/%s", mPage, mNumPages));
|
|
|
|
|
mToast = new Toast(getApplicationContext());
|
|
|
|
|
mToast = new Toast(activity);
|
|
|
|
|
mToast.setGravity(Gravity.BOTTOM | Gravity.END, PADDING, PADDING);
|
|
|
|
|
mToast.setDuration(Toast.LENGTH_SHORT);
|
|
|
|
|
mToast.setView(mTextView);
|
|
|
|
|
mToast.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
super.onCreateOptionsMenu(menu);
|
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
|
inflater.inflate(R.menu.pdf_viewer, menu);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
final int[] ids = { R.id.action_zoom_in, R.id.action_zoom_out, R.id.action_jump_to_page,
|
|
|
|
|
R.id.action_next, R.id.action_previous, R.id.action_first, R.id.action_last,
|
|
|
|
@ -499,7 +392,6 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
final int itemId = item.getItemId();
|
|
|
|
|
if (itemId == R.id.action_previous) {
|
|
|
|
@ -514,9 +406,6 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
} else if (itemId == R.id.action_last) {
|
|
|
|
|
onJumpToPageInDocument(mNumPages);
|
|
|
|
|
return true;
|
|
|
|
|
} else if (itemId == R.id.action_open) {
|
|
|
|
|
openDocument();
|
|
|
|
|
return true;
|
|
|
|
|
} else if (itemId == R.id.action_zoom_out) {
|
|
|
|
|
zoomOut(0.25f, true);
|
|
|
|
|
return true;
|
|
|
|
@ -532,14 +421,13 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|
|
|
|
} else if (itemId == R.id.action_view_document_properties) {
|
|
|
|
|
DocumentPropertiesFragment
|
|
|
|
|
.newInstance(mDocumentProperties)
|
|
|
|
|
.show(getSupportFragmentManager(), DocumentPropertiesFragment.TAG);
|
|
|
|
|
.show(activity.getSupportFragmentManager(), DocumentPropertiesFragment.TAG);
|
|
|
|
|
return true;
|
|
|
|
|
} else if (itemId == R.id.action_jump_to_page) {
|
|
|
|
|
new JumpToPageFragment()
|
|
|
|
|
.show(getSupportFragmentManager(), JumpToPageFragment.TAG);
|
|
|
|
|
JumpToPageFragment.newInstance(this)
|
|
|
|
|
.show(activity.getSupportFragmentManager(), JumpToPageFragment.TAG);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|