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

The following examples show how to use android.graphics.Paint#setFlags() . 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: FastBlur.java    From MVPArms with Apache License 2.0 6 votes vote down vote up
/**
 * 将 {@link Bitmap} 高斯模糊并返回
 *
 * @param bkg
 * @param width
 * @param height
 * @return
 */
public static Bitmap blurBitmap(Bitmap bkg, int width, int height) {
    long startMs = System.currentTimeMillis();
    float radius = 15;//越大模糊效果越大
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, width, height);
    Bitmap overlay = Bitmap.createBitmap((int) (width / scaleFactor)
            , (int) (height / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
    return overlay;
}
 
Example 2
Source File: FastBlur.java    From MVPArms with Apache License 2.0 6 votes vote down vote up
/**
 * 给 {@link View} 设置高斯模糊背景图片
 *
 * @param context
 * @param bkg
 * @param view
 */
public static void blur(Context context, Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    float radius = 15;
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());

    Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
            , (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
 
Example 3
Source File: PrintDrawable.java    From Print with Apache License 2.0 6 votes vote down vote up
private PrintDrawable(Context context, CharSequence iconText,
                      ColorStateList iconColor, Typeface iconFont, int iconSize, boolean inEditMode) {
    mContext = context;
    mPaint = new Paint();
    mPaint.setFlags(mPaint.getFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    mPath = new Path();
    mPathBounds = new RectF();

    mIconText = iconText;
    mIconColor = iconColor;
    mIconFont = iconFont;
    mIconSize = iconSize;

    mInEditMode = inEditMode;

    mPaint.setTextSize(mIconSize);
    mPaint.setTypeface(mIconFont);

    if (mIconColor != null) {
        updateIconColors();
    }
}
 
Example 4
Source File: VMDrawView.java    From VMLibrary with Apache License 2.0 6 votes vote down vote up
private void init() {
    path = new Path();
    // 实例化画笔
    paint = new Paint();
    // 设置画笔颜色
    paint.setColor(lineColor);
    // 设置抗锯齿
    paint.setAntiAlias(true);
    // 效果同上
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    // 设置画笔宽度
    paint.setStrokeWidth(lineWidth);
    // 设置画笔模式
    paint.setStyle(Paint.Style.STROKE);
    // 设置画笔末尾样式
    paint.setStrokeCap(Paint.Cap.ROUND);
}
 
Example 5
Source File: GaussianBlur.java    From AndroidUI with MIT License 5 votes vote down vote up
/**
 * 通过RenderScript进行图片模糊
 * @param bkg       需要模糊的bitmap
 * @param radius    模糊半径,RenderScript规定范围为[1,25]
 * @param view      显示模糊图片的ImageView
 * @param context   上下文
 * @return          消耗时间,单位毫秒(ms)
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static long blurByRenderScript(Bitmap bkg,int radius, ImageView view,Context context)
{
    long startMs = System.currentTimeMillis();
    float scaleFactor = 8;

    int width = (int)(view.getMeasuredWidth()/scaleFactor);
    int height = (int)(view.getMeasuredHeight()/scaleFactor);

    Bitmap overlay = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);

    RenderScript rs = RenderScript.create(context);

    Allocation overlayAlloc = Allocation.createFromBitmap(rs, overlay);
    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
    blur.setInput(overlayAlloc);
    blur.setRadius(radius);
    blur.forEach(overlayAlloc);
    overlayAlloc.copyTo(overlay);

    view.setImageBitmap(overlay);

    rs.destroy();

    return System.currentTimeMillis() - startMs;
}
 
Example 6
Source File: CircleGraphView.java    From HzGrapher with Apache License 2.0 5 votes vote down vote up
private Paint setTextPaint(int color , int textSize) {
	Paint paint = new Paint();
	Rect rect = new Rect();

	paint.setFlags(Paint.ANTI_ALIAS_FLAG);
	paint.setAntiAlias(true); //text anti alias
	paint.setFilterBitmap(true); // bitmap anti alias
	paint.setColor(color);
	paint.setStrokeWidth(3);
	paint.setTextSize(textSize);
	return paint;
}
 
Example 7
Source File: SVGAndroidRenderer.java    From starcor.xul with GNU Lesser General Public License v3.0 5 votes vote down vote up
public RendererState()
{
   fillPaint = new Paint();
   fillPaint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
   fillPaint.setStyle(Paint.Style.FILL);
   fillPaint.setTypeface(Typeface.DEFAULT);

   strokePaint = new Paint();
   strokePaint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
   strokePaint.setStyle(Paint.Style.STROKE);
   strokePaint.setTypeface(Typeface.DEFAULT);

   style = Style.getDefaultStyle();
}
 
Example 8
Source File: SVGAndroidRenderer.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
RendererState()
{
   fillPaint = new Paint();
   fillPaint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
   fillPaint.setStyle(Paint.Style.FILL);
   fillPaint.setTypeface(Typeface.DEFAULT);

   strokePaint = new Paint();
   strokePaint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
   strokePaint.setStyle(Paint.Style.STROKE);
   strokePaint.setTypeface(Typeface.DEFAULT);

   style = Style.getDefaultStyle();
}
 
Example 9
Source File: CircleBackgroundImageView.java    From OpenHub with GNU General Public License v3.0 5 votes vote down vote up
private void init(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray tp = getContext().obtainStyledAttributes(attrs, R.styleable.CircleBackgroundImageView);
        try {
            backgroundColor = tp.getInt(R.styleable.CircleBackgroundImageView_background_color, 0);
            paint = new Paint();
            paint.setColor(backgroundColor);
            paint.setFlags(Paint.ANTI_ALIAS_FLAG);
        } finally {
            tp.recycle();
        }
    }
}
 
Example 10
Source File: BlurTransformation.java    From Dota2Helper with Apache License 2.0 5 votes vote down vote up
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();

    int width = source.getWidth();
    int height = source.getHeight();
    int scaledWidth = width / mSampling;
    int scaledHeight = height / mSampling;

    Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(source, 0, 0, paint);

    RenderScript rs = RenderScript.create(mContext);
    Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
            Allocation.USAGE_SCRIPT);
    Allocation output = Allocation.createTyped(rs, input.getType());
    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

    blur.setInput(input);
    blur.setRadius(mRadius);
    blur.forEach(output);
    output.copyTo(bitmap);

    rs.destroy();

    return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
Example 11
Source File: EaseImageView.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    //init the value
    borderWidth = 0;
    borderColor = 0xddffffff;
    pressAlpha = 0x42;
    pressColor = 0x42000000;
    radius = 16;
    shapeType = 0;

    // get attribute of EaseImageView
    if (attrs != null) {
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.EaseImageView);
        borderColor = array.getColor(R.styleable.EaseImageView_ease_border_color, borderColor);
        borderWidth = array.getDimensionPixelOffset(R.styleable.EaseImageView_ease_border_width, borderWidth);
        pressAlpha = array.getInteger(R.styleable.EaseImageView_ease_press_alpha, pressAlpha);
        pressColor = array.getColor(R.styleable.EaseImageView_ease_press_color, pressColor);
        radius = array.getDimensionPixelOffset(R.styleable.EaseImageView_ease_radius, radius);
        shapeType = array.getInteger(R.styleable.EaseImageView_ease_shape_type, shapeType);
        array.recycle();
    }

    // set paint when pressed
    pressPaint = new Paint();
    pressPaint.setAntiAlias(true);
    pressPaint.setStyle(Paint.Style.FILL);
    pressPaint.setColor(pressColor);
    pressPaint.setAlpha(0);
    pressPaint.setFlags(Paint.ANTI_ALIAS_FLAG);

    setClickable(true);
    setDrawingCacheEnabled(true);
    setWillNotDraw(false);
}
 
Example 12
Source File: BlurPostprocessor.java    From fresco-processors with Apache License 2.0 5 votes vote down vote up
@Override public void process(Bitmap dest, Bitmap source) {

    int width = source.getWidth();
    int height = source.getHeight();
    int scaledWidth = width / sampling;
    int scaledHeight = height / sampling;

    Bitmap blurredBitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(blurredBitmap);
    canvas.scale(1 / (float) sampling, 1 / (float) sampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(source, 0, 0, paint);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
      try {
        blurredBitmap = RSBlur.blur(context, blurredBitmap, radius);
      } catch (android.renderscript.RSRuntimeException e) {
        blurredBitmap = FastBlur.blur(blurredBitmap, radius, true);
      }
    } else {
      blurredBitmap = FastBlur.blur(blurredBitmap, radius, true);
    }

    Bitmap scaledBitmap =
        Bitmap.createScaledBitmap(blurredBitmap, dest.getWidth(), dest.getHeight(), true);
    blurredBitmap.recycle();

    super.process(dest, scaledBitmap);
  }
 
Example 13
Source File: ImageLoader.java    From Audinaut with GNU General Public License v3.0 5 votes vote down vote up
private Bitmap createUnknownImage(int size, int primaryColor, String topText, String bottomText) {
    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint color = new Paint();
    color.setColor(primaryColor);
    canvas.drawRect(0, 0, size, size * 2.0f / 3.0f, color);

    color.setShader(new LinearGradient(0, 0, 0, size / 3.0f, Color.rgb(82, 82, 82), Color.BLACK, Shader.TileMode.MIRROR));
    canvas.drawRect(0, size * 2.0f / 3.0f, size, size, color);

    if (topText != null || bottomText != null) {
        Paint font = new Paint();
        font.setFlags(Paint.ANTI_ALIAS_FLAG);
        font.setColor(Color.WHITE);
        font.setTextSize(3.0f + size * 0.07f);

        if (topText != null) {
            canvas.drawText(topText, size * 0.05f, size * 0.6f, font);
        }

        if (bottomText != null) {
            canvas.drawText(bottomText, size * 0.05f, size * 0.8f, font);
        }
    }

    return bitmap;
}
 
Example 14
Source File: Blur.java    From Blurry with Apache License 2.0 5 votes vote down vote up
public static Bitmap of(Context context, Bitmap source, BlurFactor factor) {
  int width = factor.width / factor.sampling;
  int height = factor.height / factor.sampling;

  if (Helper.hasZero(width, height)) {
    return null;
  }

  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

  Canvas canvas = new Canvas(bitmap);
  canvas.scale(1 / (float) factor.sampling, 1 / (float) factor.sampling);
  Paint paint = new Paint();
  paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
  PorterDuffColorFilter filter =
      new PorterDuffColorFilter(factor.color, PorterDuff.Mode.SRC_ATOP);
  paint.setColorFilter(filter);
  canvas.drawBitmap(source, 0, 0, paint);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    try {
      bitmap = Blur.rs(context, bitmap, factor.radius);
    } catch (RSRuntimeException e) {
      bitmap = Blur.stack(bitmap, factor.radius, true);
    }
  } else {
    bitmap = Blur.stack(bitmap, factor.radius, true);
  }

  if (factor.sampling == BlurFactor.DEFAULT_SAMPLING) {
    return bitmap;
  } else {
    Bitmap scaled = Bitmap.createScaledBitmap(bitmap, factor.width, factor.height, true);
    bitmap.recycle();
    return scaled;
  }
}
 
Example 15
Source File: CircularView.java    From CircularView with Apache License 2.0 4 votes vote down vote up
private void init(AttributeSet attrs, int defStyle) {
    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.CircularView, defStyle, 0);
    final int centerBackgroundColor = a.getColor(
            R.styleable.CircularView_centerBackgroundColor,
            CircularViewObject.NO_COLOR);

    // Set up a default TextPaint object
    mTextPaint = new TextPaint();
    mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Paint.Align.LEFT);

    mText = a.getString(R.styleable.CircularView_text);
    mTextPaint.setTextSize(a.getDimension(
            R.styleable.CircularView_textSize,
            24f));
    mTextPaint.setColor(a.getColor(
            R.styleable.CircularView_textColor,
            mTextPaint.getColor()));


    Drawable circleDrawable = null;
    if (a.hasValue(R.styleable.CircularView_centerDrawable)) {
        circleDrawable = a.getDrawable(
                R.styleable.CircularView_centerDrawable);
        circleDrawable.setCallback(this);
    }

    mHighlightedDegreeObjectAnimator = new ObjectAnimator();
    mHighlightedDegreeObjectAnimator.setTarget(CircularView.this);
    mHighlightedDegreeObjectAnimator.setPropertyName("highlightedDegree");
    mHighlightedDegreeObjectAnimator.addListener(mAnimatorListener);

    // Update TextPaint and text measurements from attributes
    invalidateTextPaintAndMeasurements();

    mCirclePaint = new Paint();
    mCirclePaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mCirclePaint.setStyle(Paint.Style.FILL);
    mCirclePaint.setColor(Color.RED);

    mDrawHighlightedMarkerOnTop = a.getBoolean(R.styleable.CircularView_drawHighlightedMarkerOnTop, false);
    mHighlightedMarker = null;
    mHighlightedMarkerPosition = -1;
    mHighlightedDegree = a.getFloat(R.styleable.CircularView_highlightedDegree, HIGHLIGHT_NONE);
    mMarkerStartingPoint = a.getFloat(R.styleable.CircularView_markerStartingPoint, 0f);
    mAnimateMarkersOnStillHighlight = a.getBoolean(R.styleable.CircularView_animateMarkersOnStillHighlight, false);
    mAnimateMarkersOnHighlightAnimation = false;
    mIsAnimating = false;

    mCircle = new CircularViewObject(getContext(), CIRCLE_TO_MARKER_PADDING, centerBackgroundColor);
    mCircle.setSrc(circleDrawable);
    mCircle.setFitToCircle(a.getBoolean(R.styleable.CircularView_fitToCircle, false));

    mDefaultMarkerRadius = getResources().getInteger(R.integer.cv_default_marker_radius);

    mEditModeMarkerCount = a.getInt(R.styleable.CircularView_editMode_markerCount, 0);
    mEditModeMarkerRadius = a.getInt(R.styleable.CircularView_editMode_markerRadius, mDefaultMarkerRadius);

    a.recycle();

    setOnLongClickListener(mOnLongClickListener);

    if (isInEditMode()) {
        mAdapter = new SimpleCircularViewAdapter() {
            @Override
            public int getCount() {
                return mEditModeMarkerCount;
            }

            @Override
            public void setupMarker(int position, Marker marker) {
                marker.setRadius(mEditModeMarkerRadius);
                marker.setCenterBackgroundColor(getResources().getColor(android.R.color.black));
            }
        };
    }
}
 
Example 16
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 17
Source File: GaugeAccelerationHolo.java    From AccelerationAlert with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the drawing related members of the instance.
 */
private void initDrawingTools()
{
	rimRect = new RectF(0.1f, 0.1f, 0.9f, 0.9f);
	
	//inner rim oval
	innerRim = new RectF(0.25f, 0.25f, 0.75f, 0.75f);

	//inner most white dot
	innerMostDot = new RectF(0.47f, 0.47f, 0.53f, 0.53f);
			
	// the linear gradient is a bit skewed for realism
	rimPaint = new Paint();
	rimPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
	rimPaint.setShader(new LinearGradient(0.40f, 0.0f, 0.60f, 1.0f, Color
			.rgb(255, 255, 255), Color.rgb(255,255,255),
			Shader.TileMode.CLAMP));

	float rimSize = 0.03f;
	faceRect = new RectF();
	faceRect.set(rimRect.left + rimSize, rimRect.top + rimSize,
			rimRect.right - rimSize, rimRect.bottom - rimSize);

	rimShadowPaint = new Paint();
	rimShadowPaint.setStyle(Paint.Style.FILL);
	rimShadowPaint.setAntiAlias(true);

	//set the size of the outside white with the rectangles.
	//a 'bigger' negative will increase the size.
	float rimOuterSize = -0.04f;
	rimOuterRect = new RectF();
	rimOuterRect.set(rimRect.left + rimOuterSize, rimRect.top + rimOuterSize,
			rimRect.right - rimOuterSize, rimRect.bottom - rimOuterSize);
	
	rimOuterTopRect = new RectF(0.5f, 0.116f, 0.5f, 0.07f);
	rimOuterTopRect.set(rimOuterTopRect.left + rimOuterSize, rimOuterTopRect.top + rimOuterSize,
			rimOuterTopRect.right - rimOuterSize, rimOuterTopRect.bottom - rimOuterSize);
	
	rimOuterBottomRect = new RectF(0.5f, 0.93f, 0.5f, 0.884f);
	rimOuterBottomRect.set(rimOuterBottomRect.left + rimOuterSize, rimOuterBottomRect.top + rimOuterSize,
			rimOuterBottomRect.right - rimOuterSize, rimOuterBottomRect.bottom - rimOuterSize);
	
	rimOuterLeftRect = new RectF(0.116f, 0.5f, 0.07f, 0.5f);
	rimOuterLeftRect.set(rimOuterLeftRect.left + rimOuterSize, rimOuterLeftRect.top + rimOuterSize,
			rimOuterLeftRect.right - rimOuterSize, rimOuterLeftRect.bottom - rimOuterSize);
	
	rimOuterRightRect = new RectF(0.93f, 0.5f, 0.884f, 0.5f);
	rimOuterRightRect.set(rimOuterRightRect.left + rimOuterSize, rimOuterRightRect.top + rimOuterSize,
			rimOuterRightRect.right - rimOuterSize, rimOuterRightRect.bottom - rimOuterSize);

	//inner rim declarations the black oval/rect
	float rimInnerSize = 0.02f;
	innerface = new RectF();
	innerface.set(innerRim.left + rimInnerSize, innerRim.top + rimInnerSize,
			innerRim.right - rimInnerSize, innerRim.bottom - rimInnerSize);
	
	//inner 4 small rectangles 
	rimInnerTopRect = new RectF(0.46f, 0.23f, 0.54f, 0.26f);
	rimInnerBottomRect = new RectF(0.46f, 0.74f, 0.54f, 0.77f);
	rimInnerLeftRect = new RectF(0.23f, 0.54f, 0.26f, 0.46f);
	rimInnerRightRect = new RectF(0.74f, 0.54f, 0.77f, 0.46f);

	pointPaint = new Paint();
	pointPaint.setAntiAlias(true);
	pointPaint.setColor(Color.WHITE);
	pointPaint.setShadowLayer(0.01f, -0.005f, -0.005f, 0x7f000000);
	pointPaint.setStyle(Paint.Style.FILL_AND_STROKE);

	backgroundPaint = new Paint();
	backgroundPaint.setFilterBitmap(true);
}
 
Example 18
Source File: LineGraphView.java    From HzGrapher with Apache License 2.0 4 votes vote down vote up
/**
 *	draw graph with animation 
 */
private void drawGraphRegionWithAnimation(GraphCanvasWrapper graphCanvas) {
	//for draw animation
	float prev_x = 0;
	float prev_y = 0;
	
	float next_x = 0;
	float next_y = 0;
	
	int value = 0;
	float mode = 0;
	
	boolean isDrawRegion = mLineGraphVO.isDrawRegion();
	
	for (int i = 0; i < mLineGraphVO.getArrGraph().size(); i++) {
		GraphPath regionPath = new GraphPath(width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
		boolean firstSet = false;
		float x = 0;
		float y = 0;
		p.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
		pCircle.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
		float xGap = xLength/(mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length-1);
		
		value = (int) (anim/1);
		mode = anim %1;
		
		boolean isFinish = false;
		for (int j = 0; j <= value+1; j++) {
			if(j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length){
				
				if (!firstSet) {
					
					x = xGap * j ;
					y = yLength * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]/mLineGraphVO.getMaxValue();
					
					regionPath.moveTo(x, 0);
					regionPath.lineTo(x, y);
					
					firstSet = true;
				} else {
					x = xGap * j;
					y = yLength * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]/mLineGraphVO.getMaxValue();
					
					if( j > value){
						next_x = x - prev_x;
						next_y = y - prev_y;
						regionPath.lineTo(prev_x + next_x * mode, prev_y + next_y * mode);
					}else{
						regionPath.lineTo(x, y);
					}
				}
				
				prev_x = x;
				prev_y = y;
			}
		}
		isFinish = true;
		
		if(isDrawRegion){
			float x_bg = prev_x + next_x * mode;
			if(x_bg >= xLength){
				x_bg = xLength;
			}
			regionPath.lineTo(x_bg, 0);
			regionPath.lineTo(0, 0);
			
			Paint pBg = new Paint();
			pBg.setFlags(Paint.ANTI_ALIAS_FLAG);
			pBg.setAntiAlias(true); //text anti alias
			pBg.setFilterBitmap(true); // bitmap anti alias
			pBg.setStyle(Style.FILL);
			pBg.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
			graphCanvas.getCanvas().drawPath(regionPath, pBg);
		}
	}
}
 
Example 19
Source File: BlurTransformation.java    From GracefulMovies with Apache License 2.0 4 votes vote down vote up
/**
     * Transforms the given {@link Bitmap} based on the given dimensions and returns the transformed
     * result.
     * <p/>
     * <p>
     * The provided Bitmap, toTransform, should not be recycled or returned to the pool. Glide will automatically
     * recycle and/or reuse toTransform if the transformation returns a different Bitmap. Similarly implementations
     * should never recycle or return Bitmaps that are returned as the result of this method. Recycling or returning
     * the provided and/or the returned Bitmap to the pool will lead to a variety of runtime exceptions and drawing
     * errors. See #408 for an example. If the implementation obtains and discards intermediate Bitmaps, they may
     * safely be returned to the BitmapPool and/or recycled.
     * </p>
     * <p/>
     * <p>
     * outWidth and outHeight will never be {Target.SIZE_ORIGINAL}, this
     * class converts them to be the size of the Bitmap we're going to transform before calling this method.
     * </p>
     *
     * @param pool        A {@link BitmapPool} that can be used to obtain and
     *                    return intermediate {@link Bitmap}s used in this transformation. For every
     *                    {@link Bitmap} obtained from the pool during this transformation, a
     *                    {@link Bitmap} must also be returned.
     * @param toTransform The {@link Bitmap} to transform.
     * @param outWidth    The ideal width of the transformed bitmap (the transformed width does not need to match exactly).
     * @param outHeight   The ideal height of the transformed bitmap (the transformed heightdoes not need to match
     */
    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
        boolean needScaled = mSampling == DEFAULT_SAMPLING;
        int originWidth = toTransform.getWidth();
        int originHeight = toTransform.getHeight();
        int width, height;
        if (needScaled) {
            width = originWidth;
            height = originHeight;
        } else {
            width = (int) (originWidth / mSampling);
            height = (int) (originHeight / mSampling);
        }
        //find a re-use bitmap
        Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
        if (bitmap == null) {
            bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        }

        Canvas canvas = new Canvas(bitmap);
        if (mSampling != DEFAULT_SAMPLING) {
            canvas.scale(1 / mSampling, 1 / mSampling);
        }
        Paint paint = new Paint();
        paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
        PorterDuffColorFilter filter =
                new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP);
        paint.setColorFilter(filter);
        canvas.drawBitmap(toTransform, 0, 0, paint);
// TIPS: Glide will take care of returning our original Bitmap to the BitmapPool for us,
// we needn't to recycle it. 
//        toTransform.recycle();  <--- Just for tips. by Ligboy

        RenderScript rs = RenderScript.create(mContext);
        Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
                Allocation.USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

        blur.setInput(input);
        blur.setRadius(mRadius);
        blur.forEach(output);
        output.copyTo(bitmap);

        rs.destroy();

        if (needScaled) {
            return bitmap;
        } else {
            Bitmap scaled = Bitmap.createScaledBitmap(bitmap, originWidth, originHeight, true);
            bitmap.recycle();
            return scaled;
        }
    }
 
Example 20
Source File: BlurTransformation.java    From MusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
    int sampling;
    if (this.sampling == 0) {
        sampling = ImageUtil.calculateInSampleSize(toTransform.getWidth(), toTransform.getHeight(), 100);
    } else {
        sampling = this.sampling;
    }

    int width = toTransform.getWidth();
    int height = toTransform.getHeight();
    int scaledWidth = width / sampling;
    int scaledHeight = height / sampling;

    Bitmap out = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    if (out == null) {
        out = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(out);
    canvas.scale(1 / (float) sampling, 1 / (float) sampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(toTransform, 0, 0, paint);

    if (Build.VERSION.SDK_INT >= 17) {
        try {
            final RenderScript rs = RenderScript.create(context.getApplicationContext());
            final Allocation input = Allocation.createFromBitmap(rs, out, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
            final Allocation output = Allocation.createTyped(rs, input.getType());
            final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

            script.setRadius(blurRadius);
            script.setInput(input);
            script.forEach(output);

            output.copyTo(out);

            rs.destroy();

            return out;

        } catch (RSRuntimeException e) {
            // on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library
            if (BuildConfig.DEBUG) e.printStackTrace();
        }
    }

    return StackBlur.blur(out, blurRadius);
}