Removing some new object creation during touch handling
> Motion various transformation methods to Orientation Handler
> Moving orientation handler to quickstep package
Bug: 150300347
Bug: 151269990
Bug: 149610456
Change-Id: I28434c1d1f62a3b85f3583740f0a8f827513fab3
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 5abeae4..85741ed 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java
@@ -46,11 +46,8 @@
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
-import com.android.launcher3.model.PagedViewOrientedState;
-import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.touch.PagedOrientationHandler;
-import com.android.launcher3.touch.PortraitPagedViewHandler;
import com.android.launcher3.util.VibratorWrapper;
import com.android.launcher3.views.FloatingIconView;
import com.android.quickstep.BaseActivityInterface.HomeAnimationFactory;
@@ -59,6 +56,7 @@
import com.android.quickstep.util.ActivityInitListener;
import com.android.quickstep.util.AppWindowAnimationHelper;
import com.android.quickstep.util.AppWindowAnimationHelper.TransformParams;
+import com.android.quickstep.util.RecentsOrientedState;
import com.android.quickstep.util.RectFSpringAnim;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;
@@ -127,7 +125,7 @@
protected boolean mCanceled;
protected int mFinishingRecentsAnimationForNewTaskId = -1;
- private PagedViewOrientedState mOrientedState;
+ private RecentsOrientedState mOrientedState;
protected BaseSwipeUpHandler(Context context, RecentsAnimationDeviceState deviceState,
GestureState gestureState, InputConsumerController inputConsumer) {
@@ -350,9 +348,11 @@
// TODO(b/150300347): The first recents animation after launcher is started with the
// foreground app not in landscape will look funky until that bug is fixed
displayRotation = mOrientedState.getDisplayRotation();
+
+ RectF tempRectF = new RectF(TEMP_RECT);
+ mOrientedState.mapRectFromNormalOrientation(tempRectF, dp.widthPx, dp.heightPx);
+ tempRectF.roundOut(TEMP_RECT);
}
- RotationHelper.getTargetRectForRotation(TEMP_RECT, dp.widthPx, dp.heightPx,
- displayRotation);
mAppWindowAnimationHelper.updateTargetRect(TEMP_RECT);
if (mDeviceState.isFullyGesturalNavMode()) {
// We can drag all the way to the top of the screen.
@@ -447,7 +447,7 @@
protected PagedOrientationHandler getOrientationHandler() {
if (mOrientedState == null) {
- return new PortraitPagedViewHandler();
+ return PagedOrientationHandler.PORTRAIT;
}
return mOrientedState.getOrientationHandler();
}
@@ -468,8 +468,8 @@
.setTargetSet(mRecentsAnimationTargets)
.setLauncherOnTop(false)));
if (isFloatingIconView) {
- RotationHelper.mapInverseRectFromNormalOrientation(startRect,
- mDp.widthPx, mDp.heightPx, mOrientedState.getDisplayRotation());
+ mOrientedState.mapInverseRectFromNormalOrientation(
+ startRect, mDp.widthPx, mDp.heightPx);
}
RectFSpringAnim anim = new RectFSpringAnim(startRect, targetRect, mContext);
if (isFloatingIconView) {
@@ -500,8 +500,8 @@
rotatedRect.set(currentRect);
if (isFloatingIconView) {
- RotationHelper.mapRectFromNormalOrientation(rotatedRect,
- mDp.widthPx, mDp.heightPx, mOrientedState.getDisplayRotation());
+ mOrientedState.mapRectFromNormalOrientation(
+ rotatedRect, mDp.widthPx, mDp.heightPx);
mTransformParams.setCornerRadius(endRadius * progress + startRadius
* (1f - progress));
}
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityInterface.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityInterface.java
index 4abb86a..2214dd0 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityInterface.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityInterface.java
@@ -33,8 +33,6 @@
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
-import com.android.launcher3.touch.PortraitPagedViewHandler;
-import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.quickstep.fallback.FallbackRecentsView;
import com.android.quickstep.util.ActivityInitListener;
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 da73bc0..46b026e 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackSwipeHandler.java
@@ -40,9 +40,7 @@
import com.android.launcher3.R;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
-import com.android.launcher3.touch.LandscapePagedViewHandler;
import com.android.launcher3.touch.PagedOrientationHandler;
-import com.android.launcher3.touch.PortraitPagedViewHandler;
import com.android.launcher3.util.ObjectWrapper;
import com.android.quickstep.BaseActivityInterface.HomeAnimationFactory;
import com.android.quickstep.GestureState.GestureEndTarget;
@@ -503,8 +501,8 @@
PagedOrientationHandler orientationHandler = mRecentsView != null
? mRecentsView.getPagedOrientationHandler()
: (mDp.isLandscape
- ? new LandscapePagedViewHandler()
- : new PortraitPagedViewHandler());
+ ? PagedOrientationHandler.LANDSCAPE
+ : PagedOrientationHandler.PORTRAIT);
return HomeAnimationFactory
.getDefaultWindowTargetRect(orientationHandler, mDp);
}
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 d9e9cc7..75a5976 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
@@ -15,6 +15,13 @@
*/
package com.android.quickstep.util;
+import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
+import static com.android.systemui.shared.system.QuickStepContract.getWindowCornerRadius;
+import static com.android.systemui.shared.system.QuickStepContract.supportsRoundedCornersOnWindows;
+import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.ACTIVITY_TYPE_HOME;
+import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING;
+import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_OPENING;
+
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
@@ -33,7 +40,6 @@
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.Interpolators;
-import com.android.launcher3.model.PagedViewOrientedState;
import com.android.launcher3.views.BaseDragLayer;
import com.android.quickstep.RemoteAnimationTargets;
import com.android.quickstep.SystemUiProxy;
@@ -47,13 +53,6 @@
import com.android.systemui.shared.system.TransactionCompat;
import com.android.systemui.shared.system.WindowManagerWrapper;
-import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
-import static com.android.systemui.shared.system.QuickStepContract.getWindowCornerRadius;
-import static com.android.systemui.shared.system.QuickStepContract.supportsRoundedCornersOnWindows;
-import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.ACTIVITY_TYPE_HOME;
-import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING;
-import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_OPENING;
-
/**
* Utility class to handle window clip animation
*/
@@ -86,7 +85,7 @@
private final Rect mTmpRect = new Rect();
private final RectF mTmpRectF = new RectF();
private final RectF mCurrentRectWithInsets = new RectF();
- private PagedViewOrientedState mOrientedState;
+ private RecentsOrientedState mOrientedState;
// Corner radius of windows, in pixels
private final float mWindowCornerRadius;
// Corner radius of windows when they're in overview mode.
@@ -105,7 +104,7 @@
private TargetAlphaProvider mTaskAlphaCallback = (t, a) -> a;
private TargetAlphaProvider mBaseAlphaCallback = (t, a) -> 1;
- public AppWindowAnimationHelper(PagedViewOrientedState orientedState, Context context) {
+ public AppWindowAnimationHelper(RecentsOrientedState orientedState, Context context) {
Resources res = context.getResources();
mOrientedState = orientedState;
mWindowCornerRadius = getWindowCornerRadius(res);
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/ClearAllButton.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/ClearAllButton.java
index 763f5be..e455939 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/ClearAllButton.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/ClearAllButton.java
@@ -78,21 +78,6 @@
}
}
- public void onLayoutChanged() {
- if (mParent == null) {
- return;
- }
- setRotation(mParent.getPagedOrientationHandler().getDegreesRotated());
- }
-
- public void setRtl(boolean rtl) {
- if (mIsRtl == rtl) {
- return;
- }
- mIsRtl = rtl;
- invalidate();
- }
-
public void setVisibilityAlpha(float alpha) {
if (mVisibilityAlpha != alpha) {
mVisibilityAlpha = alpha;
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 e3b3102..5e8c232 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
@@ -100,8 +100,8 @@
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.statehandlers.DepthController;
-import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.testing.TestProtocol;
+import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.launcher3.touch.PagedOrientationHandler.CurveProperties;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
@@ -122,6 +122,7 @@
import com.android.quickstep.ViewUtils;
import com.android.quickstep.util.AppWindowAnimationHelper;
import com.android.quickstep.util.LayoutUtils;
+import com.android.quickstep.util.RecentsOrientedState;
import com.android.systemui.plugins.ResourceProvider;
import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
import com.android.systemui.shared.recents.model.Task;
@@ -171,6 +172,8 @@
}
};
+ protected final RecentsOrientedState mOrientationState = new RecentsOrientedState();
+
private OrientationEventListener mOrientationListener;
private int mPreviousRotation;
protected RecentsAnimationController mRecentsAnimationController;
@@ -383,7 +386,7 @@
mOrientationListener = new OrientationEventListener(getContext()) {
@Override
public void onOrientationChanged(int i) {
- int rotation = RotationHelper.getRotationFromDegrees(i);
+ int rotation = RecentsOrientedState.getRotationForUserDegreesRotated(i);
if (mPreviousRotation != rotation) {
animateRecentsRotationInPlace(rotation);
if (rotation == 0) {
@@ -661,7 +664,7 @@
final int pageIndex = requiredTaskCount - i - 1 + mTaskViewStartIndex;
final Task task = tasks.get(i);
final TaskView taskView = (TaskView) getChildAt(pageIndex);
- taskView.bind(task, mLayoutRotation);
+ taskView.bind(task, mOrientationState);
}
if (mNextPage == INVALID_PAGE) {
@@ -973,7 +976,7 @@
AnimatorSet pa = setRecentsChangedOrientation(true);
pa.addListener(AnimationSuccessListener.forRunnable(() -> {
- updateLayoutRotation(newRotation);
+ setLayoutRotation(newRotation, mOrientationState.getDisplayRotation());
mActivity.getDragLayer().recreateControllers();
rotateAllChildTasks();
setRecentsChangedOrientation(false).start();
@@ -999,8 +1002,7 @@
private void rotateAllChildTasks() {
for (int i = 0; i < getTaskViewCount(); i++) {
- TaskView taskView = getTaskViewAt(i);
- taskView.setOverviewRotation(mLayoutRotation);
+ getTaskViewAt(i).setOrientationState(mOrientationState);
}
}
@@ -1041,7 +1043,7 @@
new ComponentName(getContext(), getClass()), 0, 0), null, null, "", "", 0, 0,
false, true, false, false, new ActivityManager.TaskDescription(), 0,
new ComponentName("", ""), false);
- taskView.bind(mTmpRunningTask, mLayoutRotation);
+ taskView.bind(mTmpRunningTask, mOrientationState);
}
boolean runningTaskTileHidden = mRunningTaskTileHidden;
@@ -1530,16 +1532,28 @@
}
}
- @Override
public void setLayoutRotation(int touchRotation, int displayRotation) {
- if (!FeatureFlags.ENABLE_FIXED_ROTATION_TRANSFORM.get()) {
- return;
+ if (mOrientationState.update(touchRotation, displayRotation)) {
+ mOrientationHandler = mOrientationState.getOrientationHandler();
+ mIsRtl = mOrientationHandler.getRecentsRtlSetting(getResources());
+ setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
+ mClearAllButton.setRotation(mOrientationHandler.getDegreesRotated());
+ requestLayout();
}
+ }
- super.setLayoutRotation(touchRotation, displayRotation);
- mClearAllButton.onLayoutChanged();
- mIsRtl = mOrientationHandler.getRecentsRtlSetting(getResources());
- setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
+ public void disableMultipleLayoutRotations(boolean disable) {
+ mOrientationState.disableMultipleOrientations(disable);
+ mOrientationHandler = mOrientationState.getOrientationHandler();
+ requestLayout();
+ }
+
+ public RecentsOrientedState getPagedViewOrientedState() {
+ return mOrientationState;
+ }
+
+ public PagedOrientationHandler getPagedOrientationHandler() {
+ return mOrientationHandler;
}
@Override
@@ -1986,8 +2000,7 @@
public Consumer<MotionEvent> getEventDispatcher(float navbarRotation) {
float degreesRotated;
if (navbarRotation == 0) {
- degreesRotated = mOrientationState.areMultipleLayoutOrientationsDisabled() ? 0 :
- RotationHelper.getDegreesFromRotation(mLayoutRotation);
+ degreesRotated = mOrientationState.getTouchRotationDegrees();
} else {
degreesRotated = -navbarRotation;
}
@@ -2001,14 +2014,14 @@
return e -> {
if (navbarRotation != 0
&& !mOrientationState.areMultipleLayoutOrientationsDisabled()) {
- RotationHelper.transformEventForNavBar(e, true);
+ mOrientationState.flipVertical(e);
super.onTouchEvent(e);
- RotationHelper.transformEventForNavBar(e, false);
+ mOrientationState.flipVertical(e);
return;
}
- RotationHelper.transformEvent(-degreesRotated, e, true);
+ mOrientationState.transformEvent(-degreesRotated, e, true);
super.onTouchEvent(e);
- RotationHelper.transformEvent(-degreesRotated, e, false);
+ mOrientationState.transformEvent(-degreesRotated, e, false);
};
}
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
index 7010f9a..ceb099f 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
@@ -64,7 +64,6 @@
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.popup.SystemShortcut;
-import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.touch.PagedOrientationHandler;
@@ -79,6 +78,7 @@
import com.android.quickstep.TaskThumbnailCache;
import com.android.quickstep.TaskUtils;
import com.android.quickstep.util.LayoutUtils;
+import com.android.quickstep.util.RecentsOrientedState;
import com.android.quickstep.util.TaskCornerRadius;
import com.android.quickstep.views.RecentsView.PageCallbacks;
import com.android.quickstep.views.RecentsView.ScrollState;
@@ -119,19 +119,6 @@
private static final List<Rect> SYSTEM_GESTURE_EXCLUSION_RECT =
Collections.singletonList(new Rect());
- public static final FloatProperty<TaskView> FULLSCREEN_PROGRESS =
- new FloatProperty<TaskView>("fullscreenProgress") {
- @Override
- public void setValue(TaskView taskView, float v) {
- taskView.setFullscreenProgress(v);
- }
-
- @Override
- public Float get(TaskView taskView) {
- return taskView.mFullscreenProgress;
- }
- };
-
private static final FloatProperty<TaskView> FOCUS_TRANSITION =
new FloatProperty<TaskView>("focusTransition") {
@Override
@@ -286,11 +273,11 @@
/**
* Updates this task view to the given {@param task}.
*/
- public void bind(Task task, int recentsRotation) {
+ public void bind(Task task, RecentsOrientedState orientedState) {
cancelPendingLoadTasks();
mTask = task;
mSnapshotView.bind(task);
- setOverviewRotation(recentsRotation);
+ setOrientationState(orientedState);
}
public Task getTask() {
@@ -459,14 +446,15 @@
}
}
- void setOverviewRotation(int iconRotation) {
- PagedOrientationHandler orientationHandler = getRecentsView().getPagedOrientationHandler();
+ public void setOrientationState(RecentsOrientedState orientationState) {
+ int iconRotation = orientationState.getTouchRotation();
+ PagedOrientationHandler orientationHandler = orientationState.getOrientationHandler();
boolean isRtl = orientationHandler.getRecentsRtlSetting(getResources());
LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams();
snapshotParams.bottomMargin = LayoutUtils.thumbnailBottomMargin(getContext());
int thumbnailPadding = (int) getResources().getDimension(R.dimen.task_thumbnail_top_margin);
LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams();
- int rotation = RotationHelper.getDegreesFromRotation(iconRotation);
+ int rotation = orientationState.getTouchRotationDegrees();
switch (iconRotation) {
case Surface.ROTATION_90:
iconParams.gravity = (isRtl ? END : START) | CENTER_VERTICAL;
diff --git a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
index 3e73f49..95cd4f2 100644
--- a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
+++ b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
@@ -22,6 +22,8 @@
import static android.view.MotionEvent.ACTION_POINTER_DOWN;
import static android.view.MotionEvent.ACTION_UP;
+import static com.android.quickstep.util.RecentsOrientedState.postDisplayRotation;
+
import android.content.res.Resources;
import android.graphics.Matrix;
import android.graphics.Point;
@@ -33,8 +35,8 @@
import com.android.launcher3.R;
import com.android.launcher3.ResourceUtils;
-import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.util.DefaultDisplay;
+import com.android.quickstep.util.RecentsOrientedState.SurfaceRotation;
import java.io.PrintWriter;
@@ -52,6 +54,9 @@
private static final boolean DEBUG = false;
private static final int MAX_ORIENTATIONS = 4;
+ private final Matrix mTmpMatrix = new Matrix();
+ private final float[] mTmpPoint = new float[2];
+
private SparseArray<OrientationRectF> mSwipeTouchRegions = new SparseArray<>(MAX_ORIENTATIONS);
private final RectF mAssistantLeftRegion = new RectF();
private final RectF mAssistantRightRegion = new RectF();
@@ -304,42 +309,46 @@
}
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);
- switch (delta) {
- case Surface.ROTATION_0:
- outMatrix.reset();
- break;
- case Surface.ROTATION_90:
- outMatrix.setRotate(270);
- outMatrix.postTranslate(0, mHeight);
- break;
- case Surface.ROTATION_180:
- outMatrix.setRotate(180);
- outMatrix.postTranslate(mHeight, mWidth);
- break;
- case Surface.ROTATION_270:
- outMatrix.setRotate(90);
- outMatrix.postTranslate(mWidth, 0);
- break;
+ mTmpMatrix.reset();
+ postDisplayRotation(deltaRotation(mCurrentRotation, mRotation),
+ mHeight, mWidth, mTmpMatrix);
+ if (forceTransform) {
+ if (DEBUG) {
+ Log.d(TAG, "Transforming rotation due to forceTransform, "
+ + "mCurrentRotation: " + mCurrentRotation
+ + "mRotation: " + mRotation);
+ }
+ event.transform(mTmpMatrix);
+ return true;
}
+ mTmpPoint[0] = event.getX();
+ mTmpPoint[1] = event.getY();
+ mTmpMatrix.mapPoints(mTmpPoint);
- tmp.transform(outMatrix);
if (DEBUG) {
Log.d(TAG, "original: " + event.getX() + ", " + event.getY()
- + " new: " + tmp.getX() + ", " + tmp.getY()
+ + " new: " + mTmpPoint[0] + ", " + mTmpPoint[1]
+ " rect: " + this + " forceTransform: " + forceTransform
- + " contains: " + contains(tmp.getX(), tmp.getY()));
+ + " contains: " + contains(mTmpPoint[0], mTmpPoint[1]));
}
- if (forceTransform || contains(tmp.getX(), tmp.getY())) {
- event.transform(outMatrix);
- tmp.recycle();
+ if (contains(mTmpPoint[0], mTmpPoint[1])) {
+ event.transform(mTmpMatrix);
return true;
}
return false;
}
}
+
+ /**
+ * @return how many factors {@param newRotation} is rotated 90 degrees clockwise.
+ * E.g. 1->Rotated by 90 degrees clockwise, 2->Rotated 180 clockwise...
+ * A value of 0 means no rotation has been applied
+ */
+ @SurfaceRotation
+ private static int deltaRotation(int oldRotation, int newRotation) {
+ int delta = newRotation - oldRotation;
+ if (delta < 0) delta += 4;
+ return delta;
+ }
}
diff --git a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java
new file mode 100644
index 0000000..f72e458
--- /dev/null
+++ b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.quickstep.util;
+
+import static android.hardware.camera2.params.OutputConfiguration.ROTATION_180;
+import static android.view.Surface.ROTATION_0;
+import static android.view.Surface.ROTATION_270;
+import static android.view.Surface.ROTATION_90;
+
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import android.graphics.Matrix;
+import android.graphics.RectF;
+import android.view.MotionEvent;
+import android.view.Surface;
+
+import androidx.annotation.IntDef;
+
+import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.touch.PagedOrientationHandler;
+import com.android.launcher3.touch.PortraitPagedViewHandler;
+
+import java.lang.annotation.Retention;
+
+/**
+ * Container to hold orientation/rotation related information for Launcher.
+ * This is not meant to be an abstraction layer for applying different functionality between
+ * the different orientation/rotations. For that see {@link PagedOrientationHandler}
+ *
+ * This class has initial default state assuming the device and foreground app have
+ * no ({@link Surface#ROTATION_0} rotation.
+ */
+public final class RecentsOrientedState {
+
+ @Retention(SOURCE)
+ @IntDef({ROTATION_0, ROTATION_90, ROTATION_180, ROTATION_270})
+ public @interface SurfaceRotation {}
+
+ private PagedOrientationHandler mOrientationHandler = PagedOrientationHandler.PORTRAIT;
+
+ private @SurfaceRotation int mTouchRotation = ROTATION_0;
+ private @SurfaceRotation int mDisplayRotation = ROTATION_0;
+ /**
+ * If {@code true} we default to {@link PortraitPagedViewHandler} and don't support any fake
+ * launcher orientations.
+ */
+ private boolean mDisableMultipleOrientations;
+
+ private final Matrix mTmpMatrix = new Matrix();
+ private final Matrix mTmpInverseMatrix = new Matrix();
+
+ /**
+ * Sets the appropriate {@link PagedOrientationHandler} for {@link #mOrientationHandler}
+ * @param touchRotation The rotation the nav bar region that is touched is in
+ * @param displayRotation Rotation of the display/device
+ *
+ * @return true if there was any change in the internal state as a result of this call,
+ * false otherwise
+ */
+ public boolean update(
+ @SurfaceRotation int touchRotation, @SurfaceRotation int displayRotation) {
+ if (!FeatureFlags.ENABLE_FIXED_ROTATION_TRANSFORM.get()) {
+ return false;
+ }
+ if (mDisableMultipleOrientations) {
+ return false;
+ }
+ if (mDisplayRotation == displayRotation && mTouchRotation == touchRotation) {
+ return false;
+ }
+
+ mDisplayRotation = displayRotation;
+ mTouchRotation = touchRotation;
+ if (mTouchRotation == ROTATION_90) {
+ mOrientationHandler = PagedOrientationHandler.LANDSCAPE;
+ } else if (mTouchRotation == ROTATION_270) {
+ mOrientationHandler = PagedOrientationHandler.SEASCAPE;
+ } else {
+ mOrientationHandler = PagedOrientationHandler.PORTRAIT;
+ }
+ return true;
+ }
+
+ public boolean areMultipleLayoutOrientationsDisabled() {
+ return mDisableMultipleOrientations;
+ }
+
+ /**
+ * Setting this preference will render future calls to {@link #update(int, int)} as a no-op.
+ */
+ public void disableMultipleOrientations(boolean disable) {
+ mDisableMultipleOrientations = disable;
+ if (disable) {
+ mDisplayRotation = mTouchRotation = ROTATION_0;
+ mOrientationHandler = PagedOrientationHandler.PORTRAIT;
+ }
+ }
+
+ @SurfaceRotation
+ public int getDisplayRotation() {
+ return mDisplayRotation;
+ }
+
+ @SurfaceRotation
+ public int getTouchRotation() {
+ return mTouchRotation;
+ }
+
+ public int getTouchRotationDegrees() {
+ switch (mTouchRotation) {
+ case ROTATION_90:
+ return 90;
+ case ROTATION_180:
+ return 180;
+ case ROTATION_270:
+ return 270;
+ case ROTATION_0:
+ default:
+ return 0;
+ }
+ }
+
+ public PagedOrientationHandler getOrientationHandler() {
+ return mOrientationHandler;
+ }
+
+ /**
+ * For landscape, since the navbar is already in a vertical position, we don't have to do any
+ * rotations as the change in Y coordinate is what is read. We only flip the sign of the
+ * y coordinate to make it match existing behavior of swipe to the top to go previous
+ */
+ public void flipVertical(MotionEvent ev) {
+ mTmpMatrix.setScale(1, -1);
+ ev.transform(mTmpMatrix);
+ }
+
+ /**
+ * Creates a matrix to transform the given motion event specified by degrees.
+ * If inverse is {@code true}, the inverse of that matrix will be applied
+ */
+ public void transformEvent(float degrees, MotionEvent ev, boolean inverse) {
+ mTmpMatrix.setRotate(inverse ? -degrees : degrees);
+ ev.transform(mTmpMatrix);
+
+ // TODO: Add scaling back in based on degrees
+ /*
+ if (getWidth() > 0 && getHeight() > 0) {
+ float scale = ((float) getWidth()) / getHeight();
+ transform.postScale(scale, 1 / scale);
+ }
+ */
+ }
+
+ public void mapRectFromNormalOrientation(RectF src, int screenWidth, int screenHeight) {
+ mTmpMatrix.reset();
+ postDisplayRotation(mDisplayRotation, screenWidth, screenHeight, mTmpMatrix);
+ mTmpMatrix.mapRect(src);
+ }
+
+ public void mapInverseRectFromNormalOrientation(RectF src, int screenWidth, int screenHeight) {
+ mTmpMatrix.reset();
+ postDisplayRotation(mDisplayRotation, screenWidth, screenHeight, mTmpMatrix);
+ mTmpMatrix.invert(mTmpInverseMatrix);
+ mTmpInverseMatrix.mapRect(src);
+ }
+
+ @SurfaceRotation
+ public static int getRotationForUserDegreesRotated(float degrees) {
+ int threshold = 70;
+ if (degrees >= (360 - threshold) || degrees < (threshold)) {
+ return ROTATION_0;
+ } else if (degrees < (90 + threshold)) {
+ return ROTATION_270;
+ } else if (degrees < 180 + threshold) {
+ return ROTATION_180;
+ } else {
+ return ROTATION_90;
+ }
+ }
+
+ /**
+ * Posts the transformation on the matrix representing the provided display rotation
+ */
+ public static void postDisplayRotation(@SurfaceRotation int displayRotation,
+ float screenWidth, float screenHeight, Matrix out) {
+ switch (displayRotation) {
+ case ROTATION_0:
+ return;
+ case ROTATION_90:
+ out.postRotate(270);
+ out.postTranslate(0, screenWidth);
+ break;
+ case ROTATION_180:
+ out.postRotate(180);
+ out.postTranslate(screenHeight, screenWidth);
+ break;
+ case ROTATION_270:
+ out.postRotate(90);
+ out.postTranslate(screenHeight, 0);
+ break;
+ }
+ }
+}
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 5e47e2f..e36ae94 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -38,7 +38,6 @@
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
-import android.view.Surface;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
@@ -55,12 +54,10 @@
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.config.FeatureFlags;
-import com.android.launcher3.model.PagedViewOrientedState;
import com.android.launcher3.pageindicators.PageIndicator;
import com.android.launcher3.touch.OverScroll;
import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.launcher3.touch.PagedOrientationHandler.ChildBounds;
-import com.android.launcher3.touch.PortraitPagedViewHandler;
import com.android.launcher3.util.OverScroller;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.views.ActivityContext;
@@ -121,8 +118,7 @@
private float mLastMotion;
private float mLastMotionRemainder;
private float mTotalMotion;
- protected PagedOrientationHandler mOrientationHandler = new PortraitPagedViewHandler();
- protected final PagedViewOrientedState mOrientationState = new PagedViewOrientedState();
+ protected PagedOrientationHandler mOrientationHandler = PagedOrientationHandler.PORTRAIT;
protected int[] mPageScrolls;
private boolean mIsBeingDragged;
@@ -144,9 +140,6 @@
protected int mUnboundedScroll;
- protected int mLayoutRotation = Surface.ROTATION_0;
- protected int mDisplayRotation = Surface.ROTATION_0;
-
// Page Indicator
@Thunk int mPageIndicatorViewId;
protected T mPageIndicator;
@@ -417,37 +410,6 @@
return mUnboundedScroll;
}
- protected void updateLayoutRotation(int touchRotation) {
- setLayoutRotation(touchRotation, mDisplayRotation);
- }
-
- /** @param touchRotation Must be one of {@link android.view.Surface.ROTATION_0/90/180/270} */
- public void setLayoutRotation(int touchRotation, int displayRotation) {
- if (mLayoutRotation == touchRotation && mDisplayRotation == displayRotation) {
- return;
- }
-
- mOrientationState.update(touchRotation, displayRotation);
- mOrientationHandler = mOrientationState.getOrientationHandler();
- mLayoutRotation = touchRotation;
- mDisplayRotation = displayRotation;
- requestLayout();
- }
-
- public PagedViewOrientedState getPagedViewOrientedState() {
- return mOrientationState;
- }
-
- public PagedOrientationHandler getPagedOrientationHandler() {
- return getPagedViewOrientedState().getOrientationHandler();
- }
-
- public void disableMultipleLayoutRotations(boolean disable) {
- mOrientationState.disableMultipleOrientations(disable);
- mOrientationHandler = mOrientationState.getOrientationHandler();
- requestLayout();
- }
-
@Override
public void scrollBy(int x, int y) {
mOrientationHandler.delegateScrollBy(this, getUnboundedScroll(), x, y);
diff --git a/src/com/android/launcher3/model/PagedViewOrientedState.java b/src/com/android/launcher3/model/PagedViewOrientedState.java
deleted file mode 100644
index e48b8c1..0000000
--- a/src/com/android/launcher3/model/PagedViewOrientedState.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- *
- * * Copyright (C) 2020 The Android Open Source Project
- * *
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- *
- */
-
-package com.android.launcher3.model;
-
-import android.view.Surface;
-
-import com.android.launcher3.states.RotationHelper;
-import com.android.launcher3.touch.PortraitPagedViewHandler;
-import com.android.launcher3.touch.LandscapePagedViewHandler;
-import com.android.launcher3.touch.PagedOrientationHandler;
-import com.android.launcher3.touch.SeascapePagedViewHandler;
-
-/**
- * Container to hold orientation/rotation related information for Launcher.
- * This is not meant to be an abstraction layer for applying different functionality between
- * the different orientation/rotations. For that see {@link PagedOrientationHandler}
- *
- * This class has initial default state assuming the device and foreground app have
- * no ({@link Surface.ROTATION_0} rotation.
- *
- * Currently this class resides in {@link com.android.launcher3.PagedView}, but there's a ticket
- * to disassociate it from Launcher since it's needed before Launcher is instantiated
- * See TODO(b/150300347)
- */
-public final class PagedViewOrientedState {
-
- private PagedOrientationHandler mOrientationHandler = new PortraitPagedViewHandler();
-
- private int mTouchRotation = Surface.ROTATION_0;
- private int mDisplayRotation = Surface.ROTATION_0;
- /**
- * If {@code true} we default to {@link PortraitPagedViewHandler} and don't support any fake
- * launcher orientations.
- */
- private boolean mDisableMultipleOrientations;
-
- /**
- * Sets the appropriate {@link PagedOrientationHandler} for {@link #mOrientationHandler}
- * @param touchRotation The rotation the nav bar region that is touched is in
- * @param displayRotation Rotation of the display/device
- */
- public void update(int touchRotation, int displayRotation) {
- if (mDisableMultipleOrientations) {
- return;
- }
-
- mDisplayRotation = displayRotation;
- mTouchRotation = touchRotation;
- if (mTouchRotation == Surface.ROTATION_90) {
- mOrientationHandler = new LandscapePagedViewHandler();
- } else if (mTouchRotation == Surface.ROTATION_270) {
- mOrientationHandler = new SeascapePagedViewHandler();
- } else {
- mOrientationHandler = new PortraitPagedViewHandler();
- }
- }
-
- public boolean areMultipleLayoutOrientationsDisabled() {
- return mDisableMultipleOrientations;
- }
-
- /**
- * Setting this preference will render future calls to {@link #update(int, int)} as a no-op.
- */
- public void disableMultipleOrientations(boolean disable) {
- mDisableMultipleOrientations = disable;
- if (disable) {
- mOrientationHandler = new PortraitPagedViewHandler();
- }
- }
-
- 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.
- * Ex. Display is in portrait -> 0, user touches landscape region -> 1, this
- * method would return 3 because it takes 3 clockwise 90 degree rotations from normal to
- * landscape (portrait -> seascape -> reverse portrait -> landscape)
- */
- public int getTouchDisplayDelta() {
- return RotationHelper.deltaRotation(mTouchRotation, mDisplayRotation);
- }
-
- public PagedOrientationHandler getOrientationHandler() {
- return mOrientationHandler;
- }
-}
diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java
index 8bb6a08..2e0521f 100644
--- a/src/com/android/launcher3/states/RotationHelper.java
+++ b/src/com/android/launcher3/states/RotationHelper.java
@@ -31,12 +31,7 @@
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Resources;
-import android.graphics.Matrix;
-import android.graphics.Rect;
-import android.graphics.RectF;
import android.provider.Settings;
-import android.view.MotionEvent;
-import android.view.Surface;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
@@ -258,138 +253,6 @@
}
}
- public static int getDegreesFromRotation(int rotation) {
- int degrees;
- switch (rotation) {
- case Surface.ROTATION_90:
- degrees = 90;
- break;
- case Surface.ROTATION_180:
- degrees = 180;
- break;
- case Surface.ROTATION_270:
- degrees = 270;
- break;
- case Surface.ROTATION_0:
- default:
- degrees = 0;
- break;
- }
- return degrees;
- }
-
- public static int getRotationFromDegrees(float degrees) {
- int threshold = 70;
- if (degrees >= (360 - threshold) || degrees < (threshold)) {
- return Surface.ROTATION_0;
- } else if (degrees < (90 + threshold)) {
- return Surface.ROTATION_270;
- } else if (degrees < 180 + threshold) {
- return Surface.ROTATION_180;
- } else {
- return Surface.ROTATION_90;
- }
- }
-
- /**
- * @return how many factors {@param newRotation} is rotated 90 degrees clockwise.
- * E.g. 1->Rotated by 90 degrees clockwise, 2->Rotated 180 clockwise...
- * A value of 0 means no rotation has been applied
- */
- public static int deltaRotation(int oldRotation, int newRotation) {
- int delta = newRotation - oldRotation;
- if (delta < 0) delta += 4;
- return delta;
- }
-
- /**
- * For landscape, since the navbar is already in a vertical position, we don't have to do any
- * rotations as the change in Y coordinate is what is read. We only flip the sign of the
- * y coordinate to make it match existing behavior of swipe to the top to go previous
- */
- public static void transformEventForNavBar(MotionEvent ev, boolean inverse) {
- // TODO(b/151269990): Use a temp matrix
- Matrix m = new Matrix();
- m.setScale(1, -1);
- if (inverse) {
- Matrix inv = new Matrix();
- m.invert(inv);
- ev.transform(inv);
- } else {
- ev.transform(m);
- }
- }
-
- /**
- * Creates a matrix to transform the given motion event specified by degrees.
- * If {@param inverse} is {@code true}, the inverse of that matrix will be applied
- */
- public static void transformEvent(float degrees, MotionEvent ev, boolean inverse) {
- Matrix transform = new Matrix();
- // TODO(b/151269990): Use a temp matrix
- transform.setRotate(degrees);
- if (inverse) {
- Matrix inv = new Matrix();
- transform.invert(inv);
- ev.transform(inv);
- } else {
- ev.transform(transform);
- }
- // TODO: Add scaling back in based on degrees
-// if (getWidth() > 0 && getHeight() > 0) {
-// float scale = ((float) getWidth()) / getHeight();
-// transform.postScale(scale, 1 / scale);
-// }
- }
-
- /**
- * TODO(b/149658423): Have {@link com.android.quickstep.OrientationTouchTransformer
- * also use this}
- */
- public static Matrix getRotationMatrix(int screenWidth, int screenHeight, int displayRotation) {
- Matrix m = new Matrix();
- // TODO(b/151269990): Use a temp matrix
- switch (displayRotation) {
- case Surface.ROTATION_0:
- return m;
- case Surface.ROTATION_90:
- m.setRotate(360 - RotationHelper.getDegreesFromRotation(displayRotation));
- m.postTranslate(0, screenWidth);
- break;
- case Surface.ROTATION_270:
- m.setRotate(360 - RotationHelper.getDegreesFromRotation(displayRotation));
- m.postTranslate(screenHeight, 0);
- break;
- }
- return m;
- }
-
- public static void mapRectFromNormalOrientation(RectF src, int screenWidth, int screenHeight,
- int displayRotation) {
- Matrix m = RotationHelper.getRotationMatrix(screenWidth, screenHeight, displayRotation);
- m.mapRect(src);
- }
-
- public static void mapInverseRectFromNormalOrientation(RectF src, int screenWidth,
- int screenHeight, int displayRotation) {
- Matrix m = RotationHelper.getRotationMatrix(screenWidth, screenHeight, displayRotation);
- Matrix inverse = new Matrix();
- m.invert(inverse);
- inverse.mapRect(src);
- }
-
- public static void getTargetRectForRotation(Rect srcOut, int screenWidth, int screenHeight,
- int displayRotation) {
- RectF wrapped = new RectF(srcOut);
- Matrix m = RotationHelper.getRotationMatrix(screenWidth, screenHeight, displayRotation);
- m.mapRect(wrapped);
- wrapped.round(srcOut);
- }
-
- public static boolean isRotationLandscape(int rotation) {
- return rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90;
- }
-
@Override
public String toString() {
return String.format("[mStateHandlerRequest=%d, mCurrentStateRequest=%d,"
diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java
index 24fa815..974e3f3 100644
--- a/src/com/android/launcher3/touch/PagedOrientationHandler.java
+++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java
@@ -39,6 +39,10 @@
*/
public interface PagedOrientationHandler {
+ PagedOrientationHandler PORTRAIT = new PortraitPagedViewHandler();
+ PagedOrientationHandler LANDSCAPE = new LandscapePagedViewHandler();
+ PagedOrientationHandler SEASCAPE = new SeascapePagedViewHandler();
+
interface Int2DAction<T> {
void call(T target, int x, int y);
}