Skip to content

Commit

Permalink
Linkify text before working around balloon height bug (closes #56)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Apr 4, 2013
1 parent f03a275 commit 2af3dda
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
4 changes: 1 addition & 3 deletions res/layout-xlarge/message_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@
android:paddingRight="5dip"
android:maxWidth="@dimen/message_text_width"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:linksClickable="true"/>
android:layout_height="wrap_content"/>

</LinearLayout>

Expand Down
4 changes: 1 addition & 3 deletions res/layout/message_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
android:paddingRight="5dip"
android:maxWidth="@dimen/message_text_width"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:linksClickable="true"/>
android:layout_height="wrap_content"/>

</LinearLayout>

Expand Down
34 changes: 23 additions & 11 deletions src/org/kontalk/xmpp/ui/MessageListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.BackgroundColorSpan;
import android.text.style.ImageSpan;
import android.text.util.Linkify;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
Expand All @@ -60,7 +62,7 @@ public class MessageListItem extends RelativeLayout {
static private Drawable sDefaultContactImage;

private AbstractMessage<?> mMessage;
private CharSequence formattedMessage;
private SpannableStringBuilder formattedMessage;
private TextView mTextView;
private ImageView mStatusIcon;
private ImageView mLockView;
Expand Down Expand Up @@ -174,6 +176,25 @@ else if (size.equals("large"))
else
sizeId = android.R.style.TextAppearance;
mTextView.setTextAppearance(context, sizeId);

// linkify!
boolean linksFound = Linkify.addLinks(formattedMessage, Linkify.ALL);

/*
* workaround for bugs:
* http://code.google.com/p/android/issues/detail?id=17343
* http://code.google.com/p/android/issues/detail?id=22493
* applies only to ICS
*/
if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH ||
android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
formattedMessage.append("\u2060");

if (linksFound)
mTextView.setMovementMethod(LinkMovementMethod.getInstance());
else
mTextView.setMovementMethod(null);

mTextView.setText(formattedMessage);

int resId = 0;
Expand Down Expand Up @@ -281,7 +302,7 @@ public Drawable getDrawable() {
}
}

private CharSequence formatMessage(final Contact contact, final Pattern highlight) {
private SpannableStringBuilder formatMessage(final Contact contact, final Pattern highlight) {
SpannableStringBuilder buf;
String textContent;
try {
Expand Down Expand Up @@ -341,15 +362,6 @@ private CharSequence formatMessage(final Contact contact, final Pattern highligh
buf.setSpan(mHighlightColorSpan, m.start(), m.end(), 0);
}

/*
* workaround for bugs:
* http://code.google.com/p/android/issues/detail?id=17343
* http://code.google.com/p/android/issues/detail?id=22493
* applies only to ICS
*/
if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH ||
android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
buf.append("\u2060");
return buf;
}

Expand Down

0 comments on commit 2af3dda

Please sign in to comment.