diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index ba20cb0159..6e051bb561 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -34,6 +34,7 @@ import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; import android.text.TextWatcher; +import android.text.style.RelativeSizeSpan; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -98,6 +99,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private ViewButtonColor btnComposeColor; private Spinner spComposeFont; + private Spinner spComposeTextSize; private SwitchCompat swComposeMonospaced; private SwitchCompat swPrefixOnce; private SwitchCompat swPrefixCount; @@ -146,7 +148,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc "send_delayed", "send_undo", "answer_single", "answer_action", "sound_sent", - "compose_color", "compose_font", "compose_monospaced", + "compose_color", "compose_font", "compose_text_size", "compose_monospaced", "prefix_once", "prefix_count", "alt_re", "alt_fwd", "separate_reply", "extended_reply", "template_reply", "write_below", "quote_reply", "quote_limit", "resize_reply", "resize_paste", @@ -197,6 +199,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc btnComposeColor = view.findViewById(R.id.btnComposeColor); spComposeFont = view.findViewById(R.id.spComposeFont); + spComposeTextSize = view.findViewById(R.id.spComposeTextSize); swComposeMonospaced = view.findViewById(R.id.swComposeMonospaced); swPrefixOnce = view.findViewById(R.id.swPrefixOnce); swPrefixCount = view.findViewById(R.id.swPrefixCount); @@ -239,7 +242,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc List fonts = StyleHelper.getFonts(getContext(), false); List fn = new ArrayList<>(); - fn.add("-"); + fn.add(getString(R.string.title_style_font_default)); for (int i = 0; i < fonts.size(); i++) { StyleHelper.FontDescriptor font = fonts.get(i); SpannableStringBuilder ssb = new SpannableStringBuilderEx(font.toString()); @@ -248,9 +251,31 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc fn.add(ssb); } - ArrayAdapter adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, fn); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spComposeFont.setAdapter(adapter); + ArrayAdapter fontAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, fn); + fontAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spComposeFont.setAdapter(fontAdapter); + + int[] textSizeTitles = new int[]{ + R.string.title_style_size_xsmall, + R.string.title_style_size_small, + R.string.title_style_size_medium, + R.string.title_style_size_large, + R.string.title_style_size_xlarge}; + + List ts = new ArrayList<>(); + ts.add(getString(R.string.title_style_font_default)); + for (int i = 0; i < textSizeTitles.length; i++) { + SpannableStringBuilder ssb = new SpannableStringBuilderEx(getString(textSizeTitles[i])); + Float size = HtmlHelper.getFontSize(HtmlHelper.fontSizeNames[i], 1.0f); + if (size == null) + size = 1.0f; + ssb.setSpan(new RelativeSizeSpan(size), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + ts.add(ssb); + } + + ArrayAdapter sizeAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, ts); + sizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spComposeTextSize.setAdapter(sizeAdapter); setOptions(); @@ -572,6 +597,21 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } }); + spComposeTextSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + if (position == 0) + prefs.edit().remove("compose_text_size").apply(); + else + prefs.edit().putString("compose_text_size", HtmlHelper.fontSizeNames[position - 1]).apply(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("compose_text_size").apply(); + } + }); + swComposeMonospaced.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -1009,6 +1049,13 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } } + String compose_text_size = prefs.getString("compose_text_size", ""); + for (int pos = 0; pos < HtmlHelper.fontSizeNames.length; pos++) + if (HtmlHelper.fontSizeNames[pos].equals(compose_text_size)) { + spComposeTextSize.setSelection(pos + 1); + break; + } + swComposeMonospaced.setChecked(prefs.getBoolean("compose_monospaced", false)); swPrefixOnce.setChecked(prefs.getBoolean("prefix_once", true)); diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 98cea5484a..881382ddd5 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -138,6 +138,10 @@ public class HtmlHelper { static final float FONT_LARGE = 1.25f; // 20px=1.2 static final float FONT_XLARGE = 1.50f; // 24px=1.5 + static final String[] fontSizeNames = new String[]{ + "x-small", "small", "medium", "large", "x-large" + }; + static final int MAX_FULL_TEXT_SIZE = 1024 * 1024; // characters static final int MAX_SHARE_TEXT_SIZE = 50 * 1024; // characters static final int MAX_TRANSLATABLE_TEXT_SIZE = 50 * 1024; // characters @@ -2045,7 +2049,7 @@ public class HtmlHelper { return null; } - private static Float getFontSize(String value, float current) { + static Float getFontSize(String value, float current) { // https://developer.mozilla.org/en-US/docs/Web/CSS/font-size if (TextUtils.isEmpty(value)) return null; diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index db0e11111d..15113f27d5 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -1009,6 +1009,7 @@ public class MessageHelper { boolean format_flowed = prefs.getBoolean("format_flowed", false); int compose_color = prefs.getInt("compose_color", Color.TRANSPARENT); String compose_font = prefs.getString("compose_font", ""); + String compose_text_size = prefs.getString("compose_text_size", ""); boolean auto_link = prefs.getBoolean("auto_link", false); // Build html body @@ -1039,7 +1040,9 @@ public class MessageHelper { HtmlHelper.autoLink(document, true); } - if (!TextUtils.isEmpty(compose_font) || compose_color != Color.TRANSPARENT) { + if (compose_color != Color.TRANSPARENT || + !TextUtils.isEmpty(compose_font) || + !TextUtils.isEmpty(compose_text_size)) { List childs = new ArrayList<>(); for (Node child : document.body().childNodes()) if (TextUtils.isEmpty(child.attr("fairemail"))) { @@ -1049,10 +1052,12 @@ public class MessageHelper { break; StringBuilder style = new StringBuilder(); - if (!TextUtils.isEmpty(compose_font)) - style.append("font-family: ").append(StyleHelper.getFamily(compose_font)).append(';'); if (compose_color != Color.TRANSPARENT) style.append("color: ").append(HtmlHelper.encodeWebColor(compose_color)).append(';'); + if (!TextUtils.isEmpty(compose_font)) + style.append("font-family: ").append(StyleHelper.getFamily(compose_font)).append(';'); + if (!TextUtils.isEmpty(compose_text_size)) + style.append("font-size: ").append(compose_text_size).append(';'); Element div = document.createElement("div").attr("style", style.toString()); diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index 6fe1605fe5..2173db8111 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -574,11 +574,21 @@ android:id="@+id/spComposeFont" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginStart="12dp" android:layout_marginTop="12dp" android:entries="@array/fontNameNames" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvComposeFont" /> + +