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 0edf91718..da4fa9a06 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.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; +import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ADD_CALENDAREVENT; @@ -322,21 +323,23 @@ public class DeviceCommunicationService extends Service implements SharedPrefere break; case ACTION_NOTIFICATION: { NotificationSpec notificationSpec = new NotificationSpec(); - notificationSpec.phoneNumber = intent.getStringExtra(EXTRA_NOTIFICATION_PHONENUMBER); - notificationSpec.sender = intent.getStringExtra(EXTRA_NOTIFICATION_SENDER); - notificationSpec.subject = intent.getStringExtra(EXTRA_NOTIFICATION_SUBJECT); - notificationSpec.title = intent.getStringExtra(EXTRA_NOTIFICATION_TITLE); - notificationSpec.body = intent.getStringExtra(EXTRA_NOTIFICATION_BODY); + notificationSpec.phoneNumber = getStringExtra(intent, EXTRA_NOTIFICATION_PHONENUMBER); + notificationSpec.sender = getStringExtra(intent, EXTRA_NOTIFICATION_SENDER); + notificationSpec.subject = getStringExtra(intent, EXTRA_NOTIFICATION_SUBJECT); + notificationSpec.title = getStringExtra(intent, EXTRA_NOTIFICATION_TITLE); + notificationSpec.body = getStringExtra(intent, EXTRA_NOTIFICATION_BODY); + notificationSpec.sourceName = getStringExtra(intent, EXTRA_NOTIFICATION_SOURCENAME); notificationSpec.type = (NotificationType) intent.getSerializableExtra(EXTRA_NOTIFICATION_TYPE); notificationSpec.id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); notificationSpec.flags = intent.getIntExtra(EXTRA_NOTIFICATION_FLAGS, 0); - notificationSpec.sourceName = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCENAME); + if (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null) { notificationSpec.sender = getContactDisplayNameByNumber(notificationSpec.phoneNumber); notificationSpec.id = mRandom.nextInt(); // FIXME: add this in external SMS Receiver? GBApplication.getIDSenderLookup().add(notificationSpec.id, notificationSpec.phoneNumber); } + if (((notificationSpec.flags & NotificationSpec.FLAG_WEARABLE_REPLY) > 0) || (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null)) { // NOTE: maybe not where it belongs @@ -353,6 +356,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere notificationSpec.cannedReplies = replies.toArray(new String[replies.size()]); } } + mDeviceSupport.onNotification(notificationSpec); break; } @@ -366,8 +370,8 @@ public class DeviceCommunicationService extends Service implements SharedPrefere calendarEventSpec.type = intent.getByteExtra(EXTRA_CALENDAREVENT_TYPE, (byte) -1); calendarEventSpec.timestamp = intent.getIntExtra(EXTRA_CALENDAREVENT_TIMESTAMP, -1); calendarEventSpec.durationInSeconds = intent.getIntExtra(EXTRA_CALENDAREVENT_DURATION, -1); - calendarEventSpec.title = intent.getStringExtra(EXTRA_CALENDAREVENT_TITLE); - calendarEventSpec.description = intent.getStringExtra(EXTRA_CALENDAREVENT_DESCRIPTION); + calendarEventSpec.title = getStringExtra(intent, EXTRA_CALENDAREVENT_TITLE); + calendarEventSpec.description = getStringExtra(intent, EXTRA_CALENDAREVENT_DESCRIPTION); mDeviceSupport.onAddCalendarEvent(calendarEventSpec); break; } @@ -412,7 +416,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere case ACTION_CALLSTATE: int command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED); - String phoneNumber = intent.getStringExtra(EXTRA_CALL_PHONENUMBER); + String phoneNumber = getStringExtra(intent, EXTRA_CALL_PHONENUMBER); String callerName = null; if (phoneNumber != null) { callerName = getContactDisplayNameByNumber(phoneNumber); @@ -438,9 +442,9 @@ public class DeviceCommunicationService extends Service implements SharedPrefere break; case ACTION_SETMUSICINFO: MusicSpec musicSpec = new MusicSpec(); - musicSpec.artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST); - musicSpec.album = intent.getStringExtra(EXTRA_MUSIC_ALBUM); - musicSpec.track = intent.getStringExtra(EXTRA_MUSIC_TRACK); + musicSpec.artist = getStringExtra(intent, EXTRA_MUSIC_ARTIST); + musicSpec.album = getStringExtra(intent, EXTRA_MUSIC_ALBUM); + musicSpec.track = getStringExtra(intent, EXTRA_MUSIC_TRACK); musicSpec.duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0); musicSpec.trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0); musicSpec.trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0); @@ -703,7 +707,18 @@ public class DeviceCommunicationService extends Service implements SharedPrefere // ignore, just return name below } - return name; + return LanguageUtils.transliterate() + ? LanguageUtils.transliterate(name) + : name; + } + + //Standard method with transliteration + private String getStringExtra(Intent intent, String event){ + String extra = intent.getStringExtra(event); + + return LanguageUtils.transliterate() + ? LanguageUtils.transliterate(extra) + : extra; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java index 3575e8c55..73072c51b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java @@ -38,7 +38,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSuppo import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction; -import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.AbstractBleProfile; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile; import nodomain.freeyourgadget.gadgetbridge.util.GB; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LanguageUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LanguageUtils.java new file mode 100644 index 000000000..59d7aa817 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LanguageUtils.java @@ -0,0 +1,73 @@ +package nodomain.freeyourgadget.gadgetbridge.util; + +import java.util.HashMap; +import java.util.Map; +import java.text.Normalizer; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; + +public class LanguageUtils { + //transliteration map with english equivalent for unsupported chars + private static Map transliterateMap = new HashMap(){ + { + //extended ASCII characters + put('æ', "ae"); put('œ', "oe"); put('ß', "B"); put('ª', "a"); put('º', "o"); put('«',"\""); put('»',"\""); + + //russian chars + put('а', "a"); put('б', "b"); put('в', "v"); put('г', "g"); put('д', "d"); put('е', "e"); put('ё', "jo"); put('ж', "zh"); + put('з', "z"); put('и', "i"); put('й', "jj"); put('к', "k"); put('л', "l"); put('м', "m"); put('н', "n"); put('о', "o"); + put('п', "p"); put('р', "r"); put('с', "s"); put('т', "t"); put('у', "u"); put('ф', "f"); put('х', "kh"); put('ц', "c"); + put('ч', "ch");put('ш', "sh");put('щ', "shh");put('ъ', "\"");put('ы', "y"); put('ь', "'"); put('э', "eh"); put('ю', "ju"); + put('я', "ja"); + + //continue for other languages... + } + }; + + //check transliterate option status + public static boolean transliterate() + { + return GBApplication.getPrefs().getBoolean("transliteration", false); + } + + //replace unsupported symbols to english analog + public static String transliterate(String txt){ + if (txt == null || txt.isEmpty()) { + return txt; + } + + StringBuilder message = new StringBuilder(); + + char[] chars = txt.toCharArray(); + + for (char c : chars) + { + message.append(transliterate(c)); + } + + return flattenToAscii(message.toString()); + } + + //replace unsupported symbol to english analog text + private static String transliterate(char c){ + char lowerChar = Character.toLowerCase(c); + + if (transliterateMap.containsKey(lowerChar)) { + String replace = transliterateMap.get(lowerChar); + + if (lowerChar != c) + { + return replace.toUpperCase(); + } + + return replace; + } + + return String.valueOf(c); + } + + //convert diacritic + private static String flattenToAscii(String string) { + string = Normalizer.normalize(string, Normalizer.Form.NFD); + return string.replaceAll("\\p{M}", ""); + } +} diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 7284db28f..2ed467a6b 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -52,6 +52,8 @@ … даже когда экран включён Не беспокоить Предотвращать отправку нежелательных уведомлений в режиме \"Не беспокоить\" + Транслитерация + Используйте, если устройство не может работать с вашим языком всегда когда экран выключен никогда diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0667156fd..e219e6106 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -81,6 +81,8 @@ … also when screen is on Do Not Disturb Stop unwanted Notifications from being sent based on the Do Not Disturb mode. + Transliteration + Use, if the device can not work with your language always when screen is off diff --git a/app/src/main/res/xml/changelog_master.xml b/app/src/main/res/xml/changelog_master.xml index 1d0c0a2bc..fe8e91799 100644 --- a/app/src/main/res/xml/changelog_master.xml +++ b/app/src/main/res/xml/changelog_master.xml @@ -8,7 +8,10 @@ Add weather support through "Weather Notification" app Various fixes for K9 mail when using the generic notification receiver + Added transliteration support for Russian characters into English + Added transliteration option in the settings screen Add a preference to hide the notification icon of Gadgetbridge + Pebble: Support for build-in weather system app (FW 4.x) Pebble: Add weather support for various watchfaces Pebble: Add option to automatically delete notifications that got dismissed on the phone diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index c8f1964e1..39c7d9ed9 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -91,6 +91,13 @@ android:key="notifications_generic_whenscreenon" android:title="@string/pref_title_whenscreenon" /> + +