mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-14 12:44:15 +02:00
add option to average data points in the diagram for one day/month
make time and date editable on new measurement dialog
This commit is contained in:
@@ -258,8 +258,8 @@ public class DataEntryActivity extends Activity {
|
|||||||
btnRight.setVisibility(View.GONE);
|
btnRight.setVisibility(View.GONE);
|
||||||
expandButton.setVisibility(View.GONE);
|
expandButton.setVisibility(View.GONE);
|
||||||
switchEditMode.setVisibility(View.GONE);
|
switchEditMode.setVisibility(View.GONE);
|
||||||
dateMeasurement.setVisibility(View.GONE);
|
dateMeasurement.setVisibility(View.VISIBLE);
|
||||||
timeMeasurement.setVisibility(View.GONE);
|
timeMeasurement.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -292,7 +292,7 @@ public class UserSettingsActivity extends Activity {
|
|||||||
String date = txtBirthday.getText().toString();
|
String date = txtBirthday.getText().toString();
|
||||||
String goal_date = txtGoalDate.getText().toString();
|
String goal_date = txtGoalDate.getText().toString();
|
||||||
|
|
||||||
int id = -1;
|
int id = 0;
|
||||||
|
|
||||||
if (getIntent().getExtras().getInt("mode") == EDIT_USER_REQUEST)
|
if (getIntent().getExtras().getInt("mode") == EDIT_USER_REQUEST)
|
||||||
{
|
{
|
||||||
@@ -302,7 +302,7 @@ public class UserSettingsActivity extends Activity {
|
|||||||
{
|
{
|
||||||
openScale.addScaleUser(name, date, body_height, scale_unit, gender, initial_weight, goal_weight, goal_date);
|
openScale.addScaleUser(name, date, body_height, scale_unit, gender, initial_weight, goal_weight, goal_date);
|
||||||
|
|
||||||
id = openScale.getScaleUserList().get(openScale.getScaleUserList().size()-1).id;
|
id = openScale.getScaleUserList().get(openScale.getScaleUserList().size() - 1).id;
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
@@ -42,6 +42,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter;
|
import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter;
|
||||||
import lecho.lib.hellocharts.listener.ColumnChartOnValueSelectListener;
|
import lecho.lib.hellocharts.listener.ColumnChartOnValueSelectListener;
|
||||||
@@ -81,6 +82,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
private Calendar calLastSelected;
|
private Calendar calLastSelected;
|
||||||
|
|
||||||
private ArrayList<ScaleData> scaleDataList;
|
private ArrayList<ScaleData> scaleDataList;
|
||||||
|
private ArrayList<ScaleData> pointIndexScaleDataList;
|
||||||
|
|
||||||
public GraphFragment() {
|
public GraphFragment() {
|
||||||
calYears = Calendar.getInstance();
|
calYears = Calendar.getInstance();
|
||||||
@@ -174,54 +176,79 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
generateGraphs();
|
generateGraphs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a point to a point value stack.
|
||||||
|
*
|
||||||
|
* Average y value of point if x value is already on the stack and option "averageData" is enabled.
|
||||||
|
*
|
||||||
|
* @param pointValues stack of point values
|
||||||
|
* @param value_x x value of the point
|
||||||
|
* @param value_y y value of the point
|
||||||
|
* @return true if a new point was added otherwise false if point was average added to an existing point
|
||||||
|
*/
|
||||||
|
private boolean addPointValue(Stack<PointValue> pointValues, float value_x, float value_y) {
|
||||||
|
if (prefs.getBoolean("averageData", true) && !pointValues.isEmpty() && pointValues.peek().getX() == value_x) {
|
||||||
|
pointValues.push(new PointValue(value_x, (pointValues.pop().getY() + value_y) / 2.0f));
|
||||||
|
} else {
|
||||||
|
if (value_y != 0.0f) { // don't show zero values
|
||||||
|
pointValues.add(new PointValue(value_x, value_y));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void generateLineData(int field)
|
private void generateLineData(int field)
|
||||||
{
|
{
|
||||||
SimpleDateFormat day_date = new SimpleDateFormat("D", Locale.getDefault());
|
SimpleDateFormat day_date = new SimpleDateFormat("D", Locale.getDefault());
|
||||||
|
|
||||||
if (field == Calendar.DAY_OF_MONTH) {
|
if (field == Calendar.DAY_OF_MONTH) {
|
||||||
day_date = new SimpleDateFormat("dd", Locale.getDefault());
|
day_date = new SimpleDateFormat("dd", Locale.getDefault());
|
||||||
|
} else if (field == Calendar.MONTH) {
|
||||||
|
day_date = new SimpleDateFormat("MMM", Locale.getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
Calendar calDays = (Calendar)calLastSelected.clone();
|
Calendar calDays = (Calendar)calLastSelected.clone();
|
||||||
|
|
||||||
calDays.set(field, 1);
|
calDays.set(field, calDays.getActualMinimum(field));
|
||||||
int maxDays = calDays.getActualMaximum(field);
|
int maxDays = calDays.getActualMaximum(field);
|
||||||
|
|
||||||
List<AxisValue> axisValues = new ArrayList<AxisValue>();
|
List<AxisValue> axisValues = new ArrayList<AxisValue>();
|
||||||
|
|
||||||
for (int i=0; i<maxDays; i++) {
|
for (int i=0; i<maxDays+1; i++) {
|
||||||
String day_name = day_date.format(calDays.getTime());
|
String day_name = day_date.format(calDays.getTime());
|
||||||
|
|
||||||
axisValues.add(new AxisValue(i, day_name.toCharArray()));
|
axisValues.add(new AxisValue(i+calDays.getActualMinimum(field), day_name.toCharArray()));
|
||||||
|
|
||||||
calDays.add(field, 1);
|
calDays.add(field, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<PointValue> valuesWeight = new ArrayList<PointValue>();
|
Stack<PointValue> valuesWeight = new Stack<PointValue>();
|
||||||
List<PointValue> valuesFat = new ArrayList<PointValue>();
|
Stack<PointValue> valuesFat = new Stack<PointValue>();
|
||||||
List<PointValue> valuesWater = new ArrayList<PointValue>();
|
Stack<PointValue> valuesWater = new Stack<PointValue>();
|
||||||
List<PointValue> valuesMuscle = new ArrayList<PointValue>();
|
Stack<PointValue> valuesMuscle = new Stack<PointValue>();
|
||||||
List<PointValue> valuesWaist = new ArrayList<PointValue>();
|
Stack<PointValue> valuesWaist = new Stack<PointValue>();
|
||||||
List<PointValue> valuesHip = new ArrayList<PointValue>();
|
Stack<PointValue> valuesHip = new Stack<PointValue>();
|
||||||
List<Line> lines = new ArrayList<Line>();
|
List<Line> lines = new ArrayList<Line>();
|
||||||
|
|
||||||
Calendar calDB = Calendar.getInstance();
|
Calendar calDB = Calendar.getInstance();
|
||||||
|
|
||||||
|
pointIndexScaleDataList = new ArrayList<>();
|
||||||
|
|
||||||
for(ScaleData scaleEntry: scaleDataList)
|
for(ScaleData scaleEntry: scaleDataList)
|
||||||
{
|
{
|
||||||
calDB.setTime(scaleEntry.getDateTime());
|
calDB.setTime(scaleEntry.getDateTime());
|
||||||
|
|
||||||
valuesWeight.add(new PointValue(calDB.get(field)-1, scaleEntry.getConvertedWeight(openScale.getSelectedScaleUser().scale_unit)));
|
if (addPointValue(valuesWeight, calDB.get(field), scaleEntry.getConvertedWeight(openScale.getSelectedScaleUser().scale_unit))) {
|
||||||
if (scaleEntry.getFat() != 0.0f)
|
pointIndexScaleDataList.add(scaleEntry); // if new point was added, add this point to pointIndexScaleDataList to get the correct point index after selecting an point
|
||||||
valuesFat.add(new PointValue(calDB.get(field)-1, scaleEntry.getFat()));
|
}
|
||||||
if (scaleEntry.getWater() != 0.0f)
|
|
||||||
valuesWater.add(new PointValue(calDB.get(field)-1, scaleEntry.getWater()));
|
addPointValue(valuesFat, calDB.get(field), scaleEntry.getFat());
|
||||||
if (scaleEntry.getMuscle() != 0.0f)
|
addPointValue(valuesWater, calDB.get(field), scaleEntry.getWater());
|
||||||
valuesMuscle.add(new PointValue(calDB.get(field)-1, scaleEntry.getMuscle()));
|
addPointValue(valuesMuscle, calDB.get(field), scaleEntry.getMuscle());
|
||||||
if (scaleEntry.getWaist() != 0.0f)
|
addPointValue(valuesWaist, calDB.get(field), scaleEntry.getWaist());
|
||||||
valuesWaist.add(new PointValue(calDB.get(field)-1, scaleEntry.getWaist()));
|
addPointValue(valuesHip, calDB.get(field), scaleEntry.getHip());
|
||||||
if (scaleEntry.getHip() != 0.0f)
|
|
||||||
valuesHip.add(new PointValue(calDB.get(field)-1, scaleEntry.getHip()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -375,7 +402,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
|
|
||||||
scaleDataList = openScale.getScaleDataOfYear(calYears.get(Calendar.YEAR));
|
scaleDataList = openScale.getScaleDataOfYear(calYears.get(Calendar.YEAR));
|
||||||
|
|
||||||
generateLineData(Calendar.DAY_OF_YEAR);
|
generateLineData(Calendar.MONTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,7 +441,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
private class chartBottomValueTouchListener implements LineChartOnValueSelectListener {
|
private class chartBottomValueTouchListener implements LineChartOnValueSelectListener {
|
||||||
@Override
|
@Override
|
||||||
public void onValueSelected(int lineIndex, int pointIndex, PointValue pointValue) {
|
public void onValueSelected(int lineIndex, int pointIndex, PointValue pointValue) {
|
||||||
ScaleData scaleData = scaleDataList.get(pointIndex);
|
ScaleData scaleData = pointIndexScaleDataList.get(pointIndex);
|
||||||
|
|
||||||
long id = scaleData.getId();
|
long id = scaleData.getId();
|
||||||
|
|
||||||
|
@@ -130,4 +130,5 @@
|
|||||||
<string name="info_enter_initial_weight">Gebe dein Gewicht in deiner Einheit an</string>
|
<string name="info_enter_initial_weight">Gebe dein Gewicht in deiner Einheit an</string>
|
||||||
<string name="info_enter_goal_weight">Gebe dein Gewicht in deiner Einheit an</string>
|
<string name="info_enter_goal_weight">Gebe dein Gewicht in deiner Einheit an</string>
|
||||||
<string name="error_initial_weight_required">Fehler Anfangsgewicht ist erforderlich</string>
|
<string name="error_initial_weight_required">Fehler Anfangsgewicht ist erforderlich</string>
|
||||||
|
<string name="label_average_data">Berechne Durchschnitt pro Tag/Monat</string>
|
||||||
</resources>
|
</resources>
|
@@ -149,4 +149,5 @@
|
|||||||
<string name="label_not_found">not found</string>
|
<string name="label_not_found">not found</string>
|
||||||
<string name="label_ignoreOutOfRange">Ignore data that are out of range</string>
|
<string name="label_ignoreOutOfRange">Ignore data that are out of range</string>
|
||||||
<string name="label_initial_weight">Initial weight</string>
|
<string name="label_initial_weight">Initial weight</string>
|
||||||
|
<string name="label_average_data">Calculate average per day/month</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -3,4 +3,5 @@
|
|||||||
<CheckBoxPreference android:title="@string/label_enable_labels" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="labelsEnable" android:defaultValue="true"/>
|
<CheckBoxPreference android:title="@string/label_enable_labels" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="labelsEnable" android:defaultValue="true"/>
|
||||||
<CheckBoxPreference android:title="@string/label_enable_points" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="pointsEnable" android:defaultValue="true"/>
|
<CheckBoxPreference android:title="@string/label_enable_points" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="pointsEnable" android:defaultValue="true"/>
|
||||||
<CheckBoxPreference android:title="@string/label_delete_confirmation" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="deleteConfirmationEnable" android:defaultValue="true" />
|
<CheckBoxPreference android:title="@string/label_delete_confirmation" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="deleteConfirmationEnable" android:defaultValue="true" />
|
||||||
|
<CheckBoxPreference android:title="@string/label_average_data" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="averageData" android:defaultValue="true" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Reference in New Issue
Block a user