use of com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y in project android_packages_apps_Launcher3 by ProtonAOSP.
the class DragLayer method animateView.
/**
* This method animates a view at the end of a drag and drop animation.
* @param view The view to be animated. This view is drawn directly into DragLayer, and so
* doesn't need to be a child of DragLayer.
* @param to The final location of the view. Only the left and top parameters are used. This
* location doesn't account for scaling, and so should be centered about the desired
* final location (including scaling).
* @param finalAlpha The final alpha of the view, in case we want it to fade as it animates.
* @param finalScaleX The final scale of the view. The view is scaled about its center.
* @param finalScaleY The final scale of the view. The view is scaled about its center.
* @param duration The duration of the animation.
* @param motionInterpolator The interpolator to use for the location of the view.
* @param onCompleteRunnable Optional runnable to run on animation completion.
* @param animationEndStyle Whether or not to fade out the view once the animation completes.
* {@link #ANIMATION_END_DISAPPEAR} or {@link #ANIMATION_END_REMAIN_VISIBLE}.
* @param anchorView If not null, this represents the view which the animated view stays
*/
public void animateView(final DragView view, final Rect to, final float finalAlpha, final float finalScaleX, final float finalScaleY, int duration, final Interpolator motionInterpolator, final Runnable onCompleteRunnable, final int animationEndStyle, View anchorView) {
view.cancelAnimation();
view.requestLayout();
final int[] from = getViewLocationRelativeToSelf(view);
// Calculate the duration of the animation based on the object's distance
final float dist = (float) Math.hypot(to.left - from[0], to.top - from[1]);
final Resources res = getResources();
final float maxDist = (float) res.getInteger(R.integer.config_dropAnimMaxDist);
// If duration < 0, this is a cue to compute the duration based on the distance
if (duration < 0) {
duration = res.getInteger(R.integer.config_dropAnimMaxDuration);
if (dist < maxDist) {
duration *= DEACCEL_1_5.getInterpolation(dist / maxDist);
}
duration = Math.max(duration, res.getInteger(R.integer.config_dropAnimMinDuration));
}
// Fall back to cubic ease out interpolator for the animation if none is specified
TimeInterpolator interpolator = motionInterpolator == null ? DEACCEL_1_5 : motionInterpolator;
// Animate the view
PendingAnimation anim = new PendingAnimation(duration);
anim.add(ofFloat(view, View.SCALE_X, finalScaleX), interpolator, SpringProperty.DEFAULT);
anim.add(ofFloat(view, View.SCALE_Y, finalScaleY), interpolator, SpringProperty.DEFAULT);
anim.setViewAlpha(view, finalAlpha, interpolator);
anim.setFloat(view, VIEW_TRANSLATE_Y, to.top, interpolator);
ObjectAnimator xMotion = ofFloat(view, VIEW_TRANSLATE_X, to.left);
if (anchorView != null) {
final int startScroll = anchorView.getScrollX();
TypeEvaluator<Float> evaluator = (f, s, e) -> mapRange(f, s, e) + (anchorView.getScaleX() * (startScroll - anchorView.getScrollX()));
xMotion.setEvaluator(evaluator);
}
anim.add(xMotion, interpolator, SpringProperty.DEFAULT);
if (onCompleteRunnable != null) {
anim.addListener(forEndCallback(onCompleteRunnable));
}
playDropAnimation(view, anim.buildAnim(), animationEndStyle);
}
use of com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y in project android_packages_apps_Launcher3 by ProtonAOSP.
the class StaggeredWorkspaceAnim method addStaggeredAnimationForView.
/**
* Adds an alpha/trans animator for {@param v}, with a start delay based on the view's row.
*
* @param v A view on the workspace.
* @param row The bottom-most row that contains the view.
* @param totalRows Total number of rows.
*/
private void addStaggeredAnimationForView(View v, int row, int totalRows) {
if (mIgnoredView != null && mIgnoredView == v)
return;
// Invert the rows, because we stagger starting from the bottom of the screen.
int invertedRow = totalRows - row;
// Add 1 to the inverted row so that the bottom most row has a start delay.
long startDelay = (long) ((invertedRow + 1) * APP_CLOSE_ROW_START_DELAY_MS);
v.setTranslationY(mSpringTransY);
ResourceProvider rp = DynamicResource.provider(v.getContext());
float stiffness = rp.getFloat(R.dimen.staggered_stiffness);
float damping = rp.getFloat(R.dimen.staggered_damping_ratio);
float endTransY = 0;
float springVelocity = Math.abs(mVelocity) * Math.signum(endTransY - mSpringTransY);
ValueAnimator springTransY = new SpringAnimationBuilder(v.getContext()).setStiffness(stiffness).setDampingRatio(damping).setMinimumVisibleChange(1f).setStartValue(mSpringTransY).setEndValue(endTransY).setStartVelocity(springVelocity).build(v, VIEW_TRANSLATE_Y);
springTransY.setStartDelay(startDelay);
springTransY.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
v.setTranslationY(0f);
}
});
mAnimators.play(springTransY);
v.setAlpha(0);
ObjectAnimator alpha = ObjectAnimator.ofFloat(v, View.ALPHA, 0f, 1f);
alpha.setInterpolator(LINEAR);
alpha.setDuration(ALPHA_DURATION_MS);
alpha.setStartDelay(startDelay);
alpha.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
v.setAlpha(1f);
}
});
mAnimators.play(alpha);
}
Aggregations