summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/launcher2/CellLayout.java173
-rw-r--r--src/com/android/launcher2/Workspace.java27
2 files changed, 113 insertions, 87 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 505d465..70fe8f9 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -69,7 +69,6 @@ public class CellLayout extends ViewGroup implements Dimmable {
private int mHeightGap;
private final Rect mRect = new Rect();
- private final RectF mRectF = new RectF();
private final CellInfo mCellInfo = new CellInfo();
// These are temporary variables to prevent having to allocate a new object just to
@@ -85,20 +84,24 @@ public class CellLayout extends ViewGroup implements Dimmable {
private float mBackgroundAlpha;
private float mBackgroundAlphaMultiplier = 1.0f;
- private Drawable mBackground;
- private Drawable mBackgroundMini;
- private Drawable mBackgroundMiniHover;
- private Drawable mBackgroundHover;
- private Drawable mBackgroundMiniAcceptsDrops;
+ private Drawable mNormalBackground;
+ private Drawable mNormalGlowBackground;
+ private Drawable mActiveBackground;
+ private Drawable mActiveGlowBackground;
+ private Drawable mNormalBackgroundMini;
+ private Drawable mNormalGlowBackgroundMini;
+ private Drawable mActiveBackgroundMini;
+ private Drawable mActiveGlowBackgroundMini;
private Rect mBackgroundRect;
- private Rect mHoverRect;
- private float mHoverScale;
- private float mHoverAlpha;
- private boolean mAcceptsDrops;
-
- // If we're actively dragging something over this screen, mHover is true
- private boolean mHover = false;
-
+ private Rect mGlowBackgroundRect;
+ private float mGlowBackgroundScale;
+ private float mGlowBackgroundAlpha;
+
+ private boolean mAcceptsDrops = false;
+ // If we're actively dragging something over this screen, mIsDragOverlapping is true
+ private boolean mIsDragOverlapping = false;
+ private boolean mIsDragOccuring = false;
+ private boolean mIsDefaultDropTarget = false;
private final Point mDragCenter = new Point();
// These arrays are used to implement the drag visualization on x-large screens.
@@ -169,17 +172,24 @@ public class CellLayout extends ViewGroup implements Dimmable {
final Resources res = getResources();
if (LauncherApplication.isScreenXLarge()) {
- mBackgroundMini = res.getDrawable(R.drawable.homescreen_small_blue);
- mBackgroundMini.setFilterBitmap(true);
- mBackground = res.getDrawable(R.drawable.homescreen_large_blue);
- mBackground.setFilterBitmap(true);
- mBackgroundMiniHover = res.getDrawable(R.drawable.homescreen_small_green_strong);
- mBackgroundMiniHover.setFilterBitmap(true);
- mBackgroundHover = res.getDrawable(R.drawable.homescreen_large_green_strong);
- mBackgroundHover.setFilterBitmap(true);
- mBackgroundMiniAcceptsDrops = res.getDrawable(
- R.drawable.homescreen_small_green);
- mBackgroundMiniAcceptsDrops.setFilterBitmap(true);
+ mNormalBackground = res.getDrawable(R.drawable.homescreen_large_blue);
+ mNormalGlowBackground = res.getDrawable(R.drawable.homescreen_large_blue_strong);
+ mActiveBackground = res.getDrawable(R.drawable.homescreen_large_green);
+ mActiveGlowBackground = res.getDrawable(R.drawable.homescreen_large_green_strong);
+
+ mNormalBackgroundMini = res.getDrawable(R.drawable.homescreen_small_blue);
+ mNormalGlowBackgroundMini = res.getDrawable(R.drawable.homescreen_small_blue_strong);
+ mActiveBackgroundMini = res.getDrawable(R.drawable.homescreen_small_green);
+ mActiveGlowBackgroundMini = res.getDrawable(R.drawable.homescreen_small_green_strong);
+
+ mNormalBackground.setFilterBitmap(true);
+ mNormalGlowBackground.setFilterBitmap(true);
+ mActiveBackground.setFilterBitmap(true);
+ mActiveGlowBackground.setFilterBitmap(true);
+ mNormalBackgroundMini.setFilterBitmap(true);
+ mNormalGlowBackgroundMini.setFilterBitmap(true);
+ mActiveBackgroundMini.setFilterBitmap(true);
+ mActiveGlowBackgroundMini.setFilterBitmap(true);
}
// Initialize the data structures used for the drag visualization.
@@ -254,37 +264,69 @@ public class CellLayout extends ViewGroup implements Dimmable {
}
mBackgroundRect = new Rect();
- mHoverRect = new Rect();
+ mGlowBackgroundRect = new Rect();
setHoverScale(1.0f);
setHoverAlpha(1.0f);
}
- private void updateHoverRect() {
- float marginFraction = (mHoverScale - 1.0f) / 2.0f;
+ public void setIsDefaultDropTarget(boolean isDefaultDropTarget) {
+ if (mIsDefaultDropTarget != isDefaultDropTarget) {
+ mIsDefaultDropTarget = isDefaultDropTarget;
+ invalidate();
+ }
+ }
+
+ public void setAcceptsDrops(boolean acceptsDrops) {
+ if (mAcceptsDrops != acceptsDrops) {
+ mAcceptsDrops = acceptsDrops;
+ invalidate();
+ }
+ }
+
+ void setIsDragOccuring(boolean isDragOccuring) {
+ if (mIsDragOccuring != isDragOccuring) {
+ mIsDragOccuring = isDragOccuring;
+ invalidate();
+ }
+ }
+
+ void setIsDragOverlapping(boolean isDragOverlapping) {
+ if (mIsDragOverlapping != isDragOverlapping) {
+ mIsDragOverlapping = isDragOverlapping;
+ invalidate();
+ }
+ }
+
+ boolean getIsDragOverlapping() {
+ return mIsDragOverlapping;
+ }
+
+ private void updateGlowRect() {
+ float marginFraction = (mGlowBackgroundScale - 1.0f) / 2.0f;
int marginX = (int) (marginFraction * (mBackgroundRect.right - mBackgroundRect.left));
int marginY = (int) (marginFraction * (mBackgroundRect.bottom - mBackgroundRect.top));
- mHoverRect.set(mBackgroundRect.left - marginX, mBackgroundRect.top - marginY,
+ mGlowBackgroundRect.set(mBackgroundRect.left - marginX, mBackgroundRect.top - marginY,
mBackgroundRect.right + marginX, mBackgroundRect.bottom + marginY);
invalidate();
}
public void setHoverScale(float scaleFactor) {
- if (scaleFactor != mHoverScale) {
- mHoverScale = scaleFactor;
- updateHoverRect();
+ if (scaleFactor != mGlowBackgroundScale) {
+ mGlowBackgroundScale = scaleFactor;
+ updateGlowRect();
}
}
public float getHoverScale() {
- return mHoverScale;
+ return mGlowBackgroundScale;
}
public float getHoverAlpha() {
- return mHoverAlpha;
+ return mGlowBackgroundAlpha;
}
public void setHoverAlpha(float alpha) {
- mHoverAlpha = alpha;
+ mGlowBackgroundAlpha = alpha;
invalidate();
}
@@ -307,11 +349,11 @@ public class CellLayout extends ViewGroup implements Dimmable {
bouncer.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
- setHover(true);
+ setIsDragOverlapping(true);
}
@Override
public void onAnimationEnd(Animator animation) {
- setHover(false);
+ setIsDragOverlapping(false);
setHoverScale(1.0f);
setHoverAlpha(1.0f);
}
@@ -320,17 +362,6 @@ public class CellLayout extends ViewGroup implements Dimmable {
}
}
- public void setHover(boolean value) {
- if (mHover != value) {
- mHover = value;
- invalidate();
- }
- }
-
- public boolean getHover() {
- return mHover;
- }
-
public void drawChildren(Canvas canvas) {
super.dispatchDraw(canvas);
}
@@ -344,23 +375,30 @@ public class CellLayout extends ViewGroup implements Dimmable {
// backgrounds
if (mBackgroundAlpha > 0.0f) {
Drawable bg;
- if (getScaleX() < 0.5f) {
- bg = mAcceptsDrops ? mBackgroundMiniAcceptsDrops : mBackgroundMini;
+ boolean mini = getScaleX() < 0.5f;
+
+ if (mIsDragOverlapping) {
+ // In the mini case, we draw the active_glow bg *over* the active background
+ bg = mini ? mActiveBackgroundMini : mActiveGlowBackground;
+ } else if (mIsDragOccuring && mAcceptsDrops) {
+ bg = mini ? mActiveBackgroundMini : mActiveBackground;
+ } else if (mIsDefaultDropTarget) {
+ bg = mini ? mNormalGlowBackgroundMini : mNormalGlowBackground;
} else {
- bg = mHover ? mBackgroundHover : mBackground;
+ bg = mini ? mNormalBackgroundMini : mNormalBackground;
}
- if (bg != null) {
- bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255));
- bg.setBounds(mBackgroundRect);
- bg.draw(canvas);
- }
- if (mHover && getScaleX() < 0.5f) {
+
+ bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255));
+ bg.setBounds(mBackgroundRect);
+ bg.draw(canvas);
+
+ if (mini && mIsDragOverlapping) {
boolean modifiedClipRect = false;
- if (mHoverScale > 1.0f) {
+ if (mGlowBackgroundScale > 1.0f) {
// If the hover background's scale is greater than 1, we'll be drawing outside
// the bounds of this CellLayout. Get around that by temporarily increasing the
// size of the clip rect
- float marginFraction = (mHoverScale - 1.0f) / 2.0f;
+ float marginFraction = (mGlowBackgroundScale - 1.0f) / 2.0f;
Rect clipRect = canvas.getClipBounds();
int marginX = (int) (marginFraction * (clipRect.right - clipRect.left));
int marginY = (int) (marginFraction * (clipRect.bottom - clipRect.top));
@@ -370,9 +408,10 @@ public class CellLayout extends ViewGroup implements Dimmable {
modifiedClipRect = true;
}
- mBackgroundMiniHover.setAlpha((int) (mBackgroundAlpha * mHoverAlpha * 255));
- mBackgroundMiniHover.setBounds(mHoverRect);
- mBackgroundMiniHover.draw(canvas);
+ mActiveGlowBackgroundMini.setAlpha(
+ (int) (mBackgroundAlpha * mGlowBackgroundAlpha * 255));
+ mActiveGlowBackgroundMini.setBounds(mGlowBackgroundRect);
+ mActiveGlowBackgroundMini.draw(canvas);
if (modifiedClipRect) {
canvas.restore();
}
@@ -490,12 +529,6 @@ public class CellLayout extends ViewGroup implements Dimmable {
}
return false;
}
- public void setAcceptsDrops(boolean acceptsDrops) {
- if (mAcceptsDrops != acceptsDrops) {
- mAcceptsDrops = acceptsDrops;
- invalidate();
- }
- }
public boolean getAcceptsDrops() {
return mAcceptsDrops;
@@ -814,7 +847,7 @@ public class CellLayout extends ViewGroup implements Dimmable {
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mBackgroundRect.set(0, 0, w, h);
- updateHoverRect();
+ updateGlowRect();
}
@Override
@@ -1204,7 +1237,7 @@ public class CellLayout extends ViewGroup implements Dimmable {
mDragOutlineAnims[mDragOutlineCurrent].animateOut();
mDragOutlineCurrent = (mDragOutlineCurrent + 1) % mDragOutlineAnims.length;
- setHover(false);
+ setIsDragOverlapping(false);
}
/**
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index a066a16..0352176 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -87,7 +87,6 @@ public class Workspace extends SmoothPagedView
// Y rotation to apply to the workspace screens
private static final float WORKSPACE_ROTATION = 12.5f;
- private static final float WORKSPACE_TRANSLATION = 50.0f;
// These are extra scale factors to apply to the mini home screens
// so as to achieve the desired transform
@@ -807,11 +806,11 @@ public class Workspace extends SmoothPagedView
final CellLayout leftPage = (CellLayout) getChildAt(mCurrentPage - 1);
final CellLayout rightPage = (CellLayout) getChildAt(mCurrentPage + 1);
- if (leftPage != null && leftPage.getHover()) {
+ if (leftPage != null && leftPage.getIsDragOverlapping()) {
final Drawable d = getResources().getDrawable(R.drawable.page_hover_left);
d.setBounds(mScrollX, padding, mScrollX + d.getIntrinsicWidth(), height - padding);
d.draw(canvas);
- } else if (rightPage != null && rightPage.getHover()) {
+ } else if (rightPage != null && rightPage.getIsDragOverlapping()) {
final Drawable d = getResources().getDrawable(R.drawable.page_hover_right);
d.setBounds(mScrollX + width - d.getIntrinsicWidth(), padding, mScrollX + width, height - padding);
d.draw(canvas);
@@ -1156,15 +1155,10 @@ public class Workspace extends SmoothPagedView
final int screenCount = getChildCount();
for (int i = 0; i < screenCount; i++) {
CellLayout cl = (CellLayout) getChildAt(i);
-
+ cl.setIsDragOccuring(isDragHappening);
switch (state) {
case TOP:
- if (!isDragHappening) {
- boolean showDropHighlight = i == mCurrentPage;
- cl.setAcceptsDrops(showDropHighlight);
- break;
- }
- // otherwise, fall through below and mark non-full screens as accepting drops
+ cl.setIsDefaultDropTarget(i == mCurrentPage);
case BOTTOM_HIDDEN:
case BOTTOM_VISIBLE:
if (!isDragHappening) {
@@ -1781,7 +1775,7 @@ public class Workspace extends SmoothPagedView
// Show the current page outlines to indicate that we can accept this drop
showOutlines();
- layout.setHover(true);
+ layout.setIsDragOccuring(true);
layout.onDragEnter();
layout.visualizeDropLocation(null, mDragOutline, x, y, 1, 1);
@@ -1793,7 +1787,6 @@ public class Workspace extends SmoothPagedView
return true;
case DragEvent.ACTION_DROP: {
// Try and add any shortcuts
- int newDropCount = 0;
final LauncherModel model = mLauncher.getModel();
final ClipData data = event.getClipData();
@@ -1842,7 +1835,7 @@ public class Workspace extends SmoothPagedView
}
case DragEvent.ACTION_DRAG_ENDED:
// Hide the page outlines after the drop
- layout.setHover(false);
+ layout.setIsDragOccuring(false);
layout.onDragExit();
hideOutlines();
return true;
@@ -2008,12 +2001,12 @@ public class Workspace extends SmoothPagedView
if (layout != mDragTargetLayout) {
if (mDragTargetLayout != null) {
- mDragTargetLayout.setHover(false);
+ mDragTargetLayout.setIsDragOverlapping(false);
mSpringLoadedDragController.onDragExit();
}
mDragTargetLayout = layout;
if (mDragTargetLayout != null && mDragTargetLayout.getAcceptsDrops()) {
- mDragTargetLayout.setHover(true);
+ mDragTargetLayout.setIsDragOverlapping(true);
mSpringLoadedDragController.onDragEnter(mDragTargetLayout);
}
}
@@ -2290,7 +2283,7 @@ public class Workspace extends SmoothPagedView
final CellLayout layout = (CellLayout) getChildAt(page);
if (layout != null) {
- layout.setHover(true);
+ layout.setIsDragOverlapping(true);
if (mDragTargetLayout != null) {
mDragTargetLayout.onDragExit();
@@ -2303,7 +2296,7 @@ public class Workspace extends SmoothPagedView
private void clearAllHovers() {
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
- ((CellLayout) getChildAt(i)).setHover(false);
+ ((CellLayout) getChildAt(i)).setIsDragOverlapping(false);
}
mSpringLoadedDragController.onDragExit();
}