Refactor code to be used in LauncherLily features

Refactor add to workspace code to be used in Lily Launcher.
Also utilising code swap feature to swap out functionality of sorting
items on workspaces and finding next vacant space.

Bug: b/218186705
Test: Manually tested Launcher3 works.
Change-Id: I42a44eabeb307e1d23ef333e0a169437f9062bb6
This commit is contained in:
Shikha Malhotra
2022-04-11 07:57:18 +00:00
parent 80a315e50f
commit e957b600d3
8 changed files with 155 additions and 67 deletions

View File

@@ -23,10 +23,8 @@ import android.graphics.Bitmap;
import android.os.Process;
import android.util.Log;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.model.data.ItemInfo;
@@ -91,42 +89,6 @@ public class ModelUtils {
}
}
/**
* Sorts the set of items by hotseat, workspace (spatially from top to bottom, left to right)
*/
public static void sortWorkspaceItemsSpatially(InvariantDeviceProfile profile,
ArrayList<ItemInfo> workspaceItems) {
final int screenCols = profile.numColumns;
final int screenCellCount = profile.numColumns * profile.numRows;
Collections.sort(workspaceItems, (lhs, rhs) -> {
if (lhs.container == rhs.container) {
// Within containers, order by their spatial position in that container
switch (lhs.container) {
case LauncherSettings.Favorites.CONTAINER_DESKTOP: {
int lr = (lhs.screenId * screenCellCount + lhs.cellY * screenCols
+ lhs.cellX);
int rr = (rhs.screenId * screenCellCount + +rhs.cellY * screenCols
+ rhs.cellX);
return Integer.compare(lr, rr);
}
case LauncherSettings.Favorites.CONTAINER_HOTSEAT: {
// We currently use the screen id as the rank
return Integer.compare(lhs.screenId, rhs.screenId);
}
default:
if (FeatureFlags.IS_STUDIO_BUILD) {
throw new RuntimeException(
"Unexpected container type when sorting workspace items.");
}
return 0;
}
} else {
// Between containers, order by hotseat, desktop
return Integer.compare(lhs.container, rhs.container);
}
});
}
/**
* Iterates though current workspace items and returns available hotseat ranks for prediction.
*/