From b9bfb8c93a5d07fb97f72af25ed67bd43f1d888a Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Sat, 29 Oct 2016 20:29:35 +0200 Subject: [PATCH] Use attr resources to enable theme dependent colors for the charts. --- .../charts/AbstractChartFragment.java | 21 ++++++++++++------- app/src/main/res/values/attrs.xml | 7 +++++++ app/src/main/res/values/styles.xml | 8 ++----- 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 app/src/main/res/values/attrs.xml diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java index 253d0388..e314023d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java @@ -8,7 +8,9 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.FragmentActivity; +import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; +import android.util.TypedValue; import android.view.View; import com.github.mikephil.charting.charts.BarChart; @@ -155,15 +157,20 @@ public abstract class AbstractChartFragment extends AbstractGBFragment { } protected void init() { + TypedValue runningColor = new TypedValue(); BACKGROUND_COLOR = GBApplication.getBackgroundColor(getContext()); LEGEND_TEXT_COLOR = DESCRIPTION_COLOR = GBApplication.getTextColor(getContext()); - CHART_TEXT_COLOR = getResources().getColor(R.color.secondarytext); - HEARTRATE_COLOR = getResources().getColor(R.color.chart_heartrate); - HEARTRATE_FILL_COLOR = getResources().getColor(R.color.chart_heartrate_fill); - AK_ACTIVITY_COLOR = getResources().getColor(R.color.chart_activity_light); - AK_DEEP_SLEEP_COLOR = getResources().getColor(R.color.chart_light_sleep_light); - AK_LIGHT_SLEEP_COLOR = getResources().getColor(R.color.chart_deep_sleep_light); - AK_NOT_WORN_COLOR = getResources().getColor(R.color.chart_not_worn_light); + CHART_TEXT_COLOR = ContextCompat.getColor(getContext(), R.color.secondarytext); + HEARTRATE_COLOR = ContextCompat.getColor(getContext(), R.color.chart_heartrate); + HEARTRATE_FILL_COLOR = ContextCompat.getColor(getContext(), R.color.chart_heartrate_fill); + getContext().getTheme().resolveAttribute(R.attr.chart_activity, runningColor, true); + AK_ACTIVITY_COLOR = runningColor.data; + getContext().getTheme().resolveAttribute(R.attr.chart_light_sleep, runningColor, true); + AK_DEEP_SLEEP_COLOR = runningColor.data; + getContext().getTheme().resolveAttribute(R.attr.chart_deep_sleep, runningColor, true); + AK_LIGHT_SLEEP_COLOR = runningColor.data; + getContext().getTheme().resolveAttribute(R.attr.chart_not_worn, runningColor, true); + AK_NOT_WORN_COLOR = runningColor.data; HEARTRATE_LABEL = getContext().getString(R.string.charts_legend_heartrate); diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml new file mode 100644 index 00000000..1a0a1bd0 --- /dev/null +++ b/app/src/main/res/values/attrs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5d6ea28d..26eaea46 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -6,12 +6,10 @@ @color/primarydark_light @color/accent - - + @color/chart_not_worn_light