diff options
author | Adam Cohen <adamcohen@google.com> | 2011-09-01 13:48:05 -0700 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2011-09-01 13:54:32 -0700 |
commit | f814aa0f33c020a60de8a921176345f71a4b07c8 (patch) | |
tree | 5a21708576c72c594129bb0793bd2210685501ef | |
parent | 5037a0b02a720ae14cbf673d7d5bb148f5a524c8 (diff) | |
download | packages_apps_trebuchet-f814aa0f33c020a60de8a921176345f71a4b07c8.zip packages_apps_trebuchet-f814aa0f33c020a60de8a921176345f71a4b07c8.tar.gz packages_apps_trebuchet-f814aa0f33c020a60de8a921176345f71a4b07c8.tar.bz2 |
Unifying widget cell requirement computations
Change-Id: I5b37ebdab5b3defe7d05926882a6587d4c9f1081
-rw-r--r-- | src/com/android/launcher2/AppsCustomizePagedView.java | 9 | ||||
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 33 | ||||
-rw-r--r-- | src/com/android/launcher2/LauncherAppWidgetHostView.java | 2 |
3 files changed, 28 insertions, 16 deletions
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index df98c89..d3e0963 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -492,8 +492,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen int h = preview.getIntrinsicHeight(); if (createItemInfo instanceof PendingAddWidgetInfo) { PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) createItemInfo; - int[] spanXY = CellLayout.rectToCell(getResources(), - createWidgetInfo.minWidth, createWidgetInfo.minHeight, null); + int[] spanXY = mLauncher.getSpanForWidget(createWidgetInfo, null); createItemInfo.spanX = spanXY[0]; createItemInfo.spanY = spanXY[1]; @@ -986,8 +985,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen Object rawInfo = items.get(i); if (rawInfo instanceof AppWidgetProviderInfo) { AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo; - int[] cellSpans = CellLayout.rectToCell(getResources(), - info.minWidth, info.minHeight, null); + int[] cellSpans = mLauncher.getSpanForWidget(info, null); images.add(getWidgetPreview(info, cellSpans[0],cellSpans[1], cellWidth, cellHeight)); } else if (rawInfo instanceof ResolveInfo) { @@ -1017,8 +1015,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // Fill in the widget information AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo; createItemInfo = new PendingAddWidgetInfo(info, null, null, "13"); - int[] cellSpans = CellLayout.rectToCell(getResources(), - info.minWidth, info.minHeight, null); + int[] cellSpans = mLauncher.getSpanForWidget(info, null); FastBitmapDrawable preview = new FastBitmapDrawable(data.generatedImages.get(i)); widget.applyFromAppWidgetProviderInfo(info, preview, -1, cellSpans, mHolographicOutlineHelper); diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index d0b33a8..637d956 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -852,14 +852,13 @@ public final class Launcher extends Activity int bottom = 0; } - Padding getPaddingForWidget(AppWidgetProviderInfo widgetInfo) { + Padding getPaddingForWidget(ComponentName component) { PackageManager packageManager = getPackageManager(); Padding p = new Padding(); android.content.pm.ApplicationInfo appInfo; try { - appInfo = packageManager.getApplicationInfo( - widgetInfo.provider.getPackageName(), 0); + appInfo = packageManager.getApplicationInfo(component.getPackageName(), 0); } catch (Exception e) { // if we can't find the package, return 0 padding return p; @@ -878,6 +877,27 @@ public final class Launcher extends Activity return p; } + int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) { + if (spanXY == null) { + spanXY = new int[2]; + } + + Padding padding = getPaddingForWidget(component); + // 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 + int requiredWidth = minWidth + padding.left + padding.right; + int requiredHeight = minHeight + padding.top + padding.bottom; + return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null); + } + + int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) { + return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY); + } + + int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) { + return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY); + } + /** * Add a widget to the workspace. * @@ -890,12 +910,7 @@ public final class Launcher extends Activity // Calculate the grid spans needed to fit this widget CellLayout layout = getCellLayout(container, screen); - Padding padding = getPaddingForWidget(appWidgetInfo); - // 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 - int requiredWidth = appWidgetInfo.minWidth + padding.left + padding.right; - int requiredHeight = appWidgetInfo.minHeight + padding.top + padding.bottom; - int[] spanXY = layout.rectToCell(requiredWidth, requiredHeight, null); + int[] spanXY = getSpanForWidget(appWidgetInfo, null); // Try finding open space on Launcher screen // We have saved the position to which the widget was dragged-- this really only matters diff --git a/src/com/android/launcher2/LauncherAppWidgetHostView.java b/src/com/android/launcher2/LauncherAppWidgetHostView.java index a84ced6..7118c49 100644 --- a/src/com/android/launcher2/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher2/LauncherAppWidgetHostView.java @@ -119,7 +119,7 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView { public void setAppWidget(int appWidgetId, AppWidgetProviderInfo info) { super.setAppWidget(appWidgetId, info); // We add necessary padding to the AppWidgetHostView - Launcher.Padding padding = mLauncher.getPaddingForWidget(info); + Launcher.Padding padding = mLauncher.getPaddingForWidget(info.provider); setPadding(padding.left, padding.top, padding.right, padding.bottom); } |