Example usage for android.graphics Bitmap isRecycled

List of usage examples for android.graphics Bitmap isRecycled

Introduction

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

Prototype

public final boolean isRecycled() 

Source Link

Document

Returns true if this bitmap has been recycled.

Usage

From source file:com.squareup.picasso3.BitmapTargetAction.java

@Override
void complete(RequestHandler.Result result) {
    if (result == null) {
        throw new AssertionError(String.format("Attempted to complete action with no result!\n%s", this));
    }//from w w  w.  j a  va 2s .c  o  m
    BitmapTarget target = getTarget();
    if (target != null) {
        Bitmap bitmap = result.getBitmap();
        if (bitmap != null) {
            target.onBitmapLoaded(bitmap, result.getLoadedFrom());
            if (bitmap.isRecycled()) {
                throw new IllegalStateException("Target callback must not recycle bitmap!");
            }
        }
    }
}

From source file:com.tct.fw.ex.photo.loaders.PhotoBitmapLoader.java

/**
 * Helper function to take care of releasing resources associated
 * with an actively loaded data set./*from w  w w.  j  ava2  s.c o  m*/
 */
protected void onReleaseResources(Bitmap bitmap) {
    if (bitmap != null && !bitmap.isRecycled()) {
        bitmap.recycle();
    }
}

From source file:org.huxizhijian.hhcomicviewer.adapter.GalleryViewPagerAdapter.java

private void releaseImageViewResource(ZoomImageView imageView) {
    if (imageView == null)
        return;//from  w  ww. j  a v a 2  s.c  o  m
    Drawable drawable = imageView.getDrawable();
    if (drawable != null && drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        Bitmap bitmap = bitmapDrawable.getBitmap();
        if (bitmap != null && !bitmap.isRecycled()) {
            bitmap.recycle();
            bitmap = null;
        }
    }
    System.gc();
}

From source file:com.yamin.kk.vlc.BitmapCache.java

public Bitmap getBitmapFromMemCache(String key) {
    final Bitmap b = mMemCache.get(key);
    if (LOG_ENABLED)
        Log.d(TAG, (b == null) ? "Cache miss" : "Cache found");
    if (b != null && b.isRecycled()) {
        /* A recycled bitmap cannot be used again */
        mMemCache.remove(key);/*from  w  w  w  . jav  a  2 s . com*/
        return null;
    }
    return b;
}

From source file:com.github.barteksc.pdfviewpager.adapter.PDFPagerAdapter.java

protected void recycleBitmap(int position) {
    Bitmap b = bitmaps.get(position).get();
    if (b != null && !b.isRecycled()) {
        b.recycle();/*from   w  ww .  j a va2  s. c  o  m*/
        bitmaps.remove(position);
    }
}

From source file:org.videolan.myvlc.tool.BitmapCache.java

public Bitmap getBitmapFromMemCache(String key) {
    final Bitmap b = mMemCache.get(key);
    if (LOG_ENABLED) {
        Log.d(TAG, (b == null) ? "Cache miss" : "Cache found");
    }/*from w  w w .j  a  v a2  s  .co m*/
    if (b != null && b.isRecycled()) {
        mMemCache.remove(key);
        return null;
    }
    return b;
}

From source file:com.zhongyun.viewer.utils.VideoListImage.java

public VideoListImage(Context context, int serverType) {
    this.context = context;
    this.media = Viewer.getViewer().getMedia();
    cacheDir = FileUtils.createFile(Constants.LOCAL_ICON_PATH);
    options.inJustDecodeBounds = false;// w  w w.ja va  2s .c o m
    options.inPurgeable = true;

    int MAXMEMONRY = (int) (Runtime.getRuntime().maxMemory() / 1024);
    if (filesCache == null) {
        filesCache = new LruCache<String, Bitmap>(MAXMEMONRY / 8) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
            }

            @Override
            protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
                if (oldValue != null && !oldValue.isRecycled()) {
                    oldValue.recycle();
                    oldValue = null;
                }
            }
        };
    }
}

From source file:com.rk.lib.view.SVGView.java

/**
 * Clears LruCahe and Recycle the bitmap associated to this view
 *//*from   w  w  w  .  ja  v  a  2s .  c o m*/
public void clearMemoryGarbage() {
    memoryCache.evictAll();
    Bitmap bitmapToRecycle = ((BitmapDrawable) this.getDrawable()).getBitmap();
    if (bitmapToRecycle != null && !bitmapToRecycle.isRecycled()) {
        bitmapToRecycle.recycle();
    }
    System.gc();
}

From source file:cn.dreamtobe.touchgallery.BaseGalleryPagerAdapter.java

@Override
public Bitmap loadCache(final String key) {
    Bitmap bm = null;
    if (mMapCache != null) {
        bm = mMapCache.get(key);//from w  w w  .  j  a va2  s . com
    }

    if (bm != null) {
        if (!bm.isRecycled()) {
            return bm;
        } else {
            mMapCache.remove(key);
        }
    }

    if (mLruCache != null) {
        Object o = mLruCache.get(key);
        if (o != null && o instanceof Bitmap) {
            bm = (Bitmap) o;
            mLruCache.remove(key);
            if (!bm.isRecycled()) {
                mLruCache.put(key, bm);
                return bm;
            }
        }
    }

    if (mLruSoftCache != null && mLruSoftCache.get(key) != null) {
        Object o = mLruSoftCache.get(key).get();
        if (o != null && o instanceof Bitmap) {
            bm = (Bitmap) o;
            mLruSoftCache.remove(key);
            if (!bm.isRecycled()) {
                mLruSoftCache.put(key, new SoftReference<Object>(bm));
                return bm;
            }
        }
    }

    return null;
}

From source file:jahirfiquitiva.iconshowcase.tasks.WallpaperToCrop.java

private Uri getImageUri(Context inContext, Bitmap inImage) {

    Preferences mPrefs = new Preferences(inContext);
    File downloadsFolder;/*  ww  w. j  a  va2s  . c  o m*/

    if (inImage.isRecycled()) {
        inImage = inImage.copy(Bitmap.Config.ARGB_8888, false);
    }

    if (mPrefs.getDownloadsFolder() != null) {
        downloadsFolder = new File(mPrefs.getDownloadsFolder());
    } else {
        downloadsFolder = new File(context.getString(R.string.walls_save_location,
                Environment.getExternalStorageDirectory().getAbsolutePath()));
    }

    //noinspection ResultOfMethodCallIgnored
    downloadsFolder.mkdirs();

    File destFile = new File(downloadsFolder, wallName + ".png");

    if (!destFile.exists()) {
        try {
            inImage.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(destFile));
        } catch (final Exception e) {
            if (ShowcaseActivity.DEBUGGING)
                Utils.showLog(context, e.getLocalizedMessage());
        }
    }

    return Uri.fromFile(destFile);
}