Example usage for android.graphics Canvas translate

List of usage examples for android.graphics Canvas translate

Introduction

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

Prototype

public void translate(float dx, float dy) 

Source Link

Document

Preconcat the current matrix with the specified translation

Usage

From source file:com.cuelogic.android.WheelIndicatorView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.translate(traslationX, traslationY);
    if (circleBackgroundPaint != null)
        canvas.drawCircle(wheelBoundsRectF.centerX(), wheelBoundsRectF.centerY(),
                wheelBoundsRectF.width() / 2 - itemsLineWidth, circleBackgroundPaint);
    canvas.drawArc(wheelBoundsRectF, ANGLE_INIT_OFFSET, 360, false, innerBackgroundCirclePaint);
    drawIndicatorItems("First", canvas);

    //        itemArcPaint.setColor(Color.parseColor("#FF9000"));
    //        canvas.drawArc((float)wheelBoundsRectF.centerX(), wheelBoundsRectF.centerY(),
    //                wheelBoundsRectF.width() / 2 - itemsLineWidth,false, itemArcPaint);
    drawIndicatorArc(canvas);// w  w w . ja  va2  s  .co m
    drawIndicatorItems("Second", canvas);

}

From source file:android.support.design.internal.ScrimInsetsFrameLayout.java

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

    int width = getWidth();
    int height = getHeight();
    if (mInsets != null && mInsetForeground != null) {
        int sc = canvas.save();
        canvas.translate(getScrollX(), getScrollY());

        // Top/*from   w w w.  j a v  a 2 s  .  co m*/
        mTempRect.set(0, 0, width, mInsets.top);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Bottom
        mTempRect.set(0, height - mInsets.bottom, width, height);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Left
        mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Right
        mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        canvas.restoreToCount(sc);
    }
}

From source file:ar.worq.microturistas.view.ScrimInsetsFrameLayout.java

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

    int width = getWidth();
    int height = getHeight();
    if (mInsets != null && mInsetForeground != null) {
        int sc = canvas.save();
        canvas.translate(getScrollX(), getScrollY());

        // Top/*from   w ww  .ja v  a2 s.  c om*/
        mTempRect.set(0, 0, width, mInsets.top);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Bottom
        mTempRect.set(0, height - mInsets.bottom, width, height);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Left
        mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        // Right
        mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
        mInsetForeground.setBounds(mTempRect);
        mInsetForeground.draw(canvas);

        canvas.restoreToCount(sc);
    }
}

From source file:br.com.leoleal.swipetorefresh.SwipeProgressBar.java

/**
 * Draws a circle centered in the view.//from  w w w  . java 2 s .c  om
 *
 * @param canvas the canvas to draw on
 * @param cx the center x coordinate
 * @param cy the center y coordinate
 * @param color the color to draw
 * @param pct the percentage of the view that the circle should cover
 */
private void drawCircle(Canvas canvas, float cx, float cy, int color, float pct) {
    mPaint.setColor(color);
    canvas.save();
    canvas.translate(cx, cy);
    float radiusScale = INTERPOLATOR.getInterpolation(pct);
    canvas.scale(radiusScale, radiusScale);
    canvas.drawCircle(0, 0, cx, mPaint);
    canvas.restore();
}

From source file:me.lizheng.deckview.helpers.FakeShadowDrawable.java

@Override
public void draw(Canvas canvas) {
    if (mDirty) {
        buildComponents(getBounds());//from   w ww.ja  v  a2s.com
        mDirty = false;
    }
    canvas.translate(0, mRawShadowSize / 4);
    drawShadow(canvas);
    canvas.translate(0, -mRawShadowSize / 4);
}

From source file:io.palaima.debugdrawer.view.ScrimInsetsFrameLayout.java

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

    int width = getWidth();
    int height = getHeight();
    if (insets != null && insetForeground != null) {
        int sc = canvas.save();
        canvas.translate(getScrollX(), getScrollY());

        // Top//from w  ww.  j av a2 s .  co m
        tempRect.set(0, 0, width, insets.top);
        insetForeground.setBounds(tempRect);
        insetForeground.draw(canvas);

        // Bottom
        tempRect.set(0, height - insets.bottom, width, height);
        insetForeground.setBounds(tempRect);
        insetForeground.draw(canvas);

        // Left
        tempRect.set(0, insets.top, insets.left, height - insets.bottom);
        insetForeground.setBounds(tempRect);
        insetForeground.draw(canvas);

        // Right
        tempRect.set(width - insets.right, insets.top, width, height - insets.bottom);
        insetForeground.setBounds(tempRect);
        insetForeground.draw(canvas);

        canvas.restoreToCount(sc);
    }
}

From source file:com.github.czy1121.view.CornerLabelView.java

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

    float xy = mHeight / SQRT2;
    canvas.save();// w w w.  ja  v  a2 s  . c om
    canvas.translate(xy, xy);
    canvas.rotate((mIsTop ? 1 : -1) * (mIsLeft ? -45 : 45));
    canvas.drawPath(calcPath(), mPaint);

    mText1.draw(canvas, mPaddingBottom, mIsTop);
    if (mIsTriangle) {
        mText2.draw(canvas, mPaddingBottom + mPaddingCenter + mText1.height, mIsTop);
    }
    canvas.restore();
}

From source file:ee.ioc.phon.android.speak.Utils.java

static Bitmap bytesToBitmap(byte[] byteBuffer, int w, int h, int startPosition, int endPosition) {
    final ShortBuffer waveBuffer = ByteBuffer.wrap(byteBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
    final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    final Canvas c = new Canvas(b);
    final Paint paint = new Paint();
    paint.setColor(0xFFFFFFFF); // 0xAARRGGBB
    paint.setAntiAlias(true);/*from  w  w  w. j ava 2  s . c o m*/
    paint.setStyle(Paint.Style.STROKE);
    paint.setAlpha(80);

    final PathEffect effect = new CornerPathEffect(3);
    paint.setPathEffect(effect);

    final int numSamples = waveBuffer.remaining();
    int endIndex;
    if (endPosition == 0) {
        endIndex = numSamples;
    } else {
        endIndex = Math.min(endPosition, numSamples);
    }

    int startIndex = startPosition - 2000; // include 250ms before speech
    if (startIndex < 0) {
        startIndex = 0;
    }
    final int numSamplePerWave = 200; // 8KHz 25ms = 200 samples
    final float scale = 10.0f / 65536.0f;

    final int count = (endIndex - startIndex) / numSamplePerWave;
    final float deltaX = 1.0f * w / count;
    int yMax = h / 2;
    Path path = new Path();
    c.translate(0, yMax);
    float x = 0;
    path.moveTo(x, 0);
    for (int i = 0; i < count; i++) {
        final int avabs = getAverageAbs(waveBuffer, startIndex, i, numSamplePerWave);
        int sign = ((i & 01) == 0) ? -1 : 1;
        final float y = Math.min(yMax, avabs * h * scale) * sign;
        path.lineTo(x, y);
        x += deltaX;
        path.lineTo(x, y);
    }
    if (deltaX > 4) {
        paint.setStrokeWidth(2);
    } else {
        paint.setStrokeWidth(Math.max(0, (int) (deltaX - .05)));
    }
    c.drawPath(path, paint);
    return b;
}

From source file:com.h6ah4i.android.widget.advrecyclerview.draggable.EdgeEffectDecorator.java

@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    boolean needsInvalidate = false;

    if (mTopGlow != null && !mTopGlow.isFinished()) {
        final int restore = c.save();
        if (getClipToPadding(parent)) {
            c.translate(parent.getPaddingLeft(), parent.getPaddingTop());
        }/*from  ww w  .  j  a va2s . c o m*/
        //noinspection ConstantConditions
        needsInvalidate |= mTopGlow.draw(c);
        c.restoreToCount(restore);
    }

    if (mBottomGlow != null && !mBottomGlow.isFinished()) {
        final int restore = c.save();
        c.rotate(180);
        if (getClipToPadding(parent)) {
            c.translate(-parent.getWidth() + parent.getPaddingRight(),
                    -parent.getHeight() + parent.getPaddingBottom());
        } else {
            c.translate(-parent.getWidth(), -parent.getHeight());
        }
        needsInvalidate |= mBottomGlow.draw(c);
        c.restoreToCount(restore);
    }

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

From source file:org.akvo.caddisfly.sensor.colorimetry.strip.widget.PercentageMeterView.java

@Override
public void onDraw(@NonNull Canvas canvas) {

    if (Float.isNaN(percentage)) {
        return;// w  w  w.j ava2s.  com
    }

    double number = (100 - percentage) * NUMBER_OF_BARS * PERCENT;

    canvas.save();

    // Set each dot's diameter to half the canvas height
    canvas.translate(
            canvas.getWidth() / 2f - ((canvas.getHeight() / 2f + GUTTER_SPACE) * ((NUMBER_OF_BARS - 1) / 2f)),
            0);

    for (double i = 0; i < NUMBER_OF_BARS; i++) {

        // Reset color
        paint.setColor(Color.LTGRAY);

        if (number >= 0) {
            if (i < 2) {
                // Red if number is lower than i + 1
                // 2 red dots if number < 1 or 1 red dot if number > 1
                if (number <= i + 1) {
                    paint.setColor(red);
                }
            } else if (i < 4) {
                // Orange if number between 1 and 4
                // if number == 1.5 then 1 red followed by orange dot
                // if number == 2.5 then 2 orange dots
                // if number == 3.5 then 1 orange dot
                if (number >= i - 1 && number <= i + 2) {
                    paint.setColor(orange);
                }
            } else {
                if (number > i) {
                    // Green if number larger than 3 but yellow if number exceeds optimum
                    if (number > NUMBER_OF_BARS) {
                        paint.setColor(Color.YELLOW);
                    } else {
                        paint.setColor(green);
                    }
                }
            }
        }

        canvas.drawCircle(0, canvas.getHeight() / 2f, canvas.getHeight() / 4f, paint);

        // Position next circle
        canvas.translate(canvas.getHeight() / 2f + GUTTER_SPACE, 0);
    }

    canvas.restore();

    super.onDraw(canvas);
}