summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/DragLayer.java
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2012-01-23 17:28:51 -0800
committerAdam Cohen <adamcohen@google.com>2012-02-13 13:30:32 -0800
commited66b2bac7447febe2e405b4ce725cae4f6b5988 (patch)
tree8c3e31c514a976a9d1e7045206e21da12c031559 /src/com/android/launcher2/DragLayer.java
parent933cc5061100f22c22d66d280b6fdd07634f45a6 (diff)
downloadandroid_packages_apps_Trebuchet-ed66b2bac7447febe2e405b4ce725cae4f6b5988.tar.gz
android_packages_apps_Trebuchet-ed66b2bac7447febe2e405b4ce725cae4f6b5988.tar.bz2
android_packages_apps_Trebuchet-ed66b2bac7447febe2e405b4ce725cae4f6b5988.zip
Improving widget transitions:
-> When a widget has no configuration activity, we bind and inflate it when the user picks it up. This allows us to smoothly transition between it's preview and some actual state of the widget when it is dropped. -> When a widget has a configuration activity, we delay the above process until the configuration activity has been run at which time we transition between the preview and the actual widget. Change-Id: I5265cd98400d70e5e75c3dcd21e322ed0b352d7b
Diffstat (limited to 'src/com/android/launcher2/DragLayer.java')
-rw-r--r--src/com/android/launcher2/DragLayer.java73
1 files changed, 52 insertions, 21 deletions
diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java
index c315b6018..6f3bcd1ac 100644
--- a/src/com/android/launcher2/DragLayer.java
+++ b/src/com/android/launcher2/DragLayer.java
@@ -67,12 +67,16 @@ public class DragLayer extends FrameLayout {
private View mAnchorView = null;
private int[] mDropViewPos = new int[2];
- private float mDropViewScale;
+ private float mDropViewScaleX;
+ private float mDropViewScaleY;
private float mDropViewAlpha;
private boolean mHoverPointClosesFolder = false;
private Rect mHitRect = new Rect();
private int mWorkspaceIndex = -1;
private int mQsbIndex = -1;
+ public static final int ANIMATION_END_DISAPPEAR = 0;
+ public static final int ANIMATION_END_FADE_OUT = 1;
+ public static final int ANIMATION_END_REMAIN_VISIBLE = 2;
/**
* Used to create a new DragLayer from XML.
@@ -414,15 +418,23 @@ public class DragLayer extends FrameLayout {
animateViewIntoPosition(dragView, child, null);
}
- public void animateViewIntoPosition(DragView dragView, final int[] pos, float scale,
- Runnable onFinishRunnable) {
+ public void animateViewIntoPosition(DragView dragView, final int[] pos, float scaleX, float
+ scaleY, int animationEndStyle, Runnable onFinishRunnable, int duration) {
Rect r = new Rect();
getViewRectRelativeToSelf(dragView, r);
final int fromX = r.left;
final int fromY = r.top;
- animateViewIntoPosition(dragView, fromX, fromY, pos[0], pos[1], scale,
- onFinishRunnable, true, -1, null);
+ animateViewIntoPosition(dragView, fromX, fromY, pos[0], pos[1], 1, 1, 1, scaleX, scaleY,
+ onFinishRunnable, animationEndStyle, duration, null);
+ }
+
+ public void scaleViewIntoPosition(DragView dragView, final int[] pos, float finalAlpha,
+ float scaleX, float scaleY, int animationEndStyle, Runnable onFinishRunnable,
+ int duration) {
+ animateViewIntoPosition(dragView, pos[0], pos[1], pos[0], pos[1], finalAlpha,
+ mDropViewScaleX, mDropViewScaleY, scaleX, scaleY, onFinishRunnable,
+ animationEndStyle, duration, null);
}
public void animateViewIntoPosition(DragView dragView, final View child,
@@ -486,18 +498,19 @@ public class DragLayer extends FrameLayout {
oa.start();
}
};
- animateViewIntoPosition(dragView, fromX, fromY, toX, toY, scale,
- onCompleteRunnable, true, duration, anchorView);
+ animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, scale, scale,
+ onCompleteRunnable, ANIMATION_END_FADE_OUT, duration, anchorView);
}
private void animateViewIntoPosition(final View view, final int fromX, final int fromY,
- final int toX, final int toY, float finalScale, Runnable onCompleteRunnable,
- boolean fadeOut, int duration, View anchorView) {
+ final int toX, final int toY, float finalAlpha, float initScaleX, float initScaleY,
+ float finalScaleX, float finalScaleY, Runnable onCompleteRunnable,
+ int animationEndStyle, int duration, View anchorView) {
Rect from = new Rect(fromX, fromY, fromX +
view.getMeasuredWidth(), fromY + view.getMeasuredHeight());
Rect to = new Rect(toX, toY, toX + view.getMeasuredWidth(), toY + view.getMeasuredHeight());
- animateView(view, from, to, 1f, finalScale, duration, null, null,
- onCompleteRunnable, true, anchorView);
+ animateView(view, from, to, finalAlpha, initScaleX, initScaleY, finalScaleX, finalScaleY, duration,
+ null, null, onCompleteRunnable, animationEndStyle, anchorView);
}
/**
@@ -522,9 +535,10 @@ public class DragLayer extends FrameLayout {
* only used for the X dimension for the case of the workspace.
*/
public void animateView(final View view, final Rect from, final Rect to, final float finalAlpha,
- final float finalScale, int duration, final Interpolator motionInterpolator,
+ final float initScaleX, final float initScaleY, final float finalScaleX,
+ final float finalScaleY, int duration, final Interpolator motionInterpolator,
final Interpolator alphaInterpolator, final Runnable onCompleteRunnable,
- final boolean fadeOut, View anchorView) {
+ final int animationEndStyle, View anchorView) {
// Calculate the duration of the animation based on the object's distance
final float dist = (float) Math.sqrt(Math.pow(to.left - from.left, 2) +
Math.pow(to.top - from.top, 2));
@@ -578,10 +592,10 @@ public class DragLayer extends FrameLayout {
mDropViewPos[0] = from.left + (int) Math.round(((to.left - from.left) * motionPercent));
mDropViewPos[1] = from.top + (int) Math.round(((to.top - from.top) * motionPercent));
- mDropViewScale = percent * finalScale + (1 - percent);
+ mDropViewScaleX = percent * finalScaleX + (1 - percent) * initScaleX;
+ mDropViewScaleY = percent * finalScaleY + (1 - percent) * initScaleY;
mDropViewAlpha = alphaPercent * finalAlpha + (1 - alphaPercent) * initialAlpha;
- invalidate(mDropViewPos[0], mDropViewPos[1],
- mDropViewPos[0] + width, mDropViewPos[1] + height);
+ invalidate();
}
});
mDropAnim.addListener(new AnimatorListenerAdapter() {
@@ -589,16 +603,32 @@ public class DragLayer extends FrameLayout {
if (onCompleteRunnable != null) {
onCompleteRunnable.run();
}
- if (fadeOut) {
+ switch (animationEndStyle) {
+ case ANIMATION_END_DISAPPEAR:
+ clearAnimatedView();
+ break;
+ case ANIMATION_END_FADE_OUT:
fadeOutDragView();
- } else {
- mDropView = null;
+ break;
+ case ANIMATION_END_REMAIN_VISIBLE:
+ break;
}
}
});
mDropAnim.start();
}
+ public void clearAnimatedView() {
+ mDropView = null;
+ mDropViewScaleX = 1;
+ mDropViewScaleY = 1;
+ invalidate();
+ }
+
+ public View getAnimatedView() {
+ return mDropView;
+ }
+
private void fadeOutDragView() {
mFadeOutAnim = new ValueAnimator();
mFadeOutAnim.setDuration(150);
@@ -617,6 +647,7 @@ public class DragLayer extends FrameLayout {
mFadeOutAnim.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animation) {
mDropView = null;
+ invalidate();
}
});
mFadeOutAnim.start();
@@ -679,8 +710,8 @@ public class DragLayer extends FrameLayout {
int width = mDropView.getMeasuredWidth();
int height = mDropView.getMeasuredHeight();
canvas.translate(xPos, yPos);
- canvas.translate((1 - mDropViewScale) * width / 2, (1 - mDropViewScale) * height / 2);
- canvas.scale(mDropViewScale, mDropViewScale);
+ canvas.translate((1 - mDropViewScaleX) * width / 2, (1 - mDropViewScaleY) * height / 2);
+ canvas.scale(mDropViewScaleX, mDropViewScaleY);
mDropView.setAlpha(mDropViewAlpha);
mDropView.draw(canvas);
canvas.restore();