1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-08 19:27:04 +01:00

Moving transliteration call from module "HPlus" to common support

This commit is contained in:
ivanovlev 2017-01-17 23:07:12 +03:00
parent bfe24dd9f0
commit cbc91e7fef
3 changed files with 29 additions and 24 deletions

View File

@ -51,6 +51,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ADD_CALENDAREVENT; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ADD_CALENDAREVENT;
@ -322,21 +323,23 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
break; break;
case ACTION_NOTIFICATION: { case ACTION_NOTIFICATION: {
NotificationSpec notificationSpec = new NotificationSpec(); NotificationSpec notificationSpec = new NotificationSpec();
notificationSpec.phoneNumber = intent.getStringExtra(EXTRA_NOTIFICATION_PHONENUMBER); notificationSpec.phoneNumber = getStringExtra(intent, EXTRA_NOTIFICATION_PHONENUMBER);
notificationSpec.sender = intent.getStringExtra(EXTRA_NOTIFICATION_SENDER); notificationSpec.sender = getStringExtra(intent, EXTRA_NOTIFICATION_SENDER);
notificationSpec.subject = intent.getStringExtra(EXTRA_NOTIFICATION_SUBJECT); notificationSpec.subject = getStringExtra(intent, EXTRA_NOTIFICATION_SUBJECT);
notificationSpec.title = intent.getStringExtra(EXTRA_NOTIFICATION_TITLE); notificationSpec.title = getStringExtra(intent, EXTRA_NOTIFICATION_TITLE);
notificationSpec.body = intent.getStringExtra(EXTRA_NOTIFICATION_BODY); notificationSpec.body = getStringExtra(intent, EXTRA_NOTIFICATION_BODY);
notificationSpec.sourceName = getStringExtra(intent, EXTRA_NOTIFICATION_SOURCENAME);
notificationSpec.type = (NotificationType) intent.getSerializableExtra(EXTRA_NOTIFICATION_TYPE); notificationSpec.type = (NotificationType) intent.getSerializableExtra(EXTRA_NOTIFICATION_TYPE);
notificationSpec.id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); notificationSpec.id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
notificationSpec.flags = intent.getIntExtra(EXTRA_NOTIFICATION_FLAGS, 0); notificationSpec.flags = intent.getIntExtra(EXTRA_NOTIFICATION_FLAGS, 0);
notificationSpec.sourceName = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCENAME);
if (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null) { if (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null) {
notificationSpec.sender = getContactDisplayNameByNumber(notificationSpec.phoneNumber); notificationSpec.sender = getContactDisplayNameByNumber(notificationSpec.phoneNumber);
notificationSpec.id = mRandom.nextInt(); // FIXME: add this in external SMS Receiver? notificationSpec.id = mRandom.nextInt(); // FIXME: add this in external SMS Receiver?
GBApplication.getIDSenderLookup().add(notificationSpec.id, notificationSpec.phoneNumber); GBApplication.getIDSenderLookup().add(notificationSpec.id, notificationSpec.phoneNumber);
} }
if (((notificationSpec.flags & NotificationSpec.FLAG_WEARABLE_REPLY) > 0) if (((notificationSpec.flags & NotificationSpec.FLAG_WEARABLE_REPLY) > 0)
|| (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null)) { || (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null)) {
// NOTE: maybe not where it belongs // 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()]); notificationSpec.cannedReplies = replies.toArray(new String[replies.size()]);
} }
} }
mDeviceSupport.onNotification(notificationSpec); mDeviceSupport.onNotification(notificationSpec);
break; break;
} }
@ -366,8 +370,8 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
calendarEventSpec.type = intent.getByteExtra(EXTRA_CALENDAREVENT_TYPE, (byte) -1); calendarEventSpec.type = intent.getByteExtra(EXTRA_CALENDAREVENT_TYPE, (byte) -1);
calendarEventSpec.timestamp = intent.getIntExtra(EXTRA_CALENDAREVENT_TIMESTAMP, -1); calendarEventSpec.timestamp = intent.getIntExtra(EXTRA_CALENDAREVENT_TIMESTAMP, -1);
calendarEventSpec.durationInSeconds = intent.getIntExtra(EXTRA_CALENDAREVENT_DURATION, -1); calendarEventSpec.durationInSeconds = intent.getIntExtra(EXTRA_CALENDAREVENT_DURATION, -1);
calendarEventSpec.title = intent.getStringExtra(EXTRA_CALENDAREVENT_TITLE); calendarEventSpec.title = getStringExtra(intent, EXTRA_CALENDAREVENT_TITLE);
calendarEventSpec.description = intent.getStringExtra(EXTRA_CALENDAREVENT_DESCRIPTION); calendarEventSpec.description = getStringExtra(intent, EXTRA_CALENDAREVENT_DESCRIPTION);
mDeviceSupport.onAddCalendarEvent(calendarEventSpec); mDeviceSupport.onAddCalendarEvent(calendarEventSpec);
break; break;
} }
@ -412,7 +416,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
case ACTION_CALLSTATE: case ACTION_CALLSTATE:
int command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED); 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; String callerName = null;
if (phoneNumber != null) { if (phoneNumber != null) {
callerName = getContactDisplayNameByNumber(phoneNumber); callerName = getContactDisplayNameByNumber(phoneNumber);
@ -438,9 +442,9 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
break; break;
case ACTION_SETMUSICINFO: case ACTION_SETMUSICINFO:
MusicSpec musicSpec = new MusicSpec(); MusicSpec musicSpec = new MusicSpec();
musicSpec.artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST); musicSpec.artist = getStringExtra(intent, EXTRA_MUSIC_ARTIST);
musicSpec.album = intent.getStringExtra(EXTRA_MUSIC_ALBUM); musicSpec.album = getStringExtra(intent, EXTRA_MUSIC_ALBUM);
musicSpec.track = intent.getStringExtra(EXTRA_MUSIC_TRACK); musicSpec.track = getStringExtra(intent, EXTRA_MUSIC_TRACK);
musicSpec.duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0); musicSpec.duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0);
musicSpec.trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0); musicSpec.trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0);
musicSpec.trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 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 // 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 @Override

View File

@ -41,7 +41,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateA
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils;
public class HPlusSupport extends AbstractBTLEDeviceSupport { public class HPlusSupport extends AbstractBTLEDeviceSupport {
@ -647,10 +646,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
try { try {
TransactionBuilder builder = performInitialized("incomingCallIcon"); TransactionBuilder builder = performInitialized("incomingCallIcon");
if (LanguageUtils.transliterate()) {
name = LanguageUtils.transliterate(name);
}
//Enable call notifications //Enable call notifications
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_ACTION_INCOMING_CALL, 1}); builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_ACTION_INCOMING_CALL, 1});
@ -708,11 +703,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
try { try {
TransactionBuilder builder = performInitialized("notification"); TransactionBuilder builder = performInitialized("notification");
if (LanguageUtils.transliterate()) {
title = LanguageUtils.transliterate(title);
body = LanguageUtils.transliterate(body);
}
byte[] msg = new byte[20]; byte[] msg = new byte[20];
for (int i = 0; i < msg.length; i++) for (int i = 0; i < msg.length; i++)
msg[i] = ' '; msg[i] = ' ';

View File

@ -10,7 +10,7 @@ public class LanguageUtils {
private static Map<Character, String> transliterateMap = new HashMap<Character, String>(){ private static Map<Character, String> transliterateMap = new HashMap<Character, String>(){
{ {
//extended ASCII characters //extended ASCII characters
put('æ', "ae"); put('œ', "oe"); put('ß', "B"); put('ª', "a"); put('º', "o"); put('æ', "ae"); put('œ', "oe"); put('ß', "B"); put('ª', "a"); put('º', "o"); put('«',"\""); put('»',"\"");
//russian chars //russian chars
put('а', "a"); put('б', "b"); put('в', "v"); put('г', "g"); put('д', "d"); put('е', "e"); put('ё', "jo"); put('ж', "zh"); put('а', "a"); put('б', "b"); put('в', "v"); put('г', "g"); put('д', "d"); put('е', "e"); put('ё', "jo"); put('ж', "zh");