-
Notifications
You must be signed in to change notification settings - Fork 432
Faster start times #2700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster start times #2700
Changes from all commits
e66ff2c
5305eca
ce30b12
d57b9a1
2d11e1d
7f94958
f81e780
b5ba7de
6c9d6c6
fa517ad
940af0d
d9a47f9
9584150
1892739
a27b4d4
cb67476
8abbebf
d925805
2c89b91
4e8637d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import android.view.SubMenu; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.view.ViewStub; | ||
| import android.view.Window; | ||
| import android.view.WindowManager; | ||
| import android.webkit.JavascriptInterface; | ||
|
|
@@ -94,6 +95,7 @@ public static DocumentEditAndViewFragment newInstance(final @NonNull Document do | |
|
|
||
| private HighlightingEditor _hlEditor; | ||
| private WebView _webView; | ||
| private ViewStub _webViewStub; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The webview is the heaviest view in the document fragment. This loads it lazily when necessary |
||
| private MarkorWebViewClient _webViewClient; | ||
| private ViewGroup _editorHolder; | ||
| private ViewGroup _textActionsBar; | ||
|
|
@@ -139,7 +141,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { | |
| _hlEditor = view.findViewById(R.id.document__fragment__edit__highlighting_editor); | ||
| _editorHolder = view.findViewById(R.id.document__fragment__edit__editor_holder); | ||
| _textActionsBar = view.findViewById(R.id.document__fragment__edit__text_actions_bar); | ||
| _webView = view.findViewById(R.id.document__fragment_view_webview); | ||
| _webViewStub = view.findViewById(R.id.document__fragment_webview_stub); | ||
| _verticalScrollView = view.findViewById(R.id.document__fragment__edit__content_editor__scrolling_parent); | ||
| _lineNumbersView = view.findViewById(R.id.document__fragment__edit__line_numbers_view); | ||
| _cu = new MarkorContextUtils(activity); | ||
|
|
@@ -159,34 +161,6 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { | |
| _lineNumbersView.setup(_hlEditor); | ||
| _lineNumbersView.setLineNumbersEnabled(_appSettings.getDocumentLineNumbersEnabled(_document.path)); | ||
|
|
||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && _appSettings.getSetWebViewFulldrawing()) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same code moved into block which is called when webview is actually required and loaded |
||
| WebView.enableSlowWholeDocumentDraw(); | ||
| } | ||
|
|
||
| _webViewClient = new MarkorWebViewClient(_webView, activity); | ||
| _webView.setWebChromeClient(new GsWebViewChromeClient(_webView, activity, view.findViewById(R.id.document__fragment_fullscreen_overlay))); | ||
| _webView.setWebViewClient(_webViewClient); | ||
| _webView.addJavascriptInterface(this, "Android"); | ||
| _webView.setBackgroundColor(Color.TRANSPARENT); | ||
| WebSettings webSettings = _webView.getSettings(); | ||
| webSettings.setBuiltInZoomControls(true); | ||
| webSettings.setDisplayZoomControls(false); | ||
| webSettings.setTextZoom((int) (_appSettings.getDocumentViewFontSize(_document.path) * VIEW_FONT_SCALE)); | ||
| webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); | ||
| webSettings.setDatabaseEnabled(true); | ||
| webSettings.setGeolocationEnabled(false); | ||
| webSettings.setJavaScriptEnabled(true); | ||
| webSettings.setDomStorageEnabled(true); | ||
| webSettings.setAllowFileAccess(true); | ||
| webSettings.setAllowContentAccess(true); | ||
| webSettings.setAllowFileAccessFromFileURLs(true); | ||
| webSettings.setAllowUniversalAccessFromFileURLs(false); | ||
| webSettings.setMediaPlaybackRequiresUserGesture(false); | ||
|
|
||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && BuildConfig.IS_TEST_BUILD && BuildConfig.DEBUG) { | ||
| WebView.setWebContentsDebuggingEnabled(true); // Inspect on computer chromium browser: chrome://inspect/#devices | ||
| } | ||
|
|
||
| // Upon construction, the document format has been determined from extension etc | ||
| // Here we replace it with the last saved format. | ||
| applyTextFormat(_appSettings.getDocumentFormat(_document.path, _document.getFormat())); | ||
|
|
@@ -257,14 +231,14 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { | |
| }); | ||
| } | ||
|
|
||
| _verticalScrollView.getViewTreeObserver().addOnGlobalLayoutListener(() -> { | ||
| _hlEditor.post(() -> { | ||
| final int height = _verticalScrollView.getHeight(); | ||
| if (height != _hlEditor.getMinHeight()) { | ||
| _hlEditor.setMinHeight(height); | ||
| } | ||
| }); | ||
| final Runnable ensureMinHeight = () -> _hlEditor.post(() -> { | ||
| final int height = _verticalScrollView.getHeight(); | ||
| if (height > 0 && height != _hlEditor.getMinHeight()) { | ||
| _hlEditor.setMinHeight(height); | ||
| } | ||
| }); | ||
| _verticalScrollView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> ensureMinHeight.run()); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Listening to a scrollview layout change instead of a global layout change |
||
| _verticalScrollView.post(ensureMinHeight); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -289,7 +263,9 @@ protected void onFragmentFirstTimeVisible() { | |
|
|
||
| @Override | ||
| public void onResume() { | ||
| _webView.onResume(); | ||
| if (_webView != null) { | ||
| _webView.onResume(); | ||
| } | ||
| loadDocument(); | ||
| if (_editTextUndoRedoHelper != null && _editTextUndoRedoHelper.getTextView() != _hlEditor) { | ||
| _editTextUndoRedoHelper.setTextView(_hlEditor); | ||
|
|
@@ -300,7 +276,9 @@ public void onResume() { | |
| @Override | ||
| public void onPause() { | ||
| saveDocument(false); | ||
| _webView.onPause(); | ||
| if (_webView != null) { | ||
| _webView.onPause(); | ||
| } | ||
| _appSettings.addRecentFile(_document.file); | ||
| _appSettings.setDocumentPreviewState(_document.path, _isPreviewVisible); | ||
| _appSettings.setLastEditPosition(_document.path, TextViewUtils.getSelection(_hlEditor)[0]); | ||
|
|
@@ -364,13 +342,17 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { | |
| _menuSearchViewForViewMode.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | ||
| @Override | ||
| public boolean onQueryTextSubmit(String text) { | ||
| _webView.findNext(true); | ||
| if (_webView != null) { | ||
| _webView.findNext(true); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onQueryTextChange(String text) { | ||
| _webView.findAllAsync(text); | ||
| if (_webView != null) { | ||
| _webView.findAllAsync(text); | ||
| } | ||
| return true; | ||
| } | ||
| }); | ||
|
|
@@ -551,16 +533,18 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) { | |
| _nextConvertToPrintMode = true; | ||
| setViewModeVisibility(true); | ||
| Toast.makeText(activity, R.string.please_wait, Toast.LENGTH_LONG).show(); | ||
| _webView.postDelayed(() -> { | ||
| if (itemId == R.id.action_share_pdf) { | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
| _cu.printOrCreatePdfFromWebview(_webView, _document, getTextString().contains("beamer\n")); | ||
| if (_webView != null) { | ||
| _webView.postDelayed(() -> { | ||
| if (itemId == R.id.action_share_pdf) { | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
| _cu.printOrCreatePdfFromWebview(_webView, _document, getTextString().contains("beamer\n")); | ||
| } | ||
| } else { | ||
| Bitmap bmp = _cu.getBitmapFromWebView(_webView, itemId == R.id.action_share_image); | ||
| _cu.shareImage(getContext(), bmp, null); | ||
| } | ||
| } else { | ||
| Bitmap bmp = _cu.getBitmapFromWebView(_webView, itemId == R.id.action_share_image); | ||
| _cu.shareImage(getContext(), bmp, null); | ||
| } | ||
| }, 7000); | ||
| }, 7000); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
|
|
@@ -648,7 +632,9 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { | |
| final int current = _isPreviewVisible ? _appSettings.getDocumentViewFontSize(_document.path) : _appSettings.getDocumentFontSize(_document.path); | ||
| MarkorDialogFactory.showFontSizeDialog(activity, current, (newSize) -> { | ||
| if (_isPreviewVisible) { | ||
| _webView.getSettings().setTextZoom((int) (newSize * VIEW_FONT_SCALE)); | ||
| if (_webView != null) { | ||
| _webView.getSettings().setTextZoom((int) (newSize * VIEW_FONT_SCALE)); | ||
| } | ||
| _appSettings.setDocumentViewFontSize(_document.path, newSize); | ||
| } else { | ||
| _hlEditor.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) newSize); | ||
|
|
@@ -667,7 +653,6 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| public void checkTextChangeState() { | ||
| final boolean isTextChanged = !_document.isContentSame(_hlEditor.getText()); | ||
| Drawable d; | ||
|
|
@@ -703,12 +688,14 @@ private void showHideActionBar() { | |
| final View parent = activity.findViewById(R.id.document__fragment__edit__text_actions_bar__scrolling_parent); | ||
| final View viewScroll = activity.findViewById(R.id.document__fragment_view_webview); | ||
|
|
||
| if (bar != null && parent != null && _verticalScrollView != null && viewScroll != null) { | ||
| if (bar != null && parent != null && _verticalScrollView != null) { | ||
| final boolean hide = _textActionsBar.getChildCount() == 0; | ||
| parent.setVisibility(hide ? View.GONE : View.VISIBLE); | ||
| final int marginBottom = hide ? 0 : (int) getResources().getDimension(R.dimen.textactions_bar_height); | ||
| setMarginBottom(_verticalScrollView, marginBottom); | ||
| setMarginBottom(viewScroll, marginBottom); | ||
| if (viewScroll != null) { | ||
| setMarginBottom(viewScroll, marginBottom); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -865,6 +852,9 @@ private boolean isDisplayedAtMainActivity() { | |
| } | ||
|
|
||
| public void updateViewModeText() { | ||
| if (_webView == null) { | ||
| return; | ||
| } | ||
| // Don't let text to view mode crash app | ||
| try { | ||
| _format.getConverter().convertMarkupShowInWebView(_document, getTextString(), getActivity(), _webView, _nextConvertToPrintMode, _lineNumbersView.isLineNumbersEnabled()); | ||
|
|
@@ -877,6 +867,37 @@ public void setViewModeVisibility(final boolean show) { | |
| setViewModeVisibility(show, true); | ||
| } | ||
|
|
||
| private void setupWebViewIfNeeded(final Activity activity) { | ||
| if (_webView == null) { | ||
| _webView = (WebView) _webViewStub.inflate(); | ||
| _webView.setWebChromeClient(new GsWebViewChromeClient(_webView, activity, activity.findViewById(R.id.document__fragment_fullscreen_overlay))); | ||
| _webView.addJavascriptInterface(this, "Android"); | ||
| _webView.setBackgroundColor(Color.TRANSPARENT); | ||
| WebSettings webSettings = _webView.getSettings(); | ||
| webSettings.setBuiltInZoomControls(true); | ||
| webSettings.setDisplayZoomControls(false); | ||
| webSettings.setTextZoom((int) (_appSettings.getDocumentViewFontSize(_document.path) * VIEW_FONT_SCALE)); | ||
| webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); | ||
| webSettings.setDatabaseEnabled(true); | ||
| webSettings.setGeolocationEnabled(false); | ||
| webSettings.setJavaScriptEnabled(true); | ||
| webSettings.setDomStorageEnabled(true); | ||
| webSettings.setAllowFileAccess(true); | ||
| webSettings.setAllowContentAccess(true); | ||
| webSettings.setAllowFileAccessFromFileURLs(true); | ||
| webSettings.setAllowUniversalAccessFromFileURLs(false); | ||
| webSettings.setMediaPlaybackRequiresUserGesture(false); | ||
|
|
||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && BuildConfig.IS_TEST_BUILD && BuildConfig.DEBUG) { | ||
| WebView.setWebContentsDebuggingEnabled(true); // Inspect on computer chromium browser: chrome://inspect/#devices | ||
| } | ||
|
|
||
| _webViewClient = new MarkorWebViewClient(_webView, activity); | ||
| _webView.setWebViewClient(_webViewClient); | ||
| } | ||
| } | ||
|
|
||
| @SuppressLint({"AddJavascriptInterface", "SetJavaScriptEnabled"}) | ||
| public void setViewModeVisibility(boolean show, final boolean animate) { | ||
| final Activity activity = getActivity(); | ||
| if (activity == null) { | ||
|
|
@@ -887,13 +908,16 @@ public void setViewModeVisibility(boolean show, final boolean animate) { | |
| _format.getActions().recreateActionButtons(_textActionsBar, show ? ActionButtonBase.ActionItem.DisplayMode.VIEW : ActionButtonBase.ActionItem.DisplayMode.EDIT); | ||
| showHideActionBar(); | ||
| if (show) { | ||
| setupWebViewIfNeeded(activity); | ||
| updateViewModeText(); | ||
| _cu.showSoftKeyboard(activity, false, _hlEditor); | ||
| _hlEditor.clearFocus(); | ||
| _hlEditor.postDelayed(() -> _cu.showSoftKeyboard(activity, false, _hlEditor), 300); | ||
| GsContextUtils.fadeInOut(_webView, _verticalScrollView, animate); | ||
| } else { | ||
| _webViewClient.setRestoreScrollY(_webView.getScrollY()); | ||
| if (_webView != null) { | ||
| _webViewClient.setRestoreScrollY(_webView.getScrollY()); | ||
| } | ||
| GsContextUtils.fadeInOut(_verticalScrollView, _webView, animate); | ||
| } | ||
|
|
||
|
|
@@ -932,10 +956,12 @@ protected boolean onToolbarLongClicked(View v) { | |
|
|
||
| @Override | ||
| public void onDestroy() { | ||
| try { | ||
| _webView.loadUrl("about:blank"); | ||
| _webView.destroy(); | ||
| } catch (Exception ignored) { | ||
| if (_webView != null) { | ||
| try { | ||
| _webView.loadUrl("about:blank"); | ||
| _webView.destroy(); | ||
| } catch (Exception ignored) { | ||
| } | ||
| } | ||
| super.onDestroy(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bugfix to how the start line and start in preview interact