Refactoring

pull/194/merge
M66B 3 years ago
parent 741b7c99bb
commit e0f0d2c783

@ -25,6 +25,7 @@ import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.TypefaceSpan;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -158,14 +159,14 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swReceiptLegacy = view.findViewById(R.id.swReceiptLegacy);
swLookupMx = view.findViewById(R.id.swLookupMx);
String[] fontNameNames = getResources().getStringArray(R.array.fontNameNames);
String[] fontNameValues = getResources().getStringArray(R.array.fontNameValues);
List<Pair<String, String>> fonts = StyleHelper.getFonts(getContext());
List<CharSequence> fn = new ArrayList<>();
fn.add("-");
for (int i = 0; i < fontNameNames.length; i++) {
SpannableStringBuilder ssb = new SpannableStringBuilderEx(fontNameNames[i]);
ssb.setSpan(new TypefaceSpan(fontNameValues[i]), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
for (int i = 0; i < fonts.size(); i++) {
Pair<String, String> font = fonts.get(i);
SpannableStringBuilder ssb = new SpannableStringBuilderEx(font.second);
ssb.setSpan(new TypefaceSpan(font.first), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
fn.add(ssb);
}
@ -304,7 +305,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
spComposeFont.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
String value = (position == 0 ? "" : fontNameValues[position - 1]);
String value = (position == 0 ? "" : fonts.get(position - 1).first);
boolean monospaced = prefs.getBoolean("monospaced", false);
if (value.equals(monospaced ? "monospace" : "sans-serif"))
prefs.edit().remove("compose_font").apply();
@ -574,12 +575,14 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
boolean monospaced = prefs.getBoolean("monospaced", false);
String compose_font = prefs.getString("compose_font", monospaced ? "monospace" : "sans-serif");
String[] fontNameValues = getResources().getStringArray(R.array.fontNameValues);
for (int pos = 0; pos < fontNameValues.length; pos++)
if (fontNameValues[pos].equals(compose_font)) {
List<Pair<String, String>> fonts = StyleHelper.getFonts(getContext());
for (int pos = 0; pos < fonts.size(); pos++) {
Pair<String, String> font = fonts.get(pos);
if (font.first.equals(compose_font)) {
spComposeFont.setSelection(pos + 1);
break;
}
}
swSeparateReply.setChecked(prefs.getBoolean("separate_reply", false));
swExtendedReply.setChecked(prefs.getBoolean("extended_reply", false));

@ -169,15 +169,15 @@ public class StyleHelper {
}
}
String[] fontNameNames = anchor.getResources().getStringArray(R.array.fontNameNames);
String[] fontNameValues = anchor.getResources().getStringArray(R.array.fontNameValues);
List<Pair<String, String>> fonts = getFonts(anchor.getContext());
SubMenu smenu = popupMenu.getMenu().findItem(R.id.menu_style_font).getSubMenu();
for (int i = 0; i < fontNameNames.length; i++) {
SpannableStringBuilder ssb = new SpannableStringBuilderEx(fontNameNames[i]);
ssb.setSpan(getTypefaceSpan(fontNameValues[i], context), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
for (int i = 0; i < fonts.size(); i++) {
Pair<String, String> font = fonts.get(i);
SpannableStringBuilder ssb = new SpannableStringBuilderEx(font.second);
ssb.setSpan(getTypefaceSpan(font.first, context), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
smenu.add(R.id.group_style_font, i, 0, ssb);
}
smenu.add(R.id.group_style_font, fontNameNames.length, 0, R.string.title_style_font_default);
smenu.add(R.id.group_style_font, fonts.size(), 0, R.string.title_style_font_default);
int level = -1;
BulletSpan[] spans = edit.getSpans(start, end, BulletSpan.class);
@ -505,8 +505,8 @@ public class StyleHelper {
Log.breadcrumb("style", "action", "font");
int id = item.getItemId();
String[] names = anchor.getResources().getStringArray(R.array.fontNameValues);
String face = (id < names.length ? names[id] : null);
List<Pair<String, String>> fonts = StyleHelper.getFonts(anchor.getContext());
String face = (id < fonts.size() ? fonts.get(id).first : null);
return _setFont(face);
}
@ -953,5 +953,14 @@ public class StyleHelper {
return Typeface.DEFAULT;
}
public static List<Pair<String, String>> getFonts(Context context) {
List<Pair<String, String>> result = new ArrayList<>();
String[] fontNameNames = context.getResources().getStringArray(R.array.fontNameNames);
String[] fontNameValues = context.getResources().getStringArray(R.array.fontNameValues);
for (int i = 0; i < fontNameNames.length; i++)
result.add(new Pair(fontNameValues[i], fontNameNames[i]));
return result;
}
//TextUtils.dumpSpans(text, new LogPrinter(android.util.Log.INFO, "FairEmail"), "afterTextChanged ");
}

Loading…
Cancel
Save