From f7d458543e64307b01de803d2ddfee2f21b0bd28 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 10 Oct 2013 18:57:15 -0700 Subject: [PATCH] Altering the workspace padding to account for default widget padding (Bug 11116452) --- src/com/android/launcher3/DynamicGrid.java | 23 ++++++++++++++----- .../android/launcher3/LauncherAppState.java | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/com/android/launcher3/DynamicGrid.java b/src/com/android/launcher3/DynamicGrid.java index 065d7a759d..4776c86682 100644 --- a/src/com/android/launcher3/DynamicGrid.java +++ b/src/com/android/launcher3/DynamicGrid.java @@ -16,11 +16,14 @@ package com.android.launcher3; +import android.appwidget.AppWidgetHostView; +import android.content.ComponentName; +import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Paint; -import android.graphics.PointF; import android.graphics.Paint.FontMetrics; +import android.graphics.PointF; import android.graphics.Rect; import android.util.DisplayMetrics; import android.util.TypedValue; @@ -64,7 +67,9 @@ class DeviceProfile { boolean isLargeTablet; boolean transposeLayoutWithOrientation; + int desiredWorkspaceLeftRightMarginPx; int edgeMarginPx; + Rect defaultWidgetPadding; int widthPx; int heightPx; @@ -109,7 +114,8 @@ class DeviceProfile { hotseatIconSize = his; } - DeviceProfile(ArrayList profiles, + DeviceProfile(Context context, + ArrayList profiles, float minWidth, float minHeight, int wPx, int hPx, int awPx, int ahPx, @@ -122,7 +128,11 @@ class DeviceProfile { minWidthDps = minWidth; minHeightDps = minHeight; + ComponentName cn = new ComponentName(context.getPackageName(), + this.getClass().getName()); + defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); edgeMarginPx = resources.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); + desiredWorkspaceLeftRightMarginPx = 2 * edgeMarginPx; pageIndicatorHeightPx = resources.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_height); // Interpolate the rows @@ -312,9 +322,9 @@ class DeviceProfile { hotseatBarHeightPx + pageIndicatorHeightPx); } else { // Pad the top and bottom of the workspace with search/hotseat bar sizes - padding.set(edgeMarginPx, + padding.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left, searchBarSpaceHeightPx, - edgeMarginPx, + desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right, hotseatBarHeightPx + pageIndicatorHeightPx); } } @@ -489,7 +499,8 @@ public class DynamicGrid { size, metrics)); } - public DynamicGrid(Resources resources, int minWidthPx, int minHeightPx, + public DynamicGrid(Context context, Resources resources, + int minWidthPx, int minHeightPx, int widthPx, int heightPx, int awPx, int ahPx) { DisplayMetrics dm = resources.getDisplayMetrics(); @@ -526,7 +537,7 @@ public class DynamicGrid { 1527, 2527, 7, 7, 100, 20, 7, 72)); mMinWidth = dpiFromPx(minWidthPx, dm); mMinHeight = dpiFromPx(minHeightPx, dm); - mProfile = new DeviceProfile(deviceProfiles, + mProfile = new DeviceProfile(context, deviceProfiles, mMinWidth, mMinHeight, widthPx, heightPx, awPx, ahPx, diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index 8b34ffbe0b..a255b89a2f 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -178,7 +178,8 @@ public class LauncherAppState { int width, int height, int availableWidth, int availableHeight) { if (mDynamicGrid == null) { - mDynamicGrid = new DynamicGrid(context.getResources(), + mDynamicGrid = new DynamicGrid(context, + context.getResources(), minWidth, minHeight, width, height, availableWidth, availableHeight); }