mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Simplification of transliteration integration
This commit is contained in:
parent
31ccaf361b
commit
06295abcb6
@ -180,9 +180,10 @@ public class DebugActivity extends GBActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
MusicSpec musicSpec = new MusicSpec();
|
MusicSpec musicSpec = new MusicSpec();
|
||||||
musicSpec.artist = editContent.getText().toString() + "(artist)";
|
String testString = editContent.getText().toString();
|
||||||
musicSpec.album = editContent.getText().toString() + "(album)";
|
musicSpec.artist = testString + "(artist)";
|
||||||
musicSpec.track = editContent.getText().toString() + "(track)";
|
musicSpec.album = testString + "(album)";
|
||||||
|
musicSpec.track = testString + "(track)";
|
||||||
musicSpec.duration = 10;
|
musicSpec.duration = 10;
|
||||||
musicSpec.trackCount = 5;
|
musicSpec.trackCount = 5;
|
||||||
musicSpec.trackNr = 2;
|
musicSpec.trackNr = 2;
|
||||||
|
@ -19,10 +19,25 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils;
|
||||||
|
|
||||||
public class GBDeviceService implements DeviceService {
|
public class GBDeviceService implements DeviceService {
|
||||||
protected final Context mContext;
|
protected final Context mContext;
|
||||||
private final Class<? extends Service> mServiceClass;
|
private final Class<? extends Service> mServiceClass;
|
||||||
|
private final String[] transliterationExtras = new String[]{
|
||||||
|
EXTRA_NOTIFICATION_PHONENUMBER,
|
||||||
|
EXTRA_NOTIFICATION_SENDER,
|
||||||
|
EXTRA_NOTIFICATION_SUBJECT,
|
||||||
|
EXTRA_NOTIFICATION_TITLE,
|
||||||
|
EXTRA_NOTIFICATION_BODY,
|
||||||
|
EXTRA_NOTIFICATION_SOURCENAME,
|
||||||
|
EXTRA_CALL_PHONENUMBER,
|
||||||
|
EXTRA_MUSIC_ARTIST,
|
||||||
|
EXTRA_MUSIC_ALBUM,
|
||||||
|
EXTRA_MUSIC_TRACK,
|
||||||
|
EXTRA_CALENDAREVENT_TITLE,
|
||||||
|
EXTRA_CALENDAREVENT_DESCRIPTION
|
||||||
|
};
|
||||||
|
|
||||||
public GBDeviceService(Context context) {
|
public GBDeviceService(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@ -34,6 +49,14 @@ public class GBDeviceService implements DeviceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void invokeService(Intent intent) {
|
protected void invokeService(Intent intent) {
|
||||||
|
if(LanguageUtils.transliterate()){
|
||||||
|
for (String extra: transliterationExtras) {
|
||||||
|
if (intent.hasExtra(extra)){
|
||||||
|
intent.putExtra(extra, LanguageUtils.transliterate(intent.getStringExtra(extra)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mContext.startService(intent);
|
mContext.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,6 @@ 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;
|
||||||
@ -323,12 +322,12 @@ 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 = getStringExtra(intent, EXTRA_NOTIFICATION_PHONENUMBER);
|
notificationSpec.phoneNumber = intent.getStringExtra(EXTRA_NOTIFICATION_PHONENUMBER);
|
||||||
notificationSpec.sender = getStringExtra(intent, EXTRA_NOTIFICATION_SENDER);
|
notificationSpec.sender = intent.getStringExtra(EXTRA_NOTIFICATION_SENDER);
|
||||||
notificationSpec.subject = getStringExtra(intent, EXTRA_NOTIFICATION_SUBJECT);
|
notificationSpec.subject = intent.getStringExtra(EXTRA_NOTIFICATION_SUBJECT);
|
||||||
notificationSpec.title = getStringExtra(intent, EXTRA_NOTIFICATION_TITLE);
|
notificationSpec.title = intent.getStringExtra(EXTRA_NOTIFICATION_TITLE);
|
||||||
notificationSpec.body = getStringExtra(intent, EXTRA_NOTIFICATION_BODY);
|
notificationSpec.body = intent.getStringExtra(EXTRA_NOTIFICATION_BODY);
|
||||||
notificationSpec.sourceName = getStringExtra(intent, EXTRA_NOTIFICATION_SOURCENAME);
|
notificationSpec.sourceName = intent.getStringExtra(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);
|
||||||
@ -370,8 +369,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 = getStringExtra(intent, EXTRA_CALENDAREVENT_TITLE);
|
calendarEventSpec.title = intent.getStringExtra(EXTRA_CALENDAREVENT_TITLE);
|
||||||
calendarEventSpec.description = getStringExtra(intent, EXTRA_CALENDAREVENT_DESCRIPTION);
|
calendarEventSpec.description = intent.getStringExtra(EXTRA_CALENDAREVENT_DESCRIPTION);
|
||||||
mDeviceSupport.onAddCalendarEvent(calendarEventSpec);
|
mDeviceSupport.onAddCalendarEvent(calendarEventSpec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -416,7 +415,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 = getStringExtra(intent, EXTRA_CALL_PHONENUMBER);
|
String phoneNumber = intent.getStringExtra(EXTRA_CALL_PHONENUMBER);
|
||||||
String callerName = null;
|
String callerName = null;
|
||||||
if (phoneNumber != null) {
|
if (phoneNumber != null) {
|
||||||
callerName = getContactDisplayNameByNumber(phoneNumber);
|
callerName = getContactDisplayNameByNumber(phoneNumber);
|
||||||
@ -442,9 +441,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 = getStringExtra(intent, EXTRA_MUSIC_ARTIST);
|
musicSpec.artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST);
|
||||||
musicSpec.album = getStringExtra(intent, EXTRA_MUSIC_ALBUM);
|
musicSpec.album = intent.getStringExtra(EXTRA_MUSIC_ALBUM);
|
||||||
musicSpec.track = getStringExtra(intent, EXTRA_MUSIC_TRACK);
|
musicSpec.track = intent.getStringExtra(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);
|
||||||
@ -707,18 +706,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
// ignore, just return name below
|
// ignore, just return name below
|
||||||
}
|
}
|
||||||
|
|
||||||
return LanguageUtils.transliterate()
|
return name;
|
||||||
? 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
|
||||||
|
Loading…
Reference in New Issue
Block a user