mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 10:56:50 +01:00
Merge pull request #500 from ivanovlev/master
Transliterate unsupported Russian characters into English
This commit is contained in:
commit
31ccaf361b
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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<Character, String> transliterateMap = new HashMap<Character, String>(){
|
||||
{
|
||||
//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}", "");
|
||||
}
|
||||
}
|
@ -52,6 +52,8 @@
|
||||
<string name="pref_title_whenscreenon">… даже когда экран включён</string>
|
||||
<string name="pref_title_notification_filter">Не беспокоить</string>
|
||||
<string name="pref_summary_notification_filter">Предотвращать отправку нежелательных уведомлений в режиме \"Не беспокоить\"</string>
|
||||
<string name="pref_title_transliteration">Транслитерация</string>
|
||||
<string name="pref_summary_transliteration">Используйте, если устройство не может работать с вашим языком</string>
|
||||
<string name="always">всегда</string>
|
||||
<string name="when_screen_off">когда экран выключен</string>
|
||||
<string name="never">никогда</string>
|
||||
|
@ -81,6 +81,8 @@
|
||||
<string name="pref_title_whenscreenon">… also when screen is on</string>
|
||||
<string name="pref_title_notification_filter">Do Not Disturb</string>
|
||||
<string name="pref_summary_notification_filter">Stop unwanted Notifications from being sent based on the Do Not Disturb mode.</string>
|
||||
<string name="pref_title_transliteration">Transliteration</string>
|
||||
<string name="pref_summary_transliteration">Use, if the device can not work with your language</string>
|
||||
|
||||
<string name="always">always</string>
|
||||
<string name="when_screen_off">when screen is off</string>
|
||||
|
@ -8,7 +8,10 @@
|
||||
<release version="0.17.0" versioncode="81">
|
||||
<change>Add weather support through "Weather Notification" app</change>
|
||||
<change>Various fixes for K9 mail when using the generic notification receiver</change>
|
||||
<change>Added transliteration support for Russian characters into English</change>
|
||||
<change>Added transliteration option in the settings screen</change>
|
||||
<change>Add a preference to hide the notification icon of Gadgetbridge</change>
|
||||
|
||||
<change>Pebble: Support for build-in weather system app (FW 4.x)</change>
|
||||
<change>Pebble: Add weather support for various watchfaces</change>
|
||||
<change>Pebble: Add option to automatically delete notifications that got dismissed on the phone</change>
|
||||
|
@ -91,6 +91,13 @@
|
||||
android:key="notifications_generic_whenscreenon"
|
||||
android:title="@string/pref_title_whenscreenon" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="transliteration"
|
||||
android:summary="@string/pref_summary_transliteration"
|
||||
android:title="@string/pref_title_transliteration"
|
||||
/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="notification_filter"
|
||||
|
Loading…
Reference in New Issue
Block a user