Fixing some issues/regressions related to scaled icons.
- Fixes issue with folder icons being clipped in landscape in sw720dp (Bug: 6118397)
- Fixes issue with divider being in wrong orientation in sw720dp
- Fixes issue with scaled icons not being drawn with filtering
- Fixes issue with side pages showing under the hotseat when in landscape in phone UI
- Animates the drag view on pick up and drop
Change-Id: Iad26427ec63fcbc9bdb3b29a4645689ba445d5c8
diff --git a/src/com/android/launcher2/BubbleTextView.java b/src/com/android/launcher2/BubbleTextView.java
index 623c6ff..4a3a7a4 100644
--- a/src/com/android/launcher2/BubbleTextView.java
+++ b/src/com/android/launcher2/BubbleTextView.java
@@ -47,8 +47,6 @@
static final float PADDING_H = 8.0f;
static final float PADDING_V = 3.0f;
- private Paint mPaint;
- private float mBubbleColorAlpha;
private int mPrevAlpha = -1;
private final HolographicOutlineHelper mOutlineHelper = new HolographicOutlineHelper();
@@ -88,9 +86,6 @@
final Resources res = getContext().getResources();
int bubbleColor = res.getColor(R.color.bubble_dark_background);
- mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
- mPaint.setColor(bubbleColor);
- mBubbleColorAlpha = Color.alpha(bubbleColor) / 255.0f;
mFocusedOutlineColor = mFocusedGlowColor = mPressedOutlineColor = mPressedGlowColor =
res.getColor(android.R.color.holo_blue_light);
@@ -178,7 +173,8 @@
// The translate of scrollX and scrollY is necessary when drawing TextViews, because
// they set scrollX and scrollY to large values to achieve centered text
destCanvas.save();
- destCanvas.scale(getScaleX(), getScaleY(), getWidth() / 2, getHeight() / 2);
+ destCanvas.scale(getScaleX(), getScaleY(),
+ (getWidth() + padding) / 2, (getHeight() + padding) / 2);
destCanvas.translate(-getScrollX() + padding / 2, -getScrollY() + padding / 2);
destCanvas.clipRect(clipRect, Op.REPLACE);
draw(destCanvas);
@@ -328,7 +324,6 @@
protected boolean onSetAlpha(int alpha) {
if (mPrevAlpha != alpha) {
mPrevAlpha = alpha;
- mPaint.setAlpha((int) (alpha * mBubbleColorAlpha));
super.onSetAlpha(alpha);
}
return true;
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 1aaba6d..528984a 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -137,8 +137,8 @@
private CellLayoutChildren mChildren;
private boolean mIsHotseat = false;
- private final int mBubbleScalePercent;
- private final int mBubbleHotseatScalePercent;
+ private float mChildScale = 1f;
+ private float mHotseatChildScale = 1f;
public CellLayout(Context context) {
this(context, null);
@@ -185,8 +185,14 @@
mNormalBackground.setFilterBitmap(true);
mActiveGlowBackground.setFilterBitmap(true);
- mBubbleScalePercent = res.getInteger(R.integer.app_icon_scale_percent);
- mBubbleHotseatScalePercent = res.getInteger(R.integer.app_icon_hotseat_scale_percent);
+ int iconScale = res.getInteger(R.integer.app_icon_scale_percent);
+ if (iconScale >= 0) {
+ mChildScale = iconScale / 100f;
+ }
+ int hotseatIconScale = res.getInteger(R.integer.app_icon_hotseat_scale_percent);
+ if (hotseatIconScale >= 0) {
+ mHotseatChildScale = hotseatIconScale / 100f;
+ }
// Initialize the data structures used for the drag visualization.
@@ -497,25 +503,6 @@
@Override
protected void dispatchDraw(Canvas canvas) {
- // Debug drawing for hit space
- if (false) {
- final Rect frame = mRect;
- for (int i = mChildren.getChildCount() - 1; i >= 0; i--) {
- final View child = mChildren.getChildAt(i);
- final LayoutParams lp = (LayoutParams) child.getLayoutParams();
-
- if ((child.getVisibility() == VISIBLE || child.getAnimation() != null) &&
- lp.isLockedToGrid) {
- child.getHitRect(frame);
- frame.offset(mPaddingLeft, mPaddingTop);
-
- Paint p = new Paint();
- p.setColor(Color.GREEN);
- canvas.drawRect(frame, p);
- }
- }
- }
-
super.dispatchDraw(canvas);
if (mForegroundAlpha > 0) {
mOverScrollForegroundDrawable.setBounds(mForegroundRect);
@@ -582,12 +569,16 @@
mIsHotseat = isHotseat;
}
+ public float getChildrenScale() {
+ return mIsHotseat ? mHotseatChildScale : mChildScale;
+ }
+
public boolean addViewToCellLayout(
View child, int index, int childId, LayoutParams params, boolean markCells) {
return addViewToCellLayout(child, index, childId, params, markCells, false);
}
- private void scaleChild(BubbleTextView bubbleChild, float pivot, int scalePercent) {
+ private void scaleChild(BubbleTextView bubbleChild, float pivot, float scale) {
// If we haven't measured the child yet, do it now
// (this happens if we're being dropped from all-apps
if (bubbleChild.getLayoutParams() instanceof LayoutParams &&
@@ -597,20 +588,13 @@
int measuredWidth = bubbleChild.getMeasuredWidth();
int measuredHeight = bubbleChild.getMeasuredHeight();
- float scale = scalePercent / 100f;
- bubbleChild.setPivotX(pivot);
- bubbleChild.setPivotY(pivot);
bubbleChild.setScaleX(scale);
bubbleChild.setScaleY(scale);
- bubbleChild.setTranslationX(measuredWidth * (1 - scale) / 2);
- bubbleChild.setTranslationY(measuredHeight * (1 - scale) / 2);
}
private void resetChild(BubbleTextView bubbleChild) {
bubbleChild.setScaleX(1f);
bubbleChild.setScaleY(1f);
- bubbleChild.setTranslationX(0f);
- bubbleChild.setTranslationY(0f);
bubbleChild.setTextColor(getResources().getColor(R.color.workspace_icon_text_color));
}
@@ -629,14 +613,14 @@
// Start the child with 100% scale and visible text
resetChild(bubbleChild);
- if (mIsHotseat && !allApps && mBubbleHotseatScalePercent >= 0) {
+ if (mIsHotseat && !allApps && mHotseatChildScale >= 0) {
// Scale/make transparent for a hotseat
- scaleChild(bubbleChild, 0f, mBubbleHotseatScalePercent);
+ scaleChild(bubbleChild, 0f, mHotseatChildScale);
bubbleChild.setTextColor(getResources().getColor(android.R.color.transparent));
- } else if (mBubbleScalePercent >= 0) {
+ } else if (mChildScale >= 0) {
// Else possibly still scale it if we need to for smaller icons
- scaleChild(bubbleChild, 0f, mBubbleScalePercent);
+ scaleChild(bubbleChild, 0f, mChildScale);
}
}
@@ -727,7 +711,7 @@
public void setTagToCellInfoForPoint(int touchX, int touchY) {
final CellInfo cellInfo = mCellInfo;
- final Rect frame = mRect;
+ Rect frame = mRect;
final int x = touchX + mScrollX;
final int y = touchY + mScrollY;
final int count = mChildren.getChildCount();
@@ -741,10 +725,15 @@
lp.isLockedToGrid) {
child.getHitRect(frame);
+ float scale = child.getScaleX();
+ frame = new Rect(child.getLeft(), child.getTop(), child.getRight(),
+ child.getBottom());
// The child hit rect is relative to the CellLayoutChildren parent, so we need to
// offset that by this CellLayout's padding to test an (x,y) point that is relative
// to this view.
frame.offset(mPaddingLeft, mPaddingTop);
+ frame.inset((int) (frame.width() * (1f - scale) / 2),
+ (int) (frame.height() * (1f - scale) / 2));
if (frame.contains(x, y)) {
cellInfo.cell = child;
@@ -791,6 +780,7 @@
if (action == MotionEvent.ACTION_DOWN) {
setTagToCellInfoForPoint((int) ev.getX(), (int) ev.getY());
}
+
return false;
}
@@ -1978,8 +1968,8 @@
leftMargin - rightMargin;
height = myCellVSpan * cellHeight + ((myCellVSpan - 1) * heightGap) -
topMargin - bottomMargin;
- x = myCellX * (cellWidth + widthGap) + leftMargin;
- y = myCellY * (cellHeight + heightGap) + topMargin;
+ x = (int) (myCellX * (cellWidth + widthGap) + leftMargin);
+ y = (int) (myCellY * (cellHeight + heightGap) + topMargin);
}
}
diff --git a/src/com/android/launcher2/CellLayoutChildren.java b/src/com/android/launcher2/CellLayoutChildren.java
index 35f5af1..4ca44ed 100644
--- a/src/com/android/launcher2/CellLayoutChildren.java
+++ b/src/com/android/launcher2/CellLayoutChildren.java
@@ -18,10 +18,14 @@
import android.app.WallpaperManager;
import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;
+import com.android.launcher2.CellLayout.LayoutParams;
+
public class CellLayoutChildren extends ViewGroup {
static final String TAG = "CellLayoutChildren";
@@ -68,6 +72,22 @@
}
@Override
+ protected void dispatchDraw(Canvas canvas) {
+ // Debug drawing for hit space
+ if (false) {
+ Paint p = new Paint();
+ p.setColor(0x6600FF00);
+ for (int i = getChildCount() - 1; i >= 0; i--) {
+ final View child = getChildAt(i);
+ final CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
+
+ canvas.drawRect(lp.x, lp.y, lp.x + lp.width, lp.y + lp.height, p);
+ }
+ }
+ super.dispatchDraw(canvas);
+ }
+
+ @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int count = getChildCount();
for (int i = 0; i < count; i++) {
diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java
index a3b389d..ce5c8c5 100644
--- a/src/com/android/launcher2/DragLayer.java
+++ b/src/com/android/launcher2/DragLayer.java
@@ -433,8 +433,10 @@
public void animateViewIntoPosition(DragView dragView, final View child, int duration,
final Runnable onFinishAnimationRunnable, View anchorView) {
- ((CellLayoutChildren) child.getParent()).measureChild(child);
+ CellLayoutChildren parentChildren = (CellLayoutChildren) child.getParent();
+ CellLayout parent = (CellLayout) (CellLayout) parentChildren.getParent();
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
+ parentChildren.measureChild(child);
Rect r = new Rect();
getViewRectRelativeToSelf(dragView, r);
@@ -442,20 +444,25 @@
int coord[] = new int[2];
coord[0] = lp.x;
coord[1] = lp.y;
+
// 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);
int toX = coord[0];
int toY = coord[1];
if (child instanceof TextView) {
+ float childrenScale = parent.getChildrenScale();
TextView tv = (TextView) child;
- Drawable d = tv.getCompoundDrawables()[1];
- // Center in the y coordinate about the target's drawable
- toY += Math.round(scale * tv.getPaddingTop());
- toY -= (dragView.getHeight() - (int) Math.round(scale * d.getIntrinsicHeight())) / 2;
- // Center in the x coordinate about the target's drawable
+ // 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(((1f - childrenScale) * child.getMeasuredHeight()) / 2 +
+ scale * childrenScale * tv.getPaddingTop());
+ toY -= dragView.getMeasuredHeight() * (1 - scale * childrenScale) / 2;
toX -= (dragView.getMeasuredWidth() - Math.round(scale * child.getMeasuredWidth())) / 2;
+
+ scale *= childrenScale;
} else if (child instanceof FolderIcon) {
// Account for holographic blur padding on the drag view
toY -= Workspace.DRAG_BITMAP_PADDING / 2;
diff --git a/src/com/android/launcher2/DragView.java b/src/com/android/launcher2/DragView.java
index f6c16b3..3090e8f 100644
--- a/src/com/android/launcher2/DragView.java
+++ b/src/com/android/launcher2/DragView.java
@@ -162,7 +162,7 @@
// for debugging
Paint p = new Paint();
p.setStyle(Paint.Style.FILL);
- p.setColor(0xaaffffff);
+ p.setColor(0x66ffffff);
canvas.drawRect(0, 0, getWidth(), getHeight(), p);
}
diff --git a/src/com/android/launcher2/FastBitmapDrawable.java b/src/com/android/launcher2/FastBitmapDrawable.java
index 9fa62da..d317d33 100644
--- a/src/com/android/launcher2/FastBitmapDrawable.java
+++ b/src/com/android/launcher2/FastBitmapDrawable.java
@@ -29,7 +29,7 @@
private int mAlpha;
private int mWidth;
private int mHeight;
- private final Paint mPaint = new Paint();
+ private final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
FastBitmapDrawable(Bitmap b) {
mAlpha = 255;
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 4e0f980..b7d4c8b 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -2015,6 +2015,7 @@
}
public boolean onLongClick(View v) {
+
if (mState != State.WORKSPACE) {
return false;
}
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index e64b0c3..0854508 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -580,7 +580,14 @@
// Calculate the variable page spacing if necessary
if (mPageSpacing < 0) {
- setPageSpacing(((right - left) - getChildAt(0).getMeasuredWidth()) / 2);
+ // The gap between pages in the PagedView should be equal to the gap from the page
+ // to the edge of the screen (so it is not visible in the current screen). To
+ // account for unequal padding on each side of the paged view, we take the maximum
+ // of the left/right gap and use that as the gap between each page.
+ int offset = getRelativeChildOffset(0);
+ int spacing = Math.max(offset, (right - left) - offset -
+ getChildAt(0).getMeasuredWidth());
+ setPageSpacing(spacing);
}
}
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index b7fdfe8..b8807a9 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -1902,10 +1902,14 @@
final Bitmap b = createDragBitmap(child, new Canvas(), DRAG_BITMAP_PADDING);
final int bmpWidth = b.getWidth();
+ final int bmpHeight = b.getHeight();
mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY);
- final int dragLayerX = (int) mTempXY[0] + (child.getWidth() - bmpWidth) / 2;
- int dragLayerY = mTempXY[1] - DRAG_BITMAP_PADDING / 2;
+ int dragLayerX =
+ Math.round(mTempXY[0] - (bmpWidth - child.getScaleX() * child.getWidth()) / 2);
+ int dragLayerY =
+ Math.round(mTempXY[1] - (bmpHeight - child.getScaleY() * bmpHeight) / 2
+ - DRAG_BITMAP_PADDING / 2);
Point dragVisualizeOffset = null;
Rect dragRect = null;
@@ -1934,7 +1938,7 @@
}
mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
- DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, 1f);
+ DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, child.getScaleX());
b.recycle();
// Show the scrolling indicator when you pick up an item