Code example for ImageView

Methods: getDrawable, getTag

0
    } 
 
    // protected for testing purposes 
    protected void loadBitmapAsynchronously(T octo, ImageView thumbImageView,
        String tempThumbnailImageFileName) {
        if (thumbImageView.getTag() != null
            && thumbImageView.getTag().equals(tempThumbnailImageFileName)) {
            return; 
        } 
 
        if (cancelPotentialWork(tempThumbnailImageFileName, thumbImageView)) {
            final BitmapWorkerTask task = new BitmapWorkerTask(thumbImageView,
                octo);
            task.fileName = tempThumbnailImageFileName;
            final AsyncDrawable asyncDrawable = new AsyncDrawable(getContext()
                .getResources(), task);
            thumbImageView.setImageDrawable(asyncDrawable);
            thumbImageView.setTag(tempThumbnailImageFileName);
            int width = Math.round(convertDpToPixel(IMG_WIDTH, getContext()));
            int height = width;
            task.execute(tempThumbnailImageFileName, String.valueOf(width),
                String.valueOf(height));
        } 
    } 
 
    private void fireOnNetworkFetchingAllowedChange() { 
        synchronized (networkFetchingAuthorizationStateChangeListenerList) {
            for (NetworkFetchingAuthorizationStateChangeAdapter networkFetchingAuthorizationStateChangeListener : networkFetchingAuthorizationStateChangeListenerList) {
                Ln.d("calling state change listener");
                networkFetchingAuthorizationStateChangeListener
                    .onNetworkFetchingAllowedChange(isNetworkFetchingAllowed);
            } 
        } 
    } 
 
    private boolean cancelPotentialWork(String fileName, ImageView imageView) {
        final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
 
        if (bitmapWorkerTask != null) {
            final String bitmapFileName = bitmapWorkerTask.fileName;
            if (bitmapFileName == null || !bitmapFileName.equals(fileName)) {
                // Cancel previous task 
                bitmapWorkerTask.cancel(true);
            } else { 
                // The same work is already in progress 
                return false; 
            } 
        } 
        // No task associated with the ImageView, or an existing task was 
        // cancelled 
        return true; 
    } 
 
    private BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
        if (imageView != null) {
            final Drawable drawable = imageView.getDrawable();
            if (drawable instanceof SpiceArrayAdapter.AsyncDrawable) {
                @SuppressWarnings("unchecked") 
                final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
                return asyncDrawable.getBitmapWorkerTask();
            }