From 9ea36d429cf4e566bfcd3fccc389b504ea276313 Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Thu, 21 Sep 2023 13:56:42 -0700 Subject: [PATCH] Adding animation so the CellLayout is properly spaced on Foldables Flag: LEGACY FOLDABLE_SINGLE_PAGE DISABLED Fix: 294841331 Test: atest HomeScreenEditStateImageTest Change-Id: I5dc94b63ca322748b952ce4bd55b6951d51d190f --- src/com/android/launcher3/CellLayout.java | 14 ++++++ .../launcher3/MultipageCellLayout.java | 49 +++++++++++++++++-- src/com/android/launcher3/Workspace.java | 12 +++-- .../WorkspaceStateTransitionAnimation.java | 11 +++-- .../util/MultiTranslateDelegate.java | 5 +- 5 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 91fbe536b7..94e5970f3c 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -57,6 +57,7 @@ import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; import androidx.annotation.IntDef; +import androidx.annotation.Px; import androidx.core.graphics.ColorUtils; import androidx.core.view.ViewCompat; @@ -175,6 +176,8 @@ public class CellLayout extends ViewGroup { private final TimeInterpolator mEaseOutInterpolator; protected final ShortcutAndWidgetContainer mShortcutsAndWidgets; + @Px + protected int mSpaceBetweenCellLayoutsPx = 0; @Retention(RetentionPolicy.SOURCE) @IntDef({WORKSPACE, HOTSEAT, FOLDER}) @@ -636,12 +639,19 @@ public class CellLayout extends ViewGroup { mVisualizeGridPaint.setColor(Color.argb((int) (alpha), Color.red(mGridColor), Color.green(mGridColor), Color.blue(mGridColor))); + canvas.save(); + canvas.translate(getMarginForGivenCellParams(params), 0); canvas.drawRoundRect(mVisualizeGridRect, mGridVisualizationRoundingRadius, mGridVisualizationRoundingRadius, mVisualizeGridPaint); + canvas.restore(); } } } + protected float getMarginForGivenCellParams(CellLayoutLayoutParams params) { + return 0; + } + @Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); @@ -2844,4 +2854,8 @@ public class CellLayout extends ViewGroup { public boolean isRegionVacant(int x, int y, int spanX, int spanY) { return mOccupied.isRegionVacant(x, y, spanX, spanY); } + + public void setSpaceBetweenCellLayoutsPx(@Px int spaceBetweenCellLayoutsPx) { + mSpaceBetweenCellLayoutsPx = spaceBetweenCellLayoutsPx; + } } diff --git a/src/com/android/launcher3/MultipageCellLayout.java b/src/com/android/launcher3/MultipageCellLayout.java index 44a1414d21..4b5c9ef8e4 100644 --- a/src/com/android/launcher3/MultipageCellLayout.java +++ b/src/com/android/launcher3/MultipageCellLayout.java @@ -26,6 +26,7 @@ import com.android.launcher3.celllayout.CellLayoutLayoutParams; import com.android.launcher3.celllayout.MulticellReorderAlgorithm; import com.android.launcher3.util.CellAndSpan; import com.android.launcher3.util.GridOccupancy; +import com.android.launcher3.util.MultiTranslateDelegate; /** * CellLayout that simulates a split in the middle for use in foldable devices. @@ -139,18 +140,59 @@ public class MultipageCellLayout extends CellLayout { @Override protected void onDraw(Canvas canvas) { + float animatedWorkspaceMargin = mSpaceBetweenCellLayoutsPx * mSpringLoadedProgress; if (mLeftBackground.getAlpha() > 0) { + canvas.save(); + canvas.translate(-animatedWorkspaceMargin, 0); mLeftBackground.setState(mBackground.getState()); mLeftBackground.draw(canvas); + canvas.restore(); } if (mRightBackground.getAlpha() > 0) { + canvas.save(); + canvas.translate(animatedWorkspaceMargin, 0); mRightBackground.setState(mBackground.getState()); mRightBackground.draw(canvas); + canvas.restore(); } - super.onDraw(canvas); } + private void updateMarginBetweenCellLayouts() { + for (int i = 0; i < mShortcutsAndWidgets.getChildCount(); i++) { + View workspaceItem = mShortcutsAndWidgets.getChildAt(i); + if (!(workspaceItem instanceof Reorderable)) { + continue; + } + CellLayoutLayoutParams params = + (CellLayoutLayoutParams) workspaceItem.getLayoutParams(); + ((Reorderable) workspaceItem).getTranslateDelegate().setTranslation( + MultiTranslateDelegate.INDEX_CELLAYOUT_MULTIPAGE_SPACING, + getMarginForGivenCellParams(params), + 0 + ); + + } + } + + @Override + protected float getMarginForGivenCellParams(CellLayoutLayoutParams params) { + float margin = mSpaceBetweenCellLayoutsPx * mSpringLoadedProgress; + return params.getCellX() >= mCountX / 2 ? margin : -margin; + } + + @Override + public void setSpringLoadedProgress(float progress) { + super.setSpringLoadedProgress(progress); + updateMarginBetweenCellLayouts(); + } + + @Override + public void setSpaceBetweenCellLayoutsPx(int spaceBetweenCellLayoutsPx) { + super.setSpaceBetweenCellLayoutsPx(spaceBetweenCellLayoutsPx); + updateMarginBetweenCellLayouts(); + } + @Override protected void updateBgAlpha() { mLeftBackground.setAlpha((int) (mSpringLoadedProgress * 255)); @@ -161,8 +203,9 @@ public class MultipageCellLayout extends CellLayout { protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); Rect rect = mBackground.getBounds(); - mLeftBackground.setBounds(rect.left, rect.top, rect.right / 2 - 20, rect.bottom); - mRightBackground.setBounds(rect.right / 2 + 20, rect.top, rect.right, rect.bottom); + int middlePointInPixels = rect.centerX(); + mLeftBackground.setBounds(rect.left, rect.top, middlePointInPixels, rect.bottom); + mRightBackground.setBounds(middlePointInPixels, rect.top, rect.right, rect.bottom); } public void setCountX(int countX) { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index eeb5fe0a56..30f3f5fb3d 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -349,7 +349,7 @@ public class Workspace extends PagedView setPageSpacing(Math.max(maxInsets, maxPadding)); } - updateCellLayoutPadding(); + updateCellLayoutMeasures(); updateWorkspaceWidgetsSizes(); setPageIndicatorInset(); } @@ -373,10 +373,12 @@ public class Workspace extends PagedView mPageIndicator.setLayoutParams(lp); } - private void updateCellLayoutPadding() { + private void updateCellLayoutMeasures() { Rect padding = mLauncher.getDeviceProfile().cellLayoutPaddingPx; - mWorkspaceScreens.forEach( - s -> s.setPadding(padding.left, padding.top, padding.right, padding.bottom)); + mWorkspaceScreens.forEach(cellLayout -> { + cellLayout.setPadding(padding.left, padding.top, padding.right, padding.bottom); + cellLayout.setSpaceBetweenCellLayoutsPx(getPageSpacing() / 4); + }); } private void updateWorkspaceWidgetsSizes() { @@ -690,7 +692,7 @@ public class Workspace extends PagedView mLauncher.getStateManager().getState(), newScreen, insertIndex); updatePageScrollValues(); - updateCellLayoutPadding(); + updateCellLayoutMeasures(); return newScreen; } diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java index e4f34ae0ab..84d3805536 100644 --- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java +++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java @@ -34,6 +34,7 @@ import static com.android.launcher3.LauncherState.HOTSEAT_ICONS; import static com.android.launcher3.LauncherState.NORMAL; import static com.android.launcher3.LauncherState.WORKSPACE_PAGE_INDICATOR; import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER; +import static com.android.launcher3.config.FeatureFlags.FOLDABLE_SINGLE_PAGE; import static com.android.launcher3.graphics.Scrim.SCRIM_PROGRESS; import static com.android.launcher3.states.StateAnimationConfig.ANIM_HOTSEAT_FADE; import static com.android.launcher3.states.StateAnimationConfig.ANIM_HOTSEAT_SCALE; @@ -172,9 +173,13 @@ public class WorkspaceStateTransitionAnimation { scaleAndTranslation.translationY, translationInterpolator); PageTranslationProvider pageTranslationProvider = state.getWorkspacePageTranslationProvider( mLauncher); - for (int i = 0; i < childCount; i++) { - applyPageTranslation((CellLayout) mWorkspace.getChildAt(i), i, pageTranslationProvider, - propertySetter, config); + + if (!FOLDABLE_SINGLE_PAGE.get()) { + for (int i = 0; i < childCount; i++) { + applyPageTranslation((CellLayout) mWorkspace.getChildAt(i), i, + pageTranslationProvider, + propertySetter, config); + } } Interpolator hotseatTranslationInterpolator = config.getInterpolator( diff --git a/src/com/android/launcher3/util/MultiTranslateDelegate.java b/src/com/android/launcher3/util/MultiTranslateDelegate.java index 0e32ba7bfc..6f6392fde8 100644 --- a/src/com/android/launcher3/util/MultiTranslateDelegate.java +++ b/src/com/android/launcher3/util/MultiTranslateDelegate.java @@ -37,8 +37,11 @@ public class MultiTranslateDelegate { public static final int INDEX_TASKBAR_ALIGNMENT_ANIM = 3; public static final int INDEX_TASKBAR_REVEAL_ANIM = 4; + // Affect all items inside of a MultipageCellLayout + public static final int INDEX_CELLAYOUT_MULTIPAGE_SPACING = 3; + // Specific for widgets - public static final int INDEX_WIDGET_CENTERING = 3; + public static final int INDEX_WIDGET_CENTERING = 4; // Specific for hotseat items when adjusting for bubbles public static final int INDEX_BUBBLE_ADJUSTMENT_ANIM = 3;