mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-01 03:55:47 +02:00
Update android-emojify to 1.9.2
- Ignore the moshi R8 errors, since we use gson - Add explicit rtl support, otherwise the lib removes it - Refactor EmojiConverter to exclude fitzpatrick
This commit is contained in:
parent
21130b7562
commit
5c5b036e20
@ -236,7 +236,7 @@ dependencies {
|
||||
implementation "org.apache.commons:commons-lang3:3.7"
|
||||
implementation "org.cyanogenmod:platform.sdk:6.0"
|
||||
implementation 'com.jaredrummler:colorpicker:1.1.0'
|
||||
implementation 'com.github.wax911:android-emojify:0.1.7'
|
||||
implementation 'com.github.wax911:android-emojify:1.9.2'
|
||||
implementation 'com.google.protobuf:protobuf-javalite:4.27.2'
|
||||
implementation 'com.android.volley:volley:1.2.1'
|
||||
|
||||
|
10
app/proguard-rules.pro
vendored
10
app/proguard-rules.pro
vendored
@ -64,12 +64,10 @@
|
||||
# Keep Nordic DFU library
|
||||
-keep class no.nordicsemi.android.dfu.** { *; }
|
||||
|
||||
# Keep dependency android-emojify (io.wax911.emojify) uses
|
||||
-keep class org.hamcrest.** { *; }
|
||||
-dontwarn java.beans.BeanInfo
|
||||
-dontwarn java.beans.IntrospectionException
|
||||
-dontwarn java.beans.Introspector
|
||||
-dontwarn java.beans.PropertyDescriptor
|
||||
# For android-emojify - we are not using moshi, so ignore these
|
||||
-dontwarn com.squareup.moshi.**
|
||||
-dontwarn kotlinx.serialization.**
|
||||
-dontwarn okio.**
|
||||
|
||||
# Keep logback classes
|
||||
-keep class ch.qos.** { *; }
|
||||
|
@ -108,6 +108,7 @@
|
||||
<application
|
||||
android:name=".GBApplication"
|
||||
android:allowBackup="false"
|
||||
android:supportsRtl="true"
|
||||
android:fullBackupContent="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
@ -81,6 +81,7 @@ import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
@ -95,9 +96,8 @@ import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
import io.wax911.emojify.Emoji;
|
||||
import io.wax911.emojify.EmojiManager;
|
||||
import io.wax911.emojify.EmojiUtils;
|
||||
import io.wax911.emojify.parser.EmojiParserKt;
|
||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
@ -1319,18 +1319,12 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
return true;
|
||||
}
|
||||
|
||||
private String renderUnicodeWordPartAsImage(String word) {
|
||||
private String renderUnicodeWordPartAsImage(final String word) {
|
||||
// check for emoji
|
||||
boolean hasEmoji = false;
|
||||
if (EmojiUtils.getAllEmojis() == null)
|
||||
EmojiManager.initEmojiData(GBApplication.getContext());
|
||||
for (Emoji emoji : EmojiUtils.getAllEmojis())
|
||||
if (word.contains(emoji.getEmoji())) {
|
||||
hasEmoji = true;
|
||||
break;
|
||||
}
|
||||
final EmojiManager emojiManager = EmojiConverter.getEmojiManager(getContext());
|
||||
final boolean hasEmoji = !EmojiParserKt.extractEmojis(emojiManager, word).isEmpty();
|
||||
// if we had emoji, ensure we create 3 bit color (not 1 bit B&W)
|
||||
BangleJSBitmapStyle style = hasEmoji ? BangleJSBitmapStyle.RGB_3BPP_TRANSPARENT : BangleJSBitmapStyle.MONOCHROME_TRANSPARENT;
|
||||
final BangleJSBitmapStyle style = hasEmoji ? BangleJSBitmapStyle.RGB_3BPP_TRANSPARENT : BangleJSBitmapStyle.MONOCHROME_TRANSPARENT;
|
||||
return "\0"+bitmapToEspruinoString(textToBitmap(word), style);
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,20 @@ package nodomain.freeyourgadget.gadgetbridge.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.wax911.emojify.EmojiManager;
|
||||
import io.wax911.emojify.EmojiUtils;
|
||||
import io.wax911.emojify.contract.model.IEmoji;
|
||||
import io.wax911.emojify.parser.EmojiParserKt;
|
||||
import io.wax911.emojify.parser.candidate.UnicodeCandidate;
|
||||
import io.wax911.emojify.parser.transformer.EmojiTransformer;
|
||||
import io.wax911.emojify.serializer.gson.GsonDeserializer;
|
||||
|
||||
public class EmojiConverter {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EmojiConverter.class);
|
||||
@ -65,7 +74,27 @@ public class EmojiConverter {
|
||||
{"\u2764", "<3"}, // heart
|
||||
};
|
||||
|
||||
private static boolean isEmojiDataInitialised = false;
|
||||
private static EmojiManager emojiManagerInstance;
|
||||
|
||||
/**
|
||||
* An emoji transformer that removes fitzpatrick modifiers. This partially reimplements
|
||||
* EmojiParser.parseToAliases since I was unable to call it directly with FitzpatrickAction.REMOVE
|
||||
*/
|
||||
private static final EmojiTransformer EMOJI_TRANSFORMER_NO_FITZPATRICK = new EmojiTransformer() {
|
||||
@Nullable
|
||||
@Override
|
||||
public String invoke(@NonNull final UnicodeCandidate unicodeCandidate) {
|
||||
final IEmoji emoji = unicodeCandidate.getEmoji();
|
||||
if (emoji == null) {
|
||||
return null;
|
||||
}
|
||||
final List<String> aliases = emoji.getAliases();
|
||||
if (aliases == null || aliases.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return String.format(":%s:", aliases.get(0));
|
||||
}
|
||||
};
|
||||
|
||||
private static String convertSimpleEmojiToAscii(String text) {
|
||||
for (String[] emojiMap : simpleEmojiMapping) {
|
||||
@ -74,25 +103,25 @@ public class EmojiConverter {
|
||||
return text;
|
||||
}
|
||||
|
||||
private static synchronized void initEmojiData(Context context) {
|
||||
public static synchronized EmojiManager getEmojiManager(final Context context) {
|
||||
// Do a lazy initialisation not to slowdown the startup and when it is needed
|
||||
if (!isEmojiDataInitialised) {
|
||||
EmojiManager.initEmojiData(context);
|
||||
isEmojiDataInitialised = true;
|
||||
if (emojiManagerInstance == null) {
|
||||
emojiManagerInstance = EmojiManager.Companion.create(context, new GsonDeserializer());
|
||||
}
|
||||
return emojiManagerInstance;
|
||||
}
|
||||
|
||||
private static String convertAdvancedEmojiToAscii(String text, Context context) {
|
||||
initEmojiData(context);
|
||||
private static String convertAdvancedEmojiToAscii(final String text, final Context context) {
|
||||
final EmojiManager emojiManager = getEmojiManager(context);
|
||||
try {
|
||||
return EmojiUtils.shortCodify(text);
|
||||
} catch (Exception e){
|
||||
LOG.warn("An exception occured when converting advanced emoji to ASCII: " + text);
|
||||
return EmojiParserKt.parseFromUnicode(emojiManager, text, EMOJI_TRANSFORMER_NO_FITZPATRICK);
|
||||
} catch (final Exception e) {
|
||||
LOG.warn("An exception occurred when converting advanced emoji to ASCII: {}", text);
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertUnicodeEmojiToAscii(String text, Context context) {
|
||||
public static String convertUnicodeEmojiToAscii(String text, final Context context) {
|
||||
text = convertSimpleEmojiToAscii(text);
|
||||
|
||||
text = convertAdvancedEmojiToAscii(text, context);
|
||||
|
@ -0,0 +1,53 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.test.TestBase;
|
||||
|
||||
public class EmojiConverterTest extends TestBase {
|
||||
@Test
|
||||
public void testConvert() {
|
||||
final Map<String, String> snippets = new HashMap<String, String>() {{
|
||||
put(
|
||||
"no emoji",
|
||||
"no emoji"
|
||||
);
|
||||
|
||||
put(
|
||||
"Hello! \uD83D\uDE0A",
|
||||
"Hello! :-)"
|
||||
);
|
||||
|
||||
put(
|
||||
"\uD83D\uDE1B hi",
|
||||
":-P hi"
|
||||
);
|
||||
|
||||
put(
|
||||
"\uD83D\uDC7B\uD83D\uDC80",
|
||||
":ghost::skull:"
|
||||
);
|
||||
|
||||
put(
|
||||
"also \uD83D\uDE36 with words \uD83D\uDCAA\uD83C\uDFFC in-between \uD83D\uDE09",
|
||||
"also :no_mouth: with words :muscle: in-between ;-)"
|
||||
);
|
||||
}};
|
||||
|
||||
for (final Map.Entry<String, String> e : snippets.entrySet()) {
|
||||
assertEquals(
|
||||
e.getValue(),
|
||||
EmojiConverter.convertUnicodeEmojiToAscii(
|
||||
e.getKey(),
|
||||
RuntimeEnvironment.getApplication()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user