public PathInterpolatorGingerbread(Path path) { final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */); final float pathLength = pathMeasure.getLength(); final int numPoints = (int) (pathLength / PRECISION) + 1; mX = new float[numPoints]; mY = new float[numPoints]; final float[] position = new float[2]; for (int i = 0; i < numPoints; ++i) { final float distance = (i * pathLength) / (numPoints - 1); pathMeasure.getPosTan(distance, position, null /* tangent */); mX[i] = position[0]; mY[i] = position[1]; } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.translate(x, y); for (int i = 0; i < pathMeasures.size(); i++) { Path path1 = new Path(); PathMeasure pathMeasure = pathMeasures.get(i); MyPath path = paths.get(i); if (!isReverse) { pathMeasure.getSegment(0, pathMeasure.getLength() * animatorValue, path1, true); canvas.drawPath(path1, linePaint); } else { pathMeasure.getSegment(0, pathMeasure.getLength() * (1 - animatorValue), path1, true); canvas.drawPath(path1, linePaint); } drawCircles(radiusArray.get(i), canvas, path.endPoint, path.endDirection, i); } drawCenterCircle(canvas); // drawCircles(radiusArray.get(0),canvas, paths.get(0).endPoint, paths.get(0).endDirection); }
public FreshDownloadView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); circular_edge = getResources().getDimension(R.dimen.edge); bounds = new Rect(); mTempBounds = new RectF(); publicPaint = new Paint(); path1 = new Path(); path2 = new Path(); path3 = new Path(); pathMeasure1 = new PathMeasure(); pathMeasure2 = new PathMeasure(); pathMeasure3 = new PathMeasure(); textBounds = new Rect(); parseAttrs(context.obtainStyledAttributes(attrs, R.styleable.FreshDownloadView)); initPaint(); }
private void initData() { defaultPadding = 2 * radius + dp2px(2); defaultPaddingBottom = 2 * radius + dp2px(15); defaultWidth = (int) (2 * defaultPadding + dp2px(200)); defaultHeight = (int) (defaultPadding + defaultPaddingBottom + dp2px(80)); paint = new Paint[ballCount]; for (int i = 0; i < paint.length; i++) { paint[i] = new Paint(Paint.ANTI_ALIAS_FLAG); paint[i].setColor(ballColor); paint[i].setStyle(Paint.Style.FILL); } path = new Path(); pathMeasure = new PathMeasure(); randomBallColors = new int[ballCount]; randomRadius = new float[ballCount]; randomTransRatioX = new float[ballCount]; randomTransRatioY = new float[ballCount]; translateFraction = new float[ballCount]; translateAnim = new ValueAnimator[ballCount]; }
private void initRoomTempPath(float[] data) { mRoomTempPath.reset(); // Path path = new Path(); float pointX; float pointY; // 横向 mRoomTempPath.moveTo(Xpoint + xFirstPointOffset, getDataY(data[0], Ylabel)); mRoomTempPath.moveTo(Xpoint + xFirstPointOffset, getDataY(data[0], Ylabel)); for (int i = 0; i < Xlabel.length; i++) { float startX = Xpoint + i * Xscale + xFirstPointOffset; // 绘制数据连线 if (i != 0) { pointX = Xpoint + (i - 1) * Xscale + xFirstPointOffset; pointY = getDataY(data[i - 1], Ylabel); mRoomTempPath.lineTo(pointX, pointY); } if (i == Xlabel.length - 1) { pointX = startX; pointY = getDataY(data[i], Ylabel); mRoomTempPath.lineTo(pointX, pointY); } } mRoomTempPathMeasure = new PathMeasure(mRoomTempPath, false); }
/** * 获取target temp绘线Path数据 * * @param data target temp绘线Path数据 */ private void initTargetTempPath(float[] data) { mTargetTempPath.reset(); float pointX; float pointY; // 横向 mTargetTempPath.moveTo(Xpoint + xFirstPointOffset, getDataY(data[0], Ylabel)); for (int i = 0; i < Xlabel.length; i++) { float startX = Xpoint + i * Xscale + xFirstPointOffset; // 绘制数据连线 if (i != 0) { pointX = Xpoint + (i - 1) * Xscale + xFirstPointOffset; pointY = getDataY(data[i - 1], Ylabel); mTargetTempPath.lineTo(pointX, pointY); } if (i == Xlabel.length - 1) { pointX = startX; pointY = getDataY(data[i], Ylabel); mTargetTempPath.lineTo(pointX, pointY); } } mTargetTempPathMeasure = new PathMeasure(mTargetTempPath, false); }
public void matchVertsToPath(Path path, float bottomCoord, float extraOffset) { PathMeasure pm = new PathMeasure(path, false); for (int i = 0; i < staticVerts.length / 2; i++) { float yIndexValue = staticVerts[i * 2 + 1]; float xIndexValue = staticVerts[i * 2]; float percentOffsetX = (0.000001f + xIndexValue) / bitmap.getWidth(); float percentOffsetX2 = (0.000001f + xIndexValue) / (bitmap.getWidth() + extraOffset); percentOffsetX2 += pathOffsetPercent; pm.getPosTan(pm.getLength() * (1f - percentOffsetX), coords, null); pm.getPosTan(pm.getLength() * (1f - percentOffsetX2), coords2, null); if (yIndexValue == 0) { setXY(drawingVerts, i, coords[0], coords2[1]); } else { float desiredYCoord = bottomCoord; setXY(drawingVerts, i, coords[0], desiredYCoord); } } }
public void matchVertsToPath(Path path, float extraOffset) { PathMeasure pm = new PathMeasure(path, false); int index = 0; for (int i = 0; i < staticVerts.length / 2; i++) { float yIndexValue = staticVerts[i * 2 + 1]; float xIndexValue = staticVerts[i * 2]; float percentOffsetX = (0.000001f + xIndexValue) / bitmap.getWidth(); float percentOffsetX2 = (0.000001f + xIndexValue) / (bitmap.getWidth() + extraOffset); percentOffsetX2 += pathOffsetPercent; pm.getPosTan(pm.getLength() * (1f - percentOffsetX), coords, null); pm.getPosTan(pm.getLength() * (1f - percentOffsetX2), coords2, null); if (yIndexValue == 0) { setXY(drawingVerts, i, coords[0], coords2[1] + verticalOffset); } else { float desiredYCoord = Math.max(coords2[1], coords2[1] + easedFoamCoords[Math.min(easedFoamCoords.length - 1, index)]); setXY(drawingVerts, i, coords[0], desiredYCoord + verticalOffset); index += 1; } } }
@Override public PointF getValue(Keyframe<PointF> keyframe, float keyframeProgress) { PathKeyframe pathKeyframe = (PathKeyframe) keyframe; Path path = pathKeyframe.getPath(); if (path == null) { return keyframe.startValue; } if (pathMeasureKeyframe != pathKeyframe) { pathMeasure = new PathMeasure(path, false); pathMeasureKeyframe = pathKeyframe; } pathMeasure.getPosTan(keyframeProgress * pathMeasure.getLength(), pos, null); point.set(pos[0], pos[1]); return point; }
public SunnyType(Context context, ShortWeatherInfo info) { super(context); mPathFront = new Path(); mPathRear = new Path(); sunPath = new Path(); mPaint = new Paint(); pos = new float[2]; tan = new float[2]; mMatrix = new Matrix(); measure = new PathMeasure(); sunMeasure = new PathMeasure(); currentSunPosition = TimeUtils.getTimeDiffPercent(info.getSunrise(), info.getSunset()); currentMoonPosition = TimeUtils.getTimeDiffPercent(info.getMoonrise(), info.getMoonset()); if (currentSunPosition >= 0 && currentSunPosition <= 1) { setColor(colorDay); boat = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.ic_boat_day); } else { setColor(colorNight); boat = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.ic_boat_night); } cloud = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.ic_cloud); }
public RainType(Context context, @RainLevel int rainLevel, @WindLevel int windLevel) { super(context); setColor(0xFF6188DA); this.rainLevel = rainLevel; this.windLevel = windLevel; mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(Color.WHITE); mPaint.setStrokeWidth(5); mPaint.setStyle(Paint.Style.STROKE); mRains = new ArrayList<>(); mSnows = new ArrayList<>(); matrix = new Matrix(); bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_rain_ground); mDstFlash1 = new Path(); flashPathMeasure1 = new PathMeasure(); mDstFlash2 = new Path(); flashPathMeasure2 = new PathMeasure(); mDstFlash3 = new Path(); flashPathMeasure3 = new PathMeasure(); }
/** * 用来给每一个button设置一个中心点 * * @param orbit 一个特定角度的path */ private void setPos(Path orbit) { PathMeasure measure = new PathMeasure(orbit, false); TextLableView tv; for (int i = 0; i < mButtons.size(); i++) { PopupButton pp = mButtons.get(i); tv = kvs.get(pp); float[] coords = new float[]{0f, 0f}; int length = (int) ((i) * measure.getLength() / mButtons.size()); measure.getPosTan(length, coords, null); int px = (int) coords[0] - pp.getMeasuredWidth() / 2; int py = (int) coords[1] - pp.getMeasuredHeight() / 2; int tvx = (int) coords[0] - tv.getMeasuredWidth() / 2; tv.x = tvx; tv.y = py - 60; pp.x = px; pp.y = py; } }
public PathInterpolatorDonut(Path path) { final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */); final float pathLength = pathMeasure.getLength(); final int numPoints = (int) (pathLength / PRECISION) + 1; mX = new float[numPoints]; mY = new float[numPoints]; final float[] position = new float[2]; for (int i = 0; i < numPoints; ++i) { final float distance = (i * pathLength) / (numPoints - 1); pathMeasure.getPosTan(distance, position, null /* tangent */); mX[i] = position[0]; mY[i] = position[1]; } }
private void init() { borderPaint = new Paint(); borderPaint.setColor(borderColor); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderWidth); rectPaint = new Paint(); rectPaint.setColor(rectColor); rectPaint.setStyle(Paint.Style.FILL); linePaint = new Paint(); linePaint.setAntiAlias(true); linePaint.setColor(lineColor); linePaint.setStyle(Paint.Style.STROKE); linePaint.setStrokeWidth(lineWidth); linePaint.setStrokeJoin(Paint.Join.ROUND); textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setColor(textColor); textPaint.setTextSize(textSize); fm = textPaint.getFontMetrics(); path = new Path(); pathDst = new Path(); pm = new PathMeasure(); selectedIndex = -1; }
private void init(int selectedBgColor, float pointStrokeWidth, int pathColor, float pathWidth) { pointPaint = new Paint(); pointPaint.setAntiAlias(true); pointPaint.setColor(pointColor); pointPaint.setStrokeWidth(pointStrokeWidth); pointPaint.setStyle(Paint.Style.STROKE); pathPaint = new Paint(); pathPaint.setAntiAlias(true); pathPaint.setColor(pathColor); pathPaint.setStrokeWidth(pathWidth); pathPaint.setStyle(Paint.Style.STROKE); selectedBgPaint = new Paint(); selectedBgPaint.setAntiAlias(true); selectedBgPaint.setColor(selectedBgColor); selectedBgPaint.setStrokeWidth(0); selectedBgPaint.setStyle(Paint.Style.FILL); selectedBgPaint.setAlpha(100); path = new Path(); pathDst = new Path(); pm = new PathMeasure(); rectOval = new RectF(); selectedIndex = -1; }
private void init() { mPaint = new Paint(); mPaint.setStyle(Paint.Style.STROKE); // 设置为空心 mPaint.setStrokeWidth(15); // 宽度 mPaint.setColor(Color.RED); // 颜色 mPaint.setStrokeCap(Paint.Cap.ROUND); // 设置画笔为园笔 mPaint.setAntiAlias(true); // 抗锯齿 mPath = new Path(); // 路径 RectF rect = new RectF(-100, -100, 100, 100); // 测定圆弧的范围 mPath.addArc(rect, -90, 359.9f); // 设置路径范围,起始角度,终止角度 mPathMeasure = new PathMeasure(mPath, false); // 初始化要截取的路径 valueAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(2500); valueAnimator.setRepeatCount(ValueAnimator.INFINITE); // 设置动画播放模式 valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { animationValue = (float) animation.getAnimatedValue(); invalidate(); } }); valueAnimator.start(); }
public PathInterpolatorBase(Path path) { final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */); final float pathLength = pathMeasure.getLength(); final int numPoints = (int) (pathLength / PRECISION) + 1; mX = new float[numPoints]; mY = new float[numPoints]; final float[] position = new float[2]; for (int i = 0; i < numPoints; ++i) { final float distance = (i * pathLength) / (numPoints - 1); pathMeasure.getPosTan(distance, position, null /* tangent */); mX[i] = position[0]; mY[i] = position[1]; } }
private Point calculateItemPositions(Integer startAngle, Integer endAngle) { final Point center = getActionViewCenter(); RectF area = new RectF(center.x - radius, center.y - radius, center.x + radius, center.y + radius); Path orbit = new Path(); orbit.addArc(area, startAngle, endAngle - startAngle); PathMeasure measure = new PathMeasure(orbit, false); // Prevent overlapping when it is a full circle int divisor; if (Math.abs(endAngle - startAngle) >= 360 || subMenuButtons.size() <= 1) { divisor = subMenuButtons.size(); } else { divisor = subMenuButtons.size() - 1; } // Measure the path in order to find points that have the same distance between each other for (int i = 0; i < subMenuButtons.size(); i++) { SubButton currentSubButton = subMenuButtons.get(i); float[] coordinates = new float[]{0f, 0f}; int factor = animationType == AnimationType.RADIAL ? 0 : i; measure.getPosTan(factor * measure.getLength() / divisor, coordinates, null); currentSubButton.setX((int) coordinates[0] - currentSubButton.getWidth() / 2); currentSubButton.setY((int) coordinates[1] - currentSubButton.getHeight() / 2); } return center; }
public TagViewGroup(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); Resources.Theme theme = context.getTheme(); TypedArray array = theme.obtainStyledAttributes(attrs, R.styleable.TagViewGroup, defStyleAttr, 0); mRadius = array.getDimensionPixelSize(R.styleable.TagViewGroup_radius, DipConvertUtils.dip2px(context, DEFAULT_RADIUS)); mInnerRadius = array.getDimensionPixelSize(R.styleable.TagViewGroup_inner_radius, DipConvertUtils.dip2px(context, DEFAULT_INNER_RADIUS)); mTDistance = array.getDimensionPixelSize(R.styleable.TagViewGroup_tilt_distance, DipConvertUtils.dip2px(context, DEFAULT_TILT_DISTANCE)); mVDistance = array.getDimensionPixelSize(R.styleable.TagViewGroup_v_distance, DipConvertUtils.dip2px(context, DEFAULT_V_DISTANCE)); mLinesWidth = array.getDimensionPixelSize(R.styleable.TagViewGroup_line_width, DipConvertUtils.dip2px(context, DEFAULT_LINES_WIDTH)); mRippleMaxRadius = array.getDimensionPixelSize(R.styleable.TagViewGroup_ripple_maxRadius, DipConvertUtils.dip2px(context, DEFAULT_RIPPLE_MAX_RADIUS)); mRippleAlpha = array.getInteger(R.styleable.TagViewGroup_ripple_alpha, DEFULT_RIPPLE_ALPHA); mRippleMinRadius = mInnerRadius + (mRadius - mInnerRadius) / 2; array.recycle(); mPaint = new Paint(); mPath = new Path(); mDstPath = new Path(); mPathMeasure = new PathMeasure(); mPaint.setAntiAlias(true); mGestureDetector = new GestureDetectorCompat(context, new TagOnGestureListener()); mChildUsed = new int[4]; mCenterRect = new RectF(); }
private void initTool() { oPaint = new Paint(Paint.ANTI_ALIAS_FLAG); oPaint.setStyle(Paint.Style.FILL_AND_STROKE); cPaint = new Paint(Paint.ANTI_ALIAS_FLAG); cPaint.setStyle(Paint.Style.STROKE); cPaint.setStrokeCap(Paint.Cap.ROUND); sPaint = new Paint(Paint.ANTI_ALIAS_FLAG); sPaint.setStyle(Paint.Style.FILL); path = new Path(); dstPath = new Path(); pathMeasure = new PathMeasure(); for (int i = 0; i < menuRectFs.length; i++) { menuRectFs[i] = new RectF(); } }
private void reMeasure() { int mViewWidth = getWidth(); int mViewHeight = getHeight(); mCenterX = mViewWidth / 2; mCenterY = mViewHeight / 2; temp = mRadius / 2.0f * factor; Path path = new Path(); path.moveTo(mCenterX - temp, mCenterY - temp); path.lineTo(mCenterX + temp, mCenterY + temp); pathLeftMeasure = new PathMeasure(path, false); path = new Path(); path.moveTo(mCenterX + temp, mCenterY - temp); path.lineTo(mCenterX - temp, mCenterY + temp); pathRightMeasure = new PathMeasure(path, false); }
/** * 画折线 * * @param canvas */ public void drawLines(Canvas canvas, Line line) { if (line != null && isShow) { linePaint.setColor(line.getLineColor()); linePaint.setStrokeWidth(LeafUtil.dp2px(mContext, line.getLineWidth())); linePaint.setStyle(Paint.Style.STROKE); List<PointValue> values = line.getValues(); Path path = line.getPath(); int size = values.size(); for (int i = 0; i < size; i++) { PointValue point = values.get(i); if (i == 0) path.moveTo(point.getOriginX(), point.getOriginY()); else path.lineTo(point.getOriginX(), point.getOriginY()); } measure = new PathMeasure(path, false); linePaint.setPathEffect(createPathEffect(measure.getLength(), phase, 0.0f)); canvas.drawPath(path, linePaint); } }
/** * 画折线 * * @param canvas */ public void drawLines(Canvas canvas, Line line, Axis axisY, int moveX) { if(line != null && isShow){ linePaint.setColor(line.getLineColor()); linePaint.setStrokeWidth(LeafUtil.dp2px(mContext, line.getLineWidth())); linePaint.setStyle(Paint.Style.STROKE); List<PointValue> values = line.getValues(); Path path = line.getPath(); int size = values.size(); for (int i = 0; i < size; i++) { PointValue point = values.get(i); if(i == 0) path.moveTo(point.getOriginX() + moveX, point.getOriginY()); else path.lineTo(point.getOriginX() + moveX, point.getOriginY()); } measure = new PathMeasure(path, false); linePaint.setPathEffect(createPathEffect(measure.getLength(), phase, 0.0f)); canvas.save(Canvas.CLIP_SAVE_FLAG); canvas.clipRect(axisY.getStartX(), 0, mWidth, mHeight); canvas.drawPath(path, linePaint); canvas.restore(); } }
/** * 初始化 Path */ private void initPath() { mSearchPath = new Path(); mCirclePath = new Path(); mMeasure = new PathMeasure(); RectF oval1 = new RectF(-50, -50, 50, 50); mSearchPath.addArc(oval1, 45, 359.9f); // 放大镜的圆框 RectF oval2 = new RectF(-100, -100, 100, 100); mCirclePath.addArc(oval2, 45, 359.9f); // 搜索的圆圈 float[] pos = new float[2]; mMeasure.setPath(mCirclePath, false); mMeasure.getPosTan(0, pos, null); // 放大镜手柄的末端 mSearchPath.lineTo(pos[0], pos[1]); // 放大镜的手柄 }
private void createSuccessPath(){ if(mSuccessPath != null){ mSuccessPath.reset(); }else{ mSuccessPath = new Path(); } float mLineWith = 2*mDensity; float left = width/2 - mRadius + mRadius/3 + mLineWith; float top = mPadding + mRadius/2 + mLineWith; float right = width/2 + mRadius - mLineWith - mRadius/3; float bottom = (mLineWith + mRadius) * 1.5f + mPadding/2; float xPoint = width/2 - mRadius/6; mSuccessPath = new Path(); mSuccessPath.moveTo(left, mPadding+mRadius + mLineWith); mSuccessPath.lineTo(xPoint,bottom); mSuccessPath.lineTo(right,top); PathMeasure measure = new PathMeasure(mSuccessPath, false); mSuccessPathLength = measure.getLength(); mSuccessPathIntervals = new float[]{mSuccessPathLength, mSuccessPathLength}; }
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); }
private void init(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); width = wm.getDefaultDisplay().getWidth(); height = (int) (wm.getDefaultDisplay().getHeight() * 3 / 2f); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setStrokeWidth(2); mPaint.setColor(Color.BLUE); mPaint.setStyle(Paint.Style.STROKE); pathMeasure = new PathMeasure(); builderFollower(fllowerCount, fllowers1); builderFollower(fllowerCount, fllowers2); builderFollower(fllowerCount, fllowers3); }
/** * 绘制外层圆环进度和小圆点 */ private void drawRingProgress(Canvas canvas) { Path path = new Path(); path.addArc(mMiddleProgressRect, mStartAngle, mCurrentAngle); PathMeasure pathMeasure = new PathMeasure(path, false); pathMeasure.getPosTan(pathMeasure.getLength() * 1, pos, tan); matrix.reset(); matrix.postTranslate(pos[0] - bitmap.getWidth() / 2, pos[1] - bitmap.getHeight() / 2); canvas.drawPath(path, mArcProgressPaint); //起始角度不为0时候才进行绘制小圆点 if (mCurrentAngle == 0) { return; } canvas.drawBitmap(bitmap, matrix, mBitmapPaint); mBitmapPaint.setColor(Color.WHITE); canvas.drawCircle(pos[0], pos[1], 8, mBitmapPaint); }