From 7f3e2745049550f8b3644210b2334c33c6b100b0 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 11 May 2021 08:08:49 +0200 Subject: [PATCH] Show font size appearance --- .../java/eu/faircode/email/HtmlHelper.java | 4 ++-- .../java/eu/faircode/email/StyleHelper.java | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index c0df24b956..23de3e6791 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -114,10 +114,10 @@ import static org.w3c.css.sac.Condition.SAC_CLASS_CONDITION; public class HtmlHelper { static final int PREVIEW_SIZE = 500; // characters + static final float FONT_SMALL = 0.8f; + static final float FONT_LARGE = 1.25f; private static final int DEFAULT_FONT_SIZE = 16; // pixels private static final int DEFAULT_FONT_SIZE_PT = 12; // points - private static final float FONT_SMALL = 0.8f; - private static final float FONT_LARGE = 1.25f; private static final int GRAY_THRESHOLD = Math.round(255 * 0.2f); private static final float MIN_LUMINANCE = 0.7f; private static final int TAB_SIZE = 2; diff --git a/app/src/main/java/eu/faircode/email/StyleHelper.java b/app/src/main/java/eu/faircode/email/StyleHelper.java index 542c8119d6..169e4a25dd 100644 --- a/app/src/main/java/eu/faircode/email/StyleHelper.java +++ b/app/src/main/java/eu/faircode/email/StyleHelper.java @@ -114,9 +114,22 @@ public class StyleHelper { return true; } else if (action == R.id.menu_style) { - PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(anchor.getContext(), owner, anchor); + final Context context = anchor.getContext(); + PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, owner, anchor); popupMenu.inflate(R.menu.popup_style); - popupMenu.insertIcons(anchor.getContext()); + + { + SubMenu smenu = popupMenu.getMenu().findItem(R.id.menu_style_size).getSubMenu(); + smenu.clear(); + int[] ids = new int[]{R.id.menu_style_size_small, R.id.menu_style_size_medium, R.id.menu_style_size_large}; + int[] titles = new int[]{R.string.title_style_size_small, R.string.title_style_size_medium, R.string.title_style_size_large}; + float[] sizes = new float[]{HtmlHelper.FONT_SMALL, 1.0f, HtmlHelper.FONT_LARGE}; + for (int i = 0; i < ids.length; i++) { + SpannableStringBuilder ssb = new SpannableStringBuilder(context.getString(titles[i])); + ssb.setSpan(new RelativeSizeSpan(sizes[i]), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + smenu.add(R.id.group_style_size, ids[i], i, ssb); + } + } String[] fontNameNames = anchor.getResources().getStringArray(R.array.fontNameNames); String[] fontNameValues = anchor.getResources().getStringArray(R.array.fontNameValues); @@ -138,6 +151,8 @@ public class StyleHelper { popupMenu.getMenu().findItem(R.id.menu_style_list_increase).setVisible(level >= 0); popupMenu.getMenu().findItem(R.id.menu_style_list_decrease).setVisible(level > 0); + popupMenu.insertIcons(context); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) {