Proof of concept create list

pull/184/head
M66B 4 years ago
parent 59d6b939f5
commit 23f8dc637b

@ -113,7 +113,7 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE;
import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_INDIVIDUAL;
import static org.w3c.css.sac.Condition.SAC_CLASS_CONDITION;
public class HtmlHelper {
@ -769,7 +769,7 @@ public class HtmlHelper {
// Lists
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li
if (!view) {
if (!view && !BuildConfig.DEBUG) {
for (Element li : document.select("li")) {
li.tagName("span");
Element parent = li.parent();
@ -1702,6 +1702,9 @@ public class HtmlHelper {
}
static void convertLists(Document document) {
if (BuildConfig.DEBUG)
return;
for (Element span : document.select("span")) {
// Skip signature and referenced message
boolean body = true;
@ -2301,7 +2304,7 @@ public class HtmlHelper {
static String toHtml(Spanned spanned, Context context) {
HtmlEx converter = new HtmlEx(context);
String html = converter.toHtml(spanned, TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
String html = converter.toHtml(spanned, TO_HTML_PARAGRAPH_LINES_INDIVIDUAL);
// @Google: why convert size to and from in a different way?
Document doc = JsoupEx.parse(html);

@ -6,6 +6,7 @@ import android.content.DialogInterface;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.BulletSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.text.style.RelativeSizeSpan;
@ -13,7 +14,6 @@ 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;
@ -96,8 +96,8 @@ public class StyleHelper {
String[] fontNames = anchor.getResources().getStringArray(R.array.fontNameNames);
for (int i = 0; i < fontNames.length; i++)
popupMenu.getMenu().add(R.id.group_style_font, i, 3, fontNames[i]);
popupMenu.getMenu().add(R.id.group_style_font, fontNames.length, 3, R.string.title_style_font_default);
popupMenu.getMenu().add(R.id.group_style_font, i, 4, fontNames[i]);
popupMenu.getMenu().add(R.id.group_style_font, fontNames.length, 4, R.string.title_style_font_default);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
@ -107,6 +107,8 @@ public class StyleHelper {
return setSize(item);
case R.id.group_style_color:
return setColor(item);
case R.id.group_style_list:
return setList(item);
case R.id.group_style_font:
return setFont(item);
case R.id.group_style_clear:
@ -190,6 +192,27 @@ public class StyleHelper {
etBody.setSelection(s, e);
}
private boolean setList(MenuItem item) {
BulletSpan[] spans = t.getSpans(s, e, BulletSpan.class);
for (BulletSpan span : spans)
t.removeSpan(span);
int i = s;
int j = s + 1;
while (j < e) {
if (t.charAt(j) == '\n') {
t.setSpan(new BulletSpan(), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH);
i = j + 1;
}
j++;
}
etBody.setText(t);
etBody.setSelection(s, e);
return true;
}
private boolean setFont(MenuItem item) {
TypefaceSpan[] spans = t.getSpans(s, e, TypefaceSpan.class);
for (TypefaceSpan span : spans)

@ -24,13 +24,21 @@
android:title="@string/title_style_color" />
</group>
<group
android:id="@+id/group_style_list"
android:orderInCategory="3">
<item
android:id="@+id/menu_style_list"
android:title="@string/title_style_list" />
</group>
<group
android:id="@+id/group_style_font"
android:orderInCategory="3" />
android:orderInCategory="4" />
<group
android:id="@+id/group_style_clear"
android:orderInCategory="4">
android:orderInCategory="5">
<item
android:id="@+id/menu_style_clear"
android:title="@string/title_style_clear" />

@ -916,6 +916,7 @@
<string name="title_style_font">Font</string>
<string name="title_style_font_default">Default</string>
<string name="title_style_color">Color &#8230;</string>
<string name="title_style_list">Create list</string>
<string name="title_style_clear">Clear formatting</string>
<string name="title_style_link">Insert link</string>

Loading…
Cancel
Save