-Added 3D effect to home screen scrolling

-Added background outline fade in / out
-Modified the feel of scrolling: now using quintic
 interpolator and modified the influence of
 scroll velocity

Change-Id: Ifddcab5223ac20be7d9f800ccf09442d9b4db781

Conflicts:

	src/com/android/launcher2/CellLayout.java
This commit is contained in:
Adam Cohen
2010-09-30 14:11:56 -07:00
parent 3fb4fc921f
commit f34bab59fc
8 changed files with 267 additions and 123 deletions
+138 -8
View File
@@ -33,7 +33,9 @@ import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
@@ -63,8 +65,8 @@ public class Workspace extends SmoothPagedView
// customization mode
private static final float SHRINK_FACTOR = 0.16f;
// The maximum Y rotation to apply to the mini home screens
private static final float MINI_PAGE_MAX_ROTATION = 25.0f;
// Y rotation to apply to the workspace screens
private static final float WORKSPACE_ROTATION = 12.5f;
// These are extra scale factors to apply to the mini home screens
// so as to achieve the desired transform
@@ -72,6 +74,18 @@ public class Workspace extends SmoothPagedView
private static final float EXTRA_SCALE_FACTOR_1 = 1.0f;
private static final float EXTRA_SCALE_FACTOR_2 = 1.08f;
private static final int BACKGROUND_FADE_OUT_DELAY = 300;
private static final int BACKGROUND_FADE_OUT_DURATION = 300;
private static final int BACKGROUND_FADE_IN_DURATION = 100;
static final int SCROLL_RIGHT = 0;
static final int SCROLL_LEFT = 1;
// These animators are used to fade the
private ObjectAnimator<Float> mBackgroundFadeIn;
private ObjectAnimator<Float> mBackgroundFadeOut;
private float mBackgroundAlpha = 0;
private enum ShrinkPosition { SHRINK_TO_TOP, SHRINK_TO_MIDDLE, SHRINK_TO_BOTTOM };
private final WallpaperManager mWallpaperManager;
@@ -179,6 +193,15 @@ public class Workspace extends SmoothPagedView
mSnapVelocity = 600;
}
@Override
protected int getScrollMode() {
if (LauncherApplication.isScreenXLarge()) {
return SmoothPagedView.QUINTIC_MODE;
} else {
return SmoothPagedView.OVERSHOOT_MODE;
}
}
@Override
public void addView(View child, int index, LayoutParams params) {
if (!(child instanceof CellLayout)) {
@@ -382,12 +405,14 @@ public class Workspace extends SmoothPagedView
enableChildrenCache(mCurrentPage - 1, mCurrentPage + 1);
}
}
showOutlines();
}
protected void pageEndMoving() {
if (!LauncherApplication.isScreenXLarge()) {
clearChildrenCache();
}
hideOutlines();
}
@Override
@@ -424,6 +449,99 @@ public class Workspace extends SmoothPagedView
}
}
private float getScaleXForRotation(float degrees) {
return (float) (1.0f / Math.cos(Math.PI * degrees / 180.0f));
}
public void showOutlines() {
if (mBackgroundFadeOut != null) mBackgroundFadeOut.cancel();
if (mBackgroundFadeIn != null) mBackgroundFadeIn.cancel();
mBackgroundFadeIn = new ObjectAnimator<Float>(BACKGROUND_FADE_IN_DURATION, this,
new PropertyValuesHolder<Float>("backgroundAlpha", 1.0f));
mBackgroundFadeIn.start();
}
public void hideOutlines() {
if (mBackgroundFadeIn != null) mBackgroundFadeIn.cancel();
if (mBackgroundFadeOut != null) mBackgroundFadeOut.cancel();
mBackgroundFadeOut = new ObjectAnimator<Float>(BACKGROUND_FADE_OUT_DURATION, this,
new PropertyValuesHolder<Float>("backgroundAlpha", 0.0f));
mBackgroundFadeOut.setStartDelay(BACKGROUND_FADE_OUT_DELAY);
mBackgroundFadeOut.start();
}
public void setBackgroundAlpha(float alpha) {
mBackgroundAlpha = alpha;
for (int i = 0; i < getChildCount(); i++) {
CellLayout cl = (CellLayout) getChildAt(i);
cl.setBackgroundAlpha(alpha);
}
}
public float getBackgroundAlpha() {
return mBackgroundAlpha;
}
@Override
protected void screenScrolled(int screenCenter) {
View cur = getChildAt(mCurrentPage);
View toRight = getChildAt(mCurrentPage + 1);
View toLeft = getChildAt(mCurrentPage - 1);
for (int i = 0; i < mCurrentPage - 1; i++) {
View v = getChildAt(i);
if (v != null) {
v.setRotationY(WORKSPACE_ROTATION);
v.setScaleX(getScaleXForRotation(WORKSPACE_ROTATION));
}
}
for (int i = mCurrentPage + 1; i < getChildCount(); i++) {
View v = getChildAt(i);
if (v != null) {
v.setRotationY(-WORKSPACE_ROTATION);
v.setScaleX(getScaleXForRotation(-WORKSPACE_ROTATION));
}
}
int pageWidth = cur.getMeasuredWidth();
int delta = screenCenter - (mCurrentPage * pageWidth + pageWidth / 2 +
getRelativeChildOffset(0));
float scrollProgress = Math.abs(delta/(pageWidth*1.0f));
int scrollDirection = delta > 0 ? SCROLL_LEFT : SCROLL_RIGHT;
float rotation;
if (scrollDirection == SCROLL_RIGHT) {
rotation = -scrollProgress * WORKSPACE_ROTATION;
cur.setRotationY(rotation);
cur.setScaleX(getScaleXForRotation(rotation));
if (toLeft != null) {
rotation = WORKSPACE_ROTATION * (1 - scrollProgress);
toLeft.setRotationY(rotation);
toLeft.setScaleX(getScaleXForRotation(rotation));
}
if (toRight != null) {
toRight.setRotationY(-WORKSPACE_ROTATION);
toRight.setScaleX(getScaleXForRotation(WORKSPACE_ROTATION));
}
} else {
rotation = scrollProgress * WORKSPACE_ROTATION;
cur.setRotationY(rotation);
cur.setScaleX(getScaleXForRotation(rotation));
if (toRight != null) {
rotation = -WORKSPACE_ROTATION * (1 - scrollProgress);
toRight.setRotationY(rotation);
toRight.setScaleX(getScaleXForRotation(rotation));
}
if (toLeft != null) {
toLeft.setRotationY(WORKSPACE_ROTATION);
toLeft.setScaleX(getScaleXForRotation(WORKSPACE_ROTATION));
}
}
}
protected void onAttachedToWindow() {
super.onAttachedToWindow();
computeScroll();
@@ -624,7 +742,7 @@ public class Workspace extends SmoothPagedView
for (int i = 0; i < screenCount; i++) {
CellLayout cl = (CellLayout) getChildAt(i);
float rotation = (-i + 2) * MINI_PAGE_MAX_ROTATION / 2.0f;
float rotation = (-i + 2) * WORKSPACE_ROTATION;
float rotationScaleX = (float) (1.0f / Math.cos(Math.PI * rotation / 180.0f));
float rotationScaleY = getYScaleForScreen(i);
@@ -636,14 +754,16 @@ public class Workspace extends SmoothPagedView
new PropertyValuesHolder<Float>("scaleX", SHRINK_FACTOR * rotationScaleX),
new PropertyValuesHolder<Float>("scaleY", SHRINK_FACTOR * rotationScaleY),
new PropertyValuesHolder<Float>("backgroundAlpha", 1.0f),
new PropertyValuesHolder<Float>("dimmableProgress", 1.0f),
new PropertyValuesHolder<Float>("alpha", 0.0f),
new PropertyValuesHolder<Float>("rotationY", rotation)).start();
} else {
cl.setX((int)newX);
cl.setY((int)newY);
cl.setScaleX(SHRINK_FACTOR);
cl.setScaleY(SHRINK_FACTOR);
cl.setScaleX(SHRINK_FACTOR * rotationScaleX);
cl.setScaleY(SHRINK_FACTOR * rotationScaleY);
cl.setBackgroundAlpha(1.0f);
cl.setDimmableProgress(1.0f);
cl.setAlpha(0.0f);
cl.setRotationY(rotation);
}
@@ -696,6 +816,14 @@ public class Workspace extends SmoothPagedView
for (int i = 0; i < screenCount; i++) {
final CellLayout cl = (CellLayout)getChildAt(i);
float finalAlphaValue = (i == mCurrentPage) ? 1.0f : 0.0f;
float rotation = 0.0f;
if (i < mCurrentPage) {
rotation = WORKSPACE_ROTATION;
} else if (i > mCurrentPage) {
rotation = -WORKSPACE_ROTATION;
}
if (animated) {
s.playTogether(
new ObjectAnimator<Float>(duration, cl, "translationX", 0.0f),
@@ -704,15 +832,17 @@ public class Workspace extends SmoothPagedView
new ObjectAnimator<Float>(duration, cl, "scaleY", 1.0f),
new ObjectAnimator<Float>(duration, cl, "backgroundAlpha", 0.0f),
new ObjectAnimator<Float>(duration, cl, "alpha", finalAlphaValue),
new ObjectAnimator<Float>(duration, cl, "rotationY", 0.0f));
new ObjectAnimator<Float>(duration, cl, "dimmableProgress", 0.0f),
new ObjectAnimator<Float>(duration, cl, "rotationY", rotation));
} else {
cl.setTranslationX(0.0f);
cl.setTranslationY(0.0f);
cl.setScaleX(1.0f);
cl.setScaleY(1.0f);
cl.setBackgroundAlpha(0.0f);
cl.setAlpha(1.0f);
cl.setRotationY(0.0f);
cl.setDimmableProgress(0.0f);
cl.setAlpha(finalAlphaValue);
cl.setRotationY(rotation);
}
}
s.addListener(mUnshrinkAnimationListener);