package yuku.alkitab.base.widget;

import android.content.Context;
import android.os.Build;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * From https://stackoverflow.com/questions/33821008/illegalargumentexception-while-selecting-text-in-android-textview
 */
public class FixedTextView extends AppCompatTextView {
	public FixedTextView(final Context context) {
		super(context);
	}

	public FixedTextView(final Context context, final AttributeSet attrs) {
		super(context, attrs);
	}

	public FixedTextView(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		if (Build.VERSION.SDK_INT >= 24) {
			// passthrough
			return super.dispatchTouchEvent(event);
		}

		// simple workaround to https://code.google.com/p/android/issues/detail?id=191430
		int startSelection = getSelectionStart();
		int endSelection = getSelectionEnd();
		if (startSelection != endSelection) {
			if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
				final CharSequence text = getText();
				setText(null);
				setText(text);
			}
		}
		return super.dispatchTouchEvent(event);
	}
}

@@ -203,16 +203,54 @@
 onEvent;
+%0Aimport yuku.alkitab.base.util.AppLog;
 %0A%0A/**%0A *
@@ -425,16 +425,81 @@
 tView %7B%0A
+%09static final String TAG = FixedTextView.class.getSimpleName();%0A%0A
 %09public 
@@ -922,47 +922,191 @@
 %0A%09%09%09
-return super.dispatchTouchEvent(event);
+// but can still actually throws error.%0A%09%09%09try %7B%0A%09%09%09%09return super.dispatchTouchEvent(event);%0A%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09AppLog.e(TAG, %22Still error in dispatchTouchEvent%22, e);%0A%09%09%09%7D
 %0A%09%09%7D

Add catch on FixedTextView to catch common errors (still)