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:uk.co.senab.bitmapcache.CacheableBitmapDrawable.java

/**
 * Returns true when this wrapper has a bitmap and the bitmap has not been recycled.
 *
 * @return true - if the bitmap has not been recycled.
 *//*from  w  w  w  .j  a  v  a2s.co m*/
public synchronized boolean isBitmapValid() {
    Bitmap bitmap = getBitmap();
    return null != bitmap && !bitmap.isRecycled();
}

From source file:com.xiaoya.framepager.SuperAwesomeCardFragment.java

@Override
public void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    Set<String> keyset = imagesCache.keySet();
    for (String value : keyset) {
        Bitmap temp = imagesCache.get(value);
        if (null != temp && !temp.isRecycled()) {
            temp.recycle();//from   w w w .j av a  2 s  .  c om
        }
    }
    Iterator<String> it = keyset.iterator();
    while (it.hasNext()) {
        String s = it.next();
        it.remove();
        imagesCache.remove(s);
    }
    imagesCache.clear();
    if (!scheduledExecutorService.isShutdown()) {
        scheduledExecutorService.shutdown();
    }
}

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

public ImageDownloader() {
    options.inJustDecodeBounds = false;//from  w w w .j ava  2  s  .c  om
    cacheDir = FileUtils.createFile(Constants.LOCAL_CID_ICON_PATH);

    int MAXMEMONRY = (int) (Runtime.getRuntime().maxMemory() / 1024);
    if (null == mMemoryCache) {
        mMemoryCache = 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;
                }

            }
        };
    }

    if (null == mMemoryCache_sd) {
        mMemoryCache_sd = 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.baseproject.image.ImageCache.java

/**
 * Get from memory cache./*from  w w w  .  java  2  s  .  c o  m*/
 * 
 * @param data
 *            Unique identifier for which item to get
 * @return The bitmap if found in cache, null otherwise
 */
public Bitmap getBitmapFromMemCache(String data) {
    if (mMemoryCache != null) {
        String fileName = Utils.urlToFileName(data);
        final Bitmap memBitmap = mMemoryCache.get(fileName);
        // ?
        if (memBitmap != null && !memBitmap.isRecycled()) {
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "Memory cache hit");
            }
            return memBitmap;
        }
    }
    return null;
}

From source file:net.gree.asdk.core.imageloader.cache.ImageCache.java

private void initMemCache(Context context) {
    mMemCache = new LruCache<String, Bitmap>(mSettings.mMemCacheSize) {
        @Override/*from www  .  j a v  a  2 s.  c o  m*/
        protected int sizeOf(String key, Bitmap bitmap) {
            return getBitmapSize(bitmap);
        }

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

From source file:so.contacts.hub.basefunction.imageloader.DataCache.java

/**
 * Get from memory cache./*from ww  w  . j  av  a  2s.  co m*/
 * 
 * @param data Unique identifier for which item to get
 * @return The bitmap if found in cache, null otherwise
 */
public Object getResultFromCache(String data) {
    if (mMemCache != null) {
        final Object mCacheResult = mMemCache.get(data);
        if (mCacheResult != null) {
            return mCacheResult;
        }
    }
    //add by xcx 2015-08-25 start ?
    if (mWeakBitmaps != null) {
        WeakReference<Bitmap> weakRef = mWeakBitmaps.get(data);
        if (weakRef != null) {
            Bitmap bitmap = weakRef.get();
            if (bitmap != null && !bitmap.isRecycled()) {
                return bitmap;
            }
        }
    }
    //add by xcx 2015-08-25 end ?
    return null;
}

From source file:so.contacts.hub.basefunction.imageloader.DataCache.java

/**
 * Clears both the memory and disk cache associated with this ImageCache
 * object. Note that this includes disk access so this should not be
 * executed on the main/UI thread./*from  w w  w .ja v  a 2 s.c  om*/
 */
public void clearCache() {
    if (mMemCache != null) {
        //modify by xcx 2015-08-25 start recycle
        Map<String, Object> map = mMemCache.snapshot();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            Object value = entry.getValue();
            if (value != null && value instanceof Bitmap) {
                Bitmap bitmap = (Bitmap) value;
                if (bitmap != null && !bitmap.isRecycled()) {
                    bitmap.recycle();
                    bitmap = null;
                }
                mWeakBitmaps.remove(entry.getKey());
            }
        }
        mMemCache.evictAll();
        //modify by xcx 2015-08-25 end recycle
    }
    //add by xcx 2015-08-25 start ????
    if (mDiskLruCache != null) {
        mDiskLruCache.clearMap();
    }
    //add by xcx 2015-08-25 end ????
    System.gc();
}

From source file:nuclei.media.MediaNotificationManager.java

Notification createNotification() {
    LOG.d("updateNotificationMetadata. mMetadata=", mMetadata);
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }//from w  w  w  . j av  a2 s. c o m

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    int playPauseButtonPosition = 0;

    // If skip to previous action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(ResourceProvider.getInstance().getDrawable(ResourceProvider.PREVIOUS),
                ResourceProvider.getInstance().getString(ResourceProvider.PREVIOUS), mPreviousIntent);

        // If there is a "skip to previous" button, the play/pause button will
        // be the second one. We need to keep track of it, because the MediaStyle notification
        // requires to specify the index of the buttons (actions) that should be visible
        // when in compact view.
        playPauseButtonPosition = 1;
    }

    addPlayPauseAction(notificationBuilder);

    // If skip to next action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(ResourceProvider.getInstance().getDrawable(ResourceProvider.NEXT),
                ResourceProvider.getInstance().getString(ResourceProvider.NEXT), mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    Bitmap bitmap = description.getIconBitmap();
    if (bitmap != null && bitmap.isRecycled())
        bitmap = null;

    if (bitmap == null) {
        bitmap = mMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationBuilder
                .setStyle(
                        new NotificationCompat.MediaStyle().setShowActionsInCompactView(playPauseButtonPosition) // show only play/pause in compact view
                                .setShowCancelButton(true).setCancelButtonIntent(mCancelIntent)
                                .setMediaSession(mSessionToken))
                .setContentIntent(createContentIntent(description));
    }

    notificationBuilder.setColor(mNotificationColor).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setUsesChronometer(true).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setSmallIcon(ResourceProvider.getInstance().getDrawable(ResourceProvider.ICON_SMALL))
            .setLargeIcon(bitmap);

    if (mController != null && mController.getExtras() != null) {
        String castName = mController.getExtras().getString(MediaService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            CharSequence castInfo = ResourceProvider.getInstance().getString(ResourceProvider.CASTING_TO_DEVICE,
                    castName);
            notificationBuilder.setSubText(castInfo);
            notificationBuilder.addAction(
                    ResourceProvider.getInstance().getDrawable(ResourceProvider.ICON_CLOSE),
                    ResourceProvider.getInstance().getString(ResourceProvider.STOP_CASTING), mStopCastIntent);
        }
    }

    setNotificationPlaybackState(notificationBuilder);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
        notificationBuilder.mActions.clear();

    return notificationBuilder.build();
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.AttachmentPreviewDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.apptentive_dialog_image_preview, container);
    previewContainer = rootView.findViewById(R.id.preview_container);
    progressBar = (ProgressBar) rootView.findViewById(R.id.preview_progress);
    previewImageView = (PreviewImageView) rootView.findViewById(R.id.preview_image);

    previewImageView.setGestureCallback(this);
    header = (ViewGroup) rootView.findViewById(R.id.header_bar);
    closeButton = (ImageButton) header.findViewById(R.id.close_dialog);
    closeButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from   ww  w  .  j  av a  2 s. c om*/
        public void onClick(View v) {
            dismiss();
        }
    });

    // show the progress bar while we load content...
    progressBar.setVisibility(View.VISIBLE);

    currentImage = getArguments().getParcelable("image");

    width = inflater.getContext().getResources().getDisplayMetrics().widthPixels;
    height = inflater.getContext().getResources().getDisplayMetrics().heightPixels;
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);
    previewContainer.setLayoutParams(lp);

    ApptentiveAttachmentLoader.getInstance().load(currentImage.originalPath, currentImage.localCachePath, 0,
            previewImageView, width, height, true, new ApptentiveAttachmentLoader.LoaderCallback() {
                @Override
                public void onLoaded(ImageView view, int pos, Bitmap d) {
                    if (progressBar != null) {
                        progressBar.setVisibility(View.GONE);
                    }

                    if (previewImageView == view) {
                        previewContainer.setVisibility(View.VISIBLE);
                        if (!d.isRecycled()) {
                            previewImageView.setImageBitmap(d);
                        }
                    }
                }

                @Override
                public void onLoadTerminated() {
                    if (progressBar != null) {
                        progressBar.setVisibility(View.GONE);
                    }
                }

                @Override
                public void onDownloadStart() {
                    if (progressBar != null) {
                        progressBar.setVisibility(View.VISIBLE);
                    }
                }

                @Override
                public void onDownloadProgress(int progress) {
                }
            });

    return rootView;
}

From source file:osm.custommaps.create.PreviewMapActivity.java

@Override
protected void onPause() {
    if (helpDialogManager != null) {
        helpDialogManager.onPause();//from   w ww .j  av a 2  s .c o  m
    }
    if (isFinishing() && imageOverlay != null) {
        Bitmap image = imageOverlay.getImage();
        if (image != null && !image.isRecycled()) {
            image.recycle();
            imageOverlay.setImage(null);
        }
    }
    super.onPause();
}