Show compose font appearance

pull/198/head
M66B 4 years ago
parent 3b765e947e
commit 39210829bc

@ -22,6 +22,9 @@ package eu.faircode.email;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.TypefaceSpan;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -29,6 +32,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.Spinner; import android.widget.Spinner;
@ -40,6 +44,9 @@ import androidx.lifecycle.Lifecycle;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.util.ArrayList;
import java.util.List;
public class FragmentOptionsSend extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { public class FragmentOptionsSend extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swKeyboard; private SwitchCompat swKeyboard;
private SwitchCompat swKeyboardNoFullscreen; private SwitchCompat swKeyboardNoFullscreen;
@ -132,6 +139,20 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
spReceiptType = view.findViewById(R.id.spReceiptType); spReceiptType = view.findViewById(R.id.spReceiptType);
swLookupMx = view.findViewById(R.id.swLookupMx); swLookupMx = view.findViewById(R.id.swLookupMx);
String[] fontNameNames = getResources().getStringArray(R.array.fontNameNames);
String[] fontNameValues = getResources().getStringArray(R.array.fontNameValues);
List<CharSequence> fn = new ArrayList<>();
for (int i = 0; i < fontNameNames.length; i++) {
SpannableStringBuilder ssb = new SpannableStringBuilder(fontNameNames[i]);
ssb.setSpan(new TypefaceSpan(fontNameValues[i]), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
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);
setOptions(); setOptions();
// Wire controls // Wire controls
@ -220,13 +241,12 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
spComposeFont.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { spComposeFont.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
String[] values = getResources().getStringArray(R.array.fontNameValues); String value = fontNameValues[position];
String value = values[position];
boolean monospaced = prefs.getBoolean("monospaced", false); boolean monospaced = prefs.getBoolean("monospaced", false);
if (value.equals(monospaced ? "monospace" : "sans-serif")) if (value.equals(monospaced ? "monospace" : "sans-serif"))
prefs.edit().remove("compose_font").apply(); prefs.edit().remove("compose_font").apply();
else else
prefs.edit().putString("compose_font", values[position]).apply(); prefs.edit().putString("compose_font", value).apply();
} }
@Override @Override

Loading…
Cancel
Save