Java Code Examples for android.graphics.Path#addPath()

The following examples show how to use android.graphics.Path#addPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SVGAndroidRenderer.java    From XDroidAnimation with Apache License 2.0 6 votes vote down vote up
private void addObjectToClip(SVG.Path obj, Path combinedPath, Matrix combinedPathMatrix)
{
   updateStyleForElement(state, obj);

   if (!display())
      return;
   if (!visible())
      return;

   if (obj.transform != null)
      combinedPathMatrix.preConcat(obj.transform);

   Path  path = (new PathConverter(obj.d)).getPath();

   if (obj.boundingBox == null) {
      obj.boundingBox = calculatePathBounds(path);
   }
   checkForClipPath(obj);

   //path.setFillType(getClipRuleFromState());
   combinedPath.setFillType(getClipRuleFromState());
   combinedPath.addPath(path, combinedPathMatrix);
}
 
Example 2
Source File: DynamicPageIndicator.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
private void drawUnselected(Canvas canvas) {
    combinedUnselectedPath.rewind();

    // draw any settled, revealing or joining dots
    for (int page = 0; page < pageCount; page++) {
        int nextXIndex = page == pageCount - 1 ? page : page + 1;
        Path unselectedPath = getUnselectedPath(page,
                dotCenterX[page],
                dotCenterX[nextXIndex],
                page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                dotRevealFractions[page]);
        unselectedPath.addPath(combinedUnselectedPath);
        combinedUnselectedPath.addPath(unselectedPath);
    }
    // draw any retreating joins
    if (retreatingJoinX1 != INVALID_FRACTION) {
        Path retreatingJoinPath = getRetreatingJoinPath();
        combinedUnselectedPath.addPath(retreatingJoinPath);
    }

    canvas.drawPath(combinedUnselectedPath, unselectedPaint);
}
 
Example 3
Source File: InkPageIndicator.java    From InkPageIndicator with Apache License 2.0 6 votes vote down vote up
private void drawUnselected(Canvas canvas) {

        combinedUnselectedPath.rewind();

        // draw any settled, revealing or joining dots
        for (int page = 0; page < pageCount; page++) {
            int nextXIndex = page == pageCount - 1 ? page : page + 1;
            Path unselectedPath = getUnselectedPath(page,
                    dotCenterX[page],
                    dotCenterX[nextXIndex],
                    page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                    dotRevealFractions[page]);
            unselectedPath.addPath(combinedUnselectedPath);
            combinedUnselectedPath.addPath(unselectedPath);
        }
        // draw any retreating joins
        if (retreatingJoinX1 != INVALID_FRACTION) {
            Path retreatingJoinPath = getRetreatingJoinPath();
            combinedUnselectedPath.addPath(retreatingJoinPath);
        }

        canvas.drawPath(combinedUnselectedPath, unselectedPaint);
    }
 
Example 4
Source File: InkPageIndicator.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void drawUnselected(Canvas canvas) {

        combinedUnselectedPath.rewind();

        // draw any settled, revealing or joining dots
        for (int page = 0; page < pageCount; page++) {
            int nextXIndex = page == pageCount - 1 ? page : page + 1;
            Path unselectedPath = getUnselectedPath(page,
                    dotCenterX[page],
                    dotCenterX[nextXIndex],
                    page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                    dotRevealFractions[page]);
            unselectedPath.addPath(combinedUnselectedPath);
            combinedUnselectedPath.addPath(unselectedPath);
        }
        // draw any retreating joins
        if (retreatingJoinX1 != INVALID_FRACTION) {
            Path retreatingJoinPath = getRetreatingJoinPath();
            combinedUnselectedPath.addPath(retreatingJoinPath);
        }

        canvas.drawPath(combinedUnselectedPath, unselectedPaint);
    }
 
Example 5
Source File: SVGAndroidRenderer.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
private void addObjectToClip(SVG.Path obj, Path combinedPath, Matrix combinedPathMatrix)
{
   updateStyleForElement(state, obj);

   if (!display())
      return;
   if (!visible())
      return;

   if (obj.transform != null)
      combinedPathMatrix.preConcat(obj.transform);

   Path  path = (new PathConverter(obj.d)).getPath();

   if (obj.boundingBox == null) {
      obj.boundingBox = calculatePathBounds(path);
   }
   checkForClipPath(obj);

   //path.setFillType(getClipRuleFromState());
   combinedPath.setFillType(getClipRuleFromState());
   combinedPath.addPath(path, combinedPathMatrix);
}
 
Example 6
Source File: InkPageIndicator.java    From ForPDA with GNU General Public License v3.0 6 votes vote down vote up
private void drawUnselected(Canvas canvas) {

        combinedUnselectedPath.rewind();

        // draw any settled, revealing or joining dots
        for (int page = 0; page < pageCount; page++) {
            int nextXIndex = page == pageCount - 1 ? page : page + 1;
            Path unselectedPath = getUnselectedPath(page,
                    dotCenterX[page],
                    dotCenterX[nextXIndex],
                    page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                    dotRevealFractions[page]);
            unselectedPath.addPath(combinedUnselectedPath);
            combinedUnselectedPath.addPath(unselectedPath);
        }
        // draw any retreating joins
        if (retreatingJoinX1 != INVALID_FRACTION) {
            Path retreatingJoinPath = getRetreatingJoinPath();
            combinedUnselectedPath.addPath(retreatingJoinPath);
        }

        canvas.drawPath(combinedUnselectedPath, unselectedPaint);
    }
 
Example 7
Source File: InkPageIndicator.java    From andela-crypto-app with Apache License 2.0 6 votes vote down vote up
private void drawUnselected(Canvas canvas) {

        combinedUnselectedPath.rewind();

        // draw any settled, revealing or joining dots
        for (int page = 0; page < pageCount; page++) {
            int nextXIndex = page == pageCount - 1 ? page : page + 1;
            Path unselectedPath = getUnselectedPath(page,
                    dotCenterX[page],
                    dotCenterX[nextXIndex],
                    page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                    dotRevealFractions[page]);
            unselectedPath.addPath(combinedUnselectedPath);
            combinedUnselectedPath.addPath(unselectedPath);
        }
        // draw any retreating joins
        if (retreatingJoinX1 != INVALID_FRACTION) {
            Path retreatingJoinPath = getRetreatingJoinPath();
            combinedUnselectedPath.addPath(retreatingJoinPath);
        }

        canvas.drawPath(combinedUnselectedPath, unselectedPaint);
    }
 
Example 8
Source File: SVGAndroidRenderer.java    From starcor.xul with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void addObjectToClip(SVG.Path obj, Path combinedPath, Matrix combinedPathMatrix)
{
   updateStyleForElement(state, obj);

   if (!display())
      return;
   if (!visible())
      return;

   if (obj.transform != null)
      combinedPathMatrix.preConcat(obj.transform);

   Path  path = (new PathConverter(obj.d)).getPath();

   if (obj.boundingBox == null) {
      obj.boundingBox = calculatePathBounds(path);
   }
   checkForClipPath(obj);

   //path.setFillType(getClipRuleFromState());
   combinedPath.setFillType(getClipRuleFromState());
   combinedPath.addPath(path, combinedPathMatrix);
}
 
Example 9
Source File: ShapeWriter.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
private PathShape toShape(MultiLineString mls) {
    Path path = new Path();

    for (int i = 0; i < mls.getNumGeometries(); i++) {
        LineString lineString = (LineString) mls.getGeometryN(i);
        PathShape shape = toShape(lineString);
        path.addPath(shape.getPath());
    }
    return new PathShape(path);
}
 
Example 10
Source File: Renderer.java    From Tehreer-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Generates the path of the specified glyph.
 *
 * @param glyphId The ID of glyph whose path is generated.
 * @return The path of the glyph specified by <code>glyphId</code>.
 */
public @NonNull Path generatePath(int glyphId) {
    Path glyphPath = new Path();
    glyphPath.addPath(getGlyphPath(glyphId));

    return glyphPath;
}
 
Example 11
Source File: InkPageIndicator.java    From AsteroidOSSync with GNU General Public License v3.0 5 votes vote down vote up
private void drawUnselected(Canvas canvas) {
    combinedUnselectedPath.rewind();

    for (int page = 0; page < pageCount; page++) {
        int nextXIndex;

        if (page == pageCount - 1) {
            nextXIndex = page;
        } else {
            nextXIndex = page + 1;
        }

        Path unselectedPath = getUnselectedPath(page,
                dotCenterX[page],
                dotCenterX[nextXIndex],
                page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                dotRevealFractions[page]);

        unselectedPath.addPath(combinedUnselectedPath);
        combinedUnselectedPath.addPath(unselectedPath);
    }

    if (retreatingJoinX1 != INVALID_FRACTION) {
        Path retreatingJoinPath = getRetreatingJoinPath();
        combinedUnselectedPath.addPath(retreatingJoinPath);
    }

    canvas.drawPath(combinedUnselectedPath, unselectedPaint);
}
 
Example 12
Source File: SVGAndroidRenderer.java    From starcor.xul with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addObjectToClip(SVG.Text obj, Path combinedPath, Matrix combinedPathMatrix)
{
   updateStyleForElement(state, obj);

   if (!display())
      return;

   if (obj.transform != null)
      combinedPathMatrix.preConcat(obj.transform);

   // Get the first coordinate pair from the lists in the x and y properties.
   float  x = (obj.x == null || obj.x.size() == 0) ? 0f : obj.x.get(0).floatValueX(this);
   float  y = (obj.y == null || obj.y.size() == 0) ? 0f : obj.y.get(0).floatValueY(this);
   float  dx = (obj.dx == null || obj.dx.size() == 0) ? 0f : obj.dx.get(0).floatValueX(this);
   float  dy = (obj.dy == null || obj.dy.size() == 0) ? 0f : obj.dy.get(0).floatValueY(this);

   // Handle text alignment
   if (state.style.textAnchor != Style.TextAnchor.Start) {
      float  textWidth = calculateTextWidth(obj);
      if (state.style.textAnchor == Style.TextAnchor.Middle) {
         x -= (textWidth / 2);
      } else {
         x -= textWidth;  // 'End' (right justify)
      }
   }

   if (obj.boundingBox == null) {
      TextBoundsCalculator  proc = new TextBoundsCalculator(x, y);
      enumerateTextSpans(obj, proc);
      obj.boundingBox = new Box(proc.bbox.left, proc.bbox.top, proc.bbox.width(), proc.bbox.height());
   }
   checkForClipPath(obj);

   Path  textAsPath = new Path();
   enumerateTextSpans(obj, new PlainTextToPath(x + dx, y + dy, textAsPath));

   combinedPath.setFillType(getClipRuleFromState());
   combinedPath.addPath(textAsPath, combinedPathMatrix);
}
 
Example 13
Source File: TutorialView.java    From cloud-cup-android with Apache License 2.0 5 votes vote down vote up
private void generatePath(){
    Path pAnimated = new Path();
    Path pNoAnimated = new Path();
    for (Arrow a : this.arrows)
        if(a.getAnimated()) pAnimated.addPath(a.getPath());
        else pNoAnimated.addPath(a.getPath());

    this.pathAnimated = pAnimated;
    this.pathNoAnimation = pNoAnimated;
}
 
Example 14
Source File: SVGAndroidRenderer.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
private void addObjectToClip(SVG.GraphicsElement obj, Path combinedPath, Matrix combinedPathMatrix)
{
   updateStyleForElement(state, obj);

   if (!display())
      return;
   if (!visible())
      return;

   if (obj.transform != null)
      combinedPathMatrix.preConcat(obj.transform);

   Path  path;
   if (obj instanceof SVG.Rect)
      path = makePathAndBoundingBox((SVG.Rect) obj);
   else if (obj instanceof SVG.Circle)
      path = makePathAndBoundingBox((SVG.Circle) obj);
   else if (obj instanceof SVG.Ellipse)
      path = makePathAndBoundingBox((SVG.Ellipse) obj);
   else if (obj instanceof SVG.PolyLine)
      path = makePathAndBoundingBox((SVG.PolyLine) obj);
   else
      return;

   checkForClipPath(obj);

   combinedPath.setFillType(getClipRuleFromState());
   combinedPath.addPath(path, combinedPathMatrix);
}
 
Example 15
Source File: UPath.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public Path bezierPath()
{
    Path bez = new Path();
    for (USubPath sp : subPaths)
        bez.addPath(sp.bezierPath());
    return bez;
}
 
Example 16
Source File: DynamicPageIndicator2.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
private void drawUnselected(Canvas canvas) {
    combinedUnselectedPath.rewind();

    // draw any settled, revealing or joining dots
    for (int page = 0; page < pageCount; page++) {
        int nextXIndex = page == pageCount - 1 ? page : page + 1;
        Path unselectedPath;
        if (!isRTL()) {
            unselectedPath = getUnselectedPath(page,
                    dotCenterX[page],
                    dotCenterX[nextXIndex],
                    page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                    dotRevealFractions[page]);
        } else {
            unselectedPath = getUnselectedPath(page,
                    dotCenterX[nextXIndex],
                    dotCenterX[page],
                    page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                    dotRevealFractions[page]);
        }
        unselectedPath.addPath(combinedUnselectedPath);
        combinedUnselectedPath.addPath(unselectedPath);
    }
    // draw any retreating joins
    if (retreatingJoinX1 != INVALID_FRACTION) {
        Path retreatingJoinPath = getRetreatingJoinPath();
        combinedUnselectedPath.addPath(retreatingJoinPath);
    }

    canvas.drawPath(combinedUnselectedPath, unselectedPaint);
}
 
Example 17
Source File: SVGAndroidRenderer.java    From XDroidAnimation with Apache License 2.0 5 votes vote down vote up
private void addObjectToClip(SVG.GraphicsElement obj, Path combinedPath, Matrix combinedPathMatrix)
{
   updateStyleForElement(state, obj);

   if (!display())
      return;
   if (!visible())
      return;

   if (obj.transform != null)
      combinedPathMatrix.preConcat(obj.transform);

   Path  path;
   if (obj instanceof SVG.Rect)
      path = makePathAndBoundingBox((SVG.Rect) obj);
   else if (obj instanceof SVG.Circle)
      path = makePathAndBoundingBox((SVG.Circle) obj);
   else if (obj instanceof SVG.Ellipse)
      path = makePathAndBoundingBox((SVG.Ellipse) obj);
   else if (obj instanceof SVG.PolyLine)
      path = makePathAndBoundingBox((SVG.PolyLine) obj);
   else
      return;

   checkForClipPath(obj);

   combinedPath.setFillType(path.getFillType());
   combinedPath.addPath(path, combinedPathMatrix);
}
 
Example 18
Source File: GISDisplay.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void drawTextOnPath(
        String text,
        Path path,
        float hOffset,
        float vOffset,
        Paint paint)
{
    if (null == mMainCanvas) {
        return;
    }

    PathMeasure pm = new PathMeasure(path, false);
    Matrix matrix = new Matrix();
    Path charPath = new Path();
    Path textPath = new Path();

    float pathLength = pm.getLength();
    float coordinates[] = new float[2];
    float tangent[] = new float[2];

    int i = 0;
    float position = hOffset;

    while (i < text.length()) {
        String ch = text.substring(i, i + 1);
        float charWidth = paint.measureText(ch);

        float nextPosition = position + charWidth;
        if (nextPosition > pathLength) {
            break;
        }

        pm.getPosTan(position + charWidth / 2, coordinates, tangent);
        float rotateAngle = (float) Math.toDegrees(
                Math.atan2((double) tangent[1], (double) tangent[0]));

        charPath.reset();
        paint.getTextPath(ch, 0, ch.length(), -charWidth / 2, vOffset, charPath);
        charPath.close(); // workaround

        matrix.reset();
        matrix.postScale(1, -1, 0, 0);
        matrix.postRotate(rotateAngle, 0, 0);
        matrix.postTranslate(coordinates[0], coordinates[1]);

        textPath.addPath(charPath, matrix);

        ++i;
        position = nextPosition;
    }

    mMainCanvas.drawPath(textPath, paint);

    // for debug
    //mMainCanvas.drawTextOnPath(text, path, hOffset, vOffset, paint);
}
 
Example 19
Source File: Speaker.java    From FuckingVolumeSlider with GNU General Public License v3.0 4 votes vote down vote up
void fillPath(Path path) {
    base.fillPath(path);
    path.addPath(wawes.get(0).getPath());
    path.addPath(wawes.get(1).getPath());
}
 
Example 20
Source File: BrokenAnimator.java    From BrokenView with MIT License 4 votes vote down vote up
/**
 * Build the final bitmap-pieces to draw in animation
 */
private void buildPieces(){
    pieces = new Piece[pathArray.size()];
    Paint paint = new Paint();
    Matrix matrix = new Matrix();
    Canvas canvas = new Canvas();
    for(int i = 0; i < pieces.length; i++) {
        int shadow = Utils.nextInt(Utils.dp2px(2),Utils.dp2px(9));
        Path path = pathArray.get(i);
        RectF r = new RectF();
        path.computeBounds(r, true);

        Bitmap pBitmap = Utils.createBitmapSafely((int)r.width() + shadow * 2,
                (int)r.height() + shadow * 2, Bitmap.Config.ARGB_4444,1);
        if(pBitmap == null){
            pieces[i] = new Piece(-1, -1, null, shadow);
            continue;
        }
        pieces[i] = new Piece((int)r.left + mTouchPoint.x - shadow,
                (int)r.top + mTouchPoint.y - shadow, pBitmap, shadow);
        canvas.setBitmap(pieces[i].bitmap);
        BitmapShader mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        matrix.reset();
        matrix.setTranslate(-r.left - offsetX + shadow, -r.top - offsetY + shadow);
        mBitmapShader.setLocalMatrix(matrix);

        paint.reset();
        Path offsetPath = new Path();
        offsetPath.addPath(path, -r.left + shadow, -r.top + shadow);

        // Draw shadow
        paint.setStyle(Paint.Style.FILL);
        paint.setShadowLayer(shadow,0,0,0xff333333);
        canvas.drawPath(offsetPath,paint);
        paint.setShadowLayer(0,0,0,0);

        // In case the view has alpha channel
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));
        canvas.drawPath(offsetPath,paint);
        paint.setXfermode(null);

        // Draw bitmap
        paint.setShader(mBitmapShader);
        paint.setAlpha(0xcc);
        canvas.drawPath(offsetPath, paint);
    }
    // Sort by shadow
    Arrays.sort(pieces);
}