diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-11-29 21:50:33 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-11-29 21:50:33 +0100 |
commit | b6052c82cb8463ee465226949953a7187f4096e4 (patch) | |
tree | 6347fb72ddb1928bfcaafbe914b9de795b76d633 | |
parent | d03129f1301942ddc9808229c158b92f492e79f1 (diff) |
add ability to use system emojis instead of integrated ones via expert settings
9 files changed, 38 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/services/AbstractEmojiService.java b/src/main/java/de/pixart/messenger/services/AbstractEmojiService.java index 75f1a4c98..ff10acf0c 100644 --- a/src/main/java/de/pixart/messenger/services/AbstractEmojiService.java +++ b/src/main/java/de/pixart/messenger/services/AbstractEmojiService.java @@ -2,6 +2,10 @@ package de.pixart.messenger.services; import android.content.Context; import android.support.text.emoji.EmojiCompat; +import android.util.Log; + +import de.pixart.messenger.Config; +import de.pixart.messenger.utils.Emoticons; public abstract class AbstractEmojiService { @@ -13,9 +17,11 @@ public abstract class AbstractEmojiService { protected abstract EmojiCompat.Config buildConfig(); - public void init() { - final EmojiCompat.Config config = buildConfig(); - config.setReplaceAll(true); + public void init(boolean useBundledEmoji) { + Log.d(Config.LOGTAG, "Emojis: use integrated lib " + useBundledEmoji); + EmojiCompat.Config config = buildConfig(); + config.setReplaceAll(useBundledEmoji); + EmojiCompat.reset(config); EmojiCompat.init(config); } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index b4968770a..ddda44cc8 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -88,6 +88,7 @@ import de.pixart.messenger.xmpp.jid.InvalidJidException; import de.pixart.messenger.xmpp.jid.Jid; import de.timroes.android.listview.EnhancedListView; +import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; import static de.pixart.messenger.ui.ShowFullscreenMessageActivity.getMimeType; public class ConversationActivity extends XmppActivity @@ -210,7 +211,7 @@ public class ConversationActivity extends XmppActivity @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - new EmojiService(this).init(); + new EmojiService(this).init(useBundledEmoji()); if (savedInstanceState != null) { mOpenConversation = savedInstanceState.getString(STATE_OPEN_CONVERSATION, null); mPanelOpen = savedInstanceState.getBoolean(STATE_PANEL_OPEN, true); @@ -2100,6 +2101,10 @@ public class ConversationActivity extends XmppActivity return getPreferences().getBoolean("use_white_background", getResources().getBoolean(R.bool.use_white_background)); } + public boolean useBundledEmoji() { + return getPreferences().getBoolean(USE_BUNDLED_EMOJIS, getResources().getBoolean(R.bool.use_bundled_emoji)); + } + protected boolean trustKeysIfNeeded(int requestCode) { return trustKeysIfNeeded(requestCode, ATTACHMENT_CHOICE_INVALID); } diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 040149a31..5f8c05097 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -47,6 +47,7 @@ public class SettingsActivity extends XmppActivity implements public static final String THEME = "theme"; public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags"; public static final String SHOW_FOREGROUND_SERVICE = "show_foreground_service"; + public static final String USE_BUNDLED_EMOJIS = "use_bundled_emoji"; public static final int REQUEST_WRITE_LOGS = 0xbf8701; private SettingsFragment mSettingsFragment; diff --git a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index 161a5c366..6de7acd06 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -33,6 +33,7 @@ import de.pixart.messenger.xmpp.XmppConnection; import de.pixart.messenger.xmpp.jid.InvalidJidException; import de.pixart.messenger.xmpp.jid.Jid; +import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; import static java.lang.String.format; public class ShareWithActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate { @@ -173,7 +174,8 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - new EmojiService(this).init(); + boolean useBundledEmoji = getPreferences().getBoolean(USE_BUNDLED_EMOJIS, getResources().getBoolean(R.bool.use_bundled_emoji)); + new EmojiService(this).init(useBundledEmoji); if (getActionBar() != null) { getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false); diff --git a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java index f57b53446..27e48c0d3 100644 --- a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java @@ -5,6 +5,7 @@ import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.location.Address; import android.location.Geocoder; @@ -12,6 +13,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -34,6 +36,8 @@ import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.services.EmojiService; +import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; + public class ShowLocationActivity extends Activity implements OnMapReadyCallback { private GoogleMap mGoogleMap; @@ -70,7 +74,8 @@ public class ShowLocationActivity extends Activity implements OnMapReadyCallback @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - new EmojiService(this).init(); + boolean useBundledEmoji = getPreferences().getBoolean(USE_BUNDLED_EMOJIS, getResources().getBoolean(R.bool.use_bundled_emoji)); + new EmojiService(this).init(useBundledEmoji); if (getActionBar() != null) { getActionBar().setHomeButtonEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true); @@ -81,6 +86,10 @@ public class ShowLocationActivity extends Activity implements OnMapReadyCallback fragment.getMapAsync(this); } + protected SharedPreferences getPreferences() { + return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index 6263c2e53..df6f6980d 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -458,8 +458,7 @@ public abstract class XmppActivity extends Activity { } protected SharedPreferences getPreferences() { - return PreferenceManager - .getDefaultSharedPreferences(getApplicationContext()); + return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); } public boolean useSubjectToIdentifyConference() { diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 15a25054a..208c43e63 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -102,5 +102,6 @@ <bool name="validate_hostname">false</bool> <bool name="show_foreground_service">true</bool> <bool name="warn_unencrypted_chat">true</bool> + <bool name="use_bundled_emoji">true</bool> </resources> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index e8f72f3ca..6b3f41556 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -744,4 +744,6 @@ <string name="conversation_unencrypted_hint">This chat is unencrypted, for security reasons you should activate message encryption by using the lock icon. The preferable encryption is OMEMO.</string> <string name="pref_warn_unencrypted_chat">Warn if chat is unencrypted</string> <string name="pref_warn_unencrypted_chat_summary">If message encryption is available, you should use it. If you don\'t use message encryption, show a warning message inside the chat.</string> + <string name="pref_use_bundled_emoji">Use integrated emojis</string> + <string name="pref_use_bundled_emoji_summary">Use the integrated emoji library instead of using your devices ones. Changes will be available after reopening the app.</string> </resources> diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 70ce4e76c..82d9ea00f 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -267,6 +267,11 @@ android:key="show_dynamic_tags" android:summary="@string/pref_show_dynamic_tags_summary" android:title="@string/pref_show_dynamic_tags" /> + <CheckBoxPreference + android:defaultValue="@bool/use_bundled_emoji" + android:key="use_bundled_emoji" + android:summary="@string/pref_use_bundled_emoji_summary" + android:title="@string/pref_use_bundled_emoji" /> </PreferenceCategory> <PreferenceCategory android:title="@string/pref_security_settings"> <CheckBoxPreference |