use of android.view.animation.Interpolator in project android_frameworks_base by ResurrectionRemix.
the class TaskStackAnimationHelper method startNewStackScrollAnimation.
/**
* Starts the animation to go to the initial stack layout with a task focused. In addition, the
* previous task will be animated in after the scroll completes.
*/
public void startNewStackScrollAnimation(TaskStack newStack, ReferenceCountedTrigger animationTrigger) {
TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
TaskStackViewScroller stackScroller = mStackView.getScroller();
// Get the current set of task transforms
ArrayList<Task> stackTasks = newStack.getStackTasks();
mStackView.getCurrentTaskTransforms(stackTasks, mTmpCurrentTaskTransforms);
// Update the stack
mStackView.setTasks(newStack, false);
mStackView.updateLayoutAlgorithm(false);
// Pick up the newly visible views after the scroll
final float newScroll = stackLayout.mInitialScrollP;
mStackView.bindVisibleTaskViews(newScroll);
// Update the internal state
stackLayout.setFocusState(TaskStackLayoutAlgorithm.STATE_UNFOCUSED);
stackLayout.setTaskOverridesForInitialState(newStack, true);
stackScroller.setStackScroll(newScroll);
mStackView.cancelDeferredTaskViewLayoutAnimation();
// Get the final set of task transforms
mStackView.getLayoutTaskTransforms(newScroll, stackLayout.getFocusState(), stackTasks, false, /* ignoreTaskOverrides */
mTmpFinalTaskTransforms);
// Hide the front most task view until the scroll is complete
Task frontMostTask = newStack.getStackFrontMostTask(false);
final TaskView frontMostTaskView = mStackView.getChildViewForTask(frontMostTask);
final TaskViewTransform frontMostTransform = mTmpFinalTaskTransforms.get(stackTasks.indexOf(frontMostTask));
if (frontMostTaskView != null) {
mStackView.updateTaskViewToTransform(frontMostTaskView, stackLayout.getFrontOfStackTransform(), AnimationProps.IMMEDIATE);
}
// Setup the end listener to return all the hidden views to the view pool after the
// focus animation
animationTrigger.addLastDecrementRunnable(new Runnable() {
@Override
public void run() {
mStackView.bindVisibleTaskViews(newScroll);
// Now, animate in the front-most task
if (frontMostTaskView != null) {
mStackView.updateTaskViewToTransform(frontMostTaskView, frontMostTransform, new AnimationProps(75, 250, FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR));
}
}
});
List<TaskView> taskViews = mStackView.getTaskViews();
int taskViewCount = taskViews.size();
for (int i = 0; i < taskViewCount; i++) {
TaskView tv = taskViews.get(i);
Task task = tv.getTask();
if (mStackView.isIgnoredTask(task)) {
continue;
}
if (task == frontMostTask && frontMostTaskView != null) {
continue;
}
int taskIndex = stackTasks.indexOf(task);
TaskViewTransform fromTransform = mTmpCurrentTaskTransforms.get(taskIndex);
TaskViewTransform toTransform = mTmpFinalTaskTransforms.get(taskIndex);
// Update the task to the initial state (for the newly picked up tasks)
mStackView.updateTaskViewToTransform(tv, fromTransform, AnimationProps.IMMEDIATE);
int duration = calculateStaggeredAnimDuration(i);
Interpolator interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR;
AnimationProps anim = new AnimationProps().setDuration(AnimationProps.BOUNDS, duration).setInterpolator(AnimationProps.BOUNDS, interpolator).setListener(animationTrigger.decrementOnAnimationEnd());
animationTrigger.increment();
mStackView.updateTaskViewToTransform(tv, toTransform, anim);
}
}
use of android.view.animation.Interpolator in project android_frameworks_base by ResurrectionRemix.
the class GlobalScreenshot method createScreenshotDropOutAnimation.
private ValueAnimator createScreenshotDropOutAnimation(int w, int h, boolean statusBarVisible, boolean navBarVisible) {
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.setStartDelay(SCREENSHOT_DROP_OUT_DELAY);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mBackgroundView.setVisibility(View.GONE);
mScreenshotView.setVisibility(View.GONE);
mScreenshotView.setLayerType(View.LAYER_TYPE_NONE, null);
}
});
if (!statusBarVisible || !navBarVisible) {
// There is no status bar/nav bar, so just fade the screenshot away in place
anim.setDuration(SCREENSHOT_FAST_DROP_OUT_DURATION);
anim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float t = (Float) animation.getAnimatedValue();
float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale) - t * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_FAST_DROP_OUT_MIN_SCALE);
mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
mScreenshotView.setAlpha(1f - t);
mScreenshotView.setScaleX(scaleT);
mScreenshotView.setScaleY(scaleT);
}
});
} else {
// In the case where there is a status bar, animate to the origin of the bar (top-left)
final float scaleDurationPct = (float) SCREENSHOT_DROP_OUT_SCALE_DURATION / SCREENSHOT_DROP_OUT_DURATION;
final Interpolator scaleInterpolator = new Interpolator() {
@Override
public float getInterpolation(float x) {
if (x < scaleDurationPct) {
// Decelerate, and scale the input accordingly
return (float) (1f - Math.pow(1f - (x / scaleDurationPct), 2f));
}
return 1f;
}
};
// Determine the bounds of how to scale
float halfScreenWidth = (w - 2f * mBgPadding) / 2f;
float halfScreenHeight = (h - 2f * mBgPadding) / 2f;
final float offsetPct = SCREENSHOT_DROP_OUT_MIN_SCALE_OFFSET;
final PointF finalPos = new PointF(-halfScreenWidth + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenWidth, -halfScreenHeight + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenHeight);
// Animate the screenshot to the status bar
anim.setDuration(SCREENSHOT_DROP_OUT_DURATION);
anim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float t = (Float) animation.getAnimatedValue();
float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale) - scaleInterpolator.getInterpolation(t) * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_DROP_OUT_MIN_SCALE);
mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
mScreenshotView.setAlpha(1f - scaleInterpolator.getInterpolation(t));
mScreenshotView.setScaleX(scaleT);
mScreenshotView.setScaleY(scaleT);
mScreenshotView.setTranslationX(t * finalPos.x);
mScreenshotView.setTranslationY(t * finalPos.y);
}
});
}
return anim;
}
use of android.view.animation.Interpolator in project android_frameworks_base by ResurrectionRemix.
the class ActivatableNotificationView method startActivateAnimation.
private void startActivateAnimation(final boolean reverse) {
if (!isAttachedToWindow()) {
return;
}
int widthHalf = mBackgroundNormal.getWidth() / 2;
int heightHalf = mBackgroundNormal.getActualHeight() / 2;
float radius = (float) Math.sqrt(widthHalf * widthHalf + heightHalf * heightHalf);
Animator animator;
if (reverse) {
animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, radius, 0);
} else {
animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, 0, radius);
}
mBackgroundNormal.setVisibility(View.VISIBLE);
Interpolator interpolator;
Interpolator alphaInterpolator;
if (!reverse) {
interpolator = Interpolators.LINEAR_OUT_SLOW_IN;
alphaInterpolator = Interpolators.LINEAR_OUT_SLOW_IN;
} else {
interpolator = ACTIVATE_INVERSE_INTERPOLATOR;
alphaInterpolator = ACTIVATE_INVERSE_ALPHA_INTERPOLATOR;
}
animator.setInterpolator(interpolator);
animator.setDuration(ACTIVATE_ANIMATION_LENGTH);
if (reverse) {
mBackgroundNormal.setAlpha(1f);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
updateBackground();
}
});
animator.start();
} else {
mBackgroundNormal.setAlpha(0.4f);
animator.start();
}
mBackgroundNormal.animate().alpha(reverse ? 0f : 1f).setInterpolator(alphaInterpolator).setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float animatedFraction = animation.getAnimatedFraction();
if (reverse) {
animatedFraction = 1.0f - animatedFraction;
}
setNormalBackgroundVisibilityAmount(animatedFraction);
}
}).setDuration(ACTIVATE_ANIMATION_LENGTH);
}
use of android.view.animation.Interpolator in project android_frameworks_base by ResurrectionRemix.
the class AppTransition method createThumbnailAspectScaleAnimationLocked.
/**
* This animation runs for the thumbnail that gets cross faded with the enter/exit activity
* when a thumbnail is specified with the pending animation override.
*/
Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets, Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
Animation a;
final int thumbWidthI = thumbnailHeader.getWidth();
final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
final int thumbHeightI = thumbnailHeader.getHeight();
final int appWidth = appRect.width();
float scaleW = appWidth / thumbWidth;
getNextAppTransitionStartRect(taskId, mTmpRect);
final float fromX;
float fromY;
final float toX;
float toY;
final float pivotX;
final float pivotY;
if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
fromX = mTmpRect.left;
fromY = mTmpRect.top;
// For the curved translate animation to work, the pivot points needs to be at the
// same absolute position as the one from the real surface.
toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
pivotX = mTmpRect.width() / 2;
pivotY = appRect.height() / 2 / scaleW;
if (mGridLayoutRecentsEnabled) {
// In the grid layout, the header is displayed above the thumbnail instead of
// overlapping it.
fromY -= thumbHeightI;
toY -= thumbHeightI * scaleW;
}
} else {
pivotX = 0;
pivotY = 0;
fromX = mTmpRect.left;
fromY = mTmpRect.top;
toX = appRect.left;
toY = appRect.top;
}
final long duration = getAspectScaleDuration();
final Interpolator interpolator = getAspectScaleInterpolator();
if (mNextAppTransitionScaleUp) {
// Animation up from the thumbnail to the full screen
Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
scale.setInterpolator(interpolator);
scale.setDuration(duration);
Animation alpha = new AlphaAnimation(1f, 0f);
alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS ? duration / 2 : duration);
Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
translate.setInterpolator(interpolator);
translate.setDuration(duration);
mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
mTmpToClipRect.set(appRect);
// Containing frame is in screen space, but we need the clip rect in the
// app space.
mTmpToClipRect.offsetTo(0, 0);
mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
if (contentInsets != null) {
mTmpToClipRect.inset((int) (-contentInsets.left * scaleW), (int) (-contentInsets.top * scaleW), (int) (-contentInsets.right * scaleW), (int) (-contentInsets.bottom * scaleW));
}
Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
clipAnim.setInterpolator(interpolator);
clipAnim.setDuration(duration);
// This AnimationSet uses the Interpolators assigned above.
AnimationSet set = new AnimationSet(false);
set.addAnimation(scale);
if (!mGridLayoutRecentsEnabled) {
// In the grid layout, the header should be shown for the whole animation.
set.addAnimation(alpha);
}
set.addAnimation(translate);
set.addAnimation(clipAnim);
a = set;
} else {
// Animation down from the full screen to the thumbnail
Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
scale.setInterpolator(interpolator);
scale.setDuration(duration);
Animation alpha = new AlphaAnimation(0f, 1f);
alpha.setInterpolator(mThumbnailFadeInInterpolator);
alpha.setDuration(duration);
Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
translate.setInterpolator(interpolator);
translate.setDuration(duration);
// This AnimationSet uses the Interpolators assigned above.
AnimationSet set = new AnimationSet(false);
set.addAnimation(scale);
if (!mGridLayoutRecentsEnabled) {
// In the grid layout, the header should be shown for the whole animation.
set.addAnimation(alpha);
}
set.addAnimation(translate);
a = set;
}
return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0, null);
}
use of android.view.animation.Interpolator in project android_frameworks_base by ResurrectionRemix.
the class StackStateAnimator method startYTranslationAnimation.
private void startYTranslationAnimation(final View child, ViewState viewState, long duration, long delay) {
Float previousStartValue = getChildTag(child, TAG_START_TRANSLATION_Y);
Float previousEndValue = getChildTag(child, TAG_END_TRANSLATION_Y);
float newEndValue = viewState.yTranslation;
if (previousEndValue != null && previousEndValue == newEndValue) {
return;
}
ObjectAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_TRANSLATION_Y);
if (!mAnimationFilter.animateY) {
// just a local update was performed
if (previousAnimator != null) {
// we need to increase all animation keyframes of the previous animator by the
// relative change to the end value
PropertyValuesHolder[] values = previousAnimator.getValues();
float relativeDiff = newEndValue - previousEndValue;
float newStartValue = previousStartValue + relativeDiff;
values[0].setFloatValues(newStartValue, newEndValue);
child.setTag(TAG_START_TRANSLATION_Y, newStartValue);
child.setTag(TAG_END_TRANSLATION_Y, newEndValue);
previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
return;
} else {
// no new animation needed, let's just apply the value
child.setTranslationY(newEndValue);
return;
}
}
ObjectAnimator animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Y, child.getTranslationY(), newEndValue);
Interpolator interpolator = mHeadsUpAppearChildren.contains(child) ? mHeadsUpAppearInterpolator : Interpolators.FAST_OUT_SLOW_IN;
animator.setInterpolator(interpolator);
long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator);
animator.setDuration(newDuration);
if (delay > 0 && (previousAnimator == null || previousAnimator.getAnimatedFraction() == 0)) {
animator.setStartDelay(delay);
}
animator.addListener(getGlobalAnimationFinishedListener());
final boolean isHeadsUpDisappear = mHeadsUpDisappearChildren.contains(child);
// remove the tag when the animation is finished
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
HeadsUpManager.setIsClickedNotification(child, false);
child.setTag(TAG_ANIMATOR_TRANSLATION_Y, null);
child.setTag(TAG_START_TRANSLATION_Y, null);
child.setTag(TAG_END_TRANSLATION_Y, null);
if (isHeadsUpDisappear) {
((ExpandableNotificationRow) child).setHeadsupDisappearRunning(false);
}
}
});
startAnimator(animator);
child.setTag(TAG_ANIMATOR_TRANSLATION_Y, animator);
child.setTag(TAG_START_TRANSLATION_Y, child.getTranslationY());
child.setTag(TAG_END_TRANSLATION_Y, newEndValue);
}
Aggregations