summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherStateTransitionAnimation.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-10-26 18:32:38 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-10-26 18:34:21 -0700
commitb5e65c8bd3785409d4aeda21f2c88e75c9e22c9f (patch)
tree96f15cf9ce4f1312514959ae39cbcb1191076cf3 /src/com/android/launcher3/LauncherStateTransitionAnimation.java
parent9ccafbff26f5835ab9725d876d1bf7ccd08ccf84 (diff)
downloadandroid_packages_apps_Trebuchet-b5e65c8bd3785409d4aeda21f2c88e75c9e22c9f.tar.gz
android_packages_apps_Trebuchet-b5e65c8bd3785409d4aeda21f2c88e75c9e22c9f.tar.bz2
android_packages_apps_Trebuchet-b5e65c8bd3785409d4aeda21f2c88e75c9e22c9f.zip
Calling buildLayer only on views which are actually visible
> Creating a common listener for handling buildLayer logic Bug: 30138067 Change-Id: I803ef78b48e07e5ae5922e0392d390f274a87d75
Diffstat (limited to 'src/com/android/launcher3/LauncherStateTransitionAnimation.java')
-rw-r--r--src/com/android/launcher3/LauncherStateTransitionAnimation.java120
1 files changed, 17 insertions, 103 deletions
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
index 6d5f95159..7e842645b 100644
--- a/src/com/android/launcher3/LauncherStateTransitionAnimation.java
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -34,13 +34,12 @@ import android.view.animation.DecelerateInterpolator;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsTransitionController;
+import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.CircleRevealOutlineProvider;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.widget.WidgetsContainerView;
-import java.util.HashMap;
-
/**
* TODO: figure out what kind of tests we can write for this
*
@@ -119,9 +118,6 @@ public class LauncherStateTransitionAnimation {
public static final String TAG = "LSTAnimation";
- // Flags to determine how to set the layers on views before the transition animation
- public static final int BUILD_LAYER = 0;
- public static final int BUILD_AND_SET_LAYER = 1;
public static final int SINGLE_FRAME_DELAY = 16;
@Thunk Launcher mLauncher;
@@ -243,7 +239,7 @@ public class LauncherStateTransitionAnimation {
final View fromView = mLauncher.getWorkspace();
- final HashMap<View, Integer> layerViews = new HashMap<>();
+ final AnimationLayerSet layerViews = new AnimationLayerSet();
// If for some reason our views aren't initialized, don't animate
boolean initialized = buttonView != null;
@@ -319,14 +315,14 @@ public class LauncherStateTransitionAnimation {
panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
// Play the animation
- layerViews.put(revealView, BUILD_AND_SET_LAYER);
+ layerViews.addView(revealView);
animation.play(panelAlphaAndDrift);
// Setup the animation for the content view
contentView.setVisibility(View.VISIBLE);
contentView.setAlpha(0f);
contentView.setTranslationY(revealViewToYDrift);
- layerViews.put(contentView, BUILD_AND_SET_LAYER);
+ layerViews.addView(contentView);
// Create the individual animators
ObjectAnimator pageDrift = ObjectAnimator.ofFloat(contentView, "translationY",
@@ -365,13 +361,6 @@ public class LauncherStateTransitionAnimation {
// Hide the reveal view
revealView.setVisibility(View.INVISIBLE);
- // Disable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_NONE, null);
- }
- }
-
// This can hold unnecessary references to views.
cleanupAnimation();
pCb.onTransitionComplete();
@@ -393,16 +382,6 @@ public class LauncherStateTransitionAnimation {
dispatchOnLauncherTransitionStart(fromView, animated, false);
dispatchOnLauncherTransitionStart(toView, animated, false);
- // Enable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
- }
- if (Utilities.ATLEAST_LOLLIPOP && v.isAttachedToWindow()) {
- v.buildLayer();
- }
- }
-
// Focus the new view
toView.requestFocus();
@@ -411,25 +390,19 @@ public class LauncherStateTransitionAnimation {
};
toView.bringToFront();
toView.setVisibility(View.VISIBLE);
+
+ animation.addListener(layerViews);
toView.post(startAnimRunnable);
mCurrentAnimation = animation;
} else if (animType == PULLUP) {
// We are animating the content view alpha, so ensure we have a layer for it
- layerViews.put(contentView, BUILD_AND_SET_LAYER);
+ layerViews.addView(contentView);
animation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
dispatchOnLauncherTransitionEnd(fromView, animated, false);
dispatchOnLauncherTransitionEnd(toView, animated, false);
-
- // Disable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_NONE, null);
- }
- }
-
cleanupAnimation();
pCb.onTransitionComplete();
}
@@ -450,21 +423,12 @@ public class LauncherStateTransitionAnimation {
dispatchOnLauncherTransitionStart(fromView, animated, false);
dispatchOnLauncherTransitionStart(toView, animated, false);
- // Enable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
- }
- if (Utilities.ATLEAST_LOLLIPOP && v.isAttachedToWindow()) {
- v.buildLayer();
- }
- }
-
toView.requestFocus();
stateAnimation.start();
}
};
mCurrentAnimation = animation;
+ mCurrentAnimation.addListener(layerViews);
if (shouldPost) {
toView.post(startAnimRunnable);
} else {
@@ -479,7 +443,7 @@ public class LauncherStateTransitionAnimation {
private void playCommonTransitionAnimations(
Workspace.State toWorkspaceState, View fromView, View toView,
boolean animated, boolean initialized, AnimatorSet animation,
- HashMap<View, Integer> layerViews) {
+ AnimationLayerSet layerViews) {
// Create the workspace animation.
// NOTE: this call apparently also sets the state for the workspace if !animated
Animator workspaceAnim = mLauncher.startWorkspaceStateChangeAnimation(toWorkspaceState,
@@ -594,10 +558,8 @@ public class LauncherStateTransitionAnimation {
final Workspace.State toWorkspaceState, final boolean animated,
final Runnable onCompleteRunnable) {
final View fromWorkspace = mLauncher.getWorkspace();
- final HashMap<View, Integer> layerViews = new HashMap<>();
+ final AnimationLayerSet layerViews = new AnimationLayerSet();
final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
- final int revealDuration = mLauncher.getResources()
- .getInteger(R.integer.config_overlayRevealTime);
// Cancel the current animation
cancelAnimation();
@@ -622,16 +584,6 @@ public class LauncherStateTransitionAnimation {
return;
dispatchOnLauncherTransitionStart(fromWorkspace, animated, true);
-
- // Enable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
- }
- if (Utilities.ATLEAST_LOLLIPOP && v.isAttachedToWindow()) {
- v.buildLayer();
- }
- }
stateAnimation.start();
}
};
@@ -645,17 +597,11 @@ public class LauncherStateTransitionAnimation {
onCompleteRunnable.run();
}
- // Disable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_NONE, null);
- }
- }
-
// This can hold unnecessary references to views.
cleanupAnimation();
}
});
+ stateAnimation.addListener(layerViews);
fromWorkspace.post(startAnimRunnable);
mCurrentAnimation = animation;
} else /* if (!animated) */ {
@@ -692,7 +638,7 @@ public class LauncherStateTransitionAnimation {
final View revealView = fromView.getRevealView();
final View contentView = fromView.getContentView();
- final HashMap<View, Integer> layerViews = new HashMap<>();
+ final AnimationLayerSet layerViews = new AnimationLayerSet();
// If for some reason our views aren't initialized, don't animate
boolean initialized = buttonView != null;
@@ -735,7 +681,7 @@ public class LauncherStateTransitionAnimation {
revealView.setVisibility(View.VISIBLE);
revealView.setAlpha(1f);
revealView.setTranslationY(0);
- layerViews.put(revealView, BUILD_AND_SET_LAYER);
+ layerViews.addView(revealView);
// Calculate the final animation values
final float revealViewToXDrift;
@@ -783,7 +729,7 @@ public class LauncherStateTransitionAnimation {
}
// Setup the animation for the content view
- layerViews.put(contentView, BUILD_AND_SET_LAYER);
+ layerViews.addView(contentView);
// Create the individual animators
ObjectAnimator pageDrift = ObjectAnimator.ofFloat(contentView, "translationY",
@@ -843,13 +789,6 @@ public class LauncherStateTransitionAnimation {
onCompleteRunnable.run();
}
- // Disable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_NONE, null);
- }
- }
-
// Reset page transforms
if (contentView != null) {
contentView.setTranslationX(0);
@@ -874,24 +813,15 @@ public class LauncherStateTransitionAnimation {
dispatchOnLauncherTransitionStart(fromView, animated, false);
dispatchOnLauncherTransitionStart(toView, animated, false);
-
- // Enable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
- }
- if (Utilities.ATLEAST_LOLLIPOP && v.isAttachedToWindow()) {
- v.buildLayer();
- }
- }
stateAnimation.start();
}
};
mCurrentAnimation = animation;
+ mCurrentAnimation.addListener(layerViews);
fromView.post(startAnimRunnable);
} else if (animType == PULLUP) {
// We are animating the content view alpha, so ensure we have a layer for it
- layerViews.put(contentView, BUILD_AND_SET_LAYER);
+ layerViews.addView(contentView);
animation.addListener(new AnimatorListenerAdapter() {
boolean canceled = false;
@@ -910,13 +840,6 @@ public class LauncherStateTransitionAnimation {
onCompleteRunnable.run();
}
- // Disable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_NONE, null);
- }
- }
-
cleanupAnimation();
pCb.onTransitionComplete();
}
@@ -939,22 +862,13 @@ public class LauncherStateTransitionAnimation {
dispatchOnLauncherTransitionStart(fromView, animated, false);
dispatchOnLauncherTransitionStart(toView, animated, false);
- // Enable all necessary layers
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
- }
- if (Utilities.ATLEAST_LOLLIPOP && v.isAttachedToWindow()) {
- v.buildLayer();
- }
- }
-
// Focus the new view
toView.requestFocus();
stateAnimation.start();
}
};
mCurrentAnimation = animation;
+ mCurrentAnimation.addListener(layerViews);
if (shouldPost) {
fromView.post(startAnimRunnable);
} else {