From 7044272f180d34ab29866f6c59ee75376e8a1df5 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 10 Feb 2012 15:43:22 -0800 Subject: Allow touches to fall through AllApps nearing end of transition (Bug: 5991846, 6016062, 5991846) - Also updating mTransitionProgress so control when drops succeed Change-Id: I2f672c64f0a87249dcf7d254f963b8b2710c849f --- .../android/launcher2/AppsCustomizeTabHost.java | 22 +++++++ src/com/android/launcher2/Launcher.java | 30 +++++++++ src/com/android/launcher2/Workspace.java | 77 ++++++++++++++-------- 3 files changed, 101 insertions(+), 28 deletions(-) diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java index a5964dfca..4639c57cc 100644 --- a/src/com/android/launcher2/AppsCustomizeTabHost.java +++ b/src/com/android/launcher2/AppsCustomizeTabHost.java @@ -53,6 +53,7 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona private LinearLayout mContent; private boolean mInTransition; + private boolean mTransitioningToWorkspace; private boolean mResetAfterTransition; public AppsCustomizeTabHost(Context context, AttributeSet attrs) { @@ -154,8 +155,23 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona super.onMeasure(widthMeasureSpec, heightMeasureSpec); } + public boolean onInterceptTouchEvent(MotionEvent ev) { + // If we are mid transition then intercept touch events here so we can ignore them + if (mInTransition) { + return true; + } + return super.onInterceptTouchEvent(ev); + }; + @Override public boolean onTouchEvent(MotionEvent event) { + // Allow touch events to fall through if we are transitioning to the workspace + if (mInTransition) { + if (mTransitioningToWorkspace) { + return super.onTouchEvent(event); + } + } + // Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall // through to the workspace and trigger showWorkspace() if (event.getY() < mAppsCustomizePane.getBottom()) { @@ -349,6 +365,7 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona @Override public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) { mInTransition = true; + mTransitioningToWorkspace = toWorkspace; if (toWorkspace) { // Going from All Apps -> Workspace @@ -376,6 +393,11 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona } } + @Override + public void onLauncherTransitionStep(Launcher l, float t) { + // Do nothing + } + @Override public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { mInTransition = false; diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 92a3d08a0..1a6691db0 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -23,6 +23,7 @@ import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.animation.ValueAnimator; +import android.animation.ValueAnimator.AnimatorUpdateListener; import android.app.Activity; import android.app.ActivityManager; import android.app.AlertDialog; @@ -2224,12 +2225,24 @@ public final class Launcher extends Activity if (v instanceof LauncherTransitionable) { ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); } + + // Update the workspace transition step as well + dispatchOnLauncherTransitionStep(v, 0f); + } + + private void dispatchOnLauncherTransitionStep(View v, float t) { + if (v instanceof LauncherTransitionable) { + ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); + } } private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { if (v instanceof LauncherTransitionable) { ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); } + + // Update the workspace transition step as well + dispatchOnLauncherTransitionStep(v, 1f); } /** @@ -2314,6 +2327,14 @@ public final class Launcher extends Activity .ofFloat(toView, "alpha", 0f, 1f) .setDuration(fadeDuration); alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); + alphaAnim.addUpdateListener(new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + float t = (Float) animation.getAnimatedValue(); + dispatchOnLauncherTransitionStep(fromView, t); + dispatchOnLauncherTransitionStep(toView, t); + } + }); // toView should appear right at the end of the workspace shrink // animation @@ -2469,6 +2490,14 @@ public final class Launcher extends Activity .ofFloat(fromView, "alpha", 1f, 0f) .setDuration(fadeOutDuration); alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator()); + alphaAnim.addUpdateListener(new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + float t = 1f - (Float) animation.getAnimatedValue(); + dispatchOnLauncherTransitionStep(fromView, t); + dispatchOnLauncherTransitionStep(toView, t); + } + }); mStateAnimation = new AnimatorSet(); @@ -3447,5 +3476,6 @@ public final class Launcher extends Activity interface LauncherTransitionable { View getContent(); void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); + void onLauncherTransitionStep(Launcher l, float t); void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); } diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index f61917f9f..0d7498ab0 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -55,6 +55,7 @@ import android.view.Display; import android.view.DragEvent; import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.View.MeasureSpec; import android.view.animation.DecelerateInterpolator; @@ -234,7 +235,7 @@ public class Workspace extends SmoothPagedView private float[] mNewBackgroundAlphaMultipliers; private float[] mNewAlphas; private float[] mNewRotationYs; - private float mTransitionProgress = 1f; + private float mTransitionProgress; /** * Used to inflate the Workspace from XML. @@ -577,20 +578,26 @@ public class Workspace extends SmoothPagedView */ @Override public boolean onTouch(View v, MotionEvent event) { - return (isSmall() || mIsSwitchingState); + return (isSmall() || !isFinishedSwitchingState()); } public boolean isSwitchingState() { return mIsSwitchingState; } + /** This differs from isSwitchingState in that we take into account how far the transition + * has completed. */ + private boolean isFinishedSwitchingState() { + return !mIsSwitchingState || (mTransitionProgress > 0.5f); + } + protected void onWindowVisibilityChanged (int visibility) { mLauncher.onWindowVisibilityChanged(visibility); } @Override public boolean dispatchUnhandledMove(View focused, int direction) { - if (isSmall() || mIsSwitchingState) { + if (isSmall() || !isFinishedSwitchingState()) { // when the home screens are shrunken, shouldn't allow side-scrolling return false; } @@ -618,35 +625,36 @@ public class Workspace extends SmoothPagedView @Override protected void determineScrollingStart(MotionEvent ev) { - if (!isSmall() && !mIsSwitchingState) { - float deltaX = Math.abs(ev.getX() - mXDown); - float deltaY = Math.abs(ev.getY() - mYDown); + if (isSmall()) return; + if (!isFinishedSwitchingState()) return; - if (Float.compare(deltaX, 0f) == 0) return; + float deltaX = Math.abs(ev.getX() - mXDown); + float deltaY = Math.abs(ev.getY() - mYDown); - float slope = deltaY / deltaX; - float theta = (float) Math.atan(slope); + if (Float.compare(deltaX, 0f) == 0) return; - if (deltaX > mTouchSlop || deltaY > mTouchSlop) { - cancelCurrentPageLongPress(); - } + float slope = deltaY / deltaX; + float theta = (float) Math.atan(slope); - if (theta > MAX_SWIPE_ANGLE) { - // Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace - return; - } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) { - // Above START_DAMPING_TOUCH_SLOP_ANGLE and below MAX_SWIPE_ANGLE, we want to - // increase the touch slop to make it harder to begin scrolling the workspace. This - // results in vertically scrolling widgets to more easily. The higher the angle, the - // more we increase touch slop. - theta -= START_DAMPING_TOUCH_SLOP_ANGLE; - float extraRatio = (float) - Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE))); - super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio); - } else { - // Below START_DAMPING_TOUCH_SLOP_ANGLE, we don't do anything special - super.determineScrollingStart(ev); - } + if (deltaX > mTouchSlop || deltaY > mTouchSlop) { + cancelCurrentPageLongPress(); + } + + if (theta > MAX_SWIPE_ANGLE) { + // Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace + return; + } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) { + // Above START_DAMPING_TOUCH_SLOP_ANGLE and below MAX_SWIPE_ANGLE, we want to + // increase the touch slop to make it harder to begin scrolling the workspace. This + // results in vertically scrolling widgets to more easily. The higher the angle, the + // more we increase touch slop. + theta -= START_DAMPING_TOUCH_SLOP_ANGLE; + float extraRatio = (float) + Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE))); + super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio); + } else { + // Below START_DAMPING_TOUCH_SLOP_ANGLE, we don't do anything special + super.determineScrollingStart(ev); } } @@ -676,6 +684,14 @@ public class Workspace extends SmoothPagedView showOutlines(); } + // If we are not fading in adjacent screens, we still need to restore the alpha in case the + // user scrolls while we are transitioning (should not affect dispatchDraw optimizations) + if (!mFadeInAdjacentScreens) { + for (int i = 0; i < getChildCount(); ++i) { + getPageAt(i).setAlpha(1f); + } + } + // Show the scroll indicator as you pan the page showScrollingIndicator(false); } @@ -1703,6 +1719,11 @@ public class Workspace extends SmoothPagedView mIsSwitchingState = true; } + @Override + public void onLauncherTransitionStep(Launcher l, float t) { + mTransitionProgress = t; + } + @Override public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { mIsSwitchingState = false; -- cgit v1.2.3