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

The following are Jave code examples for showing how to use reset() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: redpacketui-open   File: CircleTransform.java   View Source Code Vote up 6 votes
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    // TODO this could be acquired from the pool too
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    float r = size / 2f;
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setColor(Color.parseColor("#F9F9F9"));
    paint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(r, r, r, paint);
    paint.reset();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
Example 2
Project: weex-svg   File: WXSvgPath.java   View Source Code Vote up 6 votes
/**
 * 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
Project: FlickLauncher   File: FolderIcon.java   View Source Code Vote up 6 votes
public void drawBackgroundStroke(Canvas canvas, Paint paint) {
    canvas.save();
    canvas.translate(getOffsetX(), getOffsetY());

    paint.reset();
    paint.setAntiAlias(true);
    if(Utilities.getFolderPreviewCirclePrefEnabled(Launcher.getLauncherActivity().getApplicationContext()) != -1){
        paint.setColor(Utilities.getFolderPreviewCirclePrefEnabled(Launcher.getLauncherActivity().getApplicationContext()));
    }else {
        paint.setColor(Color.argb(255, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY));
    }
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(mStrokeWidth);

    float radius = getScaledRadius();
    canvas.drawCircle(radius, radius, radius - 1, paint);

    canvas.restore();
}
 
Example 4
Project: FlickLauncher   File: FolderIcon.java   View Source Code Vote up 6 votes
public void drawLeaveBehind(Canvas canvas, Paint paint) {
    float originalScale = mScale;
    mScale = 0.5f;

    canvas.save();
    canvas.translate(getOffsetX(), getOffsetY());

    paint.reset();
    paint.setAntiAlias(true);
    paint.setColor(Color.argb(160, 245, 245, 245));

    float radius = getScaledRadius();
    canvas.drawCircle(radius, radius, radius, paint);

    canvas.restore();
    mScale = originalScale;
}
 
Example 5
Project: RNLearn_Project1   File: ARTShapeShadowNode.java   View Source Code Vote up 6 votes
/**
 * 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 (mFillColor != null && mFillColor.length > 0) {
    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    int colorType = (int) mFillColor[0];
    switch (colorType) {
      case 0:
        paint.setARGB(
            (int) (mFillColor.length > 4 ? mFillColor[4] * opacity * 255 : opacity * 255),
            (int) (mFillColor[1] * 255),
            (int) (mFillColor[2] * 255),
            (int) (mFillColor[3] * 255));
        break;
      default:
        // TODO(6352048): Support gradients etc.
        FLog.w(ReactConstants.TAG, "ART: Color type " + colorType + " not supported!");
    }
    return true;
  }
  return false;
}
 
Example 6
Project: RNLearn_Project1   File: ARTShapeShadowNode.java   View Source Code Vote up 6 votes
/**
 * 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 (mFillColor != null && mFillColor.length > 0) {
    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    int colorType = (int) mFillColor[0];
    switch (colorType) {
      case 0:
        paint.setARGB(
            (int) (mFillColor.length > 4 ? mFillColor[4] * opacity * 255 : opacity * 255),
            (int) (mFillColor[1] * 255),
            (int) (mFillColor[2] * 255),
            (int) (mFillColor[3] * 255));
        break;
      default:
        // TODO(6352048): Support gradients etc.
        FLog.w(ReactConstants.TAG, "ART: Color type " + colorType + " not supported!");
    }
    return true;
  }
  return false;
}
 
Example 7
Project: SimpleUILauncher   File: FolderIcon.java   View Source Code Vote up 6 votes
public void drawLeaveBehind(Canvas canvas, Paint paint) {
    float originalScale = mScale;
    mScale = 0.5f;

    canvas.save();
    canvas.translate(getOffsetX(), getOffsetY());

    paint.reset();
    paint.setAntiAlias(true);
    paint.setColor(Color.argb(160, 245, 245, 245));

    float radius = getScaledRadius();
    canvas.drawCircle(radius, radius, radius, paint);

    canvas.restore();
    mScale = originalScale;
}
 
Example 8
Project: weex-svg   File: WXSvgPath.java   View Source Code Vote up 5 votes
/**
 * 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 9
Project: TrendChartView   File: TrendYAxisView.java   View Source Code Vote up 5 votes
private void init(Context context, AttributeSet attrs) {
    DashPathEffect mPathEffect = new DashPathEffect(new float[]{dp2px(2), dp2px(2)}, 1);
    mGradeAxisPaint = new Paint();
    mGradeAxisPaint.reset();
    mGradeAxisPaint.setStyle(Paint.Style.STROKE);
    mGradeAxisPaint.setStrokeWidth(1);
    mGradeAxisPaint.setColor(isDebug ? Color.parseColor("#000000") : Color.parseColor("#16ffffff"));
    mGradeAxisPaint.setAntiAlias(true);
    mGradeAxisPaint.setPathEffect(mPathEffect);

    mTextPaint = new TextPaint();
    mTextPaint.setColor(Color.parseColor("#ffffff"));
    mTextPaint.setTextSize(dp2px(11));
    mTextPaint.setAntiAlias(true);
}
 
Example 10
Project: FlickLauncher   File: FolderIcon.java   View Source Code Vote up 5 votes
public void drawBackground(Canvas canvas, Paint paint) {
    canvas.save();
    canvas.translate(getOffsetX(), getOffsetY());

    paint.reset();
    if(Utilities.isAllowFolderTransparentPrefEnabled(Launcher.getLauncherActivity().getApplicationContext())){
        paint.setStyle(Paint.Style.STROKE);
    }else {
        paint.setStyle(Paint.Style.FILL);
    }
    paint.setXfermode(null);
    paint.setAntiAlias(true);

    int alpha = (int) Math.min(MAX_BG_OPACITY, BG_OPACITY * mColorMultiplier);
    if(Utilities.getFolderPreviewBackgroundPrefEnabled(Launcher.getLauncherActivity().getApplicationContext()) != -1){
        paint.setColor(Utilities.getFolderPreviewBackgroundPrefEnabled(Launcher.getLauncherActivity().getApplicationContext()));
    }else {
        paint.setColor(Color.argb(alpha, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY));
    }
    float radius = getScaledRadius();

    canvas.drawCircle(radius, radius, radius, paint);
    canvas.clipPath(mClipPath, Region.Op.DIFFERENCE);

    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.TRANSPARENT);
    paint.setShadowLayer(mStrokeWidth, 0, mStrokeWidth, Color.argb(SHADOW_OPACITY, 0, 0, 0));
    canvas.drawCircle(radius, radius, radius, paint);

    canvas.restore();
}
 
Example 11
Project: SimpleUILauncher   File: FolderIcon.java   View Source Code Vote up 5 votes
public void drawBackground(Canvas canvas, Paint paint) {
    canvas.save();
    canvas.translate(getOffsetX(), getOffsetY());
    paint.reset();
    paint.setStyle(Paint.Style.FILL);//充满
    paint.setColor(Color.LTGRAY);
    paint.setAntiAlias(true);
    paint.setAlpha(100);
    RectF oval3 = new RectF(0, 0, mBackground.previewSize, mBackground.previewSize);
    canvas.drawRoundRect(oval3, 40, 40,paint);
    canvas.restore();

}
 
Example 12
Project: SimpleUILauncher   File: FolderIcon.java   View Source Code Vote up 5 votes
public void drawBackgroundStroke(Canvas canvas, Paint paint) {
    canvas.save();
    canvas.translate(getOffsetX(), getOffsetY());

    paint.reset();
    paint.setAntiAlias(true);
    paint.setColor(Color.argb(0, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY));
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(mStrokeWidth);
    RectF oval3 = new RectF(0, 0, mBackground.previewSize, mBackground.previewSize);

    canvas.drawRoundRect(oval3,40,40,paint);

    canvas.restore();
}
 
Example 13
Project: TrendChartView   File: TrendChartView.java   View Source Code Vote up 4 votes
private void initPaint() {
    mPathEffect = new DashPathEffect(new float[]{dp2, dp2}, 1);
    mGradeAxisPaint = new Paint();
    mGradeAxisPaint.reset();
    mGradeAxisPaint.setStyle(Paint.Style.STROKE);
    mGradeAxisPaint.setStrokeWidth(1);
    mGradeAxisPaint.setColor(isDebug ? Color.parseColor("#f00000") : Color.parseColor("#16ffffff"));
    mGradeAxisPaint.setAntiAlias(true);
    mGradeAxisPaint.setPathEffect(mPathEffect);

    mChartPaint = new Paint();
    mChartPaint.setStyle(Paint.Style.FILL);
    mChartPaint.setStrokeWidth(4);
    mChartPaint.setAntiAlias(true);

    mChartTestLinePaint = new Paint();
    mChartTestLinePaint.setStyle(Paint.Style.STROKE);
    mChartTestLinePaint.setStrokeWidth(dp2px(1));
    mChartTestLinePaint.setColor(Color.parseColor("#DF6A56"));
    mChartTestLinePaint.setAntiAlias(true);
    mChartTestLinePaint.setAlpha(0);
    if (isDebug) {
        mChartTestLinePaint.setAlpha(255);
    }

    mChartIndicatorPaint = new Paint();
    mChartIndicatorPaint.setStyle(Paint.Style.STROKE);
    mChartIndicatorPaint.setStrokeWidth(dp2px(1));

    mWhitePaint = new Paint();
    mWhitePaint.setStyle(Paint.Style.FILL);
    mWhitePaint.setColor(Color.parseColor("#ffffff"));

    mWhiteTextPaint = new TextPaint();
    mWhiteTextPaint.setColor(Color.parseColor("#ffffff"));
    mWhiteTextPaint.setTextSize(dp2px(11));
    mWhiteTextPaint.setAntiAlias(true);

    mWhiteTextPaintHeight = mWhiteTextPaint.descent() + mWhiteTextPaint.ascent();

    mDarkTextPaint = new TextPaint(mWhiteTextPaint);
    mDarkTextPaint.setAlpha(127);

    mPathIndicatorLine = new Path();
    mPathIndicatorLine.setFillType(Path.FillType.WINDING);

    mPathGradLine = new Path();
    mRectIndicator = new RectF();
}
 
Example 14
Project: RNLearn_Project1   File: ARTShapeShadowNode.java   View Source Code Vote up 4 votes
/**
 * 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 15
Project: RNLearn_Project1   File: ARTShapeShadowNode.java   View Source Code Vote up 4 votes
/**
 * 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;
}