aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2015-01-03 21:31:56 +0100
committerlookshe <github@lookshe.org>2015-01-03 21:31:56 +0100
commit48717dd7d37c066ab626fc626a2ced626ef21d42 (patch)
treedd953348682f45cde0d812d28b352145fcde8b0e /src
parent6e3e58e3c85e049338fa5b5eff2e99545e15920c (diff)
remaining part of my patch
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java1
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java5
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java5
-rw-r--r--src/main/java/eu/siacs/conversations/utils/UIHelper.java102
4 files changed, 106 insertions, 7 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index 7af29451..8b46335a 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -19,6 +19,7 @@ public final class Config {
public static final int MESSAGE_MERGE_WINDOW = 20;
public static final boolean PARSE_EMOTICONS = false;
+ public static final boolean UTF8_EMOTICONS = false;
public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
public static final boolean NO_PROXY_LOOKUP = false; //useful to debug ibb
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
index b81544e6..c5ee9ba6 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
@@ -139,10 +139,9 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
} else {
if ((message.getEncryption() != Message.ENCRYPTION_PGP)
&& (message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
- String body = Config.PARSE_EMOTICONS ? UIHelper
+ mLastMessage.setText(Config.PARSE_EMOTICONS ? UIHelper
.transformAsciiEmoticons(message.getBody()) : message
- .getBody();
- mLastMessage.setText(body);
+ .getBody());
} else {
mLastMessage.setText(R.string.encrypted_message_received);
}
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 60046468..00000e2b 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -225,10 +225,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setVisibility(View.VISIBLE);
if (message.getBody() != null) {
if (message.getType() != Message.TYPE_PRIVATE) {
- String body = Config.PARSE_EMOTICONS ? UIHelper
+ viewHolder.messageBody.setText(Config.PARSE_EMOTICONS ? UIHelper
.transformAsciiEmoticons(message.getMergedBody())
- : message.getMergedBody();
- viewHolder.messageBody.setText(body);
+ : message.getMergedBody());
} else {
String privateMarker;
if (message.getStatus() <= Message.STATUS_RECEIVED) {
diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java
index 28a2bb4c..b4f28c45 100644
--- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java
@@ -1,13 +1,24 @@
package eu.siacs.conversations.utils;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import android.content.Context;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
+import android.text.Spannable.Factory;
+import android.text.style.ImageSpan;
+import android.text.Spannable;
public class UIHelper {
private static final int SHORT_DATE_FLAGS = DateUtils.FORMAT_SHOW_DATE
@@ -86,6 +97,83 @@ public class UIHelper {
}
}
+ public static final Map<Pattern, Integer> ANDROID_EMOTICONS = new HashMap<Pattern, Integer>();
+
+ private static final Factory spannableFactory = Spannable.Factory
+ .getInstance();
+
+ static {
+ addPattern(ANDROID_EMOTICONS, ":)", R.drawable.emo_im_happy);
+ addPattern(ANDROID_EMOTICONS, ":-)", R.drawable.emo_im_happy);
+ addPattern(ANDROID_EMOTICONS, ":(", R.drawable.emo_im_sad);
+ addPattern(ANDROID_EMOTICONS, ":-(", R.drawable.emo_im_sad);
+ addPattern(ANDROID_EMOTICONS, ";)", R.drawable.emo_im_winking);
+ addPattern(ANDROID_EMOTICONS, ";-)", R.drawable.emo_im_winking);
+ addPattern(ANDROID_EMOTICONS, ":P",
+ R.drawable.emo_im_tongue_sticking_out);
+ addPattern(ANDROID_EMOTICONS, ":-P",
+ R.drawable.emo_im_tongue_sticking_out);
+ addPattern(ANDROID_EMOTICONS, "=-O", R.drawable.emo_im_surprised);
+ addPattern(ANDROID_EMOTICONS, ":*", R.drawable.emo_im_kissing);
+ addPattern(ANDROID_EMOTICONS, ":-*", R.drawable.emo_im_kissing);
+ addPattern(ANDROID_EMOTICONS, ":O", R.drawable.emo_im_wtf);
+ addPattern(ANDROID_EMOTICONS, ":-O", R.drawable.emo_im_wtf);
+ addPattern(ANDROID_EMOTICONS, "B)", R.drawable.emo_im_cool);
+ addPattern(ANDROID_EMOTICONS, "B-)", R.drawable.emo_im_cool);
+ addPattern(ANDROID_EMOTICONS, "8)", R.drawable.emo_im_cool);
+ addPattern(ANDROID_EMOTICONS, "8-)", R.drawable.emo_im_cool);
+ addPattern(ANDROID_EMOTICONS, ":$", R.drawable.emo_im_money_mouth);
+ addPattern(ANDROID_EMOTICONS, ":-$", R.drawable.emo_im_money_mouth);
+ addPattern(ANDROID_EMOTICONS, ":-!", R.drawable.emo_im_foot_in_mouth);
+ addPattern(ANDROID_EMOTICONS, ":-[", R.drawable.emo_im_embarrassed);
+ addPattern(ANDROID_EMOTICONS, "O:)", R.drawable.emo_im_angel);
+ addPattern(ANDROID_EMOTICONS, "O:-)", R.drawable.emo_im_angel);
+ addPattern(ANDROID_EMOTICONS, ":\\", R.drawable.emo_im_undecided);
+ addPattern(ANDROID_EMOTICONS, ":-\\", R.drawable.emo_im_undecided);
+ addPattern(ANDROID_EMOTICONS, ":'(", R.drawable.emo_im_crying);
+ addPattern(ANDROID_EMOTICONS, ":D", R.drawable.emo_im_laughing);
+ addPattern(ANDROID_EMOTICONS, ":-D", R.drawable.emo_im_laughing);
+ addPattern(ANDROID_EMOTICONS, "O_o", R.drawable.emo_im_wtf);
+ addPattern(ANDROID_EMOTICONS, "o_O", R.drawable.emo_im_wtf);
+ addPattern(ANDROID_EMOTICONS, ">:O", R.drawable.emo_im_yelling);
+ addPattern(ANDROID_EMOTICONS, ">:0", R.drawable.emo_im_yelling);
+ addPattern(ANDROID_EMOTICONS, ":S", R.drawable.emo_im_lips_are_sealed);
+ addPattern(ANDROID_EMOTICONS, ":-S", R.drawable.emo_im_lips_are_sealed);
+ addPattern(ANDROID_EMOTICONS, "<3", R.drawable.emo_im_heart);
+ }
+
+ private static void addPattern(Map<Pattern, Integer> map, String smile,
+ int resource) {
+ map.put(Pattern.compile(Pattern.quote(smile)), resource);
+ }
+
+ private static boolean getSmiledText(Context context, Spannable spannable) {
+ boolean hasChanges = false;
+ Map<Pattern, Integer> emoticons = ANDROID_EMOTICONS;
+ for (Entry<Pattern, Integer> entry : emoticons.entrySet()) {
+ Matcher matcher = entry.getKey().matcher(spannable);
+ while (matcher.find()) {
+ boolean set = true;
+ for (ImageSpan span : spannable.getSpans(matcher.start(),
+ matcher.end(), ImageSpan.class))
+ if (spannable.getSpanStart(span) >= matcher.start()
+ && spannable.getSpanEnd(span) <= matcher.end())
+ spannable.removeSpan(span);
+ else {
+ set = false;
+ break;
+ }
+ if (set) {
+ spannable.setSpan(new ImageSpan(context, entry.getValue()),
+ matcher.start(), matcher.end(),
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ hasChanges = true;
+ }
+ }
+ }
+ return hasChanges;
+ }
+
private final static class EmoticonPattern {
Pattern pattern;
String replacement;
@@ -117,7 +205,7 @@ public class UIHelper {
new EmoticonPattern(":-?[0Oo]", 0x1f62e),
new EmoticonPattern("\\\\o/", 0x1F631), };
- public static String transformAsciiEmoticons(String body) {
+ public static String transformAsciiEmoticonsToUtf8(String body) {
if (body != null) {
for (EmoticonPattern p : patterns) {
body = p.replaceAll(body);
@@ -127,6 +215,18 @@ public class UIHelper {
return body;
}
+ public static Spannable transformAsciiEmoticons(Context context, String body) {
+ Spannable spannable;
+ if (Config.UTF8_EMOTICONS) {
+ spannable = spannableFactory.newSpannable(transformAsciiEmoticonsToUtf8(body));
+ }
+ else {
+ spannable = spannableFactory.newSpannable(body);
+ getSmiledText(context, spannable);
+ }
+ return spannable;
+ }
+
public static int getColorForName(String name) {
if (name.isEmpty()) {
return 0xFF202020;