1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 03:16:51 +01:00

HPlus: Detect Zeband Plus Unicode Support

This commit is contained in:
João Paulo Barraca 2017-05-04 14:16:21 +01:00
parent 497f9a6658
commit 8a39d8b2eb
4 changed files with 26 additions and 4 deletions

View File

@ -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<Character, byte[]> transliterateMap = new HashMap<Character, byte[]>(){
{

View File

@ -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));
}
}

View File

@ -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;

View File

@ -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();