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 void rotate(float degrees) 

Source Link

Document

Preconcat the current matrix with the specified rotation.

Usage

From source file:com.tjych.swip.vertical.DirectionalViewPager.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    boolean needsInvalidate = false;

    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        if (!mStartEdge.isFinished()) {
            final int restoreCount = canvas.save();

            if (mOrientation == HORIZONTAL) {
                final int height = getHeight() - getPaddingTop() - getPaddingBottom();
                final int width = getWidth();
                canvas.rotate(270);
                canvas.translate(-height + getPaddingTop(), mFirstOffset * width);
                mStartEdge.setSize(height, width);
            } else {
                final int height = getHeight();
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();
                canvas.translate(getPaddingLeft(), mFirstOffset * height);
                mStartEdge.setSize(width, height);
            }// w  w  w  .j  a  va2 s.  c o  m

            needsInvalidate |= mStartEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
        if (!mEndEdge.isFinished()) {
            final int restoreCount = canvas.save();

            if (mOrientation == HORIZONTAL) {
                final int width = getWidth();
                final int height = getHeight() - getPaddingTop() - getPaddingBottom();

                canvas.rotate(90);
                canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width);
                mEndEdge.setSize(height, width);
            } else {
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();
                final int height = getHeight();

                if (mEndEdgeMatrix == null) {
                    mEndEdgeMatrix = new Matrix();
                    mEndEdgeMatrix.setScale(1f, -1f);
                    mEndEdgeMatrix.postTranslate(0f, (mLastOffset + 1) * height);
                }

                canvas.concat(mEndEdgeMatrix);
                mEndEdge.setSize(width, height);
            }

            needsInvalidate |= mEndEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        mStartEdge.finish();
        mEndEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:com.telerik.examples.primitives.ExampleViewPagerBase.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    boolean needsInvalidate = false;

    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        if (!mLeftEdge.isFinished()) {
            if (this.orientation == LinearLayout.HORIZONTAL) {
                final int restoreCount = canvas.save();
                final int height = getHeight() - getPaddingTop() - getPaddingBottom();
                final int width = getWidth();

                canvas.rotate(270);
                canvas.translate(-height + getPaddingTop(), mFirstOffset * width);
                mLeftEdge.setSize(height, width);
                needsInvalidate |= mLeftEdge.draw(canvas);
                canvas.restoreToCount(restoreCount);
            } else {
                final int restoreCount = canvas.save();
                final int height = getHeight();
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();
                canvas.translate(getPaddingLeft(), mFirstOffset * height);
                mLeftEdge.setSize(width, height);
                needsInvalidate |= mLeftEdge.draw(canvas);
                canvas.restoreToCount(restoreCount);
            }//  w  w  w  . j  a  v  a 2s  .  c  om
        }
        if (!mRightEdge.isFinished()) {
            if (this.orientation == LinearLayout.HORIZONTAL) {
                final int restoreCount = canvas.save();
                final int width = getWidth();
                final int height = getHeight() - getPaddingTop() - getPaddingBottom();

                canvas.rotate(90);
                canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width);
                mRightEdge.setSize(height, width);
                needsInvalidate |= mRightEdge.draw(canvas);
                canvas.restoreToCount(restoreCount);
            } else {
                final int restoreCount = canvas.save();
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();
                final int height = getHeight();

                canvas.rotate(180);
                canvas.translate(-getPaddingLeft() - width, -height);
                mRightEdge.setSize(width, height);
                needsInvalidate |= mRightEdge.draw(canvas);
                canvas.restoreToCount(restoreCount);
            }
        }
    } else {
        mLeftEdge.finish();
        mRightEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:gl.android.widget.viewpager.ViewPagerEx.java

@Override
public void draw(Canvas canvas) {
    try {/*from w  w w.j ava 2  s .  c  o m*/
        super.draw(canvas);
    } catch (Exception e) {
        //         System.out.println(e.getMessage());
        //FIXME the nullpoint Exception at super.Draw(canvas) in viewPager;
        if (mFirstLayout) {
            Log.e("ViewPagerEx", "line 2305,.draw(Canvas canvas) NullPointException");
        }

    }
    boolean needsInvalidate = false;
    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        if (!mLeftEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight() - getPaddingTop() - getPaddingBottom();
            final int width = getWidth();

            canvas.rotate(270);
            canvas.translate(-height + getPaddingTop(), mFirstOffset * width);
            mLeftEdge.setSize(height, width);
            needsInvalidate |= mLeftEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
        if (!mRightEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth();
            final int height = getHeight() - getPaddingTop() - getPaddingBottom();

            canvas.rotate(90);
            canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width);
            mRightEdge.setSize(height, width);
            needsInvalidate |= mRightEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        mLeftEdge.finish();
        mRightEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:org.ohmage.widget.VerticalViewPager.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    boolean needsInvalidate = false;

    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        if (!mTopEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();
            final int height = getHeight();

            canvas.translate(0, (float) mFirstOffset * height);
            mTopEdge.setSize(width, height);
            needsInvalidate |= mTopEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }/*w  ww  .  j a va2  s .c  om*/
        if (!mBottomEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();
            final int height = getHeight();

            canvas.rotate(180);
            canvas.translate(-width, (float) -(mLastOffset + 1) * height);
            mBottomEdge.setSize(width, height);
            needsInvalidate |= mBottomEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        mTopEdge.finish();
        mBottomEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:VerticalViewPager.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    boolean needsInvalidate = false;

    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        if (!mTopEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();

            canvas.translate(-getPaddingLeft(), mFirstOffset * height);
            mTopEdge.setSize(width, height);
            needsInvalidate |= mTopEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }//from ww w  . ja v  a 2 s  .  c om
        if (!mBottomEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();
            final int height = getHeight();

            canvas.rotate(180);
            canvas.translate(-width + getPaddingLeft(), -(mLastOffset + 1) * height);
            mBottomEdge.setSize(width, height);
            needsInvalidate |= mBottomEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        mTopEdge.finish();
        mBottomEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:dev.dworks.libs.widget.ViewPager.java

private void drawHorizontally(Canvas canvas) {
    boolean needsInvalidate = false;

    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        if (!mLeftEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight() - getPaddingTop() - getPaddingBottom();
            final int width = getWidth();

            canvas.rotate(270);
            canvas.translate(-height + getPaddingTop(), mFirstOffset * width);
            mLeftEdge.setSize(height, width);
            needsInvalidate |= mLeftEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }//  w w  w .  ja va  2  s .  c o  m
        if (!mRightEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth();
            final int height = getHeight() - getPaddingTop() - getPaddingBottom();

            canvas.rotate(90);
            canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width);
            mRightEdge.setSize(height, width);
            needsInvalidate |= mRightEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        mLeftEdge.finish();
        mRightEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:javalibrary.android.ui.VerticalViewPager.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    boolean needsInvalidate = false;
    if (DEBUG)/*from  www.  j a  v  a 2s.com*/
        Log.v(TAG, "draw");
    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        /*if (!mLeftEdge.isFinished()) {
        final int restoreCount = canvas.save();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();
                
        canvas.rotate(270);
        canvas.translate(-height + getPaddingTop(), 0);
        mLeftEdge.setSize(height, getWidth());
        needsInvalidate |= mLeftEdge.draw(canvas);
        canvas.restoreToCount(restoreCount);
        }
        if (!mRightEdge.isFinished()) {
        final int restoreCount = canvas.save();
        final int width = getWidth();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();
        final int itemCount = mAdapter != null ? mAdapter.getCount() : 1;
                
        canvas.rotate(90);
        canvas.translate(-getPaddingTop(),
                -itemCount * (width + mPageMargin) + mPageMargin);
        mRightEdge.setSize(height, width);
        needsInvalidate |= mRightEdge.draw(canvas);
        canvas.restoreToCount(restoreCount);
        }*/
        if (!mTopEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight() - getPaddingTop() - getPaddingBottom();

            canvas.rotate(270);
            canvas.translate(-height + getPaddingTop(), 0);
            mTopEdge.setSize(height, getWidth());
            needsInvalidate |= mTopEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
        if (!mBottomEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth();
            final int height = getHeight() - getPaddingTop() - getPaddingBottom();
            final int itemCount = mAdapter != null ? mAdapter.getCount() : 1;

            canvas.rotate(90);
            canvas.translate(-getPaddingTop(), -itemCount * (width + mPageMargin) + mPageMargin);
            mBottomEdge.setSize(height, width);
            needsInvalidate |= mBottomEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        mLeftEdge.finish();
        mRightEdge.finish();
        mTopEdge.finish();
        mBottomEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        invalidate();
    }
}

From source file:eu.kanade.tachiyomi.ui.reader.viewer.pager.vertical.VerticalViewPagerImpl.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    boolean needsInvalidate = false;

    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        if (!mTopEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();

            canvas.translate(getPaddingLeft(), mFirstOffset * height);
            mTopEdge.setSize(width, height);
            needsInvalidate |= mTopEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }/*from ww  w.  j  a v a  2  s  .co m*/
        if (!mBottomEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();

            canvas.rotate(180);
            canvas.translate(-width - getPaddingLeft(), -(mLastOffset + 1) * height);
            mBottomEdge.setSize(width, height);
            needsInvalidate |= mBottomEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        mTopEdge.finish();
        mBottomEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    boolean needsInvalidate = false;

    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        if (!mLeftEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = isOrientationHorizontal() ? getHeight() - getPaddingTop() - getPaddingBottom()
                    : getWidth() - getPaddingLeft() - getPaddingRight();
            final int height = isOrientationHorizontal() ? getWidth() - getPaddingLeft() - getPaddingRight()
                    : getHeight() - getPaddingTop() - getPaddingBottom();

            if (isOrientationHorizontal()) {
                canvas.rotate(270);
                canvas.translate(-width + getPaddingTop(), mFirstOffset * height);
            }/*from  w  w  w.j  a va  2s .  com*/
            mLeftEdge.setSize(width, height);
            needsInvalidate |= mLeftEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
        if (!mRightEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = isOrientationHorizontal() ? getHeight() - getPaddingTop() - getPaddingBottom()
                    : getWidth() - getPaddingLeft() - getPaddingRight();
            final int height = isOrientationHorizontal() ? getWidth() - getPaddingLeft() - getPaddingRight()
                    : getHeight() - getPaddingTop() - getPaddingBottom();

            if (isOrientationHorizontal()) {
                canvas.rotate(90);
                canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * height);
            } else {
                canvas.rotate(180);
                canvas.translate(-width, -(mLastOffset + 1) * height);
            }
            mRightEdge.setSize(width, height);
            needsInvalidate |= mRightEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        mLeftEdge.finish();
        mRightEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (mEdgeGlowTop != null) {
        final int scrollX = getScrollX();
        final int scrollY = getScrollY();
        if (scrollDirection == DIRECTION_HORIZONTAL) {
            //            if (!mEdgeGlowLeft.isFinished()) {
            //               Log.i("NestedScrollView", "draw  ");
            //               final int restoreCount = canvas.save();
            //               final int height = getHeight() - getPaddingTop()
            //                     - getPaddingBottom();
            //               
            //               canvas.translate(getPaddingLeft(), height);
            //               canvas.rotate(-90);
            //               mEdgeGlowLeft.setSize(getWidth(), height);
            //               if (mEdgeGlowLeft.draw(canvas)) {
            //                  ViewCompat.postInvalidateOnAnimation(this);
            //               }
            //               canvas.restoreToCount(restoreCount);
            //            }
            //            if (!mEdgeGlowRight.isFinished()) {
            //               Log.i("NestedScrollView", "draw  ?");
            //               final int restoreCount = canvas.save();
            //               final int height = getHeight() - getPaddingTop()
            //                     - getPaddingBottom();
            ////w  ww.j a  va  2  s .c om
            //               canvas.translate(getPaddingLeft() + getWidth(),height);
            //               canvas.rotate(90);
            //               mEdgeGlowRight.setSize(getWidth(), height);
            //               if (mEdgeGlowRight.draw(canvas)) {
            //                  ViewCompat.postInvalidateOnAnimation(this);
            //               }
            //               canvas.restoreToCount(restoreCount);
            //            }

            if (!mEdgeGlowLeft.isFinished()) {
                final int restoreCount = canvas.save();
                final int height = getHeight() - getPaddingTop() - getPaddingBottom();

                canvas.rotate(270);
                canvas.translate(-height + getPaddingTop() - scrollY, Math.min(0, scrollX));
                mEdgeGlowLeft.setSize(height, getWidth());
                if (mEdgeGlowLeft.draw(canvas)) {
                    invalidate();
                }
                canvas.restoreToCount(restoreCount);
            }
            if (!mEdgeGlowRight.isFinished()) {
                final int restoreCount = canvas.save();
                final int width = getWidth();
                final int height = getHeight() - getPaddingTop() - getPaddingBottom();

                canvas.rotate(90);
                canvas.translate(-getPaddingTop() + scrollY,
                        -(Math.max(getHorizontalScrollRange(), scrollX) + width));
                mEdgeGlowRight.setSize(height, width);
                if (mEdgeGlowRight.draw(canvas)) {
                    invalidate();
                }
                canvas.restoreToCount(restoreCount);
            }
        } else if (scrollDirection == DIRECTION_VERTICAL) {
            if (!mEdgeGlowTop.isFinished()) {
                final int restoreCount = canvas.save();
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();

                canvas.translate(scrollX + getPaddingLeft(), Math.min(0, scrollY));
                mEdgeGlowTop.setSize(width, getHeight());
                if (mEdgeGlowTop.draw(canvas)) {
                    ViewCompat.postInvalidateOnAnimation(this);
                }
                canvas.restoreToCount(restoreCount);
            }
            if (!mEdgeGlowBottom.isFinished()) {
                final int restoreCount = canvas.save();
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();
                final int height = getHeight();

                canvas.translate(scrollX - width + getPaddingLeft(),
                        Math.max(getVerticalScrollRange(), scrollY) + height);
                canvas.rotate(180, width, 0);
                mEdgeGlowBottom.setSize(width, height);
                if (mEdgeGlowBottom.draw(canvas)) {
                    ViewCompat.postInvalidateOnAnimation(this);
                }
                canvas.restoreToCount(restoreCount);
            }
        } else {
            //do nothing
        }

    }
}