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:github.popeen.dsub.util.ImageLoader.java

public SilentBackgroundTask<Void> loadImage(Context context, RemoteControlClientBase remoteControl,
        MusicDirectory.Entry entry) {// ww w.  j  a  va 2s .c o m
    Bitmap bitmap;
    if (entry == null || entry.getCoverArt() == null) {
        bitmap = getUnknownImage(entry, imageSizeLarge);
        setImage(entry, 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(entry, remoteControl, drawable);
        return null;
    }

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

From source file:com.abslyon.abetterselection.CoverFlow.CoverFlowView.java

private Bitmap obtainReflection(int position, Bitmap src) {
    if (reflectHeightFraction <= 0) {
        return null;
    }//from   ww  w  . jav  a  2  s.  co  m

    Bitmap reflection = mRecycler.getCachedBitmap(position);

    if (reflection == null || reflection.isRecycled()) {
        mRecycler.removeCachedBitmap(position);

        reflection = BitmapUtils.createReflectedBitmap(src, reflectHeightFraction);

        if (reflection != null) {
            mRecycler.addBitmap2Cache(position, reflection);

            return reflection;
        }
    }

    return reflection;
}

From source file:com.torrenttunes.android.MediaNotificationManager.java

private Notification createNotification() {
    LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }/*from   w w w. j  a  v a  2  s.c om*/

    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(R.drawable.ic_skip_previous_white_24dp,
                mService.getString(R.string.label_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(R.drawable.ic_skip_next_white_24dp,
                mService.getString(R.string.label_next), mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    String fetchArtUrl = null;
    Bitmap art = null;
    if (description.getIconUri() != null) {
        // This sample assumes the iconUri will be a valid URL formatted String, but
        // it can actually be any valid Android Uri formatted String.
        // async fetch the album art icon
        String artUrl = description.getIconUri().toString();
        art = AlbumArtCache.getInstance().getBigImage(artUrl);
        if (art == null) {
            fetchArtUrl = artUrl;
            // use a placeholder art while the remote art is being downloaded
            art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art);
        }
        if (art.isRecycled()) {
            art = null;
        }
    }

    notificationBuilder
            //                .setStyle(new Notification.MediaStyle()
            //                        .setShowActionsInCompactView(
            //                                new int[]{playPauseButtonPosition})  // show only play/pause in compact view
            //                        .setMediaSession(mSessionToken))
            .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification)
            .setVisibility(Notification.VISIBILITY_PUBLIC).setUsesChronometer(true)
            .setContentIntent(createContentIntent(description)).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art);

    if (mController != null && mController.getExtras() != null) {
        String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            String castInfo = mService.getResources().getString(R.string.casting_to_device, castName);
            notificationBuilder.setSubText(castInfo);
            notificationBuilder.addAction(R.drawable.ic_close_black_24dp,
                    mService.getString(R.string.stop_casting), mStopCastIntent);
        }
    }

    setNotificationPlaybackState(notificationBuilder);
    if (fetchArtUrl != null) {
        fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
    }

    return notificationBuilder.build();
}

From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java

private Bitmap obtainReflection(Bitmap src) {
    if (reflectHeightFraction <= 0) {
        return null;
    }/*from w w w . j a  v a 2  s .  co m*/

    Bitmap reflection = mRecycler.getCachedReflectiuon(src);

    if (reflection == null || reflection.isRecycled()) {
        mRecycler.removeReflectionCache(src);

        reflection = BitmapUtils.createReflectedBitmap(src, reflectHeightFraction);

        if (reflection != null) {
            mRecycler.buildReflectionCache(src, reflection);

            return reflection;
        }
    }

    return reflection;
}

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

public SilentBackgroundTask<Void> loadImage(View view, String url, boolean large) {
    Bitmap bitmap;
    int size = large ? imageSizeLarge : imageSizeDefault;
    if (url == null) {
        String key = getKey(url + "unknown", size);
        int color = COLORS[Math.abs(key.hashCode()) % COLORS.length];
        bitmap = getUnknownImage(key, size, color, null, null);
        setImage(view, Util.createDrawableFromBitmap(context, bitmap), true);
        return null;
    }/*from  ww w  . java 2  s  .c  om*/

    bitmap = cache.get(getKey(url, size));
    if (bitmap != null && !bitmap.isRecycled()) {
        final Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap);
        setImage(view, drawable, true);
        return null;
    }
    setImage(view, null, false);

    SilentBackgroundTask<Void> task = new ViewUrlTask(view.getContext(), view, url, size);
    task.execute();
    return task;
}

From source file:com.dolphinwang.imagecoverflow.CoverFlowView.java

private Bitmap obtainReflection(int position, Bitmap src) {
    if (reflectHeightFraction <= 0) {
        return null;
    }/*from w ww  . j  a  va 2  s  . c  om*/

    Bitmap reflection = mRecycler.getCachedBitmap(position);
    if (reflection == null || reflection.isRecycled()) {
        mRecycler.removeCachedBitmap(position);
        reflection = BitmapUtils.createReflectedBitmap(src, reflectHeightFraction);

        if (reflection != null) {
            mRecycler.addBitmap2Cache(position, reflection);

            return reflection;
        }
    }

    return reflection;
}

From source file:com.htc.dotdesign.DrawingView.java

private void sharePicture() {
    if (mContext == null) {
        return;/*w  w w  . ja  v a  2s .  com*/
    }
    Bitmap bitmap = null;
    Bitmap scaledBmp = null;
    try {
        bitmap = handlePicture();
        scaledBmp = Bitmap.createScaledBitmap(bitmap, DotDesignConstants.SHARE_PHOTO_WIDTH,
                DotDesignConstants.SHARE_PHOTO_HEIGHT, false);
        DotDesignUtil.SaveImagetoExternal(scaledBmp, mContext);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (scaledBmp != null && !scaledBmp.isRecycled()) {
            scaledBmp.recycle();
            scaledBmp = null;
        }
        if (bitmap != null && !bitmap.isRecycled()) {
            bitmap.recycle();
            bitmap = null;
        }
    }
    File tmpFile = new File(mContext.getExternalFilesDir(null), DotDesignConstants.shareName);
    Intent shareintent = new Intent(Intent.ACTION_SEND);
    shareintent.setType("image/png");
    shareintent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tmpFile));
    mContext.startActivity(Intent.createChooser(shareintent, "Share"));
}

From source file:com.xdyou.sanguo.GameSanGuo.java

private void uploadImage(Bitmap mUploadBitmap) {
    // /*from   w  ww .  j a va  2 s. co m*/
    if (mUploadBitmap != null && !mUploadBitmap.isRecycled()) {
        // // , ?
        Log.d("FB", "upload image");
        Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), mUploadBitmap,
                mUploadCallback);
        request.executeAsync();
    }
}

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

/**
 * Loads a bitmap into OpenGL./*w  w w  .  ja  v  a  2s.  c o  m*/
 *
 * @param texIndex the desired texture index
 * @param bitmap   the bitmap to put into OpenGL
 */
private void loadTextureInternal(int texIndex, Bitmap bitmap, boolean recycle) {

    GLES20.glGenTextures(1, mTextureIds, texIndex);

    Log.d(TAG, "loading texture: " + texIndex + " -> " + mTextureIds[texIndex]);

    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]);

        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

        // Set filtering
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

        // Load the bitmap into the bound texture.
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

        mRectTextureIds[texIndex] = mTextureIds[texIndex];
    } else {
        Log.w(TAG, "Failed to load: " + texIndex);
    }

    if (mTextureIds[texIndex] == INVALID_TEXTURE) {
        Log.e(TAG, "Error loading texture.");
    }
}

From source file:androidx.mediarouter.app.MediaRouteControllerDialog.java

private boolean isBitmapRecycled(Bitmap bitmap) {
    return bitmap != null && bitmap.isRecycled();
}