For a more readable project overview, see my homepage
stefanhaustein / htmlview2 Goto Github PK
View Code? Open in Web Editor NEWSimple HTML to Native Components Rendering Engine for Android
License: Apache License 2.0
Simple HTML to Native Components Rendering Engine for Android
License: Apache License 2.0
For a more readable project overview, see my homepage
I am missing support for the different types of ordered lists (https://www.w3schools.com/html/html_lists.asp). Currently, only the default number type is used for each type.
this library can be support text-align:justify;
? we have 2 direction LTR and RTL, RTL is for such as arabic language or china
I just tested the change made for #5, but only <ol style="list-style-type:decimal;">
seems to be working as expected. Using <ol style="list-style-type:lower-latin;">
the output looks incorrect.
Here is my code:
String html = String.format("<html><head><style type=\"text/css\">%s</style></head><body>%s</body></html>", css, block.getData());
try {
Reader reader = new StringReader(html);
htmlProcessor.parse(reader, uiHtmlView);
} catch (Exception e) {
throw new RuntimeException(e);
}
java.lang.StackOverflowError
at org.kobjects.css.CssStyleDeclaration.getUnit(CssStyleDeclaration.java:333)
at org.kobjects.css.CssStyleDeclaration.get(CssStyleDeclaration.java:165)
at org.kobjects.css.CssStyleDeclaration.get(CssStyleDeclaration.java:102)
at org.kobjects.css.CssStyleDeclaration.get(CssStyleDeclaration.java:217)
at org.kobjects.css.CssStyleDeclaration.get(CssStyleDeclaration.java:102)
at org.kobjects.css.CssStyleDeclaration.get(CssStyleDeclaration.java:217)
at org.kobjects.css.CssStyleDeclaration.get(CssStyleDeclaration.java:102)
at org.kobjects.css.CssStyleDeclaration.get(CssStyleDeclaration.java:217)
I'm wondering is this possible? I have tried
processor.parse(BufferedReader(ByteArrayInputStream("abc".toByteArray(Charset.defaultCharset())).reader(Charset.defaultCharset())), htmlView) // Also tried using UTF-8
but it throws a runtime exception:
E/AndroidRuntime(24645): Caused by: org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT abc@1:4 in java.io.BufferedReader@2573efd)
Thanks in advance. This is an awesome library!
this is my html:
<html>
<head>
<title>HtmlView Demo</title>
</head>
<body>
<p style="text-align:left;direction:ltr;background-color: #ddf;">
<strong>
Simple HTML to Native
<p> Native Components </p>
Engine for Android
</strong>
</p>
</body>
</html>
Error:
Attempt to invoke virtual method 'boolean org.kobjects.css.CssStyleDeclaration.isSet(org.kobjects.css.CssProperty)' on a null object reference
how can i set parsed html to TextView instead of add view?
can i access directly to link on web? for example http://mysite.com/help.html
to show and parse that without attaching to application or using HttpConnection
is any solution to read and parse html tags from string? i have some html tags which i saved into database and i must read them from that, thanks
hey stefan,
i am trying to set an explicit height using height attribute but there is no effect of it on the element, can you tell me about it?
<div style="background-color:yellow;height:100px;">element</div>
thanks,
Aweosome work btw,
I can't find how to properly style the HtmlView. It uses the CssStyleSheet, but I can't change anything about CssStyleSheet.
Also I can't find out how to set the font size.
This is the lightweight webview I've been looking for a long time. I have had a few apps where I load local html (nothing fancy, only bold, italic, ul, ol). But there wasn't a library that could do it all except WebView which is unbelievably slow. So first, thank you!
I've just been using the library, but there is not much explanation. For example I'm trying to set the base text size. But no clue how to do this. Also I find the indentation for ol and ul lists too big. Is there a way to make that smaller?
Like I said, I've been looking for this a long time. So maybe put it on Android Arsenal or other websites where people can find it and be as excited as me.
hey stefanhaustein,
first of all, you did a great job by creating this and i am currently using it in a project of mine.
back to the issue, can i set a click listener to clickable elements like buttons, or get input from edittext views?
if there is any option like that, i am enable to find one.
thank you
this code is simple way to make clickable part of string:
SpannableString ss = new SpannableString("Android is a Software stack");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
startActivity(new Intent(MyActivity.this, NextActivity.class));
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
ss.setSpan(clickableSpan, 22, 27, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView textView = (TextView) findViewById(R.id.hello);
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(Color.TRANSPARENT);
now how can i implementing this feature for this library?
when i trying to use background-color:#eee;
for <span>
such as :
<span>
It's to
<span style="color:#00ff00;background-color:#eee;">do do do do</span> so
</span>
background-color:#eee;
dont apply for this part of text, that work only on <p>
tag, for example this html work fine
<span>
It's to
<p style="color:#00ff00;background-color:#eee;">do do do do</p> so
</span>
i'm trying to set dark black color as #000000
for texts, but i see light black color and i can't set to dark
<span>
It's to
<span style="color:#000000;">do do do do</span> so
</span>
You suppose i have some image into SDcard and i would like to show them on html, in sample of library image is into assets, but maybe i use and select image from other path, how can i do this action
in this html:
<p style="color:green">
salam
<span style="color:red !important">
simple text
</span>
</p>
close and open parent tags don't resolve my problem any time because it can't be extends some propertise such as color,font face or other things from parent.
for example:
<p style="color:green">
salam
</p>
<span>
simple text
</span>
<p>
</p>
how can i change nested tag as : span
I am using the HtmlView
inside a ScrollView
which is part of an activity called by a button inside my main activity. The text inside the code snippet is shorter than the original one.
The first time I open the activity, everything is displayed as expected. After pressing back and opening it again, no text is visible any more.
public class MyHtmlActivity extends AppCompatActivity {
private static final String myHtml = "<html><body><b>My Text</b></body></html>";
private static final StringReader htmlReader = new StringReader(myHtml);
private HtmlProcessor htmlProcessor = new HtmlProcessor();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
HtmlView htmlView = new HtmlView(this);
htmlProcessor.parse(htmlReader, htmlView);
scrollView.addView(htmlView);
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="myPackage.myActivity">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" >
</ScrollView>
</android.support.constraint.ConstraintLayout>
@stefanhaustein hi, could you check this html code?
I'm using latest version of your library on Gradle
text = "hello world <br/> <p style='text-align:left;'>this is an code</p> <br/> end of text <br/> and <p style='text-align:left;'>this my code</p> <br/> finish";
I get this error:
java.lang.RuntimeException: Unable to start activity ---: java.lang.RuntimeException: java.lang.RuntimeException: org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT hello world @1:13 in java.io.StringReader@36a75a9)
My code:
try {
text = "hello world <br/> <p style='text-align:left;'>this is an code</p> <br/> end of text <br/> and <p style='text-align:left;'>this my code</p> <br/> finish";
Reader reader = new StringReader(text);
HtmlView htmlView = new HtmlView(context);
htmlProcessor.parse(reader, htmlView);
ScrollView scrollView = new ScrollView(context);
scrollView.addView(htmlView);
markdownViewContent.addView(scrollView);
} catch (Exception e) {
e.printStackTrace();
Log.e("HtmlView ", e.getMessage());
throw new RuntimeException(e);
}
for this html code:
text = "<p style='font-size:15px;text-align:right'><br/><h2 style='text-align:right'>hello world</h2><br/></p>";
or
text = "<p style='font-size:15px;text-align:right'><br></br><h2 style='text-align:right'>hello world</h2><br></br></p>";
i get this error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean org.kobjects.css.CssStyleDeclaration.isSet(org.kobjects.css.CssProperty)' on a null object reference
my code:
private void showContentPreviewAsHtml() {
try {
text = "<p style='font-size:15px;text-align:right'><br></br><h2 style='text-align:right'>hello world</h2><br></br></p>";
Log.e("text ", text);
Reader reader = new StringReader(text);
HtmlView htmlView = new HtmlView(context);
htmlProcessor.parse(reader, htmlView);
ScrollView scrollView = new ScrollView(context);
scrollView.addView(htmlView);
markdownViewContent.addView(scrollView);
} catch (Exception e) {
e.printStackTrace();
Log.e("HtmlView ", e.getMessage());
throw new RuntimeException(e);
}
}
problem is break line <br/>
, <br></br>
, how can i use break line on start or end of html tags?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.