1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 18:45:49 +01:00

Amazfit Bip: Fix language setting on new firmwares

This commit is contained in:
Andreas Shimokawa 2018-02-08 22:21:15 +01:00
parent d34f8237df
commit ea4a4edc5b
2 changed files with 48 additions and 21 deletions

View File

@ -33,6 +33,8 @@ public class AmazfitBipService {
public static final byte[] COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE = new byte[]{ENDPOINT_DISPLAY, 0x13, 0x00, 0x01}; public static final byte[] COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE = new byte[]{ENDPOINT_DISPLAY, 0x13, 0x00, 0x01};
public static final byte[] COMMAND_SET_LANGUAGE_ENGLISH = new byte[]{ENDPOINT_DISPLAY, 0x13, 0x00, 0x02}; public static final byte[] COMMAND_SET_LANGUAGE_ENGLISH = new byte[]{ENDPOINT_DISPLAY, 0x13, 0x00, 0x02};
public static final byte[] COMMAND_SET_LANGUAGE_SPANISH = new byte[]{ENDPOINT_DISPLAY, 0x13, 0x00, 0x03}; public static final byte[] COMMAND_SET_LANGUAGE_SPANISH = new byte[]{ENDPOINT_DISPLAY, 0x13, 0x00, 0x03};
public static final byte[] COMMAND_SET_LANGUAGE_NEW_TEMPLATE = new byte[]{ENDPOINT_DISPLAY, 0x17, 0x00, 0, 0, 0, 0, 0};
public static final byte[] COMMAND_ACK_FIND_PHONE_IN_PROGRESS = new byte[]{ENDPOINT_DISPLAY, 0x14, 0x00, 0x00}; public static final byte[] COMMAND_ACK_FIND_PHONE_IN_PROGRESS = new byte[]{ENDPOINT_DISPLAY, 0x14, 0x00, 0x00};
} }

View File

@ -38,11 +38,13 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipF
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipService; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipService;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.model.Weather; import nodomain.freeyourgadget.gadgetbridge.model.Weather;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWriteAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert;
@ -53,8 +55,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Suppo
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Version; import nodomain.freeyourgadget.gadgetbridge.util.Version;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service.ENDPOINT_DISPLAY_ITEMS;
public class AmazfitBipSupport extends MiBand2Support { public class AmazfitBipSupport extends MiBand2Support {
private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipSupport.class); private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipSupport.class);
@ -303,43 +303,68 @@ public class AmazfitBipSupport extends MiBand2Support {
} }
private AmazfitBipSupport setLanguage(TransactionBuilder builder) { private AmazfitBipSupport setLanguage(TransactionBuilder builder) {
String language = Locale.getDefault().getLanguage(); String language = Locale.getDefault().getLanguage();
String country = Locale.getDefault().getCountry(); String country = Locale.getDefault().getCountry();
LOG.info("Setting watch language, phone language = " + language + " country = " + country); LOG.info("Setting watch language, phone language = " + language + " country = " + country);
byte[] command; final byte[] command_new;
final byte[] command_old;
String localeString;
switch (GBApplication.getPrefs().getInt("amazfitbip_language", -1)) { switch (GBApplication.getPrefs().getInt("amazfitbip_language", -1)) {
case 0: case 0:
command = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE; command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE;
localeString = "zh_CN";
break; break;
case 1: case 1:
command = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE; command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE;
localeString = "zh_TW";
break; break;
case 2: case 2:
command = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH; command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH;
localeString = "en_US";
break; break;
case 3: case 3:
Version version = new Version(gbDevice.getFirmwareVersion()); command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_SPANISH;
if (version.compareTo(new Version("0.1.0.66")) >= 0) { localeString = "es_ES";
command = AmazfitBipService.COMMAND_SET_LANGUAGE_SPANISH;
} else {
command = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH;
}
break; break;
default: default:
if (language.equals("zh")) { switch (language) {
case "zh":
if (country.equals("TW") || country.equals("HK") || country.equals("MO")) { // Taiwan, Hong Kong, Macao if (country.equals("TW") || country.equals("HK") || country.equals("MO")) { // Taiwan, Hong Kong, Macao
command = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE; command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE;
localeString = "zh_TW";
} else { } else {
command = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE; command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE;
localeString = "zh_CN";
} }
} else { break;
command = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH; case "es":
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_SPANISH;
localeString = "es_ES";
break;
default:
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH;
localeString = "en_US";
break;
} }
} }
command_new = AmazfitBipService.COMMAND_SET_LANGUAGE_NEW_TEMPLATE;
System.arraycopy(localeString.getBytes(), 0, command_new, 3, localeString.getBytes().length);
builder.add(new ConditionalWriteAction(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION)) {
@Override
protected byte[] checkCondition() {
if (gbDevice.getType() == DeviceType.AMAZFITBIP && new Version(gbDevice.getFirmwareVersion()).compareTo(new Version("0.1.0.77")) >= 0) {
return command_new;
} else {
return command_old;
}
}
});
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
return this; return this;
} }