From b2de03076a6d398781af4cbf300eb417f9b1f35c Mon Sep 17 00:00:00 2001 From: MrSluffy Date: Thu, 19 Dec 2024 16:03:10 +0800 Subject: [PATCH] re-implement widget overlap option --- src/com/android/launcher3/CellLayout.java | 18 +++++++++++++----- .../launcher3/celllayout/ReorderAlgorithm.java | 6 ++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index ad586c95f8..a1fe3cd511 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -77,6 +77,7 @@ import com.android.launcher3.util.Themes; import com.android.launcher3.util.Thunk; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.widget.LauncherAppWidgetHostView; +import com.patrykmichalik.opto.core.PreferenceExtensionsKt; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -84,6 +85,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Stack; +import app.lawnchair.preferences2.PreferenceManager2; +import app.lawnchair.theme.color.tokens.ColorTokens; +import app.lawnchair.theme.drawable.DrawableTokens; + public class CellLayout extends ViewGroup { private static final String TAG = "CellLayout"; private static final boolean LOGD = false; @@ -208,6 +213,8 @@ public class CellLayout extends ViewGroup { CellLayoutContainer mCellLayoutContainer; + public final PreferenceManager2 pref; + public static final FloatProperty SPRING_LOADED_PROGRESS = new FloatProperty("spring_loaded_progress") { @Override @@ -244,6 +251,7 @@ public class CellLayout extends ViewGroup { mActivity = ActivityContext.lookupContext(context); DeviceProfile deviceProfile = mActivity.getDeviceProfile(); + pref = PreferenceManager2.getInstance(context); resetCellSizeInternal(deviceProfile); mCountX = deviceProfile.inv.numColumns; @@ -258,11 +266,11 @@ public class CellLayout extends ViewGroup { Resources res = getResources(); - mBackground = getContext().getDrawable(R.drawable.bg_celllayout); + mBackground = DrawableTokens.BgCellLayout.resolve(getContext()); mBackground.setCallback(this); mBackground.setAlpha(0); - mGridColor = Themes.getAttrColor(getContext(), R.attr.workspaceAccentColor); + mGridColor = ColorTokens.WorkspaceAccentColor.resolveColor(getContext()); mGridVisualizationRoundingRadius = res.getDimensionPixelSize(R.dimen.grid_visualization_rounding_radius); mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * deviceProfile.iconSizePx); @@ -274,7 +282,7 @@ public class CellLayout extends ViewGroup { for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new CellLayoutLayoutParams(0, 0, 0, 0); } - mDragOutlinePaint.setColor(Themes.getAttrColor(context, R.attr.workspaceTextColor)); + mDragOutlinePaint.setColor(ColorTokens.WorkspaceAccentColor.resolveColor(getContext())); // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail @@ -1853,7 +1861,7 @@ public class CellLayout extends ViewGroup { public boolean isOccupied(int x, int y) { if (x >= 0 && x < mCountX && y >= 0 && y < mCountY) { - return mOccupied.cells[x][y]; + return mOccupied.cells[x][y] && !PreferenceExtensionsKt.firstBlocking(pref.getAllowWidgetOverlap()); } if (BuildConfigs.IS_STUDIO_BUILD) { throw new RuntimeException("Position exceeds the bound of this CellLayout"); @@ -1936,7 +1944,7 @@ public class CellLayout extends ViewGroup { } public boolean isRegionVacant(int x, int y, int spanX, int spanY) { - return mOccupied.isRegionVacant(x, y, spanX, spanY); + return mOccupied.isRegionVacant(x, y, spanX, spanY) || PreferenceExtensionsKt.firstBlocking(pref.getAllowWidgetOverlap()); } public void setSpaceBetweenCellLayoutsPx(@Px int spaceBetweenCellLayoutsPx) { diff --git a/src/com/android/launcher3/celllayout/ReorderAlgorithm.java b/src/com/android/launcher3/celllayout/ReorderAlgorithm.java index 2b592475f6..42abecd1fe 100644 --- a/src/com/android/launcher3/celllayout/ReorderAlgorithm.java +++ b/src/com/android/launcher3/celllayout/ReorderAlgorithm.java @@ -22,6 +22,7 @@ import com.android.launcher3.CellLayout; import com.android.launcher3.Utilities; import com.android.launcher3.util.CellAndSpan; import com.android.launcher3.util.GridOccupancy; +import com.patrykmichalik.opto.core.PreferenceExtensionsKt; import java.util.ArrayList; import java.util.Comparator; @@ -131,6 +132,11 @@ public class ReorderAlgorithm { ArrayList intersectingViews = new ArrayList<>(); Rect occupiedRect = new Rect(cellX, cellY, cellX + spanX, cellY + spanY); + if (PreferenceExtensionsKt.firstBlocking(mCellLayout.pref.getAllowWidgetOverlap())) { + solution.intersectingViews = new ArrayList<>(intersectingViews); + return true; + } + // Mark the desired location of the view currently being dragged. if (ignoreView != null) { CellAndSpan c = solution.map.get(ignoreView);