From d6dee559f716b37b2c01778fd6de86f5744c89c4 Mon Sep 17 00:00:00 2001 From: a0z Date: Tue, 17 Dec 2024 21:18:41 +0100 Subject: [PATCH] PAI fragment: update colors, replace piechart with gauge --- .../activities/charts/PaiChartFragment.java | 108 +++++++----------- .../main/res/layout/fragment_pai_chart.xml | 22 ++-- app/src/main/res/values/colors.xml | 3 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 56 insertions(+), 78 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/PaiChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/PaiChartFragment.java index 0c4fbed42..b1a75e422 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/PaiChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/PaiChartFragment.java @@ -19,9 +19,11 @@ package nodomain.freeyourgadget.gadgetbridge.activities.charts; import android.graphics.Color; import android.os.Build; import android.os.Bundle; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -38,9 +40,6 @@ import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarEntry; import com.github.mikephil.charting.data.ChartData; -import com.github.mikephil.charting.data.PieData; -import com.github.mikephil.charting.data.PieDataSet; -import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.formatter.ValueFormatter; import org.slf4j.Logger; @@ -55,6 +54,7 @@ import java.util.Optional; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.GaugeDrawer; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.TimeSampleProvider; @@ -69,7 +69,7 @@ public class PaiChartFragment extends AbstractChartFragment 0) { - // average = Math.abs(balance / TOTAL_DAYS_FOR_AVERAGE); - //} - //LimitLine average_line = new LimitLine(average); - //average_line.setLabel(getString(R.string.average, getAverage(average))); -// - //if (average > (mTargetValue)) { - // average_line.setLineColor(Color.GREEN); - // average_line.setTextColor(Color.GREEN); - //} else { - // average_line.setLineColor(Color.RED); - // average_line.setTextColor(Color.RED); - //} - //if (average > 0) { - // if (GBApplication.getPrefs().getBoolean("charts_show_average", true)) { - // barChart.getAxisLeft().addLimitLine(average_line); - // } - //} - return new WeekChartsData(barData, new PreformattedXIndexLabelFormatter(labels)); } @@ -383,22 +359,14 @@ public class PaiChartFragment extends AbstractChartFragment entries = new ArrayList<>(); - final int maxPai = Math.max(getPaiTarget(), total); - final String todayLabel = today != 0 ? requireContext().getString(R.string.pai_plus_num, today) : ""; - entries.add(new PieEntry(total - today, "")); - entries.add(new PieEntry(today, todayLabel)); - entries.add(new PieEntry(maxPai - total, "")); + float[] segments = new float[] { + (float) (total - today) / maxPai, + (float) today / maxPai + }; - final PieDataSet pieDataSet = new PieDataSet(entries, ""); - pieDataSet.setColors(PAI_TOTAL_COLOR, PAI_DAY_COLOR, 0x0); - data.setDataSet(pieDataSet); - data.setDrawValues(false); - - return new DayData(day, data, today, total, paiLow, paiModerate, paiHigh, minutesLow, minutesModerate, minutesHigh); + return new DayData(day, segments, today, total, paiLow, paiModerate, paiHigh, minutesLow, minutesModerate, minutesHigh); } protected ValueFormatter getRoundFormatter() { @@ -441,7 +409,7 @@ public class PaiChartFragment extends AbstractChartFragment - + + android:background="@color/chart_pai_today" /> + android:background="@color/chart_pai_weekly" /> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f9b4f6ce8..9d630812b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -37,6 +37,9 @@ #60bd6d #59b22c + #007BFF + #2ECC71 + #545254 #d8d9d8 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5e6188395..7a0750df9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2993,6 +2993,7 @@ Total average %d steps per day My daily step achievements! Steps Achievements + Weekly total Hourly chime The watch will beep once an hour Flipper zero