diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java
index a98b550b8a..b988ea3a28 100644
--- a/app/src/main/java/eu/faircode/email/FragmentCompose.java
+++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java
@@ -37,7 +37,6 @@ import android.database.Cursor;
import android.database.MatrixCursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
@@ -275,12 +274,11 @@ public class FragmentCompose extends FragmentBase {
private static final int REQUEST_TAKE_PHOTO = 7;
private static final int REQUEST_RECORD_AUDIO = 8;
private static final int REQUEST_OPENPGP = 9;
- private static final int REQUEST_COLOR = 10;
- private static final int REQUEST_CONTACT_GROUP = 11;
- private static final int REQUEST_ANSWER = 12;
- private static final int REQUEST_LINK = 13;
- private static final int REQUEST_DISCARD = 14;
- private static final int REQUEST_SEND = 15;
+ private static final int REQUEST_CONTACT_GROUP = 10;
+ private static final int REQUEST_ANSWER = 11;
+ private static final int REQUEST_LINK = 12;
+ private static final int REQUEST_DISCARD = 13;
+ private static final int REQUEST_SEND = 14;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -1446,25 +1444,7 @@ public class FragmentCompose extends FragmentBase {
private boolean onActionStyle(int action) {
Log.i("Style action=" + action);
-
- if (action == R.id.menu_color) {
- InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
- if (imm != null)
- imm.hideSoftInputFromWindow(etBody.getWindowToken(), 0);
-
- Bundle args = new Bundle();
- args.putInt("color", Color.TRANSPARENT);
- args.putString("title", getString(R.string.title_style_color));
- args.putInt("start", etBody.getSelectionStart());
- args.putInt("end", etBody.getSelectionEnd());
-
- FragmentDialogColor fragment = new FragmentDialogColor();
- fragment.setArguments(args);
- fragment.setTargetFragment(FragmentCompose.this, REQUEST_COLOR);
- fragment.show(getParentFragmentManager(), "account:color");
- return true;
- } else
- return StyleHelper.apply(action, view.findViewById(action), etBody);
+ return StyleHelper.apply(action, view.findViewById(action), etBody);
}
private void onActionRecordAudio() {
@@ -1752,10 +1732,6 @@ public class FragmentCompose extends FragmentBase {
if (resultCode == RESULT_OK && data != null)
onAnswerSelected(data.getBundleExtra("args"));
break;
- case REQUEST_COLOR:
- if (resultCode == RESULT_OK && data != null)
- onColorSelected(data.getBundleExtra("args"));
- break;
case REQUEST_LINK:
if (resultCode == RESULT_OK && data != null)
onLinkSelected(data.getBundleExtra("args"));
@@ -2764,14 +2740,6 @@ public class FragmentCompose extends FragmentBase {
etBody.getText().insert(etBody.getSelectionStart(), spanned);
}
- private void onColorSelected(Bundle args) {
- int color = args.getInt("color");
- int start = args.getInt("start");
- int end = args.getInt("end");
- etBody.setSelection(start, end);
- StyleHelper.apply(R.id.menu_color, null, etBody, color);
- }
-
private void onLinkSelected(Bundle args) {
String link = args.getString("link");
int start = args.getInt("start");
diff --git a/app/src/main/java/eu/faircode/email/StyleHelper.java b/app/src/main/java/eu/faircode/email/StyleHelper.java
index b8cb7f55db..5762842509 100644
--- a/app/src/main/java/eu/faircode/email/StyleHelper.java
+++ b/app/src/main/java/eu/faircode/email/StyleHelper.java
@@ -1,5 +1,8 @@
package eu.faircode.email;
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.DialogInterface;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
@@ -10,13 +13,18 @@ import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
import android.text.style.URLSpan;
import android.text.style.UnderlineSpan;
-import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import androidx.appcompat.widget.PopupMenu;
+import com.flask.colorpicker.ColorPickerView;
+import com.flask.colorpicker.builder.ColorPickerClickListener;
+import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
+
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
@@ -77,91 +85,162 @@ public class StyleHelper {
return true;
}
- case R.id.menu_size: {
+ case R.id.menu_style: {
final int s = start;
final int e = end;
final SpannableString t = ss;
int order = 1;
PopupMenu popupMenu = new PopupMenu(anchor.getContext(), anchor);
- popupMenu.getMenu().add(Menu.NONE, R.string.title_style_size_small, order++, R.string.title_style_size_small);
- popupMenu.getMenu().add(Menu.NONE, R.string.title_style_size_medium, order++, R.string.title_style_size_medium);
- popupMenu.getMenu().add(Menu.NONE, R.string.title_style_size_large, order++, R.string.title_style_size_large);
+ popupMenu.getMenu().add(0, R.string.title_style_size_small, order++, R.string.title_style_size_small);
+ popupMenu.getMenu().add(0, R.string.title_style_size_medium, order++, R.string.title_style_size_medium);
+ popupMenu.getMenu().add(0, R.string.title_style_size_large, order++, R.string.title_style_size_large);
+
+ popupMenu.getMenu().add(1, R.string.title_style_color, order++, R.string.title_style_color);
+
+ popupMenu.getMenu().add(2, R.string.title_style_font_cursive, order++, R.string.title_style_font_cursive);
+ popupMenu.getMenu().add(2, R.string.title_style_font_serif, order++, R.string.title_style_font_serif);
+ popupMenu.getMenu().add(2, R.string.title_style_font_sans_serif, order++, R.string.title_style_font_sans_serif);
+ popupMenu.getMenu().add(2, R.string.title_style_font_monospace, order++, R.string.title_style_font_monospace);
- popupMenu.getMenu().add(1, R.string.title_style_font_cursive, order++, R.string.title_style_font_cursive);
- popupMenu.getMenu().add(1, R.string.title_style_font_serif, order++, R.string.title_style_font_serif);
- popupMenu.getMenu().add(1, R.string.title_style_font_sans_serif, order++, R.string.title_style_font_sans_serif);
- popupMenu.getMenu().add(1, R.string.title_style_font_monospace, order++, R.string.title_style_font_monospace);
- popupMenu.getMenu().add(1, R.string.title_style_font_default, order++, R.string.title_style_font_default);
+ popupMenu.getMenu().add(3, R.string.title_style_clear, order++, R.string.title_style_clear);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
- if (item.getGroupId() == Menu.NONE) {
- RelativeSizeSpan[] spans = t.getSpans(s, e, RelativeSizeSpan.class);
- for (RelativeSizeSpan span : spans)
- t.removeSpan(span);
+ switch (item.getGroupId()) {
+ case 0:
+ return setSize(item);
+ case 1:
+ return setColor(item);
+ case 2:
+ return setFont(item);
+ case 3:
+ return clear(item);
+ default:
+ return false;
+ }
+ }
- Float size;
- if (item.getItemId() == R.string.title_style_size_small)
- size = 0.8f;
- else if (item.getItemId() == R.string.title_style_size_large)
- size = 1.25f;
- else
- size = null;
-
- if (size != null)
- t.setSpan(new RelativeSizeSpan(size), s, e, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-
- etBody.setText(t);
- etBody.setSelection(s, e);
- } else {
- TypefaceSpan[] spans = t.getSpans(s, e, TypefaceSpan.class);
- for (TypefaceSpan span : spans)
- t.removeSpan(span);
+ private boolean setSize(MenuItem item) {
+ RelativeSizeSpan[] spans = t.getSpans(s, e, RelativeSizeSpan.class);
+ for (RelativeSizeSpan span : spans)
+ t.removeSpan(span);
+
+ Float size;
+ if (item.getItemId() == R.string.title_style_size_small)
+ size = 0.8f;
+ else if (item.getItemId() == R.string.title_style_size_large)
+ size = 1.25f;
+ else
+ size = null;
+
+ if (size != null)
+ t.setSpan(new RelativeSizeSpan(size), s, e, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- String face;
- switch (item.getItemId()) {
- case R.string.title_style_font_cursive:
- face = "cursive";
- break;
- case R.string.title_style_font_serif:
- face = "serif";
- break;
- case R.string.title_style_font_sans_serif:
- face = "sans-serif";
- break;
- case R.string.title_style_font_monospace:
- face = "monospace";
- break;
- default:
- face = null;
- }
-
- if (face != null)
- t.setSpan(new TypefaceSpan(face), s, e, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-
- etBody.setText(t);
- etBody.setSelection(s, e);
+ etBody.setText(t);
+ etBody.setSelection(s, e);
+
+ return true;
+ }
+
+ private boolean setColor(MenuItem item) {
+ InputMethodManager imm = (InputMethodManager) etBody.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
+ if (imm != null)
+ imm.hideSoftInputFromWindow(etBody.getWindowToken(), 0);
+
+ ColorPickerDialogBuilder builder = ColorPickerDialogBuilder
+ .with(etBody.getContext())
+ .setTitle(R.string.title_color)
+ .showColorEdit(true)
+ .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
+ .density(6)
+ .lightnessSliderOnly()
+ .setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
+ _setColor(selectedColor);
+ }
+ })
+ .setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ _setColor(null);
+ }
+ });
+
+ Dialog dialog = builder.build();
+
+ try {
+ Field fColorEdit = builder.getClass().getDeclaredField("colorEdit");
+ fColorEdit.setAccessible(true);
+ EditText colorEdit = (EditText) fColorEdit.get(builder);
+ colorEdit.setTextColor(Helper.resolveColor(etBody.getContext(), android.R.attr.textColorPrimary));
+ } catch (Throwable ex) {
+ Log.w(ex);
}
- return false;
+ dialog.show();
+
+ return true;
}
- });
- popupMenu.show();
+ private void _setColor(Integer color) {
+ for (ForegroundColorSpan span : t.getSpans(s, e, ForegroundColorSpan.class))
+ t.removeSpan(span);
- return true;
- }
+ if (color != null)
+ t.setSpan(new ForegroundColorSpan(color), s, e, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- case R.id.menu_color: {
- for (ForegroundColorSpan span : ss.getSpans(start, end, ForegroundColorSpan.class))
- ss.removeSpan(span);
+ etBody.setText(t);
+ etBody.setSelection(s, e);
+ }
- ss.setSpan(new ForegroundColorSpan((int) args[0]), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ private boolean setFont(MenuItem item) {
+ TypefaceSpan[] spans = t.getSpans(s, e, TypefaceSpan.class);
+ for (TypefaceSpan span : spans)
+ t.removeSpan(span);
+
+ String face;
+ switch (item.getItemId()) {
+ case R.string.title_style_font_cursive:
+ face = "cursive";
+ break;
+ case R.string.title_style_font_serif:
+ face = "serif";
+ break;
+ case R.string.title_style_font_sans_serif:
+ face = "sans-serif";
+ break;
+ case R.string.title_style_font_monospace:
+ face = "monospace";
+ break;
+ default:
+ face = null;
+ }
- etBody.setText(ss);
- etBody.setSelection(start, end);
+ if (face != null)
+ t.setSpan(new TypefaceSpan(face), s, e, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+ etBody.setText(t);
+ etBody.setSelection(s, e);
+
+ return true;
+ }
+
+ private boolean clear(MenuItem item) {
+ for (Object span : t.getSpans(s, e, Object.class))
+ if (!(span instanceof ImageSpan))
+ t.removeSpan(span);
+
+ etBody.setText(t);
+ etBody.setSelection(s, e);
+
+ return true;
+ }
+ });
+
+ popupMenu.show();
return true;
}
diff --git a/app/src/main/res/drawable/baseline_format_color_text_24.xml b/app/src/main/res/drawable/baseline_format_color_text_24.xml
deleted file mode 100644
index b0074516b3..0000000000
--- a/app/src/main/res/drawable/baseline_format_color_text_24.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
diff --git a/app/src/main/res/layout/fragment_legend_compose.xml b/app/src/main/res/layout/fragment_legend_compose.xml
index 359fe87194..8a1212f0cc 100644
--- a/app/src/main/res/layout/fragment_legend_compose.xml
+++ b/app/src/main/res/layout/fragment_legend_compose.xml
@@ -233,47 +233,25 @@
app:layout_constraintTop_toTopOf="@id/ivUnderline" />
+ app:srcCompat="@drawable/baseline_text_format_24" />
-
-
-
-
+ app:layout_constraintStart_toEndOf="@id/ivStyle"
+ app:layout_constraintTop_toTopOf="@id/ivStyle" />
\ No newline at end of file
diff --git a/app/src/main/res/menu/action_answer_style.xml b/app/src/main/res/menu/action_answer_style.xml
index 84809f1cbc..57c1dcc4af 100644
--- a/app/src/main/res/menu/action_answer_style.xml
+++ b/app/src/main/res/menu/action_answer_style.xml
@@ -16,9 +16,9 @@
android:title="@string/title_style_underline" />
+ android:title="@string/title_style" />
-
-
+ android:title="@string/title_style" />
diff --git a/app/src/main/res/menu/action_signature_style.xml b/app/src/main/res/menu/action_signature_style.xml
index 84809f1cbc..57c1dcc4af 100644
--- a/app/src/main/res/menu/action_signature_style.xml
+++ b/app/src/main/res/menu/action_signature_style.xml
@@ -16,9 +16,9 @@
android:title="@string/title_style_underline" />
+ android:title="@string/title_style" />
- Priority
No server found at \'%1$s\'
+ Style
+
Bold
Italic
Underline
+
Size
Small
Medium
Large
+ Font
Cursive
Serif
Sans-serif
Monospace
Default
- Color
+ Color …
Clear formatting
Insert link
+
Add image
Insert
Attach
@@ -1167,8 +1172,7 @@
Make text bold
Make text italic
Underline text
- Set text size
- Set text color
+ Set text style
Connection is metered
Connection is unmetered