Example usage for android.graphics Canvas save

List of usage examples for android.graphics Canvas save

Introduction

In this page you can find the example usage for android.graphics Canvas save.

Prototype

public int save() 

Source Link

Document

Saves the current matrix and clip onto a private stack.

Usage

From source file:org.androfarsh.widget.DragGridLayout.java

private boolean drawChildDrawable(BitmapDrawable childDrawable, Canvas canvas, View child, long drawingTime) {
    canvas.save();
    requestCurrentRect(mTmpRect, child);
    if (child.getAnimation() == null) {
        canvas.clipRect(mTmpRect);/*from w w w  .  j a va2s.  c o m*/
    }

    final boolean result;
    if (mEditMode && (childDrawable != null) && !childDrawable.getBitmap().isRecycled()) {
        childDrawable.setBounds(mTmpRect);
        childDrawable.draw(canvas);
        result = false;
    } else {
        result = super.drawChild(canvas, child, drawingTime);
    }
    canvas.restore();
    return result;
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    int width = getWidth() - getPaddingLeft() - getPaddingRight();
    int translationX = (int) innerTranslationX + getPaddingRight();
    int clipLeft = getPaddingLeft();
    int clipRight = width + getPaddingLeft();

    if (child == containerViewBack) {
        clipRight = translationX;//ww  w  .j  a v  a 2  s . c o  m
    } else if (child == containerView) {
        clipLeft = translationX;
    }

    final int restoreCount = canvas.save();
    if (!transitionAnimationInProgress) {
        canvas.clipRect(clipLeft, 0, clipRight, getHeight());
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (translationX != 0) {
        if (child == containerView) {
            final float alpha = Math.max(0,
                    Math.min((width - translationX) / (float) AndroidUtilities.dp(20), 1.0f));
            layerShadowDrawable.setBounds(translationX - layerShadowDrawable.getIntrinsicWidth(),
                    child.getTop(), translationX, child.getBottom());
            layerShadowDrawable.setAlpha((int) (0xff * alpha));
            layerShadowDrawable.draw(canvas);
        } else if (child == containerViewBack) {
            float opacity = Math.min(0.8f, (width - translationX) / (float) width);
            if (opacity < 0) {
                opacity = 0;
            }
            scrimPaint.setColor((int) (((0x99000000 & 0xff000000) >>> 24) * opacity) << 24);
            canvas.drawRect(clipLeft, 0, clipRight, getHeight(), scrimPaint);
        }
    }

    return result;
}

From source file:com.android.slidingmenu.HorizontalListView.java

/**
 * Draws the overscroll edge glow effect on the left and right sides of the
 * horizontal list//from   w  w w. j  a v  a  2s .c o m
 */
private void drawEdgeGlow(Canvas canvas) {
    if (mEdgeGlowLeft != null && !mEdgeGlowLeft.isFinished() && isEdgeGlowEnabled()) {
        // The Edge glow is meant to come from the top of the screen, so
        // rotate it to draw on the left side.
        final int restoreCount = canvas.save();
        final int height = getHeight();

        canvas.rotate(-90, 0, 0);
        canvas.translate(-height + getPaddingBottom(), 0);

        mEdgeGlowLeft.setSize(getRenderHeight(), getRenderWidth());
        if (mEdgeGlowLeft.draw(canvas)) {
            invalidate();
        }

        canvas.restoreToCount(restoreCount);
    } else if (mEdgeGlowRight != null && !mEdgeGlowRight.isFinished() && isEdgeGlowEnabled()) {
        // The Edge glow is meant to come from the top of the screen, so
        // rotate it to draw on the right side.
        final int restoreCount = canvas.save();
        final int width = getWidth();

        canvas.rotate(90, 0, 0);
        canvas.translate(getPaddingTop(), -width);
        mEdgeGlowRight.setSize(getRenderHeight(), getRenderWidth());
        if (mEdgeGlowRight.draw(canvas)) {
            invalidate();
        }

        canvas.restoreToCount(restoreCount);
    }
}

From source file:lewa.support.v7.widget.SwitchCompat.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    final Rect padding = mTempRect;
    final Drawable trackDrawable = mTrackDrawable;
    if (trackDrawable != null) {
        trackDrawable.getPadding(padding);
    } else {/* w  w w.  ja v a2  s  . co m*/
        padding.setEmpty();
    }

    final int switchTop = mSwitchTop;
    final int switchBottom = mSwitchBottom;
    final int switchInnerTop = switchTop + padding.top;
    final int switchInnerBottom = switchBottom - padding.bottom;

    final Drawable thumbDrawable = mThumbDrawable;
    if (trackDrawable != null) {
        trackDrawable.draw(canvas);
    }

    final int saveCount = canvas.save();

    if (thumbDrawable != null) {
        thumbDrawable.draw(canvas);
    }

    final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
    if (switchText != null) {
        final int drawableState[] = getDrawableState();
        if (mTextColors != null) {
            mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0));
        }
        mTextPaint.drawableState = drawableState;

        final int cX;
        if (thumbDrawable != null) {
            final Rect bounds = thumbDrawable.getBounds();
            cX = bounds.left + bounds.right;
        } else {
            cX = getWidth();
        }

        final int left = cX / 2 - switchText.getWidth() / 2;
        final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2;
        canvas.translate(left, top);
        switchText.draw(canvas);
    }

    canvas.restoreToCount(saveCount);
}

From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java

@Override
public void onDraw(Canvas canvas) {
    mPaint.reset();// w  w  w .j a  va  2s.c om
    mPaint.setAntiAlias(true);
    mPaint.setFilterBitmap(true);
    MasterImage.getImage().setImageShowSize(getWidth() - 2 * mShadowMargin, getHeight() - 2 * mShadowMargin);

    MasterImage img = MasterImage.getImage();
    // Hide the loading indicator as needed
    if (mActivity.isLoadingVisible() && getFilteredImage() != null) {
        if ((img.getLoadedPreset() == null)
                || (img.getLoadedPreset() != null && img.getLoadedPreset().equals(img.getCurrentPreset()))) {
            mActivity.stopLoadingIndicator();
        } else if (img.getLoadedPreset() != null) {
            return;
        }
        mActivity.stopLoadingIndicator();
    }

    canvas.save();

    mShadowDrawn = false;

    Bitmap highresPreview = MasterImage.getImage().getHighresImage();
    Bitmap fullHighres = MasterImage.getImage().getPartialImage();

    boolean isDoingNewLookAnimation = MasterImage.getImage().onGoingNewLookAnimation();

    if (highresPreview == null || isDoingNewLookAnimation) {
        drawImageAndAnimate(canvas, getFilteredImage());
    } else {
        drawImageAndAnimate(canvas, highresPreview);
    }

    drawHighresImage(canvas, fullHighres);
    drawCompareImage(canvas, getGeometryOnlyImage());

    canvas.restore();

    if (!mEdgeEffect.isFinished()) {
        canvas.save();
        float dx = (getHeight() - getWidth()) / 2f;
        if (getWidth() > getHeight()) {
            dx = -(getWidth() - getHeight()) / 2f;
        }
        if (mCurrentEdgeEffect == EDGE_BOTTOM) {
            canvas.rotate(180, getWidth() / 2, getHeight() / 2);
        } else if (mCurrentEdgeEffect == EDGE_RIGHT) {
            canvas.rotate(90, getWidth() / 2, getHeight() / 2);
            canvas.translate(0, dx);
        } else if (mCurrentEdgeEffect == EDGE_LEFT) {
            canvas.rotate(270, getWidth() / 2, getHeight() / 2);
            canvas.translate(0, dx);
        }
        if (mCurrentEdgeEffect != 0) {
            mEdgeEffect.draw(canvas);
        }
        canvas.restore();
        invalidate();
    } else {
        mCurrentEdgeEffect = 0;
    }
}

From source file:com.klinker.android.sliding.MultiShrinkScroller.java

/**
 * Draw all components on the screen.//  w w  w .  j  a  v  a  2  s  . c  o m
 * @param canvas the canvas to draw on.
 */
@Override
public void draw(Canvas canvas) {
    super.draw(canvas);

    final int width = getWidth() - getPaddingLeft() - getPaddingRight();
    final int height = getHeight();

    if (!edgeGlowBottom.isFinished()) {
        final int restoreCount = canvas.save();

        // Draw the EdgeEffect on the bottom of the Window (Or a little bit below the bottom
        // of the Window if we start to scroll upwards while EdgeEffect is visible). This
        // does not need to consider the case where this MultiShrinkScroller doesn't fill
        // the Window, since the nested ScrollView should be set to fillViewport.
        canvas.translate(-width + getPaddingLeft(), height + getMaximumScrollUpwards() - getScroll());

        canvas.rotate(180, width, 0);
        if (isTwoPanel) {
            // Only show the EdgeEffect on the bottom of the ScrollView.
            edgeGlowBottom.setSize(scrollView.getWidth(), height);
        } else {
            edgeGlowBottom.setSize(width, height);
        }
        if (edgeGlowBottom.draw(canvas)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                postInvalidateOnAnimation();
            } else {
                postInvalidate();
            }
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!edgeGlowTop.isFinished()) {
        final int restoreCount = canvas.save();
        if (isTwoPanel) {
            edgeGlowTop.setSize(scrollView.getWidth(), height);
            canvas.translate(photoViewContainer.getWidth(), 0);
        } else {
            edgeGlowTop.setSize(width, height);
        }
        if (edgeGlowTop.draw(canvas)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                postInvalidateOnAnimation();
            } else {
                postInvalidate();
            }
        }
        canvas.restoreToCount(restoreCount);
    }
}

From source file:io.doist.datetimepicker.time.RadialTimePickerView.java

@Override
public void onDraw(Canvas canvas) {
    if (!mInputEnabled) {
        canvas.saveLayerAlpha(0, 0, getWidth(), getHeight(), mDisabledAlpha, Canvas.ALL_SAVE_FLAG);
    } else {//from  www  .jav a2  s. c  o  m
        canvas.save();
    }

    calculateGridSizesHours();
    calculateGridSizesMinutes();

    drawCircleBackground(canvas);
    drawSelector(canvas);

    drawTextElements(canvas, mTextSize[HOURS], mTypeface, mOuterTextHours, mTextGridWidths[HOURS],
            mTextGridHeights[HOURS], mPaint[HOURS], mColor[HOURS], mAlpha[HOURS].getValue());

    if (mIs24HourMode && mInnerTextHours != null) {
        drawTextElements(canvas, mInnerTextSize, mTypeface, mInnerTextHours, mInnerTextGridWidths,
                mInnerTextGridHeights, mPaint[HOURS], mColor[HOURS], mAlpha[HOURS].getValue());
    }

    drawTextElements(canvas, mTextSize[MINUTES], mTypeface, mOuterTextMinutes, mTextGridWidths[MINUTES],
            mTextGridHeights[MINUTES], mPaint[MINUTES], mColor[MINUTES], mAlpha[MINUTES].getValue());

    drawCenter(canvas);

    if (DEBUG) {
        drawDebug(canvas);
    }

    canvas.restore();
}

From source file:com.ecom.consumer.customviews.HorizontalListView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    canvas.save();
    super.dispatchDraw(canvas);

    if (outRect != null && !mIsBeingDragged) {
        ColorDrawable drawable = new ColorDrawable(0x884193C9);// 77318fd5new
        // ColorDrawable(0x440000ff
        // &//from   www.j  a va2 s. c  o  m
        // Color.BLUE);
        drawable.setBounds(outRect);
        drawable.draw(canvas);
    }
    outRect = null;
    drawEdgeGlow(canvas);
    canvas.restore();
}

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

/**
 * Divider/*from w ww .j  ava2  s  .  co  m*/
 *
 * @param canvas 
 */
protected void drawDivider(Canvas canvas) {
    if (mDivider == null || mDivider.getIntrinsicHeight() <= 0)
        return;
    final int dividerWidth = mDivider.getIntrinsicWidth() > 0 ? mDivider.getIntrinsicWidth()
            : getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);
    final int dividerHeight = mDivider.getIntrinsicHeight();
    mDivider.setBounds(0, 0, dividerWidth, dividerHeight);
    final float moveX = ViewCompat.getPaddingStart(this);
    final float moveY = getItemHeight() + getPaddingTop();
    canvas.save();
    canvas.translate(moveX, moveY);
    mDivider.draw(canvas);
    canvas.restore();
}

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

/**
 * //from  w w  w.j  a v a  2 s.  co  m
 *
 * @param canvas     
 * @param position   ???
 * @param itemWidth  ?
 * @param itemHeight ?
 */
protected void drawInterval(Canvas canvas, int position, int itemWidth, int itemHeight) {
    if (mInterval == null || mInterval.getIntrinsicWidth() <= 0 || position == getItemCount() - 1)
        return;
    final int intervalHeight = mInterval.getIntrinsicHeight() <= 0 ? itemHeight
            : mInterval.getIntrinsicHeight();
    mInterval.setBounds(0, 0, getIntervalWidth(), intervalHeight);
    final int moveX = ViewCompat.getPaddingStart(this) + itemWidth * position;
    final float moveY = getPaddingTop() + (itemHeight - intervalHeight) * 0.5f;
    canvas.save();
    canvas.translate(moveX, moveY);
    mInterval.draw(canvas);
    canvas.restore();
}