Use the computation of the widget size including padding.
Found all the uses of getWidgetSizePx and replaced them with the computation of padded sizes (checked it all made sense). Test: Try the various widget pickers. Bug: 191612352 Change-Id: Id2a8d12ee7ce6baabef186dbb78d817975ea2212
This commit is contained in:
parent
199aec50ad
commit
a7b3a14e75
|
@ -417,7 +417,8 @@ public class DatabaseWidgetPreviewLoader implements WidgetPreviewLoader {
|
|||
previewHeight = drawable.getIntrinsicHeight();
|
||||
} else {
|
||||
DeviceProfile dp = launcher.getDeviceProfile();
|
||||
Size widgetSize = WidgetSizes.getWidgetSizePx(dp, spanX, spanY);
|
||||
Size widgetSize = WidgetSizes.getWidgetPaddedSizePx(mContext, info.provider, dp, spanX,
|
||||
spanY);
|
||||
previewWidth = widgetSize.getWidth();
|
||||
previewHeight = widgetSize.getHeight();
|
||||
}
|
||||
|
|
|
@ -363,7 +363,9 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
|
|||
/** Sets the widget preview image size, in number of cells, and preview scale. */
|
||||
public Size setPreviewSize(int spanX, int spanY, float previewScale) {
|
||||
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
|
||||
Size widgetSize = WidgetSizes.getWidgetSizePx(deviceProfile, spanX, spanY);
|
||||
Size widgetSize =
|
||||
mItem != null ? WidgetSizes.getWidgetItemSizePx(getContext(), deviceProfile, mItem)
|
||||
: WidgetSizes.getWidgetSizePx(deviceProfile, spanX, spanY);
|
||||
mPreviewWidth = widgetSize.getWidth();
|
||||
mPreviewHeight = widgetSize.getHeight();
|
||||
mPreviewScale = previewScale;
|
||||
|
|
|
@ -296,11 +296,8 @@ public class WidgetsListAdapter extends Adapter<ViewHolder> implements OnHeaderC
|
|||
for (int i = 0; i < entry.mWidgets.size(); i++) {
|
||||
WidgetItem widgetItem = entry.mWidgets.get(i);
|
||||
DeviceProfile deviceProfile = activity.getDeviceProfile();
|
||||
Size widgetSize =
|
||||
WidgetSizes.getWidgetSizePx(
|
||||
deviceProfile,
|
||||
widgetItem.spanX,
|
||||
widgetItem.spanY);
|
||||
Size widgetSize = WidgetSizes.getWidgetItemSizePx(mContext, deviceProfile,
|
||||
widgetItem);
|
||||
if (widgetItem.isShortcut()) {
|
||||
widgetSize =
|
||||
new Size(
|
||||
|
|
|
@ -155,8 +155,8 @@ public final class WidgetsRecommendationTableLayout extends TableLayout {
|
|||
float rowHeight = 0;
|
||||
for (int j = 0; j < widgetItems.size(); j++) {
|
||||
WidgetItem widgetItem = widgetItems.get(j);
|
||||
Size widgetSize = WidgetSizes.getWidgetSizePx(
|
||||
deviceProfile, widgetItem.spanX, widgetItem.spanY);
|
||||
Size widgetSize = WidgetSizes.getWidgetItemSizePx(getContext(), deviceProfile,
|
||||
widgetItem);
|
||||
float previewHeight = widgetSize.getHeight() * previewScale;
|
||||
rowHeight = Math.max(rowHeight,
|
||||
previewHeight + mWidgetCellTextViewsHeight + mWidgetCellVerticalPadding);
|
||||
|
|
|
@ -32,6 +32,7 @@ import androidx.annotation.Nullable;
|
|||
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -70,6 +71,32 @@ public final class WidgetSizes {
|
|||
return getWidgetSizePx(profile, spanX, spanY, /* recycledCellSize= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of a WidgetItem.
|
||||
*/
|
||||
public static Size getWidgetItemSizePx(Context context, DeviceProfile profile,
|
||||
WidgetItem widgetItem) {
|
||||
if (widgetItem.isShortcut()) {
|
||||
return getWidgetSizePx(profile, widgetItem.spanX, widgetItem.spanY);
|
||||
}
|
||||
return getWidgetPaddedSizePx(context, widgetItem.componentName, profile, widgetItem.spanX,
|
||||
widgetItem.spanY);
|
||||
}
|
||||
|
||||
private static Size getWidgetSizePx(DeviceProfile profile, int spanX, int spanY,
|
||||
@Nullable Point recycledCellSize) {
|
||||
final int hBorderSpacing = (spanX - 1) * profile.cellLayoutBorderSpacingPx;
|
||||
|
|
Loading…
Reference in New Issue