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.lovebridge.chat.view.ImageCache.java

/**
 * @param options - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 */// w  w  w .j  a v  a2s . c o m
protected Bitmap getBitmapFromReusableSet(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.android.pc.ioc.image.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) {
    // 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:cmu.cconfs.instantMessage.util.ImageCache.java

/**
 * @param options/* w ww  .  j av a 2  s .com*/
 *            - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 */
protected Bitmap getBitmapFromReusableSet(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.aidigame.hisun.imengstar.huanxin.video.ImageCache.java

/**
 * @param options// w ww  . ja v  a  2 s.  c  om
 *            - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 */
public Bitmap getBitmapFromReusableSet(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:de.s2hmobile.bitmaps.ImageCache.java

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

    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        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 Bitmap getPreview(final Object o) {
    final String name = getObjectName(o);
    final String packageName = getObjectPackage(o);
    // check if the package is valid
    synchronized (sInvalidPackages) {
        boolean packageValid = !sInvalidPackages.contains(packageName);
        if (!packageValid) {
            return null;
        }/*from   www. j a  v a2 s.  c om*/
    }
    synchronized (mLoadedPreviews) {
        // check if it exists in our existing cache
        if (mLoadedPreviews.containsKey(name)) {
            WeakReference<Bitmap> bitmapReference = mLoadedPreviews.get(name);
            Bitmap bitmap = bitmapReference.get();
            if (bitmap != null) {
                return bitmap;
            }
        }
    }

    Bitmap unusedBitmap = null;
    synchronized (mUnusedBitmaps) {
        // not in cache; we need to load it from the db
        while (unusedBitmap == null && mUnusedBitmaps.size() > 0) {
            Bitmap candidate = mUnusedBitmaps.remove(0).get();
            if (candidate != null && candidate.isMutable() && candidate.getWidth() == mPreviewBitmapWidth
                    && candidate.getHeight() == mPreviewBitmapHeight) {
                unusedBitmap = candidate;
            }
        }
        if (unusedBitmap != null) {
            final Canvas c = mCachedAppWidgetPreviewCanvas.get();
            c.setBitmap(unusedBitmap);
            c.drawColor(0, PorterDuff.Mode.CLEAR);
            c.setBitmap(null);
        }
    }

    if (unusedBitmap == null) {
        unusedBitmap = Bitmap.createBitmap(mPreviewBitmapWidth, mPreviewBitmapHeight, Bitmap.Config.ARGB_8888);
    }
    Bitmap preview = readFromDb(name, unusedBitmap);

    if (preview != null) {
        synchronized (mLoadedPreviews) {
            mLoadedPreviews.put(name, new WeakReference<Bitmap>(preview));
        }
        return preview;
    } else {
        // it's not in the db... we need to generate it
        final Bitmap generatedPreview = generatePreview(o, unusedBitmap);
        preview = generatedPreview;
        if (preview != unusedBitmap) {
            throw new RuntimeException("generatePreview is not recycling the bitmap " + o);
        }

        synchronized (mLoadedPreviews) {
            mLoadedPreviews.put(name, new WeakReference<Bitmap>(preview));
        }

        // write to db on a thread pool... this can be done lazily and improves the performance
        // of the first time widget previews are loaded
        new AsyncTask<Void, Void, Void>() {
            public Void doInBackground(Void... args) {
                writeToDb(o, generatedPreview);
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);

        return preview;
    }
}

From source file:com.example.android.bitmapfun.util.ImagesCache.java

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

    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        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.app.secnodhand.imageutil.ImageCache.java

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

    try {
        if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
            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();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bitmap;
}

From source file:com.afrozaar.jazzfestreporting.util.ImageCache.java

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

    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        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.simpleimageloader.image.ImageCache.java

/**
 * @param options - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 *//* w w w  .jav  a 2  s. c om*/
public Bitmap getBitmapFromReusableSet(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)
}