Rotate Overview Task Action Menu
Fixes: 153371258
Test: Tap on icon in portrait,
landscape and seascape. Open menu
then rotate phone.
Change-Id: I38b018371561b502fe211a3c2ddea4ff7fde4274
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskMenuView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskMenuView.java
index 80022b4..9b47520 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskMenuView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskMenuView.java
@@ -40,6 +40,7 @@
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.anim.RoundedRectRevealOutlineProvider;
import com.android.launcher3.popup.SystemShortcut;
+import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.BaseDragLayer;
import com.android.quickstep.TaskOverlayFactory;
@@ -150,9 +151,26 @@
return (type & TYPE_TASK_MENU) != 0;
}
- public void setPosition(float x, float y) {
- setX(x);
- setY(y + mThumbnailTopMargin);
+ public void setPosition(float x, float y, PagedOrientationHandler pagedOrientationHandler) {
+ float adjustedY = y + mThumbnailTopMargin;
+ // Changing pivot to make computations easier
+ // NOTE: Changing the pivots means the rotated view gets rotated about the new pivots set,
+ // which would render the X and Y position set here incorrect
+ setPivotX(0);
+ setPivotY(0);
+ setRotation(pagedOrientationHandler.getDegreesRotated());
+ setX(pagedOrientationHandler.getTaskMenuX(x, mTaskView.getThumbnail()));
+ setY(pagedOrientationHandler.getTaskMenuY(adjustedY, mTaskView.getThumbnail()));
+ }
+
+ public void onRotationChanged() {
+ if (mOpenCloseAnimator != null && mOpenCloseAnimator.isRunning()) {
+ mOpenCloseAnimator.end();
+ }
+ if (mIsOpen) {
+ mOptionLayout.removeAllViews();
+ populateAndLayoutMenu();
+ }
}
public static TaskMenuView showForTask(TaskView taskView) {
@@ -168,12 +186,16 @@
}
mActivity.getDragLayer().addView(this);
mTaskView = taskView;
- addMenuOptions(mTaskView);
- orientAroundTaskView(mTaskView);
+ populateAndLayoutMenu();
post(this::animateOpen);
return true;
}
+ private void populateAndLayoutMenu() {
+ addMenuOptions(mTaskView);
+ orientAroundTaskView(mTaskView);
+ }
+
private void addMenuOptions(TaskView taskView) {
Drawable icon = taskView.getTask().icon.getConstantState().newDrawable();
mTaskIcon.setDrawable(icon);
@@ -200,21 +222,26 @@
R.layout.task_view_menu_option, this, false);
menuOption.setIconAndLabelFor(
menuOptionView.findViewById(R.id.icon), menuOptionView.findViewById(R.id.text));
+ LayoutParams lp = (LayoutParams) menuOptionView.getLayoutParams();
+ mTaskView.getPagedOrientationHandler().setLayoutParamsForTaskMenuOptionItem(lp);
menuOptionView.setOnClickListener(menuOption);
mOptionLayout.addView(menuOptionView);
}
private void orientAroundTaskView(TaskView taskView) {
+ PagedOrientationHandler orientationHandler = taskView.getPagedOrientationHandler();
measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
mActivity.getDragLayer().getDescendantRectRelativeToSelf(taskView, sTempRect);
Rect insets = mActivity.getDragLayer().getInsets();
BaseDragLayer.LayoutParams params = (BaseDragLayer.LayoutParams) getLayoutParams();
- params.width = taskView.getMeasuredWidth();
+ params.width = orientationHandler.getTaskMenuWidth(taskView.getThumbnail());
params.gravity = Gravity.START;
setLayoutParams(params);
setScaleX(taskView.getScaleX());
setScaleY(taskView.getScaleY());
- setPosition(sTempRect.left - insets.left, sTempRect.top - insets.top);
+ mOptionLayout.setOrientation(orientationHandler.getTaskMenuLayoutOrientation());
+ setPosition(sTempRect.left - insets.left, sTempRect.top - insets.top,
+ taskView.getPagedOrientationHandler());
}
private void animateOpen() {
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 b0758c9..ce8a193 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
@@ -466,6 +466,7 @@
int iconRotation = orientationState.getTouchRotation();
PagedOrientationHandler orientationHandler = orientationState.getOrientationHandler();
boolean isRtl = orientationHandler.getRecentsRtlSetting(getResources());
+ LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams();
int thumbnailPadding = (int) getResources().getDimension(R.dimen.task_thumbnail_top_margin);
LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams();
int rotation = orientationState.getTouchRotationDegrees();
@@ -473,7 +474,8 @@
case Surface.ROTATION_90:
iconParams.gravity = (isRtl ? END : START) | CENTER_VERTICAL;
iconParams.rightMargin = -thumbnailPadding;
- iconParams.leftMargin = iconParams.topMargin = iconParams.bottomMargin = 0;
+ iconParams.leftMargin = 0;
+ iconParams.topMargin = snapshotParams.topMargin / 2;
break;
case Surface.ROTATION_180:
iconParams.gravity = BOTTOM | CENTER_HORIZONTAL;
@@ -483,17 +485,21 @@
case Surface.ROTATION_270:
iconParams.gravity = (isRtl ? END : START) | CENTER_VERTICAL;
iconParams.leftMargin = -thumbnailPadding;
- iconParams.rightMargin = iconParams.topMargin = iconParams.bottomMargin = 0;
+ iconParams.rightMargin = 0;
+ iconParams.topMargin = snapshotParams.topMargin / 2;
break;
case Surface.ROTATION_0:
default:
iconParams.gravity = TOP | CENTER_HORIZONTAL;
- iconParams.leftMargin = iconParams.topMargin = iconParams.rightMargin =
- iconParams.bottomMargin = 0;
+ iconParams.leftMargin = iconParams.topMargin = iconParams.rightMargin = 0;
break;
}
mIconView.setLayoutParams(iconParams);
mIconView.setRotation(rotation);
+
+ if (mMenuView != null) {
+ mMenuView.onRotationChanged();
+ }
}
private void setIconAndDimTransitionProgress(float progress, boolean invert) {
@@ -600,7 +606,10 @@
}
if (mMenuView != null) {
- mMenuView.setPosition(getX() - getRecentsView().getScrollX(), getY());
+ PagedOrientationHandler pagedOrientationHandler = getPagedOrientationHandler();
+ RecentsView recentsView = getRecentsView();
+ mMenuView.setPosition(getX() - recentsView.getScrollX(),
+ getY() - recentsView.getScrollY(), pagedOrientationHandler);
mMenuView.setScaleX(getScaleX());
mMenuView.setScaleY(getScaleY());
}
@@ -874,6 +883,10 @@
return (RecentsView) getParent();
}
+ PagedOrientationHandler getPagedOrientationHandler() {
+ return getRecentsView().mOrientationState.getOrientationHandler();
+ }
+
public void notifyTaskLaunchFailed(String tag) {
String msg = "Failed to launch task";
if (mTask != null) {
diff --git a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
index e290685..dc50053 100644
--- a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
+++ b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
@@ -16,6 +16,7 @@
package com.android.launcher3.touch;
+import static android.widget.ListPopupWindow.WRAP_CONTENT;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL;
@@ -30,6 +31,7 @@
import android.view.VelocityTracker;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
+import android.widget.LinearLayout;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.PagedView;
@@ -224,6 +226,33 @@
}
@Override
+ public float getTaskMenuX(float x, View thumbnailView) {
+ return thumbnailView.getMeasuredWidth() + x;
+ }
+
+ @Override
+ public float getTaskMenuY(float y, View thumbnailView) {
+ return y;
+ }
+
+ @Override
+ public int getTaskMenuWidth(View view) {
+ return view.getMeasuredHeight();
+ }
+
+ @Override
+ public int getTaskMenuLayoutOrientation() {
+ return LinearLayout.HORIZONTAL;
+ }
+
+ @Override
+ public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp) {
+ lp.width = 0;
+ lp.height = WRAP_CONTENT;
+ lp.weight = 1;
+ }
+
+ @Override
public ChildBounds getChildBounds(View child, int childStart, int pageCenter,
boolean layoutChild) {
final int childHeight = child.getMeasuredHeight();
diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java
index b8396e1..cc15f99 100644
--- a/src/com/android/launcher3/touch/PagedOrientationHandler.java
+++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java
@@ -27,6 +27,7 @@
import android.view.VelocityTracker;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
+import android.widget.LinearLayout;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.PagedView;
@@ -90,6 +91,11 @@
void getCurveProperties(PagedView view, Rect insets, CurveProperties out);
boolean isGoingUp(float displacement);
boolean isLayoutNaturalToLauncher();
+ float getTaskMenuX(float x, View thumbnailView);
+ float getTaskMenuY(float y, View thumbnailView);
+ int getTaskMenuWidth(View view);
+ int getTaskMenuLayoutOrientation();
+ void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp);
/**
* Maps the velocity from the coordinate plane of the foreground app to that
diff --git a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
index dad00a4..7c30e29 100644
--- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
+++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
@@ -30,6 +30,7 @@
import android.view.VelocityTracker;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
+import android.widget.LinearLayout;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.PagedView;
@@ -222,6 +223,31 @@
}
@Override
+ public float getTaskMenuX(float x, View thumbnailView) {
+ return x;
+ }
+
+ @Override
+ public float getTaskMenuY(float y, View thumbnailView) {
+ return y;
+ }
+
+ @Override
+ public int getTaskMenuWidth(View view) {
+ return view.getMeasuredWidth();
+ }
+
+ @Override
+ public int getTaskMenuLayoutOrientation() {
+ return LinearLayout.VERTICAL;
+ }
+
+ @Override
+ public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp) {
+ // no-op, defaults are fine
+ }
+
+ @Override
public ChildBounds getChildBounds(View child, int childStart, int pageCenter,
boolean layoutChild) {
final int childWidth = child.getMeasuredWidth();
diff --git a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java
index 5ce8a57..7beb7f7 100644
--- a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java
+++ b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java
@@ -20,6 +20,7 @@
import android.graphics.PointF;
import android.graphics.RectF;
import android.view.Surface;
+import android.view.View;
import com.android.launcher3.Utilities;
@@ -64,4 +65,14 @@
float oldY = velocity.y;
velocity.set(oldY, -oldX);
}
+
+ @Override
+ public float getTaskMenuX(float x, View thumbnailView) {
+ return x;
+ }
+
+ @Override
+ public float getTaskMenuY(float y, View thumbnailView) {
+ return y + thumbnailView.getMeasuredHeight();
+ }
}