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.ricardotrujillo.appstore.viewmodel.adapter.StoreRecyclerViewAdapter.java

@Override
public void onBindViewHolder(final BindingHolder holder, final int position) {

    holder.binding.setEntry(storeManager.getStore().feed.entry.get(position));

    holder.binding.setClick(new StoreClickHandler() {

        @Override/*ww w . ja  va  2s.  co m*/
        public void onClick(View view) {

            onClickButton(view, holder);
        }
    });

    if (!storeManager.getStore().feed.entry.get(position).imageLoaded) {

        holder.binding.ivContainer.setAlpha(0f);
    }

    if (storeManager.getColorDrawable(storeManager.getStore().feed.entry.get(position).name.label) == null) {

        loadImage(holder.binding.ivFeedCenter, position, new CustomCallback() {
            @Override
            public void onSuccess() {

                Bitmap myBitmap = ((BitmapDrawable) holder.binding.ivFeedCenter.getDrawable()).getBitmap();

                if (myBitmap != null && !myBitmap.isRecycled()) {

                    Palette.from(myBitmap).generate(new Palette.PaletteAsyncListener() {

                        public void onGenerated(Palette palette) {

                            if (position < storeManager.getStore().feed.entry.size()) {

                                if (!storeManager.getStore().feed.entry.get(position).imageLoaded) {

                                    holder.binding.ivContainer.animate().setDuration(500).alpha(1f);

                                    storeManager.getStore().feed.entry.get(position).imageLoaded = true; //First insert animation
                                }

                                holder.binding.ivContainer
                                        .setBackgroundDrawable(animWorker.getDarkColorDrawable(palette)); // min supported API is 14

                                storeManager.addColorDrawable(position,
                                        animWorker.getDarkColorDrawable(palette));
                            }
                        }
                    });
                }
            }

            @Override
            public void onError() {

            }
        });

    } else {

        loadImage(holder.binding.ivFeedCenter, position, new CustomCallback() {
            @Override
            public void onSuccess() {

                holder.binding.ivContainer.setBackgroundDrawable(storeManager
                        .getColorDrawable(storeManager.getStore().feed.entry.get(position).name.label)); // min supported API is 14

                holder.binding.ivContainer.setAlpha(1f);
            }

            @Override
            public void onError() {

            }
        });
    }

    holder.getBinding(position).executePendingBindings();

    setAnimation(holder.binding.cardView, position);
}

From source file:com.roach.framework.http.bitmap.ImageWorker.java

public void recycleBitmap(ImageView iv) {
    BitmapWorkerTask bitmapWorkerTask = null;
    if (iv.getTag() != null && (iv.getTag() instanceof BitmapWorkerTask)) {
        bitmapWorkerTask = (BitmapWorkerTask) iv.getTag();
    }//from   w ww.  ja v  a 2  s.co m
    if (bitmapWorkerTask != null) {
        Bitmap bitmap = bitmapWorkerTask.getBitmap();
        iv.setImageBitmap(null);
        if (bitmap != null && !bitmap.isRecycled()) {
            bitmap.recycle();
        }
        iv.setTag(null);
        bitmapWorkerTask = null;
    }
}

From source file:com.ricardotrujillo.prueba.viewmodel.adapter.StoreRecyclerViewAdapter.java

@Override
public void onBindViewHolder(final BindingHolder holder, final int position) {

    holder.binding.setEntry(storeManager.getStore().feed.entry.get(position));

    holder.binding.setClick(new StoreClickHandler() {

        @Override/*from w w  w  .  ja  va2  s  .  c o m*/
        public void onClick(View view) {

            onClickButton(view, holder);
        }
    });

    if (!storeManager.getStore().feed.entry.get(position).imageLoaded) {

        holder.binding.ivContainer.setAlpha(0f);
    }

    if (storeManager.getColorDrawable(storeManager.getStore().feed.entry.get(position).name.label) == null) {

        loadImage(holder.binding.ivFeedCenter, position, new CustomCallback() {
            @Override
            public void onSuccess() {

                Bitmap myBitmap = ((BitmapDrawable) holder.binding.ivFeedCenter.getDrawable()).getBitmap();

                if (myBitmap != null && !myBitmap.isRecycled()) {

                    Palette.from(myBitmap).generate(new Palette.PaletteAsyncListener() {

                        public void onGenerated(Palette palette) {

                            if (!storeManager.getStore().feed.entry.get(position).imageLoaded) {

                                holder.binding.ivContainer.animate().setDuration(500).alpha(1f);

                                storeManager.getStore().feed.entry.get(position).imageLoaded = true; //First insert animation
                            }

                            storeManager.getStore().feed.entry.get(position).paletteColor = animWorker
                                    .getDarkColorDrawable(palette).getColor();

                            holder.binding.ivContainer
                                    .setBackgroundDrawable(animWorker.getDarkColorDrawable(palette)); // min supported API is 14

                            storeManager.addDrawables(position, animWorker.getDarkColorDrawable(palette));
                        }
                    });
                }
            }

            @Override
            public void onError() {

            }
        });

    } else {

        loadImage(holder.binding.ivFeedCenter, position, new CustomCallback() {
            @Override
            public void onSuccess() {

                holder.binding.ivContainer.setBackgroundDrawable(storeManager
                        .getColorDrawable(storeManager.getStore().feed.entry.get(position).name.label)); // min supported API is 14

                holder.binding.ivContainer.animate().setDuration(500).alpha(1f);
            }

            @Override
            public void onError() {

            }
        });
    }

    holder.getBinding().executePendingBindings();

    if (getItemViewType(position) == VIEW_TYPE_LOADER) {

        bindLoadingFeedItem((LoadingCellFeedViewHolder) holder);
    }

    setAnimation(holder.binding.cardView, position);
}

From source file:com.torrenttunes.android.ui.FullScreenPlayerActivity.java

private void fetchImageAsync(MediaDescriptionCompat description) {
    String artUrl = description.getIconUri().toString();
    mCurrentArtUrl = artUrl;//w w  w  .j  ava  2 s .  c om
    AlbumArtCache cache = AlbumArtCache.getInstance();
    Bitmap art = cache.getBigImage(artUrl);
    if (art == null) {
        art = description.getIconBitmap();
    }
    if (art != null && !art.isRecycled()) {
        // if we have the art cached or from the MediaDescription, use it:
        mBackgroundImage.setImageBitmap(art);
    } else {
        // otherwise, fetch a high res version and update:
        cache.fetch(artUrl, new AlbumArtCache.FetchListener() {
            @Override
            public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) {
                // sanity check, in case a new fetch request has been done while
                // the previous hasn't yet returned:
                if (!bitmap.isRecycled() && artUrl.equals(mCurrentArtUrl)) {
                    mBackgroundImage.setImageBitmap(bitmap);
                }
            }
        });
    }
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int color, int cornerDips, int borderDips,
        Context context, boolean recycleOrig) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int borderSizePx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) borderDips,
            context.getResources().getDisplayMetrics());
    final int cornerSizePx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) cornerDips,
            context.getResources().getDisplayMetrics());
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    // prepare canvas for transfer
    paint.setAntiAlias(true);/*w  ww  .  ja va  2  s.  c  om*/
    paint.setColor(0xFFFFFFFF);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawRoundRect(rectF, cornerSizePx, cornerSizePx, paint);

    // draw bitmap
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    // draw border
    paint.setColor(color);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth((float) borderSizePx);
    canvas.drawRoundRect(rectF, cornerSizePx, cornerSizePx, paint);

    if (recycleOrig && bitmap != null && !bitmap.isRecycled())
        bitmap.recycle();

    return output;
}

From source file:hochschuledarmstadt.photostream_tools.adapter.LruBitmapCache.java

@Override
protected void entryRemoved(boolean evicted, Integer key, Bitmap oldValue, Bitmap newValue) {
    if (removedBitmaps.containsKey(key)) {
        removedBitmaps.get(key).recycle();
        removedBitmaps.remove(key);/* ww w. ja va  2  s .  c  o m*/
        Log.d(BasePhotoAdapter.class.getName(), "PREVIOUSLY removed bitmap RECYCLED for photo with id: " + key);
    }
    int refCount = 0;
    if (hitCountMap.containsKey(key)) {
        refCount = hitCountMap.get(key);
    }
    if (refCount == 0) {
        if (!oldValue.isRecycled())
            oldValue.recycle();
        Log.d(BasePhotoAdapter.class.getName(), "Bitmap REMOVED and RECYCLED for photo with id: " + key);
    } else {
        if (hitCountMap.containsKey(key))
            hitCountMap.remove(key);
        removedBitmaps.put(key, oldValue);
        Log.d(BasePhotoAdapter.class.getName(), "Bitmap REMOVED for photo with id: " + key);
    }
    super.entryRemoved(evicted, key, oldValue, newValue);
}

From source file:com.snowdream.wallpaper.ImagePagerActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        return;/*from   w  ww  .  ja  v  a  2s  .c o  m*/
    }

    Bitmap bitmap = null;
    switch (requestCode) {
    case REQUEST_CODE_CROP_IMAGE:
        String path = data.getStringExtra(CropImage.IMAGE_PATH);
        if (path == null) {
            return;
        }

        bitmap = BitmapFactory.decodeFile(path);

        if (bitmap != null && !bitmap.isRecycled()) {
            try {
                setWallpaper(bitmap);
                Toast.makeText(this, "Set Successful", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(this, "Set Failed", Toast.LENGTH_SHORT).show();
            }
        }
        break;
    default:
        break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

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

/**
 * Called when there is new data to deliver to the client.  The
 * super class will take care of delivering it; the implementation
 * here just adds a little more logic./* w  w  w  .  j a v a2 s.c om*/
 */
@Override
public void deliverResult(BitmapResult result) {
    Bitmap bitmap = result != null ? result.bitmap : null;
    if (isReset()) {
        // An async query came in while the loader is stopped.  We
        // don't need the result.
        if (bitmap != null) {
            onReleaseResources(bitmap);
        }
        return;
    }
    Bitmap oldBitmap = mBitmap;
    mBitmap = bitmap;

    if (isStarted()) {
        // If the Loader is currently started, we can immediately
        // deliver its results.
        super.deliverResult(result);
    }

    // At this point we can release the resources associated with
    // 'oldBitmap' if needed; now that the new result is delivered we
    // know that it is no longer in use.
    if (oldBitmap != null && oldBitmap != bitmap && !oldBitmap.isRecycled()) {
        onReleaseResources(oldBitmap);
    }
}

From source file:ir.rasen.charsoo.controller.image_loader.core.LoadAndDisplayImageTask.java

@Override
public void run() {
    if (waitIfPaused())
        return;/* w  w  w  .ja va2 s  .  c om*/
    if (delayIfNeed())
        return;

    ReentrantLock loadFromUriLock = imageLoadingInfo.loadFromUriLock;
    L.d(LOG_START_DISPLAY_IMAGE_TASK, memoryCacheKey);
    if (loadFromUriLock.isLocked()) {
        L.d(LOG_WAITING_FOR_IMAGE_LOADED, memoryCacheKey);
    }

    loadFromUriLock.lock();
    Bitmap bmp;
    try {
        checkTaskNotActual();

        bmp = configuration.memoryCache.get(memoryCacheKey);
        if (bmp == null || bmp.isRecycled()) {
            bmp = tryLoadBitmap();
            if (bmp == null)
                return; // listener callback already was fired

            checkTaskNotActual();
            checkTaskInterrupted();

            if (options.shouldPreProcess()) {
                L.d(LOG_PREPROCESS_IMAGE, memoryCacheKey);
                bmp = options.getPreProcessor().process(bmp);
                if (bmp == null) {
                    L.e(ERROR_PRE_PROCESSOR_NULL, memoryCacheKey);
                }
            }

            if (bmp != null && options.isCacheInMemory()) {
                L.d(LOG_CACHE_IMAGE_IN_MEMORY, memoryCacheKey);
                configuration.memoryCache.put(memoryCacheKey, bmp);
            }
        } else {
            loadedFrom = LoadedFrom.MEMORY_CACHE;
            L.d(LOG_GET_IMAGE_FROM_MEMORY_CACHE_AFTER_WAITING, memoryCacheKey);
        }

        if (bmp != null && options.shouldPostProcess()) {
            L.d(LOG_POSTPROCESS_IMAGE, memoryCacheKey);
            bmp = options.getPostProcessor().process(bmp);
            if (bmp == null) {
                L.e(ERROR_POST_PROCESSOR_NULL, memoryCacheKey);
            }
        }
        checkTaskNotActual();
        checkTaskInterrupted();
    } catch (TaskCancelledException e) {
        fireCancelEvent();
        return;
    } finally {
        loadFromUriLock.unlock();
    }

    DisplayBitmapTask displayBitmapTask = new DisplayBitmapTask(bmp, imageLoadingInfo, engine, loadedFrom);
    runTask(displayBitmapTask, syncLoading, handler, engine);
}

From source file:Main.java

public static Bitmap toRoundBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float roundPx;
    float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
    if (width <= height) {
        roundPx = width / 2;//from   w w  w  .  ja  va2 s  . c o m
        top = 0;
        bottom = width;
        left = 0;
        right = width;
        height = width;
        dst_left = 0;
        dst_top = 0;
        dst_right = width;
        dst_bottom = width;
    } else {
        roundPx = height / 2;
        float clip = (width - height) / 2;
        left = clip;
        right = width - clip;
        top = 0;
        bottom = height;
        width = height;
        dst_left = 0;
        dst_top = 0;
        dst_right = height;
        dst_bottom = height;
    }
    Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom);
    final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom);
    final RectF rectF = new RectF(dst);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, src, dst, paint);
    if (bitmap != null && !bitmap.isRecycled()) {
        bitmap.recycle();
    }
    return output;
}