mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-11 06:44:00 +00:00
re-implement widget overlap option
This commit is contained in:
@@ -77,6 +77,7 @@ import com.android.launcher3.util.Themes;
|
|||||||
import com.android.launcher3.util.Thunk;
|
import com.android.launcher3.util.Thunk;
|
||||||
import com.android.launcher3.views.ActivityContext;
|
import com.android.launcher3.views.ActivityContext;
|
||||||
import com.android.launcher3.widget.LauncherAppWidgetHostView;
|
import com.android.launcher3.widget.LauncherAppWidgetHostView;
|
||||||
|
import com.patrykmichalik.opto.core.PreferenceExtensionsKt;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
@@ -84,6 +85,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Stack;
|
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 {
|
public class CellLayout extends ViewGroup {
|
||||||
private static final String TAG = "CellLayout";
|
private static final String TAG = "CellLayout";
|
||||||
private static final boolean LOGD = false;
|
private static final boolean LOGD = false;
|
||||||
@@ -208,6 +213,8 @@ public class CellLayout extends ViewGroup {
|
|||||||
|
|
||||||
CellLayoutContainer mCellLayoutContainer;
|
CellLayoutContainer mCellLayoutContainer;
|
||||||
|
|
||||||
|
public final PreferenceManager2 pref;
|
||||||
|
|
||||||
public static final FloatProperty<CellLayout> SPRING_LOADED_PROGRESS =
|
public static final FloatProperty<CellLayout> SPRING_LOADED_PROGRESS =
|
||||||
new FloatProperty<CellLayout>("spring_loaded_progress") {
|
new FloatProperty<CellLayout>("spring_loaded_progress") {
|
||||||
@Override
|
@Override
|
||||||
@@ -244,6 +251,7 @@ public class CellLayout extends ViewGroup {
|
|||||||
mActivity = ActivityContext.lookupContext(context);
|
mActivity = ActivityContext.lookupContext(context);
|
||||||
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
|
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
|
||||||
|
|
||||||
|
pref = PreferenceManager2.getInstance(context);
|
||||||
resetCellSizeInternal(deviceProfile);
|
resetCellSizeInternal(deviceProfile);
|
||||||
|
|
||||||
mCountX = deviceProfile.inv.numColumns;
|
mCountX = deviceProfile.inv.numColumns;
|
||||||
@@ -258,11 +266,11 @@ public class CellLayout extends ViewGroup {
|
|||||||
|
|
||||||
Resources res = getResources();
|
Resources res = getResources();
|
||||||
|
|
||||||
mBackground = getContext().getDrawable(R.drawable.bg_celllayout);
|
mBackground = DrawableTokens.BgCellLayout.resolve(getContext());
|
||||||
mBackground.setCallback(this);
|
mBackground.setCallback(this);
|
||||||
mBackground.setAlpha(0);
|
mBackground.setAlpha(0);
|
||||||
|
|
||||||
mGridColor = Themes.getAttrColor(getContext(), R.attr.workspaceAccentColor);
|
mGridColor = ColorTokens.WorkspaceAccentColor.resolveColor(getContext());
|
||||||
mGridVisualizationRoundingRadius =
|
mGridVisualizationRoundingRadius =
|
||||||
res.getDimensionPixelSize(R.dimen.grid_visualization_rounding_radius);
|
res.getDimensionPixelSize(R.dimen.grid_visualization_rounding_radius);
|
||||||
mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * deviceProfile.iconSizePx);
|
mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * deviceProfile.iconSizePx);
|
||||||
@@ -274,7 +282,7 @@ public class CellLayout extends ViewGroup {
|
|||||||
for (int i = 0; i < mDragOutlines.length; i++) {
|
for (int i = 0; i < mDragOutlines.length; i++) {
|
||||||
mDragOutlines[i] = new CellLayoutLayoutParams(0, 0, 0, 0);
|
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
|
// 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
|
// 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) {
|
public boolean isOccupied(int x, int y) {
|
||||||
if (x >= 0 && x < mCountX && y >= 0 && y < mCountY) {
|
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) {
|
if (BuildConfigs.IS_STUDIO_BUILD) {
|
||||||
throw new RuntimeException("Position exceeds the bound of this CellLayout");
|
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) {
|
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) {
|
public void setSpaceBetweenCellLayoutsPx(@Px int spaceBetweenCellLayoutsPx) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.android.launcher3.CellLayout;
|
|||||||
import com.android.launcher3.Utilities;
|
import com.android.launcher3.Utilities;
|
||||||
import com.android.launcher3.util.CellAndSpan;
|
import com.android.launcher3.util.CellAndSpan;
|
||||||
import com.android.launcher3.util.GridOccupancy;
|
import com.android.launcher3.util.GridOccupancy;
|
||||||
|
import com.patrykmichalik.opto.core.PreferenceExtensionsKt;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -131,6 +132,11 @@ public class ReorderAlgorithm {
|
|||||||
ArrayList<View> intersectingViews = new ArrayList<>();
|
ArrayList<View> intersectingViews = new ArrayList<>();
|
||||||
Rect occupiedRect = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
|
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.
|
// Mark the desired location of the view currently being dragged.
|
||||||
if (ignoreView != null) {
|
if (ignoreView != null) {
|
||||||
CellAndSpan c = solution.map.get(ignoreView);
|
CellAndSpan c = solution.map.get(ignoreView);
|
||||||
|
|||||||
Reference in New Issue
Block a user