use of android.view.animation.Interpolator in project platform_frameworks_base by android.
the class FlingAnimationUtils method getDismissingProperties.
private AnimatorProperties getDismissingProperties(float currValue, float endValue, float velocity, float maxDistance) {
float maxLengthSeconds = (float) (mMaxLengthSeconds * Math.pow(Math.abs(endValue - currValue) / maxDistance, 0.5f));
float diff = Math.abs(endValue - currValue);
float velAbs = Math.abs(velocity);
float y2 = calculateLinearOutFasterInY2(velAbs);
float startGradient = y2 / LINEAR_OUT_FASTER_IN_X2;
Interpolator mLinearOutFasterIn = new PathInterpolator(0, 0, LINEAR_OUT_FASTER_IN_X2, y2);
float durationSeconds = startGradient * diff / velAbs;
if (durationSeconds <= maxLengthSeconds) {
mAnimatorProperties.interpolator = mLinearOutFasterIn;
} else if (velAbs >= mMinVelocityPxPerSecond) {
// Cross fade between linear-out-faster-in and linear interpolator with current
// velocity.
durationSeconds = maxLengthSeconds;
VelocityInterpolator velocityInterpolator = new VelocityInterpolator(durationSeconds, velAbs, diff);
InterpolatorInterpolator superInterpolator = new InterpolatorInterpolator(velocityInterpolator, mLinearOutFasterIn, mLinearOutSlowIn);
mAnimatorProperties.interpolator = superInterpolator;
} else {
// Just use a normal interpolator which doesn't take the velocity into account.
durationSeconds = maxLengthSeconds;
mAnimatorProperties.interpolator = Interpolators.FAST_OUT_LINEAR_IN;
}
mAnimatorProperties.duration = (long) (durationSeconds * 1000);
return mAnimatorProperties;
}
use of android.view.animation.Interpolator in project platform_frameworks_base by android.
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;
final float fromY;
final float toX;
final float toY;
final float pivotX;
final float pivotY;
if (isTvUiMode(uiMode) || orientation == Configuration.ORIENTATION_PORTRAIT) {
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;
} 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);
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);
set.addAnimation(alpha);
set.addAnimation(translate);
a = set;
}
return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0, null);
}
use of android.view.animation.Interpolator in project platform_frameworks_base by android.
the class TaskStackAnimationHelper method startScrollToFocusedTaskAnimation.
/**
* Starts the animation to focus the next {@link TaskView} when paging through recents.
*
* @return whether or not this will trigger a scroll in the stack
*/
public boolean startScrollToFocusedTaskAnimation(Task newFocusedTask, boolean requestViewFocus) {
TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
TaskStackViewScroller stackScroller = mStackView.getScroller();
TaskStack stack = mStackView.getStack();
final float curScroll = stackScroller.getStackScroll();
final float newScroll = stackScroller.getBoundedStackScroll(stackLayout.getStackScrollForTask(newFocusedTask));
boolean willScrollToFront = newScroll > curScroll;
boolean willScroll = Float.compare(newScroll, curScroll) != 0;
// Get the current set of task transforms
int taskViewCount = mStackView.getTaskViews().size();
ArrayList<Task> stackTasks = stack.getStackTasks();
mStackView.getCurrentTaskTransforms(stackTasks, mTmpCurrentTaskTransforms);
// Pick up the newly visible views after the scroll
mStackView.bindVisibleTaskViews(newScroll);
// Update the internal state
stackLayout.setFocusState(TaskStackLayoutAlgorithm.STATE_FOCUSED);
stackScroller.setStackScroll(newScroll, null);
mStackView.cancelDeferredTaskViewLayoutAnimation();
// Get the final set of task transforms
mStackView.getLayoutTaskTransforms(newScroll, stackLayout.getFocusState(), stackTasks, true, /* ignoreTaskOverrides */
mTmpFinalTaskTransforms);
// Focus the task view
TaskView newFocusedTaskView = mStackView.getChildViewForTask(newFocusedTask);
if (newFocusedTaskView == null) {
// Log the error if we have no task view, and skip the animation
Log.e("TaskStackAnimationHelper", "b/27389156 null-task-view prebind:" + taskViewCount + " postbind:" + mStackView.getTaskViews().size() + " prescroll:" + curScroll + " postscroll: " + newScroll);
return false;
}
newFocusedTaskView.setFocusedState(true, requestViewFocus);
// Setup the end listener to return all the hidden views to the view pool after the
// focus animation
ReferenceCountedTrigger postAnimTrigger = new ReferenceCountedTrigger();
postAnimTrigger.addLastDecrementRunnable(new Runnable() {
@Override
public void run() {
mStackView.bindVisibleTaskViews(newScroll);
}
});
List<TaskView> taskViews = mStackView.getTaskViews();
taskViewCount = taskViews.size();
int newFocusTaskViewIndex = taskViews.indexOf(newFocusedTaskView);
for (int i = 0; i < taskViewCount; i++) {
TaskView tv = taskViews.get(i);
Task task = tv.getTask();
if (mStackView.isIgnoredTask(task)) {
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;
Interpolator interpolator;
if (willScrollToFront) {
duration = calculateStaggeredAnimDuration(i);
interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR;
} else {
if (i < newFocusTaskViewIndex) {
duration = 150 + ((newFocusTaskViewIndex - i - 1) * 50);
interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR;
} else if (i > newFocusTaskViewIndex) {
duration = Math.max(100, 150 - ((i - newFocusTaskViewIndex - 1) * 50));
interpolator = FOCUS_IN_FRONT_NEXT_TASK_INTERPOLATOR;
} else {
duration = 200;
interpolator = FOCUS_NEXT_TASK_INTERPOLATOR;
}
}
AnimationProps anim = new AnimationProps().setDuration(AnimationProps.BOUNDS, duration).setInterpolator(AnimationProps.BOUNDS, interpolator).setListener(postAnimTrigger.decrementOnAnimationEnd());
postAnimTrigger.increment();
mStackView.updateTaskViewToTransform(tv, toTransform, anim);
}
return willScroll;
}
use of android.view.animation.Interpolator in project platform_frameworks_base by android.
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 httpclient by pixmob.
the class FloatKeyframeSet method getFloatValue.
public float getFloatValue(float fraction) {
if (mNumKeyframes == 2) {
if (firstTime) {
firstTime = false;
firstValue = ((FloatKeyframe) mKeyframes.get(0)).getFloatValue();
lastValue = ((FloatKeyframe) mKeyframes.get(1)).getFloatValue();
deltaValue = lastValue - firstValue;
}
if (mInterpolator != null) {
fraction = mInterpolator.getInterpolation(fraction);
}
if (mEvaluator == null) {
return firstValue + fraction * deltaValue;
} else {
return ((Number) mEvaluator.evaluate(fraction, firstValue, lastValue)).floatValue();
}
}
if (fraction <= 0f) {
final FloatKeyframe prevKeyframe = (FloatKeyframe) mKeyframes.get(0);
final FloatKeyframe nextKeyframe = (FloatKeyframe) mKeyframes.get(1);
float prevValue = prevKeyframe.getFloatValue();
float nextValue = nextKeyframe.getFloatValue();
float prevFraction = prevKeyframe.getFraction();
float nextFraction = nextKeyframe.getFraction();
final Interpolator /*Time*/
interpolator = nextKeyframe.getInterpolator();
if (interpolator != null) {
fraction = interpolator.getInterpolation(fraction);
}
float intervalFraction = (fraction - prevFraction) / (nextFraction - prevFraction);
return mEvaluator == null ? prevValue + intervalFraction * (nextValue - prevValue) : ((Number) mEvaluator.evaluate(intervalFraction, prevValue, nextValue)).floatValue();
} else if (fraction >= 1f) {
final FloatKeyframe prevKeyframe = (FloatKeyframe) mKeyframes.get(mNumKeyframes - 2);
final FloatKeyframe nextKeyframe = (FloatKeyframe) mKeyframes.get(mNumKeyframes - 1);
float prevValue = prevKeyframe.getFloatValue();
float nextValue = nextKeyframe.getFloatValue();
float prevFraction = prevKeyframe.getFraction();
float nextFraction = nextKeyframe.getFraction();
final Interpolator /*Time*/
interpolator = nextKeyframe.getInterpolator();
if (interpolator != null) {
fraction = interpolator.getInterpolation(fraction);
}
float intervalFraction = (fraction - prevFraction) / (nextFraction - prevFraction);
return mEvaluator == null ? prevValue + intervalFraction * (nextValue - prevValue) : ((Number) mEvaluator.evaluate(intervalFraction, prevValue, nextValue)).floatValue();
}
FloatKeyframe prevKeyframe = (FloatKeyframe) mKeyframes.get(0);
for (int i = 1; i < mNumKeyframes; ++i) {
FloatKeyframe nextKeyframe = (FloatKeyframe) mKeyframes.get(i);
if (fraction < nextKeyframe.getFraction()) {
final Interpolator /*Time*/
interpolator = nextKeyframe.getInterpolator();
if (interpolator != null) {
fraction = interpolator.getInterpolation(fraction);
}
float intervalFraction = (fraction - prevKeyframe.getFraction()) / (nextKeyframe.getFraction() - prevKeyframe.getFraction());
float prevValue = prevKeyframe.getFloatValue();
float nextValue = nextKeyframe.getFloatValue();
return mEvaluator == null ? prevValue + intervalFraction * (nextValue - prevValue) : ((Number) mEvaluator.evaluate(intervalFraction, prevValue, nextValue)).floatValue();
}
prevKeyframe = nextKeyframe;
}
// shouldn't get here
return ((Number) mKeyframes.get(mNumKeyframes - 1).getValue()).floatValue();
}
Aggregations