static android.animation.Animator | createAnimation(android.view.View view, TransitionValues values, int viewPosX, int viewPosY, float startX, float startY, float endX, float endY, android.animation.TimeInterpolator interpolator)Creates an animator that can be used for x and/or y translations. When interrupted,
it sets a tag to keep track of the position so that it may be continued from position.
float terminalX = view.getTranslationX();
float terminalY = view.getTranslationY();
int[] startPosition = (int[]) values.view.getTag(R.id.transitionPosition);
if (startPosition != null) {
startX = startPosition[0] - viewPosX + terminalX;
startY = startPosition[1] - viewPosY + terminalY;
}
// Initial position is at translation startX, startY, so position is offset by that amount
int startPosX = viewPosX + Math.round(startX - terminalX);
int startPosY = viewPosY + Math.round(startY - terminalY);
view.setTranslationX(startX);
view.setTranslationY(startY);
if (startX == endX && startY == endY) {
return null;
}
Path path = new Path();
path.moveTo(startX, startY);
path.lineTo(endX, endY);
ObjectAnimator anim = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
path);
TransitionPositionListener listener = new TransitionPositionListener(view, values.view,
startPosX, startPosY, terminalX, terminalY);
anim.addListener(listener);
anim.addPauseListener(listener);
anim.setInterpolator(interpolator);
return anim;
|