Java Code Examples for android.graphics.Paint#reset()

The following examples show how to use android.graphics.Paint#reset() . 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: ImageUtils.java    From RelaxFinger with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 转换图片成圆形
 *
 * @param bitmap
 *            传入Bitmap对象
 *
 * @param size
 *            大小
 * @return
 */
public static Bitmap drawCircleView(Bitmap bitmap,int size){

    //前面同上,绘制图像分别需要bitmap,canvas,paint对象
    bitmap = Bitmap.createScaledBitmap(bitmap, size, size, true);//==========创建的图片的长宽为128
    Bitmap bm = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);//此处的长宽应该与上一行保持一致
    Canvas canvas = new Canvas(bm);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    //这里需要先画出一个圆
    canvas.drawCircle(size/2, size/2, size/2, paint);//===========此处应该为上面长宽的一半
    //圆画好之后将画笔重置一下
    paint.reset();
    //设置图像合成模式,该模式为只在源图像和目标图像相交的地方绘制源图像
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return bm;
}
 
Example 2
Source File: WXSvgPath.java    From Svg-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up paint according to the props set on a shadow view. Returns {@code true}
 * if the stroke should be drawn, {@code false} if not.
 */
protected boolean setupStrokePaint(Paint paint, float opacity, @Nullable RectF box) {
  paint.reset();
  if (TextUtils.isEmpty(mStrokeColor)) {
    return false;
  }

  paint.setFlags(Paint.ANTI_ALIAS_FLAG);
  paint.setStyle(Paint.Style.STROKE);
  paint.setStrokeCap(mStrokeLinecap);
  paint.setStrokeJoin(mStrokeLinejoin);
  paint.setStrokeMiter(mStrokeMiterlimit * mScale);
  paint.setStrokeWidth(mStrokeWidth * mScale);
  setupPaint(paint, opacity, mStrokeColor, box);

  if (mStrokeDasharray != null && mStrokeDasharray.length > 0) {
    paint.setPathEffect(new DashPathEffect(mStrokeDasharray, mStrokeDashoffset));
  }

  return true;
}
 
Example 3
Source File: IconUtil.java    From paper-launcher with MIT License 5 votes vote down vote up
private static Bitmap addShadow(final Bitmap bm, final int dstHeight, final int dstWidth,
                                int color, int size, float dx, float dy) {
    final Bitmap mask = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ALPHA_8);

    final Matrix scaleToFit = new Matrix();
    final RectF src = new RectF(0, 0, bm.getWidth(), bm.getHeight());
    final RectF dst = new RectF(0, 0, dstWidth - dx, dstHeight - dy);
    scaleToFit.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);

    final Matrix dropShadow = new Matrix(scaleToFit);
    dropShadow.postTranslate(dx, dy);

    final Canvas maskCanvas = new Canvas(mask);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    maskCanvas.drawBitmap(bm, scaleToFit, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
    maskCanvas.drawBitmap(bm, dropShadow, paint);

    final BlurMaskFilter filter = new BlurMaskFilter(size, BlurMaskFilter.Blur.NORMAL);
    paint.reset();
    paint.setAntiAlias(true);
    paint.setColor(color);
    paint.setMaskFilter(filter);
    paint.setFilterBitmap(true);

    final Bitmap ret = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ARGB_8888);
    final Canvas retCanvas = new Canvas(ret);
    retCanvas.drawBitmap(mask, 0, 0, paint);
    retCanvas.drawBitmap(bm, scaleToFit, null);
    mask.recycle();
    return ret;
}
 
Example 4
Source File: PDFRenderer.java    From PdfBox-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the given page as an RGB image at the given scale.
 * @param pageIndex the zero-based index of the page to be converted
 * @param scale the scaling factor, where 1 = 72 DPI
    * @param config the bitmap config to create
 * @return the rendered page image
 * @throws IOException if the PDF cannot be read
 */
public Bitmap renderImage(int pageIndex, float scale, Bitmap.Config config) throws IOException
{
	PDPage page = document.getPage(pageIndex);

       PDRectangle cropbBox = page.getCropBox();
       float widthPt = cropbBox.getWidth();
       float heightPt = cropbBox.getHeight();
       int widthPx = Math.round(widthPt * scale);
       int heightPx = Math.round(heightPt * scale);
       int rotationAngle = page.getRotation();

       // swap width and height
       Bitmap image;
       if (rotationAngle == 90 || rotationAngle == 270)
       {
           image = Bitmap.createBitmap(heightPx, widthPx, config);
       }
       else
       {
           image = Bitmap.createBitmap(widthPx, heightPx, config);
       }

       // use a transparent background if the imageType supports alpha
       Paint paint = new Paint();
       Canvas canvas = new Canvas(image);
       if (config != Bitmap.Config.ARGB_8888)
       {
           paint.setColor(Color.WHITE);
           paint.setStyle(Paint.Style.FILL);
           canvas.drawRect(0, 0, image.getWidth(), image.getHeight(), paint);
           paint.reset();
       }

       renderPage(page, paint, canvas, image.getWidth(), image.getHeight(), scale, scale);

       return image;
}
 
Example 5
Source File: SideBar.java    From SweetMusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	// TODO Auto-generated method stub
	super.onDraw(canvas);
	
	int height=getHeight();
	int width=getWidth();
	int singleHeight=height/abc.length;
	
	Paint paint=new Paint();
	
	for(int i=0;i<abc.length;i++){
		paint.setColor(Color.rgb(33, 65, 98));  	//设置画笔颜色
		paint.setTypeface(Typeface.DEFAULT_BOLD);	//设置加粗
		
		paint.setAntiAlias(true);
		paint.setTextSize(20);
		
		if(i==choose){
			paint.setColor(Color.parseColor("#3399ff"));  
               paint.setFakeBoldText(true);  
		}
		
		//计算坐标
		float x=width/2-paint.measureText(abc[i])/2;
		float y=(i+1)*singleHeight;
		
		canvas.drawText(abc[i], x, y, paint);
	}
 
	//重置画笔
	paint.reset();
}
 
Example 6
Source File: LauncherIconHelper.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds a shadow to a Bitmap.
 * <p>
 * TODO: Make this return Drawable for our use case.
 *
 * @param drawable  Drawable that should be used as the foreground layer
 *                  of the shadow.
 * @param dstHeight Height of the returned bitmap.
 * @param dstWidth  Width of the returned bitmap.
 * @param color     Colour of the drawn shadow.
 * @param size      Size of the drawn shadow.
 * @param dx        Shadow x direction.
 * @param dy        Shadow y direction.
 *
 * @return Bitmap with resulting shadow.
 *
 * @author schwiz (https://stackoverflow.com/a/24579764)
 */
private static Bitmap addShadow(final Drawable drawable, final int dstHeight, final int dstWidth, int color, int size, float dx, float dy) {
    final Bitmap bm = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bm);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    final Bitmap mask = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ALPHA_8);

    final Matrix scaleToFit = new Matrix();
    final RectF src = new RectF(0, 0, bm.getWidth(), bm.getHeight());
    final RectF dst = new RectF(0, 0, dstWidth - dx, dstHeight - dy);
    scaleToFit.setRectToRect(src, dst, Matrix.ScaleToFit.FILL);

    final Matrix dropShadow = new Matrix(scaleToFit);
    dropShadow.postTranslate(dx, dy);

    final Canvas maskCanvas = new Canvas(mask);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    maskCanvas.drawBitmap(bm, scaleToFit, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
    maskCanvas.drawBitmap(bm, dropShadow, paint);

    final BlurMaskFilter filter = new BlurMaskFilter(size, BlurMaskFilter.Blur.SOLID);
    paint.reset();
    paint.setAntiAlias(true);
    paint.setColor(color);
    paint.setMaskFilter(filter);
    paint.setFilterBitmap(true);

    final Bitmap ret = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ARGB_8888);
    final Canvas retCanvas = new Canvas(ret);
    retCanvas.drawBitmap(mask, 0, 0, paint);
    retCanvas.drawBitmap(bm, scaleToFit, null);
    mask.recycle();
    return ret;
}
 
Example 7
Source File: Utils.java    From RangeSeekBar with Apache License 2.0 5 votes vote down vote up
public static Rect measureText(String text, float textSize) {
    Paint paint = new Paint();
    Rect textRect = new Rect();
    paint.setTextSize(textSize);
    paint.getTextBounds(text, 0, text.length(), textRect);
    paint.reset();
    return textRect;
}
 
Example 8
Source File: LauncherIconHelper.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds a shadow to a Bitmap.
 * <p>
 * TODO: Make this return Drawable for our use case.
 *
 * @param drawable  Drawable that should be used as the foreground layer
 *                  of the shadow.
 * @param dstHeight Height of the returned bitmap.
 * @param dstWidth  Width of the returned bitmap.
 * @param color     Colour of the drawn shadow.
 * @param size      Size of the drawn shadow.
 * @param dx        Shadow x direction.
 * @param dy        Shadow y direction.
 *
 * @return Bitmap with resulting shadow.
 *
 * @author schwiz (https://stackoverflow.com/a/24579764)
 */
private static Bitmap addShadow(final Drawable drawable, final int dstHeight, final int dstWidth, int color, int size, float dx, float dy) {
    final Bitmap bm = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bm);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    final Bitmap mask = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ALPHA_8);

    final Matrix scaleToFit = new Matrix();
    final RectF src = new RectF(0, 0, bm.getWidth(), bm.getHeight());
    final RectF dst = new RectF(0, 0, dstWidth - dx, dstHeight - dy);
    scaleToFit.setRectToRect(src, dst, Matrix.ScaleToFit.FILL);

    final Matrix dropShadow = new Matrix(scaleToFit);
    dropShadow.postTranslate(dx, dy);

    final Canvas maskCanvas = new Canvas(mask);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    maskCanvas.drawBitmap(bm, scaleToFit, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
    maskCanvas.drawBitmap(bm, dropShadow, paint);

    final BlurMaskFilter filter = new BlurMaskFilter(size, BlurMaskFilter.Blur.SOLID);
    paint.reset();
    paint.setAntiAlias(true);
    paint.setColor(color);
    paint.setMaskFilter(filter);
    paint.setFilterBitmap(true);

    final Bitmap ret = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ARGB_8888);
    final Canvas retCanvas = new Canvas(ret);
    retCanvas.drawBitmap(mask, 0, 0, paint);
    retCanvas.drawBitmap(bm, scaleToFit, null);
    mask.recycle();
    return ret;
}
 
Example 9
Source File: WXSvgPath.java    From Svg-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up paint according to the props set on a shadow view. Returns {@code true}
 * if the fill should be drawn, {@code false} if not.
 */
protected boolean setupFillPaint(Paint paint, float opacity, @Nullable RectF box) {
  if (!TextUtils.isEmpty(mFillColor)) {
    paint.reset();
    //paint.setColor(SvgParser.parseColor(mFillColor));
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    setupPaint(paint, opacity, mFillColor, box);
    return true;
  }
  return false;
}
 
Example 10
Source File: ARTShapeShadowNode.java    From react-native-GPay with MIT License 4 votes vote down vote up
/**
 * Sets up {@link #mPaint} according to the props set on a shadow view. Returns {@code true}
 * if the fill should be drawn, {@code false} if not.
 */
protected boolean setupFillPaint(Paint paint, float opacity) {
  if (mBrushData != null && mBrushData.length > 0) {
    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    int colorType = (int) mBrushData[0];
    switch (colorType) {
      case COLOR_TYPE_SOLID_COLOR:
        paint.setARGB(
            (int) (mBrushData.length > 4 ? mBrushData[4] * opacity * 255 : opacity * 255),
            (int) (mBrushData[1] * 255),
            (int) (mBrushData[2] * 255),
            (int) (mBrushData[3] * 255));
        break;
      case COLOR_TYPE_LINEAR_GRADIENT:
        // For mBrushData format refer to LinearGradient and insertColorStopsIntoArray functions in ReactNativeART.js
        if (mBrushData.length < 5) {
          FLog.w(ReactConstants.TAG,
            "[ARTShapeShadowNode setupFillPaint] expects 5 elements, received "
            + mBrushData.length);
          return false;
        }
        float gradientStartX = mBrushData[1] * mScale;
        float gradientStartY = mBrushData[2] * mScale;
        float gradientEndX = mBrushData[3] * mScale;
        float gradientEndY = mBrushData[4] * mScale;
        int stops = (mBrushData.length - 5) / 5;
        int[] colors = null;
        float[] positions = null;
        if (stops > 0) {
          colors = new int[stops];
          positions = new float[stops];
          for (int i=0; i<stops; i++) {
            positions[i] = mBrushData[5 + 4*stops + i];
            int r = (int) (255 * mBrushData[5 + 4*i + 0]);
            int g = (int) (255 * mBrushData[5 + 4*i + 1]);
            int b = (int) (255 * mBrushData[5 + 4*i + 2]);
            int a = (int) (255 * mBrushData[5 + 4*i + 3]);
            colors[i] = Color.argb(a, r, g, b);
          }
        }
        paint.setShader(
          new LinearGradient(
            gradientStartX, gradientStartY,
            gradientEndX, gradientEndY,
            colors, positions,
            Shader.TileMode.CLAMP
          )
        );
        break;
      case COLOR_TYPE_RADIAL_GRADIENT:
        // TODO(6352048): Support radial gradient etc.
      case COLOR_TYPE_PATTERN:
        // TODO(6352048): Support patterns etc.
      default:
        FLog.w(ReactConstants.TAG, "ART: Color type " + colorType + " not supported!");
    }
    return true;
  }
  return false;
}
 
Example 11
Source File: ARTShapeShadowNode.java    From art with MIT License 4 votes vote down vote up
/**
 * Sets up {@link #mPaint} according to the props set on a shadow view. Returns {@code true}
 * if the stroke should be drawn, {@code false} if not.
 */
protected boolean setupStrokePaint(Paint paint, float opacity) {
  if (mStrokeWidth == 0 || mStrokeColor == null) {
    return false;
  }
  paint.reset();
  paint.setFlags(Paint.ANTI_ALIAS_FLAG);
  paint.setStyle(Paint.Style.STROKE);
  switch (mStrokeCap) {
    case CAP_BUTT:
      paint.setStrokeCap(Paint.Cap.BUTT);
      break;
    case CAP_SQUARE:
      paint.setStrokeCap(Paint.Cap.SQUARE);
      break;
    case CAP_ROUND:
      paint.setStrokeCap(Paint.Cap.ROUND);
      break;
    default:
      throw new JSApplicationIllegalArgumentException(
          "strokeCap " + mStrokeCap + " unrecognized");
  }
  switch (mStrokeJoin) {
    case JOIN_MITER:
      paint.setStrokeJoin(Paint.Join.MITER);
      break;
    case JOIN_BEVEL:
      paint.setStrokeJoin(Paint.Join.BEVEL);
      break;
    case JOIN_ROUND:
      paint.setStrokeJoin(Paint.Join.ROUND);
      break;
    default:
      throw new JSApplicationIllegalArgumentException(
          "strokeJoin " + mStrokeJoin + " unrecognized");
  }
  paint.setStrokeWidth(mStrokeWidth * mScale);
  paint.setColor(Color.parseColor(mStrokeColor));
  if (mStrokeDash != null && mStrokeDash.length > 0) {
    paint.setPathEffect(new DashPathEffect(mStrokeDash, 0));
  }
  if (mShadowOpacity > 0) {
    paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor);
  }
  return true;
}
 
Example 12
Source File: ARTShapeShadowNode.java    From react-native-GPay with MIT License 4 votes vote down vote up
/**
 * Sets up {@link #mPaint} according to the props set on a shadow view. Returns {@code true}
 * if the stroke should be drawn, {@code false} if not.
 */
protected boolean setupStrokePaint(Paint paint, float opacity) {
  if (mStrokeWidth == 0 || mStrokeColor == null || mStrokeColor.length == 0) {
    return false;
  }
  paint.reset();
  paint.setFlags(Paint.ANTI_ALIAS_FLAG);
  paint.setStyle(Paint.Style.STROKE);
  switch (mStrokeCap) {
    case CAP_BUTT:
      paint.setStrokeCap(Paint.Cap.BUTT);
      break;
    case CAP_SQUARE:
      paint.setStrokeCap(Paint.Cap.SQUARE);
      break;
    case CAP_ROUND:
      paint.setStrokeCap(Paint.Cap.ROUND);
      break;
    default:
      throw new JSApplicationIllegalArgumentException(
          "strokeCap " + mStrokeCap + " unrecognized");
  }
  switch (mStrokeJoin) {
    case JOIN_MITER:
      paint.setStrokeJoin(Paint.Join.MITER);
      break;
    case JOIN_BEVEL:
      paint.setStrokeJoin(Paint.Join.BEVEL);
      break;
    case JOIN_ROUND:
      paint.setStrokeJoin(Paint.Join.ROUND);
      break;
    default:
      throw new JSApplicationIllegalArgumentException(
          "strokeJoin " + mStrokeJoin + " unrecognized");
  }
  paint.setStrokeWidth(mStrokeWidth * mScale);
  paint.setARGB(
      (int) (mStrokeColor.length > 3 ? mStrokeColor[3] * opacity * 255 : opacity * 255),
      (int) (mStrokeColor[0] * 255),
      (int) (mStrokeColor[1] * 255),
      (int) (mStrokeColor[2] * 255));
  if (mStrokeDash != null && mStrokeDash.length > 0) {
    paint.setPathEffect(new DashPathEffect(mStrokeDash, 0));
  }
  return true;
}
 
Example 13
Source File: LanesStyleKit.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
public static void drawLaneSlightRight(Canvas canvas, RectF targetFrame, ResizingBehavior resizing, int primaryColor, PointF size) {
  // General Declarations
  Stack<Matrix> currentTransformation = new Stack<Matrix>();
  currentTransformation.push(new Matrix());
  Paint paint = CacheForLaneSlightRight.paint;

  // Local Variables
  float expression = Math.min(size.x / 30f, size.y / 30f);

  // Resize to Target Frame
  canvas.save();
  RectF resizedFrame = CacheForLaneSlightRight.resizedFrame;
  LanesStyleKit.resizingBehaviorApply(resizing, CacheForLaneSlightRight.originalFrame, targetFrame, resizedFrame);
  canvas.translate(resizedFrame.left, resizedFrame.top);
  canvas.scale(resizedFrame.width() / 30f, resizedFrame.height() / 30f);

  // Frame
  RectF frame = CacheForLaneSlightRight.frame;
  frame.set(0f, 0f, size.x, size.y);

  // Group
  {
    canvas.save();
    canvas.translate(9.28f, -0.86f);
    currentTransformation.peek().postTranslate(9.28f, -0.86f);
    canvas.scale(expression, expression);
    currentTransformation.peek().postScale(expression, expression);

    // Bezier 3
    RectF bezier3Rect = CacheForLaneSlightRight.bezier3Rect;
    bezier3Rect.set(0f, 10.61f, 7.17f, 27.6f);
    Path bezier3Path = CacheForLaneSlightRight.bezier3Path;
    bezier3Path.reset();
    bezier3Path.moveTo(7.17f, 10.61f);
    bezier3Path.lineTo(1.47f, 15.89f);
    bezier3Path.cubicTo(0.6f, 17.21f, 0f, 18.82f, 0f, 20.47f);
    bezier3Path.lineTo(0f, 27.6f);

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStrokeWidth(4f);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeMiter(10f);
    canvas.save();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(primaryColor);
    canvas.drawPath(bezier3Path, paint);
    canvas.restore();

    // Bezier
    canvas.save();
    canvas.translate(10.25f, 0f);
    currentTransformation.peek().postTranslate(10.25f, 0f);
    canvas.rotate(49f);
    currentTransformation.peek().postRotate(49f);
    RectF bezierRect = CacheForLaneSlightRight.bezierRect;
    bezierRect.set(0f, 0f, 12.02f, 9.99f);
    Path bezierPath = CacheForLaneSlightRight.bezierPath;
    bezierPath.reset();
    bezierPath.moveTo(4.01f, 9.92f);
    bezierPath.lineTo(4.02f, 8.66f);
    bezierPath.lineTo(4.01f, 8.66f);
    bezierPath.cubicTo(4.01f, 8.6f, 4.01f, 8.53f, 4.01f, 8.46f);
    bezierPath.cubicTo(4.01f, 8.17f, 3.82f, 7.94f, 3.53f, 7.94f);
    bezierPath.cubicTo(3.5f, 7.94f, 3.46f, 7.94f, 3.43f, 7.94f);
    bezierPath.lineTo(3.44f, 7.94f);
    bezierPath.lineTo(0.71f, 8.93f);
    bezierPath.lineTo(0.71f, 8.93f);
    bezierPath.cubicTo(0.65f, 8.96f, 0.58f, 8.97f, 0.52f, 8.97f);
    bezierPath.cubicTo(0.23f, 8.97f, 0f, 8.74f, 0f, 8.45f);
    bezierPath.cubicTo(0f, 8.3f, 0.06f, 8.17f, 0.16f, 8.07f);
    bezierPath.lineTo(0.16f, 8.08f);
    bezierPath.lineTo(6.02f, 0f);
    bezierPath.lineTo(11.86f, 8.14f);
    bezierPath.lineTo(11.86f, 8.14f);
    bezierPath.cubicTo(11.96f, 8.23f, 12.02f, 8.37f, 12.02f, 8.52f);
    bezierPath.cubicTo(12.02f, 8.8f, 11.79f, 9.03f, 11.5f, 9.03f);
    bezierPath.cubicTo(11.43f, 9.03f, 11.37f, 9.02f, 11.31f, 8.99f);
    bezierPath.lineTo(11.31f, 8.99f);
    bezierPath.lineTo(8.58f, 8f);
    bezierPath.lineTo(8.59f, 8.01f);
    bezierPath.cubicTo(8.56f, 8f, 8.52f, 8f, 8.49f, 8f);
    bezierPath.cubicTo(8.2f, 8f, 8.01f, 8.23f, 8.01f, 8.53f);
    bezierPath.cubicTo(8.01f, 8.59f, 8f, 8.66f, 8f, 8.73f);
    bezierPath.lineTo(8f, 8.72f);
    bezierPath.lineTo(8.01f, 9.99f);

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    bezierPath.setFillType(Path.FillType.EVEN_ODD);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(primaryColor);
    canvas.drawPath(bezierPath, paint);
    canvas.restore();

    canvas.restore();
  }

  canvas.restore();
}
 
Example 14
Source File: LanesStyleKit.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
public static void drawLaneUturn(Canvas canvas, RectF targetFrame, ResizingBehavior resizing, int primaryColor, PointF size) {
  // General Declarations
  Stack<Matrix> currentTransformation = new Stack<Matrix>();
  currentTransformation.push(new Matrix());
  Paint paint = CacheForLaneUturn.paint;

  // Local Variables
  float expression = Math.min(size.x / 30f, size.y / 30f);

  // Resize to Target Frame
  canvas.save();
  RectF resizedFrame = CacheForLaneUturn.resizedFrame;
  LanesStyleKit.resizingBehaviorApply(resizing, CacheForLaneUturn.originalFrame, targetFrame, resizedFrame);
  canvas.translate(resizedFrame.left, resizedFrame.top);
  canvas.scale(resizedFrame.width() / 30f, resizedFrame.height() / 30f);

  // Frame
  RectF frame = CacheForLaneUturn.frame;
  frame.set(0f, 0f, size.x, size.y);

  // Group
  {
    RectF group = CacheForLaneUturn.group;
    group.set(0f, 0f, 16f, 22f);
    canvas.save();
    canvas.translate(9f, 5f);
    currentTransformation.peek().postTranslate(9f, 5f);
    canvas.scale(expression, expression);
    currentTransformation.peek().postScale(expression, expression);

    // Bezier
    RectF bezierRect = CacheForLaneUturn.bezierRect;
    bezierRect.set(0f, 0f, 10f, 22f);
    Path bezierPath = CacheForLaneUturn.bezierPath;
    bezierPath.reset();
    bezierPath.moveTo(group.left + group.width() * 0.62498f, group.top + group.height() * 0.68182f);
    bezierPath.lineTo(group.left + group.width() * 0.62498f, group.top + group.height() * 0.28459f);
    bezierPath.cubicTo(group.left + group.width() * 0.62498f, group.top + group.height() * 0.20995f, group.left + group.width() * 0.62498f, group.top, group.left + group.width() * 0.31249f, group.top);
    bezierPath.cubicTo(group.left, group.top, group.left, group.top + group.height() * 0.27273f, group.left, group.top + group.height() * 0.27273f);
    bezierPath.lineTo(group.left, group.top + group.height());

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStrokeWidth(4f);
    paint.setStrokeMiter(10f);
    canvas.save();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(primaryColor);
    canvas.drawPath(bezierPath, paint);
    canvas.restore();

    // Bezier 2
    RectF bezier2Rect = CacheForLaneUturn.bezier2Rect;
    bezier2Rect.set(4.01f, 12.99f, 16f, 21.97f);
    Path bezier2Path = CacheForLaneUturn.bezier2Path;
    bezier2Path.reset();
    bezier2Path.moveTo(group.left + group.width() * 0.75119f, group.top + group.height() * 0.59306f);
    bezier2Path.cubicTo(group.left + group.width() * 0.75119f, group.top + group.height() * 0.59306f, group.left + group.width() * 0.7509f, group.top + group.height() * 0.64646f, group.left + group.width() * 0.75088f, group.top + group.height() * 0.65038f);
    bezier2Path.cubicTo(group.left + group.width() * 0.75102f, group.top + group.height() * 0.65333f, group.left + group.width() * 0.75125f, group.top + group.height() * 0.65651f, group.left + group.width() * 0.75125f, group.top + group.height() * 0.65947f);
    bezier2Path.cubicTo(group.left + group.width() * 0.75125f, group.top + group.height() * 0.6727f, group.left + group.width() * 0.76325f, group.top + group.height() * 0.68334f, group.left + group.width() * 0.78144f, group.top + group.height() * 0.68334f);
    bezier2Path.cubicTo(group.left + group.width() * 0.79411f, group.top + group.height() * 0.68135f, group.left + group.width() * 0.95046f, group.top + group.height() * 0.64006f, group.left + group.width() * 0.95744f, group.top + group.height() * 0.63822f);
    bezier2Path.cubicTo(group.left + group.width() * 0.96136f, group.top + group.height() * 0.63708f, group.left + group.width() * 0.9654f, group.top + group.height() * 0.63647f, group.left + group.width() * 0.96962f, group.top + group.height() * 0.63647f);
    bezier2Path.cubicTo(group.left + group.width() * 0.98363f, group.top + group.height() * 0.63647f, group.left + group.width() * 0.99555f, group.top + group.height() * 0.64296f, group.left + group.width() * 1f, group.top + group.height() * 0.65204f);
    bezier2Path.lineTo(group.left + group.width() * 0.99996f, group.top + group.height() * 0.65989f);
    bezier2Path.lineTo(group.left + group.width() * 0.99996f, group.top + group.height() * 0.6679f);
    bezier2Path.cubicTo(group.left + group.width() * 0.99829f, group.top + group.height() * 0.67142f, group.left + group.width() * 0.99548f, group.top + group.height() * 0.67455f, group.left + group.width() * 0.99185f, group.top + group.height() * 0.67704f);
    bezier2Path.cubicTo(group.left + group.width() * 0.98369f, group.top + group.height() * 0.68425f, group.left + group.width() * 0.62595f, group.top + group.height() * 0.9987f, group.left + group.width() * 0.62595f, group.top + group.height() * 0.9987f);
    bezier2Path.cubicTo(group.left + group.width() * 0.62595f, group.top + group.height() * 0.9987f, group.left + group.width() * 0.49849f, group.top + group.height() * 0.88548f, group.left + group.width() * 0.39416f, group.top + group.height() * 0.7928f);
    bezier2Path.cubicTo(group.left + group.width() * 0.32387f, group.top + group.height() * 0.73035f, group.left + group.width() * 0.26407f, group.top + group.height() * 0.67723f, group.left + group.width() * 0.26085f, group.top + group.height() * 0.67437f);
    bezier2Path.cubicTo(group.left + group.width() * 0.25452f, group.top + group.height() * 0.66996f, group.left + group.width() * 0.25071f, group.top + group.height() * 0.66378f, group.left + group.width() * 0.25071f, group.top + group.height() * 0.65706f);
    bezier2Path.cubicTo(group.left + group.width() * 0.25071f, group.top + group.height() * 0.64411f, group.left + group.width() * 0.26515f, group.top + group.height() * 0.63365f, group.left + group.width() * 0.28296f, group.top + group.height() * 0.63365f);
    bezier2Path.cubicTo(group.left + group.width() * 0.28718f, group.top + group.height() * 0.63365f, group.left + group.width() * 0.29122f, group.top + group.height() * 0.63422f, group.left + group.width() * 0.29491f, group.top + group.height() * 0.63531f);
    bezier2Path.cubicTo(group.left + group.width() * 0.30212f, group.top + group.height() * 0.63724f, group.left + group.width() * 0.45847f, group.top + group.height() * 0.67854f, group.left + group.width() * 0.46523f, group.top + group.height() * 0.68032f);
    bezier2Path.cubicTo(group.left + group.width() * 0.48933f, group.top + group.height() * 0.68052f, group.left + group.width() * 0.50133f, group.top + group.height() * 0.66988f, group.left + group.width() * 0.50133f, group.top + group.height() * 0.65665f);
    bezier2Path.cubicTo(group.left + group.width() * 0.50133f, group.top + group.height() * 0.65368f, group.left + group.width() * 0.50157f, group.top + group.height() * 0.65048f, group.left + group.width() * 0.50158f, group.top + group.height() * 0.64775f);
    bezier2Path.cubicTo(group.left + group.width() * 0.50168f, group.top + group.height() * 0.64403f, group.left + group.width() * 0.50139f, group.top + group.height() * 0.59025f, group.left + group.width() * 0.50139f, group.top + group.height() * 0.59025f);
    bezier2Path.lineTo(group.left + group.width() * 0.75119f, group.top + group.height() * 0.59306f);
    bezier2Path.close();

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(primaryColor);
    canvas.drawPath(bezier2Path, paint);

    canvas.restore();
  }

  canvas.restore();
}
 
Example 15
Source File: Tools.java    From elemeimitate with Apache License 2.0 4 votes vote down vote up
public  Bitmap toRoundBitmap(Context context, String filename) {
	Bitmap bitmap = getBitmap(context, filename);
	int width = bitmap.getWidth();
	int height = bitmap.getHeight();
	float roundPx;
	float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
	if (width <= height) {
		roundPx = width / 2;
		top = 0;
		left = 0;
		bottom = width;
		right = width;
		height = width;
		dst_left = 0;
		dst_top = 0;
		dst_right = width;
		dst_bottom = width;
	} else {
		roundPx = height / 2;
		float clip = (width - height) / 2;
		left = clip;
		right = width - clip;
		top = 0;
		bottom = height;
		width = height;
		dst_left = 0;
		dst_top = 0;
		dst_right = height;
		dst_bottom = height;
	}

	Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
	Canvas canvas = new Canvas(output);

	final int color = 0xff424242;
	final Paint paint = new Paint();
	final Rect src = new Rect((int) left, (int) top, (int) right,
			(int) bottom);
	final Rect dst = new Rect((int) dst_left, (int) dst_top,
			(int) dst_right, (int) dst_bottom);
	final RectF rectF = new RectF(dst);

	paint.setAntiAlias(true);

	canvas.drawARGB(0, 0, 0, 0);
	paint.setColor(Color.WHITE);
	paint.setStrokeWidth(4);
	canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
	paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
	canvas.drawBitmap(bitmap, src, dst, paint);

	// 画白色圆圈
	paint.reset();
	paint.setColor(Color.WHITE);
	paint.setStyle(Paint.Style.STROKE);
	paint.setStrokeWidth(STROKE_WIDTH);
	paint.setAntiAlias(true);
	canvas.drawCircle(width / 2, width / 2, width / 2 - STROKE_WIDTH / 2,
			paint);
	return output;
}
 
Example 16
Source File: LanesStyleKit.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
public static void drawLaneStraight(Canvas canvas, RectF targetFrame, ResizingBehavior resizing, int primaryColor, PointF size) {
  // General Declarations
  Stack<Matrix> currentTransformation = new Stack<Matrix>();
  currentTransformation.push(new Matrix());
  Paint paint = CacheForLaneStraight.paint;

  // Local Variables
  float expression = Math.min(size.x / 30f, size.y / 30f);

  // Resize to Target Frame
  canvas.save();
  RectF resizedFrame = CacheForLaneStraight.resizedFrame;
  LanesStyleKit.resizingBehaviorApply(resizing, CacheForLaneStraight.originalFrame, targetFrame, resizedFrame);
  canvas.translate(resizedFrame.left, resizedFrame.top);
  canvas.scale(resizedFrame.width() / 30f, resizedFrame.height() / 30f);

  // Frame
  RectF frame = CacheForLaneStraight.frame;
  frame.set(0f, 0f, size.x, size.y);

  // Group
  {
    RectF group = CacheForLaneStraight.group;
    group.set(0f, 0f, 12.02f, 24f);
    canvas.save();
    canvas.translate(9f, 3f);
    currentTransformation.peek().postTranslate(9f, 3f);
    canvas.scale(expression, expression);
    currentTransformation.peek().postScale(expression, expression);

    // Rectangle
    RectF rectangleRect = CacheForLaneStraight.rectangleRect;
    rectangleRect.set(4f, 8f, 8f, 24f);
    Path rectanglePath = CacheForLaneStraight.rectanglePath;
    rectanglePath.reset();
    rectanglePath.addRect(rectangleRect, Path.Direction.CW);

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(primaryColor);
    canvas.drawPath(rectanglePath, paint);

    // Bezier
    RectF bezierRect = CacheForLaneStraight.bezierRect;
    bezierRect.set(0f, 0f, 12.02f, 9.99f);
    Path bezierPath = CacheForLaneStraight.bezierPath;
    bezierPath.reset();
    bezierPath.moveTo(group.left + group.width() * 0.33372f, group.top + group.height() * 0.4135f);
    bezierPath.lineTo(group.left + group.width() * 0.33414f, group.top + group.height() * 0.36075f);
    bezierPath.lineTo(group.left + group.width() * 0.33397f, group.top + group.height() * 0.36096f);
    bezierPath.cubicTo(group.left + group.width() * 0.33397f, group.top + group.height() * 0.35842f, group.left + group.width() * 0.33364f, group.top + group.height() * 0.35542f, group.left + group.width() * 0.33364f, group.top + group.height() * 0.35262f);
    bezierPath.cubicTo(group.left + group.width() * 0.33364f, group.top + group.height() * 0.3405f, group.left + group.width() * 0.31766f, group.top + group.height() * 0.33075f, group.left + group.width() * 0.29345f, group.top + group.height() * 0.33075f);
    bezierPath.cubicTo(group.left + group.width() * 0.29096f, group.top + group.height() * 0.33075f, group.left + group.width() * 0.28796f, group.top + group.height() * 0.33079f, group.left + group.width() * 0.28563f, group.top + group.height() * 0.331f);
    bezierPath.lineTo(group.left + group.width() * 0.28588f, group.top + group.height() * 0.33087f);
    bezierPath.lineTo(group.left + group.width() * 0.05882f, group.top + group.height() * 0.37217f);
    bezierPath.lineTo(group.left + group.width() * 0.05916f, group.top + group.height() * 0.37212f);
    bezierPath.cubicTo(group.left + group.width() * 0.05416f, group.top + group.height() * 0.37312f, group.left + group.width() * 0.04867f, group.top + group.height() * 0.37371f, group.left + group.width() * 0.04293f, group.top + group.height() * 0.37371f);
    bezierPath.cubicTo(group.left + group.width() * 0.01922f, group.top + group.height() * 0.37371f, group.left, group.top + group.height() * 0.36408f, group.left, group.top + group.height() * 0.35221f);
    bezierPath.cubicTo(group.left, group.top + group.height() * 0.346f, group.left + group.width() * 0.00516f, group.top + group.height() * 0.34033f, group.left + group.width() * 0.01356f, group.top + group.height() * 0.33642f);
    bezierPath.lineTo(group.left + group.width() * 0.01331f, group.top + group.height() * 0.3365f);
    bezierPath.lineTo(group.left + group.width() * 0.50046f, group.top);
    bezierPath.lineTo(group.left + group.width() * 0.98669f, group.top + group.height() * 0.33908f);
    bezierPath.lineTo(group.left + group.width() * 0.98644f, group.top + group.height() * 0.339f);
    bezierPath.cubicTo(group.left + group.width() * 0.99484f, group.top + group.height() * 0.34292f, group.left + group.width(), group.top + group.height() * 0.34862f, group.left + group.width(), group.top + group.height() * 0.35483f);
    bezierPath.cubicTo(group.left + group.width(), group.top + group.height() * 0.36671f, group.left + group.width() * 0.98078f, group.top + group.height() * 0.37629f, group.left + group.width() * 0.95707f, group.top + group.height() * 0.37629f);
    bezierPath.cubicTo(group.left + group.width() * 0.95133f, group.top + group.height() * 0.37629f, group.left + group.width() * 0.94584f, group.top + group.height() * 0.37575f, group.left + group.width() * 0.94084f, group.top + group.height() * 0.37471f);
    bezierPath.lineTo(group.left + group.width() * 0.94118f, group.top + group.height() * 0.37475f);
    bezierPath.lineTo(group.left + group.width() * 0.71412f, group.top + group.height() * 0.33346f);
    bezierPath.lineTo(group.left + group.width() * 0.71437f, group.top + group.height() * 0.33358f);
    bezierPath.cubicTo(group.left + group.width() * 0.71204f, group.top + group.height() * 0.33342f, group.left + group.width() * 0.70904f, group.top + group.height() * 0.33333f, group.left + group.width() * 0.70655f, group.top + group.height() * 0.33333f);
    bezierPath.cubicTo(group.left + group.width() * 0.68234f, group.top + group.height() * 0.33333f, group.left + group.width() * 0.66636f, group.top + group.height() * 0.34308f, group.left + group.width() * 0.66636f, group.top + group.height() * 0.35521f);
    bezierPath.cubicTo(group.left + group.width() * 0.66636f, group.top + group.height() * 0.358f, group.left + group.width() * 0.66603f, group.top + group.height() * 0.361f, group.left + group.width() * 0.66603f, group.top + group.height() * 0.36354f);
    bezierPath.lineTo(group.left + group.width() * 0.66586f, group.top + group.height() * 0.36338f);
    bezierPath.lineTo(group.left + group.width() * 0.66628f, group.top + group.height() * 0.41608f);

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    bezierPath.setFillType(Path.FillType.EVEN_ODD);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(primaryColor);
    canvas.drawPath(bezierPath, paint);

    canvas.restore();
  }

  canvas.restore();
}
 
Example 17
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);
}
 
Example 18
Source File: LanesStyleKit.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
public static void drawLaneRight(Canvas canvas, RectF targetFrame, ResizingBehavior resizing, int primaryColor, PointF size) {
  // General Declarations
  Stack<Matrix> currentTransformation = new Stack<Matrix>();
  currentTransformation.push(new Matrix());
  Paint paint = CacheForLaneRight.paint;

  // Local Variables
  float expression = Math.min(size.x / 30f, size.y / 30f);

  // Resize to Target Frame
  canvas.save();
  RectF resizedFrame = CacheForLaneRight.resizedFrame;
  LanesStyleKit.resizingBehaviorApply(resizing, CacheForLaneRight.originalFrame, targetFrame, resizedFrame);
  canvas.translate(resizedFrame.left, resizedFrame.top);
  canvas.scale(resizedFrame.width() / 30f, resizedFrame.height() / 30f);

  // Frame
  RectF frame = CacheForLaneRight.frame;
  frame.set(0f, 0f, size.x, size.y);

  // Group
  {
    RectF group = CacheForLaneRight.group;
    group.set(0f, 0f, 14.85f, 23f);
    canvas.save();
    canvas.translate(9f, 4f);
    currentTransformation.peek().postTranslate(9f, 4f);
    canvas.scale(expression, expression);
    currentTransformation.peek().postScale(expression, expression);

    // Bezier
    RectF bezierRect = CacheForLaneRight.bezierRect;
    bezierRect.set(5.87f, 0f, 14.85f, 12.02f);
    Path bezierPath = CacheForLaneRight.bezierPath;
    bezierPath.reset();
    bezierPath.moveTo(group.left + group.width() * 0.50217f, group.top + group.height() * 0.00014f);
    bezierPath.cubicTo(group.left + group.width() * 0.50834f, group.top + group.height() * 0.00007f, group.left + group.width() * 0.51727f, group.top + group.height() * 0.0027f, group.left + group.width() * 0.52351f, group.top + group.height() * 0.00697f);
    bezierPath.cubicTo(group.left + group.width() * 0.53419f, group.top + group.height() * 0.01264f, group.left + group.width(), group.top + group.height() * 0.26153f, group.left + group.width(), group.top + group.height() * 0.26153f);
    bezierPath.cubicTo(group.left + group.width(), group.top + group.height() * 0.26153f, group.left + group.width() * 0.53007f, group.top + group.height() * 0.50996f, group.left + group.width() * 0.51955f, group.top + group.height() * 0.51553f);
    bezierPath.cubicTo(group.left + group.width() * 0.51301f, group.top + group.height() * 0.51993f, group.left + group.width() * 0.50386f, group.top + group.height() * 0.52258f, group.left + group.width() * 0.49391f, group.top + group.height() * 0.52258f);
    bezierPath.cubicTo(group.left + group.width() * 0.47472f, group.top + group.height() * 0.52258f, group.left + group.width() * 0.45924f, group.top + group.height() * 0.51254f, group.left + group.width() * 0.45924f, group.top + group.height() * 0.50014f);
    bezierPath.cubicTo(group.left + group.width() * 0.45924f, group.top + group.height() * 0.49721f, group.left + group.width() * 0.46007f, group.top + group.height() * 0.4944f, group.left + group.width() * 0.46169f, group.top + group.height() * 0.49183f);
    bezierPath.cubicTo(group.left + group.width() * 0.46455f, group.top + group.height() * 0.48682f, group.left + group.width() * 0.52572f, group.top + group.height() * 0.37804f, group.left + group.width() * 0.52837f, group.top + group.height() * 0.37334f);
    bezierPath.cubicTo(group.left + group.width() * 0.52866f, group.top + group.height() * 0.35658f, group.left + group.width() * 0.5129f, group.top + group.height() * 0.34823f, group.left + group.width() * 0.49331f, group.top + group.height() * 0.34823f);
    bezierPath.cubicTo(group.left + group.width() * 0.48889f, group.top + group.height() * 0.34823f, group.left + group.width() * 0.48416f, group.top + group.height() * 0.34806f, group.left + group.width() * 0.48011f, group.top + group.height() * 0.34805f);
    bezierPath.cubicTo(group.left + group.width() * 0.4746f, group.top + group.height() * 0.34798f, group.left + group.width() * 0.39493f, group.top + group.height() * 0.34818f, group.left + group.width() * 0.39493f, group.top + group.height() * 0.34818f);
    bezierPath.lineTo(group.left + group.width() * 0.39911f, group.top + group.height() * 0.1744f);
    bezierPath.cubicTo(group.left + group.width() * 0.39911f, group.top + group.height() * 0.1744f, group.left + group.width() * 0.4782f, group.top + group.height() * 0.1746f, group.left + group.width() * 0.48401f, group.top + group.height() * 0.17461f);
    bezierPath.cubicTo(group.left + group.width() * 0.48839f, group.top + group.height() * 0.17452f, group.left + group.width() * 0.49309f, group.top + group.height() * 0.17435f, group.left + group.width() * 0.49748f, group.top + group.height() * 0.17435f);
    bezierPath.cubicTo(group.left + group.width() * 0.51708f, group.top + group.height() * 0.17435f, group.left + group.width() * 0.53283f, group.top + group.height() * 0.166f, group.left + group.width() * 0.53283f, group.top + group.height() * 0.15335f);
    bezierPath.cubicTo(group.left + group.width() * 0.5299f, group.top + group.height() * 0.14453f, group.left + group.width() * 0.46873f, group.top + group.height() * 0.03576f, group.left + group.width() * 0.466f, group.top + group.height() * 0.03091f);
    bezierPath.cubicTo(group.left + group.width() * 0.46431f, group.top + group.height() * 0.02818f, group.left + group.width() * 0.46341f, group.top + group.height() * 0.02537f, group.left + group.width() * 0.46341f, group.top + group.height() * 0.02243f);
    bezierPath.cubicTo(group.left + group.width() * 0.46341f, group.top + group.height() * 0.01013f, group.left + group.width() * 0.47875f, group.top + group.height() * 0.00014f, group.left + group.width() * 0.49775f, group.top);
    bezierPath.lineTo(group.left + group.width() * 0.50217f, group.top + group.height() * 0.00014f);
    bezierPath.close();

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(primaryColor);
    canvas.drawPath(bezierPath, paint);

    // Bezier 2
    RectF bezier2Rect = CacheForLaneRight.bezier2Rect;
    bezier2Rect.set(0f, 6.03f, 11.03f, 23f);
    Path bezier2Path = CacheForLaneRight.bezier2Path;
    bezier2Path.reset();
    bezier2Path.moveTo(group.left, group.top + group.height() * 1f);
    bezier2Path.lineTo(group.left + group.width() * 0.00417f, group.top + group.height() * 0.41572f);
    bezier2Path.cubicTo(group.left + group.width() * 0.00417f, group.top + group.height() * 0.41572f, group.left + group.width() * 0.02316f, group.top + group.height() * 0.26219f, group.left + group.width() * 0.26516f, group.top + group.height() * 0.26219f);
    bezier2Path.lineTo(group.left + group.width() * 0.74277f, group.top + group.height() * 0.26219f);

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStrokeWidth(4f);
    paint.setStrokeMiter(10f);
    canvas.save();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(primaryColor);
    canvas.drawPath(bezier2Path, paint);
    canvas.restore();

    canvas.restore();
  }

  canvas.restore();
}
 
Example 19
Source File: ObjectPool.java    From pixate-freestyle-android with Apache License 2.0 4 votes vote down vote up
public void resetInstance(Paint paint) {
    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
}
 
Example 20
Source File: ARTShapeShadowNode.java    From art with MIT License 4 votes vote down vote up
/**
 * Sets up {@link #mPaint} according to the props set on a shadow view. Returns {@code true}
 * if the fill should be drawn, {@code false} if not.
 */
protected boolean setupFillPaint(Paint paint, float opacity) {
  if (mBrushData != null && mBrushData.length > 0) {
    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    int colorType = (int) mBrushData[0];
    switch (colorType) {
      case COLOR_TYPE_SOLID_COLOR:
        paint.setARGB(
            (int) (mBrushData.length > 4 ? mBrushData[4] * opacity * 255 : opacity * 255),
            (int) (mBrushData[1] * 255),
            (int) (mBrushData[2] * 255),
            (int) (mBrushData[3] * 255));
        break;
      case COLOR_TYPE_LINEAR_GRADIENT:
        // For mBrushData format refer to LinearGradient and insertColorStopsIntoArray functions in ReactNativeART.js
        if (mBrushData.length < 5) {
          FLog.w(ReactConstants.TAG,
            "[ARTShapeShadowNode setupFillPaint] expects 5 elements, received "
            + mBrushData.length);
          return false;
        }
        float gradientStartX = mBrushData[1] * mScale;
        float gradientStartY = mBrushData[2] * mScale;
        float gradientEndX = mBrushData[3] * mScale;
        float gradientEndY = mBrushData[4] * mScale;
        int stops = (mBrushData.length - 5) / 5;
        int[] colors = null;
        float[] positions = null;
        if (stops > 0) {
          colors = new int[stops];
          positions = new float[stops];
          for (int i=0; i<stops; i++) {
            positions[i] = mBrushData[5 + 4*stops + i];
            int r = (int) (255 * mBrushData[5 + 4*i + 0]);
            int g = (int) (255 * mBrushData[5 + 4*i + 1]);
            int b = (int) (255 * mBrushData[5 + 4*i + 2]);
            int a = (int) (255 * mBrushData[5 + 4*i + 3]);
            colors[i] = Color.argb(a, r, g, b);
          }
        }
        paint.setShader(
          new LinearGradient(
            gradientStartX, gradientStartY,
            gradientEndX, gradientEndY,
            colors, positions,
            Shader.TileMode.CLAMP
          )
        );
        break;
      case COLOR_TYPE_RADIAL_GRADIENT:
        // TODO(6352048): Support radial gradient etc.
      case COLOR_TYPE_PATTERN:
        // TODO(6352048): Support patterns etc.
      default:
        FLog.w(ReactConstants.TAG, "ART: Color type " + colorType + " not supported!");
    }
    if (mShadowOpacity > 0) {
      paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor);
    }
    return true;
  }
  return false;
}