Example usage for android.widget ImageView setImageDrawable

List of usage examples for android.widget ImageView setImageDrawable

Introduction

In this page you can find the example usage for android.widget ImageView setImageDrawable.

Prototype

public void setImageDrawable(@Nullable Drawable drawable) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:Main.java

public static void stripImageView(ImageView view) {
    if (view.getDrawable() instanceof BitmapDrawable) {
        ((BitmapDrawable) view.getDrawable()).getBitmap().recycle();
    }//from  ww  w  . j  a v a  2s.  co  m
    view.getDrawable().setCallback(null);
    view.setImageDrawable(null);
    view.getResources().flushLayoutCache();
    view.destroyDrawingCache();
}

From source file:Main.java

public static void recycleImageViewBitmap(ImageView imageView) {
    if (imageView == null)
        return;//from   w  w w.  j  av  a2  s.c  o m

    Drawable drawable = imageView.getDrawable();
    if (drawable == null)
        return;

    imageView.setImageDrawable(null);

    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    Bitmap bitmap = bitmapDrawable.getBitmap();
    if (bitmap != null) {
        bitmap.recycle();
    }
}

From source file:Main.java

/**
 * release all image resource bind on view
 * @param view//ww w.j  a v  a2  s. c  o m
 */
@SuppressWarnings("deprecation")
public static void unbindDrawables(View view) {
    if (null == view) {
        return;
    }
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
        if (Build.VERSION.SDK_INT >= 16)
            view.setBackground(null);
        else
            view.setBackgroundDrawable(null);
    }
    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;

        if (imageView.getDrawable() != null) {
            imageView.getDrawable().setCallback(null);
            imageView.setImageDrawable(null);
        }
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        if (!(view instanceof AdapterView<?>)) {
            ((ViewGroup) view).removeAllViews();
        }
    }
}

From source file:Main.java

public static void unbindInvisibleImageDrawables(View view) {
    if (null == view) {
        return;//from   w  ww  .  j  a  v a2  s. c om
    }

    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;

        if (imageView.getDrawable() != null && isInVisisble(imageView)) {
            imageView.getDrawable().setCallback(null);
            imageView.setImageDrawable(null);
        }
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindInvisibleImageDrawables(((ViewGroup) view).getChildAt(i));
        }
    }
}

From source file:Main.java

public static void cleanImageView(ImageView imageView) {
    if (!(imageView.getDrawable() instanceof BitmapDrawable))
        return;/* ww  w.j  av  a2  s  .  c  om*/

    //Clean up the view's image for the sake of memory
    BitmapDrawable b = (BitmapDrawable) imageView.getDrawable();
    b.getBitmap().recycle();
    imageView.setImageDrawable(null);
}

From source file:Main.java

public static void cleanImageView(ImageView imageView) {
    if (!(imageView.getDrawable() instanceof BitmapDrawable))
        return;/*from  w  w w.  ja  v  a2 s.  co m*/

    // clean up the view's image for the sake of memory
    BitmapDrawable b = (BitmapDrawable) imageView.getDrawable();
    b.getBitmap().recycle();
    imageView.setImageDrawable(null);
}

From source file:Main.java

/**
 * Cleans up view's image to reduce memory cost to device
 * @param imageView//from  w w  w .ja v  a 2  s  . com
 */
static void cleanImageView(ImageView imageView) {
    if (!(imageView.getDrawable() instanceof BitmapDrawable))
        return;

    // clean up the view's image for the sake of memory
    BitmapDrawable b = (BitmapDrawable) imageView.getDrawable();
    b.getBitmap().recycle();
    imageView.setImageDrawable(null);
}

From source file:com.arlib.floatingsearchview.util.Util.java

public static void setIconColor(ImageView iconHolder, int color) {
    Drawable wrappedDrawable = DrawableCompat.wrap(iconHolder.getDrawable());
    DrawableCompat.setTint(wrappedDrawable, color);
    iconHolder.setImageDrawable(wrappedDrawable);
    iconHolder.invalidate();//from   ww w. j  av a2s .c  o m
}

From source file:com.frostwire.android.offers.InHouseBannerFactory.java

public static void loadAd(final ImageView placeholder, AdFormat adFormat) {
    Message randomMessage = Message.random();
    int randomDrawable = getRandomDrawable(adFormat, randomMessage);
    placeholder.setImageDrawable(ContextCompat.getDrawable(placeholder.getContext(), randomDrawable));
    placeholder.setOnClickListener(CLICK_LISTENERS.get(randomMessage));
}

From source file:Main.java

public static void clearImageView(ImageView imageView) {
    if (!(imageView.getDrawable() instanceof BitmapDrawable)) {
        return;/*w  ww . j  a va2  s  .c  o m*/
    }
    Bitmap drawable = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    if (drawable != null && !drawable.isRecycled()) {
        drawable.recycle();
    }
    imageView.setImageDrawable(null);
}