re-implement widget overlap option

This commit is contained in:
MrSluffy
2024-12-19 16:03:10 +08:00
parent b22516b024
commit b2de03076a
2 changed files with 19 additions and 5 deletions

View File

@@ -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<CellLayout> SPRING_LOADED_PROGRESS =
new FloatProperty<CellLayout>("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) {

View File

@@ -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<View> 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);