Code example for TextView

Methods: setText, setTag, setVisibility

0
    private HttpImageGetter show(final TextView view, final CharSequence html) {
        if (TextUtils.isEmpty(html))
            return hide(view);
 
        try { 
            view.setText(html);
        } 
        catch (Exception e) {
        } 
        view.setVisibility(VISIBLE);
        view.setTag(null);
        return this;
    } 
 
    private HttpImageGetter hide(final TextView view) {
        view.setText(null);
        view.setVisibility(GONE);
        view.setTag(null);
        return this;
    } 
 
    /** 
     * Encode given HTML string and map it to the given id 
     *  
     * @param id 
     * @param html 
     * @return this image getter 
     */ 
    public HttpImageGetter encode(final Object id, final String html) {
        if (TextUtils.isEmpty(html))
            return this;
 
        CharSequence encoded = HtmlUtils.encode(html, loading);
        // Use default encoding if no img tags 
        if (containsImages(html))
            rawHtmlCache.put(id, encoded);
        else { 
            rawHtmlCache.remove(id);
            fullHtmlCache.put(id, encoded);
        } 
        return this;
    } 
 
    /** 
     * Bind text view to HTML string 
     *  
     * @param view 
     * @param html 
     * @param id 
     * @return this image getter 
     */ 
    public HttpImageGetter bind(final TextView view, final String html,
            final Object id) {
        if (TextUtils.isEmpty(html))
            return hide(view);
 
        CharSequence encoded = fullHtmlCache.get(id);
        if (encoded != null)
            return show(view, encoded);
 
        encoded = rawHtmlCache.get(id);
        if (encoded == null) {
            encoded = HtmlUtils.encode(html, loading);
            if (containsImages(html))
                rawHtmlCache.put(id, encoded);
            else { 
                rawHtmlCache.remove(id);
                fullHtmlCache.put(id, encoded);
                return show(view, encoded);
            } 
        } 
 
        if (TextUtils.isEmpty(encoded))
            return hide(view);
 
        show(view, encoded);
        view.setTag(id);
        ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask();
        asyncTask.execute(html, id, view);
        return this;
    }