From 9cc22ce992b1eaab9cae439dbfa97ba1f95a85f6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 21 Jun 2018 14:26:25 +0200 Subject: [PATCH] introduced build flavor to build w/o emoji compat --- .travis.yml | 2 +- README.md | 2 +- build.gradle | 17 ++++-- .../ui/widget/AbstractEditMessage.java | 17 ++++++ .../conversations/utils/EmojiWrapper.java | 0 .../ui/service/EmojiService.java | 17 ------ .../ui/service/EmojiService.java | 28 ++++++++++ .../ui/ConversationsActivity.java | 1 - .../ui/service/AbstractEmojiService.java | 26 --------- .../conversations/ui/widget/EditMessage.java | 3 +- .../ui/service/EmojiService.java | 45 ---------------- .../ui/service/EmojiService.java | 53 +++++++++++++++++++ .../res/values/font_certs.xml | 0 .../ui/service/EmojiService.java | 14 +++++ .../ui/widget/AbstractEditMessage.java | 16 ++++++ .../conversations/utils/EmojiWrapper.java | 47 ++++++++++++++++ 16 files changed, 190 insertions(+), 98 deletions(-) create mode 100644 src/compat/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java rename src/{main => compat}/java/eu/siacs/conversations/utils/EmojiWrapper.java (100%) delete mode 100644 src/free/java/eu/siacs/conversations/ui/service/EmojiService.java create mode 100644 src/freeCompat/java/eu/siacs/conversations/ui/service/EmojiService.java delete mode 100644 src/main/java/eu/siacs/conversations/ui/service/AbstractEmojiService.java delete mode 100644 src/playstore/java/eu/siacs/conversations/ui/service/EmojiService.java create mode 100644 src/playstoreCompat/java/eu/siacs/conversations/ui/service/EmojiService.java rename src/{playstore => playstoreCompat}/res/values/font_certs.xml (100%) create mode 100644 src/system/java/eu/siacs/conversations/ui/service/EmojiService.java create mode 100644 src/system/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java create mode 100644 src/system/java/eu/siacs/conversations/utils/EmojiWrapper.java diff --git a/.travis.yml b/.travis.yml index df2926aeb..a686b038d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ android: licenses: - '.+' script: - - ./gradlew assembleFreeRelease + - ./gradlew assembleFreeSystemRelease before_install: - yes | sdkmanager "platforms;android-27" diff --git a/README.md b/README.md index 9ff6ab262..5f326ff28 100644 --- a/README.md +++ b/README.md @@ -368,7 +368,7 @@ Make sure to have ANDROID_HOME point to your Android SDK. Use the Android SDK Ma git clone https://github.com/siacs/Conversations.git cd Conversations - ./gradlew assembleFreeDebug + ./gradlew assembleFreeSystemDebug There are two build flavors available. *free* and *playstore*. Unless you know what you are doing you only need *free*. diff --git a/build.gradle b/build.gradle index 79f8c484e..aec90d54f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.2' + classpath 'com.android.tools.build:gradle:3.1.3' } } @@ -23,7 +23,8 @@ repositories { configurations { playstoreImplementation - freeImplementation + compatImplementation + freeCompatImplementation } ext { @@ -39,10 +40,10 @@ dependencies { implementation "com.android.support:support-v13:$supportLibVersion" implementation "com.android.support:appcompat-v7:$supportLibVersion" implementation "com.android.support:cardview-v7:$supportLibVersion" - implementation "com.android.support:support-emoji-appcompat:$supportLibVersion" + compatImplementation "com.android.support:support-emoji-appcompat:$supportLibVersion" implementation "com.android.support:support-emoji:$supportLibVersion" implementation "com.android.support:design:$supportLibVersion" - freeImplementation "com.android.support:support-emoji-bundled:$supportLibVersion" + freeCompatImplementation "com.android.support:support-emoji-bundled:$supportLibVersion" implementation 'org.bouncycastle:bcmail-jdk15on:1.58' implementation 'com.google.zxing:core:3.3.0' implementation 'de.measite.minidns:minidns-hla:0.2.4' @@ -89,7 +90,7 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } - flavorDimensions("distribution") + flavorDimensions("distribution", "emoji") productFlavors { playstore { @@ -98,6 +99,12 @@ android { free { dimension "distribution" } + system { + dimension "emoji" + } + compat { + dimension "emoji" + } } buildTypes { diff --git a/src/compat/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java b/src/compat/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java new file mode 100644 index 000000000..3620accbd --- /dev/null +++ b/src/compat/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java @@ -0,0 +1,17 @@ +package eu.siacs.conversations.ui.widget; + +import android.content.Context; +import android.support.text.emoji.widget.EmojiAppCompatEditText; +import android.util.AttributeSet; + +public abstract class AbstractEditMessage extends EmojiAppCompatEditText { + + public AbstractEditMessage(Context context) { + super(context); + } + + public AbstractEditMessage(Context context, AttributeSet attrs) { + super(context, attrs); + } + +} \ No newline at end of file diff --git a/src/main/java/eu/siacs/conversations/utils/EmojiWrapper.java b/src/compat/java/eu/siacs/conversations/utils/EmojiWrapper.java similarity index 100% rename from src/main/java/eu/siacs/conversations/utils/EmojiWrapper.java rename to src/compat/java/eu/siacs/conversations/utils/EmojiWrapper.java diff --git a/src/free/java/eu/siacs/conversations/ui/service/EmojiService.java b/src/free/java/eu/siacs/conversations/ui/service/EmojiService.java deleted file mode 100644 index 5d336a6fc..000000000 --- a/src/free/java/eu/siacs/conversations/ui/service/EmojiService.java +++ /dev/null @@ -1,17 +0,0 @@ -package eu.siacs.conversations.ui.service; - -import android.content.Context; -import android.support.text.emoji.EmojiCompat; -import android.support.text.emoji.bundled.BundledEmojiCompatConfig; - -public class EmojiService extends AbstractEmojiService { - - public EmojiService(Context context) { - super(context); - } - - @Override - protected EmojiCompat.Config buildConfig() { - return new BundledEmojiCompatConfig(context); - } -} \ No newline at end of file diff --git a/src/freeCompat/java/eu/siacs/conversations/ui/service/EmojiService.java b/src/freeCompat/java/eu/siacs/conversations/ui/service/EmojiService.java new file mode 100644 index 000000000..094e3da92 --- /dev/null +++ b/src/freeCompat/java/eu/siacs/conversations/ui/service/EmojiService.java @@ -0,0 +1,28 @@ +package eu.siacs.conversations.ui.service; + +import android.content.Context; +import android.os.Build; +import android.support.text.emoji.EmojiCompat; +import android.support.text.emoji.FontRequestEmojiCompatConfig; +import android.support.text.emoji.bundled.BundledEmojiCompatConfig; +import android.support.v4.provider.FontRequest; +import android.util.Log; + +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; + +public class EmojiService { + + private final Context context; + + public EmojiService(Context context) { + this.context = context; + } + + public void init() { + BundledEmojiCompatConfig config = new BundledEmojiCompatConfig(context); + config.setReplaceAll(true); + EmojiCompat.init(config); + } + +} \ No newline at end of file diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index 1776777fb..d74a9b627 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -41,7 +41,6 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.databinding.DataBindingUtil; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.provider.Settings; import android.support.annotation.IdRes; diff --git a/src/main/java/eu/siacs/conversations/ui/service/AbstractEmojiService.java b/src/main/java/eu/siacs/conversations/ui/service/AbstractEmojiService.java deleted file mode 100644 index d1882f51e..000000000 --- a/src/main/java/eu/siacs/conversations/ui/service/AbstractEmojiService.java +++ /dev/null @@ -1,26 +0,0 @@ -package eu.siacs.conversations.ui.service; - -import android.content.Context; -import android.os.Build; -import android.support.text.emoji.EmojiCompat; - -public abstract class AbstractEmojiService { - - protected final Context context; - - public AbstractEmojiService(Context context) { - this.context = context; - } - - protected abstract EmojiCompat.Config buildConfig(); - - public void init() { - final EmojiCompat.Config config = buildConfig(); - //On recent Androids we assume to have the latest emojis - //there are some annoying bugs with emoji compat that make it a safer choice not to use it when possible - // a) when using the ondemand emoji font (play store) flags don’t work - // b) the text preview has annoying glitches when the cut of text contains emojis (the emoji will be half visible) - config.setReplaceAll(Build.VERSION.SDK_INT < Build.VERSION_CODES.O); - EmojiCompat.init(config); - } -} diff --git a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java index 173b7edf4..61a0272b7 100644 --- a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java +++ b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java @@ -2,7 +2,6 @@ package eu.siacs.conversations.ui.widget; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import android.support.text.emoji.widget.EmojiAppCompatEditText; import android.support.v13.view.inputmethod.EditorInfoCompat; import android.support.v13.view.inputmethod.InputConnectionCompat; import android.support.v13.view.inputmethod.InputContentInfoCompat; @@ -23,7 +22,7 @@ import android.view.inputmethod.InputConnection; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; -public class EditMessage extends EmojiAppCompatEditText { +public class EditMessage extends AbstractEditMessage { private static final InputFilter SPAN_FILTER = (source, start, end, dest, dstart, dend) -> source instanceof Spanned ? source.toString() : source; protected Handler mTypingHandler = new Handler(); diff --git a/src/playstore/java/eu/siacs/conversations/ui/service/EmojiService.java b/src/playstore/java/eu/siacs/conversations/ui/service/EmojiService.java deleted file mode 100644 index 7c33cb748..000000000 --- a/src/playstore/java/eu/siacs/conversations/ui/service/EmojiService.java +++ /dev/null @@ -1,45 +0,0 @@ -package eu.siacs.conversations.ui.service; - -import android.content.Context; -import android.support.text.emoji.EmojiCompat; -import android.support.text.emoji.FontRequestEmojiCompatConfig; -import android.support.v4.provider.FontRequest; -import android.util.Log; - -import eu.siacs.conversations.Config; -import eu.siacs.conversations.R; - -public class EmojiService extends AbstractEmojiService { - - - private final EmojiCompat.InitCallback initCallback = new EmojiCompat.InitCallback() { - @Override - public void onInitialized() { - super.onInitialized(); - Log.d(Config.LOGTAG,"EmojiService succeeded in loading fonts"); - - } - - @Override - public void onFailed(Throwable throwable) { - super.onFailed(throwable); - Log.d(Config.LOGTAG,"EmojiService failed to load fonts",throwable); - } - }; - - public EmojiService(Context context) { - super(context); - } - - @Override - protected EmojiCompat.Config buildConfig() { - final FontRequest fontRequest = new FontRequest( - "com.google.android.gms.fonts", - "com.google.android.gms", - "Noto Color Emoji Compat", - R.array.font_certs); - FontRequestEmojiCompatConfig fontRequestEmojiCompatConfig = new FontRequestEmojiCompatConfig(context, fontRequest); - fontRequestEmojiCompatConfig.registerInitCallback(initCallback); - return fontRequestEmojiCompatConfig; - } -} \ No newline at end of file diff --git a/src/playstoreCompat/java/eu/siacs/conversations/ui/service/EmojiService.java b/src/playstoreCompat/java/eu/siacs/conversations/ui/service/EmojiService.java new file mode 100644 index 000000000..52d61ff13 --- /dev/null +++ b/src/playstoreCompat/java/eu/siacs/conversations/ui/service/EmojiService.java @@ -0,0 +1,53 @@ +package eu.siacs.conversations.ui.service; + +import android.content.Context; +import android.os.Build; +import android.support.text.emoji.EmojiCompat; +import android.support.text.emoji.FontRequestEmojiCompatConfig; +import android.support.v4.provider.FontRequest; +import android.util.Log; + +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; + +public class EmojiService { + + + private final EmojiCompat.InitCallback initCallback = new EmojiCompat.InitCallback() { + @Override + public void onInitialized() { + super.onInitialized(); + Log.d(Config.LOGTAG, "EmojiService succeeded in loading fonts"); + + } + + @Override + public void onFailed(Throwable throwable) { + super.onFailed(throwable); + Log.d(Config.LOGTAG, "EmojiService failed to load fonts", throwable); + } + }; + + private final Context context; + + public EmojiService(Context context) { + this.context = context; + } + + public void init() { + final FontRequest fontRequest = new FontRequest( + "com.google.android.gms.fonts", + "com.google.android.gms", + "Noto Color Emoji Compat", + R.array.font_certs); + FontRequestEmojiCompatConfig fontRequestEmojiCompatConfig = new FontRequestEmojiCompatConfig(context, fontRequest); + fontRequestEmojiCompatConfig.registerInitCallback(initCallback); + //On recent Androids we assume to have the latest emojis + //there are some annoying bugs with emoji compat that make it a safer choice not to use it when possible + // a) when using the ondemand emoji font (play store) flags don’t work + // b) the text preview has annoying glitches when the cut of text contains emojis (the emoji will be half visible) + fontRequestEmojiCompatConfig.setReplaceAll(Build.VERSION.SDK_INT < Build.VERSION_CODES.O); + EmojiCompat.init(fontRequestEmojiCompatConfig); + } + +} \ No newline at end of file diff --git a/src/playstore/res/values/font_certs.xml b/src/playstoreCompat/res/values/font_certs.xml similarity index 100% rename from src/playstore/res/values/font_certs.xml rename to src/playstoreCompat/res/values/font_certs.xml diff --git a/src/system/java/eu/siacs/conversations/ui/service/EmojiService.java b/src/system/java/eu/siacs/conversations/ui/service/EmojiService.java new file mode 100644 index 000000000..6ca66fd62 --- /dev/null +++ b/src/system/java/eu/siacs/conversations/ui/service/EmojiService.java @@ -0,0 +1,14 @@ +package eu.siacs.conversations.ui.service; + +import android.content.Context; + +public class EmojiService { + + public EmojiService(Context context) { + //nop + } + + public void init() { + //nop + } +} \ No newline at end of file diff --git a/src/system/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java b/src/system/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java new file mode 100644 index 000000000..5f35e00b4 --- /dev/null +++ b/src/system/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java @@ -0,0 +1,16 @@ +package eu.siacs.conversations.ui.widget; + +import android.content.Context; +import android.support.v7.widget.AppCompatEditText; +import android.util.AttributeSet; + +public abstract class AbstractEditMessage extends AppCompatEditText { + + public AbstractEditMessage(Context context) { + super(context); + } + + public AbstractEditMessage(Context context, AttributeSet attrs) { + super(context, attrs); + } +} \ No newline at end of file diff --git a/src/system/java/eu/siacs/conversations/utils/EmojiWrapper.java b/src/system/java/eu/siacs/conversations/utils/EmojiWrapper.java new file mode 100644 index 000000000..9466531a3 --- /dev/null +++ b/src/system/java/eu/siacs/conversations/utils/EmojiWrapper.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package eu.siacs.conversations.utils; + +import android.support.text.emoji.EmojiCompat; + +public class EmojiWrapper { + + public static CharSequence transform(CharSequence input) { + try { + if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_SUCCEEDED) { + return EmojiCompat.get().process(input); + } else { + return input; + } + } catch (IllegalStateException e) { + return input; + } + } +}