mirror of https://github.com/M66B/FairEmail.git
Added settings background color
This commit is contained in:
parent
72869a9778
commit
774c246e33
|
@ -30,6 +30,7 @@ import android.text.SpannableStringBuilder;
|
|||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.AlignmentSpan;
|
||||
import android.text.style.BackgroundColorSpan;
|
||||
import android.text.style.BulletSpan;
|
||||
import android.text.style.CharacterStyle;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
|
@ -181,6 +182,8 @@ public class StyleHelper {
|
|||
int itemId = item.getItemId();
|
||||
if (groupId == R.id.group_style_size) {
|
||||
return setSize(item);
|
||||
} else if (itemId == R.id.menu_style_background) {
|
||||
return setBackground(item);
|
||||
} else if (itemId == R.id.menu_style_color) {
|
||||
return setColor(item);
|
||||
} else if (groupId == R.id.group_style_font) {
|
||||
|
@ -238,6 +241,59 @@ public class StyleHelper {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean setBackground(MenuItem item) {
|
||||
Helper.hideKeyboard(etBody);
|
||||
|
||||
Context context = etBody.getContext();
|
||||
int editTextColor = Helper.resolveColor(context, android.R.attr.editTextColor);
|
||||
|
||||
ColorPickerDialogBuilder builder = ColorPickerDialogBuilder
|
||||
.with(context)
|
||||
.setTitle(R.string.title_background)
|
||||
.showColorEdit(true)
|
||||
.setColorEditTextColor(editTextColor)
|
||||
.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) {
|
||||
_setBackground(selectedColor);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
_setBackground(null);
|
||||
}
|
||||
});
|
||||
|
||||
builder.build().show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void _setBackground(Integer color) {
|
||||
Log.breadcrumb("style", "action", "background");
|
||||
|
||||
BackgroundColorSpan spans[] = edit.getSpans(start, end, BackgroundColorSpan.class);
|
||||
for (BackgroundColorSpan span : spans) {
|
||||
int s = edit.getSpanStart(span);
|
||||
int e = edit.getSpanEnd(span);
|
||||
int f = edit.getSpanFlags(span);
|
||||
edit.removeSpan(span);
|
||||
splitSpan(edit, start, end, s, e, f, false,
|
||||
new BackgroundColorSpan(span.getBackgroundColor()),
|
||||
new BackgroundColorSpan(span.getBackgroundColor()));
|
||||
}
|
||||
|
||||
if (color != null)
|
||||
edit.setSpan(new BackgroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
etBody.setText(edit);
|
||||
etBody.setSelection(start, end);
|
||||
}
|
||||
|
||||
private boolean setColor(MenuItem item) {
|
||||
Helper.hideKeyboard(etBody);
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6,4h10v2H6z"
|
||||
android:strokeAlpha="0.3"
|
||||
android:fillAlpha="0.3"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M17,2L5,2c-0.55,0 -1,0.45 -1,1v4c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1L18,6h1v4L9,10v11c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-9h8L21,4h-3L18,3c0,-0.55 -0.45,-1 -1,-1zM16,6L6,6L6,4h10v2z"/>
|
||||
</vector>
|
|
@ -22,10 +22,20 @@
|
|||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_style_background"
|
||||
android:icon="@drawable/twotone_format_paint_24"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/title_background">
|
||||
<menu>
|
||||
<group android:id="@+id/group_style_background" />
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_style_color"
|
||||
android:icon="@drawable/twotone_palette_24"
|
||||
android:orderInCategory="2"
|
||||
android:orderInCategory="3"
|
||||
android:title="@string/title_color">
|
||||
<menu>
|
||||
<group android:id="@+id/group_style_color" />
|
||||
|
@ -35,7 +45,7 @@
|
|||
<item
|
||||
android:id="@+id/menu_style_font"
|
||||
android:icon="@drawable/twotone_text_format_24"
|
||||
android:orderInCategory="3"
|
||||
android:orderInCategory="4"
|
||||
android:title="@string/title_style_font">
|
||||
<menu>
|
||||
<group android:id="@+id/group_style_font" />
|
||||
|
@ -45,7 +55,7 @@
|
|||
<item
|
||||
android:id="@+id/menu_style_align"
|
||||
android:icon="@drawable/twotone_format_align_center_24"
|
||||
android:orderInCategory="4"
|
||||
android:orderInCategory="5"
|
||||
android:title="@string/title_style_align">
|
||||
<menu>
|
||||
<group android:id="@+id/group_style_align">
|
||||
|
@ -70,7 +80,7 @@
|
|||
<item
|
||||
android:id="@+id/menu_style_list"
|
||||
android:icon="@drawable/twotone_format_list_bulleted_24"
|
||||
android:orderInCategory="5"
|
||||
android:orderInCategory="6"
|
||||
android:title="@string/title_style_list">
|
||||
<menu>
|
||||
<group android:id="@+id/group_style_list">
|
||||
|
@ -96,7 +106,7 @@
|
|||
|
||||
<group
|
||||
android:id="@+id/group_style_blockquote"
|
||||
android:orderInCategory="6">
|
||||
android:orderInCategory="7">
|
||||
<item
|
||||
android:id="@+id/menu_style_blockquote"
|
||||
android:icon="@drawable/twotone_format_quote_24"
|
||||
|
@ -105,7 +115,7 @@
|
|||
|
||||
<group
|
||||
android:id="@+id/group_style_strikethrough"
|
||||
android:orderInCategory="7">
|
||||
android:orderInCategory="8">
|
||||
<item
|
||||
android:id="@+id/menu_style_strikethrough"
|
||||
android:icon="@drawable/twotone_format_strikethrough_24"
|
||||
|
@ -114,7 +124,7 @@
|
|||
|
||||
<group
|
||||
android:id="@+id/group_style_clear"
|
||||
android:orderInCategory="8">
|
||||
android:orderInCategory="9">
|
||||
<item
|
||||
android:id="@+id/menu_style_clear"
|
||||
android:icon="@drawable/twotone_format_clear_24"
|
||||
|
|
|
@ -706,6 +706,7 @@
|
|||
<string name="title_account_interval_hint">Frequency of refreshing the connection for push messages or frequency of checking for new messages</string>
|
||||
<string name="title_account_partial_fetch_hint">Disable this only in case of empty messages or corrupt attachments</string>
|
||||
<string name="title_color">Color</string>
|
||||
<string name="title_background">Background</string>
|
||||
<string name="title_transparent">Transparent</string>
|
||||
<string name="title_account_ondemand">Synchronize manually</string>
|
||||
<string name="title_account_notify">Separate notifications</string>
|
||||
|
|
Loading…
Reference in New Issue