Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@
android:theme="@style/AppTheme.Unified.StartupFlash"
android:windowSoftInputMode="stateUnchanged|adjustResize"
tools:targetApi="lollipop">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="net.gsantner.markor.activity.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="com.google.android.gm.action.AUTO_SEND" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static void launch(

intent.putExtra(Document.EXTRA_FILE, file);

GsContextUtils.instance.animateToActivity(activity, intent, false, null);
activity.startActivity(intent);
}

public static void askUserIfWantsToOpenFileInThisApp(final Activity activity, final File file) {
Expand Down Expand Up @@ -183,22 +183,23 @@ private void handleLaunchingIntent(final Intent intent) {
if (file == null || !_cu.canWriteFile(this, file, false, true)) {
showNotSupportedMessage();
} else {
Integer startLine = null;
// Open in editor/viewer
final Document doc = new Document(file);
Integer startLine = null;
if (intent.hasExtra(Document.EXTRA_FILE_LINE_NUMBER)) {
startLine = intent.getIntExtra(Document.EXTRA_FILE_LINE_NUMBER, -1);
} else if (intentData != null) {
final String line = intentData.getQueryParameter("line");
startLine = GsTextUtils.tryParseInt(line, -1);
Copy link
Collaborator Author

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

if (line != null) {
startLine = GsTextUtils.tryParseInt(line, -1);
}
}

// Start in a specific mode if required. Otherwise let the fragment decide
Boolean startInPreview = null;
if (startLine != null) {
// If a line is requested, open in edit mode so the line is shown
startInPreview = false;
} else if (intent.getBooleanExtra(Document.EXTRA_DO_PREVIEW, false) || file.getName().startsWith("index.")) {
if (intent.getBooleanExtra(Document.EXTRA_DO_PREVIEW, false) ||
file.getName().startsWith("index.")
) {
startInPreview = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,6 +95,7 @@ public static DocumentEditAndViewFragment newInstance(final @NonNull Document do

private HighlightingEditor _hlEditor;
private WebView _webView;
private ViewStub _webViewStub;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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;
Expand Down Expand Up @@ -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);
Expand All @@ -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()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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()));
Expand Down Expand Up @@ -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());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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);
Expand All @@ -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]);
Expand Down Expand Up @@ -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;
}
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -667,7 +653,6 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
}
}
}

public void checkTextChangeState() {
final boolean isTextChanged = !_document.isContentSame(_hlEditor.getText());
Drawable d;
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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());
Expand All @@ -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) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
}
Expand Down
Loading