From f316a267d828e2fd8ed1fe1656be381a1121ed9d Mon Sep 17 00:00:00 2001 From: Thales Lima Date: Fri, 19 Nov 2021 13:05:26 -0300 Subject: [PATCH] Add scrim below TaskMenu When opening a menu, a scrim with 80% alpha should be shown on top of Recents view. Align task menu second row with icon: when the menu shows up in the bottom row in landscape, the menu should be aligned on the second row. TODO: there is a RTL bug that I'm waiting because it also affects other parts, not only this menu. Bug: 193432925 Test: open Overview and tap the app icon Change-Id: I6846ee937cb5e739e8be64d17045bc3b32e28e46 --- .../com/android/quickstep/views/IconView.java | 8 ++ .../android/quickstep/views/RecentsView.java | 13 ++- .../quickstep/views/TaskMenuViewWithArrow.kt | 100 ++++++++++++++---- .../com/android/quickstep/views/TaskView.java | 4 +- 4 files changed, 102 insertions(+), 23 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/IconView.java b/quickstep/src/com/android/quickstep/views/IconView.java index ccb1a991ea..5895c05dcd 100644 --- a/quickstep/src/com/android/quickstep/views/IconView.java +++ b/quickstep/src/com/android/quickstep/views/IconView.java @@ -87,6 +87,14 @@ public class IconView extends View { return mDrawable; } + public int getDrawableWidth() { + return mDrawableWidth; + } + + public int getDrawableHeight() { + return mDrawableHeight; + } + @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 017a3b8589..c14cead0ee 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -2612,10 +2612,8 @@ public abstract class RecentsView secondaryViewTranslate = taskView.getSecondaryDissmissTranslationProperty(); int secondaryTaskDimension = mOrientationHandler.getSecondaryDimension(taskView); @@ -4681,6 +4679,15 @@ public abstract class RecentsView getEventDispatcher(float navbarRotation) { float degreesRotated; if (navbarRotation == 0) { diff --git a/quickstep/src/com/android/quickstep/views/TaskMenuViewWithArrow.kt b/quickstep/src/com/android/quickstep/views/TaskMenuViewWithArrow.kt index cd1691ba53..06a579300a 100644 --- a/quickstep/src/com/android/quickstep/views/TaskMenuViewWithArrow.kt +++ b/quickstep/src/com/android/quickstep/views/TaskMenuViewWithArrow.kt @@ -45,7 +45,10 @@ class TaskMenuViewWithArrow : ArrowPopup { companion object { const val TAG = "TaskMenuViewWithArrow" - fun showForTask(taskContainer: TaskIdAttributeContainer): Boolean { + fun showForTask( + taskContainer: TaskIdAttributeContainer, + alignSecondRow: Boolean = false + ): Boolean { val activity = BaseDraggingActivity .fromContext(taskContainer.taskView.context) val taskMenuViewWithArrow = activity.layoutInflater @@ -55,7 +58,7 @@ class TaskMenuViewWithArrow : ArrowPopup { false ) as TaskMenuViewWithArrow<*> - return taskMenuViewWithArrow.populateAndShowForTask(taskContainer) + return taskMenuViewWithArrow.populateAndShowForTask(taskContainer, alignSecondRow) } } @@ -78,6 +81,9 @@ class TaskMenuViewWithArrow : ArrowPopup { CLOSE_FADE_DURATION = CLOSE_CHILD_FADE_DURATION } + private var alignSecondRow: Boolean = false + private val extraSpaceForSecondRowAlignment: Int + get() = if (alignSecondRow) optionMeasuredHeight else 0 private val menuWidth = context.resources.getDimensionPixelSize(R.dimen.task_menu_width_grid) private lateinit var taskView: TaskView @@ -91,6 +97,10 @@ class TaskMenuViewWithArrow : ArrowPopup { else 0 + private var iconView: IconView? = null + private var scrim: View? = null + private val scrimAlpha = 0.8f + override fun isOfType(type: Int): Boolean = type and TYPE_TASK_MENU != 0 override fun getTargetObjectLocation(outPos: Rect?) { @@ -112,18 +122,35 @@ class TaskMenuViewWithArrow : ArrowPopup { optionLayout = findViewById(KtR.id.menu_option_layout) } - private fun populateAndShowForTask(taskContainer: TaskIdAttributeContainer): Boolean { + private fun populateAndShowForTask( + taskContainer: TaskIdAttributeContainer, + alignSecondRow: Boolean + ): Boolean { if (isAttachedToWindow) { return false } taskView = taskContainer.taskView this.taskContainer = taskContainer + this.alignSecondRow = alignSecondRow if (!populateMenu()) return false + addScrim() show() return true } + private fun addScrim() { + scrim = View(context).apply { + layoutParams = FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.MATCH_PARENT + ) + setBackgroundColor(Themes.getAttrColor(context, R.attr.overviewScrimColor)) + alpha = 0f + } + popupContainer.addView(scrim) + } + /** @return true if successfully able to populate task view menu, false otherwise */ private fun populateMenu(): Boolean { @@ -180,18 +207,50 @@ class TaskMenuViewWithArrow : ArrowPopup { } override fun onCreateOpenAnimation(anim: AnimatorSet) { - anim.play( - ObjectAnimator.ofFloat( - taskContainer.thumbnailView, TaskThumbnailView.DIM_ALPHA, - TaskView.MAX_PAGE_SCRIM_ALPHA + scrim?.let { + anim.play( + ObjectAnimator.ofFloat(it, View.ALPHA, 0f, scrimAlpha) + .setDuration(OPEN_DURATION.toLong()) ) - ) + } } override fun onCreateCloseAnimation(anim: AnimatorSet) { - anim.play( - ObjectAnimator.ofFloat(taskContainer.thumbnailView, TaskThumbnailView.DIM_ALPHA, 0f) - ) + scrim?.let { + anim.play( + ObjectAnimator.ofFloat(it, View.ALPHA, scrimAlpha, 0f) + .setDuration(CLOSE_DURATION.toLong()) + ) + } + } + + override fun closeComplete() { + super.closeComplete() + popupContainer.removeView(scrim) + popupContainer.removeView(iconView) + } + + /** + * Copy the iconView from taskView to dragLayer so it can stay on top of the scrim. + * It needs to be called after [getTargetObjectLocation] because [mTempRect] needs to be + * populated. + */ + private fun copyIconToDragLayer(insets: Rect) { + iconView = IconView(context).apply { + layoutParams = FrameLayout.LayoutParams( + taskContainer.iconView.width, + taskContainer.iconView.height + ) + x = mTempRect.left.toFloat() - insets.left + y = mTempRect.top.toFloat() - insets.top + drawable = taskContainer.iconView.drawable + setDrawableSize( + taskContainer.iconView.drawableWidth, + taskContainer.iconView.drawableHeight + ) + } + + popupContainer.addView(iconView) } /** @@ -217,7 +276,10 @@ class TaskMenuViewWithArrow : ArrowPopup { val dragLayer: InsettableFrameLayout = popupContainer val insets = dragLayer.insets - // Put to the right of the icon if there is space, which means left aligned with the menu + copyIconToDragLayer(insets) + + // Put this menu to the right of the icon if there is space, + // which means the arrow is left aligned with the menu val rightAlignedMenuStartX = mTempRect.left - widthWithArrow val leftAlignedMenuStartX = mTempRect.right + extraHorizontalSpace mIsLeftAligned = if (mIsRtl) { @@ -229,18 +291,17 @@ class TaskMenuViewWithArrow : ArrowPopup { var menuStartX = if (mIsLeftAligned) leftAlignedMenuStartX else rightAlignedMenuStartX - // Offset y so that the arrow and first row are center-aligned with the original icon. + // Offset y so that the arrow and row are center-aligned with the original icon. val iconHeight = mTempRect.height() - val optionHeight = optionMeasuredHeight - val yOffset = (optionHeight - iconHeight) / 2 - var menuStartY = mTempRect.top - yOffset + val yOffset = (optionMeasuredHeight - iconHeight) / 2 + var menuStartY = mTempRect.top - yOffset - extraSpaceForSecondRowAlignment // Insets are added later, so subtract them now. menuStartX -= insets.left menuStartY -= insets.top - setX(menuStartX.toFloat()) - setY(menuStartY.toFloat()) + x = menuStartX.toFloat() + y = menuStartY.toFloat() val lp = layoutParams as FrameLayout.LayoutParams val arrowLp = mArrow.layoutParams as FrameLayout.LayoutParams @@ -251,7 +312,8 @@ class TaskMenuViewWithArrow : ArrowPopup { override fun addArrow() { popupContainer.addView(mArrow) mArrow.x = getArrowX() - mArrow.y = y + (optionMeasuredHeight / 2) - (mArrowHeight / 2) + mArrow.y = y + (optionMeasuredHeight / 2) - (mArrowHeight / 2) + + extraSpaceForSecondRowAlignment updateArrowColor() diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java index 1ff2a88b31..7778813200 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.java +++ b/quickstep/src/com/android/quickstep/views/TaskView.java @@ -840,7 +840,9 @@ public class TaskView extends FrameLayout implements Reusable { TaskIdAttributeContainer menuContainer = mTaskIdAttributeContainer[iconView == mIconView ? 0 : 1]; if (mActivity.getDeviceProfile().overviewShowAsGrid) { - return TaskMenuViewWithArrow.Companion.showForTask(menuContainer); + boolean alignSecondRow = getRecentsView().isOnGridBottomRow(menuContainer.getTaskView()) + && mActivity.getDeviceProfile().isLandscape; + return TaskMenuViewWithArrow.Companion.showForTask(menuContainer, alignSecondRow); } else { return TaskMenuView.showForTask(menuContainer); }