Dbrant has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/360362 )

Change subject: Fix possible crash when highlighting text on API 23.
......................................................................

Fix possible crash when highlighting text on API 23.

https://rink.hockeyapp.net/manage/apps/226649/app_versions/204/crash_reasons/173095781

This occurs only on Android 6.0 (API 23):
To reproduce:
Find any TextView that has text selection enabled, and that has a
LinkMovementMethod associated with it. Then long-press to select some text
inside it, and then click away from the selection (on another part of the
same TextView). It crashes with an IllegalArgumentException.

This workaround patches the internals of the TextView itself. We already
have a "custom" patched TextView component, which is AppTextView, so we
can apply the fix there, and just switch all instances of TextViews that
have selection enabled to become AppTextViews.

Change-Id: If2f24c4cd3a799c5ecd2e32d29372ba9b2c1fd83
---
M app/src/main/java/org/wikipedia/views/AppTextView.java
M app/src/main/res/layout/activity_about.xml
M app/src/main/res/layout/activity_gallery.xml
M app/src/main/res/layout/dialog_reference.xml
M app/src/main/res/layout/fragment_page_bottom_content.xml
M app/src/main/res/layout/item_wiktionary_definition_with_examples.xml
6 files changed, 28 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/62/360362/1

diff --git a/app/src/main/java/org/wikipedia/views/AppTextView.java 
b/app/src/main/java/org/wikipedia/views/AppTextView.java
index 229cf49..014ca94 100644
--- a/app/src/main/java/org/wikipedia/views/AppTextView.java
+++ b/app/src/main/java/org/wikipedia/views/AppTextView.java
@@ -1,7 +1,9 @@
 package org.wikipedia.views;
 
 import android.content.Context;
+import android.os.Build;
 import android.util.AttributeSet;
+import android.view.MotionEvent;
 
 public class AppTextView extends ConfigurableTextView {
 
@@ -18,6 +20,21 @@
     }
 
     @Override
+    public boolean dispatchTouchEvent(MotionEvent event) {
+        // Workaround for 
https://code.google.com/p/android/issues/detail?id=191430
+        // which only occurs on API 23
+        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
+            if (event.getActionMasked() == MotionEvent.ACTION_DOWN
+                    && getSelectionStart() != getSelectionEnd()) {
+                CharSequence text = getText();
+                setText(null);
+                setText(text);
+            }
+        }
+        return super.dispatchTouchEvent(event);
+    }
+
+    @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
         remeasureForLineSpacing();
diff --git a/app/src/main/res/layout/activity_about.xml 
b/app/src/main/res/layout/activity_about.xml
index 377e8db..4edf976 100644
--- a/app/src/main/res/layout/activity_about.xml
+++ b/app/src/main/res/layout/activity_about.xml
@@ -56,7 +56,7 @@
                 android:layout_marginBottom="8dp"
                 style="?android:textAppearanceSmall"
                 android:text="@string/about_contributors_heading" />
-        <TextView
+        <org.wikipedia.views.AppTextView
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layoutDirection="ltr"
@@ -75,7 +75,7 @@
                 android:layout_marginBottom="8dp"
                 style="?android:textAppearanceSmall"
                 android:text="@string/about_translators_heading" />
-        <TextView
+        <org.wikipedia.views.AppTextView
                 android:id="@+id/about_translators"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -96,7 +96,7 @@
                 android:text="@string/about_libraries_heading"
                 android:layout_marginTop="8dp"
                 android:layout_marginBottom="8dp" />
-        <TextView
+        <org.wikipedia.views.AppTextView
                 android:id="@+id/activity_about_libraries"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -117,7 +117,7 @@
                 android:text="@string/about_app_license_heading"
                 android:layout_marginTop="8dp"
                 android:layout_marginBottom="8dp" />
-        <TextView
+        <org.wikipedia.views.AppTextView
                 android:id="@+id/about_app_license"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -159,7 +159,7 @@
             android:tint="@color/dark_gray"
             android:contentDescription="@null" />
 
-        <TextView
+        <org.wikipedia.views.AppTextView
             android:id="@+id/about_wmf"
             android:layout_width="wrap_content"
             android:layout_height="0dp"
diff --git a/app/src/main/res/layout/activity_gallery.xml 
b/app/src/main/res/layout/activity_gallery.xml
index 86ffd14..8b71ea5 100644
--- a/app/src/main/res/layout/activity_gallery.xml
+++ b/app/src/main/res/layout/activity_gallery.xml
@@ -47,7 +47,7 @@
         android:orientation="vertical"
         android:paddingBottom="32dp"
         android:paddingTop="64dp">
-        <TextView
+        <org.wikipedia.views.AppTextView
             android:id="@+id/gallery_description_text"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
@@ -77,7 +77,7 @@
                 android:background="?attr/selectableItemBackgroundBorderless"
                 tools:src="@drawable/ic_license_cc"
                 android:contentDescription="@null"/>
-            <TextView
+            <org.wikipedia.views.AppTextView
                 android:id="@+id/gallery_credit_text"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
diff --git a/app/src/main/res/layout/dialog_reference.xml 
b/app/src/main/res/layout/dialog_reference.xml
index 0bb3c53..a694c91 100644
--- a/app/src/main/res/layout/dialog_reference.xml
+++ b/app/src/main/res/layout/dialog_reference.xml
@@ -9,7 +9,7 @@
 
     <View android:layout_width="match_parent" android:layout_height="0.5dp" 
android:background="@color/nav_border" />
 
-    <TextView
+    <org.wikipedia.views.AppTextView
         android:id="@+id/reference_text"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
diff --git a/app/src/main/res/layout/fragment_page_bottom_content.xml 
b/app/src/main/res/layout/fragment_page_bottom_content.xml
index a3dc6ff..adc937d 100644
--- a/app/src/main/res/layout/fragment_page_bottom_content.xml
+++ b/app/src/main/res/layout/fragment_page_bottom_content.xml
@@ -21,7 +21,7 @@
         android:text="@string/page_view_in_browser"
         android:textColor="?attr/link_color"
         android:gravity="center"/>
-    <TextView
+    <org.wikipedia.views.AppTextView
         android:id="@+id/page_last_updated_text"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
@@ -32,7 +32,7 @@
         style="?android:textAppearanceSmall"
         android:textIsSelectable="true"
         android:textColorLink="?attr/link_color"/>
-    <TextView
+    <org.wikipedia.views.AppTextView
         android:id="@+id/page_license_text"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
diff --git 
a/app/src/main/res/layout/item_wiktionary_definition_with_examples.xml 
b/app/src/main/res/layout/item_wiktionary_definition_with_examples.xml
index 0173cff..4b54bbe 100644
--- a/app/src/main/res/layout/item_wiktionary_definition_with_examples.xml
+++ b/app/src/main/res/layout/item_wiktionary_definition_with_examples.xml
@@ -13,6 +13,7 @@
         android:lineSpacingMultiplier="1.3"
         android:layout_marginTop="4dp"
         android:layout_marginBottom="4dp"
+        android:textIsSelectable="true"
         android:linksClickable="true" />
 
     <LinearLayout

-- 
To view, visit https://gerrit.wikimedia.org/r/360362
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If2f24c4cd3a799c5ecd2e32d29372ba9b2c1fd83
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to