Merge "Use the icon bounds for all calculations." into jb-ub-now-jolly-elf

This commit is contained in:
Winson Chung
2013-11-14 19:19:24 +00:00
committed by Android (Google) Code Review
8 changed files with 50 additions and 28 deletions

View File

@@ -915,6 +915,13 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
return true;
}
@Override
public float getIntrinsicIconScaleFactor() {
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
return (float) grid.allAppsIconSizePx / grid.iconSizePx;
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();

View File

@@ -198,7 +198,7 @@ public class DragController {
* @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
* Makes dragging feel more precise, e.g. you can clip out a transparent border
*/
public void startDrag(Bitmap b, int dragLayerX, int dragLayerY,
public DragView startDrag(Bitmap b, int dragLayerX, int dragLayerY,
DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion,
float initialDragViewScale) {
if (PROFILE_DRAWING_DURING_DRAG) {
@@ -245,6 +245,7 @@ public class DragController {
mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
dragView.show(mMotionDownX, mMotionDownY);
handleMoveEvent(mMotionDownX, mMotionDownY);
return dragView;
}
/**

View File

@@ -522,14 +522,18 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
scale *= childScale;
int toX = coord[0];
int toY = coord[1];
float toScale = scale;
if (child instanceof TextView) {
TextView tv = (TextView) child;
// Account for the source scale of the icon (ie. from AllApps to Workspace, in which
// the workspace may have smaller icon bounds).
toScale = scale / dragView.getIntrinsicIconScaleFactor();
// The child may be scaled (always about the center of the view) so to account for it,
// we have to offset the position by the scaled size. Once we do that, we can center
// the drag view about the scaled child view.
toY += Math.round(scale * tv.getPaddingTop());
toY -= dragView.getMeasuredHeight() * (1 - scale) / 2;
toY += Math.round(toScale * tv.getPaddingTop());
toY -= dragView.getMeasuredHeight() * (1 - toScale) / 2;
toX -= (dragView.getMeasuredWidth() - Math.round(scale * child.getMeasuredWidth())) / 2;
} else if (child instanceof FolderIcon) {
// Account for holographic blur padding on the drag view
@@ -555,7 +559,7 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
}
}
};
animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, scale, scale,
animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, toScale, toScale,
onCompleteRunnable, ANIMATION_END_DISAPPEAR, duration, anchorView);
}

View File

@@ -30,6 +30,11 @@ public interface DragSource {
*/
boolean supportsFlingToDelete();
/*
* @return the scale of the icons over the workspace icon size
*/
float getIntrinsicIconScaleFactor();
/**
* A callback specifically made back to the source after an item from this source has been flung
* to be deleted on a DropTarget. In such a situation, this method will be called after

View File

@@ -51,6 +51,9 @@ public class DragView extends View {
private float mOffsetX = 0.0f;
private float mOffsetY = 0.0f;
private float mInitialScale = 1f;
// The intrinsic icon scale factor is the scale factor for a drag icon over the workspace
// size. This is ignored for non-icons.
private float mIntrinsicIconScale = 1f;
/**
* Construct the drag view.
@@ -120,6 +123,15 @@ public class DragView extends View {
mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
}
/** Sets the scale of the view over the normal workspace icon size. */
public void setIntrinsicIconScaleFactor(float scale) {
mIntrinsicIconScale = scale;
}
public float getIntrinsicIconScaleFactor() {
return mIntrinsicIconScale;
}
public float getOffsetY() {
return mOffsetY;
}

View File

@@ -27,19 +27,11 @@ import android.graphics.drawable.Drawable;
class FastBitmapDrawable extends Drawable {
private Bitmap mBitmap;
private int mAlpha;
private int mWidth;
private int mHeight;
private final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
FastBitmapDrawable(Bitmap b) {
mAlpha = 255;
mAlpha = 255;
mBitmap = b;
if (b != null) {
mWidth = mBitmap.getWidth();
mHeight = mBitmap.getHeight();
} else {
mWidth = mHeight = 0;
}
}
@Override
@@ -76,32 +68,22 @@ class FastBitmapDrawable extends Drawable {
@Override
public int getIntrinsicWidth() {
return mWidth;
return getBounds().width();
}
@Override
public int getIntrinsicHeight() {
return mHeight;
return getBounds().height();
}
@Override
public int getMinimumWidth() {
return mWidth;
return getBounds().width();
}
@Override
public int getMinimumHeight() {
return mHeight;
}
public void setBitmap(Bitmap b) {
mBitmap = b;
if (b != null) {
mWidth = mBitmap.getWidth();
mHeight = mBitmap.getHeight();
} else {
mWidth = mHeight = 0;
}
return getBounds().height();
}
public Bitmap getBitmap() {

View File

@@ -791,6 +791,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
}
@Override
public float getIntrinsicIconScaleFactor() {
return 1f;
}
@Override
public boolean supportsFlingToDelete() {
return true;

View File

@@ -2551,8 +2551,9 @@ public class Workspace extends SmoothPagedView
throw new IllegalStateException(msg);
}
mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale);
dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor());
if (child.getParent() instanceof ShortcutAndWidgetContainer) {
mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
@@ -4153,6 +4154,11 @@ public class Workspace extends SmoothPagedView
}
}
@Override
public float getIntrinsicIconScaleFactor() {
return 1f;
}
@Override
public boolean supportsFlingToDelete() {
return true;