summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherStateTransitionAnimation.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/LauncherStateTransitionAnimation.java')
-rw-r--r--src/com/android/launcher3/LauncherStateTransitionAnimation.java224
1 files changed, 129 insertions, 95 deletions
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
index d69b7432d..cdde8c13f 100644
--- a/src/com/android/launcher3/LauncherStateTransitionAnimation.java
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -80,13 +80,6 @@ import java.util.HashMap;
public class LauncherStateTransitionAnimation {
/**
- * Callbacks made during the state transition
- */
- interface Callbacks {
- public void onStateTransitionHideSearchBar();
- }
-
- /**
* Private callbacks made during transition setup.
*/
static abstract class PrivateTransitionCallbacks {
@@ -111,12 +104,10 @@ public class LauncherStateTransitionAnimation {
public static final int SINGLE_FRAME_DELAY = 16;
@Thunk Launcher mLauncher;
- @Thunk Callbacks mCb;
- @Thunk AnimatorSet mStateAnimation;
+ @Thunk AnimatorSet mCurrentAnimation;
- public LauncherStateTransitionAnimation(Launcher l, Callbacks cb) {
+ public LauncherStateTransitionAnimation(Launcher l) {
mLauncher = l;
- mCb = cb;
}
/**
@@ -125,8 +116,8 @@ public class LauncherStateTransitionAnimation {
* @param startSearchAfterTransition Immediately starts app search after the transition to
* All Apps is completed.
*/
- public void startAnimationToAllApps(final boolean animated,
- final boolean startSearchAfterTransition) {
+ public void startAnimationToAllApps(final Workspace.State fromWorkspaceState,
+ final boolean animated, final boolean startSearchAfterTransition) {
final AllAppsContainerView toView = mLauncher.getAppsView();
final View buttonView = mLauncher.getAllAppsButton();
PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() {
@@ -159,15 +150,16 @@ public class LauncherStateTransitionAnimation {
}
};
// Only animate the search bar if animating from spring loaded mode back to all apps
- startAnimationToOverlay(Workspace.State.NORMAL_HIDDEN, buttonView, toView,
- toView.getContentView(), toView.getRevealView(), toView.getSearchBarView(),
- animated, true /* hideSearchBar */, cb);
+ mCurrentAnimation = startAnimationToOverlay(fromWorkspaceState,
+ Workspace.State.NORMAL_HIDDEN, buttonView, toView, toView.getContentView(),
+ toView.getRevealView(), toView.getSearchBarView(), animated, cb);
}
/**
* Starts an animation to the widgets view.
*/
- public void startAnimationToWidgets(final boolean animated) {
+ public void startAnimationToWidgets(final Workspace.State fromWorkspaceState,
+ final boolean animated) {
final WidgetsContainerView toView = mLauncher.getWidgetsView();
final View buttonView = mLauncher.getWidgetsButton();
@@ -177,17 +169,17 @@ public class LauncherStateTransitionAnimation {
return 0.3f;
}
};
- startAnimationToOverlay(Workspace.State.OVERVIEW_HIDDEN, buttonView, toView,
- toView.getContentView(), toView.getRevealView(), null, animated,
- true /* hideSearchBar */, cb);
+ mCurrentAnimation = startAnimationToOverlay(fromWorkspaceState,
+ Workspace.State.OVERVIEW_HIDDEN, buttonView, toView, toView.getContentView(),
+ toView.getRevealView(), null, animated, cb);
}
/**
* Starts and animation to the workspace from the current overlay view.
*/
public void startAnimationToWorkspace(final Launcher.State fromState,
- final Workspace.State toWorkspaceState, final int toWorkspacePage,
- final boolean animated, final Runnable onCompleteRunnable) {
+ final Workspace.State fromWorkspaceState, final Workspace.State toWorkspaceState,
+ final int toWorkspacePage, final boolean animated, final Runnable onCompleteRunnable) {
if (toWorkspaceState != Workspace.State.NORMAL &&
toWorkspaceState != Workspace.State.SPRING_LOADED &&
toWorkspaceState != Workspace.State.OVERVIEW) {
@@ -195,10 +187,10 @@ public class LauncherStateTransitionAnimation {
}
if (fromState == Launcher.State.APPS || fromState == Launcher.State.APPS_SPRING_LOADED) {
- startAnimationToWorkspaceFromAllApps(toWorkspaceState, toWorkspacePage,
+ startAnimationToWorkspaceFromAllApps(fromWorkspaceState, toWorkspaceState, toWorkspacePage,
animated, onCompleteRunnable);
} else {
- startAnimationToWorkspaceFromWidgets(toWorkspaceState, toWorkspacePage,
+ startAnimationToWorkspaceFromWidgets(fromWorkspaceState, toWorkspaceState, toWorkspacePage,
animated, onCompleteRunnable);
}
}
@@ -207,12 +199,13 @@ public class LauncherStateTransitionAnimation {
* Creates and starts a new animation to a particular overlay view.
*/
@SuppressLint("NewApi")
- private void startAnimationToOverlay(final Workspace.State toWorkspaceState,
- final View buttonView, final View toView, final View contentView, final View revealView,
- final View overlaySearchBarView, final boolean animated, final boolean hideSearchBar,
- final PrivateTransitionCallbacks pCb) {
+ private AnimatorSet startAnimationToOverlay(final Workspace.State fromWorkspaceState,
+ final Workspace.State toWorkspaceState, final View buttonView, final View toView,
+ final View contentView, final View revealView, final View overlaySearchBarView,
+ final boolean animated, final PrivateTransitionCallbacks pCb) {
+ final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
final Resources res = mLauncher.getResources();
- final boolean material = Utilities.isLmpOrAbove();
+ final boolean material = Utilities.ATLEAST_LOLLIPOP;
final int revealDuration = res.getInteger(R.integer.config_overlayRevealTime);
final int itemsAlphaStagger =
res.getInteger(R.integer.config_overlayItemsAlphaStagger);
@@ -230,11 +223,13 @@ public class LauncherStateTransitionAnimation {
// Create the workspace animation.
// NOTE: this call apparently also sets the state for the workspace if !animated
Animator workspaceAnim = mLauncher.startWorkspaceStateChangeAnimation(toWorkspaceState, -1,
- animated, overlaySearchBarView != null /* hasOverlaySearchBar */, layerViews);
+ animated, layerViews);
- if (animated && initialized) {
- mStateAnimation = LauncherAnimUtils.createAnimatorSet();
+ // Animate the search bar
+ startWorkspaceSearchBarAnimation(animation, fromWorkspaceState, toWorkspaceState,
+ animated ? revealDuration : 0, overlaySearchBarView);
+ if (animated && initialized) {
// Setup the reveal view animation
int width = revealView.getMeasuredWidth();
int height = revealView.getMeasuredHeight();
@@ -274,7 +269,7 @@ public class LauncherStateTransitionAnimation {
// Play the animation
layerViews.put(revealView, BUILD_AND_SET_LAYER);
- mStateAnimation.play(panelAlphaAndDrift);
+ animation.play(panelAlphaAndDrift);
if (overlaySearchBarView != null) {
overlaySearchBarView.setAlpha(0f);
@@ -282,7 +277,7 @@ public class LauncherStateTransitionAnimation {
searchBarAlpha.setDuration(100);
searchBarAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
layerViews.put(overlaySearchBarView, BUILD_AND_SET_LAYER);
- mStateAnimation.play(searchBarAlpha);
+ animation.play(searchBarAlpha);
}
// Setup the animation for the content view
@@ -297,13 +292,13 @@ public class LauncherStateTransitionAnimation {
pageDrift.setDuration(revealDuration);
pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
pageDrift.setStartDelay(itemsAlphaStagger);
- mStateAnimation.play(pageDrift);
+ animation.play(pageDrift);
ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(contentView, "alpha", 0f, 1f);
itemsAlpha.setDuration(revealDuration);
itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
itemsAlpha.setStartDelay(itemsAlphaStagger);
- mStateAnimation.play(itemsAlpha);
+ animation.play(itemsAlpha);
if (material) {
float startRadius = pCb.getMaterialRevealViewStartFinalRadius();
@@ -316,10 +311,10 @@ public class LauncherStateTransitionAnimation {
if (listener != null) {
reveal.addListener(listener);
}
- mStateAnimation.play(reveal);
+ animation.play(reveal);
}
- mStateAnimation.addListener(new AnimatorListenerAdapter() {
+ animation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
dispatchOnLauncherTransitionEnd(fromView, animated, false);
@@ -335,12 +330,8 @@ public class LauncherStateTransitionAnimation {
}
}
- if (hideSearchBar) {
- mCb.onStateTransitionHideSearchBar();
- }
-
// This can hold unnecessary references to views.
- mStateAnimation = null;
+ cleanupAnimation();
pCb.onTransitionComplete();
}
@@ -348,7 +339,7 @@ public class LauncherStateTransitionAnimation {
// Play the workspace animation
if (workspaceAnim != null) {
- mStateAnimation.play(workspaceAnim);
+ animation.play(workspaceAnim);
}
// Dispatch the prepare transition signal
@@ -356,23 +347,22 @@ public class LauncherStateTransitionAnimation {
dispatchOnLauncherTransitionPrepare(toView, animated, false);
- final AnimatorSet stateAnimation = mStateAnimation;
+ final AnimatorSet stateAnimation = animation;
final Runnable startAnimRunnable = new Runnable() {
public void run() {
- // Check that mStateAnimation hasn't changed while
+ // Check that mCurrentAnimation hasn't changed while
// we waited for a layout/draw pass
- if (mStateAnimation != stateAnimation)
+ if (mCurrentAnimation != stateAnimation)
return;
dispatchOnLauncherTransitionStart(fromView, animated, false);
dispatchOnLauncherTransitionStart(toView, animated, false);
// Enable all necessary layers
- boolean isLmpOrAbove = Utilities.isLmpOrAbove();
for (View v : layerViews.keySet()) {
if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
- if (isLmpOrAbove && Utilities.isViewAttachedToWindow(v)) {
+ if (Utilities.ATLEAST_LOLLIPOP && Utilities.isViewAttachedToWindow(v)) {
v.buildLayer();
}
}
@@ -380,12 +370,14 @@ public class LauncherStateTransitionAnimation {
// Focus the new view
toView.requestFocus();
- mStateAnimation.start();
+ stateAnimation.start();
}
};
toView.bringToFront();
toView.setVisibility(View.VISIBLE);
toView.post(startAnimRunnable);
+
+ return animation;
} else {
toView.setTranslationX(0.0f);
toView.setTranslationY(0.0f);
@@ -397,10 +389,6 @@ public class LauncherStateTransitionAnimation {
// Show the content view
contentView.setVisibility(View.VISIBLE);
- if (hideSearchBar) {
- mCb.onStateTransitionHideSearchBar();
- }
-
dispatchOnLauncherTransitionPrepare(fromView, animated, false);
dispatchOnLauncherTransitionStart(fromView, animated, false);
dispatchOnLauncherTransitionEnd(fromView, animated, false);
@@ -408,18 +396,19 @@ public class LauncherStateTransitionAnimation {
dispatchOnLauncherTransitionStart(toView, animated, false);
dispatchOnLauncherTransitionEnd(toView, animated, false);
pCb.onTransitionComplete();
+
+ return null;
}
}
/**
* Starts and animation to the workspace from the apps view.
*/
- private void startAnimationToWorkspaceFromAllApps(final Workspace.State toWorkspaceState,
- final int toWorkspacePage, final boolean animated, final Runnable onCompleteRunnable) {
+ private void startAnimationToWorkspaceFromAllApps(final Workspace.State fromWorkspaceState,
+ final Workspace.State toWorkspaceState, final int toWorkspacePage,
+ final boolean animated, final Runnable onCompleteRunnable) {
AllAppsContainerView appsView = mLauncher.getAppsView();
PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() {
- int[] mAllAppsToPanelDelta;
-
@Override
float getMaterialRevealViewFinalAlpha(View revealView) {
// No alpha anim from all apps
@@ -451,8 +440,8 @@ public class LauncherStateTransitionAnimation {
}
};
// Only animate the search bar if animating to spring loaded mode from all apps
- startAnimationToWorkspaceFromOverlay(toWorkspaceState, toWorkspacePage,
- mLauncher.getAllAppsButton(), appsView, appsView.getContentView(),
+ mCurrentAnimation = startAnimationToWorkspaceFromOverlay(fromWorkspaceState, toWorkspaceState,
+ toWorkspacePage, mLauncher.getAllAppsButton(), appsView, appsView.getContentView(),
appsView.getRevealView(), appsView.getSearchBarView(), animated,
onCompleteRunnable, cb);
}
@@ -460,8 +449,9 @@ public class LauncherStateTransitionAnimation {
/**
* Starts and animation to the workspace from the widgets view.
*/
- private void startAnimationToWorkspaceFromWidgets(final Workspace.State toWorkspaceState,
- final int toWorkspacePage, final boolean animated, final Runnable onCompleteRunnable) {
+ private void startAnimationToWorkspaceFromWidgets(final Workspace.State fromWorkspaceState,
+ final Workspace.State toWorkspaceState, final int toWorkspacePage,
+ final boolean animated, final Runnable onCompleteRunnable) {
final WidgetsContainerView widgetsView = mLauncher.getWidgetsView();
PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() {
@Override
@@ -479,21 +469,23 @@ public class LauncherStateTransitionAnimation {
};
}
};
- startAnimationToWorkspaceFromOverlay(toWorkspaceState, toWorkspacePage,
- mLauncher.getWidgetsButton(), widgetsView, widgetsView.getContentView(),
- widgetsView.getRevealView(), null, animated, onCompleteRunnable, cb);
+ mCurrentAnimation = startAnimationToWorkspaceFromOverlay(fromWorkspaceState,
+ toWorkspaceState, toWorkspacePage, mLauncher.getWidgetsButton(), widgetsView,
+ widgetsView.getContentView(), widgetsView.getRevealView(), null, animated,
+ onCompleteRunnable, cb);
}
/**
* Creates and starts a new animation to the workspace.
*/
- private void startAnimationToWorkspaceFromOverlay(final Workspace.State toWorkspaceState,
- final int toWorkspacePage, final View buttonView, final View fromView,
- final View contentView, final View revealView, final View overlaySearchBarView,
- final boolean animated, final Runnable onCompleteRunnable,
- final PrivateTransitionCallbacks pCb) {
+ private AnimatorSet startAnimationToWorkspaceFromOverlay(final Workspace.State fromWorkspaceState,
+ final Workspace.State toWorkspaceState, final int toWorkspacePage, final View buttonView,
+ final View fromView, final View contentView, final View revealView,
+ final View overlaySearchBarView, final boolean animated, final Runnable onCompleteRunnable,
+ final PrivateTransitionCallbacks pCb) {
+ final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
final Resources res = mLauncher.getResources();
- final boolean material = Utilities.isLmpOrAbove();
+ final boolean material = Utilities.ATLEAST_LOLLIPOP;
final int revealDuration = res.getInteger(R.integer.config_overlayRevealTime);
final int itemsAlphaStagger =
res.getInteger(R.integer.config_overlayItemsAlphaStagger);
@@ -511,15 +503,16 @@ public class LauncherStateTransitionAnimation {
// Create the workspace animation.
// NOTE: this call apparently also sets the state for the workspace if !animated
Animator workspaceAnim = mLauncher.startWorkspaceStateChangeAnimation(toWorkspaceState,
- toWorkspacePage, animated, overlaySearchBarView != null /* hasOverlaySearchBar */,
- layerViews);
+ toWorkspacePage, animated, layerViews);
- if (animated && initialized) {
- mStateAnimation = LauncherAnimUtils.createAnimatorSet();
+ // Animate the search bar
+ startWorkspaceSearchBarAnimation(animation, fromWorkspaceState, toWorkspaceState,
+ animated ? revealDuration : 0, overlaySearchBarView);
+ if (animated && initialized) {
// Play the workspace animation
if (workspaceAnim != null) {
- mStateAnimation.play(workspaceAnim);
+ animation.play(workspaceAnim);
}
// hideAppsCustomizeHelper is called in some cases when it is already hidden
@@ -558,14 +551,14 @@ public class LauncherStateTransitionAnimation {
panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
panelDriftY.setInterpolator(decelerateInterpolator);
- mStateAnimation.play(panelDriftY);
+ animation.play(panelDriftY);
ObjectAnimator panelDriftX = ObjectAnimator.ofFloat(revealView, "translationX",
0, revealViewToXDrift);
panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
panelDriftX.setInterpolator(decelerateInterpolator);
- mStateAnimation.play(panelDriftX);
+ animation.play(panelDriftX);
// Setup animation for the reveal panel alpha
final float revealViewToAlpha = !material ? 0f :
@@ -576,7 +569,7 @@ public class LauncherStateTransitionAnimation {
panelAlpha.setDuration(material ? revealDuration : 150);
panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY);
panelAlpha.setInterpolator(decelerateInterpolator);
- mStateAnimation.play(panelAlpha);
+ animation.play(panelAlpha);
}
// Setup the animation for the content view
@@ -589,13 +582,13 @@ public class LauncherStateTransitionAnimation {
pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
pageDrift.setInterpolator(decelerateInterpolator);
pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
- mStateAnimation.play(pageDrift);
+ animation.play(pageDrift);
contentView.setAlpha(1f);
ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(contentView, "alpha", 1f, 0f);
itemsAlpha.setDuration(100);
itemsAlpha.setInterpolator(decelerateInterpolator);
- mStateAnimation.play(itemsAlpha);
+ animation.play(itemsAlpha);
if (overlaySearchBarView != null) {
overlaySearchBarView.setAlpha(1f);
@@ -604,7 +597,7 @@ public class LauncherStateTransitionAnimation {
searchAlpha.setInterpolator(decelerateInterpolator);
searchAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY);
layerViews.put(overlaySearchBarView, BUILD_AND_SET_LAYER);
- mStateAnimation.play(searchAlpha);
+ animation.play(searchAlpha);
}
if (material) {
@@ -620,14 +613,14 @@ public class LauncherStateTransitionAnimation {
if (listener != null) {
reveal.addListener(listener);
}
- mStateAnimation.play(reveal);
+ animation.play(reveal);
}
dispatchOnLauncherTransitionPrepare(fromView, animated, true);
dispatchOnLauncherTransitionPrepare(toView, animated, true);
}
- mStateAnimation.addListener(new AnimatorListenerAdapter() {
+ animation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
fromView.setVisibility(View.GONE);
@@ -657,35 +650,37 @@ public class LauncherStateTransitionAnimation {
}
// This can hold unnecessary references to views.
- mStateAnimation = null;
+ cleanupAnimation();
pCb.onTransitionComplete();
}
});
- final AnimatorSet stateAnimation = mStateAnimation;
+ final AnimatorSet stateAnimation = animation;
final Runnable startAnimRunnable = new Runnable() {
public void run() {
- // Check that mStateAnimation hasn't changed while
+ // Check that mCurrentAnimation hasn't changed while
// we waited for a layout/draw pass
- if (mStateAnimation != stateAnimation)
+ if (mCurrentAnimation != stateAnimation)
return;
+
dispatchOnLauncherTransitionStart(fromView, animated, false);
dispatchOnLauncherTransitionStart(toView, animated, false);
// Enable all necessary layers
- boolean isLmpOrAbove = Utilities.isLmpOrAbove();
for (View v : layerViews.keySet()) {
if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
- if (isLmpOrAbove && Utilities.isViewAttachedToWindow(v)) {
+ if (Utilities.ATLEAST_LOLLIPOP && Utilities.isViewAttachedToWindow(v)) {
v.buildLayer();
}
}
- mStateAnimation.start();
+ stateAnimation.start();
}
};
fromView.post(startAnimRunnable);
+
+ return animation;
} else {
fromView.setVisibility(View.GONE);
dispatchOnLauncherTransitionPrepare(fromView, animated, true);
@@ -700,9 +695,44 @@ public class LauncherStateTransitionAnimation {
if (onCompleteRunnable != null) {
onCompleteRunnable.run();
}
+
+ return null;
}
}
+ /**
+ * Coordinates the workspace search bar animation along with the launcher state animation.
+ */
+ private void startWorkspaceSearchBarAnimation(AnimatorSet animation,
+ final Workspace.State fromWorkspaceState, final Workspace.State toWorkspaceState, int duration,
+ View overlaySearchBar) {
+ final SearchDropTargetBar.State toSearchBarState =
+ toWorkspaceState.getSearchDropTargetBarState();
+
+ if (overlaySearchBar != null) {
+ if ((toWorkspaceState == Workspace.State.NORMAL) &&
+ (fromWorkspaceState == Workspace.State.NORMAL_HIDDEN)) {
+ // If we are transitioning from the overlay to the workspace, then show the
+ // workspace search bar immediately and let the overlay search bar fade out on top
+ mLauncher.getSearchDropTargetBar().animateToState(toSearchBarState, 0);
+ } else if (fromWorkspaceState == Workspace.State.NORMAL) {
+ // If we are transitioning from the workspace to the overlay, then keep the
+ // workspace search bar visible until the overlay search bar fades in on top
+ animation.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mLauncher.getSearchDropTargetBar().animateToState(toSearchBarState, 0);
+ }
+ });
+ } else {
+ // Otherwise, then just animate the workspace search bar normally
+ mLauncher.getSearchDropTargetBar().animateToState(toSearchBarState, duration);
+ }
+ } else {
+ // If there is no overlay search bar, then just animate the workspace search bar
+ mLauncher.getSearchDropTargetBar().animateToState(toSearchBarState, duration);
+ }
+ }
/**
* Dispatches the prepare-transition event to suitable views.
@@ -753,10 +783,14 @@ public class LauncherStateTransitionAnimation {
* Cancels the current animation.
*/
private void cancelAnimation() {
- if (mStateAnimation != null) {
- mStateAnimation.setDuration(0);
- mStateAnimation.cancel();
- mStateAnimation = null;
+ if (mCurrentAnimation != null) {
+ mCurrentAnimation.setDuration(0);
+ mCurrentAnimation.cancel();
+ mCurrentAnimation = null;
}
}
+
+ @Thunk void cleanupAnimation() {
+ mCurrentAnimation = null;
+ }
}