Example usage for android.graphics Canvas drawPath

List of usage examples for android.graphics Canvas drawPath

Introduction

In this page you can find the example usage for android.graphics Canvas drawPath.

Prototype

public void drawPath(@NonNull Path path, @NonNull Paint paint) 

Source Link

Document

Draw the specified path using the specified paint.

Usage

From source file:com.hobby.uiframework.widget.PagerSlidingTab.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//w w w.  j  a v a2s .  c o  m
    }

    final int height = getHeight();

    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw indicator line
    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates
    // between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }
    if (lineIndicator) {
        canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    } else {
        rectPaint.setStyle(Style.FILL);
        Path path = new Path();
        float mid = (lineLeft + lineRight) * 0.5f;
        float triangleheight = getContext().getResources().getDimension(R.dimen.indicator_triangle_height);
        float left = mid - triangleheight;
        float right = mid + triangleheight;
        path.moveTo(left, height);
        path.lineTo(mid, height - triangleheight);
        path.lineTo(right, height);
        path.close();
        canvas.drawPath(path, rectPaint);
    }

    // draw divider
    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.bob.googleplay.view.PagerSlidingTriangleStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/* w ww.j  av a  2  s.  co m*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates
    // between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    // 
    // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight,
    // height, rectPaint);

    // -->
    float x1 = (lineRight - lineLeft) / 2 + lineLeft;
    float y1 = height - indicatorHeight;

    float x2 = x1 - triangleWidth / 2f;
    float y2 = height;

    float x3 = x1 + triangleWidth / 2f;
    float y3 = height;

    Path path = new Path();
    path.moveTo(x1, y1);// 
    path.lineTo(x2, y2);// 
    path.lineTo(x3, y3);// 
    path.lineTo(x1, y1);// 

    //      rectPaint.setStyle(Style.STROKE);
    //      rectPaint.setStrokeWidth(width)
    canvas.drawPath(path, rectPaint);

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.chj.indicator.lib.TriangleSlidingIndicator.java

/**
 * //from  w ww.j a  v  a2 s  .c om
 */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates
    // between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    // 
    // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight,
    // height, rectPaint);

    float left = lineLeft;
    float top = height - indicatorHeight;
    float right = lineRight;
    float bottom = height;

    // TODO:
    Path path = new Path();
    float x1 = (right - left) / 2 + left;// :(right+left)/2
    float y1 = top;

    float x2 = x1 - triangleWidth / 2;
    float y2 = bottom;

    float x3 = x1 + triangleWidth / 2;
    float y3 = bottom;
    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x1, y1);
    path.close();

    rectPaint.setColor(Color.RED);// ?

    canvas.drawPath(path, rectPaint);

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.tomeokin.widget.jotablayout2.JoTabLayout.java

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

    // draw underline
    if (mUnderlineHeight > 0) {
        mUnderlinePaint.setColor(mUnderlineColor);

        // ? GRAVITY_BOTTOM
        // getMeasuredHeight  view 
        // getHeight ? android:clipToPadding="true" getHeight()

        if (mUnderlineGravity == GRAVITY_BOTTOM) {
            canvas.drawRect(getPaddingLeft(), getHeight() - mUnderlineHeight, getWidth() + getPaddingLeft(),
                    getHeight(), mUnderlinePaint);
        } else {//from www. j  av  a 2s  .  com
            canvas.drawRect(getPaddingLeft(), 0, getWidth() + getPaddingLeft(), mUnderlineHeight,
                    mUnderlinePaint);
        }
    }

    // draw divider
    if (mDividerWidth > 0) {
        mDividerPaint.setStrokeWidth(mDividerWidth);
        mDividerPaint.setColor(mDividerColor);
        View tab;
        for (int i = 0; i < mTabCount - 1; i++) {
            tab = getChildAt(i);
            canvas.drawLine(getPaddingLeft() + tab.getRight(), mDividerVerticalPadding,
                    getPaddingLeft() + tab.getRight(), getHeight() - mDividerVerticalPadding, mDividerPaint);
        }
    }

    calIndicatorRect();
    mIndicatorRect.left += mIndicatorAnimOffset;
    mIndicatorRect.right = mIndicatorRect.left + (int) mIndicatorWidth;

    if (mIndicatorShape != SHAPE_NONE) {
        if (mIndicatorShape == SHAPE_TRIANGLE) {
            mTrianglePaint.setColor(mIndicatorColor);
            mTrianglePath.reset();
            mTrianglePath.moveTo(mIndicatorRect.left, getHeight());
            mTrianglePath.lineTo(mIndicatorRect.left / 2 + mIndicatorRect.right / 2,
                    getHeight() - mIndicatorHeight);
            mTrianglePath.lineTo(mIndicatorRect.right, getHeight());
            mTrianglePath.close();
            canvas.drawPath(mTrianglePath, mTrianglePaint);
        } else if (mIndicatorShape == SHAPE_LINE) {
            mIndicatorDrawable.setColor(mIndicatorColor);
            if (mIndicatorGravity == GRAVITY_BOTTOM) {
                mIndicatorDrawable.setBounds(mIndicatorRect.left, getHeight() - (int) mIndicatorHeight,
                        mIndicatorRect.right, getHeight());
            } else {
                mIndicatorDrawable.setBounds(mIndicatorRect.left, 0, mIndicatorRect.right,
                        (int) mIndicatorHeight);
            }
            mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius);
            mIndicatorDrawable.draw(canvas);
        } else if (mIndicatorShape == SHAPE_SQUARE) {
            if (mIndicatorCornerRadius <= 0 || mIndicatorCornerRadius > mIndicatorHeight / 2) {
                mIndicatorCornerRadius = mIndicatorHeight / 2;
            }
            mIndicatorRect.top = (int) ((getHeight() - mIndicatorHeight) / 2);
            mIndicatorRect.bottom = mIndicatorRect.top + (int) mIndicatorHeight;

            mIndicatorDrawable.setColor(mIndicatorColor);
            mIndicatorDrawable.setBounds(mIndicatorRect.left, mIndicatorRect.top, mIndicatorRect.right,
                    mIndicatorRect.bottom);
            mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius);
            mIndicatorDrawable.draw(canvas);
        }
    }
}

From source file:com.youqu.piclbs.util.SlidingTabLayout.java

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

    if (isInEditMode() || mTabCount <= 0) {
        return;//from   w w  w . j  av a  2  s . co  m
    }

    int height = getHeight();
    int paddingLeft = getPaddingLeft();
    // draw divider
    if (mDividerWidth > 0) {
        mDividerPaint.setStrokeWidth(mDividerWidth);
        mDividerPaint.setColor(mDividerColor);
        for (int i = 0; i < mTabCount - 1; i++) {
            View tab = mTabsContainer.getChildAt(i);
            canvas.drawLine(paddingLeft + tab.getRight(), mDividerPadding, paddingLeft + tab.getRight(),
                    height - mDividerPadding, mDividerPaint);
        }
    }

    // draw underline
    if (mUnderlineHeight > 0) {
        mRectPaint.setColor(mUnderlineColor);
        if (mUnderlineGravity == Gravity.BOTTOM) {
            canvas.drawRect(paddingLeft, height - mUnderlineHeight, mTabsContainer.getWidth() + paddingLeft,
                    height, mRectPaint);
        } else {
            canvas.drawRect(paddingLeft, 0, mTabsContainer.getWidth() + paddingLeft, mUnderlineHeight,
                    mRectPaint);
        }
    }

    //draw indicator line

    calcIndicatorRect();
    if (mIndicatorStyle == STYLE_TRIANGLE) {
        if (mIndicatorHeight > 0) {
            mTrianglePaint.setColor(mIndicatorColor);
            mTrianglePath.reset();
            mTrianglePath.moveTo(paddingLeft + mIndicatorRect.left, height);
            mTrianglePath.lineTo(paddingLeft + mIndicatorRect.left / 2 + mIndicatorRect.right / 2,
                    height - mIndicatorHeight);
            mTrianglePath.lineTo(paddingLeft + mIndicatorRect.right, height);
            mTrianglePath.close();
            canvas.drawPath(mTrianglePath, mTrianglePaint);
        }
    } else if (mIndicatorStyle == STYLE_BLOCK) {
        if (mIndicatorHeight < 0) {
            mIndicatorHeight = height - mIndicatorMarginTop - mIndicatorMarginBottom;
        } else {

        }

        if (mIndicatorHeight > 0) {
            if (mIndicatorCornerRadius < 0 || mIndicatorCornerRadius > mIndicatorHeight / 2) {
                mIndicatorCornerRadius = mIndicatorHeight / 2;
            }

            mIndicatorDrawable.setColor(mIndicatorColor);
            mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
                    (int) mIndicatorMarginTop,
                    (int) (paddingLeft + mIndicatorRect.right - mIndicatorMarginRight),
                    (int) (mIndicatorMarginTop + mIndicatorHeight));
            mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius);
            mIndicatorDrawable.draw(canvas);
        }
    } else {
        /* mRectPaint.setColor(mIndicatorColor);
        calcIndicatorRect();
        canvas.drawRect(getPaddingLeft() + mIndicatorRect.left, getHeight() - mIndicatorHeight,
                mIndicatorRect.right + getPaddingLeft(), getHeight(), mRectPaint);*/

        if (mIndicatorHeight > 0) {
            mIndicatorDrawable.setColor(mIndicatorColor);

            if (mIndicatorGravity == Gravity.BOTTOM) {
                mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
                        height - (int) mIndicatorHeight - (int) mIndicatorMarginBottom,
                        paddingLeft + mIndicatorRect.right - (int) mIndicatorMarginRight,
                        height - (int) mIndicatorMarginBottom);
            } else {
                mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
                        (int) mIndicatorMarginTop,
                        paddingLeft + mIndicatorRect.right - (int) mIndicatorMarginRight,
                        (int) mIndicatorHeight + (int) mIndicatorMarginTop);
            }
            mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius);
            mIndicatorDrawable.draw(canvas);
        }
    }
}

From source file:org.mdc.chess.ChessBoard.java

private void drawMoveHints(Canvas canvas) {
    if ((moveHints == null) || blindMode) {
        return;//from   ww w.j  a  v  a  2 s.  c o m
    }
    float h = (float) (sqSize / 2.0);
    float d = (float) (sqSize / 8.0);
    double v = 35 * Math.PI / 180;
    double cosv = Math.cos(v);
    double sinv = Math.sin(v);
    double tanv = Math.tan(v);
    int n = Math.min(moveMarkPaint.size(), moveHints.size());
    for (int i = 0; i < n; i++) {
        Move m = moveHints.get(i);
        if ((m == null) || (m.from == m.to)) {
            continue;
        }
        float x0 = getXCrd(Position.getX(m.from)) + h;
        float y0 = getYCrd(Position.getY(m.from)) + h;
        float x1 = getXCrd(Position.getX(m.to)) + h;
        float y1 = getYCrd(Position.getY(m.to)) + h;

        float x2 = (float) (Math.hypot(x1 - x0, y1 - y0) + d);
        float y2 = 0;
        float x3 = (float) (x2 - h * cosv);
        float y3 = (float) (y2 - h * sinv);
        float x4 = (float) (x3 - d * sinv);
        float y4 = (float) (y3 + d * cosv);
        float x5 = (float) (x4 + (-d / 2 - y4) / tanv);
        float y5 = -d / 2;
        float x6 = 0;
        float y6 = y5 / 2;
        Path path = new Path();
        path.moveTo(x2, y2);
        path.lineTo(x3, y3);
        //          path.lineTo(x4, y4);
        path.lineTo(x5, y5);
        path.lineTo(x6, y6);
        path.lineTo(x6, -y6);
        path.lineTo(x5, -y5);
        //          path.lineTo(x4, -y4);
        path.lineTo(x3, -y3);
        path.close();
        Matrix mtx = new Matrix();
        mtx.postRotate((float) (Math.atan2(y1 - y0, x1 - x0) * 180 / Math.PI));
        mtx.postTranslate(x0, y0);
        path.transform(mtx);
        Paint p = moveMarkPaint.get(i);
        canvas.drawPath(path, p);
    }
}

From source file:com.example.gatsu.theevent.HighlightView.java

protected void draw(Canvas canvas) {

    if (mHidden) {
        return;//from   ww w .ja  va2 s  . c  o m
    }

    Path path = new Path();
    if (!hasFocus()) {
        mOutlinePaint.setColor(0xFF000000);
        canvas.drawRect(mDrawRect, mOutlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        mContext.getDrawingRect(viewDrawingRect);
        if (mCircle) {

            canvas.save();

            float width = mDrawRect.width();
            float height = mDrawRect.height();
            path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2,
                    Path.Direction.CW);
            mOutlinePaint.setColor(0xFFEF04D6);

            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint);

            canvas.restore();

        } else {

            Rect topRect = new Rect(viewDrawingRect.left, viewDrawingRect.top, viewDrawingRect.right,
                    mDrawRect.top);
            if (topRect.width() > 0 && topRect.height() > 0) {
                canvas.drawRect(topRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect bottomRect = new Rect(viewDrawingRect.left, mDrawRect.bottom, viewDrawingRect.right,
                    viewDrawingRect.bottom);
            if (bottomRect.width() > 0 && bottomRect.height() > 0) {
                canvas.drawRect(bottomRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect leftRect = new Rect(viewDrawingRect.left, topRect.bottom, mDrawRect.left, bottomRect.top);
            if (leftRect.width() > 0 && leftRect.height() > 0) {
                canvas.drawRect(leftRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect rightRect = new Rect(mDrawRect.right, topRect.bottom, viewDrawingRect.right, bottomRect.top);
            if (rightRect.width() > 0 && rightRect.height() > 0) {
                canvas.drawRect(rightRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }

            path.addRect(new RectF(mDrawRect), Path.Direction.CW);

            mOutlinePaint.setColor(0xFFFF8A00);

        }

        canvas.drawPath(path, mOutlinePaint);

        if (mMode == ModifyMode.Grow) {
            if (mCircle) {
                int width = mResizeDrawableDiagonal.getIntrinsicWidth();
                int height = mResizeDrawableDiagonal.getIntrinsicHeight();

                int d = (int) Math.round(Math.cos(/*45deg*/Math.PI / 4D) * (mDrawRect.width() / 2D));
                int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2;
                int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2;
                mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(),
                        y + mResizeDrawableDiagonal.getIntrinsicHeight());
                mResizeDrawableDiagonal.draw(canvas);
            } else {
                int left = mDrawRect.left + 1;
                int right = mDrawRect.right + 1;
                int top = mDrawRect.top + 4;
                int bottom = mDrawRect.bottom + 3;

                int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2;
                int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2;
                int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2;
                int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2;

                int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2);
                int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2);

                mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth,
                        yMiddle + widthHeight);
                mResizeDrawableWidth.draw(canvas);

                mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth,
                        yMiddle + widthHeight);
                mResizeDrawableWidth.draw(canvas);

                mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight,
                        xMiddle + heightWidth, top + heightHeight);
                mResizeDrawableHeight.draw(canvas);

                mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight,
                        xMiddle + heightWidth, bottom + heightHeight);
                mResizeDrawableHeight.draw(canvas);
            }
        }
    }
}

From source file:org.caojun.library.cropimage.HighlightView.java

protected void draw(Canvas canvas) {

    if (mHidden) {
        return;/*from ww w.j  av  a  2 s.  c  om*/
    }

    Path path = new Path();
    if (!hasFocus()) {
        mOutlinePaint.setColor(0xFF000000);
        canvas.drawRect(mDrawRect, mOutlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        mView.getDrawingRect(viewDrawingRect);
        if (mCircle) {

            canvas.save();

            float width = mDrawRect.width();
            float height = mDrawRect.height();
            path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2,
                    Path.Direction.CW);
            mOutlinePaint.setColor(0xFFEF04D6);

            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint);

            canvas.restore();

        } else {

            Rect topRect = new Rect(viewDrawingRect.left, viewDrawingRect.top, viewDrawingRect.right,
                    mDrawRect.top);
            if (topRect.width() > 0 && topRect.height() > 0) {
                canvas.drawRect(topRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect bottomRect = new Rect(viewDrawingRect.left, mDrawRect.bottom, viewDrawingRect.right,
                    viewDrawingRect.bottom);
            if (bottomRect.width() > 0 && bottomRect.height() > 0) {
                canvas.drawRect(bottomRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect leftRect = new Rect(viewDrawingRect.left, topRect.bottom, mDrawRect.left, bottomRect.top);
            if (leftRect.width() > 0 && leftRect.height() > 0) {
                canvas.drawRect(leftRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect rightRect = new Rect(mDrawRect.right, topRect.bottom, viewDrawingRect.right, bottomRect.top);
            if (rightRect.width() > 0 && rightRect.height() > 0) {
                canvas.drawRect(rightRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }

            path.addRect(new RectF(mDrawRect), Path.Direction.CW);

            mOutlinePaint.setColor(0xFFFF8A00);

        }

        canvas.drawPath(path, mOutlinePaint);

        if (mMode == ModifyMode.Grow) {
            if (mCircle) {
                int width = mResizeDrawableDiagonal.getIntrinsicWidth();
                int height = mResizeDrawableDiagonal.getIntrinsicHeight();

                int d = (int) Math.round(Math.cos(/*45deg*/Math.PI / 4D) * (mDrawRect.width() / 2D));
                int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2;
                int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2;
                mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(),
                        y + mResizeDrawableDiagonal.getIntrinsicHeight());
                mResizeDrawableDiagonal.draw(canvas);
            } else {
                int left = mDrawRect.left + 1;
                int right = mDrawRect.right + 1;
                int top = mDrawRect.top + 4;
                int bottom = mDrawRect.bottom + 3;

                int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2;
                int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2;
                int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2;
                int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2;

                int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2);
                int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2);

                mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth,
                        yMiddle + widthHeight);
                mResizeDrawableWidth.draw(canvas);

                mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth,
                        yMiddle + widthHeight);
                mResizeDrawableWidth.draw(canvas);

                mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight,
                        xMiddle + heightWidth, top + heightHeight);
                mResizeDrawableHeight.draw(canvas);

                mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight,
                        xMiddle + heightWidth, bottom + heightHeight);
                mResizeDrawableHeight.draw(canvas);
            }
        }
    }
}

From source file:de.hs_bremen.aurora_hunter.ui.views.KpIndexChartView.java

public void onDraw(Canvas canvas) {

    if (points.size() == 0) {
        return;//w  w  w  .  j a  v  a2 s.c  o  m
    }
    Path path = new Path();
    int height = canvas.getHeight();
    int width = canvas.getWidth();

    for (Point point : points) {
        point.x = point.percentageX * width + 60;
        // Log.i("scaleFactor", " : " + scaleFactor);
        //Log.i("percent", " : " + percent);

        point.y = (float) ((1 - point.percentageY * scaleFactor) * height * 0.7 + 30);
    }

    if (points.size() > 1) {
        //calcuate x/y based on size of canvas
        for (int i = 0; i < points.size(); i++) {
            if (i >= 0) {
                Point point = points.get(i);
                //  Log.i("dx",point.x + " - " + point.y );
                if (i == 0) {
                    Point next = points.get(i + 1);
                    point.dx = ((next.x - point.x) / 5);
                    point.dy = ((next.y - point.y) / 5);
                } else if (i == points.size() - 1) {
                    Point prev = points.get(i - 1);
                    point.dx = ((point.x - prev.x) / 5);
                    point.dy = ((point.y - prev.y) / 5);
                } else {
                    Point next = points.get(i + 1);
                    Point prev = points.get(i - 1);
                    point.dx = ((next.x - prev.x) / 5);
                    point.dy = ((next.y - prev.y) / 5);
                }
            }
        }
    }

    if (points.size() > 0) {
        path.moveTo(0, (float) (canvas.getHeight() * 0.8));
        path.lineTo(0, points.get(0).y);

    }
    boolean first = true;

    for (int i = 0; i < points.size(); i++) {
        Point point = points.get(i);
        if (first) {
            first = false;
            path.cubicTo(point.x - point.x * 2, point.y - point.y / 5, point.x - point.dx, point.y - point.dy,
                    point.x, point.y);
        } else {
            Point prev = points.get(i - 1);
            //  Log.i("Draw", point.dx  + " " + point.dy);
            path.cubicTo(prev.x + prev.dx, prev.y + prev.dy, point.x - point.dx, point.y - point.dy, point.x,
                    point.y);
        }
    }
    path.lineTo(width, (float) (height * 0.8));

    path.lineTo(width, (float) (height * 0.9));
    path.lineTo(0, (float) (height * 0.9));

    canvas.drawPath(path, mGraphPaint);
    canvas.drawRect(0, (float) (height * 0.9), width, height, mGraphPaint);

    double Kp1Height = (1 - 0.6666666) * height;//points.get(points.size()-1).y;
    canvas.drawRect(0, (float) Kp1Height, width, (float) Kp1Height + 1, paintG1Line);
    canvas.drawText("G1", 2, (float) Kp1Height, paintTxt);
    int detlaY = 15;

    for (Point p : points) {
        int val = (int) Math.round(9 * p.percentageY);
        //if last element
        if (points.indexOf(p) == points.size() - 1) {
            //Log.i("last", p.toString());
            //   canvas.drawText(val + "", p.x-150,p.y - detlaY, paintTxt);
        } else {
            canvas.drawText(val + "", p.x - 10, p.y - detlaY, paintTxt);
        }
        //Log.i("point", p.toString());
    }
    // Log.i("Lenght", points.size() + " ");

}

From source file:org.androfarsh.widget.DragGridLayout.java

private void drawCellGrid(Canvas canvas) {
    if (mCellDrawable != null) {
        int i = 0;
        for (final Cell cell : mCells) {
            mTmpRect.set(cell.rect);/*from   w w w .  ja  v a2  s  .c  o  m*/

            final int[] stateSet = new int[] { (mEditMode ? 1 : -1) * R.attr.state_editing,
                    (mPressedCell == cell ? 1 : -1) * android.R.attr.state_pressed };

            canvas.save();
            canvas.clipRect(cell.rect);
            mCellDrawable.setState(stateSet);
            mCellDrawable.setBounds(cell.rect);
            mCellDrawable.draw(canvas);

            if (mDebugMode) {
                mPaint.setTextAlign(Align.CENTER);
                mPaint.setTextSize(30);
                mPaint.setTypeface(Typeface.DEFAULT_BOLD);
                mPaint.setColor(Color.GREEN);
                canvas.drawText(Integer.toString(i), cell.rect.centerX(), cell.rect.centerY(), mPaint);
                ++i;
            }

            canvas.restore();
        }
    }

    if (mDebugMode) {
        mPaint.setColor(Color.GREEN);
        mPaint.setStyle(Style.STROKE);
        mPaint.setStrokeWidth(1.5f);
        canvas.drawPath(mCellsRegion.getBoundaryPath(), mPaint);
    }
}