mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 01:21:56 +01:00
HPlus: Fix Unicode handling
This commit is contained in:
parent
845869e25e
commit
759b9c81a3
@ -289,6 +289,6 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getUnicodeSupport(String address){
|
public static boolean getUnicodeSupport(String address){
|
||||||
return (prefs.getBoolean(HPlusConstants.PREF_HPLUS_UNICODE, false));
|
return (prefs.getBoolean(HPlusConstants.PREF_HPLUS_UNICODE + "_" + address, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -808,6 +808,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
|||||||
private byte[] encodeStringToDevice(String s) {
|
private byte[] encodeStringToDevice(String s) {
|
||||||
|
|
||||||
List<Byte> outBytes = new ArrayList<Byte>();
|
List<Byte> outBytes = new ArrayList<Byte>();
|
||||||
|
Boolean unicode = HPlusCoordinator.getUnicodeSupport(this.gbDevice.getAddress());
|
||||||
|
LOG.info("Encode String: Unicode=" + unicode);
|
||||||
|
|
||||||
for (int i = 0; i < s.length(); i++) {
|
for (int i = 0; i < s.length(); i++) {
|
||||||
Character c = s.charAt(i);
|
Character c = s.charAt(i);
|
||||||
@ -818,12 +820,14 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if(HPlusCoordinator.getUnicodeSupport(this.gbDevice.getAddress()))
|
if(HPlusCoordinator.getUnicodeSupport(this.gbDevice.getAddress()))
|
||||||
|
if(unicode)
|
||||||
cs = c.toString().getBytes("Unicode");
|
cs = c.toString().getBytes("Unicode");
|
||||||
else
|
else
|
||||||
cs = c.toString().getBytes("GB2312");
|
cs = c.toString().getBytes("GB2312");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
//Fallback. Result string may be strange, but better than nothing
|
//Fallback. Result string may be strange, but better than nothing
|
||||||
cs = c.toString().getBytes();
|
cs = c.toString().getBytes();
|
||||||
|
LOG.error("Could not convert String to Bytes: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int j = 0; j < cs.length; j++)
|
for (int j = 0; j < cs.length; j++)
|
||||||
|
Loading…
Reference in New Issue
Block a user