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.abslyon.abetterselection.CoverFlow.CoverFlowView.java

protected final void drawChild(Canvas canvas, int position, float offset) {

    int actuallyPosition = getActuallyPosition(position);

    final Bitmap child = mAdapter.getImage(actuallyPosition);
    final Bitmap reflection = obtainReflection(actuallyPosition, child);

    int[] wAndh = mImageRecorder.get(actuallyPosition);
    if (wAndh == null) {
        wAndh = new int[] { child.getWidth(), child.getHeight() };
        mImageRecorder.put(actuallyPosition, wAndh);
    } else {/*w  ww. ja  va2 s. c o m*/
        wAndh[0] = child.getWidth();
        wAndh[1] = child.getHeight();
    }

    if (child != null && !child.isRecycled() && canvas != null) {
        makeChildTransfromer(child, position, offset);
        canvas.drawBitmap(child, mChildTransfromer, mDrawChildPaint);
        if (reflection != null) {

            canvas.drawBitmap(reflection, mReflectionTransfromer, mDrawChildPaint);
        }
    }
}

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

protected final void drawChild(Canvas canvas, int mid, int position, float offset) {

    int actuallyPosition = getActuallyPosition(position);

    final Bitmap child = mAdapter.getImage(actuallyPosition);
    final Bitmap reflection = obtainReflection(child);

    int[] wAndh = mImageRecorder.get(actuallyPosition);
    if (wAndh == null) {
        wAndh = new int[] { child.getWidth(), child.getHeight() };
        mImageRecorder.put(actuallyPosition, wAndh);
    } else {/*w  w  w  .  j a  va  2s. c  o m*/
        wAndh[0] = child.getWidth();
        wAndh[1] = child.getHeight();
    }

    if (child != null && !child.isRecycled() && canvas != null) {
        makeChildTransformer(child, mid, position, offset);
        canvas.drawBitmap(child, mChildTransformer, mDrawChildPaint);
        if (reflection != null) {

            canvas.drawBitmap(reflection, mReflectionTransformer, mDrawChildPaint);
        }
    }
}

From source file:com.atobo.safecoo.view.coverflow.CoverFlowView.java

protected final void drawChild(Canvas canvas, int position, float offset) {

    int actuallyPosition = getActuallyPosition(position);

    final Bitmap child = mAdapter.getImage(actuallyPosition);
    final Bitmap reflection = obtainReflection(actuallyPosition, child);

    int[] wAndh = mImageRecorder.get(actuallyPosition);
    if (wAndh == null) {
        wAndh = new int[] { child.getWidth(), child.getHeight() };
        mImageRecorder.put(actuallyPosition, wAndh);
    } else {/*from   w ww.j a v  a2  s  .  c  om*/
        wAndh[0] = child.getWidth();
        wAndh[1] = child.getHeight();
    }

    if (child != null && !child.isRecycled() && canvas != null) {
        makeChildTransfromer(child, position, offset);
        canvas.drawBitmap(child, mChildTransfromer, mDrawChildPaint);
        if (reflection != null) {

            // canvas.drawBitmap(reflection, mReflectionTransfromer,
            //        mDrawChildPaint);
        }
    }
}

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

protected final void drawChild(Canvas canvas, int position, float offset) {

    int actuallyPosition = getActuallyPosition(position);

    final Bitmap child = mAdapter.getImage(actuallyPosition);
    final Bitmap reflection = obtainReflection(actuallyPosition, child);

    int[] wAndh = mImageRecorder.get(actuallyPosition);
    if (wAndh == null) {
        wAndh = new int[] { child.getWidth(), child.getHeight() };
        mImageRecorder.put(actuallyPosition, wAndh);
    } else {// w  w  w  . j a  va 2 s . c  o m
        wAndh[0] = child.getWidth();
        wAndh[1] = child.getHeight();
    }
    if (child != null && !child.isRecycled() && canvas != null) {
        makeChildTransfromer(child, position, offset);
        canvas.drawBitmap(child, mChildTransfromer, mDrawChildPaint);
        if (reflection != null) {
            canvas.drawBitmap(reflection, mReflectionTransfromer, mDrawChildPaint);
        }
    }
}

From source file:com.example.zhaozhu.practisecustomview.customviewgroup.HSlidingPaneLayout.java

@Override
protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (this.mCanSlide && !lp.slideable && (this.mSlideableView != null)) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.getClipBounds(this.mTmpRect);
        this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft());
        canvas.clipRect(this.mTmpRect);
    }// w  w  w.  ja  va 2s . c o  m

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && (this.mSlideOffset > 0)) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            Bitmap cache = child.getDrawingCache();
            if (cache != null && !cache.isRecycled()) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Log.e(HSlidingPaneLayout.TAG,
                        "drawChild: child view " + child + " returned null drawing cache");
                result = super.drawChild(canvas, child, drawingTime);
            }
        } else {
            if (child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(false);
            }
            result = super.drawChild(canvas, child, drawingTime);
        }
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:com.example.zhaozhu.practisecustomview.customviewgroup.HSlidingPaneLayout2.java

@Override
protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (this.mCanSlide && !lp.slideable && (this.mSlideableView != null)) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.getClipBounds(this.mTmpRect);
        this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft());
        canvas.clipRect(this.mTmpRect);
    }/*from  ww  w .j  a  v  a 2  s .c  o m*/

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && (this.mSlideOffset > 0)) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            Bitmap cache = child.getDrawingCache();
            if (cache != null && !cache.isRecycled()) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Log.e(HSlidingPaneLayout2.TAG,
                        "drawChild: child view " + child + " returned null drawing cache");
                result = super.drawChild(canvas, child, drawingTime);
            }
        } else {
            if (child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(false);
            }
            result = super.drawChild(canvas, child, drawingTime);
        }
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:com.rowland.moviesquire.ui.fragments.DetailFragment.java

private void bindTo() {
    // Build the image url
    String imageBackdropUrl = EBaseURlTypes.MOVIE_API_IMAGE_BASE_URL.getUrlType()
            + EBaseImageSize.IMAGE_SIZE_W500.getImageSize() + mMovie.getBackdropPath();
    String imagePosterUrl = EBaseURlTypes.MOVIE_API_IMAGE_BASE_URL.getUrlType()
            + EBaseImageSize.IMAGE_SIZE_W154.getImageSize() + mMovie.getPosterPath();

    Target target = new Target() {

        @Override//from   w  w  w .  j av a 2  s  . co m
        public void onPrepareLoad(Drawable arg0) {
            // Show some progress
        }

        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom arg1) {
            // Set background
            mBackdropMovie.setImageBitmap(bitmap);
            final Palette.PaletteAsyncListener paletteListener = new Palette.PaletteAsyncListener() {
                public void onGenerated(Palette palette) {
                    //Default color
                    final int defaultColor = 0xEF5350;
                    // Access palette colors here
                    int mutedDarkColor = palette.getDarkMutedColor(defaultColor);
                    mDetailMovieTitleContainer.setBackgroundColor(mutedDarkColor);
                    // Get the "vibrant" color swatch based on the bitmap
                    Palette.Swatch vibrantSwatch = palette.getDarkMutedSwatch();
                    if (vibrantSwatch != null) {
                        int textColor = vibrantSwatch.getBodyTextColor();
                        // Set the title color
                        mDetailMovieTitle.setTextColor(textColor);
                    }

                    // Check for null
                    if (mBackdropMoviePlay != null) {
                        // Show play Button
                        mBackdropMoviePlay.setVisibility(View.VISIBLE);
                        // Do some Animation on play button
                        mBackdropMoviePlay.startAnimation(simpleGrowAnimation);
                    }
                }
            };

            if (bitmap != null && !bitmap.isRecycled()) {
                Palette.from(bitmap).generate(paletteListener);
            }

        }

        @Override
        public void onBitmapFailed(Drawable arg0) {
            // Something went wrong - Hide play button
            mBackdropMoviePlay.setVisibility(View.GONE);
        }
    };
    // Use Picasso to load the images
    Picasso.with(mBackdropMovie.getContext()).load(imageBackdropUrl)
            .networkPolicy(Utilities.NetworkUtility.isNetworkAvailable(mBackdropMovie.getContext())
                    ? NetworkPolicy.NO_CACHE
                    : NetworkPolicy.OFFLINE)
            .placeholder(R.drawable.ic_movie_placeholder).into(target);

    Picasso.with(mMoviePoster.getContext()).load(imagePosterUrl)
            .networkPolicy(Utilities.NetworkUtility.isNetworkAvailable(mBackdropMovie.getContext())
                    ? NetworkPolicy.NO_CACHE
                    : NetworkPolicy.OFFLINE)
            .placeholder(R.drawable.ic_movie_placeholder).into(mMoviePoster);

    // Set the title
    mDetailMovieTitle.setText(mMovie.getOriginalTitle());
    // Set the overview
    mDetailMovieOverview.setText(mMovie.getOverview());
    // Set the rating
    mDetailMovieRate.setText(String.format("%d/10", Math.round(mMovie.getVoteAverage())));
    // Set popularity
    mDetailMoviePopularity.setText(String.format("%d votes", Math.round(mMovie.getPopularity())));
    // Set the release date
    if (mMovie.getReleaseDate() != null) {
        Calendar mCalendar = Calendar.getInstance();
        mCalendar.setTime(mMovie.getReleaseDate());
        mDetailMovieYear.setText(String.valueOf(mCalendar.get(Calendar.YEAR)));
    }
    // Update FAB icon drawable
    updateFabDrawable();
}

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

public void setAsDotViewTheme() {
    if (mContext == null) {
        return;//from  ww w. j  a v  a2s . c  o m
    }
    Bitmap bitmap = null;
    Bitmap photoARGB = null;
    try {
        bitmap = handlePicture();
        if (bitmap != null) {
            int[] photoData = new int[bitmap.getWidth() * bitmap.getHeight()];
            bitmap.getPixels(photoData, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
            photoARGB = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
            photoARGB.setPixels(photoData, 0, photoARGB.getWidth(), 0, 0, photoARGB.getWidth(),
                    photoARGB.getHeight());

            WallpaperMaker wallpaper = new WallpaperMaker();
            mScaledPhoto = wallpaper.convertDotViewWallpaper(photoARGB, 27, 48);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            mScaledPhoto.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();
            Intent intent = new Intent(DotDesignConstants.NOTIFY_DOTVIEW_TO_UPDATE_WALLPAPER);
            intent.putExtra(DotDesignConstants.EXTRA_BITMAP_ARRAY, byteArray);
            String filename = DotDesignUtil.getFileName() + "DotDrop";
            intent.putExtra(DotDesignConstants.EXTRA_FILE_NAME, filename);
            mContext.sendBroadcast(intent);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (bitmap != null && !bitmap.isRecycled()) {
            bitmap.recycle();
            bitmap = null;
        }
        if (mScaledPhoto != null && !mScaledPhoto.isRecycled()) {
            mScaledPhoto.recycle();
            mScaledPhoto = null;
        }
        if (photoARGB != null && !photoARGB.isRecycled()) {
            photoARGB.recycle();
            photoARGB = null;
        }
    }
    if (mActivity != null) {
        Toast.makeText(mActivity, getResources().getString(R.string.toast_theme_applied), Toast.LENGTH_SHORT)
                .show();
    }
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void releaseBitmapArray(Bitmap[] bitmapArray) {
    if (bitmapArray != null) {
        for (Bitmap bitmap : bitmapArray) {
            if (bitmap != null && !bitmap.isRecycled()) {
                bitmap.recycle();// w  w  w .j a  va 2s . co m
            }
        }
    }
}

From source file:dong.lan.tuyi.activity.MainActivity.java

/**
 * ???//from  ww w  .  j av  a 2s . c o  m
 *
 * @param data
 */
private void saveCropAvator(Intent data) {
    Bundle extras = data.getExtras();
    if (extras != null) {
        Bitmap bitmap = extras.getParcelable("data");
        if (bitmap != null) {
            // ?
            bitmap = PhotoUtil.toRoundCorner(bitmap, 10);
            if (isFromCamera && degree != 0) {
                bitmap = PhotoUtil.rotaingImageView(degree, bitmap);
            }
            String filename = username + "_head_"
                    + new SimpleDateFormat(TimeUtil.FORMAT_NORMAL).format(new Date()) + ".png";
            path = Constant.PICTURE_PATH + filename;
            Config.preferences = getSharedPreferences(Config.prefName, MODE_PRIVATE);
            Config.preferences.edit().remove(Config.USER_HEAD + username).apply();
            Config.preferences.edit().putString(Config.USER_HEAD + username, path).apply();
            PhotoUtil.saveBitmap(Constant.PICTURE_PATH, filename, bitmap, true);
            // ?
            if (bitmap != null && bitmap.isRecycled()) {
                bitmap.recycle();
            }
        }
    }
}