diff options
Diffstat (limited to 'src/main/java/eu')
6 files changed, 215 insertions, 21 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 7a50c47f..81a68008 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -18,6 +18,8 @@ public final class Config { public static final int MESSAGE_MERGE_WINDOW = 20; + public static final boolean UTF8_EMOTICONS = false; + public static final int PAGE_SIZE = 50; public static final int MAX_NUM_PAGES = 3; diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index 5bf3cdab..136108ef 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Locale; +import de.tzur.conversations.Settings; import eu.siacs.conversations.entities.Account; import android.content.SharedPreferences; @@ -58,28 +59,33 @@ public class SettingsActivity extends XmppActivity implements @Override public void onSharedPreferenceChanged(SharedPreferences preferences, String name) { - if (name.equals("resource")) { - String resource = preferences.getString("resource", "mobile") - .toLowerCase(Locale.US); - if (xmppConnectionServiceBound) { - for (Account account : xmppConnectionService.getAccounts()) { - account.setResource(resource); - if (!account.isOptionSet(Account.OPTION_DISABLED)) { - xmppConnectionService.reconnectAccount(account, false); + switch (name) { + case "resource": + String resource = preferences.getString("resource", "mobile") + .toLowerCase(Locale.US); + if (xmppConnectionServiceBound) { + for (Account account : xmppConnectionService.getAccounts()) { + account.setResource(resource); + if (!account.isOptionSet(Account.OPTION_DISABLED)) { + xmppConnectionService.reconnectAccount(account, false); + } + } + } + break; + case "keep_foreground_service": + xmppConnectionService.toggleForegroundService(); + break; + case "confirm_messages": + if (xmppConnectionServiceBound) { + for (Account account : xmppConnectionService.getAccounts()) { + if (!account.isOptionSet(Account.OPTION_DISABLED)) { + xmppConnectionService.sendPresence(account); + } } } - } - } else if (name.equals("keep_foreground_service")) { - xmppConnectionService.toggleForegroundService(); - } else if (name.equals("confirm_messages")) { - if (xmppConnectionServiceBound) { - for (Account account : xmppConnectionService.getAccounts()) { - if (!account.isOptionSet(Account.OPTION_DISABLED)) { - xmppConnectionService.sendPresence(account); - } - } - } - } + break; + } + Settings.synchronizeSettingsClassWithPreferences(getPreferences(), name); } } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index bf247787..1f1af09c 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -61,6 +61,7 @@ import java.util.Hashtable; import java.util.List; import java.util.concurrent.RejectedExecutionException; +import de.tzur.conversations.Settings; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -306,6 +307,9 @@ public abstract class XmppActivity extends Activity { setTheme(this.mTheme); this.mUsingEnterKey = usingEnterKey(); mUseSubject = getPreferences().getBoolean("use_subject", true); + + Settings.initSettingsClassWithPreferences(getPreferences()); + final ActionBar ab = getActionBar(); if (ab!=null) { ab.setDisplayHomeAsUpEnabled(true); 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 38c321d0..e62aaf96 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -13,14 +13,28 @@ import android.widget.TextView; import java.util.List; +import de.tzur.conversations.Settings; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Downloadable; import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.entities.Presences; import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.utils.UIHelper; +import android.content.Context; +import android.graphics.Color; +import android.graphics.Typeface; +import android.preference.PreferenceManager; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; public class ConversationAdapter extends ArrayAdapter<Conversation> { @@ -62,6 +76,26 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { TextView mTimestamp = (TextView) view.findViewById(R.id.conversation_lastupdate); ImageView imagePreview = (ImageView) view.findViewById(R.id.conversation_lastimage); + if (Settings.SHOW_ONLINE_STATUS) { + TextView status = (TextView) view.findViewById(R.id.status); + + String color = "#000000"; + switch (conversation.getContact().getMostAvailableStatus()) { + case Presences.ONLINE: + case Presences.CHAT: + color = "#259B23"; + break; + case Presences.AWAY: + case Presences.XA: + color = "#FF9800"; + break; + case Presences.DND: + color = "#E51C23"; + break; + } + status.setBackgroundColor(Color.parseColor(color)); + } + Message message = conversation.getLatestMessage(); if (!conversation.isRead()) { @@ -102,4 +136,4 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { return view; } -}
\ No newline at end of file +} 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 442c6ecf..7fa05050 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -5,6 +5,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.Typeface; import android.net.Uri; +import android.preference.PreferenceManager; import android.text.Spannable; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; @@ -24,6 +25,7 @@ import android.widget.Toast; import java.util.List; +import de.tzur.conversations.Settings; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -223,6 +225,10 @@ public class MessageAdapter extends ArrayAdapter<Message> { final String formattedBody = message.getMergedBody().replaceAll("^" + Message.ME_COMMAND, nick + " "); if (message.getType() != Message.TYPE_PRIVATE) { + boolean parseEmoticons = Settings.PARSE_EMOTICONS; + viewHolder.messageBody.setText(parseEmoticons ? UIHelper + .transformAsciiEmoticons(getContext(), message.getMergedBody()) + : message.getMergedBody()); if (message.hasMeCommand()) { final Spannable span = new SpannableString(formattedBody); span.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, nick.length(), diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 235ef84c..333f6e27 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -1,9 +1,18 @@ package eu.siacs.conversations.utils; +import java.util.ArrayList; import java.net.URLConnection; 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 eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; @@ -14,6 +23,9 @@ import eu.siacs.conversations.xmpp.jid.Jid; 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; import android.util.Pair; public class UIHelper { @@ -101,6 +113,136 @@ 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; + + EmoticonPattern(String ascii, int unicode) { + this.pattern = Pattern.compile("(?<=(^|\\s))" + ascii + + "(?=(\\s|$))"); + this.replacement = new String(new int[] { unicode, }, 0, 1); + } + + String replaceAll(String body) { + return pattern.matcher(body).replaceAll(replacement); + } + } + + private static final EmoticonPattern[] patterns = new EmoticonPattern[] { + new EmoticonPattern(":-?D", 0x1f600), + new EmoticonPattern("\\^\\^", 0x1f601), + new EmoticonPattern(":'D", 0x1f602), + new EmoticonPattern("\\]-?D", 0x1f608), + new EmoticonPattern(";-?\\)", 0x1f609), + new EmoticonPattern(":-?\\)", 0x1f60a), + new EmoticonPattern("[B8]-?\\)", 0x1f60e), + new EmoticonPattern(":-?\\|", 0x1f610), + new EmoticonPattern(":-?[/\\\\]", 0x1f615), + new EmoticonPattern(":-?\\*", 0x1f617), + new EmoticonPattern(":-?[Ppb]", 0x1f61b), + new EmoticonPattern(":-?\\(", 0x1f61e), + new EmoticonPattern(":-?[0Oo]", 0x1f62e), + new EmoticonPattern("\\\\o/", 0x1F631), }; + + public static String transformAsciiEmoticonsToUtf8(String body) { + if (body != null) { + for (EmoticonPattern p : patterns) { + body = p.replaceAll(body); + } + body = body.trim(); + } + 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; |