mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-30 11:40:23 +02:00
added a menue entry to show in the graph fragment weeks in months or year
This commit is contained in:
@@ -192,6 +192,17 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
prefs.edit().putBoolean("showMonth", true).commit();
|
||||
}
|
||||
|
||||
generateGraphs();
|
||||
return true;
|
||||
case R.id.enableWeek:
|
||||
if (item.isChecked()) {
|
||||
item.setChecked(false);
|
||||
prefs.edit().putBoolean("showWeek", false).commit();
|
||||
} else {
|
||||
item.setChecked(true);
|
||||
prefs.edit().putBoolean("showWeek", true).commit();
|
||||
}
|
||||
|
||||
generateGraphs();
|
||||
return true;
|
||||
default:
|
||||
@@ -206,6 +217,9 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
MenuItem enableMonth = popup.getMenu().findItem(R.id.enableMonth);
|
||||
enableMonth.setChecked(prefs.getBoolean("showMonth", true));
|
||||
|
||||
MenuItem enableWeek = popup.getMenu().findItem(R.id.enableWeek);
|
||||
enableWeek.setChecked(prefs.getBoolean("showWeek", false));
|
||||
|
||||
openScale.registerFragment(this);
|
||||
|
||||
return graphView;
|
||||
@@ -258,7 +272,19 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
*/
|
||||
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));
|
||||
PointValue prevValue = pointValues.pop();
|
||||
PointValue newValue = new PointValue(value_x, (prevValue.getY() + value_y) / 2.0f);
|
||||
|
||||
if (prevValue.getLabelAsChars() != null) {
|
||||
int avgCount = Character.getNumericValue(prevValue.getLabelAsChars()[prevValue.getLabelAsChars().length-3]) * 10 +
|
||||
Character.getNumericValue(prevValue.getLabelAsChars()[prevValue.getLabelAsChars().length-2]) + 1;
|
||||
|
||||
newValue.setLabel(String.format("Ø %.2f (%02d)", newValue.getY(), avgCount));
|
||||
} else {
|
||||
newValue.setLabel(String.format("Ø %.2f (%02d)", newValue.getY(), 2));
|
||||
}
|
||||
|
||||
pointValues.push(newValue);
|
||||
} else {
|
||||
if (value_y != 0.0f) { // don't show zero values
|
||||
pointValues.add(new PointValue(value_x, value_y));
|
||||
@@ -275,6 +301,11 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
|
||||
if (field == Calendar.DAY_OF_MONTH) {
|
||||
day_date = new SimpleDateFormat("dd", Locale.getDefault());
|
||||
|
||||
if (prefs.getBoolean("showWeek", false)) {
|
||||
field = Calendar.WEEK_OF_MONTH;
|
||||
day_date = new SimpleDateFormat("W", Locale.getDefault());
|
||||
}
|
||||
} else if (field == Calendar.DAY_OF_YEAR) {
|
||||
day_date = new SimpleDateFormat("D", Locale.getDefault());
|
||||
|
||||
@@ -282,6 +313,11 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
field = Calendar.MONTH;
|
||||
day_date = new SimpleDateFormat("MMM", Locale.getDefault());
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("showWeek", false)) {
|
||||
field = Calendar.WEEK_OF_YEAR;
|
||||
day_date = new SimpleDateFormat("w", Locale.getDefault());
|
||||
}
|
||||
}
|
||||
|
||||
Calendar calDays = (Calendar)calLastSelected.clone();
|
||||
|
@@ -6,4 +6,8 @@
|
||||
android:id="@+id/enableMonth"
|
||||
android:title="@string/label_month_view"
|
||||
android:checkable="true"/>
|
||||
<item
|
||||
android:id="@+id/enableWeek"
|
||||
android:title="@string/label_weeks_view"
|
||||
android:checkable="true"/>
|
||||
</menu>
|
||||
|
@@ -217,6 +217,7 @@
|
||||
<string name="save">Save</string>
|
||||
|
||||
<string name="label_month_view">Month view</string>
|
||||
<string name="label_weeks_view">Week view</string>
|
||||
|
||||
<string name="permission_not_granted">Permission not granted</string>
|
||||
<string name="permission_bluetooth_info">openScale requires permission to access the coarse location to search for Bluetooth devices</string>
|
||||
|
Reference in New Issue
Block a user