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.taobao.weex.ui.view.WXScrollView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (mCurrentStickyView != null) {
        canvas.save();//from  w w w.  ja  va  2 s  .  c  o  m
        mCurrentStickyView.getLocationOnScreen(mStickyP);
        int realOffset = (mStickyOffset <= 0 ? mStickyOffset : 0);
        canvas.translate(mStickyP[0], getScrollY() + realOffset);
        canvas.clipRect(0, realOffset, mCurrentStickyView.getWidth(), mCurrentStickyView.getHeight());
        mCurrentStickyView.draw(canvas);
        canvas.restore();
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.draggable.DraggingItemDecorator.java

private Bitmap createDraggingItemImage(View v, NinePatchDrawable shadow) {
    int width = v.getWidth() + mShadowPadding.left + mShadowPadding.right;
    int height = v.getHeight() + mShadowPadding.top + mShadowPadding.bottom;

    final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    final Canvas canvas = new Canvas(bitmap);

    if (shadow != null) {
        shadow.setBounds(0, 0, width, height);
        shadow.draw(canvas);//from   w ww  .  j  ava  2 s.  c  o m
    }

    final int savedCount = canvas.save(Canvas.CLIP_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG);
    // NOTE: Explicitly set clipping rect. This is required on Gingerbread.
    canvas.clipRect(mShadowPadding.left, mShadowPadding.top, width - mShadowPadding.right,
            height - mShadowPadding.bottom);
    canvas.translate(mShadowPadding.left, mShadowPadding.top);
    v.draw(canvas);
    canvas.restoreToCount(savedCount);

    return bitmap;
}

From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java

/**
 * Tab//from  w  w w  .j ava  2s.  c  om
 * 
 * @param canvas
 */
private void drawTabBG(Canvas canvas) {
    if (showTabColor) {
        mTextPaint.setColor(tabColorNormal);
        canvas.save();
        canvas.translate(getPaddingLeft(), 0);
        if (tabs.size() > 0)
            for (int i = 0; i < tabs.size(); i++) {
                if (i == nextPager) {
                    mTextPaint.setColor(getColor(tabColorNormal, tabColorSelected, textSizeOffset));
                } else if (i == currectPager) {
                    mTextPaint.setColor(getColor(tabColorNormal, tabColorSelected, 1 - textSizeOffset));
                } else {
                    mTextPaint.setColor(tabColorNormal);
                }
                canvas.drawRect(0, getPaddingTop(), itemWidth, getHeight() - getPaddingBottom(), mTextPaint);
                canvas.translate(itemWidth + intervalWidth, 0);
            }
        else {
            mTextPaint.setColor(tabColorSelected);
            canvas.drawRect(0, getPaddingTop(), itemWidth + intervalWidth + getPaddingLeft(),
                    getHeight() - getPaddingBottom(), mTextPaint);
        }
        canvas.restore();
    }
}

From source file:com.example.brendan.learningandroid2.SeekArc.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mClockwise) {
        canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
    }//from ww w.  java  2s. c  om

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

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

From source file:com.kadavelil.jossy.mapalarm.SeekArc.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mClockwise) {
        canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
    }/* w  w  w  . j  a v a 2s  .  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);

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

From source file:com.acbelter.scheduleview.ScheduleView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    changeClipRect(canvas);//  ww w. j a v a  2s.com

    canvas.save();
    canvas.translate(getPaddingLeft(), mListY + mInternalPaddingTop + getPaddingTop());
    ViewHolder holder = (ViewHolder) mTimeMark.getTag();
    for (int i = 0; i < mTimeMarks.size(); i++) {
        holder.time.setText(mTimeMarks.get(i));
        mTimeMark.layout(0, 0, mTimeMark.getMeasuredWidth(), mTimeMark.getMeasuredHeight());
        mTimeMark.draw(canvas);

        if (i != mTimeMarks.size() - 1) {
            canvas.translate(0, mTimeMarkHeight + mTimeMarksDistance);
        }
    }
    canvas.restore();

    drawEdgeEffects(canvas);
}

From source file:com.shizhefei.view.coolrefreshview.header.JellyHeader.java

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

    int totalDistance = totalDistance();
    int headerHeight;
    int pullHeight;
    int offsetToKeepHeaderWhileLoading = offsetToKeepHeaderWhileLoading();
    if (status == CoolRefreshView.PULL_STATUS_REFRESHING) {
        headerHeight = offsetToKeepHeaderWhileLoading;
        pullHeight = currentDistance;//from   w  ww  . java 2 s. co m
    } else {
        headerHeight = Math.min(currentDistance / 2, offsetToKeepHeaderWhileLoading);
        pullHeight = currentDistance;
    }
    if (headerHeight == 0) {
        return;
    }

    int saveCount = canvas.save();
    canvas.translate(0, totalDistance - currentDistance);

    final int width = canvas.getWidth();
    //??touchx ????touchx??
    mPointX = width / 2;

    final float mDisplayX = (mPointX - width / 2f) * 0.5f + width / 2f;
    mPaint.setColor(mColor);

    mPath.rewind();
    // ?
    mPath.moveTo(0, 0);
    mPath.lineTo(0, headerHeight);
    // ???
    mPath.quadTo(mDisplayX, pullHeight, width, headerHeight);
    mPath.lineTo(width, 0);
    mPath.close();
    canvas.drawPath(mPath, mPaint);
    canvas.restoreToCount(saveCount);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setOutlineProvider(mViewOutlineProvider);
    }
}

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

private void drawHorizontalScrollbar(Canvas canvas) {
    int viewHeight = mRecyclerViewHeight;

    int top = viewHeight - mHorizontalThumbHeight;
    int left = mHorizontalThumbCenterX - mHorizontalThumbWidth / 2;
    mHorizontalThumbDrawable.setBounds(0, 0, mHorizontalThumbWidth, mHorizontalThumbHeight);
    mHorizontalTrackDrawable.setBounds(0, 0, mRecyclerViewWidth, mHorizontalTrackHeight);

    canvas.translate(0, top);
    mHorizontalTrackDrawable.draw(canvas);
    canvas.translate(left, 0);//from   w  w w.  j a  v a  2 s. c o  m
    mHorizontalThumbDrawable.draw(canvas);
    canvas.translate(-left, -top);
}

From source file:com.ttxgps.zoom.GestureImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (layout) {
        if (drawable != null && !isRecycled()) {
            canvas.save();//  w w  w.  j a  v  a 2s  .c  o m

            float adjustedScale = scale * scaleAdjust;

            canvas.translate(x, y);

            if (rotation != 0.0f) {
                canvas.rotate(rotation);
            }

            if (adjustedScale != 1.0f) {
                canvas.scale(adjustedScale, adjustedScale);
            }

            drawable.draw(canvas);

            canvas.restore();
        }

        if (drawLock.availablePermits() <= 0) {
            drawLock.release();
        }
    }
}

From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java

@Override
protected void onDraw(Canvas canvas) {
    final int paddingLeft = getPaddingLeft();
    final int paddingTop = getPaddingTop();
    canvas.translate(paddingLeft, paddingTop);

    drawMonth(canvas);/*from   w  w  w  .j  a va2  s.c  o  m*/
    drawDaysOfWeek(canvas);
    drawDays(canvas);

    canvas.translate(-paddingLeft, -paddingTop);
}