Merge "Change interpolation logic to all apps transitioning on fling b/30486958" into ub-launcher3-calgary

This commit is contained in:
Hyunyoung Song
2016-08-03 22:28:30 +00:00
committed by Android (Google) Code Review
2 changed files with 85 additions and 47 deletions

View File

@@ -17,7 +17,6 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Hotseat;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.PagedView;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
@@ -42,11 +41,12 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
private final Interpolator mAccelInterpolator = new AccelerateInterpolator(2f);
private final Interpolator mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
private final Interpolator mScrollInterpolator = new PagedView.ScrollInterpolator();
private final ScrollInterpolator mScrollInterpolator = new ScrollInterpolator();
private static final float ANIMATION_DURATION = 1200;
private static final float PARALLAX_COEFFICIENT = .125f;
private static final float FAST_FLING_PX_MS = 10;
private static final int SINGLE_FRAME_MS = 16;
private AllAppsContainerView mAppsView;
private int mAllAppsBackgroundColor;
@@ -72,6 +72,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
private float mShiftRange; // changes depending on the orientation
private float mProgress; // [0, 1], mShiftRange * mProgress = shiftCurrent
// Velocity of the container. Unit is in px/ms.
private float mContainerVelocity;
private static final float DEFAULT_SHIFT_RANGE = 10;
@@ -343,7 +344,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
private void calculateDuration(float velocity, float disp) {
// TODO: make these values constants after tuning.
float velocityDivisor = Math.max(1.5f, Math.abs(0.5f * velocity));
float velocityDivisor = Math.max(2f, Math.abs(0.5f * velocity));
float travelDistance = Math.max(0.2f, disp / mShiftRange);
mAnimationDuration = (long) Math.max(100, ANIMATION_DURATION / velocityDivisor * travelDistance);
if (DBG) {
@@ -351,22 +352,29 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
}
}
public void animateToAllApps(AnimatorSet animationOut, long duration) {
Interpolator interpolator;
public boolean animateToAllApps(AnimatorSet animationOut, long duration) {
boolean shouldPost = true;
if (animationOut == null) {
return;
return shouldPost;
}
Interpolator interpolator;
if (mDetector.isIdleState()) {
preparePull(true);
mAnimationDuration = duration;
mShiftStart = mAppsView.getTranslationY();
interpolator = mFastOutSlowInInterpolator;
} else {
mScrollInterpolator.setVelocityAtZero(Math.abs(mContainerVelocity));
interpolator = mScrollInterpolator;
float nextFrameProgress = mProgress + mContainerVelocity * SINGLE_FRAME_MS / mShiftRange;
if (nextFrameProgress >= 0f) {
mProgress = nextFrameProgress;
}
shouldPost = false;
}
final float fromAllAppsTop = mAppsView.getTranslationY();
ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
fromAllAppsTop / mShiftRange, 0f);
mProgress, 0f);
driftAndAlpha.setDuration(mAnimationDuration);
driftAndAlpha.setInterpolator(interpolator);
animationOut.play(driftAndAlpha);
@@ -391,6 +399,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
}
});
mCurrentAnimation = animationOut;
return shouldPost;
}
public void showDiscoveryBounce() {
@@ -426,9 +435,10 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
});
}
public void animateToWorkspace(AnimatorSet animationOut, long duration) {
public boolean animateToWorkspace(AnimatorSet animationOut, long duration) {
boolean shouldPost = true;
if (animationOut == null) {
return;
return shouldPost;
}
Interpolator interpolator;
if (mDetector.isIdleState()) {
@@ -437,12 +447,17 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
mShiftStart = mAppsView.getTranslationY();
interpolator = mFastOutSlowInInterpolator;
} else {
mScrollInterpolator.setVelocityAtZero(Math.abs(mContainerVelocity));
interpolator = mScrollInterpolator;
float nextFrameProgress = mProgress + mContainerVelocity * SINGLE_FRAME_MS / mShiftRange;
if (nextFrameProgress <= 1f) {
mProgress = nextFrameProgress;
}
shouldPost = false;
}
final float fromAllAppsTop = mAppsView.getTranslationY();
ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
fromAllAppsTop / mShiftRange, 1f);
mProgress, 1f);
driftAndAlpha.setDuration(mAnimationDuration);
driftAndAlpha.setInterpolator(interpolator);
animationOut.play(driftAndAlpha);
@@ -467,6 +482,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
}
});
mCurrentAnimation = animationOut;
return shouldPost;
}
public void finishPullUp() {
@@ -522,4 +538,22 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
}
setProgress(mProgress);
}
static class ScrollInterpolator implements Interpolator {
boolean mSteeper;
public void setVelocityAtZero(float velocity) {
mSteeper = velocity > FAST_FLING_PX_MS;
}
public float getInterpolation(float t) {
t -= 1.0f;
float output = t * t * t;
if (mSteeper) {
output *= t * t; // Make interpolation initial slope steeper
}
return output + 1;
}
}
}