List of usage examples for android.animation ObjectAnimator setValues
public void setValues(PropertyValuesHolder... values)
From source file:Main.java
public static ObjectAnimator ofPropertyValuesHolder(Object target, PropertyValuesHolder... values) { ObjectAnimator anim = new ObjectAnimator(); anim.setTarget(target);/*from w w w . j a va2 s . c o m*/ anim.setValues(values); cancelOnDestroyActivity(anim); return anim; }
From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java
private static void setupPathMotion(Path path, ObjectAnimator oa, float precision, String propertyXName, String propertyYName) {//from w w w.j a va 2 s .c o m // Measure the total length the whole path. final PathMeasure measureForTotalLength = new PathMeasure(path, false); float totalLength = 0; // The sum of the previous contour plus the current one. Using the sum here b/c we want to // directly substract from it later. ArrayList<Float> contourLengths = new ArrayList<>(); contourLengths.add(0f); do { final float pathLength = measureForTotalLength.getLength(); totalLength += pathLength; contourLengths.add(totalLength); } while (measureForTotalLength.nextContour()); // Now determine how many sample points we need, and the step for next sample. final PathMeasure pathMeasure = new PathMeasure(path, false); final int numPoints = min(MAX_NUM_POINTS, (int) (totalLength / precision) + 1); float[] mX = new float[numPoints]; float[] mY = new float[numPoints]; final float[] position = new float[2]; int contourIndex = 0; float step = totalLength / (numPoints - 1); float currentDistance = 0; // For each sample point, determine whether we need to move on to next contour. // After we find the right contour, then sample it using the current distance value minus // the previously sampled contours' total length. for (int i = 0; i < numPoints; ++i) { pathMeasure.getPosTan(currentDistance, position, null); pathMeasure.getPosTan(currentDistance, position, null); mX[i] = position[0]; mY[i] = position[1]; currentDistance += step; if ((contourIndex + 1) < contourLengths.size() && currentDistance > contourLengths.get(contourIndex + 1)) { currentDistance -= contourLengths.get(contourIndex + 1); contourIndex++; pathMeasure.nextContour(); } } // Given the x and y value of the sample points, setup the ObjectAnimator properly. PropertyValuesHolder x = null; PropertyValuesHolder y = null; if (propertyXName != null) { x = PropertyValuesHolder.ofFloat(propertyXName, mX); } if (propertyYName != null) { y = PropertyValuesHolder.ofFloat(propertyYName, mY); } if (x == null) { oa.setValues(y); } else if (y == null) { oa.setValues(x); } else { oa.setValues(x, y); } }