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.appsimobile.appsii.module.home.SunriseDrawable.java

private void drawSun(Canvas canvas, float pct) {

    // Draw the dots
    canvas.drawCircle(mBezier1x, mBezier1y, mDotRadius, mDotPaint);
    canvas.drawCircle(mBezier4x, mBezier4y, mDotRadius, mDotPaint);

    // calculate the center point of the sun image
    float x = bezierInterpolation(pct, mBezier1x, mBezier2x, mBezier3x, mBezier4x);
    float y = bezierInterpolation(pct, mBezier1y, mBezier2y, mBezier3y, mBezier4y);

    Rect sunBounds = mSunImage.getBounds();

    x -= sunBounds.width() / 2;/*from   www .  j  ava 2s.  c  o m*/
    y -= sunBounds.height() / 2;

    // if we are in rtl, we still want to show the image normally
    // so flip it back
    canvas.translate(x, y);
    if (mIsRtl) {
        canvas.save();
        canvas.scale(-1, 1, sunBounds.centerX(), sunBounds.centerY());
    }
    // draw the sun image
    mSunImage.draw(canvas);
    // restore the flip again
    if (mIsRtl) {
        canvas.restore();
    }
    canvas.translate(-x, -y);

}

From source file:com.ssn.currency.convertor.WheelView.java

/**
 * Draws items//from w  w  w  .  java 2 s  .  c  o m
 * @param canvas the canvas for drawing
 */
private void drawItems(Canvas canvas) {
    canvas.save();

    int top = (currentItem - firstItem) * getItemHeight() + (getItemHeight() - getHeight()) / 2;
    canvas.translate(PADDING, -top + scrollingOffset);

    itemsLayout.draw(canvas);

    canvas.restore();
}

From source file:com.example.view.wheel.WheelView.java

/**
 * Draws items/*from   ww  w .  j a  v a2s  . c o  m*/
 * @param canvas the canvas for drawing
 */
private void drawItems(Canvas canvas) {
    canvas.save();

    int top = itemsLayout.getLineTop(1);
    canvas.translate(0, -top + scrollingOffset);

    itemsPaint.setColor(ITEMS_TEXT_COLOR);
    itemsPaint.drawableState = getDrawableState();
    itemsLayout.draw(canvas);

    canvas.restore();
}

From source file:org.goodev.helpviewpager.CirclePageIndicator.java

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

    if (mViewPager == null) {
        return;/*from w  ww  .j av  a 2 s . co m*/
    }
    final int count = getCount();
    if (count == 0) {
        return;
    }

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        return;
    }
    if (mCurrentPage == count - 1) {
        canvas.translate(-mCurrentOffset, 0);
    }
    int longSize;
    int longPaddingBefore;
    int longPaddingAfter;
    int shortPaddingBefore;
    if (mOrientation == HORIZONTAL) {
        longSize = getWidth();
        longPaddingBefore = getPaddingLeft();
        longPaddingAfter = getPaddingRight();
        shortPaddingBefore = getPaddingTop();
    } else {
        longSize = getHeight();
        longPaddingBefore = getPaddingTop();
        longPaddingAfter = getPaddingBottom();
        shortPaddingBefore = getPaddingLeft();
    }

    final float threeRadius = mRadius * 3;
    final float shortOffset = shortPaddingBefore + mRadius;
    float longOffset = longPaddingBefore + mRadius;
    if (mCentered) {
        longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f)
                - ((count * threeRadius) / 2.0f);
    }

    float dX;
    float dY;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //Draw stroked circles
    for (int iLoop = 0; iLoop < count; iLoop++) {
        float drawLong = longOffset + (iLoop * threeRadius);
        if (mOrientation == HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
    }

    //Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius;
    if (!mSnap && (mPageSize != 0) && (mCurrentPage != count - 1)) {
        cx += (mCurrentOffset * 1.0f / mPageSize) * threeRadius;
    }
    if (mOrientation == HORIZONTAL) {
        dX = longOffset + cx;
        dY = shortOffset;
    } else {
        dX = shortOffset;
        dY = longOffset + cx;
    }
    canvas.drawCircle(dX, dY, mRadius, mPaintFill);
    if (mCurrentPage == count - 1) {
        canvas.translate(mCurrentOffset, 0);
    }
}

From source file:com.cssweb.android.view.FinanceMini.java

public void drawHKIndex(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*  w w  w  .ja va2s  . c  om*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width, -DY * 3);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(String.valueOf(jo.getInt("zj")), x - tips, y, paint);

            paint.setColor(GlobalColor.colorPriceEqual);
            canvas.translate(0, DY);
            canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint);

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint);

        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.swipeable.RemovingItemDecorator.java

private void fillSwipingItemBackground(Canvas c, Drawable drawable, float scale) {
    final Rect bounds = mSwipingItemBounds;
    final int translationX = mTranslationX;
    final int translationY = mTranslationY;
    final float hScale = (mHorizontal) ? 1.0f : scale;
    final float vScale = (mHorizontal) ? scale : 1.0f;

    int width = (int) (hScale * bounds.width() + 0.5f);
    int height = (int) (vScale * bounds.height() + 0.5f);

    if ((height == 0) || (width == 0) || (drawable == null)) {
        return;//from   w  w w  .  ja  v  a  2  s. c  o m
    }

    final int savedCount = c.save();

    c.clipRect(bounds.left + translationX, bounds.top + translationY, bounds.left + translationX + width,
            bounds.top + translationY + height);

    // c.drawColor(0xffff0000); // <-- debug

    c.translate(bounds.left + translationX - (bounds.width() - width) / 2,
            bounds.top + translationY - (bounds.height() - height) / 2);
    drawable.setBounds(0, 0, bounds.width(), bounds.height());

    drawable.draw(c);

    c.restoreToCount(savedCount);
}

From source file:android.support.v7.widget.FastScroller.java

private void drawVerticalScrollbar(Canvas canvas) {
    int viewWidth = mRecyclerViewWidth;

    int left = viewWidth - mVerticalThumbWidth;
    int top = mVerticalThumbCenterY - mVerticalThumbHeight / 2;
    mVerticalThumbDrawable.setBounds(0, 0, mVerticalThumbWidth, mVerticalThumbHeight);
    mVerticalTrackDrawable.setBounds(0, 0, mVerticalTrackWidth, mRecyclerViewHeight);

    if (isLayoutRTL()) {
        mVerticalTrackDrawable.draw(canvas);
        canvas.translate(mVerticalThumbWidth, top);
        canvas.scale(-1, 1);/*from  w  w  w  . j a v  a  2  s .c om*/
        mVerticalThumbDrawable.draw(canvas);
        canvas.scale(1, 1);
        canvas.translate(-mVerticalThumbWidth, -top);
    } else {
        canvas.translate(left, 0);
        mVerticalTrackDrawable.draw(canvas);
        canvas.translate(0, top);
        mVerticalThumbDrawable.draw(canvas);
        canvas.translate(-left, -top);
    }
}

From source file:com.triggertrap.seekarc.SeekArc.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mClockwise) {
        canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
    }/*ww w  .j  a v  a2 s  . c  o m*/

    // Draw the arcs
    final int arcStart = mStartAngle + mAngleOffset + mRotation;
    final int arcSweep = mSweepAngle;
    canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint);
    canvas.drawArc(mArcRect, arcStart, mProgressSweep, false, mProgressPaint);

    if (mEnabled) {
        // Draw the thumb nail
        canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos);
        mThumb.draw(canvas);
    }
}

From source file:it.ndorigatti.android.view.MulticolorProgressBar.java

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

    Drawable d = mCurrentDrawable;//from  w w w  .  j  a va  2 s .co  m
    if (d != null) {
        // Translate canvas so a indeterminate circular progress bar with padding
        // rotates properly in its animation
        canvas.save();
        canvas.translate(getPaddingLeft(), getPaddingTop());
        d.draw(canvas);
        canvas.restore();
    }
}

From source file:com.cssweb.android.view.FinanceMini.java

public void drawIndex(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//www. j a v a 2 s  .  co  m
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("???", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width, -DY * 5);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x, y, paint);

        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}