/** * Translate a view to the specified translation values, while rotating to the specified rotation * value. */ public static void addTranslationRotationAnimators( List<Animator> animators, final View view, int xTranslation, int yTranslation, float rotation, int animationDelay) { addXYTranslationAnimators(animators, view, xTranslation, yTranslation, animationDelay); view.setLayerType(View.LAYER_TYPE_HARDWARE, null); view.setRotation(rotation); final ObjectAnimator rotateAnimatorY = ObjectAnimator.ofFloat(view, View.ROTATION, view.getRotation(), 0.0f); rotateAnimatorY.setInterpolator(sDecelerateQuintInterpolator); rotateAnimatorY.setDuration(sAnimationDuration); rotateAnimatorY.setStartDelay(animationDelay); rotateAnimatorY.addListener( new AnimatorListenerAdapter() { private boolean mIsCanceled = false; @Override public void onAnimationCancel(Animator animation) { mIsCanceled = true; } @Override public void onAnimationEnd(Animator animation) { if (!mIsCanceled) { view.setRotation(0); } view.setLayerType(View.LAYER_TYPE_NONE, null); } }); animators.add(rotateAnimatorY); }
/** Animate the selected photo to the foreground: zooming in to bring it forward. */ private void pickUp(final View photo) { float photoWidth = photo.getWidth(); float photoHeight = photo.getHeight(); float scale = Math.min(getHeight() / photoHeight, getWidth() / photoWidth); log("scale is %f", scale); log("target it"); float x = (getWidth() - photoWidth) / 2f; float y = (getHeight() - photoHeight) / 2f; photo.setRotation(wrapAngle(photo.getRotation())); log("animate it"); // lift up to the glass for a good look mWaitingToJoinBackground.remove(photo); moveToForeground(photo); photo .animate() .withLayer() .rotation(0f) .rotationY(0f) .alpha(1f) .scaleX(scale) .scaleY(scale) .x(x) .y(y) .setDuration(mPickUpDuration) .setInterpolator(new DecelerateInterpolator(2f)) .withEndAction( new Runnable() { @Override public void run() { log("endtimes: %f", photo.getX()); } }); }
public static float getRotation(View view) { return view.getRotation(); }
@Override public float getRotation(View view) { return view.getRotation(); }