1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2025-01-08 12:18:07 -05:00

Make everything clickable in messages (links, email addresses, telephone numbers).

This commit is contained in:
Sebastian Kaspari 2012-01-21 08:57:28 +01:00
parent e04499070a
commit ec90fe3db6

View File

@ -33,11 +33,12 @@ import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan; import android.text.style.ImageSpan;
import android.text.util.Linkify;
import android.widget.TextView; import android.widget.TextView;
/** /**
* A channel or server message * A channel or server message
* *
* @author Sebastian Kaspari <sebastian@yaaic.org> * @author Sebastian Kaspari <sebastian@yaaic.org>
*/ */
public class Message public class Message
@ -91,7 +92,7 @@ public class Message
/** /**
* Create a new message without an icon defaulting to TYPE_MESSAGE * Create a new message without an icon defaulting to TYPE_MESSAGE
* *
* @param text * @param text
*/ */
public Message(String text) public Message(String text)
@ -101,7 +102,7 @@ public class Message
/** /**
* Create a new message without an icon with a specific type * Create a new message without an icon with a specific type
* *
* @param text * @param text
* @param type Message type * @param type Message type
*/ */
@ -113,7 +114,7 @@ public class Message
/** /**
* Create a new message sent by a user, without an icon, * Create a new message sent by a user, without an icon,
* defaulting to TYPE_MESSAGE * defaulting to TYPE_MESSAGE
* *
* @param text * @param text
* @param sender * @param sender
*/ */
@ -147,7 +148,7 @@ public class Message
/** /**
* Get the message's icon * Get the message's icon
* *
* @return * @return
*/ */
public int getIcon() public int getIcon()
@ -157,7 +158,7 @@ public class Message
/** /**
* Get the text of this message * Get the text of this message
* *
* @return * @return
*/ */
public String getText() public String getText()
@ -167,7 +168,7 @@ public class Message
/** /**
* Get the type of this message * Get the type of this message
* *
* @return One of Message.TYPE_* * @return One of Message.TYPE_*
*/ */
public int getType() public int getType()
@ -219,7 +220,7 @@ public class Message
/** /**
* Render message as spannable string * Render message as spannable string
* *
* @return * @return
*/ */
public SpannableString render(Context context) public SpannableString render(Context context)
@ -323,6 +324,10 @@ public class Message
TextView canvas = new TextView(context); TextView canvas = new TextView(context);
canvas.setAutoLinkMask(Linkify.ALL);
canvas.setLinksClickable(true);
canvas.setLinkTextColor(COLOR_BLUE);
canvas.setText(this.render(context)); canvas.setText(this.render(context));
canvas.setTextSize(settings.getFontSize()); canvas.setTextSize(settings.getFontSize());
canvas.setTypeface(Typeface.MONOSPACE); canvas.setTypeface(Typeface.MONOSPACE);
@ -333,7 +338,7 @@ public class Message
/** /**
* Generate a timestamp * Generate a timestamp
* *
* @param use24hFormat * @param use24hFormat
* @return * @return
*/ */