|
18 | 18 | import android.text.Layout;
|
19 | 19 | import android.text.TextWatcher;
|
20 | 20 | import android.util.AttributeSet;
|
| 21 | +import android.util.Log; |
21 | 22 | import android.view.KeyEvent;
|
22 | 23 | import android.view.View;
|
23 | 24 | import android.view.ViewTreeObserver;
|
24 | 25 | import android.view.accessibility.AccessibilityEvent;
|
| 26 | +import android.widget.Toast; |
25 | 27 |
|
26 | 28 | import androidx.annotation.NonNull;
|
27 | 29 | import androidx.annotation.RequiresApi;
|
|
37 | 39 |
|
38 | 40 | import java.util.Objects;
|
39 | 41 | import java.util.concurrent.ExecutorService;
|
| 42 | +import java.util.concurrent.RejectedExecutionException; |
40 | 43 | import java.util.concurrent.SynchronousQueue;
|
41 | 44 | import java.util.concurrent.ThreadPoolExecutor;
|
42 | 45 | import java.util.concurrent.TimeUnit;
|
@@ -118,6 +121,13 @@ public boolean onPreDraw() {
|
118 | 121 | @Override
|
119 | 122 | protected void onDraw(Canvas canvas) {
|
120 | 123 | super.onDraw(canvas);
|
| 124 | + try { |
| 125 | + super.onDraw(canvas); |
| 126 | + } catch (Exception e) { |
| 127 | + // Hinder drawing from crashing the app |
| 128 | + Log.e(getClass().getName(), "HighlightingEdtior onDraw->super.onDraw crash" + e); |
| 129 | + Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show(); |
| 130 | + } |
121 | 131 | }
|
122 | 132 |
|
123 | 133 | // Highlighting
|
@@ -173,7 +183,10 @@ public void recomputeHighlighting() {
|
173 | 183 | */
|
174 | 184 | private void recomputeHighlightingAsync() {
|
175 | 185 | if (runHighlight(true)) {
|
176 |
| - executor.execute(this::_recomputeHighlightingWorker); |
| 186 | + try { |
| 187 | + executor.execute(this::_recomputeHighlightingWorker); |
| 188 | + } catch (RejectedExecutionException ignored) { |
| 189 | + } |
177 | 190 | }
|
178 | 191 | }
|
179 | 192 |
|
@@ -262,14 +275,12 @@ public boolean bringPointIntoView(int i) {
|
262 | 275 |
|
263 | 276 | private int rowStart(final int y) {
|
264 | 277 | final Layout layout = getLayout();
|
265 |
| - final int line = layout.getLineForVertical(y); |
266 |
| - return layout.getLineStart(line); |
| 278 | + return layout == null ? 0 : layout.getLineStart(layout.getLineForVertical(y)); |
267 | 279 | }
|
268 | 280 |
|
269 | 281 | private int rowEnd(final int y) {
|
270 | 282 | final Layout layout = getLayout();
|
271 |
| - final int line = layout.getLineForVertical(y); |
272 |
| - return layout.getLineEnd(line); |
| 283 | + return layout == null ? 0 : layout.getLineEnd(layout.getLineForVertical(y)); |
273 | 284 | }
|
274 | 285 |
|
275 | 286 | // Text-Casing
|
@@ -371,7 +382,12 @@ public boolean onTextContextMenuItem(int id) {
|
371 | 382 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && id == android.R.id.paste) {
|
372 | 383 | id = android.R.id.pasteAsPlainText;
|
373 | 384 | }
|
374 |
| - return super.onTextContextMenuItem(id); |
| 385 | + try { |
| 386 | + // i.e. DeadSystemRuntimeException can happen here |
| 387 | + return super.onTextContextMenuItem(id); |
| 388 | + } catch (Exception ignored) { |
| 389 | + return true; |
| 390 | + } |
375 | 391 | }
|
376 | 392 |
|
377 | 393 | // Accessibility code is blocked during rapid update events
|
|
0 commit comments