From d4c4ad921268501570b77f0db62607962dd80b3b Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 23 Feb 2022 12:18:48 -0800 Subject: [PATCH] Removing some unnecessary layout calls in TaskView Bug: 221095750 Test: Presubmit Change-Id: I277c1350109ce3bd0b29502c588482c737ab1e3d --- .../com/android/quickstep/views/TaskView.java | 26 +++++++++---------- .../touch/LandscapePagedViewHandler.java | 20 +++----------- .../touch/PagedOrientationHandler.java | 14 ++-------- .../touch/PortraitPagedViewHandler.java | 24 ++--------------- .../touch/SeascapePagedViewHandler.java | 9 +++---- 5 files changed, 23 insertions(+), 70 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java index f716965fa1..984b0efb55 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.java +++ b/quickstep/src/com/android/quickstep/views/TaskView.java @@ -912,31 +912,31 @@ public class TaskView extends FrameLayout implements Reusable { public void setOrientationState(RecentsOrientedState orientationState) { PagedOrientationHandler orientationHandler = orientationState.getOrientationHandler(); boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL; - LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams(); DeviceProfile deviceProfile = mActivity.getDeviceProfile(); - snapshotParams.topMargin = deviceProfile.overviewTaskThumbnailTopMarginPx; + boolean isGridTask = isGridTask(); + LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams(); + + int thumbnailTopMargin = deviceProfile.overviewTaskThumbnailTopMarginPx; int taskIconHeight = deviceProfile.overviewTaskIconSizePx; int taskMargin = isGridTask ? deviceProfile.overviewTaskMarginGridPx : deviceProfile.overviewTaskMarginPx; - int taskIconMargin = snapshotParams.topMargin - taskIconHeight - taskMargin; - LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams(); - orientationHandler.setIconAndSnapshotParams(mIconView, taskIconMargin, taskIconHeight, - snapshotParams, isRtl); - updateDwbPlacement(); - mSnapshotView.setLayoutParams(snapshotParams); + int taskIconMargin = thumbnailTopMargin - taskIconHeight - taskMargin; + orientationHandler.setTaskIconParams(iconParams, taskIconMargin, taskIconHeight, + thumbnailTopMargin, isRtl); iconParams.width = iconParams.height = taskIconHeight; mIconView.setLayoutParams(iconParams); + mIconView.setRotation(orientationHandler.getDegreesRotated()); int iconDrawableSize = isGridTask ? deviceProfile.overviewTaskIconDrawableSizeGridPx : deviceProfile.overviewTaskIconDrawableSizePx; mIconView.setDrawableSize(iconDrawableSize, iconDrawableSize); - snapshotParams.topMargin = deviceProfile.overviewTaskThumbnailTopMarginPx; - mSnapshotView.setLayoutParams(snapshotParams); - mSnapshotView.getTaskOverlay().updateOrientationState(orientationState); - } - private void updateDwbPlacement() { + LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams(); + snapshotParams.topMargin = thumbnailTopMargin; + mSnapshotView.setLayoutParams(snapshotParams); + + mSnapshotView.getTaskOverlay().updateOrientationState(orientationState); mDigitalWellBeingToast.initialize(mTask); } diff --git a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java index 4a55d2e5b1..2609e549a5 100644 --- a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java +++ b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java @@ -177,18 +177,6 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { return VIEW_TRANSLATE_X; } - @Override - public int getSplitTaskViewDismissDirection(@StagePosition int stagePosition, - DeviceProfile dp) { - // Don't use device profile here because we know we're in fake landscape, only split option - // available is top/left - if (stagePosition == STAGE_POSITION_TOP_OR_LEFT) { - // Top (visually left) side - return SPLIT_TRANSLATE_PRIMARY_NEGATIVE; - } - throw new IllegalStateException("Invalid split stage position: " + stagePosition); - } - @Override public int getPrimaryScroll(View view) { return view.getScrollY(); @@ -469,14 +457,12 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { } @Override - public void setIconAndSnapshotParams(View iconView, int taskIconMargin, int taskIconHeight, - FrameLayout.LayoutParams snapshotParams, boolean isRtl) { - FrameLayout.LayoutParams iconParams = - (FrameLayout.LayoutParams) iconView.getLayoutParams(); + public void setTaskIconParams(FrameLayout.LayoutParams iconParams, int taskIconMargin, + int taskIconHeight, int thumbnailTopMargin, boolean isRtl) { iconParams.gravity = (isRtl ? START : END) | CENTER_VERTICAL; iconParams.rightMargin = -taskIconHeight - taskIconMargin / 2; iconParams.leftMargin = 0; - iconParams.topMargin = snapshotParams.topMargin / 2; + iconParams.topMargin = thumbnailTopMargin / 2; } @Override diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java index 923dcc6d01..6e594e9cc6 100644 --- a/src/com/android/launcher3/touch/PagedOrientationHandler.java +++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java @@ -47,10 +47,6 @@ import java.util.List; */ public interface PagedOrientationHandler { - int SPLIT_TRANSLATE_PRIMARY_POSITIVE = 0; - int SPLIT_TRANSLATE_PRIMARY_NEGATIVE = 1; - int SPLIT_TRANSLATE_SECONDARY_NEGATIVE = 2; - PagedOrientationHandler PORTRAIT = new PortraitPagedViewHandler(); PagedOrientationHandler LANDSCAPE = new LandscapePagedViewHandler(); PagedOrientationHandler SEASCAPE = new SeascapePagedViewHandler(); @@ -82,12 +78,6 @@ public interface PagedOrientationHandler { FloatProperty getPrimaryViewTranslate(); FloatProperty getSecondaryViewTranslate(); - /** - * @param stagePosition The position where the view to be split will go - * @return {@link #SPLIT_TRANSLATE_*} constants to indicate which direction the - * dismissal should happen - */ - int getSplitTaskViewDismissDirection(@StagePosition int stagePosition, DeviceProfile dp); int getPrimaryScroll(View view); float getPrimaryScale(View view); int getChildStart(View view); @@ -152,8 +142,8 @@ public interface PagedOrientationHandler { StagedSplitBounds splitBoundsConfig, DeviceProfile dp); // Overview TaskMenuView methods - void setIconAndSnapshotParams(View iconView, int taskIconMargin, int taskIconHeight, - FrameLayout.LayoutParams snapshotParams, boolean isRtl); + void setTaskIconParams(FrameLayout.LayoutParams iconParams, + int taskIconMargin, int taskIconHeight, int thumbnailTopMargin, boolean isRtl); void setSplitIconParams(View primaryIconView, View secondaryIconView, int taskIconHeight, int primarySnapshotWidth, int primarySnapshotHeight, boolean isRtl, DeviceProfile deviceProfile, StagedSplitBounds splitConfig); diff --git a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java index 0d92e2542a..2c9afd6506 100644 --- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java +++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java @@ -179,24 +179,6 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { return VIEW_TRANSLATE_Y; } - @Override - public int getSplitTaskViewDismissDirection(@StagePosition int stagePosition, - DeviceProfile dp) { - if (stagePosition == STAGE_POSITION_TOP_OR_LEFT) { - if (dp.isLandscape) { - // Left side - return SPLIT_TRANSLATE_PRIMARY_NEGATIVE; - } else { - // Top side - return SPLIT_TRANSLATE_SECONDARY_NEGATIVE; - } - } else if (stagePosition == STAGE_POSITION_BOTTOM_OR_RIGHT) { - // We don't have a bottom option, so should be right - return SPLIT_TRANSLATE_PRIMARY_POSITIVE; - } - throw new IllegalStateException("Invalid split stage position: " + stagePosition); - } - @Override public int getPrimaryScroll(View view) { return view.getScrollX(); @@ -567,10 +549,8 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { } @Override - public void setIconAndSnapshotParams(View iconView, int taskIconMargin, int taskIconHeight, - FrameLayout.LayoutParams snapshotParams, boolean isRtl) { - FrameLayout.LayoutParams iconParams = - (FrameLayout.LayoutParams) iconView.getLayoutParams(); + public void setTaskIconParams(FrameLayout.LayoutParams iconParams, int taskIconMargin, + int taskIconHeight, int thumbnailTopMargin, boolean isRtl) { iconParams.gravity = TOP | CENTER_HORIZONTAL; iconParams.leftMargin = iconParams.rightMargin = 0; iconParams.topMargin = taskIconMargin; diff --git a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java index 69e19f4e6c..9151796fc5 100644 --- a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java +++ b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java @@ -23,7 +23,6 @@ import static android.view.Gravity.START; import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL; import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT; -import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT; import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_TYPE_MAIN; import android.content.res.Resources; @@ -168,14 +167,12 @@ public class SeascapePagedViewHandler extends LandscapePagedViewHandler { } @Override - public void setIconAndSnapshotParams(View mIconView, int taskIconMargin, int taskIconHeight, - FrameLayout.LayoutParams snapshotParams, boolean isRtl) { - FrameLayout.LayoutParams iconParams = - (FrameLayout.LayoutParams) mIconView.getLayoutParams(); + public void setTaskIconParams(FrameLayout.LayoutParams iconParams, + int taskIconMargin, int taskIconHeight, int thumbnailTopMargin, boolean isRtl) { iconParams.gravity = (isRtl ? END : START) | CENTER_VERTICAL; iconParams.leftMargin = -taskIconHeight - taskIconMargin / 2; iconParams.rightMargin = 0; - iconParams.topMargin = snapshotParams.topMargin / 2; + iconParams.topMargin = thumbnailTopMargin / 2; } @Override