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.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (layout != null) {
        canvas.translate(getPaddingLeft(), getPaddingTop());
        layout.draw(canvas);//from w  w  w  .  j  ava  2 s .co  m
    }
}

From source file:com.mikepenz.materialize.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());

        if (!mSystemUIVisible) {
            mInsets.top = 0;//from   www.  ja v a2 s  .  c om
            mInsets.right = 0;
            mInsets.bottom = 0;
            mInsets.left = 0;
        }

        // Top
        if (mTintStatusBar) {
            mTempRect.set(0, 0, width, mInsets.top);
            mInsetForeground.setBounds(mTempRect);
            mInsetForeground.draw(canvas);
        }

        // Bottom
        if (mTintNavigationBar) {
            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.khoai.bus.ui.IconGenerator.java

/**
 * Creates an icon with the current content and style.
 * <p/>//from   w  ww.jav  a  2 s  . co m
 * This method is useful if a custom view has previously been set, or if text content is not
 * applicable.
 */
public Bitmap makeIcon() {
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mContainer.measure(measureSpec, measureSpec);

    int measuredWidth = mContainer.getMeasuredWidth();
    int measuredHeight = mContainer.getMeasuredHeight();

    mContainer.layout(0, 0, measuredWidth, measuredHeight);

    if (mRotation == 1 || mRotation == 3) {
        measuredHeight = mContainer.getMeasuredWidth();
        measuredWidth = mContainer.getMeasuredHeight();
    }

    Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
    r.eraseColor(Color.TRANSPARENT);

    Canvas canvas = new Canvas(r);

    if (mRotation == 0) {
        // do nothing
    } else if (mRotation == 1) {
        canvas.translate(measuredWidth, 0);
        canvas.rotate(90);
    } else if (mRotation == 2) {
        canvas.rotate(180, measuredWidth / 2, measuredHeight / 2);
    } else {
        canvas.translate(0, measuredHeight);
        canvas.rotate(270);
    }
    mContainer.draw(canvas);
    return r;
}

From source file:org.cnc.mombot.utils.ContactsEditText.java

private Object convertViewToDrawable(View view) {
    BitmapDrawable bd = null;/*ww w.j ava2 s  .co m*/
    try {
        int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        view.measure(spec, spec);
        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
        Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.translate(-view.getScrollX(), -view.getScrollY());
        view.draw(canvas);
        bd = new BitmapDrawable(getContext().getResources(), bitmap);
        bd.setBounds(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    } catch (Exception ex) {
    }
    return bd;
}

From source file:com.ickphum.android.isoview.IsoCanvas.java

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

    canvas.translate(-mOriginX, -mOriginY);

    for (int x = 0; x < 100; x++) {
        for (int y = 0; y < 100; y++) {
            canvas.save();// w  w w  .  ja  v a2s .com
            canvas.translate(-x * 7, -y * 7);
            canvas.drawPath(mPaths[0], mPaints[0]);
            //canvas.drawRect(0.0f, 0.0f, 5.0f, 5.0f, mPaints[0]);
            canvas.restore();
        }
    }

    canvas.drawLine(mContentRect.left, mContentRect.top, mContentRect.right, mContentRect.bottom,
            mBackgroundLinePaint);
    canvas.drawLine(mContentRect.left, mContentRect.bottom, mContentRect.right, mContentRect.top,
            mBackgroundLinePaint);

    for (int x = -1000; x < 1000; x += 200) {
        for (int y = -1000; y < 1000; y += 200) {
            canvas.drawText(x + "," + y, x, y, mBackgroundLinePaint);
        }
    }
}

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

@Override
protected void onDraw(Canvas canvas) {
    int x = (canvas.getWidth() - width) / 2;
    int y = AndroidUtilities.dp(4);
    Theme.backgroundMediaDrawableIn.setBounds(x, y, width + x, height + y);
    Theme.backgroundMediaDrawableIn.draw(canvas);
    canvas.save();// ww w . j  a v  a2  s  . c om
    canvas.translate(textX = AndroidUtilities.dp(2 + 9) + x, textY = AndroidUtilities.dp(2 + 9) + y);
    if (pressedLink != null) {
        canvas.drawPath(urlPath, urlPaint);
    }
    if (textLayout != null) {
        textLayout.draw(canvas);
    }
    canvas.restore();
}

From source file:com.umeng.comm.ui.imagepicker.widgets.ViewPagerIndicator.java

/**
 * /*  www .j av a2s .  c o m*/
 */
@Override
protected void dispatchDraw(Canvas canvas) {
    canvas.save();
    // ?
    canvas.translate(mInitTranslationX + mTranslationX, getHeight() + 5);
    canvas.drawPath(mPath, mPaint);
    canvas.restore();

    // tab
    canvas.drawLine(mTranslationX, getHeight() - 3, mTranslationX + mHalfScreenWidth, getHeight() - 3,
            mLinePaint);
    // 
    canvas.drawLine(0, getHeight() - 1, 2 * mHalfScreenWidth, getHeight() - 1, mDividerLinePaint);
    super.dispatchDraw(canvas);
}

From source file:com.yanzhenjie.recyclerview.swipe.widget.StickyNestedScrollView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (currentlyStickingView != null) {
        canvas.save();/*from ww w.  j  a v  a  2 s  . c  om*/
        canvas.translate(getPaddingLeft() + stickyViewLeftOffset,
                getScrollY() + stickyViewTopOffset + (clippingToPadding ? getPaddingTop() : 0));
        canvas.clipRect(0, (clippingToPadding ? -stickyViewTopOffset : 0), getWidth() - stickyViewLeftOffset,
                currentlyStickingView.getHeight() + mShadowHeight + 1);
        if (mShadowDrawable != null) {
            int left = 0;
            int top = currentlyStickingView.getHeight();
            int right = currentlyStickingView.getWidth();
            int bottom = currentlyStickingView.getHeight() + mShadowHeight;
            mShadowDrawable.setBounds(left, top, right, bottom);
            mShadowDrawable.draw(canvas);
        }
        canvas.clipRect(0, (clippingToPadding ? -stickyViewTopOffset : 0), getWidth(),
                currentlyStickingView.getHeight());
        if (getStringTagForView(currentlyStickingView).contains(FLAG_HASTRANSPARENCY)) {
            showView(currentlyStickingView);
            currentlyStickingView.draw(canvas);
            hideView(currentlyStickingView);
        } else {
            currentlyStickingView.draw(canvas);
        }
        canvas.restore();
    }
}

From source file:org.wikipedia.page.shareafact.SnippetImage.java

private static int drawDescription(@NonNull Canvas canvas, @Nullable String description, int top,
        boolean isArticleRTL) {
    final int marginBottom = 5;
    final int maxHeight = 23;
    final int maxLines = 2;
    final float maxFontSize = 15.0f;
    final float minFontSize = 10.0f;

    if (TextUtils.isEmpty(description)) {
        return top - marginBottom;
    }/*from  www  . ja  v  a2s  .c  om*/
    TextPaint textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(maxFontSize);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setShadowLayer(1.0f, 0.0f, 0.0f, Color.GRAY);

    StaticLayout textLayout = optimizeTextSize(
            new TextLayoutParams(description, textPaint, DESCRIPTION_WIDTH, SPACING_MULTIPLIER), maxHeight,
            maxLines, maxFontSize, minFontSize);
    int left = HORIZONTAL_PADDING;
    if (isArticleRTL) {
        left = WIDTH - HORIZONTAL_PADDING - textLayout.getWidth();
    }

    top = top - marginBottom - textLayout.getHeight();
    canvas.save();
    canvas.translate(left, top);
    textLayout.draw(canvas);
    canvas.restore();

    return top;
}

From source file:com.simplecity.amp_library.ui.views.ScrimInsetsFrameLayout.java

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

    //Don't do anything special if we're not allowed to tint the status bar
    if (!ShuttleUtils.hasKitKat()) {
        return;// w w w  .j ava  2 s  . c o m
    }

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

        // Top
        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);
    }
}