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:app.philm.in.view.BackdropImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mOffset != 0) {
        canvas.save();/* w ww  . j  a  v a  2  s  .c  o  m*/
        canvas.translate(0f, mOffset);
        canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + mOffset);
        super.onDraw(canvas);
        canvas.restore();
    } else {
        super.onDraw(canvas);
    }
}

From source file:me.henrytao.mdcore.widgets.internal.MdCheckBox.java

@Override
protected void onDraw(Canvas canvas) {
    if (isLayoutRtl()) {
        canvas.translate(-mPaddingRight, 0);
    } else {/*from w w  w.j a  v  a 2 s . c  o  m*/
        canvas.translate(mPaddingLeft, 0);
    }
    super.onDraw(canvas);
    Drawable background = getBackground();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && background != null) {
        boolean isLayoutRtl = isLayoutRtl();
        Rect bounds = background.getBounds();
        int top = bounds.top;
        int bottom = bounds.bottom;
        int left = (isLayoutRtl ? getWidth() - mMinWidth : 0)
                + (!mHasCustomDrawable && !isLayoutRtl ? mPaddingLeft : 0);
        int right = (isLayoutRtl ? getWidth() : mMinWidth)
                - (!mHasCustomDrawable && isLayoutRtl ? mPaddingRight : 0);
        background.setHotspotBounds(left, top, right, bottom);
    }
}

From source file:com.google.android.marvin.utils.HighlightBoundsView.java

@Override
public void onDraw(Canvas c) {
    final int saveCount = c.save();
    c.translate(-SCREEN_LOCATION[0], -SCREEN_LOCATION[1]);
    c.setMatrix(mMatrix);/*from ww w.  ja v  a2s  .  c  om*/

    mPaint.setColor(mHighlightColor);

    for (AccessibilityNodeInfoCompat node : mNodes) {
        node.getBoundsInScreen(mTemp);
        c.drawRect(mTemp, mPaint);
    }

    c.restoreToCount(saveCount);
}

From source file:com.dbeginc.dbweather.utils.animations.widgets.RainFallView.java

@Override
protected void onDraw(Canvas canvas) {
    for (int i = 0; i < mRainFlakeCount; i++) {
        Drawable drawable = drawables.get(i);
        canvas.save();//ww w. j  a v a 2 s.c  o m
        canvas.translate(coords[i][0], coords[i][1]);
        drawable.draw(canvas);
        canvas.restore();
    }
    invalidate();
}

From source file:com.dbeginc.dbweather.utils.animations.widgets.SnowFallView.java

@Override
protected void onDraw(Canvas canvas) {
    for (int i = 0; i < snow_flake_count; i++) {
        Drawable drawable = drawables.get(i);
        canvas.save();/*  w w  w  .  j  ava2s  .  co m*/
        canvas.translate(coords[i][0], coords[i][1]);
        drawable.draw(canvas);
        canvas.restore();
    }
    invalidate();
}

From source file:com.arbo.gaogao.widget.MyParallaxScrimageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (imageOffset != 0) {
        canvas.save();//w  w  w .j  a  v a 2  s  .  c o m
        canvas.translate(0f, imageOffset);
        canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset);
        super.onDraw(canvas);
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
        canvas.restore();
    } else {
        super.onDraw(canvas);
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
    }
}

From source file:com.lovejjfg.zhifou.ui.widget.ParallaxScrimageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (imageOffset != 0) {
        canvas.save();/*w  ww . ja  v  a  2  s.c o m*/
        canvas.translate(0f, imageOffset);
        Log.i("imageOffset", "onDraw: " + imageOffset);
        canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset);
        super.onDraw(canvas);
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
        canvas.restore();
    } else {
        super.onDraw(canvas);
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
    }
}

From source file:org.telegram.ui.Cells.AboutLinkCell.java

@Override
protected void onDraw(Canvas canvas) {
    canvas.save();/*from w w  w . ja v a  2s .c o m*/
    canvas.translate(textX = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 71),
            textY = AndroidUtilities.dp(8));
    if (pressedLink != null) {
        canvas.drawPath(urlPath, urlPaint);
    }
    try {
        if (textLayout != null) {
            textLayout.draw(canvas);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    canvas.restore();
}

From source file:com.sinenco.sharednews.listviewremovalanimation.BackgroundContainer.java

@Override
protected void onDraw(Canvas canvas) {
    if (mShowing) {
        if (mUpdateBounds) {
            mShadowedBackground.setBounds(0, 0, getWidth(), mOpenAreaHeight);
        }//from w  w  w .  ja va2 s.c  o m
        canvas.save();
        canvas.translate(0, mOpenAreaTop);
        mShadowedBackground.draw(canvas);
        canvas.restore();
    }
}

From source file:Main.java

public static boolean drawDrawables(Canvas canvas, @Nonnull TextView textView) {
    final int compoundPaddingLeft = textView.getCompoundPaddingLeft();
    final int compoundPaddingTop = textView.getCompoundPaddingTop();
    final int compoundPaddingRight = textView.getCompoundPaddingRight();
    final int compoundPaddingBottom = textView.getCompoundPaddingBottom();

    final int scrollX = textView.getScrollX();
    final int scrollY = textView.getScrollY();

    final int right = textView.getRight();
    final int left = textView.getLeft();
    final int bottom = textView.getBottom();
    final int top = textView.getTop();

    final Drawable[] drawables = textView.getCompoundDrawables();
    if (drawables != null) {

        int vspace = bottom - top - compoundPaddingBottom - compoundPaddingTop;
        int hspace = right - left - compoundPaddingRight - compoundPaddingLeft;

        Drawable topDr = drawables[1];//from w  w  w  .j  a  v  a 2 s  . co m
        // IMPORTANT: The coordinates computed are also used in invalidateDrawable()
        // Make sure to update invalidateDrawable() when changing this code.
        if (topDr != null) {
            canvas.save();
            canvas.translate(scrollX + compoundPaddingLeft + (hspace - topDr.getBounds().width()) / 2,
                    scrollY + textView.getPaddingTop() + vspace / 2);
            topDr.draw(canvas);
            canvas.restore();
            return true;
        }
    }

    return false;
}