Skip to content

Commit

Permalink
Altering the workspace padding to account for default widget padding …
Browse files Browse the repository at this point in the history
…(Bug 11116452)
  • Loading branch information
Winson Chung committed Oct 11, 2013
1 parent 3057b1c commit f7d4585
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/com/android/launcher3/DynamicGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +67,9 @@ class DeviceProfile {
boolean isLargeTablet;
boolean transposeLayoutWithOrientation;

int desiredWorkspaceLeftRightMarginPx;
int edgeMarginPx;
Rect defaultWidgetPadding;

int widthPx;
int heightPx;
Expand Down Expand Up @@ -109,7 +114,8 @@ class DeviceProfile {
hotseatIconSize = his;
}

DeviceProfile(ArrayList<DeviceProfile> profiles,
DeviceProfile(Context context,
ArrayList<DeviceProfile> profiles,
float minWidth, float minHeight,
int wPx, int hPx,
int awPx, int ahPx,
Expand All @@ -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
Expand Down Expand Up @@ -312,9 +322,9 @@ Rect getWorkspacePadding(int orientation) {
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);
}
}
Expand Down Expand Up @@ -489,7 +499,8 @@ public static int pxFromSp(float size, DisplayMetrics metrics) {
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();
Expand Down Expand Up @@ -526,7 +537,7 @@ public DynamicGrid(Resources resources, int minWidthPx, int minHeightPx,
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,
Expand Down
3 changes: 2 additions & 1 deletion src/com/android/launcher3/LauncherAppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ DeviceProfile initDynamicGrid(Context context, int minWidth, int minHeight,
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);
}
Expand Down

0 comments on commit f7d4585

Please sign in to comment.