本文整理汇总了Java中android.graphics.PathMeasure.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java PathMeasure.getLength方法的具体用法?Java PathMeasure.getLength怎么用?Java PathMeasure.getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.PathMeasure
的用法示例。
在下文中一共展示了PathMeasure.getLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PathInterpolatorGingerbread
import android.graphics.PathMeasure; //导入方法依赖的package包/类
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];
}
}
示例2: setPos
import android.graphics.PathMeasure; //导入方法依赖的package包/类
/**
* 用来给每一个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;
}
}
示例3: PathInterpolatorDonut
import android.graphics.PathMeasure; //导入方法依赖的package包/类
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];
}
}
示例4: PathInterpolatorBase
import android.graphics.PathMeasure; //导入方法依赖的package包/类
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];
}
}
示例5: createSuccessPath
import android.graphics.PathMeasure; //导入方法依赖的package包/类
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};
}
示例6: createFailedPath
import android.graphics.PathMeasure; //导入方法依赖的package包/类
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);
}
示例7: getPoints
import android.graphics.PathMeasure; //导入方法依赖的package包/类
protected PathPoints[] getPoints(Path path, int size) {
//Size of 100 indicates that, 100 points
// would be extracted from the path
PathPoints[] pointArray = new PathPoints[size];
PathMeasure pm = new PathMeasure(path, false);
float length = pm.getLength();
float distance = 0f;
float speed = length / size;
int counter = 0;
float[] aCoordinates = new float[2];
while ((distance < length) && (counter < size)) {
pm.getPosTan(distance, aCoordinates, null);
pointArray[counter] = new PathPoints(aCoordinates[0], aCoordinates[1]);
counter++;
distance = distance + speed;
}
return pointArray;
}
示例8: setPoints
import android.graphics.PathMeasure; //导入方法依赖的package包/类
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();
}
示例9: calculateMenuItemPosition
import android.graphics.PathMeasure; //导入方法依赖的package包/类
/**
* calculate and set position to menu items
*/
private void calculateMenuItemPosition() {
float itemRadius = (expandedRadius + collapsedRadius) / 2, f;
RectF area = new RectF(
center.x - itemRadius,
center.y - itemRadius,
center.x + itemRadius,
center.y + itemRadius);
Path path = new Path();
path.addArc(area, (float) fromAngle, (float) (toAngle - fromAngle));
PathMeasure measure = new PathMeasure(path, false);
float len = measure.getLength();
int divisor = getChildCount();
float divider = len / divisor;
for (int i = 0; i < getChildCount(); i++) {
float[] coords = new float[2];
measure.getPosTan(i * divider + divider * .5f, coords, null);
FilterMenu.Item item = (FilterMenu.Item) getChildAt(i).getTag();
item.setX((int) coords[0] - item.getView().getMeasuredWidth() / 2);
item.setY((int) coords[1] - item.getView().getMeasuredHeight() / 2);
}
}
示例10: draw
import android.graphics.PathMeasure; //导入方法依赖的package包/类
void draw(Canvas canvas, Paint paint, int color, float size, Path path) {
PathMeasure mPathMeasure = new PathMeasure();
float[] mPosition = new float[2];
float[] mTan = new float[2];
mPathMeasure.setPath(path, false);
paint.setAntiAlias(true);
paint.setColor(color);
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
Bitmap brush;
// done this way because of a bug in
// Bitmap.createScaledBitmap(getBrush(),(int) size,(int) size,true);
brush = createScaledBitmap(getBrush(), (int) size, (int) size, true);
float len = mPathMeasure.getLength();
float s2 = size / 2;
float step = s2 / 8;
for (float i = 0; i < len; i += step) {
mPathMeasure.getPosTan(i, mPosition, mTan);
// canvas.drawCircle(pos[0], pos[1], size, paint);
canvas.drawBitmap(brush, mPosition[0] - s2, mPosition[1] - s2, paint);
}
}
示例11: onSizeChanged
import android.graphics.PathMeasure; //导入方法依赖的package包/类
@Override
protected void onSizeChanged(final int w, final int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
// Scale and translate the SVG path.
Matrix matrix = new Matrix();
RectF rectF = new RectF();
mPath.computeBounds(rectF, false);
RectF largeRectF = new RectF(0, 0, w * SCALE_FACTOR, h * SCALE_FACTOR);
matrix.setRectToRect(rectF, largeRectF, Matrix.ScaleToFit.CENTER);
float pathTranslationY = getResources().getDimension(R.dimen.path_translation_y);
float pathTranslationX = getResources().getDimension(R.dimen.path_translation_x);
matrix.postTranslate(pathTranslationX, pathTranslationY);
mPath.transform(matrix);
mPathMeasure = new PathMeasure(mPath, false);
mLength = mPathMeasure.getLength();
if (mProgress != 0) {
// Animate the restored frame.
animate(mProgress);
}
}
示例12: initPath
import android.graphics.PathMeasure; //导入方法依赖的package包/类
private void initPath(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];
}
}
示例13: drawFinish
import android.graphics.PathMeasure; //导入方法依赖的package包/类
private void drawFinish() {
mCurrentlyDrawing = false;
PathMeasure pm = new PathMeasure(mPath, false);
mPath.lineTo(mX, mY);
if (pm.getLength() > 0) {
mCanvas.drawPath(mPath, mPaint);
mUndo.add(mPath);
} else {
mCanvas.drawPoint(mX, mY, mPaint);
mUndo.add(mX, mY);
}
mUndoModeActive = true;
// kill the path so we don't double draw
mPath.reset();
if (mUndo.size() == 1 && mCardViewer.get() != null) {
mCardViewer.get().supportInvalidateOptionsMenu();
}
}
示例14: setPath
import android.graphics.PathMeasure; //导入方法依赖的package包/类
/**
* Set the path.
*
* @param path The new path
*/
public void setPath(Path path) {
this.path = path;
partialPath = new Path();
pathMeasure = new PathMeasure(this.path, false);
pathLength = pathMeasure.getLength();
}
示例15: drawTick
import android.graphics.PathMeasure; //导入方法依赖的package包/类
public void drawTick(Canvas canvas) {
mBgPaint.setColor(mProgressColor);
canvas.drawRoundRect(mOvalRect, mRadius, mRadius, mBgPaint);
//draw left
mLeftPath.moveTo(mWidth / 2, mHeight * 3 / 4);
mLeftPath.lineTo(mWidth / 2 - mHeight / 4, mHeight * 3 / 5);
mLeftPathMeasure = new PathMeasure(mLeftPath, true);
Path leftDst = new Path();
float leftStop = mLeftPathMeasure.getLength() * mAnimationValue;
mLeftPathMeasure.getSegment(0, leftStop, leftDst, true);
canvas.drawPath(leftDst, mTickPaint);
//draw right
mRightPath.moveTo(mWidth / 2, mHeight * 3 / 4);
mRightPath.lineTo(mWidth / 2 + mHeight / 4, mHeight / 4);
mRightPathMeasure = new PathMeasure(mRightPath, true);
Path rightDst = new Path();
float rightStop = mRightPathMeasure.getLength() * mAnimationValue;
mRightPathMeasure.getSegment(0, rightStop, rightDst, true);
canvas.drawPath(rightDst, mTickPaint);
//some devices do not support pathmeasure
if (mIsDone) {
canvas.drawPath(mLeftPath, mTickPaint);
canvas.drawPath(mRightPath, mTickPaint);
}
}