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
This commit is contained in:
Jakob Nixdorf 2018-03-22 15:27:12 +01:00
parent d962fa99e5
commit fce26d8fd0
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
3 changed files with 42 additions and 4 deletions

View file

@ -305,11 +305,20 @@ public class AboutActivity extends BaseActivity {
public void showLicenses() { 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) .setNotices(R.raw.licenses)
.setIncludeOwnLicense(true)
.setTitle(R.string.about_label_licenses) .setTitle(R.string.about_label_licenses)
.build() .setShowFullLicenseText(false)
.show(); .setIncludeOwnLicense(true)
.setNoticesCssStyle(cssFormat)
.build();
dialog.show();
} }
} }

View file

@ -25,12 +25,14 @@ package org.shadowice.flocke.andotp.Utilities;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.ColorFilter; import android.graphics.ColorFilter;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.support.annotation.ColorInt;
import java.io.File; import java.io.File;
import java.text.DateFormat; import java.text.DateFormat;
@ -40,6 +42,8 @@ import java.util.Date;
import java.util.Locale; import java.util.Locale;
public class Tools { 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 */ /* Checks if external storage is available for read and write */
public static boolean isExternalStorageWritable() { public static boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState(); String state = Environment.getExternalStorageState();
@ -63,6 +67,14 @@ public class Tools {
return colorValue; 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 */ /* Create a ColorFilter based on the current theme */
public static ColorFilter getThemeColorFilter(Context context, int colorAttr) { public static ColorFilter getThemeColorFilter(Context context, int colorAttr) {
return new PorterDuffColorFilter(getThemeColor(context, colorAttr), PorterDuff.Mode.SRC_IN); return new PorterDuffColorFilter(getThemeColor(context, colorAttr), PorterDuff.Mode.SRC_IN);

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="custom_notices_style" translatable="false">
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;
}
</string>
</resources>