Adjust target and src rects for swipe to home animation
Floating icon animation runs entirely in portrait
since that's what orienation launcher starts in.
Current app window target rects are in landscape to
be able animate to Overview correctly (which is not
in portrait since the leash from WM is in the same
orientation as that of foreground app).
Invert that rect as the animation from app window
to floating icon progresses.
Fixes: 148528795
Change-Id: Ie1149a1a8904afc80bd1986f8d67b6f2d88c49f2
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java
index 8957b0d..f50bb3e 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java
@@ -125,7 +125,7 @@
protected boolean mCanceled;
protected int mFinishingRecentsAnimationForNewTaskId = -1;
- protected PagedViewOrientedState mOrientedState;
+ private PagedViewOrientedState mOrientedState;
protected BaseSwipeUpHandler(Context context, RecentsAnimationDeviceState deviceState,
GestureState gestureState, InputConsumerController inputConsumer) {
@@ -339,8 +339,10 @@
mAppWindowAnimationHelper.updateTargetRect(TEMP_RECT);
if (mDeviceState.isFullyGesturalNavMode()) {
// We can drag all the way to the top of the screen.
- mDragLengthFactor = orientationHandler
- .getDragLengthFactor(dp.heightPx, mTransitionDragLength);
+ // TODO(b/149609070): Landscape apps are currently limited in
+ // their ability to scale past the target rect.
+ float dragFactor = (float) dp.heightPx / mTransitionDragLength;
+ mDragLengthFactor = displayRotation == 0 ? dragFactor : Math.min(1.0f, dragFactor);
}
}
@@ -402,17 +404,16 @@
* Applies the transform on the recents animation without any additional null checks
*/
protected void applyTransformUnchecked() {
- PagedOrientationHandler handler = mOrientedState.getOrientationHandler();
float shift = mCurrentShift.value;
float offset = mRecentsView == null ? 0 : mRecentsView.getScrollOffset();
- float taskSize = handler.getPrimarySize(mAppWindowAnimationHelper.getTargetRect());
+ float taskSize = getOrientationHandler()
+ .getPrimarySize(mAppWindowAnimationHelper.getTargetRect());
float offsetScale = getTaskCurveScaleForOffset(offset, taskSize);
mTransformParams.setProgress(shift)
.setOffset(offset)
.setOffsetScale(offsetScale)
.setTargetSet(mRecentsAnimationTargets)
- .setLauncherOnTop(true)
- .setPagedOrientedState(mOrientedState);
+ .setLauncherOnTop(true);
mAppWindowAnimationHelper.applyTransform(mTransformParams);
}
@@ -423,6 +424,10 @@
return TaskView.getCurveScaleForInterpolation(interpolation);
}
+ protected PagedOrientationHandler getOrientationHandler() {
+ return mOrientedState.getOrientationHandler();
+ }
+
/**
* Creates an animation that transforms the current app window into the home app.
* @param startProgress The progress of {@link #mCurrentShift} to start the window from.
@@ -430,15 +435,18 @@
*/
protected RectFSpringAnim createWindowAnimationToHome(float startProgress,
HomeAnimationFactory homeAnimationFactory) {
- final RectF startRect = new RectF(
- mAppWindowAnimationHelper.applyTransform(
- mTransformParams.setProgress(startProgress)
- .setTargetSet(mRecentsAnimationTargets)
- .setPagedOrientedState(mOrientedState)
- .setLauncherOnTop(false)));
final RectF targetRect = homeAnimationFactory.getWindowTargetRect();
final View floatingView = homeAnimationFactory.getFloatingView();
final boolean isFloatingIconView = floatingView instanceof FloatingIconView;
+ final RectF startRect = new RectF(
+ mAppWindowAnimationHelper.applyTransform(
+ mTransformParams.setProgress(startProgress)
+ .setTargetSet(mRecentsAnimationTargets)
+ .setLauncherOnTop(false)));
+ if (isFloatingIconView) {
+ RotationHelper.mapInverseRectFromNormalOrientation(startRect,
+ mDp.widthPx, mDp.heightPx, mOrientedState.getDisplayRotation());
+ }
RectFSpringAnim anim = new RectFSpringAnim(startRect, targetRect, mContext.getResources());
if (isFloatingIconView) {
FloatingIconView fiv = (FloatingIconView) floatingView;
@@ -459,6 +467,7 @@
// We want the window alpha to be 0 once this threshold is met, so that the
// FolderIconView can be seen morphing into the icon shape.
final float windowAlphaThreshold = isFloatingIconView ? 1f - SHAPE_PROGRESS_DURATION : 1f;
+ final RectF rotatedRect = new RectF();
anim.addOnUpdateListener(new RectFSpringAnim.OnUpdateListener() {
@Override
@@ -469,9 +478,12 @@
Utilities.mapRange(progress, startTransformProgress, endTransformProgress))
.setCurrentRect(currentRect)
.setTargetAlpha(getWindowAlpha(progress));
+ rotatedRect.set(currentRect);
if (isFloatingIconView) {
+ RotationHelper.mapRectFromNormalOrientation(rotatedRect,
+ mDp.widthPx, mDp.heightPx, mOrientedState.getDisplayRotation());
mTransformParams.setCornerRadius(endRadius * progress + startRadius
- * (1f - progress));
+ * (1f - progress));
}
mAppWindowAnimationHelper.applyTransform(mTransformParams);
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java
index 0ae1a3a..4179080 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java
@@ -470,7 +470,8 @@
HomeAnimationFactory factory = new HomeAnimationFactory() {
@Override
public RectF getWindowTargetRect() {
- return HomeAnimationFactory.getDefaultWindowTargetRect(mDp);
+ return HomeAnimationFactory
+ .getDefaultWindowTargetRect(mRecentsView.getPagedOrientationHandler(), mDp);
}
@Override
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java
index 999f2d7..f19ec69 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java
@@ -178,7 +178,8 @@
if (canUseWorkspaceView) {
return iconLocation;
} else {
- return HomeAnimationFactory.getDefaultWindowTargetRect(dp);
+ return HomeAnimationFactory
+ .getDefaultWindowTargetRect(recentsView.getPagedOrientationHandler(), dp);
}
}
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherSwipeHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherSwipeHandler.java
index c4466e7..de90e0b 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherSwipeHandler.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherSwipeHandler.java
@@ -941,6 +941,7 @@
mGestureState.setState(STATE_END_TARGET_ANIMATION_FINISHED);
}
});
+ getOrientationHandler().adjustFloatingIconStartVelocity(velocityPxPerMs);
windowAnim.start(velocityPxPerMs);
homeAnimFactory.playAtomicAnimation(velocityPxPerMs.y);
mRunningWindowAnim = RunningWindowAnim.wrap(windowAnim);
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskViewUtils.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskViewUtils.java
index aedb756..8d73591 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskViewUtils.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskViewUtils.java
@@ -130,7 +130,6 @@
.setLauncherOnTop(true);
final RecentsView recentsView = v.getRecentsView();
- params.setPagedOrientedState(recentsView.getPagedViewOrientedState());
final ValueAnimator appAnimator = ValueAnimator.ofFloat(0, 1);
appAnimator.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
appAnimator.addUpdateListener(new MultiValueUpdateListener() {
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/AppWindowAnimationHelper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/util/AppWindowAnimationHelper.java
index 6923ca2..91af156 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/AppWindowAnimationHelper.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/util/AppWindowAnimationHelper.java
@@ -22,6 +22,7 @@
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
+import android.view.Surface;
import androidx.annotation.Nullable;
@@ -157,11 +158,12 @@
}
private float getSrcToTargetScale() {
- if (mOrientedState == null) {
+ if (mOrientedState == null ||
+ (mOrientedState.getDisplayRotation() == Surface.ROTATION_0
+ || mOrientedState.getDisplayRotation() == Surface.ROTATION_180)) {
return mSourceRect.width() / mTargetRect.width();
} else {
- return mOrientedState.getOrientationHandler()
- .getCurrentAppAnimationScale(mSourceRect, mTargetRect);
+ return mSourceRect.height() / mTargetRect.height();
}
}
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
index 50a6629..4bd1215 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
@@ -381,7 +381,7 @@
mOrientationListener = new OrientationEventListener(getContext()) {
@Override
public void onOrientationChanged(int i) {
- int rotation = RotationHelper.getRotationFromDegrees(i, mPreviousRotation);
+ int rotation = RotationHelper.getRotationFromDegrees(i);
if (mPreviousRotation != rotation) {
animateRecentsRotationInPlace(rotation);
mPreviousRotation = rotation;
diff --git a/quickstep/src/com/android/quickstep/BaseActivityInterface.java b/quickstep/src/com/android/quickstep/BaseActivityInterface.java
index 58d6ee7..64e053f 100644
--- a/quickstep/src/com/android/quickstep/BaseActivityInterface.java
+++ b/quickstep/src/com/android/quickstep/BaseActivityInterface.java
@@ -149,13 +149,18 @@
// No-op
}
- static RectF getDefaultWindowTargetRect(DeviceProfile dp) {
+ static RectF getDefaultWindowTargetRect(PagedOrientationHandler orientationHandler,
+ DeviceProfile dp) {
final int halfIconSize = dp.iconSizePx / 2;
- final float targetCenterX = dp.availableWidthPx / 2f;
- final float targetCenterY = dp.availableHeightPx - dp.hotseatBarSizePx;
+ float primaryDimension = orientationHandler
+ .getPrimaryValue(dp.availableWidthPx, dp.availableHeightPx);
+ float secondaryDimension = orientationHandler
+ .getSecondaryValue(dp.availableWidthPx, dp.availableHeightPx);
+ final float targetX = primaryDimension / 2f;
+ final float targetY = secondaryDimension - dp.hotseatBarSizePx;
// Fallback to animate to center of screen.
- return new RectF(targetCenterX - halfIconSize, targetCenterY - halfIconSize,
- targetCenterX + halfIconSize, targetCenterY + halfIconSize);
+ return new RectF(targetX - halfIconSize, targetY - halfIconSize,
+ targetX + halfIconSize, targetY + halfIconSize);
}
}
diff --git a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
index f78ac57..832baf5 100644
--- a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
+++ b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
@@ -300,6 +300,7 @@
}
boolean applyTransform(MotionEvent event, boolean forceTransform) {
+ // TODO(b/149658423): See if we can use RotationHelper.getRotationMatrix here
MotionEvent tmp = MotionEvent.obtain(event);
Matrix outMatrix = new Matrix();
int delta = RotationHelper.deltaRotation(mCurrentRotation, mRotation);
diff --git a/src/com/android/launcher3/model/PagedViewOrientedState.java b/src/com/android/launcher3/model/PagedViewOrientedState.java
index fd1154c..1349eff 100644
--- a/src/com/android/launcher3/model/PagedViewOrientedState.java
+++ b/src/com/android/launcher3/model/PagedViewOrientedState.java
@@ -83,6 +83,10 @@
}
}
+ public int getDisplayRotation() {
+ return mDisplayRotation;
+ }
+
/**
* Gets the difference between the rotation of the device/display and which region the
* user is currently interacting with in factors of 90 degree clockwise rotations.
diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java
index 95b13b4..3b134b0 100644
--- a/src/com/android/launcher3/states/RotationHelper.java
+++ b/src/com/android/launcher3/states/RotationHelper.java
@@ -249,7 +249,7 @@
return degrees;
}
- public static int getRotationFromDegrees(int degrees, int currentRotation) {
+ public static int getRotationFromDegrees(int degrees) {
int threshold = 70;
if (degrees >= (360 - threshold) || degrees < (threshold)) {
return Surface.ROTATION_0;
diff --git a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
index 3090d97..1db65b9 100644
--- a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
+++ b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
@@ -18,10 +18,12 @@
import android.content.res.Resources;
import android.graphics.Matrix;
+import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.FloatProperty;
import android.view.MotionEvent;
+import android.view.Surface;
import android.view.VelocityTracker;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
@@ -30,6 +32,7 @@
import com.android.launcher3.LauncherState.ScaleAndTranslation;
import com.android.launcher3.PagedView;
import com.android.launcher3.Utilities;
+import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.util.OverScroller;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
@@ -37,10 +40,6 @@
import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL;
public class LandscapePagedViewHandler implements PagedOrientationHandler {
- @Override
- public float getCurrentAppAnimationScale(RectF src, RectF target) {
- return src.height() / target.height();
- }
@Override
public int getPrimaryValue(int x, int y) {
@@ -77,13 +76,15 @@
}
@Override
- public float getDragLengthFactor(int dimension, int transitionDragLength) {
- return Math.min(1.0f, (float) dimension / transitionDragLength);
+ public boolean isGoingUp(float displacement) {
+ return displacement > 0;
}
@Override
- public boolean isGoingUp(float displacement) {
- return displacement > 0;
+ public void adjustFloatingIconStartVelocity(PointF velocity) {
+ float oldX = velocity.x;
+ float oldY = velocity.y;
+ velocity.set(-oldY, oldX);
}
@Override
@@ -189,30 +190,19 @@
}
@Override
- public void offsetTaskRect(RectF rect, float value, int delta) {
- if (delta == 0) {
- rect.offset(value, 0);
- } else if (delta == 1) {
- rect.offset(0, -value);
- } else if (delta == 2) {
- rect.offset(-value, 0);
- } else {
+ public void offsetTaskRect(RectF rect, float value, int displayRotation) {
+ if (displayRotation == Surface.ROTATION_0) {
rect.offset(0, value);
+ } else if (displayRotation == Surface.ROTATION_90) {
+ rect.offset(value, 0);
+ } else if (displayRotation == Surface.ROTATION_180) {
+ rect.offset(0, -value);
+ } else {
+ rect.offset(-value, 0);
}
}
@Override
- public void mapRectFromNormalOrientation(Rect src, int screenWidth, int screenHeight) {
- Matrix m = new Matrix();
- m.setRotate(270);
- m.postTranslate(0, screenWidth);
- RectF newTarget = new RectF();
- RectF oldTarget = new RectF(src);
- m.mapRect(newTarget, oldTarget);
- src.set((int)newTarget.left, (int)newTarget.top, (int)newTarget.right, (int)newTarget.bottom);
- }
-
- @Override
public int getChildStart(View view) {
return view.getTop();
}
diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java
index 2f02076..b4802cd 100644
--- a/src/com/android/launcher3/touch/PagedOrientationHandler.java
+++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java
@@ -18,6 +18,7 @@
import android.content.res.Resources;
import android.graphics.Canvas;
+import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.FloatProperty;
@@ -75,8 +76,6 @@
boolean getRecentsRtlSetting(Resources resources);
float getDegreesRotated();
void offsetTaskRect(RectF rect, float value, int delta);
- void mapRectFromNormalOrientation(Rect src, int screenWidth, int screenHeight);
- float getCurrentAppAnimationScale(RectF src, RectF target);
int getPrimaryValue(int x, int y);
int getSecondaryValue(int x, int y);
void delegateScrollTo(PagedView pagedView, int secondaryScroll, int primaryScroll);
@@ -85,9 +84,14 @@
void delegateScrollBy(PagedView pagedView, int unboundedScroll, int x, int y);
void scrollerStartScroll(OverScroller scroller, int newPosition);
CurveProperties getCurveProperties(PagedView pagedView, Rect insets);
- float getDragLengthFactor(int dimension, int transitionDragLength);
boolean isGoingUp(float displacement);
+ /**
+ * Maps the velocity from the coordinate plane of the foreground app to that
+ * of Launcher's (which now will always be portrait)
+ */
+ void adjustFloatingIconStartVelocity(PointF velocity);
+
class CurveProperties {
public final int scroll;
public final int halfPageSize;
diff --git a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
index fbd80bb..22eee49 100644
--- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
+++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
@@ -17,10 +17,13 @@
package com.android.launcher3.touch;
import android.content.res.Resources;
+import android.graphics.Matrix;
+import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.FloatProperty;
import android.view.MotionEvent;
+import android.view.Surface;
import android.view.VelocityTracker;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
@@ -29,6 +32,7 @@
import com.android.launcher3.LauncherState.ScaleAndTranslation;
import com.android.launcher3.PagedView;
import com.android.launcher3.Utilities;
+import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.util.OverScroller;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
@@ -38,11 +42,6 @@
public class PortraitPagedViewHandler implements PagedOrientationHandler {
@Override
- public float getCurrentAppAnimationScale(RectF src, RectF target) {
- return src.width() / target.width();
- }
-
- @Override
public int getPrimaryValue(int x, int y) {
return x;
}
@@ -77,13 +76,13 @@
}
@Override
- public float getDragLengthFactor(int dimension, int transitionDragLength) {
- return (float) dimension / transitionDragLength;
+ public boolean isGoingUp(float displacement) {
+ return displacement < 0;
}
@Override
- public boolean isGoingUp(float displacement) {
- return displacement < 0;
+ public void adjustFloatingIconStartVelocity(PointF velocity) {
+ //no-op
}
@Override
@@ -189,12 +188,12 @@
}
@Override
- public void offsetTaskRect(RectF rect, float value, int delta) {
- if (delta == 0) {
+ public void offsetTaskRect(RectF rect, float value, int displayRotation) {
+ if (displayRotation == Surface.ROTATION_0) {
rect.offset(value, 0);
- } else if (delta == 1) {
+ } else if (displayRotation == Surface.ROTATION_90) {
rect.offset(0, -value);
- } else if (delta == 2) {
+ } else if (displayRotation == Surface.ROTATION_180) {
rect.offset(-value, 0);
} else {
rect.offset(0, value);
@@ -202,11 +201,6 @@
}
@Override
- public void mapRectFromNormalOrientation(Rect src, int screenWidth, int screenHeight) {
- //no-op
- }
-
- @Override
public int getChildStart(View view) {
return view.getLeft();
}
diff --git a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java
index f1875cc..eebd87f 100644
--- a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java
+++ b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java
@@ -17,9 +17,9 @@
package com.android.launcher3.touch;
import android.content.res.Resources;
-import android.graphics.Matrix;
-import android.graphics.Rect;
+import android.graphics.PointF;
import android.graphics.RectF;
+import android.view.Surface;
import com.android.launcher3.Utilities;
@@ -36,30 +36,19 @@
}
@Override
- public void offsetTaskRect(RectF rect, float value, int delta) {
- if (delta == 0) {
- rect.offset(-value, 0);
- } else if (delta == 1) {
+ public void offsetTaskRect(RectF rect, float value, int displayRotation) {
+ if (displayRotation == Surface.ROTATION_0) {
rect.offset(0, value);
- } else if (delta == 2) {
- rect.offset(-value, 0);
- } else {
+ } else if (displayRotation == Surface.ROTATION_90) {
+ rect.offset(value, 0);
+ } else if (displayRotation == Surface.ROTATION_180) {
rect.offset(0, -value);
+ } else {
+ rect.offset(-value, 0);
}
}
@Override
- public void mapRectFromNormalOrientation(Rect src, int screenWidth, int screenHeight) {
- Matrix m = new Matrix();
- m.setRotate(90);
- m.postTranslate(screenHeight, 0);
- RectF newTarget = new RectF();
- RectF oldTarget = new RectF(src);
- m.mapRect(newTarget, oldTarget);
- src.set((int)newTarget.left, (int)newTarget.top, (int)newTarget.right, (int)newTarget.bottom);
- }
-
- @Override
public float getDegreesRotated() {
return 270;
}
@@ -68,4 +57,11 @@
public boolean isGoingUp(float displacement) {
return displacement < 0;
}
+
+ @Override
+ public void adjustFloatingIconStartVelocity(PointF velocity) {
+ float oldX = velocity.x;
+ float oldY = velocity.y;
+ velocity.set(oldY, -oldX);
+ }
}