Merge "Refactor code to be used in LauncherLily features" into tm-dev am: 2e255ed0ac

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/17658880

Change-Id: I3debe6375896411b8009310fccb4d7bcebcf24ec
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Shikha Malhotra
2022-04-21 09:07:58 +00:00
committed by Automerger Merge Worker
8 changed files with 155 additions and 67 deletions

View File

@@ -228,7 +228,7 @@ filegroup {
],
}
// Common source files used to build go launcher
// Common source files used to build go launcher except go/src files
filegroup {
name: "launcher-go-src-no-build-config",
srcs: [
@@ -236,8 +236,6 @@ filegroup {
"src/**/*.kt",
"quickstep/src/**/*.java",
"quickstep/src/**/*.kt",
"go/src/**/*.java",
"go/src/**/*.kt",
"go/quickstep/src/**/*.java",
"go/quickstep/src/**/*.kt",
],

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.util;
/**
* Defines method to find the next vacant cell on a grid.
* This uses the default top-down, left-right approach and can be over-written through
* code swaps in different launchers.
*/
public abstract class AbsGridOccupancy {
/**
* Find the first vacant cell, if there is one.
*
* @param vacantOut Holds the x and y coordinate of the vacant cell
* @param spanX Horizontal cell span.
* @param spanY Vertical cell span.
*
* @return true if a vacant cell was found
*/
protected boolean findVacantCell(int[] vacantOut, boolean[][] cells, int countX, int countY,
int spanX, int spanY) {
for (int y = 0; (y + spanY) <= countY; y++) {
for (int x = 0; (x + spanX) <= countX; x++) {
boolean available = !cells[x][y];
out:
for (int i = x; i < x + spanX; i++) {
for (int j = y; j < y + spanY; j++) {
available = available && !cells[i][j];
if (!available) break out;
}
}
if (available) {
vacantOut[0] = x;
vacantOut[1] = y;
return true;
}
}
}
return false;
}
}

View File

@@ -3235,12 +3235,12 @@ public class Launcher extends StatefulActivity<LauncherState>
/** Pauses view updates that should not be run during the app launch animation. */
public void pauseExpensiveViewUpdates() {
// Pause page indicator animations as they lead to layer trashing.
mWorkspace.getPageIndicator().pauseAnimations();
getWorkspace().getPageIndicator().pauseAnimations();
}
/** Resumes view updates at the end of the app launch animation. */
public void resumeExpensiveViewUpdates() {
mWorkspace.getPageIndicator().skipAnimationsToEnd();
getWorkspace().getPageIndicator().skipAnimationsToEnd();
}
}

View File

@@ -23,7 +23,6 @@ import static android.view.View.VISIBLE;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
import static com.android.launcher3.model.ModelUtils.filterCurrentWorkspaceItems;
import static com.android.launcher3.model.ModelUtils.getMissingHotseatRanks;
import static com.android.launcher3.model.ModelUtils.sortWorkspaceItemsSpatially;
import android.annotation.TargetApi;
import android.app.Fragment;
@@ -420,8 +419,6 @@ public class LauncherPreviewRenderer extends ContextWrapper
currentWorkspaceItems, otherWorkspaceItems);
filterCurrentWorkspaceItems(currentScreenIds, dataModel.appWidgets, currentAppWidgets,
otherAppWidgets);
sortWorkspaceItemsSpatially(mIdp, currentWorkspaceItems);
for (ItemInfo itemInfo : currentWorkspaceItems) {
switch (itemInfo.itemType) {
case Favorites.ITEM_TYPE_APPLICATION:

View File

@@ -18,7 +18,6 @@ package com.android.launcher3.model;
import static com.android.launcher3.model.ItemInstallQueue.FLAG_LOADER_RUNNING;
import static com.android.launcher3.model.ModelUtils.filterCurrentWorkspaceItems;
import static com.android.launcher3.model.ModelUtils.sortWorkspaceItemsSpatially;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import android.os.Process;
@@ -27,6 +26,8 @@ import android.util.Log;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel.CallbackTask;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
import com.android.launcher3.model.data.AppInfo;
@@ -110,6 +111,42 @@ public abstract class BaseLoaderResults {
public abstract void bindWidgets();
/**
* Sorts the set of items by hotseat, workspace (spatially from top to bottom, left to right)
*/
protected 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);
}
});
}
protected void executeCallbacksTask(CallbackTask task, Executor executor) {
executor.execute(() -> {
if (mMyBindingId != mBgDataModel.lastBindId) {
@@ -131,7 +168,7 @@ public abstract class BaseLoaderResults {
return idleLock;
}
private static class WorkspaceBinder {
private class WorkspaceBinder {
private final Executor mUiExecutor;
private final Callbacks mCallbacks;

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.
*/

View File

@@ -7,7 +7,7 @@ import com.android.launcher3.model.data.ItemInfo;
/**
* Utility object to manage the occupancy in a grid.
*/
public class GridOccupancy {
public class GridOccupancy extends AbsGridOccupancy {
private final int mCountX;
private final int mCountY;
@@ -30,24 +30,7 @@ public class GridOccupancy {
* @return true if a vacant cell was found
*/
public boolean findVacantCell(int[] vacantOut, int spanX, int spanY) {
for (int y = 0; (y + spanY) <= mCountY; y++) {
for (int x = 0; (x + spanX) <= mCountX; x++) {
boolean available = !cells[x][y];
out:
for (int i = x; i < x + spanX; i++) {
for (int j = y; j < y + spanY; j++) {
available = available && !cells[i][j];
if (!available) break out;
}
}
if (available) {
vacantOut[0] = x;
vacantOut[1] = y;
return true;
}
}
}
return false;
return super.findVacantCell(vacantOut, cells, mCountX, mCountY, spanX, spanY);
}
public void copyTo(GridOccupancy dest) {

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.util;
/**
* Defines method to find the next vacant cell on a grid.
* This uses the default top-down, left-right approach and can be over-written through
* code swaps in different launchers.
*/
public abstract class AbsGridOccupancy {
/**
* Find the first vacant cell, if there is one.
*
* @param vacantOut Holds the x and y coordinate of the vacant cell
* @param spanX Horizontal cell span.
* @param spanY Vertical cell span.
*
* @return true if a vacant cell was found
*/
protected boolean findVacantCell(int[] vacantOut, boolean[][] cells, int countX, int countY,
int spanX, int spanY) {
for (int y = 0; (y + spanY) <= countY; y++) {
for (int x = 0; (x + spanX) <= countX; x++) {
boolean available = !cells[x][y];
out:
for (int i = x; i < x + spanX; i++) {
for (int j = y; j < y + spanY; j++) {
available = available && !cells[i][j];
if (!available) break out;
}
}
if (available) {
vacantOut[0] = x;
vacantOut[1] = y;
return true;
}
}
}
return false;
}
}