Commits

Vincent Schüßler committed 5db1352

Fix #104: Implement workaround for JB TextView bug

Comments (0)

Files changed (4)

res/layout/view_episode.xml

                 android:layout_marginBottom="@dimen/padding_medium"
                 android:textColor="?android:attr/textColorSecondary" />
 
-            <TextView
+            <net.x4a42.volksempfaenger.ui.PatchedTextView
                 android:id="@+id/episode_description"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:textColor="@color/episode_description_text"
                 android:textColorHighlight="@color/episode_description_text"
-                android:textColorLink="@color/episode_description_link" >
-            </TextView>
+                android:textColorLink="@color/episode_description_link" />
         </LinearLayout>
     </ScrollView>
 

src/net/x4a42/volksempfaenger/ui/AddSubscriptionActivity.java

 		if (v.getId() == R.id.entry_search) {
 			if (hasFocus) {
 				showButton();
-				searchEntry.showDropDown();
+				if (!isFinishing()) {
+					searchEntry.showDropDown();
+				}
 			} else {
 				hideButton();
 			}

src/net/x4a42/volksempfaenger/ui/PatchedTextView.java

+package net.x4a42.volksempfaenger.ui;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.TextView;
+
+// From https://code.google.com/p/android/issues/detail?id=35466#c4
+public class PatchedTextView extends TextView {
+
+	public PatchedTextView(Context context, AttributeSet attrs, int defStyle) {
+		super(context, attrs, defStyle);
+	}
+
+	public PatchedTextView(Context context, AttributeSet attrs) {
+		super(context, attrs);
+	}
+
+	public PatchedTextView(Context context) {
+		super(context);
+	}
+
+	@Override
+	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+		try {
+			super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+		} catch (IndexOutOfBoundsException e) {
+			setText(getText().toString());
+			super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+		}
+	}
+
+	@Override
+	public void setGravity(int gravity) {
+		try {
+			super.setGravity(gravity);
+		} catch (IndexOutOfBoundsException e) {
+			setText(getText().toString());
+			super.setGravity(gravity);
+		}
+	}
+
+	@Override
+	public void setText(CharSequence text, BufferType type) {
+		try {
+			super.setText(text, type);
+		} catch (IndexOutOfBoundsException e) {
+			setText(text.toString());
+		}
+	}
+
+}

src/net/x4a42/volksempfaenger/ui/ViewEpisodeActivity.java

 import android.content.ServiceConnection;
 import android.database.Cursor;
 import android.graphics.Bitmap;
-import android.graphics.Typeface;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 				descriptionSpanned.setSpan(newImg, start, end,
 						Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 				// explicitly update description
-				setDescription(descriptionSpanned);
+				episodeDescription.setText(descriptionSpanned);
 			}
 		}
 
 		if (descriptionSpanned.getSpans(0, descriptionSpanned.length(),
 				CharacterStyle.class).length == 0) {
 			// use the normal text as there is no html
-			setDescription(episodeCursor.getDescription());
+			episodeDescription.setText(episodeCursor.getDescription());
 		} else {
-			setDescription(descriptionSpanned);
+			episodeDescription.setText(descriptionSpanned);
 			lastImageLoadTask = new ImageLoadTask()
 					.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
 		}
 		invalidateOptionsMenu();
 	}
 
-	private void setDescription(CharSequence description) {
-		try {
-			episodeDescription.setText(description);
-		} catch (IndexOutOfBoundsException e) {
-			// workaround for JB
-			// https://code.google.com/p/android/issues/detail?id=36088
-			episodeDescription.setText(null);
-			episodeDescription.setText(getString(R.string.error_shownotes));
-			episodeDescription.setTypeface(null, Typeface.ITALIC);
-		}
-	}
-
 }