From e3c6d58b71ae46dfdd20b8aeefbff858b8a9dc99 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 7 Dec 2017 12:45:49 -0800 Subject: [PATCH] Adding support for tagging animations per controller, so that they can be controlled independently Change-Id: I6f360362aa16f7e02fe5fe84976b23663f228030 --- .../RecentsViewStateController.java | 8 ++-- .../launcher3/LauncherStateManager.java | 21 ++++++--- src/com/android/launcher3/Workspace.java | 10 ++--- .../WorkspaceStateTransitionAnimation.java | 11 ++--- .../allapps/AllAppsTransitionController.java | 8 ++-- .../launcher3/anim/AnimatorSetBuilder.java | 43 +++++++++++++++++++ .../launcher3/uioverrides/OverviewPanel.java | 6 +-- 7 files changed, 80 insertions(+), 27 deletions(-) create mode 100644 src/com/android/launcher3/anim/AnimatorSetBuilder.java diff --git a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java index b59e4ee2bd..530d75739c 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java @@ -17,7 +17,6 @@ package com.android.launcher3.uioverrides; 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.AnimationConfig; 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 @@ public class RecentsViewStateController implements StateHandler { @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 2cad95e9b8..de21c7f516 100644 --- a/src/com/android/launcher3/LauncherStateManager.java +++ b/src/com/android/launcher3/LauncherStateManager.java @@ -28,6 +28,7 @@ import android.view.View; 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 @@ public class LauncherStateManager { // 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 class LauncherStateManager { */ 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 @@ public class LauncherStateManager { * 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 3d59bad13b..0841c4bc7d 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -26,7 +26,6 @@ import static com.android.launcher3.Utilities.isAccessibilityEnabled; 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.AccessibleDragListenerAdapter; 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 @@ public class Workspace extends PagedView */ @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 @@ public class Workspace extends PagedView 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 edf5ada6ec..0ec3142dc4 100644 --- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java +++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java @@ -33,6 +33,7 @@ import android.view.accessibility.AccessibilityManager; 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 @@ public class WorkspaceStateTransitionAnimation { 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 @@ public class WorkspaceStateTransitionAnimation { 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 7ce032f408..14ad97b45a 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -5,7 +5,6 @@ import static com.android.launcher3.anim.Interpolators.LINEAR; 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.Utilities; 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 @@ public class AllAppsTransitionController * @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 @@ public class AllAppsTransitionController */ @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 @@ public class AllAppsTransitionController 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 0000000000..0e44b73cee --- /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 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 3ce101414a..1ba8cd62c0 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 @@ package com.android.launcher3.uioverrides; 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.Utilities; 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 @@ public class OverviewPanel extends LinearLayout implements Insettable, View.OnCl @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) {