summaryrefslogtreecommitdiffstats
path: root/quickstep
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2017-11-17 18:43:12 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-11-17 18:43:12 +0000
commit635329a5ab36163ec1e4c2c21cf78be2374aee7e (patch)
treeb02849f0ce168e32901698ddb93b04d8f9c5d806 /quickstep
parent86a8fde10b0b366f41daf647f3d433c08373db71 (diff)
parent1c9bf6a19c7f24d98ab8ea6d8385a974a057abb4 (diff)
downloadandroid_packages_apps_Trebuchet-635329a5ab36163ec1e4c2c21cf78be2374aee7e.tar.gz
android_packages_apps_Trebuchet-635329a5ab36163ec1e4c2c21cf78be2374aee7e.tar.bz2
android_packages_apps_Trebuchet-635329a5ab36163ec1e4c2c21cf78be2374aee7e.zip
Merge "Add carousel curve effect to RecentsView." into ub-launcher3-master
Diffstat (limited to 'quickstep')
-rw-r--r--quickstep/src/com/android/quickstep/RecentsView.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/quickstep/src/com/android/quickstep/RecentsView.java b/quickstep/src/com/android/quickstep/RecentsView.java
index 675f45645..ba88f99fe 100644
--- a/quickstep/src/com/android/quickstep/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/RecentsView.java
@@ -16,10 +16,12 @@
package com.android.quickstep;
+import android.animation.TimeInterpolator;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.LayoutInflater;
+import android.view.View;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
@@ -41,6 +43,12 @@ import java.util.ArrayList;
*/
public class RecentsView extends PagedView {
+ /** Designates how "curvy" the carousel is from 0 to 1, where 0 is a straight line. */
+ private static final float CURVE_FACTOR = 0.25f;
+ /** A circular curve of x from 0 to 1, where 0 is the center of the screen and 1 is the edge. */
+ private static final TimeInterpolator CURVE_INTERPOLATOR
+ = x -> (float) (1 - Math.sqrt(1 - Math.pow(x, 2)));
+
private boolean mOverviewStateEnabled;
private boolean mTaskStackListenerRegistered;
@@ -69,6 +77,7 @@ public class RecentsView extends PagedView {
super(context, attrs, defStyleAttr);
setWillNotDraw(false);
setPageSpacing((int) getResources().getDimension(R.dimen.recents_page_spacing));
+ enableFreeScroll(true);
}
@Override
@@ -170,4 +179,39 @@ public class RecentsView extends PagedView {
padding.left = padding.right = (int) ((profile.availableWidthPx - overviewWidth) / 2);
return padding;
}
+
+ @Override
+ public void scrollTo(int x, int y) {
+ super.scrollTo(x, y);
+ updateCurveProperties();
+ }
+
+ /**
+ * Scales and adjusts translation of adjacent pages as if on a curved carousel.
+ */
+ private void updateCurveProperties() {
+ if (getPageCount() == 0 || getPageAt(0).getMeasuredWidth() == 0) {
+ return;
+ }
+ final int halfScreenWidth = getMeasuredWidth() / 2;
+ final int screenCenter = halfScreenWidth + getScrollX();
+ final int pageSpacing = getResources().getDimensionPixelSize(R.dimen.recents_page_spacing);
+ final int pageCount = getPageCount();
+ for (int i = 0; i < pageCount; i++) {
+ View page = getPageAt(i);
+ int pageWidth = page.getMeasuredWidth();
+ int halfPageWidth = pageWidth / 2;
+ int pageCenter = page.getLeft() + halfPageWidth;
+ float distanceFromScreenCenter = Math.abs(pageCenter - screenCenter);
+ float distanceToReachEdge = halfScreenWidth + halfPageWidth + pageSpacing;
+ float linearInterpolation = Math.min(1, distanceFromScreenCenter / distanceToReachEdge);
+ float curveInterpolation = CURVE_INTERPOLATOR.getInterpolation(linearInterpolation);
+ float scale = 1 - curveInterpolation * CURVE_FACTOR;
+ page.setScaleX(scale);
+ page.setScaleY(scale);
+ // Make sure the biggest card (i.e. the one in front) shows on top of the adjacent ones.
+ page.setTranslationZ(scale);
+ page.setTranslationX((screenCenter - pageCenter) * curveInterpolation * CURVE_FACTOR);
+ }
+ }
}