diff --git a/HtmlTextView/build.gradle b/HtmlTextView/build.gradle
index 385e793..0501b05 100644
--- a/HtmlTextView/build.gradle
+++ b/HtmlTextView/build.gradle
@@ -22,4 +22,5 @@ publish {
dependencies {
implementation 'androidx.annotation:annotation:1.1.0'
-}
+
+ }
diff --git a/HtmlTextView/src/main/java/org/sufficientlysecure/htmltextview/DesignQuoteSpan.java b/HtmlTextView/src/main/java/org/sufficientlysecure/htmltextview/DesignQuoteSpan.java
new file mode 100644
index 0000000..8b08784
--- /dev/null
+++ b/HtmlTextView/src/main/java/org/sufficientlysecure/htmltextview/DesignQuoteSpan.java
@@ -0,0 +1,73 @@
+package org.sufficientlysecure.htmltextview;
+
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.text.Layout;
+import android.text.style.LeadingMarginSpan;
+import android.text.style.LineBackgroundSpan;
+
+import androidx.annotation.NonNull;
+
+public class DesignQuoteSpan implements LeadingMarginSpan, LineBackgroundSpan {
+
+ private int backgroundColor,stripColor;
+ private float stripeWidth,gap;
+ DesignQuoteSpan(int backgroundColor,
+ int stripColor,
+ float stripWidth,
+ float gap){
+
+ this.backgroundColor=backgroundColor;
+ this.stripColor=stripColor;
+ this.stripeWidth=stripWidth;
+ this.gap=gap;
+
+ }
+
+ @Override
+ public int getLeadingMargin(boolean first) {
+ return (int)(stripeWidth + gap);
+ }
+
+ @Override
+ public void drawLeadingMargin(Canvas c,
+ Paint p,
+ int x,
+ int dir,
+ int top,
+ int baseline,
+ int bottom,
+ CharSequence text,
+ int start,
+ int end,
+ boolean first,
+ Layout layout) {
+
+ Paint.Style style=p.getStyle();
+ int paintColor=p.getColor();
+ p.setStyle(Paint.Style.FILL);
+ p.setColor(stripColor);
+ c.drawRect((float)x,(float)top,x+dir * stripeWidth,(float)bottom,p);
+ p.setStyle(style);
+ p.setColor(paintColor);
+
+ }
+
+ @Override
+ public void drawBackground(@NonNull Canvas canvas,
+ @NonNull Paint paint,
+ int left,
+ int right,
+ int top,
+ int baseline,
+ int bottom,
+ @NonNull CharSequence text,
+ int start,
+ int end,
+ int lineNumber) {
+ int paintColor=paint.getColor();
+ paint.setColor(backgroundColor);
+ canvas.drawRect((float)left,(float)top,(float)right,(float)bottom,paint);
+ paint.setColor(paintColor);
+ }
+}
diff --git a/HtmlTextView/src/main/java/org/sufficientlysecure/htmltextview/HtmlTextView.java b/HtmlTextView/src/main/java/org/sufficientlysecure/htmltextview/HtmlTextView.java
index b3541d0..9f6cb26 100644
--- a/HtmlTextView/src/main/java/org/sufficientlysecure/htmltextview/HtmlTextView.java
+++ b/HtmlTextView/src/main/java/org/sufficientlysecure/htmltextview/HtmlTextView.java
@@ -18,6 +18,9 @@
import android.content.Context;
import android.text.Html;
+import android.text.Spannable;
+import android.text.Spanned;
+import android.text.style.QuoteSpan;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
@@ -31,7 +34,10 @@ public class HtmlTextView extends JellyBeanSpanFixTextView {
public static final String TAG = "HtmlTextView";
public static final boolean DEBUG = false;
-
+ public int blockQuoteBackgroundColor= getResources().getColor(R.color.White);
+ public int blockQuoteStripColor= getResources().getColor(R.color.black);
+ public float blockQuoteStripWidth =10F;
+ public float blockQuoteGap=20F;
@Nullable
private ClickableTableSpan clickableTableSpan;
@Nullable
@@ -92,7 +98,10 @@ public void setHtml(@RawRes int resId, @Nullable Html.ImageGetter imageGetter) {
* HtmlLocalImageGetter and HtmlRemoteImageGetter
*/
public void setHtml(@NonNull String html, @Nullable Html.ImageGetter imageGetter) {
- setText(HtmlFormatter.formatHtml(html, imageGetter, clickableTableSpan, drawTableLinkSpan, onClickATagListener,indent, removeTrailingWhiteSpace));
+
+ Spanned styledText = HtmlFormatter.formatHtml(html, imageGetter, clickableTableSpan, drawTableLinkSpan, onClickATagListener, indent, removeTrailingWhiteSpace);
+ replaceQuoteSpans(styledText);
+ setText(styledText);
// make links work
setMovementMethod(LocalLinkMovementMethod.getInstance());
@@ -155,4 +164,27 @@ private static String convertStreamToString(@NonNull InputStream is) {
Scanner s = new Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
+
+
+ private void replaceQuoteSpans(Spanned spanned) {
+
+ Spannable spannable = (Spannable) spanned;
+ QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length() - 1, QuoteSpan.class);
+ for (QuoteSpan quoteSpan : quoteSpans) {
+ int start = spannable.getSpanStart(quoteSpan);
+ int end = spannable.getSpanEnd(quoteSpan);
+ int flags = spannable.getSpanFlags(quoteSpan);
+ spannable.removeSpan(quoteSpan);
+ spannable.setSpan(new DesignQuoteSpan(
+ blockQuoteBackgroundColor,
+ blockQuoteStripColor,
+ blockQuoteStripWidth,
+ blockQuoteGap),
+ start,
+ end,
+ flags);
+ }
+ }
+
+
}
\ No newline at end of file
diff --git a/HtmlTextView/src/main/res/values/colors.xml b/HtmlTextView/src/main/res/values/colors.xml
new file mode 100644
index 0000000..813f0c6
--- /dev/null
+++ b/HtmlTextView/src/main/res/values/colors.xml
@@ -0,0 +1,5 @@
+
+
+
+ +This text is in blockquote TAG
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ut eros sed arcu auctor tincidunt id sit amet elit. Mauris in faucibus neque. Suspendisse facilisis urna nec nisi convallis tincidunt. Mauris at elit et arcu viverra auctor. Nullam et arcu ultricies, iaculis dolor efficitur, tristique eros. @@ -127,7 +129,7 @@Hello world
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vestibulum aliquam convallis dapibus. Aenean suscipit, orci id elementum vehicula, odio arcu fringilla massa, vel imperdiet augue est non mi. - +
Android will add extra space at the bottom of the textView by default fromHtml,
use setRemoveFromHtmlSpace(true)
on your HtmlTextView
diff --git a/example/src/main/res/values/colors.xml b/example/src/main/res/values/colors.xml
new file mode 100644
index 0000000..07df4af
--- /dev/null
+++ b/example/src/main/res/values/colors.xml
@@ -0,0 +1,5 @@
+
+