diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java index 40713a89..cc41d4a8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusConstants.java @@ -132,6 +132,7 @@ public final class HPlusConstants { public static final String PREF_HPLUS_WRIST = "hplus_wrist"; public static final String PREF_HPLUS_SIT_START_TIME = "hplus_sit_start_time"; public static final String PREF_HPLUS_SIT_END_TIME = "hplus_sit_end_time"; + public static final String PREF_HPLUS_UNICODE = "hplus_unicode"; public static final Map transliterateMap = new HashMap(){ { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java index c6ce5f8a..e99123bc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java @@ -25,6 +25,7 @@ import android.annotation.TargetApi; import android.app.Activity; import android.bluetooth.le.ScanFilter; import android.content.Context; +import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.ParcelUuid; @@ -281,4 +282,13 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator { return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_END_TIME, 0); } + public static void setUnicodeSupport(String address, boolean state){ + SharedPreferences.Editor editor = prefs.getPreferences().edit(); + editor.putBoolean(HPlusConstants.PREF_HPLUS_UNICODE + "_" + address, state); + editor.commit(); + } + + public static boolean getUnicodeSupport(String address){ + return (prefs.getBoolean(HPlusConstants.PREF_HPLUS_UNICODE, false)); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusHandlerThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusHandlerThread.java index 59dcb25d..3f767a47 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusHandlerThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusHandlerThread.java @@ -501,13 +501,18 @@ class HPlusHandlerThread extends GBDeviceIoThread { if(data.length >= 11){ major = data[10] & 0xFF; minor = data[9] & 0xFF; + + int hwMajor = data[2] & 0xFF; + int hwMinor = data[1] & 0xFF; + + getDevice().setFirmwareVersion2(hwMajor + "." + hwMinor); + mHPlusSupport.setUnicodeSupport((data[3] != 0)); }else { major = data[2] & 0xFF; minor = data[1] & 0xFF; } getDevice().setFirmwareVersion(major + "." + minor); - getDevice().sendDeviceUpdateIntent(getContext()); return true; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java index 8557ad08..21d4f81c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java @@ -660,6 +660,10 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { } + public void setUnicodeSupport(boolean support){ + HPlusCoordinator.setUnicodeSupport(gbDevice.getAddress(), support); + } + private void showIncomingCall(String name, String rawNumber) { try { @@ -737,6 +741,8 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { int length = messageBytes.length / 17; + length = length > 5 ? 5 : length; + builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_INCOMING_MESSAGE, HPlusConstants.ARG_INCOMING_MESSAGE}); int remaining = Math.min(255, (messageBytes.length % 17 > 0) ? length + 1 : length); @@ -808,10 +814,10 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { cs = HPlusConstants.transliterateMap.get(c); } else { try { - if (HPlusCoordinator.getLanguage(this.gbDevice.getAddress()) == HPlusConstants.ARG_LANGUAGE_CN) - cs = c.toString().getBytes("GB2312"); + if(HPlusCoordinator.getUnicodeSupport(this.gbDevice.getAddress())) + cs = c.toString().getBytes("Unicode"); else - cs = c.toString().getBytes("UTF-8"); + cs = c.toString().getBytes("GB2312"); } catch (UnsupportedEncodingException e) { //Fallback. Result string may be strange, but better than nothing cs = c.toString().getBytes();