Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.sysdata.htmlspanner;

import android.graphics.Paint;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
Expand Down Expand Up @@ -72,6 +73,9 @@ public class HtmlSpanner {
* Used for calculating margins.
*/
public static final int HORIZONTAL_EM_WIDTH = 10;
public static int NUMBER_WIDTH = 5;
public static int BULLET_WIDTH = 3;
public static int BLANK_WIDTH = 10;


private Map<String, TagNodeHandler> handlers;
Expand Down Expand Up @@ -175,9 +179,15 @@ public HtmlSpanner(int textColor,float textSize) {
public HtmlSpanner(HtmlCleaner cleaner, FontResolver fontResolver,int textColor, float textSize) {
this.htmlCleaner = cleaner;
this.fontResolver = fontResolver;
this.handlers = new HashMap<String, TagNodeHandler>();
this.handlers = new HashMap<>();
this.textColor=textColor;
this.textSize=textSize;
Paint paint = new Paint();
paint.setTextSize(textSize);
NUMBER_WIDTH = Math.round(paint.measureText("4."));
if(NUMBER_WIDTH <= 0)
BULLET_WIDTH = Math.round(paint.measureText("\u2022"));
BLANK_WIDTH = Math.round(paint.measureText(" "));
registerBuiltInHandlers();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.sysdata.htmlspanner.spans;

import android.app.Notification;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.Layout;
import android.text.Spanned;
import android.text.style.BulletSpan;
import android.text.style.LeadingMarginSpan;
import com.sysdata.htmlspanner.HtmlSpanner;

Expand All @@ -36,11 +38,11 @@
public class ListItemSpan implements LeadingMarginSpan {
private final int mNumber;

private static final int BULLET_RADIUS = 3;
private static final int NUMBER_RADIUS = 5;
private static final int BULLET_RADIUS = HtmlSpanner.BULLET_WIDTH;
private static final int NUMBER_RADIUS = HtmlSpanner.NUMBER_WIDTH;

//Gap should be about 1em
public static final int STANDARD_GAP_WIDTH = HtmlSpanner.HORIZONTAL_EM_WIDTH;
public static final int STANDARD_GAP_WIDTH = HtmlSpanner.BLANK_WIDTH;

public ListItemSpan() {
mNumber = -1;
Expand All @@ -52,9 +54,9 @@ public ListItemSpan(int number) {

public int getLeadingMargin(boolean first) {
if (mNumber != -1) {
return 2 * (NUMBER_RADIUS + STANDARD_GAP_WIDTH);
return (NUMBER_RADIUS + STANDARD_GAP_WIDTH);
} else {
return 2 * (BULLET_RADIUS + STANDARD_GAP_WIDTH);
return (BULLET_RADIUS + STANDARD_GAP_WIDTH);
}
}

Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/com/sysdata/kt/sdhtmltextview/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView.htmlText="<h1>That's a header 1</h1><h2>That's a header 2</h2><h3>That's a header 3</h3><h4>That's a header 4</h4><h5>That's a header 5</h5><h6>That's a header 6</h6>NomeCognome<br />MarioRossi<div style=\"line-height:30px\">Some text displayed in center position into a paragraph <span style=\"background-color:blue; color:white\">other text</span> (<code>span</code> markup used);<br /><big>big thing</big> (<code>big</code> markup used)<br /><small>this is not that important</small> (<code>small</code> markup used)<br />this is <em>very</em> simple (<code>em</code> markup used for emphasizing a word)<br /><cite>Origin of Species</cite> (a book title;<code>cite</code> markup used)<br /><em>Homo sapiens</em> (should appear in italics; <code>i</code> markup used)<br /><br /><strong>bolded</strong> (<code>b</code> markup used - just bolding with unspecified semantics)<div style=\"line-height:24px\"><br />&nbsp;</div><tt>text in monospace font</tt> (<code>tt</code> markup used)<br /><u>underlined</u> text (<code>u</code> markup used)<br /><strong>bolded</strong> (<code>strong</code> markup used)<ul><li>Test: <span>large size</span> (<code>font size=30px</code> markup used)</li><li>Test: <span style=\"color:red\">red text</span> (<code>font color=red</code> markup used)</li></ul>a<sub>B</sub> (<code>sub</code> markup used)<br />a<sup>C</sup> (<code>sup</code> markup used)</div><ol style=\"list-style-position:inside;\"><li>list element 1</li><li>list element 2</li></ol><div style=\"line-height:50px\">that's a div body and a line-height<br />with a <code>br</code> inside and a font styling<br /><span style=\"font-size:30px\">large size</span> (<code>style=&quot;font-size:30px&quot;</code> markup used)<br /><span style=\"font-family:Courier\">Courier font</span> (<code>style=&quot;font-family:Courier&quot;</code> markup used)<br /><span style=\"color:red\">red text</span> (<code>style=&quot;color:red&quot;</code> markup used)<br /><em>italic text</em> (<code>style=&quot;font-style:italic&quot;</code> markup used)<p style=\"text-align:left\">left text</p><p style=\"text-align:center\">centered text</p><p style=\"text-align:right\">right text</p>deleted text</div>"
textView.htmlText="<div style=\"background-color: #272822\"><span style=\"color: #272822\">_</span><span style=\"color: #f8f8f2\">SDRootValidatorConfig</span> <span style=\"color: #f8f8f2\">config</span> <span style=\"color: #f92672\">=</span> <span style=\"color: #f8f8f2\">SDRootValidatorConfig</span>\n<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">newBuilder</span><span style=\"color: #f92672\">(</span><span style=\"color: #f8f8f2\">getContext</span><span style=\"color: #f92672\">())</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">isRootCheckEnabled</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">checkForBinaryBusybox</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">checkForBinarySu</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">checkForDangerousProps</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">checkForMagiskBinary</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">checkForRootNative</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">checkForRWPaths</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">checkSuExists</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">detectPotentiallyDangerousApps</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">detectRootManagementApps</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">detectTestKeys</span><span style=\"color: #f92672\">(</span><span style=\"color: #66d9ef\">true</span><span style=\"color: #f92672\">)</span>\n" +
"<span style=\"color: #272822\">_</span><span style=\"color: #f92672\">.</span><span style=\"color: #a6e22e\">build</span><span style=\"color: #f92672\">();</span>\n" +
"</div>\n"
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>