am 5cc7c35d: Merge "Improve feedback during spring loaded mode" into honeycomb

* commit '5cc7c35dca4d1279575285f33ecef1a1df339d11':
  Improve feedback during spring loaded mode
This commit is contained in:
Michael Jurka
2011-01-25 23:11:31 -08:00
committed by Android Git Automerger
4 changed files with 36 additions and 33 deletions
@@ -1245,6 +1245,13 @@ public class CellLayout extends ViewGroup {
return result;
}
public int[] cellSpansToSize(int hSpans, int vSpans) {
int[] size = new int[2];
size[0] = hSpans * mCellWidth + (hSpans - 1) * mWidthGap;
size[1] = vSpans * mCellHeight + (vSpans - 1) * mHeightGap;
return size;
}
/**
* Calculate the grid spans needed to fit given item
*/
@@ -479,8 +479,9 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
}
}
Bitmap drawableToBitmap(Drawable d, View v) {
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Bitmap drawableToBitmap(Drawable d, View v, boolean clipHeight) {
int height = clipHeight ? v.getPaddingTop() + d.getIntrinsicHeight() : v.getHeight();
Bitmap b = Bitmap.createBitmap(v.getWidth(), height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.translate((v.getWidth() - d.getIntrinsicWidth()) / 2, v.getPaddingTop());
d.draw(c);
@@ -508,8 +509,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
// Get the widget preview as the drag representation
final LinearLayout l = (LinearLayout) v;
final ImageView i = (ImageView) l.findViewById(R.id.widget_preview);
final Drawable icon = i.getDrawable();
Bitmap b = drawableToBitmap(icon, i);
Bitmap b = drawableToBitmap(i.getDrawable(), i, true);
PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) v.getTag();
int[] spanXY = CellLayout.rectToCell(
@@ -529,7 +529,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
// get icon (top compound drawable, index is 1)
final TextView tv = (TextView) v;
final Drawable icon = tv.getCompoundDrawables()[1];
Bitmap b = drawableToBitmap(icon, tv);
Bitmap b = drawableToBitmap(icon, tv, false);
PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();
mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
@@ -546,7 +546,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
// get icon (top compound drawable, index is 1)
final TextView tv = (TextView) v;
final Drawable icon = tv.getCompoundDrawables()[1];
Bitmap b = drawableToBitmap(icon, tv);
Bitmap b = drawableToBitmap(icon, tv, false);
ApplicationInfo app = (ApplicationInfo) v.getTag();
app = new ApplicationInfo(app);
-17
View File
@@ -48,7 +48,6 @@ public class DragView extends View {
private int mDragRegionHeight;
ValueAnimator mAnim;
private float mScale = 1.0f;
private float mOffsetX = 0.0f;
private float mOffsetY = 0.0f;
@@ -144,22 +143,6 @@ public class DragView extends View {
mOnDrawRunnable = r;
}
public int getScaledDragRegionXOffset() {
return -(int)((mScale - 1.0f) * mDragRegionWidth / 2);
}
public int getScaledDragRegionWidth() {
return (int)(mScale * mDragRegionWidth);
}
public int getScaledDragRegionYOffset() {
return -(int)((mScale - 1.0f) * mDragRegionHeight / 2);
}
public int getScaledDragRegionHeight() {
return (int)(mScale * mDragRegionWidth);
}
public int getDragRegionLeft() {
return mDragRegionLeft;
}
+23 -10
View File
@@ -1488,8 +1488,10 @@ public class Workspace extends SmoothPagedView
// We need to add extra padding to the bitmap to make room for the glow effect
final int bitmapPadding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS;
CellLayout cl = (CellLayout) getChildAt(0);
int[] desiredSize = cl.cellSpansToSize(spanX, spanY);
// The outline is used to visualize where the item will land if dropped
mDragOutline = createDragOutline(b, canvas, bitmapPadding);
mDragOutline = createDragOutline(b, canvas, bitmapPadding, desiredSize[0], desiredSize[1]);
updateWhichPagesAcceptDropsDuringDrag(mShrinkState, spanX, spanY);
}
@@ -1685,13 +1687,24 @@ public class Workspace extends SmoothPagedView
* Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
* Responsibility for the bitmap is transferred to the caller.
*/
private Bitmap createDragOutline(Bitmap orig, Canvas canvas, int padding) {
private Bitmap createDragOutline(Bitmap orig, Canvas canvas, int padding, int w, int h) {
final int outlineColor = getResources().getColor(R.color.drag_outline_color);
final Bitmap b = Bitmap.createBitmap(
orig.getWidth() + padding, orig.getHeight() + padding, Bitmap.Config.ARGB_8888);
final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
canvas.setBitmap(b);
canvas.drawBitmap(orig, 0, 0, new Paint());
Rect src = new Rect(0, 0, orig.getWidth(), orig.getHeight());
float scaleFactor = Math.min((w - padding) / (float) orig.getWidth(),
(h - padding) / (float) orig.getHeight());
int scaledWidth = (int) (scaleFactor * orig.getWidth());
int scaledHeight = (int) (scaleFactor * orig.getHeight());
Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);
// center the image
dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2);
Paint p = new Paint();
p.setFilterBitmap(true);
canvas.drawBitmap(orig, src, dst, p);
mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor);
return b;
@@ -2229,11 +2242,11 @@ public class Workspace extends SmoothPagedView
int dragViewX, int dragViewY, Matrix cachedInverseMatrix) {
// Transform the coordinates of the item being dragged to the CellLayout's coordinates
final float[] draggedItemTopLeft = mTempDragCoordinates;
draggedItemTopLeft[0] = dragViewX + dragView.getScaledDragRegionXOffset();
draggedItemTopLeft[1] = dragViewY + dragView.getScaledDragRegionYOffset();
draggedItemTopLeft[0] = dragViewX;
draggedItemTopLeft[1] = dragViewY;
final float[] draggedItemBottomRight = mTempDragBottomRightCoordinates;
draggedItemBottomRight[0] = draggedItemTopLeft[0] + dragView.getScaledDragRegionWidth();
draggedItemBottomRight[1] = draggedItemTopLeft[1] + dragView.getScaledDragRegionHeight();
draggedItemBottomRight[0] = draggedItemTopLeft[0] + dragView.getDragRegionWidth();
draggedItemBottomRight[1] = draggedItemTopLeft[1] + dragView.getDragRegionHeight();
// Transform the dragged item's top left coordinates
// to the CellLayout's local coordinates