Added text alignment

pull/187/head
M66B 4 years ago
parent b341c680da
commit 19e75f50be

@ -170,7 +170,7 @@ public class HtmlEx {
// Only use the last AlignmentSpan with flag SPAN_PARAGRAPH
for (int i = alignmentSpans.length - 1; i >= 0; i--) {
AlignmentSpan s = alignmentSpans[i];
if ((text.getSpanFlags(s) & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH) {
if ((text.getSpanFlags(s) & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH || true) {
final Layout.Alignment alignment = s.getAlignment();
if (alignment == Layout.Alignment.ALIGN_NORMAL) {
textAlign = "text-align:start;";

@ -2043,6 +2043,7 @@ public class HtmlHelper {
Layout.Alignment alignment = null;
switch (value) {
case "left":
case "start":
case "justify":
alignment = (ltr ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_OPPOSITE);
break;
@ -2050,6 +2051,7 @@ public class HtmlHelper {
alignment = Layout.Alignment.ALIGN_CENTER;
break;
case "right":
case "end":
alignment = (ltr ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_NORMAL);
break;
}

@ -6,9 +6,12 @@ import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Build;
import android.text.Layout;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.AlignmentSpan;
import android.text.style.BulletSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
@ -34,6 +37,7 @@ import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class StyleHelper {
static boolean apply(int action, View anchor, EditText etBody, Object... args) {
@ -115,6 +119,8 @@ public class StyleHelper {
return setSize(item);
case R.id.group_style_color:
return setColor(item);
case R.id.group_style_align:
return setAlignment(item);
case R.id.group_style_list:
return setList(item);
case R.id.group_style_font:
@ -201,6 +207,34 @@ public class StyleHelper {
etBody.setSelection(s, e);
}
private boolean setAlignment(MenuItem item) {
AlignmentSpan[] spans = t.getSpans(s, e, AlignmentSpan.class);
for (AlignmentSpan span : spans)
t.removeSpan(span);
Layout.Alignment alignment = null;
boolean ltr = (TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_LTR);
switch (item.getItemId()) {
case R.id.menu_style_align_start:
alignment = (ltr ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_OPPOSITE);
break;
case R.id.menu_style_align_center:
alignment = Layout.Alignment.ALIGN_CENTER;
break;
case R.id.menu_style_align_end:
alignment = (ltr ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_NORMAL);
break;
}
if (alignment != null)
t.setSpan(new AlignmentSpan.Standard(alignment), s, e, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(t);
etBody.setSelection(s, e);
return true;
}
private boolean setList(MenuItem item) {
Context context = etBody.getContext();

@ -30,8 +30,29 @@
</group>
<item
android:id="@+id/menu_style_list"
android:id="@+id/menu_style_align"
android:orderInCategory="3"
android:title="@string/title_style_align">
<menu>
<group android:id="@+id/group_style_align">
<item
android:id="@+id/menu_style_align_start"
android:title="@string/title_style_align_start" />
<item
android:id="@+id/menu_style_align_center"
android:title="@string/title_style_align_center" />
<item
android:id="@+id/menu_style_align_end"
android:title="@string/title_style_align_end" />
</group>
</menu>
</item>
<item
android:id="@+id/menu_style_list"
android:orderInCategory="4"
android:title="@string/title_style_list">
<menu>
<group android:id="@+id/group_style_list">
@ -45,10 +66,9 @@
</menu>
</item>
<item
android:id="@+id/menu_style_font"
android:orderInCategory="4"
android:orderInCategory="5"
android:title="@string/title_style_font">
<menu>
<group android:id="@+id/group_style_font" />
@ -57,7 +77,7 @@
<group
android:id="@+id/group_style_blockquote"
android:orderInCategory="5">
android:orderInCategory="6">
<item
android:id="@+id/menu_style_blockquote"
android:title="@string/title_style_blockquote" />
@ -65,7 +85,7 @@
<group
android:id="@+id/group_style_strikethrough"
android:orderInCategory="6">
android:orderInCategory="7">
<item
android:id="@+id/menu_style_strikethrough"
android:title="@string/title_style_strikethrough" />
@ -73,7 +93,7 @@
<group
android:id="@+id/group_style_clear"
android:orderInCategory="7">
android:orderInCategory="8">
<item
android:id="@+id/menu_style_clear"
android:title="@string/title_style_clear" />

@ -934,6 +934,10 @@
<string name="title_style_size_medium">Medium</string>
<string name="title_style_size_large">Large</string>
<string name="title_style_color">Color &#8230;</string>
<string name="title_style_align">Align</string>
<string name="title_style_align_start">Start</string>
<string name="title_style_align_center">Center</string>
<string name="title_style_align_end">End</string>
<string name="title_style_list">List</string>
<string name="title_style_list_bullets">Bullets</string>
<string name="title_style_list_numbered">Numbered</string>

Loading…
Cancel
Save