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.watasan.infospider.fragment.PrimitiveFragment.java

public void drawProfileImage(CApiParams params) {
    // UserId??/*from www.j  a v  a 2 s. co  m*/
    userId = params.getScreenName();
    // ?Ids??
    ItemBase item = ItemListManager.getItem(params.getScreenName());
    if (item == null)
        return;

    byte[] data = null;
    data = ((ItemIds) item).getProfileImageData();
    if (data != null) {
        Log.v("--image--", "data= " + params.getImageIndex() + "  type= " + params.getApiType());
        int width = ((ItemIds) item).getProfileImageDataWidth();
        int height = ((ItemIds) item).getProfileImageDataHeight();
        Bitmap bitmap = null;
        if (width == 0 && height == 0) {
            bitmap = ImageUtil.createBitmapFromByteArrayOfResource(data);
        } else {
            bitmap = ImageUtil.createBitmapFromByteArrayOfBitmap(data, width, height);
        }

        setImage(bitmap.copy(Bitmap.Config.ARGB_4444, true));
        // ?
        data = null;
        if (bitmap.isRecycled())
            bitmap.recycle();
        bitmap = null;
    } else {
        Log.v("------- Image index", "NULL data--index =" + params.getImageIndex());
    }
}

From source file:com.ttxgps.zoom.GestureImageView.java

protected boolean isRecycled() {
    if (drawable != null && drawable instanceof BitmapDrawable) {
        Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
        if (bitmap != null) {
            return bitmap.isRecycled();
        }/*  www .  ja v a2s.  c  o m*/
    }
    return false;
}

From source file:github.daneren2005.dsub.util.ImageLoader.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setImage(RemoteControlClient remoteControl, Drawable drawable) {
    if (remoteControl != null && drawable != null) {
        Bitmap origBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && origBitmap != null) {
            origBitmap = origBitmap.copy(origBitmap.getConfig(), false);
        }//  ww  w  . j  a va2  s  .  co m
        if (origBitmap != null && !origBitmap.isRecycled()) {
            remoteControl.editMetadata(false)
                    .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, origBitmap).apply();
        } else {
            if (origBitmap != null) {
                Log.e(TAG, "Tried to load a recycled bitmap.");
            }
            remoteControl.editMetadata(false)
                    .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, null).apply();
        }
    }
}

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

/**
 * // w  ww . j ava 2 s .  c o m
 * Sets the bitmap for the image and resets the base
 * @date 2014-4-29
 * @param bitmap
 * @param selection
 */
public void setImageBitmap(final Bitmap bitmap, final Rect selection) {
    final int viewWidth = getWidth();

    if (viewWidth <= 0) {
        mOnLayoutRunnable = new Runnable() {
            public void run() {
                setImageBitmap(bitmap, updateSelection());
            }
        };
        return;
    }

    Bitmap oldBitmap = this.mBitmap;
    if (bitmap != null) {
        setBaseMatrix(bitmap, mBaseMatrix, selection);
        this.mBitmap = bitmap;
    } else {
        mBaseMatrix.reset();
        this.mBitmap = bitmap;
    }
    if (oldBitmap != null && !oldBitmap.isRecycled()) {
        oldBitmap.recycle();
    }

    mSuppMatrix.reset();
    setImageMatrix(getImageViewMatrix());
    mMaxZoom = maxZoom();

}

From source file:github.daneren2005.dsub.util.ImageLoader.java

public SilentBackgroundTask<Void> loadImage(Context context, RemoteControlClient remoteControl,
        MusicDirectory.Entry entry) {/* w w w. j a v a 2  s .c  om*/
    Bitmap bitmap;
    if (entry == null || entry.getCoverArt() == null) {
        bitmap = getUnknownImage(entry, imageSizeLarge);
        setImage(remoteControl, Util.createDrawableFromBitmap(context, bitmap));
        return null;
    }

    bitmap = cache.get(getKey(entry.getCoverArt(), imageSizeLarge));
    if (bitmap != null && !bitmap.isRecycled()) {
        Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap);
        setImage(remoteControl, drawable);
        return null;
    }

    setImage(remoteControl, Util.createDrawableFromBitmap(context, null));
    ImageTask task = new RemoteControlClientImageTask(context, entry, imageSizeLarge, imageSizeLarge, false,
            remoteControl);
    task.execute();
    return task;
}

From source file:cn.com.wo.bitmap.ImageCache.java

/**
 * Initialize the cache, providing all parameters.
 *
 * @param cacheParams The cache parameters to initialize the cache
 *///from w  w  w . j ava  2s. co  m
private void init(ImageCacheParams cacheParams) {
    mCacheParams = cacheParams;

    // Set up memory cache
    if (mCacheParams.memoryCacheEnabled) {
        if (ImageFetcher.isDebug) {
            Log.d(ImageFetcher.TAG,
                    "ImageCache Memory cache created (size = " + mCacheParams.memCacheSize + ")");
        }

        // If we're running on Honeycomb or newer, then
        if (Utils.hasHoneycomb()) {
            mReusableBitmaps = new HashSet<WeakReference<Bitmap>>();
        }

        mMemoryCache = new LruCache<String, WeakReference<BitmapDrawable>>(mCacheParams.memCacheSize) {

            /**
             * Notify the removed entry that is no longer being cached
             */
            @Override
            protected void entryRemoved(boolean evicted, String key, WeakReference<BitmapDrawable> oldValue,
                    WeakReference<BitmapDrawable> newValue) {
                BitmapDrawable drawValue = oldValue.get();
                if (drawValue != null && RecyclingBitmapDrawable.class.isInstance(oldValue)) {
                    ((RecyclingBitmapDrawable) drawValue).setIsCached(false);
                }

                Bitmap bmp = null;
                if (drawValue != null) {
                    bmp = drawValue.getBitmap();
                }
                if (evicted && bmp != null && !bmp.isRecycled()) {
                    //                       bmp.recycle();  
                    bmp = null;
                    drawValue = null;
                }

                //xiaoxh
                //                    if (RecyclingBitmapDrawable.class.isInstance(oldValue)) {
                //                        // The removed entry is a recycling drawable, so notify it 
                //                        // that it has been removed from the memory cache
                ////                        ((RecyclingBitmapDrawable) oldValue).setIsCached(false);
                //                       BitmapDrawable drawValue = oldValue.get();
                //                       if(drawValue != null)
                //                          ((RecyclingBitmapDrawable) drawValue).setIsCached(false);
                ////                       else
                ////                          mMemoryCache.remove(key);
                //                    } else {
                //                        // The removed entry is a standard BitmapDrawable
                //
                //                        if (Utils.hasHoneycomb()) {
                //                            // We're running on Honeycomb or later, so add the bitmap
                //                            // to a SoftRefrence set for possible use with inBitmap later
                //                           BitmapDrawable drawValue = oldValue.get();
                //                           if(drawValue != null)
                //                              mReusableBitmaps.add(new WeakReference<Bitmap>(drawValue.getBitmap()));
                //                        }
                //                    }
            }

            /**
             * Measure item size in kilobytes rather than units which is more practical
             * for a bitmap cache
             */
            @Override
            protected int sizeOf(String key, WeakReference<BitmapDrawable> value) {
                final int bitmapSize = getBitmapSize(value.get()) / 1024;
                return bitmapSize == 0 ? 1 : bitmapSize;
            }
        };
    }

    // By default the disk cache is not initialized here as it should be initialized
    // on a separate thread due to disk access.
    if (cacheParams.initDiskCacheOnCreate) {
        // Set up disk cache
        initDiskCache();
    }
}

From source file:github.daneren2005.dsub.util.ImageLoader.java

public SilentBackgroundTask loadImage(View view, MusicDirectory.Entry entry, boolean large, int size,
        boolean crossfade) {
    // TODO: If we know this a artist, try to load artist info instead
    if (entry != null && !entry.isAlbum() && ServerInfo.checkServerVersion(context, "1.11")
            && !Util.isOffline(context)) {
        SilentBackgroundTask task = new ArtistImageTask(view.getContext(), entry, size, imageSizeLarge, large,
                view, crossfade);//  w  w w.ja v a 2  s . co m
        task.execute();
        return task;
    } else if (entry != null && entry.getCoverArt() == null && entry.isDirectory()
            && !Util.isOffline(context)) {
        // Try to lookup child cover art
        MusicDirectory.Entry firstChild = FileUtil.lookupChild(context, entry, true);
        if (firstChild != null) {
            entry.setCoverArt(firstChild.getCoverArt());
        }
    }

    Bitmap bitmap;
    if (entry == null || entry.getCoverArt() == null) {
        bitmap = getUnknownImage(entry, size);
        setImage(view, Util.createDrawableFromBitmap(context, bitmap), crossfade);
        return null;
    }

    bitmap = cache.get(getKey(entry.getCoverArt(), size));
    if (bitmap != null && !bitmap.isRecycled()) {
        final Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap);
        setImage(view, drawable, crossfade);
        if (large) {
            nowPlaying = bitmap;
        }
        return null;
    }

    if (!large) {
        setImage(view, null, false);
    }
    ImageTask task = new ViewImageTask(view.getContext(), entry, size, imageSizeLarge, large, view, crossfade);
    task.execute();
    return task;
}

From source file:com.tumblr.cardboard.Tumblr3DActivity.java

private void updateTexture(int texIndex, Bitmap bitmap) {
    if (mTextureIds[texIndex] != INVALID_TEXTURE && bitmap != null && !bitmap.isRecycled()) {

        // Set the active texture unit
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texIndex);

        Matrix.setIdentityM(mImageRect[texIndex], 0);
        Matrix.scaleM(mImageRect[texIndex], 0, 1f, (float) bitmap.getHeight() / bitmap.getWidth(), 1f);

        // Bind to the texture in OpenGL
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIds[texIndex]);

        // Load the bitmap into the bound texture.
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    } else {//from   w w  w  .  ja  va2  s . c  o m
        Log.w(TAG, "Failed to update: " + texIndex + " val: " + mTextureIds[texIndex]);
    }
}

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

@SuppressLint("NewApi")
public void setImageBitmap(final Bitmap bitmap, final boolean fitScreen) {

    //???/*from   ww w .j a v  a 2  s.c o  m*/
    if (Build.VERSION.SDK_INT >= MIN_SDK_ENABLE_LAYER_TYPE_HARDWARE) {
        if (bitmap != null && (bitmap.getHeight() > SampleSizeUtil.getTextureSize()
                || bitmap.getWidth() > SampleSizeUtil.getTextureSize())) {
            setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        } else {
            setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
    }

    final int viewWidth = getWidth();
    if (viewWidth <= 0) {
        mOnLayoutRunnable = new Runnable() {
            public void run() {
                setImageBitmap(bitmap, fitScreen);
            }
        };
        return;
    }

    Bitmap oldBitmap = this.mBitmap;
    if (bitmap != null) {
        setBaseMatrix(bitmap, mBaseMatrix);
        this.mBitmap = bitmap;
    } else {
        mBaseMatrix.reset();
        this.mBitmap = bitmap;
    }
    if (oldBitmap != null && oldBitmap != mBitmap && !oldBitmap.isRecycled()) {
        oldBitmap.recycle();
    }

    mSuppMatrix.reset();
    setImageMatrix(getImageViewMatrix());
    mMaxZoom = maxZoom();

    // Set the image to fit the screen
    if (fitScreen) {
        zoomToScreen();
    }
}

From source file:github.popeen.dsub.util.ImageLoader.java

public SilentBackgroundTask loadImage(View view, MusicDirectory.Entry entry, boolean large, int size,
        boolean crossfade) {
    if (entry != null && entry instanceof InternetRadioStation) {
        // Continue on and load a null bitmap
    }//from  w  w w  .j av  a  2s.co m
    // If we know this a artist, try to load artist info instead
    else if (entry != null && !entry.isAlbum() && ServerInfo.checkServerVersion(context, "1.11")
            && !Util.isOffline(context)) {
        SilentBackgroundTask task = new ArtistImageTask(view.getContext(), entry, size, imageSizeLarge, large,
                view, crossfade);
        task.execute();
        return task;
    } else if (entry != null && entry.getCoverArt() == null && entry.isDirectory()
            && !Util.isOffline(context)) {
        // Try to lookup child cover art
        MusicDirectory.Entry firstChild = FileUtil.lookupChild(context, entry, true);
        if (firstChild != null) {
            entry.setCoverArt(firstChild.getCoverArt());
        }
    }

    Bitmap bitmap;
    if (entry == null || entry.getCoverArt() == null) {
        bitmap = getUnknownImage(entry, size);
        setImage(view, Util.createDrawableFromBitmap(context, bitmap), crossfade);
        return null;
    }

    bitmap = cache.get(getKey(entry.getCoverArt(), size));
    if (bitmap != null && !bitmap.isRecycled()) {
        final Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap);
        setImage(view, drawable, crossfade);
        if (large) {
            nowPlaying = bitmap;
        }
        return null;
    }

    if (!large) {
        setImage(view, null, false);
    }
    ImageTask task = new ViewImageTask(view.getContext(), entry, size, imageSizeLarge, large, view, crossfade);
    task.execute();
    return task;
}