Snap for 8837442 from 6c057718ac to tm-qpr1-release

Change-Id: Ia888540dbef5216cfbc8399a7295558e906c6ab7
This commit is contained in:
Android Build Coastguard Worker
2022-07-16 03:25:13 +00:00
5 changed files with 94 additions and 36 deletions
@@ -22,6 +22,7 @@ import android.view.InsetsState.ITYPE_BOTTOM_MANDATORY_GESTURES
import android.view.InsetsState
import android.view.WindowManager
import android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD
import android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION
import com.android.launcher3.AbstractFloatingView
import com.android.launcher3.AbstractFloatingView.TYPE_TASKBAR_ALL_APPS
import com.android.launcher3.DeviceProfile
@@ -88,11 +89,17 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
}
}
var imeInsetsSize = Insets.of(0, 0, 0, taskbarHeightForIme)
var insetsSizeOverride = arrayOf(
val imeInsetsSize = Insets.of(0, 0, 0, taskbarHeightForIme)
// Use 0 insets for the VoiceInteractionWindow (assistant) when gesture nav is enabled.
val visInsetsSize = Insets.of(0, 0, 0, if (context.isGestureNav) 0 else tappableHeight)
val insetsSizeOverride = arrayOf(
InsetsFrameProvider.InsetsSizeOverride(
TYPE_INPUT_METHOD,
imeInsetsSize
),
InsetsFrameProvider.InsetsSizeOverride(
TYPE_VOICE_INTERACTION,
visInsetsSize
)
)
for (provider in windowLayoutParams.providedInsets) {
@@ -153,7 +160,8 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
+ " insetsSize=" + provider.insetsSize)
if (provider.insetsSizeOverrides != null) {
pw.print(" insetsSizeOverrides={")
for (overrideSize in provider.insetsSizeOverrides) {
for ((i, overrideSize) in provider.insetsSizeOverrides.withIndex()) {
if (i > 0) pw.print(", ")
pw.print(overrideSize)
}
pw.print("})")
@@ -1629,7 +1629,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
// Cleanup when switching handlers
mInputConsumerProxy.unregisterCallback();
mActivityInitListener.unregister();
ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mActivityRestartListener);
TaskStackChangeListeners.getInstance().unregisterTaskStackListener(
mActivityRestartListener);
mTaskSnapshot = null;
}
+17 -26
View File
@@ -829,8 +829,8 @@ public class CellLayout extends ViewGroup {
final int hStartPadding = getPaddingLeft();
final int vStartPadding = getPaddingTop();
result[0] = (x - hStartPadding) / mCellWidth;
result[1] = (y - vStartPadding) / mCellHeight;
result[0] = (x - hStartPadding) / (mCellWidth + mBorderSpace.x);
result[1] = (y - vStartPadding) / (mCellHeight + mBorderSpace.y);
final int xAxis = mCountX;
final int yAxis = mCountY;
@@ -841,16 +841,6 @@ public class CellLayout extends ViewGroup {
if (result[1] >= yAxis) result[1] = yAxis - 1;
}
/**
* Given a point, return the cell that most closely encloses that point
* @param x X coordinate of the point
* @param y Y coordinate of the point
* @param result Array of 2 ints to hold the x and y coordinate of the cell
*/
void pointToCellRounded(int x, int y, int[] result) {
pointToCellExact(x + (mCellWidth / 2), y + (mCellHeight / 2), result);
}
/**
* Given a cell coordinate, return the point that represents the upper left corner of that cell
*
@@ -1240,7 +1230,7 @@ public class CellLayout extends ViewGroup {
*/
int[] findNearestVacantArea(int pixelX, int pixelY, int minSpanX, int minSpanY, int spanX,
int spanY, int[] result, int[] resultSpan) {
return findNearestArea(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY, true,
return findNearestArea(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY, false,
result, resultSpan);
}
@@ -1262,9 +1252,10 @@ public class CellLayout extends ViewGroup {
/**
* Find a vacant area that will fit the given bounds nearest the requested
* cell location. Uses Euclidean distance to score multiple vacant areas.
*
* @param pixelX The X location at which you want to search for a vacant area.
* @param pixelY The Y location at which you want to search for a vacant area.
* @param relativeXPos The X location relative to the Cell layout at which you want to search
* for a vacant area.
* @param relativeYPos The Y location relative to the Cell layout at which you want to search
* for a vacant area.
* @param minSpanX The minimum horizontal span required
* @param minSpanY The minimum vertical span required
* @param spanX Horizontal span of the object.
@@ -1275,15 +1266,15 @@ public class CellLayout extends ViewGroup {
* @return The X, Y cell of a vacant area that can contain this object,
* nearest the requested location.
*/
private int[] findNearestArea(int pixelX, int pixelY, int minSpanX, int minSpanY, int spanX,
int spanY, boolean ignoreOccupied, int[] result, int[] resultSpan) {
private int[] findNearestArea(int relativeXPos, int relativeYPos, int minSpanX, int minSpanY,
int spanX, int spanY, boolean ignoreOccupied, int[] result, int[] resultSpan) {
lazyInitTempRectStack();
// For items with a spanX / spanY > 1, the passed in point (pixelX, pixelY) corresponds
// to the center of the item, but we are searching based on the top-left cell, so
// we translate the point over to correspond to the top-left.
pixelX -= mCellWidth * (spanX - 1) / 2f;
pixelY -= mCellHeight * (spanY - 1) / 2f;
// For items with a spanX / spanY > 1, the passed in point (relativeXPos, relativeYPos)
// corresponds to the center of the item, but we are searching based on the top-left cell,
// so we translate the point over to correspond to the top-left.
relativeXPos = (int) (relativeXPos - (mCellWidth + mBorderSpace.x) * (spanX - 1) / 2f);
relativeYPos = (int) (relativeYPos - (mCellHeight + mBorderSpace.y) * (spanY - 1) / 2f);
// Keep track of best-scoring drop area
final int[] bestXY = result != null ? result : new int[2];
@@ -1304,7 +1295,7 @@ public class CellLayout extends ViewGroup {
for (int x = 0; x < countX - (minSpanX - 1); x++) {
int ySize = -1;
int xSize = -1;
if (ignoreOccupied) {
if (!ignoreOccupied) {
// First, let's see if this thing fits anywhere
for (int i = 0; i < minSpanX; i++) {
for (int j = 0; j < minSpanY; j++) {
@@ -1368,7 +1359,7 @@ public class CellLayout extends ViewGroup {
}
}
validRegions.push(currentRect);
double distance = Math.hypot(cellXY[0] - pixelX, cellXY[1] - pixelY);
double distance = Math.hypot(cellXY[0] - relativeXPos, cellXY[1] - relativeYPos);
if ((distance <= bestDistance && !contained) ||
currentRect.contains(bestRect)) {
@@ -2629,7 +2620,7 @@ public class CellLayout extends ViewGroup {
* nearest the requested location.
*/
public int[] findNearestArea(int pixelX, int pixelY, int spanX, int spanY, int[] result) {
return findNearestArea(pixelX, pixelY, spanX, spanY, spanX, spanY, false, result, null);
return findNearestArea(pixelX, pixelY, spanX, spanY, spanX, spanY, true, result, null);
}
boolean existsEmptyCell() {
@@ -43,6 +43,8 @@ import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.Size;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
@@ -53,6 +55,8 @@ import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.TextClock;
import androidx.annotation.Nullable;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeviceProfile;
@@ -177,10 +181,12 @@ public class LauncherPreviewRenderer extends ContextWrapper
private final Map<Integer, CellLayout> mWorkspaceScreens = new HashMap<>();
private final AppWidgetHost mAppWidgetHost;
private final SparseIntArray mWallpaperColorResources;
private final SparseArray<Size> mLauncherWidgetSpanInfo;
public LauncherPreviewRenderer(Context context,
InvariantDeviceProfile idp,
WallpaperColors wallpaperColorsOverride) {
WallpaperColors wallpaperColorsOverride,
@Nullable final SparseArray<Size> launcherWidgetSpanInfo) {
super(context);
mUiHandler = new Handler(Looper.getMainLooper());
@@ -224,6 +230,9 @@ public class LauncherPreviewRenderer extends ContextWrapper
mHotseat = mRootView.findViewById(R.id.hotseat);
mHotseat.resetLayout(false);
mLauncherWidgetSpanInfo = launcherWidgetSpanInfo == null ? new SparseArray<>() :
launcherWidgetSpanInfo;
CellLayout firstScreen = mRootView.findViewById(R.id.workspace);
firstScreen.setPadding(mDp.workspacePadding.left + mDp.cellLayoutPaddingPx.left,
mDp.workspacePadding.top + mDp.cellLayoutPaddingPx.top,
@@ -22,10 +22,13 @@ import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import android.app.WallpaperColors;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.database.Cursor;
import android.hardware.display.DisplayManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.util.Size;
import android.util.SparseArray;
import android.view.ContextThemeWrapper;
import android.view.Display;
import android.view.SurfaceControlViewHost;
@@ -34,6 +37,8 @@ import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.view.animation.AccelerateDecelerateInterpolator;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.annotation.WorkerThread;
@@ -123,6 +128,45 @@ public class PreviewSurfaceRenderer {
mOnDestroyCallbacks.executeAllAndDestroy();
}
/**
* A function that queries for the launcher app widget span info
*
* @param context The context to get the content resolver from, should be related to launcher
* @return A SparseArray with the app widget id being the key and the span info being the values
*/
@WorkerThread
@Nullable
public SparseArray<Size> getLoadedLauncherWidgetInfo(
@NonNull final Context context) {
final SparseArray<Size> widgetInfo = new SparseArray<>();
final String query = LauncherSettings.Favorites.ITEM_TYPE + " = "
+ LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
try (Cursor c = context.getContentResolver().query(LauncherSettings.Favorites.CONTENT_URI,
new String[] {
LauncherSettings.Favorites.APPWIDGET_ID,
LauncherSettings.Favorites.SPANX,
LauncherSettings.Favorites.SPANY
}, query, null, null)) {
final int appWidgetIdIndex = c.getColumnIndexOrThrow(
LauncherSettings.Favorites.APPWIDGET_ID);
final int spanXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANX);
final int spanYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANY);
while (c.moveToNext()) {
final int appWidgetId = c.getInt(appWidgetIdIndex);
final int spanX = c.getInt(spanXIndex);
final int spanY = c.getInt(spanYIndex);
widgetInfo.append(appWidgetId, new Size(spanX, spanY));
}
} catch (Exception e) {
Log.e(TAG, "Error querying for launcher widget info", e);
return null;
}
return widgetInfo;
}
/**
* Generates the preview in background
*/
@@ -174,8 +218,11 @@ public class PreviewSurfaceRenderer {
loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI,
query);
final SparseArray<Size> spanInfo =
getLoadedLauncherWidgetInfo(previewContext.getBaseContext());
MAIN_EXECUTOR.execute(() -> {
renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
renderView(previewContext, mBgDataModel, mWidgetProvidersMap, spanInfo);
mOnDestroyCallbacks.add(previewContext::onDestroy);
});
}
@@ -183,7 +230,8 @@ public class PreviewSurfaceRenderer {
} else {
LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
if (dataModel != null) {
MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null,
null));
} else {
Log.e(TAG, "Model loading failed");
}
@@ -201,12 +249,13 @@ public class PreviewSurfaceRenderer {
@UiThread
private void renderView(Context inflationContext, BgDataModel dataModel,
Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap,
@Nullable final SparseArray<Size> launcherWidgetSpanInfo) {
if (mDestroyed) {
return;
}
View view = new LauncherPreviewRenderer(inflationContext, mIdp, mWallpaperColors)
.getRenderedView(dataModel, widgetProviderInfoMap);
View view = new LauncherPreviewRenderer(inflationContext, mIdp, mWallpaperColors,
launcherWidgetSpanInfo).getRenderedView(dataModel, widgetProviderInfoMap);
// This aspect scales the view to fit in the surface and centers it
final float scale = Math.min(mWidth / (float) view.getMeasuredWidth(),
mHeight / (float) view.getMeasuredHeight());