use of com.nineoldandroids.animation.Animator in project PhotoPicker by donglua.
the class ImagePagerFragment method runExitAnimation.
/**
* The exit animation is basically a reverse of the enter animation, except that if
* the orientation has changed we simply scale the picture back into the center of
* the screen.
*
* @param endAction This action gets run after the animation completes (this is
* when we actually switch activities)
*/
public void runExitAnimation(final Runnable endAction) {
if (!getArguments().getBoolean(ARG_HAS_ANIM, false) || !hasAnim) {
endAction.run();
return;
}
final long duration = ANIM_DURATION;
// Animate image back to thumbnail size/location
ViewPropertyAnimator.animate(mViewPager).setDuration(duration).setInterpolator(new AccelerateInterpolator()).scaleX((float) thumbnailWidth / mViewPager.getWidth()).scaleY((float) thumbnailHeight / mViewPager.getHeight()).translationX(thumbnailLeft).translationY(thumbnailTop).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
endAction.run();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
// Fade out background
ObjectAnimator bgAnim = ObjectAnimator.ofInt(mViewPager.getBackground(), "alpha", 0);
bgAnim.setDuration(duration);
bgAnim.start();
// Animate a color filter to take the image back to grayscale,
// in parallel with the image scaling and moving into place.
ObjectAnimator colorizer = ObjectAnimator.ofFloat(ImagePagerFragment.this, "saturation", 1, 0);
colorizer.setDuration(duration);
colorizer.start();
}
use of com.nineoldandroids.animation.Animator in project Meizhi by drakeet.
the class FloatView method translationX.
public void translationX(float fromX, float toX, float formAlpha, final float toAlpha) {
ObjectAnimator a1 = ObjectAnimator.ofFloat(rootView, "alpha", formAlpha, toAlpha);
ObjectAnimator a2 = ObjectAnimator.ofFloat(rootView, "translationX", fromX, toX);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(a1, a2);
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
if (toAlpha == 0) {
HeadsUpManager.getInstant(getContext()).dismiss();
cutDown = -1;
if (velocityTracker != null) {
velocityTracker.clear();
try {
velocityTracker.recycle();
} catch (IllegalStateException e) {
}
}
}
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
animatorSet.start();
}
use of com.nineoldandroids.animation.Animator in project ListViewAnimations by nhaarman.
the class AnimationAdapter method animateViewIfNecessary.
/**
* Animates given View if necessary.
*
* @param position the position of the item the View represents.
* @param view the View that should be animated.
* @param parent the parent the View is hosted in.
*/
private void animateViewIfNecessary(final int position, @NonNull final View view, @NonNull final ViewGroup parent) {
assert mViewAnimator != null;
/* GridView measures the first View which is returned by getView(int, View, ViewGroup), but does not use that View.
On KitKat, it does this actually multiple times.
Therefore, we animate all these first Views, and reset the last animated position when we suspect GridView is measuring. */
mGridViewPossiblyMeasuring = mGridViewPossiblyMeasuring && (mGridViewMeasuringPosition == -1 || mGridViewMeasuringPosition == position);
if (mGridViewPossiblyMeasuring) {
mGridViewMeasuringPosition = position;
mViewAnimator.setLastAnimatedPosition(-1);
}
Animator[] childAnimators;
if (getDecoratedBaseAdapter() instanceof AnimationAdapter) {
childAnimators = ((AnimationAdapter) getDecoratedBaseAdapter()).getAnimators(parent, view);
} else {
childAnimators = new Animator[0];
}
Animator[] animators = getAnimators(parent, view);
Animator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
Animator[] concatAnimators = AnimatorUtil.concatAnimators(childAnimators, animators, alphaAnimator);
mViewAnimator.animateViewIfNecessary(position, view, concatAnimators);
}
use of com.nineoldandroids.animation.Animator in project ListViewAnimations by nhaarman.
the class AnimateAdditionAdapter method getView.
@Override
@NonNull
public View getView(final int position, @Nullable final View convertView, @NonNull final ViewGroup parent) {
final View view = super.getView(position, convertView, parent);
if (mInsertQueue.getActiveIndexes().contains(position)) {
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.MATCH_PARENT, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED);
view.measure(widthMeasureSpec, heightMeasureSpec);
int originalHeight = view.getMeasuredHeight();
ValueAnimator heightAnimator = ValueAnimator.ofInt(1, originalHeight);
heightAnimator.addUpdateListener(new HeightUpdater(view));
Animator[] customAnimators = getAdditionalAnimators(view, parent);
Animator[] animators = new Animator[customAnimators.length + 1];
animators[0] = heightAnimator;
System.arraycopy(customAnimators, 0, animators, 1, customAnimators.length);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(animators);
ViewHelper.setAlpha(view, 0);
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
AnimatorSet allAnimatorsSet = new AnimatorSet();
allAnimatorsSet.playSequentially(animatorSet, alphaAnimator);
allAnimatorsSet.setDuration(mInsertionAnimationDurationMs);
allAnimatorsSet.addListener(new ExpandAnimationListener(position));
allAnimatorsSet.start();
}
return view;
}
use of com.nineoldandroids.animation.Animator in project ListViewAnimations by nhaarman.
the class StickyListHeadersAdapterDecorator method animateViewIfNecessary.
/**
* Animates given View if necessary.
*
* @param position the position of the item the View represents.
* @param view the View that should be animated.
* @param parent the parent the View is hosted in.
*/
private void animateViewIfNecessary(final int position, @NonNull final View view, @NonNull final ViewGroup parent) {
Animator[] childAnimators;
if (getDecoratedBaseAdapter() instanceof AnimationAdapter) {
childAnimators = ((AnimationAdapter) getDecoratedBaseAdapter()).getAnimators(parent, view);
} else {
childAnimators = new Animator[0];
}
Animator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
assert mViewAnimator != null;
mViewAnimator.animateViewIfNecessary(position, view, AnimatorUtil.concatAnimators(childAnimators, new Animator[0], alphaAnimator));
}
Aggregations