From fce26d8fd0c1c442700f893bea72d1aaec6d9187 Mon Sep 17 00:00:00 2001 From: Jakob Nixdorf Date: Thu, 22 Mar 2018 15:27:12 +0100 Subject: [PATCH] Use a custom CSS file to make the LicenseDialog a little nicer This is all we can do for now, for something even nicer we will have to switch to a different library --- .../flocke/andotp/Activities/AboutActivity.java | 17 +++++++++++++---- .../flocke/andotp/Utilities/Tools.java | 12 ++++++++++++ app/src/main/res/values/licenses_css.xml | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/values/licenses_css.xml diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/AboutActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/AboutActivity.java index 7afd764d..900ede82 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/AboutActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/AboutActivity.java @@ -305,11 +305,20 @@ public class AboutActivity extends BaseActivity { public void showLicenses() { - new LicensesDialog.Builder(this) + String backgroundColor = Tools.getCSSRGBAString(Tools.getThemeColor(this, R.attr.colorBackgroundFloating)); + String textColor = Tools.getCSSRGBAString(Tools.getThemeColor(this, android.R.attr.textColorPrimary)); + String textColorSecondary = Tools.getCSSRGBAString(Tools.getThemeColor(this, android.R.attr.textColorSecondary)); + + String cssFormat = getString(R.string.custom_notices_style, backgroundColor, textColor, textColorSecondary); + + LicensesDialog dialog = new LicensesDialog.Builder(this) .setNotices(R.raw.licenses) - .setIncludeOwnLicense(true) .setTitle(R.string.about_label_licenses) - .build() - .show(); + .setShowFullLicenseText(false) + .setIncludeOwnLicense(true) + .setNoticesCssStyle(cssFormat) + .build(); + + dialog.show(); } } diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Tools.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Tools.java index 6680aea0..75275852 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Tools.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Tools.java @@ -25,12 +25,14 @@ package org.shadowice.flocke.andotp.Utilities; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; +import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.net.Uri; import android.os.Build; import android.os.Environment; +import android.support.annotation.ColorInt; import java.io.File; import java.text.DateFormat; @@ -40,6 +42,8 @@ import java.util.Date; import java.util.Locale; public class Tools { + private final static String CSS_RGBA_FORMAT = "rgba(%1$d,%2$d,%3$d,%4$1f)"; + /* Checks if external storage is available for read and write */ public static boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); @@ -63,6 +67,14 @@ public class Tools { return colorValue; } + public static String getCSSRGBAString(@ColorInt int color) { + int red = Color.red(color); + int green = Color.green(color); + int blue = Color.blue(color); + float alpha = ((float) Color.alpha(color) / 255); + return String.format(Locale.ENGLISH, CSS_RGBA_FORMAT, red, green, blue, alpha); + } + /* Create a ColorFilter based on the current theme */ public static ColorFilter getThemeColorFilter(Context context, int colorAttr) { return new PorterDuffColorFilter(getThemeColor(context, colorAttr), PorterDuff.Mode.SRC_IN); diff --git a/app/src/main/res/values/licenses_css.xml b/app/src/main/res/values/licenses_css.xml new file mode 100644 index 00000000..67eb97d3 --- /dev/null +++ b/app/src/main/res/values/licenses_css.xml @@ -0,0 +1,17 @@ + + + + body { + background-color: %1$s; + color: %2$s; + font-family: sans-serif; + overflow-wrap: break-word; + } + pre { + background-color: %1$s; + color: %3$s; + white-space: pre-wrap; + padding: 1em; + } + + \ No newline at end of file