use of android.graphics.PathMeasure in project LoadingDrawable by dinuscxj.
the class CircleBroodLoadingRenderer method getRestLength.
private float getRestLength(Path path, float startD) {
Path tempPath = new Path();
PathMeasure pathMeasure = new PathMeasure(path, false);
pathMeasure.getSegment(startD, pathMeasure.getLength(), tempPath, true);
pathMeasure.setPath(tempPath, false);
return pathMeasure.getLength();
}
use of android.graphics.PathMeasure in project WilliamChart by diogobernardino.
the class Animation method prepareAnimation.
/**
* Method that prepares the animation. Defines starting points, targets,
* distance, yadda, as well as the first set of points to be drawn.
*
* @param start X and Y start coordinates
* @param end X and Y end coordinates
*
* @return Array of {@link ChartSet} containing the first values to be drawn.
*/
private ArrayList<ChartSet> prepareAnimation(ArrayList<float[][]> start, ArrayList<float[][]> end) {
final int nSets = start.size();
final int nEntries = start.get(0).length;
mCurrEntryDuration = new long[nEntries];
// Set the animation order if not defined already
if (mOrder == null) {
mOrder = new int[nEntries];
for (int i = 0; i < mOrder.length; i++) mOrder[i] = i;
} else {
// check if size equal than set's entries size
if (mOrder.length != nEntries)
throw new IllegalArgumentException("Size of overlap order different than set's entries size.");
}
// Define animation paths for each entry
Path path;
mPathMeasures = new PathMeasure[nSets][nEntries];
for (int i = 0; i < nSets; i++) {
for (int j = 0; j < nEntries; j++) {
path = new Path();
path.moveTo(start.get(i)[j][0], start.get(i)[j][1]);
path.lineTo(end.get(i)[j][0], end.get(i)[j][1]);
mPathMeasures[i][j] = new PathMeasure(path, false);
}
}
// Calculates the expected duration as there was with no overlap (factor = 0)
float noOverlapDuration = mDuration / nEntries;
// Adjust the duration to the overlap
mEntryDuration = (int) (noOverlapDuration + (mDuration - noOverlapDuration) * mOverlapingFactor);
// Define initial time for each entry
mEntryInitTime = new long[nEntries];
mInitTime = System.currentTimeMillis();
long noOverlapInitTime;
for (int i = 0; i < nEntries; i++) {
// Calculates the expected init time as there was with no overlap (factor = 0)
noOverlapInitTime = mInitTime + (i * (mDuration / nEntries));
// Adjust the init time to overlap
mEntryInitTime[mOrder[i]] = (noOverlapInitTime - ((long) (mOverlapingFactor * (noOverlapInitTime - mInitTime))));
}
mPlaying = true;
return animate(mData);
}
use of android.graphics.PathMeasure in project Depth-LIB-Android- by danielzeller.
the class PathBitmapMesh method matchVertsToPath.
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);
}
}
}
use of android.graphics.PathMeasure in project Depth-LIB-Android- by danielzeller.
the class RenderableThree method matchVertsToPath.
private void matchVertsToPath() {
PathMeasure pmLeft = new PathMeasure(pathLeft, false);
PathMeasure pmRight = new PathMeasure(pathRight, false);
float[] coords = new float[2];
for (int i = 0; i < staticVerts.length / 2; i++) {
float yIndexValue = staticVerts[i * 2 + 1];
float xIndexValue = staticVerts[i * 2];
if (xIndexValue == 0) {
float percentOffsetY = (0.000001f + yIndexValue) / bitmap.getHeight();
pmLeft.getPosTan(pmLeft.getLength() * (1f - percentOffsetY), coords, null);
setXY(drawingVerts, i, coords[0], coords[1]);
} else {
float percentOffsetY = (0.000001f + yIndexValue) / bitmap.getHeight();
pmRight.getPosTan(pmRight.getLength() * (1f - percentOffsetY), coords, null);
setXY(drawingVerts, i, coords[0], coords[1]);
}
}
}
use of android.graphics.PathMeasure in project AndroidRubberIndicator by LyndonChin.
the class RubberIndicator method move.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void move(final boolean toRight) {
final int nextPos = getNextPosition(toRight);
if (nextPos == -1)
return;
mSmallCircle = mCircleViews.get(nextPos);
// Calculate the new x coordinate for circles.
float smallCircleX = toRight ? mLargeCircle.getX() : mLargeCircle.getX() + mLargeCircle.getWidth() - mSmallCircle.getWidth();
float largeCircleX = toRight ? mSmallCircle.getX() + mSmallCircle.getWidth() - mLargeCircle.getWidth() : mSmallCircle.getX();
float outerCircleX = mOuterCircle.getX() + largeCircleX - mLargeCircle.getX();
// animations for large circle and outer circle.
PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", mLargeCircle.getX(), largeCircleX);
ObjectAnimator largeCircleAnim = ObjectAnimator.ofPropertyValuesHolder(mLargeCircle, pvhX, mPvhScaleX, mPvhScaleY);
pvhX = PropertyValuesHolder.ofFloat("x", mOuterCircle.getX(), outerCircleX);
ObjectAnimator outerCircleAnim = ObjectAnimator.ofPropertyValuesHolder(mOuterCircle, pvhX, mPvhScaleX, mPvhScaleY);
// Animations for small circle
PointF smallCircleCenter = mSmallCircle.getCenter();
PointF smallCircleEndCenter = new PointF(smallCircleCenter.x - (mSmallCircle.getX() - smallCircleX), smallCircleCenter.y);
// Create motion anim for small circle.
mSmallCirclePath.reset();
mSmallCirclePath.moveTo(smallCircleCenter.x, smallCircleCenter.y);
mSmallCirclePath.quadTo(smallCircleCenter.x, smallCircleCenter.y, (smallCircleCenter.x + smallCircleEndCenter.x) / 2, (smallCircleCenter.y + smallCircleEndCenter.y) / 2 + mBezierCurveAnchorDistance);
mSmallCirclePath.lineTo(smallCircleEndCenter.x, smallCircleEndCenter.y);
ValueAnimator smallCircleAnim;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
smallCircleAnim = ObjectAnimator.ofObject(mSmallCircle, "center", null, mSmallCirclePath);
} else {
final PathMeasure pathMeasure = new PathMeasure(mSmallCirclePath, false);
final float[] point = new float[2];
smallCircleAnim = ValueAnimator.ofFloat(0.0f, 1.0f);
smallCircleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
pathMeasure.getPosTan(pathMeasure.getLength() * animation.getAnimatedFraction(), point, null);
mSmallCircle.setCenter(new PointF(point[0], point[1]));
}
});
}
mPvhRotation.setFloatValues(0, toRight ? -30f : 30f, 0, toRight ? 30f : -30f, 0);
ObjectAnimator otherAnim = ObjectAnimator.ofPropertyValuesHolder(mSmallCircle, mPvhRotation, mPvhScale);
mAnim = new AnimatorSet();
mAnim.play(smallCircleAnim).with(otherAnim).with(largeCircleAnim).with(outerCircleAnim);
mAnim.setInterpolator(new AccelerateDecelerateInterpolator());
mAnim.setDuration(500);
mAnim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
swapCircles(mFocusPosition, nextPos);
mFocusPosition = nextPos;
if (mOnMoveListener != null) {
if (toRight) {
mOnMoveListener.onMovedToRight();
} else {
mOnMoveListener.onMovedToLeft();
}
}
if (!mPendingAnimations.isEmpty()) {
move(mPendingAnimations.removeFirst());
}
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
mAnim.start();
}
Aggregations