am 23282720: am 1dc3b9ab: Merge "Adding the ability to scale the hotseat or items in the hotseat" into jb-mr1-dev

* commit '23282720dd7972dfc528c9d55aac069acca91082':
  Adding the ability to scale the hotseat or items in the hotseat
This commit is contained in:
Adam Cohen
2012-08-24 14:19:17 -07:00
committed by Android Git Automerger
9 changed files with 73 additions and 34 deletions
+4
View File
@@ -18,4 +18,8 @@
<!-- Camera distance for the overscroll effect. We use a higher value here because the
workspace screens run nearly flush to the edge of the screen-->
<integer name="config_cameraDistance">14000</integer>
<!-- Hotseat -->
<!-- must be between 0 and 100 -->
<integer name="hotseat_item_scale_percentage">90</integer>
</resources>
+2
View File
@@ -82,4 +82,6 @@
<bool name="hotseat_transpose_layout_with_orientation">true</bool>
<integer name="hotseat_cell_count">5</integer>
<integer name="hotseat_all_apps_index">2</integer>
<!-- must be between 0 and 100 -->
<integer name="hotseat_item_scale_percentage">100</integer>
</resources>
+34 -8
View File
@@ -137,6 +137,7 @@ public class CellLayout extends ViewGroup {
private ShortcutAndWidgetContainer mShortcutsAndWidgets;
private boolean mIsHotseat = false;
private float mHotseatScale = 1f;
public static final int MODE_DRAG_OVER = 0;
public static final int MODE_ON_DROP = 1;
@@ -199,6 +200,7 @@ public class CellLayout extends ViewGroup {
setAlwaysDrawnWithCacheEnabled(false);
final Resources res = getResources();
mHotseatScale = (res.getInteger(R.integer.hotseat_item_scale_percentage) / 100f);
mNormalBackground = res.getDrawable(R.drawable.homescreen_blue_normal_holo);
mActiveGlowBackground = res.getDrawable(R.drawable.homescreen_blue_strong_holo);
@@ -316,6 +318,10 @@ public class CellLayout extends ViewGroup {
mShortcutsAndWidgets.buildLayer();
}
public float getChildrenScale() {
return mIsHotseat ? mHotseatScale : 1.0f;
}
public void setGridSize(int x, int y) {
mCountX = x;
mCountY = y;
@@ -386,6 +392,25 @@ public class CellLayout extends ViewGroup {
}
}
public void scaleRect(Rect r, float scale) {
if (scale != 1.0f) {
r.left = (int) (r.left * scale + 0.5f);
r.top = (int) (r.top * scale + 0.5f);
r.right = (int) (r.right * scale + 0.5f);
r.bottom = (int) (r.bottom * scale + 0.5f);
}
}
Rect temp = new Rect();
void scaleRectAboutCenter(Rect in, Rect out, float scale) {
int cx = in.centerX();
int cy = in.centerY();
out.set(in);
out.offset(-cx, -cy);
scaleRect(out, scale);
out.offset(cx, cy);
}
@Override
protected void onDraw(Canvas canvas) {
// When we're large, we are either drawn in a "hover" state (ie when dragging an item to
@@ -413,9 +438,10 @@ public class CellLayout extends ViewGroup {
final float alpha = mDragOutlineAlphas[i];
if (alpha > 0) {
final Rect r = mDragOutlines[i];
scaleRectAboutCenter(r, temp, getChildrenScale());
final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
paint.setAlpha((int)(alpha + .5f));
canvas.drawBitmap(b, null, r, paint);
canvas.drawBitmap(b, null, temp, paint);
}
}
@@ -590,6 +616,9 @@ public class CellLayout extends ViewGroup {
}
}
child.setScaleX(getChildrenScale());
child.setScaleY(getChildrenScale());
// Generate an id for each view, this assumes we have at most 256x256 cells
// per workspace screen
if (lp.cellX >= 0 && lp.cellX <= mCountX - 1 && lp.cellY >= 0 && lp.cellY <= mCountY - 1) {
@@ -2071,11 +2100,8 @@ public class CellLayout extends ViewGroup {
}
initDeltaX = child.getTranslationX();
initDeltaY = child.getTranslationY();
finalScale = 1.0f - 4.0f / child.getWidth();
finalScale = getChildrenScale() - 4.0f / child.getWidth();
initScale = child.getScaleX();
child.setPivotY(child.getMeasuredHeight() * 0.5f);
child.setPivotX(child.getMeasuredWidth() * 0.5f);
this.child = child;
}
@@ -2116,7 +2142,7 @@ public class CellLayout extends ViewGroup {
// We make sure to end only after a full period
initDeltaX = 0;
initDeltaY = 0;
initScale = 1.0f;
initScale = getChildrenScale();
}
});
mShakeAnimators.put(child, this);
@@ -2137,8 +2163,8 @@ public class CellLayout extends ViewGroup {
AnimatorSet s = LauncherAnimUtils.createAnimatorSet();
a = s;
s.playTogether(
LauncherAnimUtils.ofFloat(child, "scaleX", 1f),
LauncherAnimUtils.ofFloat(child, "scaleY", 1f),
LauncherAnimUtils.ofFloat(child, "scaleX", getChildrenScale()),
LauncherAnimUtils.ofFloat(child, "scaleY", getChildrenScale()),
LauncherAnimUtils.ofFloat(child, "translationX", 0f),
LauncherAnimUtils.ofFloat(child, "translationY", 0f)
);
+13 -6
View File
@@ -274,10 +274,10 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
return scale;
}
public void getLocationInDragLayer(View child, int[] loc) {
public float getLocationInDragLayer(View child, int[] loc) {
loc[0] = 0;
loc[1] = 0;
getDescendantCoordRelativeToSelf(child, loc);
return getDescendantCoordRelativeToSelf(child, loc);
}
/**
@@ -286,7 +286,9 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
*
* @param descendant The descendant to which the passed coordinate is relative.
* @param coord The coordinate that we want mapped.
* @return The factor by which this descendant is scaled relative to this DragLayer.
* @return The factor by which this descendant is scaled relative to this DragLayer. Caution
* this scale factor is assumed to be equal in X and Y, and so if at any point this
* assumption fails, we will need to return a pair of scale factors.
*/
public float getDescendantCoordRelativeToSelf(View descendant, int[] coord) {
float scale = 1.0f;
@@ -451,12 +453,16 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
getViewRectRelativeToSelf(dragView, r);
int coord[] = new int[2];
coord[0] = lp.x;
coord[1] = lp.y;
float childScale = child.getScaleX();
coord[0] = lp.x + (int) (child.getMeasuredWidth() * (1 - childScale) / 2);
coord[1] = lp.y + (int) (child.getMeasuredHeight() * (1 - childScale) / 2);
// Since the child hasn't necessarily been laid out, we force the lp to be updated with
// the correct coordinates (above) and use these to determine the final location
float scale = getDescendantCoordRelativeToSelf((View) child.getParent(), coord);
// We need to account for the scale of the child itself, as the above only accounts for
// for the scale in parents.
scale *= childScale;
int toX = coord[0];
int toY = coord[1];
if (child instanceof TextView) {
@@ -470,7 +476,8 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
toX -= (dragView.getMeasuredWidth() - Math.round(scale * child.getMeasuredWidth())) / 2;
} else if (child instanceof FolderIcon) {
// Account for holographic blur padding on the drag view
toY -= Workspace.DRAG_BITMAP_PADDING / 2;
toY -= scale * Workspace.DRAG_BITMAP_PADDING / 2;
toY -= (1 - scale) * dragView.getMeasuredHeight() / 2;
// Center in the x coordinate about the target's drawable
toX -= (dragView.getMeasuredWidth() - Math.round(scale * child.getMeasuredWidth())) / 2;
} else {
+4
View File
@@ -75,6 +75,10 @@ public class DragView extends View {
final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale);
final float scale = (width + scaleDps) / width;
// Set the initial scale to avoid any jumps
setScaleX(initialScale);
setScaleY(initialScale);
// Animate the view into the correct position
mAnim = LauncherAnimUtils.ofFloat(0.0f, 1.0f);
mAnim.setDuration(150);
+3 -3
View File
@@ -805,10 +805,10 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
+ mFolderNameHeight;
DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
int centerX = mTempRect.centerX();
int centerY = mTempRect.centerY();
int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
int centeredLeft = centerX - width / 2;
int centeredTop = centerY - height / 2;
+1 -1
View File
@@ -38,7 +38,7 @@ public class Hotseat extends FrameLayout {
private int mCellCountX;
private int mCellCountY;
private int mAllAppsButtonRank;
private boolean mTransposeLayoutWithOrientation;
private boolean mIsLandscape;
+5 -3
View File
@@ -2129,12 +2129,14 @@ public final class Launcher extends Activity
lp = new DragLayer.LayoutParams(width, height);
}
mDragLayer.getViewRectRelativeToSelf(fi, mRectForFolderAnimation);
// The layout from which the folder is being opened may be scaled, adjust the starting
// view size by this scale factor.
float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
lp.customPosition = true;
lp.x = mRectForFolderAnimation.left;
lp.y = mRectForFolderAnimation.top;
lp.width = width;
lp.height = height;
lp.width = (int) (scale * width);
lp.height = (int) (scale * height);
mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
fi.draw(mFolderIconCanvas);
+7 -13
View File
@@ -1892,11 +1892,11 @@ public class Workspace extends SmoothPagedView
final int bmpWidth = b.getWidth();
final int bmpHeight = b.getHeight();
mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY);
float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY);
int dragLayerX =
Math.round(mTempXY[0] - (bmpWidth - child.getScaleX() * child.getWidth()) / 2);
Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2);
int dragLayerY =
Math.round(mTempXY[1] - (bmpHeight - child.getScaleY() * bmpHeight) / 2
Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2
- DRAG_BITMAP_PADDING / 2);
Point dragVisualizeOffset = null;
@@ -1926,7 +1926,7 @@ public class Workspace extends SmoothPagedView
}
mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, child.getScaleX());
DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale);
b.recycle();
// Show the scrolling indicator when you pick up an item
@@ -1966,7 +1966,7 @@ public class Workspace extends SmoothPagedView
// We want the point to be mapped to the dragTarget.
if (mLauncher.isHotseatLayout(dropTargetLayout)) {
mapPointFromSelfToSibling(mLauncher.getHotseat(), mDragViewVisualCenter);
mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
} else {
mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null);
}
@@ -2577,18 +2577,12 @@ public class Workspace extends SmoothPagedView
cachedInverseMatrix.mapPoints(xy);
}
/*
* Maps a point from the Workspace's coordinate system to another sibling view's. (Workspace
* covers the full screen)
*/
void mapPointFromSelfToSibling(View v, float[] xy) {
xy[0] = xy[0] - v.getLeft();
xy[1] = xy[1] - v.getTop();
}
void mapPointFromSelfToHotseatLayout(Hotseat hotseat, float[] xy) {
hotseat.getLayout().getMatrix().invert(mTempInverseMatrix);
xy[0] = xy[0] - hotseat.getLeft() - hotseat.getLayout().getLeft();
xy[1] = xy[1] - hotseat.getTop() - hotseat.getLayout().getTop();
mTempInverseMatrix.mapPoints(xy);
}
/*