diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WeekStepsChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WeekStepsChartFragment.java
index 1b1246e30..3cdb32c4f 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WeekStepsChartFragment.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/WeekStepsChartFragment.java
@@ -37,6 +37,7 @@ import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.charts.ActivityAnalysis;
+import nodomain.freeyourgadget.gadgetbridge.miband.MiBandCoordinator;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
@@ -44,7 +45,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
protected static final Logger LOG = LoggerFactory.getLogger(WeekStepsChartFragment.class);
private Locale mLocale;
- private int mTargetSteps;
+ private int mTargetSteps = 10000;
private BarLineChartBase mWeekStepsChart;
private PieChart mTodayStepsChart;
@@ -138,10 +139,6 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
Bundle savedInstanceState) {
mLocale = getResources().getConfiguration().locale;
- //TODO: through mGBDevice we should be able to retrieve the steps goal set by the user
- mTargetSteps = 10000;
-
-
View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false);
Bundle extras = getActivity().getIntent().getExtras();
@@ -149,6 +146,10 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
}
+ if(mGBDevice != null) {
+ mTargetSteps = MiBandCoordinator.getFitnessGoal(mGBDevice.getAddress());
+ }
+
IntentFilter filter = new IntentFilter();
filter.addAction(ControlCenter.ACTION_QUIT);
filter.addAction(ACTION_REFRESH);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandConst.java
index d85cd5ebd..ecb14feaf 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandConst.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandConst.java
@@ -16,6 +16,7 @@ public final class MiBandConst {
public static final String PREF_MIBAND_WEARSIDE = "mi_wearside";
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_FITNESS_GOAL = "mi_fitness_goal";
public static final String ORIGIN_SMS = "sms";
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandCoordinator.java
index b6154e881..afdc3e4e9 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandCoordinator.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandCoordinator.java
@@ -106,4 +106,9 @@ public class MiBandCoordinator implements DeviceCoordinator {
);
return info;
}
+
+ public static int getFitnessGoal(String miBandAddress) throws IllegalArgumentException {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
+ return Integer.parseInt(prefs.getString(MiBandConst.PREF_MIBAND_FITNESS_GOAL, "10000"));
+ }
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandPreferencesActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandPreferencesActivity.java
index a8e03ac4d..9f899a195 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandPreferencesActivity.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandPreferencesActivity.java
@@ -15,6 +15,7 @@ import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_K9M
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_PEBBLEMSG;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_SMS;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_ADDRESS;
+import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_WEARSIDE;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_USER_ALIAS;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_USER_GENDER;
@@ -56,6 +57,7 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
PREF_USER_WEIGHT_KG,
PREF_MIBAND_WEARSIDE,
PREF_MIBAND_ADDRESS,
+ PREF_MIBAND_FITNESS_GOAL,
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_SMS),
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_SMS),
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_INCOMING_CALL),
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java
index be9f288f9..54025feb2 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandService.java
@@ -141,6 +141,7 @@ public class MiBandService {
public static final byte COMMAND_SYNC = 0xb;
+ public static final byte COMMAND_SET_FITNESS_GOAL = 0x5;
/*
@@ -153,8 +154,6 @@ public class MiBandService {
public static final int COMMAND_SET_COLOR_THEME = et;
- public static final COMMAND_SET_FITNESS_GOAL = 0x5t
-
public static final COMMAND_SET_REALTIME_STEP = 0x10t
public static final COMMAND_SET_REALTIME_STEPS_NOTIFICATION = 0x3t
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java
index 612539968..37299c5cf 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java
@@ -93,6 +93,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
builder.add(new SetDeviceStateAction(getDevice(), State.INITIALIZING, getContext()));
pair(builder)
.sendUserInfo(builder)
+ .setFitnessGoal(builder)
.enableNotifications(builder, true)
.setCurrentTime(builder)
.requestBatteryInfo(builder)
@@ -263,7 +264,29 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
return this;
}
+ /**
+ * Part of device initialization process. Do not call manually.
+ *
+ * @param transaction
+ * @return
+ */
+ private MiBandSupport setFitnessGoal(TransactionBuilder transaction) {
+ LOG.info("Attempting to set Fitness Goal...");
+ BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
+ if (characteristic != null) {
+ int fitnessGoal = MiBandCoordinator.getFitnessGoal(getDevice().getAddress());
+ transaction.write(characteristic, new byte[]{
+ MiBandService.COMMAND_SET_FITNESS_GOAL,
+ 0,
+ (byte) (fitnessGoal & 0xff),
+ (byte) ((fitnessGoal >>> 8) & 0xff)
+ });
+ } else {
+ LOG.info("Unable to set Fitness Goal");
+ }
+ return this;
+ }
private void performDefaultNotification(String task, short repeat, BtLEAction extraAction) {
try {
TransactionBuilder builder = performInitialized(task);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7efc98a01..fbd2ef837 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -157,4 +157,5 @@
Alarms sent to device!
No data. Synchronize device?
About to transfer %1$s of data starting from %2$s
+ Target steps for each day
diff --git a/app/src/main/res/xml/miband_preferences.xml b/app/src/main/res/xml/miband_preferences.xml
index 1ac586b22..5fbbb3866 100644
--- a/app/src/main/res/xml/miband_preferences.xml
+++ b/app/src/main/res/xml/miband_preferences.xml
@@ -40,6 +40,14 @@
android:entryValues="@array/wearside_values"
android:key="mi_wearside"
android:title="@string/miband_prefs_wearside" />
+
+
+