diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java index 9f155c76e..d1466f573 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java @@ -153,6 +153,9 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator { @Override public boolean supportsUnicodeEmojis() { return false; } + @Override + public boolean supportsCustomFont() { return false; } + @Override public int[] getSupportedDeviceSpecificSettings(GBDevice device) { return null; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java index a9d7fd7e7..6b1049959 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java @@ -280,6 +280,11 @@ public interface DeviceCoordinator { */ boolean supportsUnicodeEmojis(); + /** + * Indicates whether the device supports using a custom font. + */ + boolean supportsCustomFont(); + /** * Indicates which device specific settings the device supports (not per device type or family, but unique per device). */ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java index fe47cb21f..c4ccca2bf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java @@ -62,6 +62,7 @@ public class HuamiConst { public static final String PREF_LANGUAGE = "language"; public static final String PREF_DATEFORMAT = "dateformat"; public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty"; + public static final String PREF_USE_CUSTOM_FONT = "use_custom_font"; public static int toActivityKind(int rawType) { switch (rawType) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java index d7bf1d353..2ec92bdf7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java @@ -197,6 +197,11 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator { return prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, null); } + public static boolean getUseCustomFont(String deviceAddress) { + SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress); + return prefs.getBoolean(HuamiConst.PREF_USE_CUSTOM_FONT, false); + } + public static boolean getGoalNotification() { Prefs prefs = GBApplication.getPrefs(); return prefs.getBoolean(MiBandConst.PREF_MI2_GOAL_NOTIFICATION, false); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java index 1971dd48c..73c82aded 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java @@ -77,6 +77,11 @@ public class AmazfitBipCoordinator extends HuamiCoordinator { return true; } + @Override + public boolean supportsCustomFont() { + return true; + } + @Override public int[] getSupportedDeviceSpecificSettings(GBDevice device) { return new int[]{ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index 152d457d1..4d3d439d0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -51,6 +51,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; +import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmClockReceiver; import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver; import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver; @@ -80,6 +81,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.EmojiConverter; import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; +import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ADD_CALENDAREVENT; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_APP_CONFIGURE; @@ -368,8 +370,23 @@ public class DeviceCommunicationService extends Service implements SharedPrefere if (text == null || text.length() == 0) return text; - if (!mCoordinator.supportsUnicodeEmojis()) + if (!mCoordinator.supportsUnicodeEmojis()) { + + // use custom font for emoji, if it is supported and enabled + if (mCoordinator.supportsCustomFont()) { + switch (mCoordinator.getDeviceType()) { + case AMAZFITBIP: + if (((HuamiCoordinator)mCoordinator).getUseCustomFont(mGBDevice.getAddress())) + return StringUtils.toCustomFont(text); + break; + // TODO: implement for Amazfit Cor + default: + break; + } + } + return EmojiConverter.convertUnicodeEmojiToAscii(text, getApplicationContext()); + } return text; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/StringUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/StringUtils.java index 007853deb..89dedbd24 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/StringUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/StringUtils.java @@ -96,4 +96,36 @@ public class StringUtils { } return ""; } + + /** + * @param str original text + * @return str with the emoticons in a format that can be displayed on an + * Amazfit Bip by using a custom font firmware with emoji support + */ + public static String toCustomFont(String str) { + StringBuilder sb = new StringBuilder(); + int i = 0; + while (i < str.length()) { + char charAt = str.charAt(i); + if (Character.isHighSurrogate(charAt)) { + int i2 = i + 1; + try { + int codePoint = Character.toCodePoint(charAt, str.charAt(i2)); + if (codePoint < 127744 || codePoint > 129510) { + sb.append(charAt); + } else { + sb.append(Character.toString((char) (codePoint - 83712))); + i = i2; + } + } catch (StringIndexOutOfBoundsException e) { + e.printStackTrace(); + sb.append(charAt); + } + } else { + sb.append(charAt); + } + i++; + } + return sb.toString(); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 16289fdc8..96cc3b117 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -167,6 +167,8 @@ Reconnection attempts Allows other apps to access HR data in realtime while Gadgetbridge is connected 3rd party realtime HR access + Use custom font + Enable this if your device has a custom font firmware for emoji support Units diff --git a/app/src/main/res/xml/devicesettings_amazfitbip.xml b/app/src/main/res/xml/devicesettings_amazfitbip.xml index d2133e176..e469798bd 100644 --- a/app/src/main/res/xml/devicesettings_amazfitbip.xml +++ b/app/src/main/res/xml/devicesettings_amazfitbip.xml @@ -17,4 +17,10 @@ android:key="language" android:summary="%s" android:title="@string/pref_title_language" /> +