1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +01:00

Merge branch 'master' into background-javascript

This commit is contained in:
Andreas Shimokawa 2017-10-01 23:36:22 +02:00
commit 49bebc3440
17 changed files with 163 additions and 58 deletions

View File

@ -1,5 +1,12 @@
### Changelog
#### Version 0.21.4
* Mi2/Bip: Fix sleep detection for newer firmwares
* Mi2/Bip: Fix ancient bug resulting in wrong activity data at the beginning in diagrams and aggregate data
* No.1 F1: Support setting time format and distance units (metric/imperial)
* Pebble: Support setting distance units to miles for Health (need to reactivate Health in App Manager after toggling)
* HPlus: Make changing distance unit system effective immediately on toggling
#### Version 0.21.3
* Amazfit Bip: Auto-switch language on connect (English, Simplified Chinese, Traditional Chinese), requires FW 0.0.9.14+

View File

@ -26,8 +26,8 @@ android {
targetSdkVersion 25
// note: always bump BOTH versionCode and versionName!
versionName "0.21.3"
versionCode 104
versionName "0.21.5"
versionCode 105
vectorDrawables.useSupportLibrary = true
}
buildTypes {

View File

@ -61,6 +61,8 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_
public class SettingsActivity extends AbstractSettingsActivity {
private static final Logger LOG = LoggerFactory.getLogger(SettingsActivity.class);
public static final String PREF_MEASUREMENT_SYSTEM = "measurement_system";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -172,6 +174,21 @@ public class SettingsActivity extends AbstractSettingsActivity {
});
final Preference unit = findPreference(PREF_MEASUREMENT_SYSTEM);
unit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_MEASUREMENT_SYSTEM);
}
});
preference.setSummary(newVal.toString());
return true;
}
});
if (!GBApplication.isRunningMarshmallowOrLater()) {
pref = findPreference("notification_filter");
PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications");
@ -268,6 +285,13 @@ public class SettingsActivity extends AbstractSettingsActivity {
audioPlayer.setDefaultValue(newValues[0]);
}
/*
* delayed execution so that the preferences are applied first
*/
private void invokeLater(Runnable runnable) {
getListView().post(runnable);
}
@Override
protected String[] getPreferenceKeysWithSummary() {
return new String[]{

View File

@ -127,7 +127,6 @@ public final class HPlusConstants {
public static final String PREF_HPLUS_SCREENTIME = "hplus_screentime";
public static final String PREF_HPLUS_ALLDAYHR = "hplus_alldayhr";
public static final String PREF_HPLUS_UNIT = "hplus_unit";
public static final String PREF_HPLUS_TIMEFORMAT = "hplus_timeformat";
public static final String PREF_HPLUS_WRIST = "hplus_wrist";
public static final String PREF_HPLUS_SIT_START_TIME = "hplus_sit_start_time";

View File

@ -35,6 +35,7 @@ import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
@ -202,7 +203,7 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
}
public static byte getUnit(String address) {
String units = prefs.getString(HPlusConstants.PREF_HPLUS_UNIT, getContext().getString(R.string.p_unit_metric));
String units = prefs.getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, getContext().getString(R.string.p_unit_metric));
if(units.equals(getContext().getString(R.string.p_unit_metric))){
return HPlusConstants.ARG_UNIT_METRIC;

View File

@ -50,13 +50,13 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider {
public static final int TYPE_UNSET = -1;
public static final int TYPE_NO_CHANGE = 0;
public static final int TYPE_ACTIVITY = 1;
public static final int TYPE_RUNNING = 2;
public static final int TYPE_NONWEAR = 3;
public static final int TYPE_CHARGING = 6;
public static final int TYPE_LIGHT_SLEEP = 9;
public static final int TYPE_IGNORE = 10;
public static final int TYPE_DEEP_SLEEP = 11;
public static final int TYPE_WAKE_UP = 12;
// appears to be a measurement problem resulting in type = 10 and intensity = 20, at least with fw 1.0.0.39
public static final int TYPE_IGNORE = 10;
public MiBand2SampleProvider(GBDevice device, DaoSession session) {
super(device, session);
@ -81,6 +81,11 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider {
int lastValidKind = determinePreviousValidActivityType(samples.get(0));
for (MiBandActivitySample sample : samples) {
int rawKind = sample.getRawKind();
if (rawKind != TYPE_UNSET) {
rawKind &= 0xf;
sample.setRawKind(rawKind);
}
switch (rawKind) {
case TYPE_IGNORE:
case TYPE_NO_CHANGE:
@ -100,11 +105,12 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider {
qb.where(MiBandActivitySampleDao.Properties.DeviceId.eq(sample.getDeviceId()),
MiBandActivitySampleDao.Properties.UserId.eq(sample.getUserId()),
MiBandActivitySampleDao.Properties.Timestamp.lt(sample.getTimestamp()),
MiBandActivitySampleDao.Properties.RawKind.notIn(TYPE_IGNORE, TYPE_NO_CHANGE));
MiBandActivitySampleDao.Properties.RawKind.notIn(TYPE_NO_CHANGE, TYPE_IGNORE, TYPE_UNSET, 16, 80, 96, 112)); // all I ever had that are 0 when doing &=0xf
qb.orderDesc(MiBandActivitySampleDao.Properties.Timestamp);
qb.limit(1);
List<MiBandActivitySample> result = qb.build().list();
if (result.size() > 0) {
return result.get(0).getRawKind();
return result.get(0).getRawKind() & 0xf;
}
return TYPE_UNSET;
}
@ -117,12 +123,13 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider {
case TYPE_LIGHT_SLEEP:
return ActivityKind.TYPE_LIGHT_SLEEP;
case TYPE_ACTIVITY:
case TYPE_RUNNING:
case TYPE_WAKE_UP:
return ActivityKind.TYPE_ACTIVITY;
case TYPE_NONWEAR:
return ActivityKind.TYPE_NOT_WORN;
case TYPE_CHARGING:
return ActivityKind.TYPE_NOT_WORN; //I believe it's a safe assumption
case TYPE_IGNORE:
default:
case TYPE_UNSET: // fall through
return ActivityKind.TYPE_UNKNOWN;

View File

@ -45,6 +45,7 @@ import java.util.List;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
@ -646,8 +647,18 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
@Override
public void onSendConfiguration(String config) {
LOG.info("Send Configuration: " + config);
TransactionBuilder builder;
try {
builder = performInitialized("Sending configuration for option: " + config);
switch (config) {
case SettingsActivity.PREF_MEASUREMENT_SYSTEM:
setUnit(builder);
break;
}
builder.queue(getQueue());
} catch (IOException e) {
GB.toast("Error setting configuration", Toast.LENGTH_LONG, GB.ERROR, e);
}
}
@Override

View File

@ -225,11 +225,6 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
GregorianCalendar now = BLETypeConversions.createCalendar();
byte[] bytes = getTimeBytes(now, TimeUnit.SECONDS);
builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_CURRENT_TIME), bytes);
// byte[] localtime = BLETypeConversions.calendarToLocalTimeBytes(now);
// builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_LOCAL_TIME_INFORMATION), localtime);
// builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_CURRENT_TIME), new byte[] {0x2, 0x00});
// builder.write(getCharacteristic(MiBand2Service.UUID_UNKNOQN_CHARACTERISTIC0), new byte[] {0x03,0x00,(byte)0x8e,(byte)0xce,0x5a,0x09,(byte)0xb3,(byte)0xd8,0x55,0x57,0x10,0x2a,(byte)0xed,0x7d,0x6b,0x78,(byte)0xc5,(byte)0xd2});
return this;
}

View File

@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.no1f1;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.net.Uri;
import android.text.format.DateFormat;
import android.widget.Toast;
import org.slf4j.Logger;
@ -34,6 +35,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
@ -142,6 +144,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
case No1F1Constants.CMD_NOTIFICATION:
case No1F1Constants.CMD_ICON:
case No1F1Constants.CMD_DEVICE_SETTINGS:
case No1F1Constants.CMD_DISPLAY_SETTINGS:
return true;
default:
LOG.warn("Unhandled characteristic change: " + characteristicUUID + " code: " + Arrays.toString(data));
@ -315,7 +318,18 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
@Override
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
@ -333,6 +347,33 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
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) {
// TODO Create custom settings page for changing hardcoded values
@ -387,12 +428,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
0x00
});
// display settings
builder.write(ctrlCharacteristic, new byte[]{
No1F1Constants.CMD_DISPLAY_SETTINGS,
0x01, // 1 - display distance in kilometers, 2 - in miles
0x01 // 1 - display 24-hour clock, 2 - for 12-hour with AM/PM
});
setDisplaySettings(builder);
// heart rate measurement mode
builder.write(ctrlCharacteristic, new byte[]{
@ -553,7 +589,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
for (int i = 0; i < samples.size(); i++) {
samples.get(i).setDeviceId(deviceId);
samples.get(i).setUserId(userId);
if (samples.get(i).getRawIntensity()<7)
if (samples.get(i).getRawIntensity() < 7)
samples.get(i).setRawKind(ActivityKind.TYPE_DEEP_SLEEP);
else
samples.get(i).setRawKind(ActivityKind.TYPE_LIGHT_SLEEP);
@ -643,16 +679,15 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
}
private void handleRealtimeHeartRateData(byte[] data) {
if (data.length==2)
{
if (data[1]==(byte) 0x11)
if (data.length == 2) {
if (data[1] == (byte) 0x11)
LOG.info("Heart rate measurement started.");
else
LOG.info("Heart rate measurement stopped.");
return;
}
// Check if data is valid. Otherwise ignore sample.
if (data[2]==0) {
if (data[2] == 0) {
No1F1ActivitySample sample = new No1F1ActivitySample();
sample.setTimestamp((int) (GregorianCalendar.getInstance().getTimeInMillis() / 1000L));
sample.setHeartRate(data[3] & 0xff);

View File

@ -571,20 +571,6 @@ class PebbleIoThread extends GBDeviceIoThread {
}
void installApp(Uri uri, int appId) {
if (uri.equals(Uri.parse("fake://health"))) {
write(mPebbleProtocol.encodeActivateHealth(true));
write(mPebbleProtocol.encodeSetSaneDistanceUnit(true));
return;
}
if (uri.equals(Uri.parse("fake://hrm"))) {
write(mPebbleProtocol.encodeActivateHRM(true));
return;
}
if (uri.equals(Uri.parse("fake://weather"))) {
write(mPebbleProtocol.encodeActivateWeather(true));
return;
}
if (mIsInstalling) {
return;
}

View File

@ -30,6 +30,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
@ -67,7 +68,30 @@ public class PebbleSupport extends AbstractSerialDeviceSupport {
@Override
public void onInstallApp(Uri uri) {
getDeviceIOThread().installApp(uri, 0);
PebbleProtocol pebbleProtocol = (PebbleProtocol) getDeviceProtocol();
PebbleIoThread pebbleIoThread = getDeviceIOThread();
// catch fake urls first
if (uri.equals(Uri.parse("fake://health"))) {
getDeviceIOThread().write(pebbleProtocol.encodeActivateHealth(true));
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))) {
pebbleIoThread.write(pebbleProtocol.encodeSetSaneDistanceUnit(true));
} else {
pebbleIoThread.write(pebbleProtocol.encodeSetSaneDistanceUnit(false));
}
return;
}
if (uri.equals(Uri.parse("fake://hrm"))) {
getDeviceIOThread().write(pebbleProtocol.encodeActivateHRM(true));
return;
}
if (uri.equals(Uri.parse("fake://weather"))) {
getDeviceIOThread().write(pebbleProtocol.encodeActivateWeather(true));
return;
}
// it is a real app
pebbleIoThread.installApp(uri, 0);
}
@Override

View File

@ -177,7 +177,7 @@
<string name="action_discover">Connecter un nouvel appareil</string>
<string name="device_with_rssi">%1$s (%2$s)</string>
<string name="title_activity_android_pairing">Appairer l\'appareil</string>
<string name="android_pairing_hint">Utiliser le l\'appairage Bluetooth d\'Android pour jumeler l\'appareil</string>
<string name="android_pairing_hint">Utiliser l\'appairage Bluetooth d\'Android pour jumeler l\'appareil.</string>
<string name="title_activity_mi_band_pairing">Appairer votre Mi Band</string>
<string name="pairing">Jumelage avec %s…</string>
<string name="pairing_creating_bond_with">Création dun lien avec %1$s (%2$s)</string>
@ -228,7 +228,7 @@
<string name="stats_x_axis_label">Total de minutes</string>
<string name="stats_y_axis_label">Pas par minute</string>
<string name="control_center_find_lost_device">Trouver l\'appareil perdu</string>
<string name="control_center_cancel_to_stop_vibration">Annuler pour arrêter les vibrations</string>
<string name="control_center_cancel_to_stop_vibration">Annuler pour arrêter les vibrations.</string>
<string name="title_activity_charts">Votre activité</string>
<string name="title_activity_set_alarm">Configurer les alarmes</string>
<string name="controlcenter_start_configure_alarms">Configurer les alarmes</string>
@ -399,10 +399,10 @@ NOTE: la base de données sera bien évidement plus grande !</string>
<string name="mi2_dnd_automatic">Automatique (détection de sommeil)</string>
<string name="mi2_dnd_scheduled">Programmé (intervalle de temps)</string>
<string name="discovery_attempting_to_pair">Tentative de jumelage avec %1$s</string>
<string name="discovery_bonding_failed_immediately">Le lien avec %1$s a échoué instantanément</string>
<string name="discovery_bonding_failed_immediately">Le lien avec %1$s a échoué instantanément.</string>
<string name="discovery_trying_to_connect_to">Tentative de connexion à: %1$s</string>
<string name="discovery_enable_bluetooth">Activez le Bluetooth pour trouver des dispositifs</string>
<string name="discovery_successfully_bonded">Correctement lié à %1$s</string>
<string name="discovery_enable_bluetooth">Activez le Bluetooth pour trouver des dispositifs.</string>
<string name="discovery_successfully_bonded">Correctement lié à %1$s.</string>
<string name="discovery_pair_title">Appairer avec %1$s ?</string>
<string name="discovery_pair_question">Sélectionnez Jumeler pour associer vos dispositifs. Si cela échoue, essayez à nouveau sans jumelage.</string>
<string name="discovery_yes_pair">Jumelage</string>

View File

@ -422,4 +422,9 @@
<string name="mi2_prefs_button_action_vibrate_summary">ボタンの動作をトリガーに band の振動を有効にします</string>
<string name="mi2_prefs_button_press_count_max_delay">ボタンを押す間の最大遅延時間</string>
<string name="mi2_prefs_button_press_count_max_delay_summary">ボタンを押す間隔の最大遅延時間 (ミリ秒単位)</string>
</resources>
<string name="mi2_prefs_button_press_count_match_delay">ボタン操作の後に遅延</string>
<string name="mi2_prefs_button_press_count_match_delay_summary">1回のボタン操作に一致した後の遅滞 (数字は button_id インテント拡張内) 0 の場合はすぐ</string>
<string name="_pebble_watch_open_on_phone">電話で開く</string>
<string name="_pebble_watch_mute">ミュート</string>
<string name="_pebble_watch_reply">返信</string>
</resources>

View File

@ -1,5 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<changelog>
<release version="0.21.4" versioncode="105">
<change>Mi2/Bip: Fix sleep detection for newer firmwares</change>
<change>Mi2/Bip: Fix ancient bug resulting in wrong activity data at the beginning in diagrams and aggregate data</change>
<change>No.1 F1: Support setting time format and distance units (metric/imperial)</change>
<change>Pebble: Support setting distance units to miles for Health (need to reactivate Health in App Manager after toggling)</change>
<change>HPlus: Make changing distance unit system effective immediately on toggling</change>
</release>
<release version="0.21.3" versioncode="104">
<change>Amazfit Bip: Auto-switch language on connect (English, Simplified Chinese, Traditional Chinese), requires FW 0.0.9.14+</change>
</release>

View File

@ -34,6 +34,13 @@
android:entryValues="@array/pref_language_values"
android:defaultValue="default"
android:summary="%s" />
<ListPreference
android:defaultValue="metric"
android:entries="@array/pref_entries_unit_system"
android:entryValues="@array/pref_values_unit_system"
android:key="measurement_system"
android:summary="%s"
android:title="@string/pref_title_unit_system" />
<CheckBoxPreference
android:defaultValue="false"
android:key="minimize_priority"
@ -463,14 +470,6 @@
android:key="hplus_alldayhr"
android:title="@string/prefs_title_all_day_heart_rate" />
<ListPreference
android:defaultValue="metric"
android:entries="@array/pref_entries_unit_system"
android:entryValues="@array/pref_values_unit_system"
android:key="hplus_unit"
android:title="@string/pref_title_unit_system"
android:summary="%s" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -0,0 +1,5 @@
* Mi2/Bip: Fix sleep detection for newer firmwares
* Mi2/Bip: Fix ancient bug resulting in wrong activity data at the beginning in diagrams and aggregate data
* No.1 F1: Support setting time format and distance units (metric/imperial)
* Pebble: Support setting distance units to miles for Health (need to reactivate Health in App Manager after toggling)
* HPlus: Make changing distance unit system effective immediately on toggling

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip