1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 06:22:55 +01:00

Transliterate unsupported Russian characters into English

This commit is contained in:
ivanovlev 2017-01-14 02:39:36 +03:00
parent 38e234552d
commit c873312831
3 changed files with 51 additions and 0 deletions

View File

@ -77,6 +77,7 @@ dependencies {
compile 'org.apache.commons:commons-lang3:3.4' compile 'org.apache.commons:commons-lang3:3.4'
// compile project(":DaoCore") // compile project(":DaoCore")
compile 'com.google.guava:guava:19.0'
} }
preBuild.dependsOn(":GBDaoGenerator:genSources") preBuild.dependsOn(":GBDaoGenerator:genSources")

View File

@ -14,6 +14,8 @@ import android.net.Uri;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.widget.Toast; import android.widget.Toast;
import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -21,6 +23,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants; import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
@ -646,6 +649,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private void showIncomingCall(String name, String number) { private void showIncomingCall(String name, String number) {
try { try {
TransactionBuilder builder = performInitialized("incomingCallIcon"); TransactionBuilder builder = performInitialized("incomingCallIcon");
name = 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});
@ -703,6 +707,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
LOG.debug("Show Notification: "+title+" --> "+body); LOG.debug("Show Notification: "+title+" --> "+body);
try { try {
TransactionBuilder builder = performInitialized("notification"); TransactionBuilder builder = performInitialized("notification");
title = transliterate(title);
body = 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++)
@ -777,6 +783,49 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
} }
} }
//replace unsupported symbols to english analog
private String transliterate(String 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 @Override
public boolean onCharacteristicChanged(BluetoothGatt gatt, public boolean onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) { BluetoothGattCharacteristic characteristic) {

View File

@ -16,6 +16,7 @@
<change>HPlus: Near real time Heart rate measurement</change> <change>HPlus: Near real time Heart rate measurement</change>
<change>HPlus: Experimental synchronization of activity data (only sleep, steps and intensity)</change> <change>HPlus: Experimental synchronization of activity data (only sleep, steps and intensity)</change>
<change>HPlus: Fix some disconnection issues</change> <change>HPlus: Fix some disconnection issues</change>
<change>HPlus: Transliterate unsupported Russian characters into English</change>
</release> </release>
<release version="0.16.0" versioncode="80"> <release version="0.16.0" versioncode="80">
<change>New devices: HPlus (e.g. Zeblaze ZeBand), contributed by João Paulo Barraca</change> <change>New devices: HPlus (e.g. Zeblaze ZeBand), contributed by João Paulo Barraca</change>