mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Activity Card: React to User settings. Unify step length
This commit is contained in:
parent
4398076ecc
commit
468a40c62e
@ -90,7 +90,7 @@ public class SleepAlarmWidget extends AppWidgetProvider {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
super.onReceive(context, intent);
|
||||
if (ACTION.equals(intent.getAction())) {
|
||||
int userSleepDuration = new ActivityUser().getSleepDuration();
|
||||
int userSleepDuration = new ActivityUser().getSleepDurationGoal();
|
||||
// current timestamp
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
// add preferred sleep duration
|
||||
|
@ -158,11 +158,11 @@ public class Widget extends AppWidgetProvider {
|
||||
int sleep = (int) dailyTotals[1];
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
int stepGoal = activityUser.getStepsGoal();
|
||||
int sleepGoal = activityUser.getSleepDuration();
|
||||
int sleepGoal = activityUser.getSleepDurationGoal();
|
||||
int sleepGoalMinutes = sleepGoal * 60;
|
||||
int distanceGoal = activityUser.getDistanceMeters() * 100;
|
||||
int distanceGoal = activityUser.getDistanceGoalMeters() * 100;
|
||||
int stepLength = activityUser.getStepLengthCm();
|
||||
double distanceMeters = dailyTotals[0] * stepLength / 100;
|
||||
double distanceMeters = dailyTotals[0] * stepLength * 0.01;
|
||||
double distanceFeet = distanceMeters * 3.28084f;
|
||||
double distanceFormatted = 0;
|
||||
|
||||
|
@ -47,6 +47,12 @@ public class AboutUserPreferencesActivity extends AbstractSettingsActivity {
|
||||
addPreferenceHandlerFor(PREF_USER_WEIGHT_KG);
|
||||
addPreferenceHandlerFor(PREF_USER_GENDER);
|
||||
addPreferenceHandlerFor(PREF_USER_STEPS_GOAL);
|
||||
|
||||
addIntentNotificationListener(PREF_USER_STEPS_GOAL);
|
||||
addIntentNotificationListener(PREF_USER_HEIGHT_CM);
|
||||
addIntentNotificationListener(PREF_USER_SLEEP_DURATION);
|
||||
addIntentNotificationListener(PREF_USER_STEP_LENGTH_CM);
|
||||
addIntentNotificationListener(PREF_USER_DISTANCE_METERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.Locale;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
||||
|
||||
/**
|
||||
@ -243,4 +244,26 @@ public abstract class AbstractSettingsActivity extends AppCompatPreferenceActivi
|
||||
LOG.warn("Could not find preference " + preferenceKey);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that the Control center is re-rendered when user preferences change
|
||||
protected void addIntentNotificationListener(final String preferenceKey) {
|
||||
Preference pref = findPreference(preferenceKey);
|
||||
|
||||
if (pref != null) {
|
||||
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
||||
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
LOG.warn("Could not find preference " + preferenceKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -514,8 +514,8 @@ public class ControlCenterv2 extends AppCompatActivity
|
||||
for (GBDevice gbDevice : deviceList) {
|
||||
final DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
|
||||
if (coordinator.supportsActivityTracking()) {
|
||||
long[] steps = getSteps(gbDevice, db);
|
||||
deviceActivityHashMap.put(gbDevice.getAddress(), steps);
|
||||
long[] stepsAndSleepData = getSteps(gbDevice, db);
|
||||
deviceActivityHashMap.put(gbDevice.getAddress(), stepsAndSleepData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class WidgetAlarmsActivity extends Activity implements View.OnClickListen
|
||||
|
||||
} else {
|
||||
setContentView(R.layout.widget_alarms_activity_list);
|
||||
int userSleepDuration = new ActivityUser().getSleepDuration();
|
||||
int userSleepDuration = new ActivityUser().getSleepDurationGoal();
|
||||
textView = findViewById(R.id.alarm5);
|
||||
if (userSleepDuration > 0) {
|
||||
Resources res = getResources();
|
||||
@ -117,7 +117,7 @@ public class WidgetAlarmsActivity extends Activity implements View.OnClickListen
|
||||
if (duration > 0) {
|
||||
calendar.add(Calendar.MINUTE, duration);
|
||||
} else {
|
||||
int userSleepDuration = new ActivityUser().getSleepDuration();
|
||||
int userSleepDuration = new ActivityUser().getSleepDurationGoal();
|
||||
// add preferred sleep duration
|
||||
if (userSleepDuration > 0) {
|
||||
calendar.add(Calendar.HOUR_OF_DAY, userSleepDuration);
|
||||
|
@ -41,8 +41,8 @@ public class ActivityListingAdapter extends AbstractActivityListingAdapter<Activ
|
||||
private final int SESSION_EMPTY = ActivitySession.SESSION_EMPTY;
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
int stepsGoal = activityUser.getStepsGoal();
|
||||
int distanceGoalMeters = activityUser.getDistanceMeters();
|
||||
long activeTimeGoalTimeMillis = activityUser.getActiveTimeMinutes() * 60 * 1000L;
|
||||
int distanceGoalMeters = activityUser.getDistanceGoalMeters();
|
||||
long activeTimeGoalTimeMillis = activityUser.getActiveTimeGoalMinutes() * 60 * 1000L;
|
||||
|
||||
public ActivityListingAdapter(Context context) {
|
||||
super(context);
|
||||
|
@ -38,20 +38,13 @@ public class StepAnalysis {
|
||||
LOG.debug("get all samples activitysessions: " + samples.toArray().length);
|
||||
List<ActivitySession> result = new ArrayList<>();
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
double STEP_LENGTH_M;
|
||||
final int MIN_SESSION_LENGTH = 60 * GBApplication.getPrefs().getInt("chart_list_min_session_length", 5);
|
||||
final int MAX_IDLE_PHASE_LENGTH = 60 * GBApplication.getPrefs().getInt("chart_list_max_idle_phase_length", 5);
|
||||
final int MIN_STEPS_PER_MINUTE = GBApplication.getPrefs().getInt("chart_list_min_steps_per_minute", 40);
|
||||
int stepLengthCm = activityUser.getStepLengthCm();
|
||||
int heightCm = activityUser.getHeightCm();
|
||||
totalDailySteps = 0;
|
||||
|
||||
if (stepLengthCm == 0 && heightCm != 0) {
|
||||
STEP_LENGTH_M = heightCm * 0.43 * 0.01;
|
||||
} else {
|
||||
STEP_LENGTH_M = stepLengthCm * 0.01;
|
||||
}
|
||||
final double STEP_LENGTH_M = stepLengthCm * 0.01;
|
||||
final double MIN_SESSION_INTENSITY = Math.max(0, Math.min(1, MIN_STEPS_PER_MINUTE * 0.01));
|
||||
totalDailySteps = 0;
|
||||
|
||||
ActivitySample previousSample = null;
|
||||
Date sessionStart = null;
|
||||
|
@ -525,8 +525,6 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
||||
addPreferenceHandlerFor(PREF_GALAXY_BUDS_TOUCH_RIGHT);
|
||||
addPreferenceHandlerFor(PREF_GALAXY_BUDS_LIVE_ANC);
|
||||
addPreferenceHandlerFor(PREF_GALAXY_BUDS_PRESSURE_RELIEF);
|
||||
addPreferenceHandlerFor(PREFS_DEVICE_CHARTS_TABS);
|
||||
|
||||
|
||||
addPreferenceHandlerFor(PREF_SONY_AMBIENT_SOUND_CONTROL);
|
||||
addPreferenceHandlerFor(PREF_SONY_FOCUS_VOICE);
|
||||
@ -810,7 +808,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
||||
activityInDeviceSteps,
|
||||
activityInDeviceSleep,
|
||||
activityInDeviceDistance,
|
||||
chartsTabsOrderSelection
|
||||
chartsTabsOrderSelection,
|
||||
};
|
||||
|
||||
for (Preference preferenceInControlCenter : preferencesInControlCenter) {
|
||||
|
@ -890,11 +890,11 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
int sleep = (int) dailyTotals[1];
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
int stepGoal = activityUser.getStepsGoal();
|
||||
int sleepGoal = activityUser.getSleepDuration();
|
||||
int sleepGoal = activityUser.getSleepDurationGoal();
|
||||
int sleepGoalMinutes = sleepGoal * 60;
|
||||
int distanceGoal = activityUser.getDistanceMeters() * 100;
|
||||
int distanceGoal = activityUser.getDistanceGoalMeters() * 100;
|
||||
int stepLength = activityUser.getStepLengthCm();
|
||||
double distanceMeters = dailyTotals[0] * stepLength / 100;
|
||||
double distanceMeters = dailyTotals[0] * stepLength * 0.01;
|
||||
double distanceFeet = distanceMeters * 3.28084f;
|
||||
double distanceFormatted = 0;
|
||||
|
||||
|
@ -282,7 +282,7 @@ public class DBHelper {
|
||||
attributes.setValidFromUTC(now.getTime());
|
||||
attributes.setHeightCM(prefsUser.getHeightCm());
|
||||
attributes.setWeightKG(prefsUser.getWeightKg());
|
||||
attributes.setSleepGoalHPD(prefsUser.getSleepDuration());
|
||||
attributes.setSleepGoalHPD(prefsUser.getSleepDurationGoal());
|
||||
attributes.setStepsGoalSPD(prefsUser.getStepsGoal());
|
||||
attributes.setUserId(user.getId());
|
||||
session.getUserAttributesDao().insert(attributes);
|
||||
@ -343,8 +343,8 @@ public class DBHelper {
|
||||
LOG.info("user changed to " + prefsUser.getWeightKg() + " from " + attr.getWeightKG());
|
||||
return false;
|
||||
}
|
||||
if (!Integer.valueOf(prefsUser.getSleepDuration()).equals(attr.getSleepGoalHPD())) {
|
||||
LOG.info("user sleep goal changed to " + prefsUser.getSleepDuration() + " from " + attr.getSleepGoalHPD());
|
||||
if (!Integer.valueOf(prefsUser.getSleepDurationGoal()).equals(attr.getSleepGoalHPD())) {
|
||||
LOG.info("user sleep goal changed to " + prefsUser.getSleepDurationGoal() + " from " + attr.getSleepGoalHPD());
|
||||
return false;
|
||||
}
|
||||
if (!Integer.valueOf(prefsUser.getStepsGoal()).equals(attr.getStepsGoalSPD())) {
|
||||
|
@ -39,11 +39,11 @@ public class ActivityUser {
|
||||
private int activityUserYearOfBirth;
|
||||
private int activityUserHeightCm;
|
||||
private int activityUserWeightKg;
|
||||
private int activityUserSleepDuration;
|
||||
private int activityUserSleepDurationGoal;
|
||||
private int activityUserStepsGoal;
|
||||
private int activityUserCaloriesBurnt;
|
||||
private int activityUserDistanceMeters;
|
||||
private int activityUserActiveTimeMinutes;
|
||||
private int activityUserCaloriesBurntGoal;
|
||||
private int activityUserDistanceGoalMeters;
|
||||
private int activityUserActiveTimeGoalMinutes;
|
||||
private int activityUserStepLengthCm;
|
||||
|
||||
private static final String defaultUserName = "gadgetbridge-user";
|
||||
@ -52,11 +52,11 @@ public class ActivityUser {
|
||||
public static final int defaultUserAge = 0;
|
||||
public static final int defaultUserHeightCm = 175;
|
||||
public static final int defaultUserWeightKg = 70;
|
||||
public static final int defaultUserSleepDuration = 7;
|
||||
public static final int defaultUserSleepDurationGoal = 7;
|
||||
public static final int defaultUserStepsGoal = 8000;
|
||||
public static final int defaultUserCaloriesBurnt = 2000;
|
||||
public static final int defaultUserDistanceMeters = 5000;
|
||||
public static final int defaultUserActiveTimeMinutes = 60;
|
||||
public static final int defaultUserCaloriesBurntGoal = 2000;
|
||||
public static final int defaultUserDistanceGoalMeters = 5000;
|
||||
public static final int defaultUserActiveTimeGoalMinutes = 60;
|
||||
public static final int defaultUserStepLengthCm = 0;
|
||||
|
||||
public static final String PREF_USER_NAME = "mi_user_alias";
|
||||
@ -96,11 +96,26 @@ public class ActivityUser {
|
||||
return activityUserYearOfBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the user defined height or a default value when none is set or the stored
|
||||
* value is 0.
|
||||
*/
|
||||
|
||||
public int getHeightCm() {
|
||||
if (activityUserHeightCm < 1) {
|
||||
activityUserHeightCm = defaultUserHeightCm;
|
||||
}
|
||||
return activityUserHeightCm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the user defined step length or the calculated default value when none is set or the stored
|
||||
* value is 0.
|
||||
*/
|
||||
public int getStepLengthCm() {
|
||||
if (activityUserStepLengthCm < 1) {
|
||||
activityUserStepLengthCm = (int) (getHeightCm() * 0.43);
|
||||
}
|
||||
return activityUserStepLengthCm;
|
||||
}
|
||||
|
||||
@ -108,11 +123,11 @@ public class ActivityUser {
|
||||
* @return the user defined sleep duration or the default value when none is set or the stored
|
||||
* value is out of any logical bounds.
|
||||
*/
|
||||
public int getSleepDuration() {
|
||||
if (activityUserSleepDuration < 1 || activityUserSleepDuration > 24) {
|
||||
activityUserSleepDuration = defaultUserSleepDuration;
|
||||
public int getSleepDurationGoal() {
|
||||
if (activityUserSleepDurationGoal < 1 || activityUserSleepDurationGoal > 24) {
|
||||
activityUserSleepDurationGoal = defaultUserSleepDurationGoal;
|
||||
}
|
||||
return activityUserSleepDuration;
|
||||
return activityUserSleepDurationGoal;
|
||||
}
|
||||
|
||||
public int getStepsGoal() {
|
||||
@ -141,11 +156,11 @@ public class ActivityUser {
|
||||
activityUserHeightCm = prefs.getInt(PREF_USER_HEIGHT_CM, defaultUserHeightCm);
|
||||
activityUserWeightKg = prefs.getInt(PREF_USER_WEIGHT_KG, defaultUserWeightKg);
|
||||
activityUserYearOfBirth = prefs.getInt(PREF_USER_YEAR_OF_BIRTH, defaultUserYearOfBirth);
|
||||
activityUserSleepDuration = prefs.getInt(PREF_USER_SLEEP_DURATION, defaultUserSleepDuration);
|
||||
activityUserSleepDurationGoal = prefs.getInt(PREF_USER_SLEEP_DURATION, defaultUserSleepDurationGoal);
|
||||
activityUserStepsGoal = prefs.getInt(PREF_USER_STEPS_GOAL, defaultUserStepsGoal);
|
||||
activityUserCaloriesBurnt = prefs.getInt(PREF_USER_CALORIES_BURNT, defaultUserCaloriesBurnt);
|
||||
activityUserDistanceMeters = prefs.getInt(PREF_USER_DISTANCE_METERS, defaultUserDistanceMeters);
|
||||
activityUserActiveTimeMinutes = prefs.getInt(PREF_USER_ACTIVETIME_MINUTES, defaultUserActiveTimeMinutes);
|
||||
activityUserCaloriesBurntGoal = prefs.getInt(PREF_USER_CALORIES_BURNT, defaultUserCaloriesBurntGoal);
|
||||
activityUserDistanceGoalMeters = prefs.getInt(PREF_USER_DISTANCE_METERS, defaultUserDistanceGoalMeters);
|
||||
activityUserActiveTimeGoalMinutes = prefs.getInt(PREF_USER_ACTIVETIME_MINUTES, defaultUserActiveTimeGoalMinutes);
|
||||
activityUserStepLengthCm = prefs.getInt(PREF_USER_STEP_LENGTH_CM, defaultUserStepLengthCm);
|
||||
}
|
||||
|
||||
@ -155,27 +170,27 @@ public class ActivityUser {
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public int getCaloriesBurnt()
|
||||
public int getCaloriesBurntGoal()
|
||||
{
|
||||
if (activityUserCaloriesBurnt < 1) {
|
||||
activityUserCaloriesBurnt = defaultUserCaloriesBurnt;
|
||||
if (activityUserCaloriesBurntGoal < 1) {
|
||||
activityUserCaloriesBurntGoal = defaultUserCaloriesBurntGoal;
|
||||
}
|
||||
return activityUserCaloriesBurnt;
|
||||
return activityUserCaloriesBurntGoal;
|
||||
}
|
||||
|
||||
public int getDistanceMeters()
|
||||
public int getDistanceGoalMeters()
|
||||
{
|
||||
if (activityUserDistanceMeters < 1) {
|
||||
activityUserDistanceMeters = defaultUserDistanceMeters;
|
||||
if (activityUserDistanceGoalMeters < 1) {
|
||||
activityUserDistanceGoalMeters = defaultUserDistanceGoalMeters;
|
||||
}
|
||||
return activityUserDistanceMeters;
|
||||
return activityUserDistanceGoalMeters;
|
||||
}
|
||||
|
||||
public int getActiveTimeMinutes()
|
||||
public int getActiveTimeGoalMinutes()
|
||||
{
|
||||
if (activityUserActiveTimeMinutes < 1) {
|
||||
activityUserActiveTimeMinutes = defaultUserActiveTimeMinutes;
|
||||
if (activityUserActiveTimeGoalMinutes < 1) {
|
||||
activityUserActiveTimeGoalMinutes = defaultUserActiveTimeGoalMinutes;
|
||||
}
|
||||
return activityUserActiveTimeMinutes;
|
||||
return activityUserActiveTimeGoalMinutes;
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public class SetConfigurationOperation extends AbstractBTLEOperation<CasioGBX10
|
||||
if(option == CasioConstants.ConfigurationOption.OPTION_DISTANCE_GOAL || all) {
|
||||
// The watch requires a monthly goal, so we multiply that with 30
|
||||
// and divide it by 100 because the value is set in 100m units
|
||||
int distance = user.getDistanceMeters() * 30;
|
||||
int distance = user.getDistanceGoalMeters() * 30;
|
||||
distance = distance / 100;
|
||||
data[6] = (byte)(distance & 0xff);
|
||||
data[7] = (byte)((distance >> 8) & 0xff);
|
||||
@ -179,7 +179,7 @@ public class SetConfigurationOperation extends AbstractBTLEOperation<CasioGBX10
|
||||
|
||||
if(option == CasioConstants.ConfigurationOption.OPTION_ACTIVITY_GOAL || all) {
|
||||
// The watch requires a monthly goal, so we multiply that with 30
|
||||
int time = user.getActiveTimeMinutes() * 30;
|
||||
int time = user.getActiveTimeGoalMinutes() * 30;
|
||||
data[9] = (byte)(time & 0xff);
|
||||
data[10] = (byte)((time >> 8) & 0xff);
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||
@ -1580,10 +1579,10 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
private void setUserGoals(TransactionBuilder builder) {
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
int steps = activityUser.getStepsGoal() / 100; // ZeTime expect the steps in 100 increment
|
||||
int calories = activityUser.getCaloriesBurnt();
|
||||
int distance = activityUser.getDistanceMeters() / 1000; // ZeTime only accepts km goals
|
||||
int sleep = activityUser.getSleepDuration();
|
||||
int activeTime = activityUser.getActiveTimeMinutes();
|
||||
int calories = activityUser.getCaloriesBurntGoal();
|
||||
int distance = activityUser.getDistanceGoalMeters() / 1000; // ZeTime only accepts km goals
|
||||
int sleep = activityUser.getSleepDurationGoal();
|
||||
int activeTime = activityUser.getActiveTimeGoalMinutes();
|
||||
|
||||
// set steps goal
|
||||
byte[] goal_steps = {ZeTimeConstants.CMD_PREAMBLE,
|
||||
|
Loading…
Reference in New Issue
Block a user