Example usage for android.graphics Bitmap isMutable

List of usage examples for android.graphics Bitmap isMutable

Introduction

In this page you can find the example usage for android.graphics Bitmap isMutable.

Prototype

public final boolean isMutable() 

Source Link

Document

Returns true if the bitmap is marked as mutable (i.e. can be drawn into)

Usage

From source file:com.nf2m.util.ImageCache.java

/**
 * @param options - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 *///from w w  w.j  av a 2s  .  c om
@Nullable
Bitmap getBitmapFromReusableSet(@NonNull BitmapFactory.Options options) {
    //BEGIN_INCLUDE(get_bitmap_from_reusable_set)
    Bitmap bitmap = null;

    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        synchronized (mReusableBitmaps) {
            final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
            Bitmap item;

            while (iterator.hasNext()) {
                item = iterator.next().get();

                if (null != item && item.isMutable()) {
                    // Check to see it the item can be used for inBitmap
                    if (canUseForInBitmap(item, options)) {
                        bitmap = item;

                        // Remove from reusable set so it can't be used again
                        iterator.remove();
                        break;
                    }
                } else {
                    // Remove from the set if the reference has been cleared.
                    iterator.remove();
                }
            }
        }
    }

    return bitmap;
    //END_INCLUDE(get_bitmap_from_reusable_set)
}

From source file:com.rsegismont.androlife.common.utils.ImageCacher.java

/**
 * @param options/*from w w w  . j  a va  2s .co  m*/
 *            - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public synchronized Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {

    Bitmap bitmap = null;

    if (mReusableBitmaps != null && (mReusableBitmaps.size() != 0)) {

        final Iterator<Integer> iterator = mReusableBitmaps.keySet().iterator();
        int length;
        Bitmap bitmapCandidate;

        while (iterator.hasNext()) {
            length = iterator.next();
            bitmapCandidate = mReusableBitmaps.get(length).get();

            if (null != bitmapCandidate && bitmapCandidate.isMutable()) {
                // Check to see it the item can be used for inBitmap
                if (canUseForInBitmap(bitmapCandidate, options)) {
                    bitmap = bitmapCandidate;
                    // Remove from reusable set so it can't be used again
                    iterator.remove();
                    break;
                }

            } else {
                // Remove from the set if the reference has been cleared.
                iterator.remove();
            }
        }

    }

    return bitmap;
}

From source file:air.com.snagfilms.utils.ImageCache.java

/**
 * @param options/*from  ww w .  j ava  2s .  com*/
 *            - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 */
protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
    Bitmap bitmap = null;

    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        synchronized (mReusableBitmaps) {
            final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
            Bitmap item;

            while (iterator.hasNext()) {
                item = iterator.next().get();

                if (null != item && item.isMutable()) {
                    // Check to see it the item can be used for inBitmap
                    if (canUseForInBitmap(item, options)) {
                        bitmap = item;

                        // Remove from reusable set so it can't be used
                        // again
                        iterator.remove();
                        break;
                    }
                } else {
                    // Remove from the set if the reference has been
                    // cleared.
                    iterator.remove();
                }
            }
        }
    }

    return bitmap;
}

From source file:com.android.leanlauncher.WidgetPreviewLoader.java

public void recycleBitmap(Object o, Bitmap bitmapToRecycle) {
    String name = getObjectName(o);
    synchronized (mLoadedPreviews) {
        if (mLoadedPreviews.containsKey(name)) {
            Bitmap b = mLoadedPreviews.get(name).get();
            if (b == bitmapToRecycle) {
                mLoadedPreviews.remove(name);
                if (bitmapToRecycle.isMutable()) {
                    synchronized (mUnusedBitmaps) {
                        mUnusedBitmaps.add(new SoftReference<Bitmap>(b));
                    }/*w  w  w . ja va2  s.c o  m*/
                }
            } else {
                throw new RuntimeException("Bitmap passed in doesn't match up");
            }
        }
    }
}

From source file:com.ifeng.util.imagecache.ImageCache.java

/**
 * @param options/*from   w w  w  .  j a v  a 2  s .c  o  m*/
 *            - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 */
protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
    Bitmap bitmap = null;

    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
        Bitmap item;

        try {
            while (iterator.hasNext()) {
                item = iterator.next().get();

                if (null != item && item.isMutable()) {
                    // Check to see it the item can be used for inBitmap
                    if (canUseForInBitmap(item, options)) {
                        bitmap = item;

                        // Remove from reusable set so it can't be used
                        // again
                        iterator.remove();
                        // iterator = mReusableBitmaps.iterator();
                        break;
                    }
                } else {
                    // Remove from the set if the reference has been
                    // cleared.
                    iterator.remove();
                    // iterator = mReusableBitmaps.iterator();
                }
                iterator = mReusableBitmaps.iterator();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return bitmap;
}

From source file:com.corebase.android.bitmap.util.ImageCache.java

/**
 * @param options/*ww w.  ja va2 s.  c  om*/
 *            - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 */
// private final Object mIteratorLock = new Object();
protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
    Bitmap bitmap = null;
    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        // final Iterator<SoftReference<Bitmap>> iterator =
        // mReusableBitmaps.iterator();
        Bitmap item;
        SoftReference<Bitmap> reference = null;
        for (String key : mReusableBitmaps.keySet()) {
            reference = mReusableBitmaps.get(key);
            if (reference != null) {
                item = reference.get();
                if (null != item && item.isMutable()) {
                    if (canUseForInBitmap(item, options)) {
                        bitmap = item;
                        mReusableBitmaps.remove(key);
                    }
                } else {
                    mReusableBitmaps.remove(key);
                }
            }
        }

        // while (iterator.hasNext()) {
        // reference = iterator.next();
        // item = reference.get();
        // if (null != item && item.isMutable()) {
        // // Check to see it the item can be used for inBitmap
        // if (canUseForInBitmap(item, options)) {
        // bitmap = item;
        // // Remove from reusable set so it can't be used again
        // iterator.remove();
        // if(mReusableBitmaps.contains(reference)){
        // mReusableBitmaps.remove(reference);
        // }
        // break;
        // }
        // } else {
        // // Remove from the set if the reference has been cleared.
        // iterator.remove();
        // if(mReusableBitmaps.contains(reference)){
        // mReusableBitmaps.remove(reference);
        // }
        // }
        // }
    }
    return bitmap;
}