mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 10:35:50 +01:00
Amazfit Bip: Fix language setting on new firmwares
This commit is contained in:
parent
d34f8237df
commit
ea4a4edc5b
@ -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_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_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};
|
||||
}
|
||||
|
@ -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.miband.MiBand2Service;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
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.AlertNotificationProfile;
|
||||
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.Version;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service.ENDPOINT_DISPLAY_ITEMS;
|
||||
|
||||
public class AmazfitBipSupport extends MiBand2Support {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipSupport.class);
|
||||
@ -303,43 +303,68 @@ public class AmazfitBipSupport extends MiBand2Support {
|
||||
}
|
||||
|
||||
private AmazfitBipSupport setLanguage(TransactionBuilder builder) {
|
||||
|
||||
String language = Locale.getDefault().getLanguage();
|
||||
String country = Locale.getDefault().getCountry();
|
||||
|
||||
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)) {
|
||||
case 0:
|
||||
command = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE;
|
||||
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE;
|
||||
localeString = "zh_CN";
|
||||
break;
|
||||
case 1:
|
||||
command = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE;
|
||||
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE;
|
||||
localeString = "zh_TW";
|
||||
break;
|
||||
case 2:
|
||||
command = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH;
|
||||
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH;
|
||||
localeString = "en_US";
|
||||
break;
|
||||
case 3:
|
||||
Version version = new Version(gbDevice.getFirmwareVersion());
|
||||
if (version.compareTo(new Version("0.1.0.66")) >= 0) {
|
||||
command = AmazfitBipService.COMMAND_SET_LANGUAGE_SPANISH;
|
||||
} else {
|
||||
command = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH;
|
||||
}
|
||||
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_SPANISH;
|
||||
localeString = "es_ES";
|
||||
break;
|
||||
default:
|
||||
if (language.equals("zh")) {
|
||||
if (country.equals("TW") || country.equals("HK") || country.equals("MO")) { // Taiwan, Hong Kong, Macao
|
||||
command = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE;
|
||||
} else {
|
||||
command = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE;
|
||||
}
|
||||
} else {
|
||||
command = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH;
|
||||
switch (language) {
|
||||
case "zh":
|
||||
if (country.equals("TW") || country.equals("HK") || country.equals("MO")) { // Taiwan, Hong Kong, Macao
|
||||
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE;
|
||||
localeString = "zh_TW";
|
||||
} else {
|
||||
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE;
|
||||
localeString = "zh_CN";
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user