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

The following examples show how to use android.graphics.Path#isEmpty() . 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: BorderColorDrawable.java    From litho with Apache License 2.0 5 votes vote down vote up
private static void drawBorder(
    Canvas canvas, RectF bounds, Path path, float[] radii, Paint paint) {
  float maxRadii = Math.min(bounds.width(), bounds.height()) / 2f;
  if (path == null) {
    // All radii are the same
    float radius = Math.min(maxRadii, radii[0]);
    canvas.drawRoundRect(bounds, radius, radius, paint);
  } else {
    if (path.isEmpty()) {
      path.addRoundRect(bounds, radii, Path.Direction.CW);
    }
    canvas.drawPath(path, paint);
  }
}
 
Example 2
Source File: OC_SectionController.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public OBPath StarWithScale(float scale,boolean shadow)
{
    Path starpath = new Path();
    boolean outer = true;
    PointF pt = new PointF();
    for (double ang = -(Math.PI);ang < Math.PI;ang += (2.0 * Math.PI / 10.0))
    {
        double cosang = Math.cos(ang);
        double sinang = Math.sin(ang);
        if (outer)
            pt.set((float) cosang, (float) sinang);
        else
            pt.set((float)cosang*0.5f, (float)sinang*0.5f);
        pt.x += 1.0;
        pt.y += 1.0;
        pt.x *= scale;
        pt.y *= scale;
        outer = !outer;
        if (starpath.isEmpty())
            starpath.moveTo(pt.x,pt.y);
        else
            starpath.lineTo(pt.x,pt.y);
    }
    starpath.close();
    Matrix m = new Matrix();
    m.postRotate(28.87f);
    starpath.transform(m);
    OBPath p = new OBPath(starpath);
    p.sizeToBoundingBoxIncludingStroke();
    float r = 1.0f,g = 216.0f/255.0f,b = 0.0f;
    p.setFillColor(Color.argb(255, (int) (r * 255), (int) (g * 255), (int) (b * 255)));
    p.setStrokeColor(Color.argb((int)(0.7*255),(int)(r*0.7*255),(int)(g*0.7*255),(int)(b*0.7*255)));
    p.setZPosition(200);
    return p;
}
 
Example 3
Source File: PathShape.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * Shape表示内容を定義するPathを設定する
 * @param path
 */
public void setPath(final Path path) {
	mPath.reset();
	if (path != null && !path.isEmpty()) {
		mPath.addPath(path);
	}
}
 
Example 4
Source File: Graphics.java    From youtube-play-icon with MIT License 5 votes vote down vote up
static void inRect(@NonNull Path into, @NonNull float[] pathData) {
  if (!into.isEmpty()) into.rewind();

  into.moveTo(pathData[0], pathData[1]); // top left
  into.lineTo(pathData[2], pathData[3]); // top right
  into.lineTo(pathData[4], pathData[5]); // bottom right
  into.lineTo(pathData[6], pathData[7]); // bottom left
}
 
Example 5
Source File: PathKeyframes.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public PathKeyframes(Path path, float error) {
    if (path == null || path.isEmpty()) {
        throw new IllegalArgumentException("The path must not be null or empty");
    }
    mKeyframeData = path.approximate(error);
}
 
Example 6
Source File: Keyframes.java    From PathLayoutManager with Apache License 2.0 4 votes vote down vote up
private void initPath(Path path) {
    if (path == null || path.isEmpty()) {
        throw new NullPointerException("path is empty!");
    }
    final PathMeasure pathMeasure = new PathMeasure(path, false);
    mX = new float[0];
    mY = new float[0];
    mAngle = new float[0];
    do {
        final float pathLength = pathMeasure.getLength();
        final int numPoints = (int) (pathLength / PRECISION) + 1;
        final float[] x = new float[numPoints];
        final float[] y = new float[numPoints];
        final float[] angle = new float[numPoints];
        final float[] position = new float[2];
        final float[] tangent = new float[2];
        for (int i = 0; i < numPoints; ++i) {
            final float distance = (i * pathLength) / (numPoints - 1);
            pathMeasure.getPosTan(distance, position, tangent);
            if (position[0] > mMaxX) {
                mMaxX = position[0];
            }
            if (position[1] > mMaxY) {
                mMaxY = position[1];
            }
            x[i] = position[0];
            y[i] = position[1];
            angle[i] = fixAngle((float) (Math.atan2(tangent[1], tangent[0]) * 180F / Math.PI));
        }
        mNumPoints += numPoints;

        float[] tmpX = new float[mX.length + x.length];
        System.arraycopy(mX, 0, tmpX, 0, mX.length);
        System.arraycopy(x, 0, tmpX, mX.length, x.length);
        mX = tmpX;

        float[] tmpY = new float[mY.length + y.length];
        System.arraycopy(mY, 0, tmpY, 0, mY.length);
        System.arraycopy(y, 0, tmpY, mY.length, y.length);
        mY = tmpY;

        float[] tmpAngle = new float[mAngle.length + angle.length];
        System.arraycopy(mAngle, 0, tmpAngle, 0, mAngle.length);
        System.arraycopy(angle, 0, tmpAngle, mAngle.length, angle.length);
        mAngle = tmpAngle;
    } while (pathMeasure.nextContour());
}