diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 2bdcfe3693..bbe9a954a4 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -72,6 +72,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.preferencemanager.PreferenceExtensionsKt; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -81,6 +82,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.Stack; +import app.lawnchair.preferences2.PreferenceManager2; import app.lawnchair.theme.color.ColorTokens; import app.lawnchair.theme.drawable.DrawableTokens; @@ -206,6 +208,7 @@ public class CellLayout extends ViewGroup { // Related to accessible drag and drop DragAndDropAccessibilityDelegate mTouchHelper; + PreferenceManager2 mPreferenceManager2; public static final FloatProperty SPRING_LOADED_PROGRESS = new FloatProperty("spring_loaded_progress") { @@ -241,6 +244,8 @@ public class CellLayout extends ViewGroup { mActivity = ActivityContext.lookupContext(context); DeviceProfile deviceProfile = mActivity.getDeviceProfile(); + mPreferenceManager2 = PreferenceManager2.getInstance(context); + mBorderSpace = mContainerType == FOLDER ? new Point(deviceProfile.folderCellLayoutBorderSpacePx) : new Point(deviceProfile.cellLayoutBorderSpacePx); @@ -1878,6 +1883,11 @@ public class CellLayout extends ViewGroup { if (cellX < 0 || cellY < 0) return false; mIntersectingViews.clear(); + if (PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getAllowWidgetOverlap())) { + // let's pretend no intersections exist + solution.intersectingViews = new ArrayList<>(mIntersectingViews); + return true; + } mOccupiedRect.set(cellX, cellY, cellX + spanX, cellY + spanY); // Mark the desired location of the view currently being dragged. @@ -2717,7 +2727,7 @@ public class CellLayout extends ViewGroup { public boolean isOccupied(int x, int y) { if (x < mCountX && y < mCountY) { - return mOccupied.cells[x][y]; + return mOccupied.cells[x][y] && !PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getAllowWidgetOverlap()); } else { throw new RuntimeException("Position exceeds the bound of this CellLayout"); } @@ -2983,6 +2993,6 @@ 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(mPreferenceManager2.getAllowWidgetOverlap()); } } diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java index fec1d6840b..fcef887b68 100644 --- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java +++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java @@ -33,6 +33,10 @@ import com.android.launcher3.CellLayout.ContainerType; import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.widget.NavigableAppWidgetHostView; +import com.patrykmichalik.preferencemanager.PreferenceExtensionsKt; + +import app.lawnchair.preferences2.PreferenceManager2; +import app.lawnchair.util.FlowUtilsKt; public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.FolderIconParent { static final String TAG = "ShortcutAndWidgetContainer"; @@ -57,11 +61,23 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. private final ActivityContext mActivity; private boolean mInvertIfRtl = false; + private final PreferenceManager2 mPreferenceManager2; + public ShortcutAndWidgetContainer(Context context, @ContainerType int containerType) { super(context); mActivity = ActivityContext.lookupContext(context); mWallpaperManager = WallpaperManager.getInstance(context); mContainerType = containerType; + mPreferenceManager2 = PreferenceManager2.getInstance(context); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + boolean mAllowWidgetOverlap = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getAllowWidgetOverlap()); + setClipChildren(!mAllowWidgetOverlap); + setClipToPadding(!mAllowWidgetOverlap); + setClipToOutline(!mAllowWidgetOverlap); } public void setCellDimensions(int cellWidth, int cellHeight, int countX, int countY, diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java index 1ef4638ba4..b8218cbf9a 100644 --- a/src/com/android/launcher3/model/LoaderCursor.java +++ b/src/com/android/launcher3/model/LoaderCursor.java @@ -53,11 +53,13 @@ import com.android.launcher3.util.ContentWriter; import com.android.launcher3.util.GridOccupancy; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSparseArrayMap; +import com.patrykmichalik.preferencemanager.PreferenceExtensionsKt; import java.net.URISyntaxException; import java.security.InvalidParameterException; import app.lawnchair.LawnchairApp; +import app.lawnchair.preferences2.PreferenceManager2; /** * Extension of {@link Cursor} with utility methods for workspace loading. @@ -104,10 +106,11 @@ public class LoaderCursor extends CursorWrapper { public int itemType; public int restoreFlag; + private final PreferenceManager2 preferenceManager2; + public LoaderCursor(Cursor cursor, Uri contentUri, LauncherAppState app, UserManagerState userManagerState) { super(cursor); - allUsers = userManagerState.allUsers; mContentUri = contentUri; mContext = app.getContext(); @@ -115,6 +118,8 @@ public class LoaderCursor extends CursorWrapper { mIDP = app.getInvariantDeviceProfile(); mPM = mContext.getPackageManager(); + preferenceManager2 = PreferenceManager2.getInstance(mContext); + // Init column indices iconIndex = getColumnIndexOrThrow(LauncherSettings.Favorites.ICON); iconPackageIndex = getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_PACKAGE); @@ -478,7 +483,7 @@ public class LoaderCursor extends CursorWrapper { + " into cell (" + containerIndex + "-" + item.screenId + ":" + item.cellX + "," + item.cellX + "," + item.spanX + "," + item.spanY + ") already occupied"); - return false; + return PreferenceExtensionsKt.firstBlocking(preferenceManager2.getAllowWidgetOverlap()); } } }