From 6b1ba4d161ba8673499c5422208086e27b903136 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Mon, 14 Aug 2017 21:35:34 +0200 Subject: [PATCH] Don't duplicate colors, use the theme #757 --- .../activities/ControlCenterv2.java | 12 +++++- .../gadgetbridge/util/AndroidUtils.java | 39 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java index 6dd08504a..164dfc4c4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java @@ -197,7 +197,7 @@ public class ControlCenterv2 extends AppCompatActivity checkAndRequestPermissions(); } - ChangeLog cl = new ChangeLog(this, (GBApplication.isDarkThemeEnabled() ? "body { color: #ffffff; background-color: #282828; }\n" : "") + DEFAULT_CSS); + ChangeLog cl = createChangeLog(); if (cl.isFirstRun()) { cl.getLogDialog().show(); } @@ -251,7 +251,7 @@ public class ControlCenterv2 extends AppCompatActivity GBApplication.quit(); return true; case R.id.external_changelog: - ChangeLog cl = new ChangeLog(this, (GBApplication.isDarkThemeEnabled() ? "body { color: #ffffff; background-color: #282828; }\n" : "") + DEFAULT_CSS); + ChangeLog cl = createChangeLog(); cl.getFullLogDialog().show(); return true; } @@ -259,6 +259,14 @@ public class ControlCenterv2 extends AppCompatActivity return true; } + private ChangeLog createChangeLog() { + String css = ChangeLog.DEFAULT_CSS; + css += "body { " + + "color: " + AndroidUtils.getTextColorHex(getBaseContext()) + "; " + + "background-color: " + AndroidUtils.getBackgroundColorHex(getBaseContext()) + ";" + + "}"; + return new ChangeLog(this, css); +} private void launchDiscoveryActivity() { startActivity(new Intent(this, DiscoveryActivity.class)); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AndroidUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AndroidUtils.java index 9c3af56f2..a3258b19f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AndroidUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AndroidUtils.java @@ -20,12 +20,16 @@ import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.res.Configuration; +import android.graphics.Color; import android.os.ParcelUuid; import android.os.Parcelable; import android.support.v4.content.LocalBroadcastManager; import java.util.Locale; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.R; + public class AndroidUtils { public static ParcelUuid[] toParcelUUids(Parcelable[] uuids) { if (uuids == null) { @@ -74,4 +78,39 @@ public class AndroidUtils { activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); activity.recreate(); } + + /** + * Returns the theme dependent text color as a css-style hex string. + * @param context the context to access the colour + */ + public static String getTextColorHex(Context context) { + int color; + if (GBApplication.isDarkThemeEnabled()) { + color = context.getResources().getColor(R.color.primarytext_dark); + } else { + color = context.getResources().getColor(R.color.primarytext_light); + } + return colorToHex(color); + } + + /** + * Returns the theme dependent background color as a css-style hex string. + * @param context the context to access the colour + */ + public static String getBackgroundColorHex(Context context) { + int color; + if (GBApplication.isDarkThemeEnabled()) { + color = context.getResources().getColor(R.color.cardview_dark_background); + } else { + color = context.getResources().getColor(R.color.cardview_light_background); + } + return colorToHex(color); + } + + private static String colorToHex(int color) { + return "#" + + Integer.toHexString(Color.red(color)) + + Integer.toHexString(Color.green(color)) + + Integer.toHexString(Color.blue(color)); + } }