Adding support for tagging animations per controller, so that they can be controlled independently
Change-Id: I6f360362aa16f7e02fe5fe84976b23663f228030
diff --git a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
index b59e4ee..530d757 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
@@ -17,7 +17,6 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
-import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;
@@ -27,6 +26,7 @@
import com.android.launcher3.LauncherStateManager.StateHandler;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.anim.AnimationSuccessListener;
+import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.anim.Interpolators;
import com.android.quickstep.AnimatedFloat;
import com.android.quickstep.RecentsView;
@@ -55,17 +55,17 @@
@Override
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
- AnimatorSet anim, AnimationConfig config) {
+ AnimatorSetBuilder builder, AnimationConfig config) {
ObjectAnimator progressAnim =
mTransitionProgress.animateToValue(toState == LauncherState.OVERVIEW ? 1 : 0);
progressAnim.setDuration(config.duration);
progressAnim.setInterpolator(Interpolators.LINEAR);
- anim.play(progressAnim);
+ builder.play(progressAnim);
ObjectAnimator visibilityAnim = animateVisibility(toState == LauncherState.OVERVIEW);
visibilityAnim.setDuration(config.duration);
visibilityAnim.setInterpolator(Interpolators.LINEAR);
- anim.play(visibilityAnim);
+ builder.play(visibilityAnim);
}
public void setVisibility(boolean isVisible) {
diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java
index 2cad95e..de21c7f 100644
--- a/src/com/android/launcher3/LauncherStateManager.java
+++ b/src/com/android/launcher3/LauncherStateManager.java
@@ -28,6 +28,7 @@
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
+import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.uioverrides.UiFactory;
/**
@@ -178,7 +179,8 @@
// transition plays in reverse and use the same duration as previous state.
mConfig.duration = state == NORMAL ? mState.transitionDuration : state.transitionDuration;
- AnimatorSet animation = createAnimationToNewWorkspaceInternal(state, onCompleteRunnable);
+ AnimatorSet animation = createAnimationToNewWorkspaceInternal(
+ state, new AnimatorSetBuilder(), onCompleteRunnable);
Runnable runnable = new StartAnimRunnable(animation, state.getFinalFocus(mLauncher));
if (delay > 0) {
mUiHandler.postDelayed(runnable, delay);
@@ -196,21 +198,28 @@
*/
public AnimatorPlaybackController createAnimationToNewWorkspace(
LauncherState state, long duration) {
+ return createAnimationToNewWorkspace(state, new AnimatorSetBuilder(), duration);
+ }
+
+ public AnimatorPlaybackController createAnimationToNewWorkspace(
+ LauncherState state, AnimatorSetBuilder builder, long duration) {
mConfig.reset();
mConfig.userControlled = true;
mConfig.duration = duration;
return AnimatorPlaybackController.wrap(
- createAnimationToNewWorkspaceInternal(state, null), duration);
+ createAnimationToNewWorkspaceInternal(state, builder, null), duration);
}
protected AnimatorSet createAnimationToNewWorkspaceInternal(final LauncherState state,
- final Runnable onCompleteRunnable) {
- final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
+ AnimatorSetBuilder builder, final Runnable onCompleteRunnable) {
final AnimationLayerSet layerViews = new AnimationLayerSet();
for (StateHandler handler : getStateHandlers()) {
- handler.setStateWithAnimation(state, layerViews, animation, mConfig);
+ builder.startTag(handler);
+ handler.setStateWithAnimation(state, layerViews, builder, mConfig);
}
+
+ final AnimatorSet animation = builder.build();
animation.addListener(layerViews);
animation.addListener(new AnimationSuccessListener() {
@@ -331,7 +340,7 @@
* Sets the UI to {@param state} by animating any changes.
*/
void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
- AnimatorSet anim, AnimationConfig config);
+ AnimatorSetBuilder builder, AnimationConfig config);
}
public interface StateListener {
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 3d59bad..0841c4b 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -26,7 +26,6 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
-import android.animation.AnimatorSet;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
@@ -64,6 +63,7 @@
import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper;
import com.android.launcher3.anim.AnimationLayerSet;
+import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.badge.FolderBadgeInfo;
import com.android.launcher3.compat.AppWidgetManagerCompat;
@@ -1548,9 +1548,9 @@
*/
@Override
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
- AnimatorSet anim, AnimationConfig config) {
+ AnimatorSetBuilder builder, AnimationConfig config) {
StateTransitionListener listener = new StateTransitionListener(toState);
- mStateTransitionAnimation.setStateWithAnimation(toState, anim, layerViews, config);
+ mStateTransitionAnimation.setStateWithAnimation(toState, builder, layerViews, config);
// Invalidate the pages now, so that we have the visible pages before the
// animation is started
@@ -1562,8 +1562,8 @@
ValueAnimator stepAnimator = ValueAnimator.ofFloat(0, 1);
stepAnimator.addUpdateListener(listener);
stepAnimator.setDuration(config.duration);
- anim.play(stepAnimator);
- anim.addListener(listener);
+ stepAnimator.addListener(listener);
+ builder.play(stepAnimator);
}
public void updateAccessibilityFlags() {
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index edf5ada..0ec3142 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -33,6 +33,7 @@
import com.android.launcher3.LauncherState.PageAlphaProvider;
import com.android.launcher3.LauncherStateManager.AnimationConfig;
import com.android.launcher3.anim.AnimationLayerSet;
+import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.anim.Interpolators;
/**
@@ -110,10 +111,10 @@
setWorkspaceProperty(toState, NO_ANIM_PROPERTY_SETTER);
}
- public void setStateWithAnimation(LauncherState toState, AnimatorSet anim,
+ public void setStateWithAnimation(LauncherState toState, AnimatorSetBuilder builder,
AnimationLayerSet layerViews, AnimationConfig config) {
AnimatedPropertySetter propertySetter =
- new AnimatedPropertySetter(config.duration, layerViews, anim);
+ new AnimatedPropertySetter(config.duration, layerViews, builder);
setWorkspaceProperty(toState, propertySetter);
}
@@ -190,13 +191,13 @@
private final long mDuration;
private final AnimationLayerSet mLayerViews;
- private final AnimatorSet mStateAnimator;
+ private final AnimatorSetBuilder mStateAnimator;
public AnimatedPropertySetter(
- long duration, AnimationLayerSet layerView, AnimatorSet anim) {
+ long duration, AnimationLayerSet layerView, AnimatorSetBuilder builder) {
mDuration = duration;
mLayerViews = layerView;
- mStateAnimator = anim;
+ mStateAnimator = builder;
}
@Override
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 7ce032f..14ad97b 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -5,7 +5,6 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
-import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.util.Property;
import android.view.View;
@@ -21,6 +20,7 @@
import com.android.launcher3.Workspace;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.anim.AnimationSuccessListener;
+import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.graphics.GradientView;
import com.android.launcher3.util.SystemUiController;
@@ -122,7 +122,7 @@
* @param progress value between 0 and 1, 0 shows all apps and 1 shows workspace
*
* @see #setState(LauncherState)
- * @see #setStateWithAnimation(LauncherState, AnimationLayerSet, AnimatorSet, AnimationConfig)
+ * @see #setStateWithAnimation(LauncherState, AnimationLayerSet, AnimatorSetBuilder, AnimationConfig)
*/
public void setProgress(float progress) {
mProgress = progress;
@@ -168,7 +168,7 @@
*/
@Override
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
- AnimatorSet animationOut, AnimationConfig config) {
+ AnimatorSetBuilder builder, AnimationConfig config) {
if (Float.compare(mProgress, toState.verticalProgress) == 0) {
// Fail fast
onProgressAnimationEnd();
@@ -182,7 +182,7 @@
anim.setInterpolator(interpolator);
anim.addListener(getProgressAnimatorListener());
- animationOut.play(anim);
+ builder.play(anim);
}
public AnimatorListenerAdapter getProgressAnimatorListener() {
diff --git a/src/com/android/launcher3/anim/AnimatorSetBuilder.java b/src/com/android/launcher3/anim/AnimatorSetBuilder.java
new file mode 100644
index 0000000..0e44b73
--- /dev/null
+++ b/src/com/android/launcher3/anim/AnimatorSetBuilder.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.anim;
+
+import android.animation.Animator;
+import android.animation.AnimatorSet;
+
+import com.android.launcher3.LauncherAnimUtils;
+
+import java.util.ArrayList;
+
+/**
+ * Utility class for building animator set
+ */
+public class AnimatorSetBuilder {
+
+ protected final ArrayList<Animator> mAnims = new ArrayList<>();
+
+ public void startTag(Object obj) { }
+
+ public void play(Animator anim) {
+ mAnims.add(anim);
+ }
+
+ public AnimatorSet build() {
+ AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
+ anim.playTogether(mAnims);
+ return anim;
+ }
+}
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java
index 3ce1014..1ba8cd6 100644
--- a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java
+++ b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java
@@ -17,7 +17,6 @@
import static com.android.launcher3.WorkspaceStateTransitionAnimation.NO_ANIM_PROPERTY_SETTER;
-import android.animation.AnimatorSet;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@@ -38,6 +37,7 @@
import com.android.launcher3.WorkspaceStateTransitionAnimation.AnimatedPropertySetter;
import com.android.launcher3.WorkspaceStateTransitionAnimation.PropertySetter;
import com.android.launcher3.anim.AnimationLayerSet;
+import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import com.android.launcher3.widget.WidgetsFullSheet;
@@ -169,8 +169,8 @@
@Override
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
- AnimatorSet anim, AnimationConfig config) {
- setState(toState, new AnimatedPropertySetter(config.duration, layerViews, anim));
+ AnimatorSetBuilder builder, AnimationConfig config) {
+ setState(toState, new AnimatedPropertySetter(config.duration, layerViews, builder));
}
private void setState(LauncherState state, PropertySetter setter) {