Example usage for android.graphics Canvas rotate

List of usage examples for android.graphics Canvas rotate

Introduction

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

Prototype

public final void rotate(float degrees, float px, float py) 

Source Link

Document

Preconcat the current matrix with the specified rotation.

Usage

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mRemeasure) {
        remeasure(getWidth(), getHeight());
        mRemeasure = false;/*from ww w .  ja va 2s . c  om*/
    }
    canvas.save();

    float yTranslate = -mViewStartY + DAY_HEADER_HEIGHT;
    // offset canvas by the current drag and header position
    canvas.translate(-mViewStartX, yTranslate);
    // clip to everything below the allDay area
    Rect dest = mDestRect;
    dest.top = (int) (mFirstCell - yTranslate);
    dest.bottom = (int) (mViewHeight - yTranslate);
    dest.left = 0;
    dest.right = mViewWidth;
    canvas.save();
    canvas.clipRect(dest);
    // Draw the movable part of the view
    doDraw(canvas);
    // restore to having no clip
    canvas.restore();

    if ((mTouchMode & TOUCH_MODE_HSCROLL) != 0) {
        float xTranslate;
        if (mViewStartX > 0) {
            xTranslate = mViewWidth;
        } else {
            xTranslate = -mViewWidth;
        }
        // Move the canvas around to prep it for the next view
        // specifically, shift it by a screen and undo the
        // yTranslation which will be redone in the nextView's onDraw().
        canvas.translate(xTranslate, -yTranslate);
        DayView nextView = (DayView) mViewSwitcher.getNextView();

        // Prevent infinite recursive calls to onDraw().
        nextView.mTouchMode = TOUCH_MODE_INITIAL_STATE;

        nextView.onDraw(canvas);
        // Move it back for this view
        canvas.translate(-xTranslate, 0);
    } else {
        // If we drew another view we already translated it back
        // If we didn't draw another view we should be at the edge of the
        // screen
        canvas.translate(mViewStartX, -yTranslate);
    }

    // Draw the fixed areas (that don't scroll) directly to the canvas.
    drawAfterScroll(canvas);
    mComputeSelectedEvents = false;

    // Draw overscroll glow
    if (!mEdgeEffectTop.isFinished()) {
        if (DAY_HEADER_HEIGHT != 0) {
            canvas.translate(0, DAY_HEADER_HEIGHT);
        }
        if (mEdgeEffectTop.draw(canvas)) {
            invalidate();
        }
        if (DAY_HEADER_HEIGHT != 0) {
            canvas.translate(0, -DAY_HEADER_HEIGHT);
        }
    }
    if (!mEdgeEffectBottom.isFinished()) {
        canvas.rotate(180, mViewWidth / 2, mViewHeight / 2);
        if (mEdgeEffectBottom.draw(canvas)) {
            invalidate();
        }
    }
    canvas.restore();
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

/**
 * overscroll//from  ww w.ja v  a 2  s. c  o  m
 *
 * @param canvas
 */
protected void drawOverScrollEffect(Canvas canvas) {
    final int scrollY = getScrollY();
    final int scrollX = getScrollX();

    final int width;
    final int height;
    final int translateX;
    final int translateY;

    width = getWidth();
    height = getHeight();

    translateX = 0;
    translateY = 0;

    if (mTopEdgeEffect != null) {//
        if (!mTopEdgeEffect.isFinished()) {
            final int restoreCount = canvas.save();
            canvas.clipRect(translateX, translateY, translateX + width,
                    translateY + mTopEdgeEffect.getMaxHeight());
            final int edgeY = Math.min(0, scrollY) + translateY;
            canvas.translate(translateX, edgeY);
            mTopEdgeEffect.setSize(width, height);
            if (mTopEdgeEffect.draw(canvas)) {
                invalidateTopGlow();
            }
            canvas.restoreToCount(restoreCount);
        }
    }

    if (mBottomEdgeEffect != null) {//
        if (!mBottomEdgeEffect.isFinished()) {
            final int restoreCount = canvas.save();
            canvas.clipRect(translateX, translateY + height - mBottomEdgeEffect.getMaxHeight(),
                    translateX + width, translateY + height);
            final int edgeX = -width + translateX;
            final int edgeY = Math.max(getHeight(), scrollY);
            canvas.translate(edgeX, edgeY);
            canvas.rotate(180, width, 0);
            mBottomEdgeEffect.setSize(width, height);
            if (mBottomEdgeEffect.draw(canvas)) {
                invalidateBottomGlow();
            }
            canvas.restoreToCount(restoreCount);
        }
    }

    if (mLeftEdgeEffect != null) {//
        if (!mLeftEdgeEffect.isFinished()) {
            canvas.clipRect(translateX, translateY, translateX + mLeftEdgeEffect.getMaxHeight(),
                    translateY + height);
            final int restoreCount = canvas.save();
            canvas.translate(-width, getHeight() - getWidth());//?
            canvas.rotate(270, width, 0);//
            mLeftEdgeEffect.setSize(height, width);//?
            if (mLeftEdgeEffect.draw(canvas)) {
                invalidateLeftGlow();
            }
            canvas.restoreToCount(restoreCount);
        }
    }

    if (mRightEdgeEffect != null) {//?
        if (!mRightEdgeEffect.isFinished()) {
            //     canvas.clipRect(translateX, width - mRightEdgeEffect.getMaxHeight(), width, translateY + height);
            final int restoreCount = canvas.save();
            canvas.translate(0, getWidth());//?
            canvas.rotate(-270, width, 0);//
            mRightEdgeEffect.setSize(height, width);//?
            if (mRightEdgeEffect.draw(canvas)) {
                invalidateRightGlow();
            }
            canvas.restoreToCount(restoreCount);
        }
    }
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

private boolean drawEndEdge(Canvas canvas) {
    if (mEndEdge.isFinished()) {
        return false;
    }//  w ww. j  av a  2  s .c  o  m

    final int restoreCount = canvas.save();
    final int width = getWidth() - getPaddingLeft() - getPaddingRight();
    final int height = getHeight() - getPaddingTop() - getPaddingBottom();

    if (mIsVertical) {
        canvas.translate(-width, height);
        canvas.rotate(180, width, 0);
    } else {
        canvas.translate(width, 0);
        canvas.rotate(90);
    }

    final boolean needsInvalidate = mEndEdge.draw(canvas);
    canvas.restoreToCount(restoreCount);
    return needsInvalidate;
}

From source file:com.appunite.list.AbsHorizontalListView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (mEdgeGlowLeft != null) {
        final int scrollX = getScrollX();
        boolean needsInvalidate = false;
        if (!mEdgeGlowLeft.isFinished()) {
            final int restoreCount = canvas.save();
            final int topPadding = mListPadding.top + mGlowPaddingTop;
            final int bottomPadding = mListPadding.bottom + mGlowPaddingBottom;
            final int height = getHeight() - topPadding - bottomPadding;

            int edgeX = Math.min(0, scrollX + mFirstPositionDistanceGuess);
            canvas.translate(edgeX, height + topPadding);
            canvas.rotate(-90, 0, 0);
            mEdgeGlowLeft.setSize(height, getWidth());
            if (mEdgeGlowLeft.draw(canvas)) {
                needsInvalidate = true;/*from   www .  j a  v a2  s  . c  o  m*/
            }
            canvas.restoreToCount(restoreCount);
        }
        if (!mEdgeGlowRight.isFinished()) {
            final int restoreCount = canvas.save();
            final int topPadding = mListPadding.top + mGlowPaddingTop;
            final int bottomPadding = mListPadding.bottom + mGlowPaddingBottom;
            final int height = getHeight() - topPadding - bottomPadding;
            final int width = getWidth();

            int edgeY = topPadding;
            int edgeX = Math.max(width, scrollX + mLastPositionDistanceGuess);

            canvas.translate(edgeX, edgeY);
            canvas.rotate(90, 0, 0);

            mEdgeGlowRight.setSize(height, width);
            if (mEdgeGlowRight.draw(canvas)) {
                needsInvalidate = true;
            }
            canvas.restoreToCount(restoreCount);
        }
        if (needsInvalidate) {
            invalidate();
        }
    }
}

From source file:com.artifex.mupdflib.TwoWayView.java

private boolean drawEndEdge(Canvas canvas) {
    if (mEndEdge.isFinished()) {
        return false;
    }//w ww .j  a  v a 2  s.  c  o m

    final int restoreCount = canvas.save();
    final int width = getWidth();
    final int height = getHeight();

    if (mIsVertical) {
        canvas.translate(-width, height);
        canvas.rotate(180, width, 0);
    } else {
        canvas.translate(width, 0);
        canvas.rotate(90);
    }

    final boolean needsInvalidate = mEndEdge.draw(canvas);
    canvas.restoreToCount(restoreCount);
    return needsInvalidate;
}

From source file:com.appunite.list.AbsListView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (mEdgeGlowTop != null) {
        final int scrollY = getScrollY();
        boolean needsInvalidate = false;
        if (!mEdgeGlowTop.isFinished()) {
            final int restoreCount = canvas.save();
            final int leftPadding = mListPadding.left + mGlowPaddingLeft;
            final int rightPadding = mListPadding.right + mGlowPaddingRight;
            final int width = getWidth() - leftPadding - rightPadding;

            int edgeY = Math.min(0, scrollY + mFirstPositionDistanceGuess);
            canvas.translate(leftPadding, edgeY);
            mEdgeGlowTop.setSize(width, getHeight());
            if (mEdgeGlowTop.draw(canvas)) {
                needsInvalidate = true;//from www  .j  a va  2 s  . com
            }
            canvas.restoreToCount(restoreCount);
        }
        if (!mEdgeGlowBottom.isFinished()) {
            final int restoreCount = canvas.save();
            final int leftPadding = mListPadding.left + mGlowPaddingLeft;
            final int rightPadding = mListPadding.right + mGlowPaddingRight;
            final int width = getWidth() - leftPadding - rightPadding;
            final int height = getHeight();

            int edgeX = -width + leftPadding;
            int edgeY = Math.max(height, scrollY + mLastPositionDistanceGuess);
            canvas.translate(edgeX, edgeY);
            canvas.rotate(180, width, 0);
            mEdgeGlowBottom.setSize(width, height);
            if (mEdgeGlowBottom.draw(canvas)) {
                needsInvalidate = true;
            }
            canvas.restoreToCount(restoreCount);
        }
        if (needsInvalidate) {
            invalidate();
        }
    }
    if (mFastScroller != null) {
        final int scrollY = getScrollY();
        if (scrollY != 0) {
            // Pin to the top/bottom during overscroll
            int restoreCount = canvas.save();
            canvas.translate(0, (float) scrollY);
            mFastScroller.draw(canvas);
            canvas.restoreToCount(restoreCount);
        } else {
            mFastScroller.draw(canvas);
        }
    }
}