/*
   Copyright 2015 Jianan - qinxiandiqi@foxmail.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package com.qinxiandiqi.easyandroid.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.Html;
import android.util.AttributeSet;
import android.widget.TextView;

import org.xml.sax.XMLReader;

/**
 * Created by Jianan on 9/29/15.
 */
public class HtmlTextView extends TextView{

    public HtmlTextView(Context context) {
        super(context);
    }

    public HtmlTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public HtmlTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setHtml(String strHtml){
        Html.fromHtml(strHtml, new Html.ImageGetter() {
            @Override
            public Drawable getDrawable(String source) {
                return null;
            }
        }, new Html.TagHandler() {
            @Override
            public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {

            }
        });
    }
}

@@ -796,25 +796,218 @@
 oid.
-util.AttributeSet
+text.SpannableStringBuilder;%0Aimport android.text.method.LinkMovementMethod;%0Aimport android.text.style.ClickableSpan;%0Aimport android.text.style.URLSpan;%0Aimport android.util.AttributeSet;%0Aimport android.view.View
 ;%0Aim
@@ -1154,16 +1154,58 @@
 tView%7B%0A%0A
+    private HtmlClickListener mListener;%0A%0A
     publ
@@ -1532,32 +1532,225 @@
 tml(
-String strHtml)%7B%0A       
+int res)%7B%0A        initHtml(getContext().getString(res));%0A    %7D%0A%0A    public void setHtml(String strHtml)%7B%0A        initHtml(strHtml);%0A    %7D%0A%0A    private void initHtml(String strHtml)%7B%0A        CharSequence charSequence =
  Htm
@@ -1900,12 +1900,37 @@
 urn 
-null
+mListener.getDrawable(source)
 ;%0A  
@@ -2105,34 +2105,1220 @@
 ) %7B%0A
-%0A            %7D%0A        %7D);
+                mListener.handleTag(opening, tag, output, xmlReader);%0A            %7D%0A        %7D);%0A%0A        SpannableStringBuilder builder = new SpannableStringBuilder(charSequence);%0A        URLSpan%5B%5D urlSpans = builder.getSpans(0, charSequence.length(), URLSpan.class);%0A        for(URLSpan span : urlSpans)%7B%0A            int start = builder.getSpanStart(span);%0A            int end = builder.getSpanEnd(span);%0A            int flag = builder.getSpanFlags(span);%0A            final String link = span.getURL();%0A            builder.setSpan(new ClickableSpan() %7B%0A                @Override%0A                public void onClick(View widget) %7B%0A                    mListener.onClickLink(link);%0A                %7D%0A            %7D, start, end, flag);%0A            builder.removeSpan(span);%0A        %7D%0A        setText(charSequence);%0A        setLinksClickable(true);%0A        setMovementMethod(LinkMovementMethod.getInstance());%0A    %7D%0A%0A    public static class HtmlClickListener%7B%0A%0A        public void onClickLink(String link)%7B%0A%0A        %7D%0A%0A        public Drawable getDrawable(String source) %7B%0A            return null;%0A        %7D%0A%0A        public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) %7B%0A%0A        %7D
 %0A   

update html TextView