use of android.animation.Animator in project weiciyuan by qii.
the class GalleryActivity method animateClose.
private void animateClose(PhotoView imageView) {
currentViewPositionLayout.setVisibility(View.INVISIBLE);
animationView.setImageDrawable(imageView.getDrawable());
pager.setVisibility(View.INVISIBLE);
final Rect startBounds = rect;
final Rect finalBounds = new Rect();
final Point globalOffset = new Point();
animationView.getGlobalVisibleRect(finalBounds, globalOffset);
startBounds.offset(-globalOffset.x, -globalOffset.y);
finalBounds.offset(-globalOffset.x, -globalOffset.y);
float startScale;
if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) {
// Extend start bounds horizontally
startScale = (float) startBounds.height() / finalBounds.height();
float startWidth = startScale * finalBounds.width();
float deltaWidth = (startWidth - startBounds.width()) / 2;
startBounds.left -= deltaWidth;
startBounds.right += deltaWidth;
} else {
// Extend start bounds vertically
startScale = (float) startBounds.width() / finalBounds.width();
float startHeight = startScale * finalBounds.height();
float deltaHeight = (startHeight - startBounds.height()) / 2;
startBounds.top -= deltaHeight;
startBounds.bottom += deltaHeight;
}
animationView.setPivotX(0f);
animationView.setPivotY(0f);
final float startScaleFinal = startScale;
animationView.animate().setInterpolator(new DecelerateInterpolator()).x(startBounds.left).y(startBounds.top).scaleY(startScaleFinal).scaleX(startScaleFinal).setDuration(300).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
GalleryActivity.this.finish();
overridePendingTransition(0, 0);
}
}).start();
}
use of android.animation.Animator in project weiciyuan by qii.
the class GalleryAnimationActivity method onBackPressed.
@Override
public void onBackPressed() {
ContainerFragment fragment = fragmentMap.get(pager.getCurrentItem());
if (fragment != null && fragment.canAnimateCloseActivity()) {
backgroundColor = new ColorDrawable(Color.BLACK);
ObjectAnimator bgAnim = ObjectAnimator.ofInt(backgroundColor, "alpha", 0);
bgAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
background.setBackground(backgroundColor);
}
});
bgAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
GalleryAnimationActivity.super.finish();
overridePendingTransition(-1, -1);
}
});
fragment.animationExit(bgAnim);
} else {
super.onBackPressed();
}
}
use of android.animation.Animator in project platform_frameworks_base by android.
the class LockPatternView method startLineEndAnimation.
private void startLineEndAnimation(final CellState state, final float startX, final float startY, final float targetX, final float targetY) {
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float t = (float) animation.getAnimatedValue();
state.lineEndX = (1 - t) * startX + t * targetX;
state.lineEndY = (1 - t) * startY + t * targetY;
invalidate();
}
});
valueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
state.lineAnimator = null;
}
});
valueAnimator.setInterpolator(mFastOutSlowInInterpolator);
valueAnimator.setDuration(100);
valueAnimator.start();
state.lineAnimator = valueAnimator;
}
use of android.animation.Animator in project platform_frameworks_base by android.
the class TaskStackAnimationHelper method startDeleteTaskAnimation.
/**
* Starts the delete animation for the specified {@link TaskView}.
*/
public void startDeleteTaskAnimation(final TaskView deleteTaskView, final ReferenceCountedTrigger postAnimationTrigger) {
TaskStackViewTouchHandler touchHandler = mStackView.getTouchHandler();
touchHandler.onBeginManualDrag(deleteTaskView);
postAnimationTrigger.increment();
postAnimationTrigger.addLastDecrementRunnable(() -> {
touchHandler.onChildDismissed(deleteTaskView);
});
final float dismissSize = touchHandler.getScaledDismissSize();
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.setDuration(400);
animator.addUpdateListener((animation) -> {
float progress = (Float) animation.getAnimatedValue();
deleteTaskView.setTranslationX(progress * dismissSize);
touchHandler.updateSwipeProgress(deleteTaskView, true, progress);
});
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
postAnimationTrigger.decrement();
}
});
animator.start();
}
use of android.animation.Animator in project platform_frameworks_base by android.
the class ScrimController method startScrimAnimation.
private void startScrimAnimation(final View scrim, float target) {
float current = getCurrentScrimAlpha(scrim);
ValueAnimator anim = ValueAnimator.ofFloat(current, target);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float alpha = (float) animation.getAnimatedValue();
setCurrentScrimAlpha(scrim, alpha);
updateScrimColor(scrim);
}
});
anim.setInterpolator(getInterpolator());
anim.setStartDelay(mAnimationDelay);
anim.setDuration(mDurationOverride != -1 ? mDurationOverride : ANIMATION_DURATION);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (mOnAnimationFinished != null) {
mOnAnimationFinished.run();
mOnAnimationFinished = null;
}
if (mKeyguardFadingOutInProgress) {
mKeyguardFadeoutAnimation = null;
mKeyguardFadingOutInProgress = false;
}
scrim.setTag(TAG_KEY_ANIM, null);
scrim.setTag(TAG_KEY_ANIM_TARGET, null);
}
});
anim.start();
if (mAnimateKeyguardFadingOut) {
mKeyguardFadingOutInProgress = true;
mKeyguardFadeoutAnimation = anim;
}
if (mSkipFirstFrame) {
anim.setCurrentPlayTime(16);
}
scrim.setTag(TAG_KEY_ANIM, anim);
scrim.setTag(TAG_KEY_ANIM_TARGET, target);
}
Aggregations