mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-02 17:06:49 +00:00
Revert "Moving rearrangementExists to ReorderLogic since it's only used there"
This reverts commit 6890893a24.
Reason for revert: Many build breaks, like https://android-build.corp.google.com/artifact/submitted/11157014/mokey_go32-trunk_staging-userdebug/latest/view/logs%2Fbuild_error.log , seem related to this.
Change-Id: I049c94fbd1e089c65fd4e0abb4ac2c165f228c92
This commit is contained in:
committed by
Android (Google) Code Review
parent
6890893a24
commit
484a7ea4f3
@@ -89,6 +89,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class CellLayout extends ViewGroup {
|
||||
@@ -1809,7 +1811,7 @@ public class CellLayout extends ViewGroup {
|
||||
return bestXY;
|
||||
}
|
||||
|
||||
public boolean addViewToTempLocation(View v, Rect rectOccupiedByPotentialDrop,
|
||||
private boolean addViewToTempLocation(View v, Rect rectOccupiedByPotentialDrop,
|
||||
int[] direction, ItemConfiguration currentState) {
|
||||
CellAndSpan c = currentState.map.get(v);
|
||||
boolean success = false;
|
||||
@@ -1828,7 +1830,7 @@ public class CellLayout extends ViewGroup {
|
||||
return success;
|
||||
}
|
||||
|
||||
public boolean pushViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop,
|
||||
private boolean pushViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop,
|
||||
int[] direction, View dragView, ItemConfiguration currentState) {
|
||||
|
||||
ViewCluster cluster = new ViewCluster(this, views, currentState);
|
||||
@@ -1926,7 +1928,7 @@ public class CellLayout extends ViewGroup {
|
||||
// This method tries to find a reordering solution which satisfies the push mechanic by trying
|
||||
// to push items in each of the cardinal directions, in an order based on the direction vector
|
||||
// passed.
|
||||
public boolean attemptPushInDirection(ArrayList<View> intersectingViews, Rect occupied,
|
||||
private boolean attemptPushInDirection(ArrayList<View> intersectingViews, Rect occupied,
|
||||
int[] direction, View ignoreView, ItemConfiguration solution) {
|
||||
if ((Math.abs(direction[0]) + Math.abs(direction[1])) > 1) {
|
||||
// If the direction vector has two non-zero components, we try pushing
|
||||
@@ -2087,7 +2089,7 @@ public class CellLayout extends ViewGroup {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop,
|
||||
private boolean addViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop,
|
||||
int[] direction, View dragView, ItemConfiguration currentState) {
|
||||
if (views.size() == 0) return true;
|
||||
|
||||
@@ -2138,6 +2140,71 @@ public class CellLayout extends ViewGroup {
|
||||
return success;
|
||||
}
|
||||
|
||||
public boolean rearrangementExists(int cellX, int cellY, int spanX, int spanY, int[] direction,
|
||||
View ignoreView, ItemConfiguration solution) {
|
||||
// Return early if get invalid cell positions
|
||||
if (cellX < 0 || cellY < 0) return false;
|
||||
|
||||
mIntersectingViews.clear();
|
||||
mOccupiedRect.set(cellX, cellY, cellX + spanX, cellY + spanY);
|
||||
|
||||
// Mark the desired location of the view currently being dragged.
|
||||
if (ignoreView != null) {
|
||||
CellAndSpan c = solution.map.get(ignoreView);
|
||||
if (c != null) {
|
||||
c.cellX = cellX;
|
||||
c.cellY = cellY;
|
||||
}
|
||||
}
|
||||
Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
|
||||
Rect r1 = new Rect();
|
||||
// The views need to be sorted so that the results are deterministic on the views positions
|
||||
// and not by the views hash which is "random".
|
||||
// The views are sorted twice, once for the X position and a second time for the Y position
|
||||
// to ensure same order everytime.
|
||||
Comparator comparator = Comparator.comparing(view ->
|
||||
((CellLayoutLayoutParams) ((View) view).getLayoutParams()).getCellX())
|
||||
.thenComparing(view ->
|
||||
((CellLayoutLayoutParams) ((View) view).getLayoutParams()).getCellY());
|
||||
List<View> views = solution.map.keySet().stream().sorted(comparator).toList();
|
||||
for (View child : views) {
|
||||
if (child == ignoreView) continue;
|
||||
CellAndSpan c = solution.map.get(child);
|
||||
CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams();
|
||||
r1.set(c.cellX, c.cellY, c.cellX + c.spanX, c.cellY + c.spanY);
|
||||
if (Rect.intersects(r0, r1)) {
|
||||
if (!lp.canReorder) {
|
||||
return false;
|
||||
}
|
||||
mIntersectingViews.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
solution.intersectingViews = new ArrayList<>(mIntersectingViews);
|
||||
|
||||
// First we try to find a solution which respects the push mechanic. That is,
|
||||
// we try to find a solution such that no displaced item travels through another item
|
||||
// without also displacing that item.
|
||||
if (attemptPushInDirection(mIntersectingViews, mOccupiedRect, direction, ignoreView,
|
||||
solution)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Next we try moving the views as a block, but without requiring the push mechanic.
|
||||
if (addViewsToTempLocation(mIntersectingViews, mOccupiedRect, direction, ignoreView,
|
||||
solution)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Ok, they couldn't move as a block, let's move them individually
|
||||
for (View v : mIntersectingViews) {
|
||||
if (!addViewToTempLocation(v, mOccupiedRect, direction, solution)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ReorderAlgorithm createReorderAlgorithm() {
|
||||
return new ReorderAlgorithm(this);
|
||||
}
|
||||
@@ -2149,13 +2216,18 @@ public class CellLayout extends ViewGroup {
|
||||
spanX, spanY, direction, dragView, decX, solution);
|
||||
}
|
||||
|
||||
public void copyCurrentStateToSolution(ItemConfiguration solution) {
|
||||
public void copyCurrentStateToSolution(ItemConfiguration solution, boolean temp) {
|
||||
int childCount = mShortcutsAndWidgets.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
View child = mShortcutsAndWidgets.getChildAt(i);
|
||||
CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams();
|
||||
solution.add(child,
|
||||
new CellAndSpan(lp.getCellX(), lp.getCellY(), lp.cellHSpan, lp.cellVSpan));
|
||||
CellAndSpan c;
|
||||
if (temp) {
|
||||
c = new CellAndSpan(lp.getTmpCellX(), lp.getTmpCellY(), lp.cellHSpan, lp.cellVSpan);
|
||||
} else {
|
||||
c = new CellAndSpan(lp.getCellX(), lp.getCellY(), lp.cellHSpan, lp.cellVSpan);
|
||||
}
|
||||
solution.add(child, c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user