1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-22 07:42:52 +00:00

Added default send font size option

This commit is contained in:
M66B 2024-12-21 09:21:20 +01:00
parent b49072eac2
commit b59ce60dec
4 changed files with 76 additions and 10 deletions

View file

@ -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<StyleHelper.FontDescriptor> fonts = StyleHelper.getFonts(getContext(), false);
List<CharSequence> 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<CharSequence> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, fn);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spComposeFont.setAdapter(adapter);
ArrayAdapter<CharSequence> 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<CharSequence> 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<CharSequence> 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));

View file

@ -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;

View file

@ -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<Node> 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());

View file

@ -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" />
<eu.faircode.email.SpinnerEx
android:id="@+id/spComposeTextSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spComposeFont" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swComposeMonospaced"
android:layout_width="0dp"
@ -588,7 +598,7 @@
android:text="@string/title_advanced_compose_monospaced"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spComposeFont"
app:layout_constraintTop_toBottomOf="@id/spComposeTextSize"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat