public WidgetTextFrame(Context context, @Nullable AttributeSet attrs) { super(context, attrs); setClipChildren(false); setClipToPadding(false); mContext = context.getApplicationContext(); mPaddingSpace = context.getResources().getDimensionPixelSize(R.dimen.edit_text_space); mRoundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); PathEffect effect = new DashPathEffect(new float[]{20, 20}, 1); mRoundPaint.setAntiAlias(true); mRoundPaint.setColor(getResources().getColor(R.color.edit_text_background_color)); mRoundPaint.setPathEffect(effect); mRoundPaint.setStyle(Paint.Style.STROKE); mRoundPaint.setStrokeWidth(3); mDeletePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mDeletePaint.setAntiAlias(true); mDeletePaint.setFilterBitmap(true); mDeletePaint.setDither(true); setWillNotDraw(false); }
public @Nullable PathEffect getPathEffect(float borderWidth) { switch (this) { case SOLID: return null; case DASHED: return new DashPathEffect( new float[] {borderWidth*3, borderWidth*3, borderWidth*3, borderWidth*3}, 0); case DOTTED: return new DashPathEffect( new float[] {borderWidth, borderWidth, borderWidth, borderWidth}, 0); default: return null; } }
/** * Procedure meant to set the value for {@link #mDrawnDivider} optional parameter. * @param color the divider's target {@link Color} value. * See {@link Paint#setColor(int)} for more information. * @param thickness the divider's target line thickness value. This value must be greater or equal than 0. * See {@link Paint#setStrokeWidth(float)} for more information. * @param style the divider's target {@link Paint.Style}. * See {@link Paint#setStyle(Paint.Style)} for more information. * @param pathEffect the divider's target {@link PathEffect}. * See {@link Paint#setPathEffect(PathEffect)} for more information. * @return the same object builder object after setting the optional attribute. */ @NonNull public DecorationSpecBuilder withDrawnDivider(@ColorInt int color, @FloatRange(from = 0, fromInclusive = false) float thickness, @Nullable final Paint.Style style, @Nullable final PathEffect pathEffect) { mDrawnDivider = new Paint(); mDrawnDivider.setColor(color); mDrawnDivider.setStrokeWidth(thickness); if (style != null) { mDrawnDivider.setStyle(style); } if (pathEffect != null) { mDrawnDivider.setPathEffect(pathEffect); } return this; }
public @Nullable PathEffect getPathEffect(float borderWidth) { switch (this) { case SOLID: return null; case DASHED: return new DashPathEffect( new float[]{borderWidth * 3, borderWidth * 3, borderWidth * 3, borderWidth * 3}, 0); case DOTTED: return new DashPathEffect( new float[]{borderWidth, borderWidth, borderWidth, borderWidth}, 0); default: return null; } }
private void createFailedPath(){ if(mFailedPath != null){ mFailedPath.reset(); mFailedPath2.reset(); }else{ mFailedPath = new Path(); mFailedPath2 = new Path(); } float left = width/2 - mRadius + mRadius/2; float top = mRadius/2 + mPadding; mFailedPath.moveTo(left,top); mFailedPath.lineTo(left+mRadius,top+mRadius); mFailedPath2.moveTo(width/2 + mRadius/2,top); mFailedPath2.lineTo(width/2 - mRadius + mRadius/2,top+mRadius); PathMeasure measure = new PathMeasure(mFailedPath, false); mFailedPathLength = measure.getLength(); mFailedPathIntervals = new float[]{mFailedPathLength, mFailedPathLength}; PathEffect PathEffect = new DashPathEffect(mFailedPathIntervals, mFailedPathLength); mPathEffectPaint2.setPathEffect(PathEffect); }
RichPolygon(final int zIndex, final List<RichPoint> points, final List<List<RichPoint>> holes, final int strokeWidth, final Paint.Cap strokeCap, final Paint.Join strokeJoin, final PathEffect pathEffect, final MaskFilter maskFilter, final boolean linearGradient, final Integer strokeColor, final boolean antialias, final boolean closed, final Shader strokeShader, final Shader fillShader, final Paint.Style style, final Integer fillColor) { super(zIndex, points, strokeWidth, strokeCap, strokeJoin, pathEffect, maskFilter, strokeShader, linearGradient, strokeColor, antialias, closed); this.fillShader = fillShader; this.style = style; this.fillColor = fillColor; if (holes != null) { addHoles(holes); } }
public void setPoints(ArrayList<float[]> pointsToPath){ synchronized (pointsToPath) { this.points = pointsToPath; float[] startPoint = convertXYToLinePoint(points.get(0)); path.moveTo(startPoint[0], startPoint[1]); for (int i = 0; i<this.points.size(); i++) { float[] linePoint = convertXYToLinePoint(points.get(i)); path.lineTo(linePoint[0],linePoint[1]); } } pathMeasure = new PathMeasure(path, false); pathLength = pathMeasure.getLength(); // the interpolated length of the entire path as it would be drawn on the screen in dp PathEffect pathEffect = new PathDashPathEffect(makeConvexArrow(15.0f, 15.0f), 5.0f, 0.0f, PathDashPathEffect.Style.ROTATE); paintSettings.setPathEffect(pathEffect); invalidate(); }
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.BLACK); pathMeasure.setPath(path, false); float length = pathMeasure.getLength(); if (length > BUG_TRAIL_DP * density) { // Note - this is likely a poor way to accomplish the result. Just for demo purposes. @SuppressLint("DrawAllocation") PathEffect effect = new DashPathEffect(new float[]{length, length}, -length + BUG_TRAIL_DP * density); paint.setPathEffect(effect); } paint.setStyle(Paint.Style.STROKE); canvas.drawPath(path, paint); paint.setStyle(Paint.Style.FILL); canvas.drawCircle(position.x, position.y, BUG_RADIUS_DP * density, paint); }
public SampleView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(6); mPath = makeFollowPath(); mEffects = new PathEffect[6]; mBonds = new RectF(); mColors = new int[] { Color.BLACK, Color.RED, Color.BLUE, Color.GREEN, Color.MAGENTA, Color.BLACK }; }
void draw(Canvas canvas) { RectF rectF = new RectF(mLeftX, mY, mRightX, mY); canvas.drawRoundRect(rectF, mBarWeight / 2, mBarWeight / 2, mBarPaint); Path path = new Path(); path.moveTo(mLeftX + mMargin, mY); path.lineTo(mRightX - mMargin, mY); PathEffect effects = new DashPathEffect(new float[]{5, 5, 5, 5}, 1); mEffectPaint.setPathEffect(effects); canvas.drawPath(path, mEffectPaint); }
private void setStroke(Cap cap, Join join, float miter, Style style, PathEffect pathEffect, Paint paint) { paint.setStrokeCap(cap); paint.setStrokeJoin(join); paint.setStrokeMiter(miter); paint.setPathEffect(pathEffect); paint.setStyle(style); }
private void setDividerPaint() { mDividerPaint.setAlpha(0); mDividerPaint.setAntiAlias(true); mDividerPaint.setColor(mDividerColor); mDividerPaint.setStrokeWidth(mDividerWidth); if(mDividerType == DividerType.DASH) mDividerPaint.setPathEffect(new DashPathEffect(new float[]{(float) mDividerDashLength, (float) mDividerDashGap}, 0.0f)); else mDividerPaint.setPathEffect(new PathEffect()); }
public PathEffectView(Context context, AttributeSet attrs) { super(context, attrs); mPaint = new Paint(); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(5); mPaint.setColor(Color.DKGRAY); mPath = new Path(); mPath.moveTo(0, 0); for (int i = 0; i <= 30; i++) { mPath.lineTo(i * 35, (float) (Math.random() * 100)); } mEffects = new PathEffect[6]; }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); makeAndMeasurePath(); if (!isInEditMode()) { // Apply the dash effect float length = mPathMeasure.getLength(); PathEffect effect = new DashPathEffect(new float[]{length, length}, length * (1 - mRatio)); mPaint.setPathEffect(effect); } canvas.drawPath(mPath, mPaint); }
public HexagonDrawable(@ColorInt int color, float width, float height, float padding) { mWidth = width; mHeight = height; mPadding = padding; mLenght = width/2 - mPadding*2; mOrigin_x = mWidth/2; mOrigin_y = mHeight/2; //六边形路径 mPath = new Path(); mPath.moveTo(mOrigin_x, mOrigin_y - mLenght); mPath.lineTo((float) (mOrigin_x + Math.sqrt(3f)*mLenght/2), mOrigin_y - mLenght/2); mPath.lineTo((float) (mOrigin_x + Math.sqrt(3f)*mLenght/2), mOrigin_y + mLenght/2); mPath.lineTo(mOrigin_x, mOrigin_y + mLenght); mPath.lineTo((float) (mOrigin_x - Math.sqrt(3f)*mLenght/2), mOrigin_y + mLenght/2); mPath.lineTo((float) (mOrigin_x - Math.sqrt(3f)*mLenght/2), mOrigin_y - mLenght/2); mPath.close(); //初始化画笔 mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(color); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeWidth(1f); //连线节点平滑处理 PathEffect pathEffect = new CornerPathEffect(10); mPaint.setPathEffect(pathEffect); }
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(100, 100, 100, mPaint); PathEffect pathEffect = new DashPathEffect(new float[]{10, 20}, 0); mPaint.setStrokeWidth(100); mPaint.setPathEffect(pathEffect); canvas.drawLine(200, 0, 200, 200, mPaint); }
public void setLineDash(V8Array intervals) { float[] floatIntervals = new float[intervals.length()]; for (int i = 0; i < intervals.length(); i++) { floatIntervals[i] = (float)((double)intervals.getDouble(i)); } PathEffect effects = new DashPathEffect(floatIntervals, 1); mPaintStroke.setPathEffect(effects); intervals.release(); }
public S hasPathEffect(PathEffect effect) { assertThat(actual().getPathEffect()) .named("path effect") .isSameAs(effect); //noinspection unchecked return (S) this; }
public void init() { normalAdapterManager = new BindSuperAdapterManager(); normalAdapterManager .bind(BindImageModel.class, BindImageHolder.ID, BindImageHolder.class) .bind(BindTextModel.class, BindTextHolder.ID, BindTextHolder.class) .bind(BindMutliModel.class, BindMutliHolder.ID, BindMutliHolder.class) .bind(BindClickModel.class, BindClickHolder.ID, BindClickHolder.class) .bindEmpty(BindNoDataHolder.NoDataModel.class, BindNoDataHolder.ID, BindNoDataHolder.class) .setNeedAnimation(true) .setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(Context context, int position) { Toast.makeText(context, "点击了!! " + position, Toast.LENGTH_SHORT).show(); } }); adapter = new BindRecyclerAdapter(this, normalAdapterManager, datas); recycler.setLayoutManager(new LinearLayoutManager(this)); //间隔线 Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setColor(getResources().getColor(R.color.material_deep_teal_200)); PathEffect effects = new DashPathEffect(new float[]{5, 5, 5, 5}, 1); paint.setPathEffect(effects); paint.setStrokeWidth(dip2px(this, 5)); recycler.addItemDecoration(new BindDecorationBuilder(adapter).setPaint(paint).setSpace(dip2px(this, 5)).builder()); recycler.setAdapter(adapter); }
/** * draw moving header line when changing header height or width * @param canvas */ private void drawMovingHeaderLine(Canvas canvas) { if(isDrawMovingHeaderLine && selectedHeaderInfor != null) { Paint paint = PaintKit.instance().getPaint(); //save paint property int oldColor = paint.getColor(); PathEffect oldPathEffect = paint.getPathEffect(); Rect clipRect = canvas.getClipBounds(); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); Path path = new Path(); if(selectedHeaderInfor.getType() == FocusCell.ROWHEADER) { //Rect rect = ModelUtil.instance().getCellAnchor(this, selectedHeaderInfor.getRow(), 0); path.moveTo(0, selectedHeaderInfor.getRect().bottom); path.lineTo(clipRect.right,selectedHeaderInfor.getRect().bottom); } else if(selectedHeaderInfor.getType() == FocusCell.COLUMNHEADER) { path.moveTo(selectedHeaderInfor.getRect().right, 0); path.lineTo(selectedHeaderInfor.getRect().right, clipRect.bottom); } paint.setPathEffect(effects); canvas.drawPath(path, paint); //restore paint.setPathEffect(oldPathEffect); paint.setStyle(Paint.Style.FILL); paint.setColor(oldColor); } }
@Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(true); //间隔线 ds.setStyle(Paint.Style.STROKE); PathEffect effects = new DashPathEffect(new float[]{1, 1}, 1); ds.setPathEffect(effects); ds.setStrokeWidth(5); }
@Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(true); ds.setStyle(Paint.Style.FILL_AND_STROKE); PathEffect effects = new DashPathEffect(new float[]{1, 1}, 1); ds.setPathEffect(effects); ds.setStrokeWidth(2); }
RichShape(final int zIndex, final List<RichPoint> points, final int strokeWidth, final Paint.Cap strokeCap, final Paint.Join strokeJoin, final PathEffect pathEffect, final MaskFilter maskFilter, final Shader strokeShader, final boolean linearGradient, final Integer strokeColor, final boolean antialias, final boolean closed) { this.zIndex = zIndex; this.strokeWidth = strokeWidth; this.strokeCap = strokeCap; this.strokeJoin = strokeJoin; this.pathEffect = pathEffect; this.maskFilter = maskFilter; this.strokeShader = strokeShader; this.linearGradient = linearGradient; this.strokeColor = strokeColor; this.antialias = antialias; this.closed = closed; if (points != null) { for (RichPoint point : points) { add(point); } } }
RichPolyline(final int zIndex, final List<RichPoint> points, final int strokeWidth, final Paint.Cap strokeCap, final Paint.Join strokeJoin, final PathEffect pathEffect, final MaskFilter maskFilter, final Shader strokeShader, final boolean linearGradient, final Integer strokeColor, final boolean antialias, final boolean closed) { super(zIndex, points, strokeWidth, strokeCap, strokeJoin, pathEffect, maskFilter, strokeShader, linearGradient, strokeColor, antialias, closed); }
public AuxiliaryLine(Context context, AttributeSet attributeSet) { super(context, attributeSet); previewwidth = getWidth(); previewheight = getHeight(); Log.e("AuxiliaryLine", " 长宽为" + previewwidth + "*" + previewheight); type = 0; myPaint = new Paint(); myPaint.setColor(Color.rgb(230, 230, 230)); myPaint.setStyle(Paint.Style.STROKE); myPaint.setStrokeWidth(1); myPaint.setAntiAlias(true); PathEffect effects = new DashPathEffect(new float[]{8,8,8,8},0.5f); myPaint.setPathEffect(effects); }
@Override protected void onDraw(Canvas canvas) { //画背景图片 if(mType==0) { if(isToFast||isWrongPose) { canvas.drawBitmap(backgroundWrongImage, src, des, null); } else { canvas.drawBitmap(backgroundImage, src, des, null); } } else { canvas.drawBitmap(backgroundImage, src, des, null); } float rate_src= getRate(); //画进度条 canvas.drawBitmap(progressImage, getSrcRect(src,rate_src), getDesRect(des,rate_src), null); if(mType==0) { canvas.drawLine(0, 0.5f*viewheight, viewwidth, 0.5f*viewheight, mLinePaint_); Path path = new Path(); path.moveTo(0, linestart); path.lineTo(viewwidth,viewheight-linestart); PathEffect effects = new DashPathEffect(new float[]{6,6,6,6},1); mLinePaint.setPathEffect(effects); canvas.drawPath(path, mLinePaint); // canvas.drawLine(0, linestart, viewwidth, viewheight-linestart, mLinePaint); } }
SymbolLine( String name, String th_name, String fname, String group, int color, float width, PathEffect effect_dir, PathEffect effect_rev ) { super( th_name, fname ); init( name, group, color, width ); mPaint.setPathEffect( effect_dir ); mRevPaint.setPathEffect( effect_rev ); mHasEffect = true; makePath(); }
/** * Draws the series. * * @param series the series * @param canvas the canvas * @param paint the paint object * @param pointsList the points to be rendered * @param seriesRenderer the series renderer * @param yAxisValue the y axis value in pixels * @param seriesIndex the series index * @param or the orientation * @param startIndex the start index of the rendering points */ protected void drawSeries(XYSeries series, Canvas canvas, Paint paint, List<Float> pointsList, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, Orientation or, int startIndex) { BasicStroke stroke = seriesRenderer.getStroke(); Cap cap = paint.getStrokeCap(); Join join = paint.getStrokeJoin(); float miter = paint.getStrokeMiter(); PathEffect pathEffect = paint.getPathEffect(); Style style = paint.getStyle(); if (stroke != null) { PathEffect effect = null; if (stroke.getIntervals() != null) { effect = new DashPathEffect(stroke.getIntervals(), stroke.getPhase()); } setStroke(stroke.getCap(), stroke.getJoin(), stroke.getMiter(), Style.FILL_AND_STROKE, effect, paint); } // float[] points = MathHelper.getFloats(pointsList); drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex); drawPoints(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex); paint.setTextSize(seriesRenderer.getChartValuesTextSize()); if (or == Orientation.HORIZONTAL) { paint.setTextAlign(Align.CENTER); } else { paint.setTextAlign(Align.LEFT); } if (seriesRenderer.isDisplayChartValues()) { paint.setTextAlign(seriesRenderer.getChartValuesTextAlign()); drawChartValuesText(canvas, series, seriesRenderer, paint, pointsList, seriesIndex, startIndex); } if (stroke != null) { setStroke(cap, join, miter, style, pathEffect, paint); } }
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { if (attrs != null && !isInEditMode()) { TypedArray ta; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ta = context.obtainStyledAttributes(attrs, R.styleable.CodeEditText, defStyleAttr, defStyleRes); } else { ta = context.obtainStyledAttributes(attrs, R.styleable.CodeEditText); } fontFamily = ta.getString(R.styleable.CodeEditText_fontFamily); if (!TextUtils.isEmpty(fontFamily)) { setTypeface(Typeface.createFromAsset(context.getAssets(), fontFamily)); } else { setTypeface(Typeface.MONOSPACE); } showLineNumber = ta.getBoolean(R.styleable.CodeEditText_showLineNumber, true); lineNumberColor = ta.getColor(R.styleable.CodeEditText_numberColor, Color.BLACK); ta.recycle(); } numberMargin = (int) (context.getResources().getDisplayMetrics().density * 3 + 0.5); mRect = new Rect(); lineNumberPaint = new Paint(); lineNumberPaint.setStyle(Paint.Style.STROKE); lineNumberPaint.setTypeface(getTypeface()); lineNumberPaint.setAntiAlias(true); lineNumberPaint.setFakeBoldText(false); lineNumberPaint.setSubpixelText(true); PathEffect effect = new DashPathEffect(new float[]{4, 4, 4, 4}, 1); lineNumberPaint.setPathEffect(effect); lineNumberPaint.setColor(lineNumberColor); }
@Override protected void onDraw(Canvas canvas) { long st = System.currentTimeMillis(); if (showLineNumber) { int height = getHeight(); int line_height = getLineHeight(); int count = height / line_height; if (getLineCount() > count) { count = getLineCount();//for long text with scrolling } Rect r = mRect; Paint paint = lineNumberPaint; String maxNumber = String.format("%0" + String.valueOf(count).length() + "d", 8); paint.getTextBounds(maxNumber, 0, maxNumber.length(), mRect); int baseLeft = getScrollX(); int lineNumberWidth = r.width() + 2 * numberMargin; int baseline = getLineBounds(0, r);//first line //draw split line canvas.drawLine(baseLeft + lineNumberWidth, 0, baseLeft + lineNumberWidth, count * line_height, paint); getLocalVisibleRect(r); int startLine = r.top / line_height; baseline += startLine * line_height; int endLine = (r.bottom + line_height - 1) / line_height; Rect tRect = new Rect(); PathEffect pathEffect = paint.getPathEffect(); paint.setPathEffect(null); for (int i = startLine; i < endLine; i++) { String number = String.valueOf(i + 1); paint.getTextBounds(number, 0, number.length(), tRect); canvas.drawText(number, baseLeft + lineNumberWidth - tRect.width() - numberMargin, baseline + 1, paint); baseline += line_height; } paint.setPathEffect(pathEffect); } Log.d(null, "C Cost:" + (System.currentTimeMillis() - st)); st = System.currentTimeMillis(); super.onDraw(canvas); Log.d(null, "S Cost:" + (System.currentTimeMillis() - st)); }
private void a(android.graphics.Paint.Cap cap, android.graphics.Paint.Join join, float f1, android.graphics.Paint.Style style, PathEffect patheffect, Paint paint) { paint.setStrokeCap(cap); paint.setStrokeJoin(join); paint.setStrokeMiter(f1); paint.setPathEffect(patheffect); paint.setStyle(style); }
private void initPaint() { mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(5); mPaint.setColor(Color.RED); mPath = new Path(); mPath.moveTo(0, 0); for(int i = 0;i<=30;i++){ mPath.lineTo(i*35, (float)Math.random()*100); } mEffects = new PathEffect[7]; mEffects[0] = null; mEffects[1] = new CornerPathEffect(10); mEffects[2] = new DiscretePathEffect(3.0F, 5.0F); mEffects[3] = new DashPathEffect(new float[] { 20, 10, 5, 10 }, mPhase); Path path = new Path(); path.addRect(0, 0, 8, 8, Path.Direction.CCW); mEffects[4] = new PathDashPathEffect(path, 12, mPhase, PathDashPathEffect.Style.ROTATE); mEffects[5] = new ComposePathEffect(mEffects[2], mEffects[4]); mEffects[6] = new SumPathEffect(mEffects[4], mEffects[3]); }