Commit eecf02da authored by Winson Chung's avatar Winson Chung
Browse files

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
parent 633f1aad
res/drawable-sw720dp-land-hdpi/divider_launcher_holo.9.png

199 Bytes

res/drawable-sw720dp-land-mdpi/divider_launcher_holo.9.png

1.05 KB

......@@ -33,7 +33,7 @@
<dimen name="workspace_bottom_padding">0dp</dimen>
<!-- We really want the page spacing to be the max of either the button bar
height or the qsb bar height -->
<dimen name="workspace_page_spacing">@dimen/button_bar_height</dimen>
<dimen name="workspace_page_spacing">-1dp</dimen>
<dimen name="workspace_divider_padding_left">0dp</dimen>
<dimen name="workspace_divider_padding_right">0dp</dimen>
<dimen name="workspace_divider_padding_top">12dp</dimen>
......
......@@ -21,7 +21,7 @@
<!-- Hotseat -->
<dimen name="hotseat_cell_width">75dp</dimen>
<dimen name="hotseat_cell_height">85dp</dimen>
<dimen name="hotseat_cell_height">75dp</dimen>
<!-- Workspace -->
<dimen name="workspace_cell_width">96dp</dimen>
......
......@@ -27,6 +27,9 @@
<dimen name="workspace_cell_width">96dip</dimen>
<dimen name="workspace_cell_height">96dip</dimen>
<dimen name="folder_cell_width">96dp</dimen>
<dimen name="folder_cell_height">96dp</dimen>
<!-- AppsCustomize -->
<integer name="apps_customize_maxCellCountX">-1</integer>
<integer name="apps_customize_maxCellCountY">-1</integer>
......@@ -49,5 +52,5 @@
<!-- When dragging items on the workspace, the number of dps by which the position of
the drag view should be offset from the position of the original view. -->
<dimen name="dragViewOffsetX">0dp</dimen>
<dimen name="dragViewOffsetY">-12dp</dimen>
<dimen name="dragViewOffsetY">0dp</dimen>
</resources>
......@@ -102,10 +102,10 @@
<!-- When dragging items on the workspace, the number of dps by which the position of
the drag view should be offset from the position of the original view. -->
<dimen name="dragViewOffsetX">0dp</dimen>
<dimen name="dragViewOffsetY">-8dp</dimen>
<dimen name="dragViewOffsetY">0dp</dimen>
<!-- When dragging an item, how much bigger (fixed dps) the dragged view
should be. If 0, it will not be scaled at all. -->
<dimen name="dragViewScale">8dp</dimen>
<dimen name="dragViewScale">12dp</dimen>
<!-- Padding applied to AppWidgets -->
<dimen name="app_widget_preview_padding_left">8dp</dimen>
......
......@@ -47,8 +47,6 @@ public class BubbleTextView extends TextView {
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 @@ public class BubbleTextView extends TextView {
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 @@ public class BubbleTextView extends TextView {
// 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 @@ public class BubbleTextView extends TextView {
protected boolean onSetAlpha(int alpha) {
if (mPrevAlpha != alpha) {
mPrevAlpha = alpha;
mPaint.setAlpha((int) (alpha * mBubbleColorAlpha));
super.onSetAlpha(alpha);
}
return true;
......
......@@ -137,8 +137,8 @@ public class CellLayout extends ViewGroup {
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 @@ public class CellLayout extends ViewGroup {
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 @@ public class CellLayout extends ViewGroup {
@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 @@ public class CellLayout extends ViewGroup {
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 @@ public class CellLayout extends ViewGroup {
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 @@ public class CellLayout extends ViewGroup {
// 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 class CellLayout extends ViewGroup {
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 @@ public class CellLayout extends ViewGroup {
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 @@ public class CellLayout extends ViewGroup {
if (action == MotionEvent.ACTION_DOWN) {
setTagToCellInfoForPoint((int) ev.getX(), (int) ev.getY());
}
return false;
}
......@@ -1978,8 +1968,8 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
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);
}
}
......
......@@ -18,10 +18,14 @@ package com.android.launcher2;
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";
......@@ -67,6 +71,22 @@ public class CellLayoutChildren extends ViewGroup {
return null;
}
@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();
......
......@@ -433,8 +433,10 @@ public class DragLayer extends FrameLayout {
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 @@ public class DragLayer extends FrameLayout {
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;
......
......@@ -162,7 +162,7 @@ public class DragView extends View {
// for debugging
Paint p = new Paint();
p.setStyle(Paint.Style.FILL);
p.setColor(0xaaffffff);
p.setColor(0x66ffffff);
canvas.drawRect(0, 0, getWidth(), getHeight(), p);
}
......
......@@ -29,7 +29,7 @@ class FastBitmapDrawable extends Drawable {
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;
......
......@@ -2015,6 +2015,7 @@ public final class Launcher extends Activity
}
public boolean onLongClick(View v) {
if (mState != State.WORKSPACE) {
return false;
}
......
......@@ -580,7 +580,14 @@ public abstract class PagedView extends ViewGroup {
// 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);
}
}
......
......@@ -1902,10 +1902,14 @@ public class Workspace extends SmoothPagedView
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 @@ public class Workspace extends SmoothPagedView
}
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment