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.example.accessibility.FeedbackClickView.java

public void onDraw(Canvas canvas) {

    int right = getWidth() - getPaddingRight();
    int bottom = getHeight() - getPaddingBottom();

    //Scroll buttons are drawn in the different scrollable areas.
    scrollableAreas = getScrollableAreas();
    for (int i = 0; i < scrollableAreas.size(); i++) {
        if (scrollableAreas.get(i) == null) {
            Log.w("prints", "LV: scrollable es null");
        }/* w  w  w.ja v a 2 s . c  om*/

        else {
            scrollableAreas.get(i).getBoundsInScreen(outBounds);
            if ((outBounds.right > right - 90) && (outBounds.bottom > bottom - 90)) {
                //If the scroll button is over home button, we draw it in another position.
                canvas.drawRect(outBounds.right - 80, bottom - 180, outBounds.right, bottom - 100, paintWhite);
                a.set(outBounds.right - 50, bottom - 130);
                b.set(outBounds.right - 30, bottom - 130);
                c.set(outBounds.right - 30, bottom - 150);
                d.set(outBounds.right - 10, bottom - 140);
                e.set(outBounds.right - 40, bottom - 110);
                f.set(outBounds.right - 50, bottom - 150);
                g.set(outBounds.right - 40, bottom - 170);
                h.set(outBounds.right - 70, bottom - 140);
                path1.moveTo(a.x, a.y);
                path1.lineTo(f.x, f.y);
                path1.moveTo(f.x, f.y);
                path1.lineTo(c.x, c.y);
                path1.moveTo(c.x, c.y);
                path1.lineTo(g.x, g.y);
                path1.moveTo(g.x, g.y);
                path1.lineTo(f.x, f.y);
                path1.moveTo(f.x, f.y);
                path1.lineTo(h.x, h.y);
                path1.moveTo(h.x, h.y);
                path1.lineTo(a.x, a.y);
                path1.moveTo(a.x, a.y);
                path1.lineTo(b.x, b.y);
                path1.lineTo(c.x, c.y);
                path1.lineTo(d.x, d.y);
                path1.lineTo(b.x, b.y);
                path1.lineTo(e.x, e.y);
                path1.lineTo(a.x, a.y);
                path1.close();
                canvas.drawPath(path1, paintBlack);
            } else {
                canvas.drawRect(outBounds.right - 80, outBounds.bottom - 80, outBounds.right, outBounds.bottom,
                        paintWhite);
                a.set(outBounds.right - 50, outBounds.bottom - 30);
                b.set(outBounds.right - 30, outBounds.bottom - 30);
                c.set(outBounds.right - 30, outBounds.bottom - 50);
                d.set(outBounds.right - 10, outBounds.bottom - 40);
                e.set(outBounds.right - 40, outBounds.bottom - 10);
                f.set(outBounds.right - 50, outBounds.bottom - 50);
                g.set(outBounds.right - 40, outBounds.bottom - 70);
                h.set(outBounds.right - 70, outBounds.bottom - 40);
                path1.moveTo(a.x, a.y);
                path1.lineTo(f.x, f.y);
                path1.moveTo(f.x, f.y);
                path1.lineTo(c.x, c.y);
                path1.moveTo(c.x, c.y);
                path1.lineTo(g.x, g.y);
                path1.moveTo(g.x, g.y);
                path1.lineTo(f.x, f.y);
                path1.moveTo(f.x, f.y);
                path1.lineTo(h.x, h.y);
                path1.moveTo(h.x, h.y);
                path1.lineTo(a.x, a.y);
                path1.moveTo(a.x, a.y);
                path1.lineTo(b.x, b.y);
                path1.lineTo(c.x, c.y);
                path1.lineTo(d.x, d.y);
                path1.lineTo(b.x, b.y);
                path1.lineTo(e.x, e.y);
                path1.lineTo(a.x, a.y);
                path1.close();
                canvas.drawPath(path1, paintBlack);
            }
            canvas.drawRect(outBounds.left, outBounds.top, outBounds.left + 80, outBounds.top + 80, paintWhite);
            a.set(outBounds.left + 30, outBounds.top + 50);
            b.set(outBounds.left + 50, outBounds.top + 50);
            c.set(outBounds.left + 50, outBounds.top + 30);
            d.set(outBounds.left + 70, outBounds.top + 40);
            e.set(outBounds.left + 40, outBounds.top + 70);
            f.set(outBounds.left + 30, outBounds.top + 30);
            g.set(outBounds.left + 40, outBounds.top + 10);
            h.set(outBounds.left + 10, outBounds.top + 40);
            path.moveTo(a.x, a.y);
            path.lineTo(b.x, b.y);
            path.moveTo(b.x, b.y);
            path.lineTo(c.x, c.y);
            path.moveTo(c.x, c.y);
            path.lineTo(d.x, d.y);
            path.moveTo(d.x, d.y);
            path.lineTo(b.x, b.y);
            path.moveTo(b.x, b.y);
            path.lineTo(e.x, e.y);
            path.moveTo(e.x, e.y);
            path.lineTo(a.x, a.y);
            path.moveTo(a.x, a.y);
            path.lineTo(f.x, f.y);
            path.lineTo(c.x, c.y);
            path.lineTo(g.x, g.y);
            path.lineTo(f.x, f.y);
            path.lineTo(h.x, h.y);
            path.lineTo(a.x, a.y);
            path.close();
            canvas.drawPath(path, paintBlack);

        }
    }

    //Home contexual menu
    if (getMenuContextual().equals("home")) {

        //Two yellow squares that represent menu options
        canvas.drawRect(right / 2 - 120, bottom / 2 - 260, right / 2 + 120, bottom / 2 - 20, mYellow);
        canvas.drawRect(right / 2 - 120, bottom / 2 + 20, right / 2 + 120, bottom / 2 + 260, mYellow);

        //House that represents Home option
        canvas.drawRect(right / 2 - 90, bottom / 2 - 130, right / 2 + 90, bottom / 2 - 50, mBlack);
        a.set(right / 2 - 90, bottom / 2 - 130);
        b.set(right / 2 + 90, bottom / 2 - 130);
        c.set(right / 2, bottom / 2 - 230);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.lineTo(c.x, c.y);
        path.lineTo(a.x, a.y);
        path.close();
        canvas.drawPath(path, mBlack);

        //Arrow that represents click option
        a.set(right / 2 - 90, bottom / 2 + 50);
        b.set(right / 2 - 75, bottom / 2 + 170);
        c.set(right / 2 + 30, bottom / 2 + 65);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.lineTo(c.x, c.y);
        path.lineTo(a.x, a.y);
        path.close();
        canvas.drawPath(path, mBlack);

        a.set(right / 2 - 30, bottom / 2 + 110);
        b.set(right / 2 + 90, bottom / 2 + 230);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.close();
        canvas.drawPath(path, mBlack);
    }

    //Scroll backward contextual menu
    if (getMenuContextual().equals("scrollbackward")) {
        Log.i("prints", "scroll backward contextual menu");
        //Two yellow squares that represent menu options
        canvas.drawRect(right / 2 - 120, bottom / 2 - 260, right / 2 + 120, bottom / 2 - 20, mYellow);
        canvas.drawRect(right / 2 - 120, bottom / 2 + 20, right / 2 + 120, bottom / 2 + 260, mYellow);

        //Picture that represents scroll backward option
        a.set(right / 2 - 30, bottom / 2 - 110);
        b.set(right / 2 + 30, bottom / 2 - 110);
        c.set(right / 2 + 30, bottom / 2 - 170);
        d.set(right / 2 + 90, bottom / 2 - 140);
        e.set(right / 2, bottom / 2 - 50);
        f.set(right / 2 - 30, bottom / 2 - 170);
        g.set(right / 2, bottom / 2 - 230);
        h.set(right / 2 - 90, bottom / 2 - 140);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.moveTo(b.x, b.y);
        path.lineTo(c.x, c.y);
        path.moveTo(c.x, c.y);
        path.lineTo(d.x, d.y);
        path.moveTo(d.x, d.y);
        path.lineTo(b.x, b.y);
        path.moveTo(b.x, b.y);
        path.lineTo(e.x, e.y);
        path.moveTo(e.x, e.y);
        path.lineTo(a.x, a.y);
        path.moveTo(a.x, a.y);
        path.lineTo(f.x, f.y);
        path.lineTo(c.x, c.y);
        path.lineTo(g.x, g.y);
        path.lineTo(f.x, f.y);
        path.lineTo(h.x, h.y);
        path.lineTo(a.x, a.y);
        path.close();
        canvas.drawPath(path, paintBlack);

        //Arrow that represents click option
        a.set(right / 2 - 90, bottom / 2 + 50);
        b.set(right / 2 - 75, bottom / 2 + 170);
        c.set(right / 2 + 30, bottom / 2 + 65);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.lineTo(c.x, c.y);
        path.lineTo(a.x, a.y);
        path.close();
        canvas.drawPath(path, mBlack);

        a.set(right / 2 - 30, bottom / 2 + 110);
        b.set(right / 2 + 90, bottom / 2 + 230);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.close();
        canvas.drawPath(path, mBlack);

    }
    if (getMenuContextual().equals("scrollforward")) {
        Log.i("prints", "scroll backward contextual menu");

        //Two yellow squares that represent menu options
        canvas.drawRect(right / 2 - 120, bottom / 2 - 260, right / 2 + 120, bottom / 2 - 20, mYellow);
        canvas.drawRect(right / 2 - 120, bottom / 2 + 20, right / 2 + 120, bottom / 2 + 260, mYellow);

        //Picture that represents scroll backward option
        a.set(right / 2 - 30, bottom / 2 - 110);
        b.set(right / 2 + 30, bottom / 2 - 110);
        c.set(right / 2 + 30, bottom / 2 - 170);
        d.set(right / 2 + 90, bottom / 2 - 140);
        e.set(right / 2, bottom / 2 - 50);
        f.set(right / 2 - 30, bottom / 2 - 170);
        g.set(right / 2, bottom / 2 - 230);
        h.set(right / 2 - 90, bottom / 2 - 140);
        path.moveTo(a.x, a.y);
        path.lineTo(f.x, f.y);
        path.moveTo(f.x, f.y);
        path.lineTo(c.x, c.y);
        path.moveTo(c.x, c.y);
        path.lineTo(g.x, g.y);
        path.moveTo(g.x, g.y);
        path.lineTo(f.x, f.y);
        path.moveTo(f.x, f.y);
        path.lineTo(h.x, h.y);
        path.moveTo(h.x, h.y);
        path.lineTo(a.x, a.y);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.lineTo(c.x, c.y);
        path.lineTo(d.x, d.y);
        path.lineTo(b.x, b.y);
        path.lineTo(e.x, e.y);
        path.lineTo(a.x, a.y);
        path.close();
        canvas.drawPath(path, paintBlack);

        //Arrow that represents click option
        a.set(right / 2 - 90, bottom / 2 + 50);
        b.set(right / 2 - 75, bottom / 2 + 170);
        c.set(right / 2 + 30, bottom / 2 + 65);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.lineTo(c.x, c.y);
        path.lineTo(a.x, a.y);
        path.close();
        canvas.drawPath(path, mBlack);

        a.set(right / 2 - 30, bottom / 2 + 110);
        b.set(right / 2 + 90, bottom / 2 + 230);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.close();
        canvas.drawPath(path, mBlack);

    }
    if (getMenuContextual().equals("back")) {
        Log.i("prints", "scroll backward contextual menu");

        //Two yellow squares that represent menu options
        canvas.drawRect(right / 2 - 120, bottom / 2 - 260, right / 2 + 120, bottom / 2 - 20, mYellow);
        canvas.drawRect(right / 2 - 120, bottom / 2 + 20, right / 2 + 120, bottom / 2 + 260, mYellow);
        paintBlack.setStyle(Paint.Style.STROKE);

        //Arrow that represents back option
        canvas.drawRect(right / 2 - 30, bottom / 2 - 110, right / 2 + 60, bottom / 2 - 110, paintBlack);
        oval.set(right / 2 + 30, bottom / 2 - 170, right / 2 + 90, bottom / 2 - 110);
        canvas.drawArc(oval, 270, 180, true, paintBlack);
        canvas.drawRect(right / 2 - 90, bottom / 2 - 170, right / 2 + 60, bottom / 2 - 170, paintBlack);
        a.set(right / 2 - 60, bottom / 2 - 140);
        b.set(right / 2 - 90, bottom / 2 - 170);
        c.set(right / 2 - 60, bottom / 2 - 200);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.moveTo(b.x, b.y);
        path.lineTo(c.x, c.y);
        canvas.drawPath(path, paintBlack);

        //Arrow that represents click option
        a.set(right / 2 - 90, bottom / 2 + 50);
        b.set(right / 2 - 75, bottom / 2 + 170);
        c.set(right / 2 + 30, bottom / 2 + 65);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.lineTo(c.x, c.y);
        path.lineTo(a.x, a.y);
        path.close();
        canvas.drawPath(path, mBlack);

        a.set(right / 2 - 30, bottom / 2 + 110);
        b.set(right / 2 + 90, bottom / 2 + 230);
        path.moveTo(a.x, a.y);
        path.lineTo(b.x, b.y);
        path.close();
        canvas.drawPath(path, mBlack);

    }

    else if (mButton.equals("clear")) {
        //Log.i("prints","clear");
    }

    if (posy < 100) {
        oval.set(getX() - 50, getY() + 20, getX() + 50, getY() + 120);
    } else {
        oval.set(getX() - 50, getY() - 120, getX() + 50, getY() - 20);
    }

    canvas.drawArc(oval, 270, getDegr(), true, mGreen);

}

From source file:org.akop.crosswords.view.CrosswordView.java

private void renderCell(Canvas canvas, Cell cell, RectF cellRect, Paint fillPaint) {
    canvas.drawRect(cellRect, fillPaint);
    canvas.drawRect(cellRect, mCellStrokePaint);

    if (cell.mCircled) {
        canvas.drawCircle(cellRect.centerX(), cellRect.centerY(), mCircleRadius, mCircleStrokePaint);
    }/*  w  w  w.  j  a  va2s  .  c  o  m*/

    if (cell.mNumber != null) {
        mNumberTextPaint.getTextBounds(cell.mNumber, 0, cell.mNumber.length(), mTempRect);

        float numberX = cellRect.left + mNumberTextPadding + (mTempRect.width() / 2);
        float numberY = cellRect.top + mNumberTextPadding + mTempRect.height();

        if (cell.mCircled) {
            canvas.drawText(cell.mNumber, numberX, numberY, mNumberStrokePaint);
        }

        canvas.drawText(cell.mNumber, numberX, numberY, mNumberTextPaint);
    }

    if (cell.mCheated) {
        Path path = new Path();
        path.moveTo(cellRect.right, cellRect.bottom);
        path.lineTo(cellRect.right - mMarkerSideLength, cellRect.bottom);
        path.lineTo(cellRect.right, cellRect.bottom - mMarkerSideLength);
        path.close();

        canvas.drawPath(path, mCheatedCellFillPaint);
        canvas.drawPath(path, mCellStrokePaint);
    }

    if (cell.mError) {
        Path path = new Path();
        path.moveTo(cellRect.left, cellRect.bottom);
        path.lineTo(cellRect.left + mMarkerSideLength, cellRect.bottom);
        path.lineTo(cellRect.left, cellRect.bottom - mMarkerSideLength);
        path.close();

        canvas.drawPath(path, mMistakeCellFillPaint);
        canvas.drawPath(path, mCellStrokePaint);
    }

    if (!cell.isEmpty()) {
        mAnswerTextPaint.getTextBounds(cell.mCharStr, 0, cell.mCharStr.length(), mTempRect);
        canvas.drawText(cell.mCharStr, cellRect.left + mCellSize / 2,
                cellRect.top + mCellSize - mAnswerTextPadding, mAnswerTextPaint);
    }
}

From source file:wm.xmwei.ui.view.indicator.PagerSlidingTabIndicator.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//w ww .j a v  a2 s. c om
    }

    final int height = getHeight();
    final int width = getWidth();

    // 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);
        nextTab.setBackgroundResource(Color.TRANSPARENT);
        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 center = (lineLeft + lineRight) / 2;

    // ,??  
    // Path path = new Path();
    //path.moveTo(center,height - indicatorHeight);//   

    BigDecimal a = BigDecimal.valueOf(1.736);
    BigDecimal b = BigDecimal.valueOf(3);
    BigDecimal bigDecimal = a.divide(b, BigDecimal.ROUND_HALF_UP);
    float result = bigDecimal.floatValue() * indicatorHeight;

    //path.lineTo(center-result-2, height);  
    // path.lineTo(center+result+2, height);
    //path.close(); // ??  
    // canvas.drawPath(path, rectPaint);

    Path path2 = new Path();
    path2.moveTo(0, 0);//   
    path2.lineTo(0, height);
    path2.lineTo(center - result - 5, height);
    path2.lineTo(center, height - indicatorHeight);
    path2.lineTo(center + result + 5, height);
    path2.lineTo(tabsContainer.getWidth(), height);
    path2.lineTo(tabsContainer.getWidth(), 0);

    path2.close(); // ??  
    canvas.drawPath(path2, bgPaint);
    // 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:de.hs_bremen.aurora_hunter.ui.views.PredictionGraphView.java

public void onDraw(Canvas canvas) {
    if (mPoints.size() == 0) {
        return;//w w  w .j  a  va2s .  co m
    }
    int yOffsetForLabels = 0;

    if (mMax * mScaleFactor > 0.8) {
        yOffsetForLabels = 15;
    }
    Path path = new Path();
    int height = canvas.getHeight();
    int width = canvas.getWidth();

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

        point.y = (float) ((1 - point.percentageY * mScaleFactor) * height) + yOffsetForLabels * 3;
    }

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

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

    }
    boolean first = true;

    for (int i = 0; i < mPoints.size(); i++) {
        Point point = mPoints.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 = mPoints.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);
        }
    }

    if (mPoints.size() > 0) {
        path.lineTo(width, mPoints.get(mPoints.size() - 1).y);
    }
    path.lineTo(width, height);
    path.lineTo(0, height);

    canvas.drawPath(path, mGraphPaint);

    int detlaY = 30;

    for (Point p : mPoints) {

        int val = (int) Math.round(p.percentageY * 100);
        //if last element

        if (mPoints.indexOf(p) == mPoints.size() - 1) {
            //Log.i("last", p.toString());
            if (val == 0 || p.y > getHeight()) {
                canvas.drawText(val + "%", p.x - 150, getHeight() - detlaY, mTextPaint);
            } else {
                canvas.drawText(val + "%", p.x - 150, p.y - detlaY + yOffsetForLabels, mTextPaint);
            }

        } else {
            if (val == 0 || p.y > getHeight()) {
                canvas.drawText(val + "%", p.x - 20, getHeight() - detlaY, mTextPaint);
            } else {
                canvas.drawText(val + "%", p.x - 20, p.y - detlaY + yOffsetForLabels, mTextPaint);
            }

        }
        //Log.i("point", p.toString());
    }
    // Log.i("Lenght", mPoints.size() + " ");

    float levelStart = (float) (canvas.getHeight() - (mNotificationLevel * canvas.getHeight()));
    float lineHeight = DpToPixelUtil.convertDpToPixel(2, getContext());

    if (mViewMode == PredictionFragment.NOTIFICATION_MODE.SET_NOTIFICATION_LEVEL) {
        mNotificationLevelPaint.setAlpha(150);
        float leftOffset = 0;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            float arcHeight = DpToPixelUtil.convertDpToPixel(30, getContext());
            leftOffset = arcHeight;
            RectF rectF = new RectF(getWidth() - arcHeight, levelStart - arcHeight / 2, getWidth(),
                    levelStart + arcHeight / 2);
            canvas.drawArc(rectF, 0, 360, true, mNotificationLevelPaint);

        }
        canvas.drawRect(0, levelStart, canvas.getWidth() - leftOffset, levelStart + lineHeight,
                mNotificationLevelPaint);

        mNotificationLevelPaint.setAlpha(20);
        canvas.drawRect(0, levelStart + lineHeight, canvas.getWidth(), canvas.getHeight(),
                mNotificationLevelPaint);
        String text = Math.round(mNotificationLevel * 100) + "%";
        canvas.drawText(text, DpToPixelUtil.convertDpToPixel(10, getContext()),
                levelStart + DpToPixelUtil.convertDpToPixel(25, getContext()), mNotificationLevelTextPaint);
    } else {
        mNotificationLevelPaint.setAlpha(30);
        canvas.drawRect(0, levelStart, canvas.getWidth(), levelStart + lineHeight, mNotificationLevelPaint);
    }

}

From source file:devlight.io.library.ArcProgressStackView.java

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

    // Save and rotate to start angle
    canvas.save();//from  w  ww .j a v  a 2 s .c  o m
    final float radius = mSize * 0.5F;
    canvas.rotate(mStartAngle, radius, radius);

    // Draw all of progress
    for (int i = 0; i < mModels.size(); i++) {
        final Model model = mModels.get(i);
        // Get progress for current model
        float progressFraction = mIsAnimated && !isInEditMode()
                ? (model.mLastProgress + (mAnimatedFraction * (model.getProgress() - model.mLastProgress)))
                        / MAX_PROGRESS
                : model.getProgress() / MAX_PROGRESS;
        if (i != mActionMoveModelIndex && mActionMoveModelIndex != ANIMATE_ALL_INDEX)
            progressFraction = model.getProgress() / MAX_PROGRESS;
        final float progress = progressFraction * mSweepAngle;

        // Check if model have gradient
        final boolean isGradient = model.getColors() != null;
        // Set width of progress
        mProgressPaint.setStrokeWidth(mProgressModelSize);

        // Set model arc progress
        model.mPath.reset();
        model.mPath.addArc(model.mBounds, 0.0F, progress);

        // Draw gradient progress or solid
        resetShadowLayer();
        mProgressPaint.setShader(null);
        mProgressPaint.setStyle(Paint.Style.STROKE);

        if (mIsModelBgEnabled) {
            //noinspection ResourceAsColor
            mProgressPaint.setColor(isInEditMode() ? mPreviewModelBgColor : model.getBgColor());
            canvas.drawArc(model.mBounds, 0.0F, mSweepAngle, false, mProgressPaint);
            if (!isInEditMode())
                mProgressPaint.clearShadowLayer();
        }

        // Check if gradient for draw shadow at first and then gradient progress
        if (isGradient) {
            if (!mIsModelBgEnabled) {
                canvas.drawPath(model.mPath, mProgressPaint);

                if (!isInEditMode())
                    mProgressPaint.clearShadowLayer();
            }

            mProgressPaint.setShader(model.mSweepGradient);
        } else
            mProgressPaint.setColor(model.getColor());

        // Here we draw main progress
        mProgressPaint.setAlpha(255);
        canvas.drawPath(model.mPath, mProgressPaint);

        // Preview mode
        if (isInEditMode())
            continue;

        // Get model title bounds
        mTextPaint.setTextSize(mProgressModelSize * 0.5F);
        mTextPaint.getTextBounds(model.getTitle(), 0, model.getTitle().length(), model.mTextBounds);

        // Draw title at start with offset
        final float titleHorizontalOffset = model.mTextBounds.height() * 0.5F;
        final float progressLength = (float) (Math.PI / 180.0F) * progress * model.mBounds.width() * 0.5F;
        final String title = (String) TextUtils.ellipsize(model.getTitle(), mTextPaint,
                progressLength - titleHorizontalOffset * 2, TextUtils.TruncateAt.END);
        canvas.drawTextOnPath(title, model.mPath, mIsRounded ? 0.0F : titleHorizontalOffset,
                titleHorizontalOffset, mTextPaint);

        // Get pos and tan at final path point
        model.mPathMeasure.setPath(model.mPath, false);
        model.mPathMeasure.getPosTan(model.mPathMeasure.getLength(), model.mPos, model.mTan);

        // Get title width
        final float titleWidth = model.mTextBounds.width();

        // Create model progress like : 23%
        final String percentProgress = String.format("%d%%", (int) model.getProgress());
        // Get progress text bounds
        mTextPaint.setTextSize(mProgressModelSize * 0.35f);
        mTextPaint.getTextBounds(percentProgress, 0, percentProgress.length(), model.mTextBounds);

        // Get pos tan with end point offset and check whether the rounded corners for offset
        final float progressHorizontalOffset = mIndicatorOrientation == IndicatorOrientation.VERTICAL
                ? model.mTextBounds.height() * 0.5F
                : model.mTextBounds.width() * 0.5F;
        final float indicatorProgressOffset = (mIsRounded ? progressFraction : 1.0F)
                * (-progressHorizontalOffset - titleHorizontalOffset
                        - (mIsRounded ? model.mTextBounds.height() * 2.0F : 0.0F));
        model.mPathMeasure.getPosTan(model.mPathMeasure.getLength() + indicatorProgressOffset, model.mPos,
                mIndicatorOrientation == IndicatorOrientation.VERTICAL && !mIsRounded ? new float[2]
                        : model.mTan);

        // Check if there available place for indicator
        if ((titleWidth + model.mTextBounds.height() + titleHorizontalOffset * 2.0F)
                - indicatorProgressOffset < progressLength) {
            // Get rotate indicator progress angle for progress value
            float indicatorProgressAngle = (float) (Math.atan2(model.mTan[1], model.mTan[0])
                    * (180.0F / Math.PI));
            // Get arc angle of progress indicator
            final float indicatorLengthProgressAngle = ((progressLength + indicatorProgressOffset)
                    / (model.mBounds.width() * 0.5F)) * (float) (180.0F / Math.PI);

            // Detect progress indicator position : left or right and then rotate
            if (mIndicatorOrientation == IndicatorOrientation.VERTICAL) {
                // Get X point of arc angle progress indicator
                final float x = (float) (model.mBounds.width() * 0.5F
                        * (Math.cos((indicatorLengthProgressAngle + mStartAngle) * Math.PI / 180.0F)))
                        + model.mBounds.centerX();
                indicatorProgressAngle += (x > radius) ? -90.0F : 90.0F;
            } else {
                // Get Y point of arc angle progress indicator
                final float y = (float) (model.mBounds.height() * 0.5F
                        * (Math.sin((indicatorLengthProgressAngle + mStartAngle) * Math.PI / 180.0F)))
                        + model.mBounds.centerY();
                indicatorProgressAngle += (y > radius) ? 180.0F : 0.0F;
            }

            // Draw progress value
            canvas.save();
            canvas.rotate(indicatorProgressAngle, model.mPos[0], model.mPos[1]);
            canvas.drawText(percentProgress, model.mPos[0] - model.mTextBounds.exactCenterX(),
                    model.mPos[1] - model.mTextBounds.exactCenterY(), mTextPaint);
            canvas.restore();
        }

        // Check if gradient and have rounded corners, because we must to create elevation effect
        // for start progress corner
        if ((isGradient || mIsLeveled) && mIsRounded && progress != 0) {
            model.mPathMeasure.getPosTan(0.0F, model.mPos, model.mTan);

            // Set paint for overlay rounded gradient with shadow
            setLevelShadowLayer();
            //noinspection ResourceAsColor
            mLevelPaint.setColor(isGradient ? model.getColors()[0] : model.getColor());

            // Get bounds of start pump
            final float halfSize = mProgressModelSize * 0.5F;
            final RectF arcRect = new RectF(model.mPos[0] - halfSize, model.mPos[1] - halfSize,
                    model.mPos[0] + halfSize, model.mPos[1] + halfSize + 2.0F);
            canvas.drawArc(arcRect, 0.0F, -180.0F, true, mLevelPaint);
        }
    }

    // Restore after drawing
    canvas.restore();
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

/** {@inheritDoc} */
@Override/* www. jav  a 2 s . c o  m*/
protected void onDraw(Canvas c) {
    // 1.- Clip to padding
    c.clipRect(mViewArea);

    // 2.- Draw the backgrounds areas
    c.drawRect(mGraphArea, mGraphAreaBgPaint);
    if (mShowFooter) {
        c.drawRect(mFooterArea, mFooterAreaBgPaint);
    }

    final LongSparseArray<Pair<double[], int[]>> data;
    final double maxValue;
    synchronized (mLock) {
        data = mData;
        maxValue = mMaxValue;
    }
    boolean hasData = data.size() > 0;
    if (hasData && mIsDataComputed) {
        // 3.- Compute viewport and draw the data
        computeItemsOnScreen(data);
        drawBarItems(c, data, maxValue);

        // 4.- Draw tick labels and current position
        if (mShowFooter) {
            drawTickLabels(c, data);
            c.drawPath(mCurrentPositionPath, mFooterAreaBgPaint);
        }
    }

    // Draw the edge scrolling effects
    drawEdgeEffects(c);
}

From source file:org.telegram.ui.ChannelAdminLogActivity.java

private TextureView createTextureView(boolean add) {
    if (parentLayout == null) {
        return null;
    }//from w ww  .ja  v  a2 s.c  o  m
    if (roundVideoContainer == null) {
        if (Build.VERSION.SDK_INT >= 21) {
            roundVideoContainer = new FrameLayout(getParentActivity()) {
                @Override
                public void setTranslationY(float translationY) {
                    super.setTranslationY(translationY);
                    contentView.invalidate();
                }
            };
            roundVideoContainer.setOutlineProvider(new ViewOutlineProvider() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, AndroidUtilities.roundMessageSize, AndroidUtilities.roundMessageSize);
                }
            });
            roundVideoContainer.setClipToOutline(true);
        } else {
            roundVideoContainer = new FrameLayout(getParentActivity()) {
                @Override
                protected void onSizeChanged(int w, int h, int oldw, int oldh) {
                    super.onSizeChanged(w, h, oldw, oldh);
                    aspectPath.reset();
                    aspectPath.addCircle(w / 2, h / 2, w / 2, Path.Direction.CW);
                    aspectPath.toggleInverseFillType();
                }

                @Override
                public void setTranslationY(float translationY) {
                    super.setTranslationY(translationY);
                    contentView.invalidate();
                }

                @Override
                public void setVisibility(int visibility) {
                    super.setVisibility(visibility);
                    if (visibility == VISIBLE) {
                        setLayerType(View.LAYER_TYPE_HARDWARE, null);
                    }
                }

                @Override
                protected void dispatchDraw(Canvas canvas) {
                    super.dispatchDraw(canvas);
                    canvas.drawPath(aspectPath, aspectPaint);
                }
            };
            aspectPath = new Path();
            aspectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
            aspectPaint.setColor(0xff000000);
            aspectPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        }
        roundVideoContainer.setWillNotDraw(false);
        roundVideoContainer.setVisibility(View.INVISIBLE);

        aspectRatioFrameLayout = new AspectRatioFrameLayout(getParentActivity());
        aspectRatioFrameLayout.setBackgroundColor(0);
        if (add) {
            roundVideoContainer.addView(aspectRatioFrameLayout,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        }

        videoTextureView = new TextureView(getParentActivity());
        videoTextureView.setOpaque(false);
        aspectRatioFrameLayout.addView(videoTextureView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    }
    if (roundVideoContainer.getParent() == null) {
        contentView.addView(roundVideoContainer, 1, new FrameLayout.LayoutParams(
                AndroidUtilities.roundMessageSize, AndroidUtilities.roundMessageSize));
    }
    roundVideoContainer.setVisibility(View.INVISIBLE);
    aspectRatioFrameLayout.setDrawingReady(false);
    return videoTextureView;
}

From source file:com.mikelau.croperino.HighlightView.java

protected void draw(Canvas canvas) {

    if (mHidden) {
        return;/* w  ww.  j  av  a  2s.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 if (mOvalo) {
            canvas.save();

            RectF r = new RectF(mDrawRect.left, mDrawRect.top, mDrawRect.right, mDrawRect.bottom);

            path.addOval(r, 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:android.support.v7.graphics.drawable.DrawerArrowDrawable.java

@Override
public void draw(Canvas canvas) {
    Rect bounds = getBounds();//from   w w  w. j a  va  2 s  .  c  om

    final boolean flipToPointRight;
    switch (mDirection) {
    case ARROW_DIRECTION_LEFT:
        flipToPointRight = false;
        break;
    case ARROW_DIRECTION_RIGHT:
        flipToPointRight = true;
        break;
    case ARROW_DIRECTION_END:
        flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR;
        break;
    case ARROW_DIRECTION_START:
    default:
        flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
        break;
    }

    // Interpolated widths of arrow bars

    float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2);
    arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress);
    final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress);
    // Interpolated size of middle bar
    final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, mProgress));
    // The rotation of the top and bottom bars (that make the arrow head)
    final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress);

    // The whole canvas rotates as the transition happens
    final float canvasRotate = lerp(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress);

    final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation));
    final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation));

    mPath.rewind();
    final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress);

    final float arrowEdge = -arrowShaftLength / 2;
    // draw middle bar
    mPath.moveTo(arrowEdge + arrowShaftCut, 0);
    mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0);

    // bottom bar
    mPath.moveTo(arrowEdge, topBottomBarOffset);
    mPath.rLineTo(arrowWidth, arrowHeight);

    // top bar
    mPath.moveTo(arrowEdge, -topBottomBarOffset);
    mPath.rLineTo(arrowWidth, -arrowHeight);

    mPath.close();

    canvas.save();

    // Rotate the whole canvas if spinning, if not, rotate it 180 to get
    // the arrow pointing the other way for RTL.
    final float barThickness = mPaint.getStrokeWidth();
    final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2);
    float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2.
    yOffset += barThickness * 1.5 + mBarGap;

    canvas.translate(bounds.centerX(), yOffset);
    if (mSpin) {
        canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1));
    } else if (flipToPointRight) {
        canvas.rotate(180);
    }
    canvas.drawPath(mPath, mPaint);

    canvas.restore();
}

From source file:com.commonsware.cwac.crossport.v7.graphics.drawable.DrawerArrowDrawable.java

@Override
public void draw(Canvas canvas) {
    Rect bounds = getBounds();//from  w  w w .java2s .c o m

    final boolean flipToPointRight;
    switch (mDirection) {
    case ARROW_DIRECTION_LEFT:
        flipToPointRight = false;
        break;
    case ARROW_DIRECTION_RIGHT:
        flipToPointRight = true;
        break;
    case ARROW_DIRECTION_END:
        flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR;
        break;
    case ARROW_DIRECTION_START:
    default:
        flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
        break;
    }

    // Interpolated widths of arrow bars

    float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2);
    arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress);
    final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress);
    // Interpolated size of middle bar
    final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, mProgress));
    // The rotation of the top and bottom bars (that make the arrow head)
    final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress);

    // The whole canvas rotates as the transition happens
    final float canvasRotate = lerp(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress);

    final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation));
    final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation));

    mPath.rewind();
    final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress);

    final float arrowEdge = -arrowShaftLength / 2;
    // draw middle bar
    mPath.moveTo(arrowEdge + arrowShaftCut, 0);
    mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0);

    // bottom bar
    mPath.moveTo(arrowEdge, topBottomBarOffset);
    mPath.rLineTo(arrowWidth, arrowHeight);

    // top bar
    mPath.moveTo(arrowEdge, -topBottomBarOffset);
    mPath.rLineTo(arrowWidth, -arrowHeight);

    mPath.close();

    canvas.save();

    // Rotate the whole canvas if spinning, if not, rotate it 180 to get
    // the arrow pointing the other way for RTL.
    final float barThickness = mPaint.getStrokeWidth();
    final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2);
    float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2.
    yOffset += barThickness * 1.5f + mBarGap;

    canvas.translate(bounds.centerX(), yOffset);
    if (mSpin) {
        canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1));
    } else if (flipToPointRight) {
        canvas.rotate(180);
    }
    canvas.drawPath(mPath, mPaint);

    canvas.restore();
}