Added support for alphabetical lists

This commit is contained in:
M66B 2021-10-14 19:02:50 +02:00
parent ca1506a091
commit 65403e2df1
5 changed files with 49 additions and 4 deletions

View File

@ -6,6 +6,7 @@
### Next version
* Added support for alphabetical lists (view only)
* Report new messages in same thread when composing a new message
* Use account categories for identities
* Small improvements and minor bug fixes

View File

@ -6,6 +6,7 @@
### Next version
* Added support for alphabetical lists (view only)
* Report new messages in same thread when composing a new message
* Use account categories for identities
* Small improvements and minor bug fixes

View File

@ -2916,8 +2916,9 @@ public class HtmlHelper {
if (level > 0)
level--;
if (list == null || ("ul".equals(list.tagName()) &&
!(ltype != null && ltype.startsWith("decimal")))) {
if (list == null ||
("ul".equals(list.tagName()) &&
!NumberSpan.isSupportedType(ltype))) {
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul
Object ul;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
@ -2940,7 +2941,7 @@ public class HtmlHelper {
}
}
setSpan(ssb, new NumberSpan(bulletIndent, bulletGap, colorAccent, textSize, level, index), start, ssb.length());
setSpan(ssb, new NumberSpan(bulletIndent, bulletGap, colorAccent, textSize, level, index, ltype), start, ssb.length());
}
break;

View File

@ -25,8 +25,14 @@ import android.graphics.Typeface;
import android.text.Layout;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.BulletSpan;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
public class NumberSpan extends BulletSpan {
private int indentWidth;
private int level;
@ -37,7 +43,27 @@ public class NumberSpan extends BulletSpan {
private int numberWidth;
private int margin;
private static final List<String> SUPPORTED_TYPES = Collections.unmodifiableList(Arrays.asList(
"lower-alpha", "lower-latin",
"upper-alpha", "upper-latin"
));
// https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type
static boolean isSupportedType(String type) {
if (TextUtils.isEmpty(type))
return false;
if (type.startsWith("decimal"))
return true;
if (SUPPORTED_TYPES.contains(type))
return true;
return false;
}
public NumberSpan(int indentWidth, int gapWidth, int color, float textSize, int level, int index) {
this(indentWidth, gapWidth, color, textSize, level, index, null);
}
public NumberSpan(int indentWidth, int gapWidth, int color, float textSize, int level, int index, String type) {
tp = new TextPaint();
tp.setStyle(Paint.Style.FILL);
tp.setColor(color);
@ -48,7 +74,22 @@ public class NumberSpan extends BulletSpan {
this.level = level;
this.index = index;
number = index + ".";
if (TextUtils.isEmpty(type))
number = index + ".";
else
switch (type) {
case "lower-alpha":
case "lower-latin":
number = ((char) ((int) 'a' + index)) + ".";
break;
case "upper-alpha":
case "upper-latin":
number = ((char) ((int) 'A' + index)) + ".";
break;
default:
number = index + ".";
}
numberWidth = Math.round(tp.measureText(number));
margin = numberWidth + gapWidth;
}

View File

@ -6,6 +6,7 @@
### Next version
* Added support for alphabetical lists (view only)
* Report new messages in same thread when composing a new message
* Use account categories for identities
* Small improvements and minor bug fixes