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:com.metinkale.prayerapp.vakit.PrefsView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    canvas.scale(0.8f, 0.8f, canvas.getWidth() / 2, canvas.getHeight() / 2);
    Object o = getValue();/*from   www . j  a  v a 2s .co m*/
    boolean active = ((o instanceof Boolean) && o.equals(true)) || ((o instanceof Integer) && !o.equals(0))
            || ((o instanceof String) && !((String) o).startsWith("silent"));
    if (mPref == Pref.Vibration2) {
        active = !o.equals(-1);
    }
    mPaint.setColor(active ? 0xff03A9F4 : 0xffe0e0e0);
    int w = getHeight();
    canvas.drawCircle(w / 2, w / 2, w / 2, mPaint);

    int p = w / 7;
    mDrawable.setBounds(p, p, w - p, w - p);
    mDrawable.setColorFilter(active ? sCFActive : sCFInactive);
    mDrawable.draw(canvas);

    if ((mPref == Pref.Time) || (mPref == Pref.SabahTime) || (mPref == Pref.Silenter)) {
        int s = (Integer) getValue();

        if (s != 0) {
            mPaint.setColor(getResources().getColor(R.color.colorPrimaryDark));
            canvas.drawCircle(getWidth() * 0.78f, getHeight() * 0.78f, getWidth() / 4, mPaint);
            mPaint.setColor(Color.WHITE);
            mPaint.setTextAlign(Align.CENTER);
            mPaint.setTextSize(w / 5);
            mPaint.setTypeface(Typeface.DEFAULT_BOLD);
            canvas.drawText(s + "", w * 0.78f, w * 0.87f, mPaint);
        }
    } else if (mPref == Pref.Vibration2)

    {
        int s = (Integer) getValue();
        String txt = "";
        if (s == 0) {
            txt = "8";
        } else if (s == 1) {
            txt = "1";
        }
        mPaint.setColor(Color.BLACK);
        mPaint.setTextAlign(Align.CENTER);
        mPaint.setTextSize(w / 2);
        mPaint.setTypeface(Typeface.DEFAULT_BOLD);
        if (s == 0) {
            canvas.rotate(90, canvas.getWidth() / 2, canvas.getHeight() / 2);
            canvas.drawText(txt, w / 2, (w * 2) / 3, mPaint);
            canvas.rotate(-90, canvas.getWidth() / 2, canvas.getHeight() / 2);
        } else {
            canvas.drawText(txt, w / 2, w * 2 / 3, mPaint);
        }
    }
}

From source file:com.jjoe64.graphview.Viewport.java

/**
 * Draws the overscroll "glow" at the four edges of the chart region, if necessary.
 *
 * @see EdgeEffectCompat/*from w  ww .  j  a  v a2 s  .co m*/
 */
private void drawEdgeEffectsUnclipped(Canvas canvas) {
    // The methods below rotate and translate the canvas as needed before drawing the glow,
    // since EdgeEffectCompat always draws a top-glow at 0,0.

    boolean needsInvalidate = false;

    if (!mEdgeEffectTop.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop());
        mEdgeEffectTop.setSize(mGraphView.getGraphContentWidth(), mGraphView.getGraphContentHeight());
        if (mEdgeEffectTop.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!mEdgeEffectBottom.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(mGraphView.getGraphContentLeft(),
                mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight());
        canvas.rotate(180, mGraphView.getGraphContentWidth() / 2, 0);
        mEdgeEffectBottom.setSize(mGraphView.getGraphContentWidth(), mGraphView.getGraphContentHeight());
        if (mEdgeEffectBottom.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!mEdgeEffectLeft.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(mGraphView.getGraphContentLeft(),
                mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight());
        canvas.rotate(-90, 0, 0);
        mEdgeEffectLeft.setSize(mGraphView.getGraphContentHeight(), mGraphView.getGraphContentWidth());
        if (mEdgeEffectLeft.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (!mEdgeEffectRight.isFinished()) {
        final int restoreCount = canvas.save();
        canvas.translate(mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(),
                mGraphView.getGraphContentTop());
        canvas.rotate(90, 0, 0);
        mEdgeEffectRight.setSize(mGraphView.getGraphContentHeight(), mGraphView.getGraphContentWidth());
        if (mEdgeEffectRight.draw(canvas)) {
            needsInvalidate = true;
        }
        canvas.restoreToCount(restoreCount);
    }

    if (needsInvalidate) {
        ViewCompat.postInvalidateOnAnimation(mGraphView);
    }
}

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

/**
 * Draw all components on the screen.//from   ww w .ja v a 2s . 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:net.simonvt.staggeredgridview.StaggeredGridView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);

    if (topEdge != null) {
        boolean needsInvalidate = false;
        if (!topEdge.isFinished()) {
            topEdge.draw(canvas);//from  w ww  . j  a  v a 2s . com
            needsInvalidate = true;
        }
        if (!bottomEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth();
            canvas.translate(-width, getHeight());
            canvas.rotate(180, width, 0);
            bottomEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
            needsInvalidate = true;
        }

        if (needsInvalidate) {
            postInvalidateOnAnimation();
        }
    }

    if (!selectorRect.isEmpty()) {
        selector.setBounds(selectorRect);
        selector.draw(canvas);
    }
}

From source file:com.microhealthllc.Slide.MultiShrinkScroller.java

/**
 * Draw all components on the screen./*  w  ww.  j  a  v  a 2 s. co 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);
        }

        // todo: figure out what is wrong with the edge glow with padded layouts
        if (paddedLayout) {
            edgeGlowBottom.setSize(0, 0);
        }

        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() * (1 / 6), 0);
        } else {
            edgeGlowTop.setSize(width, height);
        }

        // todo: figure out what is wrong with the edge glow with padded layouts
        if (paddedLayout) {
            edgeGlowTop.setSize(0, 0);
        }

        if (edgeGlowTop.draw(canvas)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                postInvalidateOnAnimation();
            } else {
                postInvalidate();
            }
        }
        canvas.restoreToCount(restoreCount);
    }
}

From source file:ir.hatamiarash.calendar.view.QiblaCompassView.java

public void drawDial(Canvas canvas) {
    // over here/*from   w w w. java2s. c o  m*/
    circlePaint.reset();
    circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color));
    circlePaint.setStrokeWidth(1);
    circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor.

    int textHeight = (int) textPaint.measureText("yY");
    markerPaint.reset();
    markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color));
    // Draw the background
    canvas.drawCircle(px, py, Radius, circlePaint);
    canvas.drawCircle(px, py, Radius - 20, circlePaint);
    // Rotate our perspective so that the "top" is
    // facing the current bearing.

    int textWidth = (int) textPaint.measureText("W");
    int cardinalX = px - textWidth / 2;
    int cardinalY = py - Radius + textHeight;

    // Draw the marker every 15 degrees and text every 45.
    for (int i = 0; i < 24; i++) {
        // Draw a marker.
        canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint);
        canvas.save();
        canvas.translate(0, textHeight);
        // Draw the cardinal points
        if (i % 6 == 0) {
            String dirString = "";
            switch (i) {
            case (0): {
                dirString = northString;
                break;
            }
            case (6):
                dirString = eastString;
                break;
            case (12):
                dirString = southString;
                break;
            case (18):
                dirString = westString;
                break;
            }
            canvas.drawText(dirString, cardinalX, cardinalY, textPaint);
        } else if (i % 3 == 0) {
            // Draw the text every alternate 45deg
            String angle = String.valueOf(i * 15);
            float angleTextWidth = textPaint.measureText(angle);
            int angleTextX = (int) (px - angleTextWidth / 2);
            int angleTextY = py - Radius + textHeight;
            canvas.drawText(angle, angleTextX, angleTextY, textPaint);
        }
        canvas.restore();
        canvas.rotate(15, px, py);
    }
}

From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java

public void drawDial(Canvas canvas) {
    // over here//from   w ww .j  a  v  a 2s  .  co m
    circlePaint.reset();
    circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color));
    circlePaint.setStrokeWidth(1);
    circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor.

    int textHeight = (int) textPaint.measureText("yY");
    markerPaint.reset();
    markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color));
    // Draw the background
    canvas.drawCircle(px, py, Radius, circlePaint);
    canvas.drawCircle(px, py, Radius - 20, circlePaint);
    // Rotate our perspective so that the "top" is
    // facing the current bearing.

    int textWidth = (int) textPaint.measureText("W");
    int cardinalX = px - textWidth / 2;
    int cardinalY = py - Radius + textHeight;

    // Draw the marker every 15 degrees and text every 45.
    for (int i = 0; i < 24; i++) {
        // Draw a marker.
        canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint);
        canvas.save();
        canvas.translate(0, textHeight);
        // Draw the cardinal points
        if (i % 6 == 0) {
            String dirString = "";
            switch (i) {
            case (0): {
                dirString = northString;
                break;
            }
            case (6):
                dirString = eastString;
                break;
            case (12):
                dirString = southString;
                break;
            case (18):
                dirString = westString;
                break;
            }
            canvas.drawText(dirString, cardinalX, cardinalY, textPaint);
        } else if (i % 3 == 0) {
            // Draw the text every alternate 45deg
            String angle = String.valueOf(i * 15);
            float angleTextWidth = textPaint.measureText(angle);
            int angleTextX = (int) (px - angleTextWidth / 2);
            int angleTextY = py - Radius + textHeight;
            canvas.drawText(angle, angleTextX, angleTextY, textPaint);
        }
        canvas.restore();

        canvas.rotate(15, px, py);
    }

}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java

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

    if (mIsOn) {// w w  w .ja  va  2  s .  co m
        mShapeDrawable.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
        mShapeDrawable.getPaint().setColor(mColor);
        mShapeDrawable.getPaint().setShadowLayer(2, 2, 2, Color.GRAY);
        mShapeDrawable.draw(canvas);
    } else {
        /*mShapeDrawable.getPaint().setStyle(Paint.Style.FILL);
        mShapeDrawable.getPaint().setColor(Color.WHITE);
        mShapeDrawable.getPaint().setShadowLayer(2,2,2,Color.GRAY);
        mShapeDrawable.draw(canvas);
        mShapeDrawable.getPaint().setStyle(Paint.Style.STROKE);
        mShapeDrawable.getPaint().setColor(Color.BLACK);
        mShapeDrawable.draw(canvas);*/
        mShapeDrawable.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
        mShapeDrawable.getPaint().setColor(Color.LTGRAY);
        mShapeDrawable.getPaint().setShadowLayer(2, 2, 2, Color.GRAY);
        mShapeDrawable.draw(canvas);
    }

    PointF center = getCircleCenter();
    mMainTextPaint.getTextBounds(mMainText, 0, mMainText.length(), mTextBounds);
    if (mOrientation == HandleDirection.RIGHT)
        canvas.drawText(mMainText, center.x + 5, center.y + mTextBounds.height() / 2 - 1, mMainTextPaint);
    else if (mOrientation == HandleDirection.LEFT)
        canvas.drawText(mMainText, center.x - 5, center.y + mTextBounds.height() / 2 - 2, mMainTextPaint);
    else
        canvas.drawText(mMainText, center.x, center.y + mTextBounds.height() / 2, mMainTextPaint);

    if (mPressDrawable != null) {
        if (mOrientation == HandleDirection.RIGHT) {
            mPressDrawable.setBounds(2, (int) (center.y - HANDLE_BREADTH / 2), HANDLE_BREADTH - 3,
                    (int) center.y + HANDLE_BREADTH / 2);
            mPressDrawable.draw(canvas);
        } else if (mOrientation == HandleDirection.LEFT) {
            canvas.save();
            canvas.rotate(180, HANDLE_LENGTH / 2, mHandlePos);
            mPressDrawable.setBounds(1, (int) (center.y - HANDLE_BREADTH / 2), HANDLE_BREADTH - 5,
                    (int) center.y + HANDLE_BREADTH / 2);
            mPressDrawable.draw(canvas);
            canvas.restore();
        }
    }
}

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

@Override
public void onDraw(Canvas canvas) {
    mPaint.reset();//from   w  w  w .  j a v a2  s  .  c o m
    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.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (mEdgeGlowTop != null) {
        final int scrollY = getScrollY();
        if (!mEdgeGlowTop.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();

            canvas.translate(getPaddingLeft(), Math.min(0, scrollY));
            mEdgeGlowTop.setSize(width, getHeight());
            if (mEdgeGlowTop.draw(canvas)) {
                ViewCompat.postInvalidateOnAnimation(this);
            }//from   w  w  w  . j a v  a2  s .co m
            canvas.restoreToCount(restoreCount);
        }
        if (!mEdgeGlowBottom.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();
            final int height = getHeight();

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