Example usage for android.view View setDrawingCacheEnabled

List of usage examples for android.view View setDrawingCacheEnabled

Introduction

In this page you can find the example usage for android.view View setDrawingCacheEnabled.

Prototype

@Deprecated
public void setDrawingCacheEnabled(boolean enabled) 

Source Link

Document

Enables or disables the drawing cache.

Usage

From source file:com.bright.cloudutils.view.ResideLayout.java

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

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.scale(1.2f - 0.2f * mSlideOffset, 1.2f - 0.2f * mSlideOffset, child.getRight(), getHeight() / 2);
    } else {/*from w w  w  . j  av a 2s. c  om*/
        assert mSlideableView != null;
        canvas.scale(1 - mSlideOffset / 3, 1 - mSlideOffset / 3, mSlideableView.getLeft(), getHeight() / 2);
        ViewCompat.setRotationY(child, -10 * mSlideOffset);
    }

    if (!lp.slideable && mSlideOffset == 0) {
        result = true;
    } else {
        if (Build.VERSION.SDK_INT >= 11) { // HC
            result = super.drawChild(canvas, child, drawingTime);
        } else {
            if (lp.dimWhenOffset && mSlideOffset > 0) {
                if (!child.isDrawingCacheEnabled()) {
                    child.setDrawingCacheEnabled(true);
                }
                final Bitmap cache = child.getDrawingCache();
                if (cache != null) {
                    canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                    result = false;
                } else {
                    Log.e(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.ylw.split.splitview.view.SplitView.java

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

    //        if (mCanSlide && !lp.slideable && mSlideableView != null) {
    //            // Clip against the slider; no sense drawing what will immediately be covered.
    //            canvas.getClipBounds(mTmpRect);
    //            if (isLayoutRtlSupport()) {
    //                mTmpRect.left = Math.max(mTmpRect.left, mSlideableView.getRight());
    //            } else {
    //                mTmpRect.right = Math.min(mTmpRect.right, mSlideableView.getLeft());
    //            }
    //            canvas.clipRect(mTmpRect);
    //        }// w w w .j  av  a 2 s  . c  om

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && mSlideOffset > 0) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            final Bitmap cache = child.getDrawingCache();
            if (cache != null) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Log.e(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.ywesee.amiko.MainActivity.java

/**
 * Takes screenshot of the whole screen//  ww  w . j  a  va 2  s . co m
 * @param activity
 */
public void sendFeedbackScreenshot(final Activity activity, int mode) {
    try {
        // Get root windows
        final View rootView = activity.getWindow().getDecorView().findViewById(android.R.id.content)
                .getRootView();
        rootView.setDrawingCacheEnabled(true);
        Bitmap bitmap = rootView.getDrawingCache();
        // The file be saved to the download folder
        File outputFile = new File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
                        + "/amiko_screenshot.png");
        FileOutputStream fOutStream = new FileOutputStream(outputFile);
        // Picture is then compressed
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOutStream);
        rootView.setDrawingCacheEnabled(false);
        fOutStream.close();
        // Start email activity
        if (mode == 1)
            startEmailActivity(activity, Uri.fromFile(outputFile), "", "AmiKo for Android");
        else if (mode == 2)
            startEmailActivity(activity, Uri.fromFile(outputFile), "zdavatz@ywesee.com",
                    "Interaction notification");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:rp3.widget.SlidingPaneLayout.java

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

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

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && mSlideOffset > 0) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            final Bitmap cache = child.getDrawingCache();
            if (cache != null) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Log.e(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.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);
    }/*from   w  w w  .j  a  va2s  .  co 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 w w  w . j a v  a 2  s .  co  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:administrator.example.com.myscrollview.VerticalViewPager.java

/**
 *  ScrollingCacheEnabled/*from  w  ww .  j a v  a2 s  . co  m*/
 * @param enabled enabled or disabled
 */
private void setScrollingCacheEnabled(boolean enabled) {
    if (mScrollingCacheEnabled != enabled) {
        mScrollingCacheEnabled = enabled;
        if (USE_CACHE) {
            final int size = getChildCount();
            for (int i = 0; i < size; ++i) {
                final View child = getChildAt(i);
                if (child.getVisibility() != GONE) {
                    child.setDrawingCacheEnabled(enabled);
                } /* end of if */
            } /* end of for */
        } /* end of if */
    } /* end of if */
}

From source file:com.waz.zclient.pages.main.conversationpager.SlidingPaneLayout.java

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

    if (canSlide && !lp.slideable && slideableView != null) {
        // Clip against the slider; no sense drawing what will immediately be covered.
        canvas.getClipBounds(tmpRect);//from   w  w  w  .j a v a 2  s  .  com
        if (isLayoutRtlSupport()) {
            tmpRect.left = Math.max(tmpRect.left, slideableView.getRight());
        } else {
            tmpRect.right = Math.min(tmpRect.right, slideableView.getLeft());
        }
        canvas.clipRect(tmpRect);
    }

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && slideOffset > 0) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            final Bitmap cache = child.getDrawingCache();
            if (cache != null) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Timber.e("drawChild: child view %s returned null drawing cache", child);
                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.nikhilnayak.games.octoshootar.ui.fragments.GameScoreFragment.java

private Bitmap getBitmapToShare() {
    final View fragmentView = GameScoreFragment.this.getView();
    final Paint paint = new Paint();
    Bitmap bitmap;/*from  w  w  w .j a  v a  2s .  co  m*/

    // Get the game name.
    final View gameName = fragmentView.findViewById(R.id.fragment_score_game_mode_name);
    final int gameNameWidth = gameName.getWidth();
    final int gameNameHeight = gameName.getHeight();

    // Get the grade card.
    final View gradeCard = fragmentView.findViewById(R.id.result_card_grade);
    final int gradeCardWidth = gradeCard.getWidth();
    final int gradeCardHeight = gradeCard.getHeight();

    // Get the details card.
    final View detailsCard = fragmentView.findViewById(R.id.result_card_details);
    final int detailsCardWidth = detailsCard.getWidth();
    final int detailsCardHeight = detailsCard.getHeight();

    // Define some padding and a margin between the elements
    final int padding = 30;
    final int margin = 50;

    // Get the bitmap dimension.
    int bitmapWidth = Math.max(gameNameWidth, Math.max(gradeCardWidth, detailsCardWidth)) + padding;
    int bitmapHeight = padding + gameNameHeight + margin + gradeCardHeight + margin + detailsCardHeight;

    // Compute the left/top for bitmap drawing
    final int gameNameLeft = bitmapWidth / 2 - gameNameWidth / 2;
    final int gameNameTop = padding / 2 + margin / 2;
    final int gradeCardLeft = bitmapWidth / 2 - gradeCardWidth / 2;
    final int gradeCardTop = padding / 2 + gameNameHeight + margin;
    final int detailsCardLeft = bitmapWidth / 2 - detailsCardWidth / 2;
    final int detailsCardTop = padding / 2 + gameNameHeight + margin + gradeCardHeight + margin;

    // Initialize a bitmap with a canvas.
    Bitmap bitmapToShare = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapToShare);
    canvas.drawColor(GameScoreFragment.this.getResources().getColor(R.color.background_grey));

    // Draw the game name
    gameName.setDrawingCacheEnabled(true);
    bitmap = gameName.getDrawingCache(true);
    canvas.drawBitmap(bitmap, gameNameLeft, gameNameTop, paint);
    gameName.setDrawingCacheEnabled(false);
    bitmap.recycle();
    bitmap = null;

    // Draw the grade card.
    gradeCard.setDrawingCacheEnabled(true);
    bitmap = gradeCard.getDrawingCache(true);
    canvas.drawBitmap(bitmap, gradeCardLeft, gradeCardTop, paint);
    gradeCard.setDrawingCacheEnabled(false);
    bitmap.recycle();
    bitmap = null;

    // Draw the details card.
    detailsCard.setDrawingCacheEnabled(true);
    bitmap = detailsCard.getDrawingCache(true);
    canvas.drawBitmap(bitmap, detailsCardLeft, detailsCardTop, paint);
    detailsCard.setDrawingCacheEnabled(false);
    bitmap.recycle();
    bitmap = null;

    return bitmapToShare;
}

From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java

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

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.getClipBounds(mTmpRect);//w  ww  .j ava2 s .c o m
        if (isLayoutRtlSupport()) {
            mTmpRect.left = Math.max(mTmpRect.left, mSlideableView.getRight());
        } else {
            mTmpRect.right = Math.min(mTmpRect.right, mSlideableView.getLeft());
        }
        canvas.clipRect(mTmpRect);
    }

    if (Build.VERSION.SDK_INT >= 11) { // HC
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (lp.dimWhenOffset && mSlideOffset > 0) {
            if (!child.isDrawingCacheEnabled()) {
                child.setDrawingCacheEnabled(true);
            }
            final Bitmap cache = child.getDrawingCache();
            if (cache != null) {
                canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                result = false;
            } else {
                Log.e(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;
}