Removing view layer support during state animation.

View layer was only being used when fading in/out hotseat in overview.
From API 21+, android automatically create layers when animating alpha

The current support for view layers does not work properly when cancelling
animations and controlling partial animations

Change-Id: I2d5785471af9819575beefe65f1f2bdd28c76bd5
diff --git a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
index 530d757..60cd0c2 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
@@ -24,7 +24,6 @@
 import com.android.launcher3.LauncherState;
 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;
@@ -54,7 +53,7 @@
     }
 
     @Override
-    public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
+    public void setStateWithAnimation(LauncherState toState,
             AnimatorSetBuilder builder, AnimationConfig config) {
         ObjectAnimator progressAnim =
                 mTransitionProgress.animateToValue(toState == LauncherState.OVERVIEW ? 1 : 0);
diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java
index de21c7f..e3768e2 100644
--- a/src/com/android/launcher3/LauncherStateManager.java
+++ b/src/com/android/launcher3/LauncherStateManager.java
@@ -25,7 +25,6 @@
 import android.os.Looper;
 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;
@@ -212,15 +211,12 @@
 
     protected AnimatorSet createAnimationToNewWorkspaceInternal(final LauncherState state,
             AnimatorSetBuilder builder, final Runnable onCompleteRunnable) {
-        final AnimationLayerSet layerViews = new AnimationLayerSet();
-
         for (StateHandler handler : getStateHandlers()) {
             builder.startTag(handler);
-            handler.setStateWithAnimation(state, layerViews, builder, mConfig);
+            handler.setStateWithAnimation(state, builder, mConfig);
         }
 
         final AnimatorSet animation = builder.build();
-        animation.addListener(layerViews);
         animation.addListener(new AnimationSuccessListener() {
 
             @Override
@@ -339,7 +335,7 @@
         /**
          * Sets the UI to {@param state} by animating any changes.
          */
-        void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
+        void setStateWithAnimation(LauncherState toState,
                 AnimatorSetBuilder builder, AnimationConfig config);
     }
 
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index a67b92a..9dc8bb7 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -62,7 +62,6 @@
 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;
@@ -1547,10 +1546,10 @@
      * Sets the current workspace {@link LauncherState}, then animates the UI
      */
     @Override
-    public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
+    public void setStateWithAnimation(LauncherState toState,
             AnimatorSetBuilder builder, AnimationConfig config) {
         StateTransitionListener listener = new StateTransitionListener(toState);
-        mStateTransitionAnimation.setStateWithAnimation(toState, builder, layerViews, config);
+        mStateTransitionAnimation.setStateWithAnimation(toState, builder, config);
 
         // Invalidate the pages now, so that we have the visible pages before the
         // animation is started
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index 0ec3142..abc140d 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -21,7 +21,6 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
-import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.animation.TimeInterpolator;
 import android.animation.ValueAnimator;
@@ -32,7 +31,6 @@
 
 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;
 
@@ -112,9 +110,9 @@
     }
 
     public void setStateWithAnimation(LauncherState toState, AnimatorSetBuilder builder,
-            AnimationLayerSet layerViews, AnimationConfig config) {
+            AnimationConfig config) {
         AnimatedPropertySetter propertySetter =
-                new AnimatedPropertySetter(config.duration, layerViews, builder);
+                new AnimatedPropertySetter(config.duration, builder);
         setWorkspaceProperty(toState, propertySetter);
     }
 
@@ -190,13 +188,10 @@
     public static class AnimatedPropertySetter extends PropertySetter {
 
         private final long mDuration;
-        private final AnimationLayerSet mLayerViews;
         private final AnimatorSetBuilder mStateAnimator;
 
-        public AnimatedPropertySetter(
-                long duration, AnimationLayerSet layerView, AnimatorSetBuilder builder) {
+        public AnimatedPropertySetter(long duration, AnimatorSetBuilder builder) {
             mDuration = duration;
-            mLayerViews = layerView;
             mStateAnimator = builder;
         }
 
@@ -211,7 +206,6 @@
             }
 
             anim.setDuration(mDuration).setInterpolator(getFadeInterpolator(alpha));
-            mLayerViews.addView(view);
             mStateAnimator.play(anim);
         }
 
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 14ad97b..5de58b4 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -18,7 +18,6 @@
 import com.android.launcher3.R;
 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;
@@ -122,7 +121,7 @@
      * @param progress value between 0 and 1, 0 shows all apps and 1 shows workspace
      *
      * @see #setState(LauncherState)
-     * @see #setStateWithAnimation(LauncherState, AnimationLayerSet, AnimatorSetBuilder, AnimationConfig)
+     * @see #setStateWithAnimation(LauncherState, AnimatorSetBuilder, AnimationConfig)
      */
     public void setProgress(float progress) {
         mProgress = progress;
@@ -167,7 +166,7 @@
      * dependent UI using various animation events
      */
     @Override
-    public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
+    public void setStateWithAnimation(LauncherState toState,
             AnimatorSetBuilder builder, AnimationConfig config) {
         if (Float.compare(mProgress, toState.verticalProgress) == 0) {
             // Fail fast
diff --git a/src/com/android/launcher3/anim/AnimationLayerSet.java b/src/com/android/launcher3/anim/AnimationLayerSet.java
deleted file mode 100644
index f0b3458..0000000
--- a/src/com/android/launcher3/anim/AnimationLayerSet.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2016 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.AnimatorListenerAdapter;
-import android.util.ArrayMap;
-import android.view.View;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * Helper class to automatically build view hardware layers for the duration of an animation.
- */
-public class AnimationLayerSet extends AnimatorListenerAdapter {
-
-    private final ArrayMap<View, Integer> mViewsToLayerTypeMap;
-
-    public AnimationLayerSet() {
-        mViewsToLayerTypeMap = new ArrayMap<>();
-    }
-
-    public AnimationLayerSet(View v) {
-        mViewsToLayerTypeMap = new ArrayMap<>(1);
-        addView(v);
-    }
-
-    public void addView(View v) {
-        mViewsToLayerTypeMap.put(v, v.getLayerType());
-    }
-
-    @Override
-    public void onAnimationStart(Animator animation) {
-        // Enable all necessary layers
-        Iterator<Map.Entry<View, Integer>> itr = mViewsToLayerTypeMap.entrySet().iterator();
-        while (itr.hasNext()) {
-            Map.Entry<View, Integer> entry = itr.next();
-            View v = entry.getKey();
-            entry.setValue(v.getLayerType());
-            v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
-            if (v.isAttachedToWindow() && v.getVisibility() == View.VISIBLE) {
-                v.buildLayer();
-            }
-        }
-    }
-
-    @Override
-    public void onAnimationEnd(Animator animation) {
-        Iterator<Map.Entry<View, Integer>> itr = mViewsToLayerTypeMap.entrySet().iterator();
-        while (itr.hasNext()) {
-            Map.Entry<View, Integer> entry = itr.next();
-            entry.getKey().setLayerType(entry.getValue(), null);
-        }
-    }
-}
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java
index 1ba8cd6..b23927b 100644
--- a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java
+++ b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java
@@ -36,7 +36,6 @@
 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;
@@ -168,9 +167,9 @@
     }
 
     @Override
-    public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
+    public void setStateWithAnimation(LauncherState toState,
             AnimatorSetBuilder builder, AnimationConfig config) {
-        setState(toState, new AnimatedPropertySetter(config.duration, layerViews, builder));
+        setState(toState, new AnimatedPropertySetter(config.duration, builder));
     }
 
     private void setState(LauncherState state, PropertySetter setter) {