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.dlazaro66.wheelindicatorview.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(canvas);// ww w .jav a 2 s  . c om
}

From source file:com.fastaccess.tfl.ui.widget.drag.DragView.java

@Override
protected void onDraw(Canvas canvas) {
    float scale = mAnimationScale;
    if (scale < 0.999f) {
        float width = mBitmap.getWidth();
        float offset = (width - (width * scale)) / 2;
        canvas.translate(offset, offset);
        canvas.scale(scale, scale);/*from  w  ww  .ja  v a 2 s  .  co m*/
    }
    canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint);
}

From source file:com.hippo.nimingban.widget.BottomShadowScrollView.java

@Override
protected void dispatchDraw(@NonNull Canvas canvas) {
    super.dispatchDraw(canvas);
    mShadowDrawable.setBounds(0, 0, getWidth(), mShadowHeight);
    int saved = canvas.save();
    int height = getChildCount() != 0 ? Math.max(getChildAt(0).getHeight(), getHeight()) : getHeight();
    canvas.translate(0, height - mShadowHeight);
    mShadowDrawable.draw(canvas);// w w  w  .j a  v a  2  s .  c  o m
    canvas.restoreToCount(saved);
}

From source file:im.ene.ribbon.FixedActionTabView.java

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

    canvas.save();/*  w w w .j a v a 2  s  .co  m*/
    canvas.translate(0, iconTranslation);
    icon.draw(canvas);
    drawBadge(canvas);
    canvas.restore();

    canvas.save();
    canvas.scale(canvasTextScale, canvasTextScale, textCenterX, textCenterY);
    canvas.drawText(getAction().getTitle(), textX, textY, textPaint);
    canvas.restore();
}

From source file:at.linuxtage.companion.widgets.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//w  w w  .j a va  2  s  .c o 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:org.wikipedia.page.shareafact.SnippetImage.java

@NonNull
private static Layout drawTextSnippet(@NonNull Canvas canvas, @NonNull CharSequence textSnippet) {
    final int top = TOP_PADDING;
    final int maxHeight = 225;
    final int maxLines = 5;
    final float maxFontSize = 195.0f;
    final float minFontSize = 32.0f;

    TextPaint textPaint = new TextPaint();
    textPaint.setAntiAlias(true);// w  ww.  j  a  v a 2  s .c  o m
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(maxFontSize);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);
    textPaint.setShadowLayer(1.0f, 1.0f, 1.0f, Color.GRAY);

    StaticLayout textLayout = optimizeTextSize(
            new TextLayoutParams(textSnippet, textPaint, TEXT_WIDTH, SPACING_MULTIPLIER), maxHeight, maxLines,
            maxFontSize, minFontSize);

    canvas.save();
    int horizontalCenterOffset = top + (maxHeight - textLayout.getHeight()) / QUARTER;
    canvas.translate(HORIZONTAL_PADDING, horizontalCenterOffset);
    textLayout.draw(canvas);
    canvas.restore();

    return textLayout;
}

From source file:net.yanzm.actionbarprogress.MaterialIndeterminateProgressDrawable.java

@Override
public void draw(Canvas canvas) {
    final int level = getLevel();
    final float input = level / 10000f;

    canvas.drawColor(trackColor);/*from ww  w  . j a  va  2  s .  co  m*/

    canvas.save();
    canvas.translate(canvas.getWidth() / 2f, 0);
    canvas.scale(canvas.getWidth() / 360f, 1);

    paint.setColor(accentColor);

    {
        final int saveCount = canvas.save();

        float translateX2 = translateInterpolator2.getInterpolation(input);
        canvas.translate(-197.60001f + translateX2 * 620.20002f, 0);

        float x = scaleInterpolator2.getInterpolation(input);
        float scaleX = 1.6199005127f * -Math.abs(x - 0.5f) + 0.909950256348f;
        rect2.set(-144f * scaleX, 0, 144f * scaleX, canvas.getHeight());
        canvas.drawRect(rect2, paint);

        canvas.restoreToCount(saveCount);
    }
    {
        final int saveCount = canvas.save();

        float translateX1 = translateInterpolator1.getInterpolation(input);
        canvas.translate(-522.59998f + translateX1 * 722.19999f, 0);

        float x = scaleInterpolator1.getInterpolation(input);
        float scaleX = 1.45369842529f * -Math.abs(x - 0.5f) + 0.826849212646f;
        rect1.set(-144f * scaleX, 0, 144f * scaleX, canvas.getHeight());
        canvas.drawRect(rect1, paint);

        canvas.restoreToCount(saveCount);
    }

    canvas.restore();
}

From source file:com.mobidev.myliveonavigationmaterial.ui.widget.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//w ww  .  j  ava  2 s.com
        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:com.appeaser.sublimenavigationviewlibrary.ScrimInsetsFrameLayout.java

public void draw(@NonNull Canvas canvas) {
    super.draw(canvas);
    int width = this.getWidth();
    int height = this.getHeight();
    if (mInsets != null && mInsetForeground != null) {
        int sc = canvas.save();
        canvas.translate(getScrollX(), getScrollY());

        this.mTempRect.set(0, 0, width, this.mInsets.top);
        this.mInsetForeground.setBounds(this.mTempRect);
        this.mInsetForeground.draw(canvas);

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

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

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

        canvas.restoreToCount(sc);/*from  w  ww. j a  v  a 2  s  . c o m*/
    }
}

From source file:com.holmes.ponderosa.ui.debug.NonConsumingScrimInsetsFrameLayout.java

@Override
public void draw(@NonNull 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/*w w  w.ja  va  2 s.c  o  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);
    }
}