mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 09:01:55 +01: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.apache.commons:commons-lang3:3.7"
|
||||||
implementation "org.cyanogenmod:platform.sdk:6.0"
|
implementation "org.cyanogenmod:platform.sdk:6.0"
|
||||||
implementation 'com.jaredrummler:colorpicker:1.1.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.google.protobuf:protobuf-javalite:4.27.2'
|
||||||
implementation 'com.android.volley:volley:1.2.1'
|
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 Nordic DFU library
|
||||||
-keep class no.nordicsemi.android.dfu.** { *; }
|
-keep class no.nordicsemi.android.dfu.** { *; }
|
||||||
|
|
||||||
# Keep dependency android-emojify (io.wax911.emojify) uses
|
# For android-emojify - we are not using moshi, so ignore these
|
||||||
-keep class org.hamcrest.** { *; }
|
-dontwarn com.squareup.moshi.**
|
||||||
-dontwarn java.beans.BeanInfo
|
-dontwarn kotlinx.serialization.**
|
||||||
-dontwarn java.beans.IntrospectionException
|
-dontwarn okio.**
|
||||||
-dontwarn java.beans.Introspector
|
|
||||||
-dontwarn java.beans.PropertyDescriptor
|
|
||||||
|
|
||||||
# Keep logback classes
|
# Keep logback classes
|
||||||
-keep class ch.qos.** { *; }
|
-keep class ch.qos.** { *; }
|
||||||
|
@ -108,6 +108,7 @@
|
|||||||
<application
|
<application
|
||||||
android:name=".GBApplication"
|
android:name=".GBApplication"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
|
android:supportsRtl="true"
|
||||||
android:fullBackupContent="false"
|
android:fullBackupContent="false"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
@ -81,6 +81,7 @@ import java.sql.Timestamp;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -95,9 +96,8 @@ import javax.xml.xpath.XPathConstants;
|
|||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
import de.greenrobot.dao.query.QueryBuilder;
|
import de.greenrobot.dao.query.QueryBuilder;
|
||||||
import io.wax911.emojify.Emoji;
|
|
||||||
import io.wax911.emojify.EmojiManager;
|
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.BuildConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
@ -1319,18 +1319,12 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String renderUnicodeWordPartAsImage(String word) {
|
private String renderUnicodeWordPartAsImage(final String word) {
|
||||||
// check for emoji
|
// check for emoji
|
||||||
boolean hasEmoji = false;
|
final EmojiManager emojiManager = EmojiConverter.getEmojiManager(getContext());
|
||||||
if (EmojiUtils.getAllEmojis() == null)
|
final boolean hasEmoji = !EmojiParserKt.extractEmojis(emojiManager, word).isEmpty();
|
||||||
EmojiManager.initEmojiData(GBApplication.getContext());
|
|
||||||
for (Emoji emoji : EmojiUtils.getAllEmojis())
|
|
||||||
if (word.contains(emoji.getEmoji())) {
|
|
||||||
hasEmoji = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// if we had emoji, ensure we create 3 bit color (not 1 bit B&W)
|
// 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);
|
return "\0"+bitmapToEspruinoString(textToBitmap(word), style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,11 +19,20 @@ package nodomain.freeyourgadget.gadgetbridge.util;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import io.wax911.emojify.EmojiManager;
|
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 {
|
public class EmojiConverter {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(EmojiConverter.class);
|
private static final Logger LOG = LoggerFactory.getLogger(EmojiConverter.class);
|
||||||
@ -65,7 +74,27 @@ public class EmojiConverter {
|
|||||||
{"\u2764", "<3"}, // heart
|
{"\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) {
|
private static String convertSimpleEmojiToAscii(String text) {
|
||||||
for (String[] emojiMap : simpleEmojiMapping) {
|
for (String[] emojiMap : simpleEmojiMapping) {
|
||||||
@ -74,25 +103,25 @@ public class EmojiConverter {
|
|||||||
return text;
|
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
|
// Do a lazy initialisation not to slowdown the startup and when it is needed
|
||||||
if (!isEmojiDataInitialised) {
|
if (emojiManagerInstance == null) {
|
||||||
EmojiManager.initEmojiData(context);
|
emojiManagerInstance = EmojiManager.Companion.create(context, new GsonDeserializer());
|
||||||
isEmojiDataInitialised = true;
|
|
||||||
}
|
}
|
||||||
|
return emojiManagerInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String convertAdvancedEmojiToAscii(String text, Context context) {
|
private static String convertAdvancedEmojiToAscii(final String text, final Context context) {
|
||||||
initEmojiData(context);
|
final EmojiManager emojiManager = getEmojiManager(context);
|
||||||
try {
|
try {
|
||||||
return EmojiUtils.shortCodify(text);
|
return EmojiParserKt.parseFromUnicode(emojiManager, text, EMOJI_TRANSFORMER_NO_FITZPATRICK);
|
||||||
} catch (Exception e){
|
} catch (final Exception e) {
|
||||||
LOG.warn("An exception occured when converting advanced emoji to ASCII: " + text);
|
LOG.warn("An exception occurred when converting advanced emoji to ASCII: {}", text);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertUnicodeEmojiToAscii(String text, Context context) {
|
public static String convertUnicodeEmojiToAscii(String text, final Context context) {
|
||||||
text = convertSimpleEmojiToAscii(text);
|
text = convertSimpleEmojiToAscii(text);
|
||||||
|
|
||||||
text = convertAdvancedEmojiToAscii(text, context);
|
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