diff options
author | Adam Cohen <adamcohen@google.com> | 2011-02-18 19:25:06 -0800 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2011-02-25 13:56:06 -0800 |
commit | d4844c3e731b00547a31f23a00f8bd4a271e2b62 (patch) | |
tree | 6efae34aca62c6f2ab8ded7fe832fc765155231a /src/com/android/launcher2/CellLayout.java | |
parent | e552b8b19ccdfd724c6b5c5f4f265de00bc1ffac (diff) | |
download | android_packages_apps_Trebuchet-d4844c3e731b00547a31f23a00f8bd4a271e2b62.tar.gz android_packages_apps_Trebuchet-d4844c3e731b00547a31f23a00f8bd4a271e2b62.tar.bz2 android_packages_apps_Trebuchet-d4844c3e731b00547a31f23a00f8bd4a271e2b62.zip |
Implementing resizable widgets in launcher
Change-Id: I18598493dcf34fc6089fa330a4b66803f658b773
Diffstat (limited to 'src/com/android/launcher2/CellLayout.java')
-rw-r--r-- | src/com/android/launcher2/CellLayout.java | 120 |
1 files changed, 106 insertions, 14 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 6691e6447..a2a539e6b 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -587,11 +587,11 @@ public class CellLayout extends ViewGroup { boolean found = false; for (int i = count - 1; i >= 0; i--) { final View child = mChildren.getChildAt(i); + final LayoutParams lp = (LayoutParams) child.getLayoutParams(); - if ((child.getVisibility()) == VISIBLE || child.getAnimation() != null) { + if ((child.getVisibility() == VISIBLE || child.getAnimation() != null) && lp.isLockedToGrid) { child.getHitRect(frame); if (frame.contains(x, y)) { - final LayoutParams lp = (LayoutParams) child.getLayoutParams(); cellInfo.cell = child; cellInfo.cellX = lp.cellX; cellInfo.cellY = lp.cellY; @@ -703,6 +703,14 @@ public class CellLayout extends ViewGroup { return mCellHeight; } + int getWidthGap() { + return mWidthGap; + } + + int getHeightGap() { + return mHeightGap; + } + int getLeftPadding() { return mLeftPadding; } @@ -1332,19 +1340,68 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) { } } + public void getExpandabilityArrayForView(View view, int[] expandability) { + final LayoutParams lp = (LayoutParams) view.getLayoutParams(); + boolean flag; + + // Left + expandability[0] = 0; + for (int x = lp.cellX - 1; x >= 0; x--) { + flag = false; + for (int y = lp.cellY; y < lp.cellY + lp.cellVSpan; y++) { + if (mOccupied[x][y]) flag = true; + } + if (flag) break; + expandability[0]++; + } + + // Top + expandability[1] = 0; + for (int y = lp.cellY - 1; y >= 0; y--) { + flag = false; + for (int x = lp.cellX; x < lp.cellX + lp.cellHSpan; x++) { + if (mOccupied[x][y]) flag = true; + } + if (flag) break; + expandability[1]++; + } + + // Right + expandability[2] = 0; + for (int x = lp.cellX + lp.cellHSpan; x < mCountX; x++) { + flag = false; + for (int y = lp.cellY; y < lp.cellY + lp.cellVSpan; y++) { + if (mOccupied[x][y]) flag = true; + } + if (flag) break; + expandability[2]++; + } + + // Bottom + expandability[3] = 0; + for (int y = lp.cellY + lp.cellVSpan; y < mCountY; y++) { + flag = false; + for (int x = lp.cellX; x < lp.cellX + lp.cellHSpan; x++) { + if (mOccupied[x][y]) flag = true; + } + if (flag) break; + expandability[3]++; + } + } + public void onMove(View view, int newCellX, int newCellY) { LayoutParams lp = (LayoutParams) view.getLayoutParams(); markCellsAsUnoccupiedForView(view); markCellsForView(newCellX, newCellY, lp.cellHSpan, lp.cellVSpan, true); } - private void markCellsAsOccupiedForView(View view) { + public void markCellsAsOccupiedForView(View view) { if (view == null || view.getParent() != mChildren) return; LayoutParams lp = (LayoutParams) view.getLayoutParams(); markCellsForView(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, true); } - private void markCellsAsUnoccupiedForView(View view) { + public void markCellsAsUnoccupiedForView(View view) { if (view == null || view.getParent() != mChildren) return; LayoutParams lp = (LayoutParams) view.getLayoutParams(); markCellsForView(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, false); @@ -1409,6 +1466,8 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) { @ViewDebug.ExportedProperty public int cellVSpan; + public boolean isLockedToGrid = true; + /** * Is this item currently being dragged */ @@ -1467,19 +1526,52 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) { public void setup(int cellWidth, int cellHeight, int widthGap, int heightGap, int hStartPadding, int vStartPadding) { + if (isLockedToGrid) { + final int myCellHSpan = cellHSpan; + final int myCellVSpan = cellVSpan; + final int myCellX = cellX; + final int myCellY = cellY; + + width = myCellHSpan * cellWidth + ((myCellHSpan - 1) * widthGap) - + leftMargin - rightMargin; + height = myCellVSpan * cellHeight + ((myCellVSpan - 1) * heightGap) - + topMargin - bottomMargin; + + x = hStartPadding + myCellX * (cellWidth + widthGap) + leftMargin; + y = vStartPadding + myCellY * (cellHeight + heightGap) + topMargin; + } + } + + public void setWidth(int width) { + this.width = width; + } + + public int getWidth() { + return width; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getHeight() { + return height; + } - final int myCellHSpan = cellHSpan; - final int myCellVSpan = cellVSpan; - final int myCellX = cellX; - final int myCellY = cellY; + public void setX(int x) { + this.x = x; + } - width = myCellHSpan * cellWidth + ((myCellHSpan - 1) * widthGap) - - leftMargin - rightMargin; - height = myCellVSpan * cellHeight + ((myCellVSpan - 1) * heightGap) - - topMargin - bottomMargin; + public int getX() { + return x; + } + + public void setY(int y) { + this.y = y; + } - x = hStartPadding + myCellX * (cellWidth + widthGap) + leftMargin; - y = vStartPadding + myCellY * (cellHeight + heightGap) + topMargin; + public int getY() { + return y; } public String toString() { |