Example usage for android.widget TextView getTag

List of usage examples for android.widget TextView getTag

Introduction

In this page you can find the example usage for android.widget TextView getTag.

Prototype

public Object getTag(int key) 

Source Link

Document

Returns the tag associated with this view and the specified key.

Usage

From source file:org.goodev.discourse.utils.ImageLoader.java

public ImageContainer getForImageSpan(UrlImageGetter imageGetter, String requestUrl, TextView imageView,
        ImageListener listener) {/*from  w ww. j  a  va 2 s. c om*/

    if (requestUrl == null) {
        requestUrl = "";
    }
    // Find any old image load request pending on this ImageView (in case this view was
    // recycled)
    Object g = imageView.getTag(R.id.poste_image_getter);
    if (g instanceof UrlImageGetter) {
        UrlImageGetter getter = (UrlImageGetter) g;
        ArrayList<ImageContainer> ics = getter.mImageContainers;
        if (getter == imageGetter) {
            boolean inQueue = false;
            ImageContainer result = null;
            for (ImageContainer imageContainer : ics) {
                // Find image url from prior request
                String recycledImageUrl = imageContainer != null ? imageContainer.getRequestUrl() : null;

                // If the new requestUrl is null or the new requestUrl is different to the previous
                // recycled requestUrl
                if (requestUrl.equals(recycledImageUrl)) {
                    inQueue = true;
                    break;
                }
            }
            if (!inQueue) {
                if (requestUrl.length() > 0) {
                    // Queue new request to fetch image
                    return get(requestUrl, listener);
                }
            }
        } else {
            imageView.setTag(R.id.poste_image_getter, null);
            boolean inQueue = false;
            for (ImageContainer imageContainer : ics) {
                // Find image url from prior request
                String recycledImageUrl = imageContainer != null ? imageContainer.getRequestUrl() : null;

                // If the new requestUrl is null or the new requestUrl is different to the previous
                // recycled requestUrl
                if (!requestUrl.equals(recycledImageUrl)) {
                    if (imageContainer != null) {
                        // Cancel previous image request
                        imageContainer.cancelRequest();
                    }
                } else {
                    inQueue = true;
                }
            }
            if (!inQueue) {
                if (requestUrl.length() > 0) {
                    // Queue new request to fetch image
                    return get(requestUrl, listener);
                }
            }

        }
    } else {
        if (requestUrl.length() > 0) {
            // Queue new request to fetch image
            return get(requestUrl, listener);
        }
    }
    return null;

}