From ae296b489bdd7a4a81e1a27a3158c3f657ac3b18 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 7 May 2021 14:09:16 +0200 Subject: [PATCH] Use dimensions for bullets --- .../java/eu/faircode/email/HtmlHelper.java | 10 +++--- .../java/eu/faircode/email/StyleHelper.java | 32 +++++++++---------- app/src/main/res/values/dimen.xml | 3 ++ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 925536f2f7..b7e4b5a0ed 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -2037,7 +2037,9 @@ public class HtmlHelper { final int colorSeparator = Helper.resolveColor(context, R.attr.colorSeparator); final int dp3 = Helper.dp2pixels(context, 3); final int dp6 = Helper.dp2pixels(context, 6); - final int dp24 = Helper.dp2pixels(context, 24); + int bulletGap = context.getResources().getDimensionPixelSize(R.dimen.bullet_gap_size); + int bulletRadius = context.getResources().getDimensionPixelSize(R.dimen.bullet_radius_size); + int bulletIndent = context.getResources().getDimensionPixelSize(R.dimen.bullet_indent_size); int message_zoom = prefs.getInt("message_zoom", 100); float textSize = Helper.getTextSize(context, 0) * message_zoom / 100f; @@ -2396,9 +2398,9 @@ public class HtmlHelper { if (type == null || "ul".equals(type.tagName())) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) - setSpan(ssb, new BulletSpanEx(dp24, dp6, colorAccent, level), start, ssb.length()); + setSpan(ssb, new BulletSpanEx(bulletIndent, bulletGap, colorAccent, level), start, ssb.length()); else - setSpan(ssb, new BulletSpanEx(dp24, dp6, colorAccent, dp3, level), start, ssb.length()); + setSpan(ssb, new BulletSpanEx(bulletIndent, bulletGap, colorAccent, bulletRadius, level), start, ssb.length()); } else { // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol int index = 0; @@ -2414,7 +2416,7 @@ public class HtmlHelper { } } - setSpan(ssb, new NumberSpan(dp24, dp6, colorAccent, textSize, level, index), start, ssb.length()); + setSpan(ssb, new NumberSpan(bulletIndent, bulletGap, colorAccent, textSize, level, index), start, ssb.length()); } break; diff --git a/app/src/main/java/eu/faircode/email/StyleHelper.java b/app/src/main/java/eu/faircode/email/StyleHelper.java index 5ca8ece9be..d7825886cd 100644 --- a/app/src/main/java/eu/faircode/email/StyleHelper.java +++ b/app/src/main/java/eu/faircode/email/StyleHelper.java @@ -290,9 +290,9 @@ public class StyleHelper { Context context = etBody.getContext(); int colorAccent = Helper.resolveColor(context, R.attr.colorAccent); - int dp3 = Helper.dp2pixels(context, 3); - int dp6 = Helper.dp2pixels(context, 6); - int dp24 = Helper.dp2pixels(context, 24); + int bulletGap = context.getResources().getDimensionPixelSize(R.dimen.bullet_gap_size); + int bulletRadius = context.getResources().getDimensionPixelSize(R.dimen.bullet_radius_size); + int bulletIndent = context.getResources().getDimensionPixelSize(R.dimen.bullet_indent_size); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int message_zoom = prefs.getInt("message_zoom", 100); @@ -315,11 +315,11 @@ public class StyleHelper { Log.i("Insert " + i + "..." + (j + 1) + " size=" + e); if (item.getItemId() == R.id.menu_style_list_bullets) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) - edit.setSpan(new BulletSpanEx(dp24, dp6, colorAccent, 0), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH); + edit.setSpan(new BulletSpanEx(bulletIndent, bulletGap, colorAccent, 0), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH); else - edit.setSpan(new BulletSpanEx(dp24, dp6, colorAccent, dp3, 0), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH); + edit.setSpan(new BulletSpanEx(bulletIndent, bulletGap, colorAccent, bulletRadius, 0), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH); else - edit.setSpan(new NumberSpan(dp24, dp6, colorAccent, textSize, 0, index++), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH); + edit.setSpan(new NumberSpan(bulletIndent, bulletGap, colorAccent, textSize, 0, index++), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH); i = j + 1; } @@ -525,27 +525,27 @@ public class StyleHelper { return (T) new QuoteSpan(q.getColor(), q.getStripeWidth(), q.getGapWidth()); } else if (NumberSpan.class.isAssignableFrom(type)) { NumberSpan n = (NumberSpan) span; - int dp6 = Helper.dp2pixels(context, 6); - int dp24 = Helper.dp2pixels(context, 24); + int bulletGap = context.getResources().getDimensionPixelSize(R.dimen.bullet_gap_size); + int bulletIndent = context.getResources().getDimensionPixelSize(R.dimen.bullet_indent_size); int colorAccent = Helper.resolveColor(context, R.attr.colorAccent); - return (T) new NumberSpan(dp24, dp6, colorAccent, n.getTextSize(), n.getLevel(), n.getIndex() + 1); + return (T) new NumberSpan(bulletIndent, bulletGap, colorAccent, n.getTextSize(), n.getLevel(), n.getIndex() + 1); } else if (BulletSpanEx.class.isAssignableFrom(type)) { BulletSpanEx b = (BulletSpanEx) span; - int dp24 = Helper.dp2pixels(context, 24); + int bulletIndent = context.getResources().getDimensionPixelSize(R.dimen.bullet_indent_size); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { - int dp6 = Helper.dp2pixels(context, 6); int colorAccent = Helper.resolveColor(context, R.attr.colorAccent); - return (T) new BulletSpanEx(dp24, dp6, colorAccent, b.getLevel()); + int bulletGap = context.getResources().getDimensionPixelSize(R.dimen.bullet_gap_size); + return (T) new BulletSpanEx(bulletIndent, bulletGap, colorAccent, b.getLevel()); } else - return (T) new BulletSpanEx(dp24, b.getGapWidth(), b.getColor(), b.getBulletRadius(), b.getLevel()); + return (T) new BulletSpanEx(bulletIndent, b.getGapWidth(), b.getColor(), b.getBulletRadius(), b.getLevel()); } else throw new IllegalArgumentException(type.getName()); } static void renumber(Editable text, boolean clean, Context context) { - int dp6 = Helper.dp2pixels(context, 6); - int dp24 = Helper.dp2pixels(context, 24); + int bulletGap = context.getResources().getDimensionPixelSize(R.dimen.bullet_gap_size); + int bulletIndent = context.getResources().getDimensionPixelSize(R.dimen.bullet_indent_size); int colorAccent = Helper.resolveColor(context, R.attr.colorAccent); Log.i("Renumber clean=" + clean + " text=" + text); @@ -595,7 +595,7 @@ public class StyleHelper { if (index != ns.getIndex()) { text.removeSpan(span); // Text size needs measuring - NumberSpan clone = new NumberSpan(dp24, dp6, colorAccent, ns.getTextSize(), level, index); + NumberSpan clone = new NumberSpan(bulletIndent, bulletGap, colorAccent, ns.getTextSize(), level, index); text.setSpan(clone, start, end, flags); } diff --git a/app/src/main/res/values/dimen.xml b/app/src/main/res/values/dimen.xml index 9ee21777ef..921cd5aa8f 100644 --- a/app/src/main/res/values/dimen.xml +++ b/app/src/main/res/values/dimen.xml @@ -5,4 +5,7 @@ 12sp 6dp 24dp + 6dp + 3dp + 24dp \ No newline at end of file