mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 01:55:50 +01:00
Amazfit Bip: Add emoji support when using custom font firmware
This commit is contained in:
parent
42049095a2
commit
b40c3ade85
@ -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;
|
||||
|
@ -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).
|
||||
*/
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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[]{
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -167,6 +167,8 @@
|
||||
<string name="pref_title_pebble_reconnect_attempts">Reconnection attempts</string>
|
||||
<string name="pref_summary_expose_hr">Allows other apps to access HR data in realtime while Gadgetbridge is connected</string>
|
||||
<string name="pref_title_expose_hr">3rd party realtime HR access</string>
|
||||
<string name="pref_title_use_custom_font">Use custom font</string>
|
||||
<string name="pref_summary_use_custom_font">Enable this if your device has a custom font firmware for emoji support</string>
|
||||
|
||||
<!-- HPlus Preferences -->
|
||||
<string name="pref_title_unit_system">Units</string>
|
||||
|
@ -17,4 +17,10 @@
|
||||
android:key="language"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_title_language" />
|
||||
<CheckBoxPreference
|
||||
android:icon="@drawable/ic_font_download"
|
||||
android:defaultValue="false"
|
||||
android:key="use_custom_font"
|
||||
android:summary="@string/pref_summary_use_custom_font"
|
||||
android:title="@string/pref_title_use_custom_font" />
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
Loading…
Reference in New Issue
Block a user