Rect r = estimateItemPosition(layout, targetCell[0], targetCell[1], spanX, spanY);
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) {
DeviceProfile profile = mLauncher.getDeviceProfile();
- if (profile.shouldInsetWidgets() && finalView instanceof NavigableAppWidgetHostView) {
- Rect widgetPadding = new Rect();
- ((NavigableAppWidgetHostView) finalView).getWidgetInset(profile, widgetPadding);
+ if (finalView instanceof NavigableAppWidgetHostView) {
+ Rect widgetPadding = profile.widgetPadding;
r.left -= widgetPadding.left;
r.right += widgetPadding.right;
r.top -= widgetPadding.top;
diff --git a/src/com/android/launcher3/celllayout/CellLayoutLayoutParams.java b/src/com/android/launcher3/celllayout/CellLayoutLayoutParams.java
index 4b6a062046..bdf764376d 100644
--- a/src/com/android/launcher3/celllayout/CellLayoutLayoutParams.java
+++ b/src/com/android/launcher3/celllayout/CellLayoutLayoutParams.java
@@ -113,13 +113,13 @@ public class CellLayoutLayoutParams extends ViewGroup.MarginLayoutParams {
* full/invariant device profile sizes.
*/
public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount,
- int rowCount, Point borderSpace, @Nullable Rect inset) {
+ int rowCount, Point borderSpace) {
setup(cellWidth, cellHeight, invertHorizontally, colCount, rowCount, 1.0f, 1.0f,
- borderSpace, inset);
+ borderSpace, null);
}
/**
- * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, Point, Rect)},
+ * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, Point)},
* if the view needs to be scaled.
*
* ie. In multi-window mode, we setup widgets so that they are measured and laid out
@@ -150,10 +150,10 @@ public class CellLayoutLayoutParams extends ViewGroup.MarginLayoutParams {
y = topMargin + (myCellY * cellHeight) + (myCellY * borderSpace.y);
if (inset != null) {
- x -= inset.left;
- y -= inset.top;
- width += inset.left + inset.right;
- height += inset.top + inset.bottom;
+ x += inset.left;
+ y += inset.top;
+ width -= inset.left + inset.right;
+ height -= inset.top + inset.bottom;
}
}
}
diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
index 7f49aa9cc1..b438e86bf8 100644
--- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
+++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
@@ -451,26 +451,8 @@ public class LauncherPreviewRenderer extends ContextWrapper
final Size origSize = WidgetSizes.getWidgetSizePx(mDpOrig,
launcherWidgetSize.getWidth(), launcherWidgetSize.getHeight());
final Size newSize = WidgetSizes.getWidgetSizePx(mDp, info.spanX, info.spanY);
- final Rect previewInset = new Rect();
- final Rect origInset = new Rect();
- // When the setup() is called for the LayoutParams, insets are added to the width
- // and height of the view. This is not accounted for in WidgetSizes and is handled
- // here.
- if (mDp.shouldInsetWidgets()) {
- previewInset.set(mDp.inv.defaultWidgetPadding);
- } else {
- previewInset.setEmpty();
- }
- if (mDpOrig.shouldInsetWidgets()) {
- origInset.set(mDpOrig.inv.defaultWidgetPadding);
- } else {
- origInset.setEmpty();
- }
-
- return new PointF((float) newSize.getWidth() / (origSize.getWidth()
- + origInset.left + origInset.right),
- (float) newSize.getHeight() / (origSize.getHeight()
- + origInset.top + origInset.bottom));
+ return new PointF((float) newSize.getWidth() / origSize.getWidth(),
+ (float) newSize.getHeight() / origSize.getHeight());
}
private void inflateAndAddPredictedIcon(WorkspaceItemInfo info) {
diff --git a/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java b/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java
index 7030f6dede..6f74fd965a 100644
--- a/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java
+++ b/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java
@@ -146,8 +146,7 @@ public class DatabaseWidgetPreviewLoader {
previewWidth = drawable.getIntrinsicWidth();
previewHeight = drawable.getIntrinsicHeight();
} else {
- Size widgetSize = WidgetSizes.getWidgetPaddedSizePx(mContext, info.provider, dp, spanX,
- spanY);
+ Size widgetSize = WidgetSizes.getWidgetSizePx(dp, spanX, spanY);
previewWidth = widgetSize.getWidth();
previewHeight = widgetSize.getHeight();
}
diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java
index bba1016f34..10aef9ac66 100644
--- a/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java
+++ b/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java
@@ -2,7 +2,6 @@ package com.android.launcher3.widget;
import static com.android.launcher3.Utilities.ATLEAST_S;
-import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Context;
@@ -105,44 +104,35 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo
int spanX = 0;
int spanY = 0;
- Rect widgetPadding = new Rect();
- Rect localPadding = new Rect();
- AppWidgetHostView.getDefaultPaddingForWidget(context, provider, widgetPadding);
Point cellSize = new Point();
for (DeviceProfile dp : idp.supportedProfiles) {
dp.getCellSize(cellSize);
- // We want to account for the extra amount of padding that we are adding to the widget
- // to ensure that it gets the full amount of space that it has requested.
- // If grids supports insetting widgets, we do not account for widget padding.
- if (dp.shouldInsetWidgets()) {
- localPadding.setEmpty();
- } else {
- localPadding.set(widgetPadding);
- }
+ Rect widgetPadding = dp.widgetPadding;
+
minSpanX = Math.max(minSpanX,
- getSpanX(localPadding, minResizeWidth, dp.cellLayoutBorderSpacePx.x,
+ getSpanX(widgetPadding, minResizeWidth, dp.cellLayoutBorderSpacePx.x,
cellSize.x));
minSpanY = Math.max(minSpanY,
- getSpanY(localPadding, minResizeHeight, dp.cellLayoutBorderSpacePx.y,
+ getSpanY(widgetPadding, minResizeHeight, dp.cellLayoutBorderSpacePx.y,
cellSize.y));
if (ATLEAST_S) {
if (maxResizeWidth > 0) {
- maxSpanX = Math.min(maxSpanX, getSpanX(localPadding, maxResizeWidth,
+ maxSpanX = Math.min(maxSpanX, getSpanX(widgetPadding, maxResizeWidth,
dp.cellLayoutBorderSpacePx.x, cellSize.x));
}
if (maxResizeHeight > 0) {
- maxSpanY = Math.min(maxSpanY, getSpanY(localPadding, maxResizeHeight,
+ maxSpanY = Math.min(maxSpanY, getSpanY(widgetPadding, maxResizeHeight,
dp.cellLayoutBorderSpacePx.y, cellSize.y));
}
}
spanX = Math.max(spanX,
- getSpanX(localPadding, minWidth, dp.cellLayoutBorderSpacePx.x,
+ getSpanX(widgetPadding, minWidth, dp.cellLayoutBorderSpacePx.x,
cellSize.x));
spanY = Math.max(spanY,
- getSpanY(localPadding, minHeight, dp.cellLayoutBorderSpacePx.y,
+ getSpanY(widgetPadding, minHeight, dp.cellLayoutBorderSpacePx.y,
cellSize.y));
}
@@ -184,15 +174,22 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo
}
private int getSpanX(Rect widgetPadding, int widgetWidth, int cellSpacing, float cellWidth) {
- return Math.max(1, (int) Math.ceil(
- (widgetWidth + widgetPadding.left + widgetPadding.right + cellSpacing) / (cellWidth
- + cellSpacing)));
+ return getSpan(widgetPadding.left + widgetPadding.right,
+ widgetWidth, cellSpacing, cellWidth);
}
private int getSpanY(Rect widgetPadding, int widgetHeight, int cellSpacing, float cellHeight) {
+ return getSpan(widgetPadding.top + widgetPadding.bottom, widgetHeight,
+ cellSpacing, cellHeight);
+ }
+
+ /**
+ * Solving the equation:
+ * n * cellSize + (n - 1) * cellSpacing - widgetPadding = widgetSize
+ */
+ private int getSpan(int widgetPadding, int widgetSize, int cellSpacing, float cellSize) {
return Math.max(1, (int) Math.ceil(
- (widgetHeight + widgetPadding.top + widgetPadding.bottom + cellSpacing) / (
- cellHeight + cellSpacing)));
+ (widgetSize + widgetPadding + cellSpacing) / (cellSize + cellSpacing)));
}
public String getLabel(PackageManager packageManager) {
diff --git a/src/com/android/launcher3/widget/NavigableAppWidgetHostView.java b/src/com/android/launcher3/widget/NavigableAppWidgetHostView.java
index 3389fb121f..f46b2146a8 100644
--- a/src/com/android/launcher3/widget/NavigableAppWidgetHostView.java
+++ b/src/com/android/launcher3/widget/NavigableAppWidgetHostView.java
@@ -25,7 +25,6 @@ import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;
-import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Reorderable;
import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.util.MultiTranslateDelegate;
@@ -48,13 +47,13 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView
private float mScaleForReorderBounce = 1f;
- private final Rect mTempRect = new Rect();
-
@ViewDebug.ExportedProperty(category = "launcher")
private boolean mChildrenFocused;
protected final ActivityContext mActivity;
+ private boolean mDisableSetPadding = false;
+
public NavigableAppWidgetHostView(Context context) {
super(context);
mActivity = ActivityContext.lookupContext(context);
@@ -146,6 +145,22 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView
dispatchChildFocus(false);
}
+ @Override
+ public void setAppWidget(int appWidgetId, AppWidgetProviderInfo info) {
+ // Prevent default padding being set on the view based on provider info. Launcher manages
+ // its own widget spacing
+ mDisableSetPadding = true;
+ super.setAppWidget(appWidgetId, info);
+ mDisableSetPadding = false;
+ }
+
+ @Override
+ public void setPadding(int left, int top, int right, int bottom) {
+ if (!mDisableSetPadding) {
+ super.setPadding(left, top, right, bottom);
+ }
+ }
+
@Override
public boolean dispatchUnhandledMove(View focused, int direction) {
return mChildrenFocused;
@@ -195,26 +210,6 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView
public void getWorkspaceVisualDragBounds(Rect bounds) {
int width = (int) (getMeasuredWidth() * mScaleToFit);
int height = (int) (getMeasuredHeight() * mScaleToFit);
-
- getWidgetInset(mActivity.getDeviceProfile(), mTempRect);
- bounds.set(mTempRect.left, mTempRect.top, width - mTempRect.right,
- height - mTempRect.bottom);
- }
-
- /**
- * Widgets have padding added by the system. We may choose to inset this padding if the grid
- * supports it.
- */
- public void getWidgetInset(DeviceProfile grid, Rect out) {
- if (!grid.shouldInsetWidgets()) {
- out.setEmpty();
- return;
- }
- AppWidgetProviderInfo info = getAppWidgetInfo();
- if (info == null) {
- out.set(grid.inv.defaultWidgetPadding);
- } else {
- AppWidgetHostView.getDefaultPaddingForWidget(getContext(), info.provider, out);
- }
+ bounds.set(0, 0, width, height);
}
}
diff --git a/src/com/android/launcher3/widget/PendingItemDragHelper.java b/src/com/android/launcher3/widget/PendingItemDragHelper.java
index 410a555896..67d21f7608 100644
--- a/src/com/android/launcher3/widget/PendingItemDragHelper.java
+++ b/src/com/android/launcher3/widget/PendingItemDragHelper.java
@@ -16,6 +16,8 @@
package com.android.launcher3.widget;
+import static com.android.launcher3.widget.util.WidgetSizes.getWidgetSizePx;
+
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
@@ -43,7 +45,6 @@ import com.android.launcher3.icons.FastBitmapDrawable;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.icons.RoundDrawableWrapper;
import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;
-import com.android.launcher3.widget.util.WidgetSizes;
/**
* Extension of {@link DragPreviewProvider} with logic specific to pending widgets/shortcuts
@@ -121,13 +122,8 @@ public class PendingItemDragHelper extends DragPreviewProvider {
mAppWidgetHostViewPreview.setAppWidget(/* appWidgetId= */ -1,
((PendingAddWidgetInfo) mAddInfo).info);
DeviceProfile deviceProfile = launcher.getDeviceProfile();
- Rect padding = new Rect();
- mAppWidgetHostViewPreview.getWidgetInset(deviceProfile, padding);
- mAppWidgetHostViewPreview.setPadding(padding.left, padding.top, padding.right,
- padding.bottom);
mAppWidgetHostViewPreview.updateAppWidget(/* remoteViews= */ mRemoteViewsPreview);
- Size widgetSizes = WidgetSizes.getWidgetPaddedSizePx(launcher,
- mAddInfo.componentName, deviceProfile, mAddInfo.spanX, mAddInfo.spanY);
+ Size widgetSizes = getWidgetSizePx(deviceProfile, mAddInfo.spanX, mAddInfo.spanY);
mAppWidgetHostViewPreview.measure(
MeasureSpec.makeMeasureSpec(widgetSizes.getWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(widgetSizes.getHeight(), MeasureSpec.EXACTLY));
diff --git a/src/com/android/launcher3/widget/util/WidgetSizes.java b/src/com/android/launcher3/widget/util/WidgetSizes.java
index 601c1b543e..7049509bd2 100644
--- a/src/com/android/launcher3/widget/util/WidgetSizes.java
+++ b/src/com/android/launcher3/widget/util/WidgetSizes.java
@@ -15,8 +15,6 @@
*/
package com.android.launcher3.widget.util;
-import static android.appwidget.AppWidgetHostView.getDefaultPaddingForWidget;
-
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
@@ -28,8 +26,6 @@ import android.util.Log;
import android.util.Size;
import android.util.SizeF;
-import androidx.annotation.Nullable;
-
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
@@ -43,24 +39,13 @@ public final class WidgetSizes {
/**
* Returns the list of all possible sizes, in dp, for a widget of given spans on this device.
- *
- * The returned sizes already take into account the system padding, and whether it is applied
- * or not in that specific configuration.
*/
- public static ArrayList getWidgetPaddedSizes(Context context, ComponentName provider,
- int spanX, int spanY) {
- Rect padding = getDefaultPaddingForWidget(context, provider, /* padding= */ null);
-
+ public static ArrayList getWidgetSizesDp(Context context, int spanX, int spanY) {
ArrayList sizes = new ArrayList<>(2);
final float density = context.getResources().getDisplayMetrics().density;
- final Point cellSize = new Point();
for (DeviceProfile profile : LauncherAppState.getIDP(context).supportedProfiles) {
- Size widgetSizePx = getWidgetSizePx(profile, spanX, spanY, cellSize);
- if (!profile.shouldInsetWidgets()) {
- widgetSizePx = new Size(widgetSizePx.getWidth() - padding.left - padding.right,
- widgetSizePx.getHeight() - padding.top - padding.bottom);
- }
+ Size widgetSizePx = getWidgetSizePx(profile, spanX, spanY);
sizes.add(new SizeF(widgetSizePx.getWidth() / density,
widgetSizePx.getHeight() / density));
}
@@ -69,21 +54,15 @@ public final class WidgetSizes {
/** Returns the size, in pixels, a widget of given spans & {@code profile}. */
public static Size getWidgetSizePx(DeviceProfile profile, int spanX, int spanY) {
- return getWidgetSizePx(profile, spanX, spanY, /* recycledCellSize= */ null);
- }
+ final int hBorderSpacing = (spanX - 1) * profile.cellLayoutBorderSpacePx.x;
+ final int vBorderSpacing = (spanY - 1) * profile.cellLayoutBorderSpacePx.y;
- /**
- * Returns the size, in pixels and removing padding, a widget of given spans & {@code profile}.
- */
- public static Size getWidgetPaddedSizePx(Context context, ComponentName component,
- DeviceProfile profile, int spanX, int spanY) {
- Size size = getWidgetSizePx(profile, spanX, spanY);
- if (profile.shouldInsetWidgets()) {
- return size;
- }
- Rect padding = getDefaultPaddingForWidget(context, component, /* padding= */ null);
- return new Size(size.getWidth() - padding.left - padding.right,
- size.getHeight() - padding.top - padding.bottom);
+ Point cellSize = profile.getCellSize();
+ Rect padding = profile.widgetPadding;
+
+ return new Size(
+ (spanX * cellSize.x) + hBorderSpacing - padding.left - padding.right,
+ (spanY * cellSize.y) + vBorderSpacing - padding.top - padding.bottom);
}
/**
@@ -92,8 +71,7 @@ public final class WidgetSizes {
* This size is used by the widget picker. It should NEVER be shared with app widgets.
*
*
For sizes shared with app widgets, please refer to
- * {@link #getWidgetPaddedSizes(Context, ComponentName, int, int)} &
- * {@link #getWidgetPaddedSizePx(Context, ComponentName, DeviceProfile, int, int)}.
+ * {@link #getWidgetSizesDp(Context, int, int)} &
*/
public static Size getWidgetItemSizePx(Context context, DeviceProfile profile,
WidgetItem widgetItem) {
@@ -102,27 +80,7 @@ public final class WidgetSizes {
.getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
return new Size(dimension, dimension);
}
- Size widgetItemSize = getWidgetSizePx(profile, widgetItem.spanX,
- widgetItem.spanY, /* recycledCellSize= */ null);
- if (profile.shouldInsetWidgets()) {
- Rect inset = new Rect();
- AppWidgetHostView.getDefaultPaddingForWidget(context, widgetItem.componentName, inset);
- return new Size(widgetItemSize.getWidth() + inset.left + inset.right,
- widgetItemSize.getHeight() + inset.top + inset.bottom);
- }
- return widgetItemSize;
- }
-
- private static Size getWidgetSizePx(DeviceProfile profile, int spanX, int spanY,
- @Nullable Point recycledCellSize) {
- final int hBorderSpacing = (spanX - 1) * profile.cellLayoutBorderSpacePx.x;
- final int vBorderSpacing = (spanY - 1) * profile.cellLayoutBorderSpacePx.y;
- if (recycledCellSize == null) {
- recycledCellSize = new Point();
- }
- profile.getCellSize(recycledCellSize);
- return new Size(((spanX * recycledCellSize.x) + hBorderSpacing),
- ((spanY * recycledCellSize.y) + vBorderSpacing));
+ return getWidgetSizePx(profile, widgetItem.spanX, widgetItem.spanY);
}
/**
@@ -154,7 +112,7 @@ public final class WidgetSizes {
*/
public static Bundle getWidgetSizeOptions(Context context, ComponentName provider, int spanX,
int spanY) {
- ArrayList paddedSizes = getWidgetPaddedSizes(context, provider, spanX, spanY);
+ ArrayList paddedSizes = getWidgetSizesDp(context, spanX, spanY);
Rect rect = getMinMaxSizes(paddedSizes);
Bundle options = new Bundle();
diff --git a/tests/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfoTest.java b/tests/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfoTest.java
index b534a41175..48cf3df0e5 100644
--- a/tests/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfoTest.java
+++ b/tests/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfoTest.java
@@ -32,6 +32,7 @@ import androidx.test.filters.SmallTest;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
+import com.android.launcher3.LauncherAppState;
import org.junit.Before;
import org.junit.Test;
@@ -161,7 +162,6 @@ public final class LauncherAppWidgetProviderInfoTest {
int maxPadding = Math.max(Math.max(padding.left, padding.right),
Math.max(padding.top, padding.bottom));
dp.cellLayoutBorderSpacePx.x = dp.cellLayoutBorderSpacePx.y = maxPadding + 1;
- Mockito.when(dp.shouldInsetWidgets()).thenReturn(true);
LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
info.minWidth = CELL_SIZE * 3;
@@ -184,7 +184,6 @@ public final class LauncherAppWidgetProviderInfoTest {
int maxPadding = Math.max(Math.max(padding.left, padding.right),
Math.max(padding.top, padding.bottom));
dp.cellLayoutBorderSpacePx.x = dp.cellLayoutBorderSpacePx.y = maxPadding - 1;
- Mockito.when(dp.shouldInsetWidgets()).thenReturn(false);
LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
info.minWidth = CELL_SIZE * 3;
info.minHeight = CELL_SIZE * 3;
@@ -257,14 +256,16 @@ public final class LauncherAppWidgetProviderInfoTest {
}
private InvariantDeviceProfile createIDP() {
- DeviceProfile profile = Mockito.mock(DeviceProfile.class);
+ DeviceProfile dp = LauncherAppState.getIDP(mContext)
+ .getDeviceProfile(mContext).copy(mContext);
+ DeviceProfile profile = Mockito.spy(dp);
doAnswer(i -> {
((Point) i.getArgument(0)).set(CELL_SIZE, CELL_SIZE);
return null;
}).when(profile).getCellSize(any(Point.class));
Mockito.when(profile.getCellSize()).thenReturn(new Point(CELL_SIZE, CELL_SIZE));
profile.cellLayoutBorderSpacePx = new Point(SPACE_SIZE, SPACE_SIZE);
- Mockito.when(profile.shouldInsetWidgets()).thenReturn(true);
+ profile.widgetPadding.setEmpty();
InvariantDeviceProfile idp = new InvariantDeviceProfile();
List supportedProfiles = new ArrayList<>(idp.supportedProfiles);
diff --git a/tests/src/com/android/launcher3/widget/picker/util/WidgetsTableUtilsTest.java b/tests/src/com/android/launcher3/widget/picker/util/WidgetsTableUtilsTest.java
index d2c2fd7217..834f8517a2 100644
--- a/tests/src/com/android/launcher3/widget/picker/util/WidgetsTableUtilsTest.java
+++ b/tests/src/com/android/launcher3/widget/picker/util/WidgetsTableUtilsTest.java
@@ -38,6 +38,7 @@ import androidx.test.filters.SmallTest;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
+import com.android.launcher3.LauncherAppState;
import com.android.launcher3.icons.ComponentWithLabel;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.model.WidgetItem;
@@ -50,6 +51,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
@@ -68,7 +70,6 @@ public final class WidgetsTableUtilsTest {
@Mock
private IconCache mIconCache;
- @Mock
private DeviceProfile mTestDeviceProfile;
private Context mContext;
@@ -198,13 +199,18 @@ public final class WidgetsTableUtilsTest {
}
private void initDP() {
+ DeviceProfile dp = LauncherAppState.getIDP(mContext)
+ .getDeviceProfile(mContext).copy(mContext);
+ mTestDeviceProfile = Mockito.spy(dp);
+
doAnswer(i -> {
((Point) i.getArgument(0)).set(CELL_SIZE, CELL_SIZE);
return null;
}).when(mTestDeviceProfile).getCellSize(any(Point.class));
when(mTestDeviceProfile.getCellSize()).thenReturn(new Point(CELL_SIZE, CELL_SIZE));
mTestDeviceProfile.cellLayoutBorderSpacePx = new Point(SPACE_SIZE, SPACE_SIZE);
- when(mTestDeviceProfile.shouldInsetWidgets()).thenReturn(false);
+ mTestDeviceProfile.widgetPadding.setEmpty();
+ mTestDeviceProfile.allAppsIconSizePx = 0;
}
private void initTestWidgets() {