From afb8ecf287dcfa4d59375b701e0bcca2ce789e20 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 28 Oct 2021 11:33:36 +0200 Subject: [PATCH] Optionally load emoji --- app/build.gradle | 3 +++ .../java/eu/faircode/email/ApplicationEx.java | 17 +++++++++++++ .../email/FragmentOptionsPrivacy.java | 12 ++++++++- .../res/layout/fragment_options_privacy.xml | 25 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 230f8ce64d..b121e2fe08 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -293,6 +293,7 @@ dependencies { def core_version = "1.6.0" // 1.7.0 def shortcuts_version = "1.0.0" def appcompat_version = "1.3.1" + def emoji_version = "1.0.0-beta01" def activity_version = "1.4.0" def fragment_version = "1.4.0-beta01" def webkit_version = "1.4.0" @@ -350,9 +351,11 @@ dependencies { implementation "androidx.core:core-google-shortcuts:$shortcuts_version" // https://mvnrepository.com/artifact/androidx.appcompat/appcompat + // https://mvnrepository.com/artifact/androidx.emoji2/emoji2 // https://mvnrepository.com/artifact/androidx.activity/activity // https://mvnrepository.com/artifact/androidx.fragment/fragment implementation "androidx.appcompat:appcompat:$appcompat_version" + implementation "androidx.emoji2:emoji2:$emoji_version" implementation "androidx.activity:activity:$activity_version" implementation "androidx.fragment:fragment:$fragment_version" diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 8823982cb6..d9691d300c 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -39,6 +39,9 @@ import android.webkit.CookieManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.emoji2.text.DefaultEmojiCompatConfig; +import androidx.emoji2.text.EmojiCompat; +import androidx.emoji2.text.FontRequestEmojiCompatConfig; import androidx.preference.PreferenceManager; import androidx.work.WorkManager; @@ -147,6 +150,7 @@ public class ApplicationEx extends Application SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final boolean crash_reports = prefs.getBoolean("crash_reports", false); + final boolean load_emoji = prefs.getBoolean("load_emoji", BuildConfig.PLAY_STORE_RELEASE); prev = Thread.getDefaultUncaughtExceptionHandler(); @@ -190,6 +194,18 @@ public class ApplicationEx extends Application if (Helper.hasWebView(this)) CookieManager.getInstance().setAcceptCookie(false); + Log.i("Load emoji=" + load_emoji); + if (!load_emoji) + try { + FontRequestEmojiCompatConfig crying = DefaultEmojiCompatConfig.create(this); + if (crying != null) { + crying.setMetadataLoadStrategy(EmojiCompat.LOAD_STRATEGY_MANUAL); + EmojiCompat.init(crying); + } + } catch (Throwable ex) { + Log.e(ex); + } + EncryptionHelper.init(this); MessageHelper.setSystemProperties(this); @@ -244,6 +260,7 @@ public class ApplicationEx extends Application ServiceSynchronize.scheduleWatchdog(this); break; case "secure": // privacy + case "load_emoji": // privacy case "shortcuts": // misc case "language": // misc case "wal": // misc diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java index 04b3dd10d9..60edf332ed 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java @@ -83,6 +83,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer private TextView tvGenericUserAgent; private SwitchCompat swSafeBrowsing; private ImageButton ibSafeBrowsing; + private SwitchCompat swLoadEmoji; private ImageButton ibDisconnectBlacklist; private Button btnDisconnectBlacklist; private TextView tvDisconnectBlacklistTime; @@ -98,7 +99,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer "disable_tracking", "hide_timezone", "pin", "biometrics", "biometrics_timeout", "autolock", "client_id", "display_hidden", "incognito_keyboard", "secure", - "generic_ua", "safe_browsing", + "generic_ua", "safe_browsing", "load_emoji", "disconnect_auto_update", "disconnect_links", "disconnect_images" }; @@ -136,6 +137,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer tvGenericUserAgent = view.findViewById(R.id.tvGenericUserAgent); swSafeBrowsing = view.findViewById(R.id.swSafeBrowsing); ibSafeBrowsing = view.findViewById(R.id.ibSafeBrowsing); + swLoadEmoji = view.findViewById(R.id.swLoadEmoji); ibDisconnectBlacklist = view.findViewById(R.id.ibDisconnectBlacklist); btnDisconnectBlacklist = view.findViewById(R.id.btnDisconnectBlacklist); tvDisconnectBlacklistTime = view.findViewById(R.id.tvDisconnectBlacklistTime); @@ -344,6 +346,13 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer grpSafeBrowsing.setEnabled(WebViewEx.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE)); + swLoadEmoji.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("load_emoji", checked).commit(); // apply won't work here + } + }); + ibDisconnectBlacklist.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -488,6 +497,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer tvGenericUserAgent.setText(WebViewEx.getUserAgent(getContext())); swGenericUserAgent.setChecked(prefs.getBoolean("generic_ua", true)); swSafeBrowsing.setChecked(prefs.getBoolean("safe_browsing", false)); + swLoadEmoji.setChecked(prefs.getBoolean("load_emoji", BuildConfig.PLAY_STORE_RELEASE)); long time = prefs.getLong("disconnect_last", -1); DateFormat DF = SimpleDateFormat.getDateTimeInstance(); diff --git a/app/src/main/res/layout/fragment_options_privacy.xml b/app/src/main/res/layout/fragment_options_privacy.xml index f3d815aa2a..9af2e468e9 100644 --- a/app/src/main/res/layout/fragment_options_privacy.xml +++ b/app/src/main/res/layout/fragment_options_privacy.xml @@ -489,6 +489,29 @@ app:layout_constraintTop_toBottomOf="@id/tvSafeBrowsingHint" app:srcCompat="@drawable/twotone_info_24" /> + + + + + app:layout_constraintTop_toBottomOf="@id/tvLoadEmojiHint" /> Lock on screen off Use generic browser user agent Google Safe browsing (Android 8+) + Load updated Emoji from Google Play Services Disconnect\'s tracker protection lists Automatically update lists weekly Use lists to warn about tracking links