<NME> AnchorAwareLinkMovementMethod.java
<BEF> package cgeo.geocaching.ui;

import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.view.MotionEvent;
import android.widget.TextView;

/**

import androidx.annotation.NonNull;

/**
 * {@code LinkMovementMethod} with built-in suppression of errors for links, where the URL cannot be handled
 * correctly by Android.
 */
public class AnchorAwareLinkMovementMethod extends LinkMovementMethod {

    private AnchorAwareLinkMovementMethod() {
        // singleton
    }

    private static final class Holder {
        // initialization on demand holder
        private static final AnchorAwareLinkMovementMethod INSTANCE = new AnchorAwareLinkMovementMethod();
    }

    public static AnchorAwareLinkMovementMethod getInstance() {
    @Override
    public boolean onTouchEvent(final TextView widget, final Spannable buffer, final MotionEvent event) {
        try {
            return super.onTouchEvent(widget, buffer, event);
        } catch (final Exception ignored) {
            // local links to anchors don't work
        }
        return false;
    }
}
                Selection.setSelection(text, text.length());
            }
        } else {
            Selection.setSelection(text, text.length());
        }
    }

    @Override
    public boolean canSelectArbitrarily() {
        return true;
    }
}

<MSG> fix #5490: fix selection for LinkMovement enabled TextView

<DFF> @@ -1,8 +1,14 @@
 package cgeo.geocaching.ui;
 
+import android.support.annotation.NonNull;
+import android.text.Layout;
+import android.text.Selection;
 import android.text.Spannable;
 import android.text.method.LinkMovementMethod;
+import android.text.method.Touch;
+import android.text.style.ClickableSpan;
 import android.view.MotionEvent;
+import android.view.View;
 import android.widget.TextView;
 
 /**
@@ -28,10 +34,53 @@ public class AnchorAwareLinkMovementMethod extends LinkMovementMethod {
     @Override
     public boolean onTouchEvent(final TextView widget, final Spannable buffer, final MotionEvent event) {
         try {
-            return super.onTouchEvent(widget, buffer, event);
+            final int action = event.getAction();
+
+            if (action == MotionEvent.ACTION_UP ||
+                    action == MotionEvent.ACTION_DOWN) {
+                int x = (int) event.getX();
+                int y = (int) event.getY();
+
+                x -= widget.getTotalPaddingLeft();
+                y -= widget.getTotalPaddingTop();
+
+                x += widget.getScrollX();
+                y += widget.getScrollY();
+
+                final Layout layout = widget.getLayout();
+                final int line = layout.getLineForVertical(y);
+                final int off = layout.getOffsetForHorizontal(line, x);
+
+                final ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
+
+                if (link.length != 0) {
+                    if (action == MotionEvent.ACTION_UP) {
+                        link[0].onClick(widget);
+                    } else {
+                        Selection.setSelection(buffer,
+                                buffer.getSpanStart(link[0]),
+                                buffer.getSpanEnd(link[0]));
+                    }
+                    return true;
+                }
+            }
+
+            return Touch.onTouchEvent(widget, buffer, event);
         } catch (final Exception ignored) {
             // local links to anchors don't work
         }
         return false;
     }
+
+    @Override
+    public void onTakeFocus(TextView view, @NonNull Spannable text, int dir) {
+        if ((dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0) {
+            if (view.getLayout() == null) {
+                // This shouldn't be null, but do something sensible if it is.
+                Selection.setSelection(text, text.length());
+            }
+        } else {
+            Selection.setSelection(text, text.length());
+        }
+    }
 }

fix #5490: fix selection for LinkMovement enabled TextView