Now setting for measurement system is sent to the device immediately after changing.

This commit is contained in:
protomors 2017-10-01 13:16:08 +03:00 committed by Andreas Shimokawa
parent 7b78003ba1
commit b819be7db6
1 changed files with 42 additions and 19 deletions

View File

@ -35,6 +35,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
@ -143,6 +144,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
case No1F1Constants.CMD_NOTIFICATION: case No1F1Constants.CMD_NOTIFICATION:
case No1F1Constants.CMD_ICON: case No1F1Constants.CMD_ICON:
case No1F1Constants.CMD_DEVICE_SETTINGS: case No1F1Constants.CMD_DEVICE_SETTINGS:
case No1F1Constants.CMD_DISPLAY_SETTINGS:
return true; return true;
default: default:
LOG.warn("Unhandled characteristic change: " + characteristicUUID + " code: " + Arrays.toString(data)); LOG.warn("Unhandled characteristic change: " + characteristicUUID + " code: " + Arrays.toString(data));
@ -316,7 +318,18 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
@Override @Override
public void onSendConfiguration(String config) { public void onSendConfiguration(String config) {
TransactionBuilder builder;
try {
builder = performInitialized("Sending configuration for option: " + config);
switch (config) {
case SettingsActivity.PREF_MEASUREMENT_SYSTEM:
setDisplaySettings(builder);
break;
}
builder.queue(getQueue());
} catch (IOException e) {
GB.toast("Error setting configuration", Toast.LENGTH_LONG, GB.ERROR, e);
}
} }
@Override @Override
@ -334,6 +347,33 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
return true; return true;
} }
/**
* Set display settings (time format and measurement system)
*
* @param transaction
* @return
*/
private No1F1Support setDisplaySettings(TransactionBuilder transaction) {
byte[] displayBytes = new byte[]{
No1F1Constants.CMD_DISPLAY_SETTINGS,
0x00, // 1 - display distance in kilometers, 2 - in miles
0x00 // 1 - display 24-hour clock, 2 - for 12-hour with AM/PM
};
String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, getContext().getString(R.string.p_unit_metric));
if (units.equals(getContext().getString(R.string.p_unit_metric))) {
displayBytes[1] = 1;
} else {
displayBytes[1] = 2;
}
if (DateFormat.is24HourFormat(getContext())) {
displayBytes[2] = 1;
} else {
displayBytes[2] = 2;
}
transaction.write(ctrlCharacteristic, displayBytes);
return this;
}
private void sendSettings(TransactionBuilder builder) { private void sendSettings(TransactionBuilder builder) {
// TODO Create custom settings page for changing hardcoded values // TODO Create custom settings page for changing hardcoded values
@ -388,24 +428,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
0x00 0x00
}); });
// display settings setDisplaySettings(builder);
byte[] displayBytes = new byte[]{
No1F1Constants.CMD_DISPLAY_SETTINGS,
0x00, // 1 - display distance in kilometers, 2 - in miles
0x00 // 1 - display 24-hour clock, 2 - for 12-hour with AM/PM
};
String units = GBApplication.getPrefs().getString("measurement_system", getContext().getString(R.string.p_unit_metric));
if (units.equals(getContext().getString(R.string.p_unit_metric))) {
displayBytes[1] = 1;
} else {
displayBytes[1] = 2;
}
if (DateFormat.is24HourFormat(getContext())) {
displayBytes[2] = 1;
} else {
displayBytes[2] = 2;
}
builder.write(ctrlCharacteristic, displayBytes);
// heart rate measurement mode // heart rate measurement mode
builder.write(ctrlCharacteristic, new byte[]{ builder.write(ctrlCharacteristic, new byte[]{