summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2010-10-14 09:01:34 -0700
committerMichael Jurka <mikejurka@google.com>2010-10-18 18:29:21 -0700
commit18014791be2e3f41080f0bf621c618e3f096c5c7 (patch)
tree98723a50d26087cd7043eb7afd86c5cb36a90fd4
parent1adf5391a3a3d215b226adf3702019c22a99e3b1 (diff)
downloadandroid_packages_apps_Trebuchet-18014791be2e3f41080f0bf621c618e3f096c5c7.tar.gz
android_packages_apps_Trebuchet-18014791be2e3f41080f0bf621c618e3f096c5c7.tar.bz2
android_packages_apps_Trebuchet-18014791be2e3f41080f0bf621c618e3f096c5c7.zip
Added bounce animation when item added to screens
Change-Id: I87d9e8545e2de588d083b48991d932eb904f6e3a
-rw-r--r--res/values-xlarge/config.xml9
-rw-r--r--src/com/android/launcher2/CellLayout.java109
-rw-r--r--src/com/android/launcher2/Workspace.java11
3 files changed, 108 insertions, 21 deletions
diff --git a/res/values-xlarge/config.xml b/res/values-xlarge/config.xml
index 73e714620..6a566799a 100644
--- a/res/values-xlarge/config.xml
+++ b/res/values-xlarge/config.xml
@@ -36,4 +36,13 @@
the drag view should be offset from the position of the original view. -->
<integer name="config_dragViewOffsetX">0</integer>
<integer name="config_dragViewOffsetY">12</integer>
+
+ <!-- When items are dropped on the mini screens in customize mode, we have a bounce animation
+ of the bright green hover outline, and then fade out the outline at the end. These are
+ the values used in that animation -->
+ <integer name="config_screenOnDropScalePercent">120</integer>
+ <integer name="config_screenOnDropScaleUpDuration">200</integer>
+ <integer name="config_screenOnDropScaleDownDuration">200</integer>
+ <integer name="config_screenOnDropAlphaFadeDelay">350</integer>
+ <integer name="config_screenOnDropAlphaFadeDuration">50</integer>
</resources>
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 018a9663a..29ff679ba 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -20,6 +20,8 @@ import com.android.launcher.R;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
@@ -34,6 +36,7 @@ import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
+import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
@@ -84,6 +87,10 @@ public class CellLayout extends ViewGroup implements Dimmable {
private Drawable mBackgroundMiniHover;
private Drawable mBackgroundHover;
private Drawable mBackgroundMiniAcceptsDrops;
+ 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
@@ -238,6 +245,69 @@ public class CellLayout extends ViewGroup implements Dimmable {
});
mDragOutlineAnims[i] = anim;
}
+ mBackgroundRect = new Rect();
+ mHoverRect = new Rect();
+ setHoverScale(1.0f);
+ setHoverAlpha(1.0f);
+ }
+
+ private void updateHoverRect() {
+ float marginFraction = (mHoverScale - 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,
+ mBackgroundRect.right + marginX, mBackgroundRect.bottom + marginY);
+ invalidate();
+ }
+
+ public void setHoverScale(float scaleFactor) {
+ if (scaleFactor != mHoverScale) {
+ mHoverScale = scaleFactor;
+ updateHoverRect();
+ }
+ }
+
+ public float getHoverScale() {
+ return mHoverScale;
+ }
+
+ public float getHoverAlpha() {
+ return mHoverAlpha;
+ }
+
+ public void setHoverAlpha(float alpha) {
+ mHoverAlpha = alpha;
+ invalidate();
+ }
+
+ void animateDrop() {
+ if (LauncherApplication.isScreenXLarge()) {
+ Resources res = getResources();
+ float onDropScale = res.getInteger(R.integer.config_screenOnDropScalePercent) / 100.0f;
+ ObjectAnimator scaleUp = ObjectAnimator.ofFloat(this, "hoverScale", onDropScale);
+ scaleUp.setDuration(res.getInteger(R.integer.config_screenOnDropScaleUpDuration));
+ ObjectAnimator scaleDown = ObjectAnimator.ofFloat(this, "hoverScale", 1.0f);
+ scaleDown.setDuration(res.getInteger(R.integer.config_screenOnDropScaleDownDuration));
+ ObjectAnimator alphaFadeOut = ObjectAnimator.ofFloat(this, "hoverAlpha", 0.0f);
+
+ alphaFadeOut.setStartDelay(res.getInteger(R.integer.config_screenOnDropAlphaFadeDelay));
+ alphaFadeOut.setDuration(res.getInteger(R.integer.config_screenOnDropAlphaFadeDelay));
+
+ AnimatorSet bouncer = new AnimatorSet();
+ bouncer.play(scaleUp).before(scaleDown);
+ bouncer.play(scaleUp).with(alphaFadeOut);
+ bouncer.addListener(new AnimatorListenerAdapter() {
+ public void onAnimationStart(Animator animation) {
+ setHover(true);
+ }
+ public void onAnimationEnd(Animator animation) {
+ setHover(false);
+ setHoverScale(1.0f);
+ setHoverAlpha(1.0f);
+ }
+ });
+ bouncer.start();
+ }
}
public void setHover(boolean value) {
@@ -267,11 +337,31 @@ public class CellLayout extends ViewGroup implements Dimmable {
}
if (bg != null) {
bg.setAlpha((int) (mBackgroundAlpha * 255));
+ bg.setBounds(mBackgroundRect);
bg.draw(canvas);
}
if (mHover && getScaleX() < 0.5f) {
- mBackgroundMiniHover.setAlpha((int) (mBackgroundAlpha * 255));
+ boolean modifiedClipRect = false;
+ if (mHoverScale > 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;
+ Rect clipRect = canvas.getClipBounds();
+ int marginX = (int) (marginFraction * (clipRect.right - clipRect.left));
+ int marginY = (int) (marginFraction * (clipRect.bottom - clipRect.top));
+ canvas.save(Canvas.CLIP_SAVE_FLAG);
+ canvas.clipRect(-marginX, -marginY,
+ getWidth() + marginX, getHeight() + marginY, Region.Op.REPLACE);
+ modifiedClipRect = true;
+ }
+
+ mBackgroundMiniHover.setAlpha((int) (mBackgroundAlpha * mHoverAlpha * 255));
+ mBackgroundMiniHover.setBounds(mHoverRect);
mBackgroundMiniHover.draw(canvas);
+ if (modifiedClipRect) {
+ canvas.restore();
+ }
}
}
@@ -692,21 +782,8 @@ public class CellLayout extends ViewGroup implements Dimmable {
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
- if (mBackground != null) {
- mBackground.setBounds(0, 0, w, h);
- }
- if (mBackgroundHover != null) {
- mBackgroundHover.setBounds(0, 0, w, h);
- }
- if (mBackgroundMiniHover != null) {
- mBackgroundMiniHover.setBounds(0, 0, w, h);
- }
- if (mBackgroundMini != null) {
- mBackgroundMini.setBounds(0, 0, w, h);
- }
- if (mBackgroundMiniAcceptsDrops != null) {
- mBackgroundMiniAcceptsDrops.setBounds(0, 0, w, h);
- }
+ mBackgroundRect.set(0, 0, w, h);
+ updateHoverRect();
}
@Override
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 8f5a11551..a82cb7f00 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -16,14 +16,14 @@
package com.android.launcher2;
-import android.animation.AnimatorListenerAdapter;
import com.android.launcher.R;
import android.animation.Animator;
-import android.animation.Animator.AnimatorListener;
+import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
+import android.animation.Animator.AnimatorListener;
import android.app.WallpaperManager;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
@@ -36,7 +36,6 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
-import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.Region.Op;
@@ -1115,8 +1114,8 @@ public class Workspace extends SmoothPagedView
}
}
- public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
- DragView dragView, Object dragInfo) {
+ public DropTarget getDropTargetDelegate(DragSource source, int x, int y,
+ int xOffset, int yOffset, DragView dragView, Object dragInfo) {
if (mIsSmall || mIsInUnshrinkAnimation) {
// If we're shrunken, don't let anyone drag on folders/etc that are on the mini-screens
@@ -1435,6 +1434,7 @@ public class Workspace extends SmoothPagedView
throw new IllegalStateException("Unknown item type: " + info.itemType);
}
cellLayout.onDragExit();
+ cellLayout.animateDrop();
return;
}
@@ -1469,6 +1469,7 @@ public class Workspace extends SmoothPagedView
addInScreen(view, indexOfChild(cellLayout), mTargetCell[0],
mTargetCell[1], info.spanX, info.spanY, insertAtFirst);
cellLayout.onDropChild(view);
+ cellLayout.animateDrop();
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
LauncherModel.addOrMoveItemInDatabase(mLauncher, info,