mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 19:06:53 +01:00
Transliteration is moved to a separate class, added settings option
This commit is contained in:
parent
b9249065eb
commit
074394cba4
@ -77,7 +77,6 @@ dependencies {
|
||||
compile 'org.apache.commons:commons-lang3:3.4'
|
||||
|
||||
// compile project(":DaoCore")
|
||||
compile 'com.google.guava:guava:19.0'
|
||||
}
|
||||
|
||||
preBuild.dependsOn(":GBDaoGenerator:genSources")
|
||||
|
@ -14,8 +14,6 @@ import android.net.Uri;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -23,7 +21,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
|
||||
@ -41,10 +38,10 @@ 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;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils;
|
||||
|
||||
|
||||
public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
@ -649,7 +646,10 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
private void showIncomingCall(String name, String number) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("incomingCallIcon");
|
||||
name = transliterate(name);
|
||||
|
||||
if (LanguageUtils.transliterate()) {
|
||||
name = LanguageUtils.transliterate(name);
|
||||
}
|
||||
|
||||
//Enable call notifications
|
||||
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_ACTION_INCOMING_CALL, 1});
|
||||
@ -707,8 +707,11 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
LOG.debug("Show Notification: "+title+" --> "+body);
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("notification");
|
||||
title = transliterate(title);
|
||||
body = transliterate(body);
|
||||
|
||||
if (LanguageUtils.transliterate()) {
|
||||
title = LanguageUtils.transliterate(title);
|
||||
body = LanguageUtils.transliterate(body);
|
||||
}
|
||||
|
||||
byte[] msg = new byte[20];
|
||||
for (int i = 0; i < msg.length; i++)
|
||||
@ -783,54 +786,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
//replace unsupported symbols to english analog
|
||||
private 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 message.toString();
|
||||
}
|
||||
|
||||
//replace unsupported symbol to english analog text
|
||||
private String transliterate(char c){
|
||||
Map<Character, String> map = ImmutableMap.<Character, String>builder()
|
||||
.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")
|
||||
.build();
|
||||
|
||||
char lowerChar = Character.toLowerCase(c);
|
||||
|
||||
if (map.containsKey(lowerChar)) {
|
||||
String replace = map.get(lowerChar);
|
||||
|
||||
if (lowerChar != c)
|
||||
{
|
||||
return replace.toUpperCase();
|
||||
}
|
||||
|
||||
return replace;
|
||||
}
|
||||
|
||||
return String.valueOf(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCharacteristicChanged(BluetoothGatt gatt,
|
||||
BluetoothGattCharacteristic characteristic) {
|
||||
|
@ -0,0 +1,64 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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>(){
|
||||
{
|
||||
//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", true);
|
||||
}
|
||||
|
||||
//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 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);
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
@ -80,6 +80,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>
|
||||
|
@ -2,7 +2,8 @@
|
||||
<changelog>
|
||||
<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>Various fixes for K9 mail when using the generic notification receiver</change>
|
||||
<change>Added transliteration option for notifications in the settings screen</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: 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