diff --git a/app/build.gradle b/app/build.gradle index 19506255c..a4954b26e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,8 +34,8 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.0' } def props = new Properties() diff --git a/app/src/main/assets/viewer.js b/app/src/main/assets/viewer.js index c11db9b06..29dd98749 100644 --- a/app/src/main/assets/viewer.js +++ b/app/src/main/assets/viewer.js @@ -59,6 +59,7 @@ function display(newCanvas, zoom) { if (!zoom) { scrollTo(0, 0); } + channel.hideProgressBar(); } function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) { diff --git a/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java b/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java index 22517fa83..0df99b771 100644 --- a/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java +++ b/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java @@ -20,24 +20,28 @@ import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; +import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.loader.app.LoaderManager; import androidx.loader.content.Loader; import com.google.android.material.snackbar.Snackbar; +import org.grapheneos.pdfviewer.fragment.DocumentPropertiesFragment; +import org.grapheneos.pdfviewer.fragment.JumpToPageFragment; +import org.grapheneos.pdfviewer.loader.DocumentPropertiesLoader; + import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.List; -import org.grapheneos.pdfviewer.fragment.DocumentPropertiesFragment; -import org.grapheneos.pdfviewer.fragment.JumpToPageFragment; -import org.grapheneos.pdfviewer.loader.DocumentPropertiesLoader; - public class PdfViewer extends AppCompatActivity implements LoaderManager.LoaderCallbacks> { public static final String TAG = "PdfViewer"; @@ -85,6 +89,8 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader private static final int STATE_END = 2; private static final int PADDING = 10; + private boolean mIsProgressBarVisible; + private Uri mUri; public int mPage; public int mNumPages; @@ -95,6 +101,9 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader private List mDocumentProperties; private InputStream mInputStream; + private CoordinatorLayout mCoordinatorLayout; + private Toolbar mToolbar; + private ProgressBar mProgressBar; private WebView mWebView; private TextView mTextView; private Toast mToast; @@ -127,6 +136,16 @@ public void setNumPages(int numPages) { runOnUiThread(PdfViewer.this::invalidateOptionsMenu); } + @JavascriptInterface + public void hideProgressBar() { + if (mIsProgressBarVisible) { + mIsProgressBarVisible = false; + runOnUiThread(() -> { + mProgressBar.setVisibility(View.INVISIBLE); + }); + } + } + @JavascriptInterface public void setDocumentProperties(final String properties) { if (mDocumentProperties != null) { @@ -154,10 +173,22 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.webview); + mCoordinatorLayout = findViewById(R.id.appCoordinatorLayout); + + mIsProgressBarVisible = false; + mProgressBar = findViewById(R.id.progressBar); + + mToolbar = findViewById(R.id.toolbar); + setSupportActionBar(mToolbar); + mToolbar.inflateMenu(R.menu.pdf_viewer); + mToolbar.setTitle(R.string.app_name); + mWebView = findViewById(R.id.webview); mWebView.setOnApplyWindowInsetsListener((view, insets) -> { - windowInsetTop = insets.getSystemWindowInsetTop(); + // The ActionBar is no longer a part of the system, so we have to + // add in its height for the inset. + windowInsetTop = insets.getSystemWindowInsetTop() + mToolbar.getMinimumHeight(); mWebView.evaluateJavascript("updateInset()", null); return insets; }); @@ -234,7 +265,7 @@ public void onPageFinished(WebView view, String url) { } }); - showSystemUi(); + showSystemUiAndActionBar(); GestureHelper.attach(PdfViewer.this, mWebView, new GestureHelper.GestureListener() { @@ -245,9 +276,9 @@ public boolean onTapUp() { if (!Boolean.valueOf(selection)) { if ((getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { - hideSystemUi(); + hideSystemUiAndActionBar(); } else { - showSystemUi(); + showSystemUiAndActionBar(); } } }); @@ -283,7 +314,7 @@ public void onZoomEnd() { // loader manager impl so that the result will be delivered. LoaderManager.getInstance(this); - snackbar = Snackbar.make(mWebView, "", Snackbar.LENGTH_LONG); + snackbar = Snackbar.make(mCoordinatorLayout, "", Snackbar.LENGTH_LONG); final Intent intent = getIntent(); if (Intent.ACTION_VIEW.equals(intent.getAction())) { @@ -328,12 +359,20 @@ public void onLoaderReset(Loader> loader) { mDocumentProperties = null; } + private void showProgressBar(final int zoom) { + if (zoom == 0) { + mIsProgressBarVisible = true; + mProgressBar.setVisibility(View.VISIBLE); + } + } + private void loadPdf() { try { if (mInputStream != null) { mInputStream.close(); } mInputStream = getContentResolver().openInputStream(mUri); + showProgressBar(0); } catch (IOException e) { snackbar.setText(R.string.io_error).show(); return; @@ -342,6 +381,7 @@ private void loadPdf() { } private void renderPage(final int zoom) { + showProgressBar(zoom); mWebView.evaluateJavascript("onRenderPage(" + zoom + ")", null); } @@ -399,14 +439,19 @@ public void onJumpToPageInDocument(final int selected_page) { } } - private void showSystemUi() { + private void showSystemUiAndActionBar() { getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + + final ActionBar actionBar = getSupportActionBar(); + if (actionBar != null && !actionBar.isShowing()) { + actionBar.show(); + } } - private void hideSystemUi() { + private void hideSystemUiAndActionBar() { getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | @@ -414,6 +459,11 @@ private void hideSystemUi() { View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE); + + final ActionBar actionBar = getSupportActionBar(); + if (actionBar != null && actionBar.isShowing()) { + actionBar.hide(); + } } @Override diff --git a/app/src/main/res/layout/webview.xml b/app/src/main/res/layout/webview.xml index 36674fc11..4d7e3ef21 100644 --- a/app/src/main/res/layout/webview.xml +++ b/app/src/main/res/layout/webview.xml @@ -1,5 +1,58 @@ - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 766ab9930..3f5900b21 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,8 +1,7 @@ -