Skip to content

Commit

Permalink
Fix lots of minor issues and crashes in v2.13.0, by @gsantner
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Nov 15, 2024
1 parent aab47c7 commit 87e1cfb
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;

Expand Down Expand Up @@ -95,8 +96,8 @@ private static void launch(
intent = new Intent(activity, DocumentActivity.class);

if (!(activity instanceof DocumentActivity) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
as.isMultiWindowEnabled()
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
as.isMultiWindowEnabled()
) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
}
Expand Down Expand Up @@ -254,7 +255,8 @@ public boolean dispatchTouchEvent(MotionEvent event) {
}
try {
return super.dispatchTouchEvent(event);
} catch (IndexOutOfBoundsException ignored) {
} catch (Exception e) {
Log.e(getClass().getName(), "Error in super.dispatchTouchEvent: " + e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private String formatShare(final String shared) {
}

// Put the shared text in the right place
parts.add(1, shared);
parts.add(parts.isEmpty() ? 0 : 1, shared);

return TextUtils.join("", parts);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import android.text.Layout;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
Expand All @@ -37,6 +39,7 @@

import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -121,7 +124,13 @@ public boolean onPreDraw() {

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
try {
super.onDraw(canvas);
} catch (Exception e) {
// Hinder drawing from crashing the app
Log.e(getClass().getName(), "HighlightingEdtior onDraw->super.onDraw crash" + e);
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show();
}

if (_numEnabled) {
_lineNumbersDrawer.draw(canvas);
Expand Down Expand Up @@ -181,7 +190,10 @@ public void recomputeHighlighting() {
*/
private void recomputeHighlightingAsync() {
if (runHighlight(true)) {
executor.execute(this::_recomputeHighlightingWorker);
try {
executor.execute(this::_recomputeHighlightingWorker);
} catch (RejectedExecutionException ignored) {
}
}
}

Expand Down Expand Up @@ -289,14 +301,12 @@ public boolean bringPointIntoView(int i) {

private int rowStart(final int y) {
final Layout layout = getLayout();
final int line = layout.getLineForVertical(y);
return layout.getLineStart(line);
return layout == null ? 0 : layout.getLineStart(layout.getLineForVertical(y));
}

private int rowEnd(final int y) {
final Layout layout = getLayout();
final int line = layout.getLineForVertical(y);
return layout.getLineEnd(line);
return layout == null ? 0 : layout.getLineEnd(layout.getLineForVertical(y));
}

// Text-Casing
Expand Down Expand Up @@ -398,7 +408,12 @@ public boolean onTextContextMenuItem(int id) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && id == android.R.id.paste) {
id = android.R.id.pasteAsPlainText;
}
return super.onTextContextMenuItem(id);
try {
// i.e. DeadSystemRuntimeException can happen here
return super.onTextContextMenuItem(id);
} catch (Exception ignored) {
return true;
}
}

// Accessibility code is blocked during rapid update events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ public boolean isExperimentalFeaturesEnabled() {
}

public boolean isHighlightBiggerHeadings() {
return getBool(R.string.pref_key__editor_markdown_bigger_headings_2, false);
return getBool(R.string.pref_key__editor_markdown_bigger_headings_3, false);
}

public String getViewModeLinkColor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Map<File, File> getVirtualFolders() {
}

for (final File file : ContextCompat.getExternalFilesDirs(_context, null)) {
if (file == null || file.getParentFile() == null) {
if (file == null || (file != null && file.getParentFile() == null)) {
continue;
}
final File remap = new File(VIRTUAL_STORAGE_ROOT, "AppData (" + file.getParentFile().toString().replace("/", "-").substring(1) + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public void onClick(View v) {
import android.text.Selection;
import android.text.TextWatcher;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import net.gsantner.markor.frontend.textview.TextViewUtils;

Expand Down Expand Up @@ -150,8 +152,10 @@ public void undo() {
mIsUndoOrRedo = true;
try {
text.replace(start, end, edit.before);
} catch (Exception ex){
} catch (Exception ex) {
// In case a undo would crash the app, don't do it instead
Log.e(getClass().getName(), "undo() Error in text.replace" + ex);
Toast.makeText(mTextView.getContext(), "undo() Error in text.replace" + ex, Toast.LENGTH_LONG).show();
return;
}
mIsUndoOrRedo = false;
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ public void extractResultFromActivityResult(final Activity context, final int re
if (resultCode == Activity.RESULT_OK && intent != null && intent.getData() != null) {
final Uri uri = intent.getData();
final String uriPath = uri.getPath();
final String ext = uriPath.substring(uriPath.lastIndexOf("."));
final String ext = uriPath == null || !uriPath.contains(".") ? "" : uriPath.substring(uriPath.lastIndexOf("."));
final String datestr = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss", Locale.ENGLISH).format(new Date());
final File temp = new File(context.getCacheDir(), datestr + ext);
GsFileUtils.copyUriToFile(context, uri, temp);
Expand Down Expand Up @@ -2743,12 +2743,12 @@ public void dialogFullWidth(AlertDialog dialog, boolean fullWidth, boolean showK
}

public static void windowAspectRatio(
final Window window,
final DisplayMetrics displayMetrics,
float portraitWidthRatio,
float portraitHeightRatio,
float landscapeWidthRatio,
float landscapeHeightRatio
final Window window,
final DisplayMetrics displayMetrics,
float portraitWidthRatio,
float portraitHeightRatio,
float landscapeWidthRatio,
float landscapeHeightRatio
) {
if (window == null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/string-not_translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pref_key__editor_disable_spelling_red_underline" translatable="false">pref_key__editor_disable_spelling_red_underline</string>
<string name="pref_key__highlight_code_monospace_font" translatable="false">pref_key__highlight_code_monospace_font</string>
<string name="pref_key__highlight_code_block_disabled" translatable="false">pref_key__highlight_code_block_disabled</string>
<string name="pref_key__editor_markdown_bigger_headings_2" translatable="false">pref_key__editor_markdown_bigger_headings_2</string>
<string name="pref_key__editor_markdown_bigger_headings_3" translatable="false">pref_key__editor_markdown_bigger_headings_3</string>
<string name="pref_key__editor_unordered_list_character" translatable="false">pref_key__editor_unordered_list_character</string>
<string name="pref_key__recent_documents" translatable="false">pref_key__recent_documents</string>
<string name="pref_key__popular_documents" translatable="false">pref_key__popular_documents</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/preferences_master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_format_size_black_24dp"
android:key="@string/pref_key__editor_markdown_bigger_headings_2"
android:key="@string/pref_key__editor_markdown_bigger_headings_3"
android:summary="@string/increase_text_size_of_headings_according_to_level"
android:title="@string/bigger_headings" />
</PreferenceCategory>
Expand Down

0 comments on commit 87e1cfb

Please sign in to comment.