As a programmer I want be constantly updated with technologies/programming languages I use, I want to read tutorials, tips, best practices and wanted to know about new tools and frameworks that are coming, and for that I was constantly asking people about best blogs / websites about Technology-X, and I was also very often bombarded with the questions like: What are the best Python blogs? or What are the best ruby on rails blogs? and What’s the best IDE for java development? etc.
But there is no solution available to get all this information in one place, so I thought of developing one: I call it Ken.
Ken is tool which I needed badly and I think a lot of other people can benefit from it, so if you are having the same problem which I had: Try Ken
Download from Google Play
While working on my app Android app Ken, I needed to render HTML in Android, I was very much delighted when I found out that android’s TextView supports HTML rendering and it can be easily achived by converting html into Spannable using Html.fromHtml( method and sending it to TextView’s setText method.
TextView myTxt = (TextView)findViewById(R.id.textView);
But there is catch with Html.fromHtml method, it doesn’t support all tags; well that was a killjoy, but html.fromHtml method accpets a TagHandler which is class we can implement to handle custom html tags, but it is not well documented, after struggling for a while and reading the source code of HTML class method I was finally able to define my own tagHandler class which is able to handle ul, ol and code tags.
Here is my custom tagHandler:
The above Java file HtmlTagHandler handles, ul, ol, and code tags.
The handleTagList() method handles the list tags, and handling of code tag was pretty easy, I just need to find the start of the code tag, I do this by adding a flag on the start of the tag Spannable.SPAN_MARK_MARK and when the tag on end I just find the object where I marked Spannable.SPAN_MARK_MARK using getLast() and find its position, and store it in the variable name “where”; that’s the start of the code tag, and I get the end of the code tag using output.length() and set the font face of that text fragment to “monospace” using (new TypefaceSpan(“monospace”).
That’s it! If you want to use it in your project create a java class with content of this file and create a object of HtmlTagHandler and pass it to your fromHtml method.
P.S: For handling image I using a nice library called “URLImageParser” Github link