Example usage for android.graphics Path Path

List of usage examples for android.graphics Path Path

Introduction

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

Prototype

public Path() 

Source Link

Document

Create an empty path

Usage

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);
    }//from  w ww . j av a 2s  .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:org.telegram.ui.ChannelAdminLogActivity.java

private TextureView createTextureView(boolean add) {
    if (parentLayout == null) {
        return null;
    }//  w w  w. java2  s.co  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.skytree.epubtest.BookViewActivity.java

@SuppressLint({ "DrawAllocation", "DrawAllocation" })
@Override/*from w w  w. j a  va2 s  .c  o m*/
protected void onDraw(Canvas canvas) {
    Paint paint = new Paint();

    float sl, sr, st, sb;
    sl = 0;
    sr = this.getWidth();
    float ah = this.arrowHeight; // arrow Height;
    if (this.isArrowDown) {
        st = 0;
        sb = this.getHeight() - ah;
    } else {
        st = ah - 10;
        sb = this.getHeight() - 10;
    }

    Path boxPath = new Path();
    boxPath.addRoundRect(new RectF(sl, st, sr, sb), 20, 20, Path.Direction.CW);

    if (arrowPosition <= arrowHeight * 1.5f) {
        arrowPosition = arrowHeight * 1.5f;
    } else if (arrowPosition >= this.getWidth() - arrowHeight * 1.5f) {
        arrowPosition = this.getWidth() - arrowHeight * 1.5f;
    }

    Path arrowPath = new Path();
    if (isArrowDown) {
        arrowPath.moveTo(arrowPosition, sb + ah);
        arrowPath.lineTo((float) (arrowPosition - ah * 0.75), sb - 10);
        arrowPath.lineTo((float) (arrowPosition + ah * 0.75), sb - 10);
        arrowPath.close();
    } else {
        arrowPath.moveTo(arrowPosition, 0);
        arrowPath.lineTo((float) (arrowPosition - ah * 0.75), ah + 10);
        arrowPath.lineTo((float) (arrowPosition + ah * 0.75), ah + 10);
        arrowPath.close();
    }

    paint.setColor(this.strokeColor);
    paint.setStyle(Paint.Style.FILL);
    boxPath.addPath(arrowPath);
    canvas.drawPath(boxPath, paint);

    paint.setColor(this.boxColor);
    paint.setStyle(Paint.Style.FILL);
    boxPath.addPath(arrowPath);
    canvas.save();
    float sf = 0.995f;
    float ox = (this.getWidth() - (this.getWidth() * sf)) / 2.0f;
    float oy = ((this.getHeight() - arrowHeight) - ((this.getHeight() - arrowHeight) * sf)) / 2.0f;

    canvas.translate(ox, oy);
    canvas.scale(sf, sf);
    canvas.drawPath(boxPath, paint);
    canvas.restore();

    if (layoutChanged) {
        this.recalcLayout();
        layoutChanged = false;
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

static Path cn1ShapeToAndroidPath(com.codename1.ui.geom.Shape shape) {
    return cn1ShapeToAndroidPath(shape, new Path());
}