|
|
@ -41,6 +41,7 @@ import androidx.core.view.inputmethod.InputContentInfoCompat;
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
|
|
|
|
|
|
|
|
public class EditTextCompose extends FixedEditText {
|
|
|
|
public class EditTextCompose extends FixedEditText {
|
|
|
|
|
|
|
|
private boolean raw = false;
|
|
|
|
private ISelection selectionListener = null;
|
|
|
|
private ISelection selectionListener = null;
|
|
|
|
private IInputContentListener inputContentListener = null;
|
|
|
|
private IInputContentListener inputContentListener = null;
|
|
|
|
|
|
|
|
|
|
|
@ -56,6 +57,14 @@ public class EditTextCompose extends FixedEditText {
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setRaw(boolean raw) {
|
|
|
|
|
|
|
|
this.raw = raw;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean getRaw() {
|
|
|
|
|
|
|
|
return raw;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onSelectionChanged(int selStart, int selEnd) {
|
|
|
|
protected void onSelectionChanged(int selStart, int selEnd) {
|
|
|
|
super.onSelectionChanged(selStart, selEnd);
|
|
|
|
super.onSelectionChanged(selStart, selEnd);
|
|
|
@ -80,32 +89,37 @@ public class EditTextCompose extends FixedEditText {
|
|
|
|
html = "<div>" + HtmlHelper.formatPre(text.toString(), false) + "</div>";
|
|
|
|
html = "<div>" + HtmlHelper.formatPre(text.toString(), false) + "</div>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Document document = HtmlHelper.sanitizeCompose(context, html, false);
|
|
|
|
SpannableStringBuilder ssb;
|
|
|
|
Spanned paste = HtmlHelper.fromDocument(getContext(), document, true, new Html.ImageGetter() {
|
|
|
|
if (raw)
|
|
|
|
@Override
|
|
|
|
ssb = new SpannableStringBuilder(html);
|
|
|
|
public Drawable getDrawable(String source) {
|
|
|
|
else {
|
|
|
|
return ImageHelper.decodeImage(getContext(),
|
|
|
|
Document document = HtmlHelper.sanitizeCompose(context, html, false);
|
|
|
|
-1, source, true, 0, EditTextCompose.this);
|
|
|
|
Spanned paste = HtmlHelper.fromDocument(getContext(), document, true, new Html.ImageGetter() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Drawable getDrawable(String source) {
|
|
|
|
|
|
|
|
return ImageHelper.decodeImage(getContext(),
|
|
|
|
|
|
|
|
-1, source, true, 0, EditTextCompose.this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
|
|
|
|
|
|
|
|
int dp3 = Helper.dp2pixels(context, 3);
|
|
|
|
|
|
|
|
int dp6 = Helper.dp2pixels(context, 6);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ssb = new SpannableStringBuilder(paste);
|
|
|
|
|
|
|
|
QuoteSpan[] spans = ssb.getSpans(0, ssb.length(), QuoteSpan.class);
|
|
|
|
|
|
|
|
for (QuoteSpan span : spans) {
|
|
|
|
|
|
|
|
QuoteSpan q;
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
|
|
|
|
|
|
|
|
q = new QuoteSpan(colorPrimary);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
q = new QuoteSpan(colorPrimary, dp3, dp6);
|
|
|
|
|
|
|
|
ssb.setSpan(q,
|
|
|
|
|
|
|
|
ssb.getSpanStart(span),
|
|
|
|
|
|
|
|
ssb.getSpanEnd(span),
|
|
|
|
|
|
|
|
ssb.getSpanFlags(span));
|
|
|
|
|
|
|
|
ssb.removeSpan(span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
|
|
|
|
|
|
|
|
int dp3 = Helper.dp2pixels(context, 3);
|
|
|
|
|
|
|
|
int dp6 = Helper.dp2pixels(context, 6);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpannableStringBuilder ssb = new SpannableStringBuilder(paste);
|
|
|
|
|
|
|
|
QuoteSpan[] spans = ssb.getSpans(0, ssb.length(), QuoteSpan.class);
|
|
|
|
|
|
|
|
for (QuoteSpan span : spans) {
|
|
|
|
|
|
|
|
QuoteSpan q;
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
|
|
|
|
|
|
|
|
q = new QuoteSpan(colorPrimary);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
q = new QuoteSpan(colorPrimary, dp3, dp6);
|
|
|
|
|
|
|
|
ssb.setSpan(q,
|
|
|
|
|
|
|
|
ssb.getSpanStart(span),
|
|
|
|
|
|
|
|
ssb.getSpanEnd(span),
|
|
|
|
|
|
|
|
ssb.getSpanFlags(span));
|
|
|
|
|
|
|
|
ssb.removeSpan(span);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int start = getSelectionStart();
|
|
|
|
int start = getSelectionStart();
|
|
|
|