mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 18:58:19 +00:00
Adding animation so the CellLayout is properly spaced on Foldables
Flag: LEGACY FOLDABLE_SINGLE_PAGE DISABLED Fix: 294841331 Test: atest HomeScreenEditStateImageTest Change-Id: I5dc94b63ca322748b952ce4bd55b6951d51d190f
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -349,7 +349,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
setPageSpacing(Math.max(maxInsets, maxPadding));
|
||||
}
|
||||
|
||||
updateCellLayoutPadding();
|
||||
updateCellLayoutMeasures();
|
||||
updateWorkspaceWidgetsSizes();
|
||||
setPageIndicatorInset();
|
||||
}
|
||||
@@ -373,10 +373,12 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
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<T extends View & PageIndicator> extends PagedView<T>
|
||||
mLauncher.getStateManager().getState(), newScreen, insertIndex);
|
||||
|
||||
updatePageScrollValues();
|
||||
updateCellLayoutPadding();
|
||||
updateCellLayoutMeasures();
|
||||
return newScreen;
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user