mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
allow the transfer of activity data without clearing MiBand's memory
This commit is contained in:
parent
020d758f69
commit
6c28b50f52
@ -1,5 +1,8 @@
|
|||||||
###Changelog
|
###Changelog
|
||||||
|
|
||||||
|
####Version next
|
||||||
|
* Miband: allow the transfer of activity data without clearing MiBand's memory
|
||||||
|
|
||||||
####Version 0.5.3
|
####Version 0.5.3
|
||||||
* Pebble: For generic notifications, support dismissing individual notficications and "Open on Phone" feature (OG & PT)
|
* Pebble: For generic notifications, support dismissing individual notficications and "Open on Phone" feature (OG & PT)
|
||||||
* Pebble: Allow to treat K9 notifcations as generic notifications (if notification mode is set to never)
|
* Pebble: Allow to treat K9 notifcations as generic notifications (if notification mode is set to never)
|
||||||
|
@ -120,10 +120,16 @@ public class AbstractSettingsActivity extends PreferenceActivity {
|
|||||||
preference.setOnPreferenceChangeListener(listener);
|
preference.setOnPreferenceChangeListener(listener);
|
||||||
|
|
||||||
// Trigger the listener immediately with the preference's current value.
|
// Trigger the listener immediately with the preference's current value.
|
||||||
listener.updateSummary(preference,
|
try {
|
||||||
PreferenceManager
|
listener.updateSummary(preference,
|
||||||
.getDefaultSharedPreferences(preference.getContext())
|
PreferenceManager
|
||||||
.getString(preference.getKey(), ""));
|
.getDefaultSharedPreferences(preference.getContext())
|
||||||
|
.getString(preference.getKey(), ""));
|
||||||
|
} catch (ClassCastException cce) {
|
||||||
|
//the preference is not a string, use the provided summary
|
||||||
|
//TODO: it shows true/false instead of the xml summary
|
||||||
|
listener.updateSummary(preference, preference.getSummary());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,6 +17,8 @@ public final class MiBandConst {
|
|||||||
public static final String PREF_MIBAND_ADDRESS = "development_miaddr"; // FIXME: should be prefixed mi_
|
public static final String PREF_MIBAND_ADDRESS = "development_miaddr"; // FIXME: should be prefixed mi_
|
||||||
public static final String PREF_MIBAND_ALARMS = "mi_alarms";
|
public static final String PREF_MIBAND_ALARMS = "mi_alarms";
|
||||||
public static final String PREF_MIBAND_FITNESS_GOAL = "mi_fitness_goal";
|
public static final String PREF_MIBAND_FITNESS_GOAL = "mi_fitness_goal";
|
||||||
|
public static final String PREF_MIBAND_DONT_ACK_TRANSFER = "mi_dont_ack_transfer";
|
||||||
|
|
||||||
|
|
||||||
public static final String ORIGIN_SMS = "sms";
|
public static final String ORIGIN_SMS = "sms";
|
||||||
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
|
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
|
||||||
|
@ -16,6 +16,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.OR
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_SMS;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_SMS;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_DONT_ACK_TRANSFER;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_WEARSIDE;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_WEARSIDE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_GENDER;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_GENDER;
|
||||||
@ -58,6 +59,7 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|||||||
PREF_MIBAND_WEARSIDE,
|
PREF_MIBAND_WEARSIDE,
|
||||||
PREF_MIBAND_ADDRESS,
|
PREF_MIBAND_ADDRESS,
|
||||||
PREF_MIBAND_FITNESS_GOAL,
|
PREF_MIBAND_FITNESS_GOAL,
|
||||||
|
PREF_MIBAND_DONT_ACK_TRANSFER,
|
||||||
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_SMS),
|
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_SMS),
|
||||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_SMS),
|
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_SMS),
|
||||||
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_INCOMING_CALL),
|
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_INCOMING_CALL),
|
||||||
|
@ -103,6 +103,8 @@ public class MiBandService {
|
|||||||
|
|
||||||
public static final byte NOTIFY_STATUS_MOTOR_TEST = 0x16;
|
public static final byte NOTIFY_STATUS_MOTOR_TEST = 0x16;
|
||||||
|
|
||||||
|
// 0x18 is returned when we cancel data sync, perhaps is an ack for this message
|
||||||
|
|
||||||
public static final byte NOTIFY_UNKNOWN = -0x1;
|
public static final byte NOTIFY_UNKNOWN = -0x1;
|
||||||
|
|
||||||
public static final int NOTIFY_PAIR_CANCEL = 0xef;
|
public static final int NOTIFY_PAIR_CANCEL = 0xef;
|
||||||
@ -148,6 +150,8 @@ public class MiBandService {
|
|||||||
|
|
||||||
public static final byte COMMAND_SET_WEAR_LOCATION = 0xf;
|
public static final byte COMMAND_SET_WEAR_LOCATION = 0xf;
|
||||||
|
|
||||||
|
public static final byte COMMAND_STOP_SYNC_DATA = 0x11;
|
||||||
|
|
||||||
public static final byte COMMAND_STOP_MOTOR_VIBRATE = 0x13;
|
public static final byte COMMAND_STOP_MOTOR_VIBRATE = 0x13;
|
||||||
|
|
||||||
/* FURTHER COMMANDS: unchecked therefore left commented
|
/* FURTHER COMMANDS: unchecked therefore left commented
|
||||||
@ -160,8 +164,6 @@ public class MiBandService {
|
|||||||
|
|
||||||
public static final COMMAND_SET_REALTIME_STEP = 0x10t
|
public static final COMMAND_SET_REALTIME_STEP = 0x10t
|
||||||
|
|
||||||
public static final COMMAND_STOP_SYNC_DATA = 0x11t
|
|
||||||
|
|
||||||
public static final byte COMMAND_GET_SENSOR_DATA = 0x12t
|
public static final byte COMMAND_GET_SENSOR_DATA = 0x12t
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -2,7 +2,9 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations;
|
|||||||
|
|
||||||
import android.bluetooth.BluetoothGatt;
|
import android.bluetooth.BluetoothGatt;
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -19,6 +21,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
|
||||||
@ -224,6 +227,18 @@ public class FetchActivityOperation extends AbstractBTLEOperation<MiBandSupport>
|
|||||||
*/
|
*/
|
||||||
private void sendAckDataTransfer(Calendar time, int bytesTransferred) {
|
private void sendAckDataTransfer(Calendar time, int bytesTransferred) {
|
||||||
byte[] ackTime = MiBandDateConverter.calendarToRawBytes(time);
|
byte[] ackTime = MiBandDateConverter.calendarToRawBytes(time);
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
||||||
|
|
||||||
|
byte[] ackChecksum = new byte[]{
|
||||||
|
(byte) (bytesTransferred & 0xff),
|
||||||
|
(byte) (0xff & (bytesTransferred >> 8))
|
||||||
|
};
|
||||||
|
if (prefs.getBoolean(MiBandConst.PREF_MIBAND_DONT_ACK_TRANSFER, false)) {
|
||||||
|
ackChecksum = new byte[]{
|
||||||
|
(byte) (~bytesTransferred & 0xff),
|
||||||
|
(byte) (0xff & (~bytesTransferred >> 8))
|
||||||
|
};
|
||||||
|
}
|
||||||
byte[] ack = new byte[]{
|
byte[] ack = new byte[]{
|
||||||
MiBandService.COMMAND_CONFIRM_ACTIVITY_DATA_TRANSFER_COMPLETE,
|
MiBandService.COMMAND_CONFIRM_ACTIVITY_DATA_TRANSFER_COMPLETE,
|
||||||
ackTime[0],
|
ackTime[0],
|
||||||
@ -232,8 +247,8 @@ public class FetchActivityOperation extends AbstractBTLEOperation<MiBandSupport>
|
|||||||
ackTime[3],
|
ackTime[3],
|
||||||
ackTime[4],
|
ackTime[4],
|
||||||
ackTime[5],
|
ackTime[5],
|
||||||
(byte) (bytesTransferred & 0xff),
|
ackChecksum[0],
|
||||||
(byte) (0xff & (bytesTransferred >> 8))
|
ackChecksum[1]
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized("send acknowledge");
|
TransactionBuilder builder = performInitialized("send acknowledge");
|
||||||
@ -246,6 +261,12 @@ public class FetchActivityOperation extends AbstractBTLEOperation<MiBandSupport>
|
|||||||
//The last data chunk sent by the miband has always length 0.
|
//The last data chunk sent by the miband has always length 0.
|
||||||
//When we ack this chunk, the transfer is done.
|
//When we ack this chunk, the transfer is done.
|
||||||
if (getDevice().isBusy() && bytesTransferred == 0) {
|
if (getDevice().isBusy() && bytesTransferred == 0) {
|
||||||
|
//if we are not clearing miband's data, we have to stop the sync
|
||||||
|
if (prefs.getBoolean(MiBandConst.PREF_MIBAND_DONT_ACK_TRANSFER, false)) {
|
||||||
|
builder = performInitialized("send acknowledge");
|
||||||
|
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), new byte[]{MiBandService.COMMAND_STOP_SYNC_DATA});
|
||||||
|
builder.queue(getQueue());
|
||||||
|
}
|
||||||
handleActivityFetchFinish();
|
handleActivityFetchFinish();
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
@ -187,4 +187,6 @@
|
|||||||
<string name="chart_steps">Steps</string>
|
<string name="chart_steps">Steps</string>
|
||||||
<string name="liveactivity_live_activity">Live Activity</string>
|
<string name="liveactivity_live_activity">Live Activity</string>
|
||||||
<string name="weeksteps_today_steps_description">Steps today, target: %1$s</string>
|
<string name="weeksteps_today_steps_description">Steps today, target: %1$s</string>
|
||||||
|
<string name="pref_title_dont_ack_transfer">Do not ack activity data transfer</string>
|
||||||
|
<string name="pref_summary_dont_ack_transfers">If the activity data are not acked to the band, they will not be cleared. Useful if GB is used together with other apps.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -164,5 +164,10 @@
|
|||||||
android:key="development_miaddr"
|
android:key="development_miaddr"
|
||||||
android:maxLength="17"
|
android:maxLength="17"
|
||||||
android:title="@string/pref_title_development_miaddr" />
|
android:title="@string/pref_title_development_miaddr" />
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="mi_dont_ack_transfer"
|
||||||
|
android:title="@string/pref_title_dont_ack_transfer"
|
||||||
|
android:summary="@string/pref_summary_dont_ack_transfers"
|
||||||
|
android:defaultValue="false" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user