Adding animation so the CellLayout is properly spaced on Foldables
Flag: LEGACY FOLDABLE_SINGLE_PAGE DISABLED
Fix: 294841331
Test: atest HomeScreenEditStateImageTest
Change-Id: I5dc94b63ca322748b952ce4bd55b6951d51d190f
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 91fbe53..94e5970 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -57,6 +57,7 @@
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 @@
private final TimeInterpolator mEaseOutInterpolator;
protected final ShortcutAndWidgetContainer mShortcutsAndWidgets;
+ @Px
+ protected int mSpaceBetweenCellLayoutsPx = 0;
@Retention(RetentionPolicy.SOURCE)
@IntDef({WORKSPACE, HOTSEAT, FOLDER})
@@ -636,12 +639,19 @@
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 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 44a1414..4b5c9ef 100644
--- a/src/com/android/launcher3/MultipageCellLayout.java
+++ b/src/com/android/launcher3/MultipageCellLayout.java
@@ -26,6 +26,7 @@
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 @@
@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 @@
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 eeb5fe0..30f3f5f 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -349,7 +349,7 @@
setPageSpacing(Math.max(maxInsets, maxPadding));
}
- updateCellLayoutPadding();
+ updateCellLayoutMeasures();
updateWorkspaceWidgetsSizes();
setPageIndicatorInset();
}
@@ -373,10 +373,12 @@
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 @@
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 e4f34ae..84d3805 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.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 @@
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 0e32ba7..6f6392f 100644
--- a/src/com/android/launcher3/util/MultiTranslateDelegate.java
+++ b/src/com/android/launcher3/util/MultiTranslateDelegate.java
@@ -37,8 +37,11 @@
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;