summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2011-06-19 12:41:22 -0700
committerWinson Chung <winsonc@google.com>2011-06-22 17:26:02 -0700
commit4b825dcd5f64a5ebb60271844fbc5257374422bc (patch)
treebc3889079d484952e71bce46f3c47e78d8f40282 /src
parent547eeb3b3e99b79fdab3b74d4e536dc014d0fb0e (diff)
downloadandroid_packages_apps_Trebuchet-4b825dcd5f64a5ebb60271844fbc5257374422bc.tar.gz
android_packages_apps_Trebuchet-4b825dcd5f64a5ebb60271844fbc5257374422bc.tar.bz2
android_packages_apps_Trebuchet-4b825dcd5f64a5ebb60271844fbc5257374422bc.zip
Tweaking launcher grid and spacing.
Change-Id: I369a87f473d1e870b2f819221f6383aab340b067
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/AppWidgetResizeFrame.java4
-rw-r--r--src/com/android/launcher2/CellLayout.java133
-rw-r--r--src/com/android/launcher2/Launcher.java10
-rw-r--r--src/com/android/launcher2/Utilities.java4
-rw-r--r--src/com/android/launcher2/Workspace.java8
5 files changed, 69 insertions, 90 deletions
diff --git a/src/com/android/launcher2/AppWidgetResizeFrame.java b/src/com/android/launcher2/AppWidgetResizeFrame.java
index eca5ad7c4..22bd6e628 100644
--- a/src/com/android/launcher2/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher2/AppWidgetResizeFrame.java
@@ -303,8 +303,8 @@ public class AppWidgetResizeFrame extends FrameLayout {
public void snapToWidget(boolean animate) {
final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
- int xOffset = mCellLayout.getLeft() + mCellLayout.getLeftPadding() - mWorkspace.getScrollX();
- int yOffset = mCellLayout.getTop() + mCellLayout.getTopPadding() - mWorkspace.getScrollY();
+ int xOffset = mCellLayout.getLeft() + mCellLayout.getPaddingLeft() - mWorkspace.getScrollX();
+ int yOffset = mCellLayout.getTop() + mCellLayout.getPaddingTop() - mWorkspace.getScrollY();
int newWidth = mWidgetView.getWidth() + 2 * mBackgroundPadding - mWidgetPaddingLeft -
mWidgetPaddingRight;
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index c1aa2d589..8182b829c 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -54,19 +54,17 @@ import java.util.HashMap;
public class CellLayout extends ViewGroup {
static final String TAG = "CellLayout";
+ private int mOriginalCellWidth;
+ private int mOriginalCellHeight;
private int mCellWidth;
private int mCellHeight;
- private int mLeftPadding;
- private int mRightPadding;
- private int mTopPadding;
- private int mBottomPadding;
-
private int mCountX;
private int mCountY;
private int mWidthGap;
private int mHeightGap;
+ private int mMaxGap;
private final Rect mRect = new Rect();
private final CellInfo mCellInfo = new CellInfo();
@@ -148,19 +146,13 @@ public class CellLayout extends ViewGroup {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);
- mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 10);
- mCellHeight = a.getDimensionPixelSize(R.styleable.CellLayout_cellHeight, 10);
- mWidthGap = a.getDimensionPixelSize(R.styleable.CellLayout_widthGap, -1);
- mHeightGap = a.getDimensionPixelSize(R.styleable.CellLayout_heightGap, -1);
-
- mLeftPadding =
- a.getDimensionPixelSize(R.styleable.CellLayout_xAxisStartPadding, 10);
- mRightPadding =
- a.getDimensionPixelSize(R.styleable.CellLayout_xAxisEndPadding, 10);
- mTopPadding =
- a.getDimensionPixelSize(R.styleable.CellLayout_yAxisStartPadding, 10);
- mBottomPadding =
- a.getDimensionPixelSize(R.styleable.CellLayout_yAxisEndPadding, 10);
+ mOriginalCellWidth =
+ mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 10);
+ mOriginalCellHeight =
+ mCellHeight = a.getDimensionPixelSize(R.styleable.CellLayout_cellHeight, 10);
+ mWidthGap = a.getDimensionPixelSize(R.styleable.CellLayout_widthGap, 0);
+ mHeightGap = a.getDimensionPixelSize(R.styleable.CellLayout_heightGap, 0);
+ mMaxGap = a.getDimensionPixelSize(R.styleable.CellLayout_maxGap, 0);
mCountX = LauncherModel.getCellCountX();
mCountY = LauncherModel.getCellCountY();
@@ -275,9 +267,10 @@ public class CellLayout extends ViewGroup {
// have. We ignore the left/right padding on CellLayout because it turns out in our design
// the padding extends outside the visible screen size, but it looked fine anyway.
int cellWidth = r.getDimensionPixelSize(R.dimen.workspace_cell_width);
- int widthGap = r.getDimensionPixelSize(R.dimen.workspace_width_gap_port);
+ int minGap = Math.min(r.getDimensionPixelSize(R.dimen.workspace_width_gap),
+ r.getDimensionPixelSize(R.dimen.workspace_height_gap));
- return widthGap * (numCells - 1) + cellWidth * numCells;
+ return minGap * (numCells - 1) + cellWidth * numCells;
}
static int heightInLandscape(Resources r, int numCells) {
@@ -285,9 +278,10 @@ public class CellLayout extends ViewGroup {
// have. We ignore the left/right padding on CellLayout because it turns out in our design
// the padding extends outside the visible screen size, but it looked fine anyway.
int cellHeight = r.getDimensionPixelSize(R.dimen.workspace_cell_height);
- int heightGap = r.getDimensionPixelSize(R.dimen.workspace_height_gap_land);
+ int minGap = Math.min(r.getDimensionPixelSize(R.dimen.workspace_width_gap),
+ r.getDimensionPixelSize(R.dimen.workspace_height_gap));
- return heightGap * (numCells - 1) + cellHeight * numCells;
+ return minGap * (numCells - 1) + cellHeight * numCells;
}
public void enableHardwareLayers() {
@@ -303,10 +297,10 @@ public class CellLayout extends ViewGroup {
private void invalidateBubbleTextView(BubbleTextView icon) {
final int padding = icon.getPressedOrFocusedBackgroundPadding();
- invalidate(icon.getLeft() + getLeftPadding() - padding,
- icon.getTop() + getTopPadding() - padding,
- icon.getRight() + getLeftPadding() + padding,
- icon.getBottom() + getTopPadding() + padding);
+ invalidate(icon.getLeft() + getPaddingLeft() - padding,
+ icon.getTop() + getPaddingTop() - padding,
+ icon.getRight() + getPaddingLeft() + padding,
+ icon.getBottom() + getPaddingTop() + padding);
}
void setPressedOrFocusedIcon(BubbleTextView icon) {
@@ -480,9 +474,9 @@ public class CellLayout extends ViewGroup {
final int width = d.getIntrinsicWidth();
final int height = d.getIntrinsicHeight();
- int x = getLeftPadding() - (mWidthGap / 2) - (width / 2);
+ int x = getPaddingLeft() - (mWidthGap / 2) - (width / 2);
for (int col = 0; col <= countX; col++) {
- int y = getTopPadding() - (mHeightGap / 2) - (height / 2);
+ int y = getPaddingTop() - (mHeightGap / 2) - (height / 2);
for (int row = 0; row <= countY; row++) {
mTmpPointF.set(x - mDragCenter.x, y - mDragCenter.y);
float dist = mTmpPointF.length();
@@ -518,8 +512,8 @@ public class CellLayout extends ViewGroup {
final Bitmap b = mPressedOrFocusedIcon.getPressedOrFocusedBackground();
if (b != null) {
canvas.drawBitmap(b,
- mPressedOrFocusedIcon.getLeft() + getLeftPadding() - padding,
- mPressedOrFocusedIcon.getTop() + getTopPadding() - padding,
+ mPressedOrFocusedIcon.getLeft() + getPaddingLeft() - padding,
+ mPressedOrFocusedIcon.getTop() + getPaddingTop() - padding,
null);
}
}
@@ -668,7 +662,7 @@ public class CellLayout extends ViewGroup {
// to this view.
final int tmpXY[] = mTmpXY;
child.getLocationOnScreen(tmpXY);
- frame.offset(mLeftPadding, mTopPadding);
+ frame.offset(mPaddingLeft, mPaddingTop);
if (frame.contains(x, y)) {
cellInfo.cell = child;
@@ -733,8 +727,8 @@ public class CellLayout extends ViewGroup {
* @param result Array of 2 ints to hold the x and y coordinate of the cell
*/
void pointToCellExact(int x, int y, int[] result) {
- final int hStartPadding = getLeftPadding();
- final int vStartPadding = getTopPadding();
+ final int hStartPadding = getPaddingLeft();
+ final int vStartPadding = getPaddingTop();
result[0] = (x - hStartPadding) / (mCellWidth + mWidthGap);
result[1] = (y - vStartPadding) / (mCellHeight + mHeightGap);
@@ -767,8 +761,8 @@ public class CellLayout extends ViewGroup {
* @param result Array of 2 ints to hold the x and y coordinate of the point
*/
void cellToPoint(int cellX, int cellY, int[] result) {
- final int hStartPadding = getLeftPadding();
- final int vStartPadding = getTopPadding();
+ final int hStartPadding = getPaddingLeft();
+ final int vStartPadding = getPaddingTop();
result[0] = hStartPadding + cellX * (mCellWidth + mWidthGap);
result[1] = vStartPadding + cellY * (mCellHeight + mHeightGap);
@@ -783,8 +777,8 @@ public class CellLayout extends ViewGroup {
* @param result Array of 2 ints to hold the x and y coordinate of the point
*/
void cellToCenterPoint(int cellX, int cellY, int[] result) {
- final int hStartPadding = getLeftPadding();
- final int vStartPadding = getTopPadding();
+ final int hStartPadding = getPaddingLeft();
+ final int vStartPadding = getPaddingTop();
result[0] = hStartPadding + cellX * (mCellWidth + mWidthGap) + mCellWidth / 2;
result[1] = vStartPadding + cellY * (mCellHeight + mHeightGap) + mCellHeight / 2;
@@ -806,30 +800,14 @@ public class CellLayout extends ViewGroup {
return mHeightGap;
}
- int getLeftPadding() {
- return mLeftPadding;
- }
-
- int getTopPadding() {
- return mTopPadding;
- }
-
- int getRightPadding() {
- return mRightPadding;
- }
-
- int getBottomPadding() {
- return mBottomPadding;
- }
-
Rect getContentRect(Rect r) {
if (r == null) {
r = new Rect();
}
int left = getPaddingLeft();
int top = getPaddingTop();
- int right = left + getWidth() - mLeftPadding - mRightPadding;
- int bottom = top + getHeight() - mTopPadding - mBottomPadding;
+ int right = left + getWidth() - mPaddingLeft - mPaddingRight;
+ int bottom = top + getHeight() - mPaddingTop - mPaddingBottom;
r.set(left, top, right, bottom);
return r;
}
@@ -848,31 +826,31 @@ public class CellLayout extends ViewGroup {
throw new RuntimeException("CellLayout cannot have UNSPECIFIED dimensions");
}
- final int cellWidth = mCellWidth;
- final int cellHeight = mCellHeight;
-
int numWidthGaps = mCountX - 1;
int numHeightGaps = mCountY - 1;
if (mWidthGap < 0 || mHeightGap < 0) {
- int vSpaceLeft = heightSpecSize - mTopPadding - mBottomPadding - (cellHeight * mCountY);
- mHeightGap = numHeightGaps > 0 ? vSpaceLeft / numHeightGaps : 0;
-
- int hSpaceLeft = widthSpecSize - mLeftPadding - mRightPadding - (cellWidth * mCountX);
- mWidthGap = numWidthGaps > 0 ? hSpaceLeft / numWidthGaps : 0;
+ int hSpace = widthSpecSize - mPaddingLeft - mPaddingRight;
+ int vSpace = heightSpecSize - mPaddingTop - mPaddingBottom;
+ int hFreeSpace = hSpace - (mCountX * mOriginalCellWidth);
+ int vFreeSpace = vSpace - (mCountY * mOriginalCellHeight);
+ mWidthGap = Math.min(mMaxGap, numWidthGaps > 0 ? (hFreeSpace / numWidthGaps) : 0);
+ mHeightGap = Math.min(mMaxGap,numHeightGaps > 0 ? (vFreeSpace / numHeightGaps) : 0);
+ int remainingHSpace = hFreeSpace - (numWidthGaps * mWidthGap);
+ int remainingVSpace = vFreeSpace - (numHeightGaps * mHeightGap);
+ mCellWidth = mOriginalCellWidth + remainingHSpace / mCountX;
+ mCellHeight = mOriginalCellHeight + remainingVSpace / mCountY;
- // center it around the min gaps
- int minGap = Math.min(mWidthGap, mHeightGap);
- mWidthGap = mHeightGap = minGap;
+ mChildren.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap);
}
// Initial values correspond to widthSpecMode == MeasureSpec.EXACTLY
int newWidth = widthSpecSize;
int newHeight = heightSpecSize;
if (widthSpecMode == MeasureSpec.AT_MOST) {
- newWidth = mLeftPadding + mRightPadding + (mCountX * cellWidth) +
+ newWidth = mPaddingLeft + mPaddingRight + (mCountX * mCellWidth) +
((mCountX - 1) * mWidthGap);
- newHeight = mTopPadding + mBottomPadding + (mCountY * cellHeight) +
+ newHeight = mPaddingTop + mPaddingBottom + (mCountY * mCellHeight) +
((mCountY - 1) * mHeightGap);
setMeasuredDimension(newWidth, newHeight);
}
@@ -880,10 +858,10 @@ public class CellLayout extends ViewGroup {
int count = getChildCount();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
- int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth - mLeftPadding -
- mRightPadding, MeasureSpec.EXACTLY);
- int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight - mTopPadding -
- mBottomPadding, MeasureSpec.EXACTLY);
+ int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth - mPaddingLeft -
+ mPaddingRight, MeasureSpec.EXACTLY);
+ int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight - mPaddingTop -
+ mPaddingBottom, MeasureSpec.EXACTLY);
child.measure(childWidthMeasureSpec, childheightMeasureSpec);
}
setMeasuredDimension(newWidth, newHeight);
@@ -894,7 +872,8 @@ public class CellLayout extends ViewGroup {
int count = getChildCount();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
- child.layout(mLeftPadding, mTopPadding, r - l - mRightPadding , b - t - mBottomPadding);
+ child.layout(mPaddingLeft, mPaddingTop,
+ r - l - mPaddingRight, b - t - mPaddingBottom);
}
}
@@ -1460,8 +1439,8 @@ public class CellLayout extends ViewGroup {
final int widthGap = mWidthGap;
final int heightGap = mHeightGap;
- final int hStartPadding = getLeftPadding();
- final int vStartPadding = getTopPadding();
+ final int hStartPadding = getPaddingLeft();
+ final int vStartPadding = getPaddingTop();
int width = cellHSpan * cellWidth + ((cellHSpan - 1) * widthGap);
int height = cellVSpan * cellHeight + ((cellVSpan - 1) * heightGap);
@@ -1656,12 +1635,12 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
}
public int getDesiredWidth() {
- return mLeftPadding + mRightPadding + (mCountX * mCellWidth) +
+ return mPaddingLeft + mPaddingRight + (mCountX * mCellWidth) +
(Math.max((mCountX - 1), 0) * mWidthGap);
}
public int getDesiredHeight() {
- return mTopPadding + mBottomPadding + (mCountY * mCellHeight) +
+ return mPaddingTop + mPaddingBottom + (mCountY * mCellHeight) +
(Math.max((mCountY - 1), 0) * mHeightGap);
}
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 5d8595701..2dfce622f 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -2109,10 +2109,10 @@ public final class Launcher extends Activity
int width = cell.getWidth();
int height = cell.getHeight();
- int x = cell.getLeftPadding();
- int y = cell.getTopPadding();
- width -= (x + cell.getRightPadding());
- height -= (y + cell.getBottomPadding());
+ int x = cell.getPaddingLeft();
+ int y = cell.getPaddingTop();
+ width -= (x + cell.getPaddingRight());
+ height -= (y + cell.getPaddingBottom());
float scale = w / width;
@@ -2135,7 +2135,7 @@ public final class Launcher extends Activity
final Canvas c = new Canvas(bitmap);
c.scale(scale, scale);
- c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
+ c.translate(-cell.getPaddingLeft(), -cell.getPaddingTop());
cell.drawChildren(c);
image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java
index 04abd77aa..775833391 100644
--- a/src/com/android/launcher2/Utilities.java
+++ b/src/com/android/launcher2/Utilities.java
@@ -114,7 +114,7 @@ final class Utilities {
width = (int) (height * ratio);
}
} else if (sourceWidth < width && sourceHeight < height) {
- // It's small, use the size they gave us.
+ // Don't scale up the icon
width = sourceWidth;
height = sourceHeight;
}
@@ -224,7 +224,7 @@ final class Utilities {
if (LauncherApplication.isScreenLarge()) {
sIconContentSize = (int) resources.getDimension(R.dimen.app_icon_content_size);
}
- sIconTextureWidth = sIconTextureHeight = sIconWidth + 2;
+ sIconTextureWidth = sIconTextureHeight = sIconWidth;
sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL));
sGlowColorPressedPaint.setColor(0xffffc300);
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 7818ef4a3..005bd2730 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -2238,8 +2238,8 @@ public class Workspace extends SmoothPagedView
// Set its old pos (in the new parent's coordinates); it will be animated
// in animateViewIntoPosition after the next layout pass
- lp.oldX = viewX - (layout.getLeft() + layout.getLeftPadding() - mScrollX);
- lp.oldY = viewY - (layout.getTop() + layout.getTopPadding() - mScrollY);
+ lp.oldX = viewX - (layout.getLeft() + layout.getPaddingLeft() - mScrollX);
+ lp.oldY = viewY - (layout.getTop() + layout.getPaddingTop() - mScrollY);
}
public void animateViewIntoPosition(final View view, final int fromX, final int fromY,
@@ -2301,8 +2301,8 @@ public class Workspace extends SmoothPagedView
final CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
// Convert the animation params to be relative to the Workspace, not the CellLayout
- final int fromX = lp.oldX + parent.getLeft() + parent.getLeftPadding();
- final int fromY = lp.oldY + parent.getTop() + parent.getTopPadding();
+ final int fromX = lp.oldX + parent.getLeft() + parent.getPaddingLeft();
+ final int fromY = lp.oldY + parent.getTop() + parent.getPaddingTop();
final int dx = lp.x - lp.oldX;
final int dy = lp.y - lp.oldY;