From e553e380d0dae577b690a355056cbaaacef2228b Mon Sep 17 00:00:00 2001 From: Vinit Nayak Date: Wed, 15 Apr 2020 14:13:38 -0700 Subject: [PATCH] Rotate Overview Task Action Menu Fixes: 153371258 Test: Tap on icon in portrait, landscape and seascape. Open menu then rotate phone. Change-Id: I38b018371561b502fe211a3c2ddea4ff7fde4274 --- .../android/quickstep/views/TaskMenuView.java | 41 +++++++++++++++---- .../com/android/quickstep/views/TaskView.java | 23 ++++++++--- .../touch/LandscapePagedViewHandler.java | 29 +++++++++++++ .../touch/PagedOrientationHandler.java | 6 +++ .../touch/PortraitPagedViewHandler.java | 26 ++++++++++++ .../touch/SeascapePagedViewHandler.java | 11 +++++ 6 files changed, 124 insertions(+), 12 deletions(-) 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 80022b4fe1..9b475205dd 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.AnimationSuccessListener; 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 @@ public class TaskMenuView extends AbstractFloatingView { 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 @@ public class TaskMenuView extends AbstractFloatingView { } 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 @@ public class TaskMenuView extends AbstractFloatingView { 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 b0758c9e48..ce8a193f00 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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { 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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { 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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { 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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { } 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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { 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 e290685d5e..dc500536d3 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.Surface; 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; @@ -223,6 +225,33 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { return 1; } + @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) { diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java index b8396e1119..cc15f99127 100644 --- a/src/com/android/launcher3/touch/PagedOrientationHandler.java +++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java @@ -27,6 +27,7 @@ import android.view.MotionEvent; 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 @@ public interface PagedOrientationHandler { 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 dad00a4b5b..7c30e29aa4 100644 --- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java +++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java @@ -30,6 +30,7 @@ import android.view.Surface; 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; @@ -221,6 +222,31 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { return -1; } + @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) { diff --git a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java index 5ce8a5763e..7beb7f7466 100644 --- a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java +++ b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java @@ -20,6 +20,7 @@ import android.content.res.Resources; 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 @@ public class SeascapePagedViewHandler extends LandscapePagedViewHandler { 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(); + } }