Example usage for android.graphics.drawable BitmapDrawable setCallback

List of usage examples for android.graphics.drawable BitmapDrawable setCallback

Introduction

In this page you can find the example usage for android.graphics.drawable BitmapDrawable setCallback.

Prototype

public final void setCallback(@Nullable Callback cb) 

Source Link

Document

Bind a Callback object to this Drawable.

Usage

From source file:Main.java

public static void releaseImageView(ImageView imageView) {
    if (imageView != null) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) (imageView.getDrawable());
        if (bitmapDrawable != null) {
            bitmapDrawable.setCallback(null);
        }//  w  w  w. j a  va2 s. co m
        imageView.setImageBitmap(null);
    }
}

From source file:Main.java

public static void unbindImageView(ImageView imageView) {
    if (imageView == null) {
        return;//  ww w  . j  a va2  s. c om
    }

    if (imageView.getBackground() != null) {
        imageView.getBackground().setCallback(null);
    }

    if (imageView.getDrawable() == null)
        return;
    if (!(imageView.getDrawable() instanceof BitmapDrawable))
        return;
    if (((BitmapDrawable) imageView.getDrawable()).getBitmap() == null)
        return;

    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
    try {
        if (drawable != null && imageView.getTag() != null && !drawable.getBitmap().isRecycled()) {
            if (!imageView.getTag().toString().equalsIgnoreCase("resource") && !usingMemoryCache) {
                drawable.getBitmap().recycle();
            }
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    }
    drawable.setCallback(null);
    imageView.setImageBitmap(null);
    imageView.setImageDrawable(null);
}